From 3eaeaed8fd741bb1f33c76032e7292df08b35a9f Mon Sep 17 00:00:00 2001 From: hallgren Date: Tue, 20 Nov 2012 12:56:48 +0000 Subject: GF cloud: move support.js and pgf_online.js Created the folder js and moved minibar/support.js and minibar/pgf_online.js there, to emphasize their status as app independent support libraries. There are probably more files that should be moved here. The cloud apps have been updated, externally hosted apps that link directly to our server need to be updated too. --- src/www/gfse/index.html | 6 +- src/www/gfse/share.html | 4 +- src/www/js/pgf_online.js | 80 ++++++++ src/www/js/support.js | 329 +++++++++++++++++++++++++++++++ src/www/minibar/about.html | 12 +- src/www/minibar/example.html | 6 +- src/www/minibar/feedback.html | 2 +- src/www/minibar/gf-web-api-examples.html | 4 +- src/www/minibar/minibar-api.html | 14 +- src/www/minibar/minibar.html | 6 +- src/www/minibar/minibar_offline.html | 4 +- src/www/minibar/pgf_online.js | 80 -------- src/www/minibar/phrasebook.html | 4 +- src/www/minibar/saldotest.html | 4 +- src/www/minibar/support.js | 329 ------------------------------- src/www/translator/index.html | 6 +- 16 files changed, 445 insertions(+), 445 deletions(-) create mode 100644 src/www/js/pgf_online.js create mode 100644 src/www/js/support.js delete mode 100644 src/www/minibar/pgf_online.js delete mode 100644 src/www/minibar/support.js (limited to 'src') diff --git a/src/www/gfse/index.html b/src/www/gfse/index.html index 3b3543c2a..c607b4374 100644 --- a/src/www/gfse/index.html +++ b/src/www/gfse/index.html @@ -33,12 +33,12 @@ This page does not work without JavaScript.
HTML -Last modified: Wed Oct 3 23:44:31 CEST 2012 +Last modified: Tue Nov 20 13:39:47 CET 2012
About

  
-
+
 
 
 
@@ -49,6 +49,6 @@ HTML
 
 
 
