Working draft of the new API for ZeroClipboard v2.0.0.
NOTE: A checked checkbox means that line item has already been implemented in the latest ZeroClipboard master branch.
var _globalConfig = {
// URL to movie, relative to the page. Default value will be "ZeroClipboard.swf" under the
// same path as the ZeroClipboard JS file.
swfPath: "path/to/ZeroClipboard.swf",
// Page domains that the SWF should trust (single string or array of strings)
trustedDomains: [window.location.host],
// Include a "nocache" query parameter on requests for the SWF
cacheBust: true,
// Forcibly set the hand cursor ("pointer") for all clipped elements
forceHandCursor: false,
// The z-index used by the Flash object. Max value (32-bit): 2147483647
zIndex: 999999999,
//
// NEW OPTIONS
//
// Sets the title of the `div` encapsulating the Flash object
title: null,
// Force the use of the enhanced (rich) clipboard on Linux OSes despite its problems
forceEnhancedClipboard: false,
// Have Flash object re-dispatch events that it swallows (`click`, etc.)
bubbleEvents: true,
// Setting this to `false` would allow users to handle calling `ZeroClipboard.activate(...);`
// themselves instead of relying on our per-element `mouseover` handler
autoActivate: true
};-
_globalConfig.swfPath -
_globalConfig.trustedDomains -
_globalConfig.cacheBust -
_globalConfig.forceHandCursor -
_globalConfig.zIndex -
_globalConfig.title -
_globalConfig.forceEnhancedClipboard -
_globalConfig.bubbleEvents -
_globalConfig.autoActivate
-
ZeroClipboard.version
-
ZeroClipboard.config({ ... });(setter) ← ReplacesZeroClipboard.setDefaults({ ... }); -
ZeroClipboard.config();(getter) -
ZeroClipboard.config("swfPath");(getter for a single option) -
ZeroClipboard.destroy();→ Destroys all ZeroClipboard instances and the Flash bridge -
ZeroClipboard.emit(...);← ReplacesZeroClipboard.dispatch(...); -
ZeroClipboard.activate(...);← Replacesclient.setCurrent(...); -
ZeroClipboard.deactivate();← Replacesclient.resetBridge(); -
ZeroClipboard.state()→ Diagnostic; returns a JSON object describing the state of the browser, Flash Player, and ZeroClipboard
- No per-client config options
function ZeroClipboard(elementsToClip /* no longer accept config options here */) {
/* ... */
}
/* no elements */
var clip1 = new ZeroClipboard();
/* single element */
var clip2 = new ZeroClipboard(document.getElementById("d_clip_button"));
/* list of elements */
var clip3 = new ZeroClipboard($(".clipboard"));-
client.id
-
client.clip(...);← Replacesclient.glue(...); -
client.unclip(...);← Replacesclient.unglue(...); -
client.handlers();← ("getter") Replaces client'sclient.handlersproperty -
client.handlers("load");← ("getter" for a single event type) Replaces client'sclient.handlers[eventType] -
client.elements();→ "getter" method that returns array of client's clipped elements -
client.destroy(); -
client.on(...); -
client.on({ ... });→ Supports the "events map" concept from jQuery -
client.off(...); -
client.off({ ... });→ Supports the "events map" concept from jQuery
-
"ready"← Formerly"load"; also updating the event data, see gist -
"beforecopy"and"copy"← Formerly"dataRequested" -
"aftercopy"← Formerly"complete". Fires after the clipboard injection but before the"click"event bubble is dispatched. -
"error"[name === "flash-disabled"]← Formerly"noFlash"; Flash is disabled or not installed. -
"error"[name === "flash-outdated"]← Formerly"wrongFlash"; Flash is too old for ZeroClipboard -
"error"[name === "flash-deactivated"]→ Flash is too old for your browser and/or is currently "click-to-play" -
"error"[name === "flash-unavailable"]→ExternalInterface.availablereturns false, so we cannot communicate from JS to Flash -
"error"[name === "version-mismatch"]→ ZeroClipboard SWF and ZeroClipboard JS are different versions; Better name suggestions welcomed! -
"error"[name === "clipboard-failure"]→ Clipboard injection failed or threw an error; Better name suggestions welcomed! -
"error"[name === (etc.???)]→ ???
- Updated to align with DOM event standards for an event data object:
client.on("x", function(e) {
// `this` === `client`
// `e.client` === `client`
// `e.target` === clipped element or `null`
// `e.type` === `"x"`
// `e.{whatever}` === whatever else (args)
});- Also include support for objects implementing the
EventListenerinterface (i.e. objects with ahandleEventfunction):
var obj = {
foo: "bar",
handleEvent: function(e) {
// `this` === `obj`
// `e.client` === `client`
// `e.target` === clipped element or `null`
// `e.type` === `"x"`
// `e.{whatever}` === whatever else (args)
}
};
client.on("x", obj);- Continue to offer passive injection via
data-clipboard-textanddata-clipboard-targetattributes. Should this be controlled via configuration rather than always on? - ??? If no
data-clipboard-textordata-clipboard-targetattributes are specified and there isn't anycopyevent handler, can still offer a passive copy on the currently selected text. Is this desirable? Should it be controlled via configuration (default → on) rather than via the mentioned rules?
Which one(s)???
- In the spirit of the HTML5 Clipboard API. Definitely including this one BUT... should a call to
e.preventDefault();be required like it is in the HTML Clipboard API? Duringcopyevent callbacks, e.g.
client.on("copy", function(e) {
e.clipboardData.clearData();
e.clipboardData.setData("text/plain", "...");
// NOTE: The following method taking an object/hash/map as an argument is NOT part of the
// HTML Clipboard API
e.clipboardData.setData({
"text/plain": "...",
"text/html": "<i>...</i>"
});
// NOTE: The following call is REQUIRED in the HTML Clipboard API due to IE backwards
// compatibility but we could choose to go either way
e.preventDefault();
});AND:
[A] No other active methods.
OR:
[B] Static methods (which is more truthful to how it works given there is only one shared Flash object):
-
ZeroClipboard.setText("...");→ Shortcut forZeroClipboard.setData({ "text/plain": "..." }); -
ZeroClipboard.setHtml("...");→ Shortcut forZeroClipboard.setData({ "text/html": "..." }); -
ZeroClipboard.setRichText("...");→ Shortcut forZeroClipboard.setData({ "application/rtf": "..." }); -
ZeroClipboard.setData({ ... });, e.g.
ZeroClipboard.setData({
/* Three standard data types */
"text/plain": "Zero",
"text/html": "<b>Zero</b>",
"application/rtf": "{\\rtf1\\ansi\n{\\b Zero}}",
/* Custom formats that must have a receiver listening for a paste from this clipboard sector */
"text/x-markdown": "**Zero**"
});-
ZeroClipboard.clearData("text/html");→ Clears the pending clipboard data for the HTML sector of the clipboard -
ZeroClipboard.clearData();→ Clears the pending clipboard data for all sectors of the clipboard
OR:
[C] Instance methods (has parity with the current v1.x API)
-
client.setText("...");→ Shortcut forclient.setData({ "text/plain": "..." }); -
client.setHtml("...");→ Shortcut forclient.setData({ "text/html": "..." }); -
client.setRichText("...");→ Shortcut forclient.setData({ "application/rtf": "..." }); -
client.setData({ ... });, e.g.
client.setData({
/* Three standard data types */
"text/plain": "Zero",
"text/html": "<b>Zero</b>",
"application/rtf": "{\\rtf1\\ansi\n{\\b Zero}}",
/* Custom formats that must have a receiver listening for a paste from this clipboard sector */
"text/x-markdown": "**Zero**"
});-
client.clearData("text/html");→ Clears the pending clipboard data for the HTML sector of the clipboard -
client.clearData();→ Clears the pending clipboard data for all sectors of the clipboard
ZeroClipboard.dispatch(...);→ZeroClipboard.emit(...);ZeroClipboard.setDefaults({ ... });→ZeroClipboard.config({ ... });client.options.trustedOrigins = [];→ZeroClipboard.config({ trustedDomains: [] });client.options.moviePath = "ZC.swf";→ZeroClipboard.config({ swfPath: "ZC.swf" });client.options.useNoCache = false;→ZeroClipboard.config({ cacheBust: false });client.handlers→client.handlers();[CONFUSING CHANGE but the oldhandlersproperty wasn't listed in the public API]client.setCurrent(...);→ZeroClipboard.activate(...);client.resetBridge();→ UseZeroClipboard.deactivate();client.setText(...);→ ??? Still up for debate. UseZeroClipboard.setText(...);???client.glue(...);→ Useclient.clip(...);client.unglue(...);→ Useclient.unclip(...);
- Constructor no longer accepts a 2nd argument as per-client config options. Use
ZeroClipboard.config(...);. - Default value of
client.options.trustedDomains:null→[window.location.host] client.options.allowScriptAccess = "always";→ This will be automatically set for you based on thetrustedDomainsconfig valueclient.setTitle(...);→ UseZeroClipboard.config({ title: "My Title" });client.options.hoverClass = "blah";→ You should be able to just use normal CSS:hoverselectorsclient.options.activeClass = "blah";→ You should be able to just use normal CSS:activeselectors- Events:
"load"→"ready"; also updating the event data, see gist"noFlash"→"error"withtypeproperty set to"flash-missing"."wrongFlash"→"error"withtypeproperty set to"flash-outdated"."dataRequested"→"beforecopy"and"copy""complete"→"aftercopy"
- Event handler callback signature and context has changed. See "Event Handler Format" above.
ZeroClipboard.detectFlashSupport();client.options.allowScriptAccess = "always";→ This SWF outbound scripting policy will be set automatically by ZeroClipboard but only if necessaryclient.options.debug = false;→ There won't be any deprecation warnings in v2.0.0, so this option will be at least temporarily unnecessaryclient.ready();→ No need to expose the state; useclient.on("ready", function(e) { /* ... */ });client.addEventListener(...);→ Useclient.on(...);client.removeEventListener(...);→ Useclient.off(...);client.reposition();client.setHandCursor(...);client.setSize(...);client.receiveEvent(...);- Events:
"mouseover""mouseout""mousedown""mouseup"
client.flashBridgeclient.htmlBridgeclient.options→ UseZeroClipboard.config();client._singleton