forked from pablof7z/chardin.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
chardinjs.min.js
1 lines (1 loc) · 5.12 KB
/
chardinjs.min.js
1
(function(){var t=[].slice;!function(e,i){var r;return r=function(){function t(t){this.data_attribute="data-intro",this.chardinCssClasses=["chardinjs-helper-layer","chardinjs-show-element","chardinjs-relative-position"],this.$el=e(t),e(i).resize(function(t){return function(){return t.refresh()}}(this))}return t.prototype.start=function(){var t,e,i,r;if(this._overlay_visible())return!1;for(this._add_overlay_layer(),r=this.$el.find("*["+this.data_attribute+"]:visible"),e=0,i=r.length;i>e;e++)t=r[e],this._show_element(t);return this.$el.trigger("chardinJs:start")},t.prototype.toggle=function(){return this._overlay_visible()?this.stop():this.start()},t.prototype.refresh=function(){var t,e,i,r,s;if(this._overlay_visible()){for(r=this.$el.find("*["+this.data_attribute+"]:visible"),s=[],e=0,i=r.length;i>e;e++)t=r[e],s.push(this._position_helper_layer(t));return s}return this},t.prototype.stop=function(){var t,r,s,o;for(this.$el.find(".chardinjs-overlay").fadeOut(function(){return e(this).remove()}),this.$el.find(".chardinjs-helper-layer").remove(),o=this.chardinCssClasses,r=0,s=o.length;s>r;r++)t=o[r],this._remove_classes(t);return i.removeEventListener?i.removeEventListener("keydown",this._onKeyDown,!0):document.detachEvent&&document.detachEvent("onkeydown",this._onKeyDown),this.$el.trigger("chardinJs:stop")},t.prototype._remove_classes=function(t){return this.$el.find("."+t).removeClass(t)},t.prototype.set_data_attribute=function(t){return this.data_attribute=t},t.prototype._overlay_visible=function(){return 0!==this.$el.find(".chardinjs-overlay").length},t.prototype._add_overlay_layer=function(){var t,e,i;return this._overlay_visible()?!1:(e=document.createElement("div"),i="",e.className="chardinjs-overlay","BODY"===this.$el.prop("tagName")?(i+="top: 0;bottom: 0; left: 0;right: 0;position: fixed;",e.setAttribute("style",i)):(t=this._get_offset(this.$el.get()[0]),t&&(i+="width: "+t.width+"px; height:"+t.height+"px; top:"+t.top+"px;left: "+t.left+"px;",e.setAttribute("style",i))),this.$el.get()[0].appendChild(e),e.onclick=function(t){return function(){return t.stop()}}(this),setTimeout(function(){return i+="opacity: .8;opacity: .8;-ms-filter: 'progid:DXImageTransform.Microsoft.Alpha(Opacity=80)';filter: alpha(opacity=80);",e.setAttribute("style",i)},10))},t.prototype._get_position=function(t){return t.getAttribute("data-position")||"bottom"},t.prototype._get_css_attribute=function(t){var e,i,r,s,o;if(o=t.getAttribute(this.data_attribute+"-css")||"",o&&String(o).replace(/\s/g,"").length>1)for(i=o.split(" ").filter(function(t){return 0!==t.length}),r=0,s=i.length;s>r;r++)e=i[r],this._add_css_attribute(e);return o},t.prototype._add_css_attribute=function(t){return!e.inArray(t,this.chardinCssClasses)>-1?this.chardinCssClasses.push(t):void 0},t.prototype._getStyle=function(t,e,r){return i.getComputedStyle?i.getComputedStyle(t,r).getPropertyValue(e):t.currentStyle[e]},t.prototype._place_tooltip=function(t,e){var i,r,s,o,n,a,l,h,p;switch(p=this._get_offset(e),e.style.top=null,e.style.right=null,e.style.bottom=null,e.style.left=null,s=this._get_position(t)){case"top":case"bottom":return o=this._get_offset(t),a=o.width,e.style.left=a/2-p.width/2+"px",e.style[s]="-"+p.height+"px";case"left":case"right":return h=parseFloat(this._getStyle(e,"max-width")),e.style[s]="-"+h+"px",o=this._get_offset(t),n=o.height,i=parseFloat(this._getStyle(e,"height")),e.style.top=n/2-i/2+"px",l=parseFloat(this._getStyle(e,"width")),r=175-(h-l),e.style[s]="-"+r+"px"}},t.prototype._position_helper_layer=function(t){var i,r;return r=e(t).data("helper_layer"),i=this._get_offset(t),r.setAttribute("style","width: "+i.width+"px; height:"+i.height+"px; top:"+i.top+"px; left: "+i.left+"px;")},t.prototype._show_element=function(t){var i,r,s;return r=document.createElement("div"),s=document.createElement("div"),e(t).data("helper_layer",r).data("tooltip_layer",s),t.id&&r.setAttribute("data-id",t.id),r.className="chardinjs-helper-layer chardinjs-"+this._get_position(t),this._position_helper_layer(t),this.$el.get()[0].appendChild(r),s.className="chardinjs-tooltip chardinjs-"+this._get_position(t),s.innerHTML="<div class='chardinjs-tooltiptext'>"+t.getAttribute(this.data_attribute)+"</div>",r.appendChild(s),this._place_tooltip(t,s),t.className+=" chardinjs-show-element "+this._get_css_attribute(t),i="",t.currentStyle?i=t.currentStyle.position:document.defaultView&&document.defaultView.getComputedStyle&&(i=document.defaultView.getComputedStyle(t,null).getPropertyValue("position")),i=i.toLowerCase(),"absolute"!==i&&"relative"!==i?t.className+=" chardinjs-relative-position":void 0},t.prototype._get_offset=function(t){var e,i,r;for(r={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 r.top=i,r.left=e,r},t}(),e.fn.extend({chardinJs:function(){var i,s,o,n;return n=arguments[0],s=2<=arguments.length?t.call(arguments,1):[],i=e(this[0]),o=i.data("chardinJs"),o||i.data("chardinJs",o=new r(this,n)),"string"==typeof n?o[n].apply(o,s):"object"==typeof n&&("string"==typeof n.attribute&&o.set_data_attribute(n.attribute),"string"==typeof n.method&&o[n.method].apply(o,s)),o}})}(window.jQuery,window)}).call(this);