Skip to content

Commit c931f4b

Browse files
committed
Port javascript plugin to Gerrit v3.1.4 API
Most of it are horrible workarounds to allow access to the shadow DOM roots to do modifications to the local DOMs. Aka regular document.getElementById need to be replaced with querySelector calls on the specific shadow roots. Which will probably break with a future Polymer / Gerrit update. Change-Id: Ibeac25a4528e0c89d17a41c3cdfea986e48b17a9 Reviewed-by: Jukka Jokiniva <[email protected]> Reviewed-by: Paul Wicking <[email protected]>
1 parent d81afa1 commit c931f4b

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

qt-gerrit-ui-plugin/qt-gerrit-ui-plugin.html

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@
5151
});
5252

5353
// Customize header changes dropdown menu
54-
plugin.hook('header-dropdown-Changes').onAttached(element => {
54+
plugin.hook('header-dropdown-changes').onAttached(element => {
5555
// this is ugly, but there is no API for this
56-
var ul_elem = element.content.children[1].children[0].children[0].children[0];
56+
var parent_elem = element.parentNode.host;
57+
var ul_elem = parent_elem.childNodes[1].root.childNodes[4].childNodes[1].childNodes[1];
5758
var li_elem;
5859
var link_elem;
5960

@@ -77,19 +78,30 @@
7778
});
7879

7980
// Hide Sanity Bot review score row by default in reply dialog
80-
plugin.hook('review-label-scores-Sanity-Review').onAttached(element => {
81-
const html = '<div onclick="\
82-
document.getElementById(\'sanitybotreviewmorediv\').style.display=\'none\'; \
83-
document.getElementById(\'sanitybotreviewscorediv\').style.display=\'block\'; \
84-
\"> \
81+
plugin.hook('review-label-scores-sanity-review').onAttached(element => {
82+
const html = '<div id="review-label-scores-sanity-review-more-button"> \
8583
<div id="sanitybotreviewmorediv" style="display:block;">more...</div> \
8684
<div id="sanitybotreviewscorediv" style="display:none;"></div> \
8785
</div>';
8886
var wrapper_elem = document.createElement('div');
8987
wrapper_elem.innerHTML = html;
90-
var child_elem = element.content.children[0];
91-
element.content.replaceChild(wrapper_elem, child_elem);
92-
document.getElementById('sanitybotreviewscorediv').appendChild(child_elem);
88+
89+
// Access the shadow DOM root (seems to be the same as .shadowRoot).
90+
var child_elem = element.content.root.childNodes[2];
91+
element.content.root.replaceChild(wrapper_elem, child_elem);
92+
93+
// Append the original content inside the just-replaced element.
94+
wrapper_elem.querySelector("#sanitybotreviewscorediv").appendChild(child_elem);
95+
96+
// Install click listener to show the score buttons when clicking on more.
97+
var more_button_handler = wrapper_elem.querySelector("#review-label-scores-sanity-review-more-button");
98+
var more_button_div = wrapper_elem.querySelector("#sanitybotreviewmorediv");
99+
var review_score_div = wrapper_elem.querySelector("#sanitybotreviewscorediv");
100+
more_button_handler.addEventListener("click", function() {
101+
more_button_div.style.display = "none";
102+
review_score_div.style.display = "block";
103+
});
104+
93105
});
94106

95107
// Customize change view
@@ -100,7 +112,7 @@
100112
plugin.ca.setActionHidden('revision', 'rebase', true);
101113

102114
// Hide 'Sanity-Review+1' button in header
103-
var secondaryActionsElem = document.getElementById("secondaryActions");
115+
var secondaryActionsElem = plugin.ca._el.root.querySelector("#secondaryActions");
104116
if (secondaryActionsElem &&
105117
secondaryActionsElem.innerHTML &&
106118
secondaryActionsElem.innerHTML.indexOf('Sanity-Review+1') != -1) {

0 commit comments

Comments
 (0)