Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

noflash passes window rather than element #107

Closed
Rarst opened this Issue · 9 comments

3 participants

@Rarst

I am tinkering with implementing ZeroClipboard for several buttons on page with Bootstrap tooltips for feedback. I've got to implementing noflash case and for some reason unlike mouseover, mouseout and complete it passes window to callback rather than specific button.

It doesn't seem to be documented differently in docs, am I doing something wrong here or this is how it is [not] supposed to work?

var copy_buttons = $(".btn-copy-link");
var clip = new ZeroClipboard(copy_buttons);

clip.on("noflash", function (client) {

    // fails because this contains window rather than button
    $(this).addClass('disabled').tooltip('destroy').tooltip({'placement':'right', 'title':'copy to clipboard needs flash'});
});
@jonrohan
Owner

Because the timing of the call (before everything is setup). There isn't a target button to pass back. The best I could do is pass back all the elements passed in.

Which in your example would be $(".btn-copy-link"). The way I currently use noflash in my implementation is to just recall all the elements. for example.

clip.on("noflash", function (client) {
  $(".btn-copy-link").addClass('disabled');
});
@Rarst

Got it. But then, I think, it doesn't need to fire multiple times? Which it seems to do if I add alert or something inside.

@jonrohan
Owner

it doesn't need to fire multiple times?

That could be a bug.

@Rarst

For the record $(".btn-copy-link") matches multiple buttons and noflash seems to fire as many times as there are buttons.

@JamesMGreene JamesMGreene was assigned
@JamesMGreene

I'd say this is a bug. The "noFlash" event should only fire once per "client" instance rather than once per glued element.

@JamesMGreene
Owner

Well, on second thought, maybe it should fire once per element. This would allow you to more easily do things like what @jonrohan described in his code example above, e.g. change all glued elements into a disabled state. If there aren't any glued elements at the time, then I would pass the window object instead.

@JamesMGreene JamesMGreene was assigned
@JamesMGreene

I'm thinking the correct fix is to make the "noflash", "wrongflash", "load" events only fire once per client instance but modifying the client API such that it can access its own glued elements (or at least give it an indirect accessor/iterator like a .forEach method). This is not currently possible due to the singleton nature, so we'll need to kill that off... that's also holding up several other instance-related bugs, e.g. #90, #199, etc.

@jonrohan @HaNdTriX @myitcv: Agree? Additional or alternate suggestions?

@jonrohan
Owner

I think once per client is what i would expect. In my example I call $(".btn-copy-link").addClass('disabled'); doing this to disable all buttons with copy link on the page.

@JamesMGreene

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

@JamesMGreene JamesMGreene closed this issue from a commit
@JamesMGreene JamesMGreene Moved Flash detection to JS
There are a few distinct but related changes here but they made sense to
just tackle together.

Moved Flash detection (including Flash version parsing) into JavaScript.
Fixes #138.

Added new `deactivatedFlash` and `overdueFlash` events. These will be
changed to an `error` event type in the future along with `noFlash`,
`wrongFlash`, etc.
Fixes #255.

Standardized non-elemental events to all have `window` as the context
(`this`). Fixes #107.

Removed deprecated `ZeroClipboard.detectFlashSupport` method. Fixes #198.
d4e4f30
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.