vendor/assets/javascripts/clipboard.js in clipboard-rails-1.5.13 vs vendor/assets/javascripts/clipboard.js in clipboard-rails-1.5.15
- old
+ new
@@ -1,128 +1,45 @@
/*!
- * clipboard.js v1.5.13
+ * clipboard.js v1.5.15
* https://zenorocha.github.io/clipboard.js
*
* 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){
/**
- * Module Dependencies
+ * A polyfill for Element.matches()
*/
+if (Element && !Element.prototype.matches) {
+ var proto = Element.prototype;
-try {
- var matches = require('matches-selector')
-} catch (err) {
- var matches = require('component-matches-selector')
+ proto.matches = proto.matchesSelector ||
+ proto.mozMatchesSelector ||
+ proto.msMatchesSelector ||
+ proto.oMatchesSelector ||
+ proto.webkitMatchesSelector;
}
/**
- * Export `closest`
- */
-
-module.exports = closest
-
-/**
- * Closest
+ * Finds the closest parent that matches a selector.
*
- * @param {Element} el
+ * @param {Element} element
* @param {String} selector
- * @param {Element} scope (optional)
+ * @return {Function}
*/
-
-function closest (el, selector, scope) {
- scope = scope || document.documentElement;
-
- // walk up the dom
- while (el && el !== scope) {
- if (matches(el, selector)) return el;
- el = el.parentNode;
- }
-
- // check scope for match
- return matches(el, selector) ? el : null;
+function closest (element, selector) {
+ while (element && element !== document) {
+ if (element.matches(selector)) return element;
+ element = element.parentNode;
+ }
}
-},{"component-matches-selector":2,"matches-selector":2}],2:[function(require,module,exports){
-/**
- * Module dependencies.
- */
+module.exports = closest;
-try {
- var query = require('query');
-} catch (err) {
- var query = require('component-query');
-}
+},{}],2:[function(require,module,exports){
+var closest = require('./closest');
/**
- * Element prototype.
- */
-
-var proto = Element.prototype;
-
-/**
- * Vendor function.
- */
-
-var vendor = proto.matches
- || 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 (!el || el.nodeType !== 1) return false;
- if (vendor) return vendor.call(el, selector);
- var nodes = query.all(selector, el.parentNode);
- for (var i = 0; i < nodes.length; ++i) {
- if (nodes[i] == el) return true;
- }
- return false;
-}
-
-},{"component-query":3,"query":3}],3:[function(require,module,exports){
-function one(selector, el) {
- return el.querySelector(selector);
-}
-
-exports = module.exports = function(selector, el){
- el = el || document;
- return one(selector, el);
-};
-
-exports.all = function(selector, el){
- el = el || document;
- return el.querySelectorAll(selector);
-};
-
-exports.engine = function(obj){
- if (!obj.one) throw new Error('.one callback required');
- if (!obj.all) throw new Error('.all callback required');
- one = obj.one;
- exports.all = obj.all;
- return exports;
-};
-
-},{}],4:[function(require,module,exports){
-var closest = require('component-closest');
-
-/**
* Delegates event to a selector.
*
* @param {Element} element
* @param {String} selector
* @param {String} type
@@ -151,21 +68,21 @@
* @param {Function} callback
* @return {Function}
*/
function listener(element, selector, type, callback) {
return function(e) {
- e.delegateTarget = closest(e.target, selector, true);
+ e.delegateTarget = closest(e.target, selector);
if (e.delegateTarget) {
callback.call(element, e);
}
}
}
module.exports = delegate;
-},{"component-closest":1}],5:[function(require,module,exports){
+},{"./closest":1}],3:[function(require,module,exports){
/**
* Check if argument is a HTML element.
*
* @param {Object} value
* @return {Boolean}
@@ -212,11 +129,11 @@
var type = Object.prototype.toString.call(value);
return type === '[object Function]';
};
-},{}],6:[function(require,module,exports){
+},{}],4:[function(require,module,exports){
var is = require('./is');
var delegate = require('delegate');
/**
* Validates all params and calls the right
@@ -309,11 +226,11 @@
return delegate(document.body, selector, type, callback);
}
module.exports = listen;
-},{"./is":5,"delegate":4}],7:[function(require,module,exports){
+},{"./is":3,"delegate":2}],5:[function(require,module,exports){
function select(element) {
var selectedText;
if (element.nodeName === 'SELECT') {
element.focus();
@@ -344,11 +261,11 @@
return selectedText;
}
module.exports = select;
-},{}],8:[function(require,module,exports){
+},{}],6:[function(require,module,exports){
function E () {
// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
}
@@ -412,11 +329,11 @@
}
};
module.exports = E;
-},{}],9:[function(require,module,exports){
+},{}],7:[function(require,module,exports){
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(['module', 'select'], factory);
} else if (typeof exports !== "undefined") {
factory(module, require('select'));
@@ -439,11 +356,11 @@
}
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof 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) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
@@ -483,121 +400,130 @@
* Defines base properties passed from constructor.
* @param {Object} options
*/
- ClipboardAction.prototype.resolveOptions = function resolveOptions() {
- var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
+ _createClass(ClipboardAction, [{
+ key: 'resolveOptions',
+ value: function resolveOptions() {
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- this.action = options.action;
- this.emitter = options.emitter;
- this.target = options.target;
- this.text = options.text;
- this.trigger = options.trigger;
+ this.action = options.action;
+ this.emitter = options.emitter;
+ this.target = options.target;
+ this.text = options.text;
+ this.trigger = options.trigger;
- this.selectedText = '';
- };
-
- ClipboardAction.prototype.initSelection = function initSelection() {
- if (this.text) {
- this.selectFake();
- } else if (this.target) {
- this.selectTarget();
+ this.selectedText = '';
}
- };
+ }, {
+ key: 'initSelection',
+ value: function initSelection() {
+ if (this.text) {
+ this.selectFake();
+ } else if (this.target) {
+ this.selectTarget();
+ }
+ }
+ }, {
+ key: 'selectFake',
+ value: function selectFake() {
+ var _this = this;
- ClipboardAction.prototype.selectFake = function selectFake() {
- var _this = this;
+ var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
- var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
+ this.removeFake();
- this.removeFake();
+ this.fakeHandlerCallback = function () {
+ return _this.removeFake();
+ };
+ this.fakeHandler = document.body.addEventListener('click', this.fakeHandlerCallback) || true;
- this.fakeHandlerCallback = function () {
- return _this.removeFake();
- };
- this.fakeHandler = document.body.addEventListener('click', this.fakeHandlerCallback) || true;
+ this.fakeElem = document.createElement('textarea');
+ // Prevent zooming on iOS
+ this.fakeElem.style.fontSize = '12pt';
+ // Reset box model
+ this.fakeElem.style.border = '0';
+ this.fakeElem.style.padding = '0';
+ this.fakeElem.style.margin = '0';
+ // Move element out of screen horizontally
+ this.fakeElem.style.position = 'absolute';
+ this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
+ // Move element to the same position vertically
+ var yPosition = window.pageYOffset || document.documentElement.scrollTop;
+ this.fakeElem.addEventListener('focus', window.scrollTo(0, yPosition));
+ this.fakeElem.style.top = yPosition + 'px';
- this.fakeElem = document.createElement('textarea');
- // Prevent zooming on iOS
- this.fakeElem.style.fontSize = '12pt';
- // Reset box model
- this.fakeElem.style.border = '0';
- this.fakeElem.style.padding = '0';
- this.fakeElem.style.margin = '0';
- // Move element out of screen horizontally
- this.fakeElem.style.position = 'absolute';
- this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
- // Move element to the same position vertically
- var yPosition = window.pageYOffset || document.documentElement.scrollTop;
- this.fakeElem.addEventListener('focus', window.scrollTo(0, yPosition));
- this.fakeElem.style.top = yPosition + 'px';
+ this.fakeElem.setAttribute('readonly', '');
+ this.fakeElem.value = this.text;
- this.fakeElem.setAttribute('readonly', '');
- this.fakeElem.value = this.text;
+ document.body.appendChild(this.fakeElem);
- document.body.appendChild(this.fakeElem);
-
- this.selectedText = (0, _select2.default)(this.fakeElem);
- this.copyText();
- };
-
- ClipboardAction.prototype.removeFake = function removeFake() {
- if (this.fakeHandler) {
- document.body.removeEventListener('click', this.fakeHandlerCallback);
- this.fakeHandler = null;
- this.fakeHandlerCallback = null;
+ this.selectedText = (0, _select2.default)(this.fakeElem);
+ this.copyText();
}
+ }, {
+ key: 'removeFake',
+ value: function removeFake() {
+ if (this.fakeHandler) {
+ document.body.removeEventListener('click', this.fakeHandlerCallback);
+ this.fakeHandler = null;
+ this.fakeHandlerCallback = null;
+ }
- if (this.fakeElem) {
- document.body.removeChild(this.fakeElem);
- this.fakeElem = null;
+ if (this.fakeElem) {
+ document.body.removeChild(this.fakeElem);
+ this.fakeElem = null;
+ }
}
- };
-
- ClipboardAction.prototype.selectTarget = function selectTarget() {
- this.selectedText = (0, _select2.default)(this.target);
- this.copyText();
- };
-
- ClipboardAction.prototype.copyText = function copyText() {
- var succeeded = void 0;
-
- try {
- succeeded = document.execCommand(this.action);
- } catch (err) {
- succeeded = false;
+ }, {
+ key: 'selectTarget',
+ value: function selectTarget() {
+ this.selectedText = (0, _select2.default)(this.target);
+ this.copyText();
}
+ }, {
+ key: 'copyText',
+ value: function copyText() {
+ var succeeded = void 0;
- this.handleResult(succeeded);
- };
+ try {
+ succeeded = document.execCommand(this.action);
+ } catch (err) {
+ succeeded = false;
+ }
- ClipboardAction.prototype.handleResult = function handleResult(succeeded) {
- this.emitter.emit(succeeded ? 'success' : 'error', {
- action: this.action,
- text: this.selectedText,
- trigger: this.trigger,
- clearSelection: this.clearSelection.bind(this)
- });
- };
-
- ClipboardAction.prototype.clearSelection = function clearSelection() {
- if (this.target) {
- this.target.blur();
+ this.handleResult(succeeded);
}
+ }, {
+ key: 'handleResult',
+ value: function handleResult(succeeded) {
+ this.emitter.emit(succeeded ? 'success' : 'error', {
+ action: this.action,
+ text: this.selectedText,
+ trigger: this.trigger,
+ clearSelection: this.clearSelection.bind(this)
+ });
+ }
+ }, {
+ key: 'clearSelection',
+ value: function clearSelection() {
+ if (this.target) {
+ this.target.blur();
+ }
- window.getSelection().removeAllRanges();
- };
-
- ClipboardAction.prototype.destroy = function destroy() {
- this.removeFake();
- };
-
- _createClass(ClipboardAction, [{
+ window.getSelection().removeAllRanges();
+ }
+ }, {
+ key: 'destroy',
+ value: function destroy() {
+ this.removeFake();
+ }
+ }, {
key: 'action',
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;
if (this._action !== 'copy' && this._action !== 'cut') {
throw new Error('Invalid "action" value, use either "copy" or "cut"');
@@ -634,11 +560,11 @@
}();
module.exports = ClipboardAction;
});
-},{"select":7}],10:[function(require,module,exports){
+},{"select":5}],8:[function(require,module,exports){
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory);
} else if (typeof exports !== "undefined") {
factory(module, require('./clipboard-action'), require('tiny-emitter'), require('good-listener'));
@@ -668,10 +594,28 @@
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
+ 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) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
@@ -702,11 +646,11 @@
* @param {Object} options
*/
function Clipboard(trigger, options) {
_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.listenClick(trigger);
return _this;
}
@@ -716,66 +660,75 @@
* or custom functions that were passed in the constructor.
* @param {Object} options
*/
- Clipboard.prototype.resolveOptions = function resolveOptions() {
- var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
+ _createClass(Clipboard, [{
+ 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.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
- this.text = typeof options.text === 'function' ? options.text : this.defaultText;
- };
+ this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
+ this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
+ this.text = typeof options.text === 'function' ? options.text : this.defaultText;
+ }
+ }, {
+ key: 'listenClick',
+ value: function listenClick(trigger) {
+ var _this2 = this;
- Clipboard.prototype.listenClick = function listenClick(trigger) {
- var _this2 = this;
+ this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) {
+ return _this2.onClick(e);
+ });
+ }
+ }, {
+ key: 'onClick',
+ value: function onClick(e) {
+ var trigger = e.delegateTarget || e.currentTarget;
- this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) {
- return _this2.onClick(e);
- });
- };
+ if (this.clipboardAction) {
+ this.clipboardAction = null;
+ }
- Clipboard.prototype.onClick = function onClick(e) {
- var trigger = e.delegateTarget || e.currentTarget;
-
- if (this.clipboardAction) {
- this.clipboardAction = null;
+ this.clipboardAction = new _clipboardAction2.default({
+ action: this.action(trigger),
+ target: this.target(trigger),
+ text: this.text(trigger),
+ trigger: trigger,
+ emitter: this
+ });
}
+ }, {
+ key: 'defaultAction',
+ value: function defaultAction(trigger) {
+ return getAttributeValue('action', trigger);
+ }
+ }, {
+ key: 'defaultTarget',
+ value: function defaultTarget(trigger) {
+ var selector = getAttributeValue('target', trigger);
- this.clipboardAction = new _clipboardAction2.default({
- action: this.action(trigger),
- target: this.target(trigger),
- text: this.text(trigger),
- trigger: trigger,
- emitter: this
- });
- };
-
- Clipboard.prototype.defaultAction = function defaultAction(trigger) {
- return getAttributeValue('action', trigger);
- };
-
- Clipboard.prototype.defaultTarget = function defaultTarget(trigger) {
- var selector = getAttributeValue('target', trigger);
-
- if (selector) {
- return document.querySelector(selector);
+ if (selector) {
+ return document.querySelector(selector);
+ }
}
- };
+ }, {
+ key: 'defaultText',
+ value: function defaultText(trigger) {
+ return getAttributeValue('text', trigger);
+ }
+ }, {
+ key: 'destroy',
+ value: function destroy() {
+ this.listener.destroy();
- Clipboard.prototype.defaultText = function defaultText(trigger) {
- return getAttributeValue('text', trigger);
- };
-
- Clipboard.prototype.destroy = function destroy() {
- this.listener.destroy();
-
- if (this.clipboardAction) {
- this.clipboardAction.destroy();
- this.clipboardAction = null;
+ if (this.clipboardAction) {
+ this.clipboardAction.destroy();
+ this.clipboardAction = null;
+ }
}
- };
+ }]);
return Clipboard;
}(_tinyEmitter2.default);
/**
@@ -794,7 +747,7 @@
}
module.exports = Clipboard;
});
-},{"./clipboard-action":9,"good-listener":6,"tiny-emitter":8}]},{},[10])(10)
+},{"./clipboard-action":7,"good-listener":4,"tiny-emitter":6}]},{},[8])(8)
});
\ No newline at end of file