forked from mapdwell/chardin.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchardinjs.min.js
2 lines (2 loc) · 10.3 KB
/
chardinjs.min.js
1
2
(function(){var t,e=[].slice;!function(i,s){var n;n=function(){function e(t){var e;this.data_attribute="data-chardin-intro",this.chardinCssClasses=["chardinjs-helper-layer","chardinjs-show-element","chardinjs-relative-position"],this.$el=i(t),this.sequenced=!!this.$el.data("chardin-sequenced"),this.sequencedItems=this._getSequencedElements(),this.sequenceIdx=0,this.active=!1,this.timeOut=null,this.isAuto=!!this.$el.data("chardin-auto"),this.delayTime=this.$el.data("chardin-delay")||2e3,i(s).resize((e=this,function(){return e.refresh()}))}return e.prototype.start=function(){var t,e,i,s;if(this._overlay_visible())return!1;if(this._add_overlay_layer(),this.sequenced)this.sequenceIdx=0,this._show_sequenced_element();else for(e=0,i=(s=this.$el.find("*["+this.data_attribute+"]:visible")).length;e<i;e++)t=s[e],this._show_element(t);return this.active=!0,this.$el.trigger("chardinJs:start")},e.prototype.toggle=function(){return this._overlay_visible()?this.stop():this.start()},e.prototype.refresh=function(){var t,e,i,s,n;if(this._overlay_visible()){for(n=[],e=0,i=(s=this.$el.find("*["+this.data_attribute+"]:visible")).length;e<i;e++)t=s[e],n.push(this._position_helper_layer(t));return n}return this},e.prototype.stop=function(){var t,e,n,r,o,a,h;for(this.active=!1,o=this.$el.find("*[data-chardin-intro]:visible"),a=0,_len=o.length;a<_len;a++)h=o[a],i(h).data("chardin-class")&&i(h).removeClass(i(h).data("chardin-class"));for(this._remove_overlay_layer(),this.$el.find(".chardinjs-helper-layer").remove(),e=0,n=(r=this.chardinCssClasses).length;e<n;e++)t=r[e],this._remove_classes(t);return s.removeEventListener?s.removeEventListener("keydown",this._onKeyDown,!0):document.detachEvent&&document.detachEvent("onkeydown",this._onKeyDown),this.sequenceIdx=0,this.$el.trigger("chardinJs:stop")},e.prototype._remove_classes=function(t){return this.$el.find("."+t).removeClass(t)},e.prototype.set_data_attribute=function(t){return this.data_attribute=t},e.prototype.set_data_helptext=function(t){return this.data_helptext=t},e.prototype._overlay_visible=function(){return 0!==this.$el.find(".chardinjs-overlay").length},e.prototype._add_overlay_layer=function(){var e="",s=this;if(this._overlay_visible())return!1;(t=document.createElement("div")).id="chardinjs-mask",element_position=this._get_offset(this.$el.get()[0]),element_position&&(i("*").filter((function(){return"fixed"==i(this).css("position")})).each((function(){i(this)[0].className+=" chardinjs-no-fixed"})),t.className="chardinjs-overlay","BODY"===this.$el.prop("tagName").toUpperCase()?e+="top: 0;bottom: 0; left: 0;right: 0;position: fixed;":e+="width: "+element_position.width+"px; height:"+element_position.height+"px; top:"+element_position.top+"px;left: "+element_position.left+"px;",t.setAttribute("style",e)),this.$el.get()[0].appendChild(t),this.$el.find("#chardinjs-mask").fadeIn(),t.onclick=function(t){return s.sequenced?s._handleMouseClick(t):s.stop()}},e.prototype._remove_overlay_layer=function(){this.$el.find(".chardinjs-helper-layer").remove(),this.$el.find(".chardinjs-show-element").removeClass("chardinjs-show-element"),this.$el.find(".chardinjs-relative-position").removeClass("chardinjs-relative-position"),this.$el.find(".chardinjs-no-fixed").removeClass("chardinjs-no-fixed"),this.$el.find("#chardinjs-mask").fadeOut((function(){return i(this).remove()}))},e.prototype._position_overlay_layer=function(t){if(t.className+=" chardinjs-show-element "+this._get_css_attribute(t),current_element_position="",t.currentStyle?current_element_position=t.currentStyle.position:document.defaultView&&document.defaultView.getComputedStyle&&(current_element_position=document.defaultView.getComputedStyle(t,null).getPropertyValue("position")),current_element_position=current_element_position.toLowerCase(),"absolute"!==current_element_position&&"relative"!==current_element_position)return t.className+=" chardinjs-relative-position"},e.prototype._get_position=function(t){var e,i,s=t.getAttribute(this.data_attribute);return null==(e="#"==s[0]&&this.data_helptext[s].position?this.data_helptext[s].position:t.getAttribute("data-chardin-position"))?"bottom":null!=(i=e.split(":"))?i[0]:e},e.prototype._get_position_offset=function(t){var e,i,s=t.getAttribute(this.data_attribute);return null==(e="#"==s[0]&&this.data_helptext[s].position?this.data_helptext[s].position:t.getAttribute("data-chardin-position"))?1:1+parseInt((null!=(i=e.split(":"))?(i[1]||"").split(",")[0]:void 0)||0,10)/100},e.prototype._get_position_distance=function(t){var e,i,s=t.getAttribute(this.data_attribute);return null==(e="#"==s[0]&&this.data_helptext[s].position?this.data_helptext[s].position:t.getAttribute("data-chardin-position"))?100:parseInt((null!=(i=e.split(":"))?(i[1]||"").split(",")[1]:void 0)||100,10)},e.prototype._get_css_attribute=function(t){var e,i,s,n,r;if((r=t.getAttribute(this.data_attribute+"-css")||"")&&String(r).replace(/\s/g,"").length>1)for(s=0,n=(i=r.split(" ").filter((function(t){return 0!==t.length}))).length;s<n;s++)e=i[s],this._add_css_attribute(e);return r},e.prototype._add_css_attribute=function(t){if(!i.inArray(t,this.chardinCssClasses)>-1)return this.chardinCssClasses.push(t)},e.prototype._getStyle=function(t,e,i){return s.getComputedStyle?s.getComputedStyle(t,i).getPropertyValue(e):t.currentStyle[e]},e.prototype._place_tooltip=function(t,e){var s,n,r,o,a,h,l,d;switch(d=this._get_offset(e),e.style.top=null,e.style.right=null,e.style.bottom=null,e.style.left=null,o=this._get_position(t),r=this._get_position_distance(t),e.className+=" chardinjs-distance-"+r,r=r/100-1,o){case"top":case"bottom":return h=this._get_offset(t).width,my_width=parseFloat(this._getStyle(e,"width")),e.style.left=h/2*this._get_position_offset(t)-d.width/2+"px",my_width&&i(e).width(my_width),e.style[o]="-"+(d.height+30*r)+"px";case"left":case"right":return l=parseFloat(this._getStyle(e,"max-width")),e.style[o]="-"+l+"px",a=this._get_offset(t).height,(s=parseFloat(this._getStyle(e,"height")))&&i(e).height(s),e.style.top=a/2*this._get_position_offset(t)-s/2+"px",n=185-(l-parseFloat(this._getStyle(e,"width")))+30*r,e.style[o]="-"+n+"px"}},e.prototype._position_helper_layer=function(t){var e,s;if(s=i(t).data("helper_layer"),e=this._get_offset(t),i(t).is(":visible")&&s&&s.setAttribute("style","display: block; width: "+e.width+"px; height:"+e.height+"px; top:"+e.top+"px; left: "+e.left+"px;"),i(t).is(":visible")&&!s&&this._show_element(t),!i(t).is(":visible")&&s)return s.setAttribute("style","display: none; width: "+e.width+"px; height:"+e.height+"px; top:"+e.top+"px; left: "+e.left+"px;")},e.prototype._remove_sequenced_element=function(){this.$el.find(".chardinjs-helper-layer").remove(),this.$el.find(".chardinjs-show-element").removeClass("chardinjs-show-element"),this.$el.find(".chardinjs-relative-position").removeClass("chardinjs-relative-position")},e.prototype._show_element=function(t){var e,s,n;e=document.createElement("div"),s=document.createElement("div");var r=t.getAttribute(this.data_attribute);if("#"==r[0]){var o=this.data_helptext[r];if(!o)return!1;s.innerHTML="<div class='chardinjs-tooltiptext'>"+o.text+"</div>"}else s.innerHTML="<div class='chardinjs-tooltiptext'>"+r+"</div>";i(t).data("helper_layer",e).data("tooltip_layer",s),t.id&&e.setAttribute("data-id",t.id),n=["chardinjs-helper-layer","chardinjs-"+this._get_position(t)],i(t).data("chardin-helper-class")&&n.push(i(t).data("chardin-helper-class")),e.className=n.join(" "),i(t).data("chardin-class")&&i(t).addClass(i(t).data("chardin-class")),this._position_helper_layer(t),this.$el.get()[0].appendChild(e),s.className="chardinjs-tooltip chardinjs-"+this._get_position(t),e.appendChild(s),this._place_tooltip(t,s);var a=this;return e.onclick=function(t){return a.sequenced?a._handleMouseClick(t):a.stop()},this._position_overlay_layer(t),a.sequenced&&s.scrollIntoView({behavior:"smooth",block:"center",inline:"nearest"}),!0},e.prototype._show_sequenced_element=function(t){var e=this;if(this.sequenceIdx<0&&(this.sequenceIdx=0),!this.sequencedItems[this.sequenceIdx])return this.stop();for(;!this._show_element(this.sequencedItems[this.sequenceIdx]);)this.sequenceIdx++;if(this.sequenceIdx<this.sequencedItems.length-1){if(this.isAuto)return this.timeOut=setTimeout((function(){return e.next(e.isAuto)}),this.delayTime)}else if(this.isAuto)return this.timeOut=setTimeout((function(){return e.stop()}),this.delayTime)},e.prototype.next=function(t){var e=this;return t=!1!==t,this.sequenceIdx++,t?(clearTimeout(this.timeOut),this.timeOut=setTimeout((function(){return e._remove_sequenced_element(),e._show_sequenced_element(!0),e.$el.trigger("chardinJs:next")}),this.delayTime)):(this._remove_sequenced_element(),this._show_sequenced_element(!1),this.$el.trigger("chardinJs:next"))},e.prototype.previous=function(t){var e=this;return t=!1!==t,this.sequenceIdx--,t?(clearTimeout(this.timeOut),this.timeOut=setTimeout((function(){return e._remove_sequenced_element(),e._show_sequenced_element(!0),e.$el.trigger("chardinJs:previous")}),this.delayTime)):(this._remove_sequenced_element(),this._show_sequenced_element(!1),this.$el.trigger("chardinJs:previous"))},e.prototype._handleMouseClick=function(t){if(this.active)return size=this._getMaxSize(),(t=t||s.event).shiftKey?this.previous(!1):this.next(!1)},e.prototype._getMaxSize=function(){var t,e,i;return t=document.body,i=document.documentElement,e=Math.max(t.scrollHeight,t.offsetHeight,i.clientHeight,i.scrollHeight,i.offsetHeight),{width:Math.max(t.scrollWidth,t.offsetWidth,i.clientWidth,i.scrollWidth,i.offsetWidth),height:e}},e.prototype._getSequencedElements=function(){return this.$el.find("*["+this.data_attribute+"]:visible").sort((function(t,e){return(i(t).data("chardin-sequence")||100)-(i(e).data("chardin-sequence")||100)}))},e.prototype._get_offset=function(t){var e,i,s;for(s={width:t.offsetWidth,height:t.offsetHeight},e=0,i=0;t&&!isNaN(t.offsetLeft)&&!isNaN(t.offsetTop);)e+=t.offsetLeft,i+=t.offsetTop,t=t.offsetParent;return s.top=i,s.left=e,s},e}(),i.fn.extend({chardinJs:function(){var t,s,r,o;return o=arguments[0],s=2<=arguments.length?e.call(arguments,1):[],t=i(this[0]),(r=t.data("chardinJs"))||t.data("chardinJs",r=new n(this,o)),"string"==typeof o?r[o].apply(r,s):"object"==typeof o&&("string"==typeof o.attribute&&r.set_data_attribute(o.attribute),"string"==typeof o.method&&r[o.method].apply(r,s),"string"==typeof o.url&&i.ajax({type:"GET",url:o.url,dataType:"json",success:function(t){r.set_data_helptext(t)}})),r}})}(window.jQuery,window)}).call(this);
//# sourceMappingURL=chardinjs.min.js.map