mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 01:04:06 +08:00
opt js
This commit is contained in:
parent
87dd24f4b8
commit
9b6e049191
@ -1,4 +1,2 @@
|
||||
highlight shyNumber ctermfg=magenta
|
||||
|
||||
syn match shyNumber "-\=\<\d\+\>#\="
|
||||
|
||||
highlight javaScriptComment cterm=reverse ctermfg=yellow
|
||||
highlight Comment cterm=reverse ctermfg=yellow
|
||||
|
@ -18,14 +18,14 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
}}, "favicon": "favicon.ico", "styles": []interface{}{
|
||||
"example.css", "chat.css",
|
||||
}},
|
||||
map[string]interface{}{"name": "header",
|
||||
"tmpl": "fieldset", "view": "Header", "init": "initHeader",
|
||||
"title": "shylinux 天行健,君子以自强不息",
|
||||
},
|
||||
map[string]interface{}{"name": "login",
|
||||
"tmpl": "fieldset", "view": "Login dialog", "init": "initLogin",
|
||||
"ctx": "web.chat", "cmd": "login",
|
||||
},
|
||||
map[string]interface{}{"name": "header",
|
||||
"tmpl": "fieldset", "view": "Header", "init": "initHeader",
|
||||
"title": "shylinux 天行健,君子以自强不息",
|
||||
},
|
||||
|
||||
map[string]interface{}{"name": "ocean",
|
||||
"tmpl": "fieldset", "view": "Ocean dialog", "init": "initOcean",
|
||||
|
@ -1,9 +1,10 @@
|
||||
|
||||
{init: function(page, pane, plugin, field, option, output) {
|
||||
kit.Log("hello world")
|
||||
plugin.Run = function(event, args, cb) {
|
||||
field.Run(event, ["share", args[0]], function(url) {
|
||||
kit.AppendChild(output, [{img: [url]}])
|
||||
})
|
||||
{init: function(run, field, option, output) {
|
||||
return {
|
||||
Run: function(event, args, cb) {
|
||||
run(event, ["share", args[0]], function(url) {
|
||||
kit.AppendChilds(output, [{img: [url]}])
|
||||
typeof cb == "function" && cb({})
|
||||
})
|
||||
},
|
||||
}
|
||||
}}
|
||||
|
@ -1,4 +1,5 @@
|
||||
page = Page({
|
||||
Page({
|
||||
check: true,
|
||||
conf: {refresh: 1000, border: 4, layout: {header:30, river:120, action:180, source:60, storm:100, footer:30}},
|
||||
onlayout: function(event, sizes) {
|
||||
var page = this
|
||||
@ -78,6 +79,20 @@ page = Page({
|
||||
break
|
||||
}
|
||||
},
|
||||
onaction: {
|
||||
title: function(event, item, value) {
|
||||
ctx.Search({"river": page.river.Pane.which.get(), "storm": page.storm.Pane.which.get(), "layout": page.action.Pane.Layout()})
|
||||
},
|
||||
user: function(event, item, value) {
|
||||
var name = kit.prompt("new name")
|
||||
name && page.login.Pane.Run(["rename", name], function(msg) {
|
||||
page.header.Pane.State("user", name)
|
||||
})
|
||||
},
|
||||
logout: function(event, item, value) {
|
||||
kit.confirm("logout?") && page.login.Pane.Exit()
|
||||
},
|
||||
},
|
||||
|
||||
initOcean: function(page, field, option, output) {
|
||||
var table = kit.AppendChild(output, "table")
|
||||
@ -115,37 +130,35 @@ page = Page({
|
||||
event.key == "Enter" && this.nextSibling.click()
|
||||
|
||||
}]}, {button: ["create", function(event) {
|
||||
if (!ui.name.value) {
|
||||
ui.name.focus()
|
||||
return
|
||||
}
|
||||
if (!ui.name.value) {ui.name.focus(); return}
|
||||
|
||||
var cmd = ["spawn", "", ui.name.value]
|
||||
ui.list.querySelectorAll("pre").forEach(function(item) {
|
||||
cmd.push(item.innerText)
|
||||
var list = kit.Selector(ui.list, "pre", function(item) {return item.innerText})
|
||||
if (list.length == 0) {kit.alert("请添加组员"); return}
|
||||
|
||||
field.Pane.Create(ui.name.value, list)
|
||||
|
||||
}]}, {name: "list", view: ["list"]},
|
||||
]}])
|
||||
return {
|
||||
Append: function(msg) {
|
||||
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, row, i, tr, event) {
|
||||
tr.className = "hidden"
|
||||
var uis = kit.AppendChild(ui.list, [{text: [row.key], click: function(event) {
|
||||
tr.className = "normal", uis.last.parentNode.removeChild(uis.last)
|
||||
}}])
|
||||
})
|
||||
if (cmd.length == 3) {
|
||||
kit.alert("请添加组员")
|
||||
return
|
||||
}
|
||||
|
||||
field.Pane.Run(cmd, function(msg) {
|
||||
},
|
||||
Clear: function(name) {
|
||||
table.innerHTML = "", ui.list.innerHTML = "", ui.name.value = name, ui.name.focus()
|
||||
},
|
||||
Create: function(name, list) {
|
||||
field.Pane.Run(["spawn", "", name].concat(list), function(msg) {
|
||||
page.river.Pane.Show()
|
||||
field.Pane.Show()
|
||||
})
|
||||
}]}, {name: "list", view: ["list"]},
|
||||
]}])
|
||||
|
||||
return {
|
||||
},
|
||||
Show: function() {
|
||||
this.ShowDialog() && (table.innerHTML = "", ui.list.innerHTML = "", ui.name.value = "good", ui.name.focus(), this.Run([], function(msg) {
|
||||
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, row, i, tr, event) {
|
||||
tr.className = "hidden"
|
||||
var uis = kit.AppendChild(ui.list, [{text: [row.key], click: function(event) {
|
||||
tr.className = "normal", uis.last.parentNode.removeChild(uis.last)
|
||||
}}])
|
||||
})
|
||||
}))
|
||||
this.Dialog() && (this.Clear("good"), this.Run([], this.Append))
|
||||
},
|
||||
Action: {
|
||||
"取消": function(event) {
|
||||
@ -179,40 +192,35 @@ page = Page({
|
||||
}
|
||||
},
|
||||
initTarget: function(page, field, option, output) {
|
||||
var river = ""
|
||||
var which = {}
|
||||
var river = "", which = {}
|
||||
output.DisplayUser = true
|
||||
output.DisplayTime = true
|
||||
return {
|
||||
Send: function(type, text, cb) {var pane = this
|
||||
pane.Run([river, "flow", type, text], function(msg) {
|
||||
pane.Show(), typeof cb == "function" && cb(msg)
|
||||
})
|
||||
},
|
||||
Stop: function() {
|
||||
return field.style.display == "none"
|
||||
},
|
||||
Show: function(i) {var pane = this
|
||||
field.Pane.Back(river, output)
|
||||
|
||||
var foot = page.footer.Pane, cmds = [river, "brow", i||which[river]||0]
|
||||
cmds[2] || (output.innerHTML = ""), pane.Tickers(page.conf.refresh, cmds, function(line, index, msg) {
|
||||
pane.Append("", line, ["text"], "index", function(line, index, event, args, cbs) {
|
||||
page.action.Pane.Core(event, line, args, cbs)
|
||||
})
|
||||
foot.State("ntxt", which[river] = cmds[2] = parseInt(line.index)+1)
|
||||
})
|
||||
},
|
||||
Listen: {
|
||||
river: function(value, old) {
|
||||
field.Pane.Save(river, output)
|
||||
river = value, field.Pane.Show()
|
||||
},
|
||||
},
|
||||
Stop: function() {
|
||||
return field.style.display == "none"
|
||||
},
|
||||
Show: function(i) {
|
||||
field.Pane.Back(river, output)
|
||||
var pane = this, foot = page.footer.Pane
|
||||
var cmds = [river, "brow", i||which[river]||0]
|
||||
cmds[2] || (output.innerHTML = ""), pane.Times(page.conf.refresh, cmds, function(line, index, msg) {
|
||||
pane.Append("", line, ["text"], "index", function(line, index, event, args, cbs) {
|
||||
var text = JSON.parse(line.text)
|
||||
page.action.Pane.Run([text.river, text.storm, text.action].concat(args), function(msg) {
|
||||
typeof cbs == "function" && cbs(msg)
|
||||
})
|
||||
})
|
||||
foot.State("text", which[river] = cmds[2] = parseInt(line.index)+1)
|
||||
})
|
||||
},
|
||||
Send: function(type, text, cb) {
|
||||
var pane = this
|
||||
pane.Run([river, "flow", type, text], function(msg) {
|
||||
pane.Show(), typeof cb == "function" && cb(msg)
|
||||
})
|
||||
},
|
||||
}
|
||||
},
|
||||
initSource: function(page, field, option, output) {
|
||||
@ -222,8 +230,13 @@ page = Page({
|
||||
}, "onkeydown": function(event) {
|
||||
event.key == "Enter" && !event.shiftKey && event.preventDefault()
|
||||
}}}])
|
||||
|
||||
return {
|
||||
Select: function() {
|
||||
ui.first.focus()
|
||||
},
|
||||
Clear: function(value) {
|
||||
ui.first.value = ""
|
||||
},
|
||||
Size: function(width, height) {
|
||||
field.style.display = (width<=0 || height<=0)? "none": "block"
|
||||
field.style.width = width+"px"
|
||||
@ -231,62 +244,59 @@ page = Page({
|
||||
ui.first.style.width = (width-7)+"px"
|
||||
ui.first.style.height = (height-7)+"px"
|
||||
},
|
||||
Select: function() {
|
||||
ui.first.focus()
|
||||
},
|
||||
Clear: function(value) {
|
||||
ui.first.value = ""
|
||||
},
|
||||
}
|
||||
},
|
||||
initAction: function(page, field, option, output) {
|
||||
var river = "", storm = 0, input = "", share = ""
|
||||
|
||||
output.DisplayRaw = true
|
||||
return {
|
||||
Listen: {
|
||||
river: function(value, old) {
|
||||
river = value
|
||||
},
|
||||
storm: function(value, old) {
|
||||
field.Pane.Save(river+storm, output)
|
||||
storm = value, field.Pane.Show()
|
||||
},
|
||||
source: function(value, old) {
|
||||
input = value, kit.Log(value)
|
||||
},
|
||||
target: function(value, old) {
|
||||
share = value, kit.Log(value)
|
||||
},
|
||||
},
|
||||
Show: function() {
|
||||
if (field.Pane.Back(river+storm, output)) {
|
||||
return
|
||||
}
|
||||
|
||||
this.Update([river, storm], "plugin", ["node", "name"], "index", false, function(line, index, event, args, cbs) {
|
||||
if (args.length > 0 && args[0] == "share") {
|
||||
Core: function(event, line, args, cbs) {
|
||||
var plugin = event.Plugin || {}, engine = {
|
||||
share: function(args) {
|
||||
typeof cbs == "function" && cbs(ctx.Share({"group": option.dataset.group, "name": option.dataset.name, "cmds": [
|
||||
line.group, line.index, args[1]||"",
|
||||
river, line.group, line.index, args[1]||"",
|
||||
]}))
|
||||
return
|
||||
}
|
||||
|
||||
var plugin = event.Plugin || {}
|
||||
var meta = plugin && plugin.Field && plugin.Field.Meta || {}
|
||||
event.shiftKey? page.target.Pane.Send("field", plugin.Format()):
|
||||
field.Pane.Run([meta.river||river, meta.storm||storm, meta.action||index].concat(args), function(msg) {
|
||||
return true
|
||||
},
|
||||
_msg: function(msg) {
|
||||
if (msg) {
|
||||
var text = plugin? plugin.Reveal(msg): ""
|
||||
text && event.ctrlKey && page.target.Pane.Send(text[0], text[1])
|
||||
typeof cbs == "function" && cbs(msg)
|
||||
} else {
|
||||
page.target.Pane.Send("field", plugin.Format())
|
||||
}
|
||||
},
|
||||
_run: function() {
|
||||
var meta = plugin && plugin.target && plugin.target.Meta || {}
|
||||
field.Pane.Run([meta.river||river, meta.storm||storm, meta.action||index].concat(args), function(msg) {
|
||||
engine._msg(msg), typeof cbs == "function" && cbs(msg)
|
||||
})
|
||||
},
|
||||
}
|
||||
if (args.length > 0 && engine[args[0]] && engine[args[0]](args)) {return}
|
||||
event.shiftKey? engine._msg(): engine._run()
|
||||
},
|
||||
Show: function() {var pane = this
|
||||
if (field.Pane.Back(river+storm, output)) {return}
|
||||
|
||||
this.Clear(), this.Update([river, storm], "plugin", ["node", "name"], "index", false, function(line, index, event, args, cbs) {
|
||||
pane.Core(event, line, args, cbs)
|
||||
})
|
||||
},
|
||||
Layout: function(name) {
|
||||
var layout = field.querySelector("select.layout")
|
||||
name && this.Action[layout.value = name](null, layout.value)
|
||||
name && this.Action[layout.value = name](window.event, layout.value)
|
||||
return layout.value
|
||||
},
|
||||
Listen: {
|
||||
river: function(value, old) {river = value},
|
||||
storm: function(value, old) {
|
||||
field.Pane.Save(river+storm, output)
|
||||
storm = value, field.Pane.Show()
|
||||
},
|
||||
source: function(value, old) {input = value},
|
||||
target: function(value, old) {share = value},
|
||||
},
|
||||
Action: {
|
||||
"聊天": function(event, value) {
|
||||
page.onlayout(event, page.conf.layout)
|
||||
@ -359,23 +369,14 @@ page = Page({
|
||||
},
|
||||
Button: [["layout", "聊天", "办公", "工作", "最高", "最宽", "最大"], "",
|
||||
"刷新", "清空", "并行", "串行", "",
|
||||
"添加", "删除", "加参", "减参", "",
|
||||
["display", "表格", "编辑", "绘图"],
|
||||
"添加", "删除", "加参", "减参", "",
|
||||
],
|
||||
}
|
||||
},
|
||||
initStorm: function(page, field, option, output) {
|
||||
var river = ""
|
||||
return {
|
||||
Listen: {
|
||||
river: function(value, old) {
|
||||
field.Pane.which.set(""), river = value, field.Pane.Show()
|
||||
},
|
||||
},
|
||||
Show: function(which) {
|
||||
this.which.get("") == which && page.action.Pane.Show()
|
||||
this.Update([river], "text", ["key", "count"], "key", which||ctx.Search("storm")||true)
|
||||
},
|
||||
Next: function() {
|
||||
var next = output.querySelector("div.item.select").nextSibling
|
||||
next? next.click(): output.firstChild.click()
|
||||
@ -384,6 +385,15 @@ page = Page({
|
||||
var prev = output.querySelector("div.item.select").previousSibling
|
||||
prev? prev.click(): output.lastChild.click()
|
||||
},
|
||||
Show: function(which) {
|
||||
this.which.get("") == which && page.action.Pane.Show()
|
||||
output.innerHTML = "", this.Update([river], "text", ["key", "count"], "key", which||ctx.Search("storm")||true)
|
||||
},
|
||||
Listen: {
|
||||
river: function(value, old) {
|
||||
field.Pane.which.set(""), river = value, field.Pane.Show()
|
||||
},
|
||||
},
|
||||
Action: {
|
||||
"创建": function(event) {
|
||||
page.steam.Pane.Show()
|
||||
@ -434,141 +444,79 @@ page = Page({
|
||||
td && td.click()
|
||||
return true
|
||||
}
|
||||
})
|
||||
event.key == "Enter" && this.nextSibling.click()
|
||||
}), event.key == "Enter" && this.nextSibling.click()
|
||||
|
||||
}]}, {button: ["create", function(event) {
|
||||
if (!ui.name.value) {
|
||||
ui.name.focus()
|
||||
return
|
||||
}
|
||||
if (!ui.name.value) {ui.name.focus(); return}
|
||||
|
||||
var cmd = [river, "spawn", ui.name.value]
|
||||
ui.list.querySelectorAll("tr").forEach(function(item) {
|
||||
cmd.push(item.dataset.pod)
|
||||
cmd.push(item.dataset.group)
|
||||
cmd.push(item.dataset.index)
|
||||
cmd.push(item.dataset.name)
|
||||
var list = []
|
||||
kit.Selector(ui.list, "tr", function(item) {
|
||||
list.push(item.dataset.pod)
|
||||
list.push(item.dataset.group)
|
||||
list.push(item.dataset.index)
|
||||
list.push(item.dataset.name)
|
||||
})
|
||||
if (list.length == 0) {kit.alert("请添加命令"); return}
|
||||
|
||||
if (cmd.length == 4) {
|
||||
kit.alert("请添加命令")
|
||||
return
|
||||
}
|
||||
field.Pane.Create(ui.name.value, list)
|
||||
|
||||
field.Pane.Run(cmd, function(msg) {
|
||||
field.Pane.Show()
|
||||
page.storm.Pane.Show(ui.name.value)
|
||||
})
|
||||
}]}, {name: "list", view: ["list", "table"]},
|
||||
]}])
|
||||
|
||||
return {
|
||||
Listen: {
|
||||
river: function(value, old) {
|
||||
river = value
|
||||
},
|
||||
Append: function(com, pod) {var pane = field.Pane
|
||||
var last = kit.AppendChild(ui.list, [{
|
||||
dataset: {pod: pod.node, group: com.key, index: com.index, name: com.name},
|
||||
row: [com.key, com.index, com.name, com.help],
|
||||
click: function(event) {last.parentNode.removeChild(last)},
|
||||
}]).last
|
||||
},
|
||||
Show: function() {
|
||||
this.ShowDialog() && (table.innerHTML = "", ui.name.value = "nice", this.Run([river], function(msg) {
|
||||
kit.AppendTable(table, ctx.Table(msg), ["user", "node"], function(value, key, pod, i, tr, event) {
|
||||
var old = table.querySelector("tr.select")
|
||||
tr.className = "select", old && (old.className = "normal"), field.Pane.Run([river, pod.user, pod.node], function(msg) {
|
||||
device.innerHTML = "", kit.AppendTable(device, ctx.Table(msg), ["key", "index", "name", "help"], function(value, key, com, i, tr, event) {
|
||||
var last = kit.AppendChild(ui.list, [{type: "tr", list: [
|
||||
{text: [com.key, "td"]}, {text: [com.index, "td"]}, {text: [com.name, "td"]}, {text: [com.help, "td"]},
|
||||
], dataset: {pod: pod.node, group: com.key, index: com.index, name: com.name}, click: function(event) {
|
||||
last.parentNode.removeChild(last)
|
||||
}}]).last
|
||||
})
|
||||
})
|
||||
Update: function(list, pod) {var pane = field.Pane
|
||||
device.innerHTML = "", kit.AppendTable(device, list, ["key", "index", "name", "help"], function(value, key, com, i, tr, event) {
|
||||
pane.Append(com, pod)
|
||||
})
|
||||
},
|
||||
Select: function(list) {var pane = field.Pane
|
||||
table.innerHTML = "", kit.AppendTable(table, list, ["user", "node"], function(value, key, pod, i, tr, event) {
|
||||
var old = table.querySelector("tr.select")
|
||||
tr.className = "select", old && (old.className = "normal"), pane.Run([river, pod.user, pod.node], function(msg) {
|
||||
pane.Update(ctx.Table(msg), pod)
|
||||
})
|
||||
table.querySelector("td").click()
|
||||
ui.name.focus()
|
||||
}))
|
||||
}), table.querySelector("td").click()
|
||||
ui.name.value = "nice", ui.name.focus()
|
||||
},
|
||||
Create: function(name, list) {
|
||||
field.Pane.Run([river, "spawn", name].concat(list), function(msg) {
|
||||
field.Pane.Show(), page.storm.Pane.Show(name)
|
||||
})
|
||||
},
|
||||
Show: function() {var pane = field.Pane
|
||||
pane.Dialog() && pane.Run([river], function(msg) {
|
||||
pane.Select(ctx.Table(msg))
|
||||
})
|
||||
},
|
||||
Listen: {
|
||||
river: function(value, old) {river = value},
|
||||
},
|
||||
Action: {
|
||||
"取消": function(event) {
|
||||
field.Pane.Show()
|
||||
},
|
||||
"取消": function(event) {field.Pane.Show()},
|
||||
"清空": function(event) {ui.list.innerHTML = ""},
|
||||
"全选": function(event) {
|
||||
ui.list.innerHTML = "", device.querySelectorAll("tr").forEach(function(item) {
|
||||
item.firstChild.click()
|
||||
})
|
||||
},
|
||||
"清空": function(event) {
|
||||
ui.list.innerHTML = ""
|
||||
},
|
||||
},
|
||||
Button: ["取消", "全选", "清空"],
|
||||
Button: ["取消", "清空", "全选"],
|
||||
}
|
||||
},
|
||||
init: function(page) {
|
||||
page.onlayout(null, page.conf.layout)
|
||||
page.onlayout(window.event, page.conf.layout)
|
||||
page.action.Pane.Layout(ctx.Search("layout")? ctx.Search("layout"): kit.isMobile? "办公": "工作")
|
||||
page.footer.Pane.Order({"ncmd": "", "text": "", ":":""}, kit.isMobile? ["ncmd", "text"]: ["ncmd", "text", ":"], function(event, item, value) {})
|
||||
page.footer.Pane.Order({"ncmd": "", "ntxt": "", ":":""}, kit.isMobile? ["ncmd", "ntxt"]: ["ncmd", "ntxt", ":"], function(event, item, value) {})
|
||||
page.header.Pane.Order({"logout": "logout", "user": ""}, ["logout", "user"], function(event, item, value) {
|
||||
switch (item) {
|
||||
case "title":
|
||||
ctx.Search({"river": page.river.Pane.which.get(), "storm": page.storm.Pane.which.get(), "layout": page.action.Pane.Layout()})
|
||||
break
|
||||
case "user":
|
||||
var name = kit.prompt("new name")
|
||||
name && page.login.Pane.Run(["rename", name], function(msg) {
|
||||
page.header.Pane.State("user", name)
|
||||
})
|
||||
break
|
||||
case "logout":
|
||||
kit.confirm("logout?") && page.login.Pane.Exit()
|
||||
break
|
||||
default:
|
||||
}
|
||||
})
|
||||
false && kit.isWeiXin && page.login.Pane.Run(["weixin"], function(msg) {
|
||||
page.Include([
|
||||
"https://res.wx.qq.com/open/js/jweixin-1.4.0.js",
|
||||
"/static/librarys/weixin.js",
|
||||
], function(event) {
|
||||
wx.error(function(res){})
|
||||
wx.ready(function(){
|
||||
page.getLocation = function(cb) {
|
||||
wx.getLocation({success: function (res) {
|
||||
cb(res)
|
||||
}})
|
||||
}
|
||||
page.openLocation = function(latitude, longitude, name) {
|
||||
wx.openLocation({latitude: parseFloat(latitude), longitude: parseFloat(longitude), name:name||"here"})
|
||||
}
|
||||
|
||||
wx.getNetworkType({success: function (res) {}})
|
||||
wx.getLocation({success: function (res) {
|
||||
page.footer.Pane.State("site", parseInt(res.latitude*10000)+","+parseInt(res.longitude*10000))
|
||||
}})
|
||||
})
|
||||
wx.config({
|
||||
appId: msg.appid[0],
|
||||
timestamp: msg.timestamp[0],
|
||||
nonceStr: msg.nonce[0],
|
||||
signature: msg.signature[0],
|
||||
jsApiList: [
|
||||
"scanQRCode",
|
||||
"chooseImage",
|
||||
"closeWindow",
|
||||
"openAddress",
|
||||
"getNetworkType",
|
||||
"getLocation",
|
||||
"openLocation",
|
||||
]
|
||||
})
|
||||
})
|
||||
})
|
||||
page.login.Pane.Run([], function(msg) {
|
||||
if (msg.result && msg.result[0]) {
|
||||
page.header.Pane.State("user", msg.nickname[0])
|
||||
page.footer.Pane.State("ip", msg.remote_ip[0])
|
||||
page.river.Pane.Show()
|
||||
return
|
||||
}
|
||||
page.login.Pane.ShowDialog(1, 1)
|
||||
page.onaction[item] && page.onaction[item](event, item, value)
|
||||
})
|
||||
page.river.Pane.Show()
|
||||
},
|
||||
})
|
||||
|
@ -7,19 +7,16 @@ function Meta(target, obj) {
|
||||
var id = 1
|
||||
var conf = {}, conf_cb = {}
|
||||
var sync = {}
|
||||
var cache = []
|
||||
return {
|
||||
__proto__: obj,
|
||||
Target: target,
|
||||
ID: function() {
|
||||
return id++
|
||||
},
|
||||
target: target,
|
||||
ID: function() {return id++},
|
||||
Conf: function(key, value, cb) {
|
||||
if (key == undefined) {
|
||||
return conf
|
||||
}
|
||||
if (cb != undefined) {
|
||||
conf_cb[key] = cb
|
||||
}
|
||||
if (key == undefined) {return conf}
|
||||
|
||||
cb != undefined && (conf_cb[key] = cb)
|
||||
|
||||
if (value != undefined) {
|
||||
var old = conf[key]
|
||||
conf[key] = value
|
||||
@ -30,26 +27,14 @@ function Meta(target, obj) {
|
||||
Sync: function(m) {
|
||||
var meta = m, data = "", list = []
|
||||
return sync[m] || (sync[m] = {
|
||||
change: function(cb) {
|
||||
list.push(cb)
|
||||
return list.length-1
|
||||
},
|
||||
eq: function(value) {
|
||||
return data == value
|
||||
},
|
||||
neq: function(value) {
|
||||
return data != value
|
||||
},
|
||||
get: function() {
|
||||
return data
|
||||
},
|
||||
change: function(cb) {list.push(cb); return list.length-1},
|
||||
eq: function(value) {return data == value},
|
||||
neq: function(value) {return data != value},
|
||||
get: function() {return data},
|
||||
set: function(value, force) {
|
||||
if (value == undefined) {
|
||||
return
|
||||
}
|
||||
if (value == data && !force) {
|
||||
return value
|
||||
}
|
||||
if (value == undefined) {return}
|
||||
if (value == data && !force) {return value}
|
||||
|
||||
old_value = data, data = value
|
||||
meta && kit.Log(meta, value, old_value)
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
@ -93,7 +78,7 @@ function Meta(target, obj) {
|
||||
if (!text.name) {
|
||||
return {}
|
||||
}
|
||||
var id = "plugin"+page.ID()
|
||||
var id = "plugin"+this.ID()
|
||||
list.push({view: [text.view+" item", "fieldset", "", "field"], data: {id: id, Run: cb}, list: [
|
||||
{text: [text.name+"("+text.help+")", "legend"]},
|
||||
{view: ["option", "form", "", "option"], list: [{type: "input", style: {"display": "none"}}]},
|
||||
@ -113,6 +98,27 @@ function Meta(target, obj) {
|
||||
ui.field && (ui.field.Meta = text)
|
||||
return ui
|
||||
},
|
||||
Save: function(name, output) {
|
||||
var temp = document.createDocumentFragment()
|
||||
while (output.childNodes.length>0) {
|
||||
var item = output.childNodes[0]
|
||||
item.parentNode.removeChild(item)
|
||||
temp.appendChild(item)
|
||||
}
|
||||
cache[name] = temp
|
||||
return name
|
||||
},
|
||||
Back: function(name, output) {
|
||||
if (!cache[name]) {return}
|
||||
|
||||
while (cache[name].childNodes.length>0) {
|
||||
item = cache[name].childNodes[0]
|
||||
item.parentNode.removeChild(item)
|
||||
output.appendChild(item)
|
||||
}
|
||||
delete(cache[name])
|
||||
return name
|
||||
},
|
||||
Include: function(src, cb) {
|
||||
typeof src == "string" && (src = [src])
|
||||
kit.AppendChild(target, [{include: [src[0], function(event) {
|
||||
@ -121,10 +127,68 @@ function Meta(target, obj) {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function Page(page) {
|
||||
page = Meta(document.body, page, {
|
||||
__proto__: kit,
|
||||
onload: function() {
|
||||
var sessid = ctx.Cookie("sessid")
|
||||
if (page.check && !sessid) {
|
||||
document.querySelectorAll("body>fieldset.Login").forEach(function(field) {
|
||||
page.Pane(page, field)
|
||||
})
|
||||
} else {
|
||||
document.querySelectorAll("body>fieldset").forEach(function(field) {
|
||||
page.Pane(page, field)
|
||||
}), page.init(page)
|
||||
}
|
||||
|
||||
if (page.check) {
|
||||
false && kit.isWeiXin? page.login.Pane.Run(["weixin"], function(msg) {
|
||||
page.Include([
|
||||
"https://res.wx.qq.com/open/js/jweixin-1.4.0.js",
|
||||
"/static/librarys/weixin.js",
|
||||
], function(event) {
|
||||
wx.error(function(res){})
|
||||
wx.ready(function(){
|
||||
page.getLocation = function(cb) {
|
||||
wx.getLocation({success: function (res) {cb(res)}})
|
||||
}
|
||||
page.openLocation = function(latitude, longitude, name) {
|
||||
wx.openLocation({latitude: parseFloat(latitude), longitude: parseFloat(longitude), name:name||"here"})
|
||||
}
|
||||
|
||||
wx.getNetworkType({success: function (res) {}})
|
||||
wx.getLocation({success: function (res) {
|
||||
page.footer.Pane.State("site", parseInt(res.latitude*10000)+","+parseInt(res.longitude*10000))
|
||||
}})
|
||||
})
|
||||
wx.config({
|
||||
appId: msg.appid[0],
|
||||
nonceStr: msg.nonce[0],
|
||||
timestamp: msg.timestamp[0],
|
||||
signature: msg.signature[0],
|
||||
jsApiList: [
|
||||
"scanQRCode",
|
||||
"chooseImage",
|
||||
"closeWindow",
|
||||
"openAddress",
|
||||
"getNetworkType",
|
||||
"getLocation",
|
||||
"openLocation",
|
||||
]
|
||||
})
|
||||
})
|
||||
}): sessid? page.login.Pane.Run([], function(msg) {
|
||||
msg.result && msg.result[0]? page.header.Pane.State("user", msg.nickname[0])
|
||||
:page.login.Pane.Dialog(1, 1)
|
||||
}): page.login.Pane.Dialog(1, 1)
|
||||
}
|
||||
window.onresize = function(event) {
|
||||
page.onlayout && page.onlayout(event)
|
||||
}, document.body.onkeydown = function(event) {
|
||||
if (page.localMap && page.localMap(event)) {return}
|
||||
page.oncontrol && page.oncontrol(event, document.body, "control")
|
||||
}
|
||||
},
|
||||
ontoast: function(text, title, duration) {
|
||||
var args = typeof text == "object"? text: {text: text, title: title, duration: duration}
|
||||
var toast = kit.ModifyView("fieldset.toast", {
|
||||
@ -296,15 +360,38 @@ function Page(page) {
|
||||
}
|
||||
},
|
||||
|
||||
initLogin: function(page, field, option, output) {
|
||||
var ui = kit.AppendChilds(option, [
|
||||
{label: "username"}, {input: ["username"]}, {type: "br"},
|
||||
{label: "password"}, {password: ["password"]}, {type: "br"},
|
||||
{button: ["login", function(event) {
|
||||
if (!ui.username.value) {ui.username.focus(); return}
|
||||
if (!ui.password.value) {ui.password.focus(); return}
|
||||
|
||||
field.Pane.Login(ui.username.value, ui.password.value, function(sessid) {
|
||||
if (!sessid) {kit.alert("用户或密码错误"); return}
|
||||
ctx.Cookie("sessid", sessid), page.login.Pane.Dialog(1, 1), page.onload()
|
||||
})
|
||||
}]}, {type: "br"},
|
||||
])
|
||||
return {
|
||||
Login: function(username, password, cb) {
|
||||
this.Run([username, password], function(msg) {cb(msg.result && msg.result[0] || "")})
|
||||
},
|
||||
Exit: function() {ctx.Cookie("sessid", ""), kit.reload()},
|
||||
}
|
||||
},
|
||||
initHeader: function(page, field, option, output) {
|
||||
var state = {}, list = [], cb = function(event, item, value) {}
|
||||
field.onclick = function(event) {
|
||||
page.pane && page.pane.scrollTo(0,0)
|
||||
}
|
||||
field.onclick = function(event) {page.pane && page.pane.scrollTo(0,0)}
|
||||
return {
|
||||
Order: function(value, order, cbs) {
|
||||
state = value, list = order, cb = cbs || cb, this.Show()
|
||||
},
|
||||
State: function(name, value) {
|
||||
value != undefined && (state[name] = value, this.Show())
|
||||
return name == undefined? state: state[name]
|
||||
},
|
||||
Show: function() {
|
||||
output.innerHTML = "", kit.AppendChild(output, [
|
||||
{"view": ["title", "div", "shycontext"], click: function(event) {
|
||||
@ -315,26 +402,19 @@ function Page(page) {
|
||||
}}})},
|
||||
])
|
||||
},
|
||||
State: function(name, value) {
|
||||
if (value != undefined) {
|
||||
state[name] = value, this.Show()
|
||||
}
|
||||
if (name != undefined) {
|
||||
return state[name]
|
||||
}
|
||||
return state
|
||||
},
|
||||
}
|
||||
},
|
||||
initFooter: function(page, field, option, output) {
|
||||
var state = {}, list = [], cb = function(event, item, value) {}
|
||||
field.onclick = function(event) {
|
||||
page.pane.scrollTo(0,page.pane.scrollHeight)
|
||||
}
|
||||
field.onclick = function(event) {page.pane.scrollTo(0,page.pane.scrollHeight)}
|
||||
return {
|
||||
Order: function(value, order, cbs) {
|
||||
state = value, list = order, cb = cbs || cb, this.Show()
|
||||
},
|
||||
State: function(name, value) {
|
||||
value != undefined && (state[name] = value, this.Show())
|
||||
return name == undefined? state: state[name]
|
||||
},
|
||||
Show: function() {
|
||||
output.innerHTML = "", kit.AppendChild(output, [
|
||||
{"view": ["title", "div", "<a href='mailto:shylinux@163.com'>shylinux@163.com</>"]},
|
||||
@ -343,92 +423,84 @@ function Page(page) {
|
||||
}}})},
|
||||
])
|
||||
},
|
||||
State: function(name, value) {
|
||||
if (value != undefined) {
|
||||
state[name] = value, this.Show()
|
||||
}
|
||||
if (name != undefined) {
|
||||
return state[name]
|
||||
}
|
||||
return state
|
||||
},
|
||||
}
|
||||
},
|
||||
initLogin: function(page, field, option, output) {
|
||||
var ui = kit.AppendChild(option, [
|
||||
{label: "username"}, {input: ["username"]}, {type: "br"},
|
||||
{label: "password"}, {password: ["password"]}, {type: "br"},
|
||||
{button: ["login", function(event) {
|
||||
if (!ui.username.value) {
|
||||
ui.username.focus()
|
||||
return
|
||||
}
|
||||
if (!ui.password.value) {
|
||||
ui.password.focus()
|
||||
return
|
||||
}
|
||||
field.Pane.Run([ui.username.value, ui.password.value], function(msg) {
|
||||
if (msg.result && msg.result[0]) {
|
||||
field.Pane.ShowDialog(1, 1)
|
||||
ctx.Cookie("sessid", msg.result[0])
|
||||
kit.reload()
|
||||
return
|
||||
}
|
||||
kit.alert("用户或密码错误")
|
||||
})
|
||||
}]},
|
||||
{button: ["scan", function(event) {
|
||||
scan(event, function(text) {
|
||||
kit.alert(text)
|
||||
})
|
||||
}]},
|
||||
{type: "br"},
|
||||
])
|
||||
return {
|
||||
Exit: function() {
|
||||
ctx.Cookie("sessid", "")
|
||||
kit.reload()
|
||||
|
||||
},
|
||||
}
|
||||
},
|
||||
Pane: Pane,
|
||||
})
|
||||
window.onload = function() {
|
||||
document.querySelectorAll("body>fieldset").forEach(function(field) {
|
||||
page.Pane(page, field)
|
||||
})
|
||||
page.init(page)
|
||||
window.onresize = function(event) {
|
||||
page.onlayout && page.onlayout(event)
|
||||
}
|
||||
// document.body.onkeydown = function(event) {
|
||||
// page.onscroll && page.onscroll(event, window, "scroll")
|
||||
// }
|
||||
document.body.onkeydown = function(event) {
|
||||
if (page.localMap && page.localMap(event)) {
|
||||
return
|
||||
}
|
||||
page.oncontrol && page.oncontrol(event, document.body, "control")
|
||||
}
|
||||
}
|
||||
return page
|
||||
return window.onload = page.onload, page
|
||||
}
|
||||
function Pane(page, field) {
|
||||
field = field || kit.AppendChild(document.body, [{type: "fieldset", list: [{view: ["option", "form"]}, {view: ["output"]}]}]).last
|
||||
|
||||
var option = field.querySelector("form.option")
|
||||
var action = field.querySelector("div.action")
|
||||
var output = field.querySelector("div.output")
|
||||
|
||||
var cache = []
|
||||
var timer = ""
|
||||
var list = [], last = -1
|
||||
var name = option.dataset.name
|
||||
var pane = Meta(field, (page[field.dataset.init] || function() {
|
||||
})(page, field, option, output) || {}, {
|
||||
__proto__: page,
|
||||
ShowDialog: function(width, height) {
|
||||
Append: function(type, line, key, which, cb) {
|
||||
type = type || line.type
|
||||
var index = list.length, ui = pane.View(output, type, line, key, function(event, cmds, cbs) {
|
||||
pane.Select(index), pane.which.set(line[which])
|
||||
})
|
||||
list.push(ui.last), field.scrollBy(0, field.scrollHeight+100);
|
||||
(type == "plugin" || type == "field") && pane.Plugin(page, pane, ui.field, function(event, cmds, cbs) {
|
||||
typeof cb == "function" && cb(line, index, event, cmds, cbs)
|
||||
})
|
||||
return ui
|
||||
},
|
||||
Update: function(cmds, type, key, which, first, cb) {
|
||||
pane.Runs(cmds, function(line, index, msg) {
|
||||
var ui = pane.Append(type, line, key, which, cb)
|
||||
if (typeof first == "string") {
|
||||
(line.key == first || line.name == first || line[which] == first) && ui.first.click()
|
||||
} else {
|
||||
first && index == 0 && ui.first.click()
|
||||
}
|
||||
})
|
||||
},
|
||||
Select: function(index) {
|
||||
-1 < last && last < list.length && (list[last].className = "item")
|
||||
last = index, list[index] && (list[index].className = "item select")
|
||||
},
|
||||
Clear: function() {
|
||||
output.innerHTML = "", list = [], last = -1
|
||||
},
|
||||
|
||||
Tickers: function(time, cmds, cb) {
|
||||
pane.Ticker(time, cmds, function(msg) {
|
||||
ctx.Table(msg, function(line, index) {
|
||||
cb(line, index, msg)
|
||||
})
|
||||
})
|
||||
},
|
||||
Ticker: function(time, cmds, cb) {
|
||||
timer && clearTimeout(timer)
|
||||
function loop() {
|
||||
!pane.Stop() && pane.Run(cmds, function(msg) {
|
||||
cb(msg), timer = setTimeout(loop, time)
|
||||
})
|
||||
}
|
||||
time && (timer = setTimeout(loop, 10))
|
||||
},
|
||||
Runs: function(cmds, cb) {
|
||||
pane.Run(cmds, function(msg) {
|
||||
ctx.Table(msg, function(line, index) {
|
||||
(cb||this.ondaemon)(line, index, msg)
|
||||
})
|
||||
})
|
||||
},
|
||||
Run: function(cmds, cb) {
|
||||
ctx.Run(page, option.dataset, cmds, cb||this.ondaemon)
|
||||
},
|
||||
|
||||
Size: function(width, height) {
|
||||
field.style.display = (width<=0 || height<=0)? "none": "block"
|
||||
field.style.width = width+"px"
|
||||
field.style.height = height+"px"
|
||||
},
|
||||
Dialog: function(width, height) {
|
||||
if (field.style.display != "block") {
|
||||
page.dialog && page.dialog != field && page.dialog.style.display == "block" && page.dialog.Show()
|
||||
page.dialog = field, field.style.display = "block", kit.ModifyView(field, {window: [width||80, height||200]})
|
||||
@ -438,106 +510,8 @@ function Pane(page, field) {
|
||||
delete(page.dialog)
|
||||
return false
|
||||
},
|
||||
Size: function(width, height) {
|
||||
field.style.display = (width<=0 || height<=0)? "none": "block"
|
||||
field.style.width = width+"px"
|
||||
field.style.height = height+"px"
|
||||
},
|
||||
Views: function(output, type, line, key, cb) {
|
||||
var ui = page.View(output, type, line, key, cb)
|
||||
if (type == "plugin" || type == "field") {
|
||||
pane.Plugin(page, pane, ui.field)
|
||||
}
|
||||
return ui
|
||||
},
|
||||
Run: function(cmds, cb) {
|
||||
ctx.Run(page, option.dataset, cmds, cb||this.ondaemon)
|
||||
},
|
||||
Runs: function(cmds, cb) {
|
||||
pane.Run(cmds, function(msg) {
|
||||
ctx.Table(msg, function(line, index) {
|
||||
(cb||this.ondaemon)(line, index, msg)
|
||||
})
|
||||
})
|
||||
},
|
||||
Time: function(time, cmds, cb) {
|
||||
function loop() {
|
||||
ctx.Run(page, option.dataset, cmds, cb)
|
||||
setTimeout(loop, time)
|
||||
}
|
||||
setTimeout(loop, time)
|
||||
},
|
||||
Times: function(time, cmds, cb) {
|
||||
timer && clearTimeout(timer)
|
||||
function loop() {
|
||||
!pane.Stop() && ctx.Run(page, option.dataset, cmds, function(msg) {
|
||||
ctx.Table(msg, function(line, index) {
|
||||
cb(line, index, msg)
|
||||
})
|
||||
})
|
||||
timer = setTimeout(loop, time)
|
||||
}
|
||||
time && (timer = setTimeout(loop, 10))
|
||||
},
|
||||
|
||||
Clear: function() {
|
||||
output.innerHTML = "", list = [], last = -1
|
||||
},
|
||||
Select: function(index) {
|
||||
-1 < last && last < list.length && (list[last].className = "item")
|
||||
last = index, list[index] && (list[index].className = "item select")
|
||||
},
|
||||
Append: function(type, line, key, which, cb) {
|
||||
var index = list.length, ui = pane.Views(output, line.type || type, line, key, function(event, cmds, cbs) {
|
||||
pane.Select(index), pane.which.set(line[which])
|
||||
typeof cb == "function" && cb(line, index, event, cmds, cbs)
|
||||
})
|
||||
list.push(ui.last), field.scrollBy(0, field.scrollHeight+100)
|
||||
return ui
|
||||
},
|
||||
Update: function(cmds, type, key, which, first, cb) {
|
||||
pane.Clear(), pane.Runs(cmds, function(line, index, msg) {
|
||||
var ui = pane.Append(type, line, key, which, cb)
|
||||
if (typeof first == "string") {
|
||||
(line.key == first || line.name == first || line[which] == first) && ui.first.click()
|
||||
} else {
|
||||
first && index == 0 && ui.first.click()
|
||||
}
|
||||
if (index == msg[msg.append[0]].length-1) {
|
||||
pane.Field.scrollTo(0, 0)
|
||||
}
|
||||
})
|
||||
},
|
||||
Share: function(objs) {
|
||||
objs = objs || {}
|
||||
objs.name = option.dataset.name
|
||||
objs.group = option.dataset.group
|
||||
return ctx.Share(objs)
|
||||
},
|
||||
Save: function(name, output) {
|
||||
var temp = document.createDocumentFragment()
|
||||
while (output.childNodes.length>0) {
|
||||
var item = output.childNodes[0]
|
||||
item.parentNode.removeChild(item)
|
||||
temp.appendChild(item)
|
||||
}
|
||||
cache[name] = temp
|
||||
return name
|
||||
},
|
||||
Back: function(name, output) {
|
||||
if (!cache[name]) {
|
||||
return
|
||||
}
|
||||
while (cache[name].childNodes.length>0) {
|
||||
item = cache[name].childNodes[0]
|
||||
item.parentNode.removeChild(item)
|
||||
output.appendChild(item)
|
||||
}
|
||||
delete(cache[name])
|
||||
return name
|
||||
},
|
||||
which: page.Sync(name), Listen: {},
|
||||
Action: {}, Button: [], Plugin: Plugin,
|
||||
which: page.Sync(name), Listen: {}, Action: {}, Button: [],
|
||||
Plugin: Plugin,
|
||||
})
|
||||
|
||||
for (var k in pane.Listen) {
|
||||
@ -550,27 +524,180 @@ function Pane(page, field) {
|
||||
}]}: value == ""? {view: ["space"]} :value == "br"? {type: "br"}: {button: [value, function(value, event) {
|
||||
typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
|
||||
}]}
|
||||
})).className="action "+name)
|
||||
|
||||
})).className="action")
|
||||
option.onsubmit = function(event) {
|
||||
event.preventDefault()
|
||||
};
|
||||
return page[name] = field, pane.Field = field, field.Pane = pane
|
||||
}
|
||||
function Plugin(page, pane, field) {
|
||||
function Plugin(page, pane, field, run) {
|
||||
var option = field.querySelector("form.option")
|
||||
var action = field.querySelector("div.action")
|
||||
var output = field.querySelector("div.output")
|
||||
|
||||
var count = 0
|
||||
var plugin = Meta(field, field.Script || {}, {
|
||||
__proto__: pane,
|
||||
Append: function(item, name) {
|
||||
var plugin = Meta(field, (field.Script && field.Script.init || function() {
|
||||
})(run, field, option, output)||{}, {
|
||||
Append: function(item, name, value) {
|
||||
kit.Item(plugin.onaction, function(k, cb) {
|
||||
item[k] == undefined && (item[k] = typeof cb == "function"? function(event) {
|
||||
cb(event, action, item.type, name, item)
|
||||
}: cb)
|
||||
})
|
||||
|
||||
args && count < args.length && (item.value = value||args[count++]||item.value||"")
|
||||
name = item.name || "input"
|
||||
|
||||
item.onfocus = function(event) {
|
||||
page.pane = pane.Field, page.plugin = field, page.input = event.target
|
||||
var input = {type: "input", name: name, data: item}
|
||||
switch (item.type) {
|
||||
case "select":
|
||||
item.className = "args"
|
||||
input.type = "select", input.list = item.values.map(function(value) {
|
||||
return {type: "option", value: value, inner: value}
|
||||
})
|
||||
break
|
||||
case "textarea":
|
||||
input.type = "textarea", item.style = "height:300px;"+"width:"+(option.clientWidth-20)+"px"
|
||||
item.className = "args"
|
||||
case "text":
|
||||
item.className = "args"
|
||||
item.autocomplete = "off"
|
||||
break
|
||||
}
|
||||
item.onkeyup = function(event) {
|
||||
|
||||
var ui = kit.AppendChild(option, [{view: [item.view||""], list: [{type: "label", inner: item.label||""}, input]}])
|
||||
var action = Meta(ui[name] || {}, item, plugin.onaction, plugin);
|
||||
|
||||
(typeof item.imports == "object"? item.imports: typeof item.imports == "string"? [item.imports]: []).forEach(function(imports) {
|
||||
page.Sync(imports).change(function(value) {
|
||||
(action.target.value = value) && item.action == "auto" && plugin.Runs(window.event)
|
||||
})
|
||||
})
|
||||
item.type == "button" && item.action == "auto" && plugin.Runs(window.event, function() {
|
||||
var td = output.querySelector("td")
|
||||
td && td.click()
|
||||
})
|
||||
return action
|
||||
},
|
||||
Remove: function() {
|
||||
var list = option.querySelectorAll(".args")
|
||||
list.length > 0 && (option.removeChild(list[list.length-1].parentNode), count--)
|
||||
},
|
||||
Delete: function() {
|
||||
page.plugin = field.previousSibling
|
||||
field.parentNode.removeChild(field)
|
||||
},
|
||||
Select: function() {
|
||||
option.querySelectorAll("input")[1].focus()
|
||||
},
|
||||
Reveal: function(msg) {
|
||||
return msg.append && msg.append[0]? ["table", JSON.stringify(ctx.Tables(msg))]: ["code", msg.result? msg.result.join(""): ""]
|
||||
},
|
||||
Format: function() {
|
||||
field.Meta.args = arguments.length > 0? kit.List(arguments):
|
||||
kit.Selector(option, ".args", function(item) {return item.value})
|
||||
return JSON.stringify(field.Meta)
|
||||
},
|
||||
Clone: function() {
|
||||
return pane.Append("field", {text: plugin.Format()}, [], run).field.Plugin
|
||||
},
|
||||
|
||||
Delay: function(time, event, text) {
|
||||
page.ontoast(text, "", -1)
|
||||
return setTimeout(function() {
|
||||
plugin.Runs(event), page.ontoast("")
|
||||
}, time)
|
||||
},
|
||||
Check: function(target, cb) {
|
||||
option.querySelectorAll(".args").forEach(function(item, index, list) {
|
||||
item == target && (index == list.length-1? plugin.Runs(event, cb): page.plugin == field && list[index+1].focus())
|
||||
})
|
||||
},
|
||||
Runs: function(event, cb) {
|
||||
this.Run(event, kit.Selector(option, ".args", function(item, index) {return item.value}), cb)
|
||||
},
|
||||
Run: function(event, args, cb) {
|
||||
var show = true
|
||||
setTimeout(function() {
|
||||
show && page.ontoast(kit.Format(args||["running..."]), meta.name, -1)
|
||||
}, 1000)
|
||||
event.Plugin = plugin, run(event, args, function(msg) {
|
||||
page.footer.Pane.State("ncmd", kit.History.get("cmd").length)
|
||||
plugin.msg = msg, plugin.display(display.deal, cb)
|
||||
show = false, page.ontoast("")
|
||||
})
|
||||
},
|
||||
|
||||
display: function(arg, cb) {
|
||||
display.deal = arg, plugin.ondaemon[display.deal||"table"](plugin.msg, cb)
|
||||
},
|
||||
ondaemon: {
|
||||
table: function(msg, cb) {
|
||||
output.innerHTML = ""
|
||||
!display.hide_append && msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) {
|
||||
page.Sync("plugin_"+exports[0]).set(plugin.onexport[exports[2]||""](value, name, line))
|
||||
});
|
||||
(display.show_result || !msg.append) && msg.result && kit.OrderCode(kit.AppendChild(output, [{view: ["code", "div", msg.Results()]}]).first)
|
||||
typeof cb == "function" && cb(msg)
|
||||
},
|
||||
editor: function(msg, cb) {
|
||||
(output.innerHTML = "", Editor(plugin, option, output, output.clientWidth-40, 400, 10, msg))
|
||||
},
|
||||
canvas: function(msg, cb) {
|
||||
typeof cb == "function" && !cb(msg) || (output.innerHTML = "", Canvas(plugin, option, output, output.clientWidth-40, 400, 10, msg))
|
||||
},
|
||||
},
|
||||
onexport: {
|
||||
"": function(value, name) {
|
||||
return value
|
||||
},
|
||||
see: function(value, name, line) {
|
||||
return value.split("/")[0]
|
||||
},
|
||||
you: function(value, name, line) {
|
||||
window.event.Plugin = plugin
|
||||
line.you && name == "status" && (line.status == "start"? function() {
|
||||
plugin.Delay(3000, window.event, line.you+" stop...") && field.Run(window.event, [line.you, "stop"])
|
||||
}(): field.Run(window.event, [line.you], function(msg) {
|
||||
plugin.Delay(3000, window.event, line.you+" start...")
|
||||
}))
|
||||
return name == "status" || line.status == "stop" ? undefined: line.you
|
||||
},
|
||||
pod: function(value, name, line) {
|
||||
if (option[exports[0]].value) {
|
||||
return option[exports[0]].value+"."+line.pod
|
||||
}
|
||||
return line.pod
|
||||
},
|
||||
dir: function(value, name, line) {
|
||||
name != "path" && (value = line.path)
|
||||
return value
|
||||
},
|
||||
},
|
||||
onaction: {
|
||||
onfocus: function(event, action, type, name, item) {
|
||||
page.pane = pane.target, page.plugin = plugin.target, page.input = event.target
|
||||
},
|
||||
onclick: function(event, action, type, name, item) {
|
||||
switch (type) {
|
||||
case "button":
|
||||
action[item.click]? action[item.click](event, item, option, field):
|
||||
plugin[item.click]? plugin[item.click](event, item, option, field): plugin.Runs(event)
|
||||
break
|
||||
case "text":
|
||||
if (event.ctrlKey) {
|
||||
action.value = kit.History.get("txt", -1).data.trim()
|
||||
}
|
||||
break
|
||||
}
|
||||
},
|
||||
ondblclick: function(event, action, type, name, item) {
|
||||
action.value = kit.History.get("txt", -1).data.trim()
|
||||
},
|
||||
onchange: function(event, action, type, name, item) {
|
||||
plugin.Check(action)
|
||||
},
|
||||
onkeyup: function(event, action, type, name, item) {
|
||||
page.oninput(event, function(event) {
|
||||
switch (event.key) {
|
||||
case "w":
|
||||
@ -582,8 +709,8 @@ function Plugin(page, pane, field) {
|
||||
event.preventDefault()
|
||||
return true
|
||||
})
|
||||
}
|
||||
item.onkeydown = function(event) {
|
||||
},
|
||||
onkeydown: function(event, action, type, name, item) {
|
||||
page.oninput(event, function(event) {
|
||||
switch (event.key) {
|
||||
case "w":
|
||||
@ -623,217 +750,9 @@ function Plugin(page, pane, field) {
|
||||
event.preventDefault()
|
||||
return true
|
||||
})
|
||||
item.type != "textarea" && event.key == "Enter" && (item.history == "true"? plugin.Goto(event.target.value): plugin.Check(action))
|
||||
}
|
||||
|
||||
var input = {type: "input", name: name, data: item}
|
||||
switch (item.type) {
|
||||
case "button":
|
||||
item.onclick = function(event) {
|
||||
action[item.click]? action[item.click](event, item, option, field):
|
||||
plugin[item.click]? plugin[item.click](event, item, option, field): plugin.Runs(event)
|
||||
}
|
||||
break
|
||||
|
||||
case "select":
|
||||
input.type = "select", input.list = item.values.map(function(value) {
|
||||
return {type: "option", value: value, inner: value}
|
||||
}), item.onchange = function(event) {
|
||||
plugin.Check(action)
|
||||
}
|
||||
|
||||
case "textarea":
|
||||
if (item.type == "textarea") {
|
||||
input.type = "textarea"
|
||||
item.style = "height:300px;"+"width:"+(option.clientWidth-20)+"px"
|
||||
}
|
||||
|
||||
default:
|
||||
if (item.type == "text") {
|
||||
item.onclick = function(event) {
|
||||
if (event.ctrlKey) {
|
||||
action.value = kit.History.get("txt", -1).data.trim()
|
||||
}
|
||||
}
|
||||
item.ondblclick = function(event) {
|
||||
action.value = kit.History.get("txt", -1).data.trim()
|
||||
}
|
||||
item.autocomplete = "off"
|
||||
|
||||
}
|
||||
args && count < args.length && (item.value = args[count++]||item.value||"")
|
||||
item.className = "args"
|
||||
}
|
||||
|
||||
var ui = kit.AppendChild(option, [{view: [item.view||""], list: [{type: "label", inner: item.label||""}, input]}])
|
||||
var action = ui[name] || {}
|
||||
|
||||
item.history == "true" && (action.History = [""], plugin.Goto = function(value) {
|
||||
action.History.push(action.value = value)
|
||||
plugin.Runs(window.event)
|
||||
return value
|
||||
}, plugin.Back = function() {
|
||||
action.History.pop(), action.History.length > 0 && plugin.Goto(action.History.pop())
|
||||
});
|
||||
|
||||
(typeof item.imports == "object"? item.imports: typeof item.imports == "string"? [item.imports]: []).forEach(function(imports) {
|
||||
page.Sync(imports).change(function(value) {
|
||||
(action.value = value) && item.action == "auto" && plugin.Runs(window.event)
|
||||
})
|
||||
})
|
||||
item.type == "button" && item.action == "auto" && plugin.Runs(window.event, function() {
|
||||
var td = output.querySelector("td")
|
||||
td && td.click()
|
||||
})
|
||||
return action
|
||||
},
|
||||
Remove: function() {
|
||||
var list = option.querySelectorAll(".args")
|
||||
list.length > 0 && option.removeChild(list[list.length-1].parentNode)
|
||||
},
|
||||
Select: function() {
|
||||
option.querySelectorAll("input")[1].focus()
|
||||
},
|
||||
Format: function() {
|
||||
field.Meta.args = arguments.length > 0? kit.List(arguments):
|
||||
kit.Selector(option, ".args", function(item) {return item.value})
|
||||
return JSON.stringify(field.Meta)
|
||||
},
|
||||
Reveal: function(msg) {
|
||||
return msg.append && msg.append[0]? ["table", JSON.stringify(ctx.Tables(msg))]: ["code", msg.result? msg.result.join(""): ""]
|
||||
},
|
||||
Delete: function() {
|
||||
page.plugin = field.previousSibling
|
||||
field.parentNode.removeChild(field)
|
||||
},
|
||||
Clone: function() {
|
||||
field.Meta.args = kit.Selector(option, "input.args", function(item, index) {
|
||||
return item.value
|
||||
})
|
||||
return pane.Views(field.parentNode, "plugin", field.Meta, [], field.Run).field.Plugin
|
||||
},
|
||||
Share: function() {
|
||||
location.href
|
||||
option
|
||||
|
||||
return
|
||||
},
|
||||
|
||||
Check: function(target, cb) {
|
||||
option.querySelectorAll(".args").forEach(function(item, index, list) {
|
||||
item == target && (index == list.length-1? plugin.Runs(event, cb): page.plugin == field && list[index+1].focus())
|
||||
})
|
||||
},
|
||||
Run: function(event, args, cb) {
|
||||
var show = true
|
||||
setTimeout(function() {
|
||||
show && page.ontoast(kit.Format(args||["running..."]), meta.name, -1)
|
||||
}, 1000)
|
||||
event.Plugin = plugin, field.Run(event, args, function(msg) {
|
||||
plugin.msg = msg, show = false, page.ontoast("")
|
||||
plugin.ondaemon[display.deal||"table"](msg, cb)
|
||||
})
|
||||
},
|
||||
Runs: function(event, cb) {
|
||||
page.footer.Pane.State("ncmd", kit.History.get("cmd").length)
|
||||
var args = kit.Selector(option, ".args", function(item, index) {
|
||||
return item.value
|
||||
})
|
||||
this.Run(event, args, cb)
|
||||
},
|
||||
Delay: function(time, event, text) {
|
||||
page.ontoast(text, "", -1)
|
||||
setTimeout(function() {
|
||||
plugin.Runs(event)
|
||||
page.ontoast("")
|
||||
}, time)
|
||||
return time
|
||||
},
|
||||
Clear: function() {
|
||||
output.innerHTML = ""
|
||||
},
|
||||
|
||||
ondaemon: {
|
||||
table: function(msg, cb) {
|
||||
output.innerHTML = ""
|
||||
!display.hide_append && msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) {
|
||||
page.Sync("plugin_"+exports[0]).set(plugin.onexport[exports[2]||""](value, name, line))
|
||||
});
|
||||
(display.show_result || !msg.append) && msg.result && kit.OrderCode(kit.AppendChild(output, [{view: ["code", "div", msg.Results()]}]).first)
|
||||
typeof cb == "function" && cb(msg)
|
||||
item.type != "textarea" && event.key == "Enter" && plugin.Check(action.target)
|
||||
},
|
||||
editor: function(msg, cb) {
|
||||
(output.innerHTML = "", Editor(plugin, option, output, output.clientWidth-40, 400, 10, msg))
|
||||
},
|
||||
canvas: function(msg, cb) {
|
||||
typeof cb == "function" && !cb(msg) || (output.innerHTML = "", Canvas(plugin, option, output, output.clientWidth-40, 400, 10, msg))
|
||||
},
|
||||
point: function(msg) {
|
||||
var id = "canvas"+page.ID()
|
||||
var canvas = kit.AppendChild(output, [{view: ["draw", "canvas"], data: {id: id, width: output.clientWidth-15}}]).last.getContext("2d")
|
||||
ctx.Table(msg, function(line) {
|
||||
var meta = JSON.parse(line.meta||"{}")
|
||||
switch (line.type) {
|
||||
case "begin":
|
||||
canvas.beginPath()
|
||||
break
|
||||
|
||||
case "circle":
|
||||
canvas.arc(parseInt(meta.x), parseInt(meta.y), parseInt(meta.r), 0, Math.PI*2, true)
|
||||
break
|
||||
|
||||
case "stroke":
|
||||
canvas.strokeStyle = meta.color
|
||||
canvas.lineWidth = parseInt(meta.width)
|
||||
canvas.stroke()
|
||||
break
|
||||
}
|
||||
})
|
||||
},
|
||||
map: function(msg) {
|
||||
kit.AppendChild(output, [{img: ["https://gss0.bdstatic.com/8bo_dTSlRMgBo1vgoIiO_jowehsv/tile/?qt=vtile&x=25310&y=9426&z=17&styles=pl&scaler=2&udt=20190622"]}])
|
||||
},
|
||||
},
|
||||
onexport: {
|
||||
"": function(value, name) {
|
||||
return value
|
||||
},
|
||||
see: function(value, name, line) {
|
||||
return value.split("/")[0]
|
||||
},
|
||||
you: function(value, name, line) {
|
||||
window.event.Plugin = plugin
|
||||
line.you && name == "status" && (line.status == "start"? function() {
|
||||
plugin.Delay(3000, window.event, line.you+" stop...") && field.Run(window.event, [line.you, "stop"])
|
||||
}(): field.Run(window.event, [line.you], function(msg) {
|
||||
plugin.Delay(3000, window.event, line.you+" start...")
|
||||
}))
|
||||
return name == "status" || line.status == "stop" ? undefined: line.you
|
||||
},
|
||||
pod: function(value, name, line) {
|
||||
if (option[exports[0]].value) {
|
||||
return option[exports[0]].value+"."+line.pod
|
||||
}
|
||||
return line.pod
|
||||
},
|
||||
dir: function(value, name, line) {
|
||||
if (name != "path") {
|
||||
value = line.path
|
||||
}
|
||||
plugin.Goto(value)
|
||||
return value
|
||||
if (value.endsWith("/")) {
|
||||
}
|
||||
|
||||
option.dir.value = value
|
||||
plugin.Runs(window.event)
|
||||
},
|
||||
},
|
||||
display: function(arg) {
|
||||
display.deal = arg
|
||||
plugin.ondaemon[display.deal||"table"](plugin.msg)
|
||||
},
|
||||
init: function() {},
|
||||
}
|
||||
})
|
||||
|
||||
var meta = field.Meta
|
||||
@ -841,13 +760,8 @@ function Plugin(page, pane, field) {
|
||||
var display = JSON.parse(meta.display||'{}')
|
||||
var exports = JSON.parse(meta.exports||'["",""]')
|
||||
JSON.parse(meta.inputs || "[]").map(plugin.Append)
|
||||
|
||||
plugin.init(page, pane, plugin, field, option, output)
|
||||
return page[field.id] = pane[field.id] = plugin.Field = field, field.Plugin = plugin
|
||||
return page[field.id] = pane[field.id] = field, field.Plugin = plugin
|
||||
}
|
||||
function Action(pane, pane, plugin, item) {
|
||||
}
|
||||
|
||||
function Editor(plugin, option, output, width, height, space, msg) {
|
||||
exports = ["dir", "path", "dir"]
|
||||
msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), exports[1], function(event, value, name, line) {
|
||||
|
@ -121,7 +121,7 @@ kit = toolkit = {
|
||||
//
|
||||
// 按键: button select
|
||||
// 输入: input password
|
||||
// 输出: label img
|
||||
// 输出: label img row
|
||||
//
|
||||
// 树状结构: tree fork leaf
|
||||
// 普通视图: view text code
|
||||
@ -209,6 +209,10 @@ kit = toolkit = {
|
||||
child.data["src"] = child.img[0]
|
||||
child.img.length > 1 && (child.data["onload"] = child.img[1])
|
||||
|
||||
} else if (child.row) {
|
||||
child.type = "tr"
|
||||
child.list = child.row.map(function(item) {return {text: [item, "td"]}})
|
||||
|
||||
} else if (child.tree) {
|
||||
child.type = "ul"
|
||||
child.list = child.tree
|
||||
@ -545,10 +549,15 @@ kit = toolkit = {
|
||||
List: function(obj, cb) {
|
||||
var list = []
|
||||
for (var i = 0; i < obj.length; i++) {
|
||||
list.push(typeof cb == "function"? cb(obj[i]): obj[i])
|
||||
list.push(typeof cb == "function"? cb(obj[i], i): obj[i])
|
||||
}
|
||||
return list
|
||||
},
|
||||
Item: function(obj, cb) {
|
||||
for (var k in obj) {
|
||||
cb(k, obj[k])
|
||||
}
|
||||
},
|
||||
alert: function(text) {
|
||||
alert(JSON.stringify(text))
|
||||
},
|
||||
|
@ -1,4 +1,5 @@
|
||||
var page = Page({
|
||||
login: true,
|
||||
conf: {border: 4},
|
||||
onlayout: function(event, sizes) {
|
||||
var height = document.body.clientHeight-page.conf.border
|
||||
|
Loading…
x
Reference in New Issue
Block a user