QuickReference

OpenForum JavaScript API Reference


πŸ“¦ Dependency Management

FunctionParametersReturnsExampleDescription
OpenForum.includeScriptscriptName: stringvoidOpenForum.includeScript("/MyLib.js");Mark a script as required
OpenForum.addScripturl: stringfluent APIOpenForum.addScript("a.js").addScript("b.js").then(()=>console.log("ready"));Queue multiple scripts then run code
OpenForum.loadScripturl: stringvoidOpenForum.loadScript("/scripts/x.js");Dynamically insert <script>
OpenForum.loadCSSurl: stringvoidOpenForum.loadCSS("/style.css");Dynamically insert <link>

βš™οΈ DependencyService

FunctionParametersReturnsDescription
DependencyService.createNewDependencyβ€”Dependency objectCreate a new dependency set. Each set manages required scripts and triggers a callback once they’re loaded.
dependency.addDependencyscript: stringself (chainable)Add a script URL/name to the dependency list. If already loaded, ignored.
dependency.setOnLoadTriggerfn: functionself (chainable)Set function to run once all required scripts are loaded.
dependency.loadDependenciesβ€”voidStart loading all required scripts (inserts `<script>` tags).
dependency.checkLoadedβ€”booleanCheck if all required scripts have finished loading.
dependency.setLoadedβ€”voidMark dependency as loaded and trigger callback.
dependency.getScriptsToLoadβ€”array of stringsList of scripts pending load.
DependencyService.dependencyLoadedid: numbervoidCalled internally when a set of scripts has loaded; marks them as available.
Example: var dep = DependencyService.createNewDependency(); dep.addDependency("/scripts/mylib.js") .addDependency("/scripts/otherlib.js") .setOnLoadTrigger(function() { console.log("All dependencies are loaded."); }) .loadDependencies();

πŸ–ΌοΈ Page & DOM Scanning

FunctionParametersReturnsExampleDescription
OpenForum.scanfirstTime: boolvoidOpenForum.scan(true);Scan DOM and refresh bindings
OpenForum.preparePagenodevoidOpenForum.preparePage(document.body);Process ofa-* attributes
OpenForum.crawlnodevoidβ€”Walk DOM to wire bindings
OpenForum.addNodeProcessorfn(node)voidβ€”Add custom DOM processor
OpenForum.addScannerfn()voidβ€”Add function to run each scan
OpenForum.addInitialiserfn()voidβ€”Runs after dependencies

πŸ“Š Data Binding

FunctionParametersReturnsExampleDescription
OpenForum.getObjectid: stringOpenForumObjectOpenForum.getObject("username").setValue("Bob");Get or create a bound object
OpenForum.persistObjectid: stringvoidβ€”Mark object state to persist
OpenForum.storePersistentStatekey?voidβ€”Save persisted object values
OpenForum.restorePersistentStatekey?voidβ€”Restore persisted values
OpenForum.addListenerid, fnvoidβ€”React to object changes
OpenForum.binda, bvoid—Bind two objects or object→fn

πŸ—‚οΈ File & Storage APIs

FunctionParametersReturnsDescription
OpenForum.loadFileurl, cb?, noCache?string or voidLoad text file
OpenForum.loadJSONurl, cb?objectLoad JSON file
OpenForum.saveFilefile, data, cb?objectSave raw file
OpenForum.saveJSONfile, obj, cb?objectSave as JSON
OpenForum.appendFilefile, data, cb?objectAppend data
OpenForum.deleteFilepage, file, cb?boolDelete file
OpenForum.copyFilesrc, dest, cb?objectCopy file
OpenForum.moveFilesrc, dest, cb?objectMove file
OpenForum.fileExistsfilestringCheck existence
OpenForum.getAttachmentspage, cb?arrayList attachments
OpenForum.getSubPagespage, cb?arrayList subpages
OpenForum.Storage.get/set/findkeystring/arrayLocal storage wrappers
OpenForum.Browser.enableBrowserStorageβ€”voidUse browser:// for offline

πŸ”— AJAX & JSON

FunctionParametersReturnsExampleDescription
JSON.getpage, action, paramschainableJSON.get("/api","getUser","id=1").onSuccess(console.log).go();AJAX GET wrapper
JSON.postpage, action, paramschainableJSON.post("/api","save","x=1").go();AJAX POST wrapper
JSON.findPathjson, "a.b.c"anyβ€”Navigate nested JSON
JSON.createPathjson, "a.b.c"objectβ€”Ensure nested path
OFX.get / OFX.posturlchainableOFX.post("/save").withData({x:1}).go(true);Offline-aware JSON with cache

πŸ“‹ Table Helpers

FunctionParametersReturnsDescription
OpenForum.Table.addRowtable, template?, clean?voidAdd row
OpenForum.Table.removeRowtable, indexrowRemove row
OpenForum.Table.moveRowUp/Downtable, indexvoidReorder rows
OpenForum.Table.applyRowFiltertableId, data, field, filtervoidShow/hide rows
OpenForum.Table.sortdata, field, ascendingvoidSort rows
OpenForum.jsonToCsvjson, delimiter?stringExport JSON as CSV

