1 /** 2 * @fileOverview Fixes to various browser quirks & bugs 3 * @author <a href="http://www.bobs-bits.com">Stephen Reay</a> 4 */ 5 6 /** 7 * @namespace Fixes to various browser quirks & bugs 8 */ 9 /* (function () { */ 10 BTM.Compatibility = {}; 11 12 /** 13 * @namespace Fixes for MSIE 14 */ 15 BTM.Compatibility.MSIE = {}; 16 17 /** 18 * @namespace Fixes for MSIE v6.x 19 */ 20 BTM.Compatibility.MSIE.Six = {}; 21 22 /** 23 * Fix the 'background flicker' problem in MSIE6 24 * @author <a href="http://www.mister-pixel.com/#Content__state=is_that_simple">Dan Popa</a> 25 */ 26 BTM.Compatibility.MSIE.Six.fixBackgroundCache = function fixBackgroundCache() { 27 BTM.log("Fixing Background Image Cache issue for MSIE 6"); 28 try { 29 document.execCommand("BackgroundImageCache", false, true); 30 } 31 catch(err) {} 32 }; 33 34 /** 35 * Fix the display of PNG images with Alpha transperancy 36 * @param {HTMLElement|String} element element ID or element reference to Image 37 * @requires BTM.DOM 38 */ 39 BTM.Compatibility.MSIE.Six.fixPNG = function fixPNG(element) { 40 element = BTM.$(element); 41 42 if (/png/gi.test(element.mimeType)) { 43 BTM.log("Fixing PNG Alpha Image issue for MSIE 6", element); 44 45 BTM.DOM.setStyle(element, 'filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + element.src + "')"); 46 BTM.DOM.setAttribute(element, 'src', BTM.options.imgdir + 'trans.gif'); 47 } 48 }; 49 50 /** 51 * Hide a SELECT element when the parent element is has a style of "display: none" dynamically applied in MSIE 6. Called automatically by BTM.Effect.hide and BTM.DOM.setStyle 52 * @param {HTMLElement|String} element element ID or element reference to SELECT element 53 */ 54 BTM.Compatibility.MSIE.Six.hideSELECT = function hideSELECT(element) { 55 BTM.DOM.setStyle(element, {'visibility':'hidden', 'position':'absolute'}); 56 }; 57 58 /** 59 * Show a SELECT element when the parent element is has a style of "display: none" dynamically removed under MSIE 6 60 * Called automatically by BTM.Effect.show and BTM.DOM.setStyle 61 * @param {HTMLElement|String} element element ID or element reference to SELECT element 62 */ 63 BTM.Compatibility.MSIE.Six.showSELECT = function showSELECT(element) { 64 BTM.DOM.setStyle(element, {'visibility':'', 'position':''}); 65 }; 66 67 68 /** 69 * Fix SELECT elements appearing in front of elements with a higher zIndex 70 * @param {HTMLElement|String} [element] an element ID or reference to the element which appears above the SELECT element 71 * @returns {HTMLElement} returns the original element 72 */ 73 BTM.Compatibility.MSIE.Six.fixSELECT = function fixSELECT(element) { 74 element = BTM.$(element); 75 76 var iframe = BTM.DOM.createElement('iframe', { 77 'src':'javascript:false', 78 'frameborder':'0', 79 'scrolling':'no' 80 }); 81 82 var size = BTM.DOM.getDimensions(element); 83 84 BTM.DOM.setStyle(iframe, { 85 'display':'none', 86 'position':'absolute', 87 'filter':'progid:DXImageTransform.Microsoft.Alpha(opacity=0)', 88 'width': size.width + 'px', 89 'height': size.height + 'px', 90 'zIndex' : BTM.DOM.getComputedStyle(element, 'zIndex') -1 91 }); 92 93 if (element.offsetParent.nodeName.toLowerCase() !== 'html') { 94 element.offsetParent.appendChild(iframe); 95 } 96 else { 97 document.body.appendChild(iframe); 98 } 99 100 return iframe; 101 }; 102 103 /** 104 * Convenience function to automatically add/remove the class "hover" to an element to mimic :hover 105 * @param {HTMLElement|String} [element] an element ID or reference to the element to mimic :hover on 106 * @returns {HTMLElement} returns the original element 107 */ 108 BTM.Compatibility.MSIE.Six.fixHover = function fixHover(element) { 109 element = BTM.$(element); 110 111 BTM.observe(element, 'mouseover', BTM.DOM.addClass.curry(element, 'hover')); 112 BTM.observe(element, 'mouseout', BTM.DOM.removeClass.curry(element, 'hover')); 113 return element; 114 }; 115 116 /** 117 * Convenience function to automatically add the class "first-child" to an element to mimic :first-child 118 * @param {HTMLElement|String} [element] an element ID or reference to the element to mimic :first-child on 119 * @returns {HTMLElement} returns the original element 120 */ 121 BTM.Compatibility.MSIE.Six.fixFirstChild = function fixFirstChild(element) { 122 BTM.DOM.addClass(element, 'first-child'); 123 }; 124 125 if (BTM.Browser.is('Trident', 6, 'lte')) { 126 BTM.Compatibility.MSIE.Six.fixBackgroundCache(); 127 BTM.Mapping.add('*:first-child', BTM.Compatibility.MSIE.Six.fixFirstChild); 128 BTM.Mapping.add('img[src$=".png"]', BTM.Compatibility.MSIE.Six.fixPNG); 129 }