这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"responsive"
],
"ignore": [
"*",
"!lib/**/*"
"_raw",
"demo",
"tests",
"v2-(deprecated)"
],
"main": "lib/picker.js",
"homepage": "http://amsul.github.io/pickadate.js",
Expand Down
12 changes: 12 additions & 0 deletions lib/picker.date.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ],
Expand Down
43 changes: 27 additions & 16 deletions lib/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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()
}
}).

Expand Down Expand Up @@ -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' )
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions lib/picker.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down