Click here to Skip to main content
15,888,233 members
Articles / jQuery

Fixing the jQueryUI Dialog Height in IE, the Quirks Way

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
7 Jun 2012CPOL1 min read 11.3K   2   1
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)


Written By
Software Developer GeekSoft
Lithuania Lithuania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
General[My vote of 1] Outdated or not functional at all Pin
Member 1035688712-Feb-14 1:10
Member 1035688712-Feb-14 1:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.