From 680ef4bdb89db158ecf77a194518cf8c49fa138b Mon Sep 17 00:00:00 2001 From: Gordon Koo Date: Tue, 4 Sep 2012 11:57:36 -0700 Subject: [PATCH] fix delay for nextOnTargetClick --- js/hopscotch-min.js | 2 +- js/hopscotch.js | 192 ++++++++++++++++++++------------------------ 2 files changed, 88 insertions(+), 106 deletions(-) diff --git a/js/hopscotch-min.js b/js/hopscotch-min.js index 472113bb..d4d1ec55 100644 --- a/js/hopscotch-min.js +++ b/js/hopscotch-min.js @@ -1 +1 @@ -(function(c,e){var o,g,l,k,i,a,n=c[e],j="undefined",b=false,d=(typeof window.jQuery!==j),m=(typeof window.sessionStorage!==j),h=document.body.style,f=(typeof h.MozTransition!==j||typeof h.MsTransition!==j||typeof h.webkitTransition!==j||typeof h.OTransition!==j||typeof h.transition!==j);if(n){return}a=function(){if(b){n.startTour()}};if(window.addEventListener){window.addEventListener("load",a)}else{if(window.attachEvent){window.attachEvent("onload",a)}}k={addClass:function(r,t){var q,s,p;if(r.className.length===0){r.className=t}else{q=r.className.split(" ");for(s=0,p=q.length;s=0){k.addClass(w,"prev")}else{k.addClass(w,"next")}return w},r=function(x,w,z){var y="hide";if(z){y="hide-all"}if(typeof w===j){w=true}if(w){k.removeClass(x,y)}else{k.addClass(x,y)}},s=function(C,z){var F,w,D,y,E,A,B=6,I=k.getStepTarget(z),x=C.element,H=C.arrowEl,G=k.getPixelValue(z.arrowOffset);F=k.getPixelValue(z.width)||u.bubbleWidth;D=k.valOrDefault(z.padding,u.bubblePadding);k.removeClass(x,"fade-in-down fade-in-up fade-in-left fade-in-right");y=I.getBoundingClientRect();if(z.orientation==="top"){w=x.offsetHeight;E=(y.top-w)-u.arrowWidth;A=y.left}else{if(z.orientation==="bottom"){E=y.bottom+u.arrowWidth;A=y.left}else{if(z.orientation==="left"){E=y.top;A=y.left-F-2*D-2*B-u.arrowWidth}else{if(z.orientation==="right"){E=y.top;A=y.right+u.arrowWidth}}}}if(!G){H.style.top="";H.style.left=""}else{if(z.orientation==="top"||z.orientation==="bottom"){H.style.top="";H.style.left=G+"px"}else{if(z.orientation==="left"||z.orientation==="right"){H.style.left="";H.style.top=G+"px"}}}A+=k.getPixelValue(z.xOffset);E+=k.getPixelValue(z.yOffset);if(!z.fixedElement){E+=k.getScrollTop();A+=k.getScrollLeft()}x.style.position=(z.fixedElement?"fixed":"absolute");if(u.animate&&d&&!f){$(x).animate({top:E+"px",left:A+"px"})}else{x.style.top=E+"px";x.style.left=A+"px"}},v=function(){var A=document.createElement("div"),B=document.createElement("div"),z=document.createElement("div"),y=this,C=false,x,w;this.element=A;this.containerEl=B;this.titleEl=document.createElement("h3");this.numberEl=document.createElement("span");this.contentEl=document.createElement("p");A.id="hopscotch-bubble";k.addClass(A,"animated");B.id="hopscotch-bubble-container";this.numberEl.id="hopscotch-bubble-number";B.appendChild(this.numberEl);z.appendChild(this.titleEl);z.appendChild(this.contentEl);z.id="hopscotch-bubble-content";B.appendChild(z);A.appendChild(B);this.initNavButtons();this.initCloseButton();this.initArrow();x=function(){if(C||!q){return}C=true;w=setTimeout(function(){s(y,p,false);C=false},200)};if(window.addEventListener){window.addEventListener("resize",x)}else{if(window.attachEvent){window.attachEvent("onresize",x)}}this.hide();document.body.appendChild(A);return this};this.initNavButtons=function(){var w=document.createElement("div");this.prevBtnEl=t("hopscotch-prev",l.prevBtn);this.nextBtnEl=t("hopscotch-next",l.nextBtn);this.doneBtnEl=t("hopscotch-done",l.doneBtn);k.addClass(this.doneBtnEl,"hide");w.appendChild(this.prevBtnEl);w.appendChild(this.nextBtnEl);w.appendChild(this.doneBtnEl);k.addClickListener(this.prevBtnEl,function(x){n.prevStep()});k.addClickListener(this.nextBtnEl,function(x){n.nextStep()});k.addClickListener(this.doneBtnEl,n.endTour);w.id="hopscotch-actions";this.buttonsEl=w;this.containerEl.appendChild(w);return this};this.initCloseButton=function(){var w=document.createElement("a");w.id="hopscotch-bubble-close";w.href="#";w.title=l.closeTooltip;w.innerHTML=l.closeTooltip;k.addClickListener(w,function(y){var x=n.getCurrStepNum(),z=n.getCurrTour(),A=(x===z.steps.length-1);k.invokeCallbacks("close",[z.id,x]);n.endTour(true,A);if(y.preventDefault){y.preventDefault()}else{if(event){event.returnValue=false}}});this.closeBtnEl=w;this.containerEl.appendChild(w);return this};this.initArrow=function(){var w,x;this.arrowEl=document.createElement("div");this.arrowEl.id="hopscotch-bubble-arrow-container";x=document.createElement("div");x.className="hopscotch-bubble-arrow-border";w=document.createElement("div");w.className="hopscotch-bubble-arrow";this.arrowEl.appendChild(x);this.arrowEl.appendChild(w);this.element.appendChild(this.arrowEl);return this};this.renderStep=function(y,D,z,A,E){var F=this,x=k.valOrDefault(y.showNextButton,u.showNextButton),w=k.valOrDefault(y.showPrevButton,u.showPrevButton),C,B;p=y;this.setTitle(y.title?y.title:"");this.setContent(y.content?y.content:"");this.setNum(D);this.orientation=y.orientation;this.showPrevButton(this.prevBtnEl&&w&&(D>0||z>0));this.showNextButton(this.nextBtnEl&&x&&!A);this.nextBtnEl.value=y.showSkip?l.skipBtn:l.nextBtn;if(A){k.removeClass(this.doneBtnEl,"hide")}else{k.addClass(this.doneBtnEl,"hide")}this.setArrow(y.orientation);C=k.getPixelValue(y.width)||u.bubbleWidth;B=k.valOrDefault(y.padding,u.bubblePadding);this.containerEl.style.width=C+"px";this.containerEl.style.padding=B+"px";this.element.style.zIndex=(y.zindex?y.zindex:"");if(y.orientation==="top"){setTimeout(function(){s(F,y);if(E){if(!y.fixedElement){E()}else{F.show()}}},5)}else{s(this,y);if(E){if(!y.fixedElement){E()}else{F.show()}}}return this};this.setTitle=function(w){if(w){this.titleEl.innerHTML=w;k.removeClass(this.titleEl,"hide")}else{k.addClass(this.titleEl,"hide")}return this};this.setContent=function(w){if(w){this.contentEl.innerHTML=w;k.removeClass(this.contentEl,"hide")}else{k.addClass(this.contentEl,"hide")}return this};this.setNum=function(w){if(l.stepNums&&w0)?I[H]:I},B=function(){return z.steps[t].length>0},v=function(){var I=z.steps[t].length;if(H0){--H;return true}else{if(t>0){I=z.steps[--t].length;if(I){H=I-1}else{H=undefined}return true}}return false},s=function(T){var R=x(),ab=R.element,X=k.getPixelValue(ab.style.top),W=X+k.getPixelValue(ab.offsetHeight),U=k.getStepTarget(C()),ac=U.getBoundingClientRect(),Z=ac.top+k.getScrollTop(),V=ac.bottom+k.getScrollTop(),P=(XV)?W:V,Y=k.getScrollTop(),K=Y+k.getWindowHeight(),L=P-q.scrollTopMargin,S=this,J,O,N,aa,M,Q;if(P>=Y&&(P<=Y+q.scrollTopMargin||I<=K)){if(T){T()}return}else{if(!q.smoothScroll){window.scrollTo(0,L);if(T){T()}return}else{if(typeof YAHOO!==j&&typeof YAHOO.env!==j&&typeof YAHOO.env.ua!==j&&typeof YAHOO.util!==j&&typeof YAHOO.util.Scroll!==j){J=YAHOO.env.ua.webkit?document.body:document.documentElement;N=YAHOO.util.Easing?YAHOO.util.Easing.easeOut:undefined;O=new YAHOO.util.Scroll(J,{scroll:{to:[0,L]}},q.scrollDuration/1000,N);O.onComplete.subscribe(T);O.animate()}else{if(d){$("body, html").animate({scrollTop:L},q.scrollDuration,T)}else{if(L<0){L=0}aa=(Y>P)?-1:1;M=Math.abs(Y-L)/(q.scrollDuration/10);Q=setInterval(function(){var ae=k.getScrollTop(),ad=ae+(aa*M);if((aa>0&&ad>=L)||aa<0&&ad<=L){ad=L;clearInterval(Q);if(T){T()}window.scrollTo(0,ad);return}window.scrollTo(0,ad);if(k.getScrollTop()===ae){clearInterval(Q);if(T){T()}}},10)}}}}},r=function(N){var L={},J,O,K,I,M;z=N;for(O in N){if(N.hasOwnProperty(O)&&O!=="id"&&O!=="steps"){L[O]=N[O]}}this.resetDefaultOptions();u.call(this,L,true);I=k.getState(q.cookieName);if(I){M=I.split(":");y=M[0];p=M[1];F=undefined;K=p.split("-");if(K.length>1){p=parseInt(K[0],10);F=parseInt(K[1],10)}else{p=parseInt(p,10)}if(M.length>2&&M[2]==="mp"){if(F&&F0){F=0}else{F=undefined}}}}}return this},D=function(){if(w){this.configure(w)}};this.startTour=function(M,L,K){var I,J;if(!z){r.call(this,M)}if(document.readyState!=="complete"){b=true;return this}if(typeof L!==j){t=L;H=K}else{if(z.id===y&&typeof p!==j){t=p;H=F;J=C();if(!k.getStepTarget(J)){G();J=C();if(!k.getStepTarget(J)){this.endTour(false,false);return this}}}else{t=0}}if(!H&&B()){H=0}k.invokeCallbacks("start",[z.id,t]);I=x();I.hide(false);this.isActive=true;if(q.animate){I.initAnimate()}if(!k.getStepTarget(C())){k.invokeCallbacks("error",[z.id,t]);if(q.skipIfNoElement){this.nextStep(false)}}else{this.showStep(t,H)}return this};this.showStep=function(T,J){var L=z.steps,K=L[T],I=L.length,Q=z.id+":"+T,P=x(),N=k.valOrDefault(K.delay,0),S=this,R=k.getStepTarget(K),O,M;t=T;H=J;if(!q.animate){P.hide(false)}if(typeof J!==j&&B()){K=K[J];Q+="-"+J}if(K.nextOnTargetClick){O=function(){if(K.delay){setTimeout(function(){S.nextStep()},K.delay)}else{S.nextStep()}return R.removeEventListener?R.removeEventListener("click",O):R.detachEvent("click",O)}}M=(T===I-1)||(J>=K.length-1);setTimeout(function(){P.renderStep(K,T,J,M,function(){s(function(){P.show()});if(K.onShow){K.onShow()}if(K.nextOnTargetClick){k.addClickListener(R,O)}});k.invokeCallbacks("show",[z.id,t])},N);if(K.multipage){Q+=":mp"}k.setState(q.cookieName,Q,1);return this};this.prevStep=function(){var K=C(),J=false,I=x();if(K.onPrev){K.onPrev()}k.invokeCallbacks("prev",[z.id,t]);if(q.skipIfNoElement){while(!J&&G()){K=C();J=k.getStepTarget(K);if(!J){k.invokeCallbacks("error",[z.id,t])}}if(!J){return this.endTour(true,false)}}else{if(G()){K=C();if(!k.getStepTarget(K)){k.invokeCallbacks("error",[z.id,t]);return this.endTour(true,false)}}}this.showStep(t,H);return this};this.nextStep=function(M){var L=C(),K=t,J=false,I=x();M=k.valOrDefault(M,true);if(q.skipIfNoElement){while(!J&&v()){L=C();J=k.getStepTarget(L);if(!J){k.invokeCallbacks("error",[z.id,t])}}if(!J){return this.endTour(true)}}else{if(v()){L=C();if(!k.getStepTarget(L)){k.invokeCallbacks("error",[z.id,t]);return this.endTour(true,false)}}}if(M){if(L.onNext){L.onNext()}k.invokeCallbacks("next",[z.id,K])}this.showStep(t,H);return this};this.endTour=function(K,J){var I=x();K=k.valOrDefault(K,true);J=k.valOrDefault(J,true);t=0;H=undefined;p=undefined;I.hide();if(K){k.clearState(q.cookieName)}n.isActive=false;if(z&&J){k.invokeCallbacks("end",[z.id])}n.removeCallbacks(true);z=null;return this};this.getCurrTour=function(){return z};this.getCurrStepNum=function(){return t};this.getCurrSubstepNum=function(){return H};this.addCallback=function(K,I,J){if(I){i[K].push({cb:I,fromTour:J})}return this};this.removeCallbacks=function(J){var M,K,I,L;for(L in i){if(J){M=i[L];for(K=0,I=M.length;K=0){k.addClass(w,"prev")}else{k.addClass(w,"next")}return w},r=function(x,w,z){var y="hide";if(z){y="hide-all"}if(typeof w===j){w=true}if(w){k.removeClass(x,y)}else{k.addClass(x,y)}},s=function(C,z){var F,w,D,y,E,A,B=6,I=k.getStepTarget(z),x=C.element,H=C.arrowEl,G=k.getPixelValue(z.arrowOffset);F=k.getPixelValue(z.width)||u.bubbleWidth;D=k.valOrDefault(z.padding,u.bubblePadding);k.removeClass(x,"fade-in-down fade-in-up fade-in-left fade-in-right");y=I.getBoundingClientRect();if(z.orientation==="top"){w=x.offsetHeight;E=(y.top-w)-u.arrowWidth;A=y.left}else{if(z.orientation==="bottom"){E=y.bottom+u.arrowWidth;A=y.left}else{if(z.orientation==="left"){E=y.top;A=y.left-F-2*D-2*B-u.arrowWidth}else{if(z.orientation==="right"){E=y.top;A=y.right+u.arrowWidth}}}}if(!G){H.style.top="";H.style.left=""}else{if(z.orientation==="top"||z.orientation==="bottom"){H.style.top="";H.style.left=G+"px"}else{if(z.orientation==="left"||z.orientation==="right"){H.style.left="";H.style.top=G+"px"}}}A+=k.getPixelValue(z.xOffset);E+=k.getPixelValue(z.yOffset);if(!z.fixedElement){E+=k.getScrollTop();A+=k.getScrollLeft()}x.style.position=(z.fixedElement?"fixed":"absolute");if(u.animate&&d&&!f){$(x).animate({top:E+"px",left:A+"px"})}else{x.style.top=E+"px";x.style.left=A+"px"}},v=function(){var A=document.createElement("div"),B=document.createElement("div"),z=document.createElement("div"),y=this,C=false,x,w;this.element=A;this.containerEl=B;this.titleEl=document.createElement("h3");this.numberEl=document.createElement("span");this.contentEl=document.createElement("p");A.id="hopscotch-bubble";k.addClass(A,"animated");B.id="hopscotch-bubble-container";this.numberEl.id="hopscotch-bubble-number";B.appendChild(this.numberEl);z.appendChild(this.titleEl);z.appendChild(this.contentEl);z.id="hopscotch-bubble-content";B.appendChild(z);A.appendChild(B);this.initNavButtons();this.initCloseButton();this.initArrow();x=function(){if(C||!q){return}C=true;w=setTimeout(function(){s(y,p,false);C=false},200)};if(window.addEventListener){window.addEventListener("resize",x)}else{if(window.attachEvent){window.attachEvent("onresize",x)}}this.hide();document.body.appendChild(A);return this};this.initNavButtons=function(){var w=document.createElement("div");this.prevBtnEl=t("hopscotch-prev",l.prevBtn);this.nextBtnEl=t("hopscotch-next",l.nextBtn);this.doneBtnEl=t("hopscotch-done",l.doneBtn);k.addClass(this.doneBtnEl,"hide");w.appendChild(this.prevBtnEl);w.appendChild(this.nextBtnEl);w.appendChild(this.doneBtnEl);k.addClickListener(this.prevBtnEl,function(x){n.prevStep(true)});k.addClickListener(this.nextBtnEl,function(x){n.nextStep(true)});k.addClickListener(this.doneBtnEl,n.endTour);w.id="hopscotch-actions";this.buttonsEl=w;this.containerEl.appendChild(w);return this};this.initCloseButton=function(){var w=document.createElement("a");w.id="hopscotch-bubble-close";w.href="#";w.title=l.closeTooltip;w.innerHTML=l.closeTooltip;k.addClickListener(w,function(y){var x=n.getCurrStepNum(),z=n.getCurrTour(),A=(x===z.steps.length-1);k.invokeCallbacks("close",[z.id,x]);n.endTour(true,A);if(y.preventDefault){y.preventDefault()}else{if(event){event.returnValue=false}}});this.closeBtnEl=w;this.containerEl.appendChild(w);return this};this.initArrow=function(){var w,x;this.arrowEl=document.createElement("div");this.arrowEl.id="hopscotch-bubble-arrow-container";x=document.createElement("div");x.className="hopscotch-bubble-arrow-border";w=document.createElement("div");w.className="hopscotch-bubble-arrow";this.arrowEl.appendChild(x);this.arrowEl.appendChild(w);this.element.appendChild(this.arrowEl);return this};this.renderStep=function(y,D,z,A,E){var F=this,x=k.valOrDefault(y.showNextButton,u.showNextButton),w=k.valOrDefault(y.showPrevButton,u.showPrevButton),C,B;p=y;this.setTitle(y.title?y.title:"");this.setContent(y.content?y.content:"");this.setNum(D);this.orientation=y.orientation;this.showPrevButton(this.prevBtnEl&&w&&(D>0||z>0));this.showNextButton(this.nextBtnEl&&x&&!A);this.nextBtnEl.value=y.showSkip?l.skipBtn:l.nextBtn;if(A){k.removeClass(this.doneBtnEl,"hide")}else{k.addClass(this.doneBtnEl,"hide")}this.setArrow(y.orientation);C=k.getPixelValue(y.width)||u.bubbleWidth;B=k.valOrDefault(y.padding,u.bubblePadding);this.containerEl.style.width=C+"px";this.containerEl.style.padding=B+"px";this.element.style.zIndex=(y.zindex?y.zindex:"");if(y.orientation==="top"){setTimeout(function(){s(F,y);if(E){if(!y.fixedElement){E()}else{F.show()}}},5)}else{s(this,y);if(E){if(!y.fixedElement){E()}else{F.show()}}}return this};this.setTitle=function(w){if(w){this.titleEl.innerHTML=w;k.removeClass(this.titleEl,"hide")}else{k.addClass(this.titleEl,"hide")}return this};this.setContent=function(w){if(w){this.contentEl.innerHTML=w;k.removeClass(this.contentEl,"hide")}else{k.addClass(this.contentEl,"hide")}return this};this.setNum=function(w){if(l.stepNums&&w0)?H[G]:H},A=function(){return y.steps[t].length>0},s=function(S){var Q=w(),aa=Q.element,W=k.getPixelValue(aa.style.top),V=W+k.getPixelValue(aa.offsetHeight),T=k.getStepTarget(B()),ab=T.getBoundingClientRect(),Y=ab.top+k.getScrollTop(),U=ab.bottom+k.getScrollTop(),O=(WU)?V:U,X=k.getScrollTop(),J=X+k.getWindowHeight(),K=O-q.scrollTopMargin,R=this,I,N,M,Z,L,P;if(O>=X&&(O<=X+q.scrollTopMargin||H<=J)){if(S){S()}return}else{if(!q.smoothScroll){window.scrollTo(0,K);if(S){S()}return}else{if(typeof YAHOO!==j&&typeof YAHOO.env!==j&&typeof YAHOO.env.ua!==j&&typeof YAHOO.util!==j&&typeof YAHOO.util.Scroll!==j){I=YAHOO.env.ua.webkit?document.body:document.documentElement;M=YAHOO.util.Easing?YAHOO.util.Easing.easeOut:undefined;N=new YAHOO.util.Scroll(I,{scroll:{to:[0,K]}},q.scrollDuration/1000,M);N.onComplete.subscribe(S);N.animate()}else{if(d){$("body, html").animate({scrollTop:K},q.scrollDuration,S)}else{if(K<0){K=0}Z=(X>O)?-1:1;L=Math.abs(X-K)/(q.scrollDuration/10);P=setInterval(function(){var ad=k.getScrollTop(),ac=ad+(Z*L);if((Z>0&&ac>=K)||Z<0&&ac<=K){ac=K;clearInterval(P);if(S){S()}window.scrollTo(0,ac);return}window.scrollTo(0,ac);if(k.getScrollTop()===ad){clearInterval(P);if(S){S()}}},10)}}}}},D=function(I,L){var K=this,H=y.steps[t+L],J=w();J.hide();setTimeout(function(){var O=B(),N=t,M=false;if(q.skipIfNoElement){while(!M&&t+L>=0&&t+L=0&&t+L0&&O.onNext){O.onNext()}else{if(L<0&&O.onPrev){O.onPrev()}}k.invokeCallbacks(L>0?"next":"prev",[y.id,N])}K.showStep(t)},H.delay?H.delay:0);return this},r=function(M){var K={},I,N,J,H,L;y=M;for(N in M){if(M.hasOwnProperty(N)&&N!=="id"&&N!=="steps"){K[N]=M[N]}}this.resetDefaultOptions();u.call(this,K,true);H=k.getState(q.cookieName);if(H){L=H.split(":");x=L[0];p=L[1];F=undefined;J=p.split("-");if(J.length>1){p=parseInt(J[0],10);F=parseInt(J[1],10)}else{p=parseInt(p,10)}if(L.length>2&&L[2]==="mp"){if(F&&F0){F=0}else{F=undefined}}}}}return this},C=function(){if(v){this.configure(v)}};this.startTour=function(L,K,J){var H,I;if(!y){r.call(this,L)}if(document.readyState!=="complete"){b=true;return this}if(typeof K!==j){t=K;G=J}else{if(y.id===x&&typeof p!==j){t=p;G=F;I=B();if(!k.getStepTarget(I)){decrementStep();I=B();if(!k.getStepTarget(I)){this.endTour(false,false);return this}}}else{t=0}}if(!G&&A()){G=0}k.invokeCallbacks("start",[y.id,t]);H=w();H.hide(false);this.isActive=true;if(q.animate){H.initAnimate()}if(!k.getStepTarget(B())){k.invokeCallbacks("error",[y.id,t]);if(q.skipIfNoElement){this.nextStep()}}else{this.showStep(t,G)}return this};this.showStep=function(Q,I){var K=y.steps,J=K[Q],H=K.length,O=y.id+":"+Q,N=w(),R=this,P=k.getStepTarget(J),M,L;t=Q;G=I;if(!q.animate){N.hide(false)}if(typeof I!==j&&A()){J=J[I];O+="-"+I}if(J.nextOnTargetClick){M=function(){R.nextStep();return P.removeEventListener?P.removeEventListener("click",M):P.detachEvent("click",M)}}L=(Q===H-1)||(I>=J.length-1);N.renderStep(J,Q,I,L,function(){s(function(){N.show()});if(J.onShow){J.onShow()}if(J.nextOnTargetClick){k.addClickListener(P,M)}});k.invokeCallbacks("show",[y.id,t]);if(J.multipage){O+=":mp"}k.setState(q.cookieName,O,1);return this};this.prevStep=function(H){D.call(this,H,-1)};this.nextStep=function(H){D.call(this,H,1)};this.endTour=function(J,I){var H=w();J=k.valOrDefault(J,true);I=k.valOrDefault(I,true);t=0;G=undefined;p=undefined;H.hide();if(J){k.clearState(q.cookieName)}n.isActive=false;if(y&&I){k.invokeCallbacks("end",[y.id])}n.removeCallbacks(true);y=null;return this};this.getCurrTour=function(){return y};this.getCurrStepNum=function(){return t};this.getCurrSubstepNum=function(){return G};this.addCallback=function(J,H,I){if(H){i[J].push({cb:H,fromTour:I})}return this};this.removeCallbacks=function(I){var L,J,H,K;for(K in i){if(I){L=i[K];for(J=0,H=L.length;J 0; }, + // incrementStep AND decrementStep ARE ONLY USEFUL FOR MULTI-PART + // STEPS, WHICH HAVE YET TO BE FULLY IMPLEMENTED. /** * incrementStep * ============= * Sets current step num and substep num to the next step in the tour. * Returns true if successful, false if not. */ + /* incrementStep = function() { var numSubsteps = currTour.steps[currStepNum].length; if (currSubstepNum < numSubsteps-1) { @@ -797,6 +800,7 @@ } return false; }, + */ /** * decrementStep @@ -804,6 +808,7 @@ * Sets current step num and substep num to the previous step in the tour. * Returns true if successful, false if not. */ + /* decrementStep = function() { var numPrevSubsteps; if (currSubstepNum > 0) { @@ -822,6 +827,7 @@ } return false; }, + */ /** * adjustWindowScroll @@ -921,6 +927,67 @@ } }, + /** + * changeStep + * ========== + * Helper function to change step by going forwards or backwards 1. + * nextStep and prevStep are publicly accessible wrappers for this function. + */ + changeStep = function(doCallbacks, direction) { + var self = this, + nextStep = currTour.steps[currStepNum + direction], + bubble = getBubble(); + + bubble.hide(); + setTimeout(function() { + var step = getCurrStep(), + origStepNum = currStepNum, + foundTarget = false; + + if (opt.skipIfNoElement) { + // increment step until we find a target or until we reach beginning + while (!foundTarget && currStepNum + direction >= 0 && currStepNum + direction < currTour.steps.length) { + currStepNum += direction; + step = getCurrStep(); + foundTarget = utils.getStepTarget(step); + + if (!foundTarget) { + utils.invokeCallbacks('error', [currTour.id, currStepNum]); + } + } + if (!foundTarget) { + return this.endTour(true); + } + } + else if (currStepNum + direction >= 0 && currStepNum + direction < currTour.steps.length) { + // only try incrementing once, and invoke error callback if no target + // is found + currStepNum += direction; + step = getCurrStep(); + if (!utils.getStepTarget(step)) { + utils.invokeCallbacks('error', [currTour.id, currStepNum]); + return this.endTour(true, false); + } + } + + if (doCallbacks) { + // invoke callbacks + if (direction > 0 && step.onNext) { + step.onNext(); + } + else if (direction < 0 && step.onPrev) { + step.onPrev(); + } + utils.invokeCallbacks(direction > 0 ? 'next' : 'prev', [currTour.id, origStepNum]); + } + + //this.showStep(currStepNum, currSubstepNum); + self.showStep(currStepNum); + }, nextStep.delay ? nextStep.delay : 0); + + return this; + }, + /** * loadTour * ======== @@ -1055,7 +1122,7 @@ if (!utils.getStepTarget(getCurrStep())) { utils.invokeCallbacks('error', [currTour.id, currStepNum]); if (opt.skipIfNoElement) { - this.nextStep(false); + this.nextStep(); } } else { @@ -1071,7 +1138,6 @@ numTourSteps = tourSteps.length, cookieVal = currTour.id + ':' + stepIdx, bubble = getBubble(), - delay = utils.valOrDefault(step.delay, 0), self = this, targetEl = utils.getStepTarget(step), nextStepFn, @@ -1095,35 +1161,26 @@ // of the target element. if (step.nextOnTargetClick) { nextStepFn = function() { - if (step.delay) { - setTimeout(function() { - self.nextStep(); - }, step.delay); - } - else { - self.nextStep(); - } + self.nextStep(); return targetEl.removeEventListener ? targetEl.removeEventListener('click', nextStepFn) : targetEl.detachEvent('click', nextStepFn); }; } isLast = (stepIdx === numTourSteps - 1) || (substepIdx >= step.length - 1); - setTimeout(function() { - bubble.renderStep(step, stepIdx, substepIdx, isLast, function() { - // when done adjusting window scroll, call bubble.show() - adjustWindowScroll(function() { - bubble.show(); - }); + bubble.renderStep(step, stepIdx, substepIdx, isLast, function() { + // when done adjusting window scroll, call bubble.show() + adjustWindowScroll(function() { + bubble.show(); + }); - if (step.onShow) { step.onShow(); } + if (step.onShow) { step.onShow(); } - // If we want to advance to next step when user clicks on target. - if (step.nextOnTargetClick) { - utils.addClickListener(targetEl, nextStepFn); - } - }); - utils.invokeCallbacks('show', [currTour.id, currStepNum]); - }, delay); + // If we want to advance to next step when user clicks on target. + if (step.nextOnTargetClick) { + utils.addClickListener(targetEl, nextStepFn); + } + }); + utils.invokeCallbacks('show', [currTour.id, currStepNum]); if (step.multipage) { cookieVal += ':mp'; @@ -1133,87 +1190,12 @@ return this; }; - this.prevStep = function() { - var step = getCurrStep(), - foundTarget = false, - bubble = getBubble(); - - // invoke callbacks - if (step.onPrev) { - step.onPrev(); - } - utils.invokeCallbacks('prev', [currTour.id, currStepNum]); - - if (opt.skipIfNoElement) { - // decrement step until we find a target or until we reach beginning - while (!foundTarget && decrementStep()) { - step = getCurrStep(); - foundTarget = utils.getStepTarget(step); - if (!foundTarget) { - utils.invokeCallbacks('error', [currTour.id, currStepNum]); - } - } - if (!foundTarget) { - return this.endTour(true, false); - } - } - else if (decrementStep()) { - // only try decrementing once, and invoke error callback if no target - // is found - step = getCurrStep(); - if (!utils.getStepTarget(step)) { - utils.invokeCallbacks('error', [currTour.id, currStepNum]); - return this.endTour(true, false); - } - } - - this.showStep(currStepNum, currSubstepNum); - - return this; + this.prevStep = function(doCallbacks) { + changeStep.call(this, doCallbacks, -1); }; - this.nextStep = function(btnClick) { - var step = getCurrStep(), - origStepNum = currStepNum, - foundTarget = false, - bubble = getBubble(); - - btnClick = utils.valOrDefault(btnClick, true); - - if (opt.skipIfNoElement) { - // increment step until we find a target or until we reach beginning - while (!foundTarget && incrementStep()) { - step = getCurrStep(); - foundTarget = utils.getStepTarget(step); - if (!foundTarget) { - utils.invokeCallbacks('error', [currTour.id, currStepNum]); - } - } - if (!foundTarget) { - return this.endTour(true); - } - } - else if (incrementStep()) { - // only try incrementing once, and invoke error callback if no target - // is found - step = getCurrStep(); - if (!utils.getStepTarget(step)) { - utils.invokeCallbacks('error', [currTour.id, currStepNum]); - return this.endTour(true, false); - } - } - - if (btnClick) { - // invoke callbacks -- only if it resulted from a button click - if (step.onNext) { - step.onNext(); - } - utils.invokeCallbacks('next', [currTour.id, origStepNum]); - } - - this.showStep(currStepNum, currSubstepNum); - - return this; + this.nextStep = function(doCallbacks) { + changeStep.call(this, doCallbacks, 1); }; /**