-
Notifications
You must be signed in to change notification settings - Fork 0
/
IEX-dev.js
3235 lines (2845 loc) · 113 KB
/
IEX-dev.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
/*
IEX.js - copyright 2018-2022, Gianluca18092004
http://iexfix.tk/
*/
/* W3C compliance for Microsoft Internet Explorer */
// timestamp: Fri, 23 Mar 2022 23:21:52
(function(window, document, win, doc) {
var IE7 = window.IE7 = {
version: "3.0",
toString: K("[IE7]")
};
IE7.compat = 10;
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 = (document.compatMode != 'CSS1Compat');
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;
};
// =========================================================================
// ie8-dom.js
// =========================================================================
var style = document.createStyleSheet(), select = function (selector, maxCount) {
var all = document.all, l = all.length, i, resultSet = [];
style.addRule(selector, "foo:bar");
for (i = 0; i < l; i += 1) {
if (all[i].currentStyle.foo === "bar") {
resultSet.push(all[i]);
if (resultSet.length > maxCount) {
break;
}
}
}
style.removeRule(0);
return resultSet;
};
if (!window.Element) {
Element = function () { };
Element.prototype.removeEventListener = function (event, listener) {
this.detachEvent('on' + event, listener);
}
var querySelectorAll = function (selector) {
return select(selector, Infinity);
};
var __querySelector = function (selector) {
return select(selector, 1)[0] || null;
};
var __createElement = document.createElement;
document.createElement = function (tagName) {
var element = __createElement(tagName);
if (element == null) {
return null;
}
for (var key in Element.prototype)
element[key] = Element.prototype[key];
return element;
};
var __getElementById = document.getElementById;
document.getElementById = function (id) {
var element = __getElementById(id);
if (element == null) {
return null;
}
for (var key in Element.prototype)
element[key] = Element.prototype[key];
return element;
};
document.querySelector = function (id) {
var element = __querySelector(id);
if (element == null) {
return null;
}
for (var key in Element.prototype)
element[key] = Element.prototype[key];
return element;
};
var __getElementsByTagName = document.getElementsByTagName, t;
document.getElementsByTagName = function (id) {
var element = __getElementsByTagName(id);
if (element == null) {
return null;
}
for (t = 0; t < element.length; t++) {
for (var key in Element.prototype) {
element[t][key] = Element.prototype[key];
}
}
return element;
};
var __getElementsByName = document.getElementsByName, n;
document.getElementsByName = function (id) {
var element = __getElementsByName(id);
if (element == null) {
return null;
}
for (n = 0; n < element.length; n++) {
for (var key in Element.prototype) {
element[n][key] = Element.prototype[key];
}
}
return element;
};
var __querySelectorAll = querySelectorAll, a;
document.querySelectorAll = function (id) {
var element = __querySelectorAll(id);
if (element == null) {
return null;
}
for (n = 0; n < element.length; a++) {
for (var key in Element.prototype) {
element[a][key] = Element.prototype[key];
}
}
return element;
};
}
function docHijack(p) { var old = doc[p]; doc[p] = function (v) { return addListen(old(v)) } }
function addEvent(on, fn, self) {
return (self = this).attachEvent('on' + on, function (e) {
var e = e || win.event;
e.preventDefault = e.preventDefault || function () { e.returnValue = false }
e.stopPropagation = e.stopPropagation || function () { e.cancelBubble = true }
fn.call(self, e);
});
}
function addListen(obj, i) {
if (i = obj.length) while (i--) obj[i].addEventListener = addEvent;
else obj.addEventListener = addEvent;
return obj;
}
addListen([doc, win]);
if ('Element' in win) win.Element.prototype.addEventListener = addEvent; //IE8
else { //IE < 8
doc.attachEvent('onreadystatechange', function () { addListen(doc.all) }); //Make sure we also init at domReady
docHijack('getElementsByTagName');
docHijack('getElementById');
docHijack('createElement');
addListen(doc.all);
}
// =========================================================================
// ie7-ajax.js
// =========================================================================
if (typeof XMLHttpRequest == "undefined")
XMLHttpRequest = function () {
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); }
catch (e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); }
catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) {}
throw new Error("This browser does not support XMLHttpRequest.");
};
// =========================================================================
// 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: (MSIE5 || 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 = (MSIE5 || appVersion < 7) ? ["[>+~\\[(]|([:.])[\\w-]+\\1"] : [CLASS];
if (pseudoClasses) unknown.push(":(" + pseudoClasses + ")");
this.UNKNOWN = new RegExp(unknown.join("|") || NONE, "i");
var complex = (MSIE5 || 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