/* The contents of this file are protected by copyright law. * All rights are retained. * A non-exclusive license is hereby granted to use the file * in connection with the website http://www.covariable.com/ * Copyright 2006 Woodley Packard and Steven Stanek */ var renderHeight = 90; var renderBorder = 3; var editing_html = 0; function edit_html() { var content = document.getElementById("content"); if(editing_html) { for(var x=0;x 0 && document.getElementById("wsSave") != null) document.getElementById("wsSave").style.display="inline"; if(modified) return; var res = ajaxPost("/wsCreate", "text/plain", "ts="+tableset); if(res.match("ws=") != null) { tableset = parseInt(res.substr(3)); modified = true; } else { alert(res); return; } setTitle("Workspace: (unsaved)"); } function setTitle(s) { var tstitle = document.getElementById("tstitle"); if(tstitle) { while(tstitle.firstChild != null) tstitle.removeChild(tstitle.firstChild); tstitle.appendChild(document.createTextNode(s)); } } function reloadPage() { window.location = "/tset?" + tableset; } /* Takes the given string and ensures that it is less than len chars. If it already less than len * our job is done and we return the string. If it is longer, we return a string of the form * "[first len/2-1 chars]...[last len/2-2 chars]" * For instance, shortenString("Nasty Large Table", 12) should return "Nasty...able" */ function shortenString(s, len) { if(s.length < len) return s; return s.slice(0, len/2-1) + "..." + s.slice((s.length)-(len/2-2)); } /* Used to forcably add linebreaks to strings where one continuous word exceeds the * specified number of characters. */ function addBreaksToString(s, len) { var wordLen =0; var breakSymbols = [' ', '\n', '.', ',']; var returnme = ""; if(s.length < len)return s; for(var i=0; i < s.length; i++) { if(s.charAt(i) == ' ') { wordLen=0; if(i + len > s.length)return s; } else wordLen++; if(wordLen == len)break; } if(wordLen < len)return s; wordLen = 0; for(var i=0; i < s.length; i++) { for (var j=0; j < breakSymbols.length; j++) if(s.charAt(i) == breakSymbols[j]) wordLen=-1; wordLen ++; returnme += s.charAt(i); if(wordLen == len) { returnme+= '\n'; wordLen=0; } } return returnme; } //For extending subclasses extend = function(subClass, baseClass) { function inheritance() {} inheritance.prototype = baseClass.prototype; subClass.prototype = new inheritance(); subClass.prototype.constructor = subClass; subClass.baseConstructor = baseClass; subClass.superClass = baseClass.prototype; } /* Returns the first child of the specified class (only the first) * Looks only at children, not other descendents */ function getChildByClass(elem, className) { for (var i=0; i < elem.childNodes.length; i++) { var presChild = elem.childNodes[i]; if(presChild.getAttribute && presChild.className == className) return presChild; } return null; } /* Takes some text and escapes all HTML special characters to make the string safe for use * using innerHTML. */ function HTMLSafeText(string) { string = string.replace(new RegExp("&", "g"), "&"); string = string.replace(new RegExp("<", "g"), "<"); string = string.replace(new RegExp(">", "g"),">"); string = string.replace(new RegExp("\"", "g"),"""); string = string.replace(new RegExp("'", "g"), "'"); return string; } /********************FOR QUICK ARRAY SEARCHS*******************/ //Return the index in the array of the value, -1=not found function indexOf(arr, val) { if(val == null) return -1; for(var i=0; i < arr.length; i++) if(arr[i] == val) return i; return -1; } /********************FOR CREATING UI ELEMENTS QUICKLY********************/ //Creator functions for various document elements function createSelection(aList, excludeIndex) { var presSelector = document.createElement("select") for (var i in aList) { if(excludeIndex != null && excludeIndex == i) { continue; } var presOption = document.createElement("option"); presOption.appendChild(document.createTextNode(aList[i])); presOption.label = aList[i]; presOption.text = aList[i]; presOption.value = aList[i]; presSelector.appendChild(presOption); } return presSelector; } /* Creates an HTML selector from the list of items provided. The values, labels and text * of all the list items are set to their name. The id is the id for the selector. The * handler is called with the id as a parameter. SelIdx is used to set the selected * element. * Both id and handlerParm will be treated as strings! */ function createSelectionHTML(aList, id, handlerName, selIdx, handlerParm, selClassName){ var html = ""; } function createRadioButton(name, id, value, onclick, checked) { var input = document.createElement("input"); input.type = "radio"; if(id!=null) input.id = id; if(name!=null) input.name = name; if(value != null) input.value = value; if(onclick != null) input.onclick = onclick; if(checked == true) input.checked = true; return input; } function closure(f) { var args = new Array(); for (var i=1; i < arguments.length; i++) args[i-1] = arguments[i]; return function(){f.apply(this, args)}; } function closureWithThis(f, myThis) { var args = new Array(); for (var i=2; i < arguments.length; i++) args[i-2] = arguments[i]; return function(){f.apply(myThis, args)} } function createTextField(value, id, onblur, className, width) { var returnme = document.createElement("input"); returnme.type = "text"; returnme.id = id; returnme.value = value; if(onblur != null) { returnme.onchange= onblur; } if(className != null) returnme.className = className; if(width != null) returnme.style.width = width + "px"; return returnme; } function createButton(name, id, onclick, className, width) { var returnme = document.createElement("button"); returnme.id = id; if(name != null) returnme.appendChild(document.createTextNode(name)); if(onclick != null) returnme.onclick = onclick; if(className != null) returnme.className = className; if(width != null) returnme.style.width = width; return returnme; } function createAnchor(text, id, target) { var aTag = document.createElement("a"); aTag.id = id; aTag.href = target; aTag.appendChild(document.createTextNode(text)); return aTag; } /* Rounded Divs are special divs which have a content bar at the top with * rounded corners and contain the contents inside of the table. */ function createLabelledDiv(title, contents) { var returnme = document.createElement("div"); var daTab = document.createElement("table"); returnme.appendChild(daTab); var daBody = document.createElement("tbody"); daTab.appendChild(daBody); var headerRow= document.createElement("tr"); daBody.appendChild(headerRow); var leftCell = document.createElement("td"); headerRow.appendChild(leftCell); var centerCell = document.createElement("td"); headerRow.appendChild(centerCell); var rightCell = document.createElement("td"); headerRow.appendChild(rightCell); daTab.className = 'roundedheader'; leftCell.className='roundedheaderleft'; centerCell.appendChild(document.createTextNode(title)); rightCell.className='roundedheaderright'; var contentsDiv = document.createElement("div"); returnme.appendChild(contentsDiv); contentsDiv.className = 'roundedContainer'; contentsDiv.appendChild(contents); return returnme; } //Like the above but produces HTML output instead function createLabelledDivHTML(title, contentHTML) { var html = "
"; html +=""; html +=""; html +=""; html +="
" + title + "
" +contentHTML+"
"; return html; }