/** * @license jQuery UI Spinner 1.20 * * Copyright (c) 2009-2010 Brant Burnett * Dual licensed under the MIT or GPL Version 2 licenses. */ (function($,undefined){var active='ui-state-active',hover='ui-state-hover',disabled='ui-state-disabled',keyCode=$.ui.keyCode,up=keyCode.UP,down=keyCode.DOWN,right=keyCode.RIGHT,left=keyCode.LEFT,pageUp=keyCode.PAGE_UP,pageDown=keyCode.PAGE_DOWN,home=keyCode.HOME,end=keyCode.END,msie=$.browser.msie,mouseWheelEventName=$.browser.mozilla?'DOMMouseScroll':'mousewheel',eventNamespace='.uispinner',validKeys=[up,down,right,left,pageUp,pageDown,home,end,keyCode.BACKSPACE,keyCode.DELETE,keyCode.TAB],focusCtrl;$.widget('ui.spinner',{options:{min:null,max:null,allowNull:false,group:'',point:'.',prefix:'',suffix:'',places:null,defaultStep:1,largeStep:10,mouseWheel:true,increment:'slow',className:null,showOn:'always',width:16,upIconClass:"ui-icon-triangle-1-n",downIconClass:"ui-icon-triangle-1-s",format:function(num,places){var options=this,regex=/(\d+)(\d{3})/,result=((isNaN(num)?0:Math.abs(num)).toFixed(places))+'';for(result=result.replace('.',options.point);regex.test(result)&&options.group;result=result.replace(regex,'$1'+options.group+'$2')){};return(num<0?'-':'')+options.prefix+result+options.suffix},parse:function(val){var options=this;if(options.group=='.')val=val.replace('.','');if(options.point!='.')val=val.replace(options.point,'.');return parseFloat(val.replace(/[^0-9\-\.]/g,''))}},_create:function(){var self=this,input=self.element,type=input.attr('type');if(!input.is('input')||((type!='text')&&(type!='number'))){console.error('Invalid target for ui.spinner');return}self._procOptions(true);self._createButtons(input);if(!input.is(':enabled'))self.disable()},_createButtons:function(input){function getMargin(margin){return margin=='auto'?0:parseInt(margin)}var self=this,options=self.options,className=options.className,buttonWidth=options.width,showOn=options.showOn,box=$.support.boxModel,height=input.outerHeight(),rightMargin=self.oMargin=getMargin(input.css('margin-right')),wrapper=self.wrapper=input.css({width:(self.oWidth=(box?input.width():input.outerWidth()))-buttonWidth,marginRight:rightMargin+buttonWidth,textAlign:'right'}).after('').next(),btnContainer=self.btnContainer=$('
'+'
 
'+'
 
'+'
'),upButton,downButton,buttons,icons,hoverDelay,hoverDelayCallback,hovered,inKeyDown,inSpecialKey,inMouseDown,rtl=input[0].dir=='rtl';if(className)wrapper.addClass(className);wrapper.append(btnContainer.css({height:height,left:-buttonWidth-rightMargin,top:(input.offset().top-wrapper.offset().top)+'px'}));buttons=self.buttons=btnContainer.find('.ui-spinner-button');buttons.css({width:buttonWidth-(box?buttons.outerWidth()-buttons.width():0),height:height/2-(box?buttons.outerHeight()-buttons.height():0)});upButton=buttons[0];downButton=buttons[1];icons=buttons.find('.ui-icon');icons.css({marginLeft:(buttons.innerWidth()-icons.width())/2,marginTop:(buttons.innerHeight()-icons.height())/2});btnContainer.width(buttons.outerWidth());if(showOn!='always')btnContainer.css('opacity',0);if(showOn=='hover'||showOn=='both')buttons.add(input).bind('mouseenter'+eventNamespace,function(){setHoverDelay(function(){hovered=true;if(!self.focused||(showOn=='hover'))self.showButtons()})}).bind('mouseleave'+eventNamespace,function hoverOut(){setHoverDelay(function(){hovered=false;if(!self.focused||(showOn=='hover'))self.hideButtons()})});buttons.hover(function(){self.buttons.removeClass(hover);if(!options.disabled)$(this).addClass(hover)},function(){$(this).removeClass(hover)}).mousedown(mouseDown).mouseup(mouseUp).mouseout(mouseUp);if(msie)buttons.dblclick(function(){if(!options.disabled){self._change();self._doSpin((this===upButton?1:-1)*options.step)}return false}).bind('selectstart',function(){return false});input.bind('keydown'+eventNamespace,function(e){var dir,large,limit,keyCode=e.keyCode;if(e.ctrl||e.alt)return true;if(isSpecialKey(keyCode))inSpecialKey=true;if(inKeyDown)return false;switch(keyCode){case up:case pageUp:dir=1;large=keyCode==pageUp;break;case down:case pageDown:dir=-1;large=keyCode==pageDown;break;case right:case left:dir=(keyCode==right)^rtl?1:-1;break;case home:limit=self.options.min;if(limit!=null)self._setValue(limit);return false;case end:limit=self.options.max;limit=self.options.max;if(limit!=null)self._setValue(limit);return false}if(dir){if(!inKeyDown&&!options.disabled){keyDir=dir;$(dir>0?upButton:downButton).addClass(active);inKeyDown=true;self._startSpin(dir,large)}return false}}).bind('keyup'+eventNamespace,function(e){if(e.ctrl||e.alt)return true;if(isSpecialKey(keyCode))inSpecialKey=false;switch(e.keyCode){case up:case right:case pageUp:case down:case left:case pageDown:buttons.removeClass(active)self._stopSpin();inKeyDown=false;return false}}).bind('keypress'+eventNamespace,function(e){if(invalidKey(e.keyCode,e.charCode))return false}).bind('change'+eventNamespace,function(){self._change()}).bind('focus'+eventNamespace,function(){function selectAll(){self.element.select()}msie?selectAll():setTimeout(selectAll,0);self.focused=true;focusCtrl=self;if(!hovered&&(showOn=='focus'||showOn=='both'))self.showButtons()}).bind('blur'+eventNamespace,function(){self.focused=false;if(!hovered&&(showOn=='focus'||showOn=='both'))self.hideButtons()});function isSpecialKey(keyCode){for(var i=0;i='0')&&(ch<='9')||(ch=='-'))return false;if(((self.places>0)&&(ch==options.point))||(ch==options.group))return false;return true}function setHoverDelay(callback){if(hoverDelay){if(callback===hoverDelayCallback)return;clearTimeout(hoverDelay)}hoverDelayCallback=callback;hoverDelay=setTimeout(execute,100);function execute(){hoverDelay=0;callback()}}function mouseDown(){if(!options.disabled){var input=self.element[0],dir=(this===upButton?1:-1);input.focus();input.select();$(this).addClass(active);inMouseDown=true;self._startSpin(dir)}return false}function mouseUp(){if(inMouseDown){$(this).removeClass(active);self._stopSpin();inMouseDown=false}return false}},_procOptions:function(init){var self=this,input=self.element,options=self.options,min=options.min,max=options.max,step=options.step,places=options.places,maxlength=-1,temp;if(options.increment=='slow')options.increment=[{count:1,mult:1,delay:250},{count:3,mult:1,delay:100},{count:0,mult:1,delay:50}];else if(options.increment=='fast')options.increment=[{count:1,mult:1,delay:250},{count:19,mult:1,delay:100},{count:80,mult:1,delay:20},{count:100,mult:10,delay:20},{count:0,mult:100,delay:20}];if((min==null)&&((temp=input.attr('min'))!=null))min=parseFloat(temp);if((max==null)&&((temp=input.attr('max'))!=null))max=parseFloat(temp);if(!step&&((temp=input.attr('step'))!=null))if(temp!='any'){step=parseFloat(temp);options.largeStep*=step}options.step=step=step||options.defaultStep;if((places==null)&&((temp=step+'').indexOf('.')!=-1))places=temp.length-temp.indexOf('.')-1;self.places=places;if((max!=null)&&(min!=null)){if(min>max)min=max;maxlength=Math.max(Math.max(maxlength,options.format(max,places,input).length),options.format(min,places,input).length)}if(init)self.inputMaxLength=input[0].maxLength;temp=self.inputMaxLength;if(temp>0){maxlength=maxlength>0?Math.min(temp,maxlength):temp;temp=Math.pow(10,maxlength)-1;if((max==null)||(max>temp))max=temp;temp=-(temp+1)/10+1;if((min==null)||(min0)input.attr('maxlength',maxlength);options.min=min;options.max=max;self._change();input.unbind(mouseWheelEventName+eventNamespace);if(options.mouseWheel)input.bind(mouseWheelEventName+eventNamespace,self._mouseWheel)},_mouseWheel:function(e){var self=$.data(this,'spinner');if(!self.options.disabled&&self.focused&&(focusCtrl===self)){self._change();self._doSpin(((e.wheelDelta||-e.detail)>0?1:-1)*self.options.step);return false}},_setTimer:function(delay,dir,large){var self=this;self._stopSpin();self.timer=setInterval(fire,delay);function fire(){self._spin(dir,large)}},_stopSpin:function(){if(this.timer){clearInterval(this.timer);this.timer=0}},_startSpin:function(dir,large){var self=this,options=self.options,increment=options.increment;self._change();self._doSpin(dir*(large?self.options.largeStep:self.options.step));if(increment&&increment.length>0){self.counter=0;self.incCounter=0;self._setTimer(increment[0].delay,dir,large)}},_spin:function(dir,large){var self=this,increment=self.options.increment,curIncrement=increment[self.incCounter];self._doSpin(dir*curIncrement.mult*(large?self.options.largeStep:self.options.step));self.counter++;if((self.counter>curIncrement.count)&&(self.incCounter0?self.options.min:self.options.max)||0;self._setValue(value+step)},_parseValue:function(){var value=this.element.val();return value?this.options.parse(value,this.element):null},_validate:function(value){var options=this.options,min=options.min,max=options.max;if((value==null)&&!options.allowNull)value=this.curvalue!=null?this.curvalue:min||max||0;if((max!=null)&&(value>max))return max;else if((min!=null)&&(value