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.ux.Spinner"></div>/**
16 * @class Ext.ux.Spinner
17 * @extends Ext.util.Observable
18 * Creates a Spinner control utilized by Ext.ux.form.SpinnerField
20 Ext.ux.Spinner = Ext.extend(Ext.util.Observable, {
22 alternateIncrementValue: 5,
23 triggerClass: 'x-form-spinner-trigger',
24 splitterClass: 'x-form-spinner-splitter',
25 alternateKey: Ext.EventObject.shiftKey,
29 constructor: function(config){
30 Ext.ux.Spinner.superclass.constructor.call(this, config);
31 Ext.apply(this, config);
32 this.mimicing = false;
35 init: function(field){
38 field.afterMethod('onRender', this.doRender, this);
39 field.afterMethod('onEnable', this.doEnable, this);
40 field.afterMethod('onDisable', this.doDisable, this);
41 field.afterMethod('afterRender', this.doAfterRender, this);
42 field.afterMethod('onResize', this.doResize, this);
43 field.afterMethod('onFocus', this.doFocus, this);
44 field.beforeMethod('onDestroy', this.doDestroy, this);
47 doRender: function(ct, position){
48 var el = this.el = this.field.getEl();
52 f.wrap = this.wrap = el.wrap({
53 cls: "x-form-field-wrap"
57 this.wrap = f.wrap.addClass('x-form-field-wrap');
60 this.trigger = this.wrap.createChild({
62 src: Ext.BLANK_IMAGE_URL,
63 cls: "x-form-trigger " + this.triggerClass
67 this.wrap.setWidth(el.getWidth() + this.trigger.getWidth());
70 this.splitter = this.wrap.createChild({
72 cls: this.splitterClass,
73 style: 'width:13px; height:2px;'
75 this.splitter.setRight((Ext.isIE) ? 1 : 2).setTop(10).show();
77 this.proxy = this.trigger.createProxy('', this.splitter, true);
78 this.proxy.addClass("x-form-spinner-proxy");
79 this.proxy.setStyle('left', '0px');
80 this.proxy.setSize(14, 1);
82 this.dd = new Ext.dd.DDProxy(this.splitter.dom.id, "SpinnerDrag", {
83 dragElId: this.proxy.id
90 doAfterRender: function(){
92 if (Ext.isIE && this.el.getY() != (y = this.trigger.getY())) {
100 this.disabled = false;
101 this.wrap.removeClass(this.field.disabledClass);
105 doDisable: function(){
107 this.disabled = true;
108 this.wrap.addClass(this.field.disabledClass);
109 this.el.removeClass(this.field.disabledClass);
113 doResize: function(w, h){
114 if (typeof w == 'number') {
115 this.el.setWidth(w - this.trigger.getWidth());
117 this.wrap.setWidth(this.el.getWidth() + this.trigger.getWidth());
121 if (!this.mimicing) {
122 this.wrap.addClass('x-trigger-wrap-focus');
123 this.mimicing = true;
124 Ext.get(Ext.isIE ? document.body : document).on("mousedown", this.mimicBlur, this, {
127 this.el.on('keydown', this.checkTab, this);
132 checkTab: function(e){
133 if (e.getKey() == e.TAB) {
139 mimicBlur: function(e){
140 if (!this.wrap.contains(e.target) && this.field.validateBlur(e)) {
146 triggerBlur: function(){
147 this.mimicing = false;
148 Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
149 this.el.un("keydown", this.checkTab, this);
150 this.field.beforeBlur();
151 this.wrap.removeClass('x-trigger-wrap-focus');
152 this.field.onBlur.call(this.field);
155 initTrigger: function(){
156 this.trigger.addClassOnOver('x-form-trigger-over');
157 this.trigger.addClassOnClick('x-form-trigger-click');
160 initSpinner: function(){
161 this.field.addEvents({
167 this.keyNav = new Ext.KeyNav(this.el, {
178 "pageUp": function(e){
180 this.onSpinUpAlternate();
183 "pageDown": function(e){
185 this.onSpinDownAlternate();
191 this.repeater = new Ext.util.ClickRepeater(this.trigger, {
192 accelerate: this.accelerate
194 this.field.mon(this.repeater, "click", this.onTriggerClick, this, {
198 this.field.mon(this.trigger, {
199 mouseover: this.onMouseOver,
200 mouseout: this.onMouseOut,
201 mousemove: this.onMouseMove,
202 mousedown: this.onMouseDown,
203 mouseup: this.onMouseUp,
208 this.field.mon(this.wrap, "mousewheel", this.handleMouseWheel, this);
210 this.dd.setXConstraint(0, 0, 10)
211 this.dd.setYConstraint(1500, 1500, 10);
212 this.dd.endDrag = this.endDrag.createDelegate(this);
213 this.dd.startDrag = this.startDrag.createDelegate(this);
214 this.dd.onDrag = this.onDrag.createDelegate(this);
217 onMouseOver: function(){
221 var middle = this.getMiddle();
222 this.tmpHoverClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-overup' : 'x-form-spinner-overdown';
223 this.trigger.addClass(this.tmpHoverClass);
227 onMouseOut: function(){
228 this.trigger.removeClass(this.tmpHoverClass);
232 onMouseMove: function(){
236 var middle = this.getMiddle();
237 if (((Ext.EventObject.getPageY() > middle) && this.tmpHoverClass == "x-form-spinner-overup") ||
238 ((Ext.EventObject.getPageY() < middle) && this.tmpHoverClass == "x-form-spinner-overdown")) {
243 onMouseDown: function(){
247 var middle = this.getMiddle();
248 this.tmpClickClass = (Ext.EventObject.getPageY() < middle) ? 'x-form-spinner-clickup' : 'x-form-spinner-clickdown';
249 this.trigger.addClass(this.tmpClickClass);
253 onMouseUp: function(){
254 this.trigger.removeClass(this.tmpClickClass);
258 onTriggerClick: function(){
259 if (this.disabled || this.el.dom.readOnly) {
262 var middle = this.getMiddle();
263 var ud = (Ext.EventObject.getPageY() < middle) ? 'Up' : 'Down';
264 this['onSpin' + ud]();
268 getMiddle: function(){
269 var t = this.trigger.getTop();
270 var h = this.trigger.getHeight();
271 var middle = t + (h / 2);
276 //checks if control is allowed to spin
277 isSpinnable: function(){
278 if (this.disabled || this.el.dom.readOnly) {
279 Ext.EventObject.preventDefault(); //prevent scrolling when disabled/readonly
285 handleMouseWheel: function(e){
286 //disable scrolling when not focused
287 if (this.wrap.hasClass('x-trigger-wrap-focus') == false) {
291 var delta = e.getWheelDelta();
304 startDrag: function(){
306 this._previousY = Ext.fly(this.dd.getDragEl()).getTop();
319 var y = Ext.fly(this.dd.getDragEl()).getTop();
322 if (this._previousY > y) {
325 if (this._previousY < y) {
329 this['onSpin' + ud]();
336 onSpinUp: function(){
337 if (this.isSpinnable() == false) {
340 if (Ext.EventObject.shiftKey == true) {
341 this.onSpinUpAlternate();
345 this.spin(false, false);
347 this.field.fireEvent("spin", this);
348 this.field.fireEvent("spinup", this);
352 onSpinDown: function(){
353 if (this.isSpinnable() == false) {
356 if (Ext.EventObject.shiftKey == true) {
357 this.onSpinDownAlternate();
361 this.spin(true, false);
363 this.field.fireEvent("spin", this);
364 this.field.fireEvent("spindown", this);
368 onSpinUpAlternate: function(){
369 if (this.isSpinnable() == false) {
372 this.spin(false, true);
373 this.field.fireEvent("spin", this);
374 this.field.fireEvent("spinup", this);
378 onSpinDownAlternate: function(){
379 if (this.isSpinnable() == false) {
382 this.spin(true, true);
383 this.field.fireEvent("spin", this);
384 this.field.fireEvent("spindown", this);
387 spin: function(down, alternate){
388 var v = parseFloat(this.field.getValue());
389 var incr = (alternate == true) ? this.alternateIncrementValue : this.incrementValue;
390 (down == true) ? v -= incr : v += incr;
392 v = (isNaN(v)) ? this.defaultValue : v;
393 v = this.fixBoundries(v);
394 this.field.setRawValue(v);
397 fixBoundries: function(value){
400 if (this.field.minValue != undefined && v < this.field.minValue) {
401 v = this.field.minValue;
403 if (this.field.maxValue != undefined && v > this.field.maxValue) {
404 v = this.field.maxValue;
407 return this.fixPrecision(v);
411 fixPrecision: function(value){
412 var nan = isNaN(value);
413 if (!this.field.allowDecimals || this.field.decimalPrecision == -1 || nan || !value) {
414 return nan ? '' : value;
416 return parseFloat(parseFloat(value).toFixed(this.field.decimalPrecision));
419 doDestroy: function(){
421 this.trigger.remove();
425 delete this.field.wrap;
429 this.splitter.remove();
442 this.repeater.purgeListeners();
445 Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur, this);
451 Ext.form.Spinner = Ext.ux.Spinner;</pre>