load "w2t"; var page = new W2t(); // --------------------------- Calculator --------------------------- object Calculator { static calculator_counter = 0; var myid; var mypage; var value = 0; var op_prefix = undef; method init(_page) { mypage = _page; myid = mypage.getid(); mypage.register_callback("${myid}_action", function(c, op, val) { switch { case not defined op_prefix: value = val; case op_prefix ~== "add": value .+= val; case op_prefix ~== "sub": value .-= val; case op_prefix ~== "mul": value .*= val; case op_prefix ~== "div": value ./= val; case op_prefix ~== "mod": value .%= val; case op_prefix ~== "pow": value .**= val; } op_prefix = op ~== "equal" ? undef : op; page.execute("document.getElementById('${myid}_value').value = $value"); }); mypage.register_callback("${myid}_close", function() { page.dom_remove(myid); }); mypage.dom_appendchild("calcs", <:> :
:

Calculator #${calculator_counter++}

: : : :
); return this; } } push W2t.styles, <:> : .calculator { : background: #aaf; : width: 20%; : height: 20%; : border: groove; : margin: 2%; : padding: 2%; : float: left; : } : .calculator input { : width: 80%; : margin: 10%; : } : .calculator button { : width: 20%; : margin: 1%; : } ; // --------------------------- Startup Page --------------------------- page.register_callback("newcalc", function() { new Calculator(page); }); page.startup = <:> : : : : Simple w2t demo : : : : : Open W2T Console
: Create new calculator :
: : ; page.run();