![]() |
| Frontier Tutorials / Writing an ObjectNotFoundHandler / Bonus: Mode 3 Utility Script |
|
|---|
This page contains a generic Mode 3 ONFH script. It is based on the ReturnBinaryObject script in the Mode 3 Example. You can call this script from small, simple scripts to implement Mode 3 ONFH handlers. See below for a complete discussion of the script.
Install the "ultimate" master script.
Install the ONFH_Mode3Return script in the ["#tools"] table.
Install one or more of the scripts the following sections in the ["#tools"].ONFH_2and3 table.
Frontier defines two standard macros for dealing with cascading style sheets: embedStyleSheet embeds the style sheet directly into a page. linkStyleSheet writes the style sheet out to disk, and returns a style sheet link tag for inclusion in the page. One of these is typically invoked from the #pageHeader or template.
embedStyleSheet embeds the style sheet directly into a page.
linkStyleSheet writes the style sheet out to disk, and returns a style sheet link tag for inclusion in the page.
One of these is typically invoked from the #pageHeader or template.
Without this script or some other method of serving CSS files, mainResponder sites cannot use the linkStyleSheet macro. Instead, they must use embedStyleSheet to embed the style sheet in each page, which can significantly increase the size of each page.
The following Mode 3 script returns a requested cascading style sheet. Installing this script in your mainResponder website allows you to use the linkStyleSheet macro in your #pageheader, and serve out the correct .css files on request.
In this script, we provide a small callback function. It calls html.utilities.renderStyleSheet, which is the workhorse script that does the heavy lifting for embedStyleSheets and linkStyleSheets.
Create the ONFH_ReturnCSS script in the ["#tools"].ONFH_2and3 table:
|
|---|
Create a default style sheet entry in your website, as described in this Userland CSS article.
Open your #pageHeader and change the embedStyleSheet call to linkStyleSheet. Or just add the linkStyleSheet call, if neither is there.
You can create additional stylesheets, as described in the Userland CSS article. To use a stylesheet other than the default, simply pass the stylesheet name in your linkStyleSheet call.
|
|---|
This Mode 3 script returns a requested JavaScript source "file". Installing this script in your mainResponder website allows you to use the <SCRIPT TYPE='text/javascript' SRC='filename.js'></SCRIPT> syntax, and serve out the specified JavaScript source "file" from a #javascript table in your website on request.
Create the ONFH_ReturnJS script in the ["#tools"].ONFH_2and3 table:
|
|---|
Create a subdirectory named "#javascripts" in your website table.
Inside the #javascripts directory, create (or paste) the JavaScript source text that you would like to include in your page.
Add the <script language='JavaScript' type='text/javascript' src='sourcefile.js'></script> tags to your page, #pageheader, or #template.
The ONFH_Mode3Return script is embedded in this page. It looks like this:
|
|---|
This script should look familiar--it's very similar to the ReturnBinaryObject script in the Mode 3 example. The main differences are:
Unlike the ReturnBinaryObject script, it does not check that the entry it finds is of the type that the extension would indicate.
It ignores the nesting depth (from the remainingPath), so that the appropriate table from any level of the website will be recognized. This means that you can, for example, use it to serve stylesheets from the top level of your site for a deeply nested page without specifying the full path or full relative path.
It does the following:
Check whether the site has the specified subtable at all. If not, there's nothing for us to do, so we return to the caller without doing any further processing.
Get the last resolved address and the remainder of the path from the page table. (Though in this case we won't use the last resolved address at all; everything we need is in the page table.)
Check to make sure that the URL is, in fact, the type of URL we want. We do this by checking that the remainingPath ends with the specified suffix.
Extract the download entry name. Strip off the suffix and discard it.
Check for a matching entry in the specified subtable. If such an entry is not found, return to the caller without doing any further processing.
If the address of a callback function is passed in, call the callback function to get the response body. Otherwise, simply coerce the target entry to a string.
Set the content-type and last-modified fields of the reply. For entries for which the modification date is not available, the last-modified field is set to the current time.
Throw a scriptError("!return") to bypass further mainResponder processing and return our response without further modification.