Add root element definition

Instead of appending/removing elements to document.body, add a global
that defines what the root element is. This way, in apps that use
elements with addional content outside, they will just need to set a
root element.

Change-Id: I0d01e4a6eea7d7d0af39989f1f831832506f1774
This commit is contained in:
Becky Siegel 2017-05-11 11:20:12 -07:00
parent 1c899dec74
commit 2602b6c958
5 changed files with 28 additions and 4 deletions

View File

@ -15,4 +15,6 @@ limitations under the License.
-->
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../../elements/shared/gr-tooltip/gr-tooltip.html">
<script src="../../scripts/rootElement.js"></script>
<script src="gr-tooltip-behavior.js"></script>

View File

@ -75,7 +75,7 @@
// Set visibility to hidden before appending to the DOM so that
// calculations can be made based on the elements size.
tooltip.style.visibility = 'hidden';
Polymer.dom(document.body).appendChild(tooltip);
Gerrit.getRootElement().appendChild(tooltip);
this._positionTooltip(tooltip);
tooltip.style.visibility = null;

View File

@ -17,6 +17,8 @@ limitations under the License.
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../gr-button/gr-button.html">
<script src="../../../scripts/rootElement.js"></script>
<dom-module id="gr-alert">
<template>
<style>

View File

@ -60,14 +60,14 @@
this.actionText = opt_actionText;
this._hideActionButton = !opt_actionText;
this._actionCallback = opt_actionCallback;
document.body.appendChild(this);
Gerrit.getRootElement().appendChild(this);
this._setShown(true);
},
hide: function() {
this._setShown(false);
if (this._hasZeroTransitionDuration()) {
document.body.removeChild(this);
Gerrit.getRootElement().removeChild(this);
}
},
@ -81,7 +81,7 @@
_handleTransitionEnd: function(e) {
if (this.shown) { return; }
document.body.removeChild(this);
Gerrit.getRootElement().removeChild(this);
},
_handleActionTap: function(e) {

View File

@ -0,0 +1,20 @@
// Copyright (C) 2017 The Android Open Source Project
//
// 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.
(function(window) {
window.Gerrit = window.Gerrit || {};
if (window.Gerrit.hasOwnProperty('getRootElement')) { return; }
window.Gerrit.getRootElement = () => document.body;
})(window);