OpenForum JavaScript API Reference
π¦ Dependency Management
Function | Parameters | Returns | Example | Description | |
OpenForum.includeScript | scriptName: string | void | OpenForum.includeScript("/MyLib.js"); | Mark a script as required | |
OpenForum.addScript | url: string | fluent API | OpenForum.addScript("a.js").addScript("b.js").then(()=>console.log("ready")); | Queue multiple scripts then run code | |
OpenForum.loadScript | url: string | void | OpenForum.loadScript("/scripts/x.js"); | Dynamically insert <script> | |
OpenForum.loadCSS | url: string | void | OpenForum.loadCSS("/style.css"); | Dynamically insert <link> | |
βοΈ DependencyService
Function | Parameters | Returns | Description | |
DependencyService.createNewDependency | β | Dependency object | Create a new dependency set. Each set manages required scripts and triggers a callback once theyβre loaded. | |
dependency.addDependency | script: string | self (chainable) | Add a script URL/name to the dependency list. If already loaded, ignored. | |
dependency.setOnLoadTrigger | fn: function | self (chainable) | Set function to run once all required scripts are loaded. | |
dependency.loadDependencies | β | void | Start loading all required scripts (inserts `<script>` tags). | |
dependency.checkLoaded | β | boolean | Check if all required scripts have finished loading. | |
dependency.setLoaded | β | void | Mark dependency as loaded and trigger callback. | |
dependency.getScriptsToLoad | β | array of strings | List of scripts pending load. | |
DependencyService.dependencyLoaded | id: number | void | Called 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
Function | Parameters | Returns | Example | Description | |
OpenForum.scan | firstTime: bool | void | OpenForum.scan(true); | Scan DOM and refresh bindings | |
OpenForum.preparePage | node | void | OpenForum.preparePage(document.body); | Process ofa-* attributes | |
OpenForum.crawl | node | void | β | Walk DOM to wire bindings | |
OpenForum.addNodeProcessor | fn(node) | void | β | Add custom DOM processor | |
OpenForum.addScanner | fn() | void | β | Add function to run each scan | |
OpenForum.addInitialiser | fn() | void | β | Runs after dependencies | |
π Data Binding
Function | Parameters | Returns | Example | Description | |
OpenForum.getObject | id: string | OpenForumObject | OpenForum.getObject("username").setValue("Bob"); | Get or create a bound object | |
OpenForum.persistObject | id: string | void | β | Mark object state to persist | |
OpenForum.storePersistentState | key? | void | β | Save persisted object values | |
OpenForum.restorePersistentState | key? | void | β | Restore persisted values | |
OpenForum.addListener | id, fn | void | β | React to object changes | |
OpenForum.bind | a, b | void | β | Bind two objects or objectβfn | |
ποΈ File & Storage APIs
Function | Parameters | Returns | Description | |
OpenForum.loadFile | url, cb?, noCache? | string or void | Load text file | |
OpenForum.loadJSON | url, cb? | object | Load JSON file | |
OpenForum.saveFile | file, data, cb? | object | Save raw file | |
OpenForum.saveJSON | file, obj, cb? | object | Save as JSON | |
OpenForum.appendFile | file, data, cb? | object | Append data | |
OpenForum.deleteFile | page, file, cb? | bool | Delete file | |
OpenForum.copyFile | src, dest, cb? | object | Copy file | |
OpenForum.moveFile | src, dest, cb? | object | Move file | |
OpenForum.fileExists | file | string | Check existence | |
OpenForum.getAttachments | page, cb? | array | List attachments | |
OpenForum.getSubPages | page, cb? | array | List subpages | |
OpenForum.Storage.get/set/find | key | string/array | Local storage wrappers | |
OpenForum.Browser.enableBrowserStorage | β | void | Use browser:// for offline | |
π AJAX & JSON
Function | Parameters | Returns | Example | Description | |
JSON.get | page, action, params | chainable | JSON.get("/api","getUser","id=1").onSuccess(console.log).go(); | AJAX GET wrapper | |
JSON.post | page, action, params | chainable | JSON.post("/api","save","x=1").go(); | AJAX POST wrapper | |
JSON.findPath | json, "a.b.c" | any | β | Navigate nested JSON | |
JSON.createPath | json, "a.b.c" | object | β | Ensure nested path | |
OFX.get / OFX.post | url | chainable | OFX.post("/save").withData({x:1}).go(true); | Offline-aware JSON with cache | |
π Table Helpers
Function | Parameters | Returns | Description | |
OpenForum.Table.addRow | table, template?, clean? | void | Add row | |
OpenForum.Table.removeRow | table, index | row | Remove row | |
OpenForum.Table.moveRowUp/Down | table, index | void | Reorder rows | |
OpenForum.Table.applyRowFilter | tableId, data, field, filter | void | Show/hide rows | |
OpenForum.Table.sort | data, field, ascending | void | Sort rows | |
OpenForum.jsonToCsv | json, delimiter? | string | Export JSON as CSV | |
οΏ½οΏ½ UI & Input
Function | Parameters | Returns | Description | |
OpenForum.setElement | id, html | void | Replace element HTML | |
OpenForum.appendToElement | id, html | void | Append child | |
OpenForum.showElement / hideElement / toggleElement | id | void | Control visibility | |
OpenForum.setTitle | title | void | Set document title | |
OpenForum.setCursor | cursor | void | Change cursor | |
OpenForum.setTabIcon | icon | void | Change favicon | |
OpenForum.addEndlessScroll | getFn, elementId, targetId? | void | Auto-load on scroll | |
OpenForum.Input.getText | getText(id) | string | Get text field value | |
OpenForum.Input.wrapSelectedText | id, start, end | void | Wrap selected text | |
OpenForum.Input.toDateField | date | string | Format date for <input type=date> | |
OpenForum.Input.fromDateField | value | Date | Parse yyyy-mm-dd | |
β±οΈ Async Utilities
Function | Parameters | Returns | Description | |
OpenForum.setInterval | fn, ms, immediate?, blocking? | timerId | Smarter interval | |
OpenForum.waitFor | testFn, callback, pause?, timeout? | void | Poll until ready | |
OpenForum.runAsync | fn | void | Run async | |
OpenForum.queue | fn, supplyState? | void | Queue tasks sequentially | |
π₯ Collaboration (IntraQ)
Function | Parameters | Returns | Description | |
new OpenForum.IntraQ | queueName, types? | IntraQ | Inter-tab message bus | |
IntraQ.addListener | fn | β | Receive messages | |
IntraQ.send | data | β | Broadcast message | |
OpenForum.InQ | β | InQ | Default shared queue | |
inq.addMessageListener | fn,type | β | Listen by type | |
inq.run | script | β | Broadcast eval | |
inq.share | objectId | β | Sync object across tabs | |
π§ Debugging & Testing
- OpenForum.setDebugToConsole(true) β enable logging
- OpenForum.testing.showComments() β overlay comments
- OpenForum.testing.showIds() β overlay IDs
- OpenForum.testing.showNames() β overlay names
- OpenForum.testing.readForm() / writeToForm(data) β form helpers
π Miscellaneous
- OpenForum.getSystemTime(cb?) β get server system time
- OpenForum.getUserReference() β persistent user ID
- OpenForum.loadGoogleFont(family, weight?) β add Google font
π¦ OpenForumObject
Represents a data-bound value in OpenForum. Objects can be attached to DOM elements, listened to, and synced with global JS variables.
Function | Parameters | Returns | Description | |
new OpenForumObject(id) | id: string | OpenForumObject | Create a new bound object with a unique identifier. Usually created via OpenForum.getObject(). | |
getId | β | string | Return the object ID. | |
add(target) | HTMLElement | self | Attach a DOM node (input, span, etc.) so the objectβs value syncs with it. | |
reset | β | void | Reset internal value to null. | |
setValue(newValue, exclude?, clone?) | any, HTMLElement?, bool? | void | Set the objectβs value and propagate to all targets. | |
setValueQuietly(newValue) | any | void | Set value without notifying listeners. | |
getValue | β | any | Get the current value. | |
scan | β | void | Check all targets and globals for changes; update value if needed. | |
addListener(listener) | fn(OpenForumObject) | void | Add a listener function that fires on value change. | |
removeListener(listener) | fn(OpenForumObject) | void | Remove a previously added listener. | |
getTargets | β | array | Return 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.
Function | Parameters | Returns | Description | |
new OpenForumTable(node) | node: HTMLElement | OpenForumTable | Create a bound table for a given template row. Usually constructed internally by OpenForum.crawlTables(). | |
setTableNode | tableNode: HTMLElement | void | Replace the table node (used when re-rendering). | |
reset | β | void | Clear cached signatures so table will refresh next scan. | |
updateQuietly | β | void | Update object signature without redrawing (used after silent changes). | |
refresh | β | void | Re-render the table if the underlying array has changed. | |
getId | β | string | Return the tableβs ID. | |
Example:
{{user.name}} |
{{user.email}} |
π³ 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.
Function | Parameters | Returns | Description | |
new Tree(elementId, name, attributes?, modifierFn?) | elementId: string, name: string, attributes?: object, modifierFn?: fn | Tree | Create a new tree bound to a DOM element. | |
tree.render | β | Tree | Render the tree into the target element. | |
tree.addChild(name, attributes) | string, object | TreeNode | Add a child node under root. | |
tree.addJSON(node) | object | TreeNode | Add a child from a JSON object. | |
tree.setJSON(node) | object | TreeNode | Replace root with JSON object. | |
tree.toJSON | β | object | Serialize the tree to JSON. | |
tree.expandAll / collapseAll | β | Tree | Expand or collapse all nodes. | |
tree.deleteChild(node) | TreeNode | Tree | Remove a child node. | |
tree.expandPath(path) | string ("/a/b/c") | boolean | Expand nodes along a given path. | |
tree.findNode(path) | string ("/a/b/c") | array of TreeNodes or null | Return path of nodes if found. | |
tree.getRoot | β | TreeNode | Get root node. | |
π² TreeNode
Function | Parameters | Returns | Description | |
getId | β | string | Return unique node ID. | |
setLazyLoad(fn) | fn(TreeNode) | TreeNode | Set a lazy-load function called when expanded. | |
getParent / setParent | TreeNode | void | Get or set parent node. | |
addChild(name, attributes) | string, object | TreeNode | Add a child node. | |
addJSON(node) | object | TreeNode | Add children from JSON. | |
importJSON(url, action, params) | string, string, string | void | Load JSON via AJAX and add children. | |
toJSON | β | object | Serialize node and children to JSON. | |
deleteChild(node) | TreeNode | TreeNode | Remove a child node. | |
isExpanded | β | bool | Check if node is expanded. | |
expand / collapse / toggle | β | TreeNode | Expand/collapse/toggle node. | |
render(depth?) | number | string (HTML) | Render node to HTML string. | |
getName / setName | string | string/void | Get or set node name. | |
getAttribute / setAttribute | string, any | any/void | Access or modify node attributes. | |
getChildren | β | array | List child nodes. | |
applyToChildren(fn) | fn(TreeNode) | void | Apply function to each child. | |
β‘ Action
Actions add clickable icons (buttons) to tree nodes.
Function | Parameters | Returns | Description | |
new Action(config) | config: {fn, icon, toolTip} | Action | Create an action from a function, icon, and tooltip. | |
action.call(node) | TreeNode | void | Run the action on a node. | |
action.render(target) | string | HTML string | Render the action icon as clickable HTML. | |
Example:
π 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.
Function | Parameters | Returns | Description | |
new AjaxRequest(method, url, request, data, onSuccess, onError, async) | method: "GET"/"POST", url: string, request: string, data: string, onSuccess: fn, onError: fn, async: bool | AjaxRequest | Create a new request object. | |
processTransactionStateChange(ev) | Event | void | Called when readyState changes; triggers success/error callbacks. | |
π Ajax
A static helper to send `AjaxRequest` objects.
Function | Parameters | Returns | Description | |
Ajax.sendRequest(request) | request: AjaxRequest | string (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.
Function | Parameters | Returns | Description | |
new Post() | β | Post | Create a new post builder. | |
addItem(name, value) | string, string | self | Add a key/value pair. | |
addForm(formId) | formId: string | self | Add all fields from a form. | |
getData | β | string | Return 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).
Function | Parameters | Returns | Description | |
OpenForum.Browser.download | fileName: string, data: string | void | Trigger a client-side download of text data as a file. | |
OpenForum.Browser.upload | callback: fn(data), onError?: fn(msg) | void | Open a hidden file input, read file as text, and pass contents to callback. | |
OpenForum.Browser.uploadDataUrl | callback: fn(dataUrl), onError?: fn(msg) | void | Open a hidden file input, read file as DataURL (e.g., base64-encoded). | |
OpenForum.Browser.overrideSave | fn: function | void | Override `Ctrl+S` / `Cmd+S` in the browser to run a custom save function. | |
OpenForum.Browser.isBrowserStorageEnabled | β | bool | Check if the browserFS system is enabled. | |
OpenForum.Browser.enableBrowserStorage | β | void | Enable 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);