Support for absolute JS plugin urls

Change-Id: I777276aa187e90ffe33969dcecf14f87aa737f20
This commit is contained in:
Viktar Donich
2017-06-27 10:32:56 -07:00
parent bda07485ec
commit 2b22d83b6e
2 changed files with 22 additions and 6 deletions

View File

@@ -43,13 +43,20 @@
},
_loadJsPlugins(plugins) {
for (let i = 0; i < plugins.length; i++) {
const scriptEl = document.createElement('script');
scriptEl.defer = true;
scriptEl.src = '/' + plugins[i];
scriptEl.onerror = Gerrit._pluginInstalled;
document.body.appendChild(scriptEl);
for (let url of plugins) {
if (!url.startsWith('http')) {
url = '/' + url;
}
this._createScriptTag(url);
}
},
_createScriptTag(url) {
const el = document.createElement('script');
el.defer = true;
el.src = url;
el.onerror = Gerrit._pluginInstalled;
return document.body.appendChild(el);
},
});
})();

View File

@@ -63,5 +63,14 @@ limitations under the License.
assert.isTrue(element.importHref.calledWith(
'/baz', Gerrit._pluginInstalled, Gerrit._pluginInstalled, true));
});
test('imports js plugins from config', () => {
sandbox.stub(element, '_createScriptTag');
element.config = {
js_resource_paths: ['foo/bar', 'http://baz'],
};
assert.isTrue(element._createScriptTag.calledWith('/foo/bar'));
assert.isTrue(element._createScriptTag.calledWith('http://baz'));
});
});
</script>