Update clipboard.js

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2017-03-29 00:26:05 +02:00
parent 2c682ad34d
commit e8d068af1e
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 249 additions and 213 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "clipboard", "name": "clipboard",
"version": "1.5.12", "version": "1.6.1",
"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",
@ -20,11 +20,11 @@
"cut" "cut"
], ],
"homepage": "https://github.com/zenorocha/clipboard.js", "homepage": "https://github.com/zenorocha/clipboard.js",
"_release": "1.5.12", "_release": "1.6.1",
"_resolution": { "_resolution": {
"type": "version", "type": "version",
"tag": "v1.5.12", "tag": "v1.6.1",
"commit": "eb7418b51bb3c963893d83954c5cfa4de3f7f527" "commit": "f59d4e6b4db55b0f462eeb96fb74db3469e0765d"
}, },
"_source": "https://github.com/zenorocha/clipboard.js.git", "_source": "https://github.com/zenorocha/clipboard.js.git",
"_target": "^1.5.12", "_target": "^1.5.12",

View File

@ -1,23 +1,43 @@
/*! /*!
* clipboard.js v1.5.12 * clipboard.js v1.6.1
* https://zenorocha.github.io/clipboard.js * https://zenorocha.github.io/clipboard.js
* *
* Licensed MIT © Zeno Rocha * Licensed MIT © Zeno Rocha
*/ */
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var matches = require('matches-selector') var DOCUMENT_NODE_TYPE = 9;
module.exports = function (element, selector, checkYoSelf) { /**
var parent = checkYoSelf ? element : element.parentNode * A polyfill for Element.matches()
*/
if (typeof Element !== 'undefined' && !Element.prototype.matches) {
var proto = Element.prototype;
while (parent && parent !== document) { proto.matches = proto.matchesSelector ||
if (matches(parent, selector)) return parent; proto.mozMatchesSelector ||
parent = parent.parentNode proto.msMatchesSelector ||
proto.oMatchesSelector ||
proto.webkitMatchesSelector;
}
/**
* Finds the closest parent that matches a selector.
*
* @param {Element} element
* @param {String} selector
* @return {Function}
*/
function closest (element, selector) {
while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {
if (element.matches(selector)) return element;
element = element.parentNode;
} }
} }
},{"matches-selector":5}],2:[function(require,module,exports){ module.exports = closest;
var closest = require('closest');
},{}],2:[function(require,module,exports){
var closest = require('./closest');
/** /**
* Delegates event to a selector. * Delegates event to a selector.
@ -52,7 +72,7 @@ function delegate(element, selector, type, callback, useCapture) {
*/ */
function listener(element, selector, type, callback) { function listener(element, selector, type, callback) {
return function(e) { return function(e) {
e.delegateTarget = closest(e.target, selector, true); e.delegateTarget = closest(e.target, selector);
if (e.delegateTarget) { if (e.delegateTarget) {
callback.call(element, e); callback.call(element, e);
@ -62,7 +82,7 @@ function listener(element, selector, type, callback) {
module.exports = delegate; module.exports = delegate;
},{"closest":1}],3:[function(require,module,exports){ },{"./closest":1}],3:[function(require,module,exports){
/** /**
* Check if argument is a HTML element. * Check if argument is a HTML element.
* *
@ -211,54 +231,28 @@ function listenSelector(selector, type, callback) {
module.exports = listen; module.exports = listen;
},{"./is":3,"delegate":2}],5:[function(require,module,exports){ },{"./is":3,"delegate":2}],5:[function(require,module,exports){
/**
* Element prototype.
*/
var proto = Element.prototype;
/**
* Vendor function.
*/
var vendor = proto.matchesSelector
|| proto.webkitMatchesSelector
|| proto.mozMatchesSelector
|| proto.msMatchesSelector
|| proto.oMatchesSelector;
/**
* Expose `match()`.
*/
module.exports = match;
/**
* Match `el` to `selector`.
*
* @param {Element} el
* @param {String} selector
* @return {Boolean}
* @api public
*/
function match(el, selector) {
if (vendor) return vendor.call(el, selector);
var nodes = el.parentNode.querySelectorAll(selector);
for (var i = 0; i < nodes.length; ++i) {
if (nodes[i] == el) return true;
}
return false;
}
},{}],6:[function(require,module,exports){
function select(element) { function select(element) {
var selectedText; var selectedText;
if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') { if (element.nodeName === 'SELECT') {
element.focus(); element.focus();
selectedText = element.value;
}
else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
var isReadOnly = element.hasAttribute('readonly');
if (!isReadOnly) {
element.setAttribute('readonly', '');
}
element.select();
element.setSelectionRange(0, element.value.length); element.setSelectionRange(0, element.value.length);
if (!isReadOnly) {
element.removeAttribute('readonly');
}
selectedText = element.value; selectedText = element.value;
} }
else { else {
@ -281,7 +275,7 @@ function select(element) {
module.exports = select; module.exports = select;
},{}],7:[function(require,module,exports){ },{}],6:[function(require,module,exports){
function E () { function E () {
// Keep this empty so it's easier to inherit from // Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
@ -349,7 +343,7 @@ E.prototype = {
module.exports = E; module.exports = E;
},{}],8:[function(require,module,exports){ },{}],7:[function(require,module,exports){
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(['module', 'select'], factory); define(['module', 'select'], factory);
@ -376,7 +370,7 @@ module.exports = E;
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj; return typeof obj;
} : function (obj) { } : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}; };
function _classCallCheck(instance, Constructor) { function _classCallCheck(instance, Constructor) {
@ -407,7 +401,6 @@ module.exports = E;
/** /**
* @param {Object} options * @param {Object} options
*/ */
function ClipboardAction(options) { function ClipboardAction(options) {
_classCallCheck(this, ClipboardAction); _classCallCheck(this, ClipboardAction);
@ -421,8 +414,10 @@ module.exports = E;
*/ */
ClipboardAction.prototype.resolveOptions = function resolveOptions() { _createClass(ClipboardAction, [{
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; key: 'resolveOptions',
value: function resolveOptions() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
this.action = options.action; this.action = options.action;
this.emitter = options.emitter; this.emitter = options.emitter;
@ -431,17 +426,19 @@ module.exports = E;
this.trigger = options.trigger; this.trigger = options.trigger;
this.selectedText = ''; this.selectedText = '';
}; }
}, {
ClipboardAction.prototype.initSelection = function initSelection() { key: 'initSelection',
value: function initSelection() {
if (this.text) { if (this.text) {
this.selectFake(); this.selectFake();
} else if (this.target) { } else if (this.target) {
this.selectTarget(); this.selectTarget();
} }
}; }
}, {
ClipboardAction.prototype.selectFake = function selectFake() { key: 'selectFake',
value: function selectFake() {
var _this = this; var _this = this;
var isRTL = document.documentElement.getAttribute('dir') == 'rtl'; var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
@ -464,7 +461,9 @@ module.exports = E;
this.fakeElem.style.position = 'absolute'; this.fakeElem.style.position = 'absolute';
this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px'; this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
// Move element to the same position vertically // Move element to the same position vertically
this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px'; var yPosition = window.pageYOffset || document.documentElement.scrollTop;
this.fakeElem.style.top = yPosition + 'px';
this.fakeElem.setAttribute('readonly', ''); this.fakeElem.setAttribute('readonly', '');
this.fakeElem.value = this.text; this.fakeElem.value = this.text;
@ -472,9 +471,10 @@ module.exports = E;
this.selectedText = (0, _select2.default)(this.fakeElem); this.selectedText = (0, _select2.default)(this.fakeElem);
this.copyText(); this.copyText();
}; }
}, {
ClipboardAction.prototype.removeFake = function removeFake() { key: 'removeFake',
value: function removeFake() {
if (this.fakeHandler) { if (this.fakeHandler) {
document.body.removeEventListener('click', this.fakeHandlerCallback); document.body.removeEventListener('click', this.fakeHandlerCallback);
this.fakeHandler = null; this.fakeHandler = null;
@ -485,15 +485,17 @@ module.exports = E;
document.body.removeChild(this.fakeElem); document.body.removeChild(this.fakeElem);
this.fakeElem = null; this.fakeElem = null;
} }
}; }
}, {
ClipboardAction.prototype.selectTarget = function selectTarget() { key: 'selectTarget',
value: function selectTarget() {
this.selectedText = (0, _select2.default)(this.target); this.selectedText = (0, _select2.default)(this.target);
this.copyText(); this.copyText();
}; }
}, {
ClipboardAction.prototype.copyText = function copyText() { key: 'copyText',
var succeeded = undefined; value: function copyText() {
var succeeded = void 0;
try { try {
succeeded = document.execCommand(this.action); succeeded = document.execCommand(this.action);
@ -502,41 +504,35 @@ module.exports = E;
} }
this.handleResult(succeeded); this.handleResult(succeeded);
}; }
}, {
ClipboardAction.prototype.handleResult = function handleResult(succeeded) { key: 'handleResult',
if (succeeded) { value: function handleResult(succeeded) {
this.emitter.emit('success', { this.emitter.emit(succeeded ? 'success' : 'error', {
action: this.action, action: this.action,
text: this.selectedText, text: this.selectedText,
trigger: this.trigger, trigger: this.trigger,
clearSelection: this.clearSelection.bind(this) clearSelection: this.clearSelection.bind(this)
}); });
} else {
this.emitter.emit('error', {
action: this.action,
trigger: this.trigger,
clearSelection: this.clearSelection.bind(this)
});
} }
}; }, {
key: 'clearSelection',
ClipboardAction.prototype.clearSelection = function clearSelection() { value: function clearSelection() {
if (this.target) { if (this.target) {
this.target.blur(); this.target.blur();
} }
window.getSelection().removeAllRanges(); window.getSelection().removeAllRanges();
}; }
}, {
ClipboardAction.prototype.destroy = function destroy() { key: 'destroy',
value: function destroy() {
this.removeFake(); this.removeFake();
}; }
}, {
_createClass(ClipboardAction, [{
key: 'action', key: 'action',
set: function set() { set: function set() {
var action = arguments.length <= 0 || arguments[0] === undefined ? 'copy' : arguments[0]; var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy';
this._action = action; this._action = action;
@ -577,7 +573,7 @@ module.exports = E;
module.exports = ClipboardAction; module.exports = ClipboardAction;
}); });
},{"select":6}],9:[function(require,module,exports){ },{"select":5}],8:[function(require,module,exports){
(function (global, factory) { (function (global, factory) {
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
define(['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory); define(['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory);
@ -611,6 +607,24 @@ module.exports = E;
} }
} }
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 _possibleConstructorReturn(self, call) { function _possibleConstructorReturn(self, call) {
if (!self) { if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@ -642,11 +656,10 @@ module.exports = E;
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
* @param {Object} options * @param {Object} options
*/ */
function Clipboard(trigger, options) { function Clipboard(trigger, options) {
_classCallCheck(this, Clipboard); _classCallCheck(this, Clipboard);
var _this = _possibleConstructorReturn(this, _Emitter.call(this)); var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this));
_this.resolveOptions(options); _this.resolveOptions(options);
_this.listenClick(trigger); _this.listenClick(trigger);
@ -660,23 +673,27 @@ module.exports = E;
*/ */
Clipboard.prototype.resolveOptions = function resolveOptions() { _createClass(Clipboard, [{
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; key: 'resolveOptions',
value: function resolveOptions() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
this.action = typeof options.action === 'function' ? options.action : this.defaultAction; this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
this.target = typeof options.target === 'function' ? options.target : this.defaultTarget; this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
this.text = typeof options.text === 'function' ? options.text : this.defaultText; this.text = typeof options.text === 'function' ? options.text : this.defaultText;
}; }
}, {
Clipboard.prototype.listenClick = function listenClick(trigger) { key: 'listenClick',
value: function listenClick(trigger) {
var _this2 = this; var _this2 = this;
this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) { this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) {
return _this2.onClick(e); return _this2.onClick(e);
}); });
}; }
}, {
Clipboard.prototype.onClick = function onClick(e) { key: 'onClick',
value: function onClick(e) {
var trigger = e.delegateTarget || e.currentTarget; var trigger = e.delegateTarget || e.currentTarget;
if (this.clipboardAction) { if (this.clipboardAction) {
@ -690,32 +707,51 @@ module.exports = E;
trigger: trigger, trigger: trigger,
emitter: this emitter: this
}); });
}; }
}, {
Clipboard.prototype.defaultAction = function defaultAction(trigger) { key: 'defaultAction',
value: function defaultAction(trigger) {
return getAttributeValue('action', trigger); return getAttributeValue('action', trigger);
}; }
}, {
Clipboard.prototype.defaultTarget = function defaultTarget(trigger) { key: 'defaultTarget',
value: function defaultTarget(trigger) {
var selector = getAttributeValue('target', trigger); var selector = getAttributeValue('target', trigger);
if (selector) { if (selector) {
return document.querySelector(selector); return document.querySelector(selector);
} }
}; }
}, {
Clipboard.prototype.defaultText = function defaultText(trigger) { key: 'defaultText',
value: function defaultText(trigger) {
return getAttributeValue('text', trigger); return getAttributeValue('text', trigger);
}; }
}, {
Clipboard.prototype.destroy = function destroy() { key: 'destroy',
value: function destroy() {
this.listener.destroy(); this.listener.destroy();
if (this.clipboardAction) { if (this.clipboardAction) {
this.clipboardAction.destroy(); this.clipboardAction.destroy();
this.clipboardAction = null; this.clipboardAction = null;
} }
}; }
}], [{
key: 'isSupported',
value: function isSupported() {
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];
var actions = typeof action === 'string' ? [action] : action;
var support = !!document.queryCommandSupported;
actions.forEach(function (action) {
support = support && !!document.queryCommandSupported(action);
});
return support;
}
}]);
return Clipboard; return Clipboard;
}(_tinyEmitter2.default); }(_tinyEmitter2.default);
@ -738,5 +774,5 @@ module.exports = E;
module.exports = Clipboard; module.exports = Clipboard;
}); });
},{"./clipboard-action":8,"good-listener":4,"tiny-emitter":7}]},{},[9])(9) },{"./clipboard-action":7,"good-listener":4,"tiny-emitter":6}]},{},[8])(8)
}); });