Sha256: 481d1640baf33799d3d6241c6c8005ace7e7534a776614a69ab63c6e3c4397de
Contents?: true
Size: 1.45 KB
Versions: 21
Compression:
Stored size: 1.45 KB
Contents
var Ajaxify = new Class({ version: 0.2, Implements: [Options, Events], options: { holder: new Element('div#ajax_holder'), fadeOutDuration: 2000 }, initialize: function(_options) { this.options.events = { loading: { name: 'ajax:loading', text: 'Loading…' }, success: { name: 'ajax:success', text: 'Changes successfully saved!' }, failure: { name: 'ajax:failure', text: Locale.get('Notifications.failure') } }; this.setOptions(_options); }, setup: function(){ this.holder = this.options.holder.inject(document.body); }, applyEvents: function(el){ el = document.id(el || document.body); var apply = function(action, callback) { el.getElements('[data-remote="true"]').addEvent(action, callback); }; apply(this.options.events.loading.name, this.loading.bind(this)); apply(this.options.events.success.name, this.success.bind(this)); apply(this.options.events.failure.name, this.failure.bind(this)); }, loading: function(xhr){ this.setMessage('loading', false); }, success: function(xhr){ this.setMessage('success', true); }, failure: function(xhr){ this.setMessage('failure', false); }, setMessage: function(status, fadeOut) { this.holder .set('text', this.options.events[status].text) .set('class', status); if (fadeOut) { this.holder.addClass('fadeout'); setTimeout(function(){ this.holder.erase('class'); }.bind(this), this.options.fadeOutDuration); } } });
Version data entries
21 entries across 21 versions & 1 rubygems