|
1 | 1 | /**
|
2 |
| - * Intro.js v0.2.1 |
| 2 | + * Intro.js v0.2.2 |
3 | 3 | * https://github.com/usablica/intro.js
|
4 | 4 | * MIT licensed
|
5 | 5 | *
|
|
9 | 9 | (function () {
|
10 | 10 |
|
11 | 11 | //Default config/variables
|
12 |
| - var VERSION = "0.2.1"; |
| 12 | + var VERSION = "0.2.2"; |
13 | 13 |
|
14 | 14 | /**
|
15 | 15 | * IntroJs main class
|
|
64 | 64 | var skipButton = targetElm.querySelector(".introjs-skipbutton"),
|
65 | 65 | nextStepButton = targetElm.querySelector(".introjs-nextbutton");
|
66 | 66 |
|
67 |
| - window.onkeydown = function(e) { |
| 67 | + self._onKeyDown = function(e) { |
68 | 68 | if (e.keyCode == 27) {
|
69 | 69 | //escape key pressed, exit the intro
|
70 | 70 | _exitIntro.call(self, targetElm);
|
|
76 | 76 | _nextStep.call(self);
|
77 | 77 | }
|
78 | 78 | };
|
| 79 | + |
| 80 | + if (window.addEventListener) { |
| 81 | + window.addEventListener("keydown", self._onKeyDown, true); |
| 82 | + } else if (document.attachEvent) { //IE |
| 83 | + document.attachEvent("onkeydown", self._onKeyDown); |
| 84 | + } |
79 | 85 | }
|
80 | 86 | return false;
|
81 | 87 | }
|
|
145 | 151 | //remove `introjs-showElement` class from the element
|
146 | 152 | var showElement = document.querySelector(".introjs-showElement");
|
147 | 153 | if (showElement) {
|
148 |
| - showElement.className = showElement.className.replace(/introjs-[a-zA-Z]+/g, '').trim(); |
| 154 | + showElement.className = showElement.className.replace(/introjs-[a-zA-Z]+/g, '').replace(/^\s+|\s+$/g, ''); // This is a manual trim. |
149 | 155 | }
|
150 | 156 | //clean listeners
|
151 |
| - window.onkeydown = null; |
| 157 | + if (window.removeEventListener) { |
| 158 | + window.removeEventListener("keydown", this._onKeyDown, true); |
| 159 | + } else if (document.detachEvent) { //IE |
| 160 | + document.detachEvent("onkeydown", this._onKeyDown); |
| 161 | + } |
152 | 162 | //set the step to zero
|
153 | 163 | this._currentStep = undefined;
|
154 | 164 | //check if any callback is defined
|
|
225 | 235 | "left: " + (elementPosition.left - 5) + "px;");
|
226 | 236 | //remove old classes
|
227 | 237 | var oldShowElement = document.querySelector(".introjs-showElement");
|
228 |
| - oldShowElement.className = oldShowElement.className.replace(/introjs-[a-zA-Z]+/g, '').trim(); |
| 238 | + oldShowElement.className = oldShowElement.className.replace(/introjs-[a-zA-Z]+/g, '').replace(/^\s+|\s+$/g, ''); |
229 | 239 | //we should wait until the CSS3 transition is competed (it's 0.3 sec) to prevent incorrect `height` and `width` calculation
|
230 |
| - setTimeout(function() { |
| 240 | + if (self._lastShowElementTimer) { |
| 241 | + clearTimeout(self._lastShowElementTimer); |
| 242 | + } |
| 243 | + self._lastShowElementTimer = setTimeout(function() { |
231 | 244 | //set current step to the label
|
232 | 245 | oldHelperNumberLayer.innerHTML = targetElement.getAttribute("data-step");
|
233 | 246 | //set current tooltip text
|
|
323 | 336 | }
|
324 | 337 |
|
325 | 338 | if (!_elementInViewport(targetElement)) {
|
326 |
| - var rect = targetElement.getBoundingClientRect() |
327 |
| - top = rect.bottom - rect.height, |
328 |
| - bottom = rect.bottom - window.innerHeight; |
| 339 | + var rect = targetElement.getBoundingClientRect(), |
| 340 | + top = rect.bottom - (rect.bottom - rect.top), |
| 341 | + bottom = rect.bottom - _getWinSize().height; |
329 | 342 |
|
330 | 343 | // Scroll up
|
331 | 344 | if (top < 0) {
|
|
338 | 351 | }
|
339 | 352 | }
|
340 | 353 |
|
| 354 | + /** |
| 355 | + * Provides a cross-browser way to get the screen dimensions |
| 356 | + * via: http://stackoverflow.com/questions/5864467/internet-explorer-innerheight |
| 357 | + * |
| 358 | + * @api private |
| 359 | + * @method _getWinSize |
| 360 | + * @returns {Object} width and height attributes |
| 361 | + */ |
| 362 | + function _getWinSize() { |
| 363 | + if (window.innerWidth != undefined) { |
| 364 | + return { width: window.innerWidth, height: window.innerHeight }; |
| 365 | + } else { |
| 366 | + var D = document.documentElement; |
| 367 | + return { width: D.clientWidth, height: D.clientHeight }; |
| 368 | + } |
| 369 | + } |
| 370 | + |
341 | 371 | /**
|
342 | 372 | * Add overlay layer to the page
|
343 | 373 | * http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
|
|
0 commit comments