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

Version Path
bhf-1.0.0.beta16 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta15 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta14 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta13 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta12 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta11 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta10 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta9 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta8 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta7 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta6 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta5 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta4 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta3 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta2 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-1.0.0.beta1 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.10.17 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.10.16 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.10.15 app/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.10.14 app/assets/javascripts/bhf/classes/Ajaxify.js