Mercurial > hg > isophonics-drupal-site
comparison core/assets/vendor/jquery-joyride/jquery.joyride-2.1.js @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 /* | |
2 * jQuery Foundation Joyride Plugin 2.1 | |
3 * http://foundation.zurb.com | |
4 * Copyright 2013, ZURB | |
5 * Free to use under the MIT license. | |
6 * http://www.opensource.org/licenses/mit-license.php | |
7 */ | |
8 | |
9 /*jslint unparam: true, browser: true, indent: 2 */ | |
10 | |
11 ;(function ($, window, undefined) { | |
12 'use strict'; | |
13 | |
14 var defaults = { | |
15 'version' : '2.1', | |
16 'tipLocation' : 'bottom', // 'top' or 'bottom' in relation to parent | |
17 'nubPosition' : 'auto', // override on a per tooltip bases | |
18 'scroll' : true, // whether to scroll to tips | |
19 'scrollSpeed' : 300, // Page scrolling speed in milliseconds | |
20 'timer' : 0, // 0 = no timer , all other numbers = timer in milliseconds | |
21 'autoStart' : false, // true or false - false tour starts when restart called | |
22 'startTimerOnClick' : true, // true or false - true requires clicking the first button start the timer | |
23 'startOffset' : 0, // the index of the tooltip you want to start on (index of the li) | |
24 'nextButton' : true, // true or false to control whether a next button is used | |
25 'tipAnimation' : 'fade', // 'pop' or 'fade' in each tip | |
26 'pauseAfter' : [], // array of indexes where to pause the tour after | |
27 'tipAnimationFadeSpeed': 300, // when tipAnimation = 'fade' this is speed in milliseconds for the transition | |
28 'cookieMonster' : false, // true or false to control whether cookies are used | |
29 'cookieName' : 'joyride', // Name the cookie you'll use | |
30 'cookieDomain' : false, // Will this cookie be attached to a domain, ie. '.notableapp.com' | |
31 'cookiePath' : false, // Set to '/' if you want the cookie for the whole website | |
32 'localStorage' : false, // true or false to control whether localstorage is used | |
33 'localStorageKey' : 'joyride', // Keyname in localstorage | |
34 'tipContainer' : 'body', // Where will the tip be attached | |
35 'modal' : false, // Whether to cover page with modal during the tour | |
36 'expose' : false, // Whether to expose the elements at each step in the tour (requires modal:true) | |
37 'postExposeCallback' : $.noop, // A method to call after an element has been exposed | |
38 'preRideCallback' : $.noop, // A method to call before the tour starts (passed index, tip, and cloned exposed element) | |
39 'postRideCallback' : $.noop, // A method to call once the tour closes (canceled or complete) | |
40 'preStepCallback' : $.noop, // A method to call before each step | |
41 'postStepCallback' : $.noop, // A method to call after each step | |
42 'template' : { // HTML segments for tip layout | |
43 'link' : '<a href="#close" class="joyride-close-tip">X</a>', | |
44 'timer' : '<div class="joyride-timer-indicator-wrap"><span class="joyride-timer-indicator"></span></div>', | |
45 'tip' : '<div class="joyride-tip-guide"><span class="joyride-nub"></span></div>', | |
46 'wrapper' : '<div class="joyride-content-wrapper" role="dialog"></div>', | |
47 'button' : '<a href="#" class="joyride-next-tip"></a>', | |
48 'modal' : '<div class="joyride-modal-bg"></div>', | |
49 'expose' : '<div class="joyride-expose-wrapper"></div>', | |
50 'exposeCover': '<div class="joyride-expose-cover"></div>' | |
51 } | |
52 }, | |
53 | |
54 Modernizr = Modernizr || false, | |
55 | |
56 settings = {}, | |
57 | |
58 methods = { | |
59 | |
60 init : function (opts) { | |
61 return this.each(function () { | |
62 | |
63 if ($.isEmptyObject(settings)) { | |
64 settings = $.extend(true, defaults, opts); | |
65 | |
66 // non configurable settings | |
67 settings.document = window.document; | |
68 settings.$document = $(settings.document); | |
69 settings.$window = $(window); | |
70 settings.$content_el = $(this); | |
71 settings.$body = $(settings.tipContainer); | |
72 settings.body_offset = $(settings.tipContainer).position(); | |
73 settings.$tip_content = $('> li', settings.$content_el); | |
74 settings.paused = false; | |
75 settings.attempts = 0; | |
76 | |
77 settings.tipLocationPatterns = { | |
78 top: ['bottom'], | |
79 bottom: [], // bottom should not need to be repositioned | |
80 left: ['right', 'top', 'bottom'], | |
81 right: ['left', 'top', 'bottom'] | |
82 }; | |
83 | |
84 // are we using jQuery 1.7+ | |
85 methods.jquery_check(); | |
86 | |
87 // can we create cookies? | |
88 if (!$.isFunction($.cookie)) { | |
89 settings.cookieMonster = false; | |
90 } | |
91 | |
92 // generate the tips and insert into dom. | |
93 if ( (!settings.cookieMonster || !$.cookie(settings.cookieName) ) && | |
94 (!settings.localStorage || !methods.support_localstorage() || !localStorage.getItem(settings.localStorageKey) ) ) { | |
95 | |
96 settings.$tip_content.each(function (index) { | |
97 methods.create({$li : $(this), index : index}); | |
98 }); | |
99 | |
100 // show first tip | |
101 if(settings.autoStart) | |
102 { | |
103 if (!settings.startTimerOnClick && settings.timer > 0) { | |
104 methods.show('init'); | |
105 methods.startTimer(); | |
106 } else { | |
107 methods.show('init'); | |
108 } | |
109 } | |
110 | |
111 } | |
112 | |
113 settings.$document.on('click.joyride', '.joyride-next-tip, .joyride-modal-bg', function (e) { | |
114 e.preventDefault(); | |
115 | |
116 if (settings.$li.next().length < 1) { | |
117 methods.end(); | |
118 } else if (settings.timer > 0) { | |
119 clearTimeout(settings.automate); | |
120 methods.hide(); | |
121 methods.show(); | |
122 methods.startTimer(); | |
123 } else { | |
124 methods.hide(); | |
125 methods.show(); | |
126 } | |
127 | |
128 }); | |
129 | |
130 settings.$document.on('click.joyride', '.joyride-close-tip', function (e) { | |
131 e.preventDefault(); | |
132 methods.end(true /* isAborted */); | |
133 }); | |
134 | |
135 settings.$window.on('resize.joyride', function (e) { | |
136 if(settings.$li){ | |
137 if(settings.exposed && settings.exposed.length>0){ | |
138 var $els = $(settings.exposed); | |
139 $els.each(function(){ | |
140 var $this = $(this); | |
141 methods.un_expose($this); | |
142 methods.expose($this); | |
143 }); | |
144 } | |
145 if (methods.is_phone()) { | |
146 methods.pos_phone(); | |
147 } else { | |
148 methods.pos_default(); | |
149 } | |
150 } | |
151 }); | |
152 } else { | |
153 methods.restart(); | |
154 } | |
155 | |
156 }); | |
157 }, | |
158 | |
159 // call this method when you want to resume the tour | |
160 resume : function () { | |
161 methods.set_li(); | |
162 methods.show(); | |
163 }, | |
164 | |
165 nextTip: function(){ | |
166 if (settings.$li.next().length < 1) { | |
167 methods.end(); | |
168 } else if (settings.timer > 0) { | |
169 clearTimeout(settings.automate); | |
170 methods.hide(); | |
171 methods.show(); | |
172 methods.startTimer(); | |
173 } else { | |
174 methods.hide(); | |
175 methods.show(); | |
176 } | |
177 }, | |
178 | |
179 tip_template : function (opts) { | |
180 var $blank, content, $wrapper; | |
181 | |
182 opts.tip_class = opts.tip_class || ''; | |
183 | |
184 $blank = $(settings.template.tip).addClass(opts.tip_class); | |
185 content = $.trim($(opts.li).html()) + | |
186 methods.button_text(opts.button_text) + | |
187 settings.template.link + | |
188 methods.timer_instance(opts.index); | |
189 | |
190 $wrapper = $(settings.template.wrapper); | |
191 if (opts.li.attr('data-aria-labelledby')) { | |
192 $wrapper.attr('aria-labelledby', opts.li.attr('data-aria-labelledby')) | |
193 } | |
194 if (opts.li.attr('data-aria-describedby')) { | |
195 $wrapper.attr('aria-describedby', opts.li.attr('data-aria-describedby')) | |
196 } | |
197 $blank.append($wrapper); | |
198 $blank.first().attr('data-index', opts.index); | |
199 $('.joyride-content-wrapper', $blank).append(content); | |
200 | |
201 return $blank[0]; | |
202 }, | |
203 | |
204 timer_instance : function (index) { | |
205 var txt; | |
206 | |
207 if ((index === 0 && settings.startTimerOnClick && settings.timer > 0) || settings.timer === 0) { | |
208 txt = ''; | |
209 } else { | |
210 txt = methods.outerHTML($(settings.template.timer)[0]); | |
211 } | |
212 return txt; | |
213 }, | |
214 | |
215 button_text : function (txt) { | |
216 if (settings.nextButton) { | |
217 txt = $.trim(txt) || 'Next'; | |
218 txt = methods.outerHTML($(settings.template.button).append(txt)[0]); | |
219 } else { | |
220 txt = ''; | |
221 } | |
222 return txt; | |
223 }, | |
224 | |
225 create : function (opts) { | |
226 // backwards compatibility with data-text attribute | |
227 var buttonText = opts.$li.attr('data-button') || opts.$li.attr('data-text'), | |
228 tipClass = opts.$li.attr('class'), | |
229 $tip_content = $(methods.tip_template({ | |
230 tip_class : tipClass, | |
231 index : opts.index, | |
232 button_text : buttonText, | |
233 li : opts.$li | |
234 })); | |
235 | |
236 $(settings.tipContainer).append($tip_content); | |
237 }, | |
238 | |
239 show : function (init) { | |
240 var opts = {}, ii, opts_arr = [], opts_len = 0, p, | |
241 $timer = null; | |
242 | |
243 // are we paused? | |
244 if (settings.$li === undefined || ($.inArray(settings.$li.index(), settings.pauseAfter) === -1)) { | |
245 | |
246 // don't go to the next li if the tour was paused | |
247 if (settings.paused) { | |
248 settings.paused = false; | |
249 } else { | |
250 methods.set_li(init); | |
251 } | |
252 | |
253 settings.attempts = 0; | |
254 | |
255 if (settings.$li.length && settings.$target.length > 0) { | |
256 if(init){ //run when we first start | |
257 settings.preRideCallback(settings.$li.index(), settings.$next_tip ); | |
258 if(settings.modal){ | |
259 methods.show_modal(); | |
260 } | |
261 } | |
262 settings.preStepCallback(settings.$li.index(), settings.$next_tip ); | |
263 | |
264 // parse options | |
265 opts_arr = (settings.$li.data('options') || ':').split(';'); | |
266 opts_len = opts_arr.length; | |
267 for (ii = opts_len - 1; ii >= 0; ii--) { | |
268 p = opts_arr[ii].split(':'); | |
269 | |
270 if (p.length === 2) { | |
271 opts[$.trim(p[0])] = $.trim(p[1]); | |
272 } | |
273 } | |
274 settings.tipSettings = $.extend({}, settings, opts); | |
275 settings.tipSettings.tipLocationPattern = settings.tipLocationPatterns[settings.tipSettings.tipLocation]; | |
276 | |
277 if(settings.modal && settings.expose){ | |
278 methods.expose(); | |
279 } | |
280 | |
281 // scroll if not modal | |
282 if (!settings.$target.is("body") && settings.scroll) { | |
283 methods.scroll_to(); | |
284 } | |
285 | |
286 if (methods.is_phone()) { | |
287 methods.pos_phone(true); | |
288 } else { | |
289 methods.pos_default(true); | |
290 } | |
291 | |
292 $timer = $('.joyride-timer-indicator', settings.$next_tip); | |
293 | |
294 if (/pop/i.test(settings.tipAnimation)) { | |
295 | |
296 $timer.outerWidth(0); | |
297 | |
298 if (settings.timer > 0) { | |
299 | |
300 settings.$next_tip.show(); | |
301 $timer.animate({ | |
302 width: $('.joyride-timer-indicator-wrap', settings.$next_tip).outerWidth() | |
303 }, settings.timer); | |
304 | |
305 } else { | |
306 | |
307 settings.$next_tip.show(); | |
308 | |
309 } | |
310 | |
311 | |
312 } else if (/fade/i.test(settings.tipAnimation)) { | |
313 | |
314 $timer.outerWidth(0); | |
315 | |
316 if (settings.timer > 0) { | |
317 | |
318 settings.$next_tip.fadeIn(settings.tipAnimationFadeSpeed); | |
319 | |
320 settings.$next_tip.show(); | |
321 $timer.animate({ | |
322 width: $('.joyride-timer-indicator-wrap', settings.$next_tip).outerWidth() | |
323 }, settings.timer); | |
324 | |
325 } else { | |
326 | |
327 settings.$next_tip.fadeIn(settings.tipAnimationFadeSpeed); | |
328 | |
329 } | |
330 } | |
331 | |
332 settings.$current_tip = settings.$next_tip; | |
333 // Focus next button for keyboard users. | |
334 $('.joyride-next-tip', settings.$current_tip).focus(); | |
335 methods.tabbable(settings.$current_tip); | |
336 // skip non-existent targets | |
337 } else if (settings.$li && settings.$target.length < 1) { | |
338 | |
339 methods.show(); | |
340 | |
341 } else { | |
342 | |
343 methods.end(); | |
344 | |
345 } | |
346 } else { | |
347 | |
348 settings.paused = true; | |
349 | |
350 } | |
351 | |
352 }, | |
353 | |
354 // detect phones with media queries if supported. | |
355 is_phone : function () { | |
356 if (Modernizr) { | |
357 return Modernizr.mq('only screen and (max-width: 767px)'); | |
358 } | |
359 | |
360 return (settings.$window.width() < 767) ? true : false; | |
361 }, | |
362 | |
363 support_localstorage : function () { | |
364 if (Modernizr) { | |
365 return Modernizr.localstorage; | |
366 } else { | |
367 return !!window.localStorage; | |
368 } | |
369 }, | |
370 | |
371 hide : function () { | |
372 if(settings.modal && settings.expose){ | |
373 methods.un_expose(); | |
374 } | |
375 if(!settings.modal){ | |
376 $('.joyride-modal-bg').hide(); | |
377 } | |
378 settings.$current_tip.hide(); | |
379 settings.postStepCallback(settings.$li.index(), settings.$current_tip); | |
380 }, | |
381 | |
382 set_li : function (init) { | |
383 if (init) { | |
384 settings.$li = settings.$tip_content.eq(settings.startOffset); | |
385 methods.set_next_tip(); | |
386 settings.$current_tip = settings.$next_tip; | |
387 } else { | |
388 settings.$li = settings.$li.next(); | |
389 methods.set_next_tip(); | |
390 } | |
391 | |
392 methods.set_target(); | |
393 }, | |
394 | |
395 set_next_tip : function () { | |
396 settings.$next_tip = $('.joyride-tip-guide[data-index=' + settings.$li.index() + ']'); | |
397 }, | |
398 | |
399 set_target : function () { | |
400 var cl = settings.$li.attr('data-class'), | |
401 id = settings.$li.attr('data-id'), | |
402 $sel = function () { | |
403 if (id) { | |
404 return $(settings.document.getElementById(id)); | |
405 } else if (cl) { | |
406 return $('.' + cl).filter(":visible").first(); | |
407 } else { | |
408 return $('body'); | |
409 } | |
410 }; | |
411 | |
412 settings.$target = $sel(); | |
413 }, | |
414 | |
415 scroll_to : function () { | |
416 var window_half, tipOffset; | |
417 | |
418 window_half = settings.$window.height() / 2; | |
419 tipOffset = Math.ceil(settings.$target.offset().top - window_half + settings.$next_tip.outerHeight()); | |
420 | |
421 $("html, body").stop().animate({ | |
422 scrollTop: tipOffset | |
423 }, settings.scrollSpeed); | |
424 }, | |
425 | |
426 paused : function () { | |
427 if (($.inArray((settings.$li.index() + 1), settings.pauseAfter) === -1)) { | |
428 return true; | |
429 } | |
430 | |
431 return false; | |
432 }, | |
433 | |
434 destroy : function () { | |
435 if(!$.isEmptyObject(settings)){ | |
436 settings.$document.off('.joyride'); | |
437 } | |
438 | |
439 $(window).off('.joyride'); | |
440 $('.joyride-close-tip, .joyride-next-tip, .joyride-modal-bg').off('.joyride'); | |
441 $('.joyride-tip-guide, .joyride-modal-bg').remove(); | |
442 clearTimeout(settings.automate); | |
443 settings = {}; | |
444 }, | |
445 | |
446 restart : function () { | |
447 if(!settings.autoStart) | |
448 { | |
449 if (!settings.startTimerOnClick && settings.timer > 0) { | |
450 methods.show('init'); | |
451 methods.startTimer(); | |
452 } else { | |
453 methods.show('init'); | |
454 } | |
455 settings.autoStart = true; | |
456 } | |
457 else | |
458 { | |
459 methods.hide(); | |
460 settings.$li = undefined; | |
461 methods.show('init'); | |
462 } | |
463 }, | |
464 | |
465 pos_default : function (init) { | |
466 var half_fold = Math.ceil(settings.$window.height() / 2), | |
467 tip_position = settings.$next_tip.offset(), | |
468 $nub = $('.joyride-nub', settings.$next_tip), | |
469 nub_width = Math.ceil($nub.outerWidth() / 2), | |
470 nub_height = Math.ceil($nub.outerHeight() / 2), | |
471 toggle = init || false; | |
472 | |
473 // tip must not be "display: none" to calculate position | |
474 if (toggle) { | |
475 settings.$next_tip.css('visibility', 'hidden'); | |
476 settings.$next_tip.show(); | |
477 } | |
478 | |
479 if (!settings.$target.is("body")) { | |
480 var | |
481 topAdjustment = settings.tipSettings.tipAdjustmentY ? parseInt(settings.tipSettings.tipAdjustmentY) : 0, | |
482 leftAdjustment = settings.tipSettings.tipAdjustmentX ? parseInt(settings.tipSettings.tipAdjustmentX) : 0; | |
483 | |
484 if (methods.bottom()) { | |
485 settings.$next_tip.css({ | |
486 top: (settings.$target.offset().top + nub_height + settings.$target.outerHeight() + topAdjustment), | |
487 left: settings.$target.offset().left + leftAdjustment}); | |
488 | |
489 if (/right/i.test(settings.tipSettings.nubPosition)) { | |
490 settings.$next_tip.css('left', settings.$target.offset().left - settings.$next_tip.outerWidth() + settings.$target.outerWidth()); | |
491 } | |
492 | |
493 methods.nub_position($nub, settings.tipSettings.nubPosition, 'top'); | |
494 | |
495 } else if (methods.top()) { | |
496 | |
497 settings.$next_tip.css({ | |
498 top: (settings.$target.offset().top - settings.$next_tip.outerHeight() - nub_height + topAdjustment), | |
499 left: settings.$target.offset().left + leftAdjustment}); | |
500 | |
501 methods.nub_position($nub, settings.tipSettings.nubPosition, 'bottom'); | |
502 | |
503 } else if (methods.right()) { | |
504 | |
505 settings.$next_tip.css({ | |
506 top: settings.$target.offset().top + topAdjustment, | |
507 left: (settings.$target.outerWidth() + settings.$target.offset().left + nub_width) + leftAdjustment}); | |
508 | |
509 methods.nub_position($nub, settings.tipSettings.nubPosition, 'left'); | |
510 | |
511 } else if (methods.left()) { | |
512 | |
513 settings.$next_tip.css({ | |
514 top: settings.$target.offset().top + topAdjustment, | |
515 left: (settings.$target.offset().left - settings.$next_tip.outerWidth() - nub_width) + leftAdjustment}); | |
516 | |
517 methods.nub_position($nub, settings.tipSettings.nubPosition, 'right'); | |
518 | |
519 } | |
520 | |
521 if (!methods.visible(methods.corners(settings.$next_tip)) && settings.attempts < settings.tipSettings.tipLocationPattern.length) { | |
522 | |
523 $nub.removeClass('bottom') | |
524 .removeClass('top') | |
525 .removeClass('right') | |
526 .removeClass('left'); | |
527 | |
528 settings.tipSettings.tipLocation = settings.tipSettings.tipLocationPattern[settings.attempts]; | |
529 | |
530 settings.attempts++; | |
531 | |
532 methods.pos_default(true); | |
533 | |
534 } | |
535 | |
536 } else if (settings.$li.length) { | |
537 | |
538 methods.pos_modal($nub); | |
539 | |
540 } | |
541 | |
542 if (toggle) { | |
543 settings.$next_tip.hide(); | |
544 settings.$next_tip.css('visibility', 'visible'); | |
545 } | |
546 | |
547 }, | |
548 | |
549 pos_phone : function (init) { | |
550 var tip_height = settings.$next_tip.outerHeight(), | |
551 tip_offset = settings.$next_tip.offset(), | |
552 target_height = settings.$target.outerHeight(), | |
553 $nub = $('.joyride-nub', settings.$next_tip), | |
554 nub_height = Math.ceil($nub.outerHeight() / 2), | |
555 toggle = init || false; | |
556 | |
557 $nub.removeClass('bottom') | |
558 .removeClass('top') | |
559 .removeClass('right') | |
560 .removeClass('left'); | |
561 | |
562 if (toggle) { | |
563 settings.$next_tip.css('visibility', 'hidden'); | |
564 settings.$next_tip.show(); | |
565 } | |
566 | |
567 if (!settings.$target.is("body")) { | |
568 | |
569 if (methods.top()) { | |
570 | |
571 settings.$next_tip.offset({top: settings.$target.offset().top - tip_height - nub_height}); | |
572 $nub.addClass('bottom'); | |
573 | |
574 } else { | |
575 | |
576 settings.$next_tip.offset({top: settings.$target.offset().top + target_height + nub_height}); | |
577 $nub.addClass('top'); | |
578 | |
579 } | |
580 | |
581 } else if (settings.$li.length) { | |
582 | |
583 methods.pos_modal($nub); | |
584 | |
585 } | |
586 | |
587 if (toggle) { | |
588 settings.$next_tip.hide(); | |
589 settings.$next_tip.css('visibility', 'visible'); | |
590 } | |
591 }, | |
592 | |
593 pos_modal : function ($nub) { | |
594 methods.center(); | |
595 $nub.hide(); | |
596 | |
597 methods.show_modal(); | |
598 | |
599 }, | |
600 | |
601 show_modal : function() { | |
602 if ($('.joyride-modal-bg').length < 1) { | |
603 $('body').append(settings.template.modal).show(); | |
604 } | |
605 | |
606 if (/pop/i.test(settings.tipAnimation)) { | |
607 $('.joyride-modal-bg').show(); | |
608 } else { | |
609 $('.joyride-modal-bg').fadeIn(settings.tipAnimationFadeSpeed); | |
610 } | |
611 }, | |
612 | |
613 expose: function(){ | |
614 var expose, | |
615 exposeCover, | |
616 el, | |
617 origCSS, | |
618 randId = 'expose-'+Math.floor(Math.random()*10000); | |
619 if (arguments.length>0 && arguments[0] instanceof $){ | |
620 el = arguments[0]; | |
621 } else if(settings.$target && !settings.$target.is("body")){ | |
622 el = settings.$target; | |
623 } else { | |
624 return false; | |
625 } | |
626 if(el.length < 1){ | |
627 if(window.console){ | |
628 console.error('element not valid', el); | |
629 } | |
630 return false; | |
631 } | |
632 expose = $(settings.template.expose); | |
633 settings.$body.append(expose); | |
634 expose.css({ | |
635 top: el.offset().top, | |
636 left: el.offset().left, | |
637 width: el.outerWidth(true), | |
638 height: el.outerHeight(true) | |
639 }); | |
640 exposeCover = $(settings.template.exposeCover); | |
641 origCSS = { | |
642 zIndex: el.css('z-index'), | |
643 position: el.css('position') | |
644 }; | |
645 el.css('z-index',expose.css('z-index')*1+1); | |
646 if(origCSS.position == 'static'){ | |
647 el.css('position','relative'); | |
648 } | |
649 el.data('expose-css',origCSS); | |
650 exposeCover.css({ | |
651 top: el.offset().top, | |
652 left: el.offset().left, | |
653 width: el.outerWidth(true), | |
654 height: el.outerHeight(true) | |
655 }); | |
656 settings.$body.append(exposeCover); | |
657 expose.addClass(randId); | |
658 exposeCover.addClass(randId); | |
659 if(settings.tipSettings['exposeClass']){ | |
660 expose.addClass(settings.tipSettings['exposeClass']); | |
661 exposeCover.addClass(settings.tipSettings['exposeClass']); | |
662 } | |
663 el.data('expose', randId); | |
664 settings.postExposeCallback(settings.$li.index(), settings.$next_tip, el); | |
665 methods.add_exposed(el); | |
666 }, | |
667 | |
668 un_expose: function(){ | |
669 var exposeId, | |
670 el, | |
671 expose , | |
672 origCSS, | |
673 clearAll = false; | |
674 if (arguments.length>0 && arguments[0] instanceof $){ | |
675 el = arguments[0]; | |
676 } else if(settings.$target && !settings.$target.is("body")){ | |
677 el = settings.$target; | |
678 } else { | |
679 return false; | |
680 } | |
681 if(el.length < 1){ | |
682 if(window.console){ | |
683 console.error('element not valid', el); | |
684 } | |
685 return false; | |
686 } | |
687 exposeId = el.data('expose'); | |
688 expose = $('.'+exposeId); | |
689 if(arguments.length>1){ | |
690 clearAll = arguments[1]; | |
691 } | |
692 if(clearAll === true){ | |
693 $('.joyride-expose-wrapper,.joyride-expose-cover').remove(); | |
694 } else { | |
695 expose.remove(); | |
696 } | |
697 origCSS = el.data('expose-css'); | |
698 if(origCSS.zIndex == 'auto'){ | |
699 el.css('z-index', ''); | |
700 } else { | |
701 el.css('z-index',origCSS.zIndex); | |
702 } | |
703 if(origCSS.position != el.css('position')){ | |
704 if(origCSS.position == 'static'){// this is default, no need to set it. | |
705 el.css('position', ''); | |
706 } else { | |
707 el.css('position',origCSS.position); | |
708 } | |
709 } | |
710 el.removeData('expose'); | |
711 el.removeData('expose-z-index'); | |
712 methods.remove_exposed(el); | |
713 }, | |
714 | |
715 add_exposed: function(el){ | |
716 settings.exposed = settings.exposed || []; | |
717 if(el instanceof $){ | |
718 settings.exposed.push(el[0]); | |
719 } else if(typeof el == 'string'){ | |
720 settings.exposed.push(el); | |
721 } | |
722 }, | |
723 | |
724 remove_exposed: function(el){ | |
725 var search; | |
726 if(el instanceof $){ | |
727 search = el[0] | |
728 } else if (typeof el == 'string'){ | |
729 search = el; | |
730 } | |
731 settings.exposed = settings.exposed || []; | |
732 for(var i=0; i<settings.exposed.length; i++){ | |
733 if(settings.exposed[i] == search){ | |
734 settings.exposed.splice(i,1); | |
735 return; | |
736 } | |
737 } | |
738 }, | |
739 | |
740 center : function () { | |
741 var $w = settings.$window; | |
742 | |
743 settings.$next_tip.css({ | |
744 top : ((($w.height() - settings.$next_tip.outerHeight()) / 2) + $w.scrollTop()), | |
745 left : ((($w.width() - settings.$next_tip.outerWidth()) / 2) + $w.scrollLeft()) | |
746 }); | |
747 | |
748 return true; | |
749 }, | |
750 | |
751 bottom : function () { | |
752 return /bottom/i.test(settings.tipSettings.tipLocation); | |
753 }, | |
754 | |
755 top : function () { | |
756 return /top/i.test(settings.tipSettings.tipLocation); | |
757 }, | |
758 | |
759 right : function () { | |
760 return /right/i.test(settings.tipSettings.tipLocation); | |
761 }, | |
762 | |
763 left : function () { | |
764 return /left/i.test(settings.tipSettings.tipLocation); | |
765 }, | |
766 | |
767 corners : function (el) { | |
768 var w = settings.$window, | |
769 window_half = w.height() / 2, | |
770 tipOffset = Math.ceil(settings.$target.offset().top - window_half + settings.$next_tip.outerHeight()),//using this to calculate since scroll may not have finished yet. | |
771 right = w.width() + w.scrollLeft(), | |
772 offsetBottom = w.height() + tipOffset, | |
773 bottom = w.height() + w.scrollTop(), | |
774 top = w.scrollTop(); | |
775 | |
776 if(tipOffset < top){ | |
777 if (tipOffset <0 ){ | |
778 top = 0; | |
779 } else { | |
780 top = tipOffset; | |
781 } | |
782 } | |
783 | |
784 if(offsetBottom > bottom){ | |
785 bottom = offsetBottom; | |
786 } | |
787 | |
788 return [ | |
789 el.offset().top < top, | |
790 right < el.offset().left + el.outerWidth(), | |
791 bottom < el.offset().top + el.outerHeight(), | |
792 w.scrollLeft() > el.offset().left | |
793 ]; | |
794 }, | |
795 | |
796 visible : function (hidden_corners) { | |
797 var i = hidden_corners.length; | |
798 | |
799 while (i--) { | |
800 if (hidden_corners[i]) return false; | |
801 } | |
802 | |
803 return true; | |
804 }, | |
805 | |
806 nub_position : function (nub, pos, def) { | |
807 if (pos === 'auto') { | |
808 nub.addClass(def); | |
809 } else { | |
810 nub.addClass(pos); | |
811 } | |
812 }, | |
813 | |
814 startTimer : function () { | |
815 if (settings.$li.length) { | |
816 settings.automate = setTimeout(function () { | |
817 methods.hide(); | |
818 methods.show(); | |
819 methods.startTimer(); | |
820 }, settings.timer); | |
821 } else { | |
822 clearTimeout(settings.automate); | |
823 } | |
824 }, | |
825 | |
826 end : function (isAborted) { | |
827 isAborted = isAborted || false; | |
828 | |
829 // Unbind resize events. | |
830 if (isAborted) { | |
831 settings.$window.off('resize.joyride'); | |
832 } | |
833 | |
834 if (settings.cookieMonster) { | |
835 $.cookie(settings.cookieName, 'ridden', { expires: 365, domain: settings.cookieDomain, path: settings.cookiePath }); | |
836 } | |
837 | |
838 if (settings.localStorage) { | |
839 localStorage.setItem(settings.localStorageKey, true); | |
840 } | |
841 | |
842 if (settings.timer > 0) { | |
843 clearTimeout(settings.automate); | |
844 } | |
845 if(settings.modal && settings.expose){ | |
846 methods.un_expose(); | |
847 } | |
848 if (settings.$current_tip) { | |
849 settings.$current_tip.hide(); | |
850 } | |
851 if (settings.$li) { | |
852 settings.postStepCallback(settings.$li.index(), settings.$current_tip, isAborted); | |
853 settings.postRideCallback(settings.$li.index(), settings.$current_tip, isAborted); | |
854 } | |
855 $('.joyride-modal-bg').hide(); | |
856 }, | |
857 | |
858 jquery_check : function () { | |
859 // define on() and off() for older jQuery | |
860 if (!$.isFunction($.fn.on)) { | |
861 | |
862 $.fn.on = function (types, sel, fn) { | |
863 | |
864 return this.delegate(sel, types, fn); | |
865 | |
866 }; | |
867 | |
868 $.fn.off = function (types, sel, fn) { | |
869 | |
870 return this.undelegate(sel, types, fn); | |
871 | |
872 }; | |
873 | |
874 return false; | |
875 } | |
876 | |
877 return true; | |
878 }, | |
879 | |
880 outerHTML : function (el) { | |
881 // support FireFox < 11 | |
882 return el.outerHTML || new XMLSerializer().serializeToString(el); | |
883 }, | |
884 | |
885 version : function () { | |
886 return settings.version; | |
887 }, | |
888 | |
889 tabbable : function (el) { | |
890 $(el).on('keydown', function( event ) { | |
891 if (!event.isDefaultPrevented() && event.keyCode && | |
892 // Escape key. | |
893 event.keyCode === 27 ) { | |
894 event.preventDefault(); | |
895 methods.end(true /* isAborted */); | |
896 return; | |
897 } | |
898 | |
899 // Prevent tabbing out of tour items. | |
900 if ( event.keyCode !== 9 ) { | |
901 return; | |
902 } | |
903 var tabbables = $(el).find(":tabbable"), | |
904 first = tabbables.filter(":first"), | |
905 last = tabbables.filter(":last"); | |
906 if ( event.target === last[0] && !event.shiftKey ) { | |
907 first.focus( 1 ); | |
908 event.preventDefault(); | |
909 } else if ( event.target === first[0] && event.shiftKey ) { | |
910 last.focus( 1 ); | |
911 event.preventDefault(); | |
912 } | |
913 }); | |
914 } | |
915 | |
916 }; | |
917 | |
918 $.fn.joyride = function (method) { | |
919 if (methods[method]) { | |
920 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); | |
921 } else if (typeof method === 'object' || !method) { | |
922 return methods.init.apply(this, arguments); | |
923 } else { | |
924 $.error('Method ' + method + ' does not exist on jQuery.joyride'); | |
925 } | |
926 }; | |
927 | |
928 }(jQuery, this)); |