diff --git a/jquery.joyride-2.1.js b/jquery.joyride-2.1.js index 72fb38d..ac2b20d 100755 --- a/jquery.joyride-2.1.js +++ b/jquery.joyride-2.1.js @@ -1,4 +1,4 @@ - /* +/* * jQuery Foundation Joyride Plugin 2.1 * http://foundation.zurb.com * Copyright 2013, ZURB @@ -22,6 +22,7 @@ '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 + 'prev_button' : true, // true or false to control whether a prev 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 @@ -45,6 +46,7 @@ 'tip' : '
', 'wrapper' : '', 'button' : '', + 'prev_button': '', 'modal' : '
', 'expose' : '
', 'exposeCover': '
' @@ -124,7 +126,20 @@ methods.hide(); methods.show(); } + }).on('click.joyride', '.joyride-prev-tip', function (e) { + e.preventDefault(); + if (settings.$li.prev().length < 1) { + // Do nothing if there are no prev element + } else if (settings.timer > 0) { + clearTimeout(settings.automate); + methods.hide(); + methods.show(null, true); + methods.startTimer(); + } else { + methods.hide(); + methods.show(null, true); + } }); settings.$document.on('click.joyride', '.joyride-close-tip', function (e) { @@ -132,7 +147,7 @@ methods.end(true /* isAborted */); }); - settings.$window.bind('resize.joyride', function (e) { + settings.$window.on('resize.joyride', function (e) { if(settings.$li){ if(settings.exposed && settings.exposed.length>0){ var $els = $(settings.exposed); @@ -183,6 +198,7 @@ $blank = $(settings.template.tip).addClass(opts.tip_class); content = $.trim($(opts.li).html()) + + methods.prev_button_text(opts.prev_button_text, opts.index) + methods.button_text(opts.button_text) + settings.template.link + methods.timer_instance(opts.index); @@ -222,21 +238,39 @@ return txt; }, + prev_button_text : function (txt, idx) { + if (settings.prev_button) { + txt = $.trim(txt) || 'Previous'; + + // Don't show the button if it's the first element + if (idx == 0) { + txt = ''; + } + else + txt = $(settings.template.prev_button).append(txt)[0].outerHTML; + } 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'), + prevButtonText = opts.$li.attr('data-button-prev') || opts.$li.attr('data-prev-text'), tipClass = opts.$li.attr('class'), $tip_content = $(methods.tip_template({ tip_class : tipClass, index : opts.index, button_text : buttonText, + prev_button_text : prevButtonText, li : opts.$li })); $(settings.tipContainer).append($tip_content); }, - show : function (init) { + show : function (init, is_prev) { var opts = {}, ii, opts_arr = [], opts_len = 0, p, $timer = null; @@ -247,7 +281,7 @@ if (settings.paused) { settings.paused = false; } else { - methods.set_li(init); + methods.set_li(init, is_prev); } settings.attempts = 0; @@ -279,7 +313,7 @@ } // scroll if not modal - if (!/body/i.test(settings.$target.selector) && settings.scroll) { + if (!settings.$target.is("body") && settings.scroll) { methods.scroll_to(); } @@ -379,13 +413,16 @@ settings.postStepCallback(settings.$li.index(), settings.$current_tip); }, - set_li : function (init) { + set_li : function (init, is_prev) { 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(); + if (is_prev) + settings.$li = settings.$li.prev(); + else + settings.$li = settings.$li.next(); methods.set_next_tip(); } @@ -401,7 +438,16 @@ id = settings.$li.attr('data-id'), $sel = function () { if (id) { - return $(settings.document.getElementById(id)); + var elt = $("[data-areaid='"+id+"']"); + if (elt.length>1){ + return elt[0]; + } + else if (elt.length==1){ + return elt; + } + else { + return $(settings.document.getElementById(id)); + } } else if (cl) { return $('.' + cl).filter(":visible").first(); } else { @@ -476,7 +522,7 @@ settings.$next_tip.show(); } - if (!/body/i.test(settings.$target.selector)) { + if (!settings.$target.is("body")) { var topAdjustment = settings.tipSettings.tipAdjustmentY ? parseInt(settings.tipSettings.tipAdjustmentY) : 0, leftAdjustment = settings.tipSettings.tipAdjustmentX ? parseInt(settings.tipSettings.tipAdjustmentX) : 0; @@ -564,7 +610,7 @@ settings.$next_tip.show(); } - if (!/body/i.test(settings.$target.selector)) { + if (!settings.$target.is("body")) { if (methods.top()) { @@ -618,7 +664,7 @@ randId = 'expose-'+Math.floor(Math.random()*10000); if (arguments.length>0 && arguments[0] instanceof $){ el = arguments[0]; - } else if(settings.$target && !/body/i.test(settings.$target.selector)){ + } else if(settings.$target && !settings.$target.is("body")){ el = settings.$target; } else { return false; @@ -673,7 +719,7 @@ clearAll = false; if (arguments.length>0 && arguments[0] instanceof $){ el = arguments[0]; - } else if(settings.$target && !/body/i.test(settings.$target.selector)){ + } else if(settings.$target && !settings.$target.is("body")){ el = settings.$target; } else { return false; @@ -744,7 +790,6 @@ top : ((($w.height() - settings.$next_tip.outerHeight()) / 2) + $w.scrollTop()), left : ((($w.width() - settings.$next_tip.outerWidth()) / 2) + $w.scrollLeft()) }); - return true; }, @@ -828,7 +873,7 @@ // Unbind resize events. if (isAborted) { - settings.$window.unbind('resize.joyride'); + settings.$window.off('resize.joyride'); } if (settings.cookieMonster) {