Re: [jQuery] Re: How to check whether an element is bound to an event or not?

2010-01-04 Thread Karl Swedberg
In jQuery 1.3.x, .live() only works for a subset of event types.  
jQuery 1.4 extends support to all event types:


Possible event values: click, dblclick, mousedown, mouseup,  
mousemove, mouseover, mouseout, keydown, keypress, keyup
Currently not supported: blur, focus, mouseenter, mouseleave,  
change, submit

http://docs.jquery.com/Events/live#typefn

Kudos for rolling your own solution for 1.3.x with the onfocusin event.

--Karl


Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Jan 3, 2010, at 5:31 AM, Md. Ali Ahsan Rana wrote:

I don't know about this much. But, just a while ago, i wa having  
problem binding focus event with live() method. Just solved it by  
the following code that i found somewhere on internet:


(function(){


var special = jQuery.event.special,
uid1 = 'D' + (+new Date()),
uid2 = 'D' + (+new Date() + 1);

jQuery.event.special.focus = {
setup: function() {
var _self = this,

handler = function(e) {
e = jQuery.event.fix(e);
e.type = 'focus';
if (_self === document) {
jQuery.event.handle.call(_self, e);

}
};

jQuery(this).data(uid1, handler);

if (_self === document) {
/* Must be live() */
if (_self.addEventListener) {

_self.addEventListener('focus', handler, true);
} else {
_self.attachEvent('onfocusin', handler);
}
} else {

return false;
}

},
teardown: function() {
var handler = jQuery(this).data(uid1);
if (this === document) {
if (this.removeEventListener) {

this.removeEventListener('focus', handler, true);
} else {
this.detachEvent('onfocusin', handler);
}
}
}

};

jQuery.event.special.blur = {
setup: function() {
var _self = this,
handler = function(e) {
e = jQuery.event.fix(e);
e.type = 'blur';

if (_self === document) {
jQuery.event.handle.call(_self, e);
}
};

jQuery(this).data(uid2, handler);

if (_self === document) {

/* Must be live() */
if (_self.addEventListener) {
_self.addEventListener('blur', handler, true);
} else {
_self.attachEvent('onfocusout', handler);

}
} else {
return false;
}

},
teardown: function() {
var handler = jQuery(this).data(uid2);
if (this === document) {

if (this.removeEventListener) {
this.removeEventListener('blur', handler, true);
} else {
this.detachEvent('onfocusout', handler);

}
}
}
};

})();




--
http://ranacseruet.blogspot.com/




[jQuery] Re: How to check whether an element is bound to an event or not?

2010-01-04 Thread MorningZ
There is an DOM element, which is reloading(replaced by ajax response
with same id/tag), then the event isn't no more bounded. I want it to
be
bounded all the time

instead of all the overhead of binding/unbinding/looking-to-do-either,
why not:

a) just replace the contents of the DOM object

b) wrap wherever you inject the ajax response with another uniquely
identifiable DOM object and wire the event to that?

then the binding is done once and it doesn't matter if the Ajax call
is never made or is made 100 times, the event isn't going anywhere :-)


On Jan 4, 8:19 am, Karl Swedberg k...@englishrules.com wrote:
 In jQuery 1.3.x, .live() only works for a subset of event types.  
 jQuery 1.4 extends support to all event types:

  Possible event values: click, dblclick, mousedown, mouseup,  
  mousemove, mouseover, mouseout, keydown, keypress, keyup
  Currently not supported: blur, focus, mouseenter, mouseleave,  
  change, submit

 http://docs.jquery.com/Events/live#typefn

 Kudos for rolling your own solution for 1.3.x with the onfocusin event.

 --Karl

 
 Karl Swedbergwww.englishrules.comwww.learningjquery.com

 On Jan 3, 2010, at 5:31 AM, Md. Ali Ahsan Rana wrote:

  I don't know about this much. But, just a while ago, i wa having  
  problem binding focus event with live() method. Just solved it by  
  the following code that i found somewhere on internet:

  (function(){

      var special = jQuery.event.special,
          uid1 = 'D' + (+new Date()),
          uid2 = 'D' + (+new Date() + 1);

      jQuery.event.special.focus = {
          setup: function() {
              var _self = this,

                  handler = function(e) {
                      e = jQuery.event.fix(e);
                      e.type = 'focus';
                      if (_self === document) {
                          jQuery.event.handle.call(_self, e);

                      }
                  };

              jQuery(this).data(uid1, handler);

              if (_self === document) {
                  /* Must be live() */
                  if (_self.addEventListener) {

                      _self.addEventListener('focus', handler, true);
                  } else {
                      _self.attachEvent('onfocusin', handler);
                  }
              } else {

                  return false;
              }

          },
          teardown: function() {
              var handler = jQuery(this).data(uid1);
              if (this === document) {
                  if (this.removeEventListener) {

                      this.removeEventListener('focus', handler, true);
                  } else {
                      this.detachEvent('onfocusin', handler);
                  }
              }
          }

      };

      jQuery.event.special.blur = {
          setup: function() {
              var _self = this,
                  handler = function(e) {
                      e = jQuery.event.fix(e);
                      e.type = 'blur';

                      if (_self === document) {
                          jQuery.event.handle.call(_self, e);
                      }
                  };

              jQuery(this).data(uid2, handler);

              if (_self === document) {

                  /* Must be live() */
                  if (_self.addEventListener) {
                      _self.addEventListener('blur', handler, true);
                  } else {
                      _self.attachEvent('onfocusout', handler);

                  }
              } else {
                  return false;
              }

          },
          teardown: function() {
              var handler = jQuery(this).data(uid2);
              if (this === document) {

                  if (this.removeEventListener) {
                      this.removeEventListener('blur', handler, true);
                  } else {
                      this.detachEvent('onfocusout', handler);

                  }
              }
          }
      };

  })();

  --
 http://ranacseruet.blogspot.com/


