Permalink
Browse files

make all custom events trigger the same - and prevent bubbling across…

… the board
  • Loading branch information...
maranomynet committed Jan 13, 2012
1 parent a45e2a3 commit 4a0288a49fda337d1b2460108ab80798a83b67d9
Showing with 14 additions and 15 deletions.
  1. +1 −1 1.1/jquery.virtualbrowser-1.1-min.js
  2. +13 −14 1.1/jquery.virtualbrowser-1.1.js

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -209,6 +209,12 @@
_result = 'result', // ...to save bandwidth
_srcDataAttr = 'data-srcattr', // ...to save bandwidth
_protocolSlash = /^(https?:)?\/\//,
+ _triggerCustomEv = function ( evtype, body, req, vbdata ) {
+ var ev = $.Event(evtype);
+ ev.stopPropagation();
+ body.trigger(ev, [req, vbdata]);
+ return ev;
+ };
@@ -221,8 +227,6 @@
body = $(this),
VBdata = body.data(_virtualBrowser),
config = VBdata.cfg,
- evBeforeload = $.Event(_VBbeforeload),
- evLoad, evLoaded,
applyLoadMsg;
if ( $.isPlainObject(arg) )
@@ -252,11 +256,10 @@
if (url)
{
- evBeforeload[_stopPropagation]();
if ( VBdata._clicked ) {
request.btn = VBdata._clicked; // store reference to the clicked button - to allow access/evaulation by event handlers.
}
- body.trigger(evBeforeload, [request, VBdata]);
+ var evBeforeload = _triggerCustomEv(_VBbeforeload, body, request, VBdata);
// trap external (non-AJAXable) URLs or links targeted at another window and set .passThrough as true
if ( // if passThrough is already set, then there's not need for further checks, and...
!evBeforeload[_passThrough] &&
@@ -348,7 +351,7 @@
var isError = !status || status == 'error';
if ( isError )
{
- body.trigger(_VBerror, [request, VBdata]);
+ _triggerCustomEv(_VBerror, body, request, VBdata);
}
else
{
@@ -366,13 +369,8 @@
// allow VBerror handlers to set custom .resultDOM and then process it normally.
if ( !isError || request[_result] || request[_resultDOM] )
{
- evLoad = $.Event(_VBload);
- evLoad[_stopPropagation]();
- body.trigger(evLoad, [request, VBdata]);
- if ( !evLoad[_isDefaultPrevented]() )
+ if ( !_triggerCustomEv(_VBload, body, request, VBdata)[_isDefaultPrevented]() )
{
- evLoaded = $.Event(_VBloaded);
- evLoaded[_stopPropagation]();
config.loadmsgElm && config.loadmsgElm.detach();
// default to just dumping resultBody's `.contents()` into the DOM.
request[_resultDOM] = request[_resultDOM] || $.getResultBody( request[_result], config.stripCfg ).contents();
@@ -391,8 +389,8 @@
.empty()
.append( request[_resultDOM] );
VBdata.lastRequest = request;
+ _triggerCustomEv(_VBloaded, body, request, VBdata);
body
- .trigger(evLoaded, [request, VBdata])
// NOTE: We can't rely on bubbling in IE8- because bubbling happens first on the container elements,
// and last on the form itself. (at least in jQuery 1.4 and 1.5)
// This makes .isDefaultPrevented() checks fail when plugin-users bind (and .preventDefault())
@@ -455,8 +453,8 @@
$.ajax(ajaxOptions);
}
}
+ return evBeforeload;
}
- return evBeforeload;
},
@@ -475,7 +473,8 @@
.unbind( 'submit', _handleHttpRequest)
.end()
.unbind( [_VBbeforeload,_VBerror,_VBload,_VBloaded].join(' ') )
- .trigger( _VBdisengaged )
+ _triggerCustomEv( body, _VBdisengaged );
+ body
.unbind( _VBdisengaged );
}

0 comments on commit 4a0288a

Please sign in to comment.