New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add javascript library and css stylesheet loading to JS class. #1410
Conversation
r += self.data | ||
if self.lib: | ||
for i in range(len(self.lib)): | ||
r+= lib_t2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that r += lib_t2 * len(self.lib)
would make sense to replace the if statement and python for-loop here (lines 410-412).
the same could be done with the css and lib for-loops above by converting them to a tuple, like r += css_t * len(self.css) % tuple(self.css)
and slightly cleaner if css was already a tuple. It may not by worth it in this case to convert those, although the whole function would have a bit more consistency to it - and look like this:
def _repr_javascript_(self):
r = css_t * len(self.css) % tuple(self.css)
r += lib_t1 * len(self.lib) % tuple(self.lib)
r += self.data
r += lib_t2 * len(self.lib)
return r
Just to be sure, is this what is supposed to happen when you give more than one js lib? In [11]: js = Javascript("""var a=[1,2,3];""", lib=["http://1.js","http://2.js"])
In [12]: print js._repr_javascript_() $.getScript("http://1.js", function () {
$.getScript("http://2.js", function () {
var a=[1,2,3];});
}); If that is indeed correct, it seems to serialize the loading of multiple scripts unnecessarily. |
jQuery doesn't have a way of loading multiple script simultaneously. http://bugs.jquery.com/ticket/9320 And a gist that implemented the capability, but it wasn't excepted. Cheers, Brian On Sat, Feb 18, 2012 at 3:29 PM, Min RK
Brian E. Granger |
No, I don't want to include any unnecessary patches. Besides, I doubt too many people are going to be loading more than one or two scripts in one of these calls, so it's not a huge deal. I just wanted to understand better, and now I do. Thanks! |
Add javascript library and css stylesheet loading to JS class.
Add javascript library and css stylesheet loading to JS class.
I have added a lib and css keyword argument to the
Javascript
display class. The lib option allows you to specify javascript libraries to load asynchronously before the JS code is run. The css option allows you to specify css stylesheet that should be loaded. Both the lib and css arguments are sequences of URLs to load the resources from. Use like this:Most importantly, the js code run by the object can use the loaded js library as well as the css styles.