forked from meteor/meteor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.layout.js
5938 lines (5384 loc) · 203 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
/**
* @preserve
* jquery.layout 1.3.0 - Release Candidate 30.79
* $Date: 2013-01-12 08:00:00 (Sat, 12 Jan 2013) $
* $Rev: 303007 $
*
* Copyright (c) 2012
* 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.
*
* Changelog: http://layout.jquery-dev.net/changelog.cfm#1.3.0.rc30.79
*
* Docs: http://layout.jquery-dev.net/documentation.html
* Tips: http://layout.jquery-dev.net/tips.html
* Help: http://groups.google.com/group/jquery-ui-layout
*/
/* JavaDoc Info: http://code.google.com/closure/compiler/docs/js-for-compiler.html
* {!Object} non-nullable type (never NULL)
* {?string} nullable type (sometimes NULL) - default for {Object}
* {number=} optional parameter
* {*} ALL types
*/
/* TODO for jQ 2.0
* change .andSelf() to .addBack()
* $.fn.disableSelection won't work
*/
// NOTE: For best readability, view with a fixed-width font and tabs equal to 4-chars
;(function ($) {
// alias Math methods - used a lot!
var min = Math.min
, max = Math.max
, round = Math.floor
, isStr = function (v) { return $.type(v) === "string"; }
/**
* @param {!Object} Instance
* @param {Array.<string>} a_fn
*/
, runPluginCallbacks = function (Instance, a_fn) {
if ($.isArray(a_fn))
for (var i=0, c=a_fn.length; i<c; i++) {
var fn = a_fn[i];
try {
if (isStr(fn)) // 'name' of a function
fn = eval(fn);
if ($.isFunction(fn))
g(fn)( Instance );
} catch (ex) {}
}
function g (f) { return f; }; // compiler hack
}
;
/*
* GENERIC $.layout METHODS - used by all layouts
*/
$.layout = {
version: "1.3.rc30.79"
, revision: 0.033007 // 1.3.0 final = 1.0300 - major(n+).minor(nn)+patch(nn+)
// $.layout.browser REPLACES $.browser
, browser: {} // set below
// *PREDEFINED* EFFECTS & DEFAULTS
// MUST list effect here - OR MUST set an fxSettings option (can be an empty hash: {})
, effects: {
// Pane Open/Close Animations
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" }
, north: { direction: "up" }
, south: { direction: "down" }
, east: { direction: "right"}
, west: { direction: "left" }
}
, scale: {
all: { duration: "fast" }
}
// these are not recommended, but can be used
, blind: {}
, clip: {}
, explode: {}
, fade: {}
, fold: {}
, puff: {}
// Pane Resize Animations
, size: {
all: { easing: "swing" }
}
}
// INTERNAL CONFIG DATA - DO NOT CHANGE THIS!
, config: {
optionRootKeys: "effects,panes,north,south,west,east,center".split(",")
, allPanes: "north,south,west,east,center".split(",")
, borderPanes: "north,south,west,east".split(",")
, oppositeEdge: {
north: "south"
, south: "north"
, east: "west"
, west: "east"
}
// offscreen data
, offscreenCSS: { left: "-99999px", right: "auto" } // used by hide/close if useOffscreenClose=true
, offscreenReset: "offscreenReset" // key used for data
// CSS used in multiple places
, hidden: { visibility: "hidden" }
, visible: { visibility: "visible" }
// layout element settings
, resizers: {
cssReq: {
position: "absolute"
, padding: 0
, margin: 0
, fontSize: "1px"
, textAlign: "left" // to counter-act "center" alignment!
, overflow: "hidden" // prevent toggler-button from overflowing
// SEE $.layout.defaults.zIndexes.resizer_normal
}
, cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=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
}
, cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
background: "#AAA"
}
}
, content: {
cssReq: {
position: "relative" /* contain floated or positioned elements */
}
, cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
overflow: "auto"
, padding: "10px"
}
, cssDemoPane: { // DEMO CSS - REMOVE scrolling from 'pane' when it has a content-div
overflow: "hidden"
, padding: 0
}
}
, panes: { // defaults for ALL panes - overridden by 'per-pane settings' below
cssReq: {
position: "absolute"
, margin: 0
// $.layout.defaults.zIndexes.pane_normal
}
, cssDemo: { // DEMO CSS - applied if: options.PANE.applyDemoStyles=true
padding: "10px"
, background: "#FFF"
, border: "1px solid #BBB"
, overflow: "auto"
}
}
, north: {
side: "top"
, sizeType: "Height"
, dir: "horz"
, cssReq: {
top: 0
, bottom: "auto"
, left: 0
, right: 0
, width: "auto"
// height: DYNAMIC
}
}
, south: {
side: "bottom"
, sizeType: "Height"
, dir: "horz"
, cssReq: {
top: "auto"
, bottom: 0
, left: 0
, right: 0
, width: "auto"
// height: DYNAMIC
}
}
, east: {
side: "right"
, sizeType: "Width"
, dir: "vert"
, cssReq: {
left: "auto"
, right: 0
, top: "auto" // DYNAMIC
, bottom: "auto" // DYNAMIC
, height: "auto"
// width: DYNAMIC
}
}
, west: {
side: "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"
}
}
}
// CALLBACK FUNCTION NAMESPACE - used to store reusable callback functions
, callbacks: {}
, getParentPaneElem: function (el) {
// must pass either a container or pane element
var $el = $(el)
, layout = $el.data("layout") || $el.data("parentLayout");
if (layout) {
var $cont = layout.container;
// see if this container is directly-nested inside an outer-pane
if ($cont.data("layoutPane")) return $cont;
var $pane = $cont.closest("."+ $.layout.defaults.panes.paneClass);
// if a pane was found, return it
if ($pane.data("layoutPane")) return $pane;
}
return null;
}
, getParentPaneInstance: function (el) {
// must pass either a container or pane element
var $pane = $.layout.getParentPaneElem(el);
return $pane ? $pane.data("layoutPane") : null;
}
, getParentLayoutInstance: function (el) {
// must pass either a container or pane element
var $pane = $.layout.getParentPaneElem(el);
return $pane ? $pane.data("parentLayout") : null;
}
, getEventObject: function (evt) {
return typeof evt === "object" && evt.stopPropagation ? evt : null;
}
, parsePaneName: function (evt_or_pane) {
var evt = $.layout.getEventObject( evt_or_pane )
, pane = evt_or_pane;
if (evt) {
// ALWAYS stop propagation of events triggered in Layout!
evt.stopPropagation();
pane = $(this).data("layoutEdge");
}
if (pane && !/^(west|east|north|south|center)$/.test(pane)) {
$.layout.msg('LAYOUT ERROR - Invalid pane-name: "'+ pane +'"');
pane = "error";
}
return pane;
}
// LAYOUT-PLUGIN REGISTRATION
// more plugins can added beyond this default list
, plugins: {
draggable: !!$.fn.draggable // resizing
, effects: {
core: !!$.effects // animimations (specific effects tested by initOptions)
, slide: $.effects && ($.effects.slide || ($.effects.effect && $.effects.effect.slide)) // default effect
}
}
// arrays of plugin or other methods to be triggered for events in *each layout* - will be passed 'Instance'
, onCreate: [] // runs when layout is just starting to be created - right after options are set
, onLoad: [] // runs after layout container and global events init, but before initPanes is called
, onReady: [] // runs after initialization *completes* - ie, after initPanes completes successfully
, onDestroy: [] // runs after layout is destroyed
, onUnload: [] // runs after layout is destroyed OR when page unloads
, afterOpen: [] // runs after setAsOpen() completes
, afterClose: [] // runs after setAsClosed() completes
/*
* GENERIC UTILITY METHODS
*/
// calculate and return the scrollbar width, as an integer
, scrollbarWidth: function () { return window.scrollbarWidth || $.layout.getScrollbarSize('width'); }
, scrollbarHeight: function () { return window.scrollbarHeight || $.layout.getScrollbarSize('height'); }
, getScrollbarSize: function (dim) {
var $c = $('<div style="position: absolute; top: -10000px; left: -10000px; width: 100px; height: 100px; overflow: scroll;"></div>').appendTo("body");
var d = { width: $c.css("width") - $c[0].clientWidth, height: $c.height() - $c[0].clientHeight };
$c.remove();
window.scrollbarWidth = d.width;
window.scrollbarHeight = d.height;
return dim.match(/^(width|height)$/) ? d[dim] : d;
}
/**
* Returns hash container 'display' and 'visibility'
*
* @see $.swap() - swaps CSS, runs callback, resets CSS
* @param {!Object} $E jQuery element
* @param {boolean=} [force=false] Run even if display != none
* @return {!Object} Returns current style props, if applicable
*/
, showInvisibly: function ($E, force) {
if ($E && $E.length && (force || $E.css("display") === "none")) { // only if not *already hidden*
var s = $E[0].style
// save ONLY the 'style' props because that is what we must restore
, CSS = { display: s.display || '', visibility: s.visibility || '' };
// show element 'invisibly' so can be measured
$E.css({ display: "block", visibility: "hidden" });
return CSS;
}
return {};
}
/**
* Returns data for setting size of an element (container or a pane).
*
* @see _create(), onWindowResize() for container, plus others for pane
* @return JSON Returns a hash of all dimensions: top, bottom, left, right, outerWidth, innerHeight, etc
*/
, getElementDimensions: function ($E, inset) {
var
// dimensions hash - start with current data IF passed
d = { css: {}, inset: {} }
, x = d.css // CSS hash
, i = { bottom: 0 } // TEMP insets (bottom = complier hack)
, N = $.layout.cssNum
, off = $E.offset()
, b, p, ei // TEMP border, padding
;
d.offsetLeft = off.left;
d.offsetTop = off.top;
if (!inset) inset = {}; // simplify logic below
$.each("Left,Right,Top,Bottom".split(","), function (idx, e) { // e = edge
b = x["border" + e] = $.layout.borderWidth($E, e);
p = x["padding"+ e] = $.layout.cssNum($E, "padding"+e);
ei = e.toLowerCase();
d.inset[ei] = inset[ei] >= 0 ? inset[ei] : p; // any missing insetX value = paddingX
i[ei] = d.inset[ei] + b; // total offset of content from outer side
});
x.width = $E.width();
x.height = $E.height();
x.top = N($E,"top",true);
x.bottom = N($E,"bottom",true);
x.left = N($E,"left",true);
x.right = N($E,"right",true);
d.outerWidth = $E.outerWidth();
d.outerHeight = $E.outerHeight();
// calc the TRUE inner-dimensions, even in quirks-mode!
d.innerWidth = max(0, d.outerWidth - i.left - i.right);
d.innerHeight = max(0, d.outerHeight - i.top - i.bottom);
// layoutWidth/Height is used in calcs for manual resizing
// layoutW/H only differs from innerW/H when in quirks-mode - then is like outerW/H
d.layoutWidth = $E.innerWidth();
d.layoutHeight = $E.innerHeight();
//if ($E.prop('tagName') === 'BODY') { debugData( d, $E.prop('tagName') ); } // DEBUG
//d.visible = $E.is(":visible");// && x.width > 0 && x.height > 0;
return d;
}
, getElementStyles: function ($E, list) {
var
CSS = {}
, style = $E[0].style
, props = list.split(",")
, sides = "Top,Bottom,Left,Right".split(",")
, attrs = "Color,Style,Width".split(",")
, p, s, a, i, j, k
;
for (i=0; i < props.length; i++) {
p = props[i];
if (p.match(/(border|padding|margin)$/))
for (j=0; j < 4; j++) {
s = sides[j];
if (p === "border")
for (k=0; k < 3; k++) {
a = attrs[k];
CSS[p+s+a] = style[p+s+a];
}
else
CSS[p+s] = style[p+s];
}
else
CSS[p] = style[p];
};
return CSS
}
/**
* Return the innerWidth for the current browser/doctype
*
* @see initPanes(), sizeMidPanes(), initHandles(), sizeHandles()
* @param {Array.<Object>} $E Must pass a jQuery object - first element is processed
* @param {number=} outerWidth (optional) Can pass a width, allowing calculations BEFORE element is resized
* @return {number} Returns the innerWidth of the elem by subtracting padding and borders
*/
, cssWidth: function ($E, outerWidth) {
// a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
if (outerWidth <= 0) return 0;
var bs = !$.layout.browser.boxModel ? "border-box" : $.support.boxSizing ? $E.css("boxSizing") : "content-box"
, b = $.layout.borderWidth
, n = $.layout.cssNum
, W = outerWidth
;
// strip border and/or padding from outerWidth to get CSS Width
if (bs !== "border-box")
W -= (b($E, "Left") + b($E, "Right"));
if (bs === "content-box")
W -= (n($E, "paddingLeft") + n($E, "paddingRight"));
return max(0,W);
}
/**
* Return the innerHeight for the current browser/doctype
*
* @see initPanes(), sizeMidPanes(), initHandles(), sizeHandles()
* @param {Array.<Object>} $E Must pass a jQuery object - first element is processed
* @param {number=} outerHeight (optional) Can pass a width, allowing calculations BEFORE element is resized
* @return {number} Returns the innerHeight of the elem by subtracting padding and borders
*/
, cssHeight: function ($E, outerHeight) {
// a 'calculated' outerHeight can be passed so borders and/or padding are removed if needed
if (outerHeight <= 0) return 0;
var bs = !$.layout.browser.boxModel ? "border-box" : $.support.boxSizing ? $E.css("boxSizing") : "content-box"
, b = $.layout.borderWidth
, n = $.layout.cssNum
, H = outerHeight
;
// strip border and/or padding from outerHeight to get CSS Height
if (bs !== "border-box")
H -= (b($E, "Top") + b($E, "Bottom"));
if (bs === "content-box")
H -= (n($E, "paddingTop") + n($E, "paddingBottom"));
return max(0,H);
}
/**
* Returns the 'current CSS numeric value' for a CSS property - 0 if property does not exist
*
* @see Called by many methods
* @param {Array.<Object>} $E Must pass a jQuery object - first element is processed
* @param {string} prop The name of the CSS property, eg: top, width, etc.
* @param {boolean=} [allowAuto=false] true = return 'auto' if that is value; false = return 0
* @return {(string|number)} Usually used to get an integer value for position (top, left) or size (height, width)
*/
, cssNum: function ($E, prop, allowAuto) {
if (!$E.jquery) $E = $($E);
var CSS = $.layout.showInvisibly($E)
, p = $.css($E[0], prop, true)
, v = allowAuto && p=="auto" ? p : Math.round(parseFloat(p) || 0);
$E.css( CSS ); // RESET
return v;
}
, borderWidth: function (el, side) {
if (el.jquery) el = el[0];
var b = "border"+ side.substr(0,1).toUpperCase() + side.substr(1); // left => Left
return $.css(el, b+"Style", true) === "none" ? 0 : Math.round(parseFloat($.css(el, b+"Width", true)) || 0);
}
/**
* Mouse-tracking utility - FUTURE REFERENCE
*
* init: if (!window.mouse) {
* window.mouse = { x: 0, y: 0 };
* $(document).mousemove( $.layout.trackMouse );
* }
*
* @param {Object} evt
*
, trackMouse: function (evt) {
window.mouse = { x: evt.clientX, y: evt.clientY };
}
*/
/**
* SUBROUTINE for preventPrematureSlideClose option
*
* @param {Object} evt
* @param {Object=} el
*/
, isMouseOverElem: function (evt, el) {
var
$E = $(el || this)
, d = $E.offset()
, T = d.top
, L = d.left
, R = L + $E.outerWidth()
, B = T + $E.outerHeight()
, x = evt.pageX // evt.clientX ?
, y = evt.pageY // evt.clientY ?
;
// if X & Y are < 0, probably means is over an open SELECT
return ($.layout.browser.msie && x < 0 && y < 0) || ((x >= L && x <= R) && (y >= T && y <= B));
}
/**
* Message/Logging Utility
*
* @example $.layout.msg("My message"); // log text
* @example $.layout.msg("My message", true); // alert text
* @example $.layout.msg({ foo: "bar" }, "Title"); // log hash-data, with custom title
* @example $.layout.msg({ foo: "bar" }, true, "Title", { sort: false }); -OR-
* @example $.layout.msg({ foo: "bar" }, "Title", { sort: false, display: true }); // alert hash-data
*
* @param {(Object|string)} info String message OR Hash/Array
* @param {(Boolean|string|Object)=} [popup=false] True means alert-box - can be skipped
* @param {(Object|string)=} [debugTitle=""] Title for Hash data - can be skipped
* @param {Object=} [debugOpts] Extra options for debug output
*/
, msg: function (info, popup, debugTitle, debugOpts) {
if ($.isPlainObject(info) && window.debugData) {
if (typeof popup === "string") {
debugOpts = debugTitle;
debugTitle = popup;
}
else if (typeof debugTitle === "object") {
debugOpts = debugTitle;
debugTitle = null;
}
var t = debugTitle || "log( <object> )"
, o = $.extend({ sort: false, returnHTML: false, display: false }, debugOpts);
if (popup === true || o.display)
debugData( info, t, o );
else if (window.console)
console.log(debugData( info, t, o ));
}
else if (popup)
alert(info);
else if (window.console)
console.log(info);
else {
var id = "#layoutLogger"
, $l = $(id);
if (!$l.length)
$l = createLog();
$l.children("ul").append('<li style="padding: 4px 10px; margin: 0; border-top: 1px solid #CCC;">'+ info.replace(/\</g,"<").replace(/\>/g,">") +'</li>');
}
function createLog () {
var pos = $.support.fixedPosition ? 'fixed' : 'absolute'
, $e = $('<div id="layoutLogger" style="position: '+ pos +'; top: 5px; z-index: 999999; max-width: 25%; overflow: hidden; border: 1px solid #000; border-radius: 5px; background: #FBFBFB; box-shadow: 0 2px 10px rgba(0,0,0,0.3);">'
+ '<div style="font-size: 13px; font-weight: bold; padding: 5px 10px; background: #F6F6F6; border-radius: 5px 5px 0 0; cursor: move;">'
+ '<span style="float: right; padding-left: 7px; cursor: pointer;" title="Remove Console" onclick="$(this).closest(\'#layoutLogger\').remove()">X</span>Layout console.log</div>'
+ '<ul style="font-size: 13px; font-weight: none; list-style: none; margin: 0; padding: 0 0 2px;"></ul>'
+ '</div>'
).appendTo("body");
$e.css('left', $(window).width() - $e.outerWidth() - 5)
if ($.ui.draggable) $e.draggable({ handle: ':first-child' });
return $e;
};
}
};
/*
* $.layout.browser REPLACES removed $.browser, with extra data
* Parsing code here adapted from jQuery 1.8 $.browse
*/
var u = navigator.userAgent.toLowerCase()
, m = /(chrome)[ \/]([\w.]+)/.exec( u )
|| /(webkit)[ \/]([\w.]+)/.exec( u )
|| /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( u )
|| /(msie) ([\w.]+)/.exec( u )
|| u.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( u )
|| []
, b = m[1] || ""
, v = m[2] || 0
, ie = b === "msie"
;
$.layout.browser = {
version: v
, safari: b === "webkit" // webkit (NOT chrome) = safari
, webkit: b === "chrome" // chrome = webkit
, msie: ie
, isIE6: ie && v == 6
// ONLY IE reverts to old box-model - update for older jQ onReady
, boxModel: !ie || $.support.boxModel !== false
};
if (b) $.layout.browser[b] = true; // set CURRENT browser
/* OLD versions of jQuery only set $.support.boxModel after page is loaded
* so if this is IE, use support.boxModel to test for quirks-mode (ONLY IE changes boxModel) */
if (ie) $(function(){ $.layout.browser.boxModel = $.support.boxModel; });
// DEFAULT OPTIONS
$.layout.defaults = {
/*
* LAYOUT & LAYOUT-CONTAINER OPTIONS
* - none of these options are applicable to individual panes
*/
name: "" // Not required, but useful for buttons and used for the state-cookie
, containerClass: "ui-layout-container" // layout-container element
, inset: null // custom container-inset values (override padding)
, scrollToBookmarkOnLoad: true // after creating a layout, scroll to bookmark in URL (.../page.htm#myBookmark)
, resizeWithWindow: true // bind thisLayout.resizeAll() to the window.resize event
, resizeWithWindowDelay: 200 // delay calling resizeAll because makes window resizing very jerky
, resizeWithWindowMaxDelay: 0 // 0 = none - force resize every XX ms while window is being resized
, maskPanesEarly: false // true = create pane-masks on resizer.mouseDown instead of waiting for resizer.dragstart
, onresizeall_start: null // CALLBACK when resizeAll() STARTS - NOT pane-specific
, onresizeall_end: null // CALLBACK when resizeAll() ENDS - NOT pane-specific
, onload_start: null // CALLBACK when Layout inits - after options initialized, but before elements
, onload_end: null // CALLBACK when Layout inits - after EVERYTHING has been initialized
, onunload_start: null // CALLBACK when Layout is destroyed OR onWindowUnload
, onunload_end: null // CALLBACK when Layout is destroyed OR onWindowUnload
, initPanes: true // false = DO NOT initialize the panes onLoad - will init later
, showErrorMessages: true // enables fatal error messages to warn developers of common errors
, showDebugMessages: false // display console-and-alert debug msgs - IF this Layout version _has_ debugging code!
// Changing this zIndex value will cause other zIndex values to automatically change
, zIndex: null // the PANE zIndex - resizers and masks will be +1
// DO NOT CHANGE the zIndex values below unless you clearly understand their relationships
, zIndexes: { // set _default_ z-index values here...
pane_normal: 0 // normal z-index for panes
, content_mask: 1 // applied to overlays used to mask content INSIDE panes during resizing
, resizer_normal: 2 // normal z-index for resizer-bars
, pane_sliding: 100 // applied to *BOTH* the pane and its resizer when a pane is 'slid open'
, pane_animate: 1000 // applied to the pane when being animated - not applied to the resizer
, resizer_drag: 10000 // applied to the CLONED resizer-bar when being 'dragged'
}
, errors: {
pane: "pane" // description of "layout pane element" - used only in error messages
, selector: "selector" // description of "jQuery-selector" - used only in error messages
, addButtonError: "Error Adding Button\nInvalid "
, containerMissing: "UI Layout Initialization Error\nThe specified layout-container does not exist."
, centerPaneMissing: "UI Layout Initialization Error\nThe center-pane element does not exist.\nThe center-pane is a required element."
, noContainerHeight: "UI Layout Initialization Warning\nThe layout-container \"CONTAINER\" has no height.\nTherefore the layout is 0-height and hence 'invisible'!"
, callbackError: "UI Layout Callback Error\nThe EVENT callback is not a valid function."
}
/*
* PANE DEFAULT SETTINGS
* - settings under the 'panes' key become the default settings for *all panes*
* - ALL pane-options can also be set specifically for each panes, which will override these 'default values'
*/
, panes: { // default options for 'all panes' - will be overridden by 'per-pane settings'
applyDemoStyles: false // NOTE: renamed from applyDefaultStyles for clarity
, 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
, initClosed: false // true = init pane as 'closed'
, initHidden: false // true = init pane as 'hidden' - no resizer-bar/spacing
// SELECTORS
//, paneSelector: "" // MUST be pane-specific - jQuery selector for pane
, contentSelector: ".ui-layout-content" // INNER div/element to auto-size so only it scrolls, not the entire pane!
, contentIgnoreSelector: ".ui-layout-ignore" // element(s) to 'ignore' when measuring 'content'
, findNestedContent: false // true = $P.find(contentSelector), false = $P.children(contentSelector)
// GENERIC ROOT-CLASSES - for auto-generated classNames
, paneClass: "ui-layout-pane" // Layout Pane
, resizerClass: "ui-layout-resizer" // Resizer Bar
, togglerClass: "ui-layout-toggler" // Toggler Button
, buttonClass: "ui-layout-button" // CUSTOM Buttons - eg: '[ui-layout-button]-toggle/-open/-close/-pin'
// ELEMENT SIZE & SPACING
//, size: 100 // MUST be pane-specific -initial size of 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 sides - HEIGHT on east/west sides
, 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
, togglerContent_open: "" // text or HTML to put INSIDE the toggler
, togglerContent_closed: "" // ditto
// RESIZING OPTIONS
, resizerDblClickToggle: true //
, autoResize: true // IF size is 'auto' or a percentage, then recalc 'pixel size' whenever the layout resizes
, autoReopen: true // IF a pane was auto-closed due to noRoom, reopen it when there is room? False = leave it closed
, resizerDragOpacity: 1 // option for ui.draggable
//, resizerCursor: "" // MUST be pane-specific - cursor when over resizer-bar
, maskContents: false // true = add DIV-mask over-or-inside this pane so can 'drag' over IFRAMES
, maskObjects: false // true = add IFRAME-mask over-or-inside this pane to cover objects/applets - content-mask will overlay this mask
, maskZindex: null // will override zIndexes.content_mask if specified - not applicable to iframe-panes
, resizingGrid: false // grid size that the resizers will snap-to during resizing, eg: [20,20]
, livePaneResizing: false // true = LIVE Resizing as resizer is dragged
, liveContentResizing: false // true = re-measure header/footer heights as resizer is dragged
, liveResizingTolerance: 1 // how many px change before pane resizes, to control performance
// SLIDING OPTIONS
, sliderCursor: "pointer" // cursor when resizer-bar will trigger 'sliding'
, slideTrigger_open: "click" // click, dblclick, mouseenter
, slideTrigger_close: "mouseleave"// click, mouseleave
, slideDelay_open: 300 // applies only for mouseenter event - 0 = instant open
, slideDelay_close: 300 // applies only for mouseleave event (300ms is the minimum!)
, hideTogglerOnSlide: false // when pane is slid-open, should the toggler show?
, preventQuickSlideClose: $.layout.browser.webkit // Chrome triggers slideClosed as it is opening
, preventPrematureSlideClose: false // handle incorrect mouseleave trigger, like when over a SELECT-list in IE
// PANE-SPECIFIC TIPS & MESSAGES
, tips: {
Open: "Open" // eg: "Open Pane"
, Close: "Close"
, Resize: "Resize"
, Slide: "Slide Open"
, Pin: "Pin"
, Unpin: "Un-Pin"
, noRoomToOpen: "Not enough room to show this panel." // alert if user tries to open a pane that cannot
, minSizeWarning: "Panel has reached its minimum size" // displays in browser statusbar
, maxSizeWarning: "Panel has reached its maximum size" // ditto
}
// HOT-KEYS & MISC
, 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'
// PANE ANIMATION
// NOTE: fxSss_open, fxSss_close & fxSss_size options (eg: fxName_open) are auto-generated if not passed
, fxName: "slide" // ('none' or blank), slide, drop, scale -- only relevant to 'open' & 'close', NOT 'size'
, fxSpeed: null // slow, normal, fast, 200, nnn - if passed, will OVERRIDE fxSettings.duration
, fxSettings: {} // can be passed, eg: { easing: "easeOutBounce", duration: 1500 }
, fxOpacityFix: true // tries to fix opacity in IE to restore anti-aliasing after animation
, animatePaneSizing: false // true = animate resizing after dragging resizer-bar OR sizePane() is called
/* NOTE: Action-specific FX options are auto-generated from the options above if not specifically set:
fxName_open: "slide" // 'Open' pane animation
fnName_close: "slide" // 'Close' pane animation
fxName_size: "slide" // 'Size' pane animation - when animatePaneSizing = true
fxSpeed_open: null
fxSpeed_close: null
fxSpeed_size: null
fxSettings_open: {}
fxSettings_close: {}
fxSettings_size: {}
*/
// CHILD/NESTED LAYOUTS
, children: null // Layout-options for nested/child layout - even {} is valid as options
, containerSelector: '' // if child is NOT 'directly nested', a selector to find it/them (can have more than one child layout!)
, initChildren: true // true = child layout will be created as soon as _this_ layout completes initialization
, destroyChildren: true // true = destroy child-layout if this pane is destroyed
, resizeChildren: true // true = trigger child-layout.resizeAll() when this pane is resized
// EVENT TRIGGERING
, triggerEventsOnLoad: false // true = trigger onopen OR onclose callbacks when layout initializes
, triggerEventsDuringLiveResize: true // true = trigger onresize callback REPEATEDLY if livePaneResizing==true
// PANE CALLBACKS
, onshow_start: null // CALLBACK when pane STARTS to Show - BEFORE onopen/onhide_start
, onshow_end: null // CALLBACK when pane ENDS being Shown - AFTER onopen/onhide_end
, onhide_start: null // CALLBACK when pane STARTS to Close - BEFORE onclose_start
, onhide_end: null // CALLBACK when pane ENDS being Closed - AFTER onclose_end
, onopen_start: null // CALLBACK when pane STARTS to Open
, onopen_end: null // CALLBACK when pane ENDS being Opened
, onclose_start: null // CALLBACK when pane STARTS to Close
, onclose_end: null // CALLBACK when pane ENDS being Closed
, onresize_start: null // CALLBACK when pane STARTS being Resized ***FOR ANY REASON***
, onresize_end: null // CALLBACK when pane ENDS being Resized ***FOR ANY REASON***
, onsizecontent_start: null // CALLBACK when sizing of content-element STARTS
, onsizecontent_end: null // CALLBACK when sizing of content-element ENDS
, onswap_start: null // CALLBACK when pane STARTS to Swap
, onswap_end: null // CALLBACK when pane ENDS being Swapped
, ondrag_start: null // CALLBACK when pane STARTS being ***MANUALLY*** Resized
, ondrag_end: null // CALLBACK when pane ENDS being ***MANUALLY*** Resized
}
/*
* PANE-SPECIFIC SETTINGS
* - options listed below MUST be specified per-pane - they CANNOT be set under 'panes'
* - all options under the 'panes' key can also be set specifically for any pane
* - most options under the 'panes' key apply only to 'border-panes' - NOT the the center-pane
*/
, north: {
paneSelector: ".ui-layout-north"
, size: "auto" // eg: "auto", "30%", .30, 200
, resizerCursor: "n-resize" // custom = url(myCursor.cur)
, customHotkey: "" // EITHER a charCode (43) OR a character ("o")
}
, south: {
paneSelector: ".ui-layout-south"
, size: "auto"
, resizerCursor: "s-resize"
, customHotkey: ""
}
, east: {
paneSelector: ".ui-layout-east"
, size: 200
, resizerCursor: "e-resize"
, customHotkey: ""
}
, west: {
paneSelector: ".ui-layout-west"
, size: 200
, resizerCursor: "w-resize"
, customHotkey: ""
}
, center: {
paneSelector: ".ui-layout-center"
, minWidth: 0
, minHeight: 0
}
};
$.layout.optionsMap = {
// layout/global options - NOT pane-options
layout: ("name,instanceKey,stateManagement,effects,inset,zIndexes,errors,"
+ "zIndex,scrollToBookmarkOnLoad,showErrorMessages,maskPanesEarly,"
+ "outset,resizeWithWindow,resizeWithWindowDelay,resizeWithWindowMaxDelay,"
+ "onresizeall,onresizeall_start,onresizeall_end,onload,onload_start,onload_end,onunload,onunload_start,onunload_end").split(",")
// borderPanes: [ ALL options that are NOT specified as 'layout' ]
// default.panes options that apply to the center-pane (most options apply _only_ to border-panes)
, center: ("paneClass,contentSelector,contentIgnoreSelector,findNestedContent,applyDemoStyles,triggerEventsOnLoad,"
+ "showOverflowOnHover,maskContents,maskObjects,liveContentResizing,"
+ "containerSelector,children,initChildren,resizeChildren,destroyChildren,"
+ "onresize,onresize_start,onresize_end,onsizecontent,onsizecontent_start,onsizecontent_end").split(",")
// options that MUST be specifically set 'per-pane' - CANNOT set in the panes (defaults) key
, noDefault: ("paneSelector,resizerCursor,customHotkey").split(",")
};
/**
* Processes options passed in converts flat-format data into subkey (JSON) format
* In flat-format, subkeys are _currently_ separated with 2 underscores, like north__optName
* Plugins may also call this method so they can transform their own data
*
* @param {!Object} hash Data/options passed by user - may be a single level or nested levels
* @param {boolean=} [addKeys=false] Should the primary layout.options keys be added if they do not exist?
* @return {Object} Returns hash of minWidth & minHeight
*/
$.layout.transformData = function (hash, addKeys) {
var json = addKeys ? { panes: {}, center: {} } : {} // init return object
, branch, optKey, keys, key, val, i, c;
if (typeof hash !== "object") return json; // no options passed
// convert all 'flat-keys' to 'sub-key' format
for (optKey in hash) {
branch = json;
val = hash[ optKey ];
keys = optKey.split("__"); // eg: west__size or north__fxSettings__duration
c = keys.length - 1;
// convert underscore-delimited to subkeys
for (i=0; i <= c; i++) {
key = keys[i];
if (i === c) { // last key = value
if ($.isPlainObject( val ))
branch[key] = $.layout.transformData( val ); // RECURSE
else
branch[key] = val;
}
else {
if (!branch[key])
branch[key] = {}; // create the subkey
// recurse to sub-key for next loop - if not done
branch = branch[key];
}
}
}
return json;
};
// INTERNAL CONFIG DATA - DO NOT CHANGE THIS!
$.layout.backwardCompatibility = {
// data used by renameOldOptions()
map: {
// OLD Option Name: NEW Option Name
applyDefaultStyles: "applyDemoStyles"
// CHILD/NESTED LAYOUTS
, childOptions: "children"
, initChildLayout: "initChildren"
, destroyChildLayout: "destroyChildren"
, resizeChildLayout: "resizeChildren"
, resizeNestedLayout: "resizeChildren"
// MISC Options
, resizeWhileDragging: "livePaneResizing"
, resizeContentWhileDragging: "liveContentResizing"
, triggerEventsWhileDragging: "triggerEventsDuringLiveResize"
, maskIframesOnResize: "maskContents"
// STATE MANAGEMENT
, useStateCookie: "stateManagement.enabled"
, "cookie.autoLoad": "stateManagement.autoLoad"
, "cookie.autoSave": "stateManagement.autoSave"
, "cookie.keys": "stateManagement.stateKeys"
, "cookie.name": "stateManagement.cookie.name"
, "cookie.domain": "stateManagement.cookie.domain"
, "cookie.path": "stateManagement.cookie.path"
, "cookie.expires": "stateManagement.cookie.expires"
, "cookie.secure": "stateManagement.cookie.secure"
// OLD Language options
, noRoomToOpenTip: "tips.noRoomToOpen"
, togglerTip_open: "tips.Close" // open = Close
, togglerTip_closed: "tips.Open" // closed = Open
, resizerTip: "tips.Resize"
, sliderTip: "tips.Slide"
}
/**
* @param {Object} opts
*/
, renameOptions: function (opts) {
var map = $.layout.backwardCompatibility.map
, oldData, newData, value
;
for (var itemPath in map) {
oldData = getBranch( itemPath );
value = oldData.branch[ oldData.key ];
if (value !== undefined) {
newData = getBranch( map[itemPath], true );
newData.branch[ newData.key ] = value;
delete oldData.branch[ oldData.key ];
}
}
/**
* @param {string} path
* @param {boolean=} [create=false] Create path if does not exist
*/
function getBranch (path, create) {
var a = path.split(".") // split keys into array
, c = a.length - 1
, D = { branch: opts, key: a[c] } // init branch at top & set key (last item)
, i = 0, k, undef;
for (; i<c; i++) { // skip the last key (data)
k = a[i];
if (D.branch[ k ] == undefined) { // child-key does not exist
if (create) {
D.branch = D.branch[ k ] = {}; // create child-branch
}
else // can't go any farther
D.branch = {}; // branch is undefined
}
else
D.branch = D.branch[ k ]; // get child-branch
}
return D;
};
}
/**
* @param {Object} opts
*/
, renameAllOptions: function (opts) {
var ren = $.layout.backwardCompatibility.renameOptions;
// rename root (layout) options
ren( opts );
// rename 'defaults' to 'panes'
if (opts.defaults) {
if (typeof opts.panes !== "object")
opts.panes = {};
$.extend(true, opts.panes, opts.defaults);
delete opts.defaults;
}
// rename options in the the options.panes key
if (opts.panes) ren( opts.panes );
// rename options inside *each pane key*, eg: options.west
$.each($.layout.config.allPanes, function (i, pane) {
if (opts[pane]) ren( opts[pane] );
});
return opts;
}
};
/* ============================================================
* BEGIN WIDGET: $( selector ).layout( {options} );
* ============================================================
*/
$.fn.layout = function (opts) {
var