[IPython-dev] Sourcing a javascript file from a notebook, and writing local javascript

Clare Sloggett claresloggett at gmail.com
Sun Jun 1 23:25:12 EDT 2014


Hi Andrew and Matthias,

Thanks very much! This should work for me. I have installed (other
people's) extensions in the past so I know where these things need to go.

I was kind of hoping there'd be a lightweight (interactive) way to change
the javascript via Notebook itself, just for dev purposes. However I can
see the security issues. This should be fine!

Although, would it work to put my external-library loading code into
nbextensions, then run the javascript that calls this library via
%%javascript or IPython.display's Javascript? Or have those things also
been deprecated?

Thanks again,
Clare


On 2 June 2014 06:01, Matthias Bussonnier <bussonniermatthias at gmail.com>
wrote:

>
> Le 31 mai 2014 à 18:41, Andrew Gibiansky a écrit :
>
> > I'm not an IPython dev, but I believe that embedding JS into a Markdown
> cell has indeed been deprecated, for security reasons. I now experiment by
> putting things in custom.js.
>
> Technically, we just never had the time to strip JS from markdown cell on
> 1.x, so it was not really supported.
> But yes, now it is sanitized and removed.
>
> >
> > Code in custom.js I think has all the privileges that normal Javascript
> has, so you should be free to load external files and scripts. You can
> include your own JS files using require.js:
>
> There should be a nbextension folder in ~/.ipython to store extra
> javascript
>
> >
> > require(['/static/custom/my_file.js']);
>
> this will fail in case where people serve IPython notebook with a prefix.
> you could use
> IPython.load_extensions('myext');
>
> that will do the right thing, and is a small wrapper around require.
> --
> M
>
> >
> > In a similar way you should be able to load foreign JS files, I think; I
> don't know require.js very well though. You could probably also just append
> a <script> tag to the DOM with a proper src attribute :)
> >
> > -- Andrew Gibiansky
> >
> >
> > On Sat, May 31, 2014 at 5:05 AM, Clare Sloggett <claresloggett at gmail.com>
> wrote:
> > Hi all,
> >
> > I was playing around with embeddable javascript libraries and seeing if
> I could make use them from a Notebook. My first attempt was to try the
> simplest thing possible; embed it in a markdown cell. The javascript I was
> trying to embed wants to both source an external file, and then use it via
> some local javascript code, like
> >    <script language="javascript" src="http://some-url/library.js
> "></script>
> >    <script language="javascript">
> >    ... code ...
> >    </script>
> >
> > In Notebook 1.x, the local code executes but throws an error about
> undefined variables, suggesting that the external javascript file was not
> loaded. Is this expected?
> >
> > In Notebook 2.0, so far as I can tell, none of it executes at all.
> >
> > Am I right in thinking that embedding Javascript into a markdown cell
> has been deprecated? Do I need to put it into custom.js instead? And, will
> I be able to source the remote file from there, or will I need to make that
> library local as well?
> >
> > Sorry if this is a naive question, a lot of aspects of this are new to
> me. I'm just looking for the most straightforward and lightweight approach
> so I can experiment with my code.
> >
> > Thanks in advance,
> > Clare
> >
> > _______________________________________________
> > IPython-dev mailing list
> > IPython-dev at scipy.org
> > http://mail.scipy.org/mailman/listinfo/ipython-dev
> >
> >
> > _______________________________________________
> > IPython-dev mailing list
> > IPython-dev at scipy.org
> > http://mail.scipy.org/mailman/listinfo/ipython-dev
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140602/c862d0dd/attachment.html>


More information about the IPython-dev mailing list