JavaScript (AJAX) Components of the Notebook

JavaScript (AJAX) Components of the Notebook


  • William Stein
  • Tom Boothby
  • Alex Clemesha

This file contains some minimal code to generate the Javascript code which is inserted to the head of the notebook web page. All of the interesting Javascript code is contained under data/sage/js/notebook_lib.js.

class sagenb.notebook.js.JSKeyCode(key, alt, ctrl, shift)

x.__init__(...) initializes x; see help(type(x)) for signature

class sagenb.notebook.js.JSKeyHandler

This class is used to make javascript functions to check for specific keyevents.

add(name, key='', alt=False, ctrl=False, shift=False)

Similar to set_key(...), but this instead checks if there is an existing keycode by the specified name, and associates the specified key combination to that name in addition. This way, if different browsers don’t catch one keycode, multiple keycodes can be assigned to the same test.


Builds all tests currently in the handler. Returns a string of javascript code which defines all functions.

set(name, key='', alt=False, ctrl=False, shift=False)

Add a named keycode to the handler. When built by all_tests(), it can be called in javascript by key_<key_name>(event_object). The function returns true if the keycode numbered by the key parameter was pressed with the appropriate modifier keys, false otherwise.


Return javascript library for the Sage Notebook. This is done by reading the template notebook_lib.js where all of the javascript code is contained and replacing a few of the values specific to the running session.

Before the code is returned (as a string), it is run through a JavascriptCompressor to minimize the amount of data needed to be sent to the browser.

The code and a hash of the code is returned.


This the output of this function is cached so that it only needs to be generated once.


sage: from sagenb.notebook.js import javascript
sage: s = javascript()
sage: s[0][:30]
'/* JavaScriptCompressor 0.1 [w'

Previous topic

The Sage Notebook

Next topic

Notebook Stylesheets (CSS)

This Page