Dashboard sipadu mbip
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

intro.js 70KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154
  1. /**
  2. * Intro.js v2.8.0-alpha.1
  3. * https://github.com/usablica/intro.js
  4. *
  5. * Copyright (C) 2017 Afshin Mehrabani (@afshinmeh)
  6. */
  7. (function (root, factory) {
  8. if (typeof exports === 'object') {
  9. // CommonJS
  10. factory(exports);
  11. } else if (typeof define === 'function' && define.amd) {
  12. // AMD. Register as an anonymous module.
  13. define(['exports'], factory);
  14. } else {
  15. // Browser globals
  16. factory(root);
  17. }
  18. } (this, function (exports) {
  19. //Default config/variables
  20. var VERSION = '2.8.0-alpha.1';
  21. /**
  22. * IntroJs main class
  23. *
  24. * @class IntroJs
  25. */
  26. function IntroJs(obj) {
  27. this._targetElement = obj;
  28. this._introItems = [];
  29. this._options = {
  30. /* Next button label in tooltip box */
  31. nextLabel: 'Next →',
  32. /* Previous button label in tooltip box */
  33. prevLabel: '← Back',
  34. /* Skip button label in tooltip box */
  35. skipLabel: 'Skip',
  36. /* Done button label in tooltip box */
  37. doneLabel: 'Done',
  38. /* Hide previous button in the first step? Otherwise, it will be disabled button. */
  39. hidePrev: false,
  40. /* Hide next button in the last step? Otherwise, it will be disabled button. */
  41. hideNext: false,
  42. /* Default tooltip box position */
  43. tooltipPosition: 'bottom',
  44. /* Next CSS class for tooltip boxes */
  45. tooltipClass: '',
  46. /* CSS class that is added to the helperLayer */
  47. highlightClass: '',
  48. /* Close introduction when pressing Escape button? */
  49. exitOnEsc: true,
  50. /* Close introduction when clicking on overlay layer? */
  51. exitOnOverlayClick: true,
  52. /* Show step numbers in introduction? */
  53. showStepNumbers: true,
  54. /* Let user use keyboard to navigate the tour? */
  55. keyboardNavigation: true,
  56. /* Show tour control buttons? */
  57. showButtons: true,
  58. /* Show tour bullets? */
  59. showBullets: true,
  60. /* Show tour progress? */
  61. showProgress: false,
  62. /* Scroll to highlighted element? */
  63. scrollToElement: true,
  64. /*
  65. * Should we scroll the tooltip or target element?
  66. *
  67. * Options are: 'element' or 'tooltip'
  68. */
  69. scrollTo: 'element',
  70. /* Padding to add after scrolling when element is not in the viewport (in pixels) */
  71. scrollPadding: 30,
  72. /* Set the overlay opacity */
  73. overlayOpacity: 0.8,
  74. /* Precedence of positions, when auto is enabled */
  75. positionPrecedence: ["bottom", "top", "right", "left"],
  76. /* Disable an interaction with element? */
  77. disableInteraction: false,
  78. /* Default hint position */
  79. hintPosition: 'top-middle',
  80. /* Hint button label */
  81. hintButtonLabel: 'Got it',
  82. /* Adding animation to hints? */
  83. hintAnimation: true
  84. };
  85. }
  86. /**
  87. * Initiate a new introduction/guide from an element in the page
  88. *
  89. * @api private
  90. * @method _introForElement
  91. * @param {Object} targetElm
  92. * @returns {Boolean} Success or not?
  93. */
  94. function _introForElement(targetElm) {
  95. var introItems = [],
  96. self = this;
  97. if (this._options.steps) {
  98. //use steps passed programmatically
  99. for (var i = 0, stepsLength = this._options.steps.length; i < stepsLength; i++) {
  100. var currentItem = _cloneObject(this._options.steps[i]);
  101. //set the step
  102. currentItem.step = introItems.length + 1;
  103. //use querySelector function only when developer used CSS selector
  104. if (typeof (currentItem.element) === 'string') {
  105. //grab the element with given selector from the page
  106. currentItem.element = document.querySelector(currentItem.element);
  107. }
  108. //intro without element
  109. if (typeof (currentItem.element) === 'undefined' || currentItem.element == null) {
  110. var floatingElementQuery = document.querySelector(".introjsFloatingElement");
  111. if (floatingElementQuery == null) {
  112. floatingElementQuery = document.createElement('div');
  113. floatingElementQuery.className = 'introjsFloatingElement';
  114. document.body.appendChild(floatingElementQuery);
  115. }
  116. currentItem.element = floatingElementQuery;
  117. currentItem.position = 'floating';
  118. }
  119. currentItem.scrollTo = currentItem.scrollTo || this._options.scrollTo;
  120. if (typeof (currentItem.disableInteraction) === 'undefined') {
  121. currentItem.disableInteraction = this._options.disableInteraction;
  122. }
  123. if (currentItem.element != null) {
  124. introItems.push(currentItem);
  125. }
  126. }
  127. } else {
  128. //use steps from data-* annotations
  129. var allIntroSteps = targetElm.querySelectorAll('*[data-intro]');
  130. //if there's no element to intro
  131. if (allIntroSteps.length < 1) {
  132. return false;
  133. }
  134. //first add intro items with data-step
  135. for (var i = 0, elmsLength = allIntroSteps.length; i < elmsLength; i++) {
  136. var currentElement = allIntroSteps[i];
  137. // skip hidden elements
  138. if (currentElement.style.display == 'none') {
  139. continue;
  140. }
  141. var step = parseInt(currentElement.getAttribute('data-step'), 10);
  142. var disableInteraction = this._options.disableInteraction;
  143. if (typeof (currentElement.getAttribute('data-disable-interaction')) != 'undefined') {
  144. disableInteraction = !!currentElement.getAttribute('data-disable-interaction');
  145. }
  146. if (step > 0) {
  147. introItems[step - 1] = {
  148. element: currentElement,
  149. intro: currentElement.getAttribute('data-intro'),
  150. step: parseInt(currentElement.getAttribute('data-step'), 10),
  151. tooltipClass: currentElement.getAttribute('data-tooltipClass'),
  152. highlightClass: currentElement.getAttribute('data-highlightClass'),
  153. position: currentElement.getAttribute('data-position') || this._options.tooltipPosition,
  154. scrollTo: currentElement.getAttribute('data-scrollTo') || this._options.scrollTo,
  155. disableInteraction: disableInteraction
  156. };
  157. }
  158. }
  159. //next add intro items without data-step
  160. //todo: we need a cleanup here, two loops are redundant
  161. var nextStep = 0;
  162. for (var i = 0, elmsLength = allIntroSteps.length; i < elmsLength; i++) {
  163. var currentElement = allIntroSteps[i];
  164. if (currentElement.getAttribute('data-step') == null) {
  165. while (true) {
  166. if (typeof introItems[nextStep] == 'undefined') {
  167. break;
  168. } else {
  169. nextStep++;
  170. }
  171. }
  172. var disableInteraction = this._options.disableInteraction;
  173. if (typeof (currentElement.getAttribute('data-disable-interaction')) != 'undefined') {
  174. disableInteraction = !!currentElement.getAttribute('data-disable-interaction');
  175. }
  176. introItems[nextStep] = {
  177. element: currentElement,
  178. intro: currentElement.getAttribute('data-intro'),
  179. step: nextStep + 1,
  180. tooltipClass: currentElement.getAttribute('data-tooltipClass'),
  181. highlightClass: currentElement.getAttribute('data-highlightClass'),
  182. position: currentElement.getAttribute('data-position') || this._options.tooltipPosition,
  183. scrollTo: currentElement.getAttribute('data-scrollTo') || this._options.scrollTo,
  184. disableInteraction: disableInteraction
  185. };
  186. }
  187. }
  188. }
  189. //removing undefined/null elements
  190. var tempIntroItems = [];
  191. for (var z = 0; z < introItems.length; z++) {
  192. introItems[z] && tempIntroItems.push(introItems[z]); // copy non-empty values to the end of the array
  193. }
  194. introItems = tempIntroItems;
  195. //Ok, sort all items with given steps
  196. introItems.sort(function (a, b) {
  197. return a.step - b.step;
  198. });
  199. //set it to the introJs object
  200. self._introItems = introItems;
  201. //add overlay layer to the page
  202. if(_addOverlayLayer.call(self, targetElm)) {
  203. //then, start the show
  204. _nextStep.call(self);
  205. var skipButton = targetElm.querySelector('.introjs-skipbutton'),
  206. nextStepButton = targetElm.querySelector('.introjs-nextbutton');
  207. self._onKeyDown = function(e) {
  208. if (e.keyCode === 27 && self._options.exitOnEsc == true) {
  209. //escape key pressed, exit the intro
  210. //check if exit callback is defined
  211. _exitIntro.call(self, targetElm);
  212. } else if(e.keyCode === 37) {
  213. //left arrow
  214. _previousStep.call(self);
  215. } else if (e.keyCode === 39) {
  216. //right arrow
  217. _nextStep.call(self);
  218. } else if (e.keyCode === 13) {
  219. //srcElement === ie
  220. var target = e.target || e.srcElement;
  221. if (target && target.className.indexOf('introjs-prevbutton') > 0) {
  222. //user hit enter while focusing on previous button
  223. _previousStep.call(self);
  224. } else if (target && target.className.indexOf('introjs-skipbutton') > 0) {
  225. //user hit enter while focusing on skip button
  226. if (self._introItems.length - 1 == self._currentStep && typeof (self._introCompleteCallback) === 'function') {
  227. self._introCompleteCallback.call(self);
  228. }
  229. _exitIntro.call(self, targetElm);
  230. } else {
  231. //default behavior for responding to enter
  232. _nextStep.call(self);
  233. }
  234. //prevent default behaviour on hitting Enter, to prevent steps being skipped in some browsers
  235. if(e.preventDefault) {
  236. e.preventDefault();
  237. } else {
  238. e.returnValue = false;
  239. }
  240. }
  241. };
  242. self._onResize = function(e) {
  243. self.refresh.call(self);
  244. };
  245. if (window.addEventListener) {
  246. if (this._options.keyboardNavigation) {
  247. window.addEventListener('keydown', self._onKeyDown, true);
  248. }
  249. //for window resize
  250. window.addEventListener('resize', self._onResize, true);
  251. } else if (document.attachEvent) { //IE
  252. if (this._options.keyboardNavigation) {
  253. document.attachEvent('onkeydown', self._onKeyDown);
  254. }
  255. //for window resize
  256. document.attachEvent('onresize', self._onResize);
  257. }
  258. }
  259. return false;
  260. }
  261. /*
  262. * makes a copy of the object
  263. * @api private
  264. * @method _cloneObject
  265. */
  266. function _cloneObject(object) {
  267. if (object == null || typeof (object) != 'object' || typeof (object.nodeType) != 'undefined') {
  268. return object;
  269. }
  270. var temp = {};
  271. for (var key in object) {
  272. if (typeof (jQuery) != 'undefined' && object[key] instanceof jQuery) {
  273. temp[key] = object[key];
  274. } else {
  275. temp[key] = _cloneObject(object[key]);
  276. }
  277. }
  278. return temp;
  279. }
  280. /**
  281. * Go to specific step of introduction
  282. *
  283. * @api private
  284. * @method _goToStep
  285. */
  286. function _goToStep(step) {
  287. //because steps starts with zero
  288. this._currentStep = step - 2;
  289. if (typeof (this._introItems) !== 'undefined') {
  290. _nextStep.call(this);
  291. }
  292. }
  293. /**
  294. * Go to the specific step of introduction with the explicit [data-step] number
  295. *
  296. * @api private
  297. * @method _goToStepNumber
  298. */
  299. function _goToStepNumber(step) {
  300. this._currentStepNumber = step;
  301. if (typeof (this._introItems) !== 'undefined') {
  302. _nextStep.call(this);
  303. }
  304. }
  305. /**
  306. * Go to next step on intro
  307. *
  308. * @api private
  309. * @method _nextStep
  310. */
  311. function _nextStep() {
  312. this._direction = 'forward';
  313. if (typeof (this._currentStepNumber) !== 'undefined') {
  314. for( var i = 0, len = this._introItems.length; i < len; i++ ) {
  315. var item = this._introItems[i];
  316. if( item.step === this._currentStepNumber ) {
  317. this._currentStep = i - 1;
  318. this._currentStepNumber = undefined;
  319. }
  320. }
  321. }
  322. if (typeof (this._currentStep) === 'undefined') {
  323. this._currentStep = 0;
  324. } else {
  325. ++this._currentStep;
  326. }
  327. if (typeof (this._introBeforeChangeCallback) !== 'undefined') {
  328. var continueStep = this._introBeforeChangeCallback.call(this);
  329. }
  330. // if `onbeforechange` returned `false`, stop displaying the element
  331. if (continueStep === false) {
  332. --this._currentStep;
  333. return false;
  334. }
  335. if ((this._introItems.length) <= this._currentStep) {
  336. //end of the intro
  337. //check if any callback is defined
  338. if (typeof (this._introCompleteCallback) === 'function') {
  339. this._introCompleteCallback.call(this);
  340. }
  341. _exitIntro.call(this, this._targetElement);
  342. return;
  343. }
  344. var nextStep = this._introItems[this._currentStep];
  345. _showElement.call(this, nextStep);
  346. }
  347. /**
  348. * Go to previous step on intro
  349. *
  350. * @api private
  351. * @method _previousStep
  352. */
  353. function _previousStep() {
  354. this._direction = 'backward';
  355. if (this._currentStep === 0) {
  356. return false;
  357. }
  358. --this._currentStep;
  359. if (typeof (this._introBeforeChangeCallback) !== 'undefined') {
  360. var continueStep = this._introBeforeChangeCallback.call(this);
  361. }
  362. // if `onbeforechange` returned `false`, stop displaying the element
  363. if (continueStep === false) {
  364. ++this._currentStep;
  365. return false;
  366. }
  367. var nextStep = this._introItems[this._currentStep];
  368. _showElement.call(this, nextStep);
  369. }
  370. /**
  371. * Update placement of the intro objects on the screen
  372. * @api private
  373. */
  374. function _refresh() {
  375. // re-align intros
  376. _setHelperLayerPosition.call(this, document.querySelector('.introjs-helperLayer'));
  377. _setHelperLayerPosition.call(this, document.querySelector('.introjs-tooltipReferenceLayer'));
  378. _setHelperLayerPosition.call(this, document.querySelector('.introjs-disableInteraction'));
  379. // re-align tooltip
  380. if(this._currentStep !== undefined && this._currentStep !== null) {
  381. var oldHelperNumberLayer = document.querySelector('.introjs-helperNumberLayer'),
  382. oldArrowLayer = document.querySelector('.introjs-arrow'),
  383. oldtooltipContainer = document.querySelector('.introjs-tooltip');
  384. _placeTooltip.call(this, this._introItems[this._currentStep].element, oldtooltipContainer, oldArrowLayer, oldHelperNumberLayer);
  385. }
  386. //re-align hints
  387. _reAlignHints.call(this);
  388. return this;
  389. }
  390. /**
  391. * Exit from intro
  392. *
  393. * @api private
  394. * @method _exitIntro
  395. * @param {Object} targetElement
  396. * @param {Boolean} force - Setting to `true` will skip the result of beforeExit callback
  397. */
  398. function _exitIntro(targetElement, force) {
  399. var continueExit = true;
  400. // calling onbeforeexit callback
  401. //
  402. // If this callback return `false`, it would halt the process
  403. if (this._introBeforeExitCallback != undefined) {
  404. continueExit = this._introBeforeExitCallback.call(self);
  405. }
  406. // skip this check if `force` parameter is `true`
  407. // otherwise, if `onbeforeexit` returned `false`, don't exit the intro
  408. if (!force && continueExit === false) return;
  409. //remove overlay layers from the page
  410. var overlayLayers = targetElement.querySelectorAll('.introjs-overlay');
  411. if (overlayLayers && overlayLayers.length > 0) {
  412. for (var i = overlayLayers.length - 1; i >= 0; i--) {
  413. //for fade-out animation
  414. var overlayLayer = overlayLayers[i];
  415. overlayLayer.style.opacity = 0;
  416. setTimeout(function () {
  417. if (this.parentNode) {
  418. this.parentNode.removeChild(this);
  419. }
  420. }.bind(overlayLayer), 500);
  421. };
  422. }
  423. //remove all helper layers
  424. var helperLayer = targetElement.querySelector('.introjs-helperLayer');
  425. if (helperLayer) {
  426. helperLayer.parentNode.removeChild(helperLayer);
  427. }
  428. var referenceLayer = targetElement.querySelector('.introjs-tooltipReferenceLayer');
  429. if (referenceLayer) {
  430. referenceLayer.parentNode.removeChild(referenceLayer);
  431. }
  432. //remove disableInteractionLayer
  433. var disableInteractionLayer = targetElement.querySelector('.introjs-disableInteraction');
  434. if (disableInteractionLayer) {
  435. disableInteractionLayer.parentNode.removeChild(disableInteractionLayer);
  436. }
  437. //remove intro floating element
  438. var floatingElement = document.querySelector('.introjsFloatingElement');
  439. if (floatingElement) {
  440. floatingElement.parentNode.removeChild(floatingElement);
  441. }
  442. _removeShowElement();
  443. //remove `introjs-fixParent` class from the elements
  444. var fixParents = document.querySelectorAll('.introjs-fixParent');
  445. if (fixParents && fixParents.length > 0) {
  446. for (var i = fixParents.length - 1; i >= 0; i--) {
  447. fixParents[i].className = fixParents[i].className.replace(/introjs-fixParent/g, '').replace(/^\s+|\s+$/g, '');
  448. }
  449. }
  450. //clean listeners
  451. if (window.removeEventListener) {
  452. window.removeEventListener('keydown', this._onKeyDown, true);
  453. } else if (document.detachEvent) { //IE
  454. document.detachEvent('onkeydown', this._onKeyDown);
  455. }
  456. //check if any callback is defined
  457. if (this._introExitCallback != undefined) {
  458. this._introExitCallback.call(self);
  459. }
  460. //set the step to zero
  461. this._currentStep = undefined;
  462. }
  463. /**
  464. * Render tooltip box in the page
  465. *
  466. * @api private
  467. * @method _placeTooltip
  468. * @param {HTMLElement} targetElement
  469. * @param {HTMLElement} tooltipLayer
  470. * @param {HTMLElement} arrowLayer
  471. * @param {HTMLElement} helperNumberLayer
  472. * @param {Boolean} hintMode
  473. */
  474. function _placeTooltip(targetElement, tooltipLayer, arrowLayer, helperNumberLayer, hintMode) {
  475. var tooltipCssClass = '',
  476. currentStepObj,
  477. tooltipOffset,
  478. targetOffset,
  479. windowSize,
  480. currentTooltipPosition;
  481. hintMode = hintMode || false;
  482. //reset the old style
  483. tooltipLayer.style.top = null;
  484. tooltipLayer.style.right = null;
  485. tooltipLayer.style.bottom = null;
  486. tooltipLayer.style.left = null;
  487. tooltipLayer.style.marginLeft = null;
  488. tooltipLayer.style.marginTop = null;
  489. arrowLayer.style.display = 'inherit';
  490. if (typeof(helperNumberLayer) != 'undefined' && helperNumberLayer != null) {
  491. helperNumberLayer.style.top = null;
  492. helperNumberLayer.style.left = null;
  493. }
  494. //prevent error when `this._currentStep` is undefined
  495. if (!this._introItems[this._currentStep]) return;
  496. //if we have a custom css class for each step
  497. currentStepObj = this._introItems[this._currentStep];
  498. if (typeof (currentStepObj.tooltipClass) === 'string') {
  499. tooltipCssClass = currentStepObj.tooltipClass;
  500. } else {
  501. tooltipCssClass = this._options.tooltipClass;
  502. }
  503. tooltipLayer.className = ('introjs-tooltip ' + tooltipCssClass).replace(/^\s+|\s+$/g, '');
  504. currentTooltipPosition = this._introItems[this._currentStep].position;
  505. if (currentTooltipPosition != "floating") { // Floating is always valid, no point in calculating
  506. if (currentTooltipPosition === "auto") {
  507. currentTooltipPosition = _determineAutoPosition.call(this, targetElement, tooltipLayer);
  508. } else {
  509. currentTooltipPosition = _determineAutoPosition.call(this, targetElement, tooltipLayer, currentTooltipPosition);
  510. }
  511. }
  512. targetOffset = _getOffset(targetElement);
  513. tooltipOffset = _getOffset(tooltipLayer);
  514. windowSize = _getWinSize();
  515. switch (currentTooltipPosition) {
  516. case 'top':
  517. arrowLayer.className = 'introjs-arrow bottom';
  518. if (hintMode) {
  519. var tooltipLayerStyleLeft = 0;
  520. } else {
  521. var tooltipLayerStyleLeft = 15;
  522. }
  523. _checkRight(targetOffset, tooltipLayerStyleLeft, tooltipOffset, windowSize, tooltipLayer);
  524. tooltipLayer.style.bottom = (targetOffset.height + 20) + 'px';
  525. break;
  526. case 'right':
  527. tooltipLayer.style.left = (targetOffset.width + 20) + 'px';
  528. if (targetOffset.top + tooltipOffset.height > windowSize.height) {
  529. // In this case, right would have fallen below the bottom of the screen.
  530. // Modify so that the bottom of the tooltip connects with the target
  531. arrowLayer.className = "introjs-arrow left-bottom";
  532. tooltipLayer.style.top = "-" + (tooltipOffset.height - targetOffset.height - 20) + "px";
  533. } else {
  534. arrowLayer.className = 'introjs-arrow left';
  535. }
  536. break;
  537. case 'left':
  538. if (!hintMode && this._options.showStepNumbers == true) {
  539. tooltipLayer.style.top = '15px';
  540. }
  541. if (targetOffset.top + tooltipOffset.height > windowSize.height) {
  542. // In this case, left would have fallen below the bottom of the screen.
  543. // Modify so that the bottom of the tooltip connects with the target
  544. tooltipLayer.style.top = "-" + (tooltipOffset.height - targetOffset.height - 20) + "px";
  545. arrowLayer.className = 'introjs-arrow right-bottom';
  546. } else {
  547. arrowLayer.className = 'introjs-arrow right';
  548. }
  549. tooltipLayer.style.right = (targetOffset.width + 20) + 'px';
  550. break;
  551. case 'floating':
  552. arrowLayer.style.display = 'none';
  553. //we have to adjust the top and left of layer manually for intro items without element
  554. tooltipLayer.style.left = '50%';
  555. tooltipLayer.style.top = '50%';
  556. tooltipLayer.style.marginLeft = '-' + (tooltipOffset.width / 2) + 'px';
  557. tooltipLayer.style.marginTop = '-' + (tooltipOffset.height / 2) + 'px';
  558. if (typeof(helperNumberLayer) != 'undefined' && helperNumberLayer != null) {
  559. helperNumberLayer.style.left = '-' + ((tooltipOffset.width / 2) + 18) + 'px';
  560. helperNumberLayer.style.top = '-' + ((tooltipOffset.height / 2) + 18) + 'px';
  561. }
  562. break;
  563. case 'bottom-right-aligned':
  564. arrowLayer.className = 'introjs-arrow top-right';
  565. var tooltipLayerStyleRight = 0;
  566. _checkLeft(targetOffset, tooltipLayerStyleRight, tooltipOffset, tooltipLayer);
  567. tooltipLayer.style.top = (targetOffset.height + 20) + 'px';
  568. break;
  569. case 'bottom-middle-aligned':
  570. arrowLayer.className = 'introjs-arrow top-middle';
  571. var tooltipLayerStyleLeftRight = targetOffset.width / 2 - tooltipOffset.width / 2;
  572. // a fix for middle aligned hints
  573. if (hintMode) {
  574. tooltipLayerStyleLeftRight += 5;
  575. }
  576. if (_checkLeft(targetOffset, tooltipLayerStyleLeftRight, tooltipOffset, tooltipLayer)) {
  577. tooltipLayer.style.right = null;
  578. _checkRight(targetOffset, tooltipLayerStyleLeftRight, tooltipOffset, windowSize, tooltipLayer);
  579. }
  580. tooltipLayer.style.top = (targetOffset.height + 20) + 'px';
  581. break;
  582. case 'bottom-left-aligned':
  583. // Bottom-left-aligned is the same as the default bottom
  584. case 'bottom':
  585. // Bottom going to follow the default behavior
  586. default:
  587. arrowLayer.className = 'introjs-arrow top';
  588. var tooltipLayerStyleLeft = 0;
  589. _checkRight(targetOffset, tooltipLayerStyleLeft, tooltipOffset, windowSize, tooltipLayer);
  590. tooltipLayer.style.top = (targetOffset.height + 20) + 'px';
  591. break;
  592. }
  593. }
  594. /**
  595. * Set tooltip left so it doesn't go off the right side of the window
  596. *
  597. * @return boolean true, if tooltipLayerStyleLeft is ok. false, otherwise.
  598. */
  599. function _checkRight(targetOffset, tooltipLayerStyleLeft, tooltipOffset, windowSize, tooltipLayer) {
  600. if (targetOffset.left + tooltipLayerStyleLeft + tooltipOffset.width > windowSize.width) {
  601. // off the right side of the window
  602. tooltipLayer.style.left = (windowSize.width - tooltipOffset.width - targetOffset.left) + 'px';
  603. return false;
  604. }
  605. tooltipLayer.style.left = tooltipLayerStyleLeft + 'px';
  606. return true;
  607. }
  608. /**
  609. * Set tooltip right so it doesn't go off the left side of the window
  610. *
  611. * @return boolean true, if tooltipLayerStyleRight is ok. false, otherwise.
  612. */
  613. function _checkLeft(targetOffset, tooltipLayerStyleRight, tooltipOffset, tooltipLayer) {
  614. if (targetOffset.left + targetOffset.width - tooltipLayerStyleRight - tooltipOffset.width < 0) {
  615. // off the left side of the window
  616. tooltipLayer.style.left = (-targetOffset.left) + 'px';
  617. return false;
  618. }
  619. tooltipLayer.style.right = tooltipLayerStyleRight + 'px';
  620. return true;
  621. }
  622. /**
  623. * Determines the position of the tooltip based on the position precedence and availability
  624. * of screen space.
  625. *
  626. * @param {Object} targetElement
  627. * @param {Object} tooltipLayer
  628. * @param {Object} desiredTooltipPosition
  629. *
  630. */
  631. function _determineAutoPosition(targetElement, tooltipLayer, desiredTooltipPosition) {
  632. // Take a clone of position precedence. These will be the available
  633. var possiblePositions = this._options.positionPrecedence.slice();
  634. var windowSize = _getWinSize();
  635. var tooltipHeight = _getOffset(tooltipLayer).height + 10;
  636. var tooltipWidth = _getOffset(tooltipLayer).width + 20;
  637. var targetOffset = _getOffset(targetElement);
  638. // If we check all the possible areas, and there are no valid places for the tooltip, the element
  639. // must take up most of the screen real estate. Show the tooltip floating in the middle of the screen.
  640. var calculatedPosition = "floating";
  641. // Check if the width of the tooltip + the starting point would spill off the right side of the screen
  642. // If no, neither bottom or top are valid
  643. if (targetOffset.left + tooltipWidth > windowSize.width || ((targetOffset.left + (targetOffset.width / 2)) - tooltipWidth) < 0) {
  644. _removeEntry(possiblePositions, "bottom");
  645. _removeEntry(possiblePositions, "top");
  646. } else {
  647. // Check for space below
  648. if ((targetOffset.height + targetOffset.top + tooltipHeight) > windowSize.height) {
  649. _removeEntry(possiblePositions, "bottom");
  650. }
  651. // Check for space above
  652. if (targetOffset.top - tooltipHeight < 0) {
  653. _removeEntry(possiblePositions, "top");
  654. }
  655. }
  656. // Check for space to the right
  657. if (targetOffset.width + targetOffset.left + tooltipWidth > windowSize.width) {
  658. _removeEntry(possiblePositions, "right");
  659. }
  660. // Check for space to the left
  661. if (targetOffset.left - tooltipWidth < 0) {
  662. _removeEntry(possiblePositions, "left");
  663. }
  664. // At this point, our array only has positions that are valid. Pick the first one, as it remains in order
  665. if (possiblePositions.length > 0) {
  666. calculatedPosition = possiblePositions[0];
  667. }
  668. // If the requested position is in the list, replace our calculated choice with that
  669. if (desiredTooltipPosition && desiredTooltipPosition != "auto") {
  670. if (possiblePositions.indexOf(desiredTooltipPosition) > -1) {
  671. calculatedPosition = desiredTooltipPosition;
  672. }
  673. }
  674. return calculatedPosition;
  675. }
  676. /**
  677. * Remove an entry from a string array if it's there, does nothing if it isn't there.
  678. *
  679. * @param {Array} stringArray
  680. * @param {String} stringToRemove
  681. */
  682. function _removeEntry(stringArray, stringToRemove) {
  683. if (stringArray.indexOf(stringToRemove) > -1) {
  684. stringArray.splice(stringArray.indexOf(stringToRemove), 1);
  685. }
  686. }
  687. /**
  688. * Update the position of the helper layer on the screen
  689. *
  690. * @api private
  691. * @method _setHelperLayerPosition
  692. * @param {Object} helperLayer
  693. */
  694. function _setHelperLayerPosition(helperLayer) {
  695. if (helperLayer) {
  696. //prevent error when `this._currentStep` in undefined
  697. if (!this._introItems[this._currentStep]) return;
  698. var currentElement = this._introItems[this._currentStep],
  699. elementPosition = _getOffset(currentElement.element),
  700. widthHeightPadding = 10;
  701. // If the target element is fixed, the tooltip should be fixed as well.
  702. // Otherwise, remove a fixed class that may be left over from the previous
  703. // step.
  704. if (_isFixed(currentElement.element)) {
  705. helperLayer.className += ' introjs-fixedTooltip';
  706. } else {
  707. helperLayer.className = helperLayer.className.replace(' introjs-fixedTooltip', '');
  708. }
  709. if (currentElement.position == 'floating') {
  710. widthHeightPadding = 0;
  711. }
  712. //set new position to helper layer
  713. helperLayer.setAttribute('style', 'width: ' + (elementPosition.width + widthHeightPadding) + 'px; ' +
  714. 'height:' + (elementPosition.height + widthHeightPadding) + 'px; ' +
  715. 'top:' + (elementPosition.top - 5) + 'px;' +
  716. 'left: ' + (elementPosition.left - 5) + 'px;');
  717. }
  718. }
  719. /**
  720. * Add disableinteraction layer and adjust the size and position of the layer
  721. *
  722. * @api private
  723. * @method _disableInteraction
  724. */
  725. function _disableInteraction() {
  726. var disableInteractionLayer = document.querySelector('.introjs-disableInteraction');
  727. if (disableInteractionLayer === null) {
  728. disableInteractionLayer = document.createElement('div');
  729. disableInteractionLayer.className = 'introjs-disableInteraction';
  730. this._targetElement.appendChild(disableInteractionLayer);
  731. }
  732. _setHelperLayerPosition.call(this, disableInteractionLayer);
  733. }
  734. /**
  735. * Setting anchors to behave like buttons
  736. *
  737. * @api private
  738. * @method _setAnchorAsButton
  739. */
  740. function _setAnchorAsButton(anchor){
  741. anchor.setAttribute('role', 'button');
  742. anchor.tabIndex = 0;
  743. }
  744. /**
  745. * Show an element on the page
  746. *
  747. * @api private
  748. * @method _showElement
  749. * @param {Object} targetElement
  750. */
  751. function _showElement(targetElement) {
  752. if (typeof (this._introChangeCallback) !== 'undefined') {
  753. this._introChangeCallback.call(this, targetElement.element);
  754. }
  755. var self = this,
  756. oldHelperLayer = document.querySelector('.introjs-helperLayer'),
  757. oldReferenceLayer = document.querySelector('.introjs-tooltipReferenceLayer'),
  758. highlightClass = 'introjs-helperLayer',
  759. elementPosition = _getOffset(targetElement.element);
  760. //check for a current step highlight class
  761. if (typeof (targetElement.highlightClass) === 'string') {
  762. highlightClass += (' ' + targetElement.highlightClass);
  763. }
  764. //check for options highlight class
  765. if (typeof (this._options.highlightClass) === 'string') {
  766. highlightClass += (' ' + this._options.highlightClass);
  767. }
  768. if (oldHelperLayer != null) {
  769. var oldHelperNumberLayer = oldReferenceLayer.querySelector('.introjs-helperNumberLayer'),
  770. oldtooltipLayer = oldReferenceLayer.querySelector('.introjs-tooltiptext'),
  771. oldArrowLayer = oldReferenceLayer.querySelector('.introjs-arrow'),
  772. oldtooltipContainer = oldReferenceLayer.querySelector('.introjs-tooltip'),
  773. skipTooltipButton = oldReferenceLayer.querySelector('.introjs-skipbutton'),
  774. prevTooltipButton = oldReferenceLayer.querySelector('.introjs-prevbutton'),
  775. nextTooltipButton = oldReferenceLayer.querySelector('.introjs-nextbutton');
  776. //update or reset the helper highlight class
  777. oldHelperLayer.className = highlightClass;
  778. //hide the tooltip
  779. oldtooltipContainer.style.opacity = 0;
  780. oldtooltipContainer.style.display = "none";
  781. if (oldHelperNumberLayer != null) {
  782. var lastIntroItem = this._introItems[(targetElement.step - 2 >= 0 ? targetElement.step - 2 : 0)];
  783. if (lastIntroItem != null && (this._direction == 'forward' && lastIntroItem.position == 'floating') || (this._direction == 'backward' && targetElement.position == 'floating')) {
  784. oldHelperNumberLayer.style.opacity = 0;
  785. }
  786. }
  787. //set new position to helper layer
  788. _setHelperLayerPosition.call(self, oldHelperLayer);
  789. _setHelperLayerPosition.call(self, oldReferenceLayer);
  790. //remove `introjs-fixParent` class from the elements
  791. var fixParents = document.querySelectorAll('.introjs-fixParent');
  792. if (fixParents && fixParents.length > 0) {
  793. for (var i = fixParents.length - 1; i >= 0; i--) {
  794. fixParents[i].className = fixParents[i].className.replace(/introjs-fixParent/g, '').replace(/^\s+|\s+$/g, '');
  795. };
  796. }
  797. //remove old classes if the element still exist
  798. _removeShowElement();
  799. //we should wait until the CSS3 transition is competed (it's 0.3 sec) to prevent incorrect `height` and `width` calculation
  800. if (self._lastShowElementTimer) {
  801. clearTimeout(self._lastShowElementTimer);
  802. }
  803. self._lastShowElementTimer = setTimeout(function() {
  804. //set current step to the label
  805. if (oldHelperNumberLayer != null) {
  806. oldHelperNumberLayer.innerHTML = targetElement.step;
  807. }
  808. //set current tooltip text
  809. oldtooltipLayer.innerHTML = targetElement.intro;
  810. //set the tooltip position
  811. oldtooltipContainer.style.display = "block";
  812. _placeTooltip.call(self, targetElement.element, oldtooltipContainer, oldArrowLayer, oldHelperNumberLayer);
  813. //change active bullet
  814. if (self._options.showBullets) {
  815. oldReferenceLayer.querySelector('.introjs-bullets li > a.active').className = '';
  816. oldReferenceLayer.querySelector('.introjs-bullets li > a[data-stepnumber="' + targetElement.step + '"]').className = 'active';
  817. }
  818. oldReferenceLayer.querySelector('.introjs-progress .introjs-progressbar').setAttribute('style', 'width:' + _getProgress.call(self) + '%;');
  819. //show the tooltip
  820. oldtooltipContainer.style.opacity = 1;
  821. if (oldHelperNumberLayer) oldHelperNumberLayer.style.opacity = 1;
  822. //reset button focus
  823. if (typeof skipTooltipButton !== "undefined" && skipTooltipButton != null && /introjs-donebutton/gi.test(skipTooltipButton.className)) {
  824. // skip button is now "done" button
  825. skipTooltipButton.focus();
  826. } else if (typeof nextTooltipButton !== "undefined" && nextTooltipButton != null) {
  827. //still in the tour, focus on next
  828. nextTooltipButton.focus();
  829. }
  830. // change the scroll of the window, if needed
  831. _scrollTo.call(self, targetElement.scrollTo, targetElement, oldtooltipLayer);
  832. }, 350);
  833. // end of old element if-else condition
  834. } else {
  835. var helperLayer = document.createElement('div'),
  836. referenceLayer = document.createElement('div'),
  837. arrowLayer = document.createElement('div'),
  838. tooltipLayer = document.createElement('div'),
  839. tooltipTextLayer = document.createElement('div'),
  840. bulletsLayer = document.createElement('div'),
  841. progressLayer = document.createElement('div'),
  842. buttonsLayer = document.createElement('div');
  843. helperLayer.className = highlightClass;
  844. referenceLayer.className = 'introjs-tooltipReferenceLayer';
  845. //set new position to helper layer
  846. _setHelperLayerPosition.call(self, helperLayer);
  847. _setHelperLayerPosition.call(self, referenceLayer);
  848. //add helper layer to target element
  849. this._targetElement.appendChild(helperLayer);
  850. this._targetElement.appendChild(referenceLayer);
  851. arrowLayer.className = 'introjs-arrow';
  852. tooltipTextLayer.className = 'introjs-tooltiptext';
  853. tooltipTextLayer.innerHTML = targetElement.intro;
  854. bulletsLayer.className = 'introjs-bullets';
  855. if (this._options.showBullets === false) {
  856. bulletsLayer.style.display = 'none';
  857. }
  858. var ulContainer = document.createElement('ul');
  859. for (var i = 0, stepsLength = this._introItems.length; i < stepsLength; i++) {
  860. var innerLi = document.createElement('li');
  861. var anchorLink = document.createElement('a');
  862. anchorLink.onclick = function() {
  863. self.goToStep(this.getAttribute('data-stepnumber'));
  864. };
  865. if (i === (targetElement.step-1)) anchorLink.className = 'active';
  866. _setAnchorAsButton(anchorLink);
  867. anchorLink.innerHTML = "&nbsp;";
  868. anchorLink.setAttribute('data-stepnumber', this._introItems[i].step);
  869. innerLi.appendChild(anchorLink);
  870. ulContainer.appendChild(innerLi);
  871. }
  872. bulletsLayer.appendChild(ulContainer);
  873. progressLayer.className = 'introjs-progress';
  874. if (this._options.showProgress === false) {
  875. progressLayer.style.display = 'none';
  876. }
  877. var progressBar = document.createElement('div');
  878. progressBar.className = 'introjs-progressbar';
  879. progressBar.setAttribute('style', 'width:' + _getProgress.call(this) + '%;');
  880. progressLayer.appendChild(progressBar);
  881. buttonsLayer.className = 'introjs-tooltipbuttons';
  882. if (this._options.showButtons === false) {
  883. buttonsLayer.style.display = 'none';
  884. }
  885. tooltipLayer.className = 'introjs-tooltip';
  886. tooltipLayer.appendChild(tooltipTextLayer);
  887. tooltipLayer.appendChild(bulletsLayer);
  888. tooltipLayer.appendChild(progressLayer);
  889. //add helper layer number
  890. if (this._options.showStepNumbers == true) {
  891. var helperNumberLayer = document.createElement('span');
  892. helperNumberLayer.className = 'introjs-helperNumberLayer';
  893. helperNumberLayer.innerHTML = targetElement.step;
  894. referenceLayer.appendChild(helperNumberLayer);
  895. }
  896. tooltipLayer.appendChild(arrowLayer);
  897. referenceLayer.appendChild(tooltipLayer);
  898. //next button
  899. var nextTooltipButton = document.createElement('a');
  900. nextTooltipButton.onclick = function() {
  901. if (self._introItems.length - 1 != self._currentStep) {
  902. _nextStep.call(self);
  903. }
  904. };
  905. _setAnchorAsButton(nextTooltipButton);
  906. nextTooltipButton.innerHTML = this._options.nextLabel;
  907. //previous button
  908. var prevTooltipButton = document.createElement('a');
  909. prevTooltipButton.onclick = function() {
  910. if (self._currentStep != 0) {
  911. _previousStep.call(self);
  912. }
  913. };
  914. _setAnchorAsButton(prevTooltipButton);
  915. prevTooltipButton.innerHTML = this._options.prevLabel;
  916. //skip button
  917. var skipTooltipButton = document.createElement('a');
  918. skipTooltipButton.className = 'introjs-button introjs-skipbutton';
  919. _setAnchorAsButton(skipTooltipButton);
  920. skipTooltipButton.innerHTML = this._options.skipLabel;
  921. skipTooltipButton.onclick = function() {
  922. if (self._introItems.length - 1 == self._currentStep && typeof (self._introCompleteCallback) === 'function') {
  923. self._introCompleteCallback.call(self);
  924. }
  925. _exitIntro.call(self, self._targetElement);
  926. };
  927. buttonsLayer.appendChild(skipTooltipButton);
  928. //in order to prevent displaying next/previous button always
  929. if (this._introItems.length > 1) {
  930. buttonsLayer.appendChild(prevTooltipButton);
  931. buttonsLayer.appendChild(nextTooltipButton);
  932. }
  933. tooltipLayer.appendChild(buttonsLayer);
  934. //set proper position
  935. _placeTooltip.call(self, targetElement.element, tooltipLayer, arrowLayer, helperNumberLayer);
  936. // change the scroll of the window, if needed
  937. _scrollTo.call(this, targetElement.scrollTo, targetElement, tooltipLayer);
  938. //end of new element if-else condition
  939. }
  940. // removing previous disable interaction layer
  941. var disableInteractionLayer = self._targetElement.querySelector('.introjs-disableInteraction');
  942. if (disableInteractionLayer) {
  943. disableInteractionLayer.parentNode.removeChild(disableInteractionLayer);
  944. }
  945. //disable interaction
  946. if (targetElement.disableInteraction) {
  947. _disableInteraction.call(self);
  948. }
  949. if (typeof nextTooltipButton !== "undefined" && nextTooltipButton != null) {
  950. nextTooltipButton.removeAttribute('tabIndex');
  951. }
  952. if (typeof prevTooltipButton !== "undefined" && prevTooltipButton != null) {
  953. prevTooltipButton.removeAttribute('tabIndex');
  954. }
  955. // when it's the first step of tour
  956. if (this._currentStep == 0 && this._introItems.length > 1) {
  957. if (typeof skipTooltipButton !== "undefined" && skipTooltipButton != null) {
  958. skipTooltipButton.className = 'introjs-button introjs-skipbutton';
  959. }
  960. if (typeof nextTooltipButton !== "undefined" && nextTooltipButton != null) {
  961. nextTooltipButton.className = 'introjs-button introjs-nextbutton';
  962. }
  963. if (this._options.hidePrev == true) {
  964. if (typeof prevTooltipButton !== "undefined" && prevTooltipButton != null) {
  965. prevTooltipButton.className = 'introjs-button introjs-prevbutton introjs-hidden';
  966. }
  967. if (typeof nextTooltipButton !== "undefined" && nextTooltipButton != null) {
  968. nextTooltipButton.className += ' introjs-fullbutton';
  969. }
  970. } else {
  971. if (typeof prevTooltipButton !== "undefined" && prevTooltipButton != null) {
  972. prevTooltipButton.className = 'introjs-button introjs-prevbutton introjs-disabled';
  973. }
  974. }
  975. if (typeof prevTooltipButton !== "undefined" && prevTooltipButton != null) {
  976. prevTooltipButton.tabIndex = '-1';
  977. }
  978. if (typeof skipTooltipButton !== "undefined" && skipTooltipButton != null) {
  979. skipTooltipButton.innerHTML = this._options.skipLabel;
  980. }
  981. } else if (this._introItems.length - 1 == this._currentStep || this._introItems.length == 1) {
  982. // last step of tour
  983. if (typeof skipTooltipButton !== "undefined" && skipTooltipButton != null) {
  984. skipTooltipButton.innerHTML = this._options.doneLabel;
  985. // adding donebutton class in addition to skipbutton
  986. skipTooltipButton.className += ' introjs-donebutton';
  987. }
  988. if (typeof prevTooltipButton !== "undefined" && prevTooltipButton != null) {
  989. prevTooltipButton.className = 'introjs-button introjs-prevbutton';
  990. }
  991. if (this._options.hideNext == true) {
  992. if (typeof nextTooltipButton !== "undefined" && nextTooltipButton != null) {
  993. nextTooltipButton.className = 'introjs-button introjs-nextbutton introjs-hidden';
  994. }
  995. if (typeof prevTooltipButton !== "undefined" && prevTooltipButton != null) {
  996. prevTooltipButton.className += ' introjs-fullbutton';
  997. }
  998. } else {
  999. if (typeof nextTooltipButton !== "undefined" && nextTooltipButton != null) {
  1000. nextTooltipButton.className = 'introjs-button introjs-nextbutton introjs-disabled';
  1001. }
  1002. }
  1003. if (typeof nextTooltipButton !== "undefined" && nextTooltipButton != null) {
  1004. nextTooltipButton.tabIndex = '-1';
  1005. }
  1006. } else {
  1007. // steps between start and end
  1008. if (typeof skipTooltipButton !== "undefined" && skipTooltipButton != null) {
  1009. skipTooltipButton.className = 'introjs-button introjs-skipbutton';
  1010. }
  1011. if (typeof prevTooltipButton !== "undefined" && prevTooltipButton != null) {
  1012. prevTooltipButton.className = 'introjs-button introjs-prevbutton';
  1013. }
  1014. if (typeof nextTooltipButton !== "undefined" && nextTooltipButton != null) {
  1015. nextTooltipButton.className = 'introjs-button introjs-nextbutton';
  1016. }
  1017. if (typeof skipTooltipButton !== "undefined" && skipTooltipButton != null) {
  1018. skipTooltipButton.innerHTML = this._options.skipLabel;
  1019. }
  1020. }
  1021. //Set focus on "next" button, so that hitting Enter always moves you onto the next step
  1022. if (typeof nextTooltipButton !== "undefined" && nextTooltipButton != null) {
  1023. nextTooltipButton.focus();
  1024. }
  1025. _setShowElement(targetElement);
  1026. if (typeof (this._introAfterChangeCallback) !== 'undefined') {
  1027. this._introAfterChangeCallback.call(this, targetElement.element);
  1028. }
  1029. }
  1030. /**
  1031. * To change the scroll of `window` after highlighting an element
  1032. *
  1033. * @api private
  1034. * @method _scrollTo
  1035. * @param {String} scrollTo
  1036. * @param {Object} targetElement
  1037. * @param {Object} tooltipLayer
  1038. */
  1039. function _scrollTo(scrollTo, targetElement, tooltipLayer) {
  1040. if (!this._options.scrollToElement) return;
  1041. if (scrollTo === 'tooltip') {
  1042. var rect = tooltipLayer.getBoundingClientRect();
  1043. } else {
  1044. var rect = targetElement.element.getBoundingClientRect();
  1045. }
  1046. if (!_elementInViewport(targetElement.element)) {
  1047. var winHeight = _getWinSize().height;
  1048. var top = rect.bottom - (rect.bottom - rect.top);
  1049. var bottom = rect.bottom - winHeight;
  1050. // TODO (afshinm): do we need scroll padding now?
  1051. // I have changed the scroll option and now it scrolls the window to
  1052. // the center of the target element or tooltip.
  1053. if (top < 0 || targetElement.element.clientHeight > winHeight) {
  1054. window.scrollBy(0, rect.top - ((winHeight / 2) - (rect.height / 2)) - this._options.scrollPadding); // 30px padding from edge to look nice
  1055. //Scroll down
  1056. } else {
  1057. window.scrollBy(0, rect.top - ((winHeight / 2) - (rect.height / 2)) + this._options.scrollPadding); // 30px padding from edge to look nice
  1058. }
  1059. }
  1060. }
  1061. /**
  1062. * To remove all show element(s)
  1063. *
  1064. * @api private
  1065. * @method _removeShowElement
  1066. */
  1067. function _removeShowElement() {
  1068. var elms = document.querySelectorAll('.introjs-showElement');
  1069. for (var i = 0, l = elms.length; i < l; i++) {
  1070. var elm = elms[i];
  1071. _removeClass(elm, /introjs-[a-zA-Z]+/g);
  1072. }
  1073. }
  1074. /**
  1075. * To set the show element
  1076. * This function set a relative (in most cases) position and changes the z-index
  1077. *
  1078. * @api private
  1079. * @method _setShowElement
  1080. * @param {Object} targetElement
  1081. */
  1082. function _setShowElement(targetElement) {
  1083. // we need to add this show element class to the parent of SVG elements
  1084. // because the SVG elements can't have independent z-index
  1085. if (targetElement.element instanceof SVGElement) {
  1086. var parentElm = targetElement.element.parentNode;
  1087. while (targetElement.element.parentNode != null) {
  1088. if (!parentElm.tagName || parentElm.tagName.toLowerCase() === 'body') break;
  1089. if (parentElm.tagName.toLowerCase() === 'svg') {
  1090. _setClass(parentElm, 'introjs-showElement introjs-relativePosition');
  1091. }
  1092. parentElm = parentElm.parentNode;
  1093. }
  1094. }
  1095. _setClass(targetElement.element, 'introjs-showElement');
  1096. var currentElementPosition = _getPropValue(targetElement.element, 'position');
  1097. if (currentElementPosition !== 'absolute' &&
  1098. currentElementPosition !== 'relative' &&
  1099. currentElementPosition !== 'fixed') {
  1100. //change to new intro item
  1101. //targetElement.element.className += ' introjs-relativePosition';
  1102. _setClass(targetElement.element, 'introjs-relativePosition')
  1103. }
  1104. var parentElm = targetElement.element.parentNode;
  1105. while (parentElm != null) {
  1106. if (!parentElm.tagName || parentElm.tagName.toLowerCase() === 'body') break;
  1107. //fix The Stacking Context problem.
  1108. //More detail: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context
  1109. var zIndex = _getPropValue(parentElm, 'z-index');
  1110. var opacity = parseFloat(_getPropValue(parentElm, 'opacity'));
  1111. var transform = _getPropValue(parentElm, 'transform') || _getPropValue(parentElm, '-webkit-transform') || _getPropValue(parentElm, '-moz-transform') || _getPropValue(parentElm, '-ms-transform') || _getPropValue(parentElm, '-o-transform');
  1112. if (/[0-9]+/.test(zIndex) || opacity < 1 || (transform !== 'none' && transform !== undefined)) {
  1113. parentElm.className += ' introjs-fixParent';
  1114. }
  1115. parentElm = parentElm.parentNode;
  1116. }
  1117. }
  1118. function _setClass(element, className) {
  1119. if (element instanceof SVGElement) {
  1120. var pre = element.getAttribute('class') || '';
  1121. element.setAttribute('class', pre + ' ' + className);
  1122. } else {
  1123. element.className += ' ' + className;
  1124. }
  1125. }
  1126. function _removeClass(element, classNameRegex) {
  1127. if (element instanceof SVGElement) {
  1128. var pre = element.getAttribute('class') || '';
  1129. element.setAttribute('class', pre.replace(classNameRegex, '').replace(/^\s+|\s+$/g, ''));
  1130. } else {
  1131. element.className = element.className.replace(classNameRegex, '').replace(/^\s+|\s+$/g, '');
  1132. }
  1133. }
  1134. /**
  1135. * Get an element CSS property on the page
  1136. * Thanks to JavaScript Kit: http://www.javascriptkit.com/dhtmltutors/dhtmlcascade4.shtml
  1137. *
  1138. * @api private
  1139. * @method _getPropValue
  1140. * @param {Object} element
  1141. * @param {String} propName
  1142. * @returns Element's property value
  1143. */
  1144. function _getPropValue (element, propName) {
  1145. var propValue = '';
  1146. if (element.currentStyle) { //IE
  1147. propValue = element.currentStyle[propName];
  1148. } else if (document.defaultView && document.defaultView.getComputedStyle) { //Others
  1149. propValue = document.defaultView.getComputedStyle(element, null).getPropertyValue(propName);
  1150. }
  1151. //Prevent exception in IE
  1152. if (propValue && propValue.toLowerCase) {
  1153. return propValue.toLowerCase();
  1154. } else {
  1155. return propValue;
  1156. }
  1157. }
  1158. /**
  1159. * Checks to see if target element (or parents) position is fixed or not
  1160. *
  1161. * @api private
  1162. * @method _isFixed
  1163. * @param {Object} element
  1164. * @returns Boolean
  1165. */
  1166. function _isFixed (element) {
  1167. var p = element.parentNode;
  1168. if (!p || p.nodeName === 'HTML') {
  1169. return false;
  1170. }
  1171. if (_getPropValue(element, 'position') == 'fixed') {
  1172. return true;
  1173. }
  1174. return _isFixed(p);
  1175. }
  1176. /**
  1177. * Provides a cross-browser way to get the screen dimensions
  1178. * via: http://stackoverflow.com/questions/5864467/internet-explorer-innerheight
  1179. *
  1180. * @api private
  1181. * @method _getWinSize
  1182. * @returns {Object} width and height attributes
  1183. */
  1184. function _getWinSize() {
  1185. if (window.innerWidth != undefined) {
  1186. return { width: window.innerWidth, height: window.innerHeight };
  1187. } else {
  1188. var D = document.documentElement;
  1189. return { width: D.clientWidth, height: D.clientHeight };
  1190. }
  1191. }
  1192. /**
  1193. * Check to see if the element is in the viewport or not
  1194. * http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
  1195. *
  1196. * @api private
  1197. * @method _elementInViewport
  1198. * @param {Object} el
  1199. */
  1200. function _elementInViewport(el) {
  1201. var rect = el.getBoundingClientRect();
  1202. return (
  1203. rect.top >= 0 &&
  1204. rect.left >= 0 &&
  1205. (rect.bottom+80) <= window.innerHeight && // add 80 to get the text right
  1206. rect.right <= window.innerWidth
  1207. );
  1208. }
  1209. /**
  1210. * Add overlay layer to the page
  1211. *
  1212. * @api private
  1213. * @method _addOverlayLayer
  1214. * @param {Object} targetElm
  1215. */
  1216. function _addOverlayLayer(targetElm) {
  1217. var overlayLayer = document.createElement('div'),
  1218. styleText = '',
  1219. self = this;
  1220. //set css class name
  1221. overlayLayer.className = 'introjs-overlay';
  1222. //check if the target element is body, we should calculate the size of overlay layer in a better way
  1223. if (!targetElm.tagName || targetElm.tagName.toLowerCase() === 'body') {
  1224. styleText += 'top: 0;bottom: 0; left: 0;right: 0;position: fixed;';
  1225. overlayLayer.setAttribute('style', styleText);
  1226. } else {
  1227. //set overlay layer position
  1228. var elementPosition = _getOffset(targetElm);
  1229. if (elementPosition) {
  1230. styleText += 'width: ' + elementPosition.width + 'px; height:' + elementPosition.height + 'px; top:' + elementPosition.top + 'px;left: ' + elementPosition.left + 'px;';
  1231. overlayLayer.setAttribute('style', styleText);
  1232. }
  1233. }
  1234. targetElm.appendChild(overlayLayer);
  1235. overlayLayer.onclick = function() {
  1236. if (self._options.exitOnOverlayClick == true) {
  1237. _exitIntro.call(self, targetElm);
  1238. }
  1239. };
  1240. setTimeout(function() {
  1241. styleText += 'opacity: ' + self._options.overlayOpacity.toString() + ';';
  1242. overlayLayer.setAttribute('style', styleText);
  1243. }, 10);
  1244. return true;
  1245. }
  1246. /**
  1247. * Removes open hint (tooltip hint)
  1248. *
  1249. * @api private
  1250. * @method _removeHintTooltip
  1251. */
  1252. function _removeHintTooltip() {
  1253. var tooltip = this._targetElement.querySelector('.introjs-hintReference');
  1254. if (tooltip) {
  1255. var step = tooltip.getAttribute('data-step');
  1256. tooltip.parentNode.removeChild(tooltip);
  1257. return step;
  1258. }
  1259. }
  1260. /**
  1261. * Start parsing hint items
  1262. *
  1263. * @api private
  1264. * @param {Object} targetElm
  1265. * @method _startHint
  1266. */
  1267. function _populateHints(targetElm) {
  1268. var self = this;
  1269. this._introItems = [];
  1270. if (this._options.hints) {
  1271. for (var i = 0, l = this._options.hints.length; i < l; i++) {
  1272. var currentItem = _cloneObject(this._options.hints[i]);
  1273. if (typeof(currentItem.element) === 'string') {
  1274. //grab the element with given selector from the page
  1275. currentItem.element = document.querySelector(currentItem.element);
  1276. }
  1277. currentItem.hintPosition = currentItem.hintPosition || this._options.hintPosition;
  1278. currentItem.hintAnimation = currentItem.hintAnimation || this._options.hintAnimation;
  1279. if (currentItem.element != null) {
  1280. this._introItems.push(currentItem);
  1281. }
  1282. }
  1283. } else {
  1284. var hints = targetElm.querySelectorAll('*[data-hint]');
  1285. if (hints.length < 1) {
  1286. return false;
  1287. }
  1288. //first add intro items with data-step
  1289. for (var i = 0, l = hints.length; i < l; i++) {
  1290. var currentElement = hints[i];
  1291. // hint animation
  1292. var hintAnimation = currentElement.getAttribute('data-hintAnimation');
  1293. if (hintAnimation) {
  1294. hintAnimation = (hintAnimation == 'true');
  1295. } else {
  1296. hintAnimation = this._options.hintAnimation;
  1297. }
  1298. this._introItems.push({
  1299. element: currentElement,
  1300. hint: currentElement.getAttribute('data-hint'),
  1301. hintPosition: currentElement.getAttribute('data-hintPosition') || this._options.hintPosition,
  1302. hintAnimation: hintAnimation,
  1303. tooltipClass: currentElement.getAttribute('data-tooltipClass'),
  1304. position: currentElement.getAttribute('data-position') || this._options.tooltipPosition
  1305. });
  1306. }
  1307. }
  1308. _addHints.call(this);
  1309. if (document.addEventListener) {
  1310. document.addEventListener('click', _removeHintTooltip.bind(this), false);
  1311. //for window resize
  1312. window.addEventListener('resize', _reAlignHints.bind(this), true);
  1313. } else if (document.attachEvent) { //IE
  1314. //for window resize
  1315. document.attachEvent('onclick', _removeHintTooltip.bind(this));
  1316. document.attachEvent('onresize', _reAlignHints.bind(this));
  1317. }
  1318. }
  1319. /**
  1320. * Re-aligns all hint elements
  1321. *
  1322. * @api private
  1323. * @method _reAlignHints
  1324. */
  1325. function _reAlignHints() {
  1326. for (var i = 0, l = this._introItems.length; i < l; i++) {
  1327. var item = this._introItems[i];
  1328. if (typeof (item.targetElement) == 'undefined') continue;
  1329. _alignHintPosition.call(this, item.hintPosition, item.element, item.targetElement)
  1330. }
  1331. }
  1332. /**
  1333. * Hide a hint
  1334. *
  1335. * @api private
  1336. * @method _hideHint
  1337. */
  1338. function _hideHint(stepId) {
  1339. _removeHintTooltip.call(this);
  1340. var hint = this._targetElement.querySelector('.introjs-hint[data-step="' + stepId + '"]');
  1341. if (hint) {
  1342. hint.className += ' introjs-hidehint';
  1343. }
  1344. // call the callback function (if any)
  1345. if (typeof (this._hintCloseCallback) !== 'undefined') {
  1346. this._hintCloseCallback.call(this, stepId);
  1347. }
  1348. }
  1349. /**
  1350. * Hide all hints
  1351. *
  1352. * @api private
  1353. * @method _hideHints
  1354. */
  1355. function _hideHints() {
  1356. var hints = this._targetElement.querySelectorAll('.introjs-hint');
  1357. if (hints && hints.length > 0) {
  1358. for (var i = 0; i < hints.length; i++) {
  1359. _hideHint.call(this, hints[i].getAttribute('data-step'));
  1360. }
  1361. }
  1362. }
  1363. /**
  1364. * Show all hints
  1365. *
  1366. * @api private
  1367. * @method _showHints
  1368. */
  1369. function _showHints() {
  1370. var hints = this._targetElement.querySelectorAll('.introjs-hint');
  1371. if (hints && hints.length > 0) {
  1372. for (var i = 0; i < hints.length; i++) {
  1373. _showHint.call(this, hints[i].getAttribute('data-step'));
  1374. }
  1375. } else {
  1376. _populateHints.call(this, this._targetElement);
  1377. }
  1378. };
  1379. /**
  1380. * Show a hint
  1381. *
  1382. * @api private
  1383. * @method _showHint
  1384. */
  1385. function _showHint(stepId) {
  1386. var hint = this._targetElement.querySelector('.introjs-hint[data-step="' + stepId + '"]');
  1387. if (hint) {
  1388. hint.className = hint.className.replace(/introjs\-hidehint/g, '');
  1389. }
  1390. };
  1391. /**
  1392. * Removes all hint elements on the page
  1393. * Useful when you want to destroy the elements and add them again (e.g. a modal or popup)
  1394. *
  1395. * @api private
  1396. * @method _removeHints
  1397. */
  1398. function _removeHints() {
  1399. var hints = this._targetElement.querySelectorAll('.introjs-hint');
  1400. if (hints && hints.length > 0) {
  1401. for (var i = 0; i < hints.length; i++) {
  1402. _removeHint.call(this, hints[i].getAttribute('data-step'));
  1403. }
  1404. }
  1405. };
  1406. /**
  1407. * Remove one single hint element from the page
  1408. * Useful when you want to destroy the element and add them again (e.g. a modal or popup)
  1409. * Use removeHints if you want to remove all elements.
  1410. *
  1411. * @api private
  1412. * @method _removeHint
  1413. */
  1414. function _removeHint(stepId) {
  1415. var hint = this._targetElement.querySelector('.introjs-hint[data-step="' + stepId + '"]');
  1416. if (hint) {
  1417. hint.parentNode.removeChild(hint);
  1418. }
  1419. };
  1420. /**
  1421. * Add all available hints to the page
  1422. *
  1423. * @api private
  1424. * @method _addHints
  1425. */
  1426. function _addHints() {
  1427. var self = this;
  1428. var oldHintsWrapper = document.querySelector('.introjs-hints');
  1429. if (oldHintsWrapper != null) {
  1430. hintsWrapper = oldHintsWrapper;
  1431. } else {
  1432. var hintsWrapper = document.createElement('div');
  1433. hintsWrapper.className = 'introjs-hints';
  1434. }
  1435. for (var i = 0, l = this._introItems.length; i < l; i++) {
  1436. var item = this._introItems[i];
  1437. // avoid append a hint twice
  1438. if (document.querySelector('.introjs-hint[data-step="' + i + '"]'))
  1439. continue;
  1440. var hint = document.createElement('a');
  1441. _setAnchorAsButton(hint);
  1442. (function (hint, item, i) {
  1443. // when user clicks on the hint element
  1444. hint.onclick = function(e) {
  1445. var evt = e ? e : window.event;
  1446. if (evt.stopPropagation) evt.stopPropagation();
  1447. if (evt.cancelBubble != null) evt.cancelBubble = true;
  1448. _showHintDialog.call(self, i);
  1449. };
  1450. }(hint, item, i));
  1451. hint.className = 'introjs-hint';
  1452. if (!item.hintAnimation) {
  1453. hint.className += ' introjs-hint-no-anim';
  1454. }
  1455. // hint's position should be fixed if the target element's position is fixed
  1456. if (_isFixed(item.element)) {
  1457. hint.className += ' introjs-fixedhint';
  1458. }
  1459. var hintDot = document.createElement('div');
  1460. hintDot.className = 'introjs-hint-dot';
  1461. var hintPulse = document.createElement('div');
  1462. hintPulse.className = 'introjs-hint-pulse';
  1463. hint.appendChild(hintDot);
  1464. hint.appendChild(hintPulse);
  1465. hint.setAttribute('data-step', i);
  1466. // we swap the hint element with target element
  1467. // because _setHelperLayerPosition uses `element` property
  1468. item.targetElement = item.element;
  1469. item.element = hint;
  1470. // align the hint position
  1471. _alignHintPosition.call(this, item.hintPosition, hint, item.targetElement);
  1472. hintsWrapper.appendChild(hint);
  1473. }
  1474. // adding the hints wrapper
  1475. document.body.appendChild(hintsWrapper);
  1476. // call the callback function (if any)
  1477. if (typeof (this._hintsAddedCallback) !== 'undefined') {
  1478. this._hintsAddedCallback.call(this);
  1479. }
  1480. }
  1481. /**
  1482. * Aligns hint position
  1483. *
  1484. * @api private
  1485. * @method _alignHintPosition
  1486. * @param {String} position
  1487. * @param {Object} hint
  1488. * @param {Object} element
  1489. */
  1490. function _alignHintPosition(position, hint, element) {
  1491. // get/calculate offset of target element
  1492. var offset = _getOffset.call(this, element);
  1493. var iconWidth = 20;
  1494. var iconHeight = 20;
  1495. // align the hint element
  1496. switch (position) {
  1497. default:
  1498. case 'top-left':
  1499. hint.style.left = offset.left + 'px';
  1500. hint.style.top = offset.top + 'px';
  1501. break;
  1502. case 'top-right':
  1503. hint.style.left = (offset.left + offset.width - iconWidth) + 'px';
  1504. hint.style.top = offset.top + 'px';
  1505. break;
  1506. case 'bottom-left':
  1507. hint.style.left = offset.left + 'px';
  1508. hint.style.top = (offset.top + offset.height - iconHeight) + 'px';
  1509. break;
  1510. case 'bottom-right':
  1511. hint.style.left = (offset.left + offset.width - iconWidth) + 'px';
  1512. hint.style.top = (offset.top + offset.height - iconHeight) + 'px';
  1513. break;
  1514. case 'middle-left':
  1515. hint.style.left = offset.left + 'px';
  1516. hint.style.top = (offset.top + (offset.height - iconHeight) / 2) + 'px';
  1517. break;
  1518. case 'middle-right':
  1519. hint.style.left = (offset.left + offset.width - iconWidth) + 'px';
  1520. hint.style.top = (offset.top + (offset.height - iconHeight) / 2) + 'px';
  1521. break;
  1522. case 'middle-middle':
  1523. hint.style.left = (offset.left + (offset.width - iconWidth) / 2) + 'px';
  1524. hint.style.top = (offset.top + (offset.height - iconHeight) / 2) + 'px';
  1525. break;
  1526. case 'bottom-middle':
  1527. hint.style.left = (offset.left + (offset.width - iconWidth) / 2) + 'px';
  1528. hint.style.top = (offset.top + offset.height - iconHeight) + 'px';
  1529. break;
  1530. case 'top-middle':
  1531. hint.style.left = (offset.left + (offset.width - iconWidth) / 2) + 'px';
  1532. hint.style.top = offset.top + 'px';
  1533. break;
  1534. }
  1535. }
  1536. /**
  1537. * Triggers when user clicks on the hint element
  1538. *
  1539. * @api private
  1540. * @method _showHintDialog
  1541. * @param {Number} stepId
  1542. */
  1543. function _showHintDialog(stepId) {
  1544. var hintElement = document.querySelector('.introjs-hint[data-step="' + stepId + '"]');
  1545. var item = this._introItems[stepId];
  1546. // call the callback function (if any)
  1547. if (typeof (this._hintClickCallback) !== 'undefined') {
  1548. this._hintClickCallback.call(this, hintElement, item, stepId);
  1549. }
  1550. // remove all open tooltips
  1551. var removedStep = _removeHintTooltip.call(this);
  1552. // to toggle the tooltip
  1553. if (parseInt(removedStep, 10) == stepId) {
  1554. return;
  1555. }
  1556. var tooltipLayer = document.createElement('div');
  1557. var tooltipTextLayer = document.createElement('div');
  1558. var arrowLayer = document.createElement('div');
  1559. var referenceLayer = document.createElement('div');
  1560. tooltipLayer.className = 'introjs-tooltip';
  1561. tooltipLayer.onclick = function (e) {
  1562. //IE9 & Other Browsers
  1563. if (e.stopPropagation) {
  1564. e.stopPropagation();
  1565. }
  1566. //IE8 and Lower
  1567. else {
  1568. e.cancelBubble = true;
  1569. }
  1570. };
  1571. tooltipTextLayer.className = 'introjs-tooltiptext';
  1572. var tooltipWrapper = document.createElement('p');
  1573. tooltipWrapper.innerHTML = item.hint;
  1574. var closeButton = document.createElement('a');
  1575. closeButton.className = 'introjs-button';
  1576. closeButton.innerHTML = this._options.hintButtonLabel;
  1577. closeButton.onclick = _hideHint.bind(this, stepId);
  1578. tooltipTextLayer.appendChild(tooltipWrapper);
  1579. tooltipTextLayer.appendChild(closeButton);
  1580. arrowLayer.className = 'introjs-arrow';
  1581. tooltipLayer.appendChild(arrowLayer);
  1582. tooltipLayer.appendChild(tooltipTextLayer);
  1583. // set current step for _placeTooltip function
  1584. this._currentStep = hintElement.getAttribute('data-step');
  1585. // align reference layer position
  1586. referenceLayer.className = 'introjs-tooltipReferenceLayer introjs-hintReference';
  1587. referenceLayer.setAttribute('data-step', hintElement.getAttribute('data-step'));
  1588. _setHelperLayerPosition.call(this, referenceLayer);
  1589. referenceLayer.appendChild(tooltipLayer);
  1590. document.body.appendChild(referenceLayer);
  1591. //set proper position
  1592. _placeTooltip.call(this, hintElement, tooltipLayer, arrowLayer, null, true);
  1593. }
  1594. /**
  1595. * Get an element position on the page
  1596. * Thanks to `meouw`: http://stackoverflow.com/a/442474/375966
  1597. *
  1598. * @api private
  1599. * @method _getOffset
  1600. * @param {Object} element
  1601. * @returns Element's position info
  1602. */
  1603. function _getOffset(element) {
  1604. var elementPosition = {};
  1605. var body = document.body;
  1606. var docEl = document.documentElement;
  1607. var scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;
  1608. var scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;
  1609. if (element instanceof SVGElement) {
  1610. var x = element.getBoundingClientRect()
  1611. elementPosition.top = x.top + scrollTop;
  1612. elementPosition.width = x.width;
  1613. elementPosition.height = x.height;
  1614. elementPosition.left = x.left + scrollLeft;
  1615. } else {
  1616. //set width
  1617. elementPosition.width = element.offsetWidth;
  1618. //set height
  1619. elementPosition.height = element.offsetHeight;
  1620. //calculate element top and left
  1621. var _x = 0;
  1622. var _y = 0;
  1623. while (element && !isNaN(element.offsetLeft) && !isNaN(element.offsetTop)) {
  1624. _x += element.offsetLeft;
  1625. _y += element.offsetTop;
  1626. element = element.offsetParent;
  1627. }
  1628. //set top
  1629. elementPosition.top = _y;
  1630. //set left
  1631. elementPosition.left = _x;
  1632. }
  1633. return elementPosition;
  1634. }
  1635. /**
  1636. * Gets the current progress percentage
  1637. *
  1638. * @api private
  1639. * @method _getProgress
  1640. * @returns current progress percentage
  1641. */
  1642. function _getProgress() {
  1643. // Steps are 0 indexed
  1644. var currentStep = parseInt((this._currentStep + 1), 10);
  1645. return ((currentStep / this._introItems.length) * 100);
  1646. }
  1647. /**
  1648. * Overwrites obj1's values with obj2's and adds obj2's if non existent in obj1
  1649. * via: http://stackoverflow.com/questions/171251/how-can-i-merge-properties-of-two-javascript-objects-dynamically
  1650. *
  1651. * @param obj1
  1652. * @param obj2
  1653. * @returns obj3 a new object based on obj1 and obj2
  1654. */
  1655. function _mergeOptions(obj1,obj2) {
  1656. var obj3 = {};
  1657. for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
  1658. for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
  1659. return obj3;
  1660. }
  1661. var introJs = function (targetElm) {
  1662. if (typeof (targetElm) === 'object') {
  1663. //Ok, create a new instance
  1664. return new IntroJs(targetElm);
  1665. } else if (typeof (targetElm) === 'string') {
  1666. //select the target element with query selector
  1667. var targetElement = document.querySelector(targetElm);
  1668. if (targetElement) {
  1669. return new IntroJs(targetElement);
  1670. } else {
  1671. throw new Error('There is no element with given selector.');
  1672. }
  1673. } else {
  1674. return new IntroJs(document.body);
  1675. }
  1676. };
  1677. /**
  1678. * Current IntroJs version
  1679. *
  1680. * @property version
  1681. * @type String
  1682. */
  1683. introJs.version = VERSION;
  1684. //Prototype
  1685. introJs.fn = IntroJs.prototype = {
  1686. clone: function () {
  1687. return new IntroJs(this);
  1688. },
  1689. setOption: function(option, value) {
  1690. this._options[option] = value;
  1691. return this;
  1692. },
  1693. setOptions: function(options) {
  1694. this._options = _mergeOptions(this._options, options);
  1695. return this;
  1696. },
  1697. start: function () {
  1698. _introForElement.call(this, this._targetElement);
  1699. return this;
  1700. },
  1701. goToStep: function(step) {
  1702. _goToStep.call(this, step);
  1703. return this;
  1704. },
  1705. addStep: function(options) {
  1706. if (!this._options.steps) {
  1707. this._options.steps = [];
  1708. }
  1709. this._options.steps.push(options);
  1710. return this;
  1711. },
  1712. addSteps: function(steps) {
  1713. if (!steps.length) return;
  1714. for(var index = 0; index < steps.length; index++) {
  1715. this.addStep(steps[index]);
  1716. }
  1717. return this;
  1718. },
  1719. goToStepNumber: function(step) {
  1720. _goToStepNumber.call(this, step);
  1721. return this;
  1722. },
  1723. nextStep: function() {
  1724. _nextStep.call(this);
  1725. return this;
  1726. },
  1727. previousStep: function() {
  1728. _previousStep.call(this);
  1729. return this;
  1730. },
  1731. exit: function(force) {
  1732. _exitIntro.call(this, this._targetElement, force);
  1733. return this;
  1734. },
  1735. refresh: function() {
  1736. _refresh.call(this);
  1737. return this;
  1738. },
  1739. onbeforechange: function(providedCallback) {
  1740. if (typeof (providedCallback) === 'function') {
  1741. this._introBeforeChangeCallback = providedCallback;
  1742. } else {
  1743. throw new Error('Provided callback for onbeforechange was not a function');
  1744. }
  1745. return this;
  1746. },
  1747. onchange: function(providedCallback) {
  1748. if (typeof (providedCallback) === 'function') {
  1749. this._introChangeCallback = providedCallback;
  1750. } else {
  1751. throw new Error('Provided callback for onchange was not a function.');
  1752. }
  1753. return this;
  1754. },
  1755. onafterchange: function(providedCallback) {
  1756. if (typeof (providedCallback) === 'function') {
  1757. this._introAfterChangeCallback = providedCallback;
  1758. } else {
  1759. throw new Error('Provided callback for onafterchange was not a function');
  1760. }
  1761. return this;
  1762. },
  1763. oncomplete: function(providedCallback) {
  1764. if (typeof (providedCallback) === 'function') {
  1765. this._introCompleteCallback = providedCallback;
  1766. } else {
  1767. throw new Error('Provided callback for oncomplete was not a function.');
  1768. }
  1769. return this;
  1770. },
  1771. onhintsadded: function(providedCallback) {
  1772. if (typeof (providedCallback) === 'function') {
  1773. this._hintsAddedCallback = providedCallback;
  1774. } else {
  1775. throw new Error('Provided callback for onhintsadded was not a function.');
  1776. }
  1777. return this;
  1778. },
  1779. onhintclick: function(providedCallback) {
  1780. if (typeof (providedCallback) === 'function') {
  1781. this._hintClickCallback = providedCallback;
  1782. } else {
  1783. throw new Error('Provided callback for onhintclick was not a function.');
  1784. }
  1785. return this;
  1786. },
  1787. onhintclose: function(providedCallback) {
  1788. if (typeof (providedCallback) === 'function') {
  1789. this._hintCloseCallback = providedCallback;
  1790. } else {
  1791. throw new Error('Provided callback for onhintclose was not a function.');
  1792. }
  1793. return this;
  1794. },
  1795. onexit: function(providedCallback) {
  1796. if (typeof (providedCallback) === 'function') {
  1797. this._introExitCallback = providedCallback;
  1798. } else {
  1799. throw new Error('Provided callback for onexit was not a function.');
  1800. }
  1801. return this;
  1802. },
  1803. onbeforeexit: function(providedCallback) {
  1804. if (typeof (providedCallback) === 'function') {
  1805. this._introBeforeExitCallback = providedCallback;
  1806. } else {
  1807. throw new Error('Provided callback for onbeforeexit was not a function.');
  1808. }
  1809. return this;
  1810. },
  1811. addHints: function() {
  1812. _populateHints.call(this, this._targetElement);
  1813. return this;
  1814. },
  1815. hideHint: function (stepId) {
  1816. _hideHint.call(this, stepId);
  1817. return this;
  1818. },
  1819. hideHints: function () {
  1820. _hideHints.call(this);
  1821. return this;
  1822. },
  1823. showHint: function (stepId) {
  1824. _showHint.call(this, stepId);
  1825. return this;
  1826. },
  1827. showHints: function () {
  1828. _showHints.call(this);
  1829. return this;
  1830. },
  1831. removeHints: function () {
  1832. _removeHints.call(this);
  1833. return this;
  1834. },
  1835. removeHint: function (stepId) {
  1836. _removeHint.call(this, stepId);
  1837. return this;
  1838. },
  1839. showHintDialog: function (stepId) {
  1840. _showHintDialog.call(this, stepId);
  1841. return this;
  1842. }
  1843. };
  1844. exports.introJs = introJs;
  1845. return introJs;
  1846. }));