Project

General

Profile

1
//\/////
2

    
3
//\  overLIB Anchor Plugin
4

    
5
//\  This file requires overLIB 4.10 or later.
6

    
7
//\
8

    
9
//\  overLIB 4.10 - You may not remove or change this notice.
10

    
11
//\  Copyright Erik Bosrup 1998-2004. All rights reserved.
12

    
13
//\  Contributors are listed on the homepage.
14

    
15
//\  See http://www.bosrup.com/web/overlib/ for details.
16

    
17
//   $Revision$                      $Date$
18

    
19
//\/////
20

    
21
//\mini
22

    
23

    
24

    
25

    
26

    
27
////////
28

    
29
// PRE-INIT
30

    
31
// Ignore these lines, configuration is below.
32

    
33
////////
34

    
35
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Anchor Plugin.');
36

    
37
else {
38

    
39
registerCommands('anchor,anchorx,anchory,noanchorwarn,anchoralign');
40

    
41

    
42

    
43

    
44

    
45

    
46

    
47
////////
48

    
49
// DEFAULT CONFIGURATION
50

    
51
// Settings you want everywhere are set here. All of this can also be
52

    
53
// changed on your html page or through an overLIB call.
54

    
55
////////
56

    
57
if (typeof ol_anchor ==  'undefined') var ol_anchor = '';
58

    
59
if (typeof ol_anchorx ==  'undefined') var ol_anchorx = 0;
60

    
61
if (typeof ol_anchory ==  'undefined') var ol_anchory = 0;
62

    
63
if (typeof ol_noanchorwarn ==  'undefined') var ol_noanchorwarn = 1;
64

    
65
if (typeof ol_anchoralign ==  'undefined') var ol_anchoralign = 'UL';
66

    
67

    
68

    
69
////////
70

    
71
// END OF CONFIGURATION
72

    
73
// Don't change anything below this line, all configuration is above.
74

    
75
////////
76

    
77

    
78

    
79

    
80

    
81

    
82

    
83

    
84

    
85

    
86

    
87
////////
88

    
89
// INIT
90

    
91
////////
92

    
93
// Runtime variables init. Don't change for config!
94

    
95
var o3_anchor = "";
96

    
97
var o3_anchorx = 0;
98

    
99
var o3_anchory = 0;
100

    
101
var o3_noanchorwarn = 1;
102

    
103
var o3_anchoralign = 'UL';
104

    
105
var mrkObj, rmrkPosition;  //reference mark object, reference mark position, an array;
106

    
107

    
108

    
109

    
110

    
111
////////
112

    
113
// PLUGIN FUNCTIONS
114

    
115
////////
116

    
117
function setAnchorVariables() {
118

    
119
	o3_anchor = ol_anchor;
120

    
121
	o3_anchorx = ol_anchorx;
122

    
123
	o3_anchory = ol_anchory;
124

    
125
	o3_noanchorwarn = ol_noanchorwarn;
126

    
127
	o3_anchoralign = ol_anchoralign;
128

    
129
	mrkObj = null;  // initialize this variable
130

    
131
}
132

    
133

    
134

    
135
// Parses Reference Mark commands
136

    
137
function parseAnchorExtras(pf,i,ar) {
138

    
139
	var v, k=i;
140

    
141

    
142

    
143
	if (k < ar.length) {
144

    
145
		if (ar[k] ==  ANCHOR) { eval(pf + "anchor = '" + escSglQuote(ar[++k]) + "'"); return k; }
146

    
147
		if (ar[k] ==  ANCHORX) { eval(pf + 'anchorx = ' + ar[++k]); return k; }
148

    
149
		if (ar[k] ==  ANCHORY) { eval(pf + 'anchory = ' + ar[++k]); return k; }
150

    
151
		if (ar[k] ==  NOANCHORWARN) { eval(pf + 'noanchorwarn = (' + pf + 'noanchorwarn==1) ? 0 : 1'); return k; }
152

    
153
		if (ar[k] ==  ANCHORALIGN) { k = opt_MULTIPLEARGS(++k, ar, (pf + 'anchoralign'));  return k; }
154

    
155
	}
156

    
157

    
158

    
159
	return -1;
160

    
161
}
162

    
163

    
164

    
165

    
166

    
167
///////
168

    
169
//  FUNCTION WHICH CHECKS FOR THE EXISTENCE OF A REFERENCE MARKER
170

    
171
///////
172

    
173
function checkAnchorObject() {
174

    
175
	var w = o3_anchor;
176

    
177

    
178

    
179
	if (w) {
180

    
181
		if (!(mrkObj = getAnchorObjectRef(w))) {
182

    
183
			if (o3_noanchorwarn) {
184

    
185
				alert('WARNING!  Reference mark "' + w + '" not found.');
186

    
187
				return false;
188

    
189
			} else w = '';
190

    
191
		}
192

    
193
	}
194

    
195

    
196

    
197
	return true;
198

    
199
}
200

    
201

    
202

    
203
///////
204

    
205
// EXTERNAL SUPPORT FUNCTIONS TO HANDLE ANCHOR PROPERTIES
206

    
207
///////
208

    
209

    
210

    
211
// Horizontal placement routine with anchors
212

    
213
function anchorHorizontal(browserWidth, horizontalScrollAmount, widthFix) {
214

    
215
	var hasAnchor = (typeof o3_anchor != 'undefined' && o3_anchor);
216

    
217
	if (!hasAnchor) return void(0);
218

    
219

    
220

    
221
	// set o3_relx for follow scroll if defined
222

    
223
	if (typeof o3_followscroll != 'undefined' && o3_followscroll && o3_sticky) o3_relx = rmrkPosition[0];
224

    
225

    
226

    
227
	return rmrkPosition[0];
228

    
229
}
230

    
231

    
232

    
233
// Vertical placement routine with anchors
234

    
235
function anchorVertical(browserHeight,verticalScrollAmount) {
236

    
237
	var hasAnchor = (typeof o3_anchor != 'undefined' && o3_anchor);	
238

    
239
	if (!hasAnchor) return void(0);
240

    
241

    
242

    
243
	// set o3_rely for follow scroll if defined
244

    
245
	if (typeof o3_followscroll != 'undefined' && o3_followscroll && o3_sticky) o3_rely = rmrkPosition[1];
246

    
247

    
248

    
249
	return rmrkPosition[1];
250

    
251
}
252

    
253

    
254

    
255
// Stub function for the runHook routine
256

    
257
function anchorPreface() {
258

    
259
	if (!mrkObj) return;
260

    
261
	rmrkPosition = getAnchorLocation(mrkObj);
262

    
263
}
264

    
265

    
266

    
267
// Get Reference Mark object 
268

    
269
function getAnchorObjectRef(aObj) {
270

    
271
	return getRefById(aObj, o3_frame.document) || getRefByName(aObj, o3_frame.document)
272

    
273
}
274

    
275

    
276

    
277
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
278

    
279
function getAnchorLocation(objRef){
280

    
281
	var mkObj, of, offsets, mlyr
282

    
283
	
284

    
285
	mkObj = mlyr = objRef
286

    
287
	offsets = [o3_anchorx, o3_anchory]
288

    
289
	
290

    
291
	if (document.layers){
292

    
293
		if (typeof mlyr.length != 'undefined' &&  mlyr.length > 1) {
294

    
295
				mkObj = mlyr[0]
296

    
297
				offsets[0] += mlyr[0].x + mlyr[1].pageX
298

    
299
				offsets[1] += mlyr[0].y + mlyr[1].pageY
300

    
301
			} else {
302

    
303
				if(mlyr.toString().indexOf('Image') != -1 || mlyr.toString().indexOf('Anchor') != -1){
304

    
305
					offsets[0] += mlyr.x
306

    
307
					offsets[1] += mlyr.y
308

    
309
				} else {
310

    
311
					offsets[0] += mlyr.pageX
312

    
313
					offsets[1] += mlyr.pageY
314

    
315
				}
316

    
317
			}          
318

    
319
	} else {
320

    
321
		offsets[0] += pageLocation(mlyr, 'Left')
322

    
323
		offsets[1] += pageLocation(mlyr, 'Top')
324

    
325
	}
326

    
327
	
328

    
329
	of = getAnchorOffsets(mkObj)
330

    
331
	
332

    
333
	if (typeof o3_dragimg != 'undefined' &&  o3_dragimg) {
334

    
335
		olImgLeft = offsets[0];
336

    
337
		olImgTop = offsets[1];
338

    
339
	}
340

    
341
	
342

    
343
	offsets[0] += of[0]                    
344

    
345
	offsets[1] += of[1]
346

    
347
	
348

    
349
	if (typeof o3_dragimg != 'undefined' &&  o3_dragimg) {
350

    
351
		olImgRight = offsets[0]; 
352

    
353
		olImgBottom = offsets[1];
354

    
355
		return;
356

    
357
	}
358

    
359
	
360

    
361
	return offsets;
362

    
363
}
364

    
365

    
366

    
367
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
368

    
369
function getAnchorOffsets(mkObj){
370

    
371
	var fx = fy = 0,  mp, puc, mkAry, sx = sy = 0, w = o3_anchoralign  
372

    
373
	var mW = mH = pW = pH = 0
374

    
375
	var off = [0, 0]
376

    
377

    
378

    
379
	mkAry = w.split(',');
380

    
381

    
382

    
383
	if (mkAry.length < 3) {
384

    
385
		mp = mkAry[0].toUpperCase();
386

    
387
		puc = (mkAry.length == 1) ? mp : mkAry[1].toUpperCase();
388

    
389
	} else if (mkAry.length == 3) {
390

    
391
		if (!isNaN(mkAry[0])) {
392

    
393
			mp = mkAry.slice(0, 2);
394

    
395
			puc = mkAry[2].toUpperCase();
396

    
397
		 } else {
398

    
399
			mp = mkAry[0].toUpperCase();
400

    
401
			puc = mkAry.slice(1);
402

    
403
		 }
404

    
405
	} else {
406

    
407
		mp = mkAry.slice(0, 2);
408

    
409
		puc = mkAry.slice(2);
410

    
411
	}
412

    
413

    
414

    
415
	var shdwPresent = typeof o3_shadow != 'undefined' &&  o3_shadow
416

    
417

    
418

    
419
	if (shdwPresent) {
420

    
421
		sx = Math.abs(o3_shadowx);
422

    
423
		sy = Math.abs(o3_shadowy);
424

    
425
	}
426

    
427

    
428

    
429
	pW = (shdwPresent ? parseInt(o3_width) : (olNs4 ? over.clip.width : over.offsetWidth))
430

    
431
	pH = (shdwPresent ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight))
432

    
433

    
434

    
435
	if (olOp &&  o3_wrap) {
436

    
437
		pW = (shdwPresent ? parseInt(o3_width) : (olNs4 ? over.clip.width : over.offsetWidth))
438

    
439
		pH = (shdwPresent ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight))
440

    
441
	}
