addDefault

addDefault

After talking w/ Yehuda, we came up with the idea of allowing people to provide default actions on triggered events.   

I discuss it a little on JMVC's forum.

http://groups.google.com/group/javascriptmvc/browse_thread/thread/4d5ae9c61f3817f0


But here's what it looks like essentially:

//imagine some plugin wanting to provide default functionality on a "hide" event.

$(".tab").bind("hide", function(ev){ 
          var el = this; 
          ev.addDefault(function(){ 
                  $(el).hide() 
          }) 
 }) 





And allow you to do something like: 

$(".tab").bind("hide", function(ev){ 
   if(!CURRENT_TAB_COMPLETE) ev.preventDefault(); 

}) 

Similar to how the browser works.  This might have problems if people expect defaults to be added after a stopPropagation is called.  But, I think the idea is powerful.  Here's a working version:


I'm going to make a plugin for this, but I think it could be a very useful addition to core, or at least something jQuery UI takes a look at.