Skip to content

Commit cde7673

Browse files
committed
Fix coding style + add tooltipPosition option
1 parent 9e62afc commit cde7673

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

intro.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
*/
1919
function IntroJs(obj) {
2020
this._targetElement = obj;
21-
21+
2222
this._options = {
2323
nextLabel: 'Next →',
2424
prevLabel: '← Back',
25-
skipLabel: 'Skip'
25+
skipLabel: 'Skip',
26+
tooltipPosition: 'bottom'
2627
}
2728
}
2829

@@ -50,7 +51,7 @@
5051
element: currentElement,
5152
intro: currentElement.getAttribute("data-intro"),
5253
step: parseInt(currentElement.getAttribute("data-step"), 10),
53-
position: currentElement.getAttribute("data-position") || 'bottom'
54+
position: currentElement.getAttribute("data-position") || this._options.tooltipPosition
5455
});
5556
}
5657

@@ -185,11 +186,12 @@
185186
function _placeTooltip(targetElement, tooltipLayer, arrowLayer) {
186187
var tooltipLayerPosition = _getOffset(tooltipLayer);
187188
//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) {
193195
case 'top':
194196
tooltipLayer.style.left = "15px";
195197
tooltipLayer.style.top = "-" + (tooltipLayerPosition.height + 10) + "px";
@@ -205,7 +207,6 @@
205207
arrowLayer.className = 'introjs-arrow right';
206208
break;
207209
case 'bottom':
208-
default:
209210
tooltipLayer.style.bottom = "-" + (tooltipLayerPosition.height + 10) + "px";
210211
arrowLayer.className = 'introjs-arrow top';
211212
break;
@@ -252,7 +253,7 @@
252253
//set current tooltip text
253254
oldtooltipLayer.innerHTML = targetElement.getAttribute("data-intro");
254255
//set the tooltip position
255-
_placeTooltip(targetElement, oldtooltipContainer, oldArrowLayer);
256+
_placeTooltip.call(self, targetElement, oldtooltipContainer, oldArrowLayer);
256257
//show the tooltip
257258
oldtooltipContainer.style.opacity = 1;
258259
}, 350);
@@ -320,7 +321,7 @@
320321
tooltipButtonsLayer.appendChild(nextTooltipButton);
321322

322323
//set proper position
323-
_placeTooltip(targetElement, tooltipLayer, arrowLayer);
324+
_placeTooltip.call(self, targetElement, tooltipLayer, arrowLayer);
324325
}
325326

326327
//add target element position style
@@ -471,11 +472,12 @@
471472
/**
472473
* Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
473474
* via: http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically
475+
*
474476
* @param obj1
475477
* @param obj2
476478
* @returns obj3 a new object based on obj1 and obj2
477479
*/
478-
function _mergeOptions(obj1,obj2){
480+
function _mergeOptions(obj1,obj2) {
479481
var obj3 = {};
480482
for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
481483
for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
@@ -514,11 +516,11 @@
514516
clone: function () {
515517
return new IntroJs(this);
516518
},
517-
setoption: function(option, value){
519+
setOption: function(option, value) {
518520
this._options[option] = value;
519521
return this;
520522
},
521-
setoptions: function(options){
523+
setOptions: function(options) {
522524
this._options = _mergeOptions(this._options, options);
523525
return this;
524526
},

0 commit comments

Comments
 (0)