-
+
 
 
diff --git a/src/www/gfse/share.html b/src/www/gfse/share.html
index 54dcdb3e0..ff92d2f73 100644
--- a/src/www/gfse/share.html
+++ b/src/www/gfse/share.html
@@ -13,8 +13,8 @@
 
 
- Last modified: Mon Feb 13 19:03:32 CET 2012 - +Last modified: Tue Nov 20 13:39:57 CET 2012 + diff --git a/src/www/js/pgf_online.js b/src/www/js/pgf_online.js new file mode 100644 index 000000000..6fe23b13e --- /dev/null +++ b/src/www/js/pgf_online.js @@ -0,0 +1,80 @@ + +/* --- Grammar access object ------------------------------------------------ */ + +function pgf_online(options) { + var server = { + // State variables (private): + grammars_url: "/grammars/", + other_grammars_urls: [], + grammar_list: null, + current_grammar_url: null, + + // Methods: + switch_grammar: function(grammar_url,cont) { + this.current_grammar_url=this.grammars_url+grammar_url; + if(cont) cont(); + }, + add_grammars_url: function(grammars_url,cont) { + this.other_grammars_urls.push(grammars_url); + if(cont) cont(); + }, + switch_to_other_grammar: function(grammar_url,cont) { + this.current_grammar_url=grammar_url; + if(cont) cont(); + }, + get_grammarlist: function(cont,err) { + if(this.grammar_list) cont(this.grammar_list) + else http_get_json(this.grammars_url+"grammars.cgi",cont,err); + }, + get_grammarlists: function(cont,err) { // May call cont several times! + var ds=this.other_grammars_urls; + var n=1+ds.length; + function pair(dir) { + return function(grammar_list){cont(dir,grammar_list,n)} + } + function ignore_error(err) { console.log(err) } + this.get_grammarlist(pair(this.grammars_url),err) + for(var i in ds) + http_get_json(ds[i]+"grammars.cgi",pair(ds[i]),ignore_error); + }, + pgf_call: function(cmd,args,cont,err) { + var url=this.current_grammar_url+"?command="+cmd+encodeArgs(args) + http_get_json(url,cont,err); + }, + + get_languages: function(cont,err) { + this.pgf_call("grammar",{},cont,err); + }, + grammar_info: function(cont,err) { + this.pgf_call("grammar",{},cont,err); + }, + + get_random: function(args,cont,err) { // cat, limit + args.random=Math.random(); // side effect!! + this.pgf_call("random",args,cont,err); + }, + linearize: function(args,cont,err) { // tree, to + this.pgf_call("linearize",args,cont,err); + }, + complete: function(args,cont,err) { // from, input, cat, limit + this.pgf_call("complete",args,cont,err); + }, + parse: function(args,cont,err) { // from, input, cat + this.pgf_call("parse",args,cont,err); + }, + translate: function(args,cont,err) { // from, input, cat, to + this.pgf_call("translate",args,cont,err); + }, + translategroup: function(args,cont,err) { // from, input, cat, to + this.pgf_call("translategroup",args,cont,err); + }, + browse: function(args,cont,err) { // id, format + if(!args.format) args.format="json"; // sife effect!! + this.pgf_call("browse",args,cont,err); + } + }; + for(var o in options) server[o]=options[o]; + if(server.grammar_list && server.grammar_list.length>0) + server.switch_grammar(server.grammar_list[0]); + return server; +} diff --git a/src/www/js/support.js b/src/www/js/support.js new file mode 100644 index 000000000..e82f4fc9c --- /dev/null +++ b/src/www/js/support.js @@ -0,0 +1,329 @@ +/* --- Accessing document elements ------------------------------------------ */ + +function element(id) { + return document.getElementById(id); +} + +/* --- JavaScript tricks ---------------------------------------------------- */ + +// To be able to use object methods that refer to "this" as callbacks +// See section 3.3 of https://github.com/spencertipping/js-in-ten-minutes/raw/master/js-in-ten-minutes.pdf +function bind(f, this_value) { + return function () {return f.apply (this_value, arguments)}; +}; + +// Implement Array.isArray for older browsers that lack it. +// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray +if(!Array.isArray) { + Array.isArray = function (arg) { + return Object.prototype.toString.call(arg) == '[object Array]'; + }; +} + +/* --- JSONP ---------------------------------------------------------------- */ + +// 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/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); +} + +var json = {next:0}; + +// Like jsonp, but instead of passing the name of the callback function, you +// pass the callback function directly, making it possible to use anonymous +// functions. +function jsonpf(url,callback,errorcallback) +{ + var name="callback"+(json.next++); + json[name]=function(x) { delete json[name]; callback(x); } + jsonp(url,"json."+name); +} + +/* --- AJAX ----------------------------------------------------------------- */ + +function GetXmlHttpObject(handler) +{ + var objXMLHttp=null + if (window.XMLHttpRequest) + { + // See http://www.w3.org/TR/XMLHttpRequest/ + // https://developer.mozilla.org/en/xmlhttprequest + objXMLHttp=new XMLHttpRequest() + } + else if (window.ActiveXObject) + { + objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") + } + return objXMLHttp +} + +function ajax_http(method,url,body,callback,errorcallback) { + var http=GetXmlHttpObject() + if (!http) { + var errortext="Browser does not support HTTP Request"; + if(errorcallback) errorcallback(errortext,500) + else alert(errortext) + } + else { + function statechange() { + if (http.readyState==4 || http.readyState=="complete") { + if(http.status<300) callback(http.responseText,http.status); + else if(errorcallback) + errorcallback(http.responseText,http.status, + http.getResponseHeader("Content-Type")); + else alert("Request for "+url+" failed: " + +http.status+" "+http.statusText); + } + } + http.onreadystatechange=statechange; + http.open(method,url,true) + http.send(body) + } + return http +} + +function ajax_http_get(url,callback,errorcallback) { + ajax_http("GET",url,null,callback,errorcallback) +} + +function ajax_http_post(url,formdata,callback,errorcallback) { + ajax_http("POST",url,formdata,callback,errorcallback) + // See https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Using_FormData_objects +} + +// JSON via AJAX +function ajax_http_get_json(url,cont,errorcallback) { + ajax_http_get(url,function(txt){cont(eval("("+txt+")"));}, errorcallback); +} + +function sameOrigin(url) { + var a=empty("a"); + a.href=url; // converts to an absolute URL + return hasPrefix(a.href,location.protocol+"//"+location.host+"/"); +} + +// Use AJAX when possible, fallback to JSONP +function http_get_json(url,cont,errorcallback) { + if(sameOrigin(url)) ajax_http_get_json(url,cont,errorcallback); + else jsonpf(url,cont,errorcallback); +} + +/* --- URL construction ----------------------------------------------------- */ + +function encodeArgs(args) { + var q="" + for(var arg in args) + if(args[arg]!=undefined) + q+="&"+arg+"="+encodeURIComponent(args[arg]); + return q; +} + +/* --- HTML construction ---------------------------------------------------- */ +function text(s) { return document.createTextNode(s); } + +function node(tag,as,ds) { + var n=document.createElement(tag); + for(var a in as) n.setAttribute(a,as[a]); + if(ds) for(var i in ds) n.appendChild(ds[i]); + return n; +} + +function empty(tag,name,value) { + var el=node(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,cs) { return node("div",{id:id},cs); } +function span_id(id) { return empty_id("span",id); } + +function wrap(tag,contents) { + return node(tag,{},Array.isArray(contents) ? contents : [contents]); +} + +function wrap_class(tag,cls,contents) { + return node(tag,{"class":cls}, + contents ? Array.isArray(contents) ? + contents : [contents] : []) +} + +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 dd(contents) { return wrap("dd",contents); } +function li(contents) { return wrap("li",contents); } + +function th(contents) { return wrap("th",contents); } +function td(contents) { return wrap("td",contents); } + +function tr(cells) { return wrap("tr",cells); } + +function button(label,action,key) { + var el=node("input",{"type":"button","value":label},[]); + if(typeof action=="string") el.setAttribute("onclick",action); + else el.onclick=action; + if(key) el.setAttribute("accesskey",key); + return el; +} + +function option(label,value) { + return node("option",{"value":value},[text(label)]); +} + +function hidden(name,value) { + return node("input",{type:"hidden",name:name,value:value},[]) +} + +function tda(cs) { return node("td",{},cs); } + +function img(src) { return empty("img","src",src); } + +/* --- Document modification ------------------------------------------------ */ + +function clear(el) { replaceInnerHTML(el,""); } +function replaceInnerHTML(el,html) { if(el) el.innerHTML=html; } +function replaceChildren(el,newchild) { clear(el); el.appendChild(newchild); } + +function appendChildren(el,ds) { + for(var i in ds) el.appendChild(ds[i]); + return el; +} + +function insertFirst(parent,child) { + parent.insertBefore(child,parent.firstChild); +} + +function insertBefore(el,ref) { ref.parentNode.insertBefore(el,ref); } + +function insertAfter(el,ref) { + ref.parentNode.insertBefore(el,ref.nextSibling); +} + +/* --- Debug ---------------------------------------------------------------- */ + +function debug(s) { + var d=element("debug"); + if(d) d.appendChild(text(s+"\n")) +} + +function show_props(obj, objName) { + var result = ""; + for (var i in obj) { + result += objName + "." + i + " = " + obj[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) { +// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/sort + return a.sort(); + /* // Note: this doesn't work on strings. + for(var i=0;iThe implementation consist of two JavaScript files: - minibar.js and support.js + minibar.js and support.js The latter is also used in a couple of small web apps based on the @@ -127,12 +127,12 @@ Some implementation details:
  • [Added 2010-10-27] Code restructuring:
    • The PGF server API has been moved to its own file: - pgf_online.js. This + pgf_online.js. This allows it to be reused in other applicaitons without importing the entire minibar. It also allows minibar to be used with different server interfaces. minibar.html has been updated to show how you use the new minibar.js and - pgf_online.js. + pgf_online.js.
    • The minibar code has been rewritten to avoid storing state information in the document tree and accessing it by referring to named document elements. The code now also avoids using string literals containing @@ -144,9 +144,9 @@ Some implementation details:
    • [Added 2011-03-03] Added a button to display word alignment. @@ -217,7 +217,7 @@ Some implementation details:
      -Last modified: Mon Sep 10 00:50:08 CEST 2012 +Last modified: Tue Nov 20 13:41:21 CET 2012
      TH diff --git a/src/www/minibar/example.html b/src/www/minibar/example.html index 7d78a7ef6..5e7814b28 100644 --- a/src/www/minibar/example.html +++ b/src/www/minibar/example.html @@ -7,8 +7,8 @@ h1, h2, h3, small, th { font-family: sans-serif; } div.modtime { float: right; } .modtime { color: #666; white-space: nowrap; } - - + + + diff --git a/src/www/minibar/gf-web-api-examples.html b/src/www/minibar/gf-web-api-examples.html index d2ddc6fc9..516e823ad 100644 --- a/src/www/minibar/gf-web-api-examples.html +++ b/src/www/minibar/gf-web-api-examples.html @@ -47,7 +47,7 @@ The Web Service API page describes the calls supported by the GF web service API. Below, we illustrate these calls by examples, and also show how to make these calls from JavaScript using the API defined in -pgf_online.js. +pgf_online.js.

      Note that pgf_online.js was initially developed @@ -174,6 +174,6 @@ full API.


      -Last modified: Sat Nov 17 18:40:55 CET 2012 +Last modified: Tue Nov 20 13:54:42 CET 2012
      TH
      diff --git a/src/www/minibar/minibar-api.html b/src/www/minibar/minibar-api.html index d65d92652..505c5155a 100644 --- a/src/www/minibar/minibar-api.html +++ b/src/www/minibar/minibar-api.html @@ -46,7 +46,7 @@ This object implements the complete Minibar web app. It is defined in minibar.js. It also uses the Input and Translations objects described below, and some auxiliary functions defined in minibar_support.js -and support.js, so to use it in an +and support.js, so to use it in an HTML file, you would normally include at least the following:
      @@ -54,7 +54,7 @@ HTML file, you would normally include at least the following:
       <script type="text/JavaScript" src="minibar_input.js"></script>
       <script type="text/JavaScript" src="minibar_translations.js"></script>
       <script type="text/JavaScript" src="minibar_support.js"></script>
      -<script type="text/JavaScript" src="support.js"></script>
      +<script type="text/JavaScript" src="../js/support.js"></script>
       

      @@ -111,13 +111,13 @@ It is defined in minibar_input.js. It also uses some auxiliary functions defined in minibar_support.js -and support.js, so to use it in an +and support.js, so to use it in an HTML file, you would normally include at least the following:

       <script type="text/JavaScript" src="minibar_input.js"></script>
       <script type="text/JavaScript" src="minibar_support.js"></script>
      -<script type="text/JavaScript" src="support.js"></script>
      +<script type="text/JavaScript" src="../js/support.js"></script>
       

      Constructor

      @@ -188,13 +188,13 @@ This object displays translations. It is defined in minibar_translations.js. It also uses some auxiliary functions defined in minibar_support.js -and support.js, so to use it in an +and support.js, so to use it in an HTML file, you would normally include at least the following:
       <script type="text/JavaScript" src="minibar_translations.js"></script>
       <script type="text/JavaScript" src="minibar_support.js"></script>
      -<script type="text/JavaScript" src="support.js"></script>
      +<script type="text/JavaScript" src="../js/support.js"></script>
       

      Constructor

      @@ -249,7 +249,7 @@ the user interface:
      -HTML Last modified: Sun Sep 30 17:33:51 CEST 2012 +HTML Last modified: Tue Nov 20 13:44:11 CET 2012
      diff --git a/src/www/minibar/minibar.html b/src/www/minibar/minibar.html index 06938a4b8..df5bfba3a 100644 --- a/src/www/minibar/minibar.html +++ b/src/www/minibar/minibar.html @@ -25,16 +25,16 @@ & Translator] -HTML Last modified: Fri Apr 27 15:53:46 CEST 2012 +HTML Last modified: Tue Nov 20 13:38:35 CET 2012
      - + - + diff --git a/src/www/minibar/minibar_offline.html b/src/www/minibar/minibar_offline.html index 6947c2844..8279c77cf 100644 --- a/src/www/minibar/minibar_offline.html +++ b/src/www/minibar/minibar_offline.html @@ -43,7 +43,7 @@ even when you are offline. | Minibar online] -HTML Last modified: Mon Apr 30 16:01:32 CEST 2012 +HTML Last modified: Tue Nov 20 13:45:07 CET 2012
      TH
      @@ -56,7 +56,7 @@ HTML Last modified: Mon Apr 30 16:01:32 CEST 2012 Last modified: Thu May 27 14:02:42 CEST 2010 +HTML Last modified: Tue Nov 20 13:47:13 CET 2012
      TH
      diff --git a/src/www/minibar/support.js b/src/www/minibar/support.js deleted file mode 100644 index e82f4fc9c..000000000 --- a/src/www/minibar/support.js +++ /dev/null @@ -1,329 +0,0 @@ -/* --- Accessing document elements ------------------------------------------ */ - -function element(id) { - return document.getElementById(id); -} - -/* --- JavaScript tricks ---------------------------------------------------- */ - -// To be able to use object methods that refer to "this" as callbacks -// See section 3.3 of https://github.com/spencertipping/js-in-ten-minutes/raw/master/js-in-ten-minutes.pdf -function bind(f, this_value) { - return function () {return f.apply (this_value, arguments)}; -}; - -// Implement Array.isArray for older browsers that lack it. -// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray -if(!Array.isArray) { - Array.isArray = function (arg) { - return Object.prototype.toString.call(arg) == '[object Array]'; - }; -} - -/* --- JSONP ---------------------------------------------------------------- */ - -// 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/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); -} - -var json = {next:0}; - -// Like jsonp, but instead of passing the name of the callback function, you -// pass the callback function directly, making it possible to use anonymous -// functions. -function jsonpf(url,callback,errorcallback) -{ - var name="callback"+(json.next++); - json[name]=function(x) { delete json[name]; callback(x); } - jsonp(url,"json."+name); -} - -/* --- AJAX ----------------------------------------------------------------- */ - -function GetXmlHttpObject(handler) -{ - var objXMLHttp=null - if (window.XMLHttpRequest) - { - // See http://www.w3.org/TR/XMLHttpRequest/ - // https://developer.mozilla.org/en/xmlhttprequest - objXMLHttp=new XMLHttpRequest() - } - else if (window.ActiveXObject) - { - objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") - } - return objXMLHttp -} - -function ajax_http(method,url,body,callback,errorcallback) { - var http=GetXmlHttpObject() - if (!http) { - var errortext="Browser does not support HTTP Request"; - if(errorcallback) errorcallback(errortext,500) - else alert(errortext) - } - else { - function statechange() { - if (http.readyState==4 || http.readyState=="complete") { - if(http.status<300) callback(http.responseText,http.status); - else if(errorcallback) - errorcallback(http.responseText,http.status, - http.getResponseHeader("Content-Type")); - else alert("Request for "+url+" failed: " - +http.status+" "+http.statusText); - } - } - http.onreadystatechange=statechange; - http.open(method,url,true) - http.send(body) - } - return http -} - -function ajax_http_get(url,callback,errorcallback) { - ajax_http("GET",url,null,callback,errorcallback) -} - -function ajax_http_post(url,formdata,callback,errorcallback) { - ajax_http("POST",url,formdata,callback,errorcallback) - // See https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Using_FormData_objects -} - -// JSON via AJAX -function ajax_http_get_json(url,cont,errorcallback) { - ajax_http_get(url,function(txt){cont(eval("("+txt+")"));}, errorcallback); -} - -function sameOrigin(url) { - var a=empty("a"); - a.href=url; // converts to an absolute URL - return hasPrefix(a.href,location.protocol+"//"+location.host+"/"); -} - -// Use AJAX when possible, fallback to JSONP -function http_get_json(url,cont,errorcallback) { - if(sameOrigin(url)) ajax_http_get_json(url,cont,errorcallback); - else jsonpf(url,cont,errorcallback); -} - -/* --- URL construction ----------------------------------------------------- */ - -function encodeArgs(args) { - var q="" - for(var arg in args) - if(args[arg]!=undefined) - q+="&"+arg+"="+encodeURIComponent(args[arg]); - return q; -} - -/* --- HTML construction ---------------------------------------------------- */ -function text(s) { return document.createTextNode(s); } - -function node(tag,as,ds) { - var n=document.createElement(tag); - for(var a in as) n.setAttribute(a,as[a]); - if(ds) for(var i in ds) n.appendChild(ds[i]); - return n; -} - -function empty(tag,name,value) { - var el=node(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,cs) { return node("div",{id:id},cs); } -function span_id(id) { return empty_id("span",id); } - -function wrap(tag,contents) { - return node(tag,{},Array.isArray(contents) ? contents : [contents]); -} - -function wrap_class(tag,cls,contents) { - return node(tag,{"class":cls}, - contents ? Array.isArray(contents) ? - contents : [contents] : []) -} - -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 dd(contents) { return wrap("dd",contents); } -function li(contents) { return wrap("li",contents); } - -function th(contents) { return wrap("th",contents); } -function td(contents) { return wrap("td",contents); } - -function tr(cells) { return wrap("tr",cells); } - -function button(label,action,key) { - var el=node("input",{"type":"button","value":label},[]); - if(typeof action=="string") el.setAttribute("onclick",action); - else el.onclick=action; - if(key) el.setAttribute("accesskey",key); - return el; -} - -function option(label,value) { - return node("option",{"value":value},[text(label)]); -} - -function hidden(name,value) { - return node("input",{type:"hidden",name:name,value:value},[]) -} - -function tda(cs) { return node("td",{},cs); } - -function img(src) { return empty("img","src",src); } - -/* --- Document modification ------------------------------------------------ */ - -function clear(el) { replaceInnerHTML(el,""); } -function replaceInnerHTML(el,html) { if(el) el.innerHTML=html; } -function replaceChildren(el,newchild) { clear(el); el.appendChild(newchild); } - -function appendChildren(el,ds) { - for(var i in ds) el.appendChild(ds[i]); - return el; -} - -function insertFirst(parent,child) { - parent.insertBefore(child,parent.firstChild); -} - -function insertBefore(el,ref) { ref.parentNode.insertBefore(el,ref); } - -function insertAfter(el,ref) { - ref.parentNode.insertBefore(el,ref.nextSibling); -} - -/* --- Debug ---------------------------------------------------------------- */ - -function debug(s) { - var d=element("debug"); - if(d) d.appendChild(text(s+"\n")) -} - -function show_props(obj, objName) { - var result = ""; - for (var i in obj) { - result += objName + "." + i + " = " + obj[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) { -// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/sort - return a.sort(); - /* // Note: this doesn't work on strings. - for(var i=0;i
      HMTL -Last modified: Fri Oct 5 00:29:39 CEST 2012 +Last modified: Tue Nov 20 13:47:37 CET 2012
      About - - + + -- cgit v1.2.3