/*
 *  SPL - The SPL Programming Language
 *  Copyright (C) 2006  Clifford Wolf <clifford@clifford.at>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  w2tdemo.webspl: Simple example for the w2t module.
 */


load "w2t";

var page = new W2t();

var xpos = 50;

page.register_callback("clicked_on_box",
function(xmlnode, word1, word2)
{
	debug "Pushed the button: $word1 $word2";

	var newboxid = page.getid();

	function newboxclick() {
		page.response_add(<:>
			: <dom method="remove" on="$newboxid" />
		</>);
	}

	page.register_callback('${newboxid}_click', newboxclick);
	page.response_add(<:>
		: <dom method="appendchild" on="root">
		:	<rect xmlns="http://www.w3.org/2000/svg"
		:		id="$newboxid" x="$xpos" y="30"
		:		width="10" height="10" fill="blue"
		:		w2t:callbacks="${newboxid}_click"
		:		onclick="w2t_callback('${newboxid}_click')" />
		: </dom>
	</>);

	xpos += 20;
});

// Set startup page
page.startup = <:>
	: <?xml version="1.0" ?>
	: <svg xmlns="http://www.w3.org/2000/svg" xmlns:w2t="$page.w2t_ns" id="root">
	:
	: <script><![CDATA[
	:
	: ${page.getscripts()}
	:
	: ]]></script>
	:
	: <rect x="30" y="30" width="10" height="10" fill="red"
	:	onclick="w2t_console_open()" />
	:
	: <rect x="100" y="100" width="100" height="100" rx="10" ry="10"
	: 	fill="yellow" stroke="navy" stroke-width="10"
	:	w2t:callbacks="clicked_on_box"
	:	onclick="w2t_callback('clicked_on_box', ['hello', 'world'])" />
	:
	: </svg>
</>;

page.run();

