2 //\ overLIB Anchor Plugin
\r
3 //\ This file requires overLIB 4.10 or later.
\r
5 //\ overLIB 4.10 - You may not remove or change this notice.
\r
6 //\ Copyright Erik Bosrup 1998-2004. All rights reserved.
\r
7 //\ Contributors are listed on the homepage.
\r
8 //\ See http://www.bosrup.com/web/overlib/ for details.
\r
9 // $Revision: 1.1 $ $Date: 2006/05/29 16:38:21 $
\r
16 // Ignore these lines, configuration is below.
\r
18 if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Anchor Plugin.');
\r
20 registerCommands('anchor,anchorx,anchory,noanchorwarn,anchoralign');
\r
25 // DEFAULT CONFIGURATION
\r
26 // Settings you want everywhere are set here. All of this can also be
\r
27 // changed on your html page or through an overLIB call.
\r
29 if (typeof ol_anchor == 'undefined') var ol_anchor = '';
\r
30 if (typeof ol_anchorx == 'undefined') var ol_anchorx = 0;
\r
31 if (typeof ol_anchory == 'undefined') var ol_anchory = 0;
\r
32 if (typeof ol_noanchorwarn == 'undefined') var ol_noanchorwarn = 1;
\r
33 if (typeof ol_anchoralign == 'undefined') var ol_anchoralign = 'UL';
\r
36 // END OF CONFIGURATION
\r
37 // Don't change anything below this line, all configuration is above.
\r
47 // Runtime variables init. Don't change for config!
\r
51 var o3_noanchorwarn = 1;
\r
52 var o3_anchoralign = 'UL';
\r
53 var mrkObj, rmrkPosition; //reference mark object, reference mark position, an array;
\r
59 function setAnchorVariables() {
\r
60 o3_anchor = ol_anchor;
\r
61 o3_anchorx = ol_anchorx;
\r
62 o3_anchory = ol_anchory;
\r
63 o3_noanchorwarn = ol_noanchorwarn;
\r
64 o3_anchoralign = ol_anchoralign;
\r
65 mrkObj = null; // initialize this variable
\r
68 // Parses Reference Mark commands
\r
69 function parseAnchorExtras(pf,i,ar) {
\r
72 if (k < ar.length) {
\r
73 if (ar[k] == ANCHOR) { eval(pf + "anchor = '" + escSglQuote(ar[++k]) + "'"); return k; }
\r
74 if (ar[k] == ANCHORX) { eval(pf + 'anchorx = ' + ar[++k]); return k; }
\r
75 if (ar[k] == ANCHORY) { eval(pf + 'anchory = ' + ar[++k]); return k; }
\r
76 if (ar[k] == NOANCHORWARN) { eval(pf + 'noanchorwarn = (' + pf + 'noanchorwarn==1) ? 0 : 1'); return k; }
\r
77 if (ar[k] == ANCHORALIGN) { k = opt_MULTIPLEARGS(++k, ar, (pf + 'anchoralign')); return k; }
\r
85 // FUNCTION WHICH CHECKS FOR THE EXISTENCE OF A REFERENCE MARKER
\r
87 function checkAnchorObject() {
\r
91 if (!(mrkObj = getAnchorObjectRef(w))) {
\r
92 if (o3_noanchorwarn) {
\r
93 alert('WARNING! Reference mark "' + w + '" not found.');
\r
103 // EXTERNAL SUPPORT FUNCTIONS TO HANDLE ANCHOR PROPERTIES
\r
106 // Horizontal placement routine with anchors
\r
107 function anchorHorizontal(browserWidth, horizontalScrollAmount, widthFix) {
\r
108 var hasAnchor = (typeof o3_anchor != 'undefined' && o3_anchor);
\r
109 if (!hasAnchor) return void(0);
\r
111 // set o3_relx for follow scroll if defined
\r
112 if (typeof o3_followscroll != 'undefined' && o3_followscroll && o3_sticky) o3_relx = rmrkPosition[0];
\r
114 return rmrkPosition[0];
\r
117 // Vertical placement routine with anchors
\r
118 function anchorVertical(browserHeight,verticalScrollAmount) {
\r
119 var hasAnchor = (typeof o3_anchor != 'undefined' && o3_anchor);
\r
120 if (!hasAnchor) return void(0);
\r
122 // set o3_rely for follow scroll if defined
\r
123 if (typeof o3_followscroll != 'undefined' && o3_followscroll && o3_sticky) o3_rely = rmrkPosition[1];
\r
125 return rmrkPosition[1];
\r
128 // Stub function for the runHook routine
\r
129 function anchorPreface() {
\r
130 if (!mrkObj) return;
\r
131 rmrkPosition = getAnchorLocation(mrkObj);
\r
134 // Get Reference Mark object
\r
135 function getAnchorObjectRef(aObj) {
\r
136 return getRefById(aObj, o3_frame.document) || getRefByName(aObj, o3_frame.document)
\r
139 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
\r
140 function getAnchorLocation(objRef){
\r
141 var mkObj, of, offsets, mlyr
\r
143 mkObj = mlyr = objRef
\r
144 offsets = [o3_anchorx, o3_anchory]
\r
146 if (document.layers){
\r
147 if (typeof mlyr.length != 'undefined' && mlyr.length > 1) {
\r
149 offsets[0] += mlyr[0].x + mlyr[1].pageX
\r
150 offsets[1] += mlyr[0].y + mlyr[1].pageY
\r
152 if(mlyr.toString().indexOf('Image') != -1 || mlyr.toString().indexOf('Anchor') != -1){
\r
153 offsets[0] += mlyr.x
\r
154 offsets[1] += mlyr.y
\r
156 offsets[0] += mlyr.pageX
\r
157 offsets[1] += mlyr.pageY
\r
161 offsets[0] += pageLocation(mlyr, 'Left')
\r
162 offsets[1] += pageLocation(mlyr, 'Top')
\r
165 of = getAnchorOffsets(mkObj)
\r
167 if (typeof o3_dragimg != 'undefined' && o3_dragimg) {
\r
168 olImgLeft = offsets[0];
\r
169 olImgTop = offsets[1];
\r
172 offsets[0] += of[0]
\r
173 offsets[1] += of[1]
\r
175 if (typeof o3_dragimg != 'undefined' && o3_dragimg) {
\r
176 olImgRight = offsets[0];
\r
177 olImgBottom = offsets[1];
\r
184 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
\r
185 function getAnchorOffsets(mkObj){
\r
186 var fx = fy = 0, mp, puc, mkAry, sx = sy = 0, w = o3_anchoralign
\r
187 var mW = mH = pW = pH = 0
\r
190 mkAry = w.split(',');
\r
192 if (mkAry.length < 3) {
\r
193 mp = mkAry[0].toUpperCase();
\r
194 puc = (mkAry.length == 1) ? mp : mkAry[1].toUpperCase();
\r
195 } else if (mkAry.length == 3) {
\r
196 if (!isNaN(mkAry[0])) {
\r
197 mp = mkAry.slice(0, 2);
\r
198 puc = mkAry[2].toUpperCase();
\r
200 mp = mkAry[0].toUpperCase();
\r
201 puc = mkAry.slice(1);
\r
204 mp = mkAry.slice(0, 2);
\r
205 puc = mkAry.slice(2);
\r
208 var shdwPresent = typeof o3_shadow != 'undefined' && o3_shadow
\r
211 sx = Math.abs(o3_shadowx);
\r
212 sy = Math.abs(o3_shadowy);
\r
215 pW = (shdwPresent ? parseInt(o3_width) : (olNs4 ? over.clip.width : over.offsetWidth))
\r
216 pH = (shdwPresent ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight))
\r
218 if (olOp && o3_wrap) {
\r
219 pW = (shdwPresent ? parseInt(o3_width) : (olNs4 ? over.clip.width : over.offsetWidth))
\r
220 pH = (shdwPresent ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight))
\r
223 if (!olOp && mkObj.toString().indexOf('Image') != -1){
\r
226 } else if (!olOp && mkObj.toString().indexOf('Anchor') != -1) { // enforced only for NS4
\r
229 mW = (olNs4) ? mkObj.clip.width : mkObj.offsetWidth
\r
230 mH = (olNs4) ? mkObj.clip.height : mkObj.offsetHeight
\r
233 if (!isNaN(mp) || typeof mp == 'object') {
\r
234 if (typeof mp == 'object') {
\r
235 fx = parseFloat(mp[0]);
\r
236 fy = parseFloat(mp[1]);
\r
238 fx = fy = parseFloat(mp);
\r
239 off = [Math.round(fx*mW), Math.round(fy*mH)];
\r
241 if (mp == 'UR') off = [mW, 0]
\r
242 else if (mp == 'LL') off = [0, mH]
\r
243 else if (mp == 'LR') off = [mW, mH]
\r
246 if (typeof o3_dragimg != 'undefined' && o3_dragimg) return off;
\r
248 if (!isNaN(puc) || typeof puc == 'object' ) {
\r
249 if (typeof puc == 'object') {
\r
250 fx = parseFloat(puc[0]);
\r
251 fy = parseFloat(puc[1]);
\r
253 fx = fy = parseFloat(puc);
\r
254 off[0] -= Math.round(fx*(pW - sx));
\r
255 off[1] -= Math.round(fy*(pH - sy));
\r
258 off[0] -= (pW - sx);
\r
260 } else if (puc == 'LL') {
\r
262 off[1] -= (pH - sy)
\r
263 } else if (puc == 'LR') {
\r
265 off[1] -= (pH - sy)
\r
272 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
\r
273 function pageLocation(o, t){
\r
276 while(o.offsetParent){
\r
277 x += o['offset' + t]
\r
280 x += o['offset' + t]
\r
285 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
\r
286 function getRefById(l, d){
\r
289 d = (d || document)
\r
290 if (d.all) return d.all[l]
\r
291 else if (d.getElementById) return d.getElementById(l)
\r
292 else if (d.layers && d.layers.length > 0) {
\r
293 if (d.layers[l]) return d.layers[l]
\r
295 for (j=0; j < d.layers.length; j++) {
\r
296 r = getRefById(l, d.layers[j].document)
\r
304 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
\r
305 function getRefByName(l, d) {
\r
308 d = (d || document)
\r
310 if (d.images[l]) return d.images[l]
\r
311 else if (d.anchors[l]) return d.anchors[l];
\r
312 else if (d.layers && d.layers.length > 0) {
\r
313 for (j=0; j < d.layers.length; j++) {
\r
314 r = getRefByName(l, d.layers[j].document)
\r
315 if (r && r.length > 0) return r
\r
316 else if (r) return [r, d.layers[j]]
\r
324 // PLUGIN REGISTRATIONS
\r
326 registerRunTimeFunction(setAnchorVariables);
\r
327 registerCmdLineFunction(parseAnchorExtras);
\r
328 registerPostParseFunction(checkAnchorObject);
\r
329 registerHook("createPopup", anchorPreface, FAFTER);
\r
330 registerHook("horizontalPlacement", anchorHorizontal, FCHAIN);
\r
331 registerHook("verticalPlacement", anchorVertical, FCHAIN);
\r
332 if(olInfo.meets(4.10)) registerNoParameterCommands('noanchorwarn');
\r