-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathjquery.layout.js
2513 lines (2272 loc) · 81 KB
/
jquery.layout.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
/*
* jquery.layout 1.2.0
*
* Copyright (c) 2008
* Fabrizio Balliano (http://www.fabrizioballiano.net)
* Kevin Dalman (http://allpro.net)
*
* Dual licensed under the GPL (http://www.gnu.org/licenses/gpl.html)
* and MIT (http://www.opensource.org/licenses/mit-license.php) licenses.
*
* $Date: 2008-12-27 02:17:22 +0100 (sab, 27 dic 2008) $
* $Rev: 203 $
*
* NOTE: For best code readability, view this with a fixed-space font and tabs equal to 4-chars
*/
(function($) {
$.fn.layout = function (opts) {
/*
* ###########################
* WIDGET CONFIG & OPTIONS
* ###########################
*/
// DEFAULTS for options
var
prefix = "ui-layout-" // prefix for ALL selectors and classNames
, defaults = { // misc default values
paneClass: prefix+"pane" // ui-layout-pane
, resizerClass: prefix+"resizer" // ui-layout-resizer
, togglerClass: prefix+"toggler" // ui-layout-toggler
, togglerInnerClass: prefix+"" // ui-layout-open / ui-layout-closed
, buttonClass: prefix+"button" // ui-layout-button
, contentSelector: "."+prefix+"content"// ui-layout-content
, contentIgnoreSelector: "."+prefix+"ignore" // ui-layout-mask
}
;
// DEFAULT PANEL OPTIONS - CHANGE IF DESIRED
var options = {
name: "" // FUTURE REFERENCE - not used right now
, scrollToBookmarkOnLoad: true // after creating a layout, scroll to bookmark in URL (.../page.htm#myBookmark)
, defaults: { // default options for 'all panes' - will be overridden by 'per-pane settings'
applyDefaultStyles: false // apply basic styles directly to resizers & buttons? If not, then stylesheet must handle it
, closable: true // pane can open & close
, resizable: true // when open, pane can be resized
, slidable: true // when closed, pane can 'slide' open over other panes - closes on mouse-out
//, paneSelector: [ ] // MUST be pane-specific!
, contentSelector: defaults.contentSelector // INNER div/element to auto-size so only it scrolls, not the entire pane!
, contentIgnoreSelector: defaults.contentIgnoreSelector // elem(s) to 'ignore' when measuring 'content'
, paneClass: defaults.paneClass // border-Pane - default: 'ui-layout-pane'
, resizerClass: defaults.resizerClass // Resizer Bar - default: 'ui-layout-resizer'
, togglerClass: defaults.togglerClass // Toggler Button - default: 'ui-layout-toggler'
, buttonClass: defaults.buttonClass // CUSTOM Buttons - default: 'ui-layout-button-toggle/-open/-close/-pin'
, resizerDragOpacity: 1 // option for ui.draggable
//, resizerCursor: "" // MUST be pane-specific - cursor when over resizer-bar
, maskIframesOnResize: true // true = all iframes OR = iframe-selector(s) - adds masking-div during resizing/dragging
//, size: 100 // inital size of pane - defaults are set 'per pane'
, minSize: 0 // when manually resizing a pane
, maxSize: 0 // ditto, 0 = no limit
, spacing_open: 6 // space between pane and adjacent panes - when pane is 'open'
, spacing_closed: 6 // ditto - when pane is 'closed'
, togglerLength_open: 50 // Length = WIDTH of toggler button on north/south edges - HEIGHT on east/west edges
, togglerLength_closed: 50 // 100% OR -1 means 'full height/width of resizer bar' - 0 means 'hidden'
, togglerAlign_open: "center" // top/left, bottom/right, center, OR...
, togglerAlign_closed: "center" // 1 => nn = offset from top/left, -1 => -nn == offset from bottom/right
, togglerTip_open: "Close" // Toggler tool-tip (title)
, togglerTip_closed: "Open" // ditto
, resizerTip: "Resize" // Resizer tool-tip (title)
, sliderTip: "Slide Open" // resizer-bar triggers 'sliding' when pane is closed
, sliderCursor: "pointer" // cursor when resizer-bar will trigger 'sliding'
, slideTrigger_open: "click" // click, dblclick, mouseover
, slideTrigger_close: "mouseout" // click, mouseout
, hideTogglerOnSlide: false // when pane is slid-open, should the toggler show?
, togglerContent_open: "" // text or HTML to put INSIDE the toggler
, togglerContent_closed: "" // ditto
, showOverflowOnHover: false // will bind allowOverflow() utility to pane.onMouseOver
, enableCursorHotkey: true // enabled 'cursor' hotkeys
//, customHotkey: "" // MUST be pane-specific - EITHER a charCode OR a character
, customHotkeyModifier: "SHIFT" // either 'SHIFT', 'CTRL' or 'CTRL+SHIFT' - NOT 'ALT'
// NOTE: fxSss_open & fxSss_close options (eg: fxName_open) are auto-generated if not passed
, fxName: "slide" // ('none' or blank), slide, drop, scale
, fxSpeed: null // slow, normal, fast, 200, nnn - if passed, will OVERRIDE fxSettings.duration
, fxSettings: {} // can be passed, eg: { easing: "easeOutBounce", duration: 1500 }
, initClosed: false // true = init pane as 'closed'
, initHidden: false // true = init pane as 'hidden' - no resizer or spacing
/* callback options do not have to be set - listed here for reference only
, onshow_start: "" // CALLBACK when pane STARTS to Show - BEFORE onopen/onhide_start
, onshow_end: "" // CALLBACK when pane ENDS being Shown - AFTER onopen/onhide_end
, onhide_start: "" // CALLBACK when pane STARTS to Close - BEFORE onclose_start
, onhide_end: "" // CALLBACK when pane ENDS being Closed - AFTER onclose_end
, onopen_start: "" // CALLBACK when pane STARTS to Open
, onopen_end: "" // CALLBACK when pane ENDS being Opened
, onclose_start: "" // CALLBACK when pane STARTS to Close
, onclose_end: "" // CALLBACK when pane ENDS being Closed
, onresize_start: "" // CALLBACK when pane STARTS to be ***MANUALLY*** Resized
, onresize_end: "" // CALLBACK when pane ENDS being Resized ***FOR ANY REASON***
*/
}
, north: {
paneSelector: "."+prefix+"north" // default = .ui-layout-north
, size: "auto"
, resizerCursor: "n-resize"
}
, south: {
paneSelector: "."+prefix+"south" // default = .ui-layout-south
, size: "auto"
, resizerCursor: "s-resize"
}
, east: {
paneSelector: "."+prefix+"east" // default = .ui-layout-east
, size: 200
, resizerCursor: "e-resize"
}
, west: {
paneSelector: "."+prefix+"west" // default = .ui-layout-west
, size: 200
, resizerCursor: "w-resize"
}
, center: {
paneSelector: "."+prefix+"center" // default = .ui-layout-center
}
};
var effects = { // LIST *PREDEFINED EFFECTS* HERE, even if effect has no settings
slide: {
all: { duration: "fast" } // eg: duration: 1000, easing: "easeOutBounce"
, north: { direction: "up" }
, south: { direction: "down" }
, east: { direction: "right"}
, west: { direction: "left" }
}
, drop: {
all: { duration: "slow" } // eg: duration: 1000, easing: "easeOutQuint"
, north: { direction: "up" }
, south: { direction: "down" }
, east: { direction: "right"}
, west: { direction: "left" }
}
, scale: {
all: { duration: "fast" }
}
};
// STATIC, INTERNAL CONFIG - DO NOT CHANGE THIS!
var config = {
allPanes: "north,south,east,west,center"
, borderPanes: "north,south,east,west"
, zIndex: { // set z-index values here
resizer_normal: 1 // normal z-index for resizer-bars
, pane_normal: 2 // normal z-index for panes
, mask: 4 // overlay div used to mask pane(s) during resizing
, sliding: 100 // applied to both the pane and its resizer when a pane is 'slid open'
, resizing: 10000 // applied to the CLONED resizer-bar when being 'dragged'
, animation: 10000 // applied to the pane when being animated - not applied to the resizer
}
, resizers: {
cssReq: {
position: "absolute"
, padding: 0
, margin: 0
, fontSize: "1px"
, textAlign: "left" // to counter-act "center" alignment!
, overflow: "hidden" // keep toggler button from overflowing
, zIndex: 1
}
, cssDef: { // DEFAULT CSS - applied if: options.PANE.applyDefaultStyles=true
background: "#DDD"
, border: "none"
}
}
, togglers: {
cssReq: {
position: "absolute"
, display: "block"
, padding: 0
, margin: 0
, overflow: "hidden"
, textAlign: "center"
, fontSize: "1px"
, cursor: "pointer"
, zIndex: 1
}
, cssDef: { // DEFAULT CSS - applied if: options.PANE.applyDefaultStyles=true
background: "#AAA"
}
}
, content: {
cssReq: {
overflow: "auto"
}
, cssDef: {}
}
, defaults: { // defaults for ALL panes - overridden by 'per-pane settings' below
cssReq: {
position: "absolute"
, margin: 0
, zIndex: 2
}
, cssDef: {
padding: "10px"
, background: "#FFF"
, border: "1px solid #BBB"
, overflow: "auto"
}
}
, north: {
edge: "top"
, sizeType: "height"
, dir: "horz"
, cssReq: {
top: 0
, bottom: "auto"
, left: 0
, right: 0
, width: "auto"
// height: DYNAMIC
}
}
, south: {
edge: "bottom"
, sizeType: "height"
, dir: "horz"
, cssReq: {
top: "auto"
, bottom: 0
, left: 0
, right: 0
, width: "auto"
// height: DYNAMIC
}
}
, east: {
edge: "right"
, sizeType: "width"
, dir: "vert"
, cssReq: {
left: "auto"
, right: 0
, top: "auto" // DYNAMIC
, bottom: "auto" // DYNAMIC
, height: "auto"
// width: DYNAMIC
}
}
, west: {
edge: "left"
, sizeType: "width"
, dir: "vert"
, cssReq: {
left: 0
, right: "auto"
, top: "auto" // DYNAMIC
, bottom: "auto" // DYNAMIC
, height: "auto"
// width: DYNAMIC
}
}
, center: {
dir: "center"
, cssReq: {
left: "auto" // DYNAMIC
, right: "auto" // DYNAMIC
, top: "auto" // DYNAMIC
, bottom: "auto" // DYNAMIC
, height: "auto"
, width: "auto"
}
}
};
// DYNAMIC DATA
var state = {
// generate random 'ID#' to identify layout - used to create global namespace for timers
id: Math.floor(Math.random() * 10000)
, container: {}
, north: {}
, south: {}
, east: {}
, west: {}
, center: {}
};
var
altEdge = {
top: "bottom"
, bottom: "top"
, left: "right"
, right: "left"
}
, altSide = {
north: "south"
, south: "north"
, east: "west"
, west: "east"
}
;
/*
* ###########################
* INTERNAL HELPER FUNCTIONS
* ###########################
*/
/**
* isStr
*
* Returns true if passed param is EITHER a simple string OR a 'string object' - otherwise returns false
*/
var isStr = function (o) {
if (typeof o == "string")
return true;
else if (typeof o == "object") {
try {
var match = o.constructor.toString().match(/string/i);
return (match !== null);
} catch (e) {}
}
return false;
};
/**
* str
*
* Returns a simple string if the passed param is EITHER a simple string OR a 'string object',
* else returns the original object
*/
var str = function (o) {
if (typeof o == "string" || isStr(o)) return $.trim(o); // trim converts 'String object' to a simple string
else return o;
};
/**
* min / max
*
* Alias for Math.min/.max to simplify coding
*/
var min = function (x,y) { return Math.min(x,y); };
var max = function (x,y) { return Math.max(x,y); };
/**
* transformData
*
* Processes the options passed in and transforms them into the format used by layout()
* Missing keys are added, and converts the data if passed in 'flat-format' (no sub-keys)
* In flat-format, pane-specific-settings are prefixed like: north__optName (2-underscores)
* To update effects, options MUST use nested-keys format, with an effects key
*
* @callers initOptions()
* @params JSON d Data/options passed by user - may be a single level or nested levels
* @returns JSON Creates a data struture that perfectly matches 'options', ready to be imported
*/
var transformData = function (d) {
var json = { defaults:{fxSettings:{}}, north:{fxSettings:{}}, south:{fxSettings:{}}, east:{fxSettings:{}}, west:{fxSettings:{}}, center:{fxSettings:{}} };
d = d || {};
if (d.effects || d.defaults || d.north || d.south || d.west || d.east || d.center)
json = $.extend( json, d ); // already in json format - add to base keys
else
// convert 'flat' to 'nest-keys' format - also handles 'empty' user-options
$.each( d, function (key,val) {
a = key.split("__");
json[ a[1] ? a[0] : "defaults" ][ a[1] ? a[1] : a[0] ] = val;
});
return json;
};
/**
* setFlowCallback
*
* Set an INTERNAL callback to avoid simultaneous animation
* Runs only if needed and only if all callbacks are not 'already set'!
*
* @param String action Either 'open' or 'close'
* @pane String pane A valid border-pane name, eg 'west'
* @pane Boolean param Extra param for callback (optional)
*/
var setFlowCallback = function (action, pane, param) {
var
cb = action +","+ pane +","+ (param ? 1 : 0)
, cP, cbPane
;
$.each(c.borderPanes.split(","), function (i,p) {
if (c[p].isMoving) {
bindCallback(p); // TRY to bind a callback
return false; // BREAK
}
});
function bindCallback (p, test) {
cP = c[p];
if (!cP.doCallback) {
cP.doCallback = true;
cP.callback = cb;
}
else { // try to 'chain' this callback
cpPane = cP.callback.split(",")[1]; // 2nd param is 'pane'
if (cpPane != p && cpPane != pane) // callback target NOT 'itself' and NOT 'this pane'
bindCallback (cpPane, true); // RECURSE
}
}
};
/**
* execFlowCallback
*
* RUN the INTERNAL callback for this pane - if one exists
*
* @param String action Either 'open' or 'close'
* @pane String pane A valid border-pane name, eg 'west'
* @pane Boolean param Extra param for callback (optional)
*/
var execFlowCallback = function (pane) {
var cP = c[pane];
// RESET flow-control flaGs
c.isLayoutBusy = false;
delete cP.isMoving;
if (!cP.doCallback || !cP.callback) return;
cP.doCallback = false; // RESET logic flag
// EXECUTE the callback
var
cb = cP.callback.split(",")
, param = (cb[2] > 0 ? true : false)
;
if (cb[0] == "open")
open( cb[1], param );
else if (cb[0] == "close")
close( cb[1], param );
if (!cP.doCallback) cP.callback = null; // RESET - unless callback above enabled it again!
};
/**
* execUserCallback
*
* Executes a Callback function after a trigger event, like resize, open or close
*
* @param String pane This is passed only so we can pass the 'pane object' to the callback
* @param String v_fn Accepts a function name, OR a comma-delimited array: [0]=function name, [1]=argument
*/
var execUserCallback = function (pane, v_fn) {
if (!v_fn) return;
var fn;
try {
if (typeof v_fn == "function")
fn = v_fn;
else if (typeof v_fn != "string")
return;
else if (v_fn.indexOf(",") > 0) {
// function name cannot contain a comma, so must be a function name AND a 'name' parameter
var
args = v_fn.split(",")
, fn = eval(args[0])
;
if (typeof fn=="function" && args.length > 1)
return fn(args[1]); // pass the argument parsed from 'list'
}
else // just the name of an external function?
fn = eval(v_fn);
if (typeof fn=="function")
// pass data: pane-name, pane-element, pane-state, pane-options, and layout-name
return fn( pane, $Ps[pane], $.extend({},state[pane]), $.extend({},options[pane]), options.name );
}
catch (ex) {}
};
/**
* cssNum
*
* Returns the 'current CSS value' for an element - returns 0 if property does not exist
*
* @callers Called by many methods
* @param jQuery $Elem Must pass a jQuery object - first element is processed
* @param String property The name of the CSS property, eg: top, width, etc.
* @returns Variant Usually is used to get an integer value for position (top, left) or size (height, width)
*/
var cssNum = function ($E, prop) {
var
val = 0
, hidden = false
, visibility = ""
;
if (!$.browser.msie) { // IE CAN read dimensions of 'hidden' elements - FF CANNOT
if ($.curCSS($E[0], "display", true) == "none") {
hidden = true;
visibility = $.curCSS($E[0], "visibility", true); // SAVE current setting
$E.css({ display: "block", visibility: "hidden" }); // show element 'invisibly' so we can measure it
}
}
val = parseInt($.curCSS($E[0], prop, true), 10) || 0;
if (hidden) { // WAS hidden, so put back the way it was
$E.css({ display: "none" });
if (visibility && visibility != "hidden")
$E.css({ visibility: visibility }); // reset 'visibility'
}
return val;
};
/**
* cssW / cssH / cssSize
*
* Contains logic to check boxModel & browser, and return the correct width/height for the current browser/doctype
*
* @callers initPanes(), sizeMidPanes(), initHandles(), sizeHandles()
* @param Variant elem Can accept a 'pane' (east, west, etc) OR a DOM object OR a jQuery object
* @param Integer outerWidth/outerHeight (optional) Can pass a width, allowing calculations BEFORE element is resized
* @returns Integer Returns the innerHeight of the elem by subtracting padding and borders
*
* @TODO May need to add additional logic to handle more browser/doctype variations?
*/
var cssW = function (e, outerWidth) {
var $E;
if (isStr(e)) {
e = str(e);
$E = $Ps[e];
}
else
$E = $(e);
// a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
if (outerWidth <= 0)
return 0;
else if (!(outerWidth>0))
outerWidth = isStr(e) ? getPaneSize(e) : $E.outerWidth();
if (!$.boxModel)
return outerWidth;
else // strip border and padding size from outerWidth to get CSS Width
return outerWidth
- cssNum($E, "paddingLeft")
- cssNum($E, "paddingRight")
- ($.curCSS($E[0], "borderLeftStyle", true) == "none" ? 0 : cssNum($E, "borderLeftWidth"))
- ($.curCSS($E[0], "borderRightStyle", true) == "none" ? 0 : cssNum($E, "borderRightWidth"))
;
};
var cssH = function (e, outerHeight) {
var $E;
if (isStr(e)) {
e = str(e);
$E = $Ps[e];
}
else
$E = $(e);
// a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
if (outerHeight <= 0)
return 0;
else if (!(outerHeight>0))
outerHeight = (isStr(e)) ? getPaneSize(e) : $E.outerHeight();
if (!$.boxModel)
return outerHeight;
else // strip border and padding size from outerHeight to get CSS Height
return outerHeight
- cssNum($E, "paddingTop")
- cssNum($E, "paddingBottom")
- ($.curCSS($E[0], "borderTopStyle", true) == "none" ? 0 : cssNum($E, "borderTopWidth"))
- ($.curCSS($E[0], "borderBottomStyle", true) == "none" ? 0 : cssNum($E, "borderBottomWidth"))
;
};
var cssSize = function (pane, outerSize) {
if (c[pane].dir=="horz") // pane = north or south
return cssH(pane, outerSize);
else // pane = east or west
return cssW(pane, outerSize);
};
/**
* getPaneSize
*
* Calculates the current 'size' (width or height) of a border-pane - optionally with 'pane spacing' added
*
* @returns Integer Returns EITHER Width for east/west panes OR Height for north/south panes - adjusted for boxModel & browser
*/
var getPaneSize = function (pane, inclSpace) {
var
$P = $Ps[pane]
, o = options[pane]
, s = state[pane]
, oSp = (inclSpace ? o.spacing_open : 0)
, cSp = (inclSpace ? o.spacing_closed : 0)
;
if (!$P || s.isHidden)
return 0;
else if (s.isClosed || (s.isSliding && inclSpace))
return cSp;
else if (c[pane].dir == "horz")
return $P.outerHeight() + oSp;
else // dir == "vert"
return $P.outerWidth() + oSp;
};
var setPaneMinMaxSizes = function (pane) {
var
d = cDims
, edge = c[pane].edge
, dir = c[pane].dir
, o = options[pane]
, s = state[pane]
, $P = $Ps[pane]
, $altPane = $Ps[ altSide[pane] ]
, paneSpacing = o.spacing_open
, altPaneSpacing = options[ altSide[pane] ].spacing_open
, altPaneSize = (!$altPane ? 0 : (dir=="horz" ? $altPane.outerHeight() : $altPane.outerWidth()))
, containerSize = (dir=="horz" ? d.innerHeight : d.innerWidth)
// limitSize prevents this pane from 'overlapping' opposite pane - even if opposite pane is currently closed
, limitSize = containerSize - paneSpacing - altPaneSize - altPaneSpacing
, minSize = s.minSize || 0
, maxSize = Math.min(s.maxSize || 9999, limitSize)
, minPos, maxPos // used to set resizing limits
;
switch (pane) {
case "north": minPos = d.offsetTop + minSize;
maxPos = d.offsetTop + maxSize;
break;
case "west": minPos = d.offsetLeft + minSize;
maxPos = d.offsetLeft + maxSize;
break;
case "south": minPos = d.offsetTop + d.innerHeight - maxSize;
maxPos = d.offsetTop + d.innerHeight - minSize;
break;
case "east": minPos = d.offsetLeft + d.innerWidth - maxSize;
maxPos = d.offsetLeft + d.innerWidth - minSize;
break;
}
// save data to pane-state
$.extend(s, { minSize: minSize, maxSize: maxSize, minPosition: minPos, maxPosition: maxPos });
};
/**
* getPaneDims
*
* Returns data for setting the size/position of center pane. Date is also used to set Height for east/west panes
*
* @returns JSON Returns a hash of all dimensions: top, bottom, left, right, (outer) width and (outer) height
*/
var getPaneDims = function () {
var d = {
top: getPaneSize("north", true) // true = include 'spacing' value for p
, bottom: getPaneSize("south", true)
, left: getPaneSize("west", true)
, right: getPaneSize("east", true)
, width: 0
, height: 0
};
with (d) {
width = cDims.innerWidth - left - right;
height = cDims.innerHeight - bottom - top;
// now add the 'container border/padding' to get final positions - relative to the container
top += cDims.top;
bottom += cDims.bottom;
left += cDims.left;
right += cDims.right;
}
return d;
};
/**
* getElemDims
*
* Returns data for setting size of an element (container or a pane).
*
* @callers create(), onWindowResize() for container, plus others for pane
* @returns JSON Returns a hash of all dimensions: top, bottom, left, right, outerWidth, innerHeight, etc
*/
var getElemDims = function ($E) {
var
d = {} // dimensions hash
, e, b, p // edge, border, padding
;
$.each("Left,Right,Top,Bottom".split(","), function () {
e = str(this);
b = d["border" +e] = cssNum($E, "border"+e+"Width");
p = d["padding"+e] = cssNum($E, "padding"+e);
d["offset" +e] = b + p; // total offset of content from outer edge
// if BOX MODEL, then 'position' = PADDING (ignore borderWidth)
if ($E == $Container)
d[e.toLowerCase()] = ($.boxModel ? p : 0);
});
d.innerWidth = d.outerWidth = $E.outerWidth();
d.innerHeight = d.outerHeight = $E.outerHeight();
if ($.boxModel) {
d.innerWidth -= (d.offsetLeft + d.offsetRight);
d.innerHeight -= (d.offsetTop + d.offsetBottom);
}
return d;
};
var setTimer = function (pane, action, fn, ms) {
var
Layout = window.layout = window.layout || {}
, Timers = Layout.timers = Layout.timers || {}
, name = "layout_"+ state.id +"_"+ pane +"_"+ action // UNIQUE NAME for every layout-pane-action
;
if (Timers[name]) return; // timer already set!
else Timers[name] = setTimeout(fn, ms);
};
var clearTimer = function (pane, action) {
var
Layout = window.layout = window.layout || {}
, Timers = Layout.timers = Layout.timers || {}
, name = "layout_"+ state.id +"_"+ pane +"_"+ action // UNIQUE NAME for every layout-pane-action
;
if (Timers[name]) {
clearTimeout( Timers[name] );
delete Timers[name];
return true;
}
else
return false;
};
/*
* ###########################
* INITIALIZATION METHODS
* ###########################
*/
/**
* create
*
* Initialize the layout - called automatically whenever an instance of layout is created
*
* @callers NEVER explicity called
* @returns An object pointer to the instance created
*/
var create = function () {
// initialize config/options
initOptions();
// initialize all objects
initContainer(); // set CSS as needed and init state.container dimensions
initPanes(); // size & position all panes
initHandles(); // create and position all resize bars & togglers buttons
initResizable(); // activate resizing on all panes where resizable=true
sizeContent("all"); // AFTER panes & handles have been initialized, size 'content' divs
if (options.scrollToBookmarkOnLoad)
with (self.location) if (hash) replace( hash ); // scrollTo Bookmark
// bind hotkey function - keyDown - if required
initHotkeys();
// bind resizeAll() for 'this layout instance' to window.resize event
$(window).resize(function () {
var timerID = "timerLayout_"+state.id;
if (window[timerID]) clearTimeout(window[timerID]);
window[timerID] = null;
if (true || $.browser.msie) // use a delay for IE because the resize event fires repeatly
window[timerID] = setTimeout(resizeAll, 100);
else // most other browsers have a built-in delay before firing the resize event
resizeAll(); // resize all layout elements NOW!
});
};
/**
* initContainer
*
* Validate and initialize container CSS and events
*
* @callers create()
*/
var initContainer = function () {
try { // format html/body if this is a full page layout
if ($Container[0].tagName == "BODY") {
$("html").css({
height: "100%"
, overflow: "hidden"
});
$("body").css({
position: "relative"
, height: "100%"
, overflow: "hidden"
, margin: 0
, padding: 0 // TODO: test whether body-padding could be handled?
, border: "none" // a body-border creates problems because it cannot be measured!
});
}
else { // set required CSS - overflow and position
var
CSS = { overflow: "hidden" } // make sure container will not 'scroll'
, p = $Container.css("position")
, h = $Container.css("height")
;
// if this is a NESTED layout, then outer-pane ALREADY has position and height
if (!$Container.hasClass("ui-layout-pane")) {
if (!p || "fixed,absolute,relative".indexOf(p) < 0)
CSS.position = "relative"; // container MUST have a 'position'
if (!h || h=="auto")
CSS.height = "100%"; // container MUST have a 'height'
}
$Container.css( CSS );
}
} catch (ex) {}
// get layout-container dimensions (updated when necessary)
cDims = state.container = getElemDims( $Container ); // update data-pointer too
};
/**
* initHotkeys
*
* Bind layout hotkeys - if options enabled
*
* @callers create()
*/
var initHotkeys = function () {
// bind keyDown to capture hotkeys, if option enabled for ANY pane
$.each(c.borderPanes.split(","), function (i,pane) {
var o = options[pane];
if (o.enableCursorHotkey || o.customHotkey) {
$(document).keydown( keyDown ); // only need to bind this ONCE
return false; // BREAK - binding was done
}
});
};
/**
* initOptions
*
* Build final CONFIG and OPTIONS data
*
* @callers create()
*/
var initOptions = function () {
// simplify logic by making sure passed 'opts' var has basic keys
opts = transformData( opts );
// update default effects, if case user passed key
if (opts.effects) {
$.extend( effects, opts.effects );
delete opts.effects;
}
// see if any 'global options' were specified
$.each("name,scrollToBookmarkOnLoad".split(","), function (idx,key) {
if (opts[key] !== undefined)
options[key] = opts[key];
else if (opts.defaults[key] !== undefined) {
options[key] = opts.defaults[key];
delete opts.defaults[key];
}
});
// remove any 'defaults' that MUST be set 'per-pane'
$.each("paneSelector,resizerCursor,customHotkey".split(","),
function (idx,key) { delete opts.defaults[key]; } // is OK if key does not exist
);
// now update options.defaults
$.extend( options.defaults, opts.defaults );
// make sure required sub-keys exist
//if (typeof options.defaults.fxSettings != "object") options.defaults.fxSettings = {};
// merge all config & options for the 'center' pane
c.center = $.extend( true, {}, c.defaults, c.center );
$.extend( options.center, opts.center );
// Most 'default options' do not apply to 'center', so add only those that DO
var o_Center = $.extend( true, {}, options.defaults, opts.defaults, options.center ); // TEMP data
$.each("paneClass,contentSelector,contentIgnoreSelector,applyDefaultStyles,showOverflowOnHover".split(","),
function (idx,key) { options.center[key] = o_Center[key]; }
);
var defs = options.defaults;
// create a COMPLETE set of options for EACH border-pane
$.each(c.borderPanes.split(","), function(i,pane) {
// apply 'pane-defaults' to CONFIG.PANE
c[pane] = $.extend( true, {}, c.defaults, c[pane] );
// apply 'pane-defaults' + user-options to OPTIONS.PANE
o = options[pane] = $.extend( true, {}, options.defaults, options[pane], opts.defaults, opts[pane] );
// make sure we have base-classes
if (!o.paneClass) o.paneClass = defaults.paneClass;
if (!o.resizerClass) o.resizerClass = defaults.resizerClass;
if (!o.togglerClass) o.togglerClass = defaults.togglerClass;
// create FINAL fx options for each pane, ie: options.PANE.fxName/fxSpeed/fxSettings[_open|_close]
$.each(["_open","_close",""], function (i,n) {
var
sName = "fxName"+n
, sSpeed = "fxSpeed"+n
, sSettings = "fxSettings"+n
;
// recalculate fxName according to specificity rules
o[sName] =
opts[pane][sName] // opts.west.fxName_open
|| opts[pane].fxName // opts.west.fxName
|| opts.defaults[sName] // opts.defaults.fxName_open
|| opts.defaults.fxName // opts.defaults.fxName
|| o[sName] // options.west.fxName_open
|| o.fxName // options.west.fxName
|| defs[sName] // options.defaults.fxName_open
|| defs.fxName // options.defaults.fxName
|| "none"
;
// validate fxName to be sure is a valid effect
var fxName = o[sName];
if (fxName == "none" || !$.effects || !$.effects[fxName] || (!effects[fxName] && !o[sSettings] && !o.fxSettings))
fxName = o[sName] = "none"; // effect not loaded, OR undefined FX AND fxSettings not passed
// set vars for effects subkeys to simplify logic
var
fx = effects[fxName] || {} // effects.slide
, fx_all = fx.all || {} // effects.slide.all
, fx_pane = fx[pane] || {} // effects.slide.west
;
// RECREATE the fxSettings[_open|_close] keys using specificity rules
o[sSettings] = $.extend(
{}
, fx_all // effects.slide.all
, fx_pane // effects.slide.west
, defs.fxSettings || {} // options.defaults.fxSettings
, defs[sSettings] || {} // options.defaults.fxSettings_open
, o.fxSettings // options.west.fxSettings
, o[sSettings] // options.west.fxSettings_open
, opts.defaults.fxSettings // opts.defaults.fxSettings
, opts.defaults[sSettings] || {} // opts.defaults.fxSettings_open
, opts[pane].fxSettings // opts.west.fxSettings
, opts[pane][sSettings] || {} // opts.west.fxSettings_open
);
// recalculate fxSpeed according to specificity rules
o[sSpeed] =
opts[pane][sSpeed] // opts.west.fxSpeed_open
|| opts[pane].fxSpeed // opts.west.fxSpeed (pane-default)
|| opts.defaults[sSpeed] // opts.defaults.fxSpeed_open
|| opts.defaults.fxSpeed // opts.defaults.fxSpeed
|| o[sSpeed] // options.west.fxSpeed_open
|| o[sSettings].duration // options.west.fxSettings_open.duration
|| o.fxSpeed // options.west.fxSpeed
|| o.fxSettings.duration // options.west.fxSettings.duration
|| defs.fxSpeed // options.defaults.fxSpeed
|| defs.fxSettings.duration// options.defaults.fxSettings.duration
|| fx_pane.duration // effects.slide.west.duration
|| fx_all.duration // effects.slide.all.duration
|| "normal" // DEFAULT
;
// DEBUG: if (pane=="east") debugData( $.extend({}, {speed: o[sSpeed], fxSettings_duration: o[sSettings].duration}, o[sSettings]), pane+"."+sName+" = "+fxName );
});
});
};
/**
* initPanes
*
* Initialize module objects, styling, size and position for all panes
*
* @callers create()
*/
var initPanes = function () {
// NOTE: do north & south FIRST so we can measure their height - do center LAST
$.each(c.allPanes.split(","), function() {
var
pane = str(this)
, o = options[pane]
, s = state[pane]
, fx = s.fx
, dir = c[pane].dir
// if o.size is not > 0, then we will use MEASURE the pane and use that as it's 'size'
, size = o.size=="auto" || isNaN(o.size) ? 0 : o.size
, minSize = o.minSize || 1
, maxSize = o.maxSize || 9999
, spacing = o.spacing_open || 0
, sel = o.paneSelector
, isIE6 = ($.browser.msie && $.browser.version < 7)
, CSS = {}
, $P, $C
;
$Cs[pane] = false; // init
if (sel.substr(0,1)==="#") // ID selector
// NOTE: elements selected 'by ID' DO NOT have to be 'children'
$P = $Ps[pane] = $Container.find(sel+":first");
else { // class or other selector
$P = $Ps[pane] = $Container.children(sel+":first");