-
Notifications
You must be signed in to change notification settings - Fork 145
Implement customizable transition animation duration setting #2321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
4970c8d
07de264
58eee13
e3e18c4
384c1ef
1004171
f9fba52
cc845d8
988d662
0269071
6b831ac
3aab50e
6ace88b
7742237
fd64beb
defe0f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /** | ||
| * CSS Selector Validation Styles | ||
| * | ||
| * Styles for visual feedback of CSS selector validation. | ||
| * | ||
| * @since n.e.x.t | ||
| */ | ||
|
|
||
| /* Valid selector indicator */ | ||
| input.plvt-selector-valid { | ||
| border-color: #46b450 !important; | ||
| background-color: #f0fdf4; | ||
| } | ||
|
|
||
| input.plvt-selector-valid:focus { | ||
| border-color: #46b450 !important; | ||
| } | ||
|
|
||
| /* Invalid selector indicator */ | ||
| input.plvt-selector-invalid { | ||
| border-color: #dc2626 !important; | ||
| background-color: #fdf2f2; | ||
| } | ||
|
|
||
| input.plvt-selector-invalid:focus { | ||
| border-color: #dc2626 !important; | ||
| } | ||
|
|
||
| /* Error message styling */ | ||
| .plvt-selector-error { | ||
| color: #dc2626; | ||
| margin-top: 5px; | ||
| font-style: italic; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,13 +29,56 @@ function plvt_print_view_transitions_admin_style(): void { | |
| } | ||
|
|
||
| $options = plvt_get_stored_setting_value(); | ||
| if ( ! isset( $options['enable_admin_transitions'] ) || true !== $options['enable_admin_transitions'] ) { | ||
| if ( ! isset( $options['enable_admin_transitions'] ) || ! (bool) $options['enable_admin_transitions'] ) { | ||
| return; | ||
| } | ||
|
|
||
| ?> | ||
| <style> | ||
| @view-transition { navigation: auto; } | ||
| ::view-transition-group(*) { --plvt-view-transition-animation-duration: <?php echo absint( $options['default_transition_animation_duration'] ); ?>ms; } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be reverted now that View Transitions are merged into core. We can iterate on any such setting in Trac. |
||
| #adminmenu > .menu-top { view-transition-name: attr(id type(<custom-ident>), none); } | ||
| </style> | ||
| <?php | ||
| } | ||
|
|
||
| /** | ||
| * Enqueues the CSS selector validation scripts and styles on the settings page. | ||
| * | ||
| * This function loads the JavaScript and CSS needed for real-time CSS selector | ||
| * validation in the View Transitions settings panel. | ||
| * | ||
| * @since n.e.x.t | ||
| * @access private | ||
| */ | ||
| function plvt_enqueue_selector_validation(): void { | ||
| $current_screen = get_current_screen(); | ||
|
|
||
| // Only enqueue on the reading settings page. | ||
| if ( null === $current_screen || 'options-reading' !== $current_screen->id ) { | ||
| return; | ||
| } | ||
|
|
||
| // Enqueue validation CSS. | ||
| wp_enqueue_style( | ||
| 'plvt-selector-validator', | ||
| plugin_dir_url( VIEW_TRANSITIONS_MAIN_FILE ) . 'css/validator-selector.css', | ||
| array(), | ||
| VIEW_TRANSITIONS_VERSION | ||
| ); | ||
|
|
||
| // Enqueue validation JS. | ||
| wp_enqueue_script( | ||
| 'plvt-selector-validator', | ||
| plugin_dir_url( VIEW_TRANSITIONS_MAIN_FILE ) . 'js/validator-selector.js', | ||
| array( 'wp-i18n' ), | ||
| VIEW_TRANSITIONS_VERSION, | ||
| array( 'in_footer' => false ) | ||
| ); | ||
|
|
||
| // Set up translations for the script. | ||
| wp_set_script_translations( | ||
| 'plvt-selector-validator', | ||
| 'view-transitions' | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /** | ||
| * CSS Selector Validation for View Transitions Settings | ||
| * | ||
| * This script provides real-time validation for CSS selector input fields | ||
| * in the View Transitions settings panel. | ||
| * | ||
| * @since n.e.x.t | ||
| */ | ||
|
|
||
| /** | ||
| * @typedef {Object} WP | ||
| * @property {Object} i18n - WordPress internationalization object | ||
| * @property {Function} i18n.__ - Translation function | ||
| */ | ||
|
|
||
| ( () => { | ||
| /** | ||
| * Validates a CSS selector by attempting to use it with document.querySelector. | ||
| * | ||
| * @param {string} selector The CSS selector to validate. | ||
| * @return {boolean} Whether the selector is valid. | ||
| */ | ||
| function validateSelector( selector ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something is wrong here because it is flagging valid selectors as invalid:
Apparently it doesn't work for selector list 😦 I guess we could switch to using a Maybe this validation feature isn't worthwhile, especially since this UI wouldn't be part of core eventually. |
||
| // Empty selectors are allowed (they reset to default) | ||
| if ( '' === selector.trim() ) { | ||
| return true; | ||
| } | ||
|
|
||
| return CSS.supports( `selector(${ selector })` ); | ||
| } | ||
|
|
||
| /** | ||
| * Sets custom validity for a selector input field. | ||
| * | ||
| * @param {HTMLInputElement} input The input element to validate. | ||
| */ | ||
| function updateValidation( input ) { | ||
| const isValid = validateSelector( input.value ); | ||
|
|
||
| if ( isValid ) { | ||
| input.setCustomValidity( '' ); | ||
| input.classList.remove( 'plvt-selector-invalid' ); | ||
| input.classList.add( 'plvt-selector-valid' ); | ||
|
|
||
| const existingError = input.parentNode.querySelector( | ||
| '.plvt-selector-error' | ||
| ); | ||
| if ( existingError ) { | ||
| existingError.remove(); | ||
| } | ||
| } else { | ||
| // @ts-ignore | ||
| const errorMessage = wp.i18n.__( | ||
| 'Invalid CSS selector', | ||
| 'view-transitions' | ||
| ); | ||
| input.setCustomValidity( errorMessage ); | ||
| input.classList.remove( 'plvt-selector-valid' ); | ||
| input.classList.add( 'plvt-selector-invalid' ); | ||
|
|
||
| let errorElement = input.parentNode.querySelector( | ||
| '.plvt-selector-error' | ||
| ); | ||
| if ( ! errorElement ) { | ||
| errorElement = document.createElement( 'p' ); | ||
| errorElement.className = 'plvt-selector-error description'; | ||
| input.parentNode.insertBefore( | ||
| errorElement, | ||
| input.nextSibling | ||
| ); | ||
| } | ||
| errorElement.textContent = errorMessage; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Initializes validation for all selector input fields. | ||
| */ | ||
| function initValidation() { | ||
| // Target all text inputs for selectors | ||
| const selectorInputs = document.querySelectorAll( | ||
| 'input[data-plvt-validate-selector]' | ||
| ); | ||
|
|
||
| selectorInputs.forEach( ( element ) => { | ||
| const input = /** @type {HTMLInputElement} */ ( element ); | ||
|
|
||
| // Validate on blur | ||
| input.addEventListener( 'blur', () => { | ||
| updateValidation( input ); | ||
| } ); | ||
|
|
||
| // Validate on input for real-time feedback | ||
| input.addEventListener( 'input', () => { | ||
| updateValidation( input ); | ||
| } ); | ||
|
|
||
| // Validate on page load if field has a value | ||
| if ( '' !== input.value.trim() ) { | ||
| updateValidation( input ); | ||
| } | ||
| } ); | ||
| } | ||
|
|
||
| // Initialize when DOM is ready | ||
| if ( 'loading' === document.readyState ) { | ||
| document.addEventListener( 'DOMContentLoaded', initValidation ); | ||
| } else { | ||
| initValidation(); | ||
| } | ||
| } )(); | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? It can be reverted anyway since this function is now obsolete for 7.0.