Skip to content
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

Add AMP preview button #812

Closed
wants to merge 11 commits into from
Closed

Add AMP preview button #812

wants to merge 11 commits into from

Conversation

ThierryA
Copy link
Collaborator

This PR adds the AMP preview button on posts which have AMP support.

amp preview button

Refer to the ACs for more info...

Close #799

@@ -0,0 +1,22 @@
/**
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems overkill to enqueue a file for this small amount of CSS but it is done that way in preparation of #709.

* @param {Object} data Object data.
* @return {void}
*/
boot: function( data ) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems overkill to have a boot() method just to call addPreviewButton() method but it is structured that way in preparation of #709.

@ThierryA ThierryA changed the title #799: Add AMP preview button #799 Add AMP preview button Nov 24, 2017

/* AMP preview button */
#preview-action.has-next-sibling .preview.amp-preview {
border-top-left-radius: 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces vs tabs here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, thanks for picking that one up.

I just switch to Atom last week and I guess this is the first flaw I see. For those who use Atom here is what I see by default.
atom issue
Tips: in settings->editor enable "Show invisible" and then you get
screen shot 2017-11-28 at 10 35 34 am
which is already an improvement. But better, install "Tabs to Space" package and set it on save which will automatically convert such inconvenience.

*
* @since 0.6
*/
var AmpPostMetaBox = ( function( $ ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this isn't a class, probably ampPostMetaBox would be a better name.

/**
* Assets handle.
*
* @const string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @var is better here. See https://stackoverflow.com/a/18446766/93579

*
* @since 0.6
*/
public function enqueue_admin_assets() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently enqueueing the assets for every admin screen. It should be limited to just the edit post screen.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if I am missing something but from my perspective it is not loading on all pages since it checks if the $post->type is set and the post_supports_amp(). It does load on the edit.php, post.php and post-new.php if the post type as AMP support. That said it isn't really necessary to load it on edit.php so I will add a check to strictly load it on post.php and post-new.php.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThierryA oh yes, I see you're right. and that it wouldn't get enqueued. But it would get enqueued if an admin screen happened to define a global $post and didn't clean it up. So yeah, I think it is best to explicitly check if the current_screen is the post editor. Maybe 'post' === get_current_screen()->base would be a good check?

array( 'jquery' ),
AMP__VERSION
);
wp_add_inline_script( self::ASSETS_HANDLE, sprintf( 'AmpPostMetaBox.boot( %s );',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this way of booting JS.

'href': this.data.previewLink,
'id': 'amp-' + $previewBtn.prop( 'id' ),
'target': 'amp-' + $previewBtn.prop( 'target' )
} )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't working yet with autosave revisions. If you try clicking the AMP preview before an autosave happens, then the opened window will not show the changes you've made.

This logic needs to be incorporated: https://github.com/WordPress/wordpress-develop/blob/a825a181e11b1a89e76d79d22bd2c220f45b3741/src/wp-admin/js/post.js#L388-L418

Copy link
Collaborator Author

@ThierryA ThierryA Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[updated] Discard previous comment, I need to do more work on this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter this commit address this issue, it should be working as expected now.

@ThierryA
Copy link
Collaborator Author

ThierryA commented Dec 1, 2017

@westonruter kindly review the changes, this should be ready to merge.

ThierryA and others added 5 commits December 3, 2017 13:04
…t skipped.

* Restore focus on edit link for AMP status edit for accessibility.
* Do not add AMP preview button if AMP has been disabled.
* Change postmeta to be flag indicating whether AMP is disabled.
* Fix spelling and clean up phpdoc.
@westonruter
Copy link
Member

Closing in favor of #813, as I got the two branches intertwined.

@westonruter westonruter closed this Dec 7, 2017
@westonruter westonruter changed the title #799 Add AMP preview button Add AMP preview button Dec 7, 2017
@westonruter westonruter deleted the feature/799-post-preview branch December 7, 2017 00:28
@westonruter westonruter added this to the v0.6 milestone Dec 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants