Support for absolute JS plugin urls
Change-Id: I777276aa187e90ffe33969dcecf14f87aa737f20
This commit is contained in:
@@ -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);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
Reference in New Issue
Block a user