-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #813 from Automattic/feature/709-block-amp-per-page
Add post preview for AMP and allow AMP to be disabled on a per-post basis
- Loading branch information
Showing
10 changed files
with
831 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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 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,57 @@ | ||
/** | ||
* 1.0 AMP preview. | ||
* | ||
* Submit box preview buttons. | ||
*/ | ||
|
||
/* Core preview button */ | ||
.wp-core-ui #preview-action.has-amp-preview #post-preview { | ||
border-top-right-radius: 0; | ||
border-bottom-right-radius: 0; | ||
float: none; | ||
} | ||
|
||
/* AMP preview button */ | ||
.wp-core-ui #amp-post-preview.preview { | ||
border-top-left-radius: 0; | ||
border-bottom-left-radius: 0; | ||
text-indent: -9999px; | ||
padding-right: 7px; | ||
padding-left: 7px; | ||
} | ||
|
||
.wp-core-ui #amp-post-preview.preview::after { | ||
content: "icon"; | ||
width: 14px; | ||
float: left; | ||
background: no-repeat center url( '../images/amp-icon.svg' ); | ||
background-size: 14px !important; | ||
} | ||
|
||
.wp-core-ui #amp-post-preview.preview.disabled::after { | ||
opacity: 0.6; | ||
} | ||
|
||
/* AMP status */ | ||
.misc-amp-status .amp-icon { | ||
float: left; | ||
background: transparent url( '../images/amp-icon.svg' ) no-repeat left; | ||
background-size: 17px; | ||
width: 17px; | ||
height: 17px; | ||
margin: 0 8px 0 1px; | ||
} | ||
|
||
#amp-status-select { | ||
margin-top: 4px; | ||
} | ||
|
||
.amp-status-actions { | ||
margin-top: 10px; | ||
} | ||
|
||
@media screen and ( max-width: 782px ) { | ||
#amp-status-select { | ||
line-height: 280%; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,170 @@ | ||
/* exported ampPostMetaBox */ | ||
|
||
/** | ||
* AMP Post Meta Box. | ||
* | ||
* @todo Rename this to be just the ampEditPostScreen? | ||
* | ||
* @since 0.6 | ||
*/ | ||
var ampPostMetaBox = ( function( $ ) { | ||
'use strict'; | ||
|
||
var component = { | ||
|
||
/** | ||
* Holds data. | ||
* | ||
* @since 0.6 | ||
*/ | ||
data: { | ||
previewLink: '', | ||
disabled: false, | ||
statusInputName: '', | ||
l10n: { | ||
ampPreviewBtnLabel: '' | ||
} | ||
}, | ||
|
||
/** | ||
* Toggle animation speed. | ||
* | ||
* @since 0.6 | ||
*/ | ||
toggleSpeed: 200, | ||
|
||
/** | ||
* Core preview button selector. | ||
* | ||
* @since 0.6 | ||
*/ | ||
previewBtnSelector: '#post-preview', | ||
|
||
/** | ||
* AMP preview button selector. | ||
* | ||
* @since 0.6 | ||
*/ | ||
ampPreviewBtnSelector: '#amp-post-preview' | ||
}; | ||
|
||
/** | ||
* Boot plugin. | ||
* | ||
* @since 0.6 | ||
* @param {Object} data Object data. | ||
* @return {void} | ||
*/ | ||
component.boot = function boot( data ) { | ||
component.data = data; | ||
$( document ).ready( function() { | ||
if ( ! component.data.disabled ) { | ||
component.addPreviewButton(); | ||
} | ||
component.listen(); | ||
} ); | ||
}; | ||
|
||
/** | ||
* Events listener. | ||
* | ||
* @since 0.6 | ||
* @return {void} | ||
*/ | ||
component.listen = function listen() { | ||
$( component.ampPreviewBtnSelector ).on( 'click.amp-post-preview', function( e ) { | ||
e.preventDefault(); | ||
component.onAmpPreviewButtonClick(); | ||
} ); | ||
|
||
$( '.edit-amp-status, [href="#amp_status"]' ).click( function( e ) { | ||
e.preventDefault(); | ||
component.toggleAmpStatus( $( e.target ) ); | ||
} ); | ||
|
||
$( '#submitpost input[type="submit"]' ).on( 'click', function() { | ||
$( component.ampPreviewBtnSelector ).addClass( 'disabled' ); | ||
} ); | ||
}; | ||
|
||
/** | ||
* Add AMP Preview button. | ||
* | ||
* @since 0.6 | ||
* @return {void} | ||
*/ | ||
component.addPreviewButton = function addPreviewButton() { | ||
var previewBtn = $( component.previewBtnSelector ); | ||
previewBtn | ||
.clone() | ||
.insertAfter( previewBtn ) | ||
.prop( { | ||
'href': component.data.previewLink, | ||
'id': component.ampPreviewBtnSelector.replace( '#', '' ) | ||
} ) | ||
.text( component.data.l10n.ampPreviewBtnLabel ) | ||
.parent() | ||
.addClass( 'has-amp-preview' ); | ||
}; | ||
|
||
/** | ||
* AMP Preview button click handler. | ||
* | ||
* We trigger the Core preview link for events propagation purposes. | ||
* | ||
* @since 0.6 | ||
* @return {void} | ||
*/ | ||
component.onAmpPreviewButtonClick = function onAmpPreviewButtonClick() { | ||
var $input; | ||
|
||
// Flag the AMP preview referer. | ||
$input = $( '<input>' ) | ||
.prop( { | ||
'type': 'hidden', | ||
'name': 'amp-preview', | ||
'value': 'do-preview' | ||
} ) | ||
.insertAfter( component.ampPreviewBtnSelector ); | ||
|
||
// Trigger Core preview button and remove AMP flag. | ||
$( component.previewBtnSelector ).click(); | ||
$input.remove(); | ||
}; | ||
|
||
/** | ||
* Add AMP status toggle. | ||
* | ||
* @since 0.6 | ||
* @param {Object} $target Event target. | ||
* @return {void} | ||
*/ | ||
component.toggleAmpStatus = function toggleAmpStatus( $target ) { | ||
var $container = $( '#amp-status-select' ), | ||
status = $container.data( 'amp-status' ), | ||
$checked, | ||
editAmpStatus = $( '.edit-amp-status' ); | ||
|
||
// Don't modify status on cancel button click. | ||
if ( ! $target.hasClass( 'button-cancel' ) ) { | ||
status = $( '[name="' + component.data.statusInputName + '"]:checked' ).val(); | ||
} | ||
|
||
$checked = $( '#amp-status-' + status ); | ||
|
||
// Toggle elements. | ||
editAmpStatus.fadeToggle( component.toggleSpeed, function() { | ||
if ( editAmpStatus.is( ':visible' ) ) { | ||
editAmpStatus.focus(); | ||
} | ||
} ); | ||
$container.slideToggle( component.toggleSpeed ); | ||
|
||
// Update status. | ||
$container.data( 'amp-status', status ); | ||
$checked.prop( 'checked', true ); | ||
$( '.amp-status-text' ).text( $checked.next().text() ); | ||
}; | ||
|
||
return component; | ||
})( window.jQuery ); |
Oops, something went wrong.