|
5 | 5 | * Copyright (C) 2017 Afshin Mehrabani (@afshinmeh)
|
6 | 6 | */
|
7 | 7 |
|
8 |
| -(function (root, factory) { |
9 |
| - if (typeof exports === 'object') { |
10 |
| - // CommonJS |
11 |
| - factory(exports); |
12 |
| - } else if (typeof define === 'function' && define.amd) { |
13 |
| - // AMD. Register as an anonymous module. |
14 |
| - define(['exports'], factory); |
15 |
| - } else { |
16 |
| - // Browser globals |
17 |
| - factory(root); |
18 |
| - } |
19 |
| -} (this, function (exports) { |
| 8 | +(function(f) { |
| 9 | + if (typeof exports === "object" && typeof module !== "undefined") { |
| 10 | + module.exports = f(); |
| 11 | + // deprecated function |
| 12 | + // @since 2.8.0 |
| 13 | + module.exports.introJs = function () { |
| 14 | + console.warn('Deprecated: please use require("intro.js") directly, instead of the introJs method of the function'); |
| 15 | + // introJs() |
| 16 | + return f().apply(this, arguments); |
| 17 | + }; |
| 18 | + } else if (typeof define === "function" && define.amd) { |
| 19 | + define([], f); |
| 20 | + } else { |
| 21 | + var g; |
| 22 | + if (typeof window !== "undefined") { |
| 23 | + g = window; |
| 24 | + } else if (typeof global !== "undefined") { |
| 25 | + g = global; |
| 26 | + } else if (typeof self !== "undefined") { |
| 27 | + g = self; |
| 28 | + } else { |
| 29 | + g = this; |
| 30 | + } |
| 31 | + g.introJs = f(); |
| 32 | + } |
| 33 | +})(function () { |
20 | 34 | //Default config/variables
|
21 | 35 | var VERSION = '2.8.0-alpha.1';
|
22 | 36 |
|
|
276 | 290 | } else if (code === 'Enter' || code === 13) {
|
277 | 291 | //srcElement === ie
|
278 | 292 | var target = e.target || e.srcElement;
|
279 |
| - if (target && target.className.indexOf('introjs-prevbutton') > 0) { |
| 293 | + if (target && target.className.match('introjs-prevbutton')) { |
280 | 294 | //user hit enter while focusing on previous button
|
281 | 295 | _previousStep.call(self);
|
282 |
| - } else if (target && target.className.indexOf('introjs-skipbutton') > 0) { |
| 296 | + } else if (target && target.className.match('introjs-skipbutton')) { |
283 | 297 | //user hit enter while focusing on skip button
|
284 | 298 | if (self._introItems.length - 1 == self._currentStep && typeof (self._introCompleteCallback) === 'function') {
|
285 | 299 | self._introCompleteCallback.call(self);
|
|
537 | 551 | var fixParents = document.querySelectorAll('.introjs-fixParent');
|
538 | 552 | if (fixParents && fixParents.length > 0) {
|
539 | 553 | for (var i = fixParents.length - 1; i >= 0; i--) {
|
540 |
| - fixParents[i].className = fixParents[i].className.replace(/introjs-fixParent/g, '').replace(/^\s+|\s+$/g, ''); |
| 554 | + _removeClass(fixParents[i], /introjs-fixParent/g); |
541 | 555 | }
|
542 | 556 | }
|
543 | 557 |
|
|
842 | 856 | // Otherwise, remove a fixed class that may be left over from the previous
|
843 | 857 | // step.
|
844 | 858 | if (_isFixed(currentElement.element)) {
|
845 |
| - helperLayer.className += ' introjs-fixedTooltip'; |
| 859 | + _addClass(helperLayer, 'introjs-fixedTooltip'); |
846 | 860 | } else {
|
847 |
| - helperLayer.className = helperLayer.className.replace(' introjs-fixedTooltip', ''); |
| 861 | + _removeClass(helperLayer, 'introjs-fixedTooltip'); |
848 | 862 | }
|
849 | 863 |
|
850 | 864 | if (currentElement.position == 'floating') {
|
|
947 | 961 | var fixParents = document.querySelectorAll('.introjs-fixParent');
|
948 | 962 | if (fixParents && fixParents.length > 0) {
|
949 | 963 | for (var i = fixParents.length - 1; i >= 0; i--) {
|
950 |
| - fixParents[i].className = fixParents[i].className.replace(/introjs-fixParent/g, '').replace(/^\s+|\s+$/g, ''); |
| 964 | + _removeClass(fixParents[i], /introjs-fixParent/g); |
951 | 965 | };
|
952 | 966 | }
|
953 | 967 |
|
|
1178 | 1192 | prevTooltipButton.className = 'introjs-button introjs-prevbutton introjs-hidden';
|
1179 | 1193 | }
|
1180 | 1194 | if (typeof nextTooltipButton !== "undefined" && nextTooltipButton != null) {
|
1181 |
| - nextTooltipButton.className += ' introjs-fullbutton'; |
| 1195 | + _addClass(nextTooltipButton, 'introjs-fullbutton'); |
1182 | 1196 | }
|
1183 | 1197 | } else {
|
1184 | 1198 | if (typeof prevTooltipButton !== "undefined" && prevTooltipButton != null) {
|
|
1197 | 1211 | if (typeof skipTooltipButton !== "undefined" && skipTooltipButton != null) {
|
1198 | 1212 | skipTooltipButton.innerHTML = this._options.doneLabel;
|
1199 | 1213 | // adding donebutton class in addition to skipbutton
|
1200 |
| - skipTooltipButton.className += ' introjs-donebutton'; |
| 1214 | + _addClass(skipTooltipButton, 'introjs-donebutton'); |
1201 | 1215 | }
|
1202 | 1216 | if (typeof prevTooltipButton !== "undefined" && prevTooltipButton != null) {
|
1203 | 1217 | prevTooltipButton.className = 'introjs-button introjs-prevbutton';
|
|
1208 | 1222 | nextTooltipButton.className = 'introjs-button introjs-nextbutton introjs-hidden';
|
1209 | 1223 | }
|
1210 | 1224 | if (typeof prevTooltipButton !== "undefined" && prevTooltipButton != null) {
|
1211 |
| - prevTooltipButton.className += ' introjs-fullbutton'; |
| 1225 | + _addClass(prevTooltipButton, 'introjs-fullbutton'); |
1212 | 1226 | }
|
1213 | 1227 | } else {
|
1214 | 1228 | if (typeof nextTooltipButton !== "undefined" && nextTooltipButton != null) {
|
|
1321 | 1335 | if (!parentElm.tagName || parentElm.tagName.toLowerCase() === 'body') break;
|
1322 | 1336 |
|
1323 | 1337 | if (parentElm.tagName.toLowerCase() === 'svg') {
|
1324 |
| - _setClass(parentElm, 'introjs-showElement introjs-relativePosition'); |
| 1338 | + _addClass(parentElm, 'introjs-showElement introjs-relativePosition'); |
1325 | 1339 | }
|
1326 | 1340 |
|
1327 | 1341 | parentElm = parentElm.parentNode;
|
1328 | 1342 | }
|
1329 | 1343 | }
|
1330 | 1344 |
|
1331 |
| - _setClass(targetElement.element, 'introjs-showElement'); |
| 1345 | + _addClass(targetElement.element, 'introjs-showElement'); |
1332 | 1346 |
|
1333 | 1347 | var currentElementPosition = _getPropValue(targetElement.element, 'position');
|
1334 | 1348 | if (currentElementPosition !== 'absolute' &&
|
1335 | 1349 | currentElementPosition !== 'relative' &&
|
1336 | 1350 | currentElementPosition !== 'fixed') {
|
1337 | 1351 | //change to new intro item
|
1338 |
| - //targetElement.element.className += ' introjs-relativePosition'; |
1339 |
| - _setClass(targetElement.element, 'introjs-relativePosition') |
| 1352 | + _addClass(targetElement.element, 'introjs-relativePosition') |
1340 | 1353 | }
|
1341 | 1354 |
|
1342 | 1355 | var parentElm = targetElement.element.parentNode;
|
|
1349 | 1362 | var opacity = parseFloat(_getPropValue(parentElm, 'opacity'));
|
1350 | 1363 | var transform = _getPropValue(parentElm, 'transform') || _getPropValue(parentElm, '-webkit-transform') || _getPropValue(parentElm, '-moz-transform') || _getPropValue(parentElm, '-ms-transform') || _getPropValue(parentElm, '-o-transform');
|
1351 | 1364 | if (/[0-9]+/.test(zIndex) || opacity < 1 || (transform !== 'none' && transform !== undefined)) {
|
1352 |
| - parentElm.className += ' introjs-fixParent'; |
| 1365 | + _addClass(parentElm, 'introjs-fixParent'); |
1353 | 1366 | }
|
1354 | 1367 |
|
1355 | 1368 | parentElm = parentElm.parentNode;
|
1356 | 1369 | }
|
1357 | 1370 | }
|
1358 | 1371 |
|
1359 |
| - function _setClass(element, className) { |
| 1372 | + /** |
| 1373 | + * Append a class to an element |
| 1374 | + * |
| 1375 | + * @api private |
| 1376 | + * @method _addClass |
| 1377 | + * @param {Object} element |
| 1378 | + * @param {String} className |
| 1379 | + * @returns null |
| 1380 | + */ |
| 1381 | + function _addClass(element, className) { |
1360 | 1382 | if (element instanceof SVGElement) {
|
| 1383 | + // svg |
1361 | 1384 | var pre = element.getAttribute('class') || '';
|
1362 | 1385 |
|
1363 | 1386 | element.setAttribute('class', pre + ' ' + className);
|
1364 | 1387 | } else {
|
1365 |
| - element.className += ' ' + className; |
| 1388 | + if (element.classList !== undefined) { |
| 1389 | + // check for modern classList property |
| 1390 | + var classes = className.split(' '); |
| 1391 | + for (var i = 0, len = classes.length; i < len; i++) { |
| 1392 | + element.classList.add( classes[i] ); |
| 1393 | + } |
| 1394 | + } else if (!element.className.match( className )) { |
| 1395 | + // check if element doesn't already have className |
| 1396 | + element.className += ' ' + className; |
| 1397 | + } |
1366 | 1398 | }
|
1367 | 1399 | }
|
1368 | 1400 |
|
| 1401 | + /** |
| 1402 | + * Remove a class from an element |
| 1403 | + * |
| 1404 | + * @api private |
| 1405 | + * @method _removeClass |
| 1406 | + * @param {Object} element |
| 1407 | + * @param {RegExp|String} classNameRegex can be regex or string |
| 1408 | + * @returns null |
| 1409 | + */ |
1369 | 1410 | function _removeClass(element, classNameRegex) {
|
1370 | 1411 | if (element instanceof SVGElement) {
|
1371 | 1412 | var pre = element.getAttribute('class') || '';
|
|
1618 | 1659 | var hint = this._targetElement.querySelector('.introjs-hint[data-step="' + stepId + '"]');
|
1619 | 1660 |
|
1620 | 1661 | if (hint) {
|
1621 |
| - hint.className += ' introjs-hidehint'; |
| 1662 | + _addClass(hint, 'introjs-hidehint'); |
1622 | 1663 | }
|
1623 | 1664 |
|
1624 | 1665 | // call the callback function (if any)
|
|
1671 | 1712 | var hint = this._targetElement.querySelector('.introjs-hint[data-step="' + stepId + '"]');
|
1672 | 1713 |
|
1673 | 1714 | if (hint) {
|
1674 |
| - hint.className = hint.className.replace(/introjs\-hidehint/g, ''); |
| 1715 | + _removeClass(hint, /introjs-hidehint/g); |
1675 | 1716 | }
|
1676 | 1717 | };
|
1677 | 1718 |
|
|
1750 | 1791 | hint.className = 'introjs-hint';
|
1751 | 1792 |
|
1752 | 1793 | if (!item.hintAnimation) {
|
1753 |
| - hint.className += ' introjs-hint-no-anim'; |
| 1794 | + _addClass(hint, 'introjs-hint-no-anim'); |
1754 | 1795 | }
|
1755 | 1796 |
|
1756 | 1797 | // hint's position should be fixed if the target element's position is fixed
|
1757 | 1798 | if (_isFixed(item.element)) {
|
1758 |
| - hint.className += ' introjs-fixedhint'; |
| 1799 | + _addClass(hint, 'introjs-fixedhint'); |
1759 | 1800 | }
|
1760 | 1801 |
|
1761 | 1802 | var hintDot = document.createElement('div');
|
|
2189 | 2230 | }
|
2190 | 2231 | };
|
2191 | 2232 |
|
2192 |
| - exports.introJs = introJs; |
2193 | 2233 | return introJs;
|
2194 |
| -})); |
| 2234 | +}); |
0 commit comments