Release v1.3.1

This commit is contained in:
Zeno Rocha
2015-09-29 22:35:01 -07:00
parent 3c414a6b2e
commit 1539bba290
4 changed files with 83 additions and 46 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "clipboard", "name": "clipboard",
"version": "1.3.0", "version": "1.3.1",
"description": "Modern copy to clipboard. No Flash. Just 2kb", "description": "Modern copy to clipboard. No Flash. Just 2kb",
"license": "MIT", "license": "MIT",
"main": "src/clipboard.js", "main": "src/clipboard.js",

123
dist/clipboard.js vendored
View File

@ -207,7 +207,8 @@ module.exports = E;
},{}],6:[function(require,module,exports){ },{}],6:[function(require,module,exports){
/** /**
* Inner class which performs selection and copy operations. * Inner class which performs selection from either `text` or `target`
* properties and then executes copy or cut operations.
*/ */
'use strict'; 'use strict';
@ -219,13 +220,24 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var ClipboardAction = (function () { var ClipboardAction = (function () {
/** /**
* Initializes selection from either `text` or `target` property.
* @param {Object} options * @param {Object} options
*/ */
function ClipboardAction(options) { function ClipboardAction(options) {
_classCallCheck(this, ClipboardAction); _classCallCheck(this, ClipboardAction);
this.resolveOptions(options);
this.initSelection();
}
/**
* Defines base properties passed from constructor.
* @param {Object} options
*/
ClipboardAction.prototype.resolveOptions = 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;
this.target = options.target; this.target = options.target;
@ -233,7 +245,14 @@ var ClipboardAction = (function () {
this.trigger = options.trigger; this.trigger = options.trigger;
this.selectedText = ''; this.selectedText = '';
};
/**
* Decides which selection strategy is going to be applied based
* on the existence of `text` and `target` properties.
*/
ClipboardAction.prototype.initSelection = function initSelection() {
if (this.text && this.target) { if (this.text && this.target) {
throw new Error('Multiple attributes declared, use either "target" or "text"'); throw new Error('Multiple attributes declared, use either "target" or "text"');
} else if (this.text) { } else if (this.text) {
@ -243,7 +262,7 @@ var ClipboardAction = (function () {
} else { } else {
throw new Error('Missing required attributes, use either "target" or "text"'); throw new Error('Missing required attributes, use either "target" or "text"');
} }
} };
/** /**
* Creates a fake input element, sets its value from `text` property, * Creates a fake input element, sets its value from `text` property,
@ -366,8 +385,10 @@ var ClipboardAction = (function () {
_createClass(ClipboardAction, [{ _createClass(ClipboardAction, [{
key: 'action', key: 'action',
set: function set(action) { set: function set() {
this._action = action || 'copy'; var action = arguments.length <= 0 || arguments[0] === undefined ? 'copy' : arguments[0];
this._action = action;
if (this._action !== 'copy' && this._action !== 'cut') { if (this._action !== 'copy' && this._action !== 'cut') {
throw new Error('Invalid "action" value, use either "copy" or "cut"'); throw new Error('Invalid "action" value, use either "copy" or "cut"');
@ -383,8 +404,8 @@ var ClipboardAction = (function () {
} }
/** /**
* Sets the `target` property using an element that will be have its content * Sets the `target` property using an element
* copied. * that will be have its content copied.
* @param {Element} target * @param {Element} target
*/ */
}, { }, {
@ -448,33 +469,27 @@ var Clipboard = (function (_Emitter) {
_inherits(Clipboard, _Emitter); _inherits(Clipboard, _Emitter);
/** /**
* Delegates a click event on the passed selector.
* @param {String} selector * @param {String} selector
* @param {Object} options * @param {Object} options
*/ */
function Clipboard(selector, options) { function Clipboard(selector, options) {
var _this = this;
_classCallCheck(this, Clipboard); _classCallCheck(this, Clipboard);
_Emitter.call(this); _Emitter.call(this);
this.resolveOptions(options); this.resolveOptions(options);
this.delegateClick(selector);
_delegateEvents2['default'].bind(document.body, selector, 'click', function (e) {
return _this.initialize(e);
});
} }
/** /**
* Defines if attributes would be resolved using an internal setter function * Defines if attributes would be resolved using internal setter functions
* or a custom function that was passed in the constructor. * or custom functions that were passed in the constructor.
* @param {Object} options * @param {Object} options
*/ */
Clipboard.prototype.resolveOptions = function resolveOptions(options) { Clipboard.prototype.resolveOptions = function resolveOptions() {
options = options || {}; var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
this.action = typeof options.action === 'function' ? options.action : this.setAction; this.action = typeof options.action === 'function' ? options.action : this.setAction;
this.target = typeof options.target === 'function' ? options.target : this.setTarget; this.target = typeof options.target === 'function' ? options.target : this.setTarget;
@ -482,34 +497,16 @@ var Clipboard = (function (_Emitter) {
}; };
/** /**
* Sets the `action` lookup function. * Delegates a click event on the passed selector.
* @param {Element} trigger * @param {String} selector
*/ */
Clipboard.prototype.setAction = function setAction(trigger) { Clipboard.prototype.delegateClick = function delegateClick(selector) {
return trigger.getAttribute(prefix + 'action'); var _this = this;
};
/** _delegateEvents2['default'].bind(document.body, selector, 'click', function (e) {
* Sets the `target` lookup function. return _this.initialize(e);
* @param {Element} trigger });
*/
Clipboard.prototype.setTarget = function setTarget(trigger) {
var target = trigger.getAttribute(prefix + 'target');
if (target) {
return document.querySelector(target);
}
};
/**
* Sets the `text` lookup function.
* @param {Element} trigger
*/
Clipboard.prototype.setText = function setText(trigger) {
return trigger.getAttribute(prefix + 'text');
}; };
/** /**
@ -531,6 +528,46 @@ var Clipboard = (function (_Emitter) {
}); });
}; };
/**
* Sets the `action` lookup function.
* @param {Element} trigger
*/
Clipboard.prototype.setAction = function setAction(trigger) {
if (!trigger.hasAttribute(prefix + 'action')) {
return;
}
return trigger.getAttribute(prefix + 'action');
};
/**
* Sets the `target` lookup function.
* @param {Element} trigger
*/
Clipboard.prototype.setTarget = function setTarget(trigger) {
if (!trigger.hasAttribute(prefix + 'target')) {
return;
}
var target = trigger.getAttribute(prefix + 'target');
return document.querySelector(target);
};
/**
* Sets the `text` lookup function.
* @param {Element} trigger
*/
Clipboard.prototype.setText = function setText(trigger) {
if (!trigger.hasAttribute(prefix + 'text')) {
return;
}
return trigger.getAttribute(prefix + 'text');
};
return Clipboard; return Clipboard;
})(_tinyEmitter2['default']); })(_tinyEmitter2['default']);

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "clipboard", "name": "clipboard",
"version": "1.3.0", "version": "1.3.1",
"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",
"main": "dist/clipboard.js", "main": "dist/clipboard.js",