forked from overlib/overlib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoverlib_anchor.js
333 lines (274 loc) · 9.11 KB
/
overlib_anchor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
//\/////
//\ overLIB Anchor Plugin
//\ This file requires overLIB 4.10 or later.
//\
//\ overLIB 4.10 - You may not remove or change this notice.
//\ Copyright Erik Bosrup 1998-2004. All rights reserved.
//\ Contributors are listed on the homepage.
//\ See http://www.bosrup.com/web/overlib/ for details.
// $Revision: 1.7 $ $Date: 2004/11/25 21:27:19 $
//\/////
//\mini
////////
// PRE-INIT
// Ignore these lines, configuration is below.
////////
if (typeof olInfo == 'undefined' || typeof olInfo.meets == 'undefined' || !olInfo.meets(4.10)) alert('overLIB 4.10 or later is required for the Anchor Plugin.');
else {
registerCommands('anchor,anchorx,anchory,noanchorwarn,anchoralign');
////////
// DEFAULT CONFIGURATION
// Settings you want everywhere are set here. All of this can also be
// changed on your html page or through an overLIB call.
////////
if (typeof ol_anchor == 'undefined') var ol_anchor = '';
if (typeof ol_anchorx == 'undefined') var ol_anchorx = 0;
if (typeof ol_anchory == 'undefined') var ol_anchory = 0;
if (typeof ol_noanchorwarn == 'undefined') var ol_noanchorwarn = 1;
if (typeof ol_anchoralign == 'undefined') var ol_anchoralign = 'UL';
////////
// END OF CONFIGURATION
// Don't change anything below this line, all configuration is above.
////////
////////
// INIT
////////
// Runtime variables init. Don't change for config!
var o3_anchor = "";
var o3_anchorx = 0;
var o3_anchory = 0;
var o3_noanchorwarn = 1;
var o3_anchoralign = 'UL';
var mrkObj, rmrkPosition; //reference mark object, reference mark position, an array;
////////
// PLUGIN FUNCTIONS
////////
function setAnchorVariables() {
o3_anchor = ol_anchor;
o3_anchorx = ol_anchorx;
o3_anchory = ol_anchory;
o3_noanchorwarn = ol_noanchorwarn;
o3_anchoralign = ol_anchoralign;
mrkObj = null; // initialize this variable
}
// Parses Reference Mark commands
function parseAnchorExtras(pf,i,ar) {
var v, k=i;
if (k < ar.length) {
if (ar[k] == ANCHOR) { eval(pf + "anchor = '" + escSglQuote(ar[++k]) + "'"); return k; }
if (ar[k] == ANCHORX) { eval(pf + 'anchorx = ' + ar[++k]); return k; }
if (ar[k] == ANCHORY) { eval(pf + 'anchory = ' + ar[++k]); return k; }
if (ar[k] == NOANCHORWARN) { eval(pf + 'noanchorwarn = (' + pf + 'noanchorwarn==1) ? 0 : 1'); return k; }
if (ar[k] == ANCHORALIGN) { k = opt_MULTIPLEARGS(++k, ar, (pf + 'anchoralign')); return k; }
}
return -1;
}
///////
// FUNCTION WHICH CHECKS FOR THE EXISTENCE OF A REFERENCE MARKER
///////
function checkAnchorObject() {
var w = o3_anchor;
if (w) {
if (!(mrkObj = getAnchorObjectRef(w))) {
if (o3_noanchorwarn) {
alert('WARNING! Reference mark "' + w + '" not found.');
return false;
} else w = '';
}
}
return true;
}
///////
// EXTERNAL SUPPORT FUNCTIONS TO HANDLE ANCHOR PROPERTIES
///////
// Horizontal placement routine with anchors
function anchorHorizontal(browserWidth, horizontalScrollAmount, widthFix) {
var hasAnchor = (typeof o3_anchor != 'undefined' && o3_anchor);
if (!hasAnchor) return void(0);
// set o3_relx for follow scroll if defined
if (typeof o3_followscroll != 'undefined' && o3_followscroll && o3_sticky) o3_relx = rmrkPosition[0];
return rmrkPosition[0];
}
// Vertical placement routine with anchors
function anchorVertical(browserHeight,verticalScrollAmount) {
var hasAnchor = (typeof o3_anchor != 'undefined' && o3_anchor);
if (!hasAnchor) return void(0);
// set o3_rely for follow scroll if defined
if (typeof o3_followscroll != 'undefined' && o3_followscroll && o3_sticky) o3_rely = rmrkPosition[1];
return rmrkPosition[1];
}
// Stub function for the runHook routine
function anchorPreface() {
if (!mrkObj) return;
rmrkPosition = getAnchorLocation(mrkObj);
}
// Get Reference Mark object
function getAnchorObjectRef(aObj) {
return getRefById(aObj, o3_frame.document) || getRefByName(aObj, o3_frame.document)
}
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
function getAnchorLocation(objRef){
var mkObj, of, offsets, mlyr
mkObj = mlyr = objRef
offsets = [o3_anchorx, o3_anchory]
if (document.layers){
if (typeof mlyr.length != 'undefined' && mlyr.length > 1) {
mkObj = mlyr[0]
offsets[0] += mlyr[0].x + mlyr[1].pageX
offsets[1] += mlyr[0].y + mlyr[1].pageY
} else {
if(mlyr.toString().indexOf('Image') != -1 || mlyr.toString().indexOf('Anchor') != -1){
offsets[0] += mlyr.x
offsets[1] += mlyr.y
} else {
offsets[0] += mlyr.pageX
offsets[1] += mlyr.pageY
}
}
} else {
offsets[0] += pageLocation(mlyr, 'Left')
offsets[1] += pageLocation(mlyr, 'Top')
}
of = getAnchorOffsets(mkObj)
if (typeof o3_dragimg != 'undefined' && o3_dragimg) {
olImgLeft = offsets[0];
olImgTop = offsets[1];
}
offsets[0] += of[0]
offsets[1] += of[1]
if (typeof o3_dragimg != 'undefined' && o3_dragimg) {
olImgRight = offsets[0];
olImgBottom = offsets[1];
return;
}
return offsets;
}
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
function getAnchorOffsets(mkObj){
var fx = fy = 0, mp, puc, mkAry, sx = sy = 0, w = o3_anchoralign
var mW = mH = pW = pH = 0
var off = [0, 0]
mkAry = w.split(',');
if (mkAry.length < 3) {
mp = mkAry[0].toUpperCase();
puc = (mkAry.length == 1) ? mp : mkAry[1].toUpperCase();
} else if (mkAry.length == 3) {
if (!isNaN(mkAry[0])) {
mp = mkAry.slice(0, 2);
puc = mkAry[2].toUpperCase();
} else {
mp = mkAry[0].toUpperCase();
puc = mkAry.slice(1);
}
} else {
mp = mkAry.slice(0, 2);
puc = mkAry.slice(2);
}
var shdwPresent = typeof o3_shadow != 'undefined' && o3_shadow
if (shdwPresent) {
sx = Math.abs(o3_shadowx);
sy = Math.abs(o3_shadowy);
}
pW = (shdwPresent ? parseInt(o3_width) : (olNs4 ? over.clip.width : over.offsetWidth))
pH = (shdwPresent ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight))
if (olOp && o3_wrap) {
pW = (shdwPresent ? parseInt(o3_width) : (olNs4 ? over.clip.width : over.offsetWidth))
pH = (shdwPresent ? parseInt(o3_aboveheight) : (olNs4 ? over.clip.height : over.offsetHeight))
}
if (!olOp && mkObj.toString().indexOf('Image') != -1){
mW = mkObj.width
mH = mkObj.height
} else if (!olOp && mkObj.toString().indexOf('Anchor') != -1) { // enforced only for NS4
mp = 'UL'
} else {
mW = (olNs4) ? mkObj.clip.width : mkObj.offsetWidth
mH = (olNs4) ? mkObj.clip.height : mkObj.offsetHeight
}
if (!isNaN(mp) || typeof mp == 'object') {
if (typeof mp == 'object') {
fx = parseFloat(mp[0]);
fy = parseFloat(mp[1]);
} else
fx = fy = parseFloat(mp);
off = [Math.round(fx*mW), Math.round(fy*mH)];
} else {
if (mp == 'UR') off = [mW, 0]
else if (mp == 'LL') off = [0, mH]
else if (mp == 'LR') off = [mW, mH]
}
if (typeof o3_dragimg != 'undefined' && o3_dragimg) return off;
else {
if (!isNaN(puc) || typeof puc == 'object' ) {
if (typeof puc == 'object') {
fx = parseFloat(puc[0]);
fy = parseFloat(puc[1]);
} else
fx = fy = parseFloat(puc);
off[0] -= Math.round(fx*(pW - sx));
off[1] -= Math.round(fy*(pH - sy));
} else {
if (puc == 'UR') {
off[0] -= (pW - sx);
off[1] -= sy
} else if (puc == 'LL') {
off[0] -= sx;
off[1] -= (pH - sy)
} else if (puc == 'LR') {
off[0] -= (pW-sx);
off[1] -= (pH - sy)
}
}
return off
}
}
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
function pageLocation(o, t){
var x = 0
while(o.offsetParent){
x += o['offset' + t]
o = o.offsetParent
}
x += o['offset' + t]
return x
}
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
function getRefById(l, d){
var r = "", j
d = (d || document)
if (d.all) return d.all[l]
else if (d.getElementById) return d.getElementById(l)
else if (d.layers && d.layers.length > 0) {
if (d.layers[l]) return d.layers[l]
for (j=0; j < d.layers.length; j++) {
r = getRefById(l, d.layers[j].document)
if(r) return r
}
}
return false
}
// Adapted to overlib from jwin by Jason Anderson -- http://www.jwinlib.com
function getRefByName(l, d) {
var r = null, j
d = (d || document)
if (d.images[l]) return d.images[l]
else if (d.anchors[l]) return d.anchors[l];
else if (d.layers && d.layers.length > 0) {
for (j=0; j < d.layers.length; j++) {
r = getRefByName(l, d.layers[j].document)
if (r && r.length > 0) return r
else if (r) return [r, d.layers[j]]
}
}
return null
}
////////
// PLUGIN REGISTRATIONS
////////
registerRunTimeFunction(setAnchorVariables);
registerCmdLineFunction(parseAnchorExtras);
registerPostParseFunction(checkAnchorObject);
registerHook("createPopup", anchorPreface, FAFTER);
registerHook("horizontalPlacement", anchorHorizontal, FCHAIN);
registerHook("verticalPlacement", anchorVertical, FCHAIN);
if(olInfo.meets(4.10)) registerNoParameterCommands('noanchorwarn');
}