4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-resizer-Splitter'>/**
19 </span> * @class Ext.resizer.Splitter
20 * @extends Ext.Component
21 * <p>This class functions <b>between siblings of a {@link Ext.layout.container.VBox VBox} or {@link Ext.layout.container.HBox HBox}
22 * layout</b> to resize both immediate siblings.</p>
23 * <p>By default it will set the size of both siblings. <b>One</b> of the siblings may be configured with
24 * <code>{@link Ext.Component#maintainFlex maintainFlex}: true</code> which will cause it not to receive a new size explicitly, but to be resized
25 * by the layout.</p>
26 * <p>A Splitter may be configured to show a centered mini-collapse tool orientated to collapse the {@link #collapseTarget}.
27 * The Splitter will then call that sibling Panel's {@link Ext.panel.Panel#collapse collapse} or {@link Ext.panel.Panel#expand expand} method
28 * to perform the appropriate operation (depending on the sibling collapse state). To create the mini-collapse tool but take care
29 * of collapsing yourself, configure the splitter with <code>{@link #performCollapse} false</code>.</p>
31 Ext.define('Ext.resizer.Splitter', {
32 extend: 'Ext.Component',
33 requires: ['Ext.XTemplate'],
34 uses: ['Ext.resizer.SplitterTracker'],
35 alias: 'widget.splitter',
38 '<tpl if="collapsible===true"><div class="' + Ext.baseCSSPrefix + 'collapse-el ' + Ext.baseCSSPrefix + 'layout-split-{collapseDir}">&nbsp;</div></tpl>'
41 baseCls: Ext.baseCSSPrefix + 'splitter',
42 collapsedClsInternal: Ext.baseCSSPrefix + 'splitter-collapsed',
44 <span id='Ext-resizer-Splitter-cfg-collapsible'> /**
45 </span> * @cfg {Boolean} collapsible
46 * <code>true</code> to show a mini-collapse tool in the Splitter to toggle expand and collapse on the {@link #collapseTarget} Panel.
47 * Defaults to the {@link Ext.panel.Panel#collapsible collapsible} setting of the Panel.
51 <span id='Ext-resizer-Splitter-cfg-performCollapse'> /**
52 </span> * @cfg {Boolean} performCollapse
53 * <p>Set to <code>false</code> to prevent this Splitter's mini-collapse tool from managing the collapse
54 * state of the {@link #collapseTarget}.</p>
57 <span id='Ext-resizer-Splitter-cfg-collapseOnDblClick'> /**
58 </span> * @cfg {Boolean} collapseOnDblClick
59 * <code>true</code> to enable dblclick to toggle expand and collapse on the {@link #collapseTarget} Panel.
61 collapseOnDblClick: true,
63 <span id='Ext-resizer-Splitter-cfg-defaultSplitMin'> /**
64 </span> * @cfg {Number} defaultSplitMin
65 * Provides a default minimum width or height for the two components
66 * that the splitter is between.
70 <span id='Ext-resizer-Splitter-cfg-defaultSplitMax'> /**
71 </span> * @cfg {Number} defaultSplitMax
72 * Provides a default maximum width or height for the two components
73 * that the splitter is between.
75 defaultSplitMax: 1000,
77 <span id='Ext-resizer-Splitter-cfg-collapsedCls'> /**
78 </span> * @cfg {String} collapsedCls
79 * A class to add to the splitter when it is collapsed. See {@link #collapsible}.
85 <span id='Ext-resizer-Splitter-cfg-collapseTarget'> /**
86 </span> * @cfg {Mixed} collapseTarget
87 * <p>A string describing the relative position of the immediate sibling Panel to collapse. May be 'prev' or 'next' (Defaults to 'next')</p>
88 * <p>Or the immediate sibling Panel to collapse.</p>
89 * <p>The orientation of the mini-collapse tool will be inferred from this setting.</p>
90 * <p><b>Note that only Panels may be collapsed.</b></p>
92 collapseTarget: 'next',
94 <span id='Ext-resizer-Splitter-property-orientation'> /**
95 </span> * @property orientation
97 * Orientation of this Splitter. <code>'vertical'</code> when used in an hbox layout, <code>'horizontal'</code>
98 * when used in a vbox layout.
101 onRender: function() {
103 target = me.getCollapseTarget(),
104 collapseDir = me.getCollapseDirection();
106 Ext.applyIf(me.renderData, {
107 collapseDir: collapseDir,
108 collapsible: me.collapsible || target.collapsible
110 Ext.applyIf(me.renderSelectors, {
111 collapseEl: '.' + Ext.baseCSSPrefix + 'collapse-el'
114 this.callParent(arguments);
116 // Add listeners on the mini-collapse tool unless performCollapse is set to false
117 if (me.performCollapse !== false) {
118 if (me.renderData.collapsible) {
119 me.mon(me.collapseEl, 'click', me.toggleTargetCmp, me);
121 if (me.collapseOnDblClick) {
122 me.mon(me.el, 'dblclick', me.toggleTargetCmp, me);
126 // Ensure the mini collapse icon is set to the correct direction when the target is collapsed/expanded by any means
127 me.mon(target, 'collapse', me.onTargetCollapse, me);
128 me.mon(target, 'expand', me.onTargetExpand, me);
130 me.el.addCls(me.baseCls + '-' + me.orientation);
131 me.el.unselectable();
133 me.tracker = Ext.create('Ext.resizer.SplitterTracker', {
137 // Relay the most important events to our owner (could open wider later):
138 me.relayEvents(me.tracker, [ 'beforedragstart', 'dragstart', 'dragend' ]);
141 getCollapseDirection: function() {
144 type = me.ownerCt.layout.type;
146 // Avoid duplication of string tests.
147 // Create a two bit truth table of the configuration of the Splitter:
148 // Collapse Target | orientation
149 // 0 0 = next, horizontal
150 // 0 1 = next, vertical
151 // 1 0 = prev, horizontal
152 // 1 1 = prev, vertical
153 if (me.collapseTarget.isComponent) {
154 idx = Number(me.ownerCt.items.indexOf(me.collapseTarget) == me.ownerCt.items.indexOf(me) - 1) << 1 | Number(type == 'hbox');
156 idx = Number(me.collapseTarget == 'prev') << 1 | Number(type == 'hbox');
159 // Read the data out the truth table
160 me.orientation = ['horizontal', 'vertical'][idx & 1];
161 return ['bottom', 'right', 'top', 'left'][idx];
164 getCollapseTarget: function() {
167 return me.collapseTarget.isComponent ? me.collapseTarget : me.collapseTarget == 'prev' ? me.previousSibling() : me.nextSibling();
170 onTargetCollapse: function(target) {
171 this.el.addCls([this.collapsedClsInternal, this.collapsedCls]);
174 onTargetExpand: function(target) {
175 this.el.removeCls([this.collapsedClsInternal, this.collapsedCls]);
178 toggleTargetCmp: function(e, t) {
179 var cmp = this.getCollapseTarget();
181 if (cmp.isVisible()) {
184 cmp.expand(cmp.animCollapse);
187 cmp.collapse(this.renderData.collapseDir, cmp.animCollapse);
193 * Work around IE bug. %age margins do not get recalculated on element resize unless repaint called.
195 setSize: function() {
197 me.callParent(arguments);