2 //\ overLIB Shadow Plugin
3 //\ This file requires overLIB 4.10 or later.
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.
15 // Ignore these lines, configuration is below.
17 if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Shadow Plugin.');
19 registerCommands('shadow,shadowcolor,shadowimage,shadowopacity,shadowx,shadowy');
23 // DEFAULT CONFIGURATION
24 // You don't have to change anything here if you don't want to. All of this can be
25 // changed on your html page or through an overLIB call.
27 if (typeof ol_shadowadjust=='undefined') var ol_shadowadjust=2; // for Ns4.x only
28 if (typeof ol_shadow=='undefined') var ol_shadow=0;
29 if (typeof ol_shadowcolor=='undefined') var ol_shadowcolor='#CCCCCC';
30 if (typeof ol_shadowimage=='undefined') var ol_shadowimage='';
31 if (typeof ol_shadowopacity=='undefined') var ol_shadowopacity=0;
32 if (typeof ol_shadowx=='undefined') var ol_shadowx=5;
33 if (typeof ol_shadowy=='undefined') var ol_shadowy=5;
36 // END OF CONFIGURATION
37 // Don't change anything below this line, all configuration is above.
46 // Runtime variables init. Don't change for config!
48 var o3_shadowcolor="#cccccc";
49 var o3_shadowimage='';
50 var o3_shadowopacity=0;
53 var bkSet=0; // Needed for this effect in NS4
57 // Function which sets runtime variables to their default values
58 function setShadowVariables() {
60 o3_shadowcolor=ol_shadowcolor;
61 o3_shadowimage=ol_shadowimage;
62 o3_shadowopacity=ol_shadowopacity;
63 o3_shadowx=ol_shadowx;
64 o3_shadowy=ol_shadowy;
68 // Parses shadow commands
69 function parseShadowExtras(pf,i,ar) {
73 if (ar[k]==SHADOW) { eval(pf +'shadow=('+pf+'shadow==0) ? 1 : 0'); return k; }
74 if (ar[k]==SHADOWCOLOR) { eval(pf+'shadowcolor="'+ar[++k]+'"'); return k; }
75 if (ar[k]==SHADOWOPACITY) {v=ar[++k]; eval(pf+'shadowopacity='+(olOp ? 0 : v)); return k; }
76 if (ar[k]==SHADOWIMAGE) { eval(pf+'shadowimage="'+ar[++k]+'"'); return k; }
77 if (ar[k]==SHADOWX) { eval(pf+'shadowx='+ar[++k]); return k; }
78 if (ar[k]==SHADOWY) { eval(pf+'shadowy='+ar[++k]); return k; }
85 // Function for MOUSEOUT/MOUSEOFF feature with shadow
86 function shadow_cursorOff() {
87 var left= parseInt(over.style.left);
88 var top=parseInt(over.style.top);
89 var right=left+(o3_shadow ? o3_width : over.offsetWidth);
90 var bottom=top+(o3_shadow ? o3_aboveheight : over.offsetHeight);
92 if (o3_x < left || o3_x > right || o3_y < top || o3_y > bottom) return true;
96 // Pre-hide processing to clean-up.
97 function checkShadowPreHide() {
98 if (o3_shadow && o3_shadowopacity) cleanUpShadowEffects();
99 if (o3_shadow && (olIe4 && isMac) ) over.style.pixelWidth=over.style.pixelHeight = 0;
103 // Funciton that creates the actual shadow
104 function generateShadow(content) {
105 var wd, ht, X = 0, Y = 0, zIdx = 0, txt, dpObj, puObj, bS= '', aPos, posStr=new Array();
107 if (!o3_shadow || (o3_shadowx == 0 && o3_shadowy == 0)) return;
109 X = Math.abs(o3_shadowx);
110 Y = Math.abs(o3_shadowy);
111 wd = parseInt(o3_width);
112 ht = (olNs4) ? over.clip.height : over.offsetHeight;
114 if (o3_shadowx == 0) {
115 if (o3_shadowy < 0) {
116 posStr[0]=' left:0; top: 0';
117 posStr[1]=' left:0; top: '+Y+'px';
118 } else if (o3_shadowy > 0) {
119 posStr[0]=' left:0; top: '+Y+'px';
120 posStr[1]=' left:0; top:0';
122 } else if (o3_shadowy == 0) {
123 if (o3_shadowx < 0) {
124 posStr[0]=' left:0; top: 0';
125 posStr[1]=' left: '+X+'px';
126 } else if (o3_shadowx > 0) {
127 posStr[0]=' left: '+ X+'px; top: 0';
128 posStr[1]=' left:0; top:0';
130 } else if (o3_shadowx > 0) {
131 if (o3_shadowy > 0) {
132 posStr[0]=' left:'+ X+'px; top:'+Y+'px';
133 posStr[1]=' left:0; top:0';
134 } else if (o3_shadowy < 0) {
135 posStr[0]=' left:'+X+'px; top:0';
136 posStr[1]=' left:0; top: '+Y+'px';
138 } else if (o3_shadowx < 0) {
139 if (o3_shadowy > 0) {
140 posStr[0]=' left:0; top:'+Y+'px';
141 posStr[1]=' left:'+X+'px; top:0';
142 } else if (o3_shadowy < 0) {
143 posStr[0]=' left:0; top:0';
144 posStr[1]=' left:'+X+'px; top:'+Y+'px';
148 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++) + '; ';
150 if (o3_shadowimage) {
151 bS='background-image: url('+o3_shadowimage+');';
154 bS='background-color: '+o3_shadowcolor +';';
159 txt += '<div id="PUContent">'+content+'</div>';
161 txt += bS+'"></div><div id="PUContent" style="position: absolute;'+posStr[1]+'; width: '+ wd+'px; z-index: '+(zIdx++)+';">'+content+'</div>';
166 if (olNs4 && bkSet) {
167 dpObj = over.document.layers['backdrop'];
168 if (typeof dpObj == 'undefined') return; // if shadow layer not found, then content layer won't be either
170 puObj = over.document.layers['PUContent'];
171 wd = puObj.clip.width;
172 ht = puObj.clip.height;
173 aPos = posStr[0].split(';');
175 dpObj.clip.width = wd;
176 dpObj.clip.height = ht;
177 dpObj.left = parseInt(aPos[0].split(':')[1]);
178 dpObj.top = parseInt(aPos[1].split(':')[1]);
180 dpObj.bgColor = (bkSet == 1) ? null : o3_shadowcolor;
181 dpObj.background.src = (bkSet==2) ? null : o3_shadowimage;
184 aPos = posStr[1].split(';');
185 puObj.left = parseInt(aPos[0].split(':')[1]);
186 puObj.top = parseInt(aPos[1].split(':')[1]);
190 puObj = (olIe4 ? o3_frame.document.all['PUContent'] : o3_frame.document.getElementById('PUContent'));
191 dpObj = (olIe4 ? o3_frame.document.all['backdrop'] : o3_frame.document.getElementById('backdrop'));
192 ht = puObj.offsetHeight;
193 dpObj.style.height = ht + 'px';
195 if (o3_shadowopacity) {
196 var op = o3_shadowopacity;
197 op = (op <= 100 ? op : 100);
199 setBrowserOpacity(op,dpObj);
203 // Set popup's new width and height values here so they are available in placeLayer()
205 o3_aboveheight = ht+Y;
213 // Cleans up opacity settings if any.
214 function cleanUpShadowEffects() {
215 if (olNs4 || olOp) return;
216 var dpObj=(olIe4 ? o3_frame.document.all['backdrop'] : o3_frame.document.getElementById('backdrop'));
217 cleanUpBrowserOpacity(dpObj);
220 // multi browser opacity support
221 function setBrowserOpacity(op,lyr){
222 if (olNs4||!op) return; // if Ns4.x or opacity not given return;
223 lyr=(lyr) ? lyr : over;
224 if (olIe4&&typeof lyr.filters != 'undefined') {
225 lyr.style.filter='Alpha(Opacity='+op+')';
226 lyr.filters.alpha.enabled=true;
228 var sOp=(typeof(lyr.style.MozOpacity)!='undefined') ? 'MozOpacity' : (typeof(lyr.style.KhtmlOpacity)!='undefined' ? 'KhtmlOpacity' : (typeof(lyr.style.opacity)!='undefined' ? 'opacity' : ''));
229 if (sOp) eval('lyr.style.'+sOp+'=op/100');
233 // multi-browser Opacity cleanup
234 function cleanUpBrowserOpacity(lyr) {
236 lyr=(lyr) ? lyr : over;
237 if (olIe4&&(typeof lyr.filters != 'undefined'&&lyr.filters.alpha.enabled)) {
238 lyr.style.filter='Alpha(Opacity=100)';
239 lyr.filters.alpha.enabled=false;
241 var sOp=(typeof(lyr.style.MozOpacity)!='undefined') ? 'MozOpacity' : (typeof(lyr.style.KhtmlOpacity)!='undefined' ? 'KhtmlOpacity' : (typeof(lyr.style.opacity)!='undefined' ? 'opacity' : ''));
242 if (sOp) eval('lyr.style.'+sOp+'=1.0');
246 // This routine is needed only for Ns4.x to allow use of popups with dropshadows and CSSCLASS at the same time on a page
247 function shadowAdjust() {
249 var fac = ol_shadowadjust;
251 document.write('<style type="text/css">\n<!--\n');
252 document.write('#backdrop, #PUContent {position: absolute; left: '+fac*o3_shadowx+'px; top: '+fac*o3_shadowy+'px; }\n');
253 document.write('-->\n<' + '\/style>');
258 // PLUGIN REGISTRATIONS
260 var before = (typeof rmrkPreface!='undefined' ? rmrkPreface : null);
262 registerRunTimeFunction(setShadowVariables);
263 registerCmdLineFunction(parseShadowExtras);
264 registerHook("cursorOff",shadow_cursorOff,FREPLACE);
265 registerHook("hideObject",checkShadowPreHide,FBEFORE);
266 registerHook("createPopup",generateShadow,FAFTER,before);
267 if (olInfo.meets(4.10)) registerNoParameterCommands('shadow');
269 if (olNs4) shadowAdjust(); // write style rules for proper support of Ns4.x