overlib_shadow.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. //\/////
  2. //\ overLIB Shadow Plugin
  3. //\ This file requires overLIB 4.10 or later.
  4. //\
  5. //\ overLIB 4.05 - You may not remove or change this notice.
  6. //\ Copyright Erik Bosrup 1998-2003. All rights reserved.
  7. //\ Contributors are listed on the homepage.
  8. //\ See http://www.bosrup.com/web/overlib/ for details.
  9. // $Revision: 1.15 $ $Date: 2004/11/25 21:27:19 $
  10. //\/////
  11. //\mini
  12. ////////
  13. // PRE-INIT
  14. // Ignore these lines, configuration is below.
  15. ////////
  16. if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Shadow Plugin.');
  17. else {
  18. registerCommands('shadow,shadowcolor,shadowimage,shadowopacity,shadowx,shadowy');
  19. ////////
  20. // DEFAULT CONFIGURATION
  21. // You don't have to change anything here if you don't want to. All of this can be
  22. // changed on your html page or through an overLIB call.
  23. ////////
  24. if (typeof ol_shadowadjust=='undefined') var ol_shadowadjust=2; // for Ns4.x only
  25. if (typeof ol_shadow=='undefined') var ol_shadow=0;
  26. if (typeof ol_shadowcolor=='undefined') var ol_shadowcolor='#CCCCCC';
  27. if (typeof ol_shadowimage=='undefined') var ol_shadowimage='';
  28. if (typeof ol_shadowopacity=='undefined') var ol_shadowopacity=0;
  29. if (typeof ol_shadowx=='undefined') var ol_shadowx=5;
  30. if (typeof ol_shadowy=='undefined') var ol_shadowy=5;
  31. ////////
  32. // END OF CONFIGURATION
  33. // Don't change anything below this line, all configuration is above.
  34. ////////
  35. ////////
  36. // INIT
  37. ////////
  38. // Runtime variables init. Don't change for config!
  39. var o3_shadow=0;
  40. var o3_shadowcolor="#cccccc";
  41. var o3_shadowimage='';
  42. var o3_shadowopacity=0;
  43. var o3_shadowx=5;
  44. var o3_shadowy=5;
  45. var bkSet=0; // Needed for this effect in NS4
  46. // Function which sets runtime variables to their default values
  47. function setShadowVariables() {
  48. o3_shadow=ol_shadow;
  49. o3_shadowcolor=ol_shadowcolor;
  50. o3_shadowimage=ol_shadowimage;
  51. o3_shadowopacity=ol_shadowopacity;
  52. o3_shadowx=ol_shadowx;
  53. o3_shadowy=ol_shadowy;
  54. }
  55. // Parses shadow commands
  56. function parseShadowExtras(pf,i,ar) {
  57. var k = i, v;
  58. if (k < ar.length) {
  59. if (ar[k]==SHADOW) { eval(pf +'shadow=('+pf+'shadow==0) ? 1 : 0'); return k; }
  60. if (ar[k]==SHADOWCOLOR) { eval(pf+'shadowcolor="'+ar[++k]+'"'); return k; }
  61. if (ar[k]==SHADOWOPACITY) {v=ar[++k]; eval(pf+'shadowopacity='+(olOp ? 0 : v)); return k; }
  62. if (ar[k]==SHADOWIMAGE) { eval(pf+'shadowimage="'+ar[++k]+'"'); return k; }
  63. if (ar[k]==SHADOWX) { eval(pf+'shadowx='+ar[++k]); return k; }
  64. if (ar[k]==SHADOWY) { eval(pf+'shadowy='+ar[++k]); return k; }
  65. }
  66. return -1;
  67. }
  68. // Function for MOUSEOUT/MOUSEOFF feature with shadow
  69. function shadow_cursorOff() {
  70. var left= parseInt(over.style.left);
  71. var top=parseInt(over.style.top);
  72. var right=left+(o3_shadow ? o3_width : over.offsetWidth);
  73. var bottom=top+(o3_shadow ? o3_aboveheight : over.offsetHeight);
  74. if (o3_x < left || o3_x > right || o3_y < top || o3_y > bottom) return true;
  75. return false;
  76. }
  77. // Pre-hide processing to clean-up.
  78. function checkShadowPreHide() {
  79. if (o3_shadow && o3_shadowopacity) cleanUpShadowEffects();
  80. if (o3_shadow && (olIe4 && isMac) ) over.style.pixelWidth=over.style.pixelHeight = 0;
  81. }
  82. // Funciton that creates the actual shadow
  83. function generateShadow(content) {
  84. var wd, ht, X = 0, Y = 0, zIdx = 0, txt, dpObj, puObj, bS= '', aPos, posStr=new Array();
  85. if (!o3_shadow || (o3_shadowx == 0 && o3_shadowy == 0)) return;
  86. X = Math.abs(o3_shadowx);
  87. Y = Math.abs(o3_shadowy);
  88. wd = parseInt(o3_width);
  89. ht = (olNs4) ? over.clip.height : over.offsetHeight;
  90. if (o3_shadowx == 0) {
  91. if (o3_shadowy < 0) {
  92. posStr[0]=' left:0; top: 0';
  93. posStr[1]=' left:0; top: '+Y+'px';
  94. } else if (o3_shadowy > 0) {
  95. posStr[0]=' left:0; top: '+Y+'px';
  96. posStr[1]=' left:0; top:0';
  97. }
  98. } else if (o3_shadowy == 0) {
  99. if (o3_shadowx < 0) {
  100. posStr[0]=' left:0; top: 0';
  101. posStr[1]=' left: '+X+'px';
  102. } else if (o3_shadowx > 0) {
  103. posStr[0]=' left: '+ X+'px; top: 0';
  104. posStr[1]=' left:0; top:0';
  105. }
  106. } else if (o3_shadowx > 0) {
  107. if (o3_shadowy > 0) {
  108. posStr[0]=' left:'+ X+'px; top:'+Y+'px';
  109. posStr[1]=' left:0; top:0';
  110. } else if (o3_shadowy < 0) {
  111. posStr[0]=' left:'+X+'px; top:0';
  112. posStr[1]=' left:0; top: '+Y+'px';
  113. }
  114. } else if (o3_shadowx < 0) {
  115. if (o3_shadowy > 0) {
  116. posStr[0]=' left:0; top:'+Y+'px';
  117. posStr[1]=' left:'+X+'px; top:0';
  118. } else if (o3_shadowy < 0) {
  119. posStr[0]=' left:0; top:0';
  120. posStr[1]=' left:'+X+'px; top:'+Y+'px';
  121. }
  122. }
  123. txt = (olNs4) ? '<div id="backdrop"></div>' : ((olIe55&&olHideForm) ? backDropSource(wd+X,ht+Y,zIdx++) : '') + '<div id="backdrop" style="position: absolute;'+posStr[0]+'; width: '+wd+'px; height: '+ht+'px; z-index: ' + (zIdx++) + '; ';
  124. if (o3_shadowimage) {
  125. bS='background-image: url('+o3_shadowimage+');';
  126. if (olNs4) bkSet=1;
  127. } else {
  128. bS='background-color: '+o3_shadowcolor +';';
  129. if (olNs4) bkSet=2;
  130. }
  131. if (olNs4) {
  132. txt += '<div id="PUContent">'+content+'</div>';
  133. } else {
  134. txt += bS+'"></div><div id="PUContent" style="position: absolute;'+posStr[1]+'; width: '+ wd+'px; z-index: '+(zIdx++)+';">'+content+'</div>';
  135. }
  136. layerWrite(txt);
  137. if (olNs4 && bkSet) {
  138. dpObj = over.document.layers['backdrop'];
  139. if (typeof dpObj == 'undefined') return; // if shadow layer not found, then content layer won't be either
  140. puObj = over.document.layers['PUContent'];
  141. wd = puObj.clip.width;
  142. ht = puObj.clip.height;
  143. aPos = posStr[0].split(';');
  144. dpObj.clip.width = wd;
  145. dpObj.clip.height = ht;
  146. dpObj.left = parseInt(aPos[0].split(':')[1]);
  147. dpObj.top = parseInt(aPos[1].split(':')[1]);
  148. dpObj.bgColor = (bkSet == 1) ? null : o3_shadowcolor;
  149. dpObj.background.src = (bkSet==2) ? null : o3_shadowimage;
  150. dpObj.zIndex = 0;
  151. aPos = posStr[1].split(';');
  152. puObj.left = parseInt(aPos[0].split(':')[1]);
  153. puObj.top = parseInt(aPos[1].split(':')[1]);
  154. puObj.zIndex = 1;
  155. } else {
  156. puObj = (olIe4 ? o3_frame.document.all['PUContent'] : o3_frame.document.getElementById('PUContent'));
  157. dpObj = (olIe4 ? o3_frame.document.all['backdrop'] : o3_frame.document.getElementById('backdrop'));
  158. ht = puObj.offsetHeight;
  159. dpObj.style.height = ht + 'px';
  160. if (o3_shadowopacity) {
  161. var op = o3_shadowopacity;
  162. op = (op <= 100 ? op : 100);
  163. setBrowserOpacity(op,dpObj);
  164. }
  165. }
  166. // Set popup's new width and height values here so they are available in placeLayer()
  167. o3_width = wd+X;
  168. o3_aboveheight = ht+Y;
  169. }
  170. ////////
  171. // SUPPORT FUNCTIONS
  172. ////////
  173. // Cleans up opacity settings if any.
  174. function cleanUpShadowEffects() {
  175. if (olNs4 || olOp) return;
  176. var dpObj=(olIe4 ? o3_frame.document.all['backdrop'] : o3_frame.document.getElementById('backdrop'));
  177. cleanUpBrowserOpacity(dpObj);
  178. }
  179. // multi browser opacity support
  180. function setBrowserOpacity(op,lyr){
  181. if (olNs4||!op) return; // if Ns4.x or opacity not given return;
  182. lyr=(lyr) ? lyr : over;
  183. if (olIe4&&typeof lyr.filters != 'undefined') {
  184. lyr.style.filter='Alpha(Opacity='+op+')';
  185. lyr.filters.alpha.enabled=true;
  186. } else {
  187. var sOp=(typeof(lyr.style.MozOpacity)!='undefined') ? 'MozOpacity' : (typeof(lyr.style.KhtmlOpacity)!='undefined' ? 'KhtmlOpacity' : (typeof(lyr.style.opacity)!='undefined' ? 'opacity' : ''));
  188. if (sOp) eval('lyr.style.'+sOp+'=op/100');
  189. }
  190. }
  191. // multi-browser Opacity cleanup
  192. function cleanUpBrowserOpacity(lyr) {
  193. if (olNs4) return;
  194. lyr=(lyr) ? lyr : over;
  195. if (olIe4&&(typeof lyr.filters != 'undefined'&&lyr.filters.alpha.enabled)) {
  196. lyr.style.filter='Alpha(Opacity=100)';
  197. lyr.filters.alpha.enabled=false;
  198. } else {
  199. var sOp=(typeof(lyr.style.MozOpacity)!='undefined') ? 'MozOpacity' : (typeof(lyr.style.KhtmlOpacity)!='undefined' ? 'KhtmlOpacity' : (typeof(lyr.style.opacity)!='undefined' ? 'opacity' : ''));
  200. if (sOp) eval('lyr.style.'+sOp+'=1.0');
  201. }
  202. }
  203. // This routine is needed only for Ns4.x to allow use of popups with dropshadows and CSSCLASS at the same time on a page
  204. function shadowAdjust() {
  205. if (!olNs4) return;
  206. var fac = ol_shadowadjust;
  207. if (olNs4) {
  208. document.write('<style type="text/css">\n<!--\n');
  209. document.write('#backdrop, #PUContent {position: absolute; left: '+fac*o3_shadowx+'px; top: '+fac*o3_shadowy+'px; }\n');
  210. document.write('-->\n<' + '\/style>');
  211. }
  212. }
  213. ////////
  214. // PLUGIN REGISTRATIONS
  215. ////////
  216. var before = (typeof rmrkPreface!='undefined' ? rmrkPreface : null);
  217. registerRunTimeFunction(setShadowVariables);
  218. registerCmdLineFunction(parseShadowExtras);
  219. registerHook("cursorOff",shadow_cursorOff,FREPLACE);
  220. registerHook("hideObject",checkShadowPreHide,FBEFORE);
  221. registerHook("createPopup",generateShadow,FAFTER,before);
  222. if (olInfo.meets(4.10)) registerNoParameterCommands('shadow');
  223. if (olNs4) shadowAdjust(); // write style rules for proper support of Ns4.x
  224. }