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

Ensure expected notice is hidden when theme support enabled by theme #1374

Merged
merged 1 commit into from
Aug 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions includes/options/class-amp-options-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,33 @@ public function render_validation_handling() {
<?php endif; ?>

<script>
jQuery( 'input[type=radio][name="amp-options[theme_support]"]' ).change( function() {
jQuery( '.amp-force-sanitize' ).toggleClass( 'hidden', 'native' === this.value );
jQuery( '.amp-validation-field' ).toggleClass( 'hidden', 'disabled' === this.value );
jQuery( '.amp-force-sanitize-canonical' ).toggleClass( 'hidden', 'native' !== this.value );
jQuery( '#force_sanitization' ).trigger( 'change' );
} ).filter( ':checked' ).trigger( 'change' );
jQuery( '#force_sanitization' ).change( function() {
jQuery( '.amp-tree-shaking' ).toggleClass( 'hidden', this.checked && 'native' !== jQuery( 'input[type=radio][name="amp-options[theme_support]"]:checked' ).val() );
} ).trigger( 'change' );
(function( $ ) {
var getThemeSupportMode = function() {
var checkedInput = $( 'input[type=radio][name="amp-options[theme_support]"]:checked' );
if ( 0 === checkedInput.length ) {
return <?php echo wp_json_encode( amp_is_canonical() ? 'native' : 'paired' ); ?>;
}
return checkedInput.val();
};

var updateTreeShakingHiddenClass = function() {
var checkbox = $( '#force_sanitization' );
$( '.amp-tree-shaking' ).toggleClass( 'hidden', checkbox.prop( 'checked' ) && 'native' !== getThemeSupportMode() );
};

var updateHiddenClasses = function() {
var themeSupportMode = getThemeSupportMode();
$( '.amp-force-sanitize' ).toggleClass( 'hidden', 'native' === themeSupportMode );
$( '.amp-validation-field' ).toggleClass( 'hidden', 'disabled' === themeSupportMode );
$( '.amp-force-sanitize-canonical' ).toggleClass( 'hidden', 'native' !== themeSupportMode );
updateTreeShakingHiddenClass();
};

$( 'input[type=radio][name="amp-options[theme_support]"]' ).change( updateHiddenClasses );
$( '#force_sanitization' ).change( updateTreeShakingHiddenClass );

updateHiddenClasses();
})( jQuery );
</script>

<p>
Expand Down