-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Improve site icon but don't change the UI #6165
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
Closed
aaronjorbin
wants to merge
75
commits into
WordPress:trunk
from
aaronjorbin:54370-site-icon-post-review-old-ui
Closed
Changes from all commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
cb96657
Fix typo
kebbet cfffe29
Adds `data-choose` attribute for media modal
kebbet ff3ef3a
Adds docblocks, removes wrapping function.
kebbet 44ca10d
Adds since tag, follow coding standards I guess.
kebbet ed9df2c
Store selected elements in vars.
kebbet 54a0565
Updates docblock, move `frame` into initializing function
kebbet e584698
Reduce calls to .attr(). Remove `classes` var
kebbet 233f89b
Adds space before the opening brackets
kebbet 8ffc136
Reuse existing attribute, rename selector (in PHP)
kebbet 5a97e40
Address review comments from @afercia
kebbet a3020b6
Merge branch 'WordPress:trunk' into 54370-site-icon-post-review
kebbet c930802
JS-fixes
kebbet c695e3c
Focus loss and fixed button ID for triggering modal.
kebbet 564cdbd
Removes unnecessary setting of focus
kebbet cb268c4
Coding standard fixes.
kebbet 1d696f7
Merge branch 'WordPress:trunk' into 54370-site-icon-post-review
kebbet edb1546
Updates docblocks, combine var-statements, start jQuery objects with …
kebbet 8269ea3
Merge branch 'WordPress:trunk' into 54370-site-icon-post-review
kebbet 10fe004
Accessibility: adds better alternative text to the images
kebbet 71f353f
CS-issue with to many tabs.
kebbet 18e9c1e
CS-issue
kebbet 142fec6
Missing semicolons.
kebbet 63f3885
Handle alt-attribute on remove
kebbet d7b30c0
Remove debug log.
kebbet f540014
Remove IIFE-sections, adjusts indents. Move var to function scope
kebbet 84a7d4b
Merge branch 'WordPress:trunk' into 54370-site-icon-post-review
kebbet b5c43ed
Temp reset
kebbet e79e952
Merge branch '54370-site-icon-post-review' of https://github.com/kebb…
kebbet 07c9089
Remove IIFE-sections, adjusts indents. Move var to function scope
kebbet ebfd54b
Merge branch 'WordPress:trunk' into 54370-site-icon-post-review
kebbet 1f309ac
Adds prefix to alt text for each preview image.
kebbet 869eae7
Address feedback from @afercia
kebbet 94efea9
CS-fixes
kebbet 8d5030a
CS-fixes
kebbet 09641b7
Update src/js/_enqueues/admin/site-icon.js
kebbet a2bafb7
Address feedback from @aaronjorbin
kebbet 2e177f0
fix
kebbet 17a1618
Merge branch 'trunk' of github.com:WordPress/wordpress-develop into 5…
aaronjorbin d32112c
Start wiring in new UI
aaronjorbin 399c5ff
Update text for description
aaronjorbin 80fa6d0
Ensure unused dependecies aren't enqueued and translations are proper…
aaronjorbin cd760fb
Set IDs so JS works
aaronjorbin 348e4aa
Minor tweaks to comments
aaronjorbin d2700c7
Ensure icons can be hidden
aaronjorbin b78cd5c
use less generic class names
aaronjorbin 9e0220f
Fix specificity in preview
aaronjorbin 9eacf2c
Use unitless for 0
aaronjorbin 22a00f0
Use unitless for 0
aaronjorbin 0a7c74b
lowercase colors
aaronjorbin 10642d3
lowercase colors
aaronjorbin 2d986fd
lowercase colors
aaronjorbin d75fb0d
Use unitless for 0
aaronjorbin 138f269
Use unitless for 0
aaronjorbin 952bb3f
lowercase colors
aaronjorbin 4ed3128
Use unitless for 0
aaronjorbin 5ffd471
Use unitless for 0
aaronjorbin 7b67b64
Fix indentation
aaronjorbin f023335
Merge branch 'trunk' of github.com:WordPress/wordpress-develop into 5…
aaronjorbin 254a288
Update Title in preview as it chagnes
aaronjorbin 57f3d4a
Update background for preview with the new image
aaronjorbin 6564f9b
Remove float which was used in old UI as it is interfering with the p…
aaronjorbin 69416b4
Merge branch 'trunk' of github.com:WordPress/wordpress-develop into 5…
aaronjorbin b76e500
Restore alt text for browser and remove svg from screen reader
aaronjorbin 16a3a8c
Use <code> tag for size info.
kebbet 91fb8a8
Tidy CSS and add border to preview field.
kebbet 9b68ef5
use prettier to format CSS and JS
aaronjorbin 984a20c
Restore current UI
aaronjorbin 3ff7d7a
fix jshint issues caused by prettier
aaronjorbin 1116243
Remove no longer used UI code
aaronjorbin e8f7676
Lowercase translators
aaronjorbin abe815b
Reuse admin bar update code for site icon preview
aaronjorbin f9ea859
use bloginfo which does echo get_bloginfo
aaronjorbin 7941464
Merge branch 'trunk' of github.com:WordPress/wordpress-develop into 5…
aaronjorbin a672eba
Reformat JS based on new jshint
aaronjorbin ad65152
Merge branch '54370-site-icon-post-review-old-ui' of github.com:aaron…
aaronjorbin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,40 @@ | ||
| (function($) { | ||
| var frame; | ||
|
|
||
| function calculateImageSelectOptions ( attachment ) { | ||
| var realWidth = attachment.get( 'width' ), | ||
| /** | ||
| * Handle the site icon setting in options-general.php. | ||
| * | ||
| * @since 6.5.0 | ||
| * @output wp-admin/js/site-icon.js | ||
| */ | ||
|
|
||
| /* global jQuery, wp */ | ||
|
|
||
| ( function ( $ ) { | ||
| var $chooseButton = $( '#choose-from-library-button' ), | ||
| $iconPreview = $( '#site-icon-preview' ), | ||
| $browserIconPreview = $( '#browser-icon-preview' ), | ||
| $appIconPreview = $( '#app-icon-preview' ), | ||
| $hiddenDataField = $( '#site_icon_hidden_field' ), | ||
| $removeButton = $( '#js-remove-site-icon' ), | ||
| frame; | ||
|
|
||
| /** | ||
| * Calculate image selection options based on the attachment dimensions. | ||
| * | ||
| * @since 6.5.0 | ||
| * | ||
| * @param {Object} attachment The attachment object representing the image. | ||
| * @return {Object} The image selection options. | ||
| */ | ||
| function calculateImageSelectOptions( attachment ) { | ||
| var realWidth = attachment.get( 'width' ), | ||
| realHeight = attachment.get( 'height' ), | ||
| xInit = 512, | ||
| yInit = 512, | ||
| ratio = xInit / yInit, | ||
| xImg = xInit, | ||
| yImg = yInit, | ||
| x1, y1, imgSelectOptions; | ||
| xImg = xInit, | ||
| yImg = yInit, | ||
| x1, | ||
| y1, | ||
| imgSelectOptions; | ||
|
|
||
| if ( realWidth / realHeight > ratio ) { | ||
| yInit = realHeight; | ||
|
|
@@ -35,104 +60,177 @@ | |
| x1: x1, | ||
| y1: y1, | ||
| x2: xInit + x1, | ||
| y2: yInit + y1 | ||
| y2: yInit + y1, | ||
| }; | ||
|
|
||
| return imgSelectOptions; | ||
| } | ||
|
|
||
| $( function() { | ||
| // Build the choose from library frame. | ||
| $( '#choose-from-library-link' ).on( 'click', function() { | ||
| var $el = $(this); | ||
|
|
||
| // Create the media frame. | ||
| frame = wp.media({ | ||
| button: { | ||
| // Set the text of the button. | ||
| text: $el.data('update'), | ||
| // Don't close, we might need to crop. | ||
| close: false | ||
| }, | ||
| states: [ | ||
| new wp.media.controller.Library({ | ||
| title: $el.data( 'choose' ), | ||
| library: wp.media.query({ type: 'image' }), | ||
| date: false, | ||
| suggestedWidth: $el.data( 'size' ), | ||
| suggestedHeight: $el.data( 'size' ) | ||
| }), | ||
| new wp.media.controller.SiteIconCropper({ | ||
| control: { | ||
| params: { | ||
| width: $el.data( 'size' ), | ||
| height: $el.data( 'size' ) | ||
| } | ||
| /** | ||
| * Initializes the media frame for selecting or cropping an image. | ||
| * | ||
| * @since 6.5.0 | ||
| */ | ||
| $chooseButton.on( 'click', function () { | ||
| var $el = $( this ); | ||
|
|
||
| // Create the media frame. | ||
| frame = wp.media( { | ||
| button: { | ||
| // Set the text of the button. | ||
| text: $el.data( 'update' ), | ||
|
|
||
| // Don't close, we might need to crop. | ||
| close: false, | ||
| }, | ||
| states: [ | ||
| new wp.media.controller.Library( { | ||
| title: $el.data( 'choose-text' ), | ||
| library: wp.media.query( { type: 'image' } ), | ||
| date: false, | ||
| suggestedWidth: $el.data( 'size' ), | ||
| suggestedHeight: $el.data( 'size' ), | ||
| } ), | ||
| new wp.media.controller.SiteIconCropper( { | ||
| control: { | ||
| params: { | ||
| width: $el.data( 'size' ), | ||
| height: $el.data( 'size' ), | ||
| }, | ||
| imgSelectOptions: calculateImageSelectOptions | ||
| }) | ||
| ] | ||
| }); | ||
|
|
||
| frame.on( 'cropped', function( attachment) { | ||
| $( '#site_icon_hidden_field' ).val(attachment.id); | ||
| switchToUpdate(attachment.url); | ||
| }, | ||
| imgSelectOptions: calculateImageSelectOptions, | ||
| } ), | ||
| ], | ||
| } ); | ||
|
|
||
| frame.on( 'cropped', function ( attachment ) { | ||
| $hiddenDataField.val( attachment.id ); | ||
| switchToUpdate( attachment ); | ||
| frame.close(); | ||
|
|
||
| // Start over with a frame that is so fresh and so clean clean. | ||
|
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 comment was flagged as odd, and I agree. Is this an Outkast reference or something? |
||
| frame = null; | ||
| } ); | ||
|
|
||
| // When an image is selected, run a callback. | ||
| frame.on( 'select', function () { | ||
| // Grab the selected attachment. | ||
| var attachment = frame.state().get( 'selection' ).first(); | ||
|
|
||
| if ( | ||
| attachment.attributes.height === $el.data( 'size' ) && | ||
| $el.data( 'size' ) === attachment.attributes.width | ||
| ) { | ||
| switchToUpdate( attachment.attributes ); | ||
| frame.close(); | ||
| // Start over with a frame that is so fresh and so clean clean. | ||
| frame = null; | ||
| }); | ||
|
|
||
| // When an image is selected, run a callback. | ||
| frame.on( 'select', function() { | ||
| // Grab the selected attachment. | ||
| var attachment = frame.state().get('selection').first(); | ||
|
|
||
| if ( attachment.attributes.height === $el.data('size') && $el.data('size') === attachment.attributes.width ) { | ||
| // Set the value of the hidden input to the attachment id. | ||
| $( '#site_icon_hidden_field').val(attachment.id); | ||
| switchToUpdate(attachment.attributes.url); | ||
| frame.close(); | ||
| } else { | ||
| frame.setState( 'cropper' ); | ||
| } | ||
| }); | ||
|
|
||
| frame.open(); | ||
| }); | ||
| }); | ||
|
|
||
| function switchToUpdate( url ){ | ||
| // Set site-icon-img src to the url and remove the hidden class. | ||
| $( '#site-icon-preview').find('img').not('.browser-preview').each( function(i, img ){ | ||
| $(img).attr('src', url ); | ||
| }); | ||
| $( '#site-icon-preview' ).removeClass( 'hidden' ); | ||
| // Remove hidden class from remove. | ||
| $( '#js-remove-site-icon' ).removeClass( 'hidden' ); | ||
| // If the button is not in the update state, swap the classes. | ||
| if( $( '#choose-from-library-link' ).attr( 'data-state' ) !== '1' ){ | ||
| var classes = $( '#choose-from-library-link' ).attr( 'class' ); | ||
| $( '#choose-from-library-link' ).attr( 'class', $( '#choose-from-library-link' ).attr('data-alt-classes') ); | ||
| $( '#choose-from-library-link' ).attr( 'data-alt-classes', classes ); | ||
| $( '#choose-from-library-link' ).attr( 'data-state', '1' ); | ||
|
|
||
| // Set the value of the hidden input to the attachment id. | ||
| $hiddenDataField.val( attachment.id ); | ||
| } else { | ||
| frame.setState( 'cropper' ); | ||
| } | ||
| } ); | ||
|
|
||
| frame.open(); | ||
| } ); | ||
|
|
||
| /** | ||
| * Update the UI when a site icon is selected. | ||
| * | ||
| * @since 6.5.0 | ||
| * | ||
| * @param {array} attributes The attributes for the attachment. | ||
| */ | ||
| function switchToUpdate( attributes ) { | ||
| var i18nAppAlternativeString, i18nBrowserAlternativeString; | ||
|
|
||
| if ( attributes.alt ) { | ||
| i18nAppAlternativeString = wp.i18n.sprintf( | ||
| /* translators: %s: The selected image alt text. */ | ||
| wp.i18n.__( 'App icon preview: Current image: %s' ), | ||
| attributes.alt | ||
| ); | ||
| i18nBrowserAlternativeString = wp.i18n.sprintf( | ||
| /* translators: %s: The selected image alt text. */ | ||
| wp.i18n.__( 'Browser icon preview: Current image: %s' ), | ||
| attributes.alt | ||
| ); | ||
| } else { | ||
| i18nAppAlternativeString = wp.i18n.sprintf( | ||
| /* translators: %s: The selected image filename. */ | ||
| wp.i18n.__( | ||
| 'App icon preview: The current image has no alternative text. The file name is: %s' | ||
| ), | ||
| attributes.filename | ||
| ); | ||
| i18nBrowserAlternativeString = wp.i18n.sprintf( | ||
| /* translators: %s: The selected image filename. */ | ||
| wp.i18n.__( | ||
| 'Browser icon preview: The current image has no alternative text. The file name is: %s' | ||
| ), | ||
| attributes.filename | ||
| ); | ||
| } | ||
|
|
||
| // swap the text of the button | ||
| $( '#choose-from-library-link' ).text( $( '#choose-from-library-link' ).attr( 'data-update-text' ) ); | ||
| // Set site-icon-img src and alternative text to app icon preview. | ||
| $appIconPreview.attr( { | ||
| src: attributes.url, | ||
| alt: i18nAppAlternativeString, | ||
| } ); | ||
|
|
||
| // Set site-icon-img src and alternative text to browser preview. | ||
| $browserIconPreview.attr( { | ||
| src: attributes.url, | ||
| alt: i18nBrowserAlternativeString, | ||
| } ); | ||
|
|
||
| // Remove hidden class from icon preview div and remove button. | ||
| $iconPreview.removeClass( 'hidden' ); | ||
| $removeButton.removeClass( 'hidden' ); | ||
|
|
||
| // If the choose button is not in the update state, swap the classes. | ||
| if ( $chooseButton.attr( 'data-state' ) !== '1' ) { | ||
| $chooseButton.attr( { | ||
| class: $chooseButton.attr( 'data-alt-classes' ), | ||
| 'data-alt-classes': $chooseButton.attr( 'class' ), | ||
| 'data-state': '1', | ||
| } ); | ||
| } | ||
|
|
||
| // Swap the text of the choose button. | ||
| $chooseButton.text( $chooseButton.attr( 'data-update-text' ) ); | ||
| } | ||
|
|
||
| $( '#js-remove-site-icon' ).on( 'click', function() { | ||
| $( '#site_icon_hidden_field' ).val( 'false' ); | ||
| $( '#site-icon-preview' ).toggleClass( 'hidden' ); | ||
| /** | ||
| * Handles the click event of the remove button. | ||
| * | ||
| * @since 6.5.0 | ||
| */ | ||
| $removeButton.on( 'click', function () { | ||
| $hiddenDataField.val( 'false' ); | ||
| $( this ).toggleClass( 'hidden' ); | ||
|
|
||
| var classes = $( '#choose-from-library-link' ).attr( 'class' ); | ||
| $( '#choose-from-library-link' ).attr( 'class', $( '#choose-from-library-link' ).attr( 'data-alt-classes' ) ); | ||
| $( '#choose-from-library-link' ).attr( 'data-alt-classes', classes ); | ||
|
|
||
| // Swap the text of the button. | ||
| $( '#choose-from-library-link' ).text( $( '#choose-from-library-link' ).attr( 'data-choose-text' ) ); | ||
| // Set the state of the button so it can be changed on new icon. | ||
| $( '#choose-from-library-link' ).attr( 'data-state', ''); | ||
| }); | ||
| }(jQuery)); | ||
| $iconPreview.toggleClass( 'hidden' ); | ||
| $browserIconPreview.attr( { | ||
| src: '', | ||
| alt: '', | ||
| } ); | ||
| $appIconPreview.attr( { | ||
| src: '', | ||
| alt: '', | ||
| } ); | ||
|
|
||
| /** | ||
| * Resets state to the button, for correct visual style and state. | ||
| * Updates the text of the button. | ||
| * Sets focus state to the button. | ||
| */ | ||
| $chooseButton | ||
| .attr( { | ||
| class: $chooseButton.attr( 'data-alt-classes' ), | ||
| 'data-alt-classes': $chooseButton.attr( 'class' ), | ||
| 'data-state': '', | ||
| } ) | ||
| .text( $chooseButton.attr( 'data-choose-text' ) ) | ||
| .trigger( 'focus' ); | ||
| } ); | ||
| } )( jQuery ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,6 @@ | |
| overflow: hidden; | ||
| position: relative; | ||
| max-width: 180px; | ||
| float: left; | ||
| } | ||
|
|
||
| .site-icon-preview .favicon, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.