The removeBC() function in jquery.textsize.js is very inefficient as written, it currently consists of:
function removeBC(){
$(textsize_element + textsize_element_class).removeClass("textsize-5");
$(textsize_element + textsize_element_class).removeClass("textsize-10");
// ...
// 36 lines omitted...
// ...
$(textsize_element + textsize_element_class).removeClass("textsize-195");
$(textsize_element + textsize_element_class).removeClass("textsize-200");
};
This "$(textsize_element + textsize_element_class)" call is somewhat expensive and should not be called on every line! Why not store the result and use that? Also, why not use a loop? The entire function could be rewritten as so:
function removeBC(){
var element = $(textsize_element + textsize_element_class);
for( var i = 5; i <= 200; i+=5 )
element.removeClass( 'textsize-' + i );
}
An alternate approach which would likely be even faster, would be to loop though the element's classes and remove any class starting with "textsize"... this is probably faster than "brute force" removal of all 40 classes (only one of which will actually be present). Something like this:
function removeBC(){
var element = $(textsize_element + textsize_element_class);
var classes = element.attr('class').split(' ');
for( var i in classes ){
if( classes[i].substring(0,8) == 'textsize' ){
element.removeClass( classes[i] );
break;
}
}
}
Hope I'm not coming off as too critical, this is a great module! Does exactly what we need. Could use a bit of optimization though. :) Hope this helps.
Comments
Comment #1
CZ commentedThank you brian_c! Yes, indeed!
Comment #2
CZ commentedFixed in the Development snapshots version.