foundation.joyride.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /*jslint unparam: true, browser: true, indent: 2 */
  2. (function ($, window, document, undefined) {
  3. 'use strict';
  4. Foundation.libs.joyride = {
  5. name: 'joyride',
  6. version : '4.2.0',
  7. defaults : {
  8. expose : false, // turn on or off the expose feature
  9. modal : false, // Whether to cover page with modal during the tour
  10. tipLocation : 'bottom', // 'top' or 'bottom' in relation to parent
  11. nubPosition : 'auto', // override on a per tooltip bases
  12. scrollSpeed : 300, // Page scrolling speed in milliseconds, 0 = no scroll animation
  13. timer : 0, // 0 = no timer , all other numbers = timer in milliseconds
  14. startTimerOnClick : true, // true or false - true requires clicking the first button start the timer
  15. startOffset : 0, // the index of the tooltip you want to start on (index of the li)
  16. nextButton : true, // true or false to control whether a next button is used
  17. tipAnimation : 'fade', // 'pop' or 'fade' in each tip
  18. pauseAfter : [], // array of indexes where to pause the tour after
  19. exposed : [], // array of expose elements
  20. tipAnimationFadeSpeed: 300, // when tipAnimation = 'fade' this is speed in milliseconds for the transition
  21. cookieMonster : false, // true or false to control whether cookies are used
  22. cookieName : 'joyride', // Name the cookie you'll use
  23. cookieDomain : false, // Will this cookie be attached to a domain, ie. '.notableapp.com'
  24. cookieExpires : 365, // set when you would like the cookie to expire.
  25. tipContainer : 'body', // Where will the tip be attached
  26. postRideCallback : function (){}, // A method to call once the tour closes (canceled or complete)
  27. postStepCallback : function (){}, // A method to call after each step
  28. preStepCallback : function (){}, // A method to call before each step
  29. preRideCallback : function (){}, // A method to call before the tour starts (passed index, tip, and cloned exposed element)
  30. postExposeCallback : function (){}, // A method to call after an element has been exposed
  31. template : { // HTML segments for tip layout
  32. link : '<a href="#close" class="joyride-close-tip">&times;</a>',
  33. timer : '<div class="joyride-timer-indicator-wrap"><span class="joyride-timer-indicator"></span></div>',
  34. tip : '<div class="joyride-tip-guide"><span class="joyride-nub"></span></div>',
  35. wrapper : '<div class="joyride-content-wrapper"></div>',
  36. button : '<a href="#" class="small button joyride-next-tip"></a>',
  37. modal : '<div class="joyride-modal-bg"></div>',
  38. expose : '<div class="joyride-expose-wrapper"></div>',
  39. exposeCover: '<div class="joyride-expose-cover"></div>'
  40. },
  41. exposeAddClass : '' // One or more space-separated class names to be added to exposed element
  42. },
  43. settings : {},
  44. init : function (scope, method, options) {
  45. this.scope = scope || this.scope;
  46. Foundation.inherit(this, 'throttle data_options scrollTo scrollLeft delay');
  47. if (typeof method === 'object') {
  48. $.extend(true, this.settings, this.defaults, method);
  49. } else {
  50. $.extend(true, this.settings, this.defaults, options);
  51. }
  52. if (typeof method != 'string') {
  53. if (!this.settings.init) this.events();
  54. return this.settings.init;
  55. } else {
  56. return this[method].call(this, options);
  57. }
  58. },
  59. events : function () {
  60. var self = this;
  61. $(this.scope)
  62. .on('click.joyride', '.joyride-next-tip, .joyride-modal-bg', function (e) {
  63. e.preventDefault();
  64. if (this.settings.$li.next().length < 1) {
  65. this.end();
  66. } else if (this.settings.timer > 0) {
  67. clearTimeout(this.settings.automate);
  68. this.hide();
  69. this.show();
  70. this.startTimer();
  71. } else {
  72. this.hide();
  73. this.show();
  74. }
  75. }.bind(this))
  76. .on('click.joyride', '.joyride-close-tip', function (e) {
  77. e.preventDefault();
  78. this.end();
  79. }.bind(this));
  80. $(window).on('resize.fndtn.joyride', self.throttle(function () {
  81. if ($('[data-joyride]').length > 0 && self.settings.$next_tip) {
  82. if (self.settings.exposed.length > 0) {
  83. var $els = $(self.settings.exposed);
  84. $els.each(function () {
  85. var $this = $(this);
  86. self.un_expose($this);
  87. self.expose($this);
  88. });
  89. }
  90. if (self.is_phone()) {
  91. self.pos_phone();
  92. } else {
  93. self.pos_default(false, true);
  94. }
  95. }
  96. }, 100));
  97. this.settings.init = true;
  98. },
  99. start : function () {
  100. var self = this,
  101. $this = $(this.scope).find('[data-joyride]'),
  102. integer_settings = ['timer', 'scrollSpeed', 'startOffset', 'tipAnimationFadeSpeed', 'cookieExpires'],
  103. int_settings_count = integer_settings.length;
  104. if (!this.settings.init) this.init();
  105. // non configureable settings
  106. this.settings.$content_el = $this;
  107. this.settings.$body = $(this.settings.tipContainer);
  108. this.settings.body_offset = $(this.settings.tipContainer).position();
  109. this.settings.$tip_content = this.settings.$content_el.find('> li');
  110. this.settings.paused = false;
  111. this.settings.attempts = 0;
  112. this.settings.tipLocationPatterns = {
  113. top: ['bottom'],
  114. bottom: [], // bottom should not need to be repositioned
  115. left: ['right', 'top', 'bottom'],
  116. right: ['left', 'top', 'bottom']
  117. };
  118. // can we create cookies?
  119. if (typeof $.cookie !== 'function') {
  120. this.settings.cookieMonster = false;
  121. }
  122. // generate the tips and insert into dom.
  123. if (!this.settings.cookieMonster || this.settings.cookieMonster && $.cookie(this.settings.cookieName) === null) {
  124. this.settings.$tip_content.each(function (index) {
  125. var $this = $(this);
  126. $.extend(true, self.settings, self.data_options($this));
  127. // Make sure that settings parsed from data_options are integers where necessary
  128. for (var i = int_settings_count - 1; i >= 0; i--) {
  129. self.settings[integer_settings[i]] = parseInt(self.settings[integer_settings[i]], 10);
  130. }
  131. self.create({$li : $this, index : index});
  132. });
  133. // show first tip
  134. if (!this.settings.startTimerOnClick && this.settings.timer > 0) {
  135. this.show('init');
  136. this.startTimer();
  137. } else {
  138. this.show('init');
  139. }
  140. }
  141. },
  142. resume : function () {
  143. this.set_li();
  144. this.show();
  145. },
  146. tip_template : function (opts) {
  147. var $blank, content;
  148. opts.tip_class = opts.tip_class || '';
  149. $blank = $(this.settings.template.tip).addClass(opts.tip_class);
  150. content = $.trim($(opts.li).html()) +
  151. this.button_text(opts.button_text) +
  152. this.settings.template.link +
  153. this.timer_instance(opts.index);
  154. $blank.append($(this.settings.template.wrapper));
  155. $blank.first().attr('data-index', opts.index);
  156. $('.joyride-content-wrapper', $blank).append(content);
  157. return $blank[0];
  158. },
  159. timer_instance : function (index) {
  160. var txt;
  161. if ((index === 0 && this.settings.startTimerOnClick && this.settings.timer > 0) || this.settings.timer === 0) {
  162. txt = '';
  163. } else {
  164. txt = this.outerHTML($(this.settings.template.timer)[0]);
  165. }
  166. return txt;
  167. },
  168. button_text : function (txt) {
  169. if (this.settings.nextButton) {
  170. txt = $.trim(txt) || 'Next';
  171. txt = this.outerHTML($(this.settings.template.button).append(txt)[0]);
  172. } else {
  173. txt = '';
  174. }
  175. return txt;
  176. },
  177. create : function (opts) {
  178. var buttonText = opts.$li.attr('data-button') || opts.$li.attr('data-text'),
  179. tipClass = opts.$li.attr('class'),
  180. $tip_content = $(this.tip_template({
  181. tip_class : tipClass,
  182. index : opts.index,
  183. button_text : buttonText,
  184. li : opts.$li
  185. }));
  186. $(this.settings.tipContainer).append($tip_content);
  187. },
  188. show : function (init) {
  189. var $timer = null;
  190. // are we paused?
  191. if (this.settings.$li === undefined
  192. || ($.inArray(this.settings.$li.index(), this.settings.pauseAfter) === -1)) {
  193. // don't go to the next li if the tour was paused
  194. if (this.settings.paused) {
  195. this.settings.paused = false;
  196. } else {
  197. this.set_li(init);
  198. }
  199. this.settings.attempts = 0;
  200. if (this.settings.$li.length && this.settings.$target.length > 0) {
  201. if (init) { //run when we first start
  202. this.settings.preRideCallback(this.settings.$li.index(), this.settings.$next_tip);
  203. if (this.settings.modal) {
  204. this.show_modal();
  205. }
  206. }
  207. this.settings.preStepCallback(this.settings.$li.index(), this.settings.$next_tip);
  208. if (this.settings.modal && this.settings.expose) {
  209. this.expose();
  210. }
  211. this.settings.tipSettings = $.extend(this.settings, this.data_options(this.settings.$li));
  212. this.settings.timer = parseInt(this.settings.timer, 10);
  213. this.settings.tipSettings.tipLocationPattern = this.settings.tipLocationPatterns[this.settings.tipSettings.tipLocation];
  214. // scroll if not modal
  215. if (!/body/i.test(this.settings.$target.selector)) {
  216. this.scroll_to();
  217. }
  218. if (this.is_phone()) {
  219. this.pos_phone(true);
  220. } else {
  221. this.pos_default(true);
  222. }
  223. $timer = this.settings.$next_tip.find('.joyride-timer-indicator');
  224. if (/pop/i.test(this.settings.tipAnimation)) {
  225. $timer.width(0);
  226. if (this.settings.timer > 0) {
  227. this.settings.$next_tip.show();
  228. this.delay(function () {
  229. $timer.animate({
  230. width: $timer.parent().width()
  231. }, this.settings.timer, 'linear');
  232. }.bind(this), this.settings.tipAnimationFadeSpeed);
  233. } else {
  234. this.settings.$next_tip.show();
  235. }
  236. } else if (/fade/i.test(this.settings.tipAnimation)) {
  237. $timer.width(0);
  238. if (this.settings.timer > 0) {
  239. this.settings.$next_tip
  240. .fadeIn(this.settings.tipAnimationFadeSpeed)
  241. .show();
  242. this.delay(function () {
  243. $timer.animate({
  244. width: $timer.parent().width()
  245. }, this.settings.timer, 'linear');
  246. }.bind(this), this.settings.tipAnimationFadeSpeed);
  247. } else {
  248. this.settings.$next_tip.fadeIn(this.settings.tipAnimationFadeSpeed);
  249. }
  250. }
  251. this.settings.$current_tip = this.settings.$next_tip;
  252. // skip non-existant targets
  253. } else if (this.settings.$li && this.settings.$target.length < 1) {
  254. this.show();
  255. } else {
  256. this.end();
  257. }
  258. } else {
  259. this.settings.paused = true;
  260. }
  261. },
  262. is_phone : function () {
  263. if (Modernizr) {
  264. return Modernizr.mq('only screen and (max-width: 767px)') || $('.lt-ie9').length > 0;
  265. }
  266. return (this.settings.$window.width() < 767);
  267. },
  268. hide : function () {
  269. if (this.settings.modal && this.settings.expose) {
  270. this.un_expose();
  271. }
  272. if (!this.settings.modal) {
  273. $('.joyride-modal-bg').hide();
  274. }
  275. this.settings.$current_tip.hide();
  276. this.settings.postStepCallback(this.settings.$li.index(),
  277. this.settings.$current_tip);
  278. },
  279. set_li : function (init) {
  280. if (init) {
  281. this.settings.$li = this.settings.$tip_content.eq(this.settings.startOffset);
  282. this.set_next_tip();
  283. this.settings.$current_tip = this.settings.$next_tip;
  284. } else {
  285. this.settings.$li = this.settings.$li.next();
  286. this.set_next_tip();
  287. }
  288. this.set_target();
  289. },
  290. set_next_tip : function () {
  291. this.settings.$next_tip = $(".joyride-tip-guide[data-index='" + this.settings.$li.index() + "']");
  292. this.settings.$next_tip.data('closed', '');
  293. },
  294. set_target : function () {
  295. var cl = this.settings.$li.attr('data-class'),
  296. id = this.settings.$li.attr('data-id'),
  297. $sel = function () {
  298. if (id) {
  299. return $(document.getElementById(id));
  300. } else if (cl) {
  301. return $('.' + cl).first();
  302. } else {
  303. return $('body');
  304. }
  305. };
  306. this.settings.$target = $sel();
  307. },
  308. scroll_to : function () {
  309. var window_half, tipOffset;
  310. window_half = $(window).height() / 2;
  311. tipOffset = Math.ceil(this.settings.$target.offset().top - window_half + this.outerHeight(this.settings.$next_tip));
  312. if (tipOffset > 0) {
  313. this.scrollTo($('html, body'), tipOffset, this.settings.scrollSpeed);
  314. }
  315. },
  316. paused : function () {
  317. return ($.inArray((this.settings.$li.index() + 1), this.settings.pauseAfter) === -1);
  318. },
  319. restart : function () {
  320. this.hide();
  321. this.settings.$li = undefined;
  322. this.show('init');
  323. },
  324. pos_default : function (init, resizing) {
  325. var half_fold = Math.ceil($(window).height() / 2),
  326. tip_position = this.settings.$next_tip.offset(),
  327. $nub = this.settings.$next_tip.find('.joyride-nub'),
  328. nub_width = Math.ceil(this.outerWidth($nub) / 2),
  329. nub_height = Math.ceil(this.outerHeight($nub) / 2),
  330. toggle = init || false;
  331. // tip must not be "display: none" to calculate position
  332. if (toggle) {
  333. this.settings.$next_tip.css('visibility', 'hidden');
  334. this.settings.$next_tip.show();
  335. }
  336. if (typeof resizing === 'undefined') {
  337. resizing = false;
  338. }
  339. if (!/body/i.test(this.settings.$target.selector)) {
  340. if (this.bottom()) {
  341. var leftOffset = this.settings.$target.offset().left;
  342. if (Foundation.rtl) {
  343. leftOffset = this.settings.$target.offset().width - this.settings.$next_tip.width() + leftOffset;
  344. }
  345. this.settings.$next_tip.css({
  346. top: (this.settings.$target.offset().top + nub_height + this.outerHeight(this.settings.$target)),
  347. left: leftOffset});
  348. this.nub_position($nub, this.settings.tipSettings.nubPosition, 'top');
  349. } else if (this.top()) {
  350. var leftOffset = this.settings.$target.offset().left;
  351. if (Foundation.rtl) {
  352. leftOffset = this.settings.$target.offset().width - this.settings.$next_tip.width() + leftOffset;
  353. }
  354. this.settings.$next_tip.css({
  355. top: (this.settings.$target.offset().top - this.outerHeight(this.settings.$next_tip) - nub_height),
  356. left: leftOffset});
  357. this.nub_position($nub, this.settings.tipSettings.nubPosition, 'bottom');
  358. } else if (this.right()) {
  359. this.settings.$next_tip.css({
  360. top: this.settings.$target.offset().top,
  361. left: (this.outerWidth(this.settings.$target) + this.settings.$target.offset().left + nub_width)});
  362. this.nub_position($nub, this.settings.tipSettings.nubPosition, 'left');
  363. } else if (this.left()) {
  364. this.settings.$next_tip.css({
  365. top: this.settings.$target.offset().top,
  366. left: (this.settings.$target.offset().left - this.outerWidth(this.settings.$next_tip) - nub_width)});
  367. this.nub_position($nub, this.settings.tipSettings.nubPosition, 'right');
  368. }
  369. if (!this.visible(this.corners(this.settings.$next_tip)) && this.settings.attempts < this.settings.tipSettings.tipLocationPattern.length) {
  370. $nub.removeClass('bottom')
  371. .removeClass('top')
  372. .removeClass('right')
  373. .removeClass('left');
  374. this.settings.tipSettings.tipLocation = this.settings.tipSettings.tipLocationPattern[this.settings.attempts];
  375. this.settings.attempts++;
  376. this.pos_default();
  377. }
  378. } else if (this.settings.$li.length) {
  379. this.pos_modal($nub);
  380. }
  381. if (toggle) {
  382. this.settings.$next_tip.hide();
  383. this.settings.$next_tip.css('visibility', 'visible');
  384. }
  385. },
  386. pos_phone : function (init) {
  387. var tip_height = this.outerHeight(this.settings.$next_tip),
  388. tip_offset = this.settings.$next_tip.offset(),
  389. target_height = this.outerHeight(this.settings.$target),
  390. $nub = $('.joyride-nub', this.settings.$next_tip),
  391. nub_height = Math.ceil(this.outerHeight($nub) / 2),
  392. toggle = init || false;
  393. $nub.removeClass('bottom')
  394. .removeClass('top')
  395. .removeClass('right')
  396. .removeClass('left');
  397. if (toggle) {
  398. this.settings.$next_tip.css('visibility', 'hidden');
  399. this.settings.$next_tip.show();
  400. }
  401. if (!/body/i.test(this.settings.$target.selector)) {
  402. if (this.top()) {
  403. this.settings.$next_tip.offset({top: this.settings.$target.offset().top - tip_height - nub_height});
  404. $nub.addClass('bottom');
  405. } else {
  406. this.settings.$next_tip.offset({top: this.settings.$target.offset().top + target_height + nub_height});
  407. $nub.addClass('top');
  408. }
  409. } else if (this.settings.$li.length) {
  410. this.pos_modal($nub);
  411. }
  412. if (toggle) {
  413. this.settings.$next_tip.hide();
  414. this.settings.$next_tip.css('visibility', 'visible');
  415. }
  416. },
  417. pos_modal : function ($nub) {
  418. this.center();
  419. $nub.hide();
  420. this.show_modal();
  421. },
  422. show_modal : function () {
  423. if (!this.settings.$next_tip.data('closed')) {
  424. var joyridemodalbg = $('.joyride-modal-bg');
  425. if (joyridemodalbg.length < 1) {
  426. $('body').append(this.settings.template.modal).show();
  427. }
  428. if (/pop/i.test(this.settings.tipAnimation)) {
  429. joyridemodalbg.show();
  430. } else {
  431. joyridemodalbg.fadeIn(this.settings.tipAnimationFadeSpeed);
  432. }
  433. }
  434. },
  435. expose : function () {
  436. var expose,
  437. exposeCover,
  438. el,
  439. origCSS,
  440. origClasses,
  441. randId = 'expose-'+Math.floor(Math.random()*10000);
  442. if (arguments.length > 0 && arguments[0] instanceof $) {
  443. el = arguments[0];
  444. } else if(this.settings.$target && !/body/i.test(this.settings.$target.selector)){
  445. el = this.settings.$target;
  446. } else {
  447. return false;
  448. }
  449. if(el.length < 1){
  450. if(window.console){
  451. console.error('element not valid', el);
  452. }
  453. return false;
  454. }
  455. expose = $(this.settings.template.expose);
  456. this.settings.$body.append(expose);
  457. expose.css({
  458. top: el.offset().top,
  459. left: el.offset().left,
  460. width: this.outerWidth(el, true),
  461. height: this.outerHeight(el, true)
  462. });
  463. exposeCover = $(this.settings.template.exposeCover);
  464. origCSS = {
  465. zIndex: el.css('z-index'),
  466. position: el.css('position')
  467. };
  468. origClasses = el.attr('class') == null ? '' : el.attr('class');
  469. el.css('z-index',parseInt(expose.css('z-index'))+1);
  470. if (origCSS.position == 'static') {
  471. el.css('position','relative');
  472. }
  473. el.data('expose-css',origCSS);
  474. el.data('orig-class', origClasses);
  475. el.attr('class', origClasses + ' ' + this.settings.exposeAddClass);
  476. exposeCover.css({
  477. top: el.offset().top,
  478. left: el.offset().left,
  479. width: this.outerWidth(el, true),
  480. height: this.outerHeight(el, true)
  481. });
  482. this.settings.$body.append(exposeCover);
  483. expose.addClass(randId);
  484. exposeCover.addClass(randId);
  485. el.data('expose', randId);
  486. this.settings.postExposeCallback(this.settings.$li.index(), this.settings.$next_tip, el);
  487. this.add_exposed(el);
  488. },
  489. un_expose : function () {
  490. var exposeId,
  491. el,
  492. expose ,
  493. origCSS,
  494. origClasses,
  495. clearAll = false;
  496. if (arguments.length > 0 && arguments[0] instanceof $) {
  497. el = arguments[0];
  498. } else if(this.settings.$target && !/body/i.test(this.settings.$target.selector)){
  499. el = this.settings.$target;
  500. } else {
  501. return false;
  502. }
  503. if(el.length < 1){
  504. if (window.console) {
  505. console.error('element not valid', el);
  506. }
  507. return false;
  508. }
  509. exposeId = el.data('expose');
  510. expose = $('.' + exposeId);
  511. if (arguments.length > 1) {
  512. clearAll = arguments[1];
  513. }
  514. if (clearAll === true) {
  515. $('.joyride-expose-wrapper,.joyride-expose-cover').remove();
  516. } else {
  517. expose.remove();
  518. }
  519. origCSS = el.data('expose-css');
  520. if (origCSS.zIndex == 'auto') {
  521. el.css('z-index', '');
  522. } else {
  523. el.css('z-index', origCSS.zIndex);
  524. }
  525. if (origCSS.position != el.css('position')) {
  526. if(origCSS.position == 'static') {// this is default, no need to set it.
  527. el.css('position', '');
  528. } else {
  529. el.css('position', origCSS.position);
  530. }
  531. }
  532. origClasses = el.data('orig-class');
  533. el.attr('class', origClasses);
  534. el.removeData('orig-classes');
  535. el.removeData('expose');
  536. el.removeData('expose-z-index');
  537. this.remove_exposed(el);
  538. },
  539. add_exposed: function(el){
  540. this.settings.exposed = this.settings.exposed || [];
  541. if (el instanceof $ || typeof el === 'object') {
  542. this.settings.exposed.push(el[0]);
  543. } else if (typeof el == 'string') {
  544. this.settings.exposed.push(el);
  545. }
  546. },
  547. remove_exposed: function(el){
  548. var search, count;
  549. if (el instanceof $) {
  550. search = el[0]
  551. } else if (typeof el == 'string'){
  552. search = el;
  553. }
  554. this.settings.exposed = this.settings.exposed || [];
  555. count = this.settings.exposed.length;
  556. for (var i=0; i < count; i++) {
  557. if (this.settings.exposed[i] == search) {
  558. this.settings.exposed.splice(i, 1);
  559. return;
  560. }
  561. }
  562. },
  563. center : function () {
  564. var $w = $(window);
  565. this.settings.$next_tip.css({
  566. top : ((($w.height() - this.outerHeight(this.settings.$next_tip)) / 2) + $w.scrollTop()),
  567. left : ((($w.width() - this.outerWidth(this.settings.$next_tip)) / 2) + this.scrollLeft($w))
  568. });
  569. return true;
  570. },
  571. bottom : function () {
  572. return /bottom/i.test(this.settings.tipSettings.tipLocation);
  573. },
  574. top : function () {
  575. return /top/i.test(this.settings.tipSettings.tipLocation);
  576. },
  577. right : function () {
  578. return /right/i.test(this.settings.tipSettings.tipLocation);
  579. },
  580. left : function () {
  581. return /left/i.test(this.settings.tipSettings.tipLocation);
  582. },
  583. corners : function (el) {
  584. var w = $(window),
  585. window_half = w.height() / 2,
  586. //using this to calculate since scroll may not have finished yet.
  587. tipOffset = Math.ceil(this.settings.$target.offset().top - window_half + this.settings.$next_tip.outerHeight()),
  588. right = w.width() + this.scrollLeft(w),
  589. offsetBottom = w.height() + tipOffset,
  590. bottom = w.height() + w.scrollTop(),
  591. top = w.scrollTop();
  592. if (tipOffset < top) {
  593. if (tipOffset < 0) {
  594. top = 0;
  595. } else {
  596. top = tipOffset;
  597. }
  598. }
  599. if (offsetBottom > bottom) {
  600. bottom = offsetBottom;
  601. }
  602. return [
  603. el.offset().top < top,
  604. right < el.offset().left + el.outerWidth(),
  605. bottom < el.offset().top + el.outerHeight(),
  606. this.scrollLeft(w) > el.offset().left
  607. ];
  608. },
  609. visible : function (hidden_corners) {
  610. var i = hidden_corners.length;
  611. while (i--) {
  612. if (hidden_corners[i]) return false;
  613. }
  614. return true;
  615. },
  616. nub_position : function (nub, pos, def) {
  617. if (pos === 'auto') {
  618. nub.addClass(def);
  619. } else {
  620. nub.addClass(pos);
  621. }
  622. },
  623. startTimer : function () {
  624. if (this.settings.$li.length) {
  625. this.settings.automate = setTimeout(function () {
  626. this.hide();
  627. this.show();
  628. this.startTimer();
  629. }.bind(this), this.settings.timer);
  630. } else {
  631. clearTimeout(this.settings.automate);
  632. }
  633. },
  634. end : function () {
  635. if (this.settings.cookieMonster) {
  636. $.cookie(this.settings.cookieName, 'ridden', { expires: this.settings.cookieExpires, domain: this.settings.cookieDomain });
  637. }
  638. if (this.settings.timer > 0) {
  639. clearTimeout(this.settings.automate);
  640. }
  641. if (this.settings.modal && this.settings.expose) {
  642. this.un_expose();
  643. }
  644. this.settings.$next_tip.data('closed', true);
  645. $('.joyride-modal-bg').hide();
  646. this.settings.$current_tip.hide();
  647. this.settings.postStepCallback(this.settings.$li.index(), this.settings.$current_tip);
  648. this.settings.postRideCallback(this.settings.$li.index(), this.settings.$current_tip);
  649. $('.joyride-tip-guide').remove();
  650. },
  651. outerHTML : function (el) {
  652. // support FireFox < 11
  653. return el.outerHTML || new XMLSerializer().serializeToString(el);
  654. },
  655. off : function () {
  656. $(this.scope).off('.joyride');
  657. $(window).off('.joyride');
  658. $('.joyride-close-tip, .joyride-next-tip, .joyride-modal-bg').off('.joyride');
  659. $('.joyride-tip-guide, .joyride-modal-bg').remove();
  660. clearTimeout(this.settings.automate);
  661. this.settings = {};
  662. },
  663. reflow : function () {}
  664. };
  665. }(Foundation.zj, this, this.document));