forked from ampproject/amphtml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathamp-story-unsupported-browser-layer.js
More file actions
129 lines (119 loc) · 3.75 KB
/
amp-story-unsupported-browser-layer.js
File metadata and controls
129 lines (119 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* Copyright 2018 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Action, getStoreService} from './amp-story-store-service';
import {CSS} from '../../../build/amp-story-unsupported-browser-layer-1.0.css';
import {LocalizedStringId} from '../../../src/localized-strings';
import {createShadowRootWithStyle} from './utils';
import {dict} from './../../../src/utils/object';
import {removeElement} from '../../../src/dom';
import {renderAsElement} from './simple-template';
/** @const {string} Class for the continue anyway button */
const CONTINUE_ANYWAY_BUTTON_CLASS = 'i-amphtml-continue-button';
/**
* Full viewport black layer indicating browser is not supported.
* @private @const {!./simple-template.ElementDef}
*/
const UNSUPPORTED_BROWSER_LAYER_TEMPLATE = {
tag: 'div',
attrs: dict({'class': 'i-amphtml-story-unsupported-browser-overlay'}),
children: [
{
tag: 'div',
attrs: dict({'class': 'i-amphtml-overlay-container'}),
children: [
{
tag: 'div',
attrs: dict({'class': 'i-amphtml-gear-icon'}),
},
{
tag: 'div',
attrs: dict({'class': 'i-amphtml-story-overlay-text'}),
localizedStringId:
LocalizedStringId.AMP_STORY_WARNING_UNSUPPORTED_BROWSER_TEXT,
},
// The continue button functionality will only be present in the default
// layer. Publisher provided fallbacks will not provide users with the
// ability to continue with an unsupported browser
{
tag: 'button',
attrs: dict({'class': 'i-amphtml-continue-button'}),
localizedStringId:
LocalizedStringId.AMP_STORY_CONTINUE_ANYWAY_BUTTON_LABEL,
},
],
},
],
};
/**
* Unsupported browser layer UI.
*/
export class UnsupportedBrowserLayer {
/**
* @param {!Window} win
*/
constructor(win) {
/** @private @const {!Window} */
this.win_ = win;
/** @private {?Element} */
this.root_ = null;
/** @private {?Element} */
this.element_ = null;
/** @private {?Element} */
this.continueButton_ = null;
/** @private @const {!./amp-story-store-service.AmpStoryStoreService} */
this.storeService_ = getStoreService(this.win_);
}
/**
* Builds and appends the component in the story.
* @return {*} TODO(#23582): Specify return type
*/
build() {
if (this.root_) {
return this.root_;
}
this.root_ = this.win_.document.createElement('div');
this.element_ = renderAsElement(
this.win_.document,
UNSUPPORTED_BROWSER_LAYER_TEMPLATE
);
createShadowRootWithStyle(this.root_, this.element_, CSS);
this.continueButton_ = this.element_./*OK*/ querySelector(
`.${CONTINUE_ANYWAY_BUTTON_CLASS}`
);
this.continueButton_.addEventListener('click', () => {
this.storeService_.dispatch(Action.TOGGLE_SUPPORTED_BROWSER, true);
});
return this.root_;
}
/**
* Returns the unsupported browser componenet
* @return {?Element} The root element of the componenet
*/
get() {
if (!this.root_) {
this.build();
}
return this.root_;
}
/**
* Removes the entire layer
*/
removeLayer() {
if (this.root_) {
removeElement(this.root_);
}
}
}