MCPcopy Create free account
hub / github.com/ampproject/amphtml / createElement

Function createElement

test/unit/test-fixed-layer.js:215–381  ·  view source on GitHub ↗
(id)

Source from the content-addressed store, hash-verified

213 }
214 }
215 function createElement(id) {
216 const children = [];
217 const elem = {
218 id,
219 nodeType: 1,
220 ownerDocument: documentApi,
221 autoTop: '',
222 tagName: id,
223 toString: () => {
224 return id;
225 },
226 style: {
227 top: '15px',
228 bottom: '',
229 position: '',
230 opacity: '0.9',
231 visibility: 'visible',
232 transition: '',
233
234 setProperty(prop, value, priority) {
235 // Override if important
236 if (priority === 'important') {
237 elem.style[prop] = `${value} !${priority}`;
238 } else if (
239 elem.style[prop] ||
240 !elem.computedStyle[prop]?.endsWith('!important')
241 ) {
242 if (
243 prop === 'transition' &&
244 !value &&
245 endsWith(elem.style[prop] || '', '!important')
246 ) {
247 // Emulate a stupid Safari bug.
248 // noop.
249 } else {
250 // If element style is already set, we can override
251 // Or, if computed style is not important priority
252 elem.style[hypenCaseToCamelCase(prop)] = value;
253 }
254 }
255 },
256 },
257 computedStyle: {
258 opacity: '0.9',
259 visibility: 'visible',
260 _top: '',
261 get top() {
262 if (
263 elem.computedStyle.transition &&
264 elem.style.transition !== '' &&
265 elem.style.transition !== 'none !important'
266 ) {
267 return this._oldTop;
268 }
269 if (elem.style.bottom) {
270 return elem.autoTop || this._top;
271 }
272 return this._top;

Callers 3

cloneNodeFunction · 0.70
innerHTMLFunction · 0.70

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected