forked from lojjic/PIE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
htc_script.js
95 lines (82 loc) · 2.99 KB
/
htc_script.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
var el = element,
doc = el.document,
docMode = doc.documentMode || 0;
// NOTE: do NOT try maintaining a long-lived variable referencing window.PIE here at the top
// level because for some reason it isn't reliably set when it should be on subsequent attachments
// of the behavior, resulting in double loads of the JS file.
if ( !window[ 'PIE' ] && docMode < 10 ) {
(function() {
var queue = {},
baseUrls = $DefaultBaseUrls$,
protocol = doc.location.protocol,
baseUrl, tester, isIE6, i = 0;
// Create stub PIE object
window[ 'PIE' ] = {
'attach': function( el ) {
queue[ el[ 'uniqueID' ] ] = el;
},
'detach': function( el ) {
delete queue[ el[ 'uniqueID' ] ];
}
};
// Are we in IE6?
tester = doc.createElement('div');
tester.innerHTML = '<!--[if IE 6]><i></i><![endif]-->';
isIE6 = tester.getElementsByTagName('i')[0];
// Look for a custom -pie-load-path, or fall back to the CDN url
baseUrl = doc.documentElement.currentStyle.getAttribute( ( isIE6 ? '' : '-' ) + 'pie-load-path' );
if( baseUrl ) {
baseUrl = baseUrl.replace(/^("|')|("|')$/g, '');
baseUrls = [ baseUrl ];
}
// Start loading JS file
function tryLoading( baseUrl ) {
var script = doc.createElement( 'script' );
script.async = true;
script.onreadystatechange = function() {
var PIE = window[ 'PIE' ],
rs = script.readyState,
id;
if ( queue && ( rs === 'complete' || rs === 'loaded' ) ) {
if ( 'version' in PIE ) {
for( id in queue ) {
if ( queue.hasOwnProperty( id ) ) {
PIE[ 'attach' ]( queue[ id ] );
}
}
queue = 0;
}
else if( baseUrls[ ++i ] ) {
tryLoading( baseUrls[ i ] );
}
}
};
if ( protocol === 'https:' ) {
baseUrl = baseUrl.replace( /^http:/, protocol );
}
script.src = baseUrl + '/PIE_IE' + ( docMode < 9 ? '678' : '9' ) + '$JSVariant$.js';
( doc.getElementsByTagName( 'head' )[0] || doc.body ).appendChild( script );
}
tryLoading( baseUrls[ i ] );
})();
}
function init() {
if ( doc.media !== 'print' ) { // IE strangely attaches a second copy of the behavior to elements when printing
var PIE = window[ 'PIE' ];
if( PIE ) {
PIE[ 'attach' ]( el );
}
}
}
function cleanup() {
if ( doc.media !== 'print' ) {
var PIE = window[ 'PIE' ];
if ( PIE ) {
PIE[ 'detach' ]( el );
}
}
el = 0;
}
if( el.readyState === 'complete' ) {
init();
}