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