Sha256: 51c07c58d7b989d872a14443f466fdc731597dc522a9c2d159c79373bc92dad5
Contents?: true
Size: 1.77 KB
Versions: 4
Compression:
Stored size: 1.77 KB
Contents
// Emerson HTTP // // Adds... (function(ns) { // Emerson Extension // -------------------------------------------------------------------------- // ### Emerson.http module // ... // // **Important Note:** // > For now, `Emerson.http` depends on the Rails `jquery_ujs` extension. var define = ns.http = function() {}; // ### Module API // * `ns` is a reference to the namespace. // * `init` is a hook for initializing the module. _.extend(define, { ns : ns, init : function init() { if($.rails === undefined) { throw("$.rails must be defined"); } return (ns.sink) ? enable() : disable(); } }); // "Base" Libary Extension // -------------------------------------------------------------------------- // Make a local copy of Emerson.base. e.g., one of jQuery, Zepto or Ender. var $ = ns.base; // Event Handling // -------------------------------------------------------------------------- // ### enable // Attach event global listeners. function enable() { $(document) .on('ajax:error', handleError) .on('ajax:success', handleSuccess); } // ### enable // Detach event global listeners. function disable() { $(document) .off('ajax:error', handleError) .off('ajax:success', handleSuccess); } // ### handleError function handleError(e, xhr, status, error) { sink(JSON.parse(xhr.responseText), status); } // ### handleSuccess function handleSuccess(e, response, status, xhr) { sink(response, status); } // ### sink // // json: <response [action, data, path, view]> // html: <response> (string) // head: <response> single space string function sink(response, status) { $(response.view).view().sink(); } })(Emerson);
Version data entries
4 entries across 4 versions & 1 rubygems