442

    
443

    
444

    
445
	if (!olOp &&  mkObj.toString().indexOf('Image') != -1){
446

    
447
		mW = mkObj.width
448

    
449
		mH = mkObj.height
450

    
451
	} else if (!olOp &&  mkObj.toString().indexOf('Anchor') != -1) {  // enforced only for NS4
452

    
453
		mp = 'UL'
454

    
455
	} else {
456

    
457
		mW = (olNs4) ? mkObj.clip.width : mkObj.offsetWidth
458

    
459
		mH = (olNs4) ? mkObj.clip.height : mkObj.offsetHeight
460

    
461
	}
462

    
463

    
464

    
465
	if (!isNaN(mp) || typeof mp == 'object') {
466

    
467
		if (typeof mp == 'object') {
468

    
469
			fx = parseFloat(mp[0]);
470

    
471
			fy = parseFloat(mp[1]);
472

    
473
		} else
474

    
475
			fx = fy = parseFloat(mp);
476

    
477
		off = [Math.round(fx*mW), Math.round(fy*mH)];
478

    
479
	} else {
480

    
481
		 if (mp == 'UR') off = [mW, 0]
482

    
483
		 else if (mp == 'LL') off = [0, mH]
484

    
485
		 else if (mp == 'LR') off = [mW, mH]
486

    
487
	}
