Use new extension point for manipulating comments This way the plugin does not need to scan all links of the page but only links that appear within a comment. Change-Id: I65cc581370d32a505249ab9bca8c5a1dd41545bd Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/lib/gerrit/BUCK b/lib/gerrit/BUCK index 38948b7..acb4718 100644 --- a/lib/gerrit/BUCK +++ b/lib/gerrit/BUCK
@@ -1,12 +1,11 @@ include_defs('//bucklets/maven_jar.bucklet') -VER = '2.12-rc0' -REPO = MAVEN_CENTRAL +VER = '2.13-SNAPSHOT' +REPO = MAVEN_LOCAL maven_jar( name = 'plugin-api', id = 'com.google.gerrit:gerrit-plugin-api:' + VER, - sha1 = '8fd408e0eedc5e891ac779ab26491fb377800e74', license = 'Apache2.0', attach_source = False, repository = REPO, @@ -15,7 +14,6 @@ maven_jar( name = 'gwtui-api', id = 'com.google.gerrit:gerrit-plugin-gwtui:' + VER, - sha1 = 'b2df95ec5181a64ee03bf9caaa73381a7c11fc88', license = 'Apache2.0', attach_source = False, repository = REPO,
diff --git a/src/main/resources/static/imagare.js b/src/main/resources/static/imagare.js index 971becf..91bec6f 100644 --- a/src/main/resources/static/imagare.js +++ b/src/main/resources/static/imagare.js
@@ -13,24 +13,20 @@ // limitations under the License. Gerrit.install(function(self) { - function onHistory(t) { - if (!startsWith(t, "/c/")) { - return; - } - + function onComment(e) { var prefs = getPrefsFromCookie(); if (prefs !== null) { - convertImageLinks(prefs); + convertImageLinks(getLinks(e), prefs); } else { Gerrit.get('/accounts/self/' + self.getPluginName() + '~preference', function(prefs) { storePrefsInCookie(prefs); - convertImageLinks(prefs); + convertImageLinks(getLinks(e), prefs); }); } } - function startsWith(s, p) { - return s.slice(0, p.length) == p; + function getLinks(e) { + return e.getElementsByTagName("a"); } function storePrefsInCookie(prefs) { @@ -64,20 +60,19 @@ return self.getPluginName() + "~prefs"; } - function convertImageLinks(prefs) { + function convertImageLinks(l, prefs) { if (!prefs.pattern) { return; } if ('TOOLTIP' === prefs.link_decoration) { - addTooltips(prefs.pattern); + addTooltips(l, prefs.pattern); } else if ('INLINE' === prefs.link_decoration) { - inlineImages(prefs.pattern); + inlineImages(l, prefs.pattern); } } - function inlineImages(pattern) { - var l = document.links; + function inlineImages(l, pattern) { for(var i = 0; i < l.length; i++) { if (l[i].href.match(pattern)) { var a = document.createElement('a'); @@ -92,7 +87,6 @@ } function addTooltips(pattern) { - var l = document.links; for(var i = 0; i < l.length; i++) { if (l[i].href.match(pattern)) { l[i].onmouseover = function (evt) { @@ -108,5 +102,5 @@ } } - Gerrit.on('history', onHistory); + Gerrit.on('comment', onComment); });