PageSourceSearch

https://www.cospa.com/js/minmax.js

js cospa.com collected 2026-10-09 22:41:05 UTC 4,527 bytes, 147 lines download raw bytes

1// minmax.js: make IE5+/Win support CSS min/max-width/height
2// version 1.0, 08-Aug-2003
3// written by Andrew Clover <[email protected]>, use freely
4
5/*@cc_on
6@if (@_win32 && @_jscript_version>4)
7
8var minmax_elements;
9
10minmax_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
20function 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      try{
37	em.style.setExpression('width', 'minmax_checkFont()');
38	document.body.insertBefore(em, document.body.firstChild);
39	}
40	catch(err){}
41    }
42  }
43
44  // transform hyphenated properties the browser has not caught to camelCase
45  for (i= minmax_props.length; i-->0;)
46    if (cs[minmax_props[i][0]])
47      st[minmax_props[i][1]]= cs[minmax_props[i][0]];
48  // add element with properties to list, store optimal size values
49  for (i= minmax_props.length; i-->0;) {
50    ms= cs[minmax_props[i][1]];
51    if (ms && ms!='auto' && ms!='none' && ms!='0' && ms!='') {
52      st.minmaxWidth= cs.width; st.minmaxHeight= cs.height;
53      minmax_elements[minmax_elements.length]= el;
54      // will need a layout later
55      minmax_delayout();
56      break;
57  } }
58}
59
60// check for font size changes
61
62var minmax_fontsize= 0;
63function minmax_checkFont() {
64  var fs= document.getElementById('minmax_em').offsetHeight;
65  if (minmax_fontsize!=fs && minmax_fontsize!=0)
66    minmax_delayout();
67  minmax_fontsize= fs;
68  return '5em';
69}
70
71// Layout. Called after window and font size-change. Go through elements we
72// picked out earlier and set their size to the minimum, maximum and optimum,
73// choosing whichever is appropriate
74
75// Request re-layout at next available moment
76var minmax_delaying= false;
77function minmax_delayout() {
78  if (minmax_delaying) return;
79  minmax_delaying= true;
80  window.setTimeout(minmax_layout, 0);
81}
82
83function minmax_stopdelaying() {
84  minmax_delaying= false;
85}
86
87function minmax_layout() {
88  window.setTimeout(minmax_stopdelaying, 100);
89  var i, el, st, cs, optimal, inrange;
90  for (i= minmax_elements.length; i-->0;) {
91    el= minmax_elements[i]; st= el.style; cs= el.currentStyle;
92
93    // horizontal size bounding
94    st.width= st.minmaxWidth; optimal= el.offsetWidth;
95    inrange= true;
96    if (inrange && cs.minWidth && cs.minWidth!='0' && cs.minWidth!='auto' && cs.minWidth!='') {
97      st.width= cs.minWidth;
98      inrange= (el.offsetWidth<optimal);
99    }
100    if (inrange && cs.maxWidth && cs.maxWidth!='none' && cs.maxWidth!='auto' && cs.maxWidth!='') {
101      st.width= cs.maxWidth;
102      inrange= (el.offsetWidth>optimal);
103    }
104    if (inrange) st.width= st.minmaxWidth;
105
106    // vertical size bounding
107    st.height= st.minmaxHeight; optimal= el.offsetHeight;
108    inrange= true;
109    if (inrange && cs.minHeight && cs.minHeight!='0' && cs.minHeight!='auto' && cs.minHeight!='') {
110      st.height= cs.minHeight;
111      inrange= (el.offsetHeight<optimal);
112    }
113    if (inrange && cs.maxHeight && cs.maxHeight!='none' && cs.maxHeight!='auto' && cs.maxHeight!='') {
114      st.height= cs.maxHeight;
115      inrange= (el.offsetHeight>optimal);
116    }
117    if (inrange) st.height= st.minmaxHeight;
118  }
119}
120
121// Scanning. Check document every so often until it has finished loading. Do
122// nothing until <body> arrives, then call main init. Pass any new elements
123// found on each scan to be bound   
124
125var minmax_SCANDELAY= 500;
126
127function minmax_scan() {
128  var el;
129  for (var i= 0; i<document.all.length; i++) {
130    el= document.all[i];
131    if (!el.minmax_bound) {
132      el.minmax_bound= true;
133      minmax_bind(el);
134  } }
135}
136
137var minmax_scanner;
138function minmax_stop() {
139  window.clearInterval(minmax_scanner);
140  minmax_scan();
141}
142
143minmax_scan();
144minmax_scanner= window.setInterval(minmax_scan, minmax_SCANDELAY);
145window.attachEvent('onload', minmax_stop);
146
147@end @*/

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.