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