Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.4 KiB

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