1 // position.js: make edge-positioning work on IE/Win
2 // version 0.5, 15-Jul-2003
3 // written by Andrew Clover <and@doxdesk.com>, use freely
5 /*@cc_on
6 @if (@_win32 && @_jscript_version>4)
8 var position_h= new Array();
9 var position_v= new Array();
10 var position_viewport;
11 var position_width= 0;
12 var position_height= 0;
13 var position_fontsize= 0;
14 var position_ARBITRARY= 200;
16 // Binding. Called on each new element; if the it's <body>, initialise script.
17 // Check all new elements to see if they need our help, make lists of them
19 function position_bind(el) {
20 if (!position_viewport) {
21 if (!document.body) return;
22 // initialisation
23 position_viewport= (document.compatMode=='CSS1Compat') ?
24 document.documentElement : document.body;
25 window.attachEvent('onresize', position_delayout);
26 var em= document.createElement('div');
27 em.setAttribute('id', 'position_em');
28 em.style.position= 'absolute'; em.style.visibility= 'hidden';
29 em.style.fontSize= 'xx-large'; em.style.height= '5em';
30 em.style.top='-5em'; em.style.left= '0';
31 em.style.setExpression('width', 'position_checkFont()');
32 document.body.appendChild(em);
33 }
35 // check for absolute edge-positioned elements (ignore ones from fixed.js!)
36 var st= el.style; var cs= el.currentStyle;
37 if (cs.position=='absolute' && !st.fixedPWidth) {
38 if (cs.left!='auto' && cs.right!='auto') {
39 position_h[position_h.length]= el;
40 st.position_width= position_ARBITRARY;
41 st.width= st.position_width+'px';
42 position_delayout();
43 }
44 if (cs.top!='auto' && cs.bottom!='auto') {
45 position_v[position_v.length]= el;
46 st.position_height= position_ARBITRARY;
47 st.height= st.position_height+'px';
48 position_delayout();
49 } }
50 }
52 function position_checkFont() { position_delayout(); return '1em'; }
54 // Layout. For each edge-positioned axis, measure difference between min-edge
55 // and max-edge positioning, set size to the difference
57 // Request re-layout at next available moment
58 var position_delaying= false;
59 function position_delayout() {
60 if (position_delaying) return;
61 position_delaying= true;
62 window.setTimeout(position_layout, 0);
63 }
65 function position_layout() {
66 position_delaying= false;
67 var i, el, st, pos, tmp;
68 var fs= document.all['position_em'].offsetWidth;
69 var newfs= (position_fontsize!=fs && position_fontsize!=0);
70 position_fontsize= fs;
72 // horizontal axis
73 if (position_viewport.clientWidth!=position_width || newfs) {
74 position_width= position_viewport.clientWidth;
75 for (i= position_h.length; i-->0;) {
76 el= position_h[i]; st= el.style; cs= el.currentStyle;
77 pos= el.offsetLeft; tmp= cs.left; st.left= 'auto';
78 st.position_width+= el.offsetLeft-pos; st.left= tmp;
79 if (st.position_width<1) st.position_width= 1;
80 st.width= st.position_width+'px';
81 } }
82 // vertical axis
83 if (position_viewport.clientHeight!=position_height || newfs) {
84 position_height= position_viewport.clientHeight;
85 for (i= position_v.length; i-->0;) {
86 el= position_v[i]; st= el.style; cs= el.currentStyle;
87 pos= el.offsetTop; tmp= cs.top; st.top= 'auto';
88 st.position_height+= el.offsetTop-pos; st.top= tmp;
89 if (st.position_height<1) st.position_height= 1;
90 st.height= st.position_height+'px';
91 } }
92 }
94 // Scanning. Check document every so often until it has finished loading. Do
95 // nothing until <body> arrives, then call main init. Pass any new elements
96 // found on each scan to be bound
98 var position_SCANDELAY= 500;
100 var position_nscanned= 0;
101 function position_scan() {
102 var nall= document.all.length;
103 for (var i= position_nscanned; i<nall; i++)
104 position_bind(document.all[i]);
105 position_nscanned= nall;
106 }
108 var position_scanner;
109 function position_stop() {
110 window.clearInterval(position_scanner);
111 position_scan();
112 }
114 position_scan();
115 position_scanner= window.setInterval(position_scan, position_SCANDELAY);
116 window.attachEvent('onload', position_stop);
118 @end @*/