ZeroClipboard v3.0.0-alpha.1
Fiddle playing around with a v3.0.0 interface for ZeroClipboard, which incorporates the HTML Clipboard API
by James Greene
HTML
<button type="button" class="btn">Click?</button>
CSS
.btn {
background-color: LightGray;
font-size: 1.0em;
padding: 0.5em;
border-radius: 0.5em;
}
JavaScript
function _isMatch(el, selector) {
var matcher;
var isMatch = false;
if (el && el.nodeType === 1) {
matcher = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector || el.oMatchesSelector || null;
try {
isMatch = !! matcher && matcher.call(e.target, selector);
} catch (err) {
isMatch = false;
}
}
return isMatch;
}
function _delegateEventHandler(e) {
if (e && e.target && e.type && (this instanceof ZeroClipboard) && this._clippings && this._clippings.length > 0 && this._listeners && ((this._listeners[e.type] && this._listeners[e.type].length > 0) || (this._listeners['*'] && this._listeners['*'].length > 0))) {
var selector;
for (var i = 0, len = this._clippings.length; i < len; i++) {
selector = this._clippings[i];
if (selector) {
if (typeof selector === "string" && _isMatch(e.target, selector)) {
// TODO Apply listeners
//return listener.apply(this, arguments);
} else if (typeof selector === "object" && selector.nodeType === 1 && e.target === selector) {
// TODO Apply listeners
//return listener.apply(this, arguments);
}
}
}
}
}
function _delegateAll(eventType) {
document.addEventListener(eventType, _delegateEventHandler, false);
}
var _clientCounter = 0;
var ZeroClipboard = function (selector) {
if (!(this instanceof ZeroClipboard)) {
return new ZeroClipboard(selector);
}
this.id = "zc_" + (_clientCounter++);
this._clippings = [];
this._listeners = {};
if (selector) {
this.clip(selector);
}
};
ZeroClipboard.prototype.clip = function (selector) {
if (selector) {
if (typeof selector === "string") {
// Deferred delegate element selector
if...