Authoring Sketches on the Desktop

Check out our beta-test site for instructional videos and examples of authored sketches.

For a complete author's manual see the Sketchpad Reference Center.

Exporting Sketches

How to export a Desktop Sketch as a Web Sketch

Tools and Tool Authoring

See Sketchpad Construction Tools -- how to author tools so that they appear in Web Sketches.

Most of the standard WSP tools support the Tool Help feature. (The Tool Help feature provides text hints for most of the standard WSP tools, and provides video hints for many of them.)

Widgets

Five widgets are available, each of which is activated by tapping its icon in the floating Widget Controller and deactivated by a second tap on the same icon. The widgeta allow the user to perform certain actions by tapping objects in the sketch: changing their styles, turning tracing on or off, labeling them, changing their visibility, and deleting them.

To make a widget available in your sketch, check the appropriate checkbox in the WSP Exporter's Export Document dialog box. For each widget you enable, you can enable it for all pages or you can list the pages on which it should appear, separated by commas (for example, "1,3,5"). Alternatively, you can use the sketch document itself to specify which widgets appear on which pages, as described in the Author Preferences section below.

Style Widget
This widget allows you to set point styles, styles for straight objects and other paths, and colors of all objects. First choose a style from the widget's palette, and then apply the selected style and color by tapping one or more sketch objects. The relevant styles are applied to each object you tap. Use the controls at the far right of the pane to confirm or cancel the style changes you've made during the current style session.
Trace Widget
This widget allows you to designate which objects in your sketch should be traced, to enable or disable tracing, to control whether traces are faded, and to erase the existing traces.
Tap an object to turn its tracing on; tap again to turn its tracing off.
  • Enabled: Use this checkbox to enable or disable all tracing in the sketch.
  • Fading: Use this checkbox to turn on or off the fading of traces over time.
  • Erase Traces: Use this checkbox to erase all the traces in the sketch.
  • Traced Objects Glow: Check this box to make all currently traced objects glow.
To create a single traced image of an otherwise untraced object, tap the object twice without dragging it. The first tap turns tracing on and the second tap turns it off again, leaving a trace. (Move the object to reveal the trace.)

Label Widget
This widget allows you to show, hide, edit, and format labels of objects. When this widget is activated, you can tap objects to show or hide their labels. If you tap an object that doesn't yet have a label, a new label is created for it. When you tap an object, its label appears in the widget's editing box and you can edit the label and change its font and size. Edit an existing label by tapping the label; edit the label of a button by tapping the handle of the button. Edit a single-line caption by tapping the caption. (Tapping a more-complex caption is possible, but the Label widget turns it into a one-line caption—probably not the desired result.)
  • Use the text size and font combo boxes to change the appearance of the label.
  • Use the drop-down next to the font box to insert mathematical symbols, Greek letters, and other special characters.
  • When you're done, return to normal operation by tapping the green confirm check mark or the label icon in the widget controller.
  • To undo the change to the last object you modified, tap the red cancel button.
  • To apply the label style (font, size, or visibilty) of the current object to another object in the sketch, tap the new object without closing the widget. (This does not apply to the radio buttons for Manual, Auto, None, Short, etc. To change several objects from Manual to Auto, for instance, you must select the Auto radio button for each object separately.)
For some objects, the label widget displays radio buttons that allow you to choose the format of their labels:
  • Parameters can be shown with their labels (Manual) or without their labels (None).
  • Expressions can be shown with their automatic descriptive labels (Auto), with editable labels (Manual), or with no labels (None).
  • Transformed images: The reflection of x in mirror m can be shown as x' (Prime), as r(x) (Short function notation), as rm(x) (Full function notation), or with an editable label (Manual).
  • Movement buttons that move a single point can be shown with the labels of the points (Auto) or with a hand-edited label (Manual).
  • Hide/Show buttons that hide or show a single object can be shown with the label of the object (Auto) or with a hand-edited label (Manual).
  • To specify any of these special label formats in tools, see Specifying Label Formats
