foundation.joyride.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. ;(function ($, window, document, undefined) {
  2. 'use strict';
  3. var Modernizr = Modernizr || false;
  4. Foundation.libs.joyride = {
  5. name : 'joyride',
  6. version : '5.0.0',
  7. defaults : {
  8. expose : false, // turn on or off the expose feature
  9. modal : true, // Whether to cover page with modal during the tour
  10. tip_location : 'bottom', // 'top' or 'bottom' in relation to parent
  11. nub_position : 'auto', // override on a per tooltip bases
  12. scroll_speed : 1500, // Page scrolling speed in milliseconds, 0 = no scroll animation
  13. scroll_animation : 'linear', // supports 'swing' and 'linear', extend with jQuery UI.
  14. timer : 0, // 0 = no timer , all other numbers = timer in milliseconds
  15. start_timer_on_click : true, // true or false - true requires clicking the first button start the timer
  16. start_offset : 0, // the index of the tooltip you want to start on (index of the li)
  17. next_button : true, // true or false to control whether a next button is used
  18. tip_animation : 'fade', // 'pop' or 'fade' in each tip
  19. pause_after : [], // array of indexes where to pause the tour after
  20. exposed : [], // array of expose elements
  21. tip_animation_fade_speed: 300, // when tipAnimation = 'fade' this is speed in milliseconds for the transition
  22. cookie_monster : false, // true or false to control whether cookies are used
  23. cookie_name : 'joyride', // Name the cookie you'll use
  24. cookie_domain : false, // Will this cookie be attached to a domain, ie. '.notableapp.com'
  25. cookie_expires : 365, // set when you would like the cookie to expire.
  26. tip_container : 'body', // Where will the tip be attached
  27. tip_location_patterns : {
  28. top: ['bottom'],
  29. bottom: [], // bottom should not need to be repositioned
  30. left: ['right', 'top', 'bottom'],
  31. right: ['left', 'top', 'bottom']
  32. },
  33. post_ride_callback : function (){}, // A method to call once the tour closes (canceled or complete)
  34. post_step_callback : function (){}, // A method to call after each step
  35. pre_step_callback : function (){}, // A method to call before each step
  36. pre_ride_callback : function (){}, // A method to call before the tour starts (passed index, tip, and cloned exposed element)
  37. post_expose_callback : function (){}, // A method to call after an element has been exposed
  38. template : { // HTML segments for tip layout
  39. link : '<a href="#close" class="joyride-close-tip">&times;</a>',
  40. timer : '<div class="joyride-timer-indicator-wrap"><span class="joyride-timer-indicator"></span></div>',
  41. tip : '<div class="joyride-tip-guide"><span class="joyride-nub"></span></div>',
  42. wrapper : '<div class="joyride-content-wrapper"></div>',
  43. button : '<a href="#" class="small button joyride-next-tip"></a>',
  44. modal : '<div class="joyride-modal-bg"></div>',
  45. expose : '<div class="joyride-expose-wrapper"></div>',
  46. expose_cover: '<div class="joyride-expose-cover"></div>'
  47. },
  48. expose_add_class : '' // One or more space-separated class names to be added to exposed element
  49. },
  50. init : function (scope, method, options) {
  51. Foundation.inherit(this, 'throttle delay');
  52. this.settings = this.defaults;
  53. this.bindings(method, options)
  54. },
  55. events : function () {
  56. var self = this;
  57. $(this.scope)
  58. .off('.joyride')
  59. .on('click.fndtn.joyride', '.joyride-next-tip, .joyride-modal-bg', function (e) {
  60. e.preventDefault();
  61. if (this.settings.$li.next().length < 1) {
  62. this.end();
  63. } else if (this.settings.timer > 0) {
  64. clearTimeout(this.settings.automate);
  65. this.hide();
  66. this.show();
  67. this.startTimer();
  68. } else {
  69. this.hide();
  70. this.show();
  71. }
  72. }.bind(this))
  73. .on('click.fndtn.joyride', '.joyride-close-tip', function (e) {
  74. e.preventDefault();
  75. this.end();
  76. }.bind(this));
  77. $(window)
  78. .off('.joyride')
  79. .on('resize.fndtn.joyride', self.throttle(function () {
  80. if ($('[data-joyride]').length > 0 && self.settings.$next_tip) {
  81. if (self.settings.exposed.length > 0) {
  82. var $els = $(self.settings.exposed);
  83. $els.each(function () {
  84. var $this = $(this);
  85. self.un_expose($this);
  86. self.expose($this);
  87. });
  88. }
  89. if (self.is_phone()) {
  90. self.pos_phone();
  91. } else {
  92. self.pos_default(false, true);
  93. }
  94. }
  95. }, 100));
  96. },
  97. start : function () {
  98. var self = this,
  99. $this = $('[data-joyride]', this.scope),
  100. integer_settings = ['timer', 'scrollSpeed', 'startOffset', 'tipAnimationFadeSpeed', 'cookieExpires'],
  101. int_settings_count = integer_settings.length;
  102. if (!$this.length > 0) return;
  103. if (!this.settings.init) this.events();
  104. this.settings = $this.data('joyride-init');
  105. // non configureable settings
  106. this.settings.$content_el = $this;
  107. this.settings.$body = $(this.settings.tip_container);
  108. this.settings.body_offset = $(this.settings.tip_container).position();
  109. this.settings.$tip_content = this.settings.$content_el.find('> li');
  110. this.settings.paused = false;
  111. this.settings.attempts = 0;
  112. // can we create cookies?
  113. if (typeof $.cookie !== 'function') {
  114. this.settings.cookie_monster = false;
  115. }
  116. // generate the tips and insert into dom.
  117. if (!this.settings.cookie_monster || this.settings.cookie_monster && $.cookie(this.settings.cookie_name) === null) {
  118. this.settings.$tip_content.each(function (index) {
  119. var $this = $(this);
  120. this.settings = $.extend({}, self.defaults, self.data_options($this))
  121. // Make sure that settings parsed from data_options are integers where necessary
  122. for (var i = int_settings_count - 1; i >= 0; i--) {
  123. self.settings[integer_settings[i]] = parseInt(self.settings[integer_settings[i]], 10);
  124. }
  125. self.create({$li : $this, index : index});
  126. });
  127. // show first tip
  128. if (!this.settings.start_timer_on_click && this.settings.timer > 0) {
  129. this.show('init');
  130. this.startTimer();
  131. } else {
  132. this.show('init');
  133. }
  134. }
  135. },
  136. resume : function () {
  137. this.set_li();
  138. this.show();
  139. },
  140. tip_template : function (opts) {
  141. var $blank, content;
  142. opts.tip_class = opts.tip_class || '';
  143. $blank = $(this.settings.template.tip).addClass(opts.tip_class);
  144. content = $.trim($(opts.li).html()) +
  145. this.button_text(opts.button_text) +
  146. this.settings.template.link +
  147. this.timer_instance(opts.index);
  148. $blank.append($(this.settings.template.wrapper));
  149. $blank.first().attr('data-index', opts.index);
  150. $('.joyride-content-wrapper', $blank).append(content);
  151. return $blank[0];
  152. },
  153. timer_instance : function (index) {
  154. var txt;
  155. if ((index === 0 && this.settings.start_timer_on_click && this.settings.timer > 0) || this.settings.timer === 0) {
  156. txt = '';
  157. } else {
  158. txt = $(this.settings.template.timer)[0].outerHTML;
  159. }
  160. return txt;
  161. },
  162. button_text : function (txt) {
  163. if (this.settings.next_button) {
  164. txt = $.trim(txt) || 'Next';
  165. txt = $(this.settings.template.button).append(txt)[0].outerHTML;
  166. } else {
  167. txt = '';
  168. }
  169. return txt;
  170. },
  171. create : function (opts) {
  172. var buttonText = opts.$li.attr('data-button') || opts.$li.attr('data-text'),
  173. tipClass = opts.$li.attr('class'),
  174. $tip_content = $(this.tip_template({
  175. tip_class : tipClass,
  176. index : opts.index,
  177. button_text : buttonText,
  178. li : opts.$li
  179. }));
  180. $(this.settings.tip_container).append($tip_content);
  181. },
  182. show : function (init) {
  183. var $timer = null;
  184. // are we paused?
  185. if (this.settings.$li === undefined
  186. || ($.inArray(this.settings.$li.index(), this.settings.pause_after) === -1)) {
  187. // don't go to the next li if the tour was paused
  188. if (this.settings.paused) {
  189. this.settings.paused = false;
  190. } else {
  191. this.set_li(init);
  192. }
  193. this.settings.attempts = 0;
  194. if (this.settings.$li.length && this.settings.$target.length > 0) {
  195. if (init) { //run when we first start
  196. this.settings.pre_ride_callback(this.settings.$li.index(), this.settings.$next_tip);
  197. if (this.settings.modal) {
  198. this.show_modal();
  199. }
  200. }
  201. this.settings.pre_step_callback(this.settings.$li.index(), this.settings.$next_tip);
  202. if (this.settings.modal && this.settings.expose) {
  203. this.expose();
  204. }
  205. this.settings.tip_settings = $.extend({}, this.settings, this.data_options(this.settings.$li));
  206. this.settings.timer = parseInt(this.settings.timer, 10);
  207. this.settings.tip_settings.tip_location_pattern = this.settings.tip_location_patterns[this.settings.tip_settings.tip_location];
  208. // scroll if not modal
  209. if (!/body/i.test(this.settings.$target.selector)) {
  210. this.scroll_to();
  211. }
  212. if (this.is_phone()) {
  213. this.pos_phone(true);
  214. } else {
  215. this.pos_default(true);
  216. }
  217. $timer = this.settings.$next_tip.find('.joyride-timer-indicator');
  218. if (/pop/i.test(this.settings.tip_animation)) {
  219. $timer.width(0);
  220. if (this.settings.timer > 0) {
  221. this.settings.$next_tip.show();
  222. this.delay(function () {
  223. $timer.animate({
  224. width: $timer.parent().width()
  225. }, this.settings.timer, 'linear');
  226. }.bind(this), this.settings.tip_animation_fade_speed);
  227. } else {
  228. this.settings.$next_tip.show();
  229. }
  230. } else if (/fade/i.test(this.settings.tip_animation)) {
  231. $timer.width(0);
  232. if (this.settings.timer > 0) {
  233. this.settings.$next_tip
  234. .fadeIn(this.settings.tip_animation_fade_speed)
  235. .show();
  236. this.delay(function () {
  237. $timer.animate({
  238. width: $timer.parent().width()
  239. }, this.settings.timer, 'linear');
  240. }.bind(this), this.settings.tip_animation_fadeSpeed);
  241. } else {
  242. this.settings.$next_tip.fadeIn(this.settings.tip_animation_fade_speed);
  243. }
  244. }
  245. this.settings.$current_tip = this.settings.$next_tip;
  246. // skip non-existant targets
  247. } else if (this.settings.$li && this.settings.$target.length < 1) {
  248. this.show();
  249. } else {
  250. this.end();
  251. }
  252. } else {
  253. this.settings.paused = true;
  254. }
  255. },
  256. is_phone : function () {
  257. return matchMedia(Foundation.media_queries.small).matches &&
  258. !matchMedia(Foundation.media_queries.medium).matches;
  259. },
  260. hide : function () {
  261. if (this.settings.modal && this.settings.expose) {
  262. this.un_expose();
  263. }
  264. if (!this.settings.modal) {
  265. $('.joyride-modal-bg').hide();
  266. }
  267. // Prevent scroll bouncing...wait to remove from layout
  268. this.settings.$current_tip.css('visibility', 'hidden');
  269. setTimeout($.proxy(function() {
  270. this.hide();
  271. this.css('visibility', 'visible');
  272. }, this.settings.$current_tip), 0);
  273. this.settings.post_step_callback(this.settings.$li.index(),
  274. this.settings.$current_tip);
  275. },
  276. set_li : function (init) {
  277. if (init) {
  278. this.settings.$li = this.settings.$tip_content.eq(this.settings.start_offset);
  279. this.set_next_tip();
  280. this.settings.$current_tip = this.settings.$next_tip;
  281. } else {
  282. this.settings.$li = this.settings.$li.next();
  283. this.set_next_tip();
  284. }
  285. this.set_target();
  286. },
  287. set_next_tip : function () {
  288. this.settings.$next_tip = $(".joyride-tip-guide").eq(this.settings.$li.index());
  289. this.settings.$next_tip.data('closed', '');
  290. },
  291. set_target : function () {
  292. var cl = this.settings.$li.attr('data-class'),
  293. id = this.settings.$li.attr('data-id'),
  294. $sel = function () {
  295. if (id) {
  296. return $(document.getElementById(id));
  297. } else if (cl) {
  298. return $('.' + cl).first();
  299. } else {
  300. return $('body');
  301. }
  302. };
  303. this.settings.$target = $sel();
  304. },
  305. scroll_to : function () {
  306. var window_half, tipOffset;
  307. window_half = $(window).height() / 2;
  308. tipOffset = Math.ceil(this.settings.$target.offset().top - window_half + this.settings.$next_tip.outerHeight());
  309. if (tipOffset > 0) {
  310. $('html, body').animate({
  311. scrollTop: tipOffset
  312. }, this.settings.scroll_speed, 'swing');
  313. }
  314. },
  315. paused : function () {
  316. return ($.inArray((this.settings.$li.index() + 1), this.settings.pause_after) === -1);
  317. },
  318. restart : function () {
  319. this.hide();
  320. this.settings.$li = undefined;
  321. this.show('init');
  322. },
  323. pos_default : function (init, resizing) {
  324. var half_fold = Math.ceil($(window).height() / 2),
  325. tip_position = this.settings.$next_tip.offset(),
  326. $nub = this.settings.$next_tip.find('.joyride-nub'),
  327. nub_width = Math.ceil($nub.outerWidth() / 2),
  328. nub_height = Math.ceil($nub.outerHeight() / 2),
  329. toggle = init || false;
  330. // tip must not be "display: none" to calculate position
  331. if (toggle) {
  332. this.settings.$next_tip.css('visibility', 'hidden');
  333. this.settings.$next_tip.show();
  334. }
  335. if (typeof resizing === 'undefined') {
  336. resizing = false;
  337. }
  338. if (!/body/i.test(this.settings.$target.selector)) {
  339. if (this.bottom()) {
  340. var leftOffset = this.settings.$target.offset().left;
  341. if (Foundation.rtl) {
  342. leftOffset = this.settings.$target.offset().width - this.settings.$next_tip.width() + leftOffset;
  343. }
  344. this.settings.$next_tip.css({
  345. top: (this.settings.$target.offset().top + nub_height + this.settings.$target.outerHeight()),
  346. left: leftOffset});
  347. this.nub_position($nub, this.settings.tip_settings.nub_position, 'top');
  348. } else if (this.top()) {
  349. var leftOffset = this.settings.$target.offset().left;
  350. if (Foundation.rtl) {
  351. leftOffset = this.settings.$target.offset().width - this.settings.$next_tip.width() + leftOffset;
  352. }
  353. this.settings.$next_tip.css({
  354. top: (this.settings.$target.offset().top - this.settings.$next_tip.outerHeight() - nub_height),
  355. left: leftOffset});
  356. this.nub_position($nub, this.settings.tip_settings.nub_position, 'bottom');
  357. } else if (this.right()) {
  358. this.settings.$next_tip.css({
  359. top: this.settings.$target.offset().top,
  360. left: (this.outerWidth(this.settings.$target) + this.settings.$target.offset().left + nub_width)});
  361. this.nub_position($nub, this.settings.tip_settings.nub_position, 'left');
  362. } else if (this.left()) {
  363. this.settings.$next_tip.css({
  364. top: this.settings.$target.offset().top,
  365. left: (this.settings.$target.offset().left - this.outerWidth(this.settings.$next_tip) - nub_width)});
  366. this.nub_position($nub, this.settings.tip_settings.nub_position, 'right');
  367. }
  368. if (!this.visible(this.corners(this.settings.$next_tip)) && this.settings.attempts < this.settings.tip_settings.tip_location_pattern.length) {
  369. $nub.removeClass('bottom')
  370. .removeClass('top')
  371. .removeClass('right')
  372. .removeClass('left');
  373. this.settings.tip_settings.tip_location = this.settings.tip_settings.tip_location_pattern[this.settings.attempts];
  374. this.settings.attempts++;
  375. this.pos_default();
  376. }
  377. } else if (this.settings.$li.length) {
  378. this.pos_modal($nub);
  379. }
  380. if (toggle) {
  381. this.settings.$next_tip.hide();
  382. this.settings.$next_tip.css('visibility', 'visible');
  383. }
  384. },
  385. pos_phone : function (init) {
  386. var tip_height = this.settings.$next_tip.outerHeight(),
  387. tip_offset = this.settings.$next_tip.offset(),
  388. target_height = this.settings.$target.outerHeight(),
  389. $nub = $('.joyride-nub', this.settings.$next_tip),
  390. nub_height = Math.ceil($nub.outerHeight() / 2),
  391. toggle = init || false;
  392. $nub.removeClass('bottom')
  393. .removeClass('top')
  394. .removeClass('right')
  395. .removeClass('left');
  396. if (toggle) {
  397. this.settings.$next_tip.css('visibility', 'hidden');
  398. this.settings.$next_tip.show();
  399. }
  400. if (!/body/i.test(this.settings.$target.selector)) {
  401. if (this.top()) {
  402. this.settings.$next_tip.offset({top: this.settings.$target.offset().top - tip_height - nub_height});
  403. $nub.addClass('bottom');
  404. } else {
  405. this.settings.$next_tip.offset({top: this.settings.$target.offset().top + target_height + nub_height});
  406. $nub.addClass('top');
  407. }
  408. } else if (this.settings.$li.length) {
  409. this.pos_modal($nub);
  410. }
  411. if (toggle) {
  412. this.settings.$next_tip.hide();
  413. this.settings.$next_tip.css('visibility', 'visible');
  414. }
  415. },
  416. pos_modal : function ($nub) {
  417. this.center();
  418. $nub.hide();
  419. this.show_modal();
  420. },
  421. show_modal : function () {
  422. if (!this.settings.$next_tip.data('closed')) {
  423. var joyridemodalbg = $('.joyride-modal-bg');
  424. if (joyridemodalbg.length < 1) {
  425. $('body').append(this.settings.template.modal).show();
  426. }
  427. if (/pop/i.test(this.settings.tip_animation)) {
  428. joyridemodalbg.show();
  429. } else {
  430. joyridemodalbg.fadeIn(this.settings.tip_animation_fade_speed);
  431. }
  432. }
  433. },
  434. expose : function () {
  435. var expose,
  436. exposeCover,
  437. el,
  438. origCSS,
  439. origClasses,
  440. randId = 'expose-'+Math.floor(Math.random()*10000);
  441. if (arguments.length > 0 && arguments[0] instanceof $) {
  442. el = arguments[0];
  443. } else if(this.settings.$target && !/body/i.test(this.settings.$target.selector)){
  444. el = this.settings.$target;
  445. } else {
  446. return false;
  447. }
  448. if(el.length < 1){
  449. if(window.console){
  450. console.error('element not valid', el);
  451. }
  452. return false;
  453. }
  454. expose = $(this.settings.template.expose);
  455. this.settings.$body.append(expose);
  456. expose.css({
  457. top: el.offset().top,
  458. left: el.offset().left,
  459. width: el.outerWidth(true),
  460. height: el.outerHeight(true)
  461. });
  462. exposeCover = $(this.settings.template.expose_cover);
  463. origCSS = {
  464. zIndex: el.css('z-index'),
  465. position: el.css('position')
  466. };
  467. origClasses = el.attr('class') == null ? '' : el.attr('class');
  468. el.css('z-index',parseInt(expose.css('z-index'))+1);
  469. if (origCSS.position == 'static') {
  470. el.css('position','relative');
  471. }
  472. el.data('expose-css',origCSS);
  473. el.data('orig-class', origClasses);
  474. el.attr('class', origClasses + ' ' + this.settings.expose_add_class);
  475. exposeCover.css({
  476. top: el.offset().top,
  477. left: el.offset().left,
  478. width: el.outerWidth(true),
  479. height: el.outerHeight(true)
  480. });
  481. if (this.settings.modal) this.show_modal();
  482. this.settings.$body.append(exposeCover);
  483. expose.addClass(randId);
  484. exposeCover.addClass(randId);
  485. el.data('expose', randId);
  486. this.settings.post_expose_callback(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.settings.$next_tip.outerHeight()) / 2) + $w.scrollTop()),
  567. left : ((($w.width() - this.settings.$next_tip.outerWidth()) / 2) + $w.scrollLeft())
  568. });
  569. return true;
  570. },
  571. bottom : function () {
  572. return /bottom/i.test(this.settings.tip_settings.tip_location);
  573. },
  574. top : function () {
  575. return /top/i.test(this.settings.tip_settings.tip_location);
  576. },
  577. right : function () {
  578. return /right/i.test(this.settings.tip_settings.tip_location);
  579. },
  580. left : function () {
  581. return /left/i.test(this.settings.tip_settings.tip_location);
  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() + w.scrollLeft(),
  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. w.scrollLeft() > 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.cookie_monster) {
  636. $.cookie(this.settings.cookie_name, 'ridden', { expires: this.settings.cookie_expires, domain: this.settings.cookie_domain });
  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.post_step_callback(this.settings.$li.index(), this.settings.$current_tip);
  648. this.settings.post_ride_callback(this.settings.$li.index(), this.settings.$current_tip);
  649. $('.joyride-tip-guide').remove();
  650. },
  651. off : function () {
  652. $(this.scope).off('.joyride');
  653. $(window).off('.joyride');
  654. $('.joyride-close-tip, .joyride-next-tip, .joyride-modal-bg').off('.joyride');
  655. $('.joyride-tip-guide, .joyride-modal-bg').remove();
  656. clearTimeout(this.settings.automate);
  657. this.settings = {};
  658. },
  659. reflow : function () {}
  660. };
  661. }(jQuery, this, this.document));