Skip to content

Commit

Permalink
Prevent amp-state for nav menu toggle being inserted outside of body
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz authored and westonruter committed May 15, 2019
1 parent 437c335 commit 340c53a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions includes/sanitizers/class-amp-nav-menu-toggle-sanitizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public function sanitize() {
$script_el->appendChild( $this->dom->createTextNode( wp_json_encode( $expanded ) ) );
$state_el->appendChild( $script_el );
$nav_el->parentNode->insertBefore( $state_el, $nav_el );
if ( 'body' === $nav_el->nodeName ) {
$nav_el->insertBefore( $state_el, $nav_el->firstChild );
} else {
$nav_el->parentNode->insertBefore( $state_el, $nav_el );
}

$button_on = sprintf( "tap:AMP.setState({ $state_id: ! $state_id })" );
$button_el->setAttribute( 'on', $button_on );
Expand Down

0 comments on commit 340c53a

Please sign in to comment.