|
|
 |
 |
The JavaScript Suite
Created by Samuel Reynolds.
Copyright © 1998 by Samuel Reynolds. All rights reserved.
See The Need
The Frontier html framework provides the ability to include static JavaScript text into a page when you render it. However, it does not provide any tools to simplify the creation of the JavaScript in the first place. I'm a software developer, and I prefer to be able to assemble a complex script from simpler, well-tested pieces.
So I wrote this JavaScript suite to provide me with the tools I wanted. And I'm publishing it in the hopes that others will find it equally useful.
Fill The Need
The JavaScript suite provides tools for editing JavaScript in the Frontier environment. You can edit JavaScripts as outlines, tables, or wpText, and render them to wpText in the ODB, to files, or directly into your web pages.
Support for macros embedded in your JavaScript allows you to include page-relative information (such as image tags). It also allows you to invoke Frontier scripts to generate JavaScript code, or to include just about anything you want as data in your JavaScript programs.
An Include mechanism is implemented as an embedded macro. This allows you to assemble complex scripts from a library of smaller scripts or script fragments.
And finally, you can extend the JavaScript with your own entity types, and incorporate creation of your new entity types directly into the JavaScript menu.
Dependencies
The JavaScript suite requires the regex extension, available from Script Meridian (http://www.scriptmeridian.org/projects/regex).
It also requires my ThreadedData Suite, available from the same place you got the JavaScript suite.
Documentation
Documentation is available via the JavaScript->Documentation submenu.
- 1.0b17 - 23 May 1999
- Updated for rendering JavaScript within website in GDB: In utils.LocateEntry, strip off leading ["..."]. section, if any.
- Fixed bug in JSInclude macro: Was looking in parent of script for helper scripts; now looks in javascript suite.
- Fixed bug in Predefined.Replace.
- Removed calls to DEBUG from Predefined scripts.
- Class and Module renderers now recognize #copyright in the Class or Module table.
- Inserted as comment at start of rendered text for Class or Module.
- May be string, wptext, or outline.
- 1.0b16 - 18 Feb 1999
- In utils.LocateEntry, if item is found in page table, try to resolve original address of item.
- This allows jssource macro to properly generate relative addresses, so duplicate files aren't created.
- jssource macro improved:
- Now calls html.write instead of wp.writeWholeFile -- allows render-to-remote-site (FTP).
- Avoids creation of duplicate files as much as possible.
- Generates file if...
- File does not exist
- File is older than source entity
- Does not generate file if file exists and is newer than source entity.
- New JSInclude macro for doing "client-side includes".
- Avoids creation of duplicate files as much as possible.
- 1.0b15 - 4 Feb 1999
- Always get opening and closing script tags from utils.ScriptStartTag and utils.ScriptEndTag.
- Fixed problem with rendering class, array, and module entities with dependencies from #js subtable of website.
- Called-from addresses of the form website.["#js"].thescript became "website.["#js"].thescript".
- Fix: When generating [[Include(...)]] macros for dependencies, escape quotes in addresses.
- Now addresses of the form website.["#js"].thescript become "website.[\"#js"].thescript".
- Affects: class, array, and module table renderers.
- Added js_allowInheritance preference. Used by class renderer only.
- Reason: Some browsers (esp. Netscape 4.04/Mac) make prototype read-only.
- If TRUE, behavior is as before:
- Class constructor is empty except for assignment of non-null parameters.
- Class prototype is assigned new object of class or of inherited class.
- Default values and methods are assigned to class prototype.
- If FALSE:
- Inheritance is not allowed (presence of #inherits field results in scriptError).
- Prototype is not manipulated directly.
- Default values are assigned to the object IFF the prototype is null (indicating that it is just being created).
- Code is a little smaller.
- 1.0b14 - 17 Jan 1999
- Fixed bug in Init script.
- Was still installing user.javascript.table table. New name is user.javascript.tableRenderers.
- Now tries to...
- Rename user.javascript.table (if found) to user.javascript.tableRenderers.
- Move items from user.javascript.table (if found) to user.javascript.tableRenderers.
- If this fails--if, for example, both tables have an item with the same name--Init puts up notice that user must fix manually.
- 1.0b13 - 12 Jan 1999
- Fixed 2 bugs in utils.LocateEntry.
- Was not finding entities in #js table in a website or directly in a website (as a directive).
- Should now properly find JavaScript entities both these locations.
- 1.0b12 - 7 Jan 1999
- Added two new prefs:
- js_language
- LANGUAGE attribute of SCRIPT tag. May not be very useful, since it's global, but here it is.
- js_type
- TYPE attribute of SCRIPT tag, per HTML 4.0 draft spec.
- Added in response to a suggestion from Deke Smith.
- Make sure you re-install (just select JavaScript->Setup->Initialize) to install the new preferences.
- Open user.javascript.prefs to change them.
- 1.0b11 - 6 Jan 1999
- Changed log name in CheckDependencies so it has no spaces in it. (The log routines don't properly handle names with spaces.)
- This only shows up if the routine actually writes to the log--i.e., when a dependency error is detected.
- 1.0b10 - 3 Jan 1999
- Compatibility scripts
- Added javascript.compat compatibility scripts.
- Removed references to xfile.compat.
- There should now be no dependency on xfile.
- Modified default outline (script) renderer
- Rewrote default outline (script) renderer to speed it up.
- No longer walks outline (slow!)
- Copies outline contents to temp script object, then converts to text. Frontier does most of the work.
- Munges with regex after conversion to string.
- Speed improvement is greatest for large script (outline) entities, but not much for small ones.
- However, you can turn off some or all of the "prettifying":
- Set js_prettify=FALSE to turn off all unnecessary munging (default is TRUE).
- With js_prettify=TRUE, set js_prettifyComment=FALSE to turn off comment marker (//) alignment (default is TRUE).
- Now handles indented comments.
- Cleaned up occasional double-semicolons.
- Modified default module renderer.
- Now tells renderer to expand macros immediately.
- This is required so that any entity that a given entity depends on will be inserted before the dependent entity.
- Modified default class renderer
- Allow inititializing parameters in attributes that are class instances.
- Now attributes that are strings can be:
- 1. Simple string (becomes default value of attribute).
- Thus, the value could be "new Array(1,2,3,4,5)". However, see (3), below.
- 2. "class " + class_name -- attribute default value becomes "new ()"
- 3. "class " + class_name + "(" + + ")" -- attribute default value becomes "new " + everything after "class "
- Changes for improved class/object support
- When a string beginning with "class" is found in an attribute value, add the class name as another dependency.
- Add these detected dependencies after the explicit dependencies when inserting includes.
- Moved default values for class instance variables and methods from constructor to prototype, to properly support objects, classes, and inheritance.
- Should work for NN3+ and IE4+ browsers.
- Allow method entry to be either an outline or a string
- If an outline (as before), assume it is a JavaScript script entity, and render it accordingly.
- If a string, assume it is the name of a JavaScript script (the JavaScript name, not the ODB name).
- Script is assumed to be rendered separately.
- Implemented rendered-item cache to speed up rendering.
- Only atomic entities are cached.
- No table entities, because a change in a nested entry doesn't change the mod date of a table.
- First render (when item is entered in the cache) is about the same speed.
- Provides about 15-20% speedup for small script (outline) entities on subsequent renderings.
- Provides up to 60% speedup for large script (outline) entities on subsequent renderings.
- Speedup is highly variable. I'm not sure why, but I think it has to do with Frontier's processes and memory management.
- Speedup will be less for table entities.
- Rendered entities are stored as strings in subtables in user.javascriptl["#cache"].
- TimeModified() doesn't work with string entries, so each one is stored in its own subtable to get the time stamp.
- This is faster than converting from wptext every time we get the cached entity.
- Turn caching off by setting js_cacheRenderedText=FALSE (default is TRUE if undefined; default setting is FALSE).
- 1.0b9 - 4 Oct 1998
- Make sure you reinstall the html macros.
- Select JavaScript->Setup->Remove to remove the old ones.
- Select JavaScript->Setup->Initialize to install the new ones.
- Tracked down and fixed "Unable to render because file not found" bug when rendering directly into web page.
- Cause: ExpandInlineMacro() first checks to see if the macro exists as stated.
- This resulted in html.data.standardMacros.include() being called instead of javascript.utils.Include().
- html.data.standardMacros.include() treated specifier as file name, and tried to load it.
- Fix: Added special-case code to not accept the macro name as given if it is equal to "include" (case insensitive).
- Tracked down and fixed 'Can't find object ""' bug.
- Cause: LocateEntry() was checking existence of jsInfoTbl^.invokedFrom instead of jsInfoTbl^.invokedFrom^.
- Then it was attempting to create a new address entryAdr = @jsInfoTbl^.invokedFrom.[inEntryName].
- jsInfoTbl^.invokedFrom is an address, or is nil or empty string if undefined.
- Fix: Change jsInfoTbl^.invokedFrom to jsInfoTbl^.invokedFrom^ in both places.
- Fixed Render
- Fixed invokedFrom/invokedFrom^ bug as above.
- Delete threaded temp table when done so include logic works correctly.
- Otherwise, rendering directly into web page intermittently loses includes after first render.
- This happened because the threaded temp table is keyed by thread ID, but thread IDs are reused.
- In particular, the Publish Page command runs with the same thread ID (the main thread?) every time it's invoked from the menu.
- Tracked down and fixed 'Can't find a sub-table named "javascript"' bug.
- Cause: LocateEntry() was dereferencing pageTbl^.javascript without checking whether it exists.
- Fix: Check defined( pageTbl^.javascript ) before using it.
- Changed expected site javascript table name from "#javascript" to "#js".
- This eliminates a problem with Frontier's handling of a directive named "#javascript".
- Changed remaining LocateScript calls to LocateEntry (mainly in html macros).
- Deleted LocateScript.
- 1.0b8 - 27 Sep 1998
- Changed JavaScript->Documentation->Macro->JavaScript name to jsrender, linked it to right address.
- Added jssource macro.
- Renders and writes out JavaScript (.js) file in same directory as current page.
- Returns SCRIPT tag pair with SRC= attribute, instead of rendered JavaScript.
- Basic script; works, but not very efficient. Could do much more.
- Added menu update command
- Invoke after adding or removing a custom template.
- Rebuilds JavaScript->New submenu to contain all available templates.
- Not needed for templates that override default templates.
- Finished up documentation of advanced features.
- 1.0b7 - 21 Sep 1998
- Added JavaScript->New->Module command to support new Module entity type.
- Includes: new template (javascript.data.templates.module), menu item, doc page, & doc menu item.
- I love it when a design works right!
- It took me about 3 minutes to add the new command, including doc page!
- 1.0b6 - 20 Sep 1998
- Fixed bug in dependency checking.
- Added Module entity support (an entity that groups other entities).
- Changed javascript() macro to jsrender() macro.
- Was getting collision with and user.javascript when rendering page.
- Removed op.setDisplay calls from outline (script) renderer.
- Getting error when rendering from web page that includes jsrender() macro.
- 1.0b5 - 19 Sep 1998
- Documented dependencies.
- Added dependency checking on install.
- Fixed typo (from dialog to dialog.notify) in menuCmd.ExtractFromText.
- 1.0b4 - 16 Sep 1998
- First public release.
- New Script: Cannot override the script template, due to bug in op.newOutlineObject.
- All other operations work as described in the documentation.
|