﻿<!--

Copyright 2008,2009 Maxim Sajin <joox@dapmx.org>

This file is part of Dap Starter Kit.

	Dap Starter Kit is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published 
	by the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Dap Starter Kit 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 Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with Dap Starter Kit. If not, see <http://www.gnu.org/licenses/>.

	Dap Starter-Kit home page: <http://dapmx.org/starter-kit/>.

-->

<htm dapns="dapmx.org/0.1.5/starter-kit/htm.xml">

	<![CDATA[
	
		dapx.htm={

			convert:{
				h	:function(value){return newElemText("h1",value)},
				p	:function(value){return newElemText("p",value)},
				b	:function(value){return newElemText("b",value)},
				i	:function(value){return newElemText("i",value)},
				
				js	:function(script){return eval(unescape(script))},
				ask	:function(message){return prompt(unescape(message))},

				"select-label":function(value){
						var label=newElemText("option",value);
						label.setAttribute("selected","selected");
						label.setAttribute("disabled","disabled");
						return label;
					},
				
				cssurl:function(url){return "url('"+url+"')"}
			},
			
			flatten:{

				nbsp:function(feed){return dapx.htm.join(feed," ")},
				br:function(feed){return dapx.htm.njoin(feed,"br")},

				lbl:function(feed){return dapx.htm.wrap(feed,"label")},
				
				row:function(feed){return dapx.htm.wrap(feed,"td")},				
				
				option:function(feed){
						var option=dapx.htm.elem("option",feed);
						if(option.getAttribute("selected"))
							if(option.getAttribute("selected")==option.getAttribute("value"))option.setAttribute("selected","selected");
							else option.removeAttribute("selected");
						return option;
					},
					
				inputs:function(feed){
						var inputs=[],type="text",tag;
						for(var i=0; i<feed.length; i++)
							if(tag=feed[i].tag)inputs.push(dapx.htm.input(feed[i].value,feed[i].tag,type));
							else type=feed[i].value;
						return inputs;
					}
					
			},
			
			mapper:{
				""	:function(value,alias,node,$){$[alias]=node[alias]},
				"!"	:function(value,alias,node){daPut(node,alias,value)},
				"?"	:function(value,alias,node){(value?enstyle:destyle)(node,alias)},				
				"+"	:function(value,alias,node){if(value)node.setAttribute(alias,alias);else node.removeAttribute(alias)},
				"style"	:function(value,alias,node){node.style[alias]=value},

				"%"	:function(value,alias,node,$){$[alias]=node[value||"value"]},
				
				submit	:function(value,alias,node,$){
							var f=node.form,a;
							if(value instanceof Array)for(var i=value.length;i-->0;)f.appendChild(value[i]); /// inputs can be added right before submit
							else if(f[alias])f[alias].value=value; /// or, a particular input can be altered
							f.submit();
						}
			},

/// private:
			join:function(feed,sep){
					var html=[];
					for(var i in feed)if(feed[i].value)html.push(feed[i].value),html.push(sep);
					return html;
			},

			njoin:function(feed,tag){
					var html=[];
					for(var i in feed)if(feed[i].value)html.push(feed[i].value),html.push(newElem(tag));
					return html;
			},

			wrap:function(feed,tag){
					var row=[];
					if(feed instanceof Array)for(var i in feed){
						var cell=newElemText(tag,feed[i].value);
						if(feed[i].tag)enstyle(cell,feed[i].tag.replace(/,/g," "));
						row.push(cell);
					}else return newElemText(tag,feed);
					return row;
			},

			input:function(value,name,type){
				var input=(type=="textarea")?newElemText("textarea",value):newElem("input");
				input.setAttribute("type",type||"text");
				input.setAttribute("value",value);
				input.setAttribute("title",name);
				input.setAttribute("name",name);
				return input;
			},
			
			elem:function(tag,feed){
				var e=newElem(tag),alias,value;
				for(var i=0;i<feed.length;i++)
					if(value=feed[i].value)
						if(alias=feed[i].tag)e.setAttribute(alias,value);
						else e.appendChild(newText(value));
				return e;
			}

		}
		
	]]>
	
	<br>
		<br/>
	</br>
	
	<nbsp>&amp;nbsp;</nbsp>
	
	<menu>
		<span class="canvas" u=" $?=" d="@submenu ; @menus :#cfg=/samples/menu.xml; @ menus.main.o; ui@mouseover;  $?=">
			<ul class="menu" d="* o@">
				<li d="ui@mouseover" u=" title$?; ">
					<span class="menuitem">
						<a d="! title; attr href"/>
					</span>
					<span d="?? =o; ?=eq $? title">
						<span class="submenu" d=" $?=; ! submenu"/>
					</span>
				</li>
			</ul>
		</span>
	</menu>
	
</htm>