Skip to content

Commit 05231a0

Browse files
authored
Merge pull request #5548 from Polymer/hide-template-controls-globally
Globally hide dom-{bind,if,repeat} elements with legacyOptmizations on
2 parents 76bfc0a + 43f57b1 commit 05231a0

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

lib/elements/dom-bind.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { OptionalMutableData } from '../mixins/mutable-data.js';
1414
import { GestureEventListeners } from '../mixins/gesture-event-listeners.js';
1515
import { strictTemplatePolicy } from '../utils/settings.js';
1616
import { wrap } from '../utils/wrap.js';
17-
import { legacyOptimizations } from '../utils/settings.js';
17+
import { hideElementsGlobally } from '../utils/hide-template-controls.js';
1818

1919
/**
2020
* @constructor
@@ -76,7 +76,7 @@ export class DomBind extends domBindBase {
7676
* @return {void}
7777
*/
7878
connectedCallback() {
79-
if (!legacyOptimizations) {
79+
if (!hideElementsGlobally()) {
8080
this.style.display = 'none';
8181
}
8282
this.render();

lib/elements/dom-if.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { enqueueDebouncer, flush } from '../utils/flush.js';
1515
import { microTask } from '../utils/async.js';
1616
import { root } from '../utils/path.js';
1717
import { wrap } from '../utils/wrap.js';
18-
import { legacyOptimizations } from '../utils/settings.js';
18+
import { hideElementsGlobally } from '../utils/hide-template-controls.js';
1919

2020
/**
2121
* The `<dom-if>` element will stamp a light-dom `<template>` child when
@@ -135,7 +135,7 @@ export class DomIf extends PolymerElement {
135135
*/
136136
connectedCallback() {
137137
super.connectedCallback();
138-
if (!legacyOptimizations) {
138+
if (!hideElementsGlobally()) {
139139
this.style.display = 'none';
140140
}
141141
if (this.if) {

lib/elements/dom-repeat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { OptionalMutableData } from '../mixins/mutable-data.js';
1616
import { matches, translate } from '../utils/path.js';
1717
import { timeOut, microTask } from '../utils/async.js';
1818
import { wrap } from '../utils/wrap.js';
19-
import { legacyOptimizations } from '../utils/settings.js';
19+
import { hideElementsGlobally } from '../utils/hide-template-controls.js';
2020

2121
/**
2222
* @constructor
@@ -321,7 +321,7 @@ export class DomRepeat extends domRepeatBase {
321321
*/
322322
connectedCallback() {
323323
super.connectedCallback();
324-
if (!legacyOptimizations) {
324+
if (!hideElementsGlobally()) {
325325
this.style.display = 'none';
326326
}
327327
// only perform attachment if the element was previously detached.

lib/utils/hide-template-controls.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
@license
3+
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
4+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7+
Code distributed by Google as part of the polymer project is also
8+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9+
*/
10+
11+
/**
12+
* @fileoverview
13+
*
14+
* Module to hide `<dom-bind>`, `<dom-if>`, and `<dom-repeat>` elements
15+
* optimally in ShadyDOM
16+
*/
17+
18+
import {legacyOptimizations, useShadow} from './settings.js';
19+
20+
let elementsHidden = false;
21+
22+
/**
23+
* @return {boolean} True if elements will be hidden globally
24+
*/
25+
export function hideElementsGlobally() {
26+
if (legacyOptimizations && !useShadow) {
27+
if (!elementsHidden) {
28+
elementsHidden = true;
29+
const style = document.createElement('style');
30+
style.textContent = 'dom-bind,dom-if,dom-repeat{display:none;}';
31+
document.head.appendChild(style);
32+
}
33+
return true;
34+
}
35+
return false;
36+
}

0 commit comments

Comments
 (0)