diff options
-rw-r--r-- | demos/position/default.html | 15 | ||||
-rw-r--r-- | demos/spinner/latlong.html | 9 | ||||
-rw-r--r-- | tests/unit/spinner/spinner_core.js | 11 | ||||
-rw-r--r-- | tests/unit/spinner/spinner_methods.js | 26 | ||||
-rw-r--r-- | tests/unit/spinner/spinner_options.js | 5 | ||||
-rw-r--r-- | ui/jquery.ui.datepicker.js | 29 | ||||
-rw-r--r-- | ui/jquery.ui.position.js | 4 | ||||
-rw-r--r-- | ui/jquery.ui.spinner.js | 64 |
8 files changed, 98 insertions, 65 deletions
diff --git a/demos/position/default.html b/demos/position/default.html index f7cba888d..f5caf3bc1 100644 --- a/demos/position/default.html +++ b/demos/position/default.html @@ -14,6 +14,7 @@ <style> #parent { width: 60%; + height: 40px; margin: 10px auto; padding: 5px; border: 1px solid #777; @@ -21,8 +22,6 @@ text-align: center; } .positionable { - width: 75px; - height: 75px; position: absolute; display: block; right: 0; @@ -30,6 +29,14 @@ background-color: #bcd5e6; text-align: center; } + #positionable1 { + width: 75px; + height: 75px; + } + #positionable2 { + width: 120px; + height: 40px; + } .ui-flipped-top { border-top: 3px solid #000000; } @@ -93,13 +100,13 @@ </p> </div> -<div class="positionable"> +<div class="positionable" id="positionable1"> <p> to position </p> </div> -<div class="positionable" style="width:120px; height: 40px;"> +<div class="positionable" id="positionable2"> <p> to position 2 </p> diff --git a/demos/spinner/latlong.html b/demos/spinner/latlong.html index d1dc612b4..149d16103 100644 --- a/demos/spinner/latlong.html +++ b/demos/spinner/latlong.html @@ -21,8 +21,9 @@ map.setCenter( latlong() ); } $( "#lat, #lng" ).spinner({ - precision: 6, - change: position + step: .001, + change: position, + stop: position }); var map = new google.maps.Map( $("#map")[0], { @@ -44,10 +45,10 @@ <div class="demo"> <label for="lat">Latitude</label> -<input id="lat" name="lat" value="44.797916"> +<input id="lat" name="lat" value="44.797"> <br> <label for="lng">Longitude</label> -<input id="lng" name="lng" value="-93.278046"> +<input id="lng" name="lng" value="-93.278"> <div id="map"></div> diff --git a/tests/unit/spinner/spinner_core.js b/tests/unit/spinner/spinner_core.js index 34a79bb16..e12d1af2f 100644 --- a/tests/unit/spinner/spinner_core.js +++ b/tests/unit/spinner/spinner_core.js @@ -109,14 +109,12 @@ test( "mouse click on up button, increases value not greater than max", function }); test( "mousewheel on input", function() { - expect( 5 ); + expect( 4 ); - var element = $( "#spin" ).spinner({ + var element = $( "#spin" ).val( 0 ).spinner({ step: 2 }); - equal( element.val(), 0 ); - element.trigger( "mousewheel" ); equal( element.val(), 0, "mousewheel event without delta does not change value" ); @@ -198,10 +196,11 @@ test( "precision", function() { equal( element.val(), "0.0501", "precision from step" ); element.val( 1.05 ).spinner( "option", { - step: 1 + step: 1, + min: -9.95 }); element.spinner( "stepDown" ); - equal( element.val(), "0.05", "precision from value" ); + equal( element.val(), "0.05", "precision from min" ); }); })( jQuery ); diff --git a/tests/unit/spinner/spinner_methods.js b/tests/unit/spinner/spinner_methods.js index fbfcf1bb3..a9fd6c889 100644 --- a/tests/unit/spinner/spinner_methods.js +++ b/tests/unit/spinner/spinner_methods.js @@ -54,7 +54,7 @@ test( "disable", function() { test( "enable", function() { expect( 5 ); - var element = $( "#spin" ).spinner({ disabled: true }) + var element = $( "#spin" ).val( 1 ).spinner({ disabled: true }) wrapper = element.spinner( "widget" ); ok( wrapper.hasClass( "ui-spinner-disabled" ), "before: wrapper has ui-spinner-disabled class" ); @@ -66,7 +66,7 @@ test( "enable", function() { ok( !element.is( ":disabled" ), "after: input does not have disabled attribute" ); spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); - equals( 1, element.val(), "keyboard - value does not change on key UP" ); + equals( 2, element.val(), "keyboard - value changes on key UP" ); }); test( "pageDown", function() { @@ -117,23 +117,23 @@ test( "stepDown", function() { }); element.spinner( "stepDown" ); - equals( element.val(), -2, "stepDown 1 step" ); + equals( element.val(), "-1", "stepDown 1 step" ); element.spinner( "stepDown", 5 ); - equals( element.val(), -12, "stepDown 5 steps" ); + equals( element.val(), "-11", "stepDown 5 steps" ); element.spinner( "stepDown", 4 ); - equals( element.val(), -15, "close to min and stepDown 4 steps" ); + equals( element.val(), "-15", "close to min and stepDown 4 steps" ); element.spinner( "stepDown" ); - equals( element.val(), -15, "at min and stepDown 1 step" ); + equals( element.val(), "-15", "at min and stepDown 1 step" ); }); test( "stepUp", function() { expect( 4 ); var element = $( "#spin" ).val( 0 ).spinner({ step: 2, - max: 15 + max: 16 }); element.spinner( "stepUp" ); @@ -143,20 +143,22 @@ test( "stepUp", function() { equals( element.val(), 12, "stepUp 5 steps" ); element.spinner( "stepUp", 4 ); - equals( element.val(), 15, "close to min and stepUp 4 steps" ); + equals( element.val(), 16, "close to min and stepUp 4 steps" ); element.spinner( "stepUp" ); - equals( element.val(), 15, "at max and stepUp 1 step" ); + equals( element.val(), 16, "at max and stepUp 1 step" ); }); test( "value", function() { expect( 2 ); - var element = $( "#spin" ).val( 0 ).spinner(); + var element = $( "#spin" ).val( 0 ).spinner({ + step: 3 + }); element.spinner( "value", 10 ); - equals( element.val(), 10, "change value via value method" ); + equals( element.val(), 9, "change value via value method" ); - equals( element.spinner( "value" ), 10, "get value via value method" ); + equals( element.spinner( "value" ), 9, "get value via value method" ); }); })( jQuery ); diff --git a/tests/unit/spinner/spinner_options.js b/tests/unit/spinner/spinner_options.js index 48bdf96a9..2b557cb69 100644 --- a/tests/unit/spinner/spinner_options.js +++ b/tests/unit/spinner/spinner_options.js @@ -123,10 +123,11 @@ test( "step, 2", function() { equals( element.val(), "2", "stepUp" ); element.spinner( "value", "10.5" ); - equals( element.val(), "10.5", "value reset to 10.5" ); + equals( element.val(), "10", "value reset to 10" ); + element.val( "4.5" ); element.spinner( "stepUp" ); - equals( element.val(), "12.5", "stepUp" ); + equals( element.val(), "6", "stepUp" ); }); test( "step, 0.7", function() { diff --git a/ui/jquery.ui.datepicker.js b/ui/jquery.ui.datepicker.js index 0b6fb2218..e09dc5a50 100644 --- a/ui/jquery.ui.datepicker.js +++ b/ui/jquery.ui.datepicker.js @@ -636,10 +636,10 @@ $.extend(Datepicker.prototype, { return; var inst = $.datepicker._getInst(input); if ($.datepicker._curInst && $.datepicker._curInst != inst) { - if ( $.datepicker._datepickerShowing ) { - $.datepicker._triggerOnClose($.datepicker._curInst); - } $.datepicker._curInst.dpDiv.stop(true, true); + if ( inst && $.datepicker._datepickerShowing ) { + $.datepicker._hideDatepicker( $.datepicker._curInst.input[0] ); + } } var beforeShow = $.datepicker._get(inst, 'beforeShow'); var beforeShowSettings = beforeShow ? beforeShow.apply(input, [input, inst]) : {}; @@ -790,14 +790,6 @@ $.extend(Datepicker.prototype, { return [position.left, position.top]; }, - /* Trigger custom callback of onClose. */ - _triggerOnClose: function(inst) { - var onClose = this._get(inst, 'onClose'); - if (onClose) - onClose.apply((inst.input ? inst.input[0] : null), - [(inst.input ? inst.input.val() : ''), inst]); - }, - /* Hide the date picker from view. @param input element - the input field attached to the date picker */ _hideDatepicker: function(input) { @@ -820,8 +812,11 @@ $.extend(Datepicker.prototype, { (showAnim == 'fadeIn' ? 'fadeOut' : 'hide'))]((showAnim ? duration : null), postProcess); if (!showAnim) postProcess(); - $.datepicker._triggerOnClose(inst); this._datepickerShowing = false; + var onClose = this._get(inst, 'onClose'); + if (onClose) + onClose.apply((inst.input ? inst.input[0] : null), + [(inst.input ? inst.input.val() : ''), inst]); this._lastInput = null; if (this._inDialog) { this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' }); @@ -843,12 +838,16 @@ $.extend(Datepicker.prototype, { _checkExternalClick: function(event) { if (!$.datepicker._curInst) return; - var $target = $(event.target); - if ($target[0].id != $.datepicker._mainDivId && + + var $target = $(event.target), + inst = $.datepicker._getInst($target[0]); + + if ( ( ( $target[0].id != $.datepicker._mainDivId && $target.parents('#' + $.datepicker._mainDivId).length == 0 && !$target.hasClass($.datepicker.markerClassName) && !$target.hasClass($.datepicker._triggerClass) && - $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI)) + $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI) ) ) || + ( $target.hasClass($.datepicker.markerClassName) && $.datepicker._curInst != inst ) ) $.datepicker._hideDatepicker(); }, diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index 24a033fc2..74530b948 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -376,7 +376,7 @@ $.ui.position = { newOverBottom; if ( overTop < 0 ) { newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset; - if ( newOverBottom < 0 || newOverBottom < Math.abs( overTop ) ) { + if ( ( position.top + myOffset + atOffset + offset) > overTop && ( newOverBottom < 0 || newOverBottom < Math.abs( overTop ) ) ) { data.elem .addClass( "ui-flipped-bottom" ); @@ -385,7 +385,7 @@ $.ui.position = { } else if ( overBottom > 0 ) { newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - withinOffset; - if ( newOverTop > 0 || Math.abs( newOverTop ) < overBottom ) { + if ( ( position.top + myOffset + atOffset + offset) > overBottom && ( newOverTop > 0 || Math.abs( newOverTop ) < overBottom ) ) { data.elem .addClass( "ui-flipped-top" ); diff --git a/ui/jquery.ui.spinner.js b/ui/jquery.ui.spinner.js index d58665265..4b7239850 100644 --- a/ui/jquery.ui.spinner.js +++ b/ui/jquery.ui.spinner.js @@ -10,6 +10,7 @@ * Depends: * jquery.ui.core.js * jquery.ui.widget.js + * jquery.ui.button.js */ (function( $ ) { @@ -147,6 +148,12 @@ $.widget( "ui.spinner", { .button() .removeClass( "ui-corner-all" ); + // IE 6 doesn't understand height: 50% for the buttons + // unless the wrapper has an explicit height + if ( this.buttons.height() === uiSpinner.height() ) { + uiSpinner.height( uiSpinner.height() ); + } + // disable spinner if element was already disabled if ( this.options.disabled ) { this.disable(); @@ -213,20 +220,16 @@ $.widget( "ui.spinner", { }, _spin: function( step, event ) { + var value = this.value() || 0; + if ( !this.counter ) { this.counter = 1; } - var value = this.value(), - newVal = value + step * this._increment( this.counter ), - // fix precision from bad JS floating point math - precision = Math.max( this._precision( value ), - this._precision( this.options.step ) ); - // clamp the new value - newVal = this._trimValue( newVal.toFixed( precision ) ); + value = this._adjustValue( value + step * this._increment( this.counter ) ); - if ( !this.spinning || this._trigger( "spin", event, { value: newVal } ) !== false) { - this._value( newVal ); + if ( !this.spinning || this._trigger( "spin", event, { value: value } ) !== false) { + this._value( value ); this.counter++; } }, @@ -243,20 +246,41 @@ $.widget( "ui.spinner", { return 1; }, - _precision: function( num ) { + _precision: function() { + var precision = this._precisionOf( this.options.step ); + if ( this.options.min !== null ) { + precision = Math.max( precision, this._precisionOf( this.options.min ) ); + } + return precision; + }, + + _precisionOf: function( num ) { var str = num.toString(), decimal = str.indexOf( "." ); return decimal === -1 ? 0 : str.length - decimal - 1; }, - _trimValue: function( value ) { - var options = this.options; + _adjustValue: function( value ) { + var base, aboveMin, + options = this.options; + + // make sure we're at a valid step + // - find out where we are relative to the base (min or 0) + base = options.min !== null ? options.min : 0; + aboveMin = value - base; + // - round to the nearest step + aboveMin = Math.round(aboveMin / options.step) * options.step; + // - rounding is based on 0, so adjust back to our base + value = base + aboveMin; - if ( options.max != null && value > options.max) { + // fix precision from bad JS floating point math + value = parseFloat( value.toFixed( this._precision() ) ); + + // clamp the value + if ( options.max !== null && value > options.max) { return options.max; } - - if ( options.min != null && value < options.min ) { + if ( options.min !== null && value < options.min ) { return options.min; } @@ -295,10 +319,10 @@ $.widget( "ui.spinner", { }), _parse: function( val ) { - if ( typeof val === "string" ) { + if ( typeof val === "string" && val !== "" ) { val = window.Globalize && this.options.numberFormat ? Globalize.parseFloat( val ) : +val; } - return isNaN( val ) ? null : val; + return val === "" || isNaN( val ) ? null : val; }, _format: function( value ) { @@ -320,13 +344,13 @@ $.widget( "ui.spinner", { }, // update the value without triggering change - _value: function( value, ignoreRange ) { + _value: function( value, allowAny ) { var parsed; if ( value !== "" ) { parsed = this._parse( value ); if ( parsed !== null ) { - if ( !ignoreRange ) { - parsed = this._trimValue( parsed ); + if ( !allowAny ) { + parsed = this._adjustValue( parsed ); } value = this._format( parsed ); } |