mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-04 03:45:58 -05:00
Improve code explanation in load.js
This commit is contained in:
parent
5fd0640d5f
commit
5cb4ab732b
1 changed files with 9 additions and 6 deletions
15
src/load.js
15
src/load.js
|
@ -21,12 +21,15 @@ if (typeof window === 'object') {
|
||||||
|
|
||||||
// Browser based loading through Prepro.js:
|
// Browser based loading through Prepro.js:
|
||||||
if (!window.include) {
|
if (!window.include) {
|
||||||
var scripts = document.getElementsByTagName('script');
|
// Get the last script tag and assume it's the one that loaded this file
|
||||||
var src = scripts[scripts.length - 1].getAttribute('src');
|
// then get its src attribute and figure out the location of our root.
|
||||||
// Assume that we're loading browser.js from a root folder, either
|
var scripts = document.getElementsByTagName('script'),
|
||||||
// through dist/paper-full.js, or directly through src/load.js, and
|
src = scripts[scripts.length - 1].getAttribute('src');
|
||||||
// match root as all the parts of the path that lead to that folder.
|
// Assume that we're loading from a non-root folder, either through
|
||||||
var root = src.match(/^(.*\/)\w*\//)[1];
|
// ../../dist/paper-full.js, or directly through ../../src/load.js,
|
||||||
|
// and match root as all the parts of the path that lead to that folder.
|
||||||
|
// So we basically just want all the leading '.' and '/' characters:
|
||||||
|
var root = src.match(/^([.\/]*)/)[1];
|
||||||
// First load the prepro's browser.js file, which provides the include()
|
// First load the prepro's browser.js file, which provides the include()
|
||||||
// function for the browser.
|
// function for the browser.
|
||||||
load(root + 'node_modules/prepro/lib/browser.js');
|
load(root + 'node_modules/prepro/lib/browser.js');
|
||||||
|
|
Loading…
Reference in a new issue