( function ( $, _, rwmb ) { 'use strict'; /** * Transform an input into a date picker. */ function transform() { let $this = $( this ), options = $this.data( 'options' ); let $inline = $this.siblings( '.rwmb-datetime-inline' ); if ( !$inline.length ) { $inline = $this.closest( '.rwmb-input-group' ).siblings( '.rwmb-datetime-inline' ); } let $timestamp = $this.siblings( '.rwmb-datetime-timestamp' ), current = $this.val(), $picker = $inline.length ? $inline : $this; $this.siblings( '.ui-datepicker-append' ).remove(); // Remove appended text options.onSelect = function () { $this.trigger( 'change' ); }; options.beforeShow = function ( i ) { if ( $( i ).prop( 'readonly' ) ) { return false; } }; if ( $timestamp.length ) { options.onClose = options.onSelect = function () { $timestamp.val( getTimestamp( $picker.datepicker( 'getDate' ) ) ); $this.trigger( 'change' ); }; $this.on( 'change', () => { if ( !$this.val() ) { $timestamp.val( '' ); } } ); } if ( !$inline.length ) { $this.removeClass( 'hasDatepicker' ).datepicker( options ); return; } options.altField = '#' + $this.attr( 'id' ); $this.on( 'keydown', _.debounce( function () { // if val is empty, return to allow empty datepicker input. if ( !$this.val() ) { return; } $picker .datepicker( 'setDate', $this.val() ) .find( '.ui-datepicker-current-day' ) .trigger( 'click' ); }, 600 ) ); $inline .removeClass( 'hasDatepicker' ) .empty() .prop( 'id', '' ) .datepicker( options ) .datepicker( 'setDate', current ); } /** * Convert date to Unix timestamp in milliseconds * @link http://stackoverflow.com/a/14006555/556258 * @param date * @return number */ function getTimestamp( date ) { if ( date === null ) { return ''; } var milliseconds = Date.UTC( date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds() ); return Math.floor( milliseconds / 1000 ); } function init( e ) { /** * WordPress sets localized data for jQuery UI datepicker at document ready. * Using setTimeout to ensure the code runs after the localized data is set. * @link https://wordpress.org/support/topic/inline-date-field-not-localization/ */ setTimeout( () => { $( e.target ).find( '.rwmb-date' ).each( transform ); }, 0 ); } rwmb.$document .on( 'mb_ready', init ) .on( 'clone', '.rwmb-date', transform ); } )( jQuery, _, rwmb );
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
jqueryui | Folder | 0755 |
|
|
leaflet | Folder | 0755 |
|
|
select2 | Folder | 0755 |
|
|
validation | Folder | 0755 |
|
|
wp-color-picker-alpha | Folder | 0755 |
|
|
autocomplete.js | File | 1.62 KB | 0644 |
|
autosave.js | File | 595 B | 0644 |
|
button-group.js | File | 1018 B | 0644 |
|
clone.js | File | 9.04 KB | 0644 |
|
color.js | File | 1.33 KB | 0644 |
|
date.js | File | 2.47 KB | 0644 |
|
datetime.js | File | 2.87 KB | 0644 |
|
file-input.js | File | 1.87 KB | 0644 |
|
file-upload.js | File | 5.1 KB | 0644 |
|
file.js | File | 3.88 KB | 0644 |
|
icon.js | File | 769 B | 0644 |
|
image-advanced.js | File | 1015 B | 0644 |
|
image-upload.js | File | 1007 B | 0644 |
|
input-list.js | File | 1.07 KB | 0644 |
|
map-frontend.js | File | 2.01 KB | 0644 |
|
map.js | File | 8.6 KB | 0644 |
|
media.js | File | 15.45 KB | 0644 |
|
modal.js | File | 4.12 KB | 0644 |
|
oembed.js | File | 880 B | 0644 |
|
osm-frontend.js | File | 1.2 KB | 0644 |
|
osm.js | File | 7.79 KB | 0644 |
|
post.js | File | 1.23 KB | 0644 |
|
range.js | File | 475 B | 0644 |
|
script.js | File | 751 B | 0644 |
|
select-advanced.js | File | 3.67 KB | 0644 |
|
select-tree.js | File | 1.62 KB | 0644 |
|
select.js | File | 536 B | 0644 |
|
slider.js | File | 922 B | 0644 |
|
taxonomy.js | File | 1.21 KB | 0644 |
|
time.js | File | 1.78 KB | 0644 |
|
user.js | File | 1.43 KB | 0644 |
|
video.js | File | 1.12 KB | 0644 |
|
wysiwyg.js | File | 5.36 KB | 0644 |
|