Skip to content

@tomaszzielinski /JqFxStack.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
JqFxStack - jQuery helper for easy reversion of element properties
/*
AUTHOR: Tomasz Zielinski
LICENSE: public domain where appropriate; free for everyone, for all usages, elsewhere
*/
function JqFxStack() {
this.id_map = {};
}
JqFxStack.prototype._fx = function(func_name, element, css, options) {
var prev_css = {};
for(var css_prop in css) {
if(css.hasOwnProperty(css_prop)) {
prev_css[css_prop] = element.css(css_prop);
}
}
var fx = {
func_name: func_name,
css: css,
prev_css: prev_css,
options: options
};
var element_id = element.attr('id');
if(!this.id_map.hasOwnProperty(element_id)) {
this.id_map[element_id] = [];
}
this.id_map[element_id].push(fx);
element[fx.func_name](fx.css, fx.options);
};
JqFxStack.prototype.revert = function(element) {
if(element instanceof Array) {
var fx_stack = this;
$.each(element, function(idx, elem){
fx_stack.revert(elem);
});
} else {
var element_id = element.attr('id');
var fx = this.id_map[element_id].pop();
element[fx.func_name](fx.prev_css, fx.options);
}
return this;
};
JqFxStack.prototype.revert_all = function(element) {
if(element instanceof Array) {
var fx_stack = this;
$.each(element, function(idx, elem){
fx_stack.revert_all(elem);
});
} else {
var element_id = element.attr('id');
var len = this.id_map[element_id].length;
for(var i=0; i<len; i++) {
this.revert(element);
}
}
return this;
};
JqFxStack.prototype.animate = function(element, css, options) {
this._fx('animate', element, css, options);
return this;
};
JqFxStack.prototype.css = function(element, css) {
this._fx('css', element, css);
return this;
};
JqFxStack.prototype.show_block = function(element) {
this._fx('css', element, {'display': 'block'});
return this;
};
JqFxStack.prototype.show_inline = function(element) {
this._fx('css', element, {'display': 'inline'});
return this;
};
JqFxStack.prototype.hide = function(element) {
this._fx('css', element, {'display': 'none'});
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.