οΏ½οΏ½ UI & Input

FunctionParametersReturnsDescription
OpenForum.setElementid, htmlvoidReplace element HTML
OpenForum.appendToElementid, htmlvoidAppend child
OpenForum.showElement / hideElement / toggleElementidvoidControl visibility
OpenForum.setTitletitlevoidSet document title
OpenForum.setCursorcursorvoidChange cursor
OpenForum.setTabIconiconvoidChange favicon
OpenForum.addEndlessScrollgetFn, elementId, targetId?voidAuto-load on scroll
OpenForum.Input.getTextgetText(id)stringGet text field value
OpenForum.Input.wrapSelectedTextid, start, endvoidWrap selected text
OpenForum.Input.toDateFielddatestringFormat date for <input type=date>
OpenForum.Input.fromDateFieldvalueDateParse yyyy-mm-dd

⏱️ Async Utilities

FunctionParametersReturnsDescription
OpenForum.setIntervalfn, ms, immediate?, blocking?timerIdSmarter interval
OpenForum.waitFortestFn, callback, pause?, timeout?voidPoll until ready
OpenForum.runAsyncfnvoidRun async
OpenForum.queuefn, supplyState?voidQueue tasks sequentially

πŸ‘₯ Collaboration (IntraQ)

FunctionParametersReturnsDescription
new OpenForum.IntraQqueueName, types?IntraQInter-tab message bus
IntraQ.addListenerfnβ€”Receive messages
IntraQ.senddataβ€”Broadcast message
OpenForum.InQβ€”InQDefault shared queue
inq.addMessageListenerfn,typeβ€”Listen by type
inq.runscriptβ€”Broadcast eval
inq.shareobjectIdβ€”Sync object across tabs

πŸ”§ Debugging & Testing


πŸ”‘ Miscellaneous

πŸ“¦ OpenForumObject

Represents a data-bound value in OpenForum. Objects can be attached to DOM elements, listened to, and synced with global JS variables.
FunctionParametersReturnsDescription
new OpenForumObject(id)id: stringOpenForumObjectCreate a new bound object with a unique identifier. Usually created via OpenForum.getObject().
getIdβ€”stringReturn the object ID.
add(target)HTMLElementselfAttach a DOM node (input, span, etc.) so the object’s value syncs with it.
resetβ€”voidReset internal value to null.
setValue(newValue, exclude?, clone?)any, HTMLElement?, bool?voidSet the object’s value and propagate to all targets.
setValueQuietly(newValue)anyvoidSet value without notifying listeners.
getValueβ€”anyGet the current value.
scanβ€”voidCheck all targets and globals for changes; update value if needed.
addListener(listener)fn(OpenForumObject)voidAdd a listener function that fires on value change.
removeListener(listener)fn(OpenForumObject)voidRemove a previously added listener.
getTargetsβ€”arrayReturn DOM nodes bound to this object.
Example: var user = OpenForum.getObject("username"); user.setValue("Alice"); user.addListener(function(obj) { console.log("New value:", obj.getValue()); });

πŸ“‹ OpenForumTable

Provides dynamic binding between JavaScript arrays and HTML tables using the `of-repeatFor` attribute.
FunctionParametersReturnsDescription
new OpenForumTable(node)node: HTMLElementOpenForumTableCreate a bound table for a given template row. Usually constructed internally by OpenForum.crawlTables().
setTableNodetableNode: HTMLElementvoidReplace the table node (used when re-rendering).
resetβ€”voidClear cached signatures so table will refresh next scan.
updateQuietlyβ€”voidUpdate object signature without redrawing (used after silent changes).
refreshβ€”voidRe-render the table if the underlying array has changed.
getIdβ€”stringReturn the table’s ID.
Example: <table of-id="usersTable"> <tr of-repeatFor="user in users"> <td>{{user.name}}</td> <td>{{user.email}}</td> </tr> </table> <script> OpenForum.getObject("users").setValue([ {name:"Alice", email:"a@test.com"}, {name:"Bob", email:"b@test.com"} ]); </script>

🌳 Tree / TreeNode / Action

A dynamic tree widget for representing hierarchical data (such as file systems). Each `Tree` has a root `TreeNode`, and nodes can contain children, actions, and attributes.
FunctionParametersReturnsDescription
new Tree(elementId, name, attributes?, modifierFn?)elementId: string, name: string, attributes?: object, modifierFn?: fnTreeCreate a new tree bound to a DOM element.
tree.renderβ€”TreeRender the tree into the target element.
tree.addChild(name, attributes)string, objectTreeNodeAdd a child node under root.
tree.addJSON(node)objectTreeNodeAdd a child from a JSON object.
tree.setJSON(node)objectTreeNodeReplace root with JSON object.
tree.toJSONβ€”objectSerialize the tree to JSON.
tree.expandAll / collapseAllβ€”TreeExpand or collapse all nodes.
tree.deleteChild(node)TreeNodeTreeRemove a child node.
tree.expandPath(path)string ("/a/b/c")booleanExpand nodes along a given path.
tree.findNode(path)string ("/a/b/c")array of TreeNodes or nullReturn path of nodes if found.
tree.getRootβ€”TreeNodeGet root node.

🌲 TreeNode

FunctionParametersReturnsDescription
getIdβ€”stringReturn unique node ID.
setLazyLoad(fn)fn(TreeNode)TreeNodeSet a lazy-load function called when expanded.
getParent / setParentTreeNodevoidGet or set parent node.
addChild(name, attributes)string, objectTreeNodeAdd a child node.
addJSON(node)objectTreeNodeAdd children from JSON.
importJSON(url, action, params)string, string, stringvoidLoad JSON via AJAX and add children.
toJSONβ€”objectSerialize node and children to JSON.
deleteChild(node)TreeNodeTreeNodeRemove a child node.
isExpandedβ€”boolCheck if node is expanded.
expand / collapse / toggleβ€”TreeNodeExpand/collapse/toggle node.
render(depth?)numberstring (HTML)Render node to HTML string.
getName / setNamestringstring/voidGet or set node name.
getAttribute / setAttributestring, anyany/voidAccess or modify node attributes.
getChildrenβ€”arrayList child nodes.
applyToChildren(fn)fn(TreeNode)voidApply function to each child.

⚑ Action

Actions add clickable icons (buttons) to tree nodes.
FunctionParametersReturnsDescription
new Action(config)config: {fn, icon, toolTip}ActionCreate an action from a function, icon, and tooltip.
action.call(node)TreeNodevoidRun the action on a node.
action.render(target)stringHTML stringRender the action icon as clickable HTML.

Example: <div id="fileTree"></div> <script> var tree = new Tree("fileTree","Root",{icon:"book"}); var docs = tree.addChild("Documents",{icon:"page"}); docs.addChild("Resume.docx",{icon:"attach"}); tree.render(); tree.getRoot().expand(); </script>

πŸ”— Ajax / AjaxRequest / Post

These APIs provide low-level AJAX utilities in OpenForum. They are usually used internally by higher-level helpers (`JSON.get/post`, `OFX`, `OpenForum.loadFile`), but can be used directly when fine-grained control is needed.

βš™οΈ AjaxRequest

Represents a single HTTP request.
FunctionParametersReturnsDescription
new AjaxRequest(method, url, request, data, onSuccess, onError, async)method: "GET"/"POST", url: string, request: string, data: string, onSuccess: fn, onError: fn, async: boolAjaxRequestCreate a new request object.
processTransactionStateChange(ev)EventvoidCalled when readyState changes; triggers success/error callbacks.

🌐 Ajax

A static helper to send `AjaxRequest` objects.
FunctionParametersReturnsDescription
Ajax.sendRequest(request)request: AjaxRequeststring (response if sync)Send the request. If `asynchronous = true`, callbacks are invoked; if false, responseText is returned directly.

πŸ“¨ Post

Helper for building `application/x-www-form-urlencoded` payloads.
FunctionParametersReturnsDescription
new Post()β€”PostCreate a new post builder.
addItem(name, value)string, stringselfAdd a key/value pair.
addForm(formId)formId: stringselfAdd all fields from a form.
getDataβ€”stringReturn built parameter string (e.g., `"key=value&key2=value2"`).

Example: var post = new Post() .addItem("username","alice") .addItem("password","secret"); var req = new AjaxRequest( "POST", "/OpenForum/Login", "", post.getData(), function(response) { console.log("Logged in:", response); }, function(err) { console.error("Error:", err); }, true ); Ajax.sendRequest(req);

🌐 OpenForum.Browser

Provides browser-side file handling and keyboard overrides. Includes download, upload, and an optional in-browser file system (browserFS).
FunctionParametersReturnsDescription
OpenForum.Browser.downloadfileName: string, data: stringvoidTrigger a client-side download of text data as a file.
OpenForum.Browser.uploadcallback: fn(data), onError?: fn(msg)voidOpen a hidden file input, read file as text, and pass contents to callback.
OpenForum.Browser.uploadDataUrlcallback: fn(dataUrl), onError?: fn(msg)voidOpen a hidden file input, read file as DataURL (e.g., base64-encoded).
OpenForum.Browser.overrideSavefn: functionvoidOverride `Ctrl+S` / `Cmd+S` in the browser to run a custom save function.
OpenForum.Browser.isBrowserStorageEnabledβ€”boolCheck if the browserFS system is enabled.
OpenForum.Browser.enableBrowserStorageβ€”voidEnable browserFS. Redirects `saveFile`, `deleteFile`, `loadFile`, etc. to use `localStorage` with `browser://` paths.

Example: client-side file download OpenForum.Browser.download("example.txt","Hello, OpenForum!"); Example: client-side file upload OpenForum.Browser.upload(function(data) { console.log("File contents:", data); }); Example: browserFS usage OpenForum.Browser.enableBrowserStorage(); // Save to browserFS OpenForum.saveFile("browser://MyPage/test.txt","Hello World"); // Load from browserFS var data = OpenForum.loadFile("browser://MyPage/test.txt"); console.log(data);