From cc1bd9d5029144740b5a33a7ee53c3584361debd Mon Sep 17 00:00:00 2001 From: Gordon Koo Date: Wed, 1 Aug 2012 17:04:43 -0700 Subject: [PATCH] added scrollTopMargin config option --- js/exampletour.js | 1 + js/hopscotch-min.js | 2 +- js/hopscotch.js | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/js/exampletour.js b/js/exampletour.js index 96c0ebd3..1bebe188 100644 --- a/js/exampletour.js +++ b/js/exampletour.js @@ -75,6 +75,7 @@ var tour = { animate: false, //smoothScroll: false, //showCloseButton: false, + scrollTopMargin: 200, showPrevButton: true, showNextButton: true, arrowWidth: 20, diff --git a/js/hopscotch-min.js b/js/hopscotch-min.js index d7b594ab..3ab3520d 100644 --- a/js/hopscotch-min.js +++ b/js/hopscotch-min.js @@ -1 +1 @@ -(function(){var k,e,j,i,h="undefined",g=false,a=false,b=(typeof window.jQuery!==h),d=(typeof window.localStorage!==h),f=document.body.style,c=(typeof f.MozTransition!==h||typeof f.MsTransition!==h||typeof f.webkitTransition!==h||typeof f.OTransition!==h||typeof f.transition!==h);if(window.hopscotch){return}window.addEventListener("load",function(){g=true;if(a){window.hopscotch.startTour()}});i={addClass:function(n,p){var m,o,l;if(b){$(n).addClass(p)}else{if(n.className.length===0){n.className=p}else{m=n.className.split(" ");for(o=0,l=m.length;o0);this.showNextButton(this.nextBtnEl&&u&&!w);if(w){i.removeClass(this.doneBtnEl,"hide")}else{i.addClass(this.doneBtnEl,"hide")}this.setArrow(v.orientation);y=i.getPixelValue(v.width)||s.bubbleWidth;x=i.valOrDefault(v.padding,s.bubblePadding);this.containerEl.style.width=y+"px";this.containerEl.style.padding=x+"px";if(v.orientation==="top"){setTimeout(function(){o(B,v);if(A){A()}},5)}else{o(this,v);if(A){A()}}q=v.onPrev;r=v.onNext;return this};this.setTitle=function(t){if(t){this.titleEl.innerHTML=t;i.removeClass(this.titleEl,"hide")}else{i.addClass(this.titleEl,"hide")}return this};this.setContent=function(t){if(t){this.contentEl.innerHTML=t;i.removeClass(this.contentEl,"hide")}else{i.addClass(this.contentEl,"hide")}return this};this.setNum=function(t){if(j.stepNums&&tF)?G:F,I=i.getScrollTop(),x=I+i.getWindowHeight(),y=C-50,w,B,A,K,z,D;if(b){$("body, html").animate({scrollTop:y},n.scrollDuration);return}else{if(typeof YAHOO!==h&&typeof YAHOO.env!==h&&typeof YAHOO.env.ua!==h&&typeof YAHOO.util!==h&&typeof YAHOO.util.Scroll!==h){w=YAHOO.env.ua.webkit?document.body:document.documentElement;A=YAHOO.util.Easing?YAHOO.util.Easing.easeOut:undefined;B=new YAHOO.util.Scroll(w,{scroll:{to:[0,y]}},n.scrollDuration/1000,A);B.animate();return}}if(y<0){y=0}if(C>=I&&C<=I+50){return}if(Cx){if(n.smoothScroll){K=(I>C)?-1:1;z=Math.abs(I-C)/(n.scrollDuration/10);D=setInterval(function(){var O=i.getScrollTop(),N=O+(K*z);if((K>0&&N>=y)||K<0&&N<=y){N=y;clearInterval(D)}window.scrollTo(0,N);if(i.getScrollTop()===O){clearInterval(D)}},10)}else{window.scrollTo(0,y)}}};this.init=function(){var v,w;if(l){this.configure(l)}};this.loadTour=function(x){var w={},v,y;q=x;for(y in x){if(x.hasOwnProperty(y)&&y!=="id"&&y!=="steps"){w[y]=x[y]}}this.configure(w);tourState=i.getState(n.cookieName);if(tourState){tourPair=tourState.split(":");u=tourPair[0];p=parseInt(tourPair[1],10);if(tourPair.length>2&&tourPair[2]==="mp"){++p}}v=o();v.showPrevButton(n.showPrevButton,true);v.showNextButton(n.showNextButton,true)};this.startTour=function(){var v;if(!q){throw"Need to load a tour before you start it!"}if(!g){a=true;return}if(q.id===u&&typeof p!==h){m=p;if(!document.getElementById(q.steps[m].targetId)){if(m<=0||!document.getElementById(q.steps[--m].targetId)){this.endTour(false);return}}}else{m=0}this.showStep(m);v=o().show();if(n.animate){v.initAnimate()}this.isActive=true};this.showStep=function(y){var z=q.steps[y],x=q.steps.length,w=q.id+":"+y,v=o();if(!q){throw"No tour currently selected!"}m=y;v.renderStep(z,y,(y===x-1),r);if(z.multiPage){w+=":mp"}i.setState(n.cookieName,w,1)};this.prevStep=function(){if(m>0){this.showStep(--m)}};this.nextStep=function(){if(n.onNext){n.onNext(t(),m)}if(m0);this.showNextButton(this.nextBtnEl&&u&&!w);if(w){i.removeClass(this.doneBtnEl,"hide")}else{i.addClass(this.doneBtnEl,"hide")}this.setArrow(v.orientation);y=i.getPixelValue(v.width)||s.bubbleWidth;x=i.valOrDefault(v.padding,s.bubblePadding);this.containerEl.style.width=y+"px";this.containerEl.style.padding=x+"px";if(v.orientation==="top"){setTimeout(function(){o(B,v);if(A){A()}},5)}else{o(this,v);if(A){A()}}q=v.onPrev;r=v.onNext;return this};this.setTitle=function(t){if(t){this.titleEl.innerHTML=t;i.removeClass(this.titleEl,"hide")}else{i.addClass(this.titleEl,"hide")}return this};this.setContent=function(t){if(t){this.contentEl.innerHTML=t;i.removeClass(this.contentEl,"hide")}else{i.addClass(this.contentEl,"hide")}return this};this.setNum=function(t){if(j.stepNums&&tF)?G:F,I=i.getScrollTop(),x=I+i.getWindowHeight(),y=C-n.scrollTopMargin,w,B,A,K,z,D;if(b){$("body, html").animate({scrollTop:y},n.scrollDuration);return}else{if(typeof YAHOO!==h&&typeof YAHOO.env!==h&&typeof YAHOO.env.ua!==h&&typeof YAHOO.util!==h&&typeof YAHOO.util.Scroll!==h){w=YAHOO.env.ua.webkit?document.body:document.documentElement;A=YAHOO.util.Easing?YAHOO.util.Easing.easeOut:undefined;B=new YAHOO.util.Scroll(w,{scroll:{to:[0,y]}},n.scrollDuration/1000,A);B.animate();return}}if(y<0){y=0}if(C>=I&&C<=I+n.scrollTopMargin){return}if(Cx){if(n.smoothScroll){K=(I>C)?-1:1;z=Math.abs(I-C)/(n.scrollDuration/10);D=setInterval(function(){var O=i.getScrollTop(),N=O+(K*z);if((K>0&&N>=y)||K<0&&N<=y){N=y;clearInterval(D)}window.scrollTo(0,N);if(i.getScrollTop()===O){clearInterval(D)}},10)}else{window.scrollTo(0,y)}}};this.init=function(){var v,w;if(l){this.configure(l)}};this.loadTour=function(x){var w={},v,y;q=x;for(y in x){if(x.hasOwnProperty(y)&&y!=="id"&&y!=="steps"){w[y]=x[y]}}this.configure(w);tourState=i.getState(n.cookieName);if(tourState){tourPair=tourState.split(":");u=tourPair[0];p=parseInt(tourPair[1],10);if(tourPair.length>2&&tourPair[2]==="mp"){++p}}v=o();v.showPrevButton(n.showPrevButton,true);v.showNextButton(n.showNextButton,true)};this.startTour=function(){var v;if(!q){throw"Need to load a tour before you start it!"}if(!g){a=true;return}if(q.id===u&&typeof p!==h){m=p;if(!document.getElementById(q.steps[m].targetId)){if(m<=0||!document.getElementById(q.steps[--m].targetId)){this.endTour(false);return}}}else{m=0}this.showStep(m);v=o().show();if(n.animate){v.initAnimate()}this.isActive=true};this.showStep=function(y){var z=q.steps[y],x=q.steps.length,w=q.id+":"+y,v=o();if(!q){throw"No tour currently selected!"}m=y;v.renderStep(z,y,(y===x-1),r);if(z.multiPage){w+=":mp"}i.setState(n.cookieName,w,1)};this.prevStep=function(){if(m>0){this.showStep(--m)}};this.nextStep=function(){if(n.onNext){n.onNext(t(),m)}if(m targetElBottom) ? bubbleBottom : targetElBottom, // whichever is lower windowTop = utils.getScrollTop(), windowBottom = windowTop + utils.getWindowHeight(), - scrollToVal = targetTop - 50, // This is our final target scroll value. + scrollToVal = targetTop - opt.scrollTopMargin, // This is our final target scroll value. scrollEl, yuiAnim, yuiEase, @@ -728,7 +728,7 @@ scrollToVal = 0; } - if (targetTop >= windowTop && targetTop <= windowTop + 50) { + if (targetTop >= windowTop && targetTop <= windowTop + opt.scrollTopMargin) { return; } @@ -929,6 +929,9 @@ * scrollDuration: Number - Duration of page scroll. Only relevant when * smoothScroll is set to true. Defaults to * 1000ms. + * scrollTopMargin: NUMBER - When the page scrolls, how much space should there + * be between the bubble/targetElement and the top + * of the viewport? Defaults to 50. * showCloseButton: Boolean - should the tour bubble show a close (X) button? * Defaults to TRUE. * showPrevButton: Boolean - should the bubble have the Previous button? @@ -962,6 +965,7 @@ opt.animate = utils.valOrDefault(opt.animate, false); opt.smoothScroll = utils.valOrDefault(opt.smoothScroll, true); opt.scrollDuration = utils.valOrDefault(opt.scrollDuration, 1000); + opt.scrollTopMargin = utils.valOrDefault(opt.scrollTopMargin, 50); opt.showCloseButton = utils.valOrDefault(opt.showCloseButton, true); opt.showPrevButton = utils.valOrDefault(opt.showPrevButton, false); opt.showNextButton = utils.valOrDefault(opt.showNextButton, true);