noflash passes window rather than element #107

Closed
Rarst opened this Issue Feb 25, 2013 · 9 comments

Comments

Projects
None yet
3 participants

Rarst commented Feb 25, 2013

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

jonrohan commented Feb 25, 2013

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 commented Feb 25, 2013

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.

Owner

jonrohan commented Feb 25, 2013

it doesn't need to fire multiple times?

That could be a bug.

Rarst commented Feb 25, 2013

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

JamesMGreene was assigned May 7, 2013

Owner

JamesMGreene commented May 19, 2013

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

Owner

JamesMGreene commented Aug 6, 2013

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 was assigned Aug 6, 2013

Owner

JamesMGreene commented Nov 27, 2013

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?

Owner

jonrohan commented Nov 27, 2013

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.

Owner

JamesMGreene commented Jan 25, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment