/[webpac2]/branches/Sack/web/iwf/iwfgui.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /branches/Sack/web/iwf/iwfgui.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1310 - (hide annotations)
Mon Sep 21 19:04:14 2009 UTC (14 years, 8 months ago) by dpavlin
File MIME type: text/cpp
File size: 45285 byte(s)
branch for refactoring of WebPAC::Input::* modules for Sack

1 dpavlin 55 // --------------------------------------------------------------------------
2     /// IWF - Interactive Website Framework. Javascript library for creating
3     /// responsive thin client interfaces.
4     ///
5     /// Copyright (C) 2005 Brock Weaver brockweaver@users.sourceforge.net
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@users.sourceforge.net
23     /// 1605 NW Maple Pl
24     /// Ankeny, IA 50021
25     ///
26     //! http://iwf.sourceforge.net/
27     // --------------------------------------------------------------------------
28     //! NOTE: To minimize file size, strip all fluffy comments (except the LGPL, of course!)
29     //! using the following regex (global flag and multiline on):
30     //! ^\t*//([^/!].*|$)
31 dpavlin 46 //
32 dpavlin 55 // This reduces file size by about 30%, give or take.
33 dpavlin 46 //
34 dpavlin 55 //! To rip out only logging statements (commented or uncommented):
35     //! ^/{0,2}iwfLog.*
36     // --------------------------------------------------------------------------
37 dpavlin 46
38     // --------------------------------------------------------------------------
39 dpavlin 55 //! iwfgui.js
40 dpavlin 46 //
41     // GUI inspection and manipulation functions
42     //
43 dpavlin 55 //! Dependencies:
44     //! iwfcore.js
45 dpavlin 46 //
46 dpavlin 55 //! Brock Weaver - brockweaver@users.sourceforge.net
47     //! v 0.2 - 2005-11-14
48     //! core bug patch
49 dpavlin 46 // --------------------------------------------------------------------------
50 dpavlin 55 //! v 0.1 - 2005-06-05
51     //! Initial release.
52     // --------------------------------------------------------------------------
53 dpavlin 46 // Issues:
54     // Timeouts have hiccups sometimes when they begin to overlap
55 dpavlin 55 // Not tested on Safari -- I need a Mac!
56 dpavlin 46 // _iwfMoveTo() has some calculation problems with certain motionType values
57     // --------------------------------------------------------------------------
58    
59     // -----------------------------------
60     // Dependency Check
61     if (!window.iwfGetById){
62 dpavlin 55 iwfLog("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>", true);
63 dpavlin 46 }
64     // -----------------------------------
65    
66    
67    
68     // -----------------------------------
69     // Begin: Visibility
70     // -----------------------------------
71    
72     function iwfShow(id, reserveSpace){
73     var el = iwfGetById(id);
74     if (reserveSpace){
75     if (iwfExists(el) && iwfExists(el.style) && iwfExists(el.style.visibility)) el.style.visibility = 'visible';
76     } else {
77     if (iwfExists(el) && iwfExists(el.style) && iwfExists(el.style.display)) el.style.display = 'inline';
78     }
79     }
80    
81     function iwfHide(id, reserveSpace){
82     var el = iwfGetById(id);
83     if (reserveSpace){
84     if (el && iwfExists(el.style) && iwfExists(el.style.visibility)) el.style.visibility = 'hidden';
85     } else {
86     if (el && iwfExists(el.style) && iwfExists(el.style.display)) el.style.display = 'none';
87     }
88     }
89    
90     function iwfHideDelay(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, "hidedelay", "visible", true);
96    
97     if (ms < 1){
98     iwfHide(el, reserveSpace);
99     } else {
100     _iwfSetTimeout(el, "hidedelay", "visible", "iwfHideDelay('" + el.id + "', 0, " + reserveSpace + ")", ms);
101     }
102     }
103    
104     function iwfShowDelay(id, ms, reserveSpace){
105     var el = iwfGetById(id);
106     if (!el) return;
107    
108     // wipeout any other re-visibling timeouts we have (nice spelling, eh?)
109     _iwfClearTimeout(el, "showdelay", "visible", true);
110    
111     if (ms < 1){
112     iwfShow(el, reserveSpace);
113     } else {
114     _iwfSetTimeout(el, "showdelay", "visible", "iwfShowDelay('" + el.id + "', 0, " + reserveSpace + ")", ms);
115     }
116     }
117    
118     function iwfShowGently(id, pct, reserveSpace){
119    
120     var el = iwfGetById(id);
121     if (!el) return;
122    
123     // wipeout any other re-visibling timeouts we have (nice spelling, eh?)
124     _iwfClearTimeout(el, "showgently", "visible", true);
125    
126     var opacity = iwfOpacity(el);
127     if (iwfIsHidden(el)){
128     // set opacity to 0
129     iwfOpacity(el, 0, false, false);
130    
131     // show it
132     iwfShow(el, reserveSpace);
133     }
134    
135     // adjust opacity up by the given percentage
136     opacity = iwfOpacity(el, pct, true);
137    
138     if (opacity < 100) {
139     // set a timeout
140     _iwfSetTimeout(el, "showgently", "visible", "iwfShowGently('" + el.id + "'," + pct + ", " + reserveSpace + ")", 50);
141     }
142     }
143    
144     function iwfHideGently(id, pct, reserveSpace){
145     var el = iwfGetById(id);
146     if (!el) return;
147    
148     if (iwfIsHidden(el)) return;
149    
150     // wipeout any other re-visibling timeouts we have (nice spelling, eh?)
151     _iwfClearTimeout(el, "hidegently", "visible", true);
152    
153     var opacity = iwfOpacity(el);
154     if (opacity <= 0){
155    
156     // hide it
157     iwfHide(el, reserveSpace);
158    
159     // set opacity back to fully opaque, so when they iwfShow() it,
160     // the element isn't fully transparent and looks like iwfShow() didn't work
161     iwfOpacity(el, 100, false, true);
162    
163    
164     } else {
165     // make it less opaque...
166     iwfOpacity(el, -pct, true);
167    
168     // set our timeout
169     _iwfSetTimeout(el, "hidegently", "visible", "iwfHideGently('" + el.id + "'," + pct + ", " + reserveSpace + ")", 50);
170     }
171     }
172    
173     function iwfHideGentlyDelay(id, pct, ms, reserveSpace){
174     var el = iwfGetById(id);
175     if (!el) return;
176    
177     if (iwfIsHidden(el)) return;
178    
179     // wipeout any other re-visibling timeouts we have (nice spelling, eh?)
180     _iwfClearTimeout(el, "hidegentlydelay", "visible", true);
181    
182    
183     if (ms < 1){
184     iwfHideGently(el, pct, reserveSpace);
185     } else {
186     _iwfSetTimeout(el, "hidegentlydelay", "visible", "iwfHideGentlyDelay('" + el.id + "'," + pct + ", 0, " + reserveSpace + ")", ms);
187     }
188    
189     }
190    
191     function iwfShowGentlyDelay(id, pct, ms, reserveSpace){
192     var el = iwfGetById(id);
193     if (!el) return;
194    
195    
196     // wipeout any other re-visibling timeouts we have (nice spelling, eh?)
197     _iwfClearTimeout(el, "showgentlydelay", "visible", true);
198    
199     if (ms < 1){
200     iwfShowGently(el, pct, reserveSpace);
201     } else {
202     _iwfSetTimeout(el, "showgentlydelay", "visible", "iwfShowGentlyDelay('" + el.id + "'," + pct + ", 0, " + reserveSpace + ")", ms);
203     }
204     }
205    
206     function iwfOpacity(id, pct, relative, keepHiddenIfAlreadyHidden){
207     var el = iwfGetById(id);
208     if (el){
209     if (iwfExists(pct) && pct != null){
210     // set opacity
211     var newPct = iwfToFloat(pct, true);
212     if (relative){
213     // lookup current opacity
214     newPct = iwfOpacity(id, null, false);
215    
216     // modify pct by that much
217     newPct += pct;
218     }
219    
220     if (newPct < 0){
221     newPct = 0;
222     } else if (newPct > 100){
223     newPct = 100;
224     }
225    
226     if (iwfExists(el.style.opacity)) el.style.opacity = newPct/100;
227     else if (iwfExists(el.style.filter)) el.style.filter = "alpha(opacity=" + newPct + ")";
228     else if (iwfExists(el.style.mozOpacity)) el.style.mozOpacity = newPct/100;
229    
230     // also display it if opacity > 0 and !keepHidden
231     if (newPct > 0 && !keepHiddenIfAlreadyHidden){
232     if (iwfIsHidden(id)){
233     iwfShow(id);
234     }
235     }
236    
237     return newPct;
238    
239     } else {
240     // get current opacity
241     var val = null;
242     if (iwfExists(el.style.opacity)){
243     if (el.style.opacity == ''){
244     val = 100;
245     } else {
246     val = iwfToFloat(el.style.opacity, 2, true) * 100;
247     }
248     } else if (iwfExists(el.style.filter)) {
249     if (el.style.filter){
250     if (el.style.filter.indexOf("opacity") == 0){
251     val = 100;
252     } else {
253     val = iwfToFloat(el.style.filter, 2, true);
254     }
255     } else {
256     val = 100;
257     }
258     } else if (iwfExists(el.style.mozOpacity)) {
259     if (el.style.mozOpacity == ''){
260     val = 100;
261     } else {
262     val = iwfToFloat(el.style.mozOpacity, 2, true) * 100;
263     }
264     }
265    
266     return val;
267     }
268     }
269     }
270    
271     function iwfIsShown(id){
272     return !iwfIsHidden(id);
273     }
274    
275     function iwfIsHidden(id){
276     var el = iwfGetById(id);
277     // if (!el) return false;
278    
279     var hidden = false;
280     if (iwfExists(el.style) && iwfExists(el.style.visibility)) {
281     hidden = el.style.visibility == 'hidden';
282     }
283     if (iwfExists(el.style) && iwfExists(el.style.display)) {
284     hidden = hidden || el.style.display == 'none';
285     }
286     return hidden;
287     }
288    
289     function iwfToggle(id, reserveSpace){
290     if (iwfIsHidden(id)) iwfShow(id, reserveSpace);
291     else iwfHide(id, reserveSpace);
292     }
293    
294    
295    
296     // -----------------------------------
297     // End: Visibility
298     // -----------------------------------
299    
300     // -----------------------------------
301     // Begin: Timers
302     // -----------------------------------
303    
304     function _iwfSetTimeout(id, name, category, fn, ms){
305     var el = iwfGetById(id);
306     if (!el) return;
307    
308     var att = iwfAttribute(el, 'iwfTimeoutCategory' + category);
309     if (!att){
310     // that attribute doesn't exist yet, or is null
311     } else if (att != name){
312     // attribute exists but doesn't match our name.
313     // clear out the existing one, since the category matches.
314     _iwfClearTimeout(el.id, att, category);
315     } else {
316     // attribute matches our name.
317     }
318    
319     iwfAttribute(el, 'iwfTimeoutCategory' + category, name);
320     //iwfLog('setting timeout for ' + name + ' to ' + fn);
321     var timeoutid = setTimeout(fn, ms);
322     iwfAttribute(el, 'iwfTimeoutId' + category, timeoutid);
323     return true;
324     }
325    
326     function _iwfCheckTimeout(id, name, category){
327     //return true;
328    
329     var el = iwfGetById(id);
330     if (!el) return false;
331    
332     var att = iwfAttribute(el, 'iwfTimeoutCategory' + category);
333     if (!att || att == name){
334     return true;
335     } else {
336     return false;
337     }
338    
339     }
340    
341     function _iwfClearTimeout(id, name, category, forceful){
342     var el = iwfGetById(id);
343     if (!el) return;
344    
345     var att = iwfAttribute(el, 'iwfTimeoutCategory' + category);
346    
347     if (att == name || forceful){
348     // iwfLog('clearing timeout for ' + att);
349     clearTimeout(iwfAttribute(el, 'iwfTimeoutId' + category));
350     iwfRemoveAttribute(el, 'iwfTimeoutId' + category);
351     iwfRemoveAttribute(el, 'iwfTimeoutCategory' + category);
352     }
353    
354     }
355    
356     function iwfDelay(ms, fpOrString){
357 dpavlin 55 // note this inner function creates a closure...
358 dpavlin 46 function _iwfDelayExpired(){
359     if (localIsString){
360     // passed a string. eval it.
361 dpavlin 55 //iwfLog("_iwfDelayExpired: calling string of:\n" + localFpOrString, true);
362 dpavlin 46 eval(localFpOrString);
363     } else {
364     // they passed a function pointer.
365     // call it, passing any args we were given.
366     if (!localArgs || localArgs.length == 0){
367     localFpOrString();
368     } else if (localArgs.length == 1){
369     localFpOrString(localArgs[0]);
370     } else {
371     var s = 'localFpOrString(';
372     for(var i=0;i<localArgs.length;i++){
373     if (i > 0){
374     s += ', ';
375     }
376     if(localArgs[i] == null){
377     s += 'null';
378     } else if(iwfIsString(localArgs[i])){
379     s += '"' + localArgs[i].replace(/"/gi, '\\"') + '"';
380     } else {
381     s += localArgs[i];
382     }
383     }
384     s += ')';
385     //iwfLog("_iwfDelayExpired: calling fp of:\n" + s, true);
386     eval(s);
387     }
388     }
389     delete localFpOrString;
390     delete localIsString;
391     delete localArgs;
392     }
393    
394     var localFpOrString = fpOrString;
395     var localIsString = iwfIsString(fpOrString);
396     var localArgs = null;
397    
398     if (!iwfIsString(fpOrString)){
399     if (arguments && arguments.length > 0){
400     localArgs = new Array();
401     for(var i=2;i<arguments.length;i++){
402     //iwfLog('args[' + i + '] = ' + arguments[i], true);
403     localArgs.push(arguments[i]);
404     }
405     }
406     }
407     setTimeout(_iwfDelayExpired, ms);
408     }
409    
410     // -----------------------------------
411     // End: Timers
412     // -----------------------------------
413    
414    
415     // -----------------------------------
416     // Begin: Positioning
417     // -----------------------------------
418    
419     function iwfX1(id, newx){
420     return iwfX(id, newx);
421     }
422    
423    
424     function iwfFocusSelect(id, promptmsg){
425     var el = iwfGetById(id);
426     if (promptmsg){
427     alert(promptmsg);
428     }
429     if (!iwfIsHidden(id)){
430     try {
431     el.focus();
432     el.select();
433     } catch(e) { }
434     }
435     return false;
436     }
437    
438     function iwfFocus(id, promptmsg){
439     var el = iwfGetById(id);
440     if (promptmsg){
441     alert(promptmsg);
442     }
443     if (!iwfIsHidden(id)){
444     try {
445     el.focus();
446     } catch(e) { }
447     }
448     return false;
449     }
450    
451    
452    
453     function iwfX(id, newx){
454     var absx = 0;
455    
456     if (iwfIsNumber(newx)) {
457     absx = iwfSetX(id, newx);
458     } else {
459     var el = iwfGetById(id);
460     if (!el) return 0;
461     if (iwfIsString(el.style.left) && el.style.left.length > 0){
462     absx = iwfToInt(el.style.left, true);
463     if (isNaN(absx)) {
464     absx = 0;
465     }
466     } else if (iwfExists(el.style.pixelLeft) && el.style.pixelLeft) {
467     absx = el.style.pixelLeft;
468     } else {
469     while (el) {
470     if (iwfExists(el.offsetLeft)) absx += el.offsetLeft;
471     el = iwfGetParent(el, true);
472     }
473     }
474     }
475    
476     return absx;
477     }
478    
479     function iwfSetX(id, newx){
480     var el = iwfGetById(id);
481     if (!el) return;
482     if(iwfExists(el.style) && iwfIsString(el.style.left)) {
483     el.style.left = newx + 'px';
484     }
485     else if(iwfExists(el.style) && iwfExists(el.style.pixelLeft)) {
486     el.style.pixelLeft = newx;
487     }
488     else if(iwfExists(el.left)) {
489     el.left = newx;
490     }
491     return newx;
492     }
493    
494     function iwfY1(id, newy){
495     var el = iwfGetById(id);
496     return iwfY(el, newy);
497     }
498    
499     function iwfY(id, newy){
500     var absy = 0;
501    
502     if (iwfIsNumber(newy)) {
503     absy = iwfSetY(id, newy);
504     } else {
505     var el = iwfGetById(id);
506     if (!el) return 0;
507    
508     if (iwfIsString(el.style.top) && el.style.top.length > 0){
509     absy = iwfToInt(el.style.top, true);
510     if (isNaN(absy)) {
511     absy = 0;
512     }
513     } else if (iwfExists(el.style.pixelTop) && el.style.pixelTop) {
514     absy = el.style.pixelTop;
515     } else {
516     while (el) {
517     if (iwfExists(el.offsetTop)) absy += el.offsetTop;
518     el = iwfGetParent(el, true);
519     }
520     }
521     }
522    
523     return absy;
524     }
525    
526     function iwfSetY(id, newy){
527     var el = iwfGetById(id);
528     if (!el) return;
529     if (iwfExists(el.style)){
530     if (iwfIsString(el.style.top)) {
531     el.style.top = newy + 'px';
532     } else if(iwfExists(el.style.pixelTop)) {
533     el.style.pixelTop = newy;
534     } else if(iwfExists(el.top)) {
535     el.top = newy;
536     }
537     }
538     return newy;
539     }
540    
541     function iwfZIndex(id, z){
542     var el = iwfGetById(id);
543 dpavlin 55 if (!el) return 0;
544    
545 dpavlin 46 if (iwfExists(el)){
546     if (iwfExists(z)){
547     el.style.zIndex = z;
548     }
549 dpavlin 55 return iwfToInt(el.style.zIndex, true);
550 dpavlin 46 }
551     return 0;
552     }
553    
554     function iwfMoveTo(id1, xDest, yDest, totalTicks, motionType){
555    
556     var el = iwfGetById(id1);
557    
558     if (el){
559     var origX = iwfX1(el);
560     var origY = iwfY1(el);
561    
562     // wipeout any other repositioning timeouts we have...
563     _iwfClearTimeout(el, "moveto", "position", true);
564    
565     // move any elements we have docked to us
566     _iwfMoveDockedItems(el, xDest, yDest, totalTicks, motionType);
567    
568     if (!totalTicks){
569     // do it immediately.
570     iwfX1(id1, xDest);
571     iwfY1(id1, yDest);
572     } else {
573     // animate the movement
574     _iwfMoveTo(id1, origX, origY, xDest, yDest, totalTicks, totalTicks, motionType);
575     }
576     }
577    
578     }
579    
580     function _iwfMoveDockedItems(id, xDest, yDest, totalTicks, motionType){
581     var elMaster = iwfGetById(id);
582     if (elMaster){
583     var dockers = iwfAttribute(elMaster, 'iwfDockers');
584     //iwfLog("Dockers for " + iwfAttribute(elMaster, 'id') + ":\n" + dockers, true);
585     if (dockers && dockers.length > 0){
586     // there is one or more items docked to us
587     // tell them to move with us!
588     dockers = dockers.split(",");
589     for(var i=0;i<dockers.length;i++){
590     var elSlave = iwfGetById(dockers[i]);
591     if (elSlave){
592     //iwfLog("found element '" + dockers[i] + "' which is docked to element " + iwfAttribute(elMaster, 'id'), true);
593     var xOffset = iwfX(elMaster) - iwfX(elSlave);
594     var yOffset = iwfY(elMaster) - iwfY(elSlave);
595     var xEnd = xDest - xOffset;
596     var yEnd = yDest - yOffset;
597     iwfMoveTo(elSlave, xEnd, yEnd, totalTicks, motionType);
598     }
599     }
600     }
601     }
602     }
603    
604     function _iwfMoveTo(id1, xOrig, yOrig, xDest, yDest, ticksLeft, totalTicks, motionType){
605     //iwfLog("_iwfMoveTo(" + id1 + ", " + xOrig + ", " + yOrig + ", " + xDest + ", " + yDest + ", " + ticksLeft + ", " + totalTicks + ", '" + motionType + "')");
606     var el = iwfGetById(id1);
607     if (!el){
608     //iwfLog("could not locate el with id of " + id1);
609     } else {
610     el_id = iwfAttribute(el, 'id');
611    
612     _iwfClearTimeout(el, "moveto", "position", true);
613    
614    
615     var elX = iwfX1(el);
616     var elY = iwfY1(el);
617    
618 dpavlin 55 //! hack for floating point anomolies -- stops animation when element is "close enough"
619 dpavlin 46 var epsilon = 0.001;
620    
621     var xDone = false;
622     if (elX > xDest){
623     if (xDest + epsilon > elX){
624     xDone = true;
625     }
626     } else {
627     if (xDest - epsilon < elX){
628     xDone = true;
629     }
630     }
631    
632     var yDone = false;
633     if (elY > yDest){
634     if (yDest + epsilon > elY){
635     yDone = true;
636     }
637     } else {
638     if (yDest - epsilon < elY){
639     yDone = true;
640     }
641     }
642    
643     if (ticksLeft <= 0 || (xDone && yDone)){
644 dpavlin 55 //! time is up / motion is "close enough"
645 dpavlin 46 //iwfLog("_iwfMoveTo time is up / motion is done.");
646     iwfX1(el, xDest);
647     iwfY1(el, yDest);
648    
649     } else {
650    
651     var pctLeft = ticksLeft / totalTicks;
652    
653     var xTotal = xDest - xOrig;
654     var yTotal = yDest - yOrig;
655    
656     var xCur, yCur, rt;
657    
658     switch(motionType){
659     case 'd':
660     case 'dec':
661     default:
662     rt = pctLeft * pctLeft * pctLeft * pctLeft * pctLeft * pctLeft;
663     xCur = xOrig + (xTotal - (rt * xTotal));
664     yCur = yOrig + (yTotal - (rt * yTotal));
665     break;
666     case 'a':
667     case 'acc':
668     pctLeft = 1 - pctLeft;
669     rt = pctLeft * pctLeft * pctLeft * pctLeft;
670     xCur = xOrig + (rt * xTotal);
671     yCur = yOrig + (rt * yTotal);
672     break;
673     case 'b':
674     case 'both':
675     if (pctDone > 0.75){
676     // over 3/4 done -- decelerate
677     rt = pctLeft * pctLeft * pctLeft * pctLeft;
678     xCur = xOrig + (xTotal - (rt * xTotal));
679     yCur = yOrig + (yTotal - (rt * yTotal));
680    
681     } else if (pctDone < 0.25){
682     // not 1/4 done yet -- accelerate
683     pctLeft = 1 - pctLeft;
684     rt = pctLeft * pctLeft * pctLeft * pctLeft; // * pctDone * pctDone;
685     xCur = xOrig + (rt * xTotal);
686     yCur = yOrig + (rt * yTotal);
687    
688     } else {
689     // between 1/4 and 3/5 done -- linear
690     xCur = xOrig + (pctLeft * xTotal);
691     yCur = yOrig + (pctLeft * yTotal);
692     }
693     break;
694     case 'lin':
695     case 'linear':
696     case 'l':
697     // use linear motion
698     xCur = xOrig + (pctLeft * xTotal);
699     yCur = yOrig + (pctLeft * yTotal);
700     break;
701     }
702    
703     iwfX1(el, xCur);
704     iwfY1(el, yCur);
705    
706    
707     ticksLeft--;
708    
709     var fn = "_iwfMoveTo('" + el_id + "', " + xOrig + ", " + yOrig + ", " + xDest + ", " + yDest + ", " + ticksLeft + ", " + totalTicks + ", '" + motionType + "')";
710     //iwfLog("timeout set to call: " + fn);
711     _iwfSetTimeout(el, "moveto", "position", fn, 50);
712     }
713     }
714     }
715    
716     function iwfUnDockFrom(id1, id2){
717     var elSlave = iwfGetById(id1);
718    
719     if (elSlave){
720     var slaveId = iwfAttribute(elSlave, 'id');
721     // determine who elSlave is docked to
722     var dockedTo = iwfAttribute(elSlave, 'iwfDockedTo');
723     if (dockedTo){
724     // elSlave says he's docked to the guy with id of dockedTo.
725     // grab that guy.
726     var elMaster = iwfGetById(dockedTo);
727     //iwfLog("dockedTo:" + iwfAttribute(elMaster, 'id'), true);
728     if (elMaster){
729     // elMaster is the guy elSlave is docked to.
730     // tell elMaster to remove elSlave from his docker list
731    
732     var dockers = iwfAttribute(elMaster, 'iwfDockers');
733     //iwfLog("undocking items from " + iwfAttribute(elMaster, 'id') + ":\n" + dockers, true);
734     if (dockers && dockers.length > 0){
735     var arrDockers = dockers.split(",");
736     if (arrDockers.length == 0){
737     arrDockers.push(dockers);
738     }
739     //iwfLog('arrDockers=' + arrDockers + '\nlength=' + arrDockers.length, true);
740     for(var i=0;i<arrDockers.length;i++){
741     //iwfLog("undocking is checking " + arrDockers[i] + " against " + slaveId, true);
742     if (arrDockers[i] == slaveId){
743     // undock elSlave from elMaster
744     arrDockers.splice(i, 1);
745    
746     var output = arrDockers.join(",");
747     //iwfLog("writing iwfDockers=" + output);
748    
749     // write this back to elMaster
750     iwfAttribute(elMaster, 'iwfDockers', output);
751     break;
752     }
753     }
754     }
755     }
756     // tell elSlave he's no longer docked to elMaster.
757     iwfAttribute(elSlave, 'iwfDockedTo', null);
758     }
759     }
760     }
761    
762     function iwfAlignTo(id1, id2, anchor1, anchor2, totalTicks, motionType){
763     var elMover = iwfGetById(id1);
764     var elStays = iwfGetById(id2);
765    
766     if (elMover && elStays){
767    
768     var newX = iwfX(elStays);
769     var newY = iwfY(elStays);
770    
771     var anc = ((anchor1 +' ').substr(0,2) + (anchor2 + ' ').substr(0,2)).toLowerCase();
772     iwfLog("anchor encoding: " + anc);
773     if (anc.charAt(0) == 'b'){
774     newY -= iwfHeight(elMover);
775     } else if (anc.charAt(0) == 'c'){
776     newY -= iwfHeight(elMover) / 2;
777     }
778    
779     var moverWidth;
780     var staysWidth;
781     if (anc.charAt(1) == 'r'){
782     moverWidth = iwfWidth(elMover);
783     newX -= moverWidth;
784     } else if (anc.charAt(1) == 'c'){
785     moverWidth = iwfWidth(elMover);
786     newX -= moverWidth / 2;
787     }
788     if (anc.charAt(2) == 'b'){
789     newY += iwfHeight(elStays);
790     } else if (anc.charAt(2) == 'c'){
791     newY += iwfHeight(elStays) / 2;
792     }
793     if (anc.charAt(3) == 'r'){
794     staysWidth = iwfWidth(elStays);
795     newX += staysWidth;
796     } else if (anc.charAt(3) == 'c'){
797     staysWidth = iwfWidth(elStays);
798     newX += staysWidth / 2;
799     }
800    
801     iwfLog(iwfAttribute(elMover, 'id') + ' width:' + moverWidth + '\n' + iwfAttribute(elStays, 'id') + ' width:' + staysWidth);
802    
803     // move to those alignment points
804     iwfMoveTo(elMover, newX, newY, totalTicks, totalTicks, motionType);
805     }
806     }
807    
808     function iwfDockTo(id1, id2, anchor1, anchor2, totalTicks, motionType){
809     var elSlave = iwfGetById(id1);
810     var elMaster = iwfGetById(id2);
811    
812     if (elSlave && elMaster){
813    
814     // dock elSlave to elMaster...
815    
816     // pull all items currently docked to elMaster
817     var dockers = iwfAttribute(elMaster,'iwfDockers');
818     // append elSlave to that list
819     if(!dockers){
820     dockers = iwfAttribute(elSlave, 'id');
821     } else {
822     var arrDockers = dockers.split(",");
823     if (arrDockers.length == 0){
824     arrDockers = new Array(dockers);
825     }
826    
827     var slaveId = iwfAttribute(elSlave, 'id');
828     var found = false;
829     for(var i=0;i<arrDockers.length;i++){
830     if (arrDockers[i] == slaveId){
831     found = true;
832     }
833     }
834     if (!found){
835     // elSlave is not in elMaster's list of dockers yet. add him.
836     dockers += "," + iwfAttribute(elSlave, 'id');
837     }
838     }
839    
840     // write list back to elMaster
841     iwfAttribute(elMaster, 'iwfDockers', dockers);
842    
843     // have elSlave remember who he's docked to
844     iwfAttribute(elSlave, 'iwfDockedTo', iwfAttribute(elMaster, 'id'));
845    
846    
847     //iwfLog("dockers for " + iwfAttribute(elMaster, 'id') + " = " + dockers, true);
848    
849    
850     iwfAlignTo(elSlave, elMaster, anchor1, anchor2, totalTicks, motionType);
851    
852     }
853    
854    
855     }
856    
857     function iwfXScroll(id) {
858     var scrollx=0;
859     var el = iwfGetById(id);
860     if (!el){
861     if(document.documentElement && document.documentElement.scrollLeft) scrollx=document.documentElement.scrollLeft;
862     else if(document.body && iwfExists(document.body.scrollLeft)) scrollx=document.body.scrollLeft;
863     } else {
864     if (iwfIsNumber(el.scrollLeft)) scrollx = el.scrollLeft;
865     }
866     return scrollx;
867     }
868     function iwfYScroll(id) {
869     var scrolly=0;
870     var el = iwfGetById(id);
871     if (!el){
872     if(document.documentElement && document.documentElement.scrollTop) scrolly=document.documentElement.scrollTop;
873     else if(document.body && iwfExists(document.body.scrollTop)) scrolly=document.body.scrollTop;
874     } else {
875     if (iwfIsNumber(el.scrollTop)) scrolly = el.scrollTop;
876     }
877     return scrolly;
878     }
879    
880    
881    
882     // -----------------------------------
883     // End: Positioning
884     // -----------------------------------
885    
886     // -----------------------------------
887     // Begin: Size
888     // -----------------------------------
889    
890 dpavlin 55 function iwfClientHeight(){
891     var vHeight = 0;
892     if(document.compatMode == 'CSS1Compat' && document.documentElement && document.documentElement.clientHeight) {
893     vHeight = document.documentElement.clientHeight;
894     } else if(document.body && document.body.clientHeight) {
895     vHeight = document.body.clientHeight;
896     } else if(iwfExists(window.innerWidth,window.innerHeight,document.width)) {
897     vHeight = window.innerHeight;
898     if(document.width>window.innerWidth) {
899     vHeight -= 16;
900     }
901     }
902     return vHeight;
903     }
904    
905     function iwfClientWidth(){
906     var vWidth = 0;
907     if(document.compatMode == 'CSS1Compat' && document.documentElement && document.documentElement.clientWidth) {
908     vWidth = document.documentElement.clientWidth;
909     } else if(document.body && document.body.clientWidth) {
910     vWidth = document.body.clientWidth;
911     } else if(iwfExists(window.innerWidth,window.innerHeight,document.height)) {
912     vWidth = window.innerWidth;
913     if(document.height>window.innerHeight) {
914     vWidth -= 16;
915     }
916     }
917     return vWidth;
918     }
919    
920 dpavlin 46 function iwfWidth(id, neww){
921    
922    
923    
924     var el = iwfGetById(id);
925     if (!el) return 0;
926     var w = 0;
927     if (iwfExists(el)){
928     if (iwfExists(el.style)){
929     if (iwfExists(el.offsetWidth) && iwfIsString(el.style.width)){
930     if (neww) iwfDetermineWidth(el, neww);
931     w = el.offsetWidth;
932     } else if (iwfExists(el.style.pixelWidth)) {
933     if(neww) el.style.pixelWidth = neww;
934     w = el.style.pixelWidth;
935     } else {
936     w = -1;
937     }
938     } else if (iwfExists(el.clip) && iwfExists(el.clip.right)) {
939     if(newh) e.clip.right = neww;
940     w = el.clip.right;
941     } else {
942     w = -2;
943     }
944    
945     //iwfLog('width of ' + iwfAttribute(el, 'id') + ' = ' + w, true);
946    
947     }
948    
949     return w;
950    
951    
952    
953     }
954    
955     function iwfHeight(id, newh){
956     var el = iwfGetById(id);
957     if (!el) return 0;
958     var h = 0;
959     if (iwfExists(el)){
960     if (iwfExists(el.style)){
961     if (iwfExists(el.offsetHeight) && iwfIsString(el.style.height)){
962     if (newh) iwfDetermineHeight(el, newh);
963     h = el.offsetHeight;
964     } else if (iwfExists(el.style.pixelHeight)) {
965     if(newh) el.style.pixelHeight = newh;
966     h = el.style.pixelHeight;
967     } else {
968     h = -1;
969     }
970     } else if (iwfExists(el.clip) && iwfExists(el.clip.bottom)) {
971     if(newh) e.clip.bottom = newh;
972     h = el.clip.bottom;
973     } else {
974     h = -2;
975     }
976     }
977     return h;
978     }
979    
980     function iwfY2(id, y2){
981     var el = iwfGetById(id);
982     if (iwfExists(el)) {
983     var y1 = iwfY(el);
984     if (iwfExists(y2)){
985 dpavlin 55 iwfHeight(el, y2 - y1);
986 dpavlin 46 }
987     return y1 + iwfHeight(el);
988     }
989     return 0;
990     }
991    
992     function iwfX2(id, x2){
993     var el = iwfGetById(id);
994     if (iwfExists(el)) {
995 dpavlin 55 var x1 = iwfX(el);
996 dpavlin 46 if (iwfExists(x2)){
997 dpavlin 55 iwfWidth(el, x2 - x1);
998 dpavlin 46 }
999     return x1 + iwfWidth(el);
1000     }
1001     return 0;
1002     }
1003    
1004     function iwfDetermineStyle(el,prop){
1005     return parseInt(document.defaultView.getComputedStyle(el,'').getPropertyValue(prop),10);
1006     }
1007     function iwfDetermineWidth(el,neww){
1008     var padl=0, padr=0, bdrl=0, bdrr=0;
1009     if (iwfExists(document.defaultView) && iwfExists(document.defaultView.getComputedStyle)){
1010     padl = iwfDetermineStyle(el,'padding-left');
1011     padr = iwfDetermineStyle(el,'padding-right');
1012     bdrl = iwfDetermineStyle(el,'border-left-width');
1013     bdrr = iwfDetermineStyle(el,'border-right-width');
1014    
1015     } else if(iwfExists(el.currentStyle,document.compatMode)){
1016     if(document.compatMode=='CSS1Compat'){
1017 dpavlin 55 padl = iwfToInt(el.currentStyle.paddingLeft, true);
1018     padr = iwfToInt(el.currentStyle.paddingRight, true);
1019     bdrl = iwfToInt(el.currentStyle.borderLeftWidth, true);
1020     bdrr = iwfToInt(el.currentStyle.borderRightWidth, true);
1021 dpavlin 46 }
1022     } else if(iwfExists(el.offsetWidth,el.style.width)){
1023     el.style.width = neww + 'px';
1024     padl=el.offsetWidth - neww;
1025     }
1026    
1027     if(isNaN(padl)) padl=0;
1028     if(isNaN(padr)) padr=0;
1029     if(isNaN(bdrl)) bdrl=0;
1030     if(isNaN(bdrr)) bdrr=0;
1031    
1032     var w2 = neww - padl - padr - bdrl - bdrr;
1033     if (isNaN(w2) || w2 < 0) return;
1034     else el.style.width = w2 + 'px';
1035     }
1036    
1037     function iwfDetermineHeight(el,newh){
1038     var padt=0, padb=0, bdrt=0, bdrb=0;
1039     if(iwfExists(document.defaultView) && iwfExists(document.defaultView.getComputedStyle)){
1040     padt = iwfDetermineStyle(el,'padding-top');
1041     padb = iwfDetermineStyle(el,'padding-bottom');
1042     badt = iwfDetermineStyle(el,'border-top-height');
1043     badb = iwfDetermineStyle(el,'border-bottom-height');
1044     } else if(iwfExists(el.currentStyle,document.compatMode)){
1045     if(document.compatMode=='CSS1Compat'){
1046 dpavlin 55 padt = iwfToInt(el.currentStyle.paddingTop, true);
1047     padb = iwfToInt(el.currentStyle.paddingBottom, true);
1048     bdrt = iwfToInt(el.currentStyle.borderTopHeight, true);
1049     bdrb = iwfToInt(el.currentStyle.borderBottomHeight, true);
1050 dpavlin 46 }
1051     } else if(iwfExists(el.offsetHeight, el.style.height)){
1052     el.style.height = newh + 'px';
1053     padt = el.offsetHeight - newh;
1054     }
1055    
1056     if(isNaN(padt)) padt=0;
1057     if(isNaN(padb)) padb=0;
1058     if(isNaN(bdrt)) bdrt=0;
1059     if(isNaN(bdrb)) bdrb=0;
1060    
1061     var h2 = newh - padt - padb - bdrt - bdrb;
1062    
1063     if(isNaN(h2) || h2 < 0) return;
1064     else el.style.height = h2 + 'px';
1065     }
1066    
1067 dpavlin 55 function iwfOverlaps(id1, id2) {
1068     var el1 = iwfGetById(id1);
1069     var el2 = iwfGetById(id2);
1070 dpavlin 46
1071 dpavlin 55 if (!el1 || !el2) return false;
1072    
1073     var x1a = iwfX(el1);
1074     var x1b = iwfX2(el1);
1075     var y1a = iwfY(el1);
1076     var y1b = iwfY2(el1);
1077    
1078     var x2a = iwfX(el2);
1079     var x2b = iwfX2(el2);
1080     var y2a = iwfY(el2);
1081     var y2b = iwfY2(el2);
1082    
1083     if(x1a > x2b || x1b < x2a || y1a > y2b || y1b < y2a) {
1084     return false;
1085     } else {
1086     return true;
1087     }
1088    
1089     }
1090    
1091     function iwfXCenter(id) {
1092     var el = iwfGetById(id);
1093     if (!el) return 0;
1094     return iwfX(el) + iwfWidth(el) / 2;
1095     }
1096    
1097     function iwfYCenter(id) {
1098     var el = iwfGetById(id);
1099     if (!el) return 0;
1100     return iwfY(el) + iwfHeight(el) / 2;
1101     }
1102    
1103 dpavlin 46 // -----------------------------------
1104     // End: Size
1105     // -----------------------------------
1106    
1107     // -----------------------------------
1108     // Begin: Event
1109     // -----------------------------------
1110    
1111 dpavlin 55 function iwfAddEvent(id, eventName,callback) {
1112 dpavlin 46 var el = iwfGetById(id);
1113     if (!el) return;
1114 dpavlin 55
1115     var txt = callback;
1116     if (iwfIsString(callback)){
1117     callback = function() { eval(txt);};
1118     }
1119    
1120     if (el.addEventListener) {
1121     el.addEventListener(eventName.substr(2), callback, false);
1122     } else if (el.attachEvent) {
1123     //iwfLog('attaching event ' + eventName + ' to element ' + el.id + ' with the callback:\n' + callback, true);
1124 dpavlin 46 el.attachEvent(eventName, callback);
1125     } else {
1126 dpavlin 55 iwfLog("Couldn't add event " + eventName + " to element " + el.id + " because neither addEventListener nor attachEvent are implemented.", true);
1127 dpavlin 46 }
1128     }
1129    
1130     function iwfRemoveEvent(id, eventName, callback){
1131     var el = iwfGetById(id);
1132     if (!el) return;
1133 dpavlin 55 if (el.removeEventListener) {
1134     el.removeEventListener(eventName.substr(2), callback, false);
1135     } else if (el.detachEvent) {
1136     el.detachEvent(eventName, callback);
1137     } else {
1138     iwfLog("Couldn't remove event " + eventName + " from element " + el.id + " because neither removeEventListener nor detachEvent are implemented.", true);
1139     }
1140 dpavlin 46 }
1141    
1142 dpavlin 55 function iwfCallAttribute(id, eventName, evt){
1143     var el = iwfGetById(id);
1144     if (!el) return false;
1145    
1146     var val = iwfAttribute(el, eventName);
1147     //iwfLog("calling attribute " + eventName + "=" + val, true);
1148     if (val){
1149     eval(val);
1150     }
1151    
1152     return;
1153    
1154    
1155    
1156    
1157     if (el.fireEvent){
1158     iwfLog("firing event " + eventName + " on el " + el.id);
1159     el.fireEvent(eventName, evt);
1160     } else if (el.dispatchEvent){
1161     // chop off the "on" at the beginning...
1162     // eventName = eventName.substr(2);
1163     // iwfLog(eventName, true);
1164     var newEvent = null;
1165     if (document.createEvent){
1166     newEvent = document.createEvent("Events");
1167     } else {
1168     newEvent = document.createEventObject();
1169     }
1170     newEvent.initEvent(eventName, true, true); //, document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
1171     iwfLog("dispatching event " + eventName + " on el " + el.id);
1172     if (!el.dispatchEvent(newEvent)){
1173     iwfLog("Could not el.dispatchEvent failed!", true);
1174     }
1175     } else {
1176     iwfLog("Could not el.fireEvent or el.dispatchEvent!", true);
1177     }
1178     }
1179    
1180 dpavlin 46 function iwfEvent(ev) {
1181     this.keyCode = 0;
1182     this.target = null;
1183     this.type = '';
1184     this.X = 0;
1185     this.Y = 0;
1186     var evt = ev || window.event;
1187     if(!evt) return;
1188    
1189     if(evt.type) this.type = evt.type;
1190     if(evt.target) this.target = evt.target;
1191     else if(evt.srcElement) this.target = evt.srcElement;
1192    
1193 dpavlin 55 this.X = iwfX(evt.target);
1194     this.Y = iwfY(evt.target);
1195    
1196 dpavlin 46 if(iwfExists(evt.clientX,evt.clientY)) {
1197     this.X = evt.clientX + iwfXScroll();
1198     this.Y = evt.clientY + iwfYScroll();
1199     } else if (iwfExists(evt.offsetX, evt.offsetY)){
1200     this.X = evt.offsetX;
1201     this.Y = evt.offsetY;
1202     }
1203    
1204     if (evt.keyCode) { this.keyCode = evt.keyCode; }
1205     else if (iwfExists(evt.which)) { this.keyCode = evt.which; }
1206    
1207     return this;
1208     }
1209    
1210     // -----------------------------------
1211     // End: Event
1212     // -----------------------------------
1213    
1214    
1215     // -----------------------------------
1216     // Begin: Image
1217     // -----------------------------------
1218     function iwfRollover(id, overurl){
1219     var el = iwfGetById(id);
1220     if (!el) return;
1221     var rollover = null;
1222     if (overurl){
1223     rollover = overurl;
1224     } else {
1225     iwfAttribute(el, "rolloversrc");
1226     }
1227     if (!rollover) return;
1228     el.iwfOrigSrc = el.src;
1229     el.iwfRolloverImg = new Image();
1230     el.iwfRolloverImg.src = rollover;
1231     iwfAddEvent(el, 'onmouseover', iwfDoRollover);
1232     iwfAddEvent(el, 'onmouseout', iwfDoRollover);
1233     }
1234    
1235     function iwfDoRollover(ev){
1236     var evt = new iwfEvent(ev);
1237     var el = evt.target;
1238     if (el.src == el.iwfOrigSrc){
1239     iwfSwapImage(el, el.iwfRolloverImg);
1240     } else {
1241     iwfSwapImage(el, el.iwfOrigSrc);
1242     }
1243     }
1244    
1245     function iwfPreloadImage(id, newimg){
1246     var el = iwfGetById(id);
1247     if (!el) return;
1248     /* todo: preload images here */
1249     }
1250    
1251     function iwfSwapImage(id, newimg){
1252     var el = iwfGetById(id);
1253     if (!el) return;
1254     if (iwfIsString(newimg)){
1255     el.src = newimg;
1256     } else {
1257     el.src = newimg.src;
1258     }
1259     }
1260    
1261     // preload images and attach event handlers for rollovers
1262     function iwfMapRollovers(){
1263     var nodes = iwfGetByTagName('img');
1264     for(var i=0;i<nodes.length;i++){
1265     iwfRollover(nodes[i]);
1266     }
1267     }
1268    
1269     // -----------------------------------
1270     // End: Image
1271     // -----------------------------------
1272    
1273    
1274     // -----------------------------------
1275     // Begin: Drag-N-Drop
1276     // -----------------------------------
1277    
1278 dpavlin 55 var iwfDragger = {el:null, curTarget:null, targets:new Array()};
1279 dpavlin 46 var iwfHiZ = 2;
1280    
1281 dpavlin 55 var iwfResizer = {elSrc:null, elTgt:null};
1282    
1283     function iwfResize(resizeId, targetId){
1284     var resizer = iwfGetById(resizeId);
1285     if (!resizer) return;
1286    
1287     var target = iwfGetById(targetId);
1288     if (!target) return;
1289    
1290     iwfResizer.elSrc = resizer;
1291     iwfResizer.elTgt = target;
1292    
1293    
1294     // set the drag start / move / stop
1295     iwfAttribute(resizer, 'iwfdragbegin', 'iwfResizeStart()');
1296     iwfAttribute(resizer, 'iwfdragmove', 'iwfResizeMove()');
1297     iwfAttribute(resizer, 'iwfdragend', 'iwfResizeEnd()');
1298    
1299     iwfDrag(resizer);
1300    
1301     }
1302    
1303     function iwfResizeStart(){
1304    
1305     }
1306    
1307     function iwfResizeMove(resizeId, targetId){
1308     // elSrc should have already been moved to its new location.
1309     // make elTgt fit to it.
1310     var tgtX = iwfX(iwfResizer.elTgt);
1311     var tgtY = iwfY(iwfResizer.elTgt);
1312    
1313     var srcX2 = iwfX2(iwfResizer.elSrc);
1314     if (srcX2 - 100 < tgtX){
1315     srcX2 = tgtX + 100;
1316     }
1317    
1318     var srcY2 = iwfY2(iwfResizer.elSrc);
1319     if (srcY2 - 50 < tgtY){
1320     srcY2 = tgtY + 50;
1321     }
1322     //iwfLog("srcX2:" + srcX2 + "\tsrcY2:" + srcY2);
1323     // iwfX1(iwfResizer.elSrc, srcX2 - iwfWidth(iwfResizer.elSrc));
1324     // iwfY1(iwfResizer.elSrc, srcY2 - iwfHeight(iwfResizer.elSrc));
1325    
1326     // iwfX2(iwfResizer.elTgt, srcX2);
1327     // iwfY2(iwfResizer.elTgt, srcY2);
1328    
1329     // if container exists, make it occupy all but titlebar space...
1330     if (iwfResizer.elTgt){
1331     var elContainer = iwfGetById(iwfResizer.elTgt.id + 'Container');
1332     if (elContainer){
1333     iwfHeight(elContainer, iwfHeight(iwfResizer.elTgt) - iwfHeight(iwfResizer.elTgt.id + 'TitleBar') - 2);
1334     }
1335     }
1336    
1337    
1338     }
1339    
1340     function iwfResizeEnd(){
1341    
1342     iwfLog(iwfElementToString(iwfResizer.elSrc), true);
1343    
1344     iwfResizer.elSrc = null;
1345     iwfResizer.elTgt = null;
1346     }
1347    
1348     function iwfDrag(id) {
1349    
1350 dpavlin 46 var el = iwfGetById(id);
1351     if (!el) return;
1352 dpavlin 55
1353     //iwfLog(iwfElementToString(el), true);
1354     if (!iwfDragger.el) {
1355     el.iwfDragTarget = true;
1356     iwfAddEvent(el, 'onmousedown', iwfDragMouseDown);
1357     // BROCK: sync issues here in IE when there is no container.
1358     // HACK: force a container always? hmmmm...
1359     // iwfFireEvent(el, 'onmousedown');
1360 dpavlin 46 }
1361     }
1362     function iwfDragMouseDown(ev){
1363 dpavlin 55
1364 dpavlin 46 var evt = new iwfEvent(ev);
1365     var el = evt.target;
1366 dpavlin 55 while(el && !el.iwfDragTarget) {
1367     el = iwfGetParent(el);
1368 dpavlin 46 }
1369     if (el) {
1370 dpavlin 55
1371     iwfDragger.el = el;
1372    
1373     iwfAddEvent(document, 'onmousemove', iwfDragMouseMove);
1374     iwfAddEvent(document, 'onmouseup', iwfDragMouseUp);
1375    
1376    
1377    
1378 dpavlin 46 if (ev && ev.preventDefault) ev.preventDefault();
1379     else if (window.event) window.event.returnValue = false;
1380 dpavlin 55 else if (iwfExists(ev.cancelBubble)) ev.cancelBubble = true;
1381 dpavlin 46
1382 dpavlin 55 el.iwfDragOrigX = iwfX(el);
1383     el.iwfDragOrigY = iwfY(el);
1384     el.iwfDragOffsetX = evt.X - iwfX(el);
1385     el.iwfDragOffsetY = evt.Y - iwfY(el);
1386    
1387    
1388 dpavlin 46 iwfZIndex(el, iwfHiZ++);
1389    
1390 dpavlin 55 iwfCallAttribute(el, 'iwfdragbegin');
1391 dpavlin 46 }
1392     }
1393    
1394     function iwfDragMouseMove(ev){
1395     var evt = new iwfEvent(ev);
1396 dpavlin 55
1397 dpavlin 46 if (iwfDragger.el) {
1398 dpavlin 55 if (evt && evt.preventDefault) evt.preventDefault();
1399 dpavlin 46 else if (window.event) window.event.returnValue = false;
1400 dpavlin 55 else if (iwfExists(ev.cancelBubble)) ev.cancelBubble = true;
1401    
1402 dpavlin 46 var el = iwfDragger.el;
1403    
1404 dpavlin 55
1405     var newX = evt.X - el.iwfDragOffsetX;
1406     if (newX > iwfClientWidth() - iwfWidth(el)){
1407     newX = iwfClientWidth() - iwfWidth(el);
1408 dpavlin 46 }
1409 dpavlin 55 if (newX < 0) {
1410     newX = 0;
1411     }
1412    
1413     var newY = evt.Y - el.iwfDragOffsetY;
1414     if (newY > iwfClientHeight() - iwfHeight(el)){
1415     newY = iwfClientHeight() - iwfHeight(el);
1416     }
1417     if (newY < 0) {
1418     newY = 0;
1419     }
1420    
1421    
1422     iwfX(el, newX);
1423     iwfY(el, newY);
1424    
1425     // and hilite any drop targets...
1426     for(var i=0;i<iwfDragger.targets.length;i++){
1427     if (!iwfDragger.curTarget && iwfOverlaps(iwfDragger.targets[i], iwfDragger.el)) {
1428     iwfDragOver(iwfDragger.targets[i]);
1429     break;
1430     }
1431     }
1432    
1433     iwfCallAttribute(el, 'iwfdragmove');
1434    
1435 dpavlin 46 }
1436     }
1437 dpavlin 55
1438 dpavlin 46 function iwfDragMouseUp(ev) {
1439     if (iwfDragger.el) {
1440     if (ev && ev.preventDefault) ev.preventDefault();
1441     else if (window.event) window.event.returnValue = false;
1442 dpavlin 55 else if (iwfExists(ev.cancelBubble)) ev.cancelBubble = true;
1443    
1444     var evt = new iwfEvent(ev);
1445     iwfRemoveEvent(document, 'onmousedown', iwfDragMouseDown);
1446     iwfRemoveEvent(document, 'onmousemove', iwfDragMouseMove);
1447     iwfRemoveEvent(document, 'onmouseup', iwfDragMouseUp);
1448    
1449     iwfCallAttribute(iwfDragger.el, 'iwfdragend');
1450    
1451     iwfDragDrop();
1452     iwfDragger.el.iwfDragTarget = false;
1453 dpavlin 46 iwfDragger.el = null;
1454     }
1455     }
1456    
1457 dpavlin 55 function iwfDragOver(idTarget) {
1458     var tgt = iwfGetById(idTarget);
1459     if (!tgt) return;
1460    
1461     if (!iwfDragger.el) return;
1462    
1463     if (iwfDragger.curTarget) return;
1464    
1465    
1466     iwfDragger.curTarget = tgt.id;
1467    
1468    
1469     tgt.iwfBackgroundColor = tgt.style.backgroundColor;
1470     tgt.style.backgroundColor = '#efefef';
1471    
1472     iwfDragger.el.iwfBorder = iwfDragger.el.style.border;
1473     iwfDragger.el.style.border = '3px solid blue';
1474    
1475     }
1476    
1477     function iwfDragOut() {
1478    
1479     var tgt = iwfGetById(iwfDragger.curTarget);
1480     if (!tgt) return;
1481    
1482     iwfDragger.curTarget = null;
1483    
1484    
1485     if (!iwfDragger.el) return;
1486    
1487    
1488    
1489     iwfDragger.el.style.border = iwfDragger.el.iwfBorder;
1490     tgt.style.backgroundColor = tgt.iwfBackgroundColor;
1491    
1492    
1493     }
1494    
1495     function iwfDragDrop() {
1496    
1497     var tgt = iwfGetById(iwfDragger.curTarget);
1498    
1499     iwfDragOut(iwfDragger.curTarget);
1500    
1501    
1502    
1503     if (!iwfDragger.el) return;
1504    
1505     var src = iwfGetById(iwfDragger.el);
1506    
1507     if (src) {
1508     if (!tgt) {
1509     if (iwfDragger.targets.length > 0) {
1510     // targets exist, but none were dropped on. return to original x/y
1511     iwfMoveTo(tgt, iwfAttribute(iwfDragger.el, 'iwfDragOrigX'), iwfAttribute(iwfDragger.el, 'iwfDragOrigY'), 30);
1512     }
1513     } else {
1514     // target found. dock to it.
1515     iwfDockTo(tgt, src, "tl", "tl", 30);
1516     }
1517     }
1518     }
1519    
1520     function iwfMapDropTargets(node) {
1521    
1522     if (!node || !node.childNodes) {
1523     iwfLog('No childNodes found for ' + iwfElementToString(node), true);
1524     return;
1525     }
1526    
1527     for(var i=0; i<node.childNodes.length;i++){
1528     iwfLog('child=' + iwfElementToString(node.childNodes[i]), true);
1529     if (iwfAttribute(node.childNodes[i], 'iwfDropTarget') == 'true'){
1530     iwfDragger.targets.push(iwfAttribute(node.childNodes[i], 'id'));
1531     }
1532     iwfMapDropTargets(node.childNodes[i]);
1533     }
1534    
1535    
1536     }
1537    
1538     function iwfMapDraggables(node){
1539     if (!node) {
1540     iwfLog("when mapping windows, node not found");
1541     return;
1542     } else if (!node.childNodes){
1543     iwfLog("No childNodes found for " + iwfElementToString(node.childNodes[i]));
1544     return;
1545     }
1546    
1547     for(var i=0; i<node.childNodes.length;i++){
1548     if (iwfAttribute(node.childNodes[i], 'iwfDraggable') == 'true'){
1549     iwfLog("Found draggable to map: " + iwfElementToString(node.childNodes[i]));
1550     iwfMakeDraggable(node.childNodes[i]);
1551     }
1552     }
1553     }
1554    
1555     function iwfMakeDraggable(id){
1556     var el = iwfGetById(id);
1557     if (!el) return;
1558    
1559     if (iwfAttribute(el, 'iwfDraggableMapped') == 'true'){
1560     // element has already been mapped for dragging. escape.
1561     return;
1562     }
1563    
1564     // mark it as being mapped as a drag target
1565     iwfAttribute(el, 'iwfDraggableMapped', 'true');
1566     iwfAttribute(el, 'iwfDragTarget', 'true');
1567    
1568     // make sure window is absolutely positioned and overflow is okay
1569     el.style.position = 'absolute';
1570     el.style.overflow = 'hidden';
1571     el.style.cursor = 'move';
1572    
1573     iwfAddEvent(el, 'onmousedown', 'iwfDrag("' + el.id + '");');
1574    
1575     }
1576    
1577     function iwfMapWindows(node){
1578     if (!node) {
1579     iwfLog("when mapping windows, node not found");
1580     return;
1581     } else if (!node.childNodes){
1582     iwfLog("No childNodes found for " + iwfElementToString(node.childNodes[i]));
1583     return;
1584     }
1585    
1586     for(var i=0; i<node.childNodes.length;i++){
1587     if (iwfAttribute(node.childNodes[i], 'iwfWindow') == 'true'){
1588     iwfLog("Found window to map: " + iwfElementToString(node.childNodes[i]));
1589     iwfGetOrCreateWindow(node.childNodes[i]);
1590     }
1591     }
1592     }
1593    
1594     function iwfGetOrCreateWindow(id){
1595     var el = iwfGetById(id);
1596     if (!el) return null;
1597    
1598     if (iwfAttribute(el, 'iwfWindowCreated') == 'true'){
1599     // window has already been created. escape.
1600     return;
1601     }
1602    
1603     // make sure window is absolutely positioned and overflow is okay
1604     el.style.position = 'absolute';
1605     el.style.overflow = 'hidden';
1606    
1607     // create a title bar
1608     var elTitle = iwfGetOrCreateById(el.id + 'TitleBar', 'div');
1609     if (!elTitle) return;
1610    
1611     elTitle.style.backgroundColor = 'navy';
1612     elTitle.style.color = 'white';
1613     elTitle.style.cursor = 'move';
1614     elTitle.innerHTML = "&nbsp;" + iwfAttribute(el, 'iwfWindowTitle');
1615    
1616     // dragging title bar should move the window
1617     iwfAddEvent(elTitle, 'onmousedown', 'iwfDrag("' + el.id + '");');
1618    
1619    
1620     // create the container which will contain all other html specified in the div
1621     var elContainer = iwfGetOrCreateById(el.id + 'Container', 'div');
1622     if (!elContainer) return;
1623    
1624     elContainer.style.width='100%';
1625     elContainer.style.height='90%';
1626     elContainer.style.overflow='scroll';
1627    
1628     // transfer window contents into the new container
1629     elContainer.innerHTML = el.innerHTML;
1630     // clear the window
1631     el.innerHTML = '';
1632    
1633    
1634     // create the resizer which will handle resizing
1635     var elResizer = iwfGetOrCreateById(el.id + 'Resizer', 'div');
1636     if (!elResizer) return;
1637    
1638    
1639     elResizer.innerHTML = "<table border='0' cellspacing='0' cellpadding='0' width='100%' height='3px' ><tr ><td width='95%' style='cursor:s-resize'>&nbsp;</td><td style='cursor:se-resize'>&nbsp;</td></tr></table>";
1640     // elResizer.innerHTML = '<span style="width:90%;background-color:red;color:white;cursor:s-resize;padding-right:30px;">blah</span><span style="width:20px;color:black;background-color:gray;cursor:se-resize">*</span>';
1641    
1642    
1643    
1644     // set style properties on resizer
1645     // iwfX(elResizer, iwfX(el) + 20);
1646     // iwfY(elResizer, iwfY(el) + 20);
1647     // iwfZIndex(elResizer, 9999999);
1648     // iwfHeight(elResizer, 15);
1649     // iwfWidth(elResizer, 15);
1650     // elTitle.style.cursor = 'move';
1651     // elResizer.style.position = 'absolute';
1652     // elResizer.style.borderStyle = 'solid';
1653     // elResizer.style.borderColor = 'black';
1654     // elResizer.style.borderWidth = '1px';
1655     // elResizer.backgroundColor = 'white';
1656     // elResizer.style.overflow = 'hidden';
1657     // elResizer.style.textAlign = 'center';
1658     // elResizer.style.cursor = 'se-resize';
1659     // elResizer.innerHTML = '-';
1660    
1661     // dragging the resizer should resize the window
1662     iwfAddEvent(elResizer, 'onmousedown', 'iwfResize("' + elResizer.id + '","' + el.id + '");');
1663    
1664    
1665     // add title bar to window
1666     iwfAddChild(el, elTitle, true);
1667    
1668     // add container to window
1669     iwfAddChild(el, elContainer);
1670    
1671     // add resizer to window
1672     iwfAddChild(el, elResizer);
1673    
1674     // iwfX(elResizer, iwfX2(el) - 15);
1675     // iwfY(elResizer, iwfY2(el) - 15);
1676    
1677     iwfLog(iwfElementToString(elResizer),true);
1678    
1679     // align resizer to bottom right of window
1680     iwfResize(elResizer, el);
1681    
1682    
1683    
1684     // add the flag saying we've created the window
1685     iwfAttribute(el, 'iwfWindowCreated', 'true');
1686    
1687    
1688     }
1689    
1690 dpavlin 46 // -----------------------------------
1691     // End: Drag-N-Drop
1692     // -----------------------------------
1693    

Properties

Name Value
svn:mime-type text/cpp

  ViewVC Help
Powered by ViewVC 1.1.26