foundation.joyride.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. ;(function ($, window, document, undefined) {
  2. 'use strict';
  3. var Modernizr = Modernizr || false;
  4. Foundation.libs.joyride = {
  5. name : 'joyride',
  6. version : '5.1.1',
  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 random_str');
  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 ($('[' + self.attr_name() + ']').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 = $('[' + this.attr_name() + ']', 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(this.attr_name(true) + '-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)) {
  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. var i = int_settings_count;
  123. while (i--) {
  124. self.settings[integer_settings[i]] = parseInt(self.settings[integer_settings[i]], 10);
  125. }
  126. self.create({$li : $this, index : index});
  127. });
  128. // show first tip
  129. if (!this.settings.start_timer_on_click && this.settings.timer > 0) {
  130. this.show('init');
  131. this.startTimer();
  132. } else {
  133. this.show('init');
  134. }
  135. }
  136. },
  137. resume : function () {
  138. this.set_li();
  139. this.show();
  140. },
  141. tip_template : function (opts) {
  142. var $blank, content;
  143. opts.tip_class = opts.tip_class || '';
  144. $blank = $(this.settings.template.tip).addClass(opts.tip_class);
  145. content = $.trim($(opts.li).html()) +
  146. this.button_text(opts.button_text) +
  147. this.settings.template.link +
  148. this.timer_instance(opts.index);
  149. $blank.append($(this.settings.template.wrapper));
  150. $blank.first().attr(this.add_namespace('data-index'), opts.index);
  151. $('.joyride-content-wrapper', $blank).append(content);
  152. return $blank[0];
  153. },
  154. timer_instance : function (index) {
  155. var txt;
  156. if ((index === 0 && this.settings.start_timer_on_click && this.settings.timer > 0) || this.settings.timer === 0) {
  157. txt = '';
  158. } else {
  159. txt = $(this.settings.template.timer)[0].outerHTML;
  160. }
  161. return txt;
  162. },
  163. button_text : function (txt) {
  164. if (this.settings.next_button) {
  165. txt = $.trim(txt) || 'Next';
  166. txt = $(this.settings.template.button).append(txt)[0].outerHTML;
  167. } else {
  168. txt = '';
  169. }
  170. return txt;
  171. },
  172. create : function (opts) {
  173. console.log(opts.$li)
  174. var buttonText = opts.$li.attr(this.add_namespace('data-button'))
  175. || opts.$li.attr(this.add_namespace('data-text')),
  176. tipClass = opts.$li.attr('class'),
  177. $tip_content = $(this.tip_template({
  178. tip_class : tipClass,
  179. index : opts.index,
  180. button_text : buttonText,
  181. li : opts.$li
  182. }));
  183. $(this.settings.tip_container).append($tip_content);
  184. },
  185. show : function (init) {
  186. var $timer = null;
  187. // are we paused?
  188. if (this.settings.$li === undefined
  189. || ($.inArray(this.settings.$li.index(), this.settings.pause_after) === -1)) {
  190. // don't go to the next li if the tour was paused
  191. if (this.settings.paused) {
  192. this.settings.paused = false;
  193. } else {
  194. this.set_li(init);
  195. }
  196. this.settings.attempts = 0;
  197. if (this.settings.$li.length && this.settings.$target.length > 0) {
  198. if (init) { //run when we first start
  199. this.settings.pre_ride_callback(this.settings.$li.index(), this.settings.$next_tip);
  200. if (this.settings.modal) {
  201. this.show_modal();
  202. }
  203. }
  204. this.settings.pre_step_callback(this.settings.$li.index(), this.settings.$next_tip);
  205. if (this.settings.modal && this.settings.expose) {
  206. this.expose();
  207. }
  208. this.settings.tip_settings = $.extend({}, this.settings, this.data_options(this.settings.$li));
  209. this.settings.timer = parseInt(this.settings.timer, 10);
  210. this.settings.tip_settings.tip_location_pattern = this.settings.tip_location_patterns[this.settings.tip_settings.tip_location];
  211. // scroll if not modal
  212. if (!/body/i.test(this.settings.$target.selector)) {
  213. this.scroll_to();
  214. }
  215. if (this.is_phone()) {
  216. this.pos_phone(true);
  217. } else {
  218. this.pos_default(true);
  219. }
  220. $timer = this.settings.$next_tip.find('.joyride-timer-indicator');
  221. if (/pop/i.test(this.settings.tip_animation)) {
  222. $timer.width(0);
  223. if (this.settings.timer > 0) {
  224. this.settings.$next_tip.show();
  225. setTimeout(function () {
  226. $timer.animate({
  227. width: $timer.parent().width()
  228. }, this.settings.timer, 'linear');
  229. }.bind(this), this.settings.tip_animation_fade_speed);
  230. } else {
  231. this.settings.$next_tip.show();
  232. }
  233. } else if (/fade/i.test(this.settings.tip_animation)) {
  234. $timer.width(0);
  235. if (this.settings.timer > 0) {
  236. this.settings.$next_tip
  237. .fadeIn(this.settings.tip_animation_fade_speed)
  238. .show();
  239. setTimeout(function () {
  240. $timer.animate({
  241. width: $timer.parent().width()
  242. }, this.settings.timer, 'linear');
  243. }.bind(this), this.settings.tip_animation_fadeSpeed);
  244. } else {
  245. this.settings.$next_tip.fadeIn(this.settings.tip_animation_fade_speed);
  246. }
  247. }
  248. this.settings.$current_tip = this.settings.$next_tip;
  249. // skip non-existant targets
  250. } else if (this.settings.$li && this.settings.$target.length < 1) {
  251. this.show();
  252. } else {
  253. this.end();
  254. }
  255. } else {
  256. this.settings.paused = true;
  257. }
  258. },
  259. is_phone : function () {
  260. return matchMedia(Foundation.media_queries.small).matches &&
  261. !matchMedia(Foundation.media_queries.medium).matches;
  262. },
  263. hide : function () {
  264. if (this.settings.modal && this.settings.expose) {
  265. this.un_expose();
  266. }
  267. if (!this.settings.modal) {
  268. $('.joyride-modal-bg').hide();
  269. }
  270. // Prevent scroll bouncing...wait to remove from layout
  271. this.settings.$current_tip.css('visibility', 'hidden');
  272. setTimeout($.proxy(function() {
  273. this.hide();
  274. this.css('visibility', 'visible');
  275. }, this.settings.$current_tip), 0);
  276. this.settings.post_step_callback(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.start_offset);
  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").eq(this.settings.$li.index());
  292. this.settings.$next_tip.data('closed', '');
  293. },
  294. set_target : function () {
  295. console.log(this.add_namespace('data-class'))
  296. var cl = this.settings.$li.attr(this.add_namespace('data-class')),
  297. id = this.settings.$li.attr(this.add_namespace('data-id')),
  298. $sel = function () {
  299. if (id) {
  300. return $(document.getElementById(id));
  301. } else if (cl) {
  302. return $('.' + cl).first();
  303. } else {
  304. return $('body');
  305. }
  306. };
  307. console.log(cl, id)
  308. this.settings.$target = $sel();
  309. },
  310. scroll_to : function () {
  311. var window_half, tipOffset;
  312. window_half = $(window).height() / 2;
  313. tipOffset = Math.ceil(this.settings.$target.offset().top - window_half + this.settings.$next_tip.outerHeight());
  314. if (tipOffset != 0) {
  315. $('html, body').animate({
  316. scrollTop: tipOffset
  317. }, this.settings.scroll_speed, 'swing');
  318. }
  319. },
  320. paused : function () {
  321. return ($.inArray((this.settings.$li.index() + 1), this.settings.pause_after) === -1);
  322. },
  323. restart : function () {
  324. this.hide();
  325. this.settings.$li = undefined;
  326. this.show('init');
  327. },
  328. pos_default : function (init, resizing) {
  329. var half_fold = Math.ceil($(window).height() / 2),
  330. tip_position = this.settings.$next_tip.offset(),
  331. $nub = this.settings.$next_tip.find('.joyride-nub'),
  332. nub_width = Math.ceil($nub.outerWidth() / 2),
  333. nub_height = Math.ceil($nub.outerHeight() / 2),
  334. toggle = init || false;
  335. // tip must not be "display: none" to calculate position
  336. if (toggle) {
  337. this.settings.$next_tip.css('visibility', 'hidden');
  338. this.settings.$next_tip.show();
  339. }
  340. if (typeof resizing === 'undefined') {
  341. resizing = false;
  342. }
  343. if (!/body/i.test(this.settings.$target.selector)) {
  344. if (this.bottom()) {
  345. if (this.rtl) {
  346. this.settings.$next_tip.css({
  347. top: (this.settings.$target.offset().top + nub_height + this.settings.$target.outerHeight()),
  348. left: this.settings.$target.offset().left + this.settings.$target.outerWidth() - this.settings.$next_tip.outerWidth()});
  349. } else {
  350. this.settings.$next_tip.css({
  351. top: (this.settings.$target.offset().top + nub_height + this.settings.$target.outerHeight()),
  352. left: this.settings.$target.offset().left});
  353. }
  354. this.nub_position($nub, this.settings.tip_settings.nub_position, 'top');
  355. } else if (this.top()) {
  356. if (this.rtl) {
  357. this.settings.$next_tip.css({
  358. top: (this.settings.$target.offset().top - this.settings.$next_tip.outerHeight() - nub_height),
  359. left: this.settings.$target.offset().left + this.settings.$target.outerWidth() - this.settings.$next_tip.outerWidth()});
  360. } else {
  361. this.settings.$next_tip.css({
  362. top: (this.settings.$target.offset().top - this.settings.$next_tip.outerHeight() - nub_height),
  363. left: this.settings.$target.offset().left});
  364. }
  365. this.nub_position($nub, this.settings.tip_settings.nub_position, 'bottom');
  366. } else if (this.right()) {
  367. this.settings.$next_tip.css({
  368. top: this.settings.$target.offset().top,
  369. left: (this.outerWidth(this.settings.$target) + this.settings.$target.offset().left + nub_width)});
  370. this.nub_position($nub, this.settings.tip_settings.nub_position, 'left');
  371. } else if (this.left()) {
  372. this.settings.$next_tip.css({
  373. top: this.settings.$target.offset().top,
  374. left: (this.settings.$target.offset().left - this.outerWidth(this.settings.$next_tip) - nub_width)});
  375. this.nub_position($nub, this.settings.tip_settings.nub_position, 'right');
  376. }
  377. if (!this.visible(this.corners(this.settings.$next_tip)) && this.settings.attempts < this.settings.tip_settings.tip_location_pattern.length) {
  378. $nub.removeClass('bottom')
  379. .removeClass('top')
  380. .removeClass('right')
  381. .removeClass('left');
  382. this.settings.tip_settings.tip_location = this.settings.tip_settings.tip_location_pattern[this.settings.attempts];
  383. this.settings.attempts++;
  384. this.pos_default();
  385. }
  386. } else if (this.settings.$li.length) {
  387. this.pos_modal($nub);
  388. }
  389. if (toggle) {
  390. this.settings.$next_tip.hide();
  391. this.settings.$next_tip.css('visibility', 'visible');
  392. }
  393. },
  394. pos_phone : function (init) {
  395. var tip_height = this.settings.$next_tip.outerHeight(),
  396. tip_offset = this.settings.$next_tip.offset(),
  397. target_height = this.settings.$target.outerHeight(),
  398. $nub = $('.joyride-nub', this.settings.$next_tip),
  399. nub_height = Math.ceil($nub.outerHeight() / 2),
  400. toggle = init || false;
  401. $nub.removeClass('bottom')
  402. .removeClass('top')
  403. .removeClass('right')
  404. .removeClass('left');
  405. if (toggle) {
  406. this.settings.$next_tip.css('visibility', 'hidden');
  407. this.settings.$next_tip.show();
  408. }
  409. if (!/body/i.test(this.settings.$target.selector)) {
  410. if (this.top()) {
  411. this.settings.$next_tip.offset({top: this.settings.$target.offset().top - tip_height - nub_height});
  412. $nub.addClass('bottom');
  413. } else {
  414. this.settings.$next_tip.offset({top: this.settings.$target.offset().top + target_height + nub_height});
  415. $nub.addClass('top');
  416. }
  417. } else if (this.settings.$li.length) {
  418. this.pos_modal($nub);
  419. }
  420. if (toggle) {
  421. this.settings.$next_tip.hide();
  422. this.settings.$next_tip.css('visibility', 'visible');
  423. }
  424. },
  425. pos_modal : function ($nub) {
  426. this.center();
  427. $nub.hide();
  428. this.show_modal();
  429. },
  430. show_modal : function () {
  431. if (!this.settings.$next_tip.data('closed')) {
  432. var joyridemodalbg = $('.joyride-modal-bg');
  433. if (joyridemodalbg.length < 1) {
  434. $('body').append(this.settings.template.modal).show();
  435. }
  436. if (/pop/i.test(this.settings.tip_animation)) {
  437. joyridemodalbg.show();
  438. } else {
  439. joyridemodalbg.fadeIn(this.settings.tip_animation_fade_speed);
  440. }
  441. }
  442. },
  443. expose : function () {
  444. var expose,
  445. exposeCover,
  446. el,
  447. origCSS,
  448. origClasses,
  449. randId = 'expose-' + this.random_str(6);
  450. if (arguments.length > 0 && arguments[0] instanceof $) {
  451. el = arguments[0];
  452. } else if(this.settings.$target && !/body/i.test(this.settings.$target.selector)){
  453. el = this.settings.$target;
  454. } else {
  455. return false;
  456. }
  457. if(el.length < 1){
  458. if(window.console){
  459. console.error('element not valid', el);
  460. }
  461. return false;
  462. }
  463. expose = $(this.settings.template.expose);
  464. this.settings.$body.append(expose);
  465. expose.css({
  466. top: el.offset().top,
  467. left: el.offset().left,
  468. width: el.outerWidth(true),
  469. height: el.outerHeight(true)
  470. });
  471. exposeCover = $(this.settings.template.expose_cover);
  472. origCSS = {
  473. zIndex: el.css('z-index'),
  474. position: el.css('position')
  475. };
  476. origClasses = el.attr('class') == null ? '' : el.attr('class');
  477. el.css('z-index',parseInt(expose.css('z-index'))+1);
  478. if (origCSS.position == 'static') {
  479. el.css('position','relative');
  480. }
  481. el.data('expose-css',origCSS);
  482. el.data('orig-class', origClasses);
  483. el.attr('class', origClasses + ' ' + this.settings.expose_add_class);
  484. exposeCover.css({
  485. top: el.offset().top,
  486. left: el.offset().left,
  487. width: el.outerWidth(true),
  488. height: el.outerHeight(true)
  489. });
  490. if (this.settings.modal) this.show_modal();
  491. this.settings.$body.append(exposeCover);
  492. expose.addClass(randId);
  493. exposeCover.addClass(randId);
  494. el.data('expose', randId);
  495. this.settings.post_expose_callback(this.settings.$li.index(), this.settings.$next_tip, el);
  496. this.add_exposed(el);
  497. },
  498. un_expose : function () {
  499. var exposeId,
  500. el,
  501. expose ,
  502. origCSS,
  503. origClasses,
  504. clearAll = false;
  505. if (arguments.length > 0 && arguments[0] instanceof $) {
  506. el = arguments[0];
  507. } else if(this.settings.$target && !/body/i.test(this.settings.$target.selector)){
  508. el = this.settings.$target;
  509. } else {
  510. return false;
  511. }
  512. if(el.length < 1){
  513. if (window.console) {
  514. console.error('element not valid', el);
  515. }
  516. return false;
  517. }
  518. exposeId = el.data('expose');
  519. expose = $('.' + exposeId);
  520. if (arguments.length > 1) {
  521. clearAll = arguments[1];
  522. }
  523. if (clearAll === true) {
  524. $('.joyride-expose-wrapper,.joyride-expose-cover').remove();
  525. } else {
  526. expose.remove();
  527. }
  528. origCSS = el.data('expose-css');
  529. if (origCSS.zIndex == 'auto') {
  530. el.css('z-index', '');
  531. } else {
  532. el.css('z-index', origCSS.zIndex);
  533. }
  534. if (origCSS.position != el.css('position')) {
  535. if(origCSS.position == 'static') {// this is default, no need to set it.
  536. el.css('position', '');
  537. } else {
  538. el.css('position', origCSS.position);
  539. }
  540. }
  541. origClasses = el.data('orig-class');
  542. el.attr('class', origClasses);
  543. el.removeData('orig-classes');
  544. el.removeData('expose');
  545. el.removeData('expose-z-index');
  546. this.remove_exposed(el);
  547. },
  548. add_exposed: function(el){
  549. this.settings.exposed = this.settings.exposed || [];
  550. if (el instanceof $ || typeof el === 'object') {
  551. this.settings.exposed.push(el[0]);
  552. } else if (typeof el == 'string') {
  553. this.settings.exposed.push(el);
  554. }
  555. },
  556. remove_exposed: function(el){
  557. var search, i;
  558. if (el instanceof $) {
  559. search = el[0]
  560. } else if (typeof el == 'string'){
  561. search = el;
  562. }
  563. this.settings.exposed = this.settings.exposed || [];
  564. i = this.settings.exposed.length;
  565. while (i--) {
  566. if (this.settings.exposed[i] == search) {
  567. this.settings.exposed.splice(i, 1);
  568. return;
  569. }
  570. }
  571. },
  572. center : function () {
  573. var $w = $(window);
  574. this.settings.$next_tip.css({
  575. top : ((($w.height() - this.settings.$next_tip.outerHeight()) / 2) + $w.scrollTop()),
  576. left : ((($w.width() - this.settings.$next_tip.outerWidth()) / 2) + $w.scrollLeft())
  577. });
  578. return true;
  579. },
  580. bottom : function () {
  581. return /bottom/i.test(this.settings.tip_settings.tip_location);
  582. },
  583. top : function () {
  584. return /top/i.test(this.settings.tip_settings.tip_location);
  585. },
  586. right : function () {
  587. return /right/i.test(this.settings.tip_settings.tip_location);
  588. },
  589. left : function () {
  590. return /left/i.test(this.settings.tip_settings.tip_location);
  591. },
  592. corners : function (el) {
  593. var w = $(window),
  594. window_half = w.height() / 2,
  595. //using this to calculate since scroll may not have finished yet.
  596. tipOffset = Math.ceil(this.settings.$target.offset().top - window_half + this.settings.$next_tip.outerHeight()),
  597. right = w.width() + w.scrollLeft(),
  598. offsetBottom = w.height() + tipOffset,
  599. bottom = w.height() + w.scrollTop(),
  600. top = w.scrollTop();
  601. if (tipOffset < top) {
  602. if (tipOffset < 0) {
  603. top = 0;
  604. } else {
  605. top = tipOffset;
  606. }
  607. }
  608. if (offsetBottom > bottom) {
  609. bottom = offsetBottom;
  610. }
  611. return [
  612. el.offset().top < top,
  613. right < el.offset().left + el.outerWidth(),
  614. bottom < el.offset().top + el.outerHeight(),
  615. w.scrollLeft() > el.offset().left
  616. ];
  617. },
  618. visible : function (hidden_corners) {
  619. var i = hidden_corners.length;
  620. while (i--) {
  621. if (hidden_corners[i]) return false;
  622. }
  623. return true;
  624. },
  625. nub_position : function (nub, pos, def) {
  626. if (pos === 'auto') {
  627. nub.addClass(def);
  628. } else {
  629. nub.addClass(pos);
  630. }
  631. },
  632. startTimer : function () {
  633. if (this.settings.$li.length) {
  634. this.settings.automate = setTimeout(function () {
  635. this.hide();
  636. this.show();
  637. this.startTimer();
  638. }.bind(this), this.settings.timer);
  639. } else {
  640. clearTimeout(this.settings.automate);
  641. }
  642. },
  643. end : function () {
  644. if (this.settings.cookie_monster) {
  645. $.cookie(this.settings.cookie_name, 'ridden', { expires: this.settings.cookie_expires, domain: this.settings.cookie_domain });
  646. }
  647. if (this.settings.timer > 0) {
  648. clearTimeout(this.settings.automate);
  649. }
  650. if (this.settings.modal && this.settings.expose) {
  651. this.un_expose();
  652. }
  653. this.settings.$next_tip.data('closed', true);
  654. $('.joyride-modal-bg').hide();
  655. this.settings.$current_tip.hide();
  656. this.settings.post_step_callback(this.settings.$li.index(), this.settings.$current_tip);
  657. this.settings.post_ride_callback(this.settings.$li.index(), this.settings.$current_tip);
  658. $('.joyride-tip-guide').remove();
  659. },
  660. off : function () {
  661. $(this.scope).off('.joyride');
  662. $(window).off('.joyride');
  663. $('.joyride-close-tip, .joyride-next-tip, .joyride-modal-bg').off('.joyride');
  664. $('.joyride-tip-guide, .joyride-modal-bg').remove();
  665. clearTimeout(this.settings.automate);
  666. this.settings = {};
  667. },
  668. reflow : function () {}
  669. };
  670. }(jQuery, this, this.document));