From ed7826554521134afa01520e43ea092d54bdc895 Mon Sep 17 00:00:00 2001 From: Gordon Koo Date: Thu, 28 Mar 2013 14:16:29 -0700 Subject: [PATCH] fix error when hopscotch is included in the head, instead of end of body --- js/hopscotch-0.0.5.js | 33 ++++++++++++++++++-- js/hopscotch-0.0.5.min.js | 64 +++++++++++++++++++-------------------- 2 files changed, 63 insertions(+), 34 deletions(-) diff --git a/js/hopscotch-0.0.5.js b/js/hopscotch-0.0.5.js index 84e67edb..cc75c0c1 100644 --- a/js/hopscotch-0.0.5.js +++ b/js/hopscotch-0.0.5.js @@ -27,7 +27,7 @@ }, hasJquery = (typeof window.jQuery !== undefinedStr), hasSessionStorage = (typeof window.sessionStorage !== undefinedStr), - docStyle = document.body.style, + docStyle = document.head.style, hasCssTransitions = (typeof docStyle.MozTransition !== undefinedStr || typeof docStyle.MsTransition !== undefinedStr || typeof docStyle.webkitTransition !== undefinedStr || @@ -962,6 +962,7 @@ resizeCooldown = false, // for updating after window resize onWinResize, winResizeTimeout, + appendToBody, opt; this.element = el; @@ -1039,7 +1040,35 @@ } this.hide(); - document.body.appendChild(el); + + /** + * Append to body once the DOM is ready. + */ + if ( document.readyState === 'complete' ) { + document.body.appendChild(el); + } + else { + // Moz, webkit, Opera + if (document.addEventListener) { + appendToBody = function() { + document.removeEventListener('DOMContentLoaded', appendToBody); + document.body.appendChild(el); + }; + + document.addEventListener('DOMContentLoaded', appendToBody); + } + // IE + else { + appendToBody = function() { + if (document.readyState === 'complete') { + document.detachEvent('onreadystatechange', appendToBody); + document.body.appendChild(el); + } + }; + + document.attachEvent('onreadystatechange', appendToBody); + } + } } }; diff --git a/js/hopscotch-0.0.5.min.js b/js/hopscotch-0.0.5.min.js index f437fa64..9ecf195f 100644 --- a/js/hopscotch-0.0.5.min.js +++ b/js/hopscotch-0.0.5.min.js @@ -1,34 +1,34 @@ -(function(u,v){var j,w,B,l,C=window.Sizzle||null,b,n,x,i=u[v],D=!1,r={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,s="undefined"!==typeof window.sessionStorage;j=document.body.style;var F="undefined"!==typeof j.MozTransition||"undefined"!==typeof j.MsTransition||"undefined"!==typeof j.webkitTransition||"undefined"!==typeof j.OTransition|| -"undefined"!==typeof j.transition;i||(j=function(){D&&i.startTour()},window.addEventListener?window.addEventListener("load",j,!1):window.attachEvent&&window.attachEvent("onload",j),b={addClass:function(a,e){var b,c,f;if(0===a.className.length)a.className=e;else{b=a.className.split(/\s+/);c=0;for(f=b.length;cg||g>=h.steps.length?null:h.steps[g]},u=function(){e.nextStep(!1)},z=function(a,d){var q,f;0<=g+a&&g+ad&&e.onPrev&&b.invokeCallback(e.onPrev),b.invokeEventCallbacks(0g?e:g,h=b.getScrollTop(),g=h+b.getWindowHeight(),m=a-f.scrollTopMargin,q,E,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,m]}},f.scrollDuration/1E3,e),a.onComplete.subscribe(d),a.animate()):y?$("body, html").animate({scrollTop:m},f.scrollDuration,d):(0>m&&(m=0),q=h>a?-1:1,E=Math.abs(h-m)/(f.scrollDuration/10),j=function(){var a=b.getScrollTop(),c=a+q*E;0=m||0>q&&c<=m?(c=m,d&&d(),window.scrollTo(0,c)):(window.scrollTo(0,c),b.getScrollTop()===a?d&&d():setTimeout(j,10))},j()):(window.scrollTo(0,m),d&&d())}else i.show();c.onShow&&b.invokeCallback(c.onShow);c.nextOnTargetClick&&b.addClickListener(k,u)});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=p(),d=b.getStepTarget(c);c.nextOnTargetClick&&b.removeClickListener(d, -u);v.call(this,a,1);return this};this.endTour=function(a,c){var d=t(),a=b.valOrDefault(a,!0),c=b.valOrDefault(c,!0);g=0;k=void 0;d.hide();a&&b.clearState(f.cookieName);i.isActive=!1;h&&c&&b.invokeEventCallbacks("end");i.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;dg||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;d