|
18 | 18 | */
|
19 | 19 | function IntroJs(obj) {
|
20 | 20 | this._targetElement = obj;
|
21 |
| - |
| 21 | + |
22 | 22 | this._options = {
|
23 | 23 | nextLabel: 'Next →',
|
24 | 24 | prevLabel: '← Back',
|
25 |
| - skipLabel: 'Skip' |
| 25 | + skipLabel: 'Skip', |
| 26 | + tooltipPosition: 'bottom' |
26 | 27 | }
|
27 | 28 | }
|
28 | 29 |
|
|
50 | 51 | element: currentElement,
|
51 | 52 | intro: currentElement.getAttribute("data-intro"),
|
52 | 53 | step: parseInt(currentElement.getAttribute("data-step"), 10),
|
53 |
| - position: currentElement.getAttribute("data-position") || 'bottom' |
| 54 | + position: currentElement.getAttribute("data-position") || this._options.tooltipPosition |
54 | 55 | });
|
55 | 56 | }
|
56 | 57 |
|
|
185 | 186 | function _placeTooltip(targetElement, tooltipLayer, arrowLayer) {
|
186 | 187 | var tooltipLayerPosition = _getOffset(tooltipLayer);
|
187 | 188 | //reset the old style
|
188 |
| - tooltipLayer.style.top = null; |
189 |
| - tooltipLayer.style.right = null; |
190 |
| - tooltipLayer.style.bottom = null; |
191 |
| - tooltipLayer.style.left = null; |
192 |
| - switch (targetElement.getAttribute('data-position')) { |
| 189 | + tooltipLayer.style.top = null; |
| 190 | + tooltipLayer.style.right = null; |
| 191 | + tooltipLayer.style.bottom = null; |
| 192 | + tooltipLayer.style.left = null; |
| 193 | + var currentTooltipPosition = this._introItems[this._currentStep].position; |
| 194 | + switch (currentTooltipPosition) { |
193 | 195 | case 'top':
|
194 | 196 | tooltipLayer.style.left = "15px";
|
195 | 197 | tooltipLayer.style.top = "-" + (tooltipLayerPosition.height + 10) + "px";
|
|
205 | 207 | arrowLayer.className = 'introjs-arrow right';
|
206 | 208 | break;
|
207 | 209 | case 'bottom':
|
208 |
| - default: |
209 | 210 | tooltipLayer.style.bottom = "-" + (tooltipLayerPosition.height + 10) + "px";
|
210 | 211 | arrowLayer.className = 'introjs-arrow top';
|
211 | 212 | break;
|
|
252 | 253 | //set current tooltip text
|
253 | 254 | oldtooltipLayer.innerHTML = targetElement.getAttribute("data-intro");
|
254 | 255 | //set the tooltip position
|
255 |
| - _placeTooltip(targetElement, oldtooltipContainer, oldArrowLayer); |
| 256 | + _placeTooltip.call(self, targetElement, oldtooltipContainer, oldArrowLayer); |
256 | 257 | //show the tooltip
|
257 | 258 | oldtooltipContainer.style.opacity = 1;
|
258 | 259 | }, 350);
|
|
320 | 321 | tooltipButtonsLayer.appendChild(nextTooltipButton);
|
321 | 322 |
|
322 | 323 | //set proper position
|
323 |
| - _placeTooltip(targetElement, tooltipLayer, arrowLayer); |
| 324 | + _placeTooltip.call(self, targetElement, tooltipLayer, arrowLayer); |
324 | 325 | }
|
325 | 326 |
|
326 | 327 | //add target element position style
|
|
471 | 472 | /**
|
472 | 473 | * Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
|
473 | 474 | * via: http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically
|
| 475 | + * |
474 | 476 | * @param obj1
|
475 | 477 | * @param obj2
|
476 | 478 | * @returns obj3 a new object based on obj1 and obj2
|
477 | 479 | */
|
478 |
| - function _mergeOptions(obj1,obj2){ |
| 480 | + function _mergeOptions(obj1,obj2) { |
479 | 481 | var obj3 = {};
|
480 | 482 | for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
|
481 | 483 | for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
|
|
514 | 516 | clone: function () {
|
515 | 517 | return new IntroJs(this);
|
516 | 518 | },
|
517 |
| - setoption: function(option, value){ |
| 519 | + setOption: function(option, value) { |
518 | 520 | this._options[option] = value;
|
519 | 521 | return this;
|
520 | 522 | },
|
521 |
| - setoptions: function(options){ |
| 523 | + setOptions: function(options) { |
522 | 524 | this._options = _mergeOptions(this._options, options);
|
523 | 525 | return this;
|
524 | 526 | },
|
|
0 commit comments