Sha256: 9384fc68782582139668e69c475612c7452e7bebdebfc6bda225b66d184b7c27

Contents?: true

Size: 1.43 KB

Versions: 16

Compression:

Stored size: 1.43 KB

Contents

var Ajaxify = new Class({
	version: 0.2,

	Implements: [Options, Events],

	options: {
		events: {
			loading: {
				name: 'ajax:loading',
				text: 'Loading…'
			},
			success: {
				name: 'ajax:success',
				text: 'Changes successfully saved!'
			},
			failure: {
				name: 'ajax:failure',
				text: 'Oops, something went wrong…'
			}
		},
		holder: new Element('div#ajax_holder'),
		fadeOutDuration: 2000
	},

	initialize: function(_options) {
		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', true);
	},

	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

16 entries across 16 versions & 1 rubygems

Version Path
bhf-0.6.14 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.6.13 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.6.12 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.6.11 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.6.10 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.6.6 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.6.5 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.6.4 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.6.3 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.6.2 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.6.1 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.6.0 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.5.13 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.5.12 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.5.11 vendor/assets/javascripts/bhf/classes/Ajaxify.js
bhf-0.5.10 vendor/assets/javascripts/bhf/classes/Ajaxify.js