Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "clipboard", | ||
"version": "1.0.0", | ||
"description": "A modern approach to copy text to clipboard. No Flash. No dependencies. Just 2kb.", | ||
"version": "1.1.0", | ||
"description": "Modern copy to clipboard. No Flash. Just 2kb", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "main": "src/clipboard.js", |
@@ -1,1 +0,1 @@ | ||
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){var d=a("closest"),e=a("component-event"),f=["focus","blur"];c.bind=function(a,b,c,g,h){return-1!==f.indexOf(c)&&(h=!0),e.bind(a,c,function(c){var e=c.target||c.srcElement;c.delegateTarget=d(e,b,!0,a),c.delegateTarget&&g.call(a,c)},h)},c.unbind=function(a,b,c,d){-1!==f.indexOf(b)&&(d=!0),e.unbind(a,b,c,d)}},{closest:2,"component-event":4}],2:[function(a,b,c){var d=a("matches-selector");b.exports=function(a,b,c){for(var e=c?a:a.parentNode;e&&e!==document;){if(d(e,b))return e;e=e.parentNode}}},{"matches-selector":3}],3:[function(a,b,c){function d(a,b){if(f)return f.call(a,b);for(var c=a.parentNode.querySelectorAll(b),d=0;d<c.length;++d)if(c[d]==a)return!0;return!1}var e=Element.prototype,f=e.matchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector;b.exports=d},{}],4:[function(a,b,c){var d=window.addEventListener?"addEventListener":"attachEvent",e=window.removeEventListener?"removeEventListener":"detachEvent",f="addEventListener"!==d?"on":"";c.bind=function(a,b,c,e){return a[d](f+b,c,e||!1),c},c.unbind=function(a,b,c,d){return a[e](f+b,c,d||!1),c}},{}],5:[function(a,b,c){function d(){}d.prototype={on:function(a,b,c){var d=this.e||(this.e={});return(d[a]||(d[a]=[])).push({fn:b,ctx:c}),this},once:function(a,b,c){var d=this,e=function(){d.off(a,e),b.apply(c,arguments)};return this.on(a,e,c)},emit:function(a){var b=[].slice.call(arguments,1),c=((this.e||(this.e={}))[a]||[]).slice(),d=0,e=c.length;for(d;e>d;d++)c[d].fn.apply(c[d].ctx,b);return this},off:function(a,b){var c=this.e||(this.e={}),d=c[a],e=[];if(d&&b)for(var f=0,g=d.length;g>f;f++)d[f].fn!==b&&e.push(d[f]);return e.length?c[a]=e:delete c[a],this}},b.exports=d},{}],6:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}c.__esModule=!0;var e=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),f=function(){function a(b){if(d(this,a),this.action=b.action,this.emitter=b.emitter,this.target=b.target,this.text=b.text,this.trigger=b.trigger,this.selectedText="",this.text&&this.target)throw new Error('Multiple attributes declared, use either "data-target" or "data-text"');if(this.text)this.selectFake();else{if(!this.target)throw new Error('Missing required attributes, use either "data-target" or "data-text"');this.selectTarget()}}return a.prototype.selectFake=function(){var a=this;this.removeFake(),this.fakeHandler=document.body.addEventListener("click",function(){return a.removeFake()}),this.fakeElem=document.createElement("input"),this.fakeElem.style.position="absolute",this.fakeElem.style.left="-9999px",this.fakeElem.setAttribute("readonly",""),this.fakeElem.value=this.text,this.selectedText=this.text,document.body.appendChild(this.fakeElem),this.fakeElem.select(),this.copyText()},a.prototype.removeFake=function(){this.fakeHandler&&(document.body.removeEventListener("click"),this.fakeHandler=null),this.fakeElem&&(document.body.removeChild(this.fakeElem),this.fakeElem=null)},a.prototype.selectTarget=function(){if("INPUT"===this.target.nodeName||"TEXTAREA"===this.target.nodeName)this.target.select(),this.selectedText=this.target.value;else{var a=document.createRange(),b=window.getSelection();a.selectNodeContents(this.target),b.addRange(a),this.selectedText=b.toString()}this.copyText()},a.prototype.copyText=function(){var a=void 0;try{a=document.execCommand(this.action)}catch(b){a=!1}this.handleResult(a)},a.prototype.handleResult=function(a){a?this.emitter.emit("success",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)}):this.emitter.emit("error",{action:this.action,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})},a.prototype.clearSelection=function(){this.target&&this.target.blur(),window.getSelection().removeAllRanges()},e(a,[{key:"action",set:function(a){if(this._action=a||"copy","copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "data-action" value, use either "copy" or "cut"')},get:function(){return this._action}},{key:"target",set:function(a){if(a&&(this._target=document.getElementById(a),!this._target))throw new Error('Invalid "data-target" selector, use a value that matches an ID')},get:function(){return this._target}}]),a}();c["default"]=f,b.exports=c["default"]},{}],7:[function(a,b,c){(function(d){"use strict";function e(a){return a&&a.__esModule?a:{"default":a}}function f(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function g(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)}c.__esModule=!0;var h=a("./clipboard-action"),i=e(h),j=a("delegate-events"),k=e(j),l=a("tiny-emitter"),m=e(l),n=function(a){function b(c){var d=this;if(f(this,b),a.call(this),!document.querySelectorAll(c).length)throw new Error("No matches were found for the provided selector");k["default"].bind(document.body,c,"click",function(a){return d.initialize(a)})}return g(b,a),b.prototype.initialize=function(a){this.clipboardAction&&(this.clipboardAction=null),this.clipboardAction=new i["default"]({action:a.delegateTarget.getAttribute("data-action"),target:a.delegateTarget.getAttribute("data-target"),text:a.delegateTarget.getAttribute("data-text"),trigger:a.delegateTarget,emitter:this})},b}(m["default"]);c["default"]=n,d.Clipboard=n,b.exports=c["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./clipboard-action":6,"delegate-events":1,"tiny-emitter":5}]},{},[7]); | ||
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){var d=a("closest"),e=a("component-event"),f=["focus","blur"];c.bind=function(a,b,c,g,h){return-1!==f.indexOf(c)&&(h=!0),e.bind(a,c,function(c){var e=c.target||c.srcElement;c.delegateTarget=d(e,b,!0,a),c.delegateTarget&&g.call(a,c)},h)},c.unbind=function(a,b,c,d){-1!==f.indexOf(b)&&(d=!0),e.unbind(a,b,c,d)}},{closest:2,"component-event":4}],2:[function(a,b,c){var d=a("matches-selector");b.exports=function(a,b,c){for(var e=c?a:a.parentNode;e&&e!==document;){if(d(e,b))return e;e=e.parentNode}}},{"matches-selector":3}],3:[function(a,b,c){function d(a,b){if(f)return f.call(a,b);for(var c=a.parentNode.querySelectorAll(b),d=0;d<c.length;++d)if(c[d]==a)return!0;return!1}var e=Element.prototype,f=e.matchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector;b.exports=d},{}],4:[function(a,b,c){var d=window.addEventListener?"addEventListener":"attachEvent",e=window.removeEventListener?"removeEventListener":"detachEvent",f="addEventListener"!==d?"on":"";c.bind=function(a,b,c,e){return a[d](f+b,c,e||!1),c},c.unbind=function(a,b,c,d){return a[e](f+b,c,d||!1),c}},{}],5:[function(a,b,c){function d(){}d.prototype={on:function(a,b,c){var d=this.e||(this.e={});return(d[a]||(d[a]=[])).push({fn:b,ctx:c}),this},once:function(a,b,c){var d=this,e=function(){d.off(a,e),b.apply(c,arguments)};return this.on(a,e,c)},emit:function(a){var b=[].slice.call(arguments,1),c=((this.e||(this.e={}))[a]||[]).slice(),d=0,e=c.length;for(d;e>d;d++)c[d].fn.apply(c[d].ctx,b);return this},off:function(a,b){var c=this.e||(this.e={}),d=c[a],e=[];if(d&&b)for(var f=0,g=d.length;g>f;f++)d[f].fn!==b&&e.push(d[f]);return e.length?c[a]=e:delete c[a],this}},b.exports=d},{}],6:[function(a,b,c){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}c.__esModule=!0;var e=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),f=function(){function a(b){if(d(this,a),this.action=b.action,this.emitter=b.emitter,this.target=b.target,this.text=b.text,this.trigger=b.trigger,this.selectedText="",this.text&&this.target)throw new Error('Multiple attributes declared, use either "data-clipboard-target" or "data-clipboard-text"');if(this.text)this.selectFake();else{if(!this.target)throw new Error('Missing required attributes, use either "data-clipboard-target" or "data-clipboard-text"');this.selectTarget()}}return a.prototype.selectFake=function(){var a=this;this.removeFake(),this.fakeHandler=document.body.addEventListener("click",function(){return a.removeFake()}),this.fakeElem=document.createElement("input"),this.fakeElem.style.position="absolute",this.fakeElem.style.left="-9999px",this.fakeElem.setAttribute("readonly",""),this.fakeElem.value=this.text,this.selectedText=this.text,document.body.appendChild(this.fakeElem),this.fakeElem.select(),this.copyText()},a.prototype.removeFake=function(){this.fakeHandler&&(document.body.removeEventListener("click"),this.fakeHandler=null),this.fakeElem&&(document.body.removeChild(this.fakeElem),this.fakeElem=null)},a.prototype.selectTarget=function(){if("INPUT"===this.target.nodeName||"TEXTAREA"===this.target.nodeName)this.target.select(),this.selectedText=this.target.value;else{var a=document.createRange(),b=window.getSelection();a.selectNodeContents(this.target),b.addRange(a),this.selectedText=b.toString()}this.copyText()},a.prototype.copyText=function(){var a=void 0;try{a=document.execCommand(this.action)}catch(b){a=!1}this.handleResult(a)},a.prototype.handleResult=function(a){a?this.emitter.emit("success",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)}):this.emitter.emit("error",{action:this.action,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})},a.prototype.clearSelection=function(){this.target&&this.target.blur(),window.getSelection().removeAllRanges()},e(a,[{key:"action",set:function(a){if(this._action=a||"copy","copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "data-clipboard-action" value, use either "copy" or "cut"')},get:function(){return this._action}},{key:"target",set:function(a){if(a&&(this._target=document.getElementById(a),!this._target))throw new Error('Invalid "data-clipboard-target" selector, use a value that matches an ID')},get:function(){return this._target}}]),a}();c["default"]=f,b.exports=c["default"]},{}],7:[function(a,b,c){(function(d){"use strict";function e(a){return a&&a.__esModule?a:{"default":a}}function f(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function g(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(Object.setPrototypeOf?Object.setPrototypeOf(a,b):a.__proto__=b)}c.__esModule=!0;var h=a("./clipboard-action"),i=e(h),j=a("delegate-events"),k=e(j),l=a("tiny-emitter"),m=e(l),n=function(a){function b(c){var d=this;if(f(this,b),a.call(this),!document.querySelectorAll(c).length)throw new Error("No matches were found for the provided selector");k["default"].bind(document.body,c,"click",function(a){return d.initialize(a)})}return g(b,a),b.prototype.initialize=function(a){this.clipboardAction&&(this.clipboardAction=null);var b="data-clipboard-";this.clipboardAction=new i["default"]({action:a.delegateTarget.getAttribute(b+"action"),target:a.delegateTarget.getAttribute(b+"target"),text:a.delegateTarget.getAttribute(b+"text"),trigger:a.delegateTarget,emitter:this})},b}(m["default"]);c["default"]=n,d.Clipboard=n,b.exports=c["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./clipboard-action":6,"delegate-events":1,"tiny-emitter":5}]},{},[7]); |
{ | ||
"name": "clipboard", | ||
"version": "1.0.0", | ||
"description": "A modern approach to copy text to clipboard. No Flash. No dependencies. Just 2kb.", | ||
"version": "1.1.0", | ||
"description": "Modern copy to clipboard. No Flash. Just 2kb", | ||
"repository": "zenorocha/clipboard.js", | ||
"main": "src/clipboard.js", | ||
"license": "MIT", | ||
"keywords": [ | ||
@@ -30,6 +31,6 @@ "clipboard", | ||
"publish": "npm run build && npm run minify", | ||
"build": "browserify src/clipboard.js -t [babelify --loose all] -o dist/clipboard.js", | ||
"minify": "uglify -s dist/clipboard.js -o dist/clipboard.min.js", | ||
"build": "browserify src/clipboard.js -t [babelify --loose all] -o dist/clipboard.min.js", | ||
"minify": "uglify -s dist/clipboard.min.js -o dist/clipboard.min.js", | ||
"test": "karma start --single-run" | ||
} | ||
} |
@@ -5,3 +5,3 @@ # clipboard.js | ||
> A modern approach to copy text to the clipboard. No Flash. No dependencies. Just 2kb. | ||
> Modern copy to clipboard. No Flash. Just 2kb | ||
@@ -56,3 +56,3 @@ <a href="http://zenorocha.github.io/clipboard.js/"><img width="728" src="https://cloud.githubusercontent.com/assets/398893/9983535/5ab0a950-5fb4-11e5-9602-e73c0b661883.jpg" alt="Demo"></a> | ||
A pretty common use case is to copy content from another element. You can do that by adding a `data-target` attribute in your trigger element. | ||
A pretty common use case is to copy content from another element. You can do that by adding a `data-clipboard-target` attribute in your trigger element. | ||
@@ -68,3 +68,3 @@ The value you include on this attribute needs to match another's element `id` attribute. | ||
<!-- Trigger --> | ||
<button class="btn" data-target="foo"> | ||
<button class="btn" data-clipboard-target="foo"> | ||
<img src="assets/clippy.svg" alt="Copy to clipboard"> | ||
@@ -76,3 +76,3 @@ </button> | ||
Additionally, you can define a `data-action` attribute to specify if you want to either `copy` or `cut` content. | ||
Additionally, you can define a `data-clipboard-action` attribute to specify if you want to either `copy` or `cut` content. | ||
@@ -88,3 +88,3 @@ If you omit this attribute, `copy` will be used by default. | ||
<!-- Trigger --> | ||
<button class="btn" data-action="cut" data-target="bar"> | ||
<button class="btn" data-clipboard-action="cut" data-clipboard-target="bar"> | ||
Cut to clipboard | ||
@@ -98,3 +98,3 @@ </button> | ||
Truth is, you don't even need another element to copy its content from. You can just include a `data-text` attribute in your trigger element. | ||
Truth is, you don't even need another element to copy its content from. You can just include a `data-clipboard-text` attribute in your trigger element. | ||
@@ -105,3 +105,3 @@ <a href="http://zenorocha.github.io/clipboard.js/#demo-text"><img width="147" alt="example-1" src="https://cloud.githubusercontent.com/assets/398893/10000347/6e16cf8c-6050-11e5-9883-1c5681f9ec45.png"></a> | ||
<!-- Trigger --> | ||
<button class="btn" data-text="Just because you can doesn't mean you should — clipboard.js"> | ||
<button class="btn" data-clipboard-text="Just because you can doesn't mean you should — clipboard.js"> | ||
Copy to clipboard | ||
@@ -108,0 +108,0 @@ </button> |
@@ -19,3 +19,3 @@ /** | ||
if (this.text && this.target) { | ||
throw new Error('Multiple attributes declared, use either "data-target" or "data-text"'); | ||
throw new Error('Multiple attributes declared, use either "data-clipboard-target" or "data-clipboard-text"'); | ||
} | ||
@@ -29,3 +29,3 @@ else if (this.text) { | ||
else { | ||
throw new Error('Missing required attributes, use either "data-target" or "data-text"'); | ||
throw new Error('Missing required attributes, use either "data-clipboard-target" or "data-clipboard-text"'); | ||
} | ||
@@ -149,3 +149,3 @@ } | ||
if (this._action !== 'copy' && this._action !== 'cut') { | ||
throw new Error('Invalid "data-action" value, use either "copy" or "cut"'); | ||
throw new Error('Invalid "data-clipboard-action" value, use either "copy" or "cut"'); | ||
} | ||
@@ -172,3 +172,3 @@ } | ||
if (!this._target) { | ||
throw new Error('Invalid "data-target" selector, use a value that matches an ID'); | ||
throw new Error('Invalid "data-clipboard-target" selector, use a value that matches an ID'); | ||
} | ||
@@ -175,0 +175,0 @@ } |
@@ -33,6 +33,8 @@ import ClipboardAction from './clipboard-action'; | ||
const prefix = 'data-clipboard-'; | ||
this.clipboardAction = new ClipboardAction({ | ||
action : e.delegateTarget.getAttribute('data-action'), | ||
target : e.delegateTarget.getAttribute('data-target'), | ||
text : e.delegateTarget.getAttribute('data-text'), | ||
action : e.delegateTarget.getAttribute(prefix + 'action'), | ||
target : e.delegateTarget.getAttribute(prefix + 'target'), | ||
text : e.delegateTarget.getAttribute(prefix + 'text'), | ||
trigger : e.delegateTarget, | ||
@@ -39,0 +41,0 @@ emitter : this |
@@ -23,3 +23,3 @@ import Clipboard from '../src/clipboard-action'; | ||
describe('#constructor', () => { | ||
it('should throw an error since both "data-text" and "data-target" were passed', done => { | ||
it('should throw an error since both "data-clipboard-text" and "data-clipboard-target" were passed', done => { | ||
try { | ||
@@ -32,3 +32,3 @@ new ClipboardAction({ | ||
catch(e) { | ||
assert.equal(e.message, 'Multiple attributes declared, use either "data-target" or "data-text"'); | ||
assert.equal(e.message, 'Multiple attributes declared, use either "data-clipboard-target" or "data-clipboard-text"'); | ||
done(); | ||
@@ -38,3 +38,3 @@ } | ||
it('should throw an error since neither "data-text" nor "data-target" were passed', done => { | ||
it('should throw an error since neither "data-clipboard-text" nor "data-clipboard-target" were passed', done => { | ||
try { | ||
@@ -46,3 +46,3 @@ new ClipboardAction({ | ||
catch(e) { | ||
assert.equal(e.message, 'Missing required attributes, use either "data-target" or "data-text"'); | ||
assert.equal(e.message, 'Missing required attributes, use either "data-clipboard-target" or "data-clipboard-text"'); | ||
done(); | ||
@@ -54,3 +54,3 @@ } | ||
describe('#set action', () => { | ||
it('should throw an error since "data-action" is invalid', done => { | ||
it('should throw an error since "data-clipboard-action" is invalid', done => { | ||
try { | ||
@@ -63,3 +63,3 @@ new ClipboardAction({ | ||
catch(e) { | ||
assert.equal(e.message, 'Invalid "data-action" value, use either "copy" or "cut"'); | ||
assert.equal(e.message, 'Invalid "data-clipboard-action" value, use either "copy" or "cut"'); | ||
done(); | ||
@@ -71,3 +71,3 @@ } | ||
describe('#set target', () => { | ||
it('should throw an error since "data-target" do not match any element', done => { | ||
it('should throw an error since "data-clipboard-target" do not match any element', done => { | ||
try { | ||
@@ -79,3 +79,3 @@ new ClipboardAction({ | ||
catch(e) { | ||
assert.equal(e.message, 'Invalid "data-target" selector, use a value that matches an ID'); | ||
assert.equal(e.message, 'Invalid "data-clipboard-target" selector, use a value that matches an ID'); | ||
done(); | ||
@@ -82,0 +82,0 @@ } |
@@ -31,3 +31,3 @@ import Clipboard from '../src/clipboard'; | ||
global.button.setAttribute('class', 'btn'); | ||
global.button.setAttribute('data-text', 'foo'); | ||
global.button.setAttribute('data-clipboard-text', 'foo'); | ||
document.body.appendChild(global.button); | ||
@@ -34,0 +34,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
0
3
0
41873
469