Tap an unformatted single-line caption in the text to edit its contents. (WARNING: If you tap a formatted caption, the caption's text will appear in the label widget, but all formatting will be lost if you accept the changes. If you want to preserve the formatting, you must click the Cancel button.)
Visibility Widget
This widget allows you to hide or show objects. When you activate the widget, all hidden objects become visible in a gray color. Change the visibility of any object by tapping it. When you're done, tap the visibility icon again to return to normal operation.
Delete Widget
This widget allows you to delete objects from your sketch by activating the widget and tapping the object you want to delete. The widget then highlights the object that will be deleted along with any other objects that depend on it, allowing you to confirm or cancel the deletion. In case you make a mistake, you can use the Undo arrow to undo your deletion and restore the deleted object(s). When you're done, tap the delete icon again to return to normal operation.
Adding Widgets to a Web Page
To add widgets to a web page, check any of the widget checkboxes in the Export Document dialog box, and list the numbers of the pages on which the widget should appear. For instance, check the Style Widget box and type "1,2,4" in the corresponding Pages box to indicate that this widget should appear on pages 1, 2, and 4 of the sketch. Type "all" to make the widget appear on all pages of the sketch. (After a sketch has been exported, the widget preferences can still be changed by editing the web page. For details, see the section below: Widget and Utility Prefs in HTML.
Widgets Button
When you include widgets in an exported sketch, the resulting web page includes a Widgets button that turns the widgets floating window on and off. (The Widgets button does not appear on any sketch page for which you've used widget preferences to disable widgets.) This button is particularly useful for a web page that includes multiple sketches. On such a web page, there's a single set of widgets, but each sketch can have its own Widgets button that activates the widgets for that sketch.
Initial State of Widget Controller
The Widget Controller is initially hidden when a new sketch page opens, and the user can press the Widgets button to turn show or hide it. Set the showWidgetPanelOnPageStart sketch preference to true to make the Widget Controller appear automatically whenever a new sketch page opens.

Utility Popup Menu

The Utility popup menu appears below the bottom left corner of a sketch and includes commands that allow the user to manipulate the sketch in some way. The two commands currently available are Download and Upload.

This menu (and its commands) are available only by checking the Include Utility Menu checkbox in the Export Document dialog box.

Download Command
This utility command allows the user to download the current websketch as a json document. Choosing the command brings up a dialog box allowing the user to name the document to be saved. (A name of a saved sketch document must always end with ".json".) The document is downloaded to the same folder in which the user's browser normally places downloads.
Upload Command
This utility command allows the user to upload a previously downloaded websketch document into the current sketch frame. The current contents of the frame will be replaced by the newly uploaded websketch. Choosing the command brings up a dialog box allowing the user to select the document to be uploaded. The name of the document to be uploaded must end with ".json". (If you have made changes in your current websketch, you will be asked if you want to download your changed sketch first, before uploading a new websketch.)
Adding Utility Commands to a Web Page
To add utility commands to a web page, check the IncludeWUtility Menu checkbox in the Export Document dialog box. If you want to specify which of these commands are available on each page of your websketch, see the section below: Widget and Utility Prefs in HTML.

AutoStart Buttons

An autostart page button is a button that will be automatically pressed every time its sketch page appears, both when the sketch is first loaded and when the user switches to the page. You can set a button to autostart in either of two ways: (a) select the button when you save your source (.gsp) sketch, or (b) label it "autostart: " followed by the desired label of your choice. For instance, you might label a reset button "autostart: Reset." (Note "autostart" by itself is not enough.)

Autostart buttons (whether designated by label or by selection) are pressed automatically whenever a sketch page is loaded. For instance, an autostart button on page 2 of a sketch will be pressed automatically every time the user navigates to that page (not just the first time).

Glide Reflection

Web Sketchpad supports glide reflection similarly to other geometric transformations. A glide-reflected image in WSP is determined by three objects: the source object (also known as the pre-image) and two points that define the mirror/vector. If you think of the glide reflection as the composition of a translation (the glide) and a reflection, these two points determine both the vector for the translation and the mirror for the reflection.

Use GSP to author a sketch or tool that will include a glide reflection when exported to WSP: Construct a reflection using a mirror determined by two points. (The mirror itself can be a segment, ray, or line.) Add the signal _glidereflect_ (including the underscores) to the label of the reflected image. When exported to WSP, the image will be converted to a glide reflection that uses the two mirror-determining points as the mirror/vector of glide reflection.

Use WSP to author a sketch that will include a glide reflection when downloaded to a json file: Construct a reflection using a mirror determined by two points, add the signal _glidereflect_ to the label of the reflected image, and download the sketch to a json file. When the json file is uploaded to WSP, the image object will be a glide-reflected image using the two points that determine the mirror as the mirror/vector of glide reflection. (As of this writing, you cannot use WSP to create a glide-reflect tool.)

DEPRECATED: The earlier technique for creating a glide reflection tool by naming the sketch "WSP Tool: glide reflect"should no longer be used, for two reasons:

Case Presentation Button

Case buttons allow you to create a presentation button that presents only one of its parent buttons. The first parent of the Case button must contain a value (e.g., a parameter or calculation), and the remaining parents must be Action Buttons. When the case button is pressed, the value of the first parent serves as an index, determining which of the remaining button parents will be activated. This index must be an integer in the range 1...n, where n is the number of button parents. If the index has any other value the Case button does nothing.

At this time, there is no direct way to create a Case button in GSP. There is, however, a work-around: create a Hide/Show button with the desired parents, and give it a name that starts with "_Case:". Whatever follows the colon will become the label of the Case button. Alternatively, if you add nothing after the colon, the label of the Case button will match the parent button that it will activate. For instance, if the second and third parents are buttons labeled Foo and Bar, the Case button will be labeled "Foo" when the value of the first parent is 1, and "Bar" when the first parent has value of 2.

Just as with Sequence and Simultaneous Presentation buttons, pressing an active Case button stops the action. Along with the auto-labeling feature, this makes it convenient to use a Case button to control a number of hidden buttons; the Case button can display the name of its current target (the parent action button) and can turn that target on or off with a click.

Author Preferences

Certain preferences can be set by sketch authors in the document itself. To set these author preferences, create a page in your document using the Desktop version of Sketchpad, and name the page "WSP Preferences" (without quotes). On this page, any independent captions of the form "preferenceName=preferenceValue" will be exported as author preferences for the document in Web Sketchpad.

We support the author preferences listed below. Some of these (disableScrolling, removeInaccessibleObjects, and the various widget preferences) determine Exporter settings that are also available in the Exporter's "Export Document" dialog box. The remaining author preferences (including the tool preferences) can be set only on the WSP Preferences page of the sketch.

disableScrolling=true
This disables dragging in whitespace to scroll sketch contents. As a side effect, this will enable standard mobile browser pinch-zoom and pan gestures, which can enhance the navigability and accessibility of the HTML document as a whole. (This preference is false by default.)
removeInaccessibleObjects=true
This preference determines whether the exporter deletes from the sketch hidden objects that cannot be made visible and that have no descendants that can be made visible. (This preference is false by default.)
sequentialSnapping=false
This setting turns off "sequential snapping" for the tool sketches in the document. Under sequential snapping, a tool's givens can be moved to their final position by clicking the final position itself, in addition to the traditional way (by first grabbing the given, and then dragging it to its final position). (This preference is true by default.)
toolLook = classic, new, or compact
This setting sets the "skin" for the toolbox, determining how the toolbox looks to the user. There are three choices:
  • classic is the original skin, showing an icon representing the tool if the WSP Tool page contains a free picture, or the name of the tool otherwise.
  • new is a skin that shows both an icon (if the WSP Tool page contains a free picture) and the name of the tool.
  • compact is a skin that provides yet another look in which the tools appear as buttons 105 pixels wide with corners that are more rounded. This look is optimized for use with icons, but if there's no icon for a tool, it's identified by name using a 20-pixel font size. Short names, up to about 10 characters, are preferred.
toolplayNewLook=true (Deprecated)
This setting is deprecated, although still supported. It turns on the "new look" for toolplay, which features tool buttons with both text and icons, and a different general appearance. (This preference is false by default.)
enableLabelDragging=false
This setting (true by default) prevents the user from dragging the labels of objects in order to reposition those labels. (This preference is true by default.)
enableLabelEditing=true
This setting (false by default) enables a form of label editing that predates the Label widget. If you want to enable label editing, we advise leaving this preference with its default value and using the Label widget instead. (This preference is false by default.)
"enableTracing=1,3"
This setting ("all" by default) allows you to control the initial tracing behavior on each page of the sketch. Tracing will initially be on for the listed pages, and off for pages that are not listed. The user can employ the Trace widget, if available, to change this initial setting; if the Trace widget is not available, there's no way that the user can change the enableTracing setting for this page.
"styleWidget=2,3"
This setting (which defaults to "all" when first enabled) determines which pages of your sketch make the Style widget available to users.
"SegmentTool=1,3"
This setting determines which pages of your sketch make the Segment tool available to users. You must provide the Segment tool, on a GSP page named "WSP Tool: Segment." Similarly, if your sketch has a Number Line tool, you can use a preference such as "Number LineTool=3,4,5". (Though this feature doesn't directly relate to the widgets, it requires the widget code. The is automatically loaded if you include page controls, the utility menu, or any widget in your Export dialog box choices.)
"Reset Button=2,3"
This setting (which defaults to "all" when first enabled) determines which pages of your sketch include a Reset button below the sketch. Users can press the resulting Reset button to reset the sketch to its initial state.

Widget, Tool, and Utility Author Preferences

By default, if you include widgets when you export a sketch, widgets are enabled on each page of your sketch. But you may want only the style widget, or you may want a widget to appear on some sketch pages but not others. You can use the WSP Preferences page of your sketch (described above) to accomplish this. Below are several examples.

"visibilityWidget=none", "labelWidget=none"
Place these two captions on the WSP Preferences page of your sketch to enable only the style and trace widgets.
"styleWidget=2,3", "visibilityWidget=2,4", "labelWidget=all", "traceWidget=all"
The above three captions on the WSP Preferences page of your sketch will enable only the label and trace widgets on page 1, enable all four widgets on page 2, enable the style, label, and trace widgets on page 3, and enable the visibility, label, and trace widgets on page 4.
"SegmentTool=1,3", "CircleTool=2,3"
Place these captions on the WSP Preferences page of your sketch to enable the Segment and Circle tools to appear only on the indicated pages of your websketch. The source (.gsp) sketch must define these two tools (on pages named “WSP Sketch: Segment” and “WSP Sketch: Circle”).
"downloadUtil=all", "uploadUtil=2,3"
The above two captions on the WSP Preferences page of your sketch will enable the Download command on all pages and the Upload command only on pages 2 and 3.
"showWidgetPanelOnPageStart=true"
This caption on the WSP Preferences page of your sketch will make the Widget Controller appear automatically whenever a new sketch page opens.
"toolHelp=false"
This caption on the WSP Preferences page of your sketch will disable the Tool Help feature for all tools in your sketch.

Widget, Tool, and Utility Prefs in HTML

Widget and Utility prefs can also be set directly via a script in the host HTML page. This is particularly useful when an HTML page contains multiple websketches distinguished by their id's or .json filenames, because it allows you to set all of the widget and utility preferences in one place.

Add a Preferences Script Block
In the head section of your HTML page, insert a script similar to the following:
<script type="text/javascript">
  PREF.setWebPagePrefs  ([
    {pages: "none"}, // turn off all widget and utility commands for all sketches (omitting the category implies all widgets and all util commands; omitting sketches implies all sketches)
    {category: "widget", name: "style", sketches: "sketch2", pages: "1, 3, 5"}, // turn on the style widget for pages 1, 3 and 5 in the sketch identified as "sketch2".
    {category: "widget", name: "visibility", sketches: "sketch3, sketch4", pages: "all"},	// turn on the visibility widget for all pages of the sketches identified as "sketch3" and "sketch4"; pages: "all" could be omitted
    {category: "tool", name: "Segment, Circle", sketches: "sketch2", pages: "2, 3"},	// make the Segment and Circle tools appear only on pages 2 and 3 of the sketch identified as "sketch2".
    {category: "util", name: "download", sketches: "sketch4"}	// Omitting pages implies all pages, so the Download utility command will appear on all pages of the specified sketch.
  ]);
</script>
Each line specifies the four parts of a preference setting: the category and name of the preference itself, and the sketches and pages to which it applies. You can use "all" or "none" as shortcuts. You can omit the name, pages, or sketches to imply "all", and you can omit the category to imply both utility commands and widgets.
Widgets Button
When you include widgets in an exported sketch, the resulting web page includes a Widgets button that turns the widgets floating window on and off. (The Widgets button does not appear on any sketch page for which you've used widget preferences to disable widgets.) This button is particularly useful for a web page that includes multiple sketches. On such a page, there's a single set of widgets, but each sketch can have its own Widgets button that activates the widgets for that sketch.
Utility-Menu Button
Similarly, when you include widgets in an exported sketch, the resulting web page includes a Utility menu button below the bottom left corner of the sketch. This button appears only on pages for which one or more utility commands are enabled.

Page Controller

The page controller makes it easy for a user to move from page to page of a sketch containing multiple pages. To add the page controller to a web page, check the Include Widgets checkbox in the Export Document dialog box. (This option is available only when you export a complete web page.) The page controller incorporates three buttons:

The page controller appears only for sketches that have more than a single page.

Page Controller Without Widgets

To export a sketch with the page controller but no widgets, you can use either Author Preferences or Widget HTML Preferences. In either case, you need to use the Include Widgets option in the Export Document dialog box.

To use Author Preferences, include the following three captions on the WSP Preferences page of your sketch:

visibilityWidget=none
styleWidget=none
labelWidget=none

To eliminate the page controller using Widget HTML Preferences, include the following script on your HTML page:

<script type="text/javascript"> WIDGETS.setWidgetPrefs ([{pages: "none"}]);<script>

Multiple Sketches on an Existing Web Page

To add one or more websketches to an existing web page (whose source is referred to below as index.html”), you must prepare the webpage directory and modify the contents of index.html.
To prepare the webpage directory:
  • On the WSP build site, use the Sketch Exporter page to export the desired websketch(es) in Javascript format. The name of each resulting file will be based on the name of the source sketch (for instance, exporting "mysketch.gsp" creates the file “mysketch-json.js”).
  • Put your downloaded json.js files into the webpage directory.
  • On the WSP build site, use the Download page to download the zip file for the current WSP build.
  • Unzip the build and put the resulting js directory into the webpage directory.
  • If you’re including widgets, also put the resulting widgets directory into the webpage directory.
To modify index.html without widgets:
  • Add the following lines in the <head> portion of the page:
    <script charset="utf-8" type="text/javascript" src="./js/jquery-2.1.0.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="./js/wsp-min.js"></script>
    <script charset="utf-8" type="text/javascript" src="./js/wsp-runner.js"></script>
    <style type="text/css”>
     .sketch_canvas { 
       border: medium solid lightgray; 
        display: inline-block; 
      }
    </style>
  • Add the following line in the <body> where you want each websketch to appear, changing the data-var to use the name associated with the downloaded json file. (Don't include the "-json.js" part of teh file name.)
    <div class="sketch_canvas" data-var="mysketch" > </div>
To modify index.html and include widgets:
  • Add the following lines in the <head> portion of the page:
    <script charset="utf-8" type="text/javascript" src="./js/jquery-2.1.0.min.js"></script>
    <script charset="utf-8" type="text/javascript" src="./js/wsp-min.js"></script>
    <script charset="utf-8" type="text/javascript" src="./widgets/jquery.tiny-draggable.js"></script>
    <link rel="stylesheet" type="text/css" href="./widgets/widgets.css" />
    <script charset="utf-8" type="text/javascript" src="./widgets/widgets.js"></script>
    <script charset="utf-8" type="text/javascript" src="./js/wsp-runner.js"></script>
    <style type="text/css”>
     .sketch_canvas { 
       border: medium solid lightgray; 
        display: inline-block; 
      }
    </style>
  • Add the following lines in the <body> where you want each websketch to appear, changing the data-var to use the name associated with the desired json.js file:
    <div class="sketch_container">
      <div class="sketch_canvas" data-var="mysketch" > </div>
            <div style="clear:both;"></div>
      <div class="util-menu-btn"></div> <!-- only needed if including the utility menu -->
      <p><!--Any (short!) desired left-justified text goes here--></p>
      <span class="page_buttons"></span> <!-- only needed if including page controls -->
      <button class="widget_button">Widgets</button> <!-- only useful if the page includes multiple websketches -->
    </div>
To store your sketches in their own directory
You can store the websketches used on your webpage in a directory of their own to avoid cluttering the main webpage directory.
  • Inside the webpage directory create a directory for storing the websketches. In this example we name this directory "sketches".
  • Put your websketch files, in json.js format, into the sketches directory.
  • Use the following form for your sketch_canvas elements. This example assumes the sketch file is "triangle-json.js".
  • <div class="sketch_canvas" data-var="sketches/triangle" > </div>
  • The first part of the data-var attribute (up to the final slash) is the path to the folder containing the sketch. The part after the final slash is the part of the sketch filename that precedes "-json.js" ("triangle" in this example). (The program also uses "triangle" internally, as the name of the javascript variable).
Avoid changing names of exported files
When Web Sketchpad creates a Javascript formatted sketch file, the file is actually a javascript file that defines a javascript variable containing the sketch information. Web Sketchpad uses the name of the variable as part of the file name. If the source file for the exporter was triangle.gsp, the javascript variable will be "triangle" and the sketch filename will be "triangle-json.js".
If you change the name of the file, the variable name and the file name will no longer match, and the sketch will not load properly.
If you want to change the name of an existing sketch file, you can either edit the named variable inside the file (ugh! risky!), or use Web Sketchpad to do it for you. To use Web Sketchpad, upload the original file either into the Exporter or into a websketch that has the Utility Menu's Upload and Download commands available. When you subsequently download the file, you can give it a new name and Web Sketchpad will guarantee that the new file name and variable name match.

Per-Page Tools

You can now specify which tools should appear on each page of a websketch.

For instance, if your GSP document has three tool pages named WSP Tool: Point, WSP Tool: Segment, and WSP Tool: Circle, you could make the Point tool appear on all pages, make the Segment tool appear on both pages 2 and 3, and make the Circle tool appear only on page 3. To do so, create a WSP Preferences page in your source sketch (the .gsp document) and enter the following captions:

SegmentTool = 2,3
CircleTool = 3

When you export your sketch, the Segment and Circle tools will appear only on the indicated pages.

Because the Point tool is not listed, it will appear on all pages of the websketch.

Make Your Webpage Respond to Sketch Page Changes

The author of a webpage can now display different information depending on the sketch page the user is displaying. For instance, the sketch container below includes a <div> element above the sketch that will appear only when the user accesses page 2 or page 3 of the corresponding sketch, and another <div> element that appears below the sketch only when the user is on page 3.

<div class="sketch_container">
  <div  class="page_toggle p_2 p_3">
    <p>This text appears only when the user is on page 2 or 3 of the sketch.</p>
  </div>
  <div class="sketch_canvas" data-url="mysketch.json" > </div>
  <div  class="page_toggle p_3">
    <p>This text appears below the sketch only when the user is on page 3.</p>
  </div>
</div>

To use this feature, include widgets on your webpage (even if you don't use the widgets themselves), and locate both the sketch_canvas and page_toggle elements within the same sketch_container <div>.

The author of a webpage can now create a link in the webpage that changes the current page of the related sketch. To be "related" the link must be in the same sketch_container <div> that contains the sketch. For instance, the link below will make the sketch change to page 2:

Go on to <a onclick="PAGENUM.gotoPage(this, 2);">page 2.</a>

To use this feature, include widgets on your webpage (even if you don't use the widgets themselves), and locate both the sketch_canvas and page_toggle elements within the same sketch_container <div>.

You can use this feature in conjunction with the page_toggle feature above to make the sketch and web page interact smoothly. For instance, you can create a web page with a page_toggle element containing text related to page 1 of the sketch, and also containing a link to switch to page 2. Clicking that link will simultaneously switch the sketch to page 2 and change the web page itself to show the page_toggle element related to page 2 of the sketch.

Add a Reset Button

Reset Button below your sketch:
You can add a Reset button below the sketch (just to the left of the page controller) by specifying the "Reset Button" author preference. You can create this preference on the WSP Preferences page of your sketch by adding the caption "Reset Button = all". To put a Reset button on some pages but not others, list the page numbers instead of "all." For example, use "Reset Button = 1,3,5" to show Reset buttons on pages 1, 3, and 5 of your sketch, but not on pages 2 or 4.
Alternatively, you can check the "Include Reset Button" checkbox on the Sketch Exporter dialog box. The input box next to the checkbox should be "all" for all pages, or should list the page numbers for which the Reset button should appear (for instance, "2, 4" for Reset Buttons on pages 2 and 4).
Reset Button in your sketch:
It's also possible to ploce a Reset button in the sketch. To do so:
  • Create a "Reset Sketch" button that does something innocuous. You might make a Hide button that hides an already-hidden point, and name the button "Reset Sketch."
  • Add the code shown below to your HTML page:
  • <script type="text/javascript">
      $(function() {
        $(".sketch_container").on ("PressButton.WSP", function (ev, ctx) {
          if (ctx.gobj.label === "Reset Sketch") {
            ctx.document.undo('all');
          }
        });
      });
    </script>
  • This code will detect the user's pressing on the "Reset Sketch" button, and call WSP's "undo ('all') function to reload the sketch in its initial state.
  • Note! The Reset button resets only the current page of the sketch; you cannot use it to reset all pages of a multi-page sketch.

CORS (Cross-Origin Resource Sharing) Restrictions and Javascript Sketch Format

Though CORS restrictions help prevent malware from infecting web users, they can make it difficult for teachers who create their own sketch-containing web pages for student use. You may find that a WSP sketch in JSON format doesn't load when you open the page on your own computer, even though the sketch appears correctly when you put that same page on a server. (Such problems are somewhat unpredictable, and vary depending on the browser you are using.)
One solution is to use the Javascript format for sketches rather than the JSON format. Here are some guidelines for doing so: