Core
OpenForum Javascript {{version}}
Latest build {{buildDate}}
- Lines of code {{lines}}
- Size {{size}} KB
DependencyService
if(typeof OpenForum == "undefined") OpenForum = {}; var DependencyService = new function() { //All sets of dependencies var dependencies = ; //All scripts that have been loaded var loadedScripts = ; //All scripts that have been requested var requestedScripts = ; var dp = this; dp.createNewDependency = function() { var dependency = new function() { //Id of the dependency set var id = dependencies.length; var self = this; //Scripts that need to be loaded var scriptsToLoad = ; //Scripts that are required var requiredScripts = ; //Function to call when all required scripts are loaded var onLoadTrigger = function() {}; var loaded = false; self.addDependency = function(script) { if( requiredScripts.includes(script) ) return this; requiredScripts.push(script); if( requestedScripts.includes(script) == false ) { requestedScripts.push(script); } return self; }; self.setOnLoadTrigger = function(triggerFunction) { onLoadTrigger = triggerFunction; return self; }; self.loadDependencies = function() { if(requiredScripts.length===0) { DependencyService.dependencyLoaded(id); return; } var openForumDependencies = OpenForum.getDependencies(); var jsServices = {request:""}; //Collate scripts that are required scriptsToLoad = ; for( var i in requiredScripts) { if( loadedScripts.includes(requiredScriptsi) ){ continue; } if(openForumDependenciesi" alt="requiredScriptsi" title="requiredScriptsi"/>]!=null) { console.log( "Excluded " + requiredScriptsi ); //TODO //continue; } else { openForumDependenciesi" alt="requiredScriptsi" title="requiredScriptsi"/>] = jsServices; console.log( "Added " + requiredScriptsi ); } scriptsToLoad.push(requiredScriptsi); } //requiredScripts = ; if(scriptsToLoad.length==0) { DependencyService.dependencyLoaded(id); return; } var fileName = ""; for(var i=0;i
OpenForum
var OpenForum = new function(){ this.FIELD_DELIMETER_START = "{"+"{"; this.FIELD_DELIMETER_END = "}"+"}"; this.pageVersion = "build-" + new Date(document.lastModified).getTime(); var self = this; var objects= ; var tables = ; var tabs = ; var persistentObjectIds = ; var nextId = 0; var hash; var hashCalls = ; var nodeProcessors = ; var scanners = ; var initialisers = ; var dependencies = ; var waitingScripts = null; var watchers = ; var defaultScanPeriod = 500; self.interval = null; self.getVersion = function() { return "1.16.15"; }; self.getBuildDate = function() { return "Tue Feb 13 2024 14:26:31 GMT-0000 (GMT)"; }; self.initDependencies = DependencyService.createNewDependency(); self.includeScript = function( scriptName ) { if(dependenciesscriptName) return; dependenciesscriptName = self.initDependencies.addDependency( scriptName ); }; self.getDependencies = function() { return dependencies; }; //Fluent dependency interface //Example: OpenForum.addScript("my script 1).addScript("my script 2").then( function() { console.log("Loaded"); } ); //Example: OpenForum.addScript("my script 1).addScript("my script 2").go(); self.addScript = function( scriptUrl ) { if(waitingScripts == null) { waitingScripts = new function() { var self = this; var dependencyService = DependencyService.createNewDependency(); self.addScript = function( scriptUrl ) { dependencyService.addDependency( scriptUrl ); return self; }; self.then = function( thenFn ) { dependencyService.setOnLoadTrigger( thenFn); dependencyService.loadDependencies(); waitingScripts = null; }; self.go = function() { dependencyService.loadDependencies(); waitingScripts = null; }; }; } return waitingScripts.addScript( scriptUrl ); }; self.getRoot = function() { var root = document.location.toString(); root = root.substring( root.indexOf("://")+3 ); root = root.substring( root.indexOf("/")+1 ); root = "/"+root.substring( 0,root.indexOf("/") ); return root; }; self.addNodeProcessor = function(processor) { nodeProcessors.push(processor); }; self.addScanner = function(scanner) { scanners.push(scanner); }; self.addInitialiser = function( fn ) { initialisers.push(fn); }; self.addHashCall = function(hash,callFn) { hashCallshash = callFn; }; self.addTable = function(table) { tablestable.getId()=table; }; self.getTable = function(ofId) { return tables; }; self.getNextId = function() { nextId++; return nextId; }; self.getObject= function(id) { //id = id.replace(/
./g,"_dot_"); if(objectsid===undefined) { objectsid = new OpenForumObject(id); } return objectsid; }; self.removeObject = function(id) { if(objectsid!=undefined) { delete objectsid; } }; self.persistObject = function(id) { persistentObjectIds.push(id); }; self.storePersistentState = function( key ) { if( typeof key == "undefined" ) { key = window.location.pathname; } if( persistentObjectIds.length==0 ) return; var json = {}; for( var i in persistentObjectIds) { var object = OpenForum.getObject( persistentObjectIdsi ); if( isUndefined(object) ) continue; try{ //Test can be stringified JSON.stringify( object.getValue() ); json = object.getValue(); } catch(e) {} } OpenForum.Storage.set( key + ".persist", JSON.stringify(json) ); }; self.restorePersistentState = function( key ) { if( typeof key == "undefined" ) { key = window.location.pathname; } var data = OpenForum.Storage.get( key + ".persist" ); if(data!=null) { try{ var json = JSON.parse( data ); for(var j in json) { //OpenForum.getObject(j).setValue( jsonj ); try{ OpenForum.evaluate( j + "=" + JSON.stringify( jsonj ) ); } catch(e) { console.log(e); } } } catch(e) { console.log(e); } } }; self.addListener = function(id,listener) { self.getObject(id).addListener(listener); }; self.removeListener = function(id,listener) { self.getObject(id).removeListener(listener); }; self.scan = function(firstTime) { for(var tableIndex in tables) { tablestableIndex.refresh(); } self.hash = window.location.hash; self._onHash(self.hash); for(var objectIndex in objects) { object = objects; if(typeof(object)=="undefined") { } else { object.scan(); } } for(var scanner in scanners) { try{ scannersscanner(); } catch(e) { console.log(e); } } if(document.body && document.body!=null && firstTime==true) { self.preparePage(document.body); } }; self.addNodeProcessor( function(node) { if(node.attributes==undefined) return; for(var a=0; a
"
";"); object.setValue(""); } else { object.setValue( OpenForum.evaluate(object.getId()) ); } } }; self.createParents = function(id) { if(id.indexOf(".")==-1) { return; } var parts = id.split("."); id = ""; for(var index=0;index
"target="editor" style="color: red" title="The page /OpenForum/Editor?pageName=/g,".").replace(/
does not exist. Click to create it.">/g,".").replace(/
/g,"").replace(/'/g,"").replace(/
(.*
)/g,""); var parts = name.split("."); var obj = window; for(var part in parts) { if( typeof objpart" alt="partspart" title="partspart"/>] === "undefined" ) return false; obj = objpart" alt="partspart" title="partspart"/>]; } return true; }; self.getGlobal = function( name ) { name = name.replace(/
"target="editor" style="color: red" title="The page /OpenForum/Editor?pageName=/g,".").replace(/
does not exist. Click to create it.">/g,".").replace(/
/g,"").replace(/'/g,"").replace(/
(.*
)/g,""); var parts = name.split("."); var obj = window; for(var part in parts) obj = objpart" alt="partspart" title="partspart"/>]; if(typeof obj === "function") return obj(); else return obj; }; self.setGlobal = function( name,value,create ) { name = name.replace(/
"target="editor" style="color: red" title="The page /OpenForum/Editor?pageName=/g,".").replace(/
does not exist. Click to create it.">/g,".").replace(/
/g,"").replace(/'/g,""); var parts = name.split("."); var obj = window; var i=0; for(i=0; i
/g,"/"); fileName = fileName.substring(fileName.lastIndexOf("/")+1); var result = OpenForum.loadFile("/OpenForum/Actions/AttachmentExists?pageName="+pageName+"&fileName="+fileName); if(result==="true" && confirm("Attachment "+fileName+" exists","Replace this attachment ?")===false ) { return; } var formData = new FormData(document.getElementById( id )); var xhr = new XMLHttpRequest(); if(callBack) { xhr.onload = function() { callBack(); }; } if(errorCallBack) { xhr.onerror = function() { errorCallBack(); }; } if(progressCallback) { xhr.onprogress = function(event) { progressCallback( event.loaded, event.total ); }; } xhr.open('POST', "/OpenForum/Actions/Attach?page="+pageName, true); xhr.send(formData); }; //==============================================================================================================// //==============================================================================================================// //==============================================================================================================// //
JSON
if( typeof(JSON)=="undefined" ) { JSON = {}; } JSON.get = function( page,action,parameters ) { var request = {method: 'GET',page: page,action: action,parameters: parameters, onSuccess: JSON.onSuccess, onError: JSON.onError, go: JSON.go}; return request; }; JSON.post = function( page,action,parameters ) { var request = {method: 'POST',page: page,action: action,parameters: parameters, onSuccess: JSON.onSuccess, onError: JSON.onError, go: JSON.go}; return request; }; JSON.onSuccess = function(onSuccess) { this.onSuccess = function(data) { //var object = JSON.parse(data); var object = OpenForum.evaluate("("+data+")"); onSuccess(object); }; return this; }; JSON.onError = function(onError) { this.onError = function(error) { onError(error); }; return this; }; JSON.go = function() { var request = null; if(this.action && this.action !== null && this.action !== "") request = "action="+this.action; if(this.method=="GET") { if(this.parameters && this.parameters.length>0) { request+="&"+this.parameters; } OpenForum.debug("INFO","JSON.get page:" + this.page + " request:" + request); Ajax.sendRequest( new AjaxRequest(this.method,this.page,request,"",this.onSuccess,this.onError,true) ); } else { if(this.parameters.length<200) { OpenForum.debug("INFO","JSON.post page:" + this.page + " request:" + request + " parameters:" + this.parameters); } else { OpenForum.debug("INFO","JSON.post page:" + this.page + " request:" + request + " parameters:"+this.parameters.substring(0,200)+"... p;arameters size:" + this.parameters.length); } Ajax.sendRequest( new AjaxRequest(this.method,this.page,request,this.parameters,this.onSuccess,this.onError,true) ); } }; JSON.findPath = function( json, path ) { var currentNode = json; path = path.split("."); for( var p in path ) { var found = false; var name = pathp; for(var n in currentNode) { if( n == name ) { found = true; currentNode = currentNodename; break; } } if( found == false ) return;OpenForum.includeScript("/OpenForum/Editor/Editors/StandaloneEditor.js"); } return currentNode; }; JSON.createPath = function( json, path ) { var currentNode = json; path = path.split("."); for( var p in path ) { var found = false; var name = pathp; for(var n in currentNode) { if( n == name ) { found = true; currentNode = currentNodename; break; } } if( found == false ) { currentNodename = {}; currentNode = currentNodename; } } return currentNode; }; JSON.webStringify = function( json ) { return JSON.stringify( json , null , " " ).replaceAll("
n","
").replaceAll(" "," "); }; //==============================================================================================================// //==============================================================================================================// //==============================================================================================================// //
AjaxRequest
requestCount = 0; function AjaxRequest(method,url,request,data,onSuccess,onError,asynchronous) { var self=this; self.id = "request_"+requestCount; requestCount++; eval( self.id+"=this;" ); self.method = method; self.url = url; self.request = request; self.data = data; self.onSuccess = onSuccess; self.onError = onError; self.asynchronous = asynchronous; self.transaction = null; this.processTransactionStateChange = function processTransactionStateChange(ev) { if (self.transaction.readyState == 4) { if (self.transaction.status == 200) { onSuccess(self.transaction.responseText); } else if (self.transaction.status === 0) { } else { onError( self.transaction.status,self.transaction.statusText ); } eval( self.id+"=null;" ); } }; } //==============================================================================================================// //==============================================================================================================// //==============================================================================================================// //
Ajax
Ajax = new function() { this.sendRequest = function sendRequest(request) { request.transaction = false; if(window.XMLHttpRequest) { try { request.transaction = new XMLHttpRequest(); } catch(e) { alert(e); request.transaction = false; } } else if(window.ActiveXObject) { try { request.transaction = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { alert(e); try { request.transaction = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { alert(e); request.transaction = false; } } } if(request.transaction) { if(request.asynchronous === true) { var fn = eval(request.id+".processTransactionStateChange"); request.transaction.onreadystatechange= function(ev){ fn(ev); }; if(request.request!==null && request.request.length>0) { request.transaction.open(request.method, request.url+"?"+request.request,true); request.transaction.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); //request.transaction.setRequestHeader("If-Modified-Since", new Date(0)); request.transaction.send(request.data); } else { request.transaction.open(request.method, request.url,true); request.transaction.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); //request.transaction.setRequestHeader("If-Modified-Since", new Date(0)); request.transaction.send(request.data); } } else { if(request.request!==null && request.request.length>0) { request.transaction.open(request.method, request.url+"?"+request.request,false); request.transaction.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); } else { request.transaction.open(request.method, request.url,false); request.transaction.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); } //request.transaction.setRequestHeader("If-Modified-Since", new Date(0)); request.transaction.send(request.data); this.currentRequest=null; return request.transaction.responseText; } } else { alert("failed"); } }; }; //==============================================================================================================// //==============================================================================================================// //==============================================================================================================// //
Post
function Post() { this.data = ; this.addItem = function(name,value) { this.item = ; this.datathis.data.length = this.item; this.item0 = name; this.item1 = value; return this; }; this.addForm = function(formId) { form = document.getElementById(formId); for(var loop=0;loop
Tree
var NextTreeNodeIndex = 0; var TreeNodes = ; function Tree(elementId,name,attributes,modifier) { var self = this; var jsonModifier = function(json) { if(modifier) modifier(json); }; var root = new TreeNode(name,attributes,null,jsonModifier); self.setJSONModifier = function(newModifier) { modifier = newModifier; }; self.render = function() { var element = document.getElementById(elementId); element.innerHTML = root.render(0); return this; }; self.addChild = function(name,attributes) { return root.addChild(name,attributes); }; self.addJSON = function(node) { return root.addJSON(node); }; self.setJSON = function(node) { root = root.addJSON(node); root.setParent(null); return root; }; self.toJSON = function() { return root.toJSON(); }; self.render(); self.expandAll = function() { root.applyToChildren( function(child){ child.expand(); } ); root.expand(); return this; }; self.collapseAll = function() { root.applyToChildren( function(child){ child.collapse(); } ); root.collapse(); return this; }; self.deleteChild = function(node) { node.parent.deleteChild(node); return this; }; self.getRoot = function() { return root; }; self.expandPath = function(path) { var nodePath = findPath(path); if(nodePath!==null) { nodePath.forEach( function(node) {node.expand(); } ); return true; } else { return false; } }; self.findNode = function(path) { return findPath(path); }; self.init = function() {}; var findPath = function(path) { if(path.charAt(0)==="/") { path = path.substring(1); } var parts = path.split("/"); var node = root; var nodePath = root; for(var i=0;i
" title=
""+ attributes.toolTip +"
" target=
"_pageView
">"; } else { data += """ + attributes.link + "
" target=
"_pageView
">"; } if(attributes.icon) { data += ""; } data += name; data += ""; } else { if(attributes && attributes.icon) { data += ""; } data += name; } if(attributes && attributes.actions) { for(var actionIndex in attributes.actions) { var actionConfig = attributes.actionsactionIndex; var action = new Action(actionConfig); data+=action.render("TreeNodes""target="editor" style="color: red" title="The page /OpenForum/Editor?pageName=/OpenForum/Javascript/Core/
""+id+"
" does not exist. Click to create it.">
""+id+"
""); } } data+="
"; if(expanded===true) { for(var childIndex in children) { data+=childrenchildIndex.render(depth+1); } } data+="
."+fileExtension).onSuccess( function(result) { tree.setJSON(result); tree.render(); tree.getRoot().expand(); tree.init(); } ).go(); } return tree; }; //==============================================================================================================// //==============================================================================================================// //==============================================================================================================// //Global extra methods function typeOf( thing ) { return Object.prototype.toString.call( thing ).slice(8, -1).toLowerCase(); } function isArray( thing ) { return typeOf( thing ) == "array"; } function isObject( thing ) { return typeOf( thing ) == "object"; } function isFunction( thing ) { return typeOf( thing ) == "function"; } function isUndefined( thing ) { return typeOf( thing ) == "undefined"; } function isString( thing ) { return typeOf( thing ) == "string"; } function isNumber( thing ) { return typeOf( thing ) == "number"; } function isFloat( thing ) { return thing === +thing && thing !== (thing|0); } function isInteger( thing ) { return thing === +thing && thing === (thing|0); } function isNullOrBlank( thing ) { return ( isUndefined(thing) || thing == null || ( isString( thing ) && thing.trim().length == 0) ); } //
Math extra methods
Math.degToRad = function( deg ) { return (deg * Math.PI)/180; }; Math.radToDeg = function( rad ) { return (rad * 180)/Math.PI; }; //
String extra methods
String.prototype.contains = function(start) { return (this.indexOf(start)!==-1); }; String.prototype.startsWith = function(start) { return (this.indexOf(start)===0); }; String.prototype.endsWith = function(start) { if(!this.contains(start)) return false; return (this.indexOf(start)===this.length-start.length); }; String.prototype.between = function(start,end) { if(!this.contains(start) || !this.contains(end)) return; return this.substring(this.indexOf(start)+start.length,this.indexOf(end)); }; String.prototype.before = function (end) { if(!this.contains(end)) return; return this.substring(0,this.indexOf(end)); }; String.prototype.beforeLast = function (end) { if(!this.contains(end)) return; return this.substring(0,this.lastIndexOf(end)); }; String.prototype.after = function (start) { if(!this.contains(start)) return; return this.substring(this.indexOf(start)+start.length); }; String.prototype.afterLast = function (start) { if(!this.contains(start)) return; return this.substring(this.lastIndexOf(start)+start.length); }; String.prototype.replaceAll = function(find,replace) { return this.replace( new RegExp(find,"g"), replace); }; String.prototype.padBefore = function(padding,targetLength) { var result = this; while(result.length
hours * 3600) + (minutes * 60) + seconds)*1000; }; self.plusSeconds = function( newSeconds ) { seconds += parseInt(newSeconds); minutes += Math.floor(seconds/60); seconds = seconds % 60; hours += Math.floor(minutes/60); minutes = minutes % 60; }; self.getHours = function() { return hours; }; self.getMinutes = function() { return minutes; }; self.getSeconds = function() { return seconds; }; self.setHours = function(newHours) { hours=newHours; }; self.setMinutes = function(newMinutes) { minutes=newMinutes; }; self.setSeconds = function(newSeconds) { seconds=newSeconds; }; self.plusMinutes = function( newMinutes ) { minutes += parseInt(newMinutes); hours += Math.floor(minutes/60); minutes = minutes % 60; }; self.plusHours = function( newHours ) { hours += parseInt(newHours); }; self.isAtOrAfter = function(time) { if( self.getTime() >= time.getTime() ) return true; else return false; }; self.isAfter = function(time) { if( self.getTime() > time.getTime() ) return true; else return false; }; self.isAtOrBefore = function(time) { if( self.getTime() <= time.getTime() ) return true; else return false; }; self.isBefore = function(time) { if( self.getTime() < time.getTime() ) return true; else return false; }; self.toString = function() { return ("" + hours).padBefore("0",2) + ":" + ("" + minutes).padBefore("0",2) + ":" + ("" + seconds).padBefore("0",2); }; self.toShortString = function() { return ("" + hours).padBefore("0",2) + ":" + ("" + minutes).padBefore("0",2); }; }; //
Async processing helper function Process() { var callFn; var waitTest; var thenFn; var self = this; self.call = function(newCallFn) { callFn = newCallFn; return self; }; self.waitFor = function(newWaitTest) { waitTest = newWaitTest; return self; }; self.then = function(newThenFn) { thenFn = newThenFn; return self; }; var wait = function() { if(waitTest()===false) { setTimeout(wait,100); } else { if(thenFn) thenFn(); } }; self.run = function(data) { if(callFn) callFn(data); wait(); }; } //==============================================================================================================// //==============================================================================================================// //==============================================================================================================// //
OpenForumObject
function OpenForumObject(objectId) { var self = this; var id = objectId; var value = null; var targets=; var listeners=; var quiet = false; OpenForum.debug("INFO","Object " + id + " created"); var notifyListeners = function() { if(quiet) { OpenForum.debug("INFO","Object " + id + " has changed but is quiet"); return; } for(var listenerIndex in listeners) { var listener = listenerslistenerIndex; listener( self ); if(listener.getId) { OpenForum.debug("INFO","Object " + id + " has notified " + listener.getId() + "of change"); } } }; self.getId = function() { return id; }; self.add = function(target) { targets.push(target); if(value != null) { // If you want to join, you have to take on the value var hold = value; value = null; // Force the value to be set in all targets as will be seen as a change self.setValueQuietly(hold); // Not a real change of value, so quietly does it } if(target.getId) { OpenForum.debug("INFO","Object " + id + " has added new target " + target.getId(; } else { OpenForum.debug("INFO","Object " + id + " has added new target " + target); } }; self.reset = function() { value = null; }; self.setValueQuietly = function (newValue,exclude,clone) { quiet = true; self.setValue(newValue,exclude,clone); quiet = false; }; self.setValue = function(newValue,exclude,clone) { if(OpenForum.isEqual(newValue,value)) { return; } OpenForum.debug("INFO","Object " + id + " value set to " + newValue); if(clone && typeof newValue == "object") { value = OpenForum.clone(newValue); } else { value = newValue; } for(var targetIndex in targets) { var target = targetstargetIndex; if(target===null) { continue; } if(exclude && exclude===target) { continue; } if(typeof(target.type)!="undefined" && target.type=="checkbox") { target.checked = value; } else if(typeof(target.type)!="undefined" && target.type=="select-multiple") { for(var i in target.options) { target.optionsi.selected=false; for(var j in value) { if(target.optionsi.value==valuej) { target.optionsi.selected=true; } } } OpenForum.setGlobal(id,value); } else if(typeof(target.value)!="undefined") { target.value = value; } else if(target.innerHTML) { if(value==="") { target.innerHTML = " "; } else { target.innerHTML = ""+value; } } } }; self.getValue = function() { return value; }; self.scan = function() { for(var targetIndex=0; targetIndex
OpenForumTable
function OpenForumTable(node) { var self = this; var rowNode = node; var tableNode = node.parentNode; var value; var id; if(tableNode.attributes && tableNode.attributes'of-id') { id=tableNode.attributes'of-id'.value; } else if(tableNode.id) { id=tableNode.id; } else { id="OFTable"+OpenForum.getNextId(); } node.parentNode.removeChild(node); var temp = document.createElement("table"); temp.appendChild(node); var rowHTML = temp.innerHTML; var repeatFor = node.attributes'of-repeatFor'.value; var target = repeatFor.substring(repeatFor.indexOf(" in ")+4); var element = repeatFor.substring(0,repeatFor.indexOf(" in ")); var targetObject = OpenForum.getObject(target); var targetObjectSignature = OpenForum.createObjectSignature( targetObject.getValue() ); if(id.indexOf("OFTable")===0) id += "_" + repeatFor.replaceAll(" ","_"); OpenForum.debug("INFO","Added OpenForum table " + repeatFor + " as " + id); var tableTop = tableNode.innerHTML; tableNode.id = id; self.setTableNode = function(newTableNode) { tableNode = newTableNode; }; self.reset = function() { targetObjectSignature = null; value = null; }; self.updateQuietly = function() { targetObjectSignature = OpenForum.createObjectSignature( targetObject.getValue() ); }; self.refresh = function() { try { if(tableNode.attributes && tableNode.attributes'of-id' && typeof tableNode.value != "undefined" ) { //Not sure what the empty string was there for, but it stops select working //if( this.tableNode.value!=this.value && this.value!="") { if( tableNode.value!=value) { value = tableNode.value; OpenForum.setGlobal(tableNode.id,value); OpenForum.debug("INFO","Table " + id + " value changed to " + value); } else { var newValue = OpenForum.getGlobal(tableNode.id); if( typeof tableNode.value !== "undefined" && tableNode.value!=newValue && typeof newValue !== "undefined" && newValue !== null ) { tableNode.value=newValue; value = newValue; if(tableNode.value === newValue) { OpenForum.debug("INFO","Table " + id + " value changed to " + value); } } } } } catch(e) { OpenForum.debug("ERROR","Table " + id + " set value failed.", e); } //check if changed var objectSignature = OpenForum.createObjectSignature( targetObject.getValue() ); if(objectSignature==targetObjectSignature) { return; } var errors = false; var tableData = tableTop; var collection = targetObject.getValue(); for( var elementIndex in collection ) { try { var item = {}; itemelement= collectionelementIndex; itemelement.index = elementIndex; var data = ""+rowHTML; while(data.indexOf(OpenForum.FIELD_DELIMETER_START)!=-1) { var name = data.substring(data.indexOf(OpenForum.FIELD_DELIMETER_START)+2,data.indexOf(OpenForum.FIELD_DELIMETER_END)); var rowValue; if(name.indexOf(".")===-1) { if(name==element) { rowValue = itemelement; } else { rowValue = OpenForum.getGlobal(name); } } else { var parts = name.split("."); rowValue = item; for(var part in parts) { if(partspart.indexOf("(")!==-1) { var fn = partspart.substring(0,partspart.indexOf("(")); var call = partspart.substring(partspart.indexOf("("),partspart.indexOf(")")).split(","); rowValue = rowValuefn.apply( this,call ); } else if(partspart.indexOf("=")!==-1) { var pName = partspart.substring(0,partspart.indexOf("=")); var value = partspart.substring(partspart.indexOf("=")+1).split("?"); if( rowValuepName == value0 ) { rowValue = value1; } else { rowValue = ""; } }else { rowValue = rowValuepart" alt="partspart" title="partspart"/>]; } } } var dataStart = data.substring(0,data.indexOf(OpenForum.FIELD_DELIMETER_START)); var dataEnd = data.substring(data.indexOf(OpenForum.FIELD_DELIMETER_END)+2); if(dataStart.indexOf("of-if=
"")==dataStart.length-7) { data = dataStart.substring(0,dataStart.indexOf("of-if=
""))+ rowValue+ dataEnd.substring(1); } else { data = dataStart + rowValue + dataEnd; } if( tableNode.type=="select-one") { if(OpenForum.getGlobal(id) === rowValue ) { data = data.replace("selected=
"
"","selected"); OpenForum.debug("INFO","Table " + id + " selected = " + rowValue); } else { data = data.replace("selected=
"
"",""); } } } tableData += data; } catch(e) { OpenForum.debug("ERROR","Table " + id + " refresh failed.", e); //Fail quietly errors = true; } } OpenForum.debug("INFO","Table " + id + " updated."); tableNode.innerHTML=tableData; //Only update the signature once the data is in the view without errors if(errors==false) { targetObjectSignature=objectSignature; } }; self.getId = function() { return id; }; } //==============================================================================================================// //==============================================================================================================// //==============================================================================================================// if(!OpenForum) { OpenForum = {}; } OpenForum.Browser={}; OpenForum.Browser.download = function(fileName,data){ var hiddenElement = document.createElement('a'); hiddenElement.href = 'data:attachment/text,' + encodeURIComponent(data); hiddenElement.target = '_blank'; hiddenElement.style.display = "none"; hiddenElement.download = fileName; document.body.appendChild(hiddenElement); hiddenElement.click(); }; OpenForum.Browser.upload = function(callback,onError) { var hiddenElement = document.createElement('input'); hiddenElement.type = "file"; hiddenElement.style.display = "none"; hiddenElement.onchange = function(event) { var reader = new FileReader(); reader.onload = function(event) { if(event.target.readyState != 2) return; if(event.target.error) { if(onError) { onError('Error while reading file'); } else { alert('Error while reading file'); } return; } callback( event.target.result ); }; reader.readAsText(event.target.files0); }; document.body.appendChild(hiddenElement); hiddenElement.click(); }; OpenForum.Browser.uploadDataUrl = function(callback,onError) { var hiddenElement = document.createElement('input'); hiddenElement.type = "file"; hiddenElement.style.display = "none"; hiddenElement.onchange = function(event) { var reader = new FileReader(); reader.onload = function(event) { if(event.target.readyState != 2) return; if(event.target.error) { if(onError) { onError('Error while reading file'); } else { alert('Error while reading file'); } return; } callback( event.target.result ); }; reader.readAsDataURL(event.target.files0); }; document.body.appendChild(hiddenElement); hiddenElement.click(); }; OpenForum.Browser.overrideSave = function(fn) { $(document).bind('keydown', function(e) { if(e.ctrlKey && (e.which == 83)) { e.preventDefault(); fn(); return false; } }); }; OpenForum.Browser.enableBrowserStorage = function() { OpenForum.getBrowserFileTree = function() { var data = OpenForum.Storage.get("browserFS"); if(data == null) { data = "{}"; } return JSON.parse( data ); }; OpenForum.findBrowserFileTreeNode = function( fileName, nodeData ) { var path = fileName.replaceAll( "
.","-dot-" ).replaceAll( "/","." ); var json = OpenForum.getBrowserFileTree(); var node = JSON.findPath( json , path ); if( isUndefined( node ) ) { node = JSON.createPath( json , path ); OpenForum.Storage.set( "browserFS", JSON.stringify( json ) ); } if( !isUndefined( nodeData ) ){ for( var n in nodeData ) { noden = nodeDatan; } OpenForum.Storage.set( "browserFS", JSON.stringify( json ) ); } return node; }; OpenForum.remoteSave = OpenForum.saveFile; OpenForum.saveFile = function(fileName,data,callBack) { if(fileName.startsWith("browser://")) { fileName = fileName.replace("browser:/","browserFS "); OpenForum.Storage.set(fileName,data); var simpleFileName = fileName.substring( fileName.lastIndexOf("/")+1 ); var extension = simpleFileName.substring( simpleFileName.lastIndexOf(".")+1 ); OpenForum.findBrowserFileTreeNode( fileName, { type: "file", size: data.length, created: new Date().getTime(), updated: new Date().getTime(), fileName: simpleFileName, extension: extension } ); if(callBack) { callBack( {"result":"ok","message":"Saved " + fileName,"saved":true} ); } } else { return OpenForum.remoteSave(fileName,data,callBack); } }; OpenForum.remoteDelete = OpenForum.deleteFile; OpenForum.deleteFile = function(pageName,fileName,callBack) { if(fileName.startsWith("browser://")) { fileName = fileName.replace("browser:/","browserFS "); OpenForum.findBrowserFileTreeNode( fileName, { deleted: true } ); if(callBack) { callBack( {"result":"ok","message":"Deleted " + fileName,"deleted":true} ); } } else { return OpenForum.remoteDelete(pageName,fileName,callBack); } }; OpenForum.remoteLoad = OpenForum.loadFile; OpenForum.loadFile = function(fileName,callBack,noCache) { if(fileName.startsWith("browser://")) { fileName = fileName.replace("browser:/","browserFS "); var data = OpenForum.Storage.get(fileName); if(callBack) { callBack( data ); } return data; } else { return OpenForum.remoteLoad(fileName,callBack,noCache); } }; OpenForum.remoteAppend = OpenForum.appendFile; OpenForum.appendFile = function(fileName,data,callBack) { if(fileName.startsWith("browser://")) { fileName = fileName.replace("browser:/","browserFS "); var currentData = OpenForum.Storage.get(fileName); if( currentData == null ) { return OpenForum.saveFile(fileName,data,callBack); } data = currentData + data; OpenForum.Storage.set(fileName,data); OpenForum.findBrowserFileTreeNode( fileName, { modified: new Date().getTime(), size: data.length } ); if(callBack) { callBack( {"result":"ok","message":"Appended " + fileName,"appended":true} ); } } else { return OpenForum.remoteAppend(fileName,data,callBack); } }; OpenForum.remoteCopy = OpenForum.copyFile; OpenForum.copyFile = function(fileName,toFileName,callBack) { if(fileName.startsWith("browser://")) { fileName = fileName.replace("browser:/","browserFS "); var data = OpenForum.Storage.get(fileName); OpenForum.saveFile(toFileName,data); if(callBack) { callBack( {"result":"ok","message":"Copied " + fileName,"copied":true} ); } } else { return OpenForum.remoteCopy(fileName,toFileName,callBack); } }; OpenForum.remoteMove = OpenForum.moveFile; OpenForum.moveFile = function(fileName,toFileName,callBack) { if(fileName.startsWith("browser://")) { fileName = fileName.replace("browser:/","browserFS "); var data = OpenForum.Storage.get(fileName); OpenForum.saveFile(toFileName,data); OpenForum.deleteFile(fileName); if(callBack) { callBack( {"result":"ok","message":"Moved " + fileName,"moved":true} ); } } else { return OpenForum.remoteMove(fileName,toFileName,callBack); } }; OpenForum.remoteFileExists = OpenForum.fileExists; OpenForum.fileExists = function(fileName) { if(fileName.startsWith("browser://")) { fileName = fileName.replace("browser:/","browserFS "); return OpenForum.Storage.get(fileName) != null; } else { return OpenForum.remoteFileExists(fileName); } }; OpenForum.remoteGetAttachments = OpenForum.getAttachments; OpenForum.getAttachments = function(pageName,callBack,matching,withMetaData) { if(pageName.startsWith("browser://")) { pageName = pageName.replace("browser:/","browserFS "); //TODO if(callBack) { callBack( {"result":"ok","message":"Saved " + fileName,"saved":true} ); } } else { return OpenForum.remoteGetAttachments(pageName,callBack,matching,withMetaData); } }; OpenForum.remoteCreateFileTree = OpenForum.createFileTree; OpenForum.createFileTree = function(id,root,fileExtension,modifier) { if(root.startsWith("browser://")) { var tree = new Tree(id,"Loading...","",modifier); var fsJson = OpenForum.findBrowserFileTreeNode( root.replace("browser:/","browserFS ") ); //Copy //https://open-forum.onestonesoup.org/OpenForum/Javascript/Tree?action=getPageTree&pageName=/TheLab/Experiments/BrowserFileStorage var toFileTree = function( name, json, path ) { if( isUndefined( path ) ) { path = ""; } var newNode = {}; newNode.name = name; newNode.attributes = { type: "page", pageName: path, link: path, icon: "book", toolTip: "Open page" }; newNode.leaves = ; for(var i in json) { var node = jsoni; if(node.type && node.type == "file") { if( ( typeof fileExtension != "undefined" ) && node.extension.match( ".*
." + fileExtension ) ) { continue; } var jsonNode = {}; jsonNode.name = node.fileName; jsonNode.leaves = ; jsonNode.attributes = { type: "file", pageName: path, fileName: node.fileName, link: path + "/" +node.fileName, icon: "attach", actions: { fn: "function(node){ window.open('/OpenForum/Editor?pageName=' + node.getAttribute('pageName') + '&fileName=' + node.getAttribute('fileName')); }", icon: "pencil", toolTip: "Edit file" } }; newNode.leaves.push( jsonNode ); } else { newNode.leaves.push( toFileTree( i, node, path + "/" + i ) ); } } return newNode; }; var jsonTree = toFileTree( root.substring( root.lastIndexOf("/")+1 ) ,fsJson, root ); tree.setJSON(jsonTree); tree.render(); tree.getRoot().expand(); tree.init(); return tree; } else { return OpenForum.remoteCreateFileTree(id,root,fileExtension,modifier); } }; }; //==============================================================================================================// //==============================================================================================================// //==============================================================================================================// OpenForum.action = {}; OpenForum.action.copyPage = function(pageName,newPageName) { window.open("/OpenForum/Actions/Copy?newPageName="+newPageName+"&pageName="+pageName); }; OpenForum.action.movePage = function(pageName,newPageName) { window.location = "/OpenForum/Actions/Move?newPageName="+newPageName+"&pageName="+pageName; }; OpenForum.action.zipPage = function(pageName) { window.location = "/OpenForum/Actions/Zip?action=zip&pageName="+pageName; }; OpenForum.action.deletePage = function(pageName) { window.location = "/OpenForum/Actions/Delete?pageName="+pageName; }; //==============================================================================================================// //==============================================================================================================// //==============================================================================================================// if(!OpenForum) { OpenForum = {}; } OpenForum.BLANK = ""; //Used in Extensions where "" cannot be used OpenForum.createObjectSignature = function(object) { var cache = ; var signature = JSON.stringify(object, function(key, value) { if (typeof value === 'object' && value !== null) { if (cache.indexOf(value) !== -1) { // Circular reference found, discard key return; } // Store value in our collection cache.push(value); } return value; }); cache = null; return signature; }; OpenForum.copyElement = function(id) { document.getElementById(id).select(); document.execCommand('copy'); }; OpenForum.copyData = function(data) { var hiddenElement = document.createElement('textarea'); hiddenElement.value = data; document.body.appendChild( hiddenElement ); hiddenElement.select(); document.execCommand('copy'); document.body.removeChild( hiddenElement ); }; OpenForum.setElement = function(id,content) { document.getElementById(id).innerHTML = content; OpenForum.crawl( document.getElementById(id) ); }; OpenForum.appendToElement = function(id,content) { document.getElementById(id).innerHTML += content; OpenForum.crawl( document.getElementById(id) ); }; OpenForum.showElement = function(id) { document.getElementById(id).style.display = "block"; }; OpenForum.hideElement = function(id) { document.getElementById(id).style.display = "none"; }; OpenForum.toggleElement = function(id) { if(document.getElementById(id).style.display==="block") { document.getElementById(id).style.display = "none"; } else { document.getElementById(id).style.display = "block"; } }; OpenForum.setTitle = function(title) { document.title = title; }; OpenForum.setCursor = function(pointer) { if(pointer == "wait") { document.body.style.cursor = 'wait'; return; } else if(pointer == "zoom-in") { document.body.style.cursor = 'zoom-in'; return; } else if(pointer == "pointer") { document.body.style.cursor = 'pointer'; return; } else if(pointer == "crosshair") { document.body.style.cursor = 'crosshair'; return; } else if(pointer == "default") { document.body.style.cursor = 'default'; return; } if(pointer.indexOf(".")==-1) { pointer = "/OpenForum/Images/icons/png/" +pointer+ ".png"; } document.getElementsByTagName("body")0.style.cursor = "url('"+pointer+"'), auto"; }; OpenForum.setTabIcon = function(icon) { if(icon.indexOf(".")==-1) { icon = "/OpenForum/Images/icons/png/" +icon+ ".png"; } var link = document.querySelector("linkrel~='icon'"); if (!link) { link = document.createElement('link'); link.rel = 'icon'; document.head.appendChild(link); } link.href = icon; }; OpenForum.getParameter = function( name ) { name = name.replace(/" alt="
" title="
"/>/g,"
" alt="").replace(/
" title="").replace(/
"/>]/g,"
]"); var regexS = "
?&"+name+"=(^*)"; var regex = new RegExp( regexS ); var results = regex.exec( window.location.href ); if( results === null ) return ""; else return results1; }; OpenForum.getCookie = function(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = cai; while (c.charAt(0)==' ') { c = c.substring(1,c.length); } if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); } } return null; }; //Keep all the evil in one place OpenForum.evaluate = function(script) { try{ return eval(script); } catch (e) { OpenForum.debug( "ERROR", "Exception evaluating '" + script + "'",e ); throw e; } }; OpenForum.globalExists = function( name ) { name = name.replace(/
"target="editor" style="color: red" title="The page /OpenForum/Editor?pageName=/g,".").replace(/
does not exist. Click to create it.">/g,".").replace(/
/g,"").replace(/'/g,"").replace(/
(.*
)/g,""); var parts = name.split("."); var obj = window; for(var part in parts) { if( typeof objpart" alt="partspart" title="partspart"/>] === "undefined" ) return false; obj = objpart" alt="partspart" title="partspart"/>]; } return true; }; OpenForum.getGlobal = function( name ) { name = name.replace(/
"target="editor" style="color: red" title="The page /OpenForum/Editor?pageName=/g,".").replace(/
does not exist. Click to create it.">/g,".").replace(/
/g,"").replace(/'/g,"").replace(/
(.*
)/g,""); var parts = name.split("."); var obj = window; for(var part in parts) obj = objpart" alt="partspart" title="partspart"/>]; if(typeof obj === "function") return obj(); else return obj; }; OpenForum.setGlobal = function( name,value,create ) { name = name.replace(/
"target="editor" style="color: red" title="The page /OpenForum/Editor?pageName=/g,".").replace(/
does not exist. Click to create it.">/g,".").replace(/
/g,"").replace(/'/g,""); var parts = name.split("."); var obj = window; var i=0; for(i=0; i
t"; var csv = ""; if(Array.isArray(json)) { for(var i in json) { var row = jsoni; //add column name row if(csv.length===0) { for (var c in row) { if(csv.length>0) { csv+=delimiter; } csv += c; } csv += "
n"; } //add row var csvRow = ""; for (var r in row) { if(csvRow.length>0) { csvRow+=delimiter; } csvRow += rowr; } csv += csvRow +"
n"; } } else if(typeof json === "object") { for(var name in json) { csv += name + delimiter + jsonname + "
n"; } } return csv; }; OpenForum.Table.closeTable = function(table) { for(var i in table) { tablei.view = "display: block;"; tablei.edit = "display: none;"; } }; OpenForum.Table.addRow = function(table,templateRow,clean) { if(!templateRow) { templateRow = tabletable.length-1; } if(!templateRow.view) { templateRow.view = "display: block;"; templateRow.edit = "display: none;"; } var newRow = OpenForum.clone( templateRow ); if(clean) { OpenForum.clean( newRow ); } table.push( newRow ); OpenForum.Table.editRow(table,table.length-1); }; OpenForum.Table.removeRow = function(table,index) { return table.splice(index,1)0; }; OpenForum.Table.moveRowUp = function(table,index) { if(index<=0) return; var row = table.splice(index,1)0; table.splice(index-1,0,row); }; OpenForum.Table.moveRowDown = function(table,index) { if(index>=table.length-1) return; var row = table.splice(index,1)0; table.splice(index+1,0,row); }; OpenForum.Table.applyRowFilter = function(tableName,tableData,fieldName,fieldFilter) { var table = document.getElementById(tableName); var filters = ; var allBlank = true; if(typeof fieldFilter == "undefined" && fieldName.length) { //Assume array of filters filters = fieldName; for(var i in filters) { if(filtersi.fieldFilter!="") allBlank = false; filtersi.query = ".*"+filtersi.fieldFilter+".*"; } } else { if(fieldFilter!="") allBlank = false; filters.push( {fieldName: fieldName, fieldFilter: fieldFilter, query: ".*"+fieldFilter+".*"} ); } var index = 1; for(var i in tableData) { var rowData = tableDatai; if(allBlank) { OpenForum.Table.showRow(table,index); } else { OpenForum.Table.showRow(table,index); for(var j in filters) { if( (filtersj.query != ".*.*") && (""+rowDataj" alt="filtersj" title="filtersj"/>.fieldName]).match(filtersj.query) == null) { OpenForum.Table.hideRow(table,index); } } } index++; } }; OpenForum.Table.sort = function(tableData,fieldName,ascending) { tableData.sort( function(a,b) { if(ascending) { if(afieldNamefieldName) return 1; else return -1; } else { if(afieldName>bfieldName) return 1; else return -1; } } ); }; OpenForum.Table.hideRow = function(table,row) { var nodes = table.querySelectorAll('tbody tr:nth-child(' + row + ')'); nodes.item(0).style.display = "none"; }; OpenForum.Table.showRow = function(table,row) { var nodes = table.querySelectorAll('tbody tr:nth-child(' + row + ')'); nodes.item(0).style.display = ""; }; OpenForum.Table.renderTable = function(tableName,tableData) { var html = "
" + n.replaceAll("_"," ") + " | "; } html += "
" + cell + " | "; } html += "
Child Pages
Build Script
Script elements
- /OpenForum/Javascript/Core/open-forum-storage.js
- /OpenForum/Javascript/Core/open-forum-ajax.js
- /OpenForum/Javascript/Core/open-forum-ofx.js
- /OpenForum/Javascript/Core/open-forum-scanner.js
- /OpenForum/Javascript/Core/open-forum-table.js
- /OpenForum/Javascript/Core/data.json
- /OpenForum/Javascript/Core/open-forum-client.js
- /OpenForum/Javascript/Core/open-forum-backup.js
- /OpenForum/Javascript/Core/page.js
- /OpenForum/Javascript/Core/open-forum-dependency.js
- /OpenForum/Javascript/Core/open-forum-utils.js
- /OpenForum/Javascript/Core/open-forum-ajax-request.js
- /OpenForum/Javascript/Core/open-forum.help.js
- /OpenForum/Javascript/Core/script.build.json
- /OpenForum/Javascript/Core/open-forum-files.js
- /OpenForum/Javascript/Core/release-info.json
- /OpenForum/Javascript/Core/open-forum-debug.js
- /OpenForum/Javascript/Core/open-forum-object.js
- /OpenForum/Javascript/Core/open-forum-js-extensions.js
- /OpenForum/Javascript/Core/open-forum-action.js
- /OpenForum/Javascript/Core/open-forum-ajax-post.js
- /OpenForum/Javascript/Core/open-forum-tree.js
- /OpenForum/Javascript/Core/open-forum.build.json
- /OpenForum/Javascript/Core/open-forum-json.js
- /OpenForum/Javascript/Core/open-forum-google-font.js
- /OpenForum/Javascript/Core/open-forum-browser.js