/** * @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