zclip.min.js
6.83 KB
!function(a){a.fn.zclip=function(c){if("object"==typeof c&&!c.length){var b=a.extend({path:"ZeroClipboard.swf",copy:null,beforeCopy:null,afterCopy:null,clickAfter:!0,setHandCursor:!0,setCSSEffects:!0},c);return this.each(function(){var e=a(this);if(e.is(":visible")&&("string"==typeof b.copy||a.isFunction(b.copy))){ZeroClipboard.setMoviePath(b.path);var d=new ZeroClipboard.Client;a.isFunction(b.copy)&&e.bind("zClip_copy",b.copy),a.isFunction(b.beforeCopy)&&e.bind("zClip_beforeCopy",b.beforeCopy),a.isFunction(b.afterCopy)&&e.bind("zClip_afterCopy",b.afterCopy),d.setHandCursor(b.setHandCursor),d.setCSSEffects(b.setCSSEffects),d.addEventListener("mouseOver",function(f){e.trigger("mouseenter")}),d.addEventListener("mouseOut",function(f){e.trigger("mouseleave")}),d.addEventListener("mouseDown",function(f){e.trigger("mousedown"),a.isFunction(b.copy)?d.setText(e.triggerHandler("zClip_copy")):d.setText(b.copy),a.isFunction(b.beforeCopy)&&e.trigger("zClip_beforeCopy")}),d.addEventListener("complete",function(f,g){a.isFunction(b.afterCopy)?e.trigger("zClip_afterCopy"):(g.length>500&&(g=g.substr(0,500)+"...\n\n("+(g.length-500)+" characters not shown)"),e.removeClass("hover"),alert("Copied text to clipboard:\n\n "+g)),b.clickAfter&&e.trigger("click")}),d.glue(e[0],e.parent()[0]),a(window).bind("load resize",function(){d.reposition()})}})}if("string"==typeof c)return this.each(function(){var f=a(this);c=c.toLowerCase();var e=f.data("zclipId"),d=a("#"+e+".zclip");"remove"==c?(d.remove(),f.removeClass("active hover")):"hide"==c?(d.hide(),f.removeClass("active hover")):"show"==c&&d.show()})}}(jQuery);var ZeroClipboard={version:"1.0.7",clients:{},moviePath:"ZeroClipboard.swf",nextId:1,$:function(a){return"string"==typeof a&&(a=document.getElementById(a)),a.addClass||(a.hide=function(){this.style.display="none"},a.show=function(){this.style.display=""},a.addClass=function(b){this.removeClass(b),this.className+=" "+b},a.removeClass=function(d){for(var e=this.className.split(/\s+/),b=-1,c=0;c<e.length;c++)e[c]==d&&(b=c,c=e.length);return b>-1&&(e.splice(b,1),this.className=e.join(" ")),this},a.hasClass=function(b){return!!this.className.match(new RegExp("\\s*"+b+"\\s*"))}),a},setMoviePath:function(a){this.moviePath=a},dispatch:function(d,b,c){var a=this.clients[d];a&&a.receiveEvent(b,c)},register:function(b,a){this.clients[b]=a},getDOMObjectPosition:function(c,a){var b={left:0,top:0,width:c.width?c.width:c.offsetWidth,height:c.height?c.height:c.offsetHeight};return c&&c!=a&&(b.left+=c.offsetLeft,b.top+=c.offsetTop),b},Client:function(a){this.handlers={},this.id=ZeroClipboard.nextId++,this.movieId="ZeroClipboardMovie_"+this.id,ZeroClipboard.register(this.id,this),a&&this.glue(a)}};ZeroClipboard.Client.prototype={id:0,ready:!1,movie:null,clipText:"",handCursorEnabled:!0,cssEffects:!0,handlers:null,glue:function(d,b,e){this.domElement=ZeroClipboard.$(d);var f=99;this.domElement.style.zIndex&&(f=parseInt(this.domElement.style.zIndex,10)+1),"string"==typeof b?b=ZeroClipboard.$(b):"undefined"==typeof b&&(b=document.getElementsByTagName("body")[0]);var c=ZeroClipboard.getDOMObjectPosition(this.domElement,b);this.div=document.createElement("div"),this.div.className="zclip",this.div.id="zclip-"+this.movieId,$(this.domElement).data("zclipId","zclip-"+this.movieId);var a=this.div.style;if(a.position="absolute",a.left=""+c.left+"px",a.top=""+c.top+"px",a.width=""+c.width+"px",a.height=""+c.height+"px",a.zIndex=f,"object"==typeof e)for(addedStyle in e)a[addedStyle]=e[addedStyle];b.appendChild(this.div),this.div.innerHTML=this.getHTML(c.width,c.height)},getHTML:function(d,a){var c="",b="id="+this.id+"&width="+d+"&height="+a;if(navigator.userAgent.match(/MSIE/)){var e=location.href.match(/^https/i)?"https://":"http://";c+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+e+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+d+'" height="'+a+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+b+'"/><param name="wmode" value="transparent"/></object>'}else c+='<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+d+'" height="'+a+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+b+'" wmode="transparent" />';return c},hide:function(){this.div&&(this.div.style.left="-2000px")},show:function(){this.reposition()},destroy:function(){if(this.domElement&&this.div){this.hide(),this.div.innerHTML="";var a=document.getElementsByTagName("body")[0];try{a.removeChild(this.div)}catch(b){}this.domElement=null,this.div=null}},reposition:function(c){if(c&&(this.domElement=ZeroClipboard.$(c),this.domElement||this.hide()),this.domElement&&this.div){var b=ZeroClipboard.getDOMObjectPosition(this.domElement),a=this.div.style;a.left=""+b.left+"px",a.top=""+b.top+"px"}},setText:function(a){this.clipText=a,this.ready&&this.movie.setText(a)},addEventListener:function(a,b){a=a.toString().toLowerCase().replace(/^on/,""),this.handlers[a]||(this.handlers[a]=[]),this.handlers[a].push(b)},setHandCursor:function(a){this.handCursorEnabled=a,this.ready&&this.movie.setHandCursor(a)},setCSSEffects:function(a){this.cssEffects=!!a},receiveEvent:function(d,f){switch(d=d.toString().toLowerCase().replace(/^on/,"")){case"load":if(this.movie=document.getElementById(this.movieId),!this.movie){var c=this;return void setTimeout(function(){c.receiveEvent("load",null)},1)}if(!this.ready&&navigator.userAgent.match(/Firefox/)&&navigator.userAgent.match(/Windows/)){var c=this;return setTimeout(function(){c.receiveEvent("load",null)},100),void(this.ready=!0)}this.ready=!0;try{this.movie.setText(this.clipText)}catch(h){}try{this.movie.setHandCursor(this.handCursorEnabled)}catch(h){}break;case"mouseover":this.domElement&&this.cssEffects&&(this.domElement.addClass("hover"),this.recoverActive&&this.domElement.addClass("active"));break;case"mouseout":this.domElement&&this.cssEffects&&(this.recoverActive=!1,this.domElement.hasClass("active")&&(this.domElement.removeClass("active"),this.recoverActive=!0),this.domElement.removeClass("hover"));break;case"mousedown":this.domElement&&this.cssEffects&&this.domElement.addClass("active");break;case"mouseup":this.domElement&&this.cssEffects&&(this.domElement.removeClass("active"),this.recoverActive=!1)}if(this.handlers[d])for(var b=0,a=this.handlers[d].length;b<a;b++){var g=this.handlers[d][b];"function"==typeof g?g(this,f):"object"==typeof g&&2==g.length?g[0][g[1]](this,f):"string"==typeof g&&window[g](this,f)}}};