diff --git a/bower.json b/bower.json index fc830763..9664a204 100644 --- a/bower.json +++ b/bower.json @@ -22,8 +22,10 @@ "responsive" ], "ignore": [ - "*", - "!lib/**/*" + "_raw", + "demo", + "tests", + "v2-(deprecated)" ], "main": "lib/picker.js", "homepage": "http://amsul.github.io/pickadate.js", diff --git a/lib/picker.date.js b/lib/picker.date.js index 73b9f94a..2c01de2d 100644 --- a/lib/picker.date.js +++ b/lib/picker.date.js @@ -933,6 +933,18 @@ DatePicker.prototype.nodes = function( isOpen ) { DatePicker.defaults = (function( prefix ) { return { + // Mark input as readonly + readOnly: true, + + // If set to true, the picker will never update the value of the input + // it's attached to. + apiOnly: false, + + // Close and clear the picker when the delete key is pressed + closeOnDelete: true, + + // Open the picker when the space key is pressed + openOnSpace: true, // Months and weekdays monthsFull: [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ], diff --git a/lib/picker.js b/lib/picker.js index 533ff476..89c27624 100644 --- a/lib/picker.js +++ b/lib/picker.js @@ -92,7 +92,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) { // and set as readonly to prevent keyboard popup. ELEMENT.autofocus = ELEMENT == document.activeElement ELEMENT.type = 'text' - ELEMENT.readOnly = true + ELEMENT.readOnly = SETTINGS.readOnly // Create a new picker component with the settings. @@ -132,7 +132,9 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) { // If it’s disabled or nothing inside is actively focused, re-focus the element. if ( targetDisabled || !$.contains( P.$root[0], activeElement ) ) { - ELEMENT.focus() + setTimeout( function() { + ELEMENT.focus() + }, 0 ); } // If something is superficially changed, update the `highlight` based on the `nav`. @@ -202,17 +204,24 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) { return false } - // Check if `space` or `delete` was pressed or the picker is closed with a key movement. - if ( keycode == 32 || isKeycodeDelete || !STATE.open && P.component.key[ keycode ] ) { + if ( keycode == 32 && SETTINGS.openOnSpace ) { - // Prevent it from moving the page and bubbling to doc. - event.preventDefault() - event.stopPropagation() + // Prevent it from moving the page and bubbling to doc. + event.preventDefault() + event.stopPropagation() + + // Open the picker. + P.open() + } + + if ( isKeycodeDelete && SETTINGS.closeOnDelete ) { + + // Prevent it from moving the page and bubbling to doc. + event.preventDefault() + event.stopPropagation() - // If `delete` was pressed, clear the values and close the picker. - // Otherwise open the picker. - if ( isKeycodeDelete ) { P.clear().close() } - else { P.open() } + // Clear and close the picker. + P.clear().close() } }). @@ -466,11 +475,13 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) { P.component.set( thingItem, thingValue, options || {} ) } - // Then, check to update the element value and broadcast a change. - if ( thingItem == 'select' || thingItem == 'clear' ) { - $ELEMENT.val( thingItem == 'clear' ? '' : - PickerConstructor._.trigger( P.component.formats.toString, P.component, [ SETTINGS.format, P.component.get( thingItem ) ] ) - ).trigger( 'change' ) + if ( !SETTINGS.apiOnly ) { + // Then, check to update the element value and broadcast a change. + if ( thingItem == 'select' || thingItem == 'clear' ) { + $ELEMENT.val( thingItem == 'clear' ? '' : + PickerConstructor._.trigger( P.component.formats.toString, P.component, [ SETTINGS.format, P.component.get( thingItem ) ] ) + ).trigger( 'change' ) + } } } diff --git a/lib/picker.time.js b/lib/picker.time.js index 0849c243..74567790 100644 --- a/lib/picker.time.js +++ b/lib/picker.time.js @@ -638,6 +638,18 @@ TimePicker.prototype.nodes = function( isOpen ) { TimePicker.defaults = (function( prefix ) { return { + // Mark input as readonly + readOnly: true, + + // If set to true, the picker will never update the value of the input + // it's attached to. + apiOnly: false, + + // Close and clear the picker when the delete key is pressed + closeOnDelete: true, + + // Open the picker when the space key is pressed + openOnSpace: true, // Clear clear: 'Clear',