Adding Javascript on a per-worksheet basis

2 views
Skip to first unread message

Rob Beezer

unread,
Feb 6, 2010, 2:50:29 AM2/6/10
to sage-notebook
Another question about creating worksheets programatically. I need to
add a bit (one line) of Javascript to a worksheet (see yesterday's
jsMath post). It is not something that should be added to *every*
worksheet ever, so it shouldn't just be added to a system-wide
script. When I put it in with the "contents" of a worksheet (as you
you would via the Edit text area in the notebook), it is not parsed
right, and I basically get all the contents of the worksheet twice
(even though the javascript does have the right effect).

So I stuffed the one needed line into

sagenb/data/sage/html/notebook/base.html

where the worksheet name gets set, just above the
"server_ping_while_alive()" line. This works cleanly - it migrates to
the page, seemingly causes no odd behavior and it has the desired
effect.

Is there a way to have this same result on a per-worksheet basis as I
create a worksheet progrmatically, and if so, how?

Thanks,
Rob

Jason Grout

unread,
Feb 6, 2010, 1:01:47 PM2/6/10
to sage-n...@googlegroups.com
On 02/06/2010 12:50 AM, Rob Beezer wrote:
> Another question about creating worksheets programatically. I need to
> add a bit (one line) of Javascript to a worksheet (see yesterday's
> jsMath post). It is not something that should be added to *every*
> worksheet ever, so it shouldn't just be added to a system-wide
> script.

Why not? The security restriction in jsmath prevents a user from
inserting arbitrary HTML into a page. However, Sage users can already
do that in several different ways. So I don't see a problem with
letting them create HTML via jsmath too.

--

Rob Beezer

unread,
Feb 6, 2010, 1:51:17 PM2/6/10
to sage-notebook
Thanks, Jason. Just figured there were good reasons for it being the
way it is right now. I'll propose a change then with a patch.

Do you know off the top of your head in which file the
jsMath.safeHBoxes is set, or where I would place a change to override
the default settings?

Pat LeSmithe

unread,
Feb 6, 2010, 1:54:14 PM2/6/10
to sage-n...@googlegroups.com
On 02/06/2010 10:51 AM, Rob Beezer wrote:
> Thanks, Jason. Just figured there were good reasons for it being the
> way it is right now. I'll propose a change then with a patch.
>
> Do you know off the top of your head in which file the
> jsMath.safeHBoxes is set, or where I would place a change to override
> the default settings?

The file is sagenb/data/sage/js/jsmath.js (line 97).

Rob Beezer

unread,
Feb 6, 2010, 2:47:13 PM2/6/10
to sage-notebook
Thanks, I'll get the change together this weekend.

jason...@creativetrax.com

unread,
Feb 8, 2010, 7:25:55 AM2/8/10
to sage-n...@googlegroups.com
Rob Beezer wrote:
> Thanks, Jason. Just figured there were good reasons for it being the
> way it is right now. I'll propose a change then with a patch.
>
> Do you know off the top of your head in which file the
> jsMath.safeHBoxes is set, or where I would place a change to override
> the default settings?
>

Pat's suggested file looks like where jsmath is located. I would
strongly suggest *not* patching jsmath. We have a couple of settings
related to jsmath that are done right around where we include
jsmath---do it there. That way we can transparently upgrade jsmath
(maybe to mathjax), and we clearly know where we deviate from the defaults.

I think I'm talking about data/sage/html/notebook/head.tmpl or something
like that.

Thanks,

Jason


Rob Beezer

unread,
Feb 8, 2010, 11:09:33 AM2/8/10
to sage-notebook
Jason,

I agree we shouldn't patch part of the jsMath distribution, and gave
this some thought. There is also

sagenb/data/jsmath/jsMath.js

in a directory full of lots of other jsMath files.

So is the file being patched under control of notebook development (as
it is in a subdirectory named "sage") or is it an integral part of
default jsMath? I don't know enough about how jsMath gets unpacked
into the notebook file structure to say for sure. The patch has a
positive review, so adjust that if required.

Thanks,
Rob

Pat LeSmithe

unread,
Feb 8, 2010, 8:08:38 PM2/8/10
to sage-n...@googlegroups.com
On 02/08/2010 08:09 AM, Rob Beezer wrote:
> Jason,
>
> I agree we shouldn't patch part of the jsMath distribution, and gave
> this some thought. There is also
>
> sagenb/data/jsmath/jsMath.js
>
> in a directory full of lots of other jsMath files.
>
> So is the file being patched under control of notebook development (as
> it is in a subdirectory named "sage") or is it an integral part of
> default jsMath? I don't know enough about how jsMath gets unpacked
> into the notebook file structure to say for sure. The patch has a
> positive review, so adjust that if required.
>
> Thanks,
> Rob
>
> On Feb 8, 4:25 am, jason-s...@creativetrax.com wrote:
>> Rob Beezer wrote:
>>> Thanks, Jason. Just figured there were good reasons for it being the
>>> way it is right now. I'll propose a change then with a patch.
>>
>>> Do you know off the top of your head in which file the
>>> jsMath.safeHBoxes is set, or where I would place a change to override
>>> the default settings?
>>
>> Pat's suggested file looks like where jsmath is located. I would

But it's not. The file

sagenb/data/sage/js/jsmath.js

is a template version of jsMath's easy/load.js. The server (see
twist.py) populates it with, e.g., our jsMath macros. (Someday, we
could set these and other preferences from server, user, and/or
worksheet settings.)

The jsMath files are in

sagenb/data/jsmath

The ticket is

http://trac.sagemath.org/sage_trac/ticket/8202

jason...@creativetrax.com

unread,
Feb 9, 2010, 10:37:57 AM2/9/10
to sage-n...@googlegroups.com


Perfect. Thanks for clarifying.

Thanks,

Jason


Reply all
Reply to author
Forward
0 new messages