Skip to content
This repository has been archived by the owner on Feb 14, 2025. It is now read-only.

Commit

Permalink
Provide fallback to currentScript.
Browse files Browse the repository at this point in the history
  • Loading branch information
larsmoa committed May 10, 2020
1 parent 62622b2 commit 7b72a32
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions source/Global.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
import {LRU} from "./utils/LRU.js";
import {WorkerManager} from "./utils/WorkerManager.js";

function getCurrentScript() {
var currentScript = (document && document.currentScript) ? document.currentScript : (function() {
var scripts = document.getElementsByTagName('script');
return scripts[scripts.length - 1].getAttribute('src');
})();
return currentScript;
}

function getBasePath()
{
if(document.currentScript && document.currentScript.src)
var currentScript = getCurrentScript();
if(currentScript && currentScript.src)
{
var scriptPath = new URL(document.currentScript.src + "/..").href;
var scriptPath = new URL(currentScript.src + "/..").href;

if(scriptPath.slice(-1) === "/")
{
Expand Down

0 comments on commit 7b72a32

Please sign in to comment.