Skip to content
This repository has been archived by the owner on Jun 23, 2018. It is now read-only.

id needed in script tag #78

Open
TheThirdOne opened this issue May 3, 2014 · 12 comments
Open

id needed in script tag #78

TheThirdOne opened this issue May 3, 2014 · 12 comments

Comments

@TheThirdOne
Copy link

Why exactly does the script tag need to have an id?

This seems unnecessary and it would allow more diversity if jsrepl was not dependent on DOM . This is a particularly large problem when working with Chrome extensions, where you have no control over the background DOM.

@amasad
Copy link
Contributor

amasad commented May 5, 2014

it's needed to get the url for the sandbox to load[1]. The sandbox being the iframe on old browser, or the Web Worker in newer browsers. Which will contain the interpreter for security, isolation, and performance reasons.

@amasad
Copy link
Contributor

amasad commented May 5, 2014

If you have better ideas, please would love to hear them

@TheThirdOne
Copy link
Author

I see now why it needs an id. One idea I had as a fallback at least:

function endsWith(str, suffix) {
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
var script = document.getElementsByTagName('script');
for(var i = 0; i < script.length;i++){
if(endsWith(script[i].src, 'jsrepl.js')){
return script.src
}
}

It's not ideal in the least, but it would remove (or negate the need of) the id system. It would simply need the name of the file to be jsrepl.js

@amasad
Copy link
Contributor

amasad commented May 5, 2014

I feel that the name of the script is the most variable here. But that wouldn't hurt I guess. Maybe a regexp to look for jsrepl would be best.

@TheThirdOne
Copy link
Author

Sorry, I accidentally posted early. Why do you feel the name is the most variable?

@TheThirdOne
Copy link
Author

Another suggestion, what if when a user initializes jsrepl, they supply a src attribute if they need to deviate from the normal pattern? That should be unobtrusive, and flexible for any projects needs.

@amasad
Copy link
Contributor

amasad commented May 5, 2014

Because people load the scripts from different folders and sometimes append version numbers to scripts.
I know that ACE the code editor, does a similar thing because it uses workers too. Take a look at how they do it. They match using regexp but you can also pass in options using data- attributes.
https://github.com/ajaxorg/ace/blob/86e7a496667f18913ff9bf4019f802578d6524b5/lib/ace/config.js#L155-L185

@TheThirdOne
Copy link
Author

At least loading from folders is handled by my approach, but regex would be fine for testing src to see if it is jsrepl.js or some variant. I think a combination of manual override, searching script elements, and special id would provide coverage for almost all use cases and not be hard not implement.

@amasad
Copy link
Contributor

amasad commented May 5, 2014

ah sorry, missed the endsWith function. Sounds great, feel free to send a pull request to implement this. Let me know if you need any help

@TheThirdOne
Copy link
Author

Is there any way to move the loader script detection inside the loader class, or any easy way a user could manually initiate it?

I will be glad to make a pull request implementing this, but it may have to wait for a bit because I have finals and don't know coffee-script at all.

@amasad
Copy link
Contributor

amasad commented May 5, 2014

It seems possible but would take a little bit of refactoring.

CoffeeScript is not that different from JS, try this book http://arcturo.github.io/library/coffeescript/

@TheThirdOne
Copy link
Author

I realize that CoffeeScript is not very different, but it has different enough syntax that I can't whip up a pull request in a very short time.

I will probably implement searching script tags by next week, but manual override will have to wait for a while.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants