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
diff --git a/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.html b/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.html
index 6b35328..3e9e19e 100644
--- a/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.html
+++ b/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.html
@@ -15,4 +15,6 @@
-->
<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>
diff --git a/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js b/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js
index 8eb63a4..ad3f2c2 100644
--- a/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js
+++ b/polygerrit-ui/app/behaviors/gr-tooltip-behavior/gr-tooltip-behavior.js
@@ -75,7 +75,7 @@
// Set visibility to hidden before appending to the DOM so that
// calculations can be made based on the element’s size.
tooltip.style.visibility = 'hidden';
- Polymer.dom(document.body).appendChild(tooltip);
+ Gerrit.getRootElement().appendChild(tooltip);
this._positionTooltip(tooltip);
tooltip.style.visibility = null;
diff --git a/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.html b/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.html
index 10eadf9..71cdec4 100644
--- a/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.html
+++ b/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.html
@@ -17,6 +17,8 @@
<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>
diff --git a/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.js b/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.js
index ee7fe97..a2daeb3 100644
--- a/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.js
+++ b/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.js
@@ -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) {
diff --git a/polygerrit-ui/app/scripts/rootElement.js b/polygerrit-ui/app/scripts/rootElement.js
new file mode 100644
index 0000000..1a07edf
--- /dev/null
+++ b/polygerrit-ui/app/scripts/rootElement.js
@@ -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);
\ No newline at end of file