488

    
489

    
490

    
491
	if (typeof o3_dragimg != 'undefined' &&  o3_dragimg) return off;
492

    
493
	else {
494

    
495
		if (!isNaN(puc) || typeof puc == 'object' ) {
496

    
497
			if (typeof puc == 'object') {
498

    
499
				fx = parseFloat(puc[0]);
500

    
501
				fy = parseFloat(puc[1]);
502

    
503
			} else
504

    
505
				fx = fy = parseFloat(puc);
506

    
507
			off[0] -= Math.round(fx*(pW - sx));
508

    
509
			off[1] -= Math.round(fy*(pH - sy));
510

    
511
		} else {
512

    
513
			if (puc == 'UR') {
514

    
515
				off[0] -= (pW - sx); 
516

    
517
				off[1] -= sy
518

    
519
			} else if (puc == 'LL') {
520

    
521
				off[0] -= sx;
522

    
523
				off[1] -= (pH - sy)
524

    
525
			} else if (puc == 'LR') {
526

    
527
				off[0] -= (pW-sx);
528

    
529
				off[1] -= (pH - sy)
530

    
531
			}
532

    
533
		}
534

    
535
		return off
536

    
537
	}
538

    
539
}
540

    
541

    
542

    
543
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
544

    
545
function pageLocation(o, t){
546

    
547
	var x = 0
548

    
549

    
550

    
551
	while(o.offsetParent){
552

    
553
		x += o['offset' + t]
554

    
555
		o = o.offsetParent
556

    
557
	}
558

    
559
	x += o['offset' + t]
560

    
561

    
562

    
563
	return x
564

    
565
} 
566

    
567

    
568

    
569
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
570

    
571
function getRefById(l, d){
572

    
573
	var r = "", j
574

    
575

    
576

    
577
	d = (d || document)
578

    
579
	if (d.all) return d.all[l]    
580

    
581
	else if (d.getElementById) return d.getElementById(l)
582

    
583
	else if (d.layers &&  d.layers.length > 0) {
584

    
585
		if (d.layers[l]) return d.layers[l]
586

    
587
		
588

    
589
		for (j=0; j < d.layers.length; j++) {
590

    
591
			r = getRefById(l, d.layers[j].document)
592

    
593
			if(r) return r               
594

    
595
		}
596

    
597
	}
598

    
599

    
600

    
601
	return false
602

    
603
}
604

    
605

    
606

    
607
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
608

    
609
function getRefByName(l, d) {
610

    
611
	var r = null, j
612

    
613

    
614

    
615
	d = (d || document)
616

    
617

    
618

    
619
	if (d.images[l]) return d.images[l]
620

    
621
	else if (d.anchors[l]) return d.anchors[l];
622

    
623
	else if (d.layers &&  d.layers.length > 0) {
624

    
625
		for (j=0; j < d.layers.length; j++) {
626

    
627
			r = getRefByName(l, d.layers[j].document)
628

    
629
			if (r &&  r.length > 0) return r
630

    
631
			else if (r) return [r, d.layers[j]]
632

    
633
		}
634

    
635
	}
636

    
637

    
638

    
639
	return null
640

    
641
}
642

    
643

    
644

    
645
////////
646

    
647
// PLUGIN REGISTRATIONS
648

    
649
////////
650

    
651
registerRunTimeFunction(setAnchorVariables);
652

    
653
registerCmdLineFunction(parseAnchorExtras);
654

    
655
registerPostParseFunction(checkAnchorObject);
656

    
657
registerHook("createPopup", anchorPreface, FAFTER);
658

    
659
registerHook("horizontalPlacement", anchorHorizontal, FCHAIN);
660

    
661
registerHook("verticalPlacement", anchorVertical, FCHAIN);
662

    
663
if(olInfo.meets(4.10)) registerNoParameterCommands('noanchorwarn');
664

    
665
}
(2-2/11)