Permalink
Browse files

Change IE version detection to use conditional-comment method courtes…

…y of James Padolsey, as it is more reliable than the old approach (DynaTrace magically makes XMLHttpRequest defined in IE6!)
  • Loading branch information...
1 parent 694dd02 commit 200f9b4dc84854bbaea668d993dd2dd20a4cd053 Jason Johnston committed Aug 22, 2010
View
2 sources/BackgroundRenderer.js
@@ -150,7 +150,7 @@ PIE.BackgroundRenderer = PIE.RendererBase.newRenderer( {
pxX, pxY,
clipT = 0, clipL = 0,
clipR = elW + 1, clipB = elH + 1, //make sure the default clip region is not inside the box (by a subpixel)
- clipAdjust = PIE.isIE8 ? 0 : 1; //prior to IE8 requires 1 extra pixel in the image clip region
+ clipAdjust = PIE.ieVersion === 8 ? 0 : 1; //prior to IE8 requires 1 extra pixel in the image clip region
// Positioning - find the pixel offset from the top/left and convert to a ratio
// The position is shifted by half a pixel, to adjust for the half-pixel coordorigin shift which is
View
4 sources/BorderRenderer.js
@@ -101,11 +101,11 @@ PIE.BorderRenderer = PIE.RendererBase.newRenderer( {
rs[ 'padding' + side ] = '';
rs[ 'padding' + side ] = ( new PIE.Length( cs[ 'padding' + side ] ) ).pixels( el ) +
( new PIE.Length( cs[ 'border' + side + 'Width' ] ) ).pixels( el ) +
- ( !PIE.isIE8 && i % 2 ? 1 : 0 ); //needs an extra horizontal pixel to counteract the extra "inner border" going away
+ ( !PIE.ieVersion === 8 && i % 2 ? 1 : 0 ); //needs an extra horizontal pixel to counteract the extra "inner border" going away
}
rs.borderWidth = 0;
}
- else if( PIE.isIE6 ) {
+ else if( PIE.ieVersion === 6 ) {
// Wrap all the element's children in a custom element, set the element to visiblity:hidden,
// and set the wrapper element to visiblity:visible. This hides the outer element's decorations
// (background and border) but displays all the contents.
View
2 sources/BoxShadowOutsetRenderer.js
@@ -32,7 +32,7 @@ PIE.BoxShadowOutsetRenderer = PIE.RendererBase.newRenderer( {
i = len, j,
w = el.offsetWidth,
h = el.offsetHeight,
- clipAdjust = PIE.isIE8 ? 1 : 0, //workaround for IE8 bug where VML leaks out top/left of clip region by 1px
+ clipAdjust = PIE.ieVersion === 8 ? 1 : 0, //workaround for IE8 bug where VML leaks out top/left of clip region by 1px
corners = [ 'tl', 'tr', 'br', 'bl' ], corner,
shadowInfo, shape, fill, ss, xOff, yOff, spread, blur, shrink, color, alpha, path,
totalW, totalH, focusX, focusY, isBottom, isRight;
View
25 sources/PIE_open.js
@@ -7,10 +7,26 @@ if( !PIE ) {
CLASS_PREFIX: 'pie_'
};
- // Detect IE6
- if( !window.XMLHttpRequest ) {
- PIE.isIE6 = true;
+ /*
+ * IE version detection approach by James Padolsey, with modifications -- from
+ * http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/
+ */
+ PIE.ieVersion = function(){
+ var v = 4,
+ div = element.document.createElement('div'),
+ all = div.getElementsByTagName('i');
+
+ while (
+ div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
+ all[0]
+ ) {}
+
+ return v;
+ }();
+
+ // Detect IE6
+ if( PIE.ieVersion === 6 ) {
// IE6 can't access properties with leading dash, but can without it.
PIE.CSS_PREFIX = PIE.CSS_PREFIX.replace( /^-/, '' );
@@ -19,5 +35,4 @@ if( !PIE ) {
}
// Detect IE8
- PIE.ie8DocMode = element.document.documentMode;
- PIE.isIE8 = !!PIE.ie8DocMode;
+ PIE.ie8DocMode = PIE.ieVersion === 8 && element.document.documentMode;
View
4 sources/event_handlers.js
@@ -74,7 +74,7 @@ function propChanged() {
*/
function mouseEntered() {
var el = event.srcElement;
- if( PIE.isIE6 && el.tagName !== 'A' ) {
+ if( PIE.ieVersion === 6 && el.tagName !== 'A' ) {
el.className += ' ' + PIE.CLASS_PREFIX + 'hover';
}
//must delay this because the mouseleave event fires before the :hover styles are added.
@@ -85,7 +85,7 @@ function mouseEntered() {
*/
function mouseLeft() {
var el = event.srcElement;
- if( PIE.isIE6 && el.tagName !== 'A' ) {
+ if( PIE.ieVersion === 6 && el.tagName !== 'A' ) {
el.className = el.className.replace( PIE.hoverClassRE, '' );
}
//must delay this because the mouseleave event fires before the :hover styles are removed.

0 comments on commit 200f9b4

Please sign in to comment.