From e7073c1575f39a27eee725d1218cf8b304871e98 Mon Sep 17 00:00:00 2001 From: hallgren Date: Fri, 9 Apr 2010 13:51:34 +0000 Subject: Adding the Minibar files to the darcs repository. --- src/runtime/javascript/minibar/support.js | 157 ++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 src/runtime/javascript/minibar/support.js (limited to 'src/runtime/javascript/minibar/support.js') diff --git a/src/runtime/javascript/minibar/support.js b/src/runtime/javascript/minibar/support.js new file mode 100644 index 000000000..15ccc38d0 --- /dev/null +++ b/src/runtime/javascript/minibar/support.js @@ -0,0 +1,157 @@ +function element(id) { + return document.getElementById(id); +} + +// Inspired by the function jsonp from +// http://www.west-wind.com/Weblog/posts/107136.aspx +// See also http://niryariv.wordpress.com/2009/05/05/jsonp-quickly/ +// http://en.wikipedia.org/wiki/JSON#JSONP +function jsonp(url,callback) +{ + if (url.indexOf("?") > -1) + url += "&jsonp=" + else + url += "?jsonp=" + url += callback + "&"; + //url += new Date().getTime().toString(); // prevent caching + + var script = empty("script"); + script.setAttribute("src",url); + script.setAttribute("type","text/javascript"); + document.body.appendChild(script); +} + +/* --- HTML construction ---------------------------------------------------- */ +function text(s) { return document.createTextNode(s); } + +function empty(tag,name,value) { + var el=document.createElement(tag); + if(name && value) el.setAttribute(name,value); + return el; +} + +function empty_id(tag,id) { return empty(tag,"id",id); } +function empty_class(tag,cls) { return empty(tag,"class",cls); } + +function div_id(id) { return empty_id("div",id); } + +function wrap(tag,contents) { + var el=empty(tag); + el.appendChild(contents); + return el; +} + +function wrap_class(tag,cls,contents) { + var el=empty_class(tag,cls); + if(contents) el.appendChild(contents); + return el; +} + +function span_class(cls,contents) { return wrap_class("span",cls,contents); } +function div_class(cls,contents) { return wrap_class("div",cls,contents); } + +function p(contents) { return wrap("p",contents); } +function dt(contents) { return wrap("dt",contents); } + +function th(contents) { return wrap("th",contents); } +function td(contents) { return wrap("td",contents); } + +function tr(cells) { + var tr=empty("tr"); + for(var i=0;i"; + } + return result; +} + +function field_names(obj) { + var result = ""; + for (var i in obj) { + result += " " + i; + } + return result; +} + +/* --- Data manipulation ---------------------------------------------------- */ +function swap(a,i,j) { // Note: this doesn't work on strings. + var tmp=a[i]; + a[i]=a[j]; + a[j]=tmp; + return a; +} + +function sort(a) { // Note: this doesn't work on strings. + for(var i=0;i