This repository has been archived by the owner on Feb 17, 2021. It is now read-only.
/
hopscotch-0.0.4.min.js
32 lines (32 loc) · 15.9 KB
/
hopscotch-0.0.4.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(function(t,u){var k,v,z,l,b,p,i=t[u],A=!1,q={animate:!1,smoothScroll:!0,scrollDuration:1E3,scrollTopMargin:200,showCloseButton:!0,showPrevButton:!1,showNextButton:!0,bubbleWidth:280,bubblePadding:15,arrowWidth:20,skipIfNoElement:!0,cookieName:"hopscotch.tour.state"},x="undefined"!==typeof window.jQuery,r="undefined"!==typeof window.sessionStorage;k=document.body.style;var B="undefined"!==typeof k.MozTransition||"undefined"!==typeof k.MsTransition||"undefined"!==typeof k.webkitTransition||"undefined"!==
typeof k.OTransition||"undefined"!==typeof k.transition;i||(k=function(){A&&i.startTour()},window.addEventListener?window.addEventListener("load",k,!1):window.attachEvent&&window.attachEvent("onload",k),b={addClass:function(a,e){var b,d,f;if(0===a.className.length)a.className=e;else{b=a.className.split(/\s+/);d=0;for(f=b.length;d<f;++d)if(b[d]===e)return;b.splice(0,0,e);a.className=b.join(" ")}},removeClass:function(a,b){var c,d,f,h,g,i,j;d=b.split(/\s+/);c=a.className.split(/\s+/);h=0;for(i=d.length;h<
i;++h){f=d[h];g=0;for(j=c.length;g<j&&c[g]!==f;++g);g<j&&c.splice(g,1)}a.className=c.join(" ")},getPixelValue:function(a){var b=typeof a;return"number"===b?a:"string"===b?parseInt(a,10):0},valOrDefault:function(a,b){return"undefined"!==typeof a?a:b},invokeCallbacks:function(a,b){for(var c=p[a],d=0,f=c.length;d<f;++d)c[d].cb.apply(this,b)},getScrollTop:function(){return"undefined"!==typeof window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop},getScrollLeft:function(){return"undefined"!==
typeof window.pageXOffset?window.pageXOffset:document.documentElement.scrollLeft},getWindowHeight:function(){return window.innerHeight?window.innerHeight:document.documentElement.clientHeight},getWindowWidth:function(){return window.innerWidth?window.innerWidth:document.documentElement.clientWidth},addClickListener:function(a,b){return a.addEventListener?a.addEventListener("click",b,!1):a.attachEvent("onclick",b)},removeClickListener:function(a,b){a.removeEventListener?a.removeEventListener("click",
b,!1):a.detachEvent("click",b)},evtPreventDefault:function(a){a.preventDefault?a.preventDefault():event&&(event.returnValue=!1)},extend:function(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c])},getStepTarget:function(a){return!a||!a.target?null:"string"===typeof a.target?/[#\.].*/.test(a.target)?document.querySelector?document.querySelector(a.target):x?(a=jQuery(a.target),a.length?a[0]:null):window.Sizzle?(a=Sizzle(a.target),a.length?a[0]:null):"#"===a.target[0]&&-1===a.target.indexOf(" ")?document.getElementById(a.target.substring(1)):
null:document.getElementById(a.target):a.target},setState:function(a,b,c){var d="";r?sessionStorage.setItem(a,b):(c&&(d=new Date,d.setTime(d.getTime()+864E5*c),d="; expires="+d.toGMTString()),document.cookie=a+"="+b+d+"; path=/")},getState:function(a){var b=a+"=",c=document.cookie.split(";"),d;if(r)return sessionStorage.getItem(a);for(a=0;a<c.length;a++){for(d=c[a];" "===d.charAt(0);)d=d.substring(1,d.length);if(0===d.indexOf(b))return d.substring(b.length,d.length)}return null},clearState:function(a){r?
sessionStorage.removeItem(a):this.setState(a,"",-1)}},p={next:[],prev:[],start:[],end:[],show:[],error:[],close:[]},l={stepNums:null,nextBtn:"Next",prevBtn:"Back",doneBtn:"Done",skipBtn:"Skip",closeTooltip:"Close"},v=function(a){this.init(a)},v.prototype={isShowing:!1,currStep:void 0,_createButton:function(a,e){var c=document.createElement("input");c.id=a;c.type="button";c.value=e;b.addClass(c,"hopscotch-nav-button");0<=a.indexOf("prev")?b.addClass(c,"prev"):b.addClass(c,"next");return c},setPosition:function(a){var e,
c,d,f,h;d=b.getStepTarget(a);var g=this.element,i=this.arrowEl,j=b.getPixelValue(a.arrowOffset);e=b.getPixelValue(a.width)||this.opt.bubbleWidth;c=b.valOrDefault(a.padding,this.opt.bubblePadding);b.removeClass(g,"fade-in-down fade-in-up fade-in-left fade-in-right");d=d.getBoundingClientRect();"top"===a.orientation?(e=g.offsetHeight,f=d.top-e-this.opt.arrowWidth,h=d.left):"bottom"===a.orientation?(f=d.bottom+this.opt.arrowWidth,h=d.left):"left"===a.orientation?(f=d.top,h=d.left-e-2*c-12-this.opt.arrowWidth):
"right"===a.orientation&&(f=d.top,h=d.right+this.opt.arrowWidth);if(j)if("top"===a.orientation||"bottom"===a.orientation)i.style.top="",i.style.left=j+"px";else{if("left"===a.orientation||"right"===a.orientation)i.style.left="",i.style.top=j+"px"}else i.style.top="",i.style.left="";h+=b.getPixelValue(a.xOffset);f+=b.getPixelValue(a.yOffset);a.fixedElement||(f+=b.getScrollTop(),h+=b.getScrollLeft());g.style.position=a.fixedElement?"fixed":"absolute";this.opt.animate&&x&&!B?$(g).animate({top:f+"px",
left:h+"px"}):(g.style.top=f+"px",g.style.left=h+"px")},_initNavButtons:function(){var a=document.createElement("div");this.prevBtnEl=this._createButton("hopscotch-prev",l.prevBtn);this.nextBtnEl=this._createButton("hopscotch-next",l.nextBtn);this.doneBtnEl=this._createButton("hopscotch-done",l.doneBtn);b.addClass(this.doneBtnEl,"hide");a.appendChild(this.prevBtnEl);a.appendChild(this.nextBtnEl);a.appendChild(this.doneBtnEl);b.addClickListener(this.prevBtnEl,function(){i.prevStep(!0)});b.addClickListener(this.nextBtnEl,
function(){i.nextStep(!0)});b.addClickListener(this.doneBtnEl,i.endTour);a.className="hopscotch-actions";this.buttonsEl=a;this.containerEl.appendChild(a);return this},_getCloseFn:function(){var a=this;this.closeFn||(this.closeFn=function(e){if(a.opt.onClose)a.opt.onClose();a.opt.id&&!a.opt.isTourBubble?i.getCalloutManager().removeCallout(a.opt.id):a.destroy();b.evtPreventDefault(e)});return this.closeFn},initCloseButton:function(){var a=document.createElement("a");a.className="hopscotch-bubble-close";
a.href="#";a.title=l.closeTooltip;a.innerHTML=l.closeTooltip;this.opt.isTourBubble?b.addClickListener(a,function(a){var c=i.getCurrStepNum(),d=i.getCurrTour(),f=c===d.steps.length-1;b.invokeCallbacks("close",[d.id,c]);i.endTour(!0,f);a.preventDefault?a.preventDefault():event&&(event.returnValue=!1)}):b.addClickListener(a,this._getCloseFn());this.closeBtnEl=a;this.containerEl.appendChild(a);return this},_initArrow:function(){var a,b;this.arrowEl=document.createElement("div");this.arrowEl.className=
"hopscotch-bubble-arrow-container";b=document.createElement("div");b.className="hopscotch-bubble-arrow-border";a=document.createElement("div");a.className="hopscotch-bubble-arrow";this.arrowEl.appendChild(b);this.arrowEl.appendChild(a);this.element.appendChild(this.arrowEl);return this},render:function(a,e,c,d){var f=this.element,h,g;a?this.currStep=a:this.currStep&&(a=this.currStep);h=b.valOrDefault(a.showNextButton,this.opt.showNextButton);g=b.valOrDefault(a.showPrevButton,this.opt.showPrevButton);
this.setTitle(a.title?a.title:"");this.setContent(a.content?a.content:"");this.opt.showNumber&&this.setNum(e);this.orientation=a.orientation;this.opt.showNavButtons&&(this.showPrevButton(this.prevBtnEl&&g&&0<e),this.showNextButton(this.nextBtnEl&&h&&!c),this.nextBtnEl.value=a.showSkip?l.skipBtn:l.nextBtn,c?b.removeClass(this.doneBtnEl,"hide"):b.addClass(this.doneBtnEl,"hide"));this._setArrow(a.orientation);e=b.getPixelValue(a.width)||this.opt.bubbleWidth;c=b.valOrDefault(a.padding,this.opt.bubblePadding);
this.containerEl.style.width=e+"px";this.containerEl.style.padding=c+"px";f.style.zIndex=a.zindex?a.zindex:"";"top"===a.orientation?(f.style.top="-9999px",f.style.left="-9999px",b.removeClass(f,"hide"),this.setPosition(a),b.addClass(f,"hide")):this.setPosition(a);d&&!a.fixedElement?d():this.show();return this},setTitle:function(a){a?(this.titleEl.innerHTML=a,b.removeClass(this.titleEl,"hide")):b.addClass(this.titleEl,"hide");return this},setContent:function(a){a?(this.contentEl.innerHTML=a,b.removeClass(this.contentEl,
"hide")):b.addClass(this.contentEl,"hide");return this},setNum:function(a){a=l.stepNums&&a<l.stepNums.length?l.stepNums[a]:a+1;this.numberEl.innerHTML=a},_setArrow:function(a){b.removeClass(this.arrowEl,"down up right left");"top"===a?b.addClass(this.arrowEl,"down"):"bottom"===a?b.addClass(this.arrowEl,"up"):"left"===a?b.addClass(this.arrowEl,"right"):"right"===a&&b.addClass(this.arrowEl,"left")},_getArrowDirection:function(){if("top"===this.orientation)return"down";if("bottom"===this.orientation)return"up";
if("left"===this.orientation)return"right";if("right"===this.orientation)return"left"},show:function(){var a=this,e="fade-in-"+this._getArrowDirection();b.removeClass(this.element,"hide");this.opt.animate?setTimeout(function(){b.addClass(a.element,"animate")},50):(b.addClass(this.element,e),setTimeout(function(){b.removeClass(a.element,"invisible")},50),setTimeout(function(){b.removeClass(a.element,e)},1E3));this.isShowing=!0;return this},hide:function(a){var e=this.element,a=b.valOrDefault(a,!0);
e.style.top="";e.style.left="";a?(b.addClass(e,"hide"),b.removeClass(e,"invisible")):(b.removeClass(e,"hide"),this.opt.animate||b.addClass(e,"invisible"));b.removeClass(e,"animate fade-in-up fade-in-down fade-in-right fade-in-left");this.isShowing=!1;return this},_showButton:function(a,e,c){var d="hide";c&&(d="hide-all");"undefined"===typeof e&&(e=!0);e?b.removeClass(a,d):b.addClass(a,d)},showPrevButton:function(a,b){this._showButton(this.prevBtnEl,a,b)},showNextButton:function(a,b){this._showButton(this.nextBtnEl,
a,b)},showCloseButton:function(a,b){this._showButton(this.closeBtnEl,a,b)},_initAnimate:function(){var a=this;setTimeout(function(){b.addClass(a.element,"animate")},50)},_removeAnimate:function(){b.removeClass(this.element,"animate")},destroy:function(){var a=this.element;a.parentNode.removeChild(a);b.removeClickListener(this.closeBtnEl,this._getCloseFn())},init:function(a){var e=document.createElement("div"),c=document.createElement("div"),d=document.createElement("div"),f=this,h=!1;this.element=
e;this.containerEl=c;this.titleEl=document.createElement("h3");this.contentEl=document.createElement("p");opt={animate:q.animate,showPrevButton:q.showPrevButton,showNextButton:q.showNextButton,bubbleWidth:q.bubbleWidth,bubblePadding:q.bubblePadding,arrowWidth:q.arrowWidth,showNumber:!0,showNavButtons:!0,isTourBubble:!0};a="undefined"===typeof a?{}:a;b.extend(opt,a);this.opt=opt;e.className="hopscotch-bubble animated";c.className="hopscotch-bubble-container";opt.showNumber?(this.numberEl=document.createElement("span"),
this.numberEl.className="hopscotch-bubble-number",c.appendChild(this.numberEl)):b.addClass(e,"no-number");d.appendChild(this.titleEl);d.appendChild(this.contentEl);d.className="hopscotch-bubble-content";c.appendChild(d);e.appendChild(c);opt.showNavButtons&&this._initNavButtons();this.initCloseButton();this._initArrow();a=function(){!h&&f.isShowing&&(h=!0,setTimeout(function(){f.setPosition(f.currStep);h=!1},100))};window.addEventListener?window.addEventListener("resize",a,!1):window.attachEvent&&
window.attachEvent("onresize",a,!1);this.hide();document.body.appendChild(e)}},z=function(){var a={};this.createCallout=function(b){var c;if(b.id){if(a[b.id])throw"Callout by that id already exists. Please choose a unique id.";b.isTourBubble=!1;c=new v(b);a[b.id]=c;b.target&&c.render(b)}else throw"Must specify a callout id.";};this.getCallout=function(b){return a[b]};this.removeAllCallouts=function(){for(var b in a)this.removeCallout(b)};this.removeCallout=function(b){var c=a[b];a[b]=null;c&&c.destroy()}},
k=function(a){var e=this,c,d,f,h,g,k,j,r,s=function(){c||(c=new v({animate:f.animate,bubblePadding:f.bubblePadding,bubbleWidth:f.bubbleWidth,showNextButton:f.showNextButton,showPrevButton:f.showPrevButton,arrowWidth:f.arrowWidth}));return c},n=function(){return 0>g||g>=h.steps.length?null:h.steps[g]},t=function(){e.nextStep(!1)},y=function(a,d){var f,c;0<=g+a&&g+a<h.steps.length?(g+=a,c=n(),setTimeout(function(){(f=b.getStepTarget(c))?d(g):(b.invokeCallbacks("error",[h.id,g]),y(a,d))},b.valOrDefault(c.delay,
0))):d(-1)},u=function(a,d){var c=this,e,i,j,k;s().hide();a=b.valOrDefault(a,!0);e=n();j=e.multipage;i=g;k=function(c){if(-1===c)return this.endTour(!0);if(a){if(0<d&&e.onNext)e.onNext();else if(0>d&&e.onPrev)e.onPrev();b.invokeCallbacks(0<d?"next":"prev",[h.id,i]);if(0<d&&j)return}this.showStep(c)};if(!j&&f.skipIfNoElement)y(d,function(a){k.call(c,a)});else if(0<=g+d&&g+d<h.steps.length){g+=d;e=n();if(!b.getStepTarget(e)&&!j)return b.invokeCallbacks("error",[h.id,g]),this.endTour(!0,!1);this.changeStepCb(g)}return this};
this.getCalloutManager=function(){"undefined"===typeof d&&(d=new z);return d};this.startTour=function(a,d){var c;if(!h){c={};var e;h=a;for(e in a)a.hasOwnProperty(e)&&("id"!==e&&"steps"!==e)&&(c[e]=a[e]);this.resetDefaultOptions();r.call(this,c,!0);if(c=b.getState(f.cookieName))c=c.split(":"),k=c[0],j=c[1],j=parseInt(j,10),2<c.length&&"mp"===c[2]&&j<h.steps.length-1&&++j}"undefined"!==typeof d&&(g=d);if("complete"!==document.readyState)return A=!0,this;if("undefined"===typeof g)if(h.id===k&&"undefined"!==
typeof j){if(g=j,c=n(),c=b.getStepTarget(c),c||(--g,c=n(),c=b.getStepTarget(c)),!c&&f.skipIfNoElement&&(y(1),c=-1!==g&&b.getStepTarget(h.steps[g])),!c)return this.endTour(!1,!1),this}else g=0;b.invokeCallbacks("start",[h.id,g]);c=s();c.hide(!1);this.isActive=!0;f.animate&&c._initAnimate();b.getStepTarget(n())?this.showStep(g):(b.invokeCallbacks("error",[h.id,g]),f.skipIfNoElement&&this.nextStep(!1));return this};this.showStep=function(a){var c=h.steps[a];setTimeout(function(){var d=h.steps.length,
e=h.id+":"+a,i=s(),j=b.getStepTarget(c);g=a;f.animate||i.hide(!1);i.render(c,a,a===d-1,function(){var a=function(){i.show()},d=s().element,e=b.getPixelValue(d.style.top),d=e+b.getPixelValue(d.offsetHeight),g=b.getStepTarget(n()).getBoundingClientRect(),h=g.top+b.getScrollTop(),g=g.bottom+b.getScrollTop(),e=e<h?e:h,d=d>g?d:g,h=b.getScrollTop(),g=h+b.getWindowHeight(),m=e-f.scrollTopMargin,w,k,l;e>=h&&(e<=h+f.scrollTopMargin||d<=g)?a&&a():f.smoothScroll?"undefined"!==typeof YAHOO&&"undefined"!==typeof YAHOO.env&&
"undefined"!==typeof YAHOO.env.ua&&"undefined"!==typeof YAHOO.util&&"undefined"!==typeof YAHOO.util.Scroll?(e=YAHOO.env.ua.webkit?document.body:document.documentElement,d=YAHOO.util.Easing?YAHOO.util.Easing.easeOut:void 0,e=new YAHOO.util.Scroll(e,{scroll:{to:[0,m]}},f.scrollDuration/1E3,d),e.onComplete.subscribe(a),e.animate()):x?$("body, html").animate({scrollTop:m},f.scrollDuration,a):(0>m&&(m=0),w=h>e?-1:1,k=Math.abs(h-m)/(f.scrollDuration/10),l=function(){var c=b.getScrollTop(),d=c+w*k;0<w&&
d>=m||0>w&&d<=m?(d=m,a&&a(),window.scrollTo(0,d)):(window.scrollTo(0,d),b.getScrollTop()===c?a&&a():setTimeout(l,10))},l()):(window.scrollTo(0,m),a&&a());if(c.onShow)c.onShow();c.nextOnTargetClick&&b.addClickListener(j,t)});b.invokeCallbacks("show",[h.id,g]);c.multipage&&(e+=":mp");b.setState(f.cookieName,e,1)},c.delay?c.delay:0);return this};this.prevStep=function(a){u.call(this,a,-1);return this};this.nextStep=function(a){var c=n(),d=b.getStepTarget(c);c.nextOnTargetClick&&b.removeClickListener(d,
t);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;j=void 0;d.hide();a&&b.clearState(f.cookieName);i.isActive=!1;h&&c&&b.invokeCallbacks("end",[h.id]);i.removeCallbacks(!0);h=null;return this};this.getCurrTour=function(){return h};this.getCurrStepNum=function(){return g};this.listen=function(a,b,c){a&&b&&p[a].push({cb:b,fromTour:c});return this};this.removeCallback=function(a,b){var c=p[a],d,e;d=0;for(e=c.length;d<e;++d)b===c[d].cb&&
c.splice(d,1);return this};this.removeCallbacks=function(a){var b,c,d,e;for(e in p)if(a){b=p[e];c=0;for(d=b.length;c<d;++c)b[c].fromTour&&(b.splice(c--,1),--d)}else p[e]=[];return this};this.setCookieName=function(a){f.cookieName=a;return this};this.resetDefaultOptions=function(){f||(f={});b.extend(f,q);return this};r=function(a,c){var d;f||this.resetDefaultOptions();b.extend(f,a);a&&b.extend(l,a.i18n);this.listen("next",a.onNext,c).listen("prev",a.onPrev,c).listen("start",a.onStart,c).listen("end",
a.onEnd,c).listen("show",a.onShow,c).listen("error",a.onError,c).listen("close",a.onClose,c);d=s();f.animate?d._initAnimate():d._removeAnimate();d.showCloseButton(a.showCloseButton,"undefined"!==typeof a.showCloseButton);return this};this.configure=function(a){return r.call(this,a,!1)};a&&this.configure(a)},i=new k,t[u]=i)})(window,"hopscotch");