Skip to content

Instantly share code, notes, and snippets.

@jshirley
Created June 3, 2009 23:40
Show Gist options
  • Save jshirley/123334 to your computer and use it in GitHub Desktop.
Save jshirley/123334 to your computer and use it in GitHub Desktop.
Y.on('delegate', function(e) {
var tgt = e.target;
e.halt();
var uri = tgt.get('href');
var cfg = {
headers: { 'Content-Type': 'text/html; charset=utf-8' }
};
if ( tgt.hasClass('rest-delete') )
cfg.method = 'DELETE';
else if ( tgt.hasClass('rest-post') )
cfg.method = 'POST';
else if ( tgt.hasClass('rest-put') )
cfg.method = 'PUT';
else if ( tgt.hasClass('rest-get') )
cfg.method = 'GET';
/* On complete, delete the parent element */
var extra = [];
var completeHandler = RestEventHandler.complete;
if ( tgt.hasClass('delete-parent') ) {
}
else if ( tgt.hasClass('replace-parent') ) {
extra.push('frontend-replace-parent=1');
completeHandler = RestEventHandler.completeAndReplace;
}
else if ( tgt.hasClass('popup-response') ) {
completeHandler = RestEventHandler.completeAndPopup;
overlay.set("align", { node: tgt, points:[Y.WidgetPositionExt.TR, Y.WidgetPositionExt.TR]});
}
if ( uri.indexOf('?') > 0 )
uri += '&' + extra.join('&');
else
uri += '?' + extra.join('&');
Y.on('io:start', RestEventHandler.start, this, [ tgt ]);
Y.on('io:complete', completeHandler, this, [ tgt ]);
Y.on('io:abort', RestEventHandler.abort, this, [ tgt ]);
Y.on('io:failure', RestEventHandler.failure, this, [ tgt ]);
var request = Y.io(uri, cfg);
}, document.body, 'click', 'a.rest-delete, a.rest-post, a.rest-get, a.rest-put');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment