addDefault

5 views
Skip to first unread message

Justin Meyer

unread,
Jan 23, 2010, 5:20:13 PM1/23/10
to JavaScriptMVC
Another idea to enable event based APIs to be more powerful is letting
you have custom default events. I've just added a plugin to do that:

http://javascriptmvc.googlecode.com/svn/trunk/jquery/event/default/default.js

This way, you could have an acts as "tab" plugin do something like:

$(".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();
})

Somewhere else and prevent the "act as tab's" default behavior of
hiding the tab.

I think $.actsAs will allow you to wire up default functionality like:

$.actsAs("jupiter.tabs", {
"default .tab hide" : function(el, ev){
el.hide()
}
})

In your Controller:

$.controller('my.tabs', {
".tab hide" : function(el, ev){
if(!CURRENT_TAB_COMPLETE) ev.preventDefault();
}
})

Thoughts?

Currently, there might be a problem if you .preventDefault(). If
above your current delegated element, there is something waiting to
attach a default event, it will not have the opportunity. However, I
think this adds another important layer to JMVC.

Justin Meyer

unread,
Jan 23, 2010, 5:26:10 PM1/23/10
to JavaScriptMVC
Added this on jQuery's forum. Vote for it if you like it.

http://forum.jquery.com/#Topic/14737000000658449

On Jan 23, 4:20 pm, Justin Meyer <justinbme...@gmail.com> wrote:
> Another idea to enable event based APIs to be more powerful is letting
> you have custom default events.  I've just added a plugin to do that:
>

> http://javascriptmvc.googlecode.com/svn/trunk/jquery/event/default/de...

Reply all
Reply to author
Forward
0 new messages