/
jtoolbar.js
2082 lines (1785 loc) · 78.5 KB
/
jtoolbar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* JavaScript Toolbar Widget
* David Underhill and James Chen
*/
/* createCookie(), readCookie() are by Peter-Paul Koch of quirksmode.org */
var JTB = function() {
/* private constants */
var SPRINGINESS_FACTOR = 1.3;
var SPLIT_CLOSE = 1.0 - (1.0 / SPRINGINESS_FACTOR);
var ICON_SIZE = 16;
var ICON_BORDER_SIZE = 0;
var ICON_MARGIN = 3;
var ICON_COUNT = 3;
var ICON_ANCHOR = null;
var ICON_ANCHOR_WIDTH = 32;
var ICON_ANCHOR_HEIGHT = 48;
var MAX_DEBUG_LINES = 5;
var COOKIE_LIFETIME_DAYS = 60;
/* private members */
var toolbars = [];
var mouseDragX, mouseDragY;
var mouseX, mouseY;
var debugErrReported = false;
function debug(newstr) {
if(window.console) {
console.debug(newstr);
}
else if(!debugErrReported) {
debugErrReported = true;
alert('warning: you need to run firebug and enable the console to see debugging output');
}
}
function createCookie(name,value,days) {
var expires;
if(days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
}
else {
expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
}
function createBooleanCookie(name,value,days) {
if(value === true) {
createCookie(name, 'T', days);
}
else {
createCookie(name, 'F', days);
}
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while(c.charAt(0)==' ') {
c = c.substring(1,c.length);
}
if(c.indexOf(nameEQ) === 0) {
return c.substring(nameEQ.length,c.length);
}
}
return null;
}
function readBooleanCookie(name) {
var v = readCookie(name);
if(v === null) {
return null;
}
return (v === 'T');
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
/** simple object containing a set of coordinates */
function Coords(x, y) {
this.x = x;
this.y = y;
}
/** returns the distance squared from a point to a rectangle */
function distanceSqToRectangle(x, y, rx, ry, rw, rh) {
var dx, dy;
if(x < rx) {
dx = rx - x;
}
else if(x > rx + rw) {
dx = x - rx - rw;
}
else {
dx = 0;
}
if(y < ry) {
dy = ry - y;
}
else if(y > ry + rh) {
dy = y - ry - rh;
}
else {
dy = 0;
}
return (dx*dx) + (dy*dy);
}
function findPosX(obj) {
var curleft = 0;
if(obj.offsetParent) {
while(1) {
curleft += obj.offsetLeft;
if(!obj.offsetParent) {
break;
}
obj = obj.offsetParent;
}
}
else if(obj.x) {
curleft += obj.x;
}
return curleft;
}
function findPosY(obj) {
var curtop = 0;
if(obj.offsetParent) {
while(1) {
curtop += obj.offsetTop;
if(!obj.offsetParent) {
break;
}
obj = obj.offsetParent;
}
}
else if(obj.y) {
curtop += obj.y;
}
return curtop;
}
/** returns the effective value of a property of obj */
function findValue(obj, propName, inheritedIsDefault) {
var v = eval('obj.' + propName);
if(v === '') {
if(!inheritedIsDefault) {
return 0;
}
}
else if(v != 'inherit') {
return v;
}
if(obj.parentNode==document.body || obj.parentNode===null) {
return 0;
}
else {
return findValue(obj.parentNode, propName);
}
}
/**
* gets the width not included in offsetWidth (e.g. borders,
* padding, and margin)
*/
function getExtraWidth(e) {
if(e === null) {
return 0;
}
var ret = 0;
ret += parseInt(findValue(e, 'style.paddingLeft', false), 10);
ret += parseInt(findValue(e, 'style.paddingRight', false), 10);
ret += parseInt(findValue(e, 'style.marginLeft', false), 10);
ret += parseInt(findValue(e, 'style.marginRight', false), 10);
ret += parseInt(findValue(e, 'style.borderLeftWidth', false), 10);
ret += parseInt(findValue(e, 'style.borderRightWidth', false), 10);
return ret;
}
/**
* gets the height not included in offsetHeight (e.g. borders,
* padding, and margin)
*/
function getExtraHeight(e) {
if(e === null) {
return 0;
}
var ret = 0;
ret += parseInt(findValue(e, 'style.paddingTop', false), 10);
ret += parseInt(findValue(e, 'style.paddingBottom', false), 10);
ret += parseInt(findValue(e, 'style.marginTop', false), 10);
ret += parseInt(findValue(e, 'style.marginBottom', false), 10);
ret += parseInt(findValue(e, 'style.borderTopWidth', false), 10);
ret += parseInt(findValue(e, 'style.borderBottomWidth', false), 10);
return ret;
}
/** returns the effective z-index of the object */
function findZIndex(obj) {
var z = obj.style.zIndex;
if(z === '') {
if(obj.parentNode==document.body || obj.parentNode===null) {
return 0;
}
else {
return findZIndex(obj.parentNode);
}
}
else {
return z;
}
}
/** get a child element */
function getChild(elt, child_name) {
var children = elt.childNodes;
var i;
for(i=0; i<children.length; i++) {
try {
var c = children[i];
var name = c.getAttribute('id');
if(name == child_name) {
return c;
}
}
catch(err) {}
}
return null;
}
/** updates the toolbar's size and position based on the ongoing animation */
function handleToolbarAnimation(tb) {
tb.refreshGfx();
/* periodically call this method until the animation is done */
if(tb.isAnimating()) {
setTimeout(function(){JTB.handleAnimationCallback(tb.tb_id);},
JTB.ANIM_INTERVAL_MSEC);
}
else if(tb.isChildToolbar() && tb.getState()==JTB.STATE_INVIS) {
var container = tb.tb_parent.getContainer();
if(container !== null) {
try { container.removeChild(tb.e_tb); } catch(err) { /* ignore */ }
}
}
}
/** Compute the size in pixels of some length field. */
function lengthToPixels(len, isWidth) {
var i;
if(len===null || len==='') {
return 0;
}
if(typeof(len) == 'string') {
if(len.indexOf('%') >= 0) {
var max;
if(isWidth) {
max = document.body.offsetWidth;
}
else {
max = document.body.offsetHeight;
}
return Math.ceil(parseInt(len, 10) * max / 100);
}
}
/* assume pixels as units */
return parseInt(len, 10);
}
/** compute the maximum x and y values used according to absolutely
* positioned children (recursve) */
function computeMaxXY(e) {
var i, c, cur;
var max = new Coords(lengthToPixels(e.offsetLeft + e.offsetWidth, true),
lengthToPixels(e.offsetTop + e.offsetHeight, false));
for(i=0; i<e.childNodes.length; i++) {
if(e.getAttribute('isToolbar') === null) {
cur = computeMaxXY(e.childNodes[i]);
if(cur.x > max.x) {
max.x = cur.x;
}
if(cur.y > max.y) {
max.y = cur.y;
}
}
}
return max;
}
/** sets the style parameters of an icon div */
function setupIconDiv(e) {
e.style.backgroundRepeat = 'no-repeat';
e.style.border = ICON_BORDER_SIZE + 'px solid black';
e.style.width = ICON_SIZE + 'px';
e.style.height = ICON_SIZE + 'px';
e.style.position = 'absolute';
var m = ICON_MARGIN + 'px ';
e.style.margin = m + m + m + m;
}
/* export public members */
return {
/* public constants */
VERSION : "0.1",
ORIENT_LEFT : "left",
ORIENT_RIGHT : "right",
ORIENT_TOP : "top",
ORIENT_BOTTOM : "bottom",
STATE_VIS : "vis",
STATE_INVIS : "invis",
ANIM_INTERVAL_MSEC : 25,
DOCK_CLOSEST_INCUMBENT_ADVANTAGE : 1.1,
/**
* Helps determine what size an element should be. It allows width
* and/or the height dimensions to be forced to a specific value if
* desired.
*/
SizeHelper : function(e, tb) {
/** the element this handles size for */
this.e = e;
/** the toolbar this is associated with */
this.tb = tb;
/** the current intended width of this element */
this.width = 0;
/** the current intended height of this element */
this.height = 0;
/**
* The width of this element when it is in a vertical orientation.
* If empty, then the "natural" width is used. If a percentage is
* specified, then it will be a percentage of the container.
*/
this.vert_orient_width = '';
/**
* The height of this element when it is in a horizontal
* orientation. If empty, then the "natural" width is used. If a
* percentage is specified, then it will be a percentage of the
* container.
*/
this.horiz_orient_height = '';
/**
* The width and height of this element when it is floating. If
* empty, then the "natural" width is used. If a percentage is
* specified, then it will be a percentage of the container.
*/
this.float_width = '';
this.float_height = '';
/**
* Whether to have size based on orientation even if in float mode
* (e.g. whether to ignore the float_width and float_height fields).
*/
this.float_ignore = true;
/** cached parameters to enable quick bailout from size computation */
this.cached_isVert = null;
this.cached_isFloat = null;
/* set the natural size override based on the style values */
if(e.style.width !== '') {
var w = parseInt(e.style.width, 10);
this.float_width = this.vert_orient_width = w;
}
else if(tb === null) {
this.float_width = this.e.offsetWidth;
}
if(e.style.height !== '') {
var h = parseInt(e.style.height, 10);
this.float_height = this.horiz_orient_height = h;
}
else if(tb === null) {
this.float_height = this.e.offsetHeight;
}
},
/**
* Toolbar link constructor
*/
ToolbarLink : function(name, link, encToolbar) {
this.name = name;
this.link = link;
this.encToolbar = encToolbar;
},
/**
* Toolbar constructor
* @param content_name name of the element the toolbar is attached to
* @param tb_name name of the element to use or make for the toolbar
* @param ... remaining arguments specify name-link pairs
*/
Toolbar : function(content_name, tb_name) {
/* name of the element which is the toolbar is attached to */
this.content_id = content_name;
/* name of the div which contains the toolbar */
this.tb_id = tb_name;
/* elements which compose the toolbar */
this.e_container = null;
this.e_content = null;
this.e_tb = null;
this.e_icons = null;
this.e_icon_drag = null;
this.e_icon_float = null;
this.e_icon_pin = null;
this.e_links = null;
/* toolbar hierarchy support */
this.tb_parent = null;
this.vis_tb_child = null;
/* sizing information helpers */
this.sz_container = null;
this.sz_tb = null;
/* time the toolbar animation started */
this.anim_start = -1;
/* % of time for the first half of the animation */
this.anim_split = 0;
/* src width and height of an animation */
this.anim_src_width = 0;
this.anim_src_height = 0;
this.anim_first_half = true;
/* orientation of the toolbar */
this.orient = JTB.ORIENT_LEFT;
/* whether the toolbar is docked */
this.docked = true;
/* threshold (in pixels) for a position to be considered in a docking area */
this.docking_threshold = 100;
/* absolute position offset from parent if not docked */
this.floatx = 0;
this.floaty = 0;
/* whether to clamp a floating toolbar to its container's size */
this.clamp_size_on_float = false;
/* position at the beginning of a drag */
this.dragStartX = 0;
this.dragStartY = 0;
/* whether to show the drag graphic */
this.show_drag = true;
/* whether to show the float graphic */
this.show_float = true;
/* whether to show the pin/unpin graphic */
this.show_pin = true;
/* path to icon location */
this.img_path = 'images/';
/* whether the toolbar is being dragged */
this.dragging = false;
/* whether the toolbar is currently pinned */
this.pinned = true;
/** whether the toolbar always takes up space (even when unpinned) */
this.alwaysShiftContent = false;
/* whether the toolbar is visible, invis, or transitioning */
this.state = JTB.STATE_VIS;
/* number of milliseconds for the toolbar to slide in/out */
this.animation_len_msec = 400;
/* whether to use the spring animation or not */
this.anim_springy = true;
/* pixels from the edge which triggers the toolbar to show */
this.trigger_dist = 100;
/* array of ToolbarLink objects to show in the toolbar div */
this.links = [];
/* register the toolbar so we can find it later */
toolbars[toolbars.length] = this;
/* create the requested links */
if(arguments.length > 1) {
var i, name, link;
for(i=1; i<arguments.length/2; i+=1) {
name = arguments[2*i];
link = arguments[2*i+1];
if (typeof(link) != "string") {
// link is actually a nested toolar
link.setParentToolbar(this);
}
this.links[i-1] = new JTB.ToolbarLink(name, link, this);
}
}
this.hookup();
},
init : function() {
/** Compute the size for this element based on the reference toolbar's status. */
JTB.SizeHelper.prototype.refreshSizeData = function() {
var orient;
var isFloat;
if(this.tb !== null) {
orient = this.tb.getOrientation();
isFloat = this.tb.isFloating();
}
else {
orient = null;
isFloat = true;
}
this.refreshSizeDataFull(orient, isFloat);
};
/** Compute the size for this element based on the specified toolbar
* status. */
JTB.SizeHelper.prototype.refreshSizeDataFull = function(orient, isFloat) {
var isVert = (orient==JTB.ORIENT_LEFT || orient==JTB.ORIENT_RIGHT);
var isHoriz = (orient==JTB.ORIENT_TOP || orient==JTB.ORIENT_BOTTOM);
/* stop now if the parameters have not changed */
if(this.cached_isVert===isVert && this.cached_isFloat===isFloat) {
return;
}
this.cached_isVert = isVert;
this.cached_isFloat = isFloat;
/* get the predetermined height and width values (if any) */
var w=0, h=0;
if((!isFloat || this.float_ignore) && this.tb!==null) {
if(isVert) {
w = lengthToPixels(this.vert_orient_width, true);
}
else if(isHoriz) {
h = lengthToPixels(this.horiz_orient_height, false);
}
}
else {
w = lengthToPixels(this.float_width, true);
h = lengthToPixels(this.float_height, false);
}
/* save the current values: we're just getting not setting sizes */
var es = this.e.style;
var orig_w = es.width;
var orig_h = es.height;
var orig_dis = es.display;
var orig_pos = es.position;
/* prepare each dimension */
es.width = ((w===0) ? '' : (w + 'px'));
es.height = ((h===0) ? '' : (h + 'px'));
/* make sure the element is visible and unrestricted in size */
es.display = 'block';
es.position = 'absolute';
/* get the preferred sizes: incorrect if there absolutely
* positioned elements inside of us */
if(this.assume_no_abs_postioned_elts) {
this.width = this.e.offsetWidth;
this.height = this.e.offsetHeight;
}
else {
/* compute the real preferred size by looking at all
* children inside the element (absolute positioned elements
* otherwise screw us up)
*/
var maxXY = computeMaxXY(this.e);
this.width = maxXY.x - this.e.offsetLeft;
this.height = maxXY.y - this.e.offsetTop;
}
/* restore the original style */
es.width = orig_w;
es.height = orig_h;
es.display = orig_dis;
es.position = orig_pos;
};
/**
* Invalidates any cached values. Should be called whenever the
* content of a toolbar changes.
*/
JTB.SizeHelper.prototype.invalidateCacheAndRefreshSizeData = function() {
this.cached_isVert = this.cached_isFloat = null;
this.refreshSizeData();
};
/** Sets the width of the element when it is vertically orientated */
JTB.SizeHelper.prototype.setVertOrientWidth = function(w) {
if(this.vert_orient_width != w) {
this.vert_orient_width = w;
if(!this.tb.isFloating() || this.float_ignore) {
this.refreshSizeData();
}
}
};
/** Sets the height of the element when it is horizontally orientated */
JTB.SizeHelper.prototype.setHorizOrientHeight = function(h) {
if(this.horiz_orient_height != h) {
this.horiz_orient_height = h;
if(!this.tb.isFloating() || this.float_ignore) {
this.refreshSizeData();
}
}
};
/** Sets the orientation-specific dimension sizes. */
JTB.SizeHelper.prototype.setOrientSpecificSize = function(w, h) {
if(this.vert_orient_width!=w && this.horiz_orient_height!=h) {
this.vert_orient_width = w;
this.horiz_orient_height = h;
if(!this.tb.isFloating() || this.float_ignore) {
this.refreshSizeData();
}
}
};
/** Sets the width of the element when it is floating */
JTB.SizeHelper.prototype.setFloatWidth = function(w) {
if(this.float_width != w) {
this.float_width = w;
if(this.tb.isFloating()) {
this.refreshSizeData();
}
}
};
/** Sets the height of the element when it is floating */
JTB.SizeHelper.prototype.setFloatHeight = function(h) {
if(this.float_height != h) {
this.float_height = h;
if(this.tb.isFloating()) {
this.refreshSizeData();
}
}
};
/** Sets the orientation-specific dimension sizes. */
JTB.SizeHelper.prototype.setFloatSize = function(w, h) {
if(this.float_width!=w && this.float_height!=h) {
this.float_width = w;
this.float_height = h;
if(this.tb.isFloating()) {
this.refreshSizeData();
}
}
};
/** Sets whether floating should not be taken into account when
* determining size (e.g. true=ignore setFloatXXX values). */
JTB.SizeHelper.prototype.setFloatIgnore = function(b) {
if(this.float_ignore != b) {
this.float_ignore = b;
if(this.tb.isFloating()) {
this.refreshSizeData();
}
}
};
/** gets the preferred width of the element */
JTB.SizeHelper.prototype.getPreferredWidth = function() {
return this.width;
};
/** gets the preferred height of the element */
JTB.SizeHelper.prototype.getPreferredHeight = function() {
return this.height;
};
/** gets the current width of the element */
JTB.SizeHelper.prototype.getCurrentWidth = function() {
return this.e.offsetWidth;
};
/** gets the current height of the element */
JTB.SizeHelper.prototype.getCurrentHeight = function() {
return this.e.offsetHeight;
};
/** string representation */
JTB.SizeHelper.prototype.toString = function() {
return this.e.getAttribute('id') + ': ' +
'pref=' + this.width + '/' + this.height + ' ' +
'curr=' + this.getCurrentWidth() + '/' + this.getCurrentHeight() + ' ' +
'orient=' + this.vert_orient_width + '/' + this.horiz_orient_height + ' ' +
'float=' + this.float_width + '/' + this.float_height + ' ' + '(' + this.float_ignore + ')';
};
/** return the HTML representation of this link object */
JTB.ToolbarLink.prototype.makeLink = function() {
var orient = this.encToolbar.getOrientation();
var displayStyle = (orient == JTB.ORIENT_LEFT || orient == JTB.ORIENT_RIGHT) ? "block" : "table-cell";
if (typeof(this.link) == "string") {
// normal link
return '<div style="display: ' + displayStyle + '"> <a href="' + this.link + '">' + this.name + '</a> </div>';
}
else {
// link is actually a nested toolbar
var tbName = this.link.getToolbarName();
//return '<div onmouseover=\"JTB.showChildToolbar(\'' + tbName + '\', 100, 100)\">' + this.name + '</div>';
return '<div onmouseover=\"JTB.showChildToolbar(\'' + tbName + '\', JTB.findXOffset(\'' + tbName + '\', event)' + ', JTB.findYOffset(\'' + tbName + '\', event))\" style=\"display: ' + displayStyle + '">' + this.name + '</div>';
}
};
JTB.Toolbar.prototype.getParentToolbar = function () {
return this.tb_parent;
};
JTB.Toolbar.prototype.setParentToolbar = function (tb) {
this.tb_parent = tb;
return this;
};
/** get the name of the element the toolbar is attached to (may be null) */
JTB.Toolbar.prototype.getContentName = function() {
if(this.tb_parent === null) {
return this.content_id;
}
else {
return this.tb_parent.getContentName();
}
};
/** set the name of the element the toolbar is attached to */
JTB.Toolbar.prototype.setContentName = function(content_name) {
if(this.tb_parent === null) {
this.content_id = content_name;
}
else {
this.tb_parent.setContentName(content_name);
}
return this;
};
/** get the parent element of the toolbar and its attached content (may be null) */
JTB.Toolbar.prototype.getParent = function() {
var content = this.getContent();
if(content === null) {
return null;
}
else {
return content.parentNode;
}
};
/** get the container element which holds toolbar and its attached content (may be null) */
JTB.Toolbar.prototype.getContainer = function() {
if(this.tb_parent === null) {
return this.e_container;
}
else {
return this.tb_parent.getContainer();
}
};
/** get the container size information (may be null on unattached
* child toolbars) */
JTB.Toolbar.prototype.getContainerSize = function() {
if(this.tb_parent === null) {
return this.sz_container;
}
else {
return this.tb_parent.getContainerSize();
}
};
/** get the content element to which the toolbar is attached (may be null) */
JTB.Toolbar.prototype.getContent = function() {
if(this.tb_parent === null) {
return this.e_content;
}
else {
return this.tb_parent.getContent();
}
};
/** return the name of the element containing the toolbar */
JTB.Toolbar.prototype.getToolbarName = function() {
return this.tb_id;
};
/** shows a child toolbar (makes childToolbar a child if it isn't already one) */
JTB.Toolbar.prototype.showChildToolbar = function(childToolbar, x, y) {
/* remove the child from any old parent */
childToolbar.hideFromParentToolbar();
/* tell the child toolbar it belongs to us now */
childToolbar.tb_parent = this;
/* copy parent's styles into child unless the child has its own */
var cs = childToolbar.e_tb.style;
var ps = this.e_tb.style;
if(cs.backgroundColor==='') { cs.backgroundColor = ps.backgroundColor; }
if(cs.backgroundImage==='') { cs.backgroundImage = ps.backgroundImage; }
if(cs.backgroundRepeat==='') { cs.backgroundRepeat = ps.backgroundRepeat; }
if(cs.backgroundAttachment==='') { cs.backgroundAttachment = ps.backgroundAttachment; }
if(cs.backgroundPosition==='') { cs.backgroundPosition = ps.backgroundPosition; }
if(cs.border==='') { cs.border = ps.border; }
if(childToolbar.e_tb.getAttribute('class')==='') {
childToolbar.e_tb.setAttribute('class', this.e_tb.getAttribute('class'));
}
/* float the child to the correct position */
childToolbar.floatx = x;
childToolbar.floaty = y;
/* put the child at the same depth as its parent */
childToolbar.e_tb.style.zIndex = this.e_tb.style.zIndex;
/* make sure the child is in the container */
var container = this.getContainer();
if(container !== null) {
container.appendChild(childToolbar.e_tb);
}
/* show the child */
this.vis_tb_child = childToolbar;
childToolbar.setState(JTB.STATE_VIS);
this.refreshGfx();
return this;
};
/** returns true if this is a child toolbar */
JTB.Toolbar.prototype.isChildToolbar = function() {
return this.e_content === null;
};
/** hides a child toolbar */
JTB.Toolbar.prototype.hideFromParentToolbar = function() {
var e = this;
if(e.tb_parent !== null) {
if(e.tb_parent.vis_tb_child == e) {
e.tb_parent.vis_tb_child = null;
e.setState(JTB.STATE_INVIS);
e.tb_parent.refreshGfx();
}
}
};
/** get the location of the toolbar on its parent */
JTB.Toolbar.prototype.getOrientation = function() {
return this.orient;
};
/** returns true if the toolbar is side-oriented */
JTB.Toolbar.prototype.isSideOriented = function() {
return (this.orient==JTB.ORIENT_LEFT || this.orient==JTB.ORIENT_RIGHT);
};
/** set the location of the toolbar on its parent */
JTB.Toolbar.prototype.setOrientation = function(orient) {
if(orient != this.orient) {
this.orient = orient;
this.refreshGfx();
createCookie("orient", this.orient, COOKIE_LIFETIME_DAYS);
}
return this;
};
/** get whether the toolbar is docked */
JTB.Toolbar.prototype.isDocked = function() {
return !this.isChildToolbar() && this.docked;
};
/** get whether the toolbar is floating */
JTB.Toolbar.prototype.isFloating = function() {
return !this.isDocked();
};
/** set whether the toolbar is docked */
JTB.Toolbar.prototype.setDocked = function(b) {
this.docked = !this.isChildToolbar() && b;
this.refreshGfx();
createBooleanCookie("docked", this.docked, COOKIE_LIFETIME_DAYS);
return this;
};
/** get the docking threshold */
JTB.Toolbar.prototype.getDockingThreshold = function() {
return this.docking_threshold;
};
/** set the docking threshold */
JTB.Toolbar.prototype.setDockingThreshold = function(thresh) {
this.docking_threshold = thresh;
return this;
};
/** get the float x offset of this toolbar from its parent */
JTB.Toolbar.prototype.getFloatPosX = function() {
return this.floatx;
};
/** set the float x offset of this toolbar from its parent */
JTB.Toolbar.prototype.setFloatPosX = function(x) {
this.setFloatPos(x, this.floaty);
return this;
};
/** get the float y offset of this toolbar from its parent */
JTB.Toolbar.prototype.getFloatPosY = function() {
return this.floaty;
};
/** set the float y offset of this toolbar from its parent */
JTB.Toolbar.prototype.setFloatPosY = function(y) {
this.setFloatPos(this.floatx, y);
return this;
};
/** set the float offsets of this toolbar from its parent */
JTB.Toolbar.prototype.setFloatPos = function(x, y) {
this.floatx = x;
this.floaty = y;
if(this.isFloating()) {
this.refreshGfx();
}
createCookie("floatx", this.floatx, COOKIE_LIFETIME_DAYS);
createCookie("floaty", this.floaty, COOKIE_LIFETIME_DAYS);
return this;
};
/** get whether the toolbar is clamped to the container's size when floating */
JTB.Toolbar.prototype.isClampFloatingToolbarSize = function() {
return this.clamp_size_on_float;
};
/** set whether the toolbar is clamped to the container's size when floating */
JTB.Toolbar.prototype.setClampFloatingToolbarSize = function(b) {
this.clamp_size_on_float = b;
if(this.isFloating()) {
this.refreshGfx();
}
return this;
};
/** returns true if an animation is going on */
JTB.Toolbar.prototype.isAnimating = function() {
return (this.anim_start != -1);
};
/** set toolbar attributes so it displays according to the current Toolbar state */
JTB.Toolbar.prototype.refreshGfx = function() {
/* efficiency: hide the toolbar container while we arrange it */
var container = this.getContainer();
var sz_container = this.getContainerSize();
var sz_container_w=0, sz_container_h=0;
if(sz_container !== null) {
sz_container.refreshSizeData();
sz_container_w = sz_container.getPreferredWidth();
sz_container_h = sz_container.getPreferredHeight();
}
else {