mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Adds minify task
This commit is contained in:
parent
d682f4a3d4
commit
8780d3c6bb
65
dist/clipboard.js
vendored
65
dist/clipboard.js
vendored
@ -1,65 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
||||
|
||||
var Clipboard = (function () {
|
||||
|
||||
// Constructor
|
||||
|
||||
function Clipboard(triggers) {
|
||||
_classCallCheck(this, Clipboard);
|
||||
|
||||
this._triggers = triggers;
|
||||
this.init();
|
||||
}
|
||||
|
||||
// Getters & Setters
|
||||
|
||||
_createClass(Clipboard, [{
|
||||
key: 'init',
|
||||
|
||||
// Methods
|
||||
|
||||
value: function init() {
|
||||
[].forEach.call(this.triggers, this.bind);
|
||||
}
|
||||
}, {
|
||||
key: 'bind',
|
||||
value: function bind(trigger) {
|
||||
trigger.addEventListener('click', function (e) {
|
||||
var value = e.currentTarget.getAttribute('value') || '';
|
||||
var targetSelector = e.currentTarget.getAttribute('for');
|
||||
var target = document.getElementById(targetSelector);
|
||||
|
||||
if (target.nodeName === 'INPUT' || target.nodeName === 'TEXTAREA') {
|
||||
target.select();
|
||||
} else {
|
||||
var range = document.createRange();
|
||||
range.selectNode(target);
|
||||
window.getSelection().addRange(range);
|
||||
}
|
||||
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
window.getSelection().removeAllRanges();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'triggers',
|
||||
get: function get() {
|
||||
return document.querySelectorAll(this._triggers);
|
||||
},
|
||||
set: function set(val) {
|
||||
return this._triggers = val;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Clipboard;
|
||||
})();
|
@ -13,10 +13,12 @@
|
||||
<button class="btn" for="target" type="button">Copy</button>
|
||||
</form>
|
||||
|
||||
<script src="dist/clipboard.js"></script>
|
||||
<script src="dist/clipboard.min.js"></script>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
new Clipboard('.btn');
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -4,10 +4,13 @@
|
||||
"description": "A modern approach to copy to the clipboard",
|
||||
"main": "src/clipboard.js",
|
||||
"dependencies": {
|
||||
"babel": "^5.8.23"
|
||||
"babel": "^5.8.23",
|
||||
"uglify": "^0.1.5"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel src/clipboard.js --out-file dist/clipboard.js",
|
||||
"watch": "babel src/clipboard.js --out-file dist/clipboard.js --watch"
|
||||
"start" : "npm run build && npm run minify",
|
||||
"build" : "babel src/clipboard.js --out-file dist/clipboard.min.js",
|
||||
"watch" : "babel src/clipboard.js --out-file dist/clipboard.min.js --watch",
|
||||
"minify": "uglify -s dist/clipboard.min.js -o dist/clipboard.min.js"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user