on click prevents first evaluation

33 views
Skip to first unread message

David Farmer

unread,
Nov 18, 2016, 3:06:59 PM11/18/16
to sage-cell

I am trying to monitor the usage of the sage cells on a web page, so I inserted code like this:

$("button.sagecell_evalButton").on('click', function() {

    do_stuff_here

}

Everything seems to be working fine, except that the first time I click an evaluate button,
nothing seems to happen.  The second and later clicks work as usual.

My javascript records the initial click, even though the cell is not being evaluated.

If I replace do_stuff_here by *absolutely nothing*, the first click on the evaluate button
still has nothing happen.  So I am guessing that I should use some other method to
record the clicks on the evaluate buttons.

In case it matters, the above jascript is inside a setTimeout, so that it doesn't run until
after the sage cell code builds the cells on the page.  Probably that is not the right way
to do it, either.

Also, there are a dozen or so (linked) cells on the page, and it does not matter which
button I click first: nothing happens to any of them.  But they do flash a color, so I know
I am clicking it.

Any suggestions?

David

William Stein

unread,
Nov 18, 2016, 3:11:41 PM11/18/16
to David Farmer, sage-cell
On Fri, Nov 18, 2016 at 12:06 PM, David Farmer <far...@aimath.org> wrote:
>
> I am trying to monitor the usage of the sage cells on a web page, so I
> inserted code like this:
>
> $("button.sagecell_evalButton").on('click', function() {
>
> do_stuff_here
>
> }
>
> Everything seems to be working fine, except that the first time I click an
> evaluate button,
> nothing seems to happen. The second and later clicks work as usual.
>
> My javascript records the initial click, even though the cell is not being
> evaluated.
>
> If I replace do_stuff_here by *absolutely nothing*, the first click on the
> evaluate button
> still has nothing happen. So I am guessing that I should use some other
> method to
> record the clicks on the evaluate buttons.

It's conceivable you might be hitting this, though I doubt it...

http://stackoverflow.com/questions/11184276/return-false-from-jquery-click-event

>
> In case it matters, the above jascript is inside a setTimeout, so that it
> doesn't run until
> after the sage cell code builds the cells on the page. Probably that is not
> the right way
> to do it, either.

That sounds sketchy. Is there an event that the sage cell library
fires when it's done initializing or some callback function you can
register?

(I've never even looked at the source code of sage-cell's javascript library...)

>
> Also, there are a dozen or so (linked) cells on the page, and it does not
> matter which
> button I click first: nothing happens to any of them. But they do flash a
> color, so I know
> I am clicking it.
>
> Any suggestions?
>
> David
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-cell" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-cell+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-cell/51505dd0-6ab3-475d-ba7e-4ff8510b2968%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
William (http://wstein.org)

David Farmer

unread,
Nov 18, 2016, 3:18:08 PM11/18/16
to sage-cell

> It's conceivable you might be hitting this, though I doubt it...
>
> http://stackoverflow.com/questions/11184276/return-false-from-jquery-click-event

I don't return false (I don't explicitly return anything), because I
want the event to proceed normally: I am just recording some information
about it. So I also doubt that is it.

Paul Masson

unread,
Nov 18, 2016, 4:43:03 PM11/18/16
to sage-cell, far...@aimath.org


On Friday, November 18, 2016 at 12:11:41 PM UTC-8, William Stein wrote:
On Fri, Nov 18, 2016 at 12:06 PM, David Farmer <far...@aimath.org> wrote:
> In case it matters, the above jascript is inside a setTimeout, so that it
> doesn't run until
> after the sage cell code builds the cells on the page.  Probably that is not
> the right way
> to do it, either.

That sounds sketchy.  Is there an event that the sage cell library
fires when it's done initializing or some callback function you can
register?
 
The setup for embedded cells allows for an explicit callback function:

 

David Farmer

unread,
Nov 19, 2016, 9:07:15 AM11/19/16
to sage-cell

I made a minimal example showing the behavior I previously
described, by just adding a small amount of javascript to the
the minimal example in the documentation. In that case,
it worked just fine and the cell evaluated on the first click.

I'll try to make a minimal example by deleting items from
the actual page I care about. So, please don't look into this
until I post a live example.

Regards,

David


Ingo Dahn

unread,
Jun 28, 2022, 1:41:07 PM6/28/22
to sage-cell
I am trying to achieve the same objective - recording whether an evalbutton was clicked - is there meanwhile  any recommended solution?

Ingo Dahn

unread,
Jun 28, 2022, 2:01:36 PM6/28/22
to sage-cell
Solved adding a click handler to the evalbutton in the SageCell callback function.
Reply all
Reply to author
Forward
0 new messages