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>
33 Ext.define('Ext.resizer.Splitter', {
34 extend: 'Ext.Component',
35 requires: ['Ext.XTemplate'],
36 uses: ['Ext.resizer.SplitterTracker'],
37 alias: 'widget.splitter',
40 '<tpl if="collapsible===true"><div class="' + Ext.baseCSSPrefix + 'collapse-el ' + Ext.baseCSSPrefix + 'layout-split-{collapseDir}">&nbsp;</div></tpl>'
43 baseCls: Ext.baseCSSPrefix + 'splitter',
44 collapsedClsInternal: Ext.baseCSSPrefix + 'splitter-collapsed',
46 <span id='Ext-resizer-Splitter-cfg-collapsible'> /**
47 </span> * @cfg {Boolean} collapsible
48 * <code>true</code> to show a mini-collapse tool in the Splitter to toggle expand and collapse on the {@link #collapseTarget} Panel.
49 * Defaults to the {@link Ext.panel.Panel#collapsible collapsible} setting of the Panel.
53 <span id='Ext-resizer-Splitter-cfg-performCollapse'> /**
54 </span> * @cfg {Boolean} performCollapse
55 * <p>Set to <code>false</code> to prevent this Splitter's mini-collapse tool from managing the collapse
56 * state of the {@link #collapseTarget}.</p>
59 <span id='Ext-resizer-Splitter-cfg-collapseOnDblClick'> /**
60 </span> * @cfg {Boolean} collapseOnDblClick
61 * <code>true</code> to enable dblclick to toggle expand and collapse on the {@link #collapseTarget} Panel.
63 collapseOnDblClick: true,
65 <span id='Ext-resizer-Splitter-cfg-defaultSplitMin'> /**
66 </span> * @cfg {Number} defaultSplitMin
67 * Provides a default minimum width or height for the two components
68 * that the splitter is between.
72 <span id='Ext-resizer-Splitter-cfg-defaultSplitMax'> /**
73 </span> * @cfg {Number} defaultSplitMax
74 * Provides a default maximum width or height for the two components
75 * that the splitter is between.
77 defaultSplitMax: 1000,
79 <span id='Ext-resizer-Splitter-cfg-collapsedCls'> /**
80 </span> * @cfg {String} collapsedCls
81 * A class to add to the splitter when it is collapsed. See {@link #collapsible}.
87 <span id='Ext-resizer-Splitter-cfg-collapseTarget'> /**
88 </span> * @cfg {Mixed} collapseTarget
89 * <p>A string describing the relative position of the immediate sibling Panel to collapse. May be 'prev' or 'next' (Defaults to 'next')</p>
90 * <p>Or the immediate sibling Panel to collapse.</p>
91 * <p>The orientation of the mini-collapse tool will be inferred from this setting.</p>
92 * <p><b>Note that only Panels may be collapsed.</b></p>
94 collapseTarget: 'next',
96 <span id='Ext-resizer-Splitter-property-orientation'> /**
97 </span> * @property orientation
99 * Orientation of this Splitter. <code>'vertical'</code> when used in an hbox layout, <code>'horizontal'</code>
100 * when used in a vbox layout.
103 onRender: function() {
105 target = me.getCollapseTarget(),
106 collapseDir = me.getCollapseDirection();
108 Ext.applyIf(me.renderData, {
109 collapseDir: collapseDir,
110 collapsible: me.collapsible || target.collapsible
112 Ext.applyIf(me.renderSelectors, {
113 collapseEl: '.' + Ext.baseCSSPrefix + 'collapse-el'
116 this.callParent(arguments);
118 // Add listeners on the mini-collapse tool unless performCollapse is set to false
119 if (me.performCollapse !== false) {
120 if (me.renderData.collapsible) {
121 me.mon(me.collapseEl, 'click', me.toggleTargetCmp, me);
123 if (me.collapseOnDblClick) {
124 me.mon(me.el, 'dblclick', me.toggleTargetCmp, me);
128 // Ensure the mini collapse icon is set to the correct direction when the target is collapsed/expanded by any means
129 me.mon(target, 'collapse', me.onTargetCollapse, me);
130 me.mon(target, 'expand', me.onTargetExpand, me);
132 me.el.addCls(me.baseCls + '-' + me.orientation);
133 me.el.unselectable();
135 me.tracker = Ext.create('Ext.resizer.SplitterTracker', {
139 // Relay the most important events to our owner (could open wider later):
140 me.relayEvents(me.tracker, [ 'beforedragstart', 'dragstart', 'dragend' ]);
143 getCollapseDirection: function() {
146 type = me.ownerCt.layout.type;
148 // Avoid duplication of string tests.
149 // Create a two bit truth table of the configuration of the Splitter:
150 // Collapse Target | orientation
151 // 0 0 = next, horizontal
152 // 0 1 = next, vertical
153 // 1 0 = prev, horizontal
154 // 1 1 = prev, vertical
155 if (me.collapseTarget.isComponent) {
156 idx = Number(me.ownerCt.items.indexOf(me.collapseTarget) == me.ownerCt.items.indexOf(me) - 1) << 1 | Number(type == 'hbox');
158 idx = Number(me.collapseTarget == 'prev') << 1 | Number(type == 'hbox');
161 // Read the data out the truth table
162 me.orientation = ['horizontal', 'vertical'][idx & 1];
163 return ['bottom', 'right', 'top', 'left'][idx];
166 getCollapseTarget: function() {
169 return me.collapseTarget.isComponent ? me.collapseTarget : me.collapseTarget == 'prev' ? me.previousSibling() : me.nextSibling();
172 onTargetCollapse: function(target) {
173 this.el.addCls([this.collapsedClsInternal, this.collapsedCls]);
176 onTargetExpand: function(target) {
177 this.el.removeCls([this.collapsedClsInternal, this.collapsedCls]);
180 toggleTargetCmp: function(e, t) {
181 var cmp = this.getCollapseTarget();
183 if (cmp.isVisible()) {
186 cmp.expand(cmp.animCollapse);
189 cmp.collapse(this.renderData.collapseDir, cmp.animCollapse);
195 * Work around IE bug. %age margins do not get recalculated on element resize unless repaint called.
197 setSize: function() {
199 me.callParent(arguments);