mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a12a056ef6 | ||
|
|
cb4301658c | ||
|
|
5efcdf2810 | ||
|
|
72926580c3 | ||
|
|
4967f118fe | ||
|
|
44d59b34a2 | ||
|
|
9d6375d20e | ||
|
|
37136663df | ||
|
|
db575bb4df | ||
|
|
bb6c4c0e7c | ||
|
|
03ee9829e0 | ||
|
|
24f6e1f541 | ||
|
|
5bdfff6375 | ||
|
|
4b73122f81 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
lib
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
bower_components
|
bower_components
|
||||||
node_modules
|
node_modules
|
||||||
|
|||||||
@@ -4,3 +4,4 @@
|
|||||||
/.*
|
/.*
|
||||||
/bower.json
|
/bower.json
|
||||||
/karma.conf.js
|
/karma.conf.js
|
||||||
|
/src
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "clipboard",
|
"name": "clipboard",
|
||||||
"version": "1.5.1",
|
"version": "1.5.4",
|
||||||
"description": "Modern copy to clipboard. No Flash. Just 2kb",
|
"description": "Modern copy to clipboard. No Flash. Just 2kb",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "dist/clipboard.js",
|
"main": "dist/clipboard.js",
|
||||||
@@ -10,7 +10,9 @@
|
|||||||
"/test/",
|
"/test/",
|
||||||
"/.*",
|
"/.*",
|
||||||
"/bower.json",
|
"/bower.json",
|
||||||
"/karma.conf.js"
|
"/karma.conf.js",
|
||||||
|
"/src",
|
||||||
|
"/lib"
|
||||||
],
|
],
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"clipboard",
|
"clipboard",
|
||||||
|
|||||||
@@ -6,7 +6,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<!-- 1. Define some markup -->
|
<!-- 1. Define some markup -->
|
||||||
<button id="btn" data-clipboard-text="1">Copy</button>
|
<div id="btn" data-clipboard-text="1">
|
||||||
|
<span>Copy</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- 2. Include library -->
|
<!-- 2. Include library -->
|
||||||
<script src="../dist/clipboard.min.js"></script>
|
<script src="../dist/clipboard.min.js"></script>
|
||||||
|
|||||||
20
dist/clipboard.js
vendored
20
dist/clipboard.js
vendored
@@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* clipboard.js v1.5.1
|
* clipboard.js v1.5.4
|
||||||
* https://zenorocha.github.io/clipboard.js
|
* https://zenorocha.github.io/clipboard.js
|
||||||
*
|
*
|
||||||
* Licensed MIT © Zeno Rocha
|
* Licensed MIT © Zeno Rocha
|
||||||
@@ -92,13 +92,9 @@ function delegate(element, selector, type, callback) {
|
|||||||
*/
|
*/
|
||||||
function listener(element, selector, type, callback) {
|
function listener(element, selector, type, callback) {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
var delegateTarget = closest(e.target, selector, true);
|
e.delegateTarget = closest(e.target, selector, true);
|
||||||
|
|
||||||
if (delegateTarget) {
|
|
||||||
Object.defineProperty(e, 'target', {
|
|
||||||
value: delegateTarget
|
|
||||||
});
|
|
||||||
|
|
||||||
|
if (e.delegateTarget) {
|
||||||
callback.call(element, e);
|
callback.call(element, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -665,15 +661,17 @@ var Clipboard = (function (_Emitter) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Clipboard.prototype.onClick = function onClick(e) {
|
Clipboard.prototype.onClick = function onClick(e) {
|
||||||
|
var trigger = e.delegateTarget || e.currentTarget;
|
||||||
|
|
||||||
if (this.clipboardAction) {
|
if (this.clipboardAction) {
|
||||||
this.clipboardAction = null;
|
this.clipboardAction = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clipboardAction = new _clipboardAction2['default']({
|
this.clipboardAction = new _clipboardAction2['default']({
|
||||||
action: this.action(e.target),
|
action: this.action(trigger),
|
||||||
target: this.target(e.target),
|
target: this.target(trigger),
|
||||||
text: this.text(e.target),
|
text: this.text(trigger),
|
||||||
trigger: e.target,
|
trigger: trigger,
|
||||||
emitter: this
|
emitter: this
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
4
dist/clipboard.min.js
vendored
4
dist/clipboard.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -3,7 +3,7 @@
|
|||||||
Package.describe({
|
Package.describe({
|
||||||
name: "zenorocha:clipboard",
|
name: "zenorocha:clipboard",
|
||||||
summary: "Modern copy to clipboard. No Flash. Just 2kb.",
|
summary: "Modern copy to clipboard. No Flash. Just 2kb.",
|
||||||
version: "1.5.1",
|
version: "1.5.4",
|
||||||
git: "https://github.com/zenorocha/clipboard.js"
|
git: "https://github.com/zenorocha/clipboard.js"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
31
package.json
31
package.json
@@ -1,34 +1,24 @@
|
|||||||
{
|
{
|
||||||
"name": "clipboard",
|
"name": "clipboard",
|
||||||
"version": "1.5.1",
|
"version": "1.5.4",
|
||||||
"description": "Modern copy to clipboard. No Flash. Just 2kb",
|
"description": "Modern copy to clipboard. No Flash. Just 2kb",
|
||||||
"repository": "zenorocha/clipboard.js",
|
"repository": "zenorocha/clipboard.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "dist/clipboard.js",
|
"main": "lib/clipboard.js",
|
||||||
"browser": "src/clipboard.js",
|
|
||||||
"browserify": {
|
|
||||||
"transform": [
|
|
||||||
[
|
|
||||||
"babelify",
|
|
||||||
{
|
|
||||||
"loose": "all"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"clipboard",
|
"clipboard",
|
||||||
"copy",
|
"copy",
|
||||||
"cut"
|
"cut"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babelify": "^6.3.0",
|
"good-listener": "^1.1.4",
|
||||||
"browserify": "^11.2.0",
|
|
||||||
"good-listener": "^1.1.2",
|
|
||||||
"select": "^1.0.4",
|
"select": "^1.0.4",
|
||||||
"tiny-emitter": "^1.0.0"
|
"tiny-emitter": "^1.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel": "^5.8.29",
|
||||||
|
"babelify": "^6.3.0",
|
||||||
|
"browserify": "^11.2.0",
|
||||||
"karma": "^0.13.10",
|
"karma": "^0.13.10",
|
||||||
"karma-browserify": "^4.4.0",
|
"karma-browserify": "^4.4.0",
|
||||||
"karma-chai": "^0.1.0",
|
"karma-chai": "^0.1.0",
|
||||||
@@ -43,11 +33,10 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npm run build-debug && npm run build-min",
|
"build": "npm run build-debug && npm run build-min",
|
||||||
"build-debug": "browserify src/clipboard.js -s Clipboard -p [bannerify --file .banner ] -o dist/clipboard.js",
|
"build-debug": "browserify src/clipboard.js -s Clipboard -t [babelify --loose all] -p [bannerify --file .banner ] -o dist/clipboard.js",
|
||||||
"build-min": "uglifyjs dist/clipboard.js --comments '/!/' -m screw_ie8=true -c screw_ie8=true,unused=false -o dist/clipboard.min.js",
|
"build-min": "uglifyjs dist/clipboard.js --comments '/!/' -m screw_ie8=true -c screw_ie8=true,unused=false -o dist/clipboard.min.js",
|
||||||
"build-watch": "watchify src/clipboard.js -s Clipboard -o dist/clipboard.js -v",
|
"build-watch": "watchify src/clipboard.js -s Clipboard -t [babelify --loose all] -o dist/clipboard.js -v",
|
||||||
"test": "npm run test-browser && npm run test-server",
|
"test": "karma start --single-run",
|
||||||
"test-browser": "karma start --single-run",
|
"prepublish": "babel src --out-dir lib --loose all"
|
||||||
"test-server": "mocha test/module-systems.js"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,15 +42,17 @@ class Clipboard extends Emitter {
|
|||||||
* @param {Event} e
|
* @param {Event} e
|
||||||
*/
|
*/
|
||||||
onClick(e) {
|
onClick(e) {
|
||||||
|
var trigger = e.delegateTarget || e.currentTarget;
|
||||||
|
|
||||||
if (this.clipboardAction) {
|
if (this.clipboardAction) {
|
||||||
this.clipboardAction = null;
|
this.clipboardAction = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.clipboardAction = new ClipboardAction({
|
this.clipboardAction = new ClipboardAction({
|
||||||
action : this.action(e.target),
|
action : this.action(trigger),
|
||||||
target : this.target(e.target),
|
target : this.target(trigger),
|
||||||
text : this.text(e.target),
|
text : this.text(trigger),
|
||||||
trigger : e.target,
|
trigger : trigger,
|
||||||
emitter : this
|
emitter : this
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,14 @@ describe('Clipboard', () => {
|
|||||||
global.button.setAttribute('data-clipboard-text', 'foo');
|
global.button.setAttribute('data-clipboard-text', 'foo');
|
||||||
document.body.appendChild(global.button);
|
document.body.appendChild(global.button);
|
||||||
|
|
||||||
|
global.span = document.createElement('span');
|
||||||
|
global.span.innerHTML = 'bar';
|
||||||
|
|
||||||
|
global.button.appendChild(span);
|
||||||
|
|
||||||
global.event = {
|
global.event = {
|
||||||
target: global.button
|
target: global.button,
|
||||||
|
currentTarget: global.button
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -63,6 +69,14 @@ describe('Clipboard', () => {
|
|||||||
assert.instanceOf(clipboard.clipboardAction, ClipboardAction);
|
assert.instanceOf(clipboard.clipboardAction, ClipboardAction);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should use an event\'s currentTarget when not equal to target', () => {
|
||||||
|
let clipboard = new Clipboard('.btn');
|
||||||
|
let bubbledEvent = { target: global.span, currentTarget: global.button };
|
||||||
|
|
||||||
|
clipboard.onClick(bubbledEvent);
|
||||||
|
assert.instanceOf(clipboard.clipboardAction, ClipboardAction);
|
||||||
|
});
|
||||||
|
|
||||||
it('should throws exception target', done => {
|
it('should throws exception target', done => {
|
||||||
try {
|
try {
|
||||||
var clipboard = new Clipboard('.btn', {
|
var clipboard = new Clipboard('.btn', {
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
var assert = require('chai').assert;
|
|
||||||
var browserify = require('browserify');
|
|
||||||
|
|
||||||
describe('CommonJS', function() {
|
|
||||||
it('should import the lib in a commonjs env without babel', function(done) {
|
|
||||||
browserify('./dist/clipboard.js').bundle(function(err) {
|
|
||||||
assert.equal(err, null);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('AMD', function() {
|
|
||||||
// TODO: Write test case
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user