Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribut data-areaid + Jquery 3 #219

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 59 additions & 14 deletions jquery.joyride-2.1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* jQuery Foundation Joyride Plugin 2.1
* http://foundation.zurb.com
* Copyright 2013, ZURB
Expand All @@ -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
Expand All @@ -45,6 +46,7 @@
'tip' : '<div class="joyride-tip-guide"><span class="joyride-nub"></span></div>',
'wrapper' : '<div class="joyride-content-wrapper" role="dialog"></div>',
'button' : '<a href="#" class="joyride-next-tip"></a>',
'prev_button': '<a href="#" class="small button joyride-prev-tip"></a>',
'modal' : '<div class="joyride-modal-bg"></div>',
'expose' : '<div class="joyride-expose-wrapper"></div>',
'exposeCover': '<div class="joyride-expose-cover"></div>'
Expand Down Expand Up @@ -124,15 +126,28 @@
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) {
e.preventDefault();
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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -247,7 +281,7 @@
if (settings.paused) {
settings.paused = false;
} else {
methods.set_li(init);
methods.set_li(init, is_prev);
}

settings.attempts = 0;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -564,7 +610,7 @@
settings.$next_tip.show();
}

if (!/body/i.test(settings.$target.selector)) {
if (!settings.$target.is("body")) {

if (methods.top()) {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
},

Expand Down Expand Up @@ -828,7 +873,7 @@

// Unbind resize events.
if (isAborted) {
settings.$window.unbind('resize.joyride');
settings.$window.off('resize.joyride');
}

if (settings.cookieMonster) {
Expand Down