Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / jQuery

Fixing the jQueryUI Dialog Height in IE, the Quirks Way

0.00/5 (No votes)
7 Jun 2012CPOL1 min read 11.4K  
How to fix the jQueryUI dialog height in IE, the quirks way

Today, I had some fun trying to figure out how to fix the height of the jQueryUI dialog. The client wanted it to be exactly 500px. Or something that resembled 500px. Anyway, it definitely shouldn't have been from the top to the bottom of the screen. Although I sure set it to 500.

The fun part is that it had to work in IE7-9, but in *quirks* mode. The client won't switch to the standards mode, since the site (made in early 2000s, tables inside tables all the way down) would break apart.

After some debugging, I figured that one line in a certain method would save me. Namely, a fix would require adding a line at the beginning of the "_size" method. So, I could just leave it like that..

Except That I Couldn't.

Doing so wouldn't just violate the Open/Closed principle, it would offend the shadows of the Fathers of SOLIDity and the Alt.Net deities.

After all, JavaScript is a dynamic language, right? So, we can do whatever dirty trick we can think of, including messing with "private" methods.

Extending a jQueryUI Widget by Rewriting a Widget's Private Method? Nothing Could Be Easier!

JavaScript
var proto = $.ui.dialog.prototype;
var _size = proto._size;
proto._size = function(){ 
    this.element.hide(); 
    _size.apply(this); 
};

While I could easily put there something like alert('OHMYGOSH!!!') (and have fun imagining my coworkers trying to figure out what's going on), what I'm actually doing here is just add something to the beginning. So, first I'm saving a reference to the existing function, then I redefine it, adding the line I need and then invoking the function itself.

So, why do I feel like I've just committed a sin?

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)