Sha256: 22411319b3bd09db37fe98abb9cd959b3c855b530ea7b2aeca40f55a04888594

Contents?: true

Size: 1.45 KB

Versions: 52

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

52 entries across 52 versions & 1 rubygems

Version Path
bhf-0.10.12 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.10.11 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.10.10 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.10.9 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.9.9 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.9.8 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.9.7 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.9.6 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.9.5 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.9.4 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.9.3 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.9.2 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.9.1 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.9.0 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.8.7 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.8.6 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.8.5 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.8.4 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.8.3 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.8.2 app/assets/javascripts/bhf/classes/Ajaxify.js