forked from pablof7z/chardin.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chardinjs.min.js
2 lines (2 loc) · 5.37 KB
/
chardinjs.min.js
1
2
// Generated by CoffeeScript 1.10.0
(function(){var e=[].slice;(function(t,n){var r;return r=function(){function r(){var r,i;i=arguments[0],r=2<=arguments.length?e.call(arguments,1):[],this.$el=t(i),t(n).resize(function(e){return function(){return e.refresh()}}(this))}return r.prototype.start=function(){var t,n,r,i,s;t=1<=arguments.length?e.call(arguments,0):[];if(this._overlay_visible())return!1;this.$el.data("chardinjs-brightness",t[0]),this._add_overlay_layer(),s=this.$el.find("*[data-intro]:visible");for(r=0,i=s.length;r<i;r++)n=s[r],this._show_element(n);return this.$el.trigger("chardinJs:start")},r.prototype.toggle=function(){return this._overlay_visible()?this.stop(this,arguments):this.start.apply(this,arguments)},r.prototype.refresh=function(){var e,t,n,r,i;if(this._overlay_visible()){r=this.$el.find("*[data-intro]:visible"),i=[];for(t=0,n=r.length;t<n;t++)e=r[t],i.push(this._position_helper_layer(e));return i}return this},r.prototype.stop=function(){return this.$el.find(".chardinjs-overlay").fadeOut(function(){return t(this).remove()}),this.$el.find(".chardinjs-helper-layer").remove(),this.$el.find(".chardinjs-relative-position").removeClass("chardinjs-relative-position"),n.removeEventListener?n.removeEventListener("keydown",this._onKeyDown,!0):document.detachEvent&&document.detachEvent("onkeydown",this._onKeyDown),this.$el.trigger("chardinJs:stop")},r.prototype._overlay_visible=function(){return this.$el.find(".chardinjs-overlay").length!==0},r.prototype._add_overlay_layer=function(){var e,t,n,r;return this._overlay_visible()?!1:(n=document.createElement("div"),r="",n.className="chardinjs-overlay",this.$el.prop("tagName")==="BODY"?(r+="top: 0;bottom: 0; left: 0;right: 0;position: fixed;",n.setAttribute("style",r)):(e=this._get_offset(this.$el.get()[0]),e&&(r+="width: "+e.width+"px; height:"+e.height+"px; top:"+e.top+"px;left: "+e.left+"px;",n.setAttribute("style",r))),this.$el.get()[0].appendChild(n),n.innerHTML='<svg style="width:100%;height:100%;"> <defs> <mask id="chardinjs-mask" x="0" y="0" width="'+n.offsetWidth+'" height="'+n.offsetHeight+'" > <rect x="0" y="0" width="'+n.offsetWidth+'" height="'+n.offsetHeight+'" fill="white"/> </mask> </defs> <rect x="0" y="0" width="'+n.offsetWidth+'" height="'+n.offsetHeight+'" style="stroke: none; fill: black; mask: url(#chardinjs-mask)"/> </svg>',n.onclick=function(e){return function(){return e.stop()}}(this),t=function(e){return function(){var t,n;return n=(t=e.$el.data("chardinjs-brightness"))!=null?t:.8,"opacity:"+n+";background:none;"}}(this),setTimeout(function(){return r+=t(),n.setAttribute("style",r)},10))},r.prototype._get_position=function(e){return e.getAttribute("data-position")||"bottom"},r.prototype._getStyle=function(e,t,r){return n.getComputedStyle?n.getComputedStyle(e,r).getPropertyValue(t):e.currentStyle[t]},r.prototype._place_tooltip=function(e,n){var r,i,s,o,u,a,f,l,c,h;h=this._get_offset(n),n.style.top=null,n.style.right=null,n.style.bottom=null,n.style.left=null,o=this._get_position(e);switch(o){case"top":case"bottom":return u=this._get_offset(e),f=u.width,i=t(n).width(),n.style.left=f/2-h.width/2+"px",n.style[o]="-"+h.height+"px";case"left":case"right":return c=parseFloat(this._getStyle(n,"max-width")),n.style[o]="-"+c+"px",u=this._get_offset(e),a=u.height,r=parseFloat(this._getStyle(n,"height")),n.style.top=a/2-r/2+"px",l=parseFloat(this._getStyle(n,"width")),s=175-(c-l),n.style[o]="-"+s+"px"}},r.prototype._position_helper_layer=function(e){var n,r,i,s,o,u;return i=t(e).data("helper_layer"),n=this._get_offset(e),o=n.left,u=n.top,s=n.width,r=n.height,document.getElementById("chardinjs-mask").innerHTML+='<rect x="'+o+'" y="'+u+'" width="'+s+'" height="'+r+'" fill="black"></rect>',i.setAttribute("style","width: "+n.width+"px; height:"+n.height+"px; top:"+n.top+"px; left: "+n.left+"px;")},r.prototype._show_element=function(e){var n,r,i,s,o,u,a,f;s=document.createElement("div"),a=document.createElement("div"),f=document.createElement("a"),t(e).data("helper_layer",s).data("tooltip_layer",a).data("tooltip_link",f),i=e.getAttribute("data-documentation-text"),r=e.getAttribute("data-documentation-link"),u=!e.getAttribute("data-open-documentation-active-window"),f.innerHTML=i!=null?i:"more...",f.setAttribute("href",r!=null?r:"#"),r&&u&&f.setAttribute("target","_blank"),e.id&&s.setAttribute("data-id",e.id),s.className="chardinjs-helper-layer chardinjs-"+this._get_position(e),this._position_helper_layer(e),this.$el.get()[0].appendChild(s),a.className="chardinjs-tooltip chardinjs-"+this._get_position(e),o=e.getAttribute("data-intro");if(r||i)o+=" "+f.outerHTML;a.innerHTML="<div class='chardinjs-tooltiptext'>"+o+"</div>",s.appendChild(a),this._place_tooltip(e,a),n="",e.currentStyle?n=e.currentStyle.position:document.defaultView&&document.defaultView.getComputedStyle&&(n=document.defaultView.getComputedStyle(e,null).getPropertyValue("position")),n=n.toLowerCase();if(n!=="absolute"&&n!=="relative")return e.className+=" chardinjs-relative-position"},r.prototype._get_offset=function(e){var t,n,r;r={width:e.offsetWidth,height:e.offsetHeight},t=0,n=0;while(e&&!isNaN(e.offsetLeft)&&!isNaN(e.offsetTop))t+=e.offsetLeft,n+=e.offsetTop,e=e.offsetParent;return r.top=n,r.left=t,r},r}(),t.fn.extend({chardinJs:function(){var n,i,s,o;return o=arguments[0],i=2<=arguments.length?e.call(arguments,1):[],n=t(this[0]),s=n.data("chardinJs"),s||n.data("chardinJs",s=new r(this,o)),typeof o=="string"&&s[o].apply(s,i),s}})})(window.jQuery,window)}).call(this);