return page history
α-wwwiki
::
history/console/20130730-081037.txt
editor : alpha [82.249.90.43] 2013/07/30 08:10:37 _h1 console _p A template for creating a javascript console integrated in the wiki page. _h3 template {pre °° 1) define the output console : {pre {@ id="console" }} // could be any div with various styles 2) define the submit button : {input // start input {@ type="submit" // button's type (could be text) value="do something" // button's name onclick=" // start onclick •• // start hiding curly braces (from any parser evaluation) ... function doSomething () { something } // any javascript ... getId('console').innerHTML = doSomething(); // display in console this.disabled = true; // disable submit button •• // end hiding curly braces " // end onclick } // end attributes } // end input °°} _h3 example _p Computing the partition of the unity [0,1]. Open the editor to see the code. {input {@ type="submit" value="unity" onclick="°° function unity (n) { var N = Math.pow(2, n); var str = alpha.doLoop('{h4 ' + n + '}'); for (var i=0; i< N+1; i++) { str += ' | ' + i/N; } return str + ' | '; } function table (n) { var str= ''; for (var i=0; i< n; i++) { str += '\n' + unity(i); } return str; } getId('console').innerHTML = table(10); this.disabled = true; °°"}} {div {@ id="console" style="white-space:pre-wrap; font:normal 0.8em courier new;" } }