Permalinks: Change structure tag button state more reliably.

Changes the highlighted tag buttons accordingly when selecting one of the commong permalink settings.

Deprecates `options_permalink_add_js()` as that JavaScript isn't added inline anymore.

Fixes #29872.

Built from https://develop.svn.wordpress.org/trunk@41598


git-svn-id: http://core.svn.wordpress.org/trunk@41433 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2017-09-26 08:24:46 +00:00
parent 72db8faa65
commit fce70235f2
6 changed files with 46 additions and 27 deletions

View File

@ -1491,3 +1491,26 @@ function post_form_autocomplete_off() {
echo ' autocomplete="off"'; echo ' autocomplete="off"';
} }
} }
/**
* Display JavaScript on the page.
*
* @since 3.5.0
* @deprecated 4.9.0
*/
function options_permalink_add_js() {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.permalink-structure input:radio').change(function() {
if ( 'custom' == this.value )
return;
jQuery('#permalink_structure').val( this.value );
});
jQuery( '#permalink_structure' ).on( 'click input', function() {
jQuery( '#custom_selection' ).prop( 'checked', true );
});
});
</script>
<?php
}

View File

@ -86,28 +86,6 @@ function options_general_add_js() {
<?php <?php
} }
/**
* Display JavaScript on the page.
*
* @since 3.5.0
*/
function options_permalink_add_js() {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.permalink-structure input:radio').change(function() {
if ( 'custom' == this.value )
return;
jQuery('#permalink_structure').val( this.value );
});
jQuery( '#permalink_structure' ).on( 'click input', function() {
jQuery( '#custom_selection' ).prop( 'checked', true );
});
});
</script>
<?php
}
/** /**
* Display JavaScript on the page. * Display JavaScript on the page.
* *

View File

@ -181,8 +181,28 @@ $('.contextual-help-tabs').delegate('a', 'click', function(e) {
var permalinkStructureFocused = false, var permalinkStructureFocused = false,
$permalinkStructure = $( '#permalink_structure' ), $permalinkStructure = $( '#permalink_structure' ),
$permalinkStructureInputs = $( '.permalink-structure input:radio' ),
$permalinkCustomSelection = $( '#custom_selection' ),
$availableStructureTags = $( '.form-table.permalink-structure .available-structure-tags button' ); $availableStructureTags = $( '.form-table.permalink-structure .available-structure-tags button' );
// Change permalink structure input when selecting one of the common structures.
$permalinkStructureInputs.on( 'change', function() {
if ( 'custom' === this.value ) {
return;
}
$permalinkStructure.val( this.value );
// Update button states after selection.
$availableStructureTags.each( function() {
changeStructureTagButtonState( $( this ) );
} );
} );
$permalinkStructure.on( 'click input', function() {
$permalinkCustomSelection.prop( 'checked', true );
} );
// Check if the permalink structure input field has had focus at least once. // Check if the permalink structure input field has had focus at least once.
$permalinkStructure.on( 'focus', function( event ) { $permalinkStructure.on( 'focus', function( event ) {
permalinkStructureFocused = true; permalinkStructureFocused = true;
@ -249,7 +269,7 @@ $availableStructureTags.on( 'click', function() {
selectionStart = selectionEnd = permalinkStructureValue.length; selectionStart = selectionEnd = permalinkStructureValue.length;
} }
$( '#custom_selection' ).prop( 'checked', true ); $permalinkCustomSelection.prop( 'checked', true );
// Prepend and append slashes if necessary. // Prepend and append slashes if necessary.
if ( '/' !== permalinkStructureValue.substr( 0, selectionStart ).substr( -1 ) ) { if ( '/' !== permalinkStructureValue.substr( 0, selectionStart ).substr( -1 ) ) {

File diff suppressed because one or more lines are too long

View File

@ -46,8 +46,6 @@ get_current_screen()->set_help_sidebar(
'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>' '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
); );
add_filter('admin_head', 'options_permalink_add_js');
$home_path = get_home_path(); $home_path = get_home_path();
$iis7_permalinks = iis7_supports_permalinks(); $iis7_permalinks = iis7_supports_permalinks();
$permalink_structure = get_option( 'permalink_structure' ); $permalink_structure = get_option( 'permalink_structure' );

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.9-alpha-41597'; $wp_version = '4.9-alpha-41598';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.