Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Fixing the jQueryUI dialog height in IE, the Quirks way

, 7 Jun 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
codeproject 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 f

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 2000's, 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 offended 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!

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)

Share

About the Author

Artem Smirnov
Software Developer Freelancer
Russian Federation Russian Federation
No Biography provided

Comments and Discussions

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

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 7 Jun 2012
Article Copyright 2012 by Artem Smirnov
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid