3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.SplitBar"></div>/**
17 * @extends Ext.util.Observable
18 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
22 var split = new Ext.SplitBar("elementToDrag", "elementToSize",
23 Ext.SplitBar.HORIZONTAL, Ext.SplitBar.LEFT);
24 split.setAdapter(new Ext.SplitBar.AbsoluteLayoutAdapter("container"));
28 split.on('moved', splitterMoved);
31 * Create a new SplitBar
32 * @param {Mixed} dragElement The element to be dragged and act as the SplitBar.
33 * @param {Mixed} resizingElement The element to be resized based on where the SplitBar element is dragged
34 * @param {Number} orientation (optional) Either Ext.SplitBar.HORIZONTAL or Ext.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
35 * @param {Number} placement (optional) Either Ext.SplitBar.LEFT or Ext.SplitBar.RIGHT for horizontal or
36 Ext.SplitBar.TOP or Ext.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
37 position of the SplitBar).
39 Ext.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
42 this.el = Ext.get(dragElement, true);
43 this.el.dom.unselectable = "on";
45 this.resizingEl = Ext.get(resizingElement, true);
49 * The orientation of the split. Either Ext.SplitBar.HORIZONTAL or Ext.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
50 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
53 this.orientation = orientation || Ext.SplitBar.HORIZONTAL;
55 <div id="prop-Ext.SplitBar-tickSize"></div>/**
56 * The increment, in pixels by which to move this SplitBar. When <i>undefined</i>, the SplitBar moves smoothly.
60 <div id="prop-Ext.SplitBar-minSize"></div>/**
61 * The minimum size of the resizing element. (Defaults to 0)
66 <div id="prop-Ext.SplitBar-maxSize"></div>/**
67 * The maximum size of the resizing element. (Defaults to 2000)
72 <div id="prop-Ext.SplitBar-animate"></div>/**
73 * Whether to animate the transition to the new size
78 <div id="prop-Ext.SplitBar-useShim"></div>/**
79 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
89 this.proxy = Ext.SplitBar.createProxy(this.orientation);
91 this.proxy = Ext.get(existingProxy).dom;
94 this.dd = new Ext.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
97 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
100 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
106 * @private The adapter to use to positon and resize elements
108 this.adapter = new Ext.SplitBar.BasicLayoutAdapter();
109 this.adapter.init(this);
111 if(this.orientation == Ext.SplitBar.HORIZONTAL){
113 this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Ext.SplitBar.LEFT : Ext.SplitBar.RIGHT);
114 this.el.addClass("x-splitbar-h");
117 this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Ext.SplitBar.TOP : Ext.SplitBar.BOTTOM);
118 this.el.addClass("x-splitbar-v");
122 <div id="event-Ext.SplitBar-resize"></div>/**
124 * Fires when the splitter is moved (alias for {@link #moved})
125 * @param {Ext.SplitBar} this
126 * @param {Number} newSize the new width or height
129 <div id="event-Ext.SplitBar-moved"></div>/**
131 * Fires when the splitter is moved
132 * @param {Ext.SplitBar} this
133 * @param {Number} newSize the new width or height
136 <div id="event-Ext.SplitBar-beforeresize"></div>/**
137 * @event beforeresize
138 * Fires before the splitter is dragged
139 * @param {Ext.SplitBar} this
146 Ext.SplitBar.superclass.constructor.call(this);
149 Ext.extend(Ext.SplitBar, Ext.util.Observable, {
150 onStartProxyDrag : function(x, y){
151 this.fireEvent("beforeresize", this);
152 this.overlay = Ext.DomHelper.append(document.body, {cls: "x-drag-overlay", html: " "}, true);
153 this.overlay.unselectable();
154 this.overlay.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
156 Ext.get(this.proxy).setDisplayed("block");
157 var size = this.adapter.getElementSize(this);
158 this.activeMinSize = this.getMinimumSize();
159 this.activeMaxSize = this.getMaximumSize();
160 var c1 = size - this.activeMinSize;
161 var c2 = Math.max(this.activeMaxSize - size, 0);
162 if(this.orientation == Ext.SplitBar.HORIZONTAL){
163 this.dd.resetConstraints();
164 this.dd.setXConstraint(
165 this.placement == Ext.SplitBar.LEFT ? c1 : c2,
166 this.placement == Ext.SplitBar.LEFT ? c2 : c1,
169 this.dd.setYConstraint(0, 0);
171 this.dd.resetConstraints();
172 this.dd.setXConstraint(0, 0);
173 this.dd.setYConstraint(
174 this.placement == Ext.SplitBar.TOP ? c1 : c2,
175 this.placement == Ext.SplitBar.TOP ? c2 : c1,
179 this.dragSpecs.startSize = size;
180 this.dragSpecs.startPoint = [x, y];
181 Ext.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
185 * @private Called after the drag operation by the DDProxy
187 onEndProxyDrag : function(e){
188 Ext.get(this.proxy).setDisplayed(false);
189 var endPoint = Ext.lib.Event.getXY(e);
191 Ext.destroy(this.overlay);
195 if(this.orientation == Ext.SplitBar.HORIZONTAL){
196 newSize = this.dragSpecs.startSize +
197 (this.placement == Ext.SplitBar.LEFT ?
198 endPoint[0] - this.dragSpecs.startPoint[0] :
199 this.dragSpecs.startPoint[0] - endPoint[0]
202 newSize = this.dragSpecs.startSize +
203 (this.placement == Ext.SplitBar.TOP ?
204 endPoint[1] - this.dragSpecs.startPoint[1] :
205 this.dragSpecs.startPoint[1] - endPoint[1]
208 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
209 if(newSize != this.dragSpecs.startSize){
210 if(this.fireEvent('beforeapply', this, newSize) !== false){
211 this.adapter.setElementSize(this, newSize);
212 this.fireEvent("moved", this, newSize);
213 this.fireEvent("resize", this, newSize);
218 <div id="method-Ext.SplitBar-getAdapter"></div>/**
219 * Get the adapter this SplitBar uses
220 * @return The adapter object
222 getAdapter : function(){
226 <div id="method-Ext.SplitBar-setAdapter"></div>/**
227 * Set the adapter this SplitBar uses
228 * @param {Object} adapter A SplitBar adapter object
230 setAdapter : function(adapter){
231 this.adapter = adapter;
232 this.adapter.init(this);
235 <div id="method-Ext.SplitBar-getMinimumSize"></div>/**
236 * Gets the minimum size for the resizing element
237 * @return {Number} The minimum size
239 getMinimumSize : function(){
243 <div id="method-Ext.SplitBar-setMinimumSize"></div>/**
244 * Sets the minimum size for the resizing element
245 * @param {Number} minSize The minimum size
247 setMinimumSize : function(minSize){
248 this.minSize = minSize;
251 <div id="method-Ext.SplitBar-getMaximumSize"></div>/**
252 * Gets the maximum size for the resizing element
253 * @return {Number} The maximum size
255 getMaximumSize : function(){
259 <div id="method-Ext.SplitBar-setMaximumSize"></div>/**
260 * Sets the maximum size for the resizing element
261 * @param {Number} maxSize The maximum size
263 setMaximumSize : function(maxSize){
264 this.maxSize = maxSize;
267 <div id="method-Ext.SplitBar-setCurrentSize"></div>/**
268 * Sets the initialize size for the resizing element
269 * @param {Number} size The initial size
271 setCurrentSize : function(size){
272 var oldAnimate = this.animate;
273 this.animate = false;
274 this.adapter.setElementSize(this, size);
275 this.animate = oldAnimate;
278 <div id="method-Ext.SplitBar-destroy"></div>/**
279 * Destroy this splitbar.
280 * @param {Boolean} removeEl True to remove the element
282 destroy : function(removeEl){
283 Ext.destroy(this.shim, Ext.get(this.proxy));
288 this.purgeListeners();
293 * @private static Create our own proxy element element. So it will be the same same size on all browsers, we won't use borders. Instead we use a background color.
295 Ext.SplitBar.createProxy = function(dir){
296 var proxy = new Ext.Element(document.createElement("div"));
297 document.body.appendChild(proxy.dom);
298 proxy.unselectable();
299 var cls = 'x-splitbar-proxy';
300 proxy.addClass(cls + ' ' + (dir == Ext.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
304 <div id="cls-Ext.SplitBar.BasicLayoutAdapter"></div>/**
305 * @class Ext.SplitBar.BasicLayoutAdapter
306 * Default Adapter. It assumes the splitter and resizing element are not positioned
307 * elements and only gets/sets the width of the element. Generally used for table based layouts.
309 Ext.SplitBar.BasicLayoutAdapter = function(){
312 Ext.SplitBar.BasicLayoutAdapter.prototype = {
313 // do nothing for now
317 <div id="method-Ext.SplitBar.BasicLayoutAdapter-getElementSize"></div>/**
318 * Called before drag operations to get the current size of the resizing element.
319 * @param {Ext.SplitBar} s The SplitBar using this adapter
321 getElementSize : function(s){
322 if(s.orientation == Ext.SplitBar.HORIZONTAL){
323 return s.resizingEl.getWidth();
325 return s.resizingEl.getHeight();
329 <div id="method-Ext.SplitBar.BasicLayoutAdapter-setElementSize"></div>/**
330 * Called after drag operations to set the size of the resizing element.
331 * @param {Ext.SplitBar} s The SplitBar using this adapter
332 * @param {Number} newSize The new size to set
333 * @param {Function} onComplete A function to be invoked when resizing is complete
335 setElementSize : function(s, newSize, onComplete){
336 if(s.orientation == Ext.SplitBar.HORIZONTAL){
338 s.resizingEl.setWidth(newSize);
340 onComplete(s, newSize);
343 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
348 s.resizingEl.setHeight(newSize);
350 onComplete(s, newSize);
353 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
359 <div id="cls-Ext.SplitBar.AbsoluteLayoutAdapter"></div>/**
360 *@class Ext.SplitBar.AbsoluteLayoutAdapter
361 * @extends Ext.SplitBar.BasicLayoutAdapter
362 * Adapter that moves the splitter element to align with the resized sizing element.
363 * Used with an absolute positioned SplitBar.
364 * @param {Mixed} container The container that wraps around the absolute positioned content. If it's
365 * document.body, make sure you assign an id to the body element.
367 Ext.SplitBar.AbsoluteLayoutAdapter = function(container){
368 this.basic = new Ext.SplitBar.BasicLayoutAdapter();
369 this.container = Ext.get(container);
372 Ext.SplitBar.AbsoluteLayoutAdapter.prototype = {
377 getElementSize : function(s){
378 return this.basic.getElementSize(s);
381 setElementSize : function(s, newSize, onComplete){
382 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
385 moveSplitter : function(s){
386 var yes = Ext.SplitBar;
389 s.el.setX(s.resizingEl.getRight());
392 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
395 s.el.setY(s.resizingEl.getBottom());
398 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
404 <div id="prop-Ext.SplitBar.AbsoluteLayoutAdapter-VERTICAL"></div>/**
405 * Orientation constant - Create a vertical SplitBar
409 Ext.SplitBar.VERTICAL = 1;
411 <div id="prop-Ext.SplitBar.AbsoluteLayoutAdapter-HORIZONTAL"></div>/**
412 * Orientation constant - Create a horizontal SplitBar
416 Ext.SplitBar.HORIZONTAL = 2;
418 <div id="prop-Ext.SplitBar.AbsoluteLayoutAdapter-LEFT"></div>/**
419 * Placement constant - The resizing element is to the left of the splitter element
423 Ext.SplitBar.LEFT = 1;
425 <div id="prop-Ext.SplitBar.AbsoluteLayoutAdapter-RIGHT"></div>/**
426 * Placement constant - The resizing element is to the right of the splitter element
430 Ext.SplitBar.RIGHT = 2;
432 <div id="prop-Ext.SplitBar.AbsoluteLayoutAdapter-TOP"></div>/**
433 * Placement constant - The resizing element is positioned above the splitter element
437 Ext.SplitBar.TOP = 3;
439 <div id="prop-Ext.SplitBar.AbsoluteLayoutAdapter-BOTTOM"></div>/**
440 * Placement constant - The resizing element is positioned under splitter element
444 Ext.SplitBar.BOTTOM = 4;