This commit is contained in:
Jaydson Gomes 2015-10-03 23:04:35 +00:00
commit cc282b8072
3 changed files with 78 additions and 72 deletions

133
dist/clipboard.js vendored
View File

@ -51,57 +51,57 @@ exports.unbind = function(el, type, fn, capture){
};
},{"closest":2,"component-event":4}],2:[function(require,module,exports){
var matches = require('matches-selector')
module.exports = function (element, selector, checkYoSelf) {
var parent = checkYoSelf ? element : element.parentNode
while (parent && parent !== document) {
if (matches(parent, selector)) return parent;
parent = parent.parentNode
}
}
var matches = require('matches-selector')
module.exports = function (element, selector, checkYoSelf) {
var parent = checkYoSelf ? element : element.parentNode
while (parent && parent !== document) {
if (matches(parent, selector)) return parent;
parent = parent.parentNode
}
}
},{"matches-selector":3}],3:[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;
/**
* 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;
}
},{}],4:[function(require,module,exports){
var bind = window.addEventListener ? 'addEventListener' : 'attachEvent',
@ -148,12 +148,12 @@ function E () {
E.prototype = {
on: function (name, callback, ctx) {
var e = this.e || (this.e = {});
(e[name] || (e[name] = [])).push({
fn: callback,
ctx: ctx
});
return this;
},
@ -163,7 +163,7 @@ E.prototype = {
self.off(name, fn);
callback.apply(ctx, arguments);
};
return this.on(name, fn, ctx);
},
@ -172,11 +172,11 @@ E.prototype = {
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
var i = 0;
var len = evtArr.length;
for (i; i < len; i++) {
evtArr[i].fn.apply(evtArr[i].ctx, data);
}
return this;
},
@ -184,21 +184,21 @@ E.prototype = {
var e = this.e || (this.e = {});
var evts = e[name];
var liveEvents = [];
if (evts && callback) {
for (var i = 0, len = evts.length; i < len; i++) {
if (evts[i].fn !== callback) liveEvents.push(evts[i]);
}
}
// Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
(liveEvents.length)
(liveEvents.length)
? e[name] = liveEvents
: delete e[name];
return this;
}
};
@ -534,11 +534,12 @@ var Clipboard = (function (_Emitter) {
*/
Clipboard.prototype.setAction = function setAction(trigger) {
if (!trigger.hasAttribute(prefix + 'action')) {
var attr = prefix + 'action';
if (!trigger.hasAttribute(attr)) {
return;
}
return trigger.getAttribute(prefix + 'action');
return trigger.getAttribute(attr);
};
/**
@ -547,11 +548,12 @@ var Clipboard = (function (_Emitter) {
*/
Clipboard.prototype.setTarget = function setTarget(trigger) {
if (!trigger.hasAttribute(prefix + 'target')) {
var attr = prefix + 'target';
if (!trigger.hasAttribute(attr)) {
return;
}
var target = trigger.getAttribute(prefix + 'target');
var target = trigger.getAttribute(attr);
return document.querySelector(target);
};
@ -561,11 +563,12 @@ var Clipboard = (function (_Emitter) {
*/
Clipboard.prototype.setText = function setText(trigger) {
if (!trigger.hasAttribute(prefix + 'text')) {
var attr = prefix + 'text';
if (!trigger.hasAttribute(attr)) {
return;
}
return trigger.getAttribute(prefix + 'text');
return trigger.getAttribute(attr);
};
return Clipboard;
@ -575,4 +578,4 @@ exports['default'] = Clipboard;
module.exports = exports['default'];
},{"./clipboard-action":6,"delegate-events":1,"tiny-emitter":5}]},{},[7])(7)
});
});

File diff suppressed because one or more lines are too long

View File

@ -62,11 +62,12 @@ class Clipboard extends Emitter {
* @param {Element} trigger
*/
setAction(trigger) {
if (!trigger.hasAttribute(prefix + 'action')) {
let attr = `${prefix}action`;
if (!trigger.hasAttribute(attr)) {
return;
}
return trigger.getAttribute(prefix + 'action');
return trigger.getAttribute(attr);
}
/**
@ -74,11 +75,12 @@ class Clipboard extends Emitter {
* @param {Element} trigger
*/
setTarget(trigger) {
if (!trigger.hasAttribute(prefix + 'target')) {
let attr = `${prefix}target`;
if (!trigger.hasAttribute(attr)) {
return;
}
let target = trigger.getAttribute(prefix + 'target');
let target = trigger.getAttribute(attr);
return document.querySelector(target);
}
@ -87,11 +89,12 @@ class Clipboard extends Emitter {
* @param {Element} trigger
*/
setText(trigger) {
if (!trigger.hasAttribute(prefix + 'text')) {
let attr = `${prefix}text`;
if (!trigger.hasAttribute(attr)) {
return;
}
return trigger.getAttribute(prefix + 'text');
return trigger.getAttribute(attr);
}
}