From e73c4e5c43e359292f03a925d548bb3690f5e1ec Mon Sep 17 00:00:00 2001 From: Gordon Koo Date: Mon, 1 Apr 2013 15:27:35 -0700 Subject: [PATCH] move onShow callback to invoke after bubble actually shows (in case of windowScroll) --- js/hopscotch-0.0.5.js | 24 ++++++++++++---------- js/hopscotch-0.0.5.min.js | 42 +++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/js/hopscotch-0.0.5.js b/js/hopscotch-0.0.5.js index 2eb046a9..10439782 100644 --- a/js/hopscotch-0.0.5.js +++ b/js/hopscotch-0.0.5.js @@ -1656,7 +1656,16 @@ cookieVal = currTour.id + ':' + stepNum, bubble = getBubble(), targetEl = utils.getStepTarget(step), - isLast; + isLast, + showBubble; + + showBubble = function() { + bubble.show(); + utils.invokeEventCallbacks('show'); + if (step.onShow) { + utils.invokeCallback(step.onShow); + } + }; // Update bubble for current step currStepNum = stepNum; @@ -1668,18 +1677,12 @@ isLast = (stepNum === numTourSteps - 1); bubble.render(step, stepNum, isLast, function(adjustScroll) { - // when done adjusting window scroll, call bubble.show() + // when done adjusting window scroll, call showBubble helper fn if (adjustScroll) { - adjustWindowScroll(function() { - bubble.show(); - }); + adjustWindowScroll(showBubble); } else { - bubble.show(); - } - - if (step.onShow) { - utils.invokeCallback(step.onShow); + showBubble(); } // If we want to advance to next step when user clicks on target. @@ -1687,7 +1690,6 @@ utils.addClickListener(targetEl, targetClickNextFn); } }); - utils.invokeEventCallbacks('show'); if (step.multipage) { cookieVal += ':mp'; diff --git a/js/hopscotch-0.0.5.min.js b/js/hopscotch-0.0.5.min.js index 2e465cde..f693069e 100644 --- a/js/hopscotch-0.0.5.min.js +++ b/js/hopscotch-0.0.5.min.js @@ -1,13 +1,13 @@ -(function(v,B){var j,w,C,m,D=window.Sizzle||null,b,p,x,l=v[B],E=!1,s={animate:!1,smoothScroll:!0,scrollDuration:1E3,scrollTopMargin:200,showCloseButton:!0,showPrevButton:!1,showNextButton:!0,bubbleWidth:280,bubblePadding:15,arrowWidth:20,skipIfNoElement:!0},y="undefined"!==typeof window.jQuery,t="undefined"!==typeof window.sessionStorage;j=document.head.style;var G="undefined"!==typeof j.MozTransition||"undefined"!==typeof j.MsTransition||"undefined"!==typeof j.webkitTransition||"undefined"!==typeof j.OTransition|| -"undefined"!==typeof j.transition;l||(j=function(){E&&l.startTour()},window.addEventListener?window.addEventListener("load",j,!1):window.attachEvent&&window.attachEvent("onload",j),b={addClass:function(a,c){var b,e,f;if(0===a.className.length)a.className=c;else{b=a.className.split(/\s+/);e=0;for(f=b.length;eg||g>=h.steps.length?null:h.steps[g]},t=function(){c.nextStep(!1)},z=function(a,f){var r,d;0<=g+a&&g+ad&&c.onPrev&&b.invokeCallback(c.onPrev),b.invokeEventCallbacks(0g?e:g,h=b.getScrollTop(),g=h+b.getWindowHeight(),n=a-f.scrollTopMargin,r,F,j;a>=h&&(a<=h+f.scrollTopMargin||e<=g)?d&&d():f.smoothScroll?"undefined"!==typeof YAHOO&&"undefined"!==typeof YAHOO.env&&"undefined"!==typeof YAHOO.env.ua&&"undefined"!==typeof YAHOO.util&&"undefined"!==typeof YAHOO.util.Scroll?(a=YAHOO.env.ua.webkit?document.body:document.documentElement, -e=YAHOO.util.Easing?YAHOO.util.Easing.easeOut:void 0,a=new YAHOO.util.Scroll(a,{scroll:{to:[0,n]}},f.scrollDuration/1E3,e),a.onComplete.subscribe(d),a.animate()):y?$("body, html").animate({scrollTop:n},f.scrollDuration,d):(0>n&&(n=0),r=h>a?-1:1,F=Math.abs(h-n)/(f.scrollDuration/10),j=function(){var a=b.getScrollTop(),c=a+r*F;0=n||0>r&&c<=n?(c=n,d&&d(),window.scrollTo(0,c)):(window.scrollTo(0,c),b.getScrollTop()===a?d&&d():setTimeout(j,10))},j()):(window.scrollTo(0,n),d&&d())}else i.show();c.onShow&& -b.invokeCallback(c.onShow);c.nextOnTargetClick&&b.addClickListener(k,t)});b.invokeEventCallbacks("show");c.multipage&&(e+=":mp");b.setState(f.cookieName,e,1)},c.delay||0);return this};this.prevStep=function(a){v.call(this,a,-1);return this};this.nextStep=function(a){var c=q(),d=b.getStepTarget(c);c.nextOnTargetClick&&b.removeClickListener(d,t);v.call(this,a,1);return this};this.endTour=function(a,c){var d=u(),a=b.valOrDefault(a,!0),c=b.valOrDefault(c,!0);g=0;k=void 0;d.hide();a&&b.clearState(f.cookieName); -l.isActive=!1;h&&c&&b.invokeEventCallbacks("end");l.removeCallbacks(!0);h=null;return this};this.getCurrTour=function(){return h};this.getCurrStepNum=function(){return g};this.listen=function(a,b,c){a&&p[a].push({cb:b,fromTour:c});return this};this.unlisten=function(a,b){var c=p[a],d,e;d=0;for(e=c.length;dg||g>=h.steps.length?null:h.steps[g]},r=function(){c.nextStep(!1)},z=function(a,f){var t,d;0<=g+a&&g+ad&&c.onPrev&&b.invokeCallback(c.onPrev),b.invokeEventCallbacks(0e?d:e,g=b.getScrollTop(),e=g+b.getWindowHeight(),h=a-f.scrollTopMargin,x,t,i;a>=g&&(a<=g+f.scrollTopMargin||d<=e)?j&&j():f.smoothScroll?"undefined"!==typeof YAHOO&&"undefined"!==typeof YAHOO.env&&"undefined"!==typeof YAHOO.env.ua&&"undefined"!==typeof YAHOO.util&&"undefined"!==typeof YAHOO.util.Scroll?(a=YAHOO.env.ua.webkit? +document.body:document.documentElement,d=YAHOO.util.Easing?YAHOO.util.Easing.easeOut:void 0,a=new YAHOO.util.Scroll(a,{scroll:{to:[0,h]}},f.scrollDuration/1E3,d),a.onComplete.subscribe(j),a.animate()):y?$("body, html").animate({scrollTop:h},f.scrollDuration,j):(0>h&&(h=0),x=g>a?-1:1,t=Math.abs(g-h)/(f.scrollDuration/10),i=function(){var a=b.getScrollTop(),c=a+x*t;0=h||0>x&&c<=h?(c=h,j&&j(),window.scrollTo(0,c)):(window.scrollTo(0,c),b.getScrollTop()===a?j&&j():setTimeout(i,10))},i()):(window.scrollTo(0, +h),j&&j())}else j();c.nextOnTargetClick&&b.addClickListener(k,r)});c.multipage&&(e+=":mp");b.setState(f.cookieName,e,1)},c.delay||0);return this};this.prevStep=function(a){u.call(this,a,-1);return this};this.nextStep=function(a){var c=p(),d=b.getStepTarget(c);c.nextOnTargetClick&&b.removeClickListener(d,r);u.call(this,a,1);return this};this.endTour=function(a,c){var d=s(),a=b.valOrDefault(a,!0),c=b.valOrDefault(c,!0);g=0;k=void 0;d.hide();a&&b.clearState(f.cookieName);l.isActive=!1;h&&c&&b.invokeEventCallbacks("end"); +l.removeCallbacks(!0);h=null;return this};this.getCurrTour=function(){return h};this.getCurrStepNum=function(){return g};this.listen=function(a,b,c){a&&n[a].push({cb:b,fromTour:c});return this};this.unlisten=function(a,b){var c=n[a],d,e;d=0;for(e=c.length;d