root/galaxy-central/static/scripts/ie7-recalc.js @ 2

リビジョン 2, 4.8 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
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: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。