tags:

views:

31

answers:

2

I use facebox plugin on certain links.

I want to disable some of the links dynamically. so clicking them will not open facebox.

I tried several ways to do it but none of them seem to work. Facebox still works when clicking on the links.

I even tried this (prevent the click and mouse down events) but it still doesn't disable the facebox from popping up.

$('#who_button').click(function(event) {  event.preventDefault();});
$('#who_button').mousedown(function(event) {  event.preventDefault();});

What can I do?

EDIT:

Following brad and PetersenDidIt advice I tried this:

$('#who_button').click(function(event) { alert ('here');event.stopPropagation(); event.stopImmediatePropagation();});
    $('#who_button').mousedown(function(event) { event.stopPropagation(); event.stopImmediatePropagation();});

AND still no luck. Moreover I see that the facebox frame appears under the alert dialog. which means that facebox starts before my click/mousedown events are even called.

Is it possible to attach event which will occur before all other events?

Perhaps facebox uses another event (not click or mousedown). what can it be?

A: 

Try event.stopPropagation()

PetersenDidIt
this will only prevent bubbling up on any parent elements. If the click is bound directly to the element referenced above, it will still fire. Depends on how Facebox binds its events.
brad
Thanks ! please see edit above
Nir
+1  A: 

preventDefault just prevents whatever the normal behaviour of that click is (ie redirect on a link).

I've never used facebox, so I'm not sure how it binds its events, but you probably want some thing more like:

event.stopImmediatePropagation()

EDIT

Looks like facebox uses it's own custom event. You can see this in the source (below). So your best bet is to unbind your element from that event:

$("ele").unbind("click.facebox");

Facebox public function

  $.fn.facebox = function(settings) {
    if ($(this).length == 0) return

    init(settings)

    function clickHandler() {
      $.facebox.loading(true)

      // support for rel="facebox.inline_popup" syntax, to add a class
      // also supports deprecated "facebox[.inline_popup]" syntax
      var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
      if (klass) klass = klass[1]

      fillFaceboxFromHref(this.href, klass)
      return false
    }

    return this.bind('click.facebox', clickHandler)
  }
brad
Thanks! please see edit above
Nir
see above edit...
brad
Thank you brad ! $("ele").unbind("click.facebox"); doesnt work because this syntax requires to specifiy the bound function name. However:$("#who_button").unbind(); Seems to work well.
Nir
hmm... according to the docs (http://api.jquery.com/unbind/) you should be able to just pass in the event itself, to unbind all handlers of that specific event with the option to pass in a specific handler bound to that event to be removed. But ya unbinding all events should of course also work.
brad