<!doctype html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
<title><%= sys.name %> API 文档</title>
<style type="text/css">
@import url(/res/prism/prism.css);
pre{ margin: 0mm 1cm 0mm 0mm !important; border-radius: 1mm; max-height: 50vh }
body{ font: 12px/2em arial; counter-reset: funcs }
.hide{ display: none }
dl:before{ height: 1px; content: ''; background-color: #ccc; display: block; max-width: 5in; margin-bottom: 2mm }
dl dt{ padding-left: 2mm; color: #777 }
dl dt:before{ content: '方法 ' counter(funcs) '：'; counter-increment: funcs }
dl dt b{ font-size: 1pc; color: #08c }
dl dd tt{ display: inline-block; margin-left: 4mm; color: blue; cursor: pointer; font-family: arial }
dd u{ color: green; cursor: pointer }
dl:hover dd tt:after{ content: '「执行」' }
.mask{ background-color: rgba(0,0,0,0.5); position: fixed; left: 0mm; right: 0mm; top: 0mm; bottom: 0mm }
.form{ margin: calc(50vh - 4cm) auto 0mm; background-color: #fff }
.form { width: 320px; box-shadow: 0mm 0mm 2mm #123; border-radius: 2mm }
.form .cap{ background-color: #ccc; padding: 1mm 3mm; border-radius: 2mm 2mm 0mm 0mm }
.form .btn{ text-align: right; padding: 2mm }
.form .btn div{ display: inline-block; vertical-align: middle; padding: 0mm 3mm }
.form .btn div{ border-radius: 1mm; background-color: #ccc; margin: 0mm 1mm; cursor: default }
.form .btn .ok{ background-color: #29f; color: #fff }
.ipt{ padding: 2mm 4mm 2mm 0mm; overflow: auto; max-height: 30vh }
.ipt div{ padding: 1mm 0mm }
.ipt span{ float: left; white-space: nowrap; width: 18mm; text-align: right; padding: 2px 0mm; overflow: hidden; text-overflow: ellipsis }
.ipt p{ margin: 0mm 0mm 0mm 2cm; border: 1px solid #ccc; border-radius: 1mm; padding: 2px 2mm }
.ipt p input{ width: 100%; border: none }
</style></head><body>
<h1><%= sys.name %> API 文档</h1>
<%= (this.Memo || []).join("<br />") %><%
var showSource = func => {
	if(sys.hideApiFunc) return "function() { [ native code ] }";
	// 判断最后一个 } 字符前面的 tab 数量
	func = func.replace(/(^\s+|\s+$)/g, "");
	var tabs = func.match(/\t*\}$/)?.[0];
	if(!tabs) return func;
	if(tabs.length - 1 < 1) return func;
	var reg = new RegExp("\\n\\t{" + (tabs.length - 1) + "}", "g");
	return func.replace(reg, "\n");
}
for(var x in this) {
	if(x.slice(-3) != "Doc") continue;
	var doc = this[x], intro = doc.slice(2);
	var apiname = x.slice(0, -3); %>
<dl>
	<dt><b><%= apiname %></b>: <%= doc[0] %></dt>
	<dd>@form { <%= doc[1] %> }</dd><% for(var y in intro) { if("function" == typeof intro[y]) continue; %>
	<dd><%= intro[y] %></dd><% } %>
	<dd>
		[<u>检视源码</u>] <tt></tt>
		<div class="hide"><pre><code class="language-javascript"><%= showSource(this[apiname.toLowerCase()] + "") %></code></pre></div>
	</dd>
</dl><% } %>
<div class="win hide">
	<div class="form">
		<div class="cap">参数录入</div>
		<div class="ipt"></div>
		<div class="btn">
			<div class="ok">执行</div>
			<div class="no">取消</div>
		</div>
	</div>
</div>
<script type="text/javascript">
var win = new function() {
	var mask = document.querySelector(".win");
	var form = mask.querySelector(".form");
	var btn = mask.querySelectorAll(".btn div");
	var ipt = mask.querySelector(".ipt"), me = this;
	this.show = function(par, e, store, data, op) {
		ipt.innerHTML = "";
		var cc = (e.target.result || new Object).data || new Object;
		this.ipts = new Array;
		for(var i = 0; i < par.length; i++) {
			var k = par[i].replace(/[\[\s\]]/g, "");
			if(!k) continue;
			var tag = document.createElement("input");
			tag.placeholder = k; tag.value = cc[k] || "";
			var row = document.createElement("div");
			var p = document.createElement("p");
			var span = document.createElement("span");
			row.appendChild(span).innerHTML = k;
			p.appendChild(tag); row.appendChild(p);
			ipt.appendChild(row); this.ipts.push(tag);
		}
		mask.className = "mask";
		this.data = data; this.op = op;
	};
	btn[0].onclick = function() {
		var cc = new Object;
		for(var i = 0; i < me.ipts.length; i++) {
			var tag = me.ipts[i];
			if(!tag.value) continue;
			var k = tag.placeholder;
			cc[k] = me.data[k] = tag.value;
		}
		doPost(me.data, me.op);
		mask.className = "hide";
		if(!me.ipts.length) return;
		var store = db.result.transaction(["ApiValues"], "readwrite").objectStore("ApiValues");
		store.get(me.op).onsuccess = function(e) {
			store.put({ api: me.op, data: cc });
		};
	};
	btn[1].onclick = function() { mask.className = "hide"; };
};
document.querySelectorAll("dd tt").forEach(function(x) {
	var dd = x.parentNode.parentNode.querySelectorAll("dd");
	var op = x.parentNode.parentNode.querySelector("dl b").innerHTML;
	var view = x.parentNode.querySelector("u");
	var code = x.parentNode.querySelector(".hide");
	view.onclick = function() {
		var isHide = code.className == "hide";
		view.innerHTML = isHide ? "隐藏源码" : "检视源码";
		code.className = isHide ? "show" : "hide";
	};
	var par = new Array;
	dd.forEach(function(r){
		var rs = r.innerHTML.match(/\@form {\s*(.+?)\s*}/);
		if(rs) par = rs[1].split(/[\s\,]+/);
	});
	x.onclick = function() {
		var form = new Object;
		var store = db.result.transaction(["ApiValues"], "readwrite").objectStore("ApiValues");
		store.get(op).onsuccess = function(e) {
			return win.show(par, e, store, form, op);
			var cc = (e.target.result || new Object).data || new Object;
			for(var i = 0; i < par.length; i++) {
				var k = par[i].replace(/[\[\s\]]/g, "");
				if(!k) continue;
				var val = prompt(k, cc[k] || "");
				if(val === null) continue;
				form[k] = cc[k] = val;
			}
			doPost(form, op);
			if(!par.length) return;
			store.put({ api: op, data: cc });
		};
	};
});
function doPost(form, op) {
	xhr.open("POST", "<%= sys.apipath || '?r=' %>" + op, true);
	xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xhr.onload = function(){
		var json = xhr.responseText;
		try{ json = JSON.parse(json); }
		catch(err) { console.log("Not JSON !!!", err.message); }
		finally{ console.log(json); }
		alert(xhr.responseText);
	};
	xhr.onerror = function(err){ alert(JSON.stringify(err)); };
	xhr.send(toForm(form));
}
function toForm(form) {
	if("object" != typeof form) return form;
	if(!form) return form;
	var arr = new Array;
	for(var x in form) arr.push(x + "=" + encodeURIComponent(form[x]));
	return arr.join("&");
}
var xhr = new XMLHttpRequest;
var db = indexedDB.open(location.pathname.slice(10));
db.onupgradeneeded = function() { db.result.createObjectStore('ApiValues', { keyPath: "api" }); };
</script><script src="/res/prism/prism.js"></script></body></html>