123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654 |
- /*
- * jQuery Foundation Joyride Plugin 2.0.3
- * http://foundation.zurb.com
- * Copyright 2012, ZURB
- * Free to use under the MIT license.
- * http://www.opensource.org/licenses/mit-license.php
- */
-
- /*jslint unparam: true, browser: true, indent: 2 */
-
- ;(function ($, window, undefined) {
- 'use strict';
-
- var defaults = {
- 'version' : '2.0.3',
- 'tipLocation' : 'bottom', // 'top' or 'bottom' in relation to parent
- 'nubPosition' : 'auto', // override on a per tooltip bases
- 'scrollSpeed' : 300, // Page scrolling speed in milliseconds
- 'timer' : 0, // 0 = no timer , all other numbers = timer in milliseconds
- 'startTimerOnClick' : true, // true or false - true requires clicking the first button start the timer
- 'startOffset' : 0, // the index of the tooltip you want to start on (index of the li)
- 'nextButton' : true, // true or false to control whether a next button is used
- 'tipAnimation' : 'fade', // 'pop' or 'fade' in each tip
- 'pauseAfter' : [], // array of indexes where to pause the tour after
- 'tipAnimationFadeSpeed': 300, // when tipAnimation = 'fade' this is speed in milliseconds for the transition
- 'cookieMonster' : false, // true or false to control whether cookies are used
- 'cookieName' : 'joyride', // Name the cookie you'll use
- 'cookieDomain' : false, // Will this cookie be attached to a domain, ie. '.notableapp.com'
- 'tipContainer' : 'body', // Where will the tip be attached
- 'postRideCallback' : $.noop, // A method to call once the tour closes (canceled or complete)
- 'postStepCallback' : $.noop, // A method to call after each step
- 'template' : { // HTML segments for tip layout
- 'link' : '<a href="#close" class="joyride-close-tip">X</a>',
- 'timer' : '<div class="joyride-timer-indicator-wrap"><span class="joyride-timer-indicator"></span></div>',
- 'tip' : '<div class="joyride-tip-guide"><span class="joyride-nub"></span></div>',
- 'wrapper' : '<div class="joyride-content-wrapper"></div>',
- 'button' : '<a href="#" class="joyride-next-tip"></a>'
- }
- },
-
- Modernizr = Modernizr || false,
-
- settings = {},
-
- methods = {
-
- init : function (opts) {
- return this.each(function () {
-
- if ($.isEmptyObject(settings)) {
- settings = $.extend(true, defaults, opts);
-
- // non configurable settings
- settings.document = window.document;
- settings.$document = $(settings.document);
- settings.$window = $(window);
- settings.$content_el = $(this);
- settings.body_offset = $(settings.tipContainer).position();
- settings.$tip_content = $('> li', settings.$content_el);
- settings.paused = false;
- settings.attempts = 0;
-
- settings.tipLocationPatterns = {
- top: ['bottom'],
- bottom: [], // bottom should not need to be repositioned
- left: ['right', 'top', 'bottom'],
- right: ['left', 'top', 'bottom']
- };
-
- // are we using jQuery 1.7+
- methods.jquery_check();
-
- // can we create cookies?
- if (!$.isFunction($.cookie)) {
- settings.cookieMonster = false;
- }
-
- // generate the tips and insert into dom.
- if (!settings.cookieMonster || !$.cookie(settings.cookieName)) {
-
- settings.$tip_content.each(function (index) {
- methods.create({$li : $(this), index : index});
- });
-
- // show first tip
- if (!settings.startTimerOnClick && settings.timer > 0) {
- methods.show('init');
- methods.startTimer();
- } else {
- methods.show('init');
- }
-
- }
-
- settings.$document.on('click.joyride', '.joyride-next-tip, .joyride-modal-bg', function (e) {
- e.preventDefault();
-
- if (settings.$li.next().length < 1) {
- methods.end();
- } else if (settings.timer > 0) {
- clearTimeout(settings.automate);
- methods.hide();
- methods.show();
- methods.startTimer();
- } else {
- methods.hide();
- methods.show();
- }
-
- });
-
- settings.$document.on('click.joyride', '.joyride-close-tip', function (e) {
- e.preventDefault();
- methods.end();
- });
-
- settings.$window.bind('resize.joyride', function (e) {
- if (methods.is_phone()) {
- methods.pos_phone();
- } else {
- methods.pos_default();
- }
- });
- } else {
- methods.restart();
- }
-
- });
- },
-
- // call this method when you want to resume the tour
- resume : function () {
- methods.set_li();
- methods.show();
- },
-
- nextTip: function(){
- if (settings.$li.next().length < 1) {
- methods.end();
- } else if (settings.timer > 0) {
- clearTimeout(settings.automate);
- methods.hide();
- methods.show();
- methods.startTimer();
- } else {
- methods.hide();
- methods.show();
- }
- },
-
- tip_template : function (opts) {
- var $blank, content;
-
- opts.tip_class = opts.tip_class || '';
-
- $blank = $(settings.template.tip).addClass(opts.tip_class);
- content = $.trim($(opts.li).html()) +
- methods.button_text(opts.button_text) +
- settings.template.link +
- methods.timer_instance(opts.index);
-
- $blank.append($(settings.template.wrapper));
- $blank.first().attr('data-index', opts.index);
- $('.joyride-content-wrapper', $blank).append(content);
-
- return $blank[0];
- },
-
- timer_instance : function (index) {
- var txt;
-
- if ((index === 0 && settings.startTimerOnClick && settings.timer > 0) || settings.timer === 0) {
- txt = '';
- } else {
- txt = methods.outerHTML($(settings.template.timer)[0]);
- }
- return txt;
- },
-
- button_text : function (txt) {
- if (settings.nextButton) {
- txt = $.trim(txt) || 'Next';
- txt = methods.outerHTML($(settings.template.button).append(txt)[0]);
- } else {
- txt = '';
- }
- return txt;
- },
-
- create : function (opts) {
- // backwards compatibility with data-text attribute
- var buttonText = opts.$li.attr('data-button') || opts.$li.attr('data-text'),
- tipClass = opts.$li.attr('class'),
- $tip_content = $(methods.tip_template({
- tip_class : tipClass,
- index : opts.index,
- button_text : buttonText,
- li : opts.$li
- }));
-
- $(settings.tipContainer).append($tip_content);
- },
-
- show : function (init) {
- var opts = {}, ii, opts_arr = [], opts_len = 0, p,
- $timer = null;
-
- // are we paused?
- if (settings.$li === undefined || ($.inArray(settings.$li.index(), settings.pauseAfter) === -1)) {
-
- // don't go to the next li if the tour was paused
- if (settings.paused) {
- settings.paused = false;
- } else {
- methods.set_li(init);
- }
-
- settings.attempts = 0;
-
- if (settings.$li.length && settings.$target.length > 0) {
- opts_arr = (settings.$li.data('options') || ':').split(';');
- opts_len = opts_arr.length;
-
- // parse options
- for (ii = opts_len - 1; ii >= 0; ii--) {
- p = opts_arr[ii].split(':');
-
- if (p.length === 2) {
- opts[$.trim(p[0])] = $.trim(p[1]);
- }
- }
-
- settings.tipSettings = $.extend({}, settings, opts);
-
- settings.tipSettings.tipLocationPattern = settings.tipLocationPatterns[settings.tipSettings.tipLocation];
-
- // scroll if not modal
- if (!/body/i.test(settings.$target.selector)) {
- methods.scroll_to();
- }
-
- if (methods.is_phone()) {
- methods.pos_phone(true);
- } else {
- methods.pos_default(true);
- }
-
- $timer = $('.joyride-timer-indicator', settings.$next_tip);
-
- if (/pop/i.test(settings.tipAnimation)) {
-
- $timer.outerWidth(0);
-
- if (settings.timer > 0) {
-
- settings.$next_tip.show();
- $timer.animate({
- width: $('.joyride-timer-indicator-wrap', settings.$next_tip).outerWidth()
- }, settings.timer);
-
- } else {
-
- settings.$next_tip.show();
-
- }
-
-
- } else if (/fade/i.test(settings.tipAnimation)) {
-
- $timer.outerWidth(0);
-
- if (settings.timer > 0) {
-
- settings.$next_tip.fadeIn(settings.tipAnimationFadeSpeed);
-
- settings.$next_tip.show();
- $timer.animate({
- width: $('.joyride-timer-indicator-wrap', settings.$next_tip).outerWidth()
- }, settings.timer);
-
- } else {
-
- settings.$next_tip.fadeIn(settings.tipAnimationFadeSpeed);
-
- }
- }
-
- settings.$current_tip = settings.$next_tip;
-
- // skip non-existent targets
- } else if (settings.$li && settings.$target.length < 1) {
-
- methods.show();
-
- } else {
-
- methods.end();
-
- }
- } else {
-
- settings.paused = true;
-
- }
-
- },
-
- // detect phones with media queries if supported.
- is_phone : function () {
- if (Modernizr) {
- return Modernizr.mq('only screen and (max-width: 767px)');
- }
-
- return (settings.$window.width() < 767) ? true : false;
- },
-
- hide : function () {
- settings.postStepCallback(settings.$li.index(), settings.$current_tip);
- $('.joyride-modal-bg').hide();
- settings.$current_tip.hide();
- },
-
- set_li : function (init) {
- if (init) {
- settings.$li = settings.$tip_content.eq(settings.startOffset);
- methods.set_next_tip();
- settings.$current_tip = settings.$next_tip;
- } else {
- settings.$li = settings.$li.next();
- methods.set_next_tip();
- }
-
- methods.set_target();
- },
-
- set_next_tip : function () {
- settings.$next_tip = $('.joyride-tip-guide[data-index=' + settings.$li.index() + ']');
- },
-
- set_target : function () {
- var cl = settings.$li.attr('data-class'),
- id = settings.$li.attr('data-id'),
- $sel = function () {
- if (id) {
- return $(settings.document.getElementById(id));
- } else if (cl) {
- return $('.' + cl).first();
- } else {
- return $('body');
- }
- };
-
- settings.$target = $sel();
- },
-
- scroll_to : function () {
- var window_half, tipOffset;
-
- window_half = settings.$window.height() / 2;
- tipOffset = Math.ceil(settings.$target.offset().top - window_half + settings.$next_tip.outerHeight());
-
- $("html, body").stop().animate({
- scrollTop: tipOffset
- }, settings.scrollSpeed);
- },
-
- paused : function () {
- if (($.inArray((settings.$li.index() + 1), settings.pauseAfter) === -1)) {
- return true;
- }
-
- return false;
- },
-
- destroy : function () {
- settings.$document.off('.joyride');
- $(window).off('.joyride');
- $('.joyride-close-tip, .joyride-next-tip, .joyride-modal-bg').off('.joyride');
- $('.joyride-tip-guide, .joyride-modal-bg').remove();
- clearTimeout(settings.automate);
- settings = {};
- },
-
- restart : function () {
- methods.hide();
- settings.$li = undefined;
- methods.show('init');
- },
-
- pos_default : function (init) {
- var half_fold = Math.ceil(settings.$window.height() / 2),
- tip_position = settings.$next_tip.offset(),
- $nub = $('.joyride-nub', settings.$next_tip),
- nub_height = Math.ceil($nub.outerHeight() / 2),
- toggle = init || false;
-
- // tip must not be "display: none" to calculate position
- if (toggle) {
- settings.$next_tip.css('visibility', 'hidden');
- settings.$next_tip.show();
- }
-
- if (!/body/i.test(settings.$target.selector)) {
-
- if (methods.bottom()) {
- settings.$next_tip.css({
- top: (settings.$target.offset().top + nub_height + settings.$target.outerHeight()),
- left: settings.$target.offset().left});
-
- methods.nub_position($nub, settings.tipSettings.nubPosition, 'top');
-
- } else if (methods.top()) {
-
- settings.$next_tip.css({
- top: (settings.$target.offset().top - settings.$next_tip.outerHeight() - nub_height),
- left: settings.$target.offset().left});
-
- methods.nub_position($nub, settings.tipSettings.nubPosition, 'bottom');
-
- } else if (methods.right()) {
-
- settings.$next_tip.css({
- top: settings.$target.offset().top,
- left: (settings.$target.outerWidth() + settings.$target.offset().left)});
-
- methods.nub_position($nub, settings.tipSettings.nubPosition, 'left');
-
- } else if (methods.left()) {
-
- settings.$next_tip.css({
- top: settings.$target.offset().top,
- left: (settings.$target.offset().left - settings.$next_tip.outerWidth() - nub_height)});
-
- methods.nub_position($nub, settings.tipSettings.nubPosition, 'right');
-
- }
-
- if (!methods.visible(methods.corners(settings.$next_tip)) && settings.attempts < settings.tipSettings.tipLocationPattern.length) {
-
- $nub.removeClass('bottom')
- .removeClass('top')
- .removeClass('right')
- .removeClass('left');
-
- settings.tipSettings.tipLocation = settings.tipSettings.tipLocationPattern[settings.attempts];
-
- settings.attempts++;
-
- methods.pos_default(true);
-
- }
-
- } else if (settings.$li.length) {
-
- methods.pos_modal($nub);
-
- }
-
- if (toggle) {
- settings.$next_tip.hide();
- settings.$next_tip.css('visibility', 'visible');
- }
-
- },
-
- pos_phone : function (init) {
- var tip_height = settings.$next_tip.outerHeight(),
- tip_offset = settings.$next_tip.offset(),
- target_height = settings.$target.outerHeight(),
- $nub = $('.joyride-nub', settings.$next_tip),
- nub_height = Math.ceil($nub.outerHeight() / 2),
- toggle = init || false;
-
- $nub.removeClass('bottom')
- .removeClass('top')
- .removeClass('right')
- .removeClass('left');
-
- if (toggle) {
- settings.$next_tip.css('visibility', 'hidden');
- settings.$next_tip.show();
- }
-
- if (!/body/i.test(settings.$target.selector)) {
-
- if (methods.top()) {
-
- settings.$next_tip.offset({top: settings.$target.offset().top - tip_height - nub_height});
- $nub.addClass('bottom');
-
- } else {
-
- settings.$next_tip.offset({top: settings.$target.offset().top + target_height + nub_height});
- $nub.addClass('top');
-
- }
-
- } else if (settings.$li.length) {
-
- methods.pos_modal($nub);
-
- }
-
- if (toggle) {
- settings.$next_tip.hide();
- settings.$next_tip.css('visibility', 'visible');
- }
- },
-
- pos_modal : function ($nub) {
- methods.center();
- $nub.hide();
-
- if ($('.joyride-modal-bg').length < 1) {
- $('body').append('<div class="joyride-modal-bg">').show();
- }
-
- if (/pop/i.test(settings.tipAnimation)) {
- $('.joyride-modal-bg').show();
- } else {
- $('.joyride-modal-bg').fadeIn(settings.tipAnimationFadeSpeed);
- }
- },
-
- center : function () {
- var $w = settings.$window;
-
- settings.$next_tip.css({
- top : ((($w.height() - settings.$next_tip.outerHeight()) / 2) + $w.scrollTop()),
- left : ((($w.width() - settings.$next_tip.outerWidth()) / 2) + $w.scrollLeft())
- });
-
- return true;
- },
-
- bottom : function () {
- return /bottom/i.test(settings.tipSettings.tipLocation);
- },
-
- top : function () {
- return /top/i.test(settings.tipSettings.tipLocation);
- },
-
- right : function () {
- return /right/i.test(settings.tipSettings.tipLocation);
- },
-
- left : function () {
- return /left/i.test(settings.tipSettings.tipLocation);
- },
-
- corners : function (el) {
- var w = settings.$window,
- right = w.width() + w.scrollLeft(),
- bottom = w.width() + w.scrollTop();
-
- return [
- el.offset().top <= w.scrollTop(),
- right <= el.offset().left + el.outerWidth(),
- bottom <= el.offset().top + el.outerHeight(),
- w.scrollLeft() >= el.offset().left
- ];
- },
-
- visible : function (hidden_corners) {
- var i = hidden_corners.length;
-
- while (i--) {
- if (hidden_corners[i]) return false;
- }
-
- return true;
- },
-
- nub_position : function (nub, pos, def) {
- if (pos === 'auto') {
- nub.addClass(def);
- } else {
- nub.addClass(pos);
- }
- },
-
- startTimer : function () {
- if (settings.$li.length) {
- settings.automate = setTimeout(function () {
- methods.hide();
- methods.show();
- methods.startTimer();
- }, settings.timer);
- } else {
- clearTimeout(settings.automate);
- }
- },
-
- end : function () {
- if (settings.cookieMonster) {
- $.cookie(settings.cookieName, 'ridden', { expires: 365, domain: settings.cookieDomain });
- }
-
- if (settings.timer > 0) {
- clearTimeout(settings.automate);
- }
-
- $('.joyride-modal-bg').hide();
- settings.$current_tip.hide();
- settings.postStepCallback(settings.$li.index(), settings.$current_tip);
- settings.postRideCallback(settings.$li.index(), settings.$current_tip);
- },
-
- jquery_check : function () {
- // define on() and off() for older jQuery
- if (!$.isFunction($.fn.on)) {
-
- $.fn.on = function (types, sel, fn) {
-
- return this.delegate(sel, types, fn);
-
- };
-
- $.fn.off = function (types, sel, fn) {
-
- return this.undelegate(sel, types, fn);
-
- };
-
- return false;
- }
-
- return true;
- },
-
- outerHTML : function (el) {
- // support FireFox < 11
- return el.outerHTML || new XMLSerializer().serializeToString(el);
- },
-
- version : function () {
- return settings.version;
- }
-
- };
-
- $.fn.joyride = function (method) {
- if (methods[method]) {
- return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
- } else if (typeof method === 'object' || !method) {
- return methods.init.apply(this, arguments);
- } else {
- $.error('Method ' + method + ' does not exist on jQuery.joyride');
- }
- };
-
- }(jQuery, this));
|