0
|
1 // minmax.js: make IE5+/Win support CSS min/max-width/height
|
|
2 // version 1.0, 08-Aug-2003
|
|
3 // written by Andrew Clover <and@doxdesk.com>, use freely
|
|
4
|
|
5 /*@cc_on
|
|
6 @if (@_win32 && @_jscript_version>4)
|
|
7
|
|
8 var minmax_elements;
|
|
9
|
|
10 minmax_props= new Array(
|
|
11 new Array('min-width', 'minWidth'),
|
|
12 new Array('max-width', 'maxWidth'),
|
|
13 new Array('min-height','minHeight'),
|
|
14 new Array('max-height','maxHeight')
|
|
15 );
|
|
16
|
|
17 // Binding. Called on all new elements. If <body>, initialise; check all
|
|
18 // elements for minmax properties
|
|
19
|
|
20 function minmax_bind(el) {
|
|
21 var i, em, ms;
|
|
22 var st= el.style, cs= el.currentStyle;
|
|
23
|
|
24 if (minmax_elements==window.undefined) {
|
|
25 // initialise when body element has turned up, but only on IE
|
|
26 if (!document.body || !document.body.currentStyle) return;
|
|
27 minmax_elements= new Array();
|
|
28 window.attachEvent('onresize', minmax_delayout);
|
|
29 // make font size listener
|
|
30 em= document.createElement('div');
|
|
31 em.setAttribute('id', 'minmax_em');
|
|
32 em.style.position= 'absolute'; em.style.visibility= 'hidden';
|
|
33 em.style.fontSize= 'xx-large'; em.style.height= '5em';
|
|
34 em.style.top='-5em'; em.style.left= '0';
|
|
35 if (em.style.setExpression) {
|
|
36 em.style.setExpression('width', 'minmax_checkFont()');
|
|
37 document.body.insertBefore(em, document.body.firstChild);
|
|
38 }
|
|
39 }
|
|
40
|
|
41 // transform hyphenated properties the browser has not caught to camelCase
|
|
42 for (i= minmax_props.length; i-->0;)
|
|
43 if (cs[minmax_props[i][0]])
|
|
44 st[minmax_props[i][1]]= cs[minmax_props[i][0]];
|
|
45 // add element with properties to list, store optimal size values
|
|
46 for (i= minmax_props.length; i-->0;) {
|
|
47 ms= cs[minmax_props[i][1]];
|
|
48 if (ms && ms!='auto' && ms!='none' && ms!='0' && ms!='') {
|
|
49 st.minmaxWidth= cs.width; st.minmaxHeight= cs.height;
|
|
50 minmax_elements[minmax_elements.length]= el;
|
|
51 // will need a layout later
|
|
52 minmax_delayout();
|
|
53 break;
|
|
54 } }
|
|
55 }
|
|
56
|
|
57 // check for font size changes
|
|
58
|
|
59 var minmax_fontsize= 0;
|
|
60 function minmax_checkFont() {
|
|
61 var fs= document.getElementById('minmax_em').offsetHeight;
|
|
62 if (minmax_fontsize!=fs && minmax_fontsize!=0)
|
|
63 minmax_delayout();
|
|
64 minmax_fontsize= fs;
|
|
65 return '5em';
|
|
66 }
|
|
67
|
|
68 // Layout. Called after window and font size-change. Go through elements we
|
|
69 // picked out earlier and set their size to the minimum, maximum and optimum,
|
|
70 // choosing whichever is appropriate
|
|
71
|
|
72 function minmax_delayout() {
|
|
73 minmax_layout();
|
|
74 }
|
|
75
|
|
76 function minmax_layout() {
|
|
77 var i, el, st, cs, optimal, inrange;
|
|
78 for (i= minmax_elements.length; i-->0;) {
|
|
79 el= minmax_elements[i]; st= el.style; cs= el.currentStyle;
|
|
80
|
|
81 // horizontal size bounding
|
|
82 st.width= st.minmaxWidth; optimal= el.offsetWidth;
|
|
83 inrange= true;
|
|
84 if (inrange && cs.minWidth && cs.minWidth!='0' && cs.minWidth!='auto' && cs.minWidth!='') {
|
|
85 st.width= cs.minWidth;
|
|
86 inrange= (el.offsetWidth<optimal);
|
|
87 }
|
|
88 if (inrange && cs.maxWidth && cs.maxWidth!='none' && cs.maxWidth!='auto' && cs.maxWidth!='') {
|
|
89 st.width= cs.maxWidth;
|
|
90 inrange= (el.offsetWidth>optimal);
|
|
91 }
|
|
92 if (inrange) st.width= st.minmaxWidth;
|
|
93
|
|
94 // vertical size bounding
|
|
95 st.height= st.minmaxHeight; optimal= el.offsetHeight;
|
|
96 inrange= true;
|
|
97 if (inrange && cs.minHeight && cs.minHeight!='0' && cs.minHeight!='auto' && cs.minHeight!='') {
|
|
98 st.height= cs.minHeight;
|
|
99 inrange= (el.offsetHeight<optimal);
|
|
100 }
|
|
101 if (inrange && cs.maxHeight && cs.maxHeight!='none' && cs.maxHeight!='auto' && cs.maxHeight!='') {
|
|
102 st.height= cs.maxHeight;
|
|
103 inrange= (el.offsetHeight>optimal);
|
|
104 }
|
|
105 if (inrange) st.height= st.minmaxHeight;
|
|
106 }
|
|
107 }
|
|
108
|
|
109 // Scanning. Check document every so often until it has finished loading. Do
|
|
110 // nothing until <body> arrives, then call main init. Pass any new elements
|
|
111 // found on each scan to be bound
|
|
112
|
|
113 var minmax_SCANDELAY= 500;
|
|
114
|
|
115 function minmax_scan() {
|
|
116 var el;
|
|
117 for (var i= 0; i<document.all.length; i++) {
|
|
118 el= document.all[i];
|
|
119 if (!el.minmax_bound) {
|
|
120 el.minmax_bound= true;
|
|
121 minmax_bind(el);
|
|
122 } }
|
|
123 }
|
|
124
|
|
125 var minmax_scanner;
|
|
126 function minmax_stop() {
|
|
127 window.clearInterval(minmax_scanner);
|
|
128 minmax_scan();
|
|
129 }
|
|
130
|
|
131 minmax_scan();
|
|
132 minmax_scanner=window.setInterval(minmax_scan, minmax_SCANDELAY);
|
|
133 window.attachEvent('onload', minmax_stop);
|
|
134
|
|
135 @end @*/
|