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) { _loadJsPlugins(plugins) {
for (let i = 0; i < plugins.length; i++) { for (let url of plugins) {
const scriptEl = document.createElement('script'); if (!url.startsWith('http')) {
scriptEl.defer = true; url = '/' + url;
scriptEl.src = '/' + plugins[i];
scriptEl.onerror = Gerrit._pluginInstalled;
document.body.appendChild(scriptEl);
} }
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( assert.isTrue(element.importHref.calledWith(
'/baz', Gerrit._pluginInstalled, Gerrit._pluginInstalled, true)); '/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> </script>