>> You could reduce the code by using switch

Switch usually ends up being vertical code, lookup tables are often shorter
and faster. In Javascript, switch is just a nice-looking form of
if-then-else.

> modalContent.top(mdcTop + 'px').left(mdcLeft + 'px');
> switch(animation){
>     case 'fade':
>         modalContent.fadeIn(speed);
>         break;
>   case 'slide':
>         modalContent.hide().slideDown(speed);
>         break;
>   case 'show':
>         modalContent.show();
>         break;
> }

If you had the user define the animation effect in terms of the actual
jQuery method names ("fadeIn", "slideDown", "show") and made the default be
"show", you could replace all of that with one line:

modalContent.css({top: mdcTop+'px', left:
mdcLeft+px}).hide()[animation](speed);

If you want to keep the same names it's just a lookup table:

var fx = {fade: 'fadeIn', slide: 'slideDown'}[animation] || 'show';
modalContent.css({top: mdcTop+'px', left: mdcLeft+px}).hide()[fx](speed);

I changed the code a bit in the transformation, it seemed like .hide() could
always be applied and show can now take a speed.

Also, I noticed that this plugin uses $(window).unbind("resize") to clear
its resize handler. That will also clear anyone else's resize handler!
Plugins should always pass in the second arg identifying the handler to be
removed, otherwise they won't play nicely with others.


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to