Skip to content

Instantly share code, notes, and snippets.

@jarrodek
Created March 9, 2017 11:28
Show Gist options
  • Save jarrodek/eb2755cf1997e8180080eeb808a2c94a to your computer and use it in GitHub Desktop.
Save jarrodek/eb2755cf1997e8180080eeb808a2c94a to your computer and use it in GitHub Desktop.
A script that recognizes Polymer element's URL and parses it to read location of assets like web workers to import during runtime.
var importLocation = '';
(function() {
var url;
if (window.currentImport && window.currentImport.URL) {
url = window.currentImport.URL;
if (window.currentImport._URL) {
url = window.currentImport._URL;
}
} else if (window.currentImport._URL) {
url = window.currentImport._URL;
} else {
url = window.location.href;
}
if (url === 'about:blank') {
importLocation = '../';
// in test cases for edge this will fail because it should be set to ../../
// but right now I can't waste time to check how to check if this is the particular case.
} else {
var path = url.substr(url.indexOf('/', 8));
path = path.substr(0, path.lastIndexOf('/') + 1);
if (path.indexOf('/test') !== -1 || path.indexOf('/demo') !== -1) {
path = path.substr(0, path.length - 1);
path = path.substr(0, path.lastIndexOf('/') + 1);
}
importLocation = path;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment