Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Closed
JamesMGreene opened this Issue Dec 9, 2013 · 7 comments

Comments

Projects
None yet
3 participants
Owner

JamesMGreene commented Dec 9, 2013

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)
Contributor

jonrohan commented Dec 10, 2013

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

Owner

JamesMGreene commented Dec 10, 2013

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.

Contributor

jonrohan commented Dec 10, 2013

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

termi commented Dec 31, 2013

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);
Owner

JamesMGreene commented Dec 31, 2013

@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

@ghost ghost assigned JamesMGreene Jan 18, 2014

JamesMGreene added a commit to JamesMGreene/zeroclipboard that referenced this issue Jan 20, 2014

Deprecated '[un]glue', replaced with '[un]clip'.
Applies partially to Issues #286 and #289 but does not fix either in
whole.
Owner

JamesMGreene commented Jan 20, 2014

@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.

Owner

JamesMGreene commented Jan 25, 2014

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

@JamesMGreene JamesMGreene self-assigned this Mar 20, 2014

@JamesMGreene JamesMGreene added the major label Mar 20, 2014

JamesMGreene added a commit to JamesMGreene/zeroclipboard that referenced this issue Mar 26, 2014

Event callback model mimics DOM Event API model.
Also changed all event names.

Fixes #286.
Fixes #285.
Fixes #105.

JamesMGreene added a commit to JamesMGreene/zeroclipboard that referenced this issue Mar 26, 2014

Event callback model mimics DOM Event API model.
Also changed all event names.

Fixes #286.
Fixes #285.
Fixes #105.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment