Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Convert event handler callback model to mimic DOM Event API model #286

Closed
JamesMGreene opened this Issue · 7 comments

3 participants

@JamesMGreene
Owner

Most of the ZeroClipboard event handler callbacks have the following format:

var clip = new ZeroClipboard();
clip.on("dataRequested", function(client, args) {
  // `this` === glued element or `window`
  // `client` === `clip`
  // `args` === whatever else
});

I think it would be great to move these over to a model that follows the DOM Event API more closely.

For example:

var clip = new ZeroClipboard();
clip.on("dataRequested", function(e) {
  // `this` === `clip`
  // `e.target` === glued element or `null`
  // `e.type` === `"datarequested"`
  // `e.{whatever}` === whatever else (args)
});

The big hitch is that these cannot be transparently converted, so our options are to:

  1. Implement this as a breaking change in v2.0.0 but not sooner; or
  2. Use entirely new event names, e.g.:
    • "load""ready"
    • "noFlash" and "wrongFlash""error" (see #285)
    • "dataRequested""beforeCopy"/"copy" (see #105)
    • "complete""afterCopy" (see #105)
    • Problematic ones are "mouse{over|out|down|up}", which we should not rename but rather just drop when possible (see #81)
@jonrohan
Owner

I'm cool with this change in 2.0.0 we could even focus on 2.0 sooner rather than later

@JamesMGreene

we could even focus on 2.0 sooner rather than later

Definitely where I'm headed but I think we need to solve a handful of fundamental flaws first, e.g. #90 and #199.

@jonrohan
Owner

yeah #90 is the top of the list of wish i could fix this now

@termi

Since you intend to mimic DOM Event API model please make a support of handleEvent.

Example:

let application = {
  name: "my example application"
  , handleEvent(e) {
    // `this` === application
    // `e.client` === ZeroClipboard instance
    // `e.target` === glued element or `null`
    console.log(this.name);// > "my example application"
  }
}
let clip = new ZeroClipboard();
clip.on("dataRequested", application);
@JamesMGreene

@termi: Huh, I've never seen that technique before (other than in the jQuery event system)! I'll plan on including that.

Note to self: http://www.thecssninja.com/javascript/handleevent

@JamesMGreene JamesMGreene was assigned
@JamesMGreene JamesMGreene referenced this issue from a commit in JamesMGreene/zeroclipboard
@JamesMGreene JamesMGreene Deprecated '[un]glue', replaced with '[un]clip'.
Applies partially to Issues #286 and #289 but does not fix either in
whole.
8159d5a
@JamesMGreene

@termi: Your EventListener interface request is partially present in PR #324 for the v1.x Event API (so not following the DOM Event Model). I'll extend this to the DOM Event Model APIs when I start work on v2.x as well.

@JamesMGreene

Note: Should also resolve #107 when working on this issue.

@JamesMGreene JamesMGreene self-assigned this
@JamesMGreene JamesMGreene added the major label
@JamesMGreene JamesMGreene referenced this issue from a commit in JamesMGreene/zeroclipboard
@JamesMGreene JamesMGreene Event callback model mimics DOM Event API model.
Also changed all event names.

Fixes #286.
Fixes #285.
Fixes #105.
d5c30b6
@JamesMGreene JamesMGreene referenced this issue from a commit in JamesMGreene/zeroclipboard
@JamesMGreene JamesMGreene Event callback model mimics DOM Event API model.
Also changed all event names.

Fixes #286.
Fixes #285.
Fixes #105.
4bca90b
@JamesMGreene JamesMGreene closed this issue from a commit
@JamesMGreene JamesMGreene Event callback model mimics DOM Event API model.
Also changed all event names.

Fixes #286.
Fixes #285.
Fixes #105.
5bca19b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.