Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing zeroclipboard for jslint

  • Loading branch information...
commit 9965e9541ffc75c764071740aacb9620aabb12db 1 parent 942097b
@jonrohan jonrohan authored
View
9 .jshintrc
@@ -0,0 +1,9 @@
+{
+ "camelcase": true,
+ "indent": 2,
+ "strict": true,
+ "trailing": true,
+ "boss": true,
+ "browser": true,
+ "node": true
+}
View
13 Makefile
@@ -6,6 +6,7 @@ JS_HINT = $(NODE_PATH)/jshint/bin/hint
all: \
node_modules \
+ clean \
ZeroClipboard.min.js \
LICENSE \
test \
@@ -13,18 +14,18 @@ all: \
node_modules: Makefile
npm install
+clean: Makefile
+ @rm -f ./ZeroClipboard*.js
+
LICENSE: Makefile
- @rm -f $@
@node src/build.js ./src/license.js $@
@chmod a-w $@
-ZeroClipboard.js: Makefile
- @rm -f $@
+ZeroClipboard.js: clean
@node src/build.js ./src/javascript/ZeroClipboard.js $@
@chmod a-w $@
ZeroClipboard.min.js: ZeroClipboard.js
- @rm -f $@
$(JS_COMPILER) ./ZeroClipboard.js > $@
@chmod a-w $@
@@ -42,4 +43,6 @@ testpage:
git commit -a -m "Update demo files to latest changes."
git push
git checkout master
- git stash pop
+ git stash pop
+
+.PHONY: all test clean
View
2  ZeroClipboard.min.js
@@ -4,4 +4,4 @@
// Author: Jon Rohan
// Author: James M. Greene
// License: MIT
-(function(){"use strict";var a;a={version:"1.0.8",clients:{},moviePath:"ZeroClipboard.swf",nextId:1,$:function(a){return typeof a=="string"&&(a=document.getElementById(a)),a.addClass||(a.hide=function(){this.style.display="none"},a.show=function(){this.style.display=""},a.addClass=function(a){this.removeClass(a),this.className+=" "+a},a.removeClass=function(a){var b=this.className.split(/\s+/),c=-1;for(var d=0;d<b.length;d++)b[d]==a&&(c=d,d=b.length);return c>-1&&(b.splice(c,1),this.className=b.join(" ")),this},a.hasClass=function(a){return!!this.className.match(new RegExp("\\s*"+a+"\\s*"))}),a},setMoviePath:function(a){this.moviePath=a},newClient:function(){return new a.Client},dispatch:function(a,b,c){var d=this.clients[a];d&&d.receiveEvent(b,c)},register:function(a,b){this.clients[a]=b},getDOMObjectPosition:function(a,b){var c={left:0,top:0,width:a.width?a.width:a.offsetWidth,height:a.height?a.height:a.offsetHeight};while(a&&a!=b)c.left+=a.offsetLeft,c.left+=a.style.borderLeftWidth?parseInt(a.style.borderLeftWidth):0,c.top+=a.offsetTop,c.top+=a.style.borderTopWidth?parseInt(a.style.borderTopWidth):0,a=a.offsetParent;return c},Client:function(b){this.handlers={},this.id=a.nextId++,this.movieId="ZeroClipboardMovie_"+this.id,a.register(this.id,this),b&&this.glue(b)}},a.Client.prototype={id:0,title:"",ready:!1,movie:null,clipText:"",handCursorEnabled:!0,cssEffects:!0,handlers:null,zIndex:99,glue:function(b,c,d){this.domElement=a.$(b),this.domElement.style.zIndex&&(this.zIndex=parseInt(this.domElement.style.zIndex,10)+1),!this.title&&this.domElement.getAttribute("title")!=null&&(this.title=this.domElement.getAttribute("title")),typeof c=="string"?c=a.$(c):typeof c=="undefined"&&(c=document.getElementsByTagName("body")[0]);var e=a.getDOMObjectPosition(this.domElement,c);this.div=document.createElement("div");var f=this.div.style;f.position="absolute",f.left=""+e.left+"px",f.top=""+e.top+"px",f.width=""+e.width+"px",f.height=""+e.height+"px",f.zIndex=this.zIndex;if(typeof d=="object")for(var g in d)f[g]=d[g];c.appendChild(this.div),this.div.innerHTML=this.getHTML(e.width,e.height)},getHTML:function(b,c){var d="",e="id="+this.id+"&width="+b+"&height="+c,f=this.title?' title="'+this.title+'"':"";if(navigator.userAgent.match(/MSIE/)){var g=location.href.match(/^https/i)?"https://":"http://";d+="<object"+f+' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+g+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+b+'" height="'+c+'" id="'+this.movieId+'"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+a.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="'+e+'"/><param name="wmode" value="transparent"/></object>'}else d+="<embed"+f+' id="'+this.movieId+'" src="'+a.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+b+'" height="'+c+'" name="'+this.movieId+'" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+e+'" wmode="transparent" />';return d},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(b){b&&(this.domElement=a.$(b),this.domElement||this.hide());if(this.domElement&&this.div){var c=a.getDOMObjectPosition(this.domElement),d=this.div.style;d.left=""+c.left+"px",d.top=""+c.top+"px"}},setText:function(a){this.clipText=a,this.ready&&this.movie.setText(a)},setTitle:function(a){this.title=a;if(this.div){var b=this.div.children;b.length&&b[0].setAttribute("title",this.title)}},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(a,b){a=a.toString().toLowerCase().replace(/^on/,"");switch(a){case"load":this.movie=document.getElementById(this.movieId);if(!this.movie){var c=this;setTimeout(function(){c.receiveEvent("load",null)},1);return}if(!this.ready&&navigator.userAgent.match(/Firefox/)&&navigator.userAgent.match(/Windows/)){var c=this;setTimeout(function(){c.receiveEvent("load",null)},100),this.ready=!0;return}this.ready=!0,this.movie.setText(this.clipText),this.movie.setHandCursor(this.handCursorEnabled);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[a])for(var d=0,e=this.handlers[a].length;d<e;d++){var f=this.handlers[a][d];typeof f=="function"?f(this,b):typeof f=="object"&&f.length==2?f[0][f[1]](this,b):typeof f=="string"&&window[f](this,b)}}},typeof module!="undefined"?module.exports=a:window.ZeroClipboard=a})();
+(function(){"use strict";var a;a={version:"1.0.8",clients:{},moviePath:"ZeroClipboard.swf",nextId:1,$:function(a){return typeof a=="string"&&(a=document.getElementById(a)),a.addClass||(a.hide=function(){this.style.display="none"},a.show=function(){this.style.display=""},a.addClass=function(a){this.removeClass(a),this.className+=" "+a},a.removeClass=function(a){var b=this.className.split(/\s+/),c=-1;for(var d=0;d<b.length;d++)b[d]==a&&(c=d,d=b.length);return c>-1&&(b.splice(c,1),this.className=b.join(" ")),this},a.hasClass=function(a){return!!this.className.match(new RegExp("\\s*"+a+"\\s*"))}),a},setMoviePath:function(a){this.moviePath=a},newClient:function(){return new a.Client},dispatch:function(a,b,c){var d=this.clients[a];d&&d.receiveEvent(b,c)},register:function(a,b){this.clients[a]=b},getDOMObjectPosition:function(a,b){var c={left:0,top:0,width:a.width?a.width:a.offsetWidth,height:a.height?a.height:a.offsetHeight};while(a&&a!=b)c.left+=a.offsetLeft,c.left+=a.style.borderLeftWidth?parseInt(a.style.borderLeftWidth,10):0,c.top+=a.offsetTop,c.top+=a.style.borderTopWidth?parseInt(a.style.borderTopWidth,10):0,a=a.offsetParent;return c},Client:function(b){this.handlers={},this.id=a.nextId++,this.movieId="ZeroClipboardMovie_"+this.id,a.register(this.id,this),b&&this.glue(b)}},a.Client.prototype={id:0,title:"",ready:!1,movie:null,clipText:"",handCursorEnabled:!0,cssEffects:!0,handlers:null,zIndex:99,glue:function(b,c,d){this.domElement=a.$(b),this.domElement.style.zIndex&&(this.zIndex=parseInt(this.domElement.style.zIndex,10)+1),!this.title&&this.domElement.getAttribute("title")!==null&&(this.title=this.domElement.getAttribute("title")),typeof c=="string"?c=a.$(c):typeof c=="undefined"&&(c=document.getElementsByTagName("body")[0]);var e=a.getDOMObjectPosition(this.domElement,c);this.div=document.createElement("div");var f=this.div.style;f.position="absolute",f.left=""+e.left+"px",f.top=""+e.top+"px",f.width=""+e.width+"px",f.height=""+e.height+"px",f.zIndex=this.zIndex;if(typeof d=="object")for(var g in d)f[g]=d[g];c.appendChild(this.div),this.div.innerHTML=this.getHTML(e.width,e.height)},getHTML:function(b,c){var d="",e="id="+this.id+"&width="+b+"&height="+c,f=this.title?' title="'+this.title+'"':"";if(navigator.userAgent.match(/MSIE/)){var g=location.href.match(/^https/i)?"https://":"http://";d+="<object"+f+' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+g+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+b+'" height="'+c+'" id="'+this.movieId+'"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+a.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="'+e+'"/><param name="wmode" value="transparent"/></object>'}else d+="<embed"+f+' id="'+this.movieId+'" src="'+a.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+b+'" height="'+c+'" name="'+this.movieId+'" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+e+'" wmode="transparent" />';return d},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(b){b&&(this.domElement=a.$(b),this.domElement||this.hide());if(this.domElement&&this.div){var c=a.getDOMObjectPosition(this.domElement),d=this.div.style;d.left=""+c.left+"px",d.top=""+c.top+"px"}},setText:function(a){this.clipText=a,this.ready&&this.movie.setText(a)},setTitle:function(a){this.title=a;if(this.div){var b=this.div.children;b.length&&b[0].setAttribute("title",this.title)}},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(a,b){a=a.toString().toLowerCase().replace(/^on/,"");switch(a){case"load":this.movie=document.getElementById(this.movieId);var c;if(!this.movie){c=this,setTimeout(function(){c.receiveEvent("load",null)},1);return}if(!this.ready&&navigator.userAgent.match(/Firefox/)&&navigator.userAgent.match(/Windows/)){c=this,setTimeout(function(){c.receiveEvent("load",null)},100),this.ready=!0;return}this.ready=!0,this.movie.setText(this.clipText),this.movie.setHandCursor(this.handCursorEnabled);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[a])for(var d=0,e=this.handlers[a].length;d<e;d++){var f=this.handlers[a][d];typeof f=="function"?f(this,b):typeof f=="object"&&f.length==2?f[0][f[1]](this,b):typeof f=="string"&&window[f](this,b)}}},typeof module!="undefined"?module.exports=a:window.ZeroClipboard=a})();
View
6 package.json
@@ -31,9 +31,9 @@
},
"devDependencies": {
"uglify-js": "1.2.3",
- "nodeunit": "latest",
- "jshint": "latest",
- "handlebars": "latest"
+ "nodeunit": "0.7.4",
+ "jshint": "0.9.1",
+ "handlebars": "1.0.7"
},
"component": {
"scripts": {
View
537 src/javascript/ZeroClipboard.js
@@ -3,288 +3,289 @@
//
{{#each contributors}}// Author: {{name}}
{{/each}}// License: {{license}}
-(function(){
-"use strict";
-var ZeroClipboard;
-ZeroClipboard = {
-
- version: "{{version}}",
- clients: {}, // registered upload clients on page, indexed by id
- moviePath: 'ZeroClipboard.swf', // URL to movie
- nextId: 1, // ID of next movie
-
- $: function(thingy) {
- // simple DOM lookup utility function
- if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
- if (!thingy.addClass) {
- // extend element with a few useful methods
- thingy.hide = function() { this.style.display = 'none'; };
- thingy.show = function() { this.style.display = ''; };
- thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
- thingy.removeClass = function(name) {
- var classes = this.className.split(/\s+/);
- var idx = -1;
- for (var k = 0; k < classes.length; k++) {
- if (classes[k] == name) { idx = k; k = classes.length; }
- }
- if (idx > -1) {
- classes.splice( idx, 1 );
- this.className = classes.join(' ');
- }
- return this;
- };
- thingy.hasClass = function(name) {
- return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
+(function () {
+ "use strict";
+ var ZeroClipboard;
+ ZeroClipboard = {
+
+ version: "{{version}}",
+ clients: {}, // registered upload clients on page, indexed by id
+ moviePath: 'ZeroClipboard.swf', // URL to movie
+ nextId: 1, // ID of next movie
+
+ $: function (thingy) {
+ // simple DOM lookup utility function
+ if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
+ if (!thingy.addClass) {
+ // extend element with a few useful methods
+ thingy.hide = function () { this.style.display = 'none'; };
+ thingy.show = function () { this.style.display = ''; };
+ thingy.addClass = function (name) { this.removeClass(name); this.className += ' ' + name; };
+ thingy.removeClass = function (name) {
+ var classes = this.className.split(/\s+/);
+ var idx = -1;
+ for (var k = 0; k < classes.length; k++) {
+ if (classes[k] == name) { idx = k; k = classes.length; }
+ }
+ if (idx > -1) {
+ classes.splice(idx, 1);
+ this.className = classes.join(' ');
+ }
+ return this;
+ };
+ thingy.hasClass = function (name) {
+ return !!this.className.match(new RegExp("\\s*" + name + "\\s*"));
+ };
+ }
+ return thingy;
+ },
+
+ setMoviePath: function (path) {
+ // set path to ZeroClipboard.swf
+ this.moviePath = path;
+ },
+
+ // use this method in JSNI calls to obtain a new Client instance
+ newClient: function () {
+ return new ZeroClipboard.Client();
+ },
+
+ dispatch: function (id, eventName, args) {
+ // receive event from flash movie, send to client
+ var client = this.clients[id];
+ if (client) {
+ client.receiveEvent(eventName, args);
+ }
+ },
+
+ register: function (id, client) {
+ // register new client to receive events
+ this.clients[id] = client;
+ },
+
+ getDOMObjectPosition: function (obj, stopObj) {
+ // get absolute coordinates for dom element
+ var info = {
+ left: 0,
+ top: 0,
+ width: obj.width ? obj.width : obj.offsetWidth,
+ height: obj.height ? obj.height : obj.offsetHeight
};
- }
- return thingy;
- },
-
- setMoviePath: function(path) {
- // set path to ZeroClipboard.swf
- this.moviePath = path;
- },
-
- // use this method in JSNI calls to obtain a new Client instance
- newClient: function() {
- return new ZeroClipboard.Client();
- },
-
- dispatch: function(id, eventName, args) {
- // receive event from flash movie, send to client
- var client = this.clients[id];
- if (client) {
- client.receiveEvent(eventName, args);
- }
- },
-
- register: function(id, client) {
- // register new client to receive events
- this.clients[id] = client;
- },
-
- getDOMObjectPosition: function(obj, stopObj) {
- // get absolute coordinates for dom element
- var info = {
- left: 0,
- top: 0,
- width: obj.width ? obj.width : obj.offsetWidth,
- height: obj.height ? obj.height : obj.offsetHeight
- };
-
- while (obj && (obj != stopObj)) {
- info.left += obj.offsetLeft;
- info.left += obj.style.borderLeftWidth ? parseInt(obj.style.borderLeftWidth) : 0;
- info.top += obj.offsetTop;
- info.top += obj.style.borderTopWidth ? parseInt(obj.style.borderTopWidth) : 0;
- obj = obj.offsetParent;
- }
- return info;
- },
+ while (obj && (obj != stopObj)) {
+ info.left += obj.offsetLeft;
+ info.left += obj.style.borderLeftWidth ? parseInt(obj.style.borderLeftWidth, 10) : 0;
+ info.top += obj.offsetTop;
+ info.top += obj.style.borderTopWidth ? parseInt(obj.style.borderTopWidth, 10) : 0;
+ obj = obj.offsetParent;
+ }
- Client: function(elem) {
- // constructor for new simple upload client
- this.handlers = {};
+ return info;
+ },
- // unique ID
- this.id = ZeroClipboard.nextId++;
- this.movieId = 'ZeroClipboardMovie_' + this.id;
+ Client: function (elem) {
+ // constructor for new simple upload client
+ this.handlers = {};
- // register client with singleton to receive flash events
- ZeroClipboard.register(this.id, this);
+ // unique ID
+ this.id = ZeroClipboard.nextId++;
+ this.movieId = 'ZeroClipboardMovie_' + this.id;
- // create movie
- if (elem) this.glue(elem);
- }
-};
-
-ZeroClipboard.Client.prototype = {
-
- id: 0, // unique ID for us
- title: "", // tooltip for the flash element
- ready: false, // whether movie is ready to receive events or not
- movie: null, // reference to movie object
- clipText: '', // text to copy to clipboard
- handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
- cssEffects: true, // enable CSS mouse effects on dom container
- handlers: null, // user event handlers
- zIndex: 99, // default zIndex of the movie object
-
- glue: function(elem, appendElem, stylesToAdd) {
- // glue to DOM element
- // elem can be ID or actual DOM element object
- this.domElement = ZeroClipboard.$(elem);
-
- // float just above object, or default zIndex if dom element isn't set
- if (this.domElement.style.zIndex) {
- this.zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
- }
+ // register client with singleton to receive flash events
+ ZeroClipboard.register(this.id, this);
- // check if the element has a title
- if (!this.title && this.domElement.getAttribute("title") != null) {
- this.title = this.domElement.getAttribute("title");
+ // create movie
+ if (elem) this.glue(elem);
}
+ };
+
+ ZeroClipboard.Client.prototype = {
+
+ id: 0, // unique ID for us
+ title: "", // tooltip for the flash element
+ ready: false, // whether movie is ready to receive events or not
+ movie: null, // reference to movie object
+ clipText: '', // text to copy to clipboard
+ handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
+ cssEffects: true, // enable CSS mouse effects on dom container
+ handlers: null, // user event handlers
+ zIndex: 99, // default zIndex of the movie object
+
+ glue: function (elem, appendElem, stylesToAdd) {
+ // glue to DOM element
+ // elem can be ID or actual DOM element object
+ this.domElement = ZeroClipboard.$(elem);
- if (typeof(appendElem) == 'string') {
- appendElem = ZeroClipboard.$(appendElem);
- }
- else if (typeof(appendElem) == 'undefined') {
- appendElem = document.getElementsByTagName('body')[0];
- }
+ // float just above object, or default zIndex if dom element isn't set
+ if (this.domElement.style.zIndex) {
+ this.zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
+ }
- // find X/Y position of domElement
- var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
-
- // create floating DIV above element
- this.div = document.createElement('div');
- var style = this.div.style;
- style.position = 'absolute';
- style.left = '' + box.left + 'px';
- style.top = '' + box.top + 'px';
- style.width = '' + box.width + 'px';
- style.height = '' + box.height + 'px';
- style.zIndex = this.zIndex;
-
- if (typeof(stylesToAdd) == 'object') {
- for (var addedStyle in stylesToAdd) {
- style[addedStyle] = stylesToAdd[addedStyle];
+ // check if the element has a title
+ if (!this.title && this.domElement.getAttribute("title") !== null) {
+ this.title = this.domElement.getAttribute("title");
}
- }
- // style.backgroundColor = '#f00'; // debug
+ if (typeof(appendElem) == 'string') {
+ appendElem = ZeroClipboard.$(appendElem);
+ }
+ else if (typeof(appendElem) == 'undefined') {
+ appendElem = document.getElementsByTagName('body')[0];
+ }
- appendElem.appendChild(this.div);
+ // find X/Y position of domElement
+ var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
- this.div.innerHTML = this.getHTML( box.width, box.height );
- },
+ // create floating DIV above element
+ this.div = document.createElement('div');
+ var style = this.div.style;
+ style.position = 'absolute';
+ style.left = '' + box.left + 'px';
+ style.top = '' + box.top + 'px';
+ style.width = '' + box.width + 'px';
+ style.height = '' + box.height + 'px';
+ style.zIndex = this.zIndex;
- getHTML: function(width, height) {
- // return HTML for movie
- var html = '';
- var flashvars = 'id=' + this.id +
- '&width=' + width +
- '&height=' + height,
- title = this.title ? ' title="' + this.title + '"' : '';
+ if (typeof(stylesToAdd) == 'object') {
+ for (var addedStyle in stylesToAdd) {
+ style[addedStyle] = stylesToAdd[addedStyle];
+ }
+ }
- if (navigator.userAgent.match(/MSIE/)) {
- // IE gets an OBJECT tag
- var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
- html += '<object' + title + ' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'"><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="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';
- }
- else {
- // all other browsers get an EMBED tag
- html += '<embed' + title + ' id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';
- }
- return html;
- },
+ // style.backgroundColor = '#f00'; // debug
- hide: function() {
- // temporarily hide floater offscreen
- if (this.div) {
- this.div.style.left = '-2000px';
- }
- },
+ appendElem.appendChild(this.div);
- show: function() {
- // show ourselves after a call to hide()
- this.reposition();
- },
+ this.div.innerHTML = this.getHTML(box.width, box.height);
+ },
- destroy: function() {
- // destroy control and floater
- if (this.domElement && this.div) {
- this.hide();
- this.div.innerHTML = '';
+ getHTML: function (width, height) {
+ // return HTML for movie
+ var html = '';
+ var flashvars = 'id=' + this.id +
+ '&width=' + width +
+ '&height=' + height,
+ title = this.title ? ' title="' + this.title + '"' : '';
- var body = document.getElementsByTagName('body')[0];
- try { body.removeChild( this.div ); } catch(e) {}
+ if (navigator.userAgent.match(/MSIE/)) {
+ // IE gets an OBJECT tag
+ var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
+ html += '<object' + title + ' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="' + protocol + 'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + width + '" height="' + height + '" id="' + this.movieId + '"><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="' + flashvars + '"/><param name="wmode" value="transparent"/></object>';
+ }
+ else {
+ // all other browsers get an EMBED tag
+ html += '<embed' + title + ' id="' + this.movieId + '" src="' + ZeroClipboard.moviePath + '" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="' + this.movieId + '" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="' + flashvars + '" wmode="transparent" />';
+ }
+ return html;
+ },
- this.domElement = null;
- this.div = null;
- }
- },
+ hide: function () {
+ // temporarily hide floater offscreen
+ if (this.div) {
+ this.div.style.left = '-2000px';
+ }
+ },
- reposition: function(elem) {
- // reposition our floating div, optionally to new container
- // warning: container CANNOT change size, only position
- if (elem) {
- this.domElement = ZeroClipboard.$(elem);
- if (!this.domElement) this.hide();
- }
+ show: function () {
+ // show ourselves after a call to hide()
+ this.reposition();
+ },
- if (this.domElement && this.div) {
- var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
- var style = this.div.style;
- style.left = '' + box.left + 'px';
- style.top = '' + box.top + 'px';
- }
- },
-
- setText: function(newText) {
- // set text to be copied to clipboard
- this.clipText = newText;
- if (this.ready) this.movie.setText(newText);
- },
-
- setTitle: function(newTitle) {
- // set title of flash element
- this.title = newTitle;
- // Update the already glued object if it exists.
- if (this.div) {
- var flashElems = this.div.children;
- if (flashElems.length) {
- flashElems[0].setAttribute('title', this.title);
+ destroy: function () {
+ // destroy control and floater
+ if (this.domElement && this.div) {
+ this.hide();
+ this.div.innerHTML = '';
+
+ var body = document.getElementsByTagName('body')[0];
+ try { body.removeChild(this.div); } catch (e) {}
+
+ this.domElement = null;
+ this.div = null;
}
- }
- },
-
- addEventListener: function(eventName, func) {
- // add user event listener for event
- // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
- eventName = eventName.toString().toLowerCase().replace(/^on/, '');
- if (!this.handlers[eventName]) this.handlers[eventName] = [];
- this.handlers[eventName].push(func);
- },
-
- setHandCursor: function(enabled) {
- // enable hand cursor (true), or default arrow cursor (false)
- this.handCursorEnabled = enabled;
- if (this.ready) this.movie.setHandCursor(enabled);
- },
-
- setCSSEffects: function(enabled) {
- // enable or disable CSS effects on DOM container
- this.cssEffects = !!enabled;
- },
-
- receiveEvent: function(eventName, args) {
- // receive event from flash
- eventName = eventName.toString().toLowerCase().replace(/^on/, '');
-
- // special behavior for certain events
- switch (eventName) {
+ },
+
+ reposition: function (elem) {
+ // reposition our floating div, optionally to new container
+ // warning: container CANNOT change size, only position
+ if (elem) {
+ this.domElement = ZeroClipboard.$(elem);
+ if (!this.domElement) this.hide();
+ }
+
+ if (this.domElement && this.div) {
+ var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
+ var style = this.div.style;
+ style.left = '' + box.left + 'px';
+ style.top = '' + box.top + 'px';
+ }
+ },
+
+ setText: function (newText) {
+ // set text to be copied to clipboard
+ this.clipText = newText;
+ if (this.ready) this.movie.setText(newText);
+ },
+
+ setTitle: function (newTitle) {
+ // set title of flash element
+ this.title = newTitle;
+ // Update the already glued object if it exists.
+ if (this.div) {
+ var flashElems = this.div.children;
+ if (flashElems.length) {
+ flashElems[0].setAttribute('title', this.title);
+ }
+ }
+ },
+
+ addEventListener: function (eventName, func) {
+ // add user event listener for event
+ // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
+ eventName = eventName.toString().toLowerCase().replace(/^on/, '');
+ if (!this.handlers[eventName]) this.handlers[eventName] = [];
+ this.handlers[eventName].push(func);
+ },
+
+ setHandCursor: function (enabled) {
+ // enable hand cursor (true), or default arrow cursor (false)
+ this.handCursorEnabled = enabled;
+ if (this.ready) this.movie.setHandCursor(enabled);
+ },
+
+ setCSSEffects: function (enabled) {
+ // enable or disable CSS effects on DOM container
+ this.cssEffects = !!enabled;
+ },
+
+ receiveEvent: function (eventName, args) {
+ // receive event from flash
+ eventName = eventName.toString().toLowerCase().replace(/^on/, '');
+
+ // special behavior for certain events
+ switch (eventName) {
case 'load':
// movie claims it is ready, but in IE this isn't always the case...
// bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
this.movie = document.getElementById(this.movieId);
+ var self;
if (!this.movie) {
- var self = this;
- setTimeout( function() { self.receiveEvent('load', null); }, 1 );
+ self = this;
+ setTimeout(function () { self.receiveEvent('load', null); }, 1);
return;
}
// firefox on pc needs a "kick" in order to set these in certain cases
if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
- var self = this;
- setTimeout( function() { self.receiveEvent('load', null); }, 100 );
+ self = this;
+ setTimeout(function () { self.receiveEvent('load', null); }, 100);
this.ready = true;
return;
}
this.ready = true;
- this.movie.setText( this.clipText );
- this.movie.setHandCursor( this.handCursorEnabled );
+ this.movie.setText(this.clipText);
+ this.movie.setHandCursor(this.handCursorEnabled);
break;
case 'mouseover':
@@ -317,34 +318,34 @@ ZeroClipboard.Client.prototype = {
this.recoverActive = false;
}
break;
- } // switch eventName
+ } // switch eventName
- if (this.handlers[eventName]) {
- for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
- var func = this.handlers[eventName][idx];
+ if (this.handlers[eventName]) {
+ for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
+ var func = this.handlers[eventName][idx];
- if (typeof(func) == 'function') {
- // actual function reference
- func(this, args);
- }
- else if ((typeof(func) == 'object') && (func.length == 2)) {
- // PHP style object + method, i.e. [myObject, 'myMethod']
- func[0][ func[1] ](this, args);
- }
- else if (typeof(func) == 'string') {
- // name of function
- window[func](this, args);
- }
- } // foreach event handler defined
- } // user defined handler for event
- }
+ if (typeof(func) == 'function') {
+ // actual function reference
+ func(this, args);
+ }
+ else if ((typeof(func) == 'object') && (func.length == 2)) {
+ // PHP style object + method, i.e. [myObject, 'myMethod']
+ func[0][func[1]](this, args);
+ }
+ else if (typeof(func) == 'string') {
+ // name of function
+ window[func](this, args);
+ }
+ } // foreach event handler defined
+ } // user defined handler for event
+ }
-};
+ };
-if (typeof module !== "undefined") {
- module.exports = ZeroClipboard;
-} else {
- window.ZeroClipboard = ZeroClipboard;
-}
+ if (typeof module !== "undefined") {
+ module.exports = ZeroClipboard;
+ } else {
+ window.ZeroClipboard = ZeroClipboard;
+ }
})();
View
537 zeroclipboard.js
@@ -4,288 +4,289 @@
// Author: Jon Rohan
// Author: James M. Greene
// License: MIT
-(function(){
-"use strict";
-var ZeroClipboard;
-ZeroClipboard = {
-
- version: "1.0.8",
- clients: {}, // registered upload clients on page, indexed by id
- moviePath: 'ZeroClipboard.swf', // URL to movie
- nextId: 1, // ID of next movie
-
- $: function(thingy) {
- // simple DOM lookup utility function
- if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
- if (!thingy.addClass) {
- // extend element with a few useful methods
- thingy.hide = function() { this.style.display = 'none'; };
- thingy.show = function() { this.style.display = ''; };
- thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
- thingy.removeClass = function(name) {
- var classes = this.className.split(/\s+/);
- var idx = -1;
- for (var k = 0; k < classes.length; k++) {
- if (classes[k] == name) { idx = k; k = classes.length; }
- }
- if (idx > -1) {
- classes.splice( idx, 1 );
- this.className = classes.join(' ');
- }
- return this;
- };
- thingy.hasClass = function(name) {
- return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
+(function () {
+ "use strict";
+ var ZeroClipboard;
+ ZeroClipboard = {
+
+ version: "1.0.8",
+ clients: {}, // registered upload clients on page, indexed by id
+ moviePath: 'ZeroClipboard.swf', // URL to movie
+ nextId: 1, // ID of next movie
+
+ $: function (thingy) {
+ // simple DOM lookup utility function
+ if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
+ if (!thingy.addClass) {
+ // extend element with a few useful methods
+ thingy.hide = function () { this.style.display = 'none'; };
+ thingy.show = function () { this.style.display = ''; };
+ thingy.addClass = function (name) { this.removeClass(name); this.className += ' ' + name; };
+ thingy.removeClass = function (name) {
+ var classes = this.className.split(/\s+/);
+ var idx = -1;
+ for (var k = 0; k < classes.length; k++) {
+ if (classes[k] == name) { idx = k; k = classes.length; }
+ }
+ if (idx > -1) {
+ classes.splice(idx, 1);
+ this.className = classes.join(' ');
+ }
+ return this;
+ };
+ thingy.hasClass = function (name) {
+ return !!this.className.match(new RegExp("\\s*" + name + "\\s*"));
+ };
+ }
+ return thingy;
+ },
+
+ setMoviePath: function (path) {
+ // set path to ZeroClipboard.swf
+ this.moviePath = path;
+ },
+
+ // use this method in JSNI calls to obtain a new Client instance
+ newClient: function () {
+ return new ZeroClipboard.Client();
+ },
+
+ dispatch: function (id, eventName, args) {
+ // receive event from flash movie, send to client
+ var client = this.clients[id];
+ if (client) {
+ client.receiveEvent(eventName, args);
+ }
+ },
+
+ register: function (id, client) {
+ // register new client to receive events
+ this.clients[id] = client;
+ },
+
+ getDOMObjectPosition: function (obj, stopObj) {
+ // get absolute coordinates for dom element
+ var info = {
+ left: 0,
+ top: 0,
+ width: obj.width ? obj.width : obj.offsetWidth,
+ height: obj.height ? obj.height : obj.offsetHeight
};
- }
- return thingy;
- },
-
- setMoviePath: function(path) {
- // set path to ZeroClipboard.swf
- this.moviePath = path;
- },
-
- // use this method in JSNI calls to obtain a new Client instance
- newClient: function() {
- return new ZeroClipboard.Client();
- },
-
- dispatch: function(id, eventName, args) {
- // receive event from flash movie, send to client
- var client = this.clients[id];
- if (client) {
- client.receiveEvent(eventName, args);
- }
- },
-
- register: function(id, client) {
- // register new client to receive events
- this.clients[id] = client;
- },
-
- getDOMObjectPosition: function(obj, stopObj) {
- // get absolute coordinates for dom element
- var info = {
- left: 0,
- top: 0,
- width: obj.width ? obj.width : obj.offsetWidth,
- height: obj.height ? obj.height : obj.offsetHeight
- };
-
- while (obj && (obj != stopObj)) {
- info.left += obj.offsetLeft;
- info.left += obj.style.borderLeftWidth ? parseInt(obj.style.borderLeftWidth) : 0;
- info.top += obj.offsetTop;
- info.top += obj.style.borderTopWidth ? parseInt(obj.style.borderTopWidth) : 0;
- obj = obj.offsetParent;
- }
- return info;
- },
+ while (obj && (obj != stopObj)) {
+ info.left += obj.offsetLeft;
+ info.left += obj.style.borderLeftWidth ? parseInt(obj.style.borderLeftWidth, 10) : 0;
+ info.top += obj.offsetTop;
+ info.top += obj.style.borderTopWidth ? parseInt(obj.style.borderTopWidth, 10) : 0;
+ obj = obj.offsetParent;
+ }
- Client: function(elem) {
- // constructor for new simple upload client
- this.handlers = {};
+ return info;
+ },
- // unique ID
- this.id = ZeroClipboard.nextId++;
- this.movieId = 'ZeroClipboardMovie_' + this.id;
+ Client: function (elem) {
+ // constructor for new simple upload client
+ this.handlers = {};
- // register client with singleton to receive flash events
- ZeroClipboard.register(this.id, this);
+ // unique ID
+ this.id = ZeroClipboard.nextId++;
+ this.movieId = 'ZeroClipboardMovie_' + this.id;
- // create movie
- if (elem) this.glue(elem);
- }
-};
-
-ZeroClipboard.Client.prototype = {
-
- id: 0, // unique ID for us
- title: "", // tooltip for the flash element
- ready: false, // whether movie is ready to receive events or not
- movie: null, // reference to movie object
- clipText: '', // text to copy to clipboard
- handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
- cssEffects: true, // enable CSS mouse effects on dom container
- handlers: null, // user event handlers
- zIndex: 99, // default zIndex of the movie object
-
- glue: function(elem, appendElem, stylesToAdd) {
- // glue to DOM element
- // elem can be ID or actual DOM element object
- this.domElement = ZeroClipboard.$(elem);
-
- // float just above object, or default zIndex if dom element isn't set
- if (this.domElement.style.zIndex) {
- this.zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
- }
+ // register client with singleton to receive flash events
+ ZeroClipboard.register(this.id, this);
- // check if the element has a title
- if (!this.title && this.domElement.getAttribute("title") != null) {
- this.title = this.domElement.getAttribute("title");
+ // create movie
+ if (elem) this.glue(elem);
}
+ };
+
+ ZeroClipboard.Client.prototype = {
+
+ id: 0, // unique ID for us
+ title: "", // tooltip for the flash element
+ ready: false, // whether movie is ready to receive events or not
+ movie: null, // reference to movie object
+ clipText: '', // text to copy to clipboard
+ handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
+ cssEffects: true, // enable CSS mouse effects on dom container
+ handlers: null, // user event handlers
+ zIndex: 99, // default zIndex of the movie object
+
+ glue: function (elem, appendElem, stylesToAdd) {
+ // glue to DOM element
+ // elem can be ID or actual DOM element object
+ this.domElement = ZeroClipboard.$(elem);
- if (typeof(appendElem) == 'string') {
- appendElem = ZeroClipboard.$(appendElem);
- }
- else if (typeof(appendElem) == 'undefined') {
- appendElem = document.getElementsByTagName('body')[0];
- }
+ // float just above object, or default zIndex if dom element isn't set
+ if (this.domElement.style.zIndex) {
+ this.zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
+ }
- // find X/Y position of domElement
- var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
-
- // create floating DIV above element
- this.div = document.createElement('div');
- var style = this.div.style;
- style.position = 'absolute';
- style.left = '' + box.left + 'px';
- style.top = '' + box.top + 'px';
- style.width = '' + box.width + 'px';
- style.height = '' + box.height + 'px';
- style.zIndex = this.zIndex;
-
- if (typeof(stylesToAdd) == 'object') {
- for (var addedStyle in stylesToAdd) {
- style[addedStyle] = stylesToAdd[addedStyle];
+ // check if the element has a title
+ if (!this.title && this.domElement.getAttribute("title") !== null) {
+ this.title = this.domElement.getAttribute("title");
}
- }
- // style.backgroundColor = '#f00'; // debug
+ if (typeof(appendElem) == 'string') {
+ appendElem = ZeroClipboard.$(appendElem);
+ }
+ else if (typeof(appendElem) == 'undefined') {
+ appendElem = document.getElementsByTagName('body')[0];
+ }
- appendElem.appendChild(this.div);
+ // find X/Y position of domElement
+ var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
- this.div.innerHTML = this.getHTML( box.width, box.height );
- },
+ // create floating DIV above element
+ this.div = document.createElement('div');
+ var style = this.div.style;
+ style.position = 'absolute';
+ style.left = '' + box.left + 'px';
+ style.top = '' + box.top + 'px';
+ style.width = '' + box.width + 'px';
+ style.height = '' + box.height + 'px';
+ style.zIndex = this.zIndex;
- getHTML: function(width, height) {
- // return HTML for movie
- var html = '';
- var flashvars = 'id=' + this.id +
- '&width=' + width +
- '&height=' + height,
- title = this.title ? ' title="' + this.title + '"' : '';
+ if (typeof(stylesToAdd) == 'object') {
+ for (var addedStyle in stylesToAdd) {
+ style[addedStyle] = stylesToAdd[addedStyle];
+ }
+ }
- if (navigator.userAgent.match(/MSIE/)) {
- // IE gets an OBJECT tag
- var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
- html += '<object' + title + ' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'"><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="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';
- }
- else {
- // all other browsers get an EMBED tag
- html += '<embed' + title + ' id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';
- }
- return html;
- },
+ // style.backgroundColor = '#f00'; // debug
- hide: function() {
- // temporarily hide floater offscreen
- if (this.div) {
- this.div.style.left = '-2000px';
- }
- },
+ appendElem.appendChild(this.div);
- show: function() {
- // show ourselves after a call to hide()
- this.reposition();
- },
+ this.div.innerHTML = this.getHTML(box.width, box.height);
+ },
- destroy: function() {
- // destroy control and floater
- if (this.domElement && this.div) {
- this.hide();
- this.div.innerHTML = '';
+ getHTML: function (width, height) {
+ // return HTML for movie
+ var html = '';
+ var flashvars = 'id=' + this.id +
+ '&width=' + width +
+ '&height=' + height,
+ title = this.title ? ' title="' + this.title + '"' : '';
- var body = document.getElementsByTagName('body')[0];
- try { body.removeChild( this.div ); } catch(e) {}
+ if (navigator.userAgent.match(/MSIE/)) {
+ // IE gets an OBJECT tag
+ var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
+ html += '<object' + title + ' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="' + protocol + 'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + width + '" height="' + height + '" id="' + this.movieId + '"><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="' + flashvars + '"/><param name="wmode" value="transparent"/></object>';
+ }
+ else {
+ // all other browsers get an EMBED tag
+ html += '<embed' + title + ' id="' + this.movieId + '" src="' + ZeroClipboard.moviePath + '" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="' + this.movieId + '" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="' + flashvars + '" wmode="transparent" />';
+ }
+ return html;
+ },
- this.domElement = null;
- this.div = null;
- }
- },
+ hide: function () {
+ // temporarily hide floater offscreen
+ if (this.div) {
+ this.div.style.left = '-2000px';
+ }
+ },
- reposition: function(elem) {
- // reposition our floating div, optionally to new container
- // warning: container CANNOT change size, only position
- if (elem) {
- this.domElement = ZeroClipboard.$(elem);
- if (!this.domElement) this.hide();
- }
+ show: function () {
+ // show ourselves after a call to hide()
+ this.reposition();
+ },
- if (this.domElement && this.div) {
- var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
- var style = this.div.style;
- style.left = '' + box.left + 'px';
- style.top = '' + box.top + 'px';
- }
- },
-
- setText: function(newText) {
- // set text to be copied to clipboard
- this.clipText = newText;
- if (this.ready) this.movie.setText(newText);
- },
-
- setTitle: function(newTitle) {
- // set title of flash element
- this.title = newTitle;
- // Update the already glued object if it exists.
- if (this.div) {
- var flashElems = this.div.children;
- if (flashElems.length) {
- flashElems[0].setAttribute('title', this.title);
+ destroy: function () {
+ // destroy control and floater
+ if (this.domElement && this.div) {
+ this.hide();
+ this.div.innerHTML = '';
+
+ var body = document.getElementsByTagName('body')[0];
+ try { body.removeChild(this.div); } catch (e) {}
+
+ this.domElement = null;
+ this.div = null;
}
- }
- },
-
- addEventListener: function(eventName, func) {
- // add user event listener for event
- // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
- eventName = eventName.toString().toLowerCase().replace(/^on/, '');
- if (!this.handlers[eventName]) this.handlers[eventName] = [];
- this.handlers[eventName].push(func);
- },
-
- setHandCursor: function(enabled) {
- // enable hand cursor (true), or default arrow cursor (false)
- this.handCursorEnabled = enabled;
- if (this.ready) this.movie.setHandCursor(enabled);
- },
-
- setCSSEffects: function(enabled) {
- // enable or disable CSS effects on DOM container
- this.cssEffects = !!enabled;
- },
-
- receiveEvent: function(eventName, args) {
- // receive event from flash
- eventName = eventName.toString().toLowerCase().replace(/^on/, '');
-
- // special behavior for certain events
- switch (eventName) {
+ },
+
+ reposition: function (elem) {
+ // reposition our floating div, optionally to new container
+ // warning: container CANNOT change size, only position
+ if (elem) {
+ this.domElement = ZeroClipboard.$(elem);
+ if (!this.domElement) this.hide();
+ }
+
+ if (this.domElement && this.div) {
+ var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
+ var style = this.div.style;
+ style.left = '' + box.left + 'px';
+ style.top = '' + box.top + 'px';
+ }
+ },
+
+ setText: function (newText) {
+ // set text to be copied to clipboard
+ this.clipText = newText;
+ if (this.ready) this.movie.setText(newText);
+ },
+
+ setTitle: function (newTitle) {
+ // set title of flash element
+ this.title = newTitle;
+ // Update the already glued object if it exists.
+ if (this.div) {
+ var flashElems = this.div.children;
+ if (flashElems.length) {
+ flashElems[0].setAttribute('title', this.title);
+ }
+ }
+ },
+
+ addEventListener: function (eventName, func) {
+ // add user event listener for event
+ // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
+ eventName = eventName.toString().toLowerCase().replace(/^on/, '');
+ if (!this.handlers[eventName]) this.handlers[eventName] = [];
+ this.handlers[eventName].push(func);
+ },
+
+ setHandCursor: function (enabled) {
+ // enable hand cursor (true), or default arrow cursor (false)
+ this.handCursorEnabled = enabled;
+ if (this.ready) this.movie.setHandCursor(enabled);
+ },
+
+ setCSSEffects: function (enabled) {
+ // enable or disable CSS effects on DOM container
+ this.cssEffects = !!enabled;
+ },
+
+ receiveEvent: function (eventName, args) {
+ // receive event from flash
+ eventName = eventName.toString().toLowerCase().replace(/^on/, '');
+
+ // special behavior for certain events
+ switch (eventName) {
case 'load':
// movie claims it is ready, but in IE this isn't always the case...
// bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
this.movie = document.getElementById(this.movieId);
+ var self;
if (!this.movie) {
- var self = this;
- setTimeout( function() { self.receiveEvent('load', null); }, 1 );
+ self = this;
+ setTimeout(function () { self.receiveEvent('load', null); }, 1);
return;
}
// firefox on pc needs a "kick" in order to set these in certain cases
if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
- var self = this;
- setTimeout( function() { self.receiveEvent('load', null); }, 100 );
+ self = this;
+ setTimeout(function () { self.receiveEvent('load', null); }, 100);
this.ready = true;
return;
}
this.ready = true;
- this.movie.setText( this.clipText );
- this.movie.setHandCursor( this.handCursorEnabled );
+ this.movie.setText(this.clipText);
+ this.movie.setHandCursor(this.handCursorEnabled);
break;
case 'mouseover':
@@ -318,34 +319,34 @@ ZeroClipboard.Client.prototype = {
this.recoverActive = false;
}
break;
- } // switch eventName
+ } // switch eventName
- if (this.handlers[eventName]) {
- for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
- var func = this.handlers[eventName][idx];
+ if (this.handlers[eventName]) {
+ for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
+ var func = this.handlers[eventName][idx];
- if (typeof(func) == 'function') {
- // actual function reference
- func(this, args);
- }
- else if ((typeof(func) == 'object') && (func.length == 2)) {
- // PHP style object + method, i.e. [myObject, 'myMethod']
- func[0][ func[1] ](this, args);
- }
- else if (typeof(func) == 'string') {
- // name of function
- window[func](this, args);
- }
- } // foreach event handler defined
- } // user defined handler for event
- }
+ if (typeof(func) == 'function') {
+ // actual function reference
+ func(this, args);
+ }
+ else if ((typeof(func) == 'object') && (func.length == 2)) {
+ // PHP style object + method, i.e. [myObject, 'myMethod']
+ func[0][func[1]](this, args);
+ }
+ else if (typeof(func) == 'string') {
+ // name of function
+ window[func](this, args);
+ }
+ } // foreach event handler defined
+ } // user defined handler for event
+ }
-};
+ };
-if (typeof module !== "undefined") {
- module.exports = ZeroClipboard;
-} else {
- window.ZeroClipboard = ZeroClipboard;
-}
+ if (typeof module !== "undefined") {
+ module.exports = ZeroClipboard;
+ } else {
+ window.ZeroClipboard = ZeroClipboard;
+ }
})();
Please sign in to comment.
Something went wrong with that request. Please try again.