Skip to content

Commit

Permalink
Update Meta Box
Browse files Browse the repository at this point in the history
  • Loading branch information
rilwis committed Jan 9, 2025
1 parent aa429e6 commit b76955f
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 107 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"wpmetabox/mb-relationships": "dev-master",
"wpmetabox/mb-rest-api": "dev-master",
"wpmetabox/mb-yoast-seo": "dev-master",
"wpmetabox/meta-box": "^5.10",
"wpmetabox/meta-box": "dev-master",
"wpmetabox/meta-box-beaver-themer-integrator": "dev-master",
"wpmetabox/meta-box-facetwp-integrator": "dev-master",
"wpmetabox/text-limiter": "dev-master"
Expand Down
10 changes: 6 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions modules/meta-box/css/image-select.css
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
.rwmb-image-select {
display: inline-block;
width: 80px;
height: 80px;
float: left;
margin: 0 10px 10px 0;
margin: 0 8px 8px 0;
border: 3px solid #d8d8d8;
border-radius: 3px;
border-radius: 4px;
padding: 1px;
cursor: pointer;

--color: #2271b1;
}

.block-editor-page .rwmb-image-select {
--color: var(--wp-admin-theme-color, #2271b1);
}

.rwmb-image-select img {
width: 100%;
height: 100%;
object-fit: cover;
}

.rwmb-image-select:hover,
.rwmb-image-select.rwmb-active {
border-color: #0074a2;
.rwmb-image-select:has(:checked) {
border-color: var(--color);
}

.rwmb-image_select.rwmb-image_select {
display: none;
}
1 change: 1 addition & 0 deletions modules/meta-box/css/key-value.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.rwmb-key_value-clone {
display: flex;
align-items: center;
gap: 8px;
}
.rwmb-key_value-clone input {
flex: 1;
Expand Down
17 changes: 6 additions & 11 deletions modules/meta-box/inc/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static function show( array $field, bool $saved, $post_id = 0 ) {
}

$end = static::end_html( $field );
$end = self::filter( 'end_html', $end, $field, $meta );
$end = self::filter( 'end_html', $end, $field, $meta );
$html = self::filter( 'wrapper_html', $begin . $field_html . $end, $field, $meta );

// Display label and input in DIV and allow user-defined classes to be appended.
Expand Down Expand Up @@ -75,20 +75,15 @@ public static function html( $meta, $field ) {
protected static function begin_html( array $field ): string {
$id = $field['attributes']['id'] ?? $field['id'];
$required = $field['required'] || ! empty( $field['attributes']['required'] );
$required = $required ? '<span class="rwmb-required">*</span>' : '';

$label = $field['name'] ? sprintf(
'<label for="%s">%s%s</label>',
// Translators: %1$s - field ID, %2$s - field label, %3$s - required asterisk, %4$s - label description.
'<div class="rwmb-label" id="%1$s-label"><label for="%1$s">%2$s%3$s</label>%4$s</div>',
esc_attr( $id ),
$field['name'],
$required ? '<span class="rwmb-required">*</span>' : ''
) : '';

$label .= static::label_description( $field );

$label = $label ? sprintf(
'<div class="rwmb-label" id="%s-label">%s</div>',
esc_attr( $id ),
$label
$required,
static::label_description( $field )
) : '';

$data_min_clone = is_numeric( $field['min_clone'] ) && $field['min_clone'] > 1 ? ' data-min-clone=' . $field['min_clone'] : '';
Expand Down
4 changes: 0 additions & 4 deletions modules/meta-box/inc/fields/fieldset-text.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ protected static function input_description( array $field ) : string {
return '';
}

protected static function label_description( array $field ) : string {
return '';
}

/**
* Normalize parameters for field.
*
Expand Down
1 change: 0 additions & 1 deletion modules/meta-box/inc/fields/image-select.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class RWMB_Image_Select_Field extends RWMB_Field {
public static function admin_enqueue_scripts() {
wp_enqueue_style( 'rwmb-image-select', RWMB_CSS_URL . 'image-select.css', [], RWMB_VER );
wp_style_add_data( 'rwmb-image-select', 'path', RWMB_CSS_DIR . 'image-select.css' );
wp_enqueue_script( 'rwmb-image-select', RWMB_JS_URL . 'image-select.js', [ 'jquery' ], RWMB_VER, true );
}

/**
Expand Down
17 changes: 1 addition & 16 deletions modules/meta-box/inc/fields/key-value.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,7 @@ public static function html( $meta, $field ) {
}

protected static function begin_html( array $field ) : string {
$desc = $field['desc'] ? "<p id='{$field['id']}_description' class='description'>{$field['desc']}</p>" : '';

if ( empty( $field['name'] ) ) {
return '<div class="rwmb-input">' . $desc;
}

return sprintf(
'<div class="rwmb-label">
<label for="%s">%s</label>
</div>
<div class="rwmb-input">
%s',
$field['id'],
$field['name'],
$desc
);
return parent::begin_html( $field ) . parent::input_description( $field );
}

protected static function input_description( array $field ) : string {
Expand Down
25 changes: 15 additions & 10 deletions modules/meta-box/js/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
* Transform an input into a date picker.
*/
function transform() {
var $this = $( this ),
options = $this.data( 'options' ),
$inline = $this.siblings( '.rwmb-datetime-inline' ),
$timestamp = $this.siblings( '.rwmb-datetime-timestamp' ),
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() {
options.onSelect = function () {
$this.trigger( 'change' );
}
options.beforeShow = function( i ) {
};
options.beforeShow = function ( i ) {
if ( $( i ).prop( 'readonly' ) ) {
return false;
}
}
};

if ( $timestamp.length ) {
options.onClose = options.onSelect = function () {
Expand All @@ -36,15 +41,15 @@
} );
}

if ( ! $inline.length ) {
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() ) {
if ( !$this.val() ) {
return;
}
$picker
Expand Down
29 changes: 17 additions & 12 deletions modules/meta-box/js/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
* Transform an input into a datetime picker.
*/
function transform() {
var $this = $( this ),
options = $this.data( 'options' ),
$inline = $this.siblings( '.rwmb-datetime-inline' ),
$timestamp = $this.siblings( '.rwmb-datetime-timestamp' ),
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() {
options.onSelect = function () {
$this.trigger( 'change' );
}
options.beforeShow = function( i ) {
};
options.beforeShow = function ( i ) {
if ( $( i ).prop( 'readonly' ) ) {
return false;
}
}
};

if ( $timestamp.length ) {
options.onClose = options.onSelect = function () {
Expand All @@ -36,15 +41,15 @@
} );
}

if ( ! $inline.length ) {
if ( !$inline.length ) {
$this.removeClass( 'hasDatepicker' ).datetimepicker( 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() ) {
if ( !$this.val() ) {
return;
}
$picker
Expand Down Expand Up @@ -78,9 +83,9 @@
// Set language if available
function setTimeI18n() {
if ( $.timepicker.regional.hasOwnProperty( i18n.locale ) ) {
$.timepicker.setDefaults( $.timepicker.regional[i18n.locale] );
$.timepicker.setDefaults( $.timepicker.regional[ i18n.locale ] );
} else if ( $.timepicker.regional.hasOwnProperty( i18n.localeShort ) ) {
$.timepicker.setDefaults( $.timepicker.regional[i18n.localeShort] );
$.timepicker.setDefaults( $.timepicker.regional[ i18n.localeShort ] );
}
}

Expand Down
27 changes: 0 additions & 27 deletions modules/meta-box/js/image-select.js

This file was deleted.

7 changes: 5 additions & 2 deletions modules/meta-box/js/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* Transform an input into a time picker.
*/
function transform() {
var $this = $( this ),
let $this = $( this ),
options = $this.data( 'options' ),
$inline = $this.siblings( '.rwmb-datetime-inline' ),
current = $this.val();
current = formatTime( current );

Expand All @@ -22,6 +21,10 @@
}
};

let $inline = $this.siblings( '.rwmb-datetime-inline' );
if ( !$inline.length ) {
$inline = $this.closest( '.rwmb-input-group' ).siblings( '.rwmb-datetime-inline' );
}
if ( !$inline.length ) {
$this.removeClass( 'hasDatepicker' ).timepicker( options ).timepicker( 'setTime', current );
return;
Expand Down
Loading

0 comments on commit b76955f

Please sign in to comment.