Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Created an '_extend' utility method

  • Loading branch information...
commit 8d620fd8dc27f7fad981aaf8f37dd959b928a3cc 1 parent e9cae00
@JamesMGreene JamesMGreene authored
View
14 .jshintrc
@@ -1,11 +1,13 @@
{
- "camelcase": true,
- "indent": 2,
- "strict": false,
- "trailing": true,
"boss": true,
"browser": true,
- "multistr": true,
+ "camelcase": true,
+ "eqeqeq": true,
+ "eqnull": true,
"es3": true,
- "es5": false
+ "es5": false,
+ "indent": 2,
+ "multistr": true,
+ "strict": false,
+ "trailing": true
}
View
2  Gruntfile.js
@@ -1,5 +1,7 @@
/*jshint -W106 */
+/*jshint node:true */
module.exports = function(grunt) {
+ 'use strict';
// Metadata
var pkg = grunt.file.readJSON('package.json');
View
33 ZeroClipboard.js
@@ -251,13 +251,31 @@
}
}
};
+ var _extend = function() {
+ var i, len, arg, prop, src, copy, target = arguments[0] || {};
+ for (i = 1, len = arguments.length; i < len; i++) {
+ if ((arg = arguments[i]) != null) {
+ for (prop in arg) {
+ if (arg.hasOwnProperty(prop)) {
+ src = target[prop];
+ copy = arg[prop];
+ if (target === copy) {
+ continue;
+ }
+ if (copy !== undefined) {
+ target[prop] = copy;
+ }
+ }
+ }
+ }
+ }
+ return target;
+ };
var ZeroClipboard = function(elements, options) {
if (elements) (ZeroClipboard.prototype._singleton || this).glue(elements);
if (ZeroClipboard.prototype._singleton) return ZeroClipboard.prototype._singleton;
ZeroClipboard.prototype._singleton = this;
- this.options = {};
- for (var kd in _defaults) this.options[kd] = _defaults[kd];
- for (var ko in options) this.options[ko] = options[ko];
+ this.options = _extend({}, _defaults, options);
this.handlers = {};
if (typeof flashState.global.noflash !== "boolean") {
flashState.global.noflash = !_detectFlashSupport();
@@ -332,7 +350,7 @@
debug: true
};
ZeroClipboard.setDefaults = function(options) {
- for (var ko in options) _defaults[ko] = options[ko];
+ _extend(_defaults, options);
};
ZeroClipboard.destroy = function() {
if (ZeroClipboard.prototype._singleton) {
@@ -351,8 +369,7 @@
var client = ZeroClipboard.prototype._singleton;
var container = document.getElementById("global-zeroclipboard-html-bridge");
if (!container) {
- var opts = {};
- for (var ko in client.options) opts[ko] = client.options[ko];
+ var opts = _extend({}, client.options);
opts.amdModuleId = _amdModuleId;
opts.cjsModuleId = _cjsModuleId;
var flashvars = _vars(opts);
@@ -527,7 +544,7 @@
elements = _prepGlue(elements);
for (var i = 0; i < elements.length; i++) {
if (elements[i] && elements[i].nodeType === 1) {
- if (_inArray(elements[i], gluedElements) == -1) {
+ if (_inArray(elements[i], gluedElements) === -1) {
gluedElements.push(elements[i]);
_addEventHandler(elements[i], "mouseover", _elementMouseOver);
}
@@ -540,7 +557,7 @@
for (var i = 0; i < elements.length; i++) {
_removeEventHandler(elements[i], "mouseover", _elementMouseOver);
var arrayIndex = _inArray(elements[i], gluedElements);
- if (arrayIndex != -1) gluedElements.splice(arrayIndex, 1);
+ if (arrayIndex !== -1) gluedElements.splice(arrayIndex, 1);
}
return this;
};
View
2  ZeroClipboard.min.js
@@ -6,4 +6,4 @@
* http://zeroclipboard.org/
* v1.2.3
*/
-!function(){"use strict";function a(a){return parseFloat(a.replace(/,/g,".").replace(/[^0-9\.]/g,""))>=10}var b,c=[],d={global:{noflash:null,wrongflash:null,version:"0.0.0"},clients:{}},e=function(){var a=/\-([a-z])/g,b=function(a,b){return b.toUpperCase()};return function(c){return c.replace(a,b)}}(),f=function(a,b){var c,d,f,g,h,i;if(window.getComputedStyle?c=window.getComputedStyle(a,null).getPropertyValue(b):(d=e(b),c=a.currentStyle?a.currentStyle[d]:a.style[d]),"cursor"===b&&(!c||"auto"===c))for(f=a.tagName.toLowerCase(),g=["a"],h=0,i=g.length;i>h;h++)if(f===g[h])return"pointer";return c},g=function(a){if(u.prototype._singleton){a||(a=window.event);var b;this!==window?b=this:a.target?b=a.target:a.srcElement&&(b=a.srcElement),u.prototype._singleton.setCurrent(b)}},h=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent&&a.attachEvent("on"+b,c)},i=function(a,b,c){a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent&&a.detachEvent("on"+b,c)},j=function(a,b){if(a.addClass)return a.addClass(b),a;if(b&&"string"==typeof b){var c=(b||"").split(/\s+/);if(1===a.nodeType)if(a.className){for(var d=" "+a.className+" ",e=a.className,f=0,g=c.length;g>f;f++)d.indexOf(" "+c[f]+" ")<0&&(e+=" "+c[f]);a.className=e.replace(/^\s+|\s+$/g,"")}else a.className=b}return a},k=function(a,b){if(a.removeClass)return a.removeClass(b),a;if(b&&"string"==typeof b||void 0===b){var c=(b||"").split(/\s+/);if(1===a.nodeType&&a.className)if(b){for(var d=(" "+a.className+" ").replace(/[\n\t]/g," "),e=0,f=c.length;f>e;e++)d=d.replace(" "+c[e]+" "," ");a.className=d.replace(/^\s+|\s+$/g,"")}else a.className=""}return a},l=function(){var a,b,c,d=1;return"function"==typeof document.body.getBoundingClientRect&&(a=document.body.getBoundingClientRect(),b=a.right-a.left,c=document.body.offsetWidth,d=Math.round(b/c*100)/100),d},m=function(a,b){var c={left:0,top:0,width:0,height:0,zIndex:s(b)-1};if(a.getBoundingClientRect){var d,e,f,g=a.getBoundingClientRect();"pageXOffset"in window&&"pageYOffset"in window?(d=window.pageXOffset,e=window.pageYOffset):(f=l(),d=Math.round(document.documentElement.scrollLeft/f),e=Math.round(document.documentElement.scrollTop/f));var h=document.documentElement.clientLeft||0,i=document.documentElement.clientTop||0;c.left=g.left+d-h,c.top=g.top+e-i,c.width="width"in g?g.width:g.right-g.left,c.height="height"in g?g.height:g.bottom-g.top}return c},n=function(a,b){var c=!(b&&b.useNoCache===!1);return c?(-1===a.indexOf("?")?"?":"&")+"nocache="+(new Date).getTime():""},o=function(a){var b=[],c=[];return a.trustedOrigins&&("string"==typeof a.trustedOrigins?c.push(a.trustedOrigins):"object"==typeof a.trustedOrigins&&"length"in a.trustedOrigins&&(c=c.concat(a.trustedOrigins))),a.trustedDomains&&("string"==typeof a.trustedDomains?c.push(a.trustedDomains):"object"==typeof a.trustedDomains&&"length"in a.trustedDomains&&(c=c.concat(a.trustedDomains))),c.length&&b.push("trustedOrigins="+encodeURIComponent(c.join(","))),"string"==typeof a.amdModuleId&&a.amdModuleId&&b.push("amdModuleId="+encodeURIComponent(a.amdModuleId)),"string"==typeof a.cjsModuleId&&a.cjsModuleId&&b.push("cjsModuleId="+encodeURIComponent(a.cjsModuleId)),b.join("&")},p=function(a,b){if(b.indexOf)return b.indexOf(a);for(var c=0,d=b.length;d>c;c++)if(b[c]===a)return c;return-1},q=function(a){if("string"==typeof a)throw new TypeError("ZeroClipboard doesn't accept query strings.");return a.length?a:[a]},r=function(a,b,c,d,e){e?window.setTimeout(function(){a.call(b,c,d)},0):a.call(b,c,d)},s=function(a){var b,c;return a&&("number"==typeof a&&a>0?b=a:"string"==typeof a&&(c=parseInt(a,10))&&!isNaN(c)&&c>0&&(b=c)),b||("number"==typeof x.zIndex&&x.zIndex>0?b=x.zIndex:"string"==typeof x.zIndex&&(c=parseInt(x.zIndex,10))&&!isNaN(c)&&c>0&&(b=c)),b||0},t=function(a,b){if(a&&b!==!1&&"undefined"!=typeof console&&console&&(console.warn||console.log)){var c="`"+a+"` is deprecated. See docs for more info:\n https://github.com/zeroclipboard/zeroclipboard/blob/master/docs/instructions.md#deprecations";console.warn?console.warn(c):console.log(c)}},u=function(a,b){if(a&&(u.prototype._singleton||this).glue(a),u.prototype._singleton)return u.prototype._singleton;u.prototype._singleton=this,this.options={};for(var c in x)this.options[c]=x[c];for(var e in b)this.options[e]=b[e];this.handlers={},"boolean"!=typeof d.global.noflash&&(d.global.noflash=!w()),d.clients.hasOwnProperty(this.options.moviePath)||(d.clients[this.options.moviePath]={ready:!1}),d.global.noflash===!1&&A()};u.prototype.setCurrent=function(a){b=a,B.call(this);var c=a.getAttribute("title");c&&this.setTitle(c);var d=this.options.forceHandCursor===!0||"pointer"===f(a,"cursor");return v.call(this,d),this},u.prototype.setText=function(a){return a&&""!==a&&(this.options.text=a,this.ready()&&this.flashBridge.setText(a)),this},u.prototype.setTitle=function(a){return a&&""!==a&&this.htmlBridge.setAttribute("title",a),this},u.prototype.setSize=function(a,b){return this.ready()&&this.flashBridge.setSize(a,b),this};var v=function(a){this.ready()&&this.flashBridge.setHandCursor(a)},w=function(){var a=!1;if("boolean"==typeof d.global.noflash)a=d.global.noflash===!1;else{if("function"==typeof ActiveXObject)try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash")&&(a=!0)}catch(b){}!a&&navigator.mimeTypes["application/x-shockwave-flash"]&&(a=!0)}return a};u.version="1.2.3";var x={moviePath:"ZeroClipboard.swf",trustedOrigins:null,text:null,hoverClass:"zeroclipboard-is-hover",activeClass:"zeroclipboard-is-active",allowScriptAccess:"sameDomain",useNoCache:!0,forceHandCursor:!1,zIndex:999999999,debug:!0};u.setDefaults=function(a){for(var b in a)x[b]=a[b]},u.destroy=function(){if(u.prototype._singleton){u.prototype._singleton.unglue(c);var a=u.prototype._singleton.htmlBridge;a&&a.parentNode&&a.parentNode.removeChild(a),delete u.prototype._singleton}};var y=null,z=null,A=function(){var a,b,c=u.prototype._singleton,d=document.getElementById("global-zeroclipboard-html-bridge");if(!d){var e={};for(var f in c.options)e[f]=c.options[f];e.amdModuleId=y,e.cjsModuleId=z;var g=o(e),h=' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="global-zeroclipboard-flash-bridge" width="100%" height="100%"> <param name="movie" value="'+c.options.moviePath+n(c.options.moviePath,c.options)+'"/> <param name="allowScriptAccess" value="'+c.options.allowScriptAccess+'"/> <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="'+g+'"/> <embed src="'+c.options.moviePath+n(c.options.moviePath,c.options)+'" 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="'+g+'" scale="exactfit"> </embed> </object>';d=document.createElement("div"),d.id="global-zeroclipboard-html-bridge",d.setAttribute("class","global-zeroclipboard-container"),d.style.position="absolute",d.style.left="0px",d.style.top="-9999px",d.style.width="15px",d.style.height="15px",d.style.zIndex=""+s(c.options.zIndex),document.body.appendChild(d),d.innerHTML=h}c.htmlBridge=d,a=document["global-zeroclipboard-flash-bridge"],a&&(b=a.length)&&(a=a[b-1]),c.flashBridge=a||d.children[0].lastElementChild};u.prototype.resetBridge=function(){return this.htmlBridge&&(this.htmlBridge.style.left="0px",this.htmlBridge.style.top="-9999px",this.htmlBridge.removeAttribute("title")),b&&(k(b,this.options.activeClass),b=null),this.options.text=null,this},u.prototype.ready=function(){return d.clients[this.options.moviePath].ready===!0};var B=function(){if(b){var a=m(b,this.options.zIndex);this.htmlBridge.style.top=a.top+"px",this.htmlBridge.style.left=a.left+"px",this.htmlBridge.style.width=a.width+"px",this.htmlBridge.style.height=a.height+"px",this.htmlBridge.style.zIndex=a.zIndex+1,this.setSize(a.width,a.height)}return this};u.dispatch=function(a,b){if("string"==typeof a&&a){var c=u.prototype._singleton,d=a.toLowerCase().replace(/^on/,"");d&&C.call(c,d,b)}},u.prototype.on=function(a,b){for(var c=a.toString().split(/\s/g),e={},f=0,g=c.length;g>f;f++)a=c[f].toLowerCase().replace(/^on/,""),e[a]=!0,this.handlers[a]||(this.handlers[a]=b);return e.noflash&&d.global.noflash&&C.call(this,"onNoFlash",{}),e.wrongflash&&d.global.wrongflash&&C.call(this,"onWrongFlash",{flashVersion:d.global.version}),e.load&&d.clients[this.options.moviePath].ready&&C.call(this,"onLoad",{flashVersion:d.global.version}),this},u.prototype.addEventListener=u.prototype.on,u.prototype.off=function(a,b){for(var c=a.toString().split(/\s/g),d=0;d<c.length;d++){a=c[d].toLowerCase().replace(/^on/,"");for(var e in this.handlers)e===a&&this.handlers[e]===b&&delete this.handlers[e]}return this},u.prototype.removeEventListener=u.prototype.off;var C=function(c,e){c=c.toString().toLowerCase().replace(/^on/,"");var f=b,g=!0;switch(c){case"load":if(e&&e.flashVersion){if(!a(e.flashVersion))return C.call(this,"onWrongFlash",{flashVersion:e.flashVersion}),void 0;d.clients[this.options.moviePath].ready=!0,d.global.version=e.flashVersion}break;case"wrongflash":e&&e.flashVersion&&!a(e.flashVersion)&&(d.global.wrongflash=!0,d.global.version=e.flashVersion);break;case"mouseover":j(f,this.options.hoverClass);break;case"mouseout":k(f,this.options.hoverClass),this.resetBridge();break;case"mousedown":j(f,this.options.activeClass);break;case"mouseup":k(f,this.options.activeClass);break;case"datarequested":var h=f.getAttribute("data-clipboard-target"),i=h?document.getElementById(h):null;if(i){var l=i.value||i.textContent||i.innerText;l&&this.setText(l)}else{var m=f.getAttribute("data-clipboard-text");m&&this.setText(m)}g=!1;break;case"complete":this.options.text=null}if(this.handlers[c]){var n=this.handlers[c];"string"==typeof n&&"function"==typeof window[n]&&(n=window[n]),"function"==typeof n&&r(n,f,this,e,g)}};u.prototype.glue=function(a){a=q(a);for(var b=0;b<a.length;b++)a[b]&&1===a[b].nodeType&&-1==p(a[b],c)&&(c.push(a[b]),h(a[b],"mouseover",g));return this},u.prototype.unglue=function(a){a=q(a);for(var b=0;b<a.length;b++){i(a[b],"mouseover",g);var d=p(a[b],c);-1!=d&&c.splice(d,1)}return this},u.detectFlashSupport=function(){var a=u.prototype._singleton&&u.prototype._singleton.options.debug||x.debug;return t("ZeroClipboard.detectFlashSupport",a),w()},u.prototype.setHandCursor=function(a){return t("ZeroClipboard.prototype.setHandCursor",this.options.debug),a="boolean"==typeof a?a:!!a,v.call(this,a),this.options.forceHandCursor=a,this},u.prototype.reposition=function(){return t("ZeroClipboard.prototype.reposition",this.options.debug),B.call(this)},u.prototype.receiveEvent=function(a,b){if(t("ZeroClipboard.prototype.receiveEvent",this.options.debug),"string"==typeof a&&a){var c=a.toLowerCase().replace(/^on/,"");c&&C.call(this,c,b)}},"function"==typeof define&&define.amd?define(["require","exports","module"],function(a,b,c){return y=c&&c.id||null,u}):"object"==typeof module&&module&&"object"==typeof module.exports&&module.exports?(z=module.id||null,module.exports=u):window.ZeroClipboard=u}();
+!function(){"use strict";function a(a){return parseFloat(a.replace(/,/g,".").replace(/[^0-9\.]/g,""))>=10}var b,c=[],d={global:{noflash:null,wrongflash:null,version:"0.0.0"},clients:{}},e=function(){var a=/\-([a-z])/g,b=function(a,b){return b.toUpperCase()};return function(c){return c.replace(a,b)}}(),f=function(a,b){var c,d,f,g,h,i;if(window.getComputedStyle?c=window.getComputedStyle(a,null).getPropertyValue(b):(d=e(b),c=a.currentStyle?a.currentStyle[d]:a.style[d]),"cursor"===b&&(!c||"auto"===c))for(f=a.tagName.toLowerCase(),g=["a"],h=0,i=g.length;i>h;h++)if(f===g[h])return"pointer";return c},g=function(a){if(v.prototype._singleton){a||(a=window.event);var b;this!==window?b=this:a.target?b=a.target:a.srcElement&&(b=a.srcElement),v.prototype._singleton.setCurrent(b)}},h=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent&&a.attachEvent("on"+b,c)},i=function(a,b,c){a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent&&a.detachEvent("on"+b,c)},j=function(a,b){if(a.addClass)return a.addClass(b),a;if(b&&"string"==typeof b){var c=(b||"").split(/\s+/);if(1===a.nodeType)if(a.className){for(var d=" "+a.className+" ",e=a.className,f=0,g=c.length;g>f;f++)d.indexOf(" "+c[f]+" ")<0&&(e+=" "+c[f]);a.className=e.replace(/^\s+|\s+$/g,"")}else a.className=b}return a},k=function(a,b){if(a.removeClass)return a.removeClass(b),a;if(b&&"string"==typeof b||void 0===b){var c=(b||"").split(/\s+/);if(1===a.nodeType&&a.className)if(b){for(var d=(" "+a.className+" ").replace(/[\n\t]/g," "),e=0,f=c.length;f>e;e++)d=d.replace(" "+c[e]+" "," ");a.className=d.replace(/^\s+|\s+$/g,"")}else a.className=""}return a},l=function(){var a,b,c,d=1;return"function"==typeof document.body.getBoundingClientRect&&(a=document.body.getBoundingClientRect(),b=a.right-a.left,c=document.body.offsetWidth,d=Math.round(b/c*100)/100),d},m=function(a,b){var c={left:0,top:0,width:0,height:0,zIndex:s(b)-1};if(a.getBoundingClientRect){var d,e,f,g=a.getBoundingClientRect();"pageXOffset"in window&&"pageYOffset"in window?(d=window.pageXOffset,e=window.pageYOffset):(f=l(),d=Math.round(document.documentElement.scrollLeft/f),e=Math.round(document.documentElement.scrollTop/f));var h=document.documentElement.clientLeft||0,i=document.documentElement.clientTop||0;c.left=g.left+d-h,c.top=g.top+e-i,c.width="width"in g?g.width:g.right-g.left,c.height="height"in g?g.height:g.bottom-g.top}return c},n=function(a,b){var c=!(b&&b.useNoCache===!1);return c?(-1===a.indexOf("?")?"?":"&")+"nocache="+(new Date).getTime():""},o=function(a){var b=[],c=[];return a.trustedOrigins&&("string"==typeof a.trustedOrigins?c.push(a.trustedOrigins):"object"==typeof a.trustedOrigins&&"length"in a.trustedOrigins&&(c=c.concat(a.trustedOrigins))),a.trustedDomains&&("string"==typeof a.trustedDomains?c.push(a.trustedDomains):"object"==typeof a.trustedDomains&&"length"in a.trustedDomains&&(c=c.concat(a.trustedDomains))),c.length&&b.push("trustedOrigins="+encodeURIComponent(c.join(","))),"string"==typeof a.amdModuleId&&a.amdModuleId&&b.push("amdModuleId="+encodeURIComponent(a.amdModuleId)),"string"==typeof a.cjsModuleId&&a.cjsModuleId&&b.push("cjsModuleId="+encodeURIComponent(a.cjsModuleId)),b.join("&")},p=function(a,b){if(b.indexOf)return b.indexOf(a);for(var c=0,d=b.length;d>c;c++)if(b[c]===a)return c;return-1},q=function(a){if("string"==typeof a)throw new TypeError("ZeroClipboard doesn't accept query strings.");return a.length?a:[a]},r=function(a,b,c,d,e){e?window.setTimeout(function(){a.call(b,c,d)},0):a.call(b,c,d)},s=function(a){var b,c;return a&&("number"==typeof a&&a>0?b=a:"string"==typeof a&&(c=parseInt(a,10))&&!isNaN(c)&&c>0&&(b=c)),b||("number"==typeof y.zIndex&&y.zIndex>0?b=y.zIndex:"string"==typeof y.zIndex&&(c=parseInt(y.zIndex,10))&&!isNaN(c)&&c>0&&(b=c)),b||0},t=function(a,b){if(a&&b!==!1&&"undefined"!=typeof console&&console&&(console.warn||console.log)){var c="`"+a+"` is deprecated. See docs for more info:\n https://github.com/zeroclipboard/zeroclipboard/blob/master/docs/instructions.md#deprecations";console.warn?console.warn(c):console.log(c)}},u=function(){var a,b,c,d,e,f,g=arguments[0]||{};for(a=1,b=arguments.length;b>a;a++)if(null!=(c=arguments[a]))for(d in c)if(c.hasOwnProperty(d)){if(e=g[d],f=c[d],g===f)continue;void 0!==f&&(g[d]=f)}return g},v=function(a,b){return a&&(v.prototype._singleton||this).glue(a),v.prototype._singleton?v.prototype._singleton:(v.prototype._singleton=this,this.options=u({},y,b),this.handlers={},"boolean"!=typeof d.global.noflash&&(d.global.noflash=!x()),d.clients.hasOwnProperty(this.options.moviePath)||(d.clients[this.options.moviePath]={ready:!1}),d.global.noflash===!1&&B(),void 0)};v.prototype.setCurrent=function(a){b=a,C.call(this);var c=a.getAttribute("title");c&&this.setTitle(c);var d=this.options.forceHandCursor===!0||"pointer"===f(a,"cursor");return w.call(this,d),this},v.prototype.setText=function(a){return a&&""!==a&&(this.options.text=a,this.ready()&&this.flashBridge.setText(a)),this},v.prototype.setTitle=function(a){return a&&""!==a&&this.htmlBridge.setAttribute("title",a),this},v.prototype.setSize=function(a,b){return this.ready()&&this.flashBridge.setSize(a,b),this};var w=function(a){this.ready()&&this.flashBridge.setHandCursor(a)},x=function(){var a=!1;if("boolean"==typeof d.global.noflash)a=d.global.noflash===!1;else{if("function"==typeof ActiveXObject)try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash")&&(a=!0)}catch(b){}!a&&navigator.mimeTypes["application/x-shockwave-flash"]&&(a=!0)}return a};v.version="1.2.3";var y={moviePath:"ZeroClipboard.swf",trustedOrigins:null,text:null,hoverClass:"zeroclipboard-is-hover",activeClass:"zeroclipboard-is-active",allowScriptAccess:"sameDomain",useNoCache:!0,forceHandCursor:!1,zIndex:999999999,debug:!0};v.setDefaults=function(a){u(y,a)},v.destroy=function(){if(v.prototype._singleton){v.prototype._singleton.unglue(c);var a=v.prototype._singleton.htmlBridge;a&&a.parentNode&&a.parentNode.removeChild(a),delete v.prototype._singleton}};var z=null,A=null,B=function(){var a,b,c=v.prototype._singleton,d=document.getElementById("global-zeroclipboard-html-bridge");if(!d){var e=u({},c.options);e.amdModuleId=z,e.cjsModuleId=A;var f=o(e),g=' <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="global-zeroclipboard-flash-bridge" width="100%" height="100%"> <param name="movie" value="'+c.options.moviePath+n(c.options.moviePath,c.options)+'"/> <param name="allowScriptAccess" value="'+c.options.allowScriptAccess+'"/> <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="'+f+'"/> <embed src="'+c.options.moviePath+n(c.options.moviePath,c.options)+'" 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="'+f+'" scale="exactfit"> </embed> </object>';d=document.createElement("div"),d.id="global-zeroclipboard-html-bridge",d.setAttribute("class","global-zeroclipboard-container"),d.style.position="absolute",d.style.left="0px",d.style.top="-9999px",d.style.width="15px",d.style.height="15px",d.style.zIndex=""+s(c.options.zIndex),document.body.appendChild(d),d.innerHTML=g}c.htmlBridge=d,a=document["global-zeroclipboard-flash-bridge"],a&&(b=a.length)&&(a=a[b-1]),c.flashBridge=a||d.children[0].lastElementChild};v.prototype.resetBridge=function(){return this.htmlBridge&&(this.htmlBridge.style.left="0px",this.htmlBridge.style.top="-9999px",this.htmlBridge.removeAttribute("title")),b&&(k(b,this.options.activeClass),b=null),this.options.text=null,this},v.prototype.ready=function(){return d.clients[this.options.moviePath].ready===!0};var C=function(){if(b){var a=m(b,this.options.zIndex);this.htmlBridge.style.top=a.top+"px",this.htmlBridge.style.left=a.left+"px",this.htmlBridge.style.width=a.width+"px",this.htmlBridge.style.height=a.height+"px",this.htmlBridge.style.zIndex=a.zIndex+1,this.setSize(a.width,a.height)}return this};v.dispatch=function(a,b){if("string"==typeof a&&a){var c=v.prototype._singleton,d=a.toLowerCase().replace(/^on/,"");d&&D.call(c,d,b)}},v.prototype.on=function(a,b){for(var c=a.toString().split(/\s/g),e={},f=0,g=c.length;g>f;f++)a=c[f].toLowerCase().replace(/^on/,""),e[a]=!0,this.handlers[a]||(this.handlers[a]=b);return e.noflash&&d.global.noflash&&D.call(this,"onNoFlash",{}),e.wrongflash&&d.global.wrongflash&&D.call(this,"onWrongFlash",{flashVersion:d.global.version}),e.load&&d.clients[this.options.moviePath].ready&&D.call(this,"onLoad",{flashVersion:d.global.version}),this},v.prototype.addEventListener=v.prototype.on,v.prototype.off=function(a,b){for(var c=a.toString().split(/\s/g),d=0;d<c.length;d++){a=c[d].toLowerCase().replace(/^on/,"");for(var e in this.handlers)e===a&&this.handlers[e]===b&&delete this.handlers[e]}return this},v.prototype.removeEventListener=v.prototype.off;var D=function(c,e){c=c.toString().toLowerCase().replace(/^on/,"");var f=b,g=!0;switch(c){case"load":if(e&&e.flashVersion){if(!a(e.flashVersion))return D.call(this,"onWrongFlash",{flashVersion:e.flashVersion}),void 0;d.clients[this.options.moviePath].ready=!0,d.global.version=e.flashVersion}break;case"wrongflash":e&&e.flashVersion&&!a(e.flashVersion)&&(d.global.wrongflash=!0,d.global.version=e.flashVersion);break;case"mouseover":j(f,this.options.hoverClass);break;case"mouseout":k(f,this.options.hoverClass),this.resetBridge();break;case"mousedown":j(f,this.options.activeClass);break;case"mouseup":k(f,this.options.activeClass);break;case"datarequested":var h=f.getAttribute("data-clipboard-target"),i=h?document.getElementById(h):null;if(i){var l=i.value||i.textContent||i.innerText;l&&this.setText(l)}else{var m=f.getAttribute("data-clipboard-text");m&&this.setText(m)}g=!1;break;case"complete":this.options.text=null}if(this.handlers[c]){var n=this.handlers[c];"string"==typeof n&&"function"==typeof window[n]&&(n=window[n]),"function"==typeof n&&r(n,f,this,e,g)}};v.prototype.glue=function(a){a=q(a);for(var b=0;b<a.length;b++)a[b]&&1===a[b].nodeType&&-1===p(a[b],c)&&(c.push(a[b]),h(a[b],"mouseover",g));return this},v.prototype.unglue=function(a){a=q(a);for(var b=0;b<a.length;b++){i(a[b],"mouseover",g);var d=p(a[b],c);-1!==d&&c.splice(d,1)}return this},v.detectFlashSupport=function(){var a=v.prototype._singleton&&v.prototype._singleton.options.debug||y.debug;return t("ZeroClipboard.detectFlashSupport",a),x()},v.prototype.setHandCursor=function(a){return t("ZeroClipboard.prototype.setHandCursor",this.options.debug),a="boolean"==typeof a?a:!!a,w.call(this,a),this.options.forceHandCursor=a,this},v.prototype.reposition=function(){return t("ZeroClipboard.prototype.reposition",this.options.debug),C.call(this)},v.prototype.receiveEvent=function(a,b){if(t("ZeroClipboard.prototype.receiveEvent",this.options.debug),"string"==typeof a&&a){var c=a.toLowerCase().replace(/^on/,"");c&&D.call(this,c,b)}},"function"==typeof define&&define.amd?define(["require","exports","module"],function(a,b,c){return z=c&&c.id||null,v}):"object"==typeof module&&module&&"object"==typeof module.exports&&module.exports?(A=module.id||null,module.exports=v):window.ZeroClipboard=v}();
View
9 src/javascript/ZeroClipboard/client.js
@@ -13,13 +13,8 @@ var ZeroClipboard = function (elements, options) {
ZeroClipboard.prototype._singleton = this;
- this.options = {};
-
- // set the defaults
- for (var kd in _defaults) this.options[kd] = _defaults[kd];
-
- // override the defaults
- for (var ko in options) this.options[ko] = options[ko];
+ // Set and override the defaults
+ this.options = _extend({}, _defaults, options);
// event handlers
this.handlers = {};
View
2  src/javascript/ZeroClipboard/core.js
@@ -19,7 +19,7 @@ var _defaults = {
* returns nothing
*/
ZeroClipboard.setDefaults = function (options) {
- for (var ko in options) _defaults[ko] = options[ko];
+ _extend(_defaults, options);
};
/*
View
3  src/javascript/ZeroClipboard/dom.js
@@ -18,8 +18,7 @@ var _bridge = function () {
if (!container) {
// Create a copy of the `client.options` object to avoid exposing
// the `amdModuleId` and `cjsModuleId` settings
- var opts = {};
- for (var ko in client.options) opts[ko] = client.options[ko];
+ var opts = _extend({}, client.options);
// Set these last to override them just in case any [v1.2.0-beta.1] users
// are still passing them in to [v1.2.0-beta.2] (or higher)
opts.amdModuleId = _amdModuleId;
View
4 src/javascript/ZeroClipboard/event.js
@@ -185,7 +185,7 @@ ZeroClipboard.prototype.glue = function (elements) {
for (var i = 0; i < elements.length ; i++) {
if (elements[i] && elements[i].nodeType === 1) {
// if the element has not been glued
- if (_inArray(elements[i], gluedElements) == -1) {
+ if (_inArray(elements[i], gluedElements) === -1) {
// push to glued elements
gluedElements.push(elements[i]);
@@ -215,7 +215,7 @@ ZeroClipboard.prototype.unglue = function (elements) {
var arrayIndex = _inArray(elements[i], gluedElements);
// if the index is not -1, remove from array
- if (arrayIndex != -1) gluedElements.splice(arrayIndex, 1);
+ if (arrayIndex !== -1) gluedElements.splice(arrayIndex, 1);
}
return this;
View
35 src/javascript/ZeroClipboard/utils.js
@@ -409,4 +409,39 @@ var _deprecationWarning = function(deprecatedApiName, debugEnabled) {
console.log(deprecationWarning);
}
}
+};
+
+
+/*
+ * Shallow-copy the owned properties of one object over to another, similar to jQuery's `$.extend`.
+ * @returns the target object
+ * @private
+ */
+var _extend = function() {
+ var i, len, arg, prop, src, copy,
+ target = arguments[0] || {};
+
+ for (i = 1, len = arguments.length; i < len; i++) {
+ // Only deal with non-null/undefined values
+ if ((arg = arguments[i]) != null) {
+ // Extend the base object
+ for (prop in arg) {
+ if (arg.hasOwnProperty(prop)) {
+ src = target[prop];
+ copy = arg[prop];
+
+ // Prevent never-ending loops
+ if (target === copy) {
+ continue;
+ }
+
+ // Don't bring in undefined values
+ if (copy !== undefined) {
+ target[prop] = copy;
+ }
+ }
+ }
+ }
+ }
+ return target;
};
View
17 test/.jshintrc
@@ -1,13 +1,18 @@
{
- "camelcase": true,
- "indent": 2,
- "strict": false,
- "trailing": true,
"boss": true,
"browser": true,
- "node": true,
- "multistr": false,
+ "camelcase": true,
+ "eqeqeq": true,
+ "eqnull": true,
+ "es3": true,
+ "es5": false,
"evil": true,
+ "globalstrict": true,
+ "indent": 2,
+ "multistr": true,
+ "strict": true,
+ "trailing": true,
+
"globals": {
"$": false,
"QUnit": false
View
3  test/core.js.html
@@ -17,9 +17,10 @@
// Prevent against Firefox/Firebug failing the global pollution check
var getInterface = null;
</script>
+ <script src="../src/javascript/ZeroClipboard/utils.js"></script>
<script>
var ZeroClipboard = function(elements, options) {
- this.options = QUnit.extend(QUnit.extend({}, _defaults), options);
+ this.options = _extend({}, _defaults, options);
};
</script>
<script src="../src/javascript/ZeroClipboard/core.js"></script>
View
2  test/event.js
@@ -92,7 +92,7 @@
var clip = new ZeroClipboard();
// Assert
- assert.throws(function() {
+ assert["throws"](function() {
// Act
clip.glue("#d_clip_button");
}, TypeError);
View
13 test/event.js.html
@@ -21,7 +21,12 @@
<script src="../src/javascript/ZeroClipboard/utils.js"></script>
<script src="../src/javascript/ZeroClipboard/flash.js"></script>
<script>
- var _zcCounter = 1;
+ var _zcCounter = 1,
+ _defaults = {
+ hoverClass: "zeroclipboard-is-hover",
+ activeClass: "zeroclipboard-is-active",
+ moviePath: "ZeroClipboard.swf"
+ };
function ZeroClipboard(elements, options) {
// If there's a client already, return the singleton
if (ZeroClipboard.prototype._singleton) {
@@ -29,11 +34,7 @@
}
ZeroClipboard.prototype._singleton = this;
- this.options = QUnit.extend({
- hoverClass: "zeroclipboard-is-hover",
- activeClass: "zeroclipboard-is-active",
- moviePath: "ZeroClipboard.swf"
- }, options);
+ this.options = _extend({}, _defaults, options);
if (typeof flashState.global.noflash !== "boolean") {
flashState.global.noflash = !_detectFlashSupport();
View
102 test/utils.js
@@ -1,4 +1,4 @@
-/*global _camelizeCssPropName, _getStyle, _removeClass, _addClass, _vars, _noCache, _inArray, _dispatchCallback */
+/*global _camelizeCssPropName, _getStyle, _removeClass, _addClass, _vars, _noCache, _inArray, _dispatchCallback, _extend */
"use strict";
@@ -257,4 +257,104 @@
QUnit.stop();
});
+
+ test("`_extend` works on plain objects", function(assert) {
+ assert.expect(5);
+
+ // Plain objects
+ var a = {
+ "a": "apple",
+ "c": "cantalope"
+ },
+ b = {
+ "b": "banana",
+ "c": "cherry" // cuz cantalope sucks ;)
+ },
+ c = {
+ "a": "apple",
+ "b": "banana",
+ "c": "cherry"
+ };
+
+ assert.deepEqual(_extend({}, a), a, "actual equals expected, `target` is updated, `source` is unaffected");
+ assert.deepEqual(_extend({}, b), b, "actual equals expected, `target` is updated, `source` is unaffected");
+ assert.deepEqual(_extend({}, c), c, "actual equals expected, `target` is updated, `source` is unaffected");
+ assert.deepEqual(_extend(a, b), c, "actual equals expected");
+ assert.deepEqual(a, c, "`a` equals `c` because `_extend` updates the `target` argument");
+ });
+
+
+ test("`_extend` only copies owned properties", function(assert) {
+ assert.expect(1);
+
+ // Now prototypes...
+ var SomeClass = function() {
+ this.b = "banana";
+ };
+ SomeClass.prototype.c = "cantalope"; // cuz cantalope sucks ;)
+
+ var a = {
+ "a": "apple",
+ "c": "cherry"
+ },
+ b = new SomeClass(),
+ c = {
+ "a": "apple",
+ "b": "banana",
+ "c": "cherry"
+ };
+
+ assert.deepEqual(_extend(a, b), c, "actual equals expected because `_extend` does not copy over prototype properties");
+ });
+
+
+ test("`_extend` only copies owned properties from Array source", function(assert) {
+ assert.expect(3);
+
+ var a = {
+ "a": "apple",
+ "b": "banana"
+ },
+ b = ["zero", "one", "two"],
+ c = {
+ "a": "apple",
+ "b": "banana",
+ "0": "zero",
+ "1": "one",
+ "2": "two"
+ };
+
+ assert.deepEqual(_extend(a, b), c, "actual equals expected because `_extend` does not copy over prototype properties");
+ assert.strictEqual("length" in a, false, "`a` should not have gained a `length` property");
+ assert.strictEqual("length" in b, true, "`b` should still have a `length` property");
+ });
+
+
+ test("`_extend` will merge multiple objects", function(assert) {
+ assert.expect(2);
+
+ var a = {
+ "a": "apple",
+ "c": "cantalope",
+ "d": "dragon fruit"
+ },
+ b = {
+ "b": "banana",
+ "c": "cherry" // cuz cantalope sucks ;)
+ },
+ c = {
+ "a": "apricot",
+ "b": "blueberry"
+ },
+ d = {
+ "a": "apricot",
+ "b": "blueberry",
+ "c": "cherry",
+ "d": "dragon fruit"
+ };
+
+ assert.deepEqual(_extend({}, a, b, c), d, "actual equals expected, `target` is updated, `source` is unaffected");
+ assert.deepEqual(_extend(a, b, c), d, "actual equals expected");
+ });
+
})(QUnit.module, QUnit.test);
Please sign in to comment.
Something went wrong with that request. Please try again.