forked from Integralist/Dean-Edwards--IE-7-and-8-and-9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IE9.js
executable file
·2901 lines (2513 loc) · 100 KB
/
IE9.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
IE7/IE8/IE9.js - copyright 2004-2010, Dean Edwards
http://code.google.com/p/ie7-js/
http://www.opensource.org/licenses/mit-license.php
*/
/* W3C compliance for Microsoft Internet Explorer */
/* credits/thanks:
Shaggy, Martijn Wargers, Jimmy Cerra, Mark D Anderson,
Lars Dieckow, Erik Arvidsson, Gellért Gyuris, James Denny,
Unknown W Brackets, Benjamin Westfarer, Rob Eberhardt,
Bill Edney, Kevin Newman, James Crompton, Matthew Mastracci,
Doug Wright, Richard York, Kenneth Kolano, MegaZone,
Thomas Verelst, Mark 'Tarquin' Wilton-Jones, Rainer Åhlfors,
David Zulaica, Ken Kolano, Kevin Newman, Sjoerd Visscher,
Ingo Chao
*/
// timestamp: Fri, 30 Apr 2010 20:59:18
(function(window, document) {
var IE7 = window.IE7 = {
version: "2.1(beta4)",
toString: K("[IE7]")
};
IE7.compat = 9;
var appVersion = IE7.appVersion = navigator.appVersion.match(/MSIE (\d\.\d)/)[1] - 0;
if (/ie7_off/.test(top.location.search) || appVersion < 5.5 || appVersion >= IE7.compat) return;
var MSIE5 = appVersion < 6;
var Undefined = K();
var documentElement = document.documentElement, body, viewport;
var ANON = "!";
var HEADER = ":link{ie7-link:link}:visited{ie7-link:visited}";
// -----------------------------------------------------------------------
// external
// -----------------------------------------------------------------------
var RELATIVE = /^[\w\.]+[^:]*$/;
function makePath(href, path) {
if (RELATIVE.test(href)) href = (path || "") + href;
return href;
};
function getPath(href, path) {
href = makePath(href, path);
return href.slice(0, href.lastIndexOf("/") + 1);
};
// Get the path to this script
var script = document.scripts[document.scripts.length - 1];
var path = getPath(script.src);
// Use microsoft's http request object to load external files
try {
var httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (ex) {
// ActiveX disabled
}
var fileCache = {};
function loadFile(href, path) {
try {
href = makePath(href, path);
if (!fileCache[href]) {
httpRequest.open("GET", href, false);
httpRequest.send();
if (httpRequest.status == 0 || httpRequest.status == 200) {
fileCache[href] = httpRequest.responseText;
}
}
} catch (ex) {
// ignore errors
}
return fileCache[href] || "";
};
// -----------------------------------------------------------------------
// OO support
// -----------------------------------------------------------------------
// This is a cut-down version of base2 (http://code.google.com/p/base2/)
var _slice = Array.prototype.slice;
// private
var _FORMAT = /%([1-9])/g;
var _LTRIM = /^\s\s*/;
var _RTRIM = /\s\s*$/;
var _RESCAPE = /([\/()[\]{}|*+-.,^$?\\])/g; // safe regular expressions
var _BASE = /\bbase\b/;
var _HIDDEN = ["constructor", "toString"]; // only override these when prototyping
var prototyping;
function Base(){};
Base.extend = function(_instance, _static) {
// Build the prototype.
prototyping = true;
var _prototype = new this;
extend(_prototype, _instance);
prototyping = false;
// Create the wrapper for the constructor function.
var _constructor = _prototype.constructor;
function klass() {
// Don't call the constructor function when prototyping.
if (!prototyping) _constructor.apply(this, arguments);
};
_prototype.constructor = klass;
// Build the static interface.
klass.extend = arguments.callee;
extend(klass, _static);
klass.prototype = _prototype;
return klass;
};
Base.prototype.extend = function(source) {
return extend(this, source);
};
// A collection of regular expressions and their associated replacement values.
// A Base class for creating parsers.
var HASH = "#";
var ITEMS = "#";
var KEYS = ".";
var COMPILED = "/";
var REGGRP_BACK_REF = /\\(\d+)/g,
REGGRP_ESCAPE_COUNT = /\[(\\.|[^\]\\])+\]|\\.|\(\?/g,
REGGRP_PAREN = /\(/g,
REGGRP_LOOKUP = /\$(\d+)/,
REGGRP_LOOKUP_SIMPLE = /^\$\d+$/,
REGGRP_LOOKUPS = /(\[(\\.|[^\]\\])+\]|\\.|\(\?)|\(/g,
REGGRP_DICT_ENTRY = /^<#\w+>$/,
REGGRP_DICT_ENTRIES = /<#(\w+)>/g;
var RegGrp = Base.extend({
constructor: function(values) {
this[KEYS] = [];
this[ITEMS] = {};
this.merge(values);
},
//dictionary: null,
//ignoreCase: false,
add: function(expression, replacement) {
delete this[COMPILED];
if (expression instanceof RegExp) {
expression = expression.source;
}
if (!this[HASH + expression]) this[KEYS].push(String(expression));
return this[ITEMS][HASH + expression] = new RegGrp.Item(expression, replacement, this);
},
compile: function(recompile) {
if (recompile || !this[COMPILED]) {
this[COMPILED] = new RegExp(this, this.ignoreCase ? "gi" : "g");
}
return this[COMPILED];
},
merge: function(values) {
for (var i in values) this.add(i, values[i]);
},
exec: function(string) {
var group = this,
patterns = group[KEYS],
items = group[ITEMS], item;
var result = this.compile(true).exec(string);
if (result) {
// Loop through the RegGrp items.
var i = 0, offset = 1;
while ((item = items[HASH + patterns[i++]])) {
var next = offset + item.length + 1;
if (result[offset]) { // do we have a result?
if (item.replacement === 0) {
return group.exec(string);
} else {
var args = result.slice(offset, next), j = args.length;
while (--j) args[j] = args[j] || ""; // some platforms return null/undefined for non-matching sub-expressions
args[0] = {match: args[0], item: item};
return args;
}
}
offset = next;
}
}
return null;
},
parse: function(string) {
string += ""; // type safe
var group = this,
patterns = group[KEYS],
items = group[ITEMS];
return string.replace(this.compile(), function(match) {
var args = [], item, offset = 1, i = arguments.length;
while (--i) args[i] = arguments[i] || ""; // some platforms return null/undefined for non-matching sub-expressions
// Loop through the RegGrp items.
while ((item = items[HASH + patterns[i++]])) {
var next = offset + item.length + 1;
if (args[offset]) { // do we have a result?
var replacement = item.replacement;
switch (typeof replacement) {
case "function":
return replacement.apply(group, args.slice(offset, next));
case "number":
return args[offset + replacement];
default:
return replacement;
}
}
offset = next;
}
return match;
});
},
toString: function() {
var strings = [],
keys = this[KEYS],
items = this[ITEMS], item;
for (var i = 0; item = items[HASH + keys[i]]; i++) {
strings[i] = item.source;
}
return "(" + strings.join(")|(") + ")";
}
}, {
IGNORE: null, // a null replacement value means that there is no replacement.
Item: Base.extend({
constructor: function(source, replacement, owner) {
var length = source.indexOf("(") === -1 ? 0 : RegGrp.count(source);
var dictionary = owner.dictionary;
if (dictionary && source.indexOf("<#") !== -1) {
if (REGGRP_DICT_ENTRY.test(source)) {
var entry = dictionary[ITEMS][HASH + source.slice(2, -1)];
source = entry.replacement;
length = entry._length;
} else {
source = dictionary.parse(source);
}
}
if (typeof replacement == "number") replacement = String(replacement);
else if (replacement == null) replacement = 0;
// Does the expression use sub-expression lookups?
if (typeof replacement == "string" && REGGRP_LOOKUP.test(replacement)) {
if (REGGRP_LOOKUP_SIMPLE.test(replacement)) { // A simple lookup? (e.g. "$2").
// Store the index (used for fast retrieval of matched strings).
var index = replacement.slice(1) - 0;
if (index && index <= length) replacement = index;
} else {
// A complicated lookup (e.g. "Hello $2 $1.").
var lookup = replacement, regexp;
replacement = function(match) {
if (!regexp) {
regexp = new RegExp(source, "g" + (this.ignoreCase ? "i": ""));
}
return match.replace(regexp, lookup);
};
}
}
this.length = length;
this.source = String(source);
this.replacement = replacement;
}
}),
count: function(expression) {
return (String(expression).replace(REGGRP_ESCAPE_COUNT, "").match(REGGRP_PAREN) || "").length;
}
});
var Dictionary = RegGrp.extend({
parse: function(phrase) {
// Prevent sub-expressions in dictionary entries from capturing.
var entries = this[ITEMS];
return phrase.replace(REGGRP_DICT_ENTRIES, function(match, entry) {
entry = entries[HASH + entry];
return entry ? entry._nonCapturing : match;
});
},
add: function(expression, replacement) {
// Get the underlying replacement value.
if (replacement instanceof RegExp) {
replacement = replacement.source;
}
// Translate the replacement.
// The result is the original replacement recursively parsed by this dictionary.
var nonCapturing = replacement.replace(REGGRP_LOOKUPS, _nonCapture);
if (replacement.indexOf("(") !== -1) {
var realLength = RegGrp.count(replacement);
}
if (replacement.indexOf("<#") !== -1) {
replacement = this.parse(replacement);
nonCapturing = this.parse(nonCapturing);
}
var item = this.base(expression, replacement);
item._nonCapturing = nonCapturing;
item._length = realLength || item.length; // underlying number of sub-groups
return item;
},
toString: function() {
return "(<#" + this[PATTERNS].join(">)|(<#") + ">)";
}
});
function _nonCapture(match, escaped) {
return escaped || "(?:"; // non-capturing
};
// =========================================================================
// lang/extend.js
// =========================================================================
function extend(object, source) { // or extend(object, key, value)
if (object && source) {
var proto = (typeof source == "function" ? Function : Object).prototype;
// Add constructor, toString etc
var i = _HIDDEN.length, key;
if (prototyping) while (key = _HIDDEN[--i]) {
var value = source[key];
if (value != proto[key]) {
if (_BASE.test(value)) {
_override(object, key, value)
} else {
object[key] = value;
}
}
}
// Copy each of the source object's properties to the target object.
for (key in source) if (typeof proto[key] == "undefined") {
var value = source[key];
// Check for method overriding.
if (object[key] && typeof value == "function" && _BASE.test(value)) {
_override(object, key, value);
} else {
object[key] = value;
}
}
}
return object;
};
function _override(object, name, method) {
// Override an existing method.
var ancestor = object[name];
object[name] = function() {
var previous = this.base;
this.base = ancestor;
var returnValue = method.apply(this, arguments);
this.base = previous;
return returnValue;
};
};
function combine(keys, values) {
// Combine two arrays to make a hash.
if (!values) values = keys;
var hash = {};
for (var i in keys) hash[i] = values[i];
return hash;
};
function format(string) {
// Replace %n with arguments[n].
// e.g. format("%1 %2%3 %2a %1%3", "she", "se", "lls");
// ==> "she sells sea shells"
// Only %1 - %9 supported.
var args = arguments;
var _FORMAT = new RegExp("%([1-" + arguments.length + "])", "g");
return String(string).replace(_FORMAT, function(match, index) {
return index < args.length ? args[index] : match;
});
};
function match(string, expression) {
// Same as String.match() except that this function will return an empty
// array if there is no match.
return String(string).match(expression) || [];
};
function rescape(string) {
// Make a string safe for creating a RegExp.
return String(string).replace(_RESCAPE, "\\$1");
};
// http://blog.stevenlevithan.com/archives/faster-trim-javascript
function trim(string) {
return String(string).replace(_LTRIM, "").replace(_RTRIM, "");
};
function K(k) {
return function() {
return k;
};
};
// -----------------------------------------------------------------------
// parsing
// -----------------------------------------------------------------------
var Parser = RegGrp.extend({ignoreCase: true});
var SINGLE_QUOTES = /'/g,
ESCAPED = /'(\d+)'/g,
ESCAPE = /\\/g,
UNESCAPE = /\\([nrtf'"])/g;
var strings = [];
var encoder = new Parser({
// comments
"<!\\-\\-|\\-\\->": "",
"\\/\\*[^*]*\\*+([^\\/][^*]*\\*+)*\\/": "",
// get rid
"@(namespace|import)[^;\\n]+[;\\n]": "",
// strings
"'(\\\\.|[^'\\\\])*'": encodeString,
'"(\\\\.|[^"\\\\])*"': encodeString,
// white space
"\\s+": " "
});
function encode(selector) {
return encoder.parse(selector).replace(UNESCAPE, "$1");
};
function decode(query) {
// put string values back
return query.replace(ESCAPED, decodeString);
};
function encodeString(string) {
var index = strings.length;
strings[index] = string.slice(1, -1)
.replace(UNESCAPE, "$1")
.replace(SINGLE_QUOTES, "\\'");
return "'" + index + "'";
};
function decodeString(match, index) {
var string = strings[index];
if (string == null) return match;
return "'" + strings[index] + "'";
};
function getString(value) {
return value.indexOf("'") === 0 ? strings[value.slice(1, - 1)] : value;
};
// clone a "width" function to create a "height" function
var rotater = new RegGrp({
Width: "Height",
width: "height",
Left: "Top",
left: "top",
Right: "Bottom",
right: "bottom",
onX: "onY"
});
function rotate(fn) {
return rotater.parse(fn);
};
// -----------------------------------------------------------------------
// event handling
// -----------------------------------------------------------------------
var eventHandlers = [];
function addResize(handler) {
addRecalc(handler);
addEventHandler(window, "onresize", handler);
};
// add an event handler (function) to an element
function addEventHandler(element, type, handler) {
element.attachEvent(type, handler);
// store the handler so it can be detached later
eventHandlers.push(arguments);
};
// remove an event handler assigned to an element by IE7
function removeEventHandler(element, type, handler) {
try {
element.detachEvent(type, handler);
} catch (ex) {
// write a letter of complaint to microsoft..
}
};
// remove event handlers (they eat memory)
addEventHandler(window, "onunload", function() {
var handler;
while (handler = eventHandlers.pop()) {
removeEventHandler(handler[0], handler[1], handler[2]);
}
});
function register(handler, element, condition) { // -@DRE
//var set = handler[element.uniqueID];
if (!handler.elements) handler.elements = {};
if (condition) handler.elements[element.uniqueID] = element;
else delete handler.elements[element.uniqueID];
//return !set && condition;
return condition;
};
addEventHandler(window, "onbeforeprint", function() {
if (!IE7.CSS.print) new StyleSheet("print");
IE7.CSS.print.recalc();
});
// -----------------------------------------------------------------------
// pixel conversion
// -----------------------------------------------------------------------
// this is handy because it means that web developers can mix and match
// measurement units in their style sheets. it is not uncommon to
// express something like padding in "em" units whilst border thickness
// is most often expressed in pixels.
var PIXEL = /^\d+(px)?$/i;
var PERCENT = /^\d+%$/;
var getPixelValue = function(element, value) {
if (PIXEL.test(value)) return parseInt(value);
var style = element.style.left;
var runtimeStyle = element.runtimeStyle.left;
element.runtimeStyle.left = element.currentStyle.left;
element.style.left = value || 0;
value = element.style.pixelLeft;
element.style.left = style;
element.runtimeStyle.left = runtimeStyle;
return value;
};
// -----------------------------------------------------------------------
// generic
// -----------------------------------------------------------------------
var $IE7 = "ie7-";
var Fix = Base.extend({
constructor: function() {
this.fixes = [];
this.recalcs = [];
},
init: Undefined
});
// a store for functions that will be called when refreshing IE7
var recalcs = [];
function addRecalc(recalc) {
recalcs.push(recalc);
};
IE7.recalc = function() {
IE7.HTML.recalc();
// re-apply style sheet rules (re-calculate ie7 classes)
IE7.CSS.recalc();
// apply global fixes to the document
for (var i = 0; i < recalcs.length; i++) recalcs[i]();
};
function isFixed(element) {
return element.currentStyle["ie7-position"] == "fixed";
};
// original style
function getDefinedStyle(element, propertyName) {
return element.currentStyle[$IE7 + propertyName] || element.currentStyle[propertyName];
};
function setOverrideStyle(element, propertyName, value) {
if (element.currentStyle[$IE7 + propertyName] == null) {
element.runtimeStyle[$IE7 + propertyName] = element.currentStyle[propertyName];
}
element.runtimeStyle[propertyName] = value;
};
// Create a temporary element which is used to inherit styles
// from the target element.
function createTempElement(tagName) {
var element = document.createElement(tagName || "object");
element.style.cssText = "position:absolute;padding:0;display:block;border:none;clip:rect(0 0 0 0);left:-9999";
element.ie7_anon = true;
return element;
};
// =========================================================================
// ie7-css.js
// =========================================================================
var NEXT_SIBLING = "(e.nextSibling&&IE7._getElementSibling(e,'next'))",
PREVIOUS_SIBLING = NEXT_SIBLING.replace(/next/g, "previous"),
IS_ELEMENT = "e.nodeName>'@'",
IF_ELEMENT = "if(" + IS_ELEMENT + "){";
var ID_ATTRIBUTE = "(e.nodeName==='FORM'?IE7._getAttribute(e,'id'):e.id)";
var HYPERLINK = /a(#[\w-]+)?(\.[\w-]+)?:(hover|active)/i;
var FIRST_LINE_LETTER = /(.*)(:first-(line|letter))/;
var SPACE = /\s/;
var RULE = /((?:\\.|[^{\\])+)\{((?:\\.|[^}\\])+)\}/g;
var SELECTOR = /(?:\\.|[^,\\])+/g;
var styleSheets = document.styleSheets;
var inheritedProperties = [];
IE7.CSS = new (Fix.extend({ // single instance
parser: new Parser,
screen: "",
print: "",
styles: [],
rules: [],
pseudoClasses: appVersion < 7 ? "first\\-child" : "",
dynamicPseudoClasses: {
toString: function() {
var strings = [];
for (var pseudoClass in this) strings.push(pseudoClass);
return strings.join("|");
}
},
init: function() {
var NONE = "^\x01$";
var CLASS = "\\[class=?[^\\]]*\\]";
var pseudoClasses = [];
if (this.pseudoClasses) pseudoClasses.push(this.pseudoClasses);
var dynamicPseudoClasses = this.dynamicPseudoClasses.toString();
if (dynamicPseudoClasses) pseudoClasses.push(dynamicPseudoClasses);
pseudoClasses = pseudoClasses.join("|");
var unknown = appVersion < 7 ? ["[>+~\\[(]|([:.])[\\w-]+\\1"] : [CLASS];
if (pseudoClasses) unknown.push(":(" + pseudoClasses + ")");
this.UNKNOWN = new RegExp(unknown.join("|") || NONE, "i");
var complex = appVersion < 7 ? ["\\[[^\\]]+\\]|[^\\s(\\[]+\\s*[+~]"] : [CLASS];
var complexRule = complex.concat();
if (pseudoClasses) complexRule.push(":(" + pseudoClasses + ")");
Rule.COMPLEX = new RegExp(complexRule.join("|") || NONE, "ig");
if (this.pseudoClasses) complex.push(":(" + this.pseudoClasses + ")");
DynamicRule.COMPLEX = new RegExp(complex.join("|") || NONE, "i");
dynamicPseudoClasses = "not\\(:" + dynamicPseudoClasses.split("|").join("\\)|not\\(:") + "\\)|" + dynamicPseudoClasses;
DynamicRule.MATCH = new RegExp(dynamicPseudoClasses ? "(.*?):(" + dynamicPseudoClasses + ")(.*)" : NONE, "i");
this.createStyleSheet();
this.refresh();
},
addEventHandler: function() {
addEventHandler.apply(null, arguments);
},
addFix: function(expression, replacement) {
this.parser.add(expression, replacement);
},
addRecalc: function(propertyName, test, handler, replacement) {
// recalcs occur whenever the document is refreshed using document.recalc()
propertyName = propertyName.source || propertyName;
test = new RegExp("([{;\\s])" + propertyName + "\\s*:\\s*" + test + "[^;}]*");
var id = this.recalcs.length;
if (typeof replacement == "string") replacement = propertyName + ":" + replacement;
this.addFix(test, function(match) {
if (typeof replacement == "function") replacement = replacement(match);
return (replacement ? replacement : match) + ";ie7-" + match.slice(1) + ";ie7_recalc" + id + ":1";
});
this.recalcs.push(arguments);
return id;
},
apply: function() {
this.getInlineCSS();
new StyleSheet("screen");
this.trash();
},
createStyleSheet: function() {
// create the IE7 style sheet
document.getElementsByTagName("head")[0].appendChild(document.createElement("style"));
this.styleSheet = styleSheets[styleSheets.length - 1];
// flag it so we can ignore it during parsing
this.styleSheet.ie7 = true;
this.styleSheet.owningElement.ie7 = true;
this.styleSheet.cssText = HEADER;
},
getInlineCSS: function() {// load inline styles
var styleSheets = document.getElementsByTagName("style"), styleSheet;
for (var i = styleSheets.length - 1; styleSheet = styleSheets[i]; i--) {
if (!styleSheet.disabled && !styleSheet.ie7) {
styleSheet._cssText = styleSheet.innerHTML;
}
}
},
getText: function(styleSheet, path) {
// Internet Explorer will trash unknown selectors (it converts them to "UNKNOWN").
// So we must reload external style sheets (internal style sheets can have their text
// extracted through the innerHTML property).
// load the style sheet text from an external file
try {
var cssText = styleSheet.cssText;
} catch (e) {
cssText = "";
}
if (httpRequest) cssText = loadFile(styleSheet.href, path) || cssText;
return cssText;
},
recalc: function() {
this.screen.recalc();
// we're going to read through all style rules.
// certain rules have had ie7 properties added to them.
// e.g. p{top:0; ie7_recalc2:1; left:0}
// this flags a property in the rule as needing a fix.
// the selector text is then used to query the document.
// we can then loop through the results of the query
// and fix the elements.
// we ignore the IE7 rules - so count them in the header
var RECALCS = /ie7_recalc\d+/g;
var start = HEADER.match(/[{,]/g).length;
// only calculate screen fixes. print fixes don't show up anyway
var rules = this.styleSheet.rules, rule;
var calcs, calc, elements, element, i, j, k, id;
// loop through all rules
for (i = start; rule = rules[i]; i++) {
var cssText = rule.style.cssText;
// search for the "ie7_recalc" flag (there may be more than one)
if (calcs = cssText.match(RECALCS)) {
// use the selector text to query the document
elements = cssQuery(rule.selectorText);
// if there are matching elements then loop
// through the recalc functions and apply them
// to each element
if (elements.length) for (j = 0; j < calcs.length; j++) {
// get the matching flag (e.g. ie7_recalc3)
id = calcs[j];
// extract the numeric id from the end of the flag
// and use it to index the collection of recalc
// functions
calc = IE7.CSS.recalcs[id.slice(10)][2];
for (k = 0; (element = elements[k]); k++) {
// apply the fix
if (element.currentStyle[id]) calc(element, cssText);
}
}
}
}
},
refresh: function() {
this.styleSheet.cssText = HEADER + this.screen + this.print;
},
trash: function() {
// trash the old style sheets
for (var i = 0; i < styleSheets.length; i++) {
if (!styleSheets[i].ie7) {
try {
var cssText = styleSheets[i].cssText;
} catch (e) {
cssText = "";
}
if (cssText) styleSheets[i].cssText = "";
}
}
}
}));
// -----------------------------------------------------------------------
// IE7 StyleSheet class
// -----------------------------------------------------------------------
var StyleSheet = Base.extend({
constructor: function(media) {
this.media = media;
this.load();
IE7.CSS[media] = this;
IE7.CSS.refresh();
},
createRule: function(selector, cssText) {
var match;
if (PseudoElement && (match = selector.match(PseudoElement.MATCH))) {
return new PseudoElement(match[1], match[2], cssText);
} else if (match = selector.match(DynamicRule.MATCH)) {
if (!HYPERLINK.test(match[0]) || DynamicRule.COMPLEX.test(match[0])) {
return new DynamicRule(selector, match[1], match[2], match[3], cssText);
}
} else {
return new Rule(selector, cssText);
}
return selector + " {" + cssText + "}";
},
getText: function() {
// store for style sheet text
// parse media decalarations
var MEDIA = /@media\s+([^{]+?)\s*\{([^@]+\})\s*\}/gi;
var IMPORTS = /@import[^;\n]+/gi;
var TRIM_IMPORTS = /@import\s+url\s*\(\s*["']?|["']?\s*\)\s*/gi;
var URL = /(url\s*\(\s*['"]?)([\w\.]+[^:\)]*['"]?\))/gi;
var self = this;
// Store loaded cssText URLs
var fileCache = {};
function getCSSText(styleSheet, path, media, level) {
var cssText = "";
if (!level) {
media = toSimpleMedia(styleSheet.media);
level = 0;
}
if (media === "none") {
styleSheet.disabled = true;
return "";
}
if (media === "all" || media === self.media) {
// IE only allows importing style sheets three levels deep.
// it will crash if you try to access a level below this
try {
var canAcess = !!styleSheet.cssText;
} catch (exe) {}
if (level < 3 && canAcess) {
var hrefs = styleSheet.cssText.match(IMPORTS);
// loop through imported style sheets
for (var i = 0, imported; i < styleSheet.imports.length; i++) {
var imported = styleSheet.imports[i];
var href = styleSheet._href || styleSheet.href;
imported._href = hrefs[i].replace(TRIM_IMPORTS, "");
// call this function recursively to get all imported style sheets
cssText += getCSSText(imported, getPath(href, path), media, level + 1);
}
}
// retrieve inline style or load an external style sheet
cssText += encode(styleSheet.href ? loadStyleSheet(styleSheet, path) : styleSheet.owningElement._cssText);
cssText = parseMedia(cssText, self.media);
}
return cssText;
};
// Load all style sheets in the document
for (var i = 0; i < styleSheets.length; i++) {
var styleSheet = styleSheets[i];
if (!styleSheet.disabled && !styleSheet.ie7) this.cssText += getCSSText(styleSheet);
}
// helper functions
function parseMedia(cssText, media) {
filterMedia.value = media;
return cssText.replace(MEDIA, filterMedia);
};
function filterMedia(match, media, cssText) {
media = toSimpleMedia(media);
switch (media) {
case "screen":
case "print":
if (media !== filterMedia.value) return "";
case "all":
return cssText;
}
return "";
};
function toSimpleMedia(media) {
if (!media) return "all";
var split = media.toLowerCase().split(/\s*,\s*/);
media = "none";
for (var i = 0; i < split.length; i++) {
if (split[i] === "all") return "all";
if (split[i] === "screen") {
if (media === "print") return "all";
media = "screen";
} else if (split[i] === "print") {
if (media === "screen") return "all";
media = "print";
}
}
return media;
};
// Load an external style sheet
function loadStyleSheet(styleSheet, path) {
var href = styleSheet._href || styleSheet.href;
var url = makePath(href, path);
// If the style sheet has already loaded then don't reload it
if (fileCache[url]) return "";
// Load from source
fileCache[url] = styleSheet.disabled ? "" :
fixUrls(IE7.CSS.getText(styleSheet, path), getPath(href, path));
return fileCache[url];
};
// Fix CSS paths.
// We're lumping all css text into one big style sheet so relative
// paths have to be fixed. This is necessary anyway because of other
// Internet Explorer bugs.
function fixUrls(cssText, pathname) {
// hack & slash
return cssText.replace(URL, "$1" + pathname.slice(0, pathname.lastIndexOf("/") + 1) + "$2");
};
},
load: function() {
this.cssText = "";
this.getText();
this.parse();
if (inheritedProperties.length) {
this.cssText = parseInherited(this.cssText);
}
this.cssText = decode(this.cssText);
fileCache = {};
},
parse: function() {
var cssText = IE7.CSS.parser.parse(this.cssText);
var declarations = "";
this.cssText = cssText.replace(/@charset[^;]+;|@font\-face[^\}]+\}/g, function(match) {
declarations += match + "\n";
return "";
});
this.declarations = decode(declarations);
// Parse the style sheet
var offset = IE7.CSS.rules.length;
var rules = [], rule;
while ((rule = RULE.exec(this.cssText))) {
var cssText = rule[2];
if (cssText) {
var fixDescendants = appVersion < 7 && cssText.indexOf("AlphaImageLoader") !== -1;
var selectors = rule[1].match(SELECTOR), selector;
for (var i = 0; selector = selectors[i]; i++) {
selector = trim(selector);
var isUnknown = IE7.CSS.UNKNOWN.test(selector);
selectors[i] = isUnknown ? this.createRule(selector, cssText) : selector + "{" + cssText + "}";
if (fixDescendants) selectors[i] += this.createRule(selector + ">*", "position:relative");
}
rules.push(selectors.join("\n"));
}
}
this.cssText = rules.join("\n");
this.rules = IE7.CSS.rules.slice(offset);
},
recalc: function() {
var rule, i;
for (i = 0; (rule = this.rules[i]); i++) rule.recalc();
},
toString: function() {
return this.declarations + "@media " + this.media + "{" + this.cssText + "}";
}
});
var PseudoElement;
// -----------------------------------------------------------------------
// IE7 style rules
// -----------------------------------------------------------------------
var Rule = IE7.Rule = Base.extend({
constructor: function(selector, cssText) {
this.id = IE7.CSS.rules.length;
this.className = Rule.PREFIX + this.id;
var pseudoElement = selector.match(FIRST_LINE_LETTER);
this.selector = (pseudoElement ? pseudoElement[1] : selector) || "*";
this.selectorText = this.parse(this.selector) + (pseudoElement ? pseudoElement[2] : "");
this.cssText = cssText;
this.MATCH = new RegExp("\\s" + this.className + "(\\s|$)", "g");
IE7.CSS.rules.push(this);
this.init();
},
init: Undefined,