-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Proposal: Add On This Day Widget #11630
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
Open
alshakero
wants to merge
49
commits into
WordPress:trunk
Choose a base branch
from
alshakero:add/on-this-day-widget
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
c5067f3
Add On This Day Widget
alshakero e1b0ba0
Lint
alshakero 5b7cbcf
Refactor CSS
alshakero 45571e4
Cleaner CSS
alshakero 6bd17f6
Remove unneeded file
alshakero c1fcec2
Remove extra space
alshakero bdf30db
Merge branch 'trunk' into add/on-this-day-widget
alshakero b53e3b5
Add caching for fetching and rendering
alshakero 63c8422
Merge branch 'add/on-this-day-widget' of https://github.com/alshakero…
alshakero 4865fc0
Redesign
alshakero a32a13f
Fix on mobile
alshakero a79feb4
Render date pill only on the header of the postbox (not the title)
alshakero 3ea2323
Design fine tuning
alshakero eceeec1
Merge branch 'trunk' into add/on-this-day-widget
alshakero aa09b83
Switch to WP_Query
alshakero 05c5a23
Remove #[AllowDynamicProperties] attribute from WP_On_This_Day class
alshakero 488310b
Add an adjustable window size
alshakero 9747fb5
Merge branch 'trunk' into add/on-this-day-widget
alshakero dfc24f2
Merge branch 'trunk' into add/on-this-day-widget
alshakero bcf3daa
Address feedback
alshakero f62cfb3
Merge branch 'add/on-this-day-widget' of https://github.com/alshakero…
alshakero e446635
Don't concat two strings to make a sentence
alshakero 4f6b9bc
Switch to `wp_scrub_utf8`
alshakero 7dea82e
Bring back success message config
alshakero 5b46861
Fix toggle indicator collapse on On This Day widget
escapemanuele 6e960aa
Merge branch 'trunk' into add/on-this-day-widget
alshakero afc4ac2
Move away from CSS prop to `attr` for simpler escaping
alshakero efd8b31
Use `sprintf` instead
alshakero 3d7ea6f
Refine On This Day widget escaping and rendered markup
escapemanuele ded7416
Run PHPCBF
alshakero 2aa110e
Merge branch 'trunk' into add/on-this-day-widget
alshakero 993c4fb
Switch to `WP_HTML_Tag_Processor` and use CSS for adding ellipsis ins…
alshakero d20b27d
Merge branch 'add/on-this-day-widget' of https://github.com/alshakero…
alshakero 5a3fb28
Merge branch 'trunk' into add/on-this-day-widget
alshakero 2c80205
Don't add whitespace for non-block tags and add tests
alshakero 903f2c3
Merge branch 'add/on-this-day-widget' of https://github.com/alshakero…
alshakero d458d25
Merge branch 'trunk' into add/on-this-day-widget
alshakero 39ed253
Remove excess whitespace
alshakero 01e5164
Merge branch 'add/on-this-day-widget' of https://github.com/alshakero…
alshakero 3be969a
Address feedback
alshakero 165261c
Merge branch 'trunk' into add/on-this-day-widget
alshakero 67ff936
Redesign:
alshakero e165fc7
Merge branch 'trunk' into add/on-this-day-widget
alshakero f0b6fb9
Cleaner empty state
alshakero d1479ff
Merge branch 'trunk' into add/on-this-day-widget
alshakero 0658426
Merge branch 'trunk' into add/on-this-day-widget
alshakero 242b0d5
Address feedback
alshakero 2f00c14
Merge branch 'trunk' into add/on-this-day-widget
alshakero b4c40ed
Fix file path in tests
alshakero 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
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 |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /** | ||
| * @output wp-admin/js/on-this-day.js | ||
| */ | ||
|
|
||
| ( function( $ ) { | ||
| function flashState( $button, message ) { | ||
| var original = $button.data( 'wpOtdShareLabel' ) || $button.text(); | ||
|
|
||
| $button.text( message ).addClass( 'wp-on-this-day-is-copied' ); | ||
|
|
||
| window.setTimeout( function() { | ||
| $button.text( original ).removeClass( 'wp-on-this-day-is-copied' ); | ||
| }, 2000 ); | ||
| } | ||
|
|
||
| function legacyCopy( text ) { | ||
| var $textarea = $( '<textarea readonly></textarea>' ) | ||
| .val( text ) | ||
| .css( { | ||
| position: 'absolute', | ||
| left: '-9999px' | ||
| } ) | ||
| .appendTo( 'body' ); | ||
|
|
||
| $textarea[0].select(); | ||
|
|
||
| try { | ||
| document.execCommand( 'copy' ); | ||
| } catch ( error ) {} | ||
|
|
||
| $textarea.remove(); | ||
| } | ||
|
|
||
| function copyShareUrl( $button, url ) { | ||
| var success = $button.data( 'wpOtdShareCopied' ) || 'Link copied!'; | ||
|
|
||
| function done() { | ||
| flashState( $button, success ); | ||
| } | ||
|
|
||
| if ( navigator.clipboard && navigator.clipboard.writeText ) { | ||
| navigator.clipboard.writeText( url ).then( | ||
| done, | ||
| function() { | ||
| legacyCopy( url ); | ||
| done(); | ||
| } | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| legacyCopy( url ); | ||
| done(); | ||
| } | ||
|
|
||
| $( '.wp-on-this-day-post-share' ).on( 'click', function( event ) { | ||
| var $button = $( this ), | ||
| url = $button.data( 'wpOtdShareUrl' ), | ||
| shareData = { | ||
| title: $button.data( 'wpOtdShareTitle' ) || document.title, | ||
| url: url | ||
| }; | ||
|
|
||
| event.preventDefault(); | ||
|
|
||
| if ( ! url ) { | ||
| return; | ||
| } | ||
|
|
||
| if ( | ||
| navigator.share && | ||
| ( ! navigator.canShare || navigator.canShare( shareData ) ) | ||
| ) { | ||
| navigator.share( shareData ).then( | ||
| function() { | ||
| flashState( $button, $button.data( 'wpOtdShareShared' ) || 'Shared!' ); | ||
| }, | ||
| function( error ) { | ||
| if ( ! error || 'AbortError' !== error.name ) { | ||
| copyShareUrl( $button, url ); | ||
| } | ||
| } | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| copyShareUrl( $button, url ); | ||
| } ); | ||
|
|
||
| function setupCarousel() { | ||
| var $root = $( this ), | ||
| $slides = $root.find( '.wp-on-this-day-post' ), | ||
| $counter = $root.find( '.wp-on-this-day-carousel-current' ), | ||
| current = Math.max( 0, $slides.index( $slides.filter( '.wp-on-this-day-is-active' ) ) ); | ||
|
|
||
| if ( $slides.length < 2 ) { | ||
| return; | ||
| } | ||
|
|
||
| function show( target ) { | ||
| current = ( ( target % $slides.length ) + $slides.length ) % $slides.length; | ||
|
|
||
| $slides | ||
| .removeClass( 'wp-on-this-day-is-active' ) | ||
| .attr( 'aria-hidden', 'true' ) | ||
| .eq( current ) | ||
| .addClass( 'wp-on-this-day-is-active' ) | ||
| .attr( 'aria-hidden', 'false' ); | ||
| $counter.text( current + 1 ); | ||
| } | ||
|
|
||
| $root.find( '.wp-on-this-day-carousel-prev' ).on( 'click', function() { | ||
| show( current - 1 ); | ||
| } ); | ||
| $root.find( '.wp-on-this-day-carousel-next' ).on( 'click', function() { | ||
| show( current + 1 ); | ||
| } ); | ||
|
|
||
| $root.on( 'keydown', function( event ) { | ||
| if ( 'ArrowLeft' === event.key ) { | ||
| show( current - 1 ); | ||
| } | ||
|
|
||
| if ( 'ArrowRight' === event.key ) { | ||
| show( current + 1 ); | ||
| } | ||
| } ); | ||
|
|
||
| show( current ); | ||
| } | ||
|
|
||
| $( '.wp-on-this-day-carousel' ).each( setupCarousel ); | ||
| }( jQuery ) ); | ||
Oops, something went wrong.
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.
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.
I'm not seeing anything that requires jQuery in this file (correct me if I am wrong) so it would be good to avoid the dependency. https://youmightnotneedjquery.com/
Uh oh!
There was an error while loading. Please reload this page.
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.
It is not a requirement per se, but I started with vanilla JS, and the code was longer and too verbose. I then compared to other widgets and everyone except password-toggle uses jQuery.