|
4 | 4 | * MIT licensed
|
5 | 5 | *
|
6 | 6 | * Copyright (C) 2013 usabli.ca - A weekend project by Afshin Mehrabani (@afshinmeh)
|
7 |
| - */ |
| 7 | + */ |
8 | 8 |
|
9 | 9 | (function () {
|
10 | 10 |
|
|
35 | 35 |
|
36 | 36 | //if there's no element to intro
|
37 | 37 | if(allIntroSteps.length < 1) {
|
38 |
| - return; |
| 38 | + return false; |
39 | 39 | }
|
40 | 40 |
|
41 | 41 | for (var i = 0, elmsLength = allIntroSteps.length; i < elmsLength; i++) {
|
42 | 42 | var currentElement = allIntroSteps[i];
|
43 | 43 | introItems.push({
|
44 | 44 | element: currentElement,
|
45 | 45 | intro: currentElement.getAttribute("data-intro"),
|
46 |
| - step: parseInt(currentElement.getAttribute("data-step")), |
| 46 | + step: parseInt(currentElement.getAttribute("data-step"), 10), |
47 | 47 | position: currentElement.getAttribute("data-position") || 'bottom'
|
48 | 48 | });
|
49 | 49 | }
|
|
65 | 65 | nextStepButton = targetElm.querySelector(".introjs-nextbutton");
|
66 | 66 |
|
67 | 67 | targetElm.onkeydown = function(e) {
|
68 |
| - if(e.keyCode == 27) { |
| 68 | + if (e.keyCode == 27) { |
69 | 69 | //escape key pressed, exit the intro
|
70 | 70 | _exitIntro.call(self, targetElm);
|
71 | 71 | } else if(e.keyCode == 37) {
|
|
87 | 87 | * @method _nextStep
|
88 | 88 | */
|
89 | 89 | function _nextStep() {
|
90 |
| - if(this._currentStep == undefined) { |
| 90 | + if (typeof(this._currentStep) === 'undefined') { |
91 | 91 | this._currentStep = 0;
|
92 | 92 | } else {
|
93 | 93 | ++this._currentStep;
|
94 | 94 | }
|
| 95 | + |
95 | 96 | if((this._introItems.length) <= this._currentStep) {
|
96 | 97 | //end of the intro
|
97 | 98 | //check if any callback is defined
|
|
101 | 102 | _exitIntro.call(this, this._targetElement);
|
102 | 103 | return;
|
103 | 104 | }
|
104 |
| - _showElement.call(this, this._introItems[this._currentStep].element); |
105 | 105 |
|
| 106 | + _showElement.call(this, this._introItems[this._currentStep].element); |
106 | 107 | }
|
107 | 108 |
|
108 | 109 | /**
|
|
112 | 113 | * @method _nextStep
|
113 | 114 | */
|
114 | 115 | function _previousStep() {
|
115 |
| - if(this._currentStep == 0){ |
116 |
| - return; |
| 116 | + if (this._currentStep == 0){ |
| 117 | + return false; |
117 | 118 | }
|
118 | 119 |
|
119 | 120 | _showElement.call(this, this._introItems[--this._currentStep].element);
|
|
154 | 155 | }
|
155 | 156 | }
|
156 | 157 |
|
| 158 | + /** |
| 159 | + * Render tooltip box in the page |
| 160 | + * |
| 161 | + * @api private |
| 162 | + * @method _placeTooltip |
| 163 | + * @param {Object} targetElement |
| 164 | + * @param {Object} tooltipLayer |
| 165 | + * @param {Object} arrowLayer |
| 166 | + */ |
157 | 167 | function _placeTooltip(targetElement, tooltipLayer, arrowLayer) {
|
158 | 168 | var tooltipLayerPosition = _getOffset(tooltipLayer);
|
159 | 169 | //reset the old style
|
160 | 170 | tooltipLayer.style.top = null;
|
161 | 171 | tooltipLayer.style.right = null;
|
162 | 172 | tooltipLayer.style.bottom = null;
|
163 | 173 | tooltipLayer.style.left = null;
|
164 |
| - switch(targetElement.getAttribute('data-position')){ |
| 174 | + switch (targetElement.getAttribute('data-position')) { |
165 | 175 | case 'top':
|
166 | 176 | tooltipLayer.style.left = "15px";
|
167 | 177 | tooltipLayer.style.top = "-" + (tooltipLayerPosition.height + 10) + "px";
|
|
193 | 203 | * @param {Object} targetElement
|
194 | 204 | */
|
195 | 205 | function _showElement(targetElement) {
|
196 |
| - |
| 206 | + |
197 | 207 | var self = this,
|
198 | 208 | oldHelperLayer = document.querySelector(".introjs-helperLayer"),
|
199 | 209 | elementPosition = _getOffset(targetElement);
|
|
293 | 303 |
|
294 | 304 | //set css class name
|
295 | 305 | overlayLayer.className = "introjs-overlay";
|
296 |
| - |
| 306 | + |
297 | 307 | //set overlay layer position
|
298 | 308 | var elementPosition = _getOffset(targetElm);
|
299 | 309 | if(elementPosition) {
|
|
336 | 346 | var _x = 0;
|
337 | 347 | var _y = 0;
|
338 | 348 | while(element && !isNaN(element.offsetLeft) && !isNaN(element.offsetTop)) {
|
339 |
| - _x += element.offsetLeft; |
340 |
| - _y += element.offsetTop; |
341 |
| - element = element.offsetParent; |
| 349 | + _x += element.offsetLeft; |
| 350 | + _y += element.offsetTop; |
| 351 | + element = element.offsetParent; |
342 | 352 | }
|
343 | 353 | //set top
|
344 | 354 | elementPosition.top = _y;
|
|
357 | 367 | //select the target element with query selector
|
358 | 368 | var targetElement = document.querySelector(targetElm);
|
359 | 369 |
|
360 |
| - if(targetElement) { |
| 370 | + if (targetElement) { |
361 | 371 | return new IntroJs(targetElement);
|
362 | 372 | } else {
|
363 | 373 | throw new Error("There's no element with given selector.");
|
|
378 | 388 | //Prototype
|
379 | 389 | introJs.fn = IntroJs.prototype = {
|
380 | 390 | clone: function () {
|
381 |
| - return IntroJs(this); |
| 391 | + return new IntroJs(this); |
382 | 392 | },
|
383 | 393 | start: function () {
|
384 | 394 | _introForElement.call(this, this._targetElement);
|
|
402 | 412 | }
|
403 | 413 | };
|
404 | 414 |
|
405 |
| - this['introJs'] = introJs; |
| 415 | + window['introJs'] = introJs; |
406 | 416 | })();
|
0 commit comments