diff --git a/dist/clipboard.js b/dist/clipboard.js deleted file mode 100644 index f471046..0000000 --- a/dist/clipboard.js +++ /dev/null @@ -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; -})(); diff --git a/index.html b/index.html index 555d495..f09e521 100644 --- a/index.html +++ b/index.html @@ -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> diff --git a/package.json b/package.json index 9e803ee..4aed12a 100644 --- a/package.json +++ b/package.json @@ -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" } }