Re: [jQuery] Re: How to check whether an element is bound to an event or not?

2010-01-03 Thread waseem sabjee
on certain versions of IE i had issues where the .live() function just
didn't work. no click events at all were firing only on IE. not sure if this
has been fixed.

On Sun, Jan 3, 2010 at 9:23 AM, Md. Ali Ahsan Rana ranacser...@gmail.comwrote:

 Hi,
  Thanks for your reply. It helped me a lot.

 Regards



Re: [jQuery] Re: How to check whether an element is bound to an event or not?

2010-01-03 Thread Md. Ali Ahsan Rana
I don't know about this much. But, just a while ago, i wa having problem
binding focus event with live() method. Just solved it by the following code
that i found somewhere on internet:

(function(){

var special = jQuery.event.special,
uid1 = 'D' + (+new Date()),
uid2 = 'D' + (+new Date() + 1);

jQuery.event.special.focus = {
setup: function() {
var _self = this,
handler = function(e) {
e = jQuery.event.fix(e);
e.type = 'focus';
if (_self === document) {
jQuery.event.handle.call(_self, e);
}
};

jQuery(this).data(uid1, handler);

if (_self === document) {
/* Must be live() */
if (_self.addEventListener) {
_self.addEventListener('focus', handler, true);
} else {
_self.attachEvent('onfocusin', handler);
}
} else {
return false;
}

},
teardown: function() {
var handler = jQuery(this).data(uid1);
if (this === document) {
if (this.removeEventListener) {
this.removeEventListener('focus', handler, true);
} else {
this.detachEvent('onfocusin', handler);
}
}
}
};

jQuery.event.special.blur = {
setup: function() {
var _self = this,
handler = function(e) {
e = jQuery.event.fix(e);
e.type = 'blur';
if (_self === document) {
jQuery.event.handle.call(_self, e);
}
};

jQuery(this).data(uid2, handler);

if (_self === document) {
/* Must be live() */
if (_self.addEventListener) {
_self.addEventListener('blur', handler, true);
} else {
_self.attachEvent('onfocusout', handler);
}
} else {
return false;
}

},
teardown: function() {
var handler = jQuery(this).data(uid2);
if (this === document) {
if (this.removeEventListener) {
this.removeEventListener('blur', handler, true);
} else {
this.detachEvent('onfocusout', handler);
}
}
}
};

})();





-- 
http://ranacseruet.blogspot.com/


[jQuery] Re: How to check whether an element is bound to an event or not?

2010-01-02 Thread Joe Sondow
Yes, the live function. http://docs.jquery.com/Events/live

Added in jQuery 1.3: Binds a handler to an event (like click) for all
current - and future - matched element. Can also bind custom events.

On Jan 2, 11:44 pm, Md. Ali Ahsan Rana ranacser...@gmail.com
wrote:
 hi, thanks. But, what is happening here is:
      There is an DOM element, which is reloading(replaced by ajax response
 with same id/tag), then the event isn't no more bounded. I want it to be
 bounded all the time.  Do you think, here unbound will work? Or Is there any
 way to keep the binding whenever a new element is being loaded?

 Regards

 On Sun, Jan 3, 2010 at 1:41 AM, waseem sabjee waseemsab...@gmail.comwrote:



  usually when I bind a click event I do this.
  unbind before bind

  $(elm).unbind('click');
  $(elm).bind(click, function() {

  });

  may be a modification like this

  if(!$(elm).unbind('click')) {
     $(elm).bind(click, function() {
       alert(This element was only bound if it was not bound);
     });
  }

  On Sat, Jan 2, 2010 at 7:28 PM, ranacseruet ranacser...@gmail.com wrote:

  I need to check whether an element is bound to an event or not. How to
  achieve this?

 --http://ranacseruet.blogspot.com/


Re: [jQuery] Re: How to check whether an element is bound to an event or not?

2010-01-02 Thread Md. Ali Ahsan Rana
Hi,
 Thanks for your reply. It helped me a lot.

Regards