Short version: I am expanding the jQuery object object, which is designed to accept arguments 0-3 and pass them as second-fourth arguments to jQuery.animate. In addition, I want to isolate the callback and insert another function call into it.
I am expanding the jQuery library in the usual way, through jQuery.fn.newfunction = .... This is a custom animation function, in particular, that extends the object so that its external width, including fields, is equal to the internal width of the parent node.
jQuery.fn.expand_to_parent_container = function() {
var args = Array.prototype.slice.call(arguments);
return this.each(function(){
var parent = $(this).parent();
parent.inner_width = parent.innerWidth();
var inner_outer_differential = $(this).outerWidth(true) - $(this).width();
$(this).data('original_width', $(this).width());
args.unshift({ width: parent.inner_width - inner_outer_differential });
$.fn.animate.apply($(this), args );
});
}
. arguments, "" , properties .animate (API ). .expand_to_parent_container duration, easing, callback, jQuery (, , ). , jQuery.speed , / , /, jQuery, 'd .animate.
.
jQuery.fn.contract_to_original_size = function() {
var args = Array.prototype.slice.call(arguments);
var callback_with_width_reset = function(){
callback();
$(this).width('auto');
}
args.unshift({ width: $(this).data('original_width') });
if($(this).data('original_width')) {
$.fn.animate.apply($(this), args );
} else {
$(this).width('auto');
}
}
var callback_with_width_reset ..., , width reset auto, - , . , arguments args.