wip
This commit is contained in:
@@ -109,18 +109,35 @@ class WP_Widget_Archives extends WP_Widget {
|
||||
|
||||
<?php ob_start(); ?>
|
||||
<script>
|
||||
(function() {
|
||||
var dropdown = document.getElementById( "<?php echo esc_js( $dropdown_id ); ?>" );
|
||||
( ( dropdownId ) => {
|
||||
const dropdown = document.getElementById( dropdownId );
|
||||
function onSelectChange() {
|
||||
if ( dropdown.options[ dropdown.selectedIndex ].value !== '' ) {
|
||||
document.location.href = this.options[ this.selectedIndex ].value;
|
||||
setTimeout( () => {
|
||||
if ( 'escape' === dropdown.dataset.lastkey ) {
|
||||
return;
|
||||
}
|
||||
if ( dropdown.value ) {
|
||||
document.location.href = dropdown.value;
|
||||
}
|
||||
}, 250 );
|
||||
}
|
||||
function onKeyUp( event ) {
|
||||
if ( 'Escape' === event.key ) {
|
||||
dropdown.dataset.lastkey = 'escape';
|
||||
} else {
|
||||
delete dropdown.dataset.lastkey;
|
||||
}
|
||||
}
|
||||
dropdown.onchange = onSelectChange;
|
||||
})();
|
||||
function onClick() {
|
||||
delete dropdown.dataset.lastkey;
|
||||
}
|
||||
dropdown.addEventListener( 'keyup', onKeyUp );
|
||||
dropdown.addEventListener( 'click', onClick );
|
||||
dropdown.addEventListener( 'change', onSelectChange );
|
||||
})( <?php echo wp_json_encode( $dropdown_id, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?> );
|
||||
</script>
|
||||
<?php
|
||||
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) );
|
||||
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) );
|
||||
} else {
|
||||
$format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
|
||||
|
||||
|
||||
@@ -96,19 +96,36 @@ class WP_Widget_Categories extends WP_Widget {
|
||||
?>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
var dropdown = document.getElementById( "<?php echo esc_js( $dropdown_id ); ?>" );
|
||||
function onCatChange() {
|
||||
if ( dropdown.options[ dropdown.selectedIndex ].value > 0 ) {
|
||||
dropdown.parentNode.submit();
|
||||
( ( dropdownId ) => {
|
||||
const dropdown = document.getElementById( dropdownId );
|
||||
function onSelectChange() {
|
||||
setTimeout( () => {
|
||||
if ( 'escape' === dropdown.dataset.lastkey ) {
|
||||
return;
|
||||
}
|
||||
if ( dropdown.value && parseInt( dropdown.value ) > 0 && dropdown instanceof HTMLSelectElement ) {
|
||||
dropdown.parentElement.submit();
|
||||
}
|
||||
}, 250 );
|
||||
}
|
||||
function onKeyUp( event ) {
|
||||
if ( 'Escape' === event.key ) {
|
||||
dropdown.dataset.lastkey = 'escape';
|
||||
} else {
|
||||
delete dropdown.dataset.lastkey;
|
||||
}
|
||||
}
|
||||
dropdown.onchange = onCatChange;
|
||||
})();
|
||||
function onClick() {
|
||||
delete dropdown.dataset.lastkey;
|
||||
}
|
||||
dropdown.addEventListener( 'keyup', onKeyUp );
|
||||
dropdown.addEventListener( 'click', onClick );
|
||||
dropdown.addEventListener( 'change', onSelectChange );
|
||||
})( <?php echo wp_json_encode( $dropdown_id, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?> );
|
||||
</script>
|
||||
|
||||
<?php
|
||||
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) );
|
||||
wp_print_inline_script_tag( wp_remove_surrounding_empty_script_tags( ob_get_clean() ) . "\n//# sourceURL=" . rawurlencode( __METHOD__ ) );
|
||||
} else {
|
||||
$format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
|
||||
|
||||
|
||||
@@ -215,14 +215,14 @@ class WP_Widget_Custom_HTML extends WP_Widget {
|
||||
);
|
||||
|
||||
wp_enqueue_script( 'custom-html-widgets' );
|
||||
wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
|
||||
wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) );
|
||||
|
||||
if ( empty( $settings ) ) {
|
||||
$settings = array(
|
||||
'disabled' => true,
|
||||
);
|
||||
}
|
||||
wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.init( %s );', wp_json_encode( $settings ) ), 'after' );
|
||||
wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.init( %s );', wp_json_encode( $settings, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ), 'after' );
|
||||
|
||||
$l10n = array(
|
||||
'errorNotice' => array(
|
||||
@@ -233,7 +233,7 @@ class WP_Widget_Custom_HTML extends WP_Widget {
|
||||
// @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
|
||||
),
|
||||
);
|
||||
wp_add_inline_script( 'custom-html-widgets', sprintf( 'jQuery.extend( wp.customHtmlWidgets.l10n, %s );', wp_json_encode( $l10n ) ), 'after' );
|
||||
wp_add_inline_script( 'custom-html-widgets', sprintf( 'jQuery.extend( wp.customHtmlWidgets.l10n, %s );', wp_json_encode( $l10n, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ), 'after' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -160,8 +160,8 @@ class WP_Widget_Media_Audio extends WP_Widget_Media {
|
||||
$handle,
|
||||
sprintf(
|
||||
'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
|
||||
wp_json_encode( $this->id_base ),
|
||||
wp_json_encode( $exported_schema )
|
||||
wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
||||
wp_json_encode( $exported_schema, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
|
||||
)
|
||||
);
|
||||
|
||||
@@ -172,9 +172,9 @@ class WP_Widget_Media_Audio extends WP_Widget_Media {
|
||||
wp.mediaWidgets.controlConstructors[ %1$s ].prototype.mime_type = %2$s;
|
||||
wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n = _.extend( {}, wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n, %3$s );
|
||||
',
|
||||
wp_json_encode( $this->id_base ),
|
||||
wp_json_encode( $this->widget_options['mime_type'] ),
|
||||
wp_json_encode( $this->l10n )
|
||||
wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
||||
wp_json_encode( $this->widget_options['mime_type'], JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
||||
wp_json_encode( $this->l10n, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -148,8 +148,8 @@ class WP_Widget_Media_Gallery extends WP_Widget_Media {
|
||||
$handle,
|
||||
sprintf(
|
||||
'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
|
||||
wp_json_encode( $this->id_base ),
|
||||
wp_json_encode( $exported_schema )
|
||||
wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
||||
wp_json_encode( $exported_schema, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
|
||||
)
|
||||
);
|
||||
|
||||
@@ -160,9 +160,9 @@ class WP_Widget_Media_Gallery extends WP_Widget_Media {
|
||||
wp.mediaWidgets.controlConstructors[ %1$s ].prototype.mime_type = %2$s;
|
||||
_.extend( wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n, %3$s );
|
||||
',
|
||||
wp_json_encode( $this->id_base ),
|
||||
wp_json_encode( $this->widget_options['mime_type'] ),
|
||||
wp_json_encode( $this->l10n )
|
||||
wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
||||
wp_json_encode( $this->widget_options['mime_type'], JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
||||
wp_json_encode( $this->l10n, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -240,7 +240,6 @@ class WP_Widget_Media_Gallery extends WP_Widget_Media {
|
||||
* Whether the widget has content to show.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @access protected
|
||||
*
|
||||
* @param array $instance Widget instance props.
|
||||
* @return bool Whether widget has content.
|
||||
|
||||
@@ -323,8 +323,8 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
|
||||
$handle,
|
||||
sprintf(
|
||||
'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
|
||||
wp_json_encode( $this->id_base ),
|
||||
wp_json_encode( $exported_schema )
|
||||
wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
||||
wp_json_encode( $exported_schema, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
|
||||
)
|
||||
);
|
||||
|
||||
@@ -335,9 +335,9 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
|
||||
wp.mediaWidgets.controlConstructors[ %1$s ].prototype.mime_type = %2$s;
|
||||
wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n = _.extend( {}, wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n, %3$s );
|
||||
',
|
||||
wp_json_encode( $this->id_base ),
|
||||
wp_json_encode( $this->widget_options['mime_type'] ),
|
||||
wp_json_encode( $this->l10n )
|
||||
wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
||||
wp_json_encode( $this->widget_options['mime_type'], JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
||||
wp_json_encode( $this->l10n, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -199,8 +199,8 @@ class WP_Widget_Media_Video extends WP_Widget_Media {
|
||||
$handle,
|
||||
sprintf(
|
||||
'wp.mediaWidgets.modelConstructors[ %s ].prototype.schema = %s;',
|
||||
wp_json_encode( $this->id_base ),
|
||||
wp_json_encode( $exported_schema )
|
||||
wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
||||
wp_json_encode( $exported_schema, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
|
||||
)
|
||||
);
|
||||
|
||||
@@ -211,9 +211,9 @@ class WP_Widget_Media_Video extends WP_Widget_Media {
|
||||
wp.mediaWidgets.controlConstructors[ %1$s ].prototype.mime_type = %2$s;
|
||||
wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n = _.extend( {}, wp.mediaWidgets.controlConstructors[ %1$s ].prototype.l10n, %3$s );
|
||||
',
|
||||
wp_json_encode( $this->id_base ),
|
||||
wp_json_encode( $this->widget_options['mime_type'] ),
|
||||
wp_json_encode( $this->l10n )
|
||||
wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
||||
wp_json_encode( $this->widget_options['mime_type'], JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
||||
wp_json_encode( $this->l10n, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -435,7 +435,7 @@ class WP_Widget_Text extends WP_Widget {
|
||||
wp_enqueue_editor();
|
||||
wp_enqueue_media();
|
||||
wp_enqueue_script( 'text-widgets' );
|
||||
wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
|
||||
wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ) ) );
|
||||
wp_add_inline_script( 'text-widgets', 'wp.textWidgets.init();', 'after' );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user