1 |
// ----------------------------------------------------------------------------- |
2 |
// IWF - Interactive Website Framework. Javascript library for creating |
3 |
// responsive thin client interfaces. |
4 |
// |
5 |
// Copyright (C) 2005 Brock Weaver brockweaver@gmail.com |
6 |
// |
7 |
// This library is free software; you can redistribute it and/or modify |
8 |
// it under the terms of the GNU Lesser General Public License as published |
9 |
// by the Free Software Foundation; either version 2.1 of the License, or |
10 |
// (at your option) any later version. |
11 |
// |
12 |
// This library is distributed in the hope that it will be useful, but |
13 |
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
15 |
// License for more details. |
16 |
// |
17 |
// You should have received a copy of the GNU Lesser General Public License |
18 |
// along with this library; if not, write to the Free Software Foundation, |
19 |
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
// |
21 |
// Brock Weaver |
22 |
// brockweaver@gmail.com |
23 |
// 1605 NW Maple Pl |
24 |
// Ankeny, IA 50021 |
25 |
// ----------------------------------------------------------------------------- |
26 |
|
27 |
// -------------------------------------------------------------------------- |
28 |
// iwfgui.js |
29 |
// |
30 |
// GUI inspection and manipulation functions |
31 |
// |
32 |
// Dependencies: |
33 |
// iwfcore.js |
34 |
// |
35 |
// Brock Weaver - brockweaver@sourceforge.net - iwf.sourceforge.net |
36 |
// v 0.1 - 2005-06-05 |
37 |
// Initial release. |
38 |
// -------------------------------------------------------------------------- |
39 |
// Issues: |
40 |
// Timeouts have hiccups sometimes when they begin to overlap |
41 |
// Not tested on Safari -- I need an iMac! |
42 |
// _iwfMoveTo() has some calculation problems with certain motionType values |
43 |
// -------------------------------------------------------------------------- |
44 |
|
45 |
// ----------------------------------- |
46 |
// Dependency Check |
47 |
if (!window.iwfGetById){ |
48 |
alert("IWF Dependency Error: you must set a reference to the iwfcore.js file *before* iwfgui.js! I.E.:\n\n<script type='text/javascript' src='iwfcore.js'></script>\n<script type='text/javascript' src='iwfgui.js'></script>"); |
49 |
} |
50 |
// ----------------------------------- |
51 |
|
52 |
|
53 |
|
54 |
// ----------------------------------- |
55 |
// Begin: Visibility |
56 |
// ----------------------------------- |
57 |
|
58 |
function iwfShow(id, reserveSpace){ |
59 |
var el = iwfGetById(id); |
60 |
if (reserveSpace){ |
61 |
if (iwfExists(el) && iwfExists(el.style) && iwfExists(el.style.visibility)) el.style.visibility = 'visible'; |
62 |
} else { |
63 |
if (iwfExists(el) && iwfExists(el.style) && iwfExists(el.style.display)) el.style.display = 'inline'; |
64 |
} |
65 |
} |
66 |
|
67 |
function iwfHide(id, reserveSpace){ |
68 |
var el = iwfGetById(id); |
69 |
if (reserveSpace){ |
70 |
if (el && iwfExists(el.style) && iwfExists(el.style.visibility)) el.style.visibility = 'hidden'; |
71 |
} else { |
72 |
if (el && iwfExists(el.style) && iwfExists(el.style.display)) el.style.display = 'none'; |
73 |
} |
74 |
} |
75 |
|
76 |
function iwfHideDelay(id, ms, reserveSpace){ |
77 |
var el = iwfGetById(id); |
78 |
if (!el) return; |
79 |
|
80 |
// wipeout any other re-visibling timeouts we have (nice spelling, eh?) |
81 |
_iwfClearTimeout(el, "hidedelay", "visible", true); |
82 |
|
83 |
if (ms < 1){ |
84 |
iwfHide(el, reserveSpace); |
85 |
} else { |
86 |
_iwfSetTimeout(el, "hidedelay", "visible", "iwfHideDelay('" + el.id + "', 0, " + reserveSpace + ")", ms); |
87 |
} |
88 |
} |
89 |
|
90 |
function iwfShowDelay(id, ms, reserveSpace){ |
91 |
var el = iwfGetById(id); |
92 |
if (!el) return; |
93 |
|
94 |
// wipeout any other re-visibling timeouts we have (nice spelling, eh?) |
95 |
_iwfClearTimeout(el, "showdelay", "visible", true); |
96 |
|
97 |
if (ms < 1){ |
98 |
iwfShow(el, reserveSpace); |
99 |
} else { |
100 |
_iwfSetTimeout(el, "showdelay", "visible", "iwfShowDelay('" + el.id + "', 0, " + reserveSpace + ")", ms); |
101 |
} |
102 |
} |
103 |
|
104 |
function iwfShowGently(id, pct, reserveSpace){ |
105 |
|
106 |
var el = iwfGetById(id); |
107 |
if (!el) return; |
108 |
|
109 |
// wipeout any other re-visibling timeouts we have (nice spelling, eh?) |
110 |
_iwfClearTimeout(el, "showgently", "visible", true); |
111 |
|
112 |
var opacity = iwfOpacity(el); |
113 |
if (iwfIsHidden(el)){ |
114 |
// set opacity to 0 |
115 |
iwfOpacity(el, 0, false, false); |
116 |
|
117 |
// show it |
118 |
iwfShow(el, reserveSpace); |
119 |
} |
120 |
|
121 |
// adjust opacity up by the given percentage |
122 |
opacity = iwfOpacity(el, pct, true); |
123 |
|
124 |
if (opacity < 100) { |
125 |
// set a timeout |
126 |
_iwfSetTimeout(el, "showgently", "visible", "iwfShowGently('" + el.id + "'," + pct + ", " + reserveSpace + ")", 50); |
127 |
} |
128 |
} |
129 |
|
130 |
function iwfHideGently(id, pct, reserveSpace){ |
131 |
var el = iwfGetById(id); |
132 |
if (!el) return; |
133 |
|
134 |
if (iwfIsHidden(el)) return; |
135 |
|
136 |
// wipeout any other re-visibling timeouts we have (nice spelling, eh?) |
137 |
_iwfClearTimeout(el, "hidegently", "visible", true); |
138 |
|
139 |
var opacity = iwfOpacity(el); |
140 |
if (opacity <= 0){ |
141 |
|
142 |
// hide it |
143 |
iwfHide(el, reserveSpace); |
144 |
|
145 |
// set opacity back to fully opaque, so when they iwfShow() it, |
146 |
// the element isn't fully transparent and looks like iwfShow() didn't work |
147 |
iwfOpacity(el, 100, false, true); |
148 |
|
149 |
|
150 |
} else { |
151 |
// make it less opaque... |
152 |
iwfOpacity(el, -pct, true); |
153 |
|
154 |
// set our timeout |
155 |
_iwfSetTimeout(el, "hidegently", "visible", "iwfHideGently('" + el.id + "'," + pct + ", " + reserveSpace + ")", 50); |
156 |
} |
157 |
} |
158 |
|
159 |
function iwfHideGentlyDelay(id, pct, ms, reserveSpace){ |
160 |
var el = iwfGetById(id); |
161 |
if (!el) return; |
162 |
|
163 |
if (iwfIsHidden(el)) return; |
164 |
|
165 |
// wipeout any other re-visibling timeouts we have (nice spelling, eh?) |
166 |
_iwfClearTimeout(el, "hidegentlydelay", "visible", true); |
167 |
|
168 |
|
169 |
if (ms < 1){ |
170 |
iwfHideGently(el, pct, reserveSpace); |
171 |
} else { |
172 |
_iwfSetTimeout(el, "hidegentlydelay", "visible", "iwfHideGentlyDelay('" + el.id + "'," + pct + ", 0, " + reserveSpace + ")", ms); |
173 |
} |
174 |
|
175 |
} |
176 |
|
177 |
function iwfShowGentlyDelay(id, pct, ms, reserveSpace){ |
178 |
var el = iwfGetById(id); |
179 |
if (!el) return; |
180 |
|
181 |
|
182 |
// wipeout any other re-visibling timeouts we have (nice spelling, eh?) |
183 |
_iwfClearTimeout(el, "showgentlydelay", "visible", true); |
184 |
|
185 |
if (ms < 1){ |
186 |
iwfShowGently(el, pct, reserveSpace); |
187 |
} else { |
188 |
_iwfSetTimeout(el, "showgentlydelay", "visible", "iwfShowGentlyDelay('" + el.id + "'," + pct + ", 0, " + reserveSpace + ")", ms); |
189 |
} |
190 |
} |
191 |
|
192 |
function iwfOpacity(id, pct, relative, keepHiddenIfAlreadyHidden){ |
193 |
var el = iwfGetById(id); |
194 |
if (el){ |
195 |
if (iwfExists(pct) && pct != null){ |
196 |
// set opacity |
197 |
var newPct = iwfToFloat(pct, true); |
198 |
if (relative){ |
199 |
// lookup current opacity |
200 |
newPct = iwfOpacity(id, null, false); |
201 |
|
202 |
// modify pct by that much |
203 |
newPct += pct; |
204 |
} |
205 |
|
206 |
if (newPct < 0){ |
207 |
newPct = 0; |
208 |
} else if (newPct > 100){ |
209 |
newPct = 100; |
210 |
} |
211 |
|
212 |
if (iwfExists(el.style.opacity)) el.style.opacity = newPct/100; |
213 |
else if (iwfExists(el.style.filter)) el.style.filter = "alpha(opacity=" + newPct + ")"; |
214 |
else if (iwfExists(el.style.mozOpacity)) el.style.mozOpacity = newPct/100; |
215 |
|
216 |
// also display it if opacity > 0 and !keepHidden |
217 |
if (newPct > 0 && !keepHiddenIfAlreadyHidden){ |
218 |
if (iwfIsHidden(id)){ |
219 |
iwfShow(id); |
220 |
} |
221 |
} |
222 |
|
223 |
return newPct; |
224 |
|
225 |
} else { |
226 |
// get current opacity |
227 |
var val = null; |
228 |
if (iwfExists(el.style.opacity)){ |
229 |
if (el.style.opacity == ''){ |
230 |
val = 100; |
231 |
} else { |
232 |
val = iwfToFloat(el.style.opacity, 2, true) * 100; |
233 |
} |
234 |
} else if (iwfExists(el.style.filter)) { |
235 |
if (el.style.filter){ |
236 |
if (el.style.filter.indexOf("opacity") == 0){ |
237 |
val = 100; |
238 |
} else { |
239 |
val = iwfToFloat(el.style.filter, 2, true); |
240 |
} |
241 |
} else { |
242 |
val = 100; |
243 |
} |
244 |
} else if (iwfExists(el.style.mozOpacity)) { |
245 |
if (el.style.mozOpacity == ''){ |
246 |
val = 100; |
247 |
} else { |
248 |
val = iwfToFloat(el.style.mozOpacity, 2, true) * 100; |
249 |
} |
250 |
} |
251 |
|
252 |
return val; |
253 |
} |
254 |
} |
255 |
} |
256 |
|
257 |
function iwfIsShown(id){ |
258 |
return !iwfIsHidden(id); |
259 |
} |
260 |
|
261 |
function iwfIsHidden(id){ |
262 |
var el = iwfGetById(id); |
263 |
// if (!el) return false; |
264 |
|
265 |
var hidden = false; |
266 |
if (iwfExists(el.style) && iwfExists(el.style.visibility)) { |
267 |
hidden = el.style.visibility == 'hidden'; |
268 |
} |
269 |
if (iwfExists(el.style) && iwfExists(el.style.display)) { |
270 |
hidden = hidden || el.style.display == 'none'; |
271 |
} |
272 |
return hidden; |
273 |
} |
274 |
|
275 |
function iwfToggle(id, reserveSpace){ |
276 |
if (iwfIsHidden(id)) iwfShow(id, reserveSpace); |
277 |
else iwfHide(id, reserveSpace); |
278 |
} |
279 |
|
280 |
|
281 |
|
282 |
// ----------------------------------- |
283 |
// End: Visibility |
284 |
// ----------------------------------- |
285 |
|
286 |
// ----------------------------------- |
287 |
// Begin: Timers |
288 |
// ----------------------------------- |
289 |
|
290 |
function _iwfSetTimeout(id, name, category, fn, ms){ |
291 |
var el = iwfGetById(id); |
292 |
if (!el) return; |
293 |
|
294 |
var att = iwfAttribute(el, 'iwfTimeoutCategory' + category); |
295 |
if (!att){ |
296 |
// that attribute doesn't exist yet, or is null |
297 |
} else if (att != name){ |
298 |
// attribute exists but doesn't match our name. |
299 |
// clear out the existing one, since the category matches. |
300 |
_iwfClearTimeout(el.id, att, category); |
301 |
} else { |
302 |
// attribute matches our name. |
303 |
} |
304 |
|
305 |
iwfAttribute(el, 'iwfTimeoutCategory' + category, name); |
306 |
//iwfLog('setting timeout for ' + name + ' to ' + fn); |
307 |
var timeoutid = setTimeout(fn, ms); |
308 |
iwfAttribute(el, 'iwfTimeoutId' + category, timeoutid); |
309 |
return true; |
310 |
} |
311 |
|
312 |
function _iwfCheckTimeout(id, name, category){ |
313 |
//return true; |
314 |
|
315 |
var el = iwfGetById(id); |
316 |
if (!el) return false; |
317 |
|
318 |
var att = iwfAttribute(el, 'iwfTimeoutCategory' + category); |
319 |
if (!att || att == name){ |
320 |
return true; |
321 |
} else { |
322 |
return false; |
323 |
} |
324 |
|
325 |
} |
326 |
|
327 |
function _iwfClearTimeout(id, name, category, forceful){ |
328 |
var el = iwfGetById(id); |
329 |
if (!el) return; |
330 |
|
331 |
var att = iwfAttribute(el, 'iwfTimeoutCategory' + category); |
332 |
|
333 |
if (att == name || forceful){ |
334 |
// iwfLog('clearing timeout for ' + att); |
335 |
clearTimeout(iwfAttribute(el, 'iwfTimeoutId' + category)); |
336 |
iwfRemoveAttribute(el, 'iwfTimeoutId' + category); |
337 |
iwfRemoveAttribute(el, 'iwfTimeoutCategory' + category); |
338 |
} |
339 |
|
340 |
} |
341 |
|
342 |
// BROCK |
343 |
function iwfDelay(ms, fpOrString){ |
344 |
function _iwfDelayExpired(){ |
345 |
if (localIsString){ |
346 |
// passed a string. eval it. |
347 |
iwfLog("_iwfDelayExpired: calling string of:\n" + localFpOrString, true); |
348 |
eval(localFpOrString); |
349 |
} else { |
350 |
// they passed a function pointer. |
351 |
// call it, passing any args we were given. |
352 |
if (!localArgs || localArgs.length == 0){ |
353 |
localFpOrString(); |
354 |
} else if (localArgs.length == 1){ |
355 |
localFpOrString(localArgs[0]); |
356 |
} else { |
357 |
var s = 'localFpOrString('; |
358 |
for(var i=0;i<localArgs.length;i++){ |
359 |
if (i > 0){ |
360 |
s += ', '; |
361 |
} |
362 |
if(localArgs[i] == null){ |
363 |
s += 'null'; |
364 |
} else if(iwfIsString(localArgs[i])){ |
365 |
s += '"' + localArgs[i].replace(/"/gi, '\\"') + '"'; |
366 |
} else { |
367 |
s += localArgs[i]; |
368 |
} |
369 |
} |
370 |
s += ')'; |
371 |
//iwfLog("_iwfDelayExpired: calling fp of:\n" + s, true); |
372 |
eval(s); |
373 |
} |
374 |
} |
375 |
delete localFpOrString; |
376 |
delete localIsString; |
377 |
delete localArgs; |
378 |
} |
379 |
|
380 |
var localFpOrString = fpOrString; |
381 |
var localIsString = iwfIsString(fpOrString); |
382 |
var localArgs = null; |
383 |
|
384 |
if (!iwfIsString(fpOrString)){ |
385 |
if (arguments && arguments.length > 0){ |
386 |
localArgs = new Array(); |
387 |
for(var i=2;i<arguments.length;i++){ |
388 |
//iwfLog('args[' + i + '] = ' + arguments[i], true); |
389 |
localArgs.push(arguments[i]); |
390 |
} |
391 |
} |
392 |
} |
393 |
setTimeout(_iwfDelayExpired, ms); |
394 |
} |
395 |
|
396 |
// ----------------------------------- |
397 |
// End: Timers |
398 |
// ----------------------------------- |
399 |
|
400 |
|
401 |
// ----------------------------------- |
402 |
// Begin: Positioning |
403 |
// ----------------------------------- |
404 |
|
405 |
function iwfX1(id, newx){ |
406 |
return iwfX(id, newx); |
407 |
} |
408 |
|
409 |
|
410 |
function iwfFocusSelect(id, promptmsg){ |
411 |
var el = iwfGetById(id); |
412 |
if (promptmsg){ |
413 |
alert(promptmsg); |
414 |
} |
415 |
if (!iwfIsHidden(id)){ |
416 |
try { |
417 |
el.focus(); |
418 |
el.select(); |
419 |
} catch(e) { } |
420 |
} |
421 |
return false; |
422 |
} |
423 |
|
424 |
function iwfFocus(id, promptmsg){ |
425 |
var el = iwfGetById(id); |
426 |
if (promptmsg){ |
427 |
alert(promptmsg); |
428 |
} |
429 |
if (!iwfIsHidden(id)){ |
430 |
try { |
431 |
el.focus(); |
432 |
} catch(e) { } |
433 |
} |
434 |
return false; |
435 |
} |
436 |
|
437 |
|
438 |
|
439 |
function iwfX(id, newx){ |
440 |
var absx = 0; |
441 |
|
442 |
if (iwfIsNumber(newx)) { |
443 |
absx = iwfSetX(id, newx); |
444 |
} else { |
445 |
var el = iwfGetById(id); |
446 |
if (!el) return 0; |
447 |
if (iwfIsString(el.style.left) && el.style.left.length > 0){ |
448 |
absx = iwfToInt(el.style.left, true); |
449 |
if (isNaN(absx)) { |
450 |
absx = 0; |
451 |
} |
452 |
} else if (iwfExists(el.style.pixelLeft) && el.style.pixelLeft) { |
453 |
absx = el.style.pixelLeft; |
454 |
} else { |
455 |
while (el) { |
456 |
if (iwfExists(el.offsetLeft)) absx += el.offsetLeft; |
457 |
el = iwfGetParent(el, true); |
458 |
} |
459 |
} |
460 |
} |
461 |
|
462 |
return absx; |
463 |
} |
464 |
|
465 |
function iwfSetX(id, newx){ |
466 |
var el = iwfGetById(id); |
467 |
if (!el) return; |
468 |
if(iwfExists(el.style) && iwfIsString(el.style.left)) { |
469 |
el.style.left = newx + 'px'; |
470 |
} |
471 |
else if(iwfExists(el.style) && iwfExists(el.style.pixelLeft)) { |
472 |
el.style.pixelLeft = newx; |
473 |
} |
474 |
else if(iwfExists(el.left)) { |
475 |
el.left = newx; |
476 |
} |
477 |
return newx; |
478 |
} |
479 |
|
480 |
function iwfY1(id, newy){ |
481 |
var el = iwfGetById(id); |
482 |
return iwfY(el, newy); |
483 |
} |
484 |
|
485 |
function iwfY(id, newy){ |
486 |
var absy = 0; |
487 |
|
488 |
if (iwfIsNumber(newy)) { |
489 |
absy = iwfSetY(id, newy); |
490 |
} else { |
491 |
var el = iwfGetById(id); |
492 |
if (!el) return 0; |
493 |
|
494 |
if (iwfIsString(el.style.top) && el.style.top.length > 0){ |
495 |
absy = iwfToInt(el.style.top, true); |
496 |
if (isNaN(absy)) { |
497 |
absy = 0; |
498 |
} |
499 |
} else if (iwfExists(el.style.pixelTop) && el.style.pixelTop) { |
500 |
absy = el.style.pixelTop; |
501 |
} else { |
502 |
while (el) { |
503 |
if (iwfExists(el.offsetTop)) absy += el.offsetTop; |
504 |
el = iwfGetParent(el, true); |
505 |
} |
506 |
} |
507 |
} |
508 |
|
509 |
return absy; |
510 |
} |
511 |
|
512 |
function iwfSetY(id, newy){ |
513 |
var el = iwfGetById(id); |
514 |
if (!el) return; |
515 |
if (iwfExists(el.style)){ |
516 |
if (iwfIsString(el.style.top)) { |
517 |
el.style.top = newy + 'px'; |
518 |
} else if(iwfExists(el.style.pixelTop)) { |
519 |
el.style.pixelTop = newy; |
520 |
} else if(iwfExists(el.top)) { |
521 |
el.top = newy; |
522 |
} |
523 |
} |
524 |
return newy; |
525 |
} |
526 |
|
527 |
function iwfZIndex(id, z){ |
528 |
var el = iwfGetById(id); |
529 |
if (iwfExists(el)){ |
530 |
if (iwfExists(z)){ |
531 |
el.style.zIndex = z; |
532 |
} |
533 |
return parseInt(el.style.zIndex); |
534 |
} |
535 |
return 0; |
536 |
} |
537 |
|
538 |
function iwfMoveTo(id1, xDest, yDest, totalTicks, motionType){ |
539 |
|
540 |
var el = iwfGetById(id1); |
541 |
|
542 |
if (el){ |
543 |
var origX = iwfX1(el); |
544 |
var origY = iwfY1(el); |
545 |
|
546 |
// wipeout any other repositioning timeouts we have... |
547 |
_iwfClearTimeout(el, "moveto", "position", true); |
548 |
|
549 |
// move any elements we have docked to us |
550 |
_iwfMoveDockedItems(el, xDest, yDest, totalTicks, motionType); |
551 |
|
552 |
if (!totalTicks){ |
553 |
// do it immediately. |
554 |
iwfX1(id1, xDest); |
555 |
iwfY1(id1, yDest); |
556 |
} else { |
557 |
// animate the movement |
558 |
_iwfMoveTo(id1, origX, origY, xDest, yDest, totalTicks, totalTicks, motionType); |
559 |
} |
560 |
} |
561 |
|
562 |
} |
563 |
|
564 |
function _iwfMoveDockedItems(id, xDest, yDest, totalTicks, motionType){ |
565 |
var elMaster = iwfGetById(id); |
566 |
if (elMaster){ |
567 |
var dockers = iwfAttribute(elMaster, 'iwfDockers'); |
568 |
//iwfLog("Dockers for " + iwfAttribute(elMaster, 'id') + ":\n" + dockers, true); |
569 |
if (dockers && dockers.length > 0){ |
570 |
// there is one or more items docked to us |
571 |
// tell them to move with us! |
572 |
dockers = dockers.split(","); |
573 |
for(var i=0;i<dockers.length;i++){ |
574 |
var elSlave = iwfGetById(dockers[i]); |
575 |
if (elSlave){ |
576 |
//iwfLog("found element '" + dockers[i] + "' which is docked to element " + iwfAttribute(elMaster, 'id'), true); |
577 |
var xOffset = iwfX(elMaster) - iwfX(elSlave); |
578 |
var yOffset = iwfY(elMaster) - iwfY(elSlave); |
579 |
var xEnd = xDest - xOffset; |
580 |
var yEnd = yDest - yOffset; |
581 |
iwfMoveTo(elSlave, xEnd, yEnd, totalTicks, motionType); |
582 |
} |
583 |
} |
584 |
} |
585 |
} |
586 |
} |
587 |
|
588 |
function _iwfMoveTo(id1, xOrig, yOrig, xDest, yDest, ticksLeft, totalTicks, motionType){ |
589 |
//iwfLog("_iwfMoveTo(" + id1 + ", " + xOrig + ", " + yOrig + ", " + xDest + ", " + yDest + ", " + ticksLeft + ", " + totalTicks + ", '" + motionType + "')"); |
590 |
var el = iwfGetById(id1); |
591 |
if (!el){ |
592 |
//iwfLog("could not locate el with id of " + id1); |
593 |
} else { |
594 |
el_id = iwfAttribute(el, 'id'); |
595 |
|
596 |
_iwfClearTimeout(el, "moveto", "position", true); |
597 |
|
598 |
|
599 |
var elX = iwfX1(el); |
600 |
var elY = iwfY1(el); |
601 |
|
602 |
// hack for floating point anomolies -- stops animation when element is "close enough" |
603 |
var epsilon = 0.001; |
604 |
|
605 |
var xDone = false; |
606 |
if (elX > xDest){ |
607 |
if (xDest + epsilon > elX){ |
608 |
xDone = true; |
609 |
} |
610 |
} else { |
611 |
if (xDest - epsilon < elX){ |
612 |
xDone = true; |
613 |
} |
614 |
} |
615 |
|
616 |
var yDone = false; |
617 |
if (elY > yDest){ |
618 |
if (yDest + epsilon > elY){ |
619 |
yDone = true; |
620 |
} |
621 |
} else { |
622 |
if (yDest - epsilon < elY){ |
623 |
yDone = true; |
624 |
} |
625 |
} |
626 |
|
627 |
if (ticksLeft <= 0 || (xDone && yDone)){ |
628 |
// time is up. / motion is done |
629 |
//iwfLog("_iwfMoveTo time is up / motion is done."); |
630 |
iwfX1(el, xDest); |
631 |
iwfY1(el, yDest); |
632 |
|
633 |
} else { |
634 |
|
635 |
var pctLeft = ticksLeft / totalTicks; |
636 |
|
637 |
var xTotal = xDest - xOrig; |
638 |
var yTotal = yDest - yOrig; |
639 |
|
640 |
var xCur, yCur, rt; |
641 |
|
642 |
switch(motionType){ |
643 |
case 'd': |
644 |
case 'dec': |
645 |
default: |
646 |
rt = pctLeft * pctLeft * pctLeft * pctLeft * pctLeft * pctLeft; |
647 |
xCur = xOrig + (xTotal - (rt * xTotal)); |
648 |
yCur = yOrig + (yTotal - (rt * yTotal)); |
649 |
break; |
650 |
case 'a': |
651 |
case 'acc': |
652 |
pctLeft = 1 - pctLeft; |
653 |
rt = pctLeft * pctLeft * pctLeft * pctLeft; |
654 |
xCur = xOrig + (rt * xTotal); |
655 |
yCur = yOrig + (rt * yTotal); |
656 |
break; |
657 |
case 'b': |
658 |
case 'both': |
659 |
if (pctDone > 0.75){ |
660 |
// over 3/4 done -- decelerate |
661 |
rt = pctLeft * pctLeft * pctLeft * pctLeft; |
662 |
xCur = xOrig + (xTotal - (rt * xTotal)); |
663 |
yCur = yOrig + (yTotal - (rt * yTotal)); |
664 |
|
665 |
} else if (pctDone < 0.25){ |
666 |
// not 1/4 done yet -- accelerate |
667 |
pctLeft = 1 - pctLeft; |
668 |
rt = pctLeft * pctLeft * pctLeft * pctLeft; // * pctDone * pctDone; |
669 |
xCur = xOrig + (rt * xTotal); |
670 |
yCur = yOrig + (rt * yTotal); |
671 |
|
672 |
} else { |
673 |
// between 1/4 and 3/5 done -- linear |
674 |
xCur = xOrig + (pctLeft * xTotal); |
675 |
yCur = yOrig + (pctLeft * yTotal); |
676 |
} |
677 |
break; |
678 |
case 'lin': |
679 |
case 'linear': |
680 |
case 'l': |
681 |
// use linear motion |
682 |
xCur = xOrig + (pctLeft * xTotal); |
683 |
yCur = yOrig + (pctLeft * yTotal); |
684 |
break; |
685 |
} |
686 |
|
687 |
iwfX1(el, xCur); |
688 |
iwfY1(el, yCur); |
689 |
|
690 |
|
691 |
ticksLeft--; |
692 |
|
693 |
var fn = "_iwfMoveTo('" + el_id + "', " + xOrig + ", " + yOrig + ", " + xDest + ", " + yDest + ", " + ticksLeft + ", " + totalTicks + ", '" + motionType + "')"; |
694 |
//iwfLog("timeout set to call: " + fn); |
695 |
_iwfSetTimeout(el, "moveto", "position", fn, 50); |
696 |
} |
697 |
} |
698 |
} |
699 |
|
700 |
function iwfUnDockFrom(id1, id2){ |
701 |
var elSlave = iwfGetById(id1); |
702 |
|
703 |
if (elSlave){ |
704 |
var slaveId = iwfAttribute(elSlave, 'id'); |
705 |
// determine who elSlave is docked to |
706 |
var dockedTo = iwfAttribute(elSlave, 'iwfDockedTo'); |
707 |
if (dockedTo){ |
708 |
// elSlave says he's docked to the guy with id of dockedTo. |
709 |
// grab that guy. |
710 |
var elMaster = iwfGetById(dockedTo); |
711 |
//iwfLog("dockedTo:" + iwfAttribute(elMaster, 'id'), true); |
712 |
if (elMaster){ |
713 |
// elMaster is the guy elSlave is docked to. |
714 |
// tell elMaster to remove elSlave from his docker list |
715 |
|
716 |
var dockers = iwfAttribute(elMaster, 'iwfDockers'); |
717 |
//iwfLog("undocking items from " + iwfAttribute(elMaster, 'id') + ":\n" + dockers, true); |
718 |
if (dockers && dockers.length > 0){ |
719 |
var arrDockers = dockers.split(","); |
720 |
if (arrDockers.length == 0){ |
721 |
arrDockers.push(dockers); |
722 |
} |
723 |
//iwfLog('arrDockers=' + arrDockers + '\nlength=' + arrDockers.length, true); |
724 |
for(var i=0;i<arrDockers.length;i++){ |
725 |
//iwfLog("undocking is checking " + arrDockers[i] + " against " + slaveId, true); |
726 |
if (arrDockers[i] == slaveId){ |
727 |
// undock elSlave from elMaster |
728 |
arrDockers.splice(i, 1); |
729 |
|
730 |
var output = arrDockers.join(","); |
731 |
//iwfLog("writing iwfDockers=" + output); |
732 |
|
733 |
// write this back to elMaster |
734 |
iwfAttribute(elMaster, 'iwfDockers', output); |
735 |
break; |
736 |
} |
737 |
} |
738 |
} |
739 |
} |
740 |
// tell elSlave he's no longer docked to elMaster. |
741 |
iwfAttribute(elSlave, 'iwfDockedTo', null); |
742 |
} |
743 |
} |
744 |
} |
745 |
|
746 |
function iwfAlignTo(id1, id2, anchor1, anchor2, totalTicks, motionType){ |
747 |
var elMover = iwfGetById(id1); |
748 |
var elStays = iwfGetById(id2); |
749 |
|
750 |
if (elMover && elStays){ |
751 |
|
752 |
var newX = iwfX(elStays); |
753 |
var newY = iwfY(elStays); |
754 |
|
755 |
var anc = ((anchor1 +' ').substr(0,2) + (anchor2 + ' ').substr(0,2)).toLowerCase(); |
756 |
iwfLog("anchor encoding: " + anc); |
757 |
if (anc.charAt(0) == 'b'){ |
758 |
newY -= iwfHeight(elMover); |
759 |
} else if (anc.charAt(0) == 'c'){ |
760 |
newY -= iwfHeight(elMover) / 2; |
761 |
} |
762 |
|
763 |
var moverWidth; |
764 |
var staysWidth; |
765 |
if (anc.charAt(1) == 'r'){ |
766 |
moverWidth = iwfWidth(elMover); |
767 |
newX -= moverWidth; |
768 |
} else if (anc.charAt(1) == 'c'){ |
769 |
moverWidth = iwfWidth(elMover); |
770 |
newX -= moverWidth / 2; |
771 |
} |
772 |
if (anc.charAt(2) == 'b'){ |
773 |
newY += iwfHeight(elStays); |
774 |
} else if (anc.charAt(2) == 'c'){ |
775 |
newY += iwfHeight(elStays) / 2; |
776 |
} |
777 |
if (anc.charAt(3) == 'r'){ |
778 |
staysWidth = iwfWidth(elStays); |
779 |
newX += staysWidth; |
780 |
} else if (anc.charAt(3) == 'c'){ |
781 |
staysWidth = iwfWidth(elStays); |
782 |
newX += staysWidth / 2; |
783 |
} |
784 |
|
785 |
iwfLog(iwfAttribute(elMover, 'id') + ' width:' + moverWidth + '\n' + iwfAttribute(elStays, 'id') + ' width:' + staysWidth); |
786 |
|
787 |
// move to those alignment points |
788 |
iwfMoveTo(elMover, newX, newY, totalTicks, totalTicks, motionType); |
789 |
} |
790 |
} |
791 |
|
792 |
function iwfDockTo(id1, id2, anchor1, anchor2, totalTicks, motionType){ |
793 |
var elSlave = iwfGetById(id1); |
794 |
var elMaster = iwfGetById(id2); |
795 |
|
796 |
if (elSlave && elMaster){ |
797 |
|
798 |
// dock elSlave to elMaster... |
799 |
|
800 |
// pull all items currently docked to elMaster |
801 |
var dockers = iwfAttribute(elMaster,'iwfDockers'); |
802 |
// append elSlave to that list |
803 |
if(!dockers){ |
804 |
dockers = iwfAttribute(elSlave, 'id'); |
805 |
} else { |
806 |
var arrDockers = dockers.split(","); |
807 |
if (arrDockers.length == 0){ |
808 |
arrDockers = new Array(dockers); |
809 |
} |
810 |
|
811 |
var slaveId = iwfAttribute(elSlave, 'id'); |
812 |
var found = false; |
813 |
for(var i=0;i<arrDockers.length;i++){ |
814 |
if (arrDockers[i] == slaveId){ |
815 |
found = true; |
816 |
} |
817 |
} |
818 |
if (!found){ |
819 |
// elSlave is not in elMaster's list of dockers yet. add him. |
820 |
dockers += "," + iwfAttribute(elSlave, 'id'); |
821 |
} |
822 |
} |
823 |
|
824 |
// write list back to elMaster |
825 |
iwfAttribute(elMaster, 'iwfDockers', dockers); |
826 |
|
827 |
// have elSlave remember who he's docked to |
828 |
iwfAttribute(elSlave, 'iwfDockedTo', iwfAttribute(elMaster, 'id')); |
829 |
|
830 |
|
831 |
//iwfLog("dockers for " + iwfAttribute(elMaster, 'id') + " = " + dockers, true); |
832 |
|
833 |
|
834 |
iwfAlignTo(elSlave, elMaster, anchor1, anchor2, totalTicks, motionType); |
835 |
|
836 |
} |
837 |
|
838 |
|
839 |
} |
840 |
|
841 |
function iwfXScroll(id) { |
842 |
var scrollx=0; |
843 |
var el = iwfGetById(id); |
844 |
if (!el){ |
845 |
if(document.documentElement && document.documentElement.scrollLeft) scrollx=document.documentElement.scrollLeft; |
846 |
else if(document.body && iwfExists(document.body.scrollLeft)) scrollx=document.body.scrollLeft; |
847 |
} else { |
848 |
if (iwfIsNumber(el.scrollLeft)) scrollx = el.scrollLeft; |
849 |
} |
850 |
return scrollx; |
851 |
} |
852 |
function iwfYScroll(id) { |
853 |
var scrolly=0; |
854 |
var el = iwfGetById(id); |
855 |
if (!el){ |
856 |
if(document.documentElement && document.documentElement.scrollTop) scrolly=document.documentElement.scrollTop; |
857 |
else if(document.body && iwfExists(document.body.scrollTop)) scrolly=document.body.scrollTop; |
858 |
} else { |
859 |
if (iwfIsNumber(el.scrollTop)) scrolly = el.scrollTop; |
860 |
} |
861 |
return scrolly; |
862 |
} |
863 |
|
864 |
|
865 |
|
866 |
// ----------------------------------- |
867 |
// End: Positioning |
868 |
// ----------------------------------- |
869 |
|
870 |
// ----------------------------------- |
871 |
// Begin: Size |
872 |
// ----------------------------------- |
873 |
|
874 |
function iwfWidth(id, neww){ |
875 |
|
876 |
|
877 |
|
878 |
var el = iwfGetById(id); |
879 |
if (!el) return 0; |
880 |
var w = 0; |
881 |
if (iwfExists(el)){ |
882 |
if (iwfExists(el.style)){ |
883 |
if (iwfExists(el.offsetWidth) && iwfIsString(el.style.width)){ |
884 |
if (neww) iwfDetermineWidth(el, neww); |
885 |
w = el.offsetWidth; |
886 |
} else if (iwfExists(el.style.pixelWidth)) { |
887 |
if(neww) el.style.pixelWidth = neww; |
888 |
w = el.style.pixelWidth; |
889 |
} else { |
890 |
w = -1; |
891 |
} |
892 |
} else if (iwfExists(el.clip) && iwfExists(el.clip.right)) { |
893 |
if(newh) e.clip.right = neww; |
894 |
w = el.clip.right; |
895 |
} else { |
896 |
w = -2; |
897 |
} |
898 |
|
899 |
//iwfLog('width of ' + iwfAttribute(el, 'id') + ' = ' + w, true); |
900 |
|
901 |
} |
902 |
|
903 |
return w; |
904 |
|
905 |
|
906 |
|
907 |
// var el = iwfGetById(id); |
908 |
// var w = 0; |
909 |
// if (iwfExists(el)){ |
910 |
// if(iwfExists(el.style, el.offsetWidth) && iwfIsString(el.style.width)) { |
911 |
// if(neww) iwfDetermineWidth(el, neww); |
912 |
// w = el.offsetWidth; |
913 |
// } |
914 |
// else if(iwfExists(el.style) && iwfExists(el.style.pixelWidth)) { |
915 |
// if(neww) el.style.pixelWidth = neww; |
916 |
// w = el.style.pixelWidth; |
917 |
// } |
918 |
// else if(iwfExists(el.clip) && iwfExists(el.clip.right)) { |
919 |
// if(neww) e.clip.right = neww; |
920 |
// w = el.clip.right; |
921 |
// } |
922 |
// } |
923 |
// return w; |
924 |
} |
925 |
|
926 |
function iwfHeight(id, newh){ |
927 |
var el = iwfGetById(id); |
928 |
if (!el) return 0; |
929 |
var h = 0; |
930 |
if (iwfExists(el)){ |
931 |
if (iwfExists(el.style)){ |
932 |
if (iwfExists(el.offsetHeight) && iwfIsString(el.style.height)){ |
933 |
if (newh) iwfDetermineHeight(el, newh); |
934 |
h = el.offsetHeight; |
935 |
} else if (iwfExists(el.style.pixelHeight)) { |
936 |
if(newh) el.style.pixelHeight = newh; |
937 |
h = el.style.pixelHeight; |
938 |
} else { |
939 |
h = -1; |
940 |
} |
941 |
} else if (iwfExists(el.clip) && iwfExists(el.clip.bottom)) { |
942 |
if(newh) e.clip.bottom = newh; |
943 |
h = el.clip.bottom; |
944 |
} else { |
945 |
h = -2; |
946 |
} |
947 |
} |
948 |
return h; |
949 |
} |
950 |
|
951 |
function iwfY2(id, y2){ |
952 |
var el = iwfGetById(id); |
953 |
if (iwfExists(el)) { |
954 |
var y1 = iwfY(el); |
955 |
if (iwfExists(y2)){ |
956 |
var h = iwfHeight(el); |
957 |
iwfHeight(el, y1 + h); |
958 |
} |
959 |
return y1 + iwfHeight(el); |
960 |
} |
961 |
return 0; |
962 |
} |
963 |
|
964 |
function iwfX2(id, x2){ |
965 |
var el = iwfGetById(id); |
966 |
if (iwfExists(el)) { |
967 |
var x1 = iwfX(id); |
968 |
if (iwfExists(x2)){ |
969 |
var w = iwfWidth(id); |
970 |
iwfWidth(id, x1 + h); |
971 |
} |
972 |
return x1 + iwfWidth(el); |
973 |
} |
974 |
return 0; |
975 |
} |
976 |
|
977 |
function iwfDetermineStyle(el,prop){ |
978 |
return parseInt(document.defaultView.getComputedStyle(el,'').getPropertyValue(prop),10); |
979 |
} |
980 |
function iwfDetermineWidth(el,neww){ |
981 |
var padl=0, padr=0, bdrl=0, bdrr=0; |
982 |
if (iwfExists(document.defaultView) && iwfExists(document.defaultView.getComputedStyle)){ |
983 |
padl = iwfDetermineStyle(el,'padding-left'); |
984 |
padr = iwfDetermineStyle(el,'padding-right'); |
985 |
bdrl = iwfDetermineStyle(el,'border-left-width'); |
986 |
bdrr = iwfDetermineStyle(el,'border-right-width'); |
987 |
|
988 |
} else if(iwfExists(el.currentStyle,document.compatMode)){ |
989 |
if(document.compatMode=='CSS1Compat'){ |
990 |
padl = parseInt(el.currentStyle.paddingLeft); |
991 |
padr = parseInt(el.currentStyle.paddingRight); |
992 |
bdrl = parseInt(el.currentStyle.borderLeftWidth); |
993 |
bdrr = parseInt(el.currentStyle.borderRightWidth); |
994 |
} |
995 |
} else if(iwfExists(el.offsetWidth,el.style.width)){ |
996 |
el.style.width = neww + 'px'; |
997 |
padl=el.offsetWidth - neww; |
998 |
} |
999 |
|
1000 |
if(isNaN(padl)) padl=0; |
1001 |
if(isNaN(padr)) padr=0; |
1002 |
if(isNaN(bdrl)) bdrl=0; |
1003 |
if(isNaN(bdrr)) bdrr=0; |
1004 |
|
1005 |
var w2 = neww - padl - padr - bdrl - bdrr; |
1006 |
if (isNaN(w2) || w2 < 0) return; |
1007 |
else el.style.width = w2 + 'px'; |
1008 |
} |
1009 |
|
1010 |
function iwfDetermineHeight(el,newh){ |
1011 |
var padt=0, padb=0, bdrt=0, bdrb=0; |
1012 |
if(iwfExists(document.defaultView) && iwfExists(document.defaultView.getComputedStyle)){ |
1013 |
padt = iwfDetermineStyle(el,'padding-top'); |
1014 |
padb = iwfDetermineStyle(el,'padding-bottom'); |
1015 |
badt = iwfDetermineStyle(el,'border-top-height'); |
1016 |
badb = iwfDetermineStyle(el,'border-bottom-height'); |
1017 |
} else if(iwfExists(el.currentStyle,document.compatMode)){ |
1018 |
if(document.compatMode=='CSS1Compat'){ |
1019 |
padt = parseInt(el.currentStyle.paddingTop); |
1020 |
padb = parseInt(el.currentStyle.paddingBottom); |
1021 |
bdrt = parseInt(el.currentStyle.borderTopHeight); |
1022 |
bdrb = parseInt(el.currentStyle.borderBottomHeight); |
1023 |
} |
1024 |
} else if(iwfExists(el.offsetHeight, el.style.height)){ |
1025 |
el.style.height = newh + 'px'; |
1026 |
padt = el.offsetHeight - newh; |
1027 |
} |
1028 |
|
1029 |
if(isNaN(padt)) padt=0; |
1030 |
if(isNaN(padb)) padb=0; |
1031 |
if(isNaN(bdrt)) bdrt=0; |
1032 |
if(isNaN(bdrb)) bdrb=0; |
1033 |
|
1034 |
var h2 = newh - padt - padb - bdrt - bdrb; |
1035 |
|
1036 |
if(isNaN(h2) || h2 < 0) return; |
1037 |
else el.style.height = h2 + 'px'; |
1038 |
} |
1039 |
|
1040 |
|
1041 |
// ----------------------------------- |
1042 |
// End: Size |
1043 |
// ----------------------------------- |
1044 |
|
1045 |
// ----------------------------------- |
1046 |
// Begin: Event |
1047 |
// ----------------------------------- |
1048 |
|
1049 |
function iwfAddEvent(id,eventName,callback) { |
1050 |
var el = iwfGetById(id); |
1051 |
if (!el) return; |
1052 |
if (el.attachEvent) { |
1053 |
el.attachEvent(eventName, callback); |
1054 |
} else { |
1055 |
el[eventName] = callback; |
1056 |
} |
1057 |
} |
1058 |
|
1059 |
function iwfRemoveEvent(id, eventName, callback){ |
1060 |
var el = iwfGetById(id); |
1061 |
if (!el) return; |
1062 |
if (el.detachEvent) el.detachEvent(eventName, callback); |
1063 |
else eval('el.' + eventName + ' = null;'); |
1064 |
} |
1065 |
|
1066 |
function iwfEvent(ev) { |
1067 |
this.keyCode = 0; |
1068 |
this.target = null; |
1069 |
this.type = ''; |
1070 |
this.X = 0; |
1071 |
this.Y = 0; |
1072 |
var evt = ev || window.event; |
1073 |
if(!evt) return; |
1074 |
|
1075 |
if(evt.type) this.type = evt.type; |
1076 |
if(evt.target) this.target = evt.target; |
1077 |
else if(evt.srcElement) this.target = evt.srcElement; |
1078 |
|
1079 |
if(iwfExists(evt.clientX,evt.clientY)) { |
1080 |
this.X = evt.clientX + iwfXScroll(); |
1081 |
this.Y = evt.clientY + iwfYScroll(); |
1082 |
} else if (iwfExists(evt.offsetX, evt.offsetY)){ |
1083 |
this.X = evt.offsetX; |
1084 |
this.Y = evt.offsetY; |
1085 |
} |
1086 |
|
1087 |
if (evt.keyCode) { this.keyCode = evt.keyCode; } |
1088 |
else if (iwfExists(evt.which)) { this.keyCode = evt.which; } |
1089 |
|
1090 |
return this; |
1091 |
} |
1092 |
|
1093 |
// ----------------------------------- |
1094 |
// End: Event |
1095 |
// ----------------------------------- |
1096 |
|
1097 |
|
1098 |
// ----------------------------------- |
1099 |
// Begin: Image |
1100 |
// ----------------------------------- |
1101 |
function iwfRollover(id, overurl){ |
1102 |
var el = iwfGetById(id); |
1103 |
if (!el) return; |
1104 |
var rollover = null; |
1105 |
if (overurl){ |
1106 |
rollover = overurl; |
1107 |
} else { |
1108 |
iwfAttribute(el, "rolloversrc"); |
1109 |
} |
1110 |
if (!rollover) return; |
1111 |
el.iwfOrigSrc = el.src; |
1112 |
el.iwfRolloverImg = new Image(); |
1113 |
el.iwfRolloverImg.src = rollover; |
1114 |
iwfAddEvent(el, 'onmouseover', iwfDoRollover); |
1115 |
iwfAddEvent(el, 'onmouseout', iwfDoRollover); |
1116 |
} |
1117 |
|
1118 |
function iwfDoRollover(ev){ |
1119 |
var evt = new iwfEvent(ev); |
1120 |
var el = evt.target; |
1121 |
if (el.src == el.iwfOrigSrc){ |
1122 |
iwfSwapImage(el, el.iwfRolloverImg); |
1123 |
} else { |
1124 |
iwfSwapImage(el, el.iwfOrigSrc); |
1125 |
} |
1126 |
} |
1127 |
|
1128 |
function iwfPreloadImage(id, newimg){ |
1129 |
var el = iwfGetById(id); |
1130 |
if (!el) return; |
1131 |
/* todo: preload images here */ |
1132 |
} |
1133 |
|
1134 |
function iwfSwapImage(id, newimg){ |
1135 |
var el = iwfGetById(id); |
1136 |
if (!el) return; |
1137 |
if (iwfIsString(newimg)){ |
1138 |
el.src = newimg; |
1139 |
} else { |
1140 |
el.src = newimg.src; |
1141 |
} |
1142 |
} |
1143 |
|
1144 |
// preload images and attach event handlers for rollovers |
1145 |
function iwfMapRollovers(){ |
1146 |
var nodes = iwfGetByTagName('img'); |
1147 |
for(var i=0;i<nodes.length;i++){ |
1148 |
iwfRollover(nodes[i]); |
1149 |
} |
1150 |
} |
1151 |
|
1152 |
// ----------------------------------- |
1153 |
// End: Image |
1154 |
// ----------------------------------- |
1155 |
|
1156 |
|
1157 |
// ----------------------------------- |
1158 |
// Begin: Drag-N-Drop |
1159 |
// ----------------------------------- |
1160 |
|
1161 |
var iwfDragger = {el:null, inUse:false}; |
1162 |
var iwfHiZ = 2; |
1163 |
|
1164 |
function iwfEnableDrag(id, startCallback, dragCallback, endCallback) { |
1165 |
var el = iwfGetById(id); |
1166 |
if (!el) return; |
1167 |
el.iwfDraggable = true; |
1168 |
el.iwfOnDragStart = startCallback; |
1169 |
el.iwfOnDrag = dragCallback; |
1170 |
el.iwfOnDragEnd = endCallback; |
1171 |
iwfAddEvent(el, 'onmousedown', iwfDragMouseDown); |
1172 |
if (!iwfDragger.inUse) { |
1173 |
iwfDragger.inUse = true; |
1174 |
iwfAddEvent(document, 'onmousemove', iwfDragMouseMove); |
1175 |
} |
1176 |
} |
1177 |
function iwfDragMouseDown(ev){ |
1178 |
var evt = new iwfEvent(ev); |
1179 |
var el = evt.target; |
1180 |
while(el && !el.iwfDraggable) { |
1181 |
el = iwfParent(el); |
1182 |
} |
1183 |
if (el) { |
1184 |
if (ev && ev.preventDefault) ev.preventDefault(); |
1185 |
else if (window.event) window.event.returnValue = false; |
1186 |
el.iwfDragX = evt.X; |
1187 |
el.iwfDragY = evt.Y; |
1188 |
|
1189 |
iwfZIndex(el, iwfHiZ++); |
1190 |
|
1191 |
iwfDragger.el = el; |
1192 |
iwfAddEvent(document, 'onmouseup', iwfDragMouseUp, false); |
1193 |
if (el.iwfOnDragStart) { |
1194 |
el.iwfOnDragStart(el, evt.X, evt.Y); |
1195 |
} |
1196 |
} |
1197 |
} |
1198 |
|
1199 |
function iwfDragMouseMove(ev){ |
1200 |
var evt = new iwfEvent(ev); |
1201 |
if (iwfDragger.el) { |
1202 |
if (ev && ev.preventDefault) ev.preventDefault(); |
1203 |
else if (window.event) window.event.returnValue = false; |
1204 |
var el = iwfDragger.el; |
1205 |
var dx = evt.X - el.iwfDragX; |
1206 |
var dy = evt.Y - el.iwfDragY; |
1207 |
el.iwfDragX = evt.X; |
1208 |
el.iwfDragY = evt.Y; |
1209 |
|
1210 |
if (el.iwfOnDrag) { |
1211 |
el.iwfOnDrag(el, dx, dy); |
1212 |
} else { |
1213 |
iwfX(el, iwfX(el) + dx); |
1214 |
iwfY(el, iwfY(el) + dy); |
1215 |
} |
1216 |
} |
1217 |
} |
1218 |
function iwfDragMouseUp(ev) { |
1219 |
if (iwfDragger.el) { |
1220 |
if (ev && ev.preventDefault) ev.preventDefault(); |
1221 |
else if (window.event) window.event.returnValue = false; |
1222 |
iwfRemoveEvent(document, 'onmouseup', iwfDragMouseUp, false); |
1223 |
if (iwfDragger.el.iwfOnDragEnd) { |
1224 |
var evt = new iwfEvent(ev); |
1225 |
iwfDragger.el.iwfOnDragEnd(iwfDragger.el, evt.X, evt.Y); |
1226 |
} |
1227 |
iwfDragger.el = null; |
1228 |
} |
1229 |
} |
1230 |
|
1231 |
// ----------------------------------- |
1232 |
// End: Drag-N-Drop |
1233 |
// ----------------------------------- |
1234 |
|
1235 |
// ----------------------------------- |
1236 |
// Begin: Initializers |
1237 |
// ----------------------------------- |
1238 |
iwfMapRollovers(); |
1239 |
// ----------------------------------- |
1240 |
// End: Initializers |
1241 |
// ----------------------------------- |