2 //\ overLIB Anchor Plugin
3 //\ This file requires overLIB 4.00 or later.
5 //\ overLIB 4.00 - 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' || olInfo.simpleversion < 400) alert('overLIB 4.00 or later is required for the Anchor Plugin.');
19 registerCommands('anchor,anchorx,anchory,noanchorwarn,anchoralign');
24 // DEFAULT CONFIGURATION
25 // Settings you want everywhere are set here. All of this can also be
26 // changed on your html page or through an overLIB call.
28 if (typeof ol_anchor == 'undefined') var ol_anchor = '';
29 if (typeof ol_anchorx == 'undefined') var ol_anchorx = 0;
30 if (typeof ol_anchory == 'undefined') var ol_anchory = 0;
31 if (typeof ol_noanchorwarn == 'undefined') var ol_noanchorwarn = 1;
32 if (typeof ol_anchoralign == 'undefined') var ol_anchoralign = 'UL';
35 // END OF CONFIGURATION
36 // Don't change anything below this line, all configuration is above.
46 // Runtime variables init. Don't change for config!
50 var o3_noanchorwarn = 1;
51 var o3_anchoralign = 'UL';
52 var mrkObj, rmrkPosition; //reference mark object, reference mark position, an array;
58 function setAnchorVariables() {
59 o3_anchor = ol_anchor;
60 o3_anchorx = ol_anchorx;
61 o3_anchory = ol_anchory;
62 o3_noanchorwarn = ol_noanchorwarn;
63 o3_anchoralign = ol_anchoralign;
64 mrkObj = null; // initialize this variable
67 // Parses Reference Mark commands
68 function parseAnchorExtras(pf,i,ar) {
72 if (ar[k] == ANCHOR) { eval(pf + "anchor = '" + escSglQuote(ar[++k]) + "'"); return k; }
73 if (ar[k] == ANCHORX) { eval(pf + 'anchorx = ' + ar[++k]); return k; }
74 if (ar[k] == ANCHORY) { eval(pf + 'anchory = ' + ar[++k]); return k; }
75 if (ar[k] == NOANCHORWARN) { eval(pf + 'noanchorwarn = (' + pf + 'noanchorwarn==1) ? 0 : 1'); return k; }
76 if (ar[k] == ANCHORALIGN) { k = opt_MULTIPLEARGS(++k, ar, (pf + 'anchoralign')); return k; }
84 // FUNCTION WHICH CHECKS FOR THE EXISTENCE OF A REFERENCE MARKER
86 function checkAnchorObject() {
90 if (!(mrkObj = getAnchorObjectRef(w))) {
91 if (o3_noanchorwarn) {
92 alert('WARNING! Reference mark "' + w + '" not found.');
103 // HANDLING FUNCTIONS, OVERLOADS CORE MODULE
106 // Decides where we want the popup.
107 function anchorPlaceLayer() {
108 var placeX, placeY, widthFix = 0;
110 // HORIZONTAL PLACEMENT
111 if (eval('o3_frame.'+docRoot) && eval("typeof o3_frame."+docRoot+".clientWidth == 'number'") && eval('o3_frame.'+docRoot+'.clientWidth')) {
112 iwidth = eval('o3_frame.'+docRoot+'.clientWidth');
113 } else if (typeof(o3_frame.innerWidth) == 'number') {
114 widthFix = Math.ceil(1.2*(o3_frame.outerWidth - o3_frame.innerWidth));
115 iwidth = o3_frame.innerWidth;
119 placeX = rmrkPosition[0];
120 placeY = rmrkPosition[1];
122 // Horizontal scroll offset
123 winoffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollLeft') : o3_frame.pageXOffset;
124 var parsedWidth = parseInt(o3_width);
126 if (o3_fixx > -1 || o3_relx != null) {
128 placeX=(o3_relx != null ? ( o3_relx < 0 ? winoffset +o3_relx+ iwidth - parsedWidth - widthFix : winoffset+o3_relx) : o3_fixx);
130 // If HAUTO, decide what to use.
132 if ((o3_x - winoffset) > (iwidth / 2)) {
140 if (o3_hpos == CENTER) { // Center
141 placeX = o3_x+o3_offsetx-(parsedWidth/2);
143 if (placeX < winoffset) placeX = winoffset;
146 if (o3_hpos == RIGHT) { // Right
147 placeX = o3_x+o3_offsetx;
149 if ((placeX+parsedWidth) > (winoffset+iwidth - widthFix)) {
150 placeX = iwidth+winoffset - parsedWidth - widthFix;
151 if (placeX < 0) placeX = 0;
154 if (o3_hpos == LEFT) { // Left
155 placeX = o3_x-o3_offsetx-parsedWidth;
156 if (placeX < winoffset) placeX = winoffset;
161 var snapping = placeX % o3_snapx;
163 if (o3_hpos == LEFT) {
164 placeX = placeX - (o3_snapx+snapping);
167 placeX = placeX+(o3_snapx - snapping);
170 if (placeX < winoffset) placeX = winoffset;
174 // VERTICAL PLACEMENT
175 if (eval('o3_frame.'+docRoot) && eval("typeof o3_frame."+docRoot+".clientHeight == 'number'") && eval('o3_frame.'+docRoot+'.clientHeight')) {
176 iheight = eval('o3_frame.'+docRoot+'.clientHeight');
177 } else if (typeof(o3_frame.innerHeight) == 'number') {
178 iheight = o3_frame.innerHeight;
181 // Vertical scroll offset
182 scrolloffset=(olIe4) ? eval('o3_frame.'+docRoot+'.scrollTop') : o3_frame.pageYOffset;
183 var parsedHeight=(o3_aboveheight ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight));
185 if (o3_fixy > -1 || o3_rely != null) {
187 placeY = (o3_rely != null ? (o3_rely < 0 ? scrolloffset+o3_rely+iheight - parsedHeight : scrolloffset+o3_rely) : o3_fixy);
189 // If VAUTO, decide what to use.
191 if ((o3_y - scrolloffset) > (iheight/2)) {
199 if (o3_vpos == ABOVE) {
200 if (o3_aboveheight == 0) o3_aboveheight = parsedHeight;
202 placeY = o3_y - (o3_aboveheight+o3_offsety);
203 if (placeY < scrolloffset) placeY = scrolloffset;
206 placeY = o3_y+o3_offsety;
211 var snapping = placeY % o3_snapy;
213 if (o3_aboveheight > 0 && o3_vpos == ABOVE) {
214 placeY = placeY - (o3_snapy+snapping);
216 placeY = placeY+(o3_snapy - snapping);
219 if (placeY < scrolloffset) placeY = scrolloffset;
224 // Actually move the object.
225 repositionTo(over, placeX, placeY);
226 if (typeof o3_scroll != 'undefined' && o3_scroll && o3_sticky && (o3_relx || o3_rely) && (typeof o3_draggable == 'undefined' || !o3_draggable)) {
227 if (typeof over.scroller == 'undefined' || over.scroller.canScroll) over.scroller = new scroller(placeX - winoffset, placeY - scrolloffset, setTimeout("repositionOver()", 20));
231 // EXTERNAL SUPPORT FUNCTIONS TO HANDLE ANCHOR PROPERTIES
234 // Stub function for the runHook routine
235 function anchorPreface() {
237 rmrkPosition = getAnchorLocation(mrkObj);
240 // Get Reference Mark object
241 function getAnchorObjectRef(aObj) {
242 return getRefById(aObj, o3_frame.document) || getRefByName(aObj, o3_frame.document)
245 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
246 function getAnchorLocation(objRef){
247 var mkObj, of, offsets, mlyr
249 mkObj = mlyr = objRef
250 offsets = [o3_anchorx, o3_anchory]
252 if (document.layers){
253 if (typeof mlyr.length != 'undefined' && mlyr.length > 1) {
255 offsets[0] += mlyr[0].x + mlyr[1].pageX
256 offsets[1] += mlyr[0].y + mlyr[1].pageY
258 if(mlyr.toString().indexOf('Image') != -1 || mlyr.toString().indexOf('Anchor') != -1){
262 offsets[0] += mlyr.pageX
263 offsets[1] += mlyr.pageY
267 offsets[0] += pageLocation(mlyr, 'Left')
268 offsets[1] += pageLocation(mlyr, 'Top')
271 of = getAnchorOffsets(mkObj)
273 if (typeof o3_dragimg != 'undefined' && o3_dragimg) {
274 olImgLeft = offsets[0];
275 olImgTop = offsets[1];
281 if (typeof o3_dragimg != 'undefined' && o3_dragimg) {
282 olImgRight = offsets[0];
283 olImgBottom = offsets[1];
290 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
291 function getAnchorOffsets(mkObj){
292 var fx = fy = 0, mp, puc, mkAry, sx = sy = 0, w = o3_anchoralign
293 var mW = mH = pW = pH = 0
296 mkAry = w.split(',');
298 if (mkAry.length < 3) {
299 mp = mkAry[0].toUpperCase();
300 puc = (mkAry.length == 1) ? mp : mkAry[1].toUpperCase();
301 } else if (mkAry.length == 3) {
302 if (!isNaN(mkAry[0])) {
303 mp = mkAry.slice(0, 2);
304 puc = mkAry[2].toUpperCase();
306 mp = mkAry[0].toUpperCase();
307 puc = mkAry.slice(1);
310 mp = mkAry.slice(0, 2);
311 puc = mkAry.slice(2);
314 var shdwPresent = typeof o3_shadow != 'undefined' && o3_shadow
317 sx = Math.abs(o3_shadowx);
318 sy = Math.abs(o3_shadowy);
321 pW = (shdwPresent ? parseInt(o3_width) : (olNs4 ? over.clip.width : over.offsetWidth))
322 pH = (shdwPresent ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight))
324 if (olOp && o3_wrap) {
325 pW = (shdwPresent ? parseInt(o3_width) : (olNs4 ? over.clip.width : over.offsetWidth))
326 pH = (shdwPresent ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight))
329 if (!olOp && mkObj.toString().indexOf('Image') != -1){
332 } else if (!olOp && mkObj.toString().indexOf('Anchor') != -1) { // enforced only for NS4
335 mW = (olNs4) ? mkObj.clip.width : mkObj.offsetWidth
336 mH = (olNs4) ? mkObj.clip.height : mkObj.offsetHeight
339 if (!isNaN(mp) || typeof mp == 'object') {
340 if (typeof mp == 'object') {
341 fx = parseFloat(mp[0]);
342 fy = parseFloat(mp[1]);
344 fx = fy = parseFloat(mp);
345 off = [Math.round(fx*mW), Math.round(fy*mH)];
347 if (mp == 'UR') off = [mW, 0]
348 else if (mp == 'LL') off = [0, mH]
349 else if (mp == 'LR') off = [mW, mH]
352 if (typeof o3_dragimg != 'undefined' && o3_dragimg) return off;
354 if (!isNaN(puc) || typeof puc == 'object' ) {
355 if (typeof puc == 'object') {
356 fx = parseFloat(puc[0]);
357 fy = parseFloat(puc[1]);
359 fx = fy = parseFloat(puc);
360 off[0] -= Math.round(fx*(pW - sx));
361 off[1] -= Math.round(fy*(pH - sy));
366 } else if (puc == 'LL') {
369 } else if (puc == 'LR') {
378 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
379 function pageLocation(o, t){
382 while(o.offsetParent){
391 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
392 function getRefById(l, d){
396 if (d.all) return d.all[l]
397 else if (d.getElementById) return d.getElementById(l)
398 else if (d.layers && d.layers.length > 0) {
399 if (d.layers[l]) return d.layers[l]
401 for (j=0; j < d.layers.length; j++) {
402 r = getRefById(l, d.layers[j].document)
410 // Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
411 function getRefByName(l, d) {
416 if (d.images[l]) return d.images[l]
417 else if (d.anchors[l]) return d.anchors[l];
418 else if (d.layers && d.layers.length > 0) {
419 for (j=0; j < d.layers.length; j++) {
420 r = getRefByName(l, d.layers[j].document)
421 if (r && r.length > 0) return r
422 else if (r) return [r, d.layers[j]]
430 // PLUGIN REGISTRATIONS
432 registerHook("placeLayer", anchorPlaceLayer, FREPLACE);
433 registerRunTimeFunction(setAnchorVariables);
434 registerCmdLineFunction(parseAnchorExtras);
435 registerPostParseFunction(checkAnchorObject);
436 registerHook("createPopup", anchorPreface, FAFTER);