ZeroClipboard.min.js 7.9 KB

12345678
  1. /*!
  2. * zeroclipboard
  3. * The Zero Clipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie, and a JavaScript interface.
  4. * Copyright 2012 Jon Rohan, James M. Greene, .
  5. * Released under the MIT license
  6. * http://jonrohan.github.com/ZeroClipboard/
  7. * v1.1.4
  8. */(function(){function b(a,b){var c=a.style[b];a.currentStyle?c=a.currentStyle[b]:window.getComputedStyle&&(c=document.defaultView.getComputedStyle(a,null).getPropertyValue(b));if(c=="auto"&&b=="cursor"){var d=["a"];for(var e=0;e<d.length;e++)if(a.tagName.toLowerCase()==d[e])return"pointer"}return c}function c(b){b||(b=window.event);var c;this!==window?c=this:b.target?c=b.target:b.srcElement&&(c=b.srcElement),a._client.setCurrent(e(c))}function e(a){return!a||a.addClass?a:(a.addClass=function(a){if(a&&typeof a=="string"){var b=(a||"").split(/\s+/),c=this;if(c.nodeType===1)if(!c.className)c.className=a;else{var d=" "+c.className+" ",e=c.className;for(var f=0,g=b.length;f<g;f++)d.indexOf(" "+b[f]+" ")<0&&(e+=" "+b[f]);c.className=e.replace(/^\s+|\s+$/g,"")}}return this},a.removeClass=function(a){if(a&&typeof a=="string"||a===undefined){var b=(a||"").split(/\s+/),c=this;if(c.nodeType===1&&c.className)if(a){var d=(" "+c.className+" ").replace(/[\n\t]/g," ");for(var e=0,f=b.length;e<f;e++)d=d.replace(" "+b[e]+" "," ");c.className=d.replace(/^\s+|\s+$/g,"")}else c.className=""}return this},a)}"use strict";var a={};a.Client=function(b){var c=a._client;if(c)return b&&c.glue(b),c;this.handlers={},this._text=null,a.detectFlashSupport()&&this.bridge(),b&&this.glue(b),a._client=this},a.Client.prototype.bridge=function(){function b(a){return(a.indexOf("?")>=0?"&":"?")+"nocache="+(new Date).getTime()}function c(){var b=[];return a._trustedDomain&&b.push("trustedDomain="+a._trustedDomain),b.join("&")}this.htmlBridge=a.$("#global-zeroclipboard-html-bridge");if(this.htmlBridge.length){this.htmlBridge=this.htmlBridge[0],this.flashBridge=document["global-zeroclipboard-flash-bridge"];return}var d=' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="global-zeroclipboard-flash-bridge" width="100%" height="100%"> <param name="movie" value="'+a._moviePath+b(a._moviePath)+'"/> <param name="allowScriptAccess" value="always" /> <param name="scale" value="exactfit"> <param name="loop" value="false" /> <param name="menu" value="false" /> <param name="quality" value="best" /> <param name="bgcolor" value="#ffffff" /> <param name="wmode" value="transparent"/> <param name="flashvars" value="'+c()+'"/> <embed src="'+a._moviePath+b(a._moviePath)+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="100%" height="100%" name="global-zeroclipboard-flash-bridge" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+c()+'" scale="exactfit"> </embed> </object>';this.htmlBridge=document.createElement("div"),this.htmlBridge.id="global-zeroclipboard-html-bridge",this.htmlBridge.setAttribute("class","global-zeroclipboard-container"),this.htmlBridge.setAttribute("data-clipboard-ready",!1),this.htmlBridge.style.position="absolute",this.htmlBridge.style.left="-9999px",this.htmlBridge.style.top="-9999px",this.htmlBridge.style.width="15px",this.htmlBridge.style.height="15px",this.htmlBridge.style.zIndex="9999",this.htmlBridge.innerHTML=d,document.body.appendChild(this.htmlBridge),this.flashBridge=document["global-zeroclipboard-flash-bridge"]},a.Client.prototype.resetBridge=function(){this.htmlBridge.style.left="-9999px",this.htmlBridge.style.top="-9999px",this.htmlBridge.removeAttribute("title"),this.htmlBridge.removeAttribute("data-clipboard-text"),a.currentElement.removeClass("zeroclipboard-is-active"),delete a.currentElement},a.Client.prototype.ready=function(){var a=this.htmlBridge.getAttribute("data-clipboard-ready");return a==="true"||a===!0},a.Client.prototype.setCurrent=function(c){a.currentElement=c,this.reposition(),this.setText(this._text||c.getAttribute("data-clipboard-text")),c.getAttribute("title")&&this.setTitle(c.getAttribute("title")),b(c,"cursor")=="pointer"?this.setHandCursor(!0):this.setHandCursor(!1)},a.Client.prototype.reposition=function(){if(!a.currentElement)return!1;var b=d(a.currentElement);this.htmlBridge.style.top=b.top+"px",this.htmlBridge.style.left=b.left+"px",this.htmlBridge.style.width=b.width+"px",this.htmlBridge.style.height=b.height+"px",this.htmlBridge.style.zIndex=b.zIndex+1,this.setSize(b.width,b.height)},a.Client.prototype.setText=function(a){a&&a!==""&&(this._text=a,this.ready()&&this.flashBridge.setText(a))},a.Client.prototype.resetText=function(){this._text=null},a.Client.prototype.setTitle=function(a){a&&a!==""&&this.htmlBridge.setAttribute("title",a)},a.Client.prototype.setSize=function(a,b){this.ready()&&this.flashBridge.setSize(a,b)},a.Client.prototype.setHandCursor=function(a){this.ready()&&this.flashBridge.setHandCursor(a)},a.version="1.1.4",a._moviePath="ZeroClipboard.swf",a._client=null,a.setMoviePath=function(a){this._moviePath=a},a.setTrustedDomain=function(a){this._trustedDomain=a},a.destroy=function(){var b=a.$("#global-zeroclipboard-html-bridge");if(!b.length)return;delete a._client;var c=b[0];c.parentNode.removeChild(c)},a.detectFlashSupport=function(){var a=!1;try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash")&&(a=!0)}catch(b){navigator.mimeTypes["application/x-shockwave-flash"]&&(a=!0)}return a},a.dispatch=function(b,c){a._client.receiveEvent(b,c)},a.Client.prototype.on=function(b,c){var d=b.toString().split(/\s/g);for(var e=0;e<d.length;e++)b=d[e].toLowerCase().replace(/^on/,""),this.handlers[b]||(this.handlers[b]=[]),this.handlers[b].push(c);this.handlers.noflash&&!a.detectFlashSupport()&&this.receiveEvent("onNoFlash",null)},a.Client.prototype.addEventListener=function(a,b){this.on(a,b)},a.Client.prototype.receiveEvent=function(b,c){b=b.toString().toLowerCase().replace(/^on/,"");var d=a.currentElement;switch(b){case"load":if(c&&parseFloat(c.flashVersion.replace(",",".").replace(/[^0-9\.]/gi,""))<10){this.receiveEvent("onWrongFlash",{flashVersion:c.flashVersion});return}this.htmlBridge.setAttribute("data-clipboard-ready",!0);break;case"mouseover":d.addClass("zeroclipboard-is-hover");break;case"mouseout":d.removeClass("zeroclipboard-is-hover"),this.resetBridge();break;case"mousedown":d.addClass("zeroclipboard-is-active");break;case"mouseup":d.removeClass("zeroclipboard-is-active");break;case"complete":this.resetText()}if(this.handlers[b])for(var e=0,f=this.handlers[b].length;e<f;e++){var g=this.handlers[b][e];typeof g=="function"?g.call(d,this,c):typeof g=="string"&&window[g].call(d,this,c)}},a.Client.prototype.glue=function(b){function d(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent&&a.attachEvent("on"+b,c)}var e=a.$(b);for(var f=0;f<e.length;f++)d(e[f],"mouseover",c)},a.Client.prototype.unglue=function(b){function d(a,b,c){a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent&&a.detachEvent("on"+b,c)}var e=a.$(b);for(var f=0;f<e.length;f++)d(e[f],"mouseover",c)};var d=function(a){var c={left:0,top:0,width:a.width?a.width:a.offsetWidth,height:a.height?a.height:a.offsetHeight,zIndex:9999},d=b(a,"zIndex");d&&d!="auto"&&(c.zIndex=parseInt(d,10));while(a)c.left+=a.offsetLeft,c.left+=b(a,"borderLeftWidth")?parseInt(b(a,"borderLeftWidth"),10):0,c.top+=a.offsetTop,c.top+=b(a,"borderTopWidth")?parseInt(b(a,"borderTopWidth"),10):0,a=a.offsetParent;return c};a.$=function(a){var b=function(a,b){return b.querySelectorAll(a)},c;typeof Sizzle=="function"?b=function(a,b){return Sizzle.uniqueSort(Sizzle(a,b))}:typeof jQuery=="function"&&(b=function(a,b){return jQuery.unique(jQuery.find(a,b))}),typeof a=="string"&&(c=b(a,document),c.length===0&&(c=[document.getElementById(a)]));var d=[];for(var f=0;f<c.length;f++)c[f]!==null&&d.push(e(c[f]));return d},typeof module!="undefined"?module.exports=a:window.ZeroClipboard=a})();