Changeset 703:1a44cbb3ca1a for admin/js/ie7/ie7-recalc.js
- Timestamp:
- 09/05/11 21:22:12 (14 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/js/ie7/ie7-recalc.js
r0 r703 1 /* IE7/IE8.js - copyright 2004-2008, Dean Edwards */ 2 (function(){if(!IE7.loaded)return;CLASSES=/\sie7_class\d+/g;IE7.CSS.extend({elements:{},handlers:[],reset:function(){this.removeEventHandlers();var a=this.elements;for(var b in a)a[b].runtimeStyle.cssText="";this.elements={};var a=IE7.Rule.elements;for(var b in a){with(a[b])className=className.replace(CLASSES,"")}IE7.Rule.elements={}},reload:function(){this.rules=[];this.getInlineStyles();this.screen.load();if(this.print)this.print.load();this.refresh();this.trash()},addRecalc:function(b,c,d,e){this.base(b,c,function(a){d(a);IE7.CSS.elements[a.uniqueID]=a},e)},recalc:function(){this.reset();this.base()},addEventHandler:function(a,b,c){a.attachEvent(b,c);this.handlers.push(arguments)},removeEventHandlers:function(){var a;while(a=this.handlers.pop()){a[0].detachEvent(a[1],a[2])}},getInlineStyles:function(){var a=document.getElementsByTagName("style"),b;for(var c=a.length-1;(b=a[c]);c--){if(!b.disabled&&!b.ie7){var d=b.cssText||b.innerHTML;this.styles.push(d);b.cssText=d}}},trash:function(){var a=document.styleSheets,b,c;for(c=0;c<a.length;c++){b=a[c];if(!b.ie7&&!b.cssText){b.cssText=b.cssText}}this.base()},getText:function(a){return a.cssText||this.base(a)}});IE7.CSS.addEventHandler(window,"onunload",function(){IE7.CSS.removeEventHandlers()});IE7.Rule.elements={};IE7.Rule.prototype.extend({add:function(a){this.base(a);IE7.Rule.elements[a.uniqueID]=a}});if(IE7.PseudoElement){IE7.PseudoElement.hash={};IE7.PseudoElement.prototype.extend({create:function(a){var b=this.selector+":"+a.uniqueID;if(!IE7.PseudoElement.hash[b]){IE7.PseudoElement.hash[b]=true;this.base(a)}}})}IE7.HTML.extend({elements:{},addRecalc:function(b,c){this.base(b,function(a){if(!this.elements[a.uniqueID]){c(a);this.elements[a.uniqueID]=a}})}});document.recalc=function(a){if(IE7.CSS.screen){if(a)IE7.CSS.reload();IE7.recalc()}}})(); 1 2 // ========================================================================= 3 // ie7-recalc.js 4 // ========================================================================= 5 6 (function() { 7 /* --------------------------------------------------------------------- 8 9 This allows refreshing of IE7 style rules. If you modify the DOM 10 you can update IE7 by calling document.recalc(). 11 12 This should be the LAST module included. 13 14 --------------------------------------------------------------------- */ 15 16 if (!IE7.loaded) return; 17 18 // remove all IE7 classes from an element 19 CLASSES = /\sie7_class\d+/g; 20 21 IE7.CSS.extend({ 22 // store for elements that have style properties calculated 23 elements: {}, 24 handlers: [], 25 26 // clear IE7 classes and styles 27 reset: function() { 28 this.removeEventHandlers(); 29 // reset IE7 classes here 30 var elements = this.elements; 31 for (var i in elements) elements[i].runtimeStyle.cssText = ""; 32 this.elements = {}; 33 // reset runtimeStyle here 34 var elements = IE7.Rule.elements; 35 for (var i in elements) { 36 with (elements[i]) className = className.replace(CLASSES, ""); 37 } 38 IE7.Rule.elements = {}; 39 }, 40 41 reload: function() { 42 this.rules = []; 43 this.getInlineStyles(); 44 this.screen.load(); 45 if (this.print) this.print.load(); 46 this.refresh(); 47 this.trash(); 48 }, 49 50 addRecalc: function(propertyName, test, handler, replacement) { 51 // call the ancestor method to add a wrapped recalc method 52 this.base(propertyName, test, function(element) { 53 // execute the original recalc method 54 handler(element); 55 // store a reference to this element so we can clear its style later 56 IE7.CSS.elements[element.uniqueID] = element; 57 }, replacement); 58 }, 59 60 recalc: function() { 61 // clear IE7 styles and classes 62 this.reset(); 63 // execute the ancestor method to perform recalculations 64 this.base(); 65 }, 66 67 addEventHandler: function(element, type, handler) { 68 element.attachEvent(type, handler); 69 // store the handler so it can be detached later 70 this.handlers.push(arguments); 71 }, 72 73 removeEventHandlers: function() { 74 var handler; 75 while (handler = this.handlers.pop()) { 76 handler[0].detachEvent(handler[1], handler[2]); 77 } 78 }, 79 80 getInlineStyles: function() { 81 // load inline styles 82 var styleSheets = document.getElementsByTagName("style"), styleSheet; 83 for (var i = styleSheets.length - 1; (styleSheet = styleSheets[i]); i--) { 84 if (!styleSheet.disabled && !styleSheet.ie7) { 85 var cssText = styleSheet.cssText || styleSheet.innerHTML; 86 this.styles.push(cssText); 87 styleSheet.cssText = cssText; 88 } 89 } 90 }, 91 92 trash: function() { 93 // trash the old style sheets 94 var styleSheets = document.styleSheets, styleSheet, i; 95 for (i = 0; i < styleSheets.length; i++) { 96 styleSheet = styleSheets[i]; 97 if (!styleSheet.ie7 && !styleSheet.cssText) { 98 styleSheet.cssText = styleSheet.cssText; 99 } 100 } 101 this.base(); 102 }, 103 104 getText: function(styleSheet) { 105 return styleSheet.cssText || this.base(styleSheet); 106 } 107 }); 108 109 // remove event handlers (they eat memory) 110 IE7.CSS.addEventHandler(window, "onunload", function() { 111 IE7.CSS.removeEventHandlers(); 112 }); 113 114 // store all elements with an IE7 class assigned 115 IE7.Rule.elements = {}; 116 117 IE7.Rule.prototype.extend({ 118 add: function(element) { 119 // execute the ancestor "add" method 120 this.base(element); 121 // store a reference to this element so we can clear its classes later 122 IE7.Rule.elements[element.uniqueID] = element; 123 } 124 }); 125 126 // store created pseudo elements 127 if (IE7.PseudoElement) { 128 IE7.PseudoElement.hash = {}; 129 130 IE7.PseudoElement.prototype.extend({ 131 create: function(target) { 132 var key = this.selector + ":" + target.uniqueID; 133 if (!IE7.PseudoElement.hash[key]) { 134 IE7.PseudoElement.hash[key] = true; 135 this.base(target); 136 } 137 } 138 }); 139 } 140 141 IE7.HTML.extend({ 142 elements: {}, 143 144 addRecalc: function(selector, handler) { 145 // call the ancestor method to add a wrapped recalc method 146 this.base(selector, function(element) { 147 if (!this.elements[element.uniqueID]) { 148 // execute the original recalc method 149 handler(element); 150 // store a reference to this element so that 151 // it is not "fixed" again 152 this.elements[element.uniqueID] = element; 153 } 154 }); 155 } 156 }); 157 158 // allow refreshing of IE7 fixes 159 document.recalc = function(reload) { 160 if (IE7.CSS.screen) { 161 if (reload) IE7.CSS.reload(); 162 IE7.recalc(); 163 } 164 }; 165 166 })();
Note: See TracChangeset
for help on using the changeset viewer.