Skip to content

Commit 4b43359

Browse files
authored
Added back JS for vh (#36719)
1 parent e5a9aec commit 4b43359

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

extensions/amp-story/1.0/amp-story-page.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import {isPrerenderActivePage} from './prerender-active-page';
5959
import {listen, listenOnce} from '#utils/event-helper';
6060
import {CSS as pageAttachmentCSS} from '../../../build/amp-story-open-page-attachment-0.1.css';
6161
import {propagateAttributes} from '#core/dom/propagate-attributes';
62-
import {toggle} from '#core/dom/style';
62+
import {px, toggle} from '#core/dom/style';
6363
import {renderPageAttachmentUI} from './amp-story-open-page-attachment';
6464
import {renderPageDescription} from './semantic-render';
6565
import {whenUpgradedToCustomElement} from '#core/dom/amp-element-helpers';
@@ -214,6 +214,9 @@ export class AmpStoryPage extends AMP.BaseElement {
214214
/** @private {?AdvancementConfig} */
215215
this.advancement_ = null;
216216

217+
/** @private {?Element} */
218+
this.cssVariablesStyleEl_ = null;
219+
217220
/** @const @private {!function(boolean)} */
218221
this.debounceToggleLoadingSpinner_ = debounce(
219222
this.win,
@@ -610,13 +613,23 @@ export class AmpStoryPage extends AMP.BaseElement {
610613
const {height, width} = layoutBox;
611614
state.height = height;
612615
state.width = width;
616+
state.vh = height / 100;
613617
},
614618
mutate: (state) => {
615619
const {height, width} = state;
616620
if (state.height === 0 && state.width === 0) {
617621
return;
618622
}
619623
this.storeService_.dispatch(Action.SET_PAGE_SIZE, {height, width});
624+
if (!this.cssVariablesStyleEl_) {
625+
const doc = this.win.document;
626+
this.cssVariablesStyleEl_ = doc.createElement('style');
627+
this.cssVariablesStyleEl_.setAttribute('type', 'text/css');
628+
doc.head.appendChild(this.cssVariablesStyleEl_);
629+
}
630+
this.cssVariablesStyleEl_.textContent = `:root {--story-page-vh: ${px(
631+
state.vh
632+
)} !important}`;
620633
},
621634
},
622635
{}

0 commit comments

Comments
 (0)