diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go
index 25ffc1fb..be121073 100644
--- a/src/contexts/cli/cli.go
+++ b/src/contexts/cli/cli.go
@@ -578,6 +578,10 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
m.Cmdp(time.Second, []string{"go init"}, []string{"cli.system", "go", "get",
"cmd_env", "GOPATH", m.Conf("runtime", "boot.ctx_path")}, list)
+ case "stat":
+ m.Cmd("nfs.dir", "src", "dir_deep", "dir_type", "file").CopyTo(m, "append")
+ m.Cmd("nfs.dir", "usr/librarys", "dir_deep", "dir_type", "file").CopyTo(m, "append")
+ m.Set("result").Table()
}
return
}},
@@ -745,8 +749,17 @@ var version = struct {
"missyou": &ctx.Command{Name: "missyou", Help: "服务升级", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
m.Option("dir_root", "")
- m.Cmd("nfs.dir", m.Conf("missyou", "path")).Table(func() {
+ m.Cmd("nfs.dir", m.Conf("missyou", "path")).Table(func(value map[string]string) {
+ name := strings.TrimSuffix(value["filename"], "/")
+ m.Add("append", "create_time", value["time"])
+ m.Add("append", "you", name)
+ if m.Confs("nfs.node", name) {
+ m.Add("append", "status", "start")
+ } else {
+ m.Add("append", "status", "stop")
+ }
})
+ m.Table()
return
}
@@ -755,20 +768,29 @@ var version = struct {
}
if m.Confs("ssh.node", arg[0]) {
- m.Echo(arg[0])
+ switch kit.Select("", arg, 1) {
+ case "stop":
+ m.Cmdy("ssh._route", arg[0], "context", "cli", "quit", 0)
+ default:
+ m.Echo(arg[0])
+ }
return
}
p := path.Join(m.Conf("missyou", "path"), arg[0])
- if s, e := os.Stat(p); e == nil && s.IsDir() {
- m.Cmdy("cli.system", "node.sh", "create", p, "daemon", "cmd_daemon", "true")
- return e
+ if _, e := os.Stat(p); e != nil {
+ m.Cmd("nfs.copy", path.Join(p, "etc/local.shy"), "usr/missyou/job.shy")
+ m.Confm("missyou", "local", func(index string, local string) {
+ m.Cmd("nfs.git", "clone", local, path.Join(p, "usr/local", index))
+ })
}
- m.Cmdy("nfs.copy", path.Join(p, "etc/local.shy"), "usr/missyou/job.shy")
- m.Confm("missyou", "local", func(index string, local string) {
- m.Cmd("nfs.git", "clone", local, path.Join(p, "usr/local", index))
- })
+ m.Cmdy("cli.system", m.Conf("runtime", "boot.ctx_bin"), "daemon",
+ "cmd_dir", p,
+ "cmd_env", "ctx_home", m.Conf("runtime", "boot.ctx_home"),
+ "cmd_env", "ctx_box", fmt.Sprintf("http://localhost%s", m.Conf("runtime", "boot.web_port")),
+ "cmd_daemon", "true",
+ )
return
}},
"quit": &ctx.Command{Name: "quit code", Help: "停止服务", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go
index fca0b62f..9f648f92 100644
--- a/src/contexts/cli/version.go
+++ b/src/contexts/cli/version.go
@@ -4,5 +4,5 @@ var version = struct {
host string
self int
}{
- "2019-06-30 12:52:58", "com", 26,
+ "2019-06-30 17:36:39", "com.mac", 30,
}
diff --git a/src/contexts/ctx/core.go b/src/contexts/ctx/core.go
index 2007beae..94eebe7c 100644
--- a/src/contexts/ctx/core.go
+++ b/src/contexts/ctx/core.go
@@ -360,16 +360,14 @@ func (m *Message) CallBack(sync bool, cb func(msg *Message) (sub *Message), arg
// m.Gos(m, func(m *Message) {
m.Call(func(sub *Message) *Message {
msg := cb(sub)
- m.Log("sync", m.Format("done", "result", "append"))
wait <- m
return msg
}, arg...)
// })
- m.Log("sync", m.Format("wait", "result", "append"))
select {
case <-time.After(kit.Duration(m.Conf("call_timeout"))):
- m.Log("sync", m.Format("timeout", "result", "append"))
+ m.Log("sync", m.Format("timeout", "detail", "option"))
case <-wait:
}
return m
diff --git a/src/contexts/ctx/ctx.go b/src/contexts/ctx/ctx.go
index c5b5c07a..2c696590 100644
--- a/src/contexts/ctx/ctx.go
+++ b/src/contexts/ctx/ctx.go
@@ -39,6 +39,7 @@ func (ctx *CTX) Begin(m *Message, arg ...string) Server {
}
func (ctx *CTX) Start(m *Message, arg ...string) bool {
m.Cmd("ctx._init")
+ kit.Log("fuck", "what")
if m.Optionv("ps_target", Index); len(arg) == 0 {
m.Option("cli.modal", "active")
m.Option("log.disable", false)
@@ -46,10 +47,12 @@ func (ctx *CTX) Start(m *Message, arg ...string) bool {
m.Cmd("log._init")
m.Cmd("yac._init")
m.Cmd("gdb._init")
+ m.Log("fuck", "what")
m.Cmd("cli.source", m.Conf("system", "script.init")).Cmd("cli.source", "stdio").Cmd("cli.source", m.Conf("system", "script.exit"))
} else {
m.Option("cli.modal", "action")
m.Cmd("yac._init")
+ m.Log("fuck", "what")
for _, v := range m.Spawn().Cmd(arg).Meta["result"] {
fmt.Printf("%s", v)
}
diff --git a/src/contexts/ctx/type.go b/src/contexts/ctx/type.go
index 4845dd9c..02100a24 100644
--- a/src/contexts/ctx/type.go
+++ b/src/contexts/ctx/type.go
@@ -368,7 +368,6 @@ func (m *Message) Table(cbs ...interface{}) *Message {
row[k], wor = data, append(wor, data+strings.Repeat(space, width[k]-kit.Width(data, len(space))))
}
- m.Log("fuck", "waht %v", row)
if !cb(row, wor, i) {
break
}
diff --git a/src/contexts/gdb/gdb.go b/src/contexts/gdb/gdb.go
index d8e60a87..1e28a4f4 100644
--- a/src/contexts/gdb/gdb.go
+++ b/src/contexts/gdb/gdb.go
@@ -99,7 +99,7 @@ func (gdb *GDB) Start(m *ctx.Message, arg ...string) bool {
action := m.Conf("signal", sig)
m.Log("signal", "%v: %v", action, sig)
switch action {
- case "QUIT":
+ case "QUIT", "INT":
m.Cmd("cli.quit", 0)
case "restart":
m.Cmd("cli.quit", 1)
@@ -143,7 +143,7 @@ var Index = &ctx.Context{Name: "gdb", Help: "调试中心",
"31": "upgrade",
"1": "HUP",
- // "2": "INT",
+ "2": "INT",
// "9": "KILL",
// "10": "BUS",
// "11": "SEGV",
diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go
index fa409e06..b43fce6a 100644
--- a/src/contexts/ssh/ssh.go
+++ b/src/contexts/ssh/ssh.go
@@ -156,9 +156,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
"componet_type": "private", "componet_ctx": "cli", "componet_cmd": "missyou",
"componet_args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "action"},
- map[string]interface{}{"type": "button", "value": "行动"},
+ map[string]interface{}{"type": "button", "value": "行动", "action": "auto"},
},
- "exports": []interface{}{"you", "filename"},
+ "exports": []interface{}{"you", "", "you"},
},
},
"favor": []interface{}{
@@ -166,9 +166,9 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
"componet_type": "public", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "aaa", "clip"}, "inputs": []interface{}{
- map[string]interface{}{"type": "text", "name": "you", "imports": "plugin_you"},
+ map[string]interface{}{"type": "text", "name": "you", "imports": "plugin_you", "action": "auto"},
map[string]interface{}{"type": "text", "name": "txt", "view": "long"},
- map[string]interface{}{"type": "button", "value": "运行"},
+ map[string]interface{}{"type": "button", "value": "存储"},
},
},
map[string]interface{}{"componet_name": "qrcode", "componet_help": "生成二维码",
@@ -176,6 +176,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
"componet_type": "public", "componet_ctx": "web.chat", "componet_cmd": "login",
"componet_args": []interface{}{"qrcode"}, "inputs": []interface{}{
map[string]interface{}{"label": "content", "type": "text", "name": "content"},
+ map[string]interface{}{"type": "button", "value": "生成"},
},
},
map[string]interface{}{"componet_name": "salary", "componet_help": "计算工资",
@@ -212,17 +213,17 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "ssh", "remote"}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod"},
- map[string]interface{}{"type": "button", "value": "执行"},
+ map[string]interface{}{"type": "button", "value": "执行", "action": "auto"},
},
- "exports": []interface{}{"pod", "key", "pod"},
+ "exports": []interface{}{"pod", "pod", "pod"},
},
map[string]interface{}{"componet_name": "ctx", "componet_help": "ctx",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "$$", "context"}, "inputs": []interface{}{
- map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
+ map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod", "action": "auto"},
map[string]interface{}{"type": "text", "name": "ctx", "value": "nfs", "imports": "plugin_ctx"},
- map[string]interface{}{"type": "button", "value": "模块"},
+ map[string]interface{}{"type": "button", "value": "查看"},
},
"exports": []interface{}{"ctx", "names"},
},
@@ -240,8 +241,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
"componet_args": []interface{}{"$$", "context", "nfs", "dir"}, "inputs": []interface{}{
- map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
- map[string]interface{}{"type": "text", "name": "dir", "value": "", "view": "long", "imports": []interface{}{"plugin_dir", "plugin_you"}},
+ map[string]interface{}{"type": "text", "name": "pod", "imports": []interface{}{"plugin_you", "plugin_pod"}},
+ map[string]interface{}{"type": "text", "name": "dir", "value": "", "view": "long", "imports": []interface{}{"plugin_dir"}},
map[string]interface{}{"type": "button", "value": "查看"},
map[string]interface{}{"type": "button", "value": "回退", "click": "Back"},
},
@@ -340,7 +341,12 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
}},
"_node": &ctx.Command{Name: "_node [init|create name type module|delete name]", Help: "节点", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 {
- m.Cmdy("ctx.config", "node", "format", "table", "fields", "type", "module", "create_time")
+ m.Confm("ssh.node", func(key string, value map[string]interface{}) {
+ m.Add("append", "create_time", value["create_time"])
+ m.Add("append", "pod", key)
+ m.Add("append", "type", value["type"])
+ })
+ m.Sort("key").Table()
return
}
@@ -672,6 +678,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
m.Confm("node", names[0], func(name string, node map[string]interface{}) {
if kit.Format(node["type"]) != "master" {
ps = append(ps, kit.Format(node["module"]))
+ } else {
+ ps = append(ps, "")
}
})
diff --git a/src/examples/chat/chat.go b/src/examples/chat/chat.go
index cbbba141..c057daee 100644
--- a/src/examples/chat/chat.go
+++ b/src/examples/chat/chat.go
@@ -140,7 +140,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
case "weixin":
m.Cmdy(".js_token")
case "qrcode":
- m.Append("qrcode", arg[1])
+ m.Append("qrcode", kit.Select(m.Option("index_url"), arg, 1))
case "rename":
default:
if m.Cmds("ssh.work", "share", arg[0]) {
@@ -211,6 +211,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
"tool": map[string]interface{}{},
})
m.Echo(h)
+ return
m.Option("username", m.Conf("runtime", "user.name"))
m.Confm("flow", []string{h, "user"}, func(key string, value map[string]interface{}) {
diff --git a/usr/librarys/chat.css b/usr/librarys/chat.css
index 54820f73..4813510d 100644
--- a/usr/librarys/chat.css
+++ b/usr/librarys/chat.css
@@ -1,52 +1,52 @@
-fieldset.Ocean div.create pre:hover {
- background-color:red;
-}
-fieldset.Ocean div.create pre:hover {
- background-color:red;
-}
-
-fieldset.River {
- float:left;
-}
-fieldset.Target div.output div.item:hover {
- background-color:lightgreen;
-}
-fieldset.Target>div.output>div.item {
- padding-top:6px;
- clear:both;
-}
-fieldset.Target>div.output>div.item>div.text {
- padding:6px;
- float:left;
-}
-fieldset.Target>div.output>div.item>div.user {
- border-right:solid 1px green;
- border-bottom:solid 1px green;
- float:left;
- padding:6px;
-}
-fieldset.Source div.output {
- padding:0;
-}
-fieldset.Action div.output div.item:hover {
- background-color:lightblue;
-}
-fieldset.Storm {
- float:right;
-}
-
-fieldset.Steam table.device {
- padding:10px;
- border:solid 1px green;
- margin-left:10px;
- float:left;
-}
-fieldset.Steam div.output tr.select {
- background-color:red;
-}
-fieldset.Steam div.create {
- /* clear:both; */
-}
-fieldset.Steam div.create pre:hover {
- background-color:red;
-}
+fieldset.Ocean div.create pre:hover {
+ background-color:red;
+}
+fieldset.Ocean div.create pre:hover {
+ background-color:red;
+}
+
+fieldset.River {
+ float:left;
+}
+fieldset.Target div.output div.item:hover {
+ background-color:lightgreen;
+}
+fieldset.Target>div.output>div.item {
+ padding-top:6px;
+ clear:both;
+}
+fieldset.Target>div.output>div.item>div.text {
+ padding:6px;
+ float:left;
+}
+fieldset.Target>div.output>div.item>div.user {
+ border-right:solid 1px green;
+ border-bottom:solid 1px green;
+ float:left;
+ padding:6px;
+}
+fieldset.Source div.output {
+ padding:0;
+}
+fieldset.Action div.output div.item:hover {
+ background-color:lightblue;
+}
+fieldset.Storm {
+ float:right;
+}
+
+fieldset.Steam table.device {
+ padding:10px;
+ border:solid 1px green;
+ margin-left:10px;
+ float:left;
+}
+fieldset.Steam div.output tr.select {
+ background-color:red;
+}
+fieldset.Steam div.create {
+ /* clear:both; */
+}
+fieldset.Steam div.create pre:hover {
+ background-color:red;
+}
diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js
index 960438a9..38e9bd04 100644
--- a/usr/librarys/chat.js
+++ b/usr/librarys/chat.js
@@ -1,555 +1,555 @@
-page = Page({
- 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
- kit.isWindows && (document.body.style.overflow = "hidden")
-
- var height = document.body.clientHeight-page.conf.border
- var width = document.body.clientWidth-page.conf.border
- page.conf.height = height
- page.conf.width = width
-
- sizes = sizes || {}
- sizes.header == undefined && (sizes.header = page.header.clientHeight)
- sizes.footer == undefined && (sizes.footer = page.footer.clientHeight)
- page.header.Pane.Size(width, sizes.header)
- page.footer.Pane.Size(width, sizes.footer)
-
- sizes.river == undefined && (sizes.river = page.river.clientWidth)
- sizes.storm == undefined && (sizes.storm = page.storm.clientWidth)
- height -= page.header.offsetHeight+page.footer.offsetHeight
- page.river.Pane.Size(sizes.river, height)
- page.storm.Pane.Size(sizes.storm, height)
-
- sizes.action == undefined && (sizes.action = page.action.clientHeight)
- sizes.source == undefined && (sizes.source = page.source.clientHeight);
- (sizes.action == -1 || sizes.source == 0) && (sizes.action = height, sizes.source = 0)
- width -= page.river.offsetWidth+page.storm.offsetWidth
- page.action.Pane.Size(width, sizes.action)
- page.source.Pane.Size(width, sizes.source)
-
- height -= page.source.offsetHeight+page.action.offsetHeight
- page.target.Pane.Size(width, height)
- kit.History.add("lay", sizes)
- },
- oncontrol: function(event, target, action) {
- var page = this
- switch (action) {
- case "control":
- if (event.ctrlKey) {
- switch (event.key) {
- case "0":
- page.source.Pane.Select()
- break
- case "1":
- case "2":
- case "3":
- case "4":
- case "5":
- case "6":
- case "7":
- case "8":
- case "9":
- page.action.Pane.Select(parseInt(event.key))
- break
- case "n":
- page.ocean.Pane.Show()
- break
- case "m":
- page.steam.Pane.Show()
- break
- case "i":
- page.storm.Pane.Next()
- break
- case "o":
- page.storm.Pane.Prev()
- break
- case "b":
- page.action.Action["最大"](event)
-
- }
- break
- } else {
- switch (event.key) {
- case "Escape":
- page.dialog && page.dialog.Pane.Show()
- }
- }
- break
- }
- },
-
- initOcean: function(page, field, option, output) {
- var table = kit.AppendChild(output, "table")
- var ui = kit.AppendChild(field, [{view: ["create ocean"], list: [
- {input: ["name", function(event) {
- page.oninput(event, function(event) {
- switch (event.key) {
- case "1":
- case "2":
- case "3":
- case "4":
- case "5":
- case "6":
- case "7":
- case "8":
- var tr = table.querySelectorAll("tr.normal")[parseInt(event.key)-1]
- tr && tr.childNodes[0].click()
- return true
- case "9":
- field.Pane.Action["全选"](event)
- return true
- case "0":
- field.Pane.Action["清空"](event)
- return true
- case "-":
- var pre = ui.list.querySelector("pre")
- pre && pre.click()
- return true
- case "=":
- var td = table.querySelector("tr.normal td")
- td && td.click()
- return true
- }
- })
- event.key == "Enter" && this.nextSibling.click()
-
- }]}, {button: ["create", function(event) {
- 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)
- })
- if (cmd.length == 3) {
- kit.alert("请添加组员")
- return
- }
-
- field.Pane.Run(cmd, 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)
- }}])
- })
- }))
- },
- Action: {
- "取消": function(event) {
- field.Pane.Show()
- },
- "全选": function(event) {
- table.querySelectorAll("tr.normal").forEach(function(item) {
- item.firstChild.click()
- })
- },
- "清空": function(event) {
- ui.list.querySelectorAll("pre").forEach(function(item) {
- item.click()
- })
- },
- },
- Button: ["取消", "全选", "清空"],
- }
- },
- initRiver: function(page, field, option, output) {
- return {
- Show: function() {
- this.Update([], "text", ["name", "count"], "key", ctx.Search("river")||true)
- },
- Action: {
- "创建": function(event) {
- page.ocean.Pane.Show()
- },
- },
- Button: ["创建"],
- }
- },
- initTarget: function(page, field, option, output) {
- var river = ""
- var which = {}
- output.DisplayUser = true
- return {
- 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 = ["brow", river, 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(["flow", river, type, text], function(msg) {
- pane.Show(), typeof cb == "function" && cb(msg)
- })
- },
- }
- },
- initSource: function(page, field, option, output) {
- var ui = kit.AppendChild(field, [{"view": ["input", "textarea"], "data": {"onkeyup": function(event){
- page.oninput(event), kit.isSpace(event.key) && field.Pane.which.set(event.target.value)
- event.key == "Enter" && !event.shiftKey && page.target.Pane.Send("text", event.target.value, field.Pane.Clear)
- }, "onkeydown": function(event) {
- event.key == "Enter" && !event.shiftKey && event.preventDefault()
- }}}])
-
- return {
- Size: function(width, height) {
- field.style.display = (width<=0 || height<=0)? "none": "block"
- field.style.width = width+"px"
- field.style.height = height+"px"
- 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) {
- var plugin = event.Plugin
- event.shiftKey? page.target.Pane.Send("field", plugin.Format()):
- field.Pane.Run([river, storm, index].concat(args), function(msg) {
- var text = plugin.Reveal(msg)
- event.ctrlKey && page.target.Pane.Send(text[0], text[1])
- typeof cbs == "function" && cbs(msg)
- })
- })
- },
- Layout: function(name) {
- var layout = field.querySelector("select.layout")
- name && this.Action[layout.value = name](null, layout.value)
- return layout.value
- },
- Action: {
- "聊天": function(event, value) {
- page.onlayout(event, page.conf.layout)
- },
- "办公": function(event, value) {
- page.onlayout(event, page.conf.layout)
- page.onlayout(event, {river: 0, action:300, source:60})
- },
- "工作": function(event, value) {
- page.onlayout(event, page.conf.layout)
- page.onlayout(event, {river:0, action:-1, source:60})
- },
- "最高": function(event, value) {
- page.onlayout(event, {action: -1})
- },
- "最宽": function(event, value) {
- page.onlayout(event, {river:0, storm:0})
- },
- "最大": function(event, value) {
- page.onlayout(event, {header:0, footer:0, river:0, action: -1, storm:0})
- },
-
- "刷新": function(event, value) {
- output.innerHTML = "", field.Pane.Show()
- },
- "清空": function(event, value) {
- kit.Selector(output, "fieldset>div.output", function(item) {
- item.innerHTML = ""
- })
- },
- "并行": function(event, value) {
- kit.Selector(output, "fieldset", function(item) {
- item.Plugin.Runs(event)
- })
- },
- "串行": function(event, value) {
- var list = kit.Selector(output, "fieldset")
- function run(list) {
- list.length > 0? list[0].Plugin.Runs(event, function() {
- field.Pane.Conf("running", true), setTimeout(function() {
- run(list.slice(1))
- }, 1000)
- }): field.Pane.Conf("running", false)
- }
- run(list)
- },
-
- "添加": function(event, value) {
- page.plugin && page.plugin.Plugin.Clone().Select()
- },
- "删除": function(event, value) {
- page.input && page.plugin.Plugin.Delete()
- },
- "加参": function(event, value) {
- page.plugin && page.plugin.Plugin.Append({})
- },
- "减参": function(event, value) {
- page.plugin && page.plugin.Plugin.Remove()
- },
- },
- Button: [["layout", "聊天", "办公", "工作", "最高", "最宽", "最大"], "",
- "刷新", "清空", "并行", "串行", "",
- "添加", "删除", "加参", "减参", "",
- ],
- }
- },
- 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()
- },
- Prev: function() {
- var prev = output.querySelector("div.item.select").previousSibling
- prev? prev.click(): output.lastChild.click()
- },
- Action: {
- "创建": function(event) {
- page.steam.Pane.Show()
- },
- },
- Button: ["创建"],
- }
- },
- initSteam: function(page, field, option, output) {
- var river = ""
- var table = kit.AppendChild(output, "table")
- var device = kit.AppendChild(field, [{"view": ["device", "table"]}]).last
- var ui = kit.AppendChild(field, [{view: ["create steam"], list: [
- {input: ["name", function(event) {
- page.oninput(event, function(event) {
- switch (event.key) {
- case "i":
- var prev = table.querySelector("tr.select").previousSibling
- prev && prev.childNodes[0].click()
- return true
- case "o":
- var next = table.querySelector("tr.select").nextSibling
- next && next.childNodes[0].click()
- return true
- case "1":
- case "2":
- case "3":
- case "4":
- case "5":
- case "6":
- case "7":
- case "8":
- var tr = device.querySelectorAll("tr.normal")[parseInt(event.key)-1]
- tr && tr.childNodes[0].click()
- return true
- case "9":
- field.Pane.Action["全选"](event)
- return true
- case "0":
- field.Pane.Action["清空"](event)
- return true
- case "-":
- var tr = ui.list.querySelectorAll("tr")[1]
- tr && tr.childNodes[0].click()
- return true
- case "=":
- var td = device.querySelector("tr.normal td")
- td && td.click()
- return true
- }
- })
- event.key == "Enter" && this.nextSibling.click()
- }]}, {button: ["create", function(event) {
- 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)
- })
-
- if (cmd.length == 4) {
- kit.alert("请添加命令")
- return
- }
-
- 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
- },
- },
- Show: function() {
- this.ShowDialog() && (table.innerHTML = "", ui.name.value = "nice", this.Run([river], function(msg) {
- kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], 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.key], 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["user.route"], group: com.key, index: com.index, name: com.name}, click: function(event) {
- last.parentNode.removeChild(last)
- }}]).last
- })
- })
- })
- table.querySelector("td").click()
- ui.name.focus()
- }))
- },
- Action: {
- "取消": function(event) {
- field.Pane.Show()
- },
- "全选": function(event) {
- ui.list.innerHTML = "", device.querySelectorAll("tr").forEach(function(item) {
- item.firstChild.click()
- })
- },
- "清空": function(event) {
- ui.list.innerHTML = ""
- },
- },
- Button: ["取消", "全选", "清空"],
- }
- },
- init: function(page) {
- page.onlayout(null, page.conf.layout)
- page.action.Pane.Layout(ctx.Search("layout")? ctx.Search("layout"): kit.isMobile? "办公": "工作")
- page.footer.Pane.Order({"site": "", "ip": "", "text": "", ":":""}, kit.isMobile? ["site", "ip", "text"]: ["ip", "text", ":"], 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 = Page({
+ 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
+ kit.isWindows && (document.body.style.overflow = "hidden")
+
+ var height = document.body.clientHeight-page.conf.border
+ var width = document.body.clientWidth-page.conf.border
+ page.conf.height = height
+ page.conf.width = width
+
+ sizes = sizes || {}
+ sizes.header == undefined && (sizes.header = page.header.clientHeight)
+ sizes.footer == undefined && (sizes.footer = page.footer.clientHeight)
+ page.header.Pane.Size(width, sizes.header)
+ page.footer.Pane.Size(width, sizes.footer)
+
+ sizes.river == undefined && (sizes.river = page.river.clientWidth)
+ sizes.storm == undefined && (sizes.storm = page.storm.clientWidth)
+ height -= page.header.offsetHeight+page.footer.offsetHeight
+ page.river.Pane.Size(sizes.river, height)
+ page.storm.Pane.Size(sizes.storm, height)
+
+ sizes.action == undefined && (sizes.action = page.action.clientHeight)
+ sizes.source == undefined && (sizes.source = page.source.clientHeight);
+ (sizes.action == -1 || sizes.source == 0) && (sizes.action = height, sizes.source = 0)
+ width -= page.river.offsetWidth+page.storm.offsetWidth
+ page.action.Pane.Size(width, sizes.action)
+ page.source.Pane.Size(width, sizes.source)
+
+ height -= page.source.offsetHeight+page.action.offsetHeight
+ page.target.Pane.Size(width, height)
+ kit.History.add("lay", sizes)
+ },
+ oncontrol: function(event, target, action) {
+ var page = this
+ switch (action) {
+ case "control":
+ if (event.ctrlKey) {
+ switch (event.key) {
+ case "0":
+ page.source.Pane.Select()
+ break
+ case "1":
+ case "2":
+ case "3":
+ case "4":
+ case "5":
+ case "6":
+ case "7":
+ case "8":
+ case "9":
+ page.action.Pane.Select(parseInt(event.key))
+ break
+ case "n":
+ page.ocean.Pane.Show()
+ break
+ case "m":
+ page.steam.Pane.Show()
+ break
+ case "i":
+ page.storm.Pane.Next()
+ break
+ case "o":
+ page.storm.Pane.Prev()
+ break
+ case "b":
+ page.action.Action["最大"](event)
+
+ }
+ break
+ } else {
+ switch (event.key) {
+ case "Escape":
+ page.dialog && page.dialog.Pane.Show()
+ }
+ }
+ break
+ }
+ },
+
+ initOcean: function(page, field, option, output) {
+ var table = kit.AppendChild(output, "table")
+ var ui = kit.AppendChild(field, [{view: ["create ocean"], list: [
+ {input: ["name", function(event) {
+ page.oninput(event, function(event) {
+ switch (event.key) {
+ case "1":
+ case "2":
+ case "3":
+ case "4":
+ case "5":
+ case "6":
+ case "7":
+ case "8":
+ var tr = table.querySelectorAll("tr.normal")[parseInt(event.key)-1]
+ tr && tr.childNodes[0].click()
+ return true
+ case "9":
+ field.Pane.Action["全选"](event)
+ return true
+ case "0":
+ field.Pane.Action["清空"](event)
+ return true
+ case "-":
+ var pre = ui.list.querySelector("pre")
+ pre && pre.click()
+ return true
+ case "=":
+ var td = table.querySelector("tr.normal td")
+ td && td.click()
+ return true
+ }
+ })
+ event.key == "Enter" && this.nextSibling.click()
+
+ }]}, {button: ["create", function(event) {
+ 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)
+ })
+ if (cmd.length == 3) {
+ kit.alert("请添加组员")
+ return
+ }
+
+ field.Pane.Run(cmd, 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)
+ }}])
+ })
+ }))
+ },
+ Action: {
+ "取消": function(event) {
+ field.Pane.Show()
+ },
+ "全选": function(event) {
+ table.querySelectorAll("tr.normal").forEach(function(item) {
+ item.firstChild.click()
+ })
+ },
+ "清空": function(event) {
+ ui.list.querySelectorAll("pre").forEach(function(item) {
+ item.click()
+ })
+ },
+ },
+ Button: ["取消", "全选", "清空"],
+ }
+ },
+ initRiver: function(page, field, option, output) {
+ return {
+ Show: function() {
+ this.Update([], "text", ["name", "count"], "key", ctx.Search("river")||true)
+ },
+ Action: {
+ "创建": function(event) {
+ page.ocean.Pane.Show()
+ },
+ },
+ Button: ["创建"],
+ }
+ },
+ initTarget: function(page, field, option, output) {
+ var river = ""
+ var which = {}
+ output.DisplayUser = true
+ return {
+ 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 = ["brow", river, 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(["flow", river, type, text], function(msg) {
+ pane.Show(), typeof cb == "function" && cb(msg)
+ })
+ },
+ }
+ },
+ initSource: function(page, field, option, output) {
+ var ui = kit.AppendChild(field, [{"view": ["input", "textarea"], "data": {"onkeyup": function(event){
+ page.oninput(event), kit.isSpace(event.key) && field.Pane.which.set(event.target.value)
+ event.key == "Enter" && !event.shiftKey && page.target.Pane.Send("text", event.target.value, field.Pane.Clear)
+ }, "onkeydown": function(event) {
+ event.key == "Enter" && !event.shiftKey && event.preventDefault()
+ }}}])
+
+ return {
+ Size: function(width, height) {
+ field.style.display = (width<=0 || height<=0)? "none": "block"
+ field.style.width = width+"px"
+ field.style.height = height+"px"
+ 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) {
+ var plugin = event.Plugin
+ event.shiftKey? page.target.Pane.Send("field", plugin.Format()):
+ field.Pane.Run([river, storm, index].concat(args), function(msg) {
+ var text = plugin.Reveal(msg)
+ event.ctrlKey && page.target.Pane.Send(text[0], text[1])
+ typeof cbs == "function" && cbs(msg)
+ })
+ })
+ },
+ Layout: function(name) {
+ var layout = field.querySelector("select.layout")
+ name && this.Action[layout.value = name](null, layout.value)
+ return layout.value
+ },
+ Action: {
+ "聊天": function(event, value) {
+ page.onlayout(event, page.conf.layout)
+ },
+ "办公": function(event, value) {
+ page.onlayout(event, page.conf.layout)
+ page.onlayout(event, {river: 0, action:300, source:60})
+ },
+ "工作": function(event, value) {
+ page.onlayout(event, page.conf.layout)
+ page.onlayout(event, {river:0, action:-1, source:60})
+ },
+ "最高": function(event, value) {
+ page.onlayout(event, {action: -1})
+ },
+ "最宽": function(event, value) {
+ page.onlayout(event, {river:0, storm:0})
+ },
+ "最大": function(event, value) {
+ page.onlayout(event, {header:0, footer:0, river:0, action: -1, storm:0})
+ },
+
+ "刷新": function(event, value) {
+ output.innerHTML = "", field.Pane.Show()
+ },
+ "清空": function(event, value) {
+ kit.Selector(output, "fieldset>div.output", function(item) {
+ item.innerHTML = ""
+ })
+ },
+ "并行": function(event, value) {
+ kit.Selector(output, "fieldset", function(item) {
+ item.Plugin.Runs(event)
+ })
+ },
+ "串行": function(event, value) {
+ var list = kit.Selector(output, "fieldset")
+ function run(list) {
+ list.length > 0? list[0].Plugin.Runs(event, function() {
+ field.Pane.Conf("running", true), setTimeout(function() {
+ run(list.slice(1))
+ }, 100)
+ }): field.Pane.Conf("running", false)
+ }
+ run(list)
+ },
+
+ "添加": function(event, value) {
+ page.plugin && page.plugin.Plugin.Clone().Select()
+ },
+ "删除": function(event, value) {
+ page.input && page.plugin.Plugin.Delete()
+ },
+ "加参": function(event, value) {
+ page.plugin && page.plugin.Plugin.Append({})
+ },
+ "减参": function(event, value) {
+ page.plugin && page.plugin.Plugin.Remove()
+ },
+ },
+ Button: [["layout", "聊天", "办公", "工作", "最高", "最宽", "最大"], "",
+ "刷新", "清空", "并行", "串行", "",
+ "添加", "删除", "加参", "减参", "",
+ ],
+ }
+ },
+ 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()
+ },
+ Prev: function() {
+ var prev = output.querySelector("div.item.select").previousSibling
+ prev? prev.click(): output.lastChild.click()
+ },
+ Action: {
+ "创建": function(event) {
+ page.steam.Pane.Show()
+ },
+ },
+ Button: ["创建"],
+ }
+ },
+ initSteam: function(page, field, option, output) {
+ var river = ""
+ var table = kit.AppendChild(output, "table")
+ var device = kit.AppendChild(field, [{"view": ["device", "table"]}]).last
+ var ui = kit.AppendChild(field, [{view: ["create steam"], list: [
+ {input: ["name", function(event) {
+ page.oninput(event, function(event) {
+ switch (event.key) {
+ case "i":
+ var prev = table.querySelector("tr.select").previousSibling
+ prev && prev.childNodes[0].click()
+ return true
+ case "o":
+ var next = table.querySelector("tr.select").nextSibling
+ next && next.childNodes[0].click()
+ return true
+ case "1":
+ case "2":
+ case "3":
+ case "4":
+ case "5":
+ case "6":
+ case "7":
+ case "8":
+ var tr = device.querySelectorAll("tr.normal")[parseInt(event.key)-1]
+ tr && tr.childNodes[0].click()
+ return true
+ case "9":
+ field.Pane.Action["全选"](event)
+ return true
+ case "0":
+ field.Pane.Action["清空"](event)
+ return true
+ case "-":
+ var tr = ui.list.querySelectorAll("tr")[1]
+ tr && tr.childNodes[0].click()
+ return true
+ case "=":
+ var td = device.querySelector("tr.normal td")
+ td && td.click()
+ return true
+ }
+ })
+ event.key == "Enter" && this.nextSibling.click()
+ }]}, {button: ["create", function(event) {
+ 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)
+ })
+
+ if (cmd.length == 4) {
+ kit.alert("请添加命令")
+ return
+ }
+
+ 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
+ },
+ },
+ Show: function() {
+ this.ShowDialog() && (table.innerHTML = "", ui.name.value = "nice", this.Run([river], function(msg) {
+ kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], 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.key], 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["user.route"], group: com.key, index: com.index, name: com.name}, click: function(event) {
+ last.parentNode.removeChild(last)
+ }}]).last
+ })
+ })
+ })
+ table.querySelector("td").click()
+ ui.name.focus()
+ }))
+ },
+ Action: {
+ "取消": function(event) {
+ field.Pane.Show()
+ },
+ "全选": function(event) {
+ ui.list.innerHTML = "", device.querySelectorAll("tr").forEach(function(item) {
+ item.firstChild.click()
+ })
+ },
+ "清空": function(event) {
+ ui.list.innerHTML = ""
+ },
+ },
+ Button: ["取消", "全选", "清空"],
+ }
+ },
+ init: function(page) {
+ page.onlayout(null, page.conf.layout)
+ page.action.Pane.Layout(ctx.Search("layout")? ctx.Search("layout"): kit.isMobile? "办公": "工作")
+ page.footer.Pane.Order({"site": "", "ip": "", "text": "", ":":""}, kit.isMobile? ["site", "ip", "text"]: ["ip", "text", ":"], 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)
+ })
+ },
+})
diff --git a/usr/librarys/context.js b/usr/librarys/context.js
index 2bc19e22..74fbe5f4 100644
--- a/usr/librarys/context.js
+++ b/usr/librarys/context.js
@@ -4,7 +4,7 @@ ctx = context = {
for (var k in dataset) {
option[k] = dataset[k].split(",")
}
- kit.Log(option)
+ kit.Log(cmd)
this.GET("", option, function(msg) {
msg[0] && (msg = msg[0])
// msg && (msg.__proto__ = (page || {}))
diff --git a/usr/librarys/example.css b/usr/librarys/example.css
index c85dbb2e..45ff1e0f 100644
--- a/usr/librarys/example.css
+++ b/usr/librarys/example.css
@@ -23,7 +23,7 @@ fieldset>form.option div.hide {
display:none;
}
fieldset>form.option div input.args {
- width:80px;
+ width:100px;
}
fieldset>form.option div.cmd input.args {
color:white;
@@ -81,7 +81,8 @@ fieldset>div.output table td {
}
fieldset.toast {
- background-color:#ffffff00;
+ border:solid 2px red;
+ background-color:#ffffff;
position:absolute;
display:none;
}
diff --git a/usr/librarys/example.js b/usr/librarys/example.js
index 79e7ef93..c7087370 100644
--- a/usr/librarys/example.js
+++ b/usr/librarys/example.js
@@ -1,728 +1,753 @@
-function Page(page) {
- var id = 1
- var conf = {}, conf_cb = {}
- var sync = {}
- page.__proto__ = {
- __proto__: kit,
- ID: function() {
- return id++
- },
- Conf: function(key, value, cb) {
- if (key == undefined) {
- return conf
- }
- if (cb != undefined) {
- conf_cb[key] = cb
- }
- if (value != undefined) {
- var old = conf[key]
- conf[key] = value
- conf_cb[key] && conf_cb[key](value, old)
- }
- return conf[key]
- },
- 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
- },
- set: function(value, force) {
- 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++) {
- list[i](value, old_value)
- }
- return value
- },
- })
- },
- View: function(parent, type, line, key, cb) {
- var text = line, list = [], ui = {}
- switch (type) {
- case "icon":
- list.push({img: [line[key[0]], function(event) {
- // event.target.scrollIntoView()
- }]})
- break
-
- case "text":
- list.push({text: [key.length>1? line[key[0]]+"("+line[key[1]]+")":
- (key.length>0? line[key[0]]: "null"), "span"], click: cb})
- break
-
- case "code":
- list.push({view: ["code", key.length>1? line[key[0]]+"("+line[key[1]]+")":
- (key.length>0? line[key[0]]: "null")], click: cb})
- break
-
- case "table":
- list.push({type: "table", list: JSON.parse(line.text || "[]").map(function(item, index) {
- return {type: "tr", list: item.map(function(value) {
- return {text: [value, index == 0? "th": "td"]}
- })}
- })})
- break
-
- case "field":
- var text = JSON.parse(line.text)
-
- case "plugin":
- var id = "plugin"+page.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"}}]},
- {view: ["output", "div", "", "output"]},
- {script: ""+id+".Script="+(text.init||"{}")},
- ]})
- break
- }
-
- parent.DisplayUser && (list = [{view: ["user", "div", line.create_nick||line.create_user]}, {view: ["text"], list:list}])
- !parent.DisplayRaw && (list = [{view: ["item"], list:list}])
- ui = kit.AppendChild(parent, list)
- ui.field && (ui.field.Meta = text)
- return ui
- },
- Include: function(src, cb) {
- kit.AppendChild(document.body, [{include: [src[0], function(event) {
- src.length == 1? cb(event): page.Include(src.slice(1), cb)
- }]}])
- },
- ontoast: function(text, title, duration) {
- var args = typeof text == "object"? text: {text: text, title: title, duration: duration}
- var toast = kit.ModifyView("fieldset.toast", {
- display: "block", dialog: [args.width||200, args.height||40], padding: 10,
- })
-
- var list = [{text: [args.text||""]}]
- args.inputs && args.inputs.forEach(function(input) {
- if (typeof input == "string") {
- list.push({inner: input, type: "label", style: {"margin-right": "5px"}})
- list.push({input: [input, page.oninput]})
- } else {
- list.push({inner: input[0], type: "label", style: {"margin-right": "5px"}})
- var option = []
- for (var i = 1; i < input.length; i++) {
- option.push({type: "option", inner: input[i]})
- }
- list.push({name: input[0], type: "select", list: option})
- }
- list.push({type: "br"})
- })
- args.button && args.button.forEach(function(input) {
- list.push({type: "button", inner: input, click: function(event) {
- var values = {}
- toast.querySelectorAll("input").forEach(function(input) {
- values[input.name] = input.value
- })
- toast.querySelectorAll("select").forEach(function(input) {
- values[input.name] = input.value
- })
- typeof args.cb == "function" && args.cb(input, values)
- toast.style.display = "none"
- }})
- })
-
- kit.ModifyNode(toast.querySelector("legend"), args.title||"tips")
- var ui = kit.AppendChild(kit.ModifyNode(toast.querySelector("div.output"), ""), list)
- args.duration !=- 1 && setTimeout(function(){toast.style.display = "none"}, args.duration||3000)
- page.toast = toast
- },
- ondebug: function() {
- if (!this.debug) {
- var pane = Pane(page)
- pane.Field.style.position = "absolute"
- pane.Field.style["background-color"] = "#ffffff00"
- pane.Field.style["color"] = "red"
- pane.ShowDialog(400, 400)
- this.debug = pane
- }
- kit.AppendChild(this.debug.Field, [{text: [JSON.stringify(arguments.length==1? arguments[0]: arguments)]}])
- },
- oninput: function(event, local) {
- var target = event.target
- kit.History.add("key", (event.ctrlKey? "Control+": "")+(event.shiftKey? "Shift+": "")+event.key)
-
- if (event.ctrlKey) {
- if (typeof local == "function" && local(event)) {
- event.stopPropagation()
- event.preventDefault()
- return true
- }
- switch (event.key) {
- case "a":
- case "e":
- case "f":
- case "b":
- case "h":
- case "d":
- break
- case "k":
- kit.DelText(target, target.selectionStart)
- break
- case "u":
- kit.DelText(target, 0, target.selectionEnd)
- break
- case "w":
- var start = target.selectionStart-2
- var end = target.selectionEnd-1
- for (var i = start; i >= 0; i--) {
- if (target.value[end] == " " && target.value[i] != " ") {
- break
- }
- if (target.value[end] != " " && target.value[i] == " ") {
- break
- }
- }
- kit.DelText(target, i+1, end-i)
- break
- default:
- return false
-
- }
- event.stopPropagation()
- return true
- }
- switch (event.key) {
- case "Escape":
- target.blur()
- event.stopPropagation()
- return true
- default:
- if (kit.HitText(target, "jk")) {
- kit.DelText(target, target.selectionStart-2, 2)
- target.blur()
- event.stopPropagation()
- return true
- }
- }
- return false
- },
- onscroll: function(event, target, action) {
- switch (event.key) {
- case "h":
- if (event.ctrlKey) {
- target.scrollBy(-conf.scroll_x*10, 0)
- } else {
- target.scrollBy(-conf.scroll_x, 0)
- }
- break
- case "H":
- target.scrollBy(-document.body.scrollWidth, 0)
- break
- case "l":
- if (event.ctrlKey) {
- target.scrollBy(conf.scroll_x*10, 0)
- } else {
- target.scrollBy(conf.scroll_x, 0)
- }
- break
- case "L":
- target.scrollBy(document.body.scrollWidth, 0)
- break
- case "j":
- if (event.ctrlKey) {
- target.scrollBy(0, conf.scroll_y*10)
- } else {
- target.scrollBy(0, conf.scroll_y)
- }
- break
- case "J":
- target.scrollBy(0, document.body.scrollHeight)
- break
- case "k":
- if (event.ctrlKey) {
- target.scrollBy(0, -conf.scroll_y*10)
- } else {
- target.scrollBy(0, -conf.scroll_y)
- }
- break
- case "K":
- target.scrollBy(0, -document.body.scrollHeight)
- break
- }
- },
-
- 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)
- }
- return {
- Order: function(value, order, cbs) {
- state = value, list = order, cb = cbs || cb, this.Show()
- },
- Show: function() {
- output.innerHTML = "", kit.AppendChild(output, [
- {"view": ["title", "div", "shycontext"], click: function(event) {
- cb(event, "title", "shycontext")
- }},
- {"view": ["state"], list: list.map(function(item) {return {text: [state[item], "div"], click: function(event) {
- cb(event, item, state[item])
- }}})},
- ])
- },
- 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)
- }
- return {
- Order: function(value, order, cbs) {
- state = value, list = order, cb = cbs || cb, this.Show()
- },
- Show: function() {
- output.innerHTML = "", kit.AppendChild(output, [
- {"view": ["title", "div", "shylinux@163.com>"]},
- {"view": ["state"], list: list.map(function(item) {return {text: [item+":"+state[item], "div"], click: function(item) {
- cb(event, item, state[item])
- }}})},
- ])
- },
- 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"},
- {type: "img", data: {"src": "/chat/qrcode?text=hi"}}
- ])
- 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) {
- page.oncontrol && page.oncontrol(event, document.body, "control")
- }
- }
- return 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 conf = {}, conf_cb = {}
- var name = option.dataset.componet_name
- var pane = (page[field.dataset.init] || function() {
- })(page, field, option, output) || {}; pane.__proto__ = {
- __proto__: page,
- Conf: function(key, value, cb) {
- if (key == undefined) {
- return conf
- }
- if (cb != undefined) {
- conf_cb[key] = cb
- }
- if (value != undefined) {
- var old = conf[key]
- conf[key] = value
- conf_cb[key] && conf_cb[key](value, old)
- }
- return conf[key]
- },
- ShowDialog: 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]})
- return true
- }
- field.style.display = "none"
- 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"
- },
- View: function(parent, type, line, key, cb) {
- var ui = page.View(parent, 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.View(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()
- }
- })
- },
- Share: function(objs) {
- objs = objs || {}
- objs.componet_name = option.dataset.componet_name
- objs.componet_group = option.dataset.componet_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,
- }
-
- for (var k in pane.Listen) {
- page.Sync(k).change(pane.Listen[k])
- }
- pane.Button && pane.Button.length > 0 && (kit.InsertChild(field, output, "div", pane.Button.map(function(value) {
- return typeof value == "object"? {className: value[0], select: [value.slice(1), function(event) {
- value = event.target.value
- typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
- }]}: value == ""? {view: ["space"]} :value == "br"? {type: "br"}: {button: [value, function(event) {
- typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
- }]}
- })).className="action "+name)
- option.onsubmit = function(event) {
- event.preventDefault()
- };
- return page[name] = field, pane.Field = field, field.Pane = pane
-}
-function Plugin(page, pane, field) {
- var option = field.querySelector("form.option")
- var output = field.querySelector("div.output")
-
- var count = 0
- var wait = false
- var plugin = field.Script || {}; plugin.__proto__ = {
- __proto__: pane,
- Append: function(item, name) {
- name = name || item.name
-
- item.onfocus = function(event) {
- page.pane = pane.Field, page.plugin = field, page.input = event.target
- }
- item.onkeydown = function(event) {
- page.oninput(event, function(event) {
- switch (event.key) {
- case "p":
- action.Back()
- break
- case "i":
- var next = field.nextSibling;
- next && next.Plugin.Select()
- break
- case "o":
- var prev = field.previousSibling;
- prev && prev.Plugin.Select()
- break
- case "c":
- output.innerHTML = ""
- break
- case "r":
- output.innerHTML = ""
- case "j":
- plugin.Runs(event)
- break
- case "l":
- page.action.scrollTo(0, field.offsetTop)
- break
- case "b":
- plugin.Append(item).focus()
- break
- case "m":
- plugin.Clone().plugin.Plugin.Select()
- break
- default:
- return false
- }
- event.stopPropagation()
- event.preventDefault()
- return true
- })
- event.key == "Enter" && 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)
- }
-
- default:
- if (item.type == "text") {
- item.onclick = function(event) {
- if (event.ctrlKey) {
- action.value = kit.History.get("txt", -1).data
- }
- }
- }
- 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] || {}
-
- action.History = [""], action.Goto = function(value) {
- action.History.push(action.value = value)
- plugin.Check(action)
- return value
- }, action.Back = function() {
- action.History.pop(), action.History.length > 0 && action.Goto(action.History.pop())
- };
-
- (typeof item.imports == "object"? item.imports: typeof item.imports == "string"? [item.imports]: []).forEach(function(imports) {
- page.Sync(imports).change(action.Goto)
- })
- 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.View(field.parentNode, "plugin", field.Meta, [], field.Run).field.Plugin
- },
- Check: function(target) {
- option.querySelectorAll(".args").forEach(function(item, index, list) {
- item == target && (index == list.length-1? plugin.Runs(event): page.plugin == field && list[index+1].focus())
- })
- },
- Runs: function(event, cb) {
- if (wait) {
- return
- }
- wait = true, event.Plugin = plugin, this.Clear(), field.Run(event, kit.Selector(option, ".args", function(item, index) {
- return item.value
- }), function(msg) {
- wait = false, typeof cb == "function" && cb(msg)
- plugin.ondaemon[display.deal||"table"](msg)
- })
- },
- Clear: function() {
- output.innerHTML = ""
- },
- ondaemon: {
- table: function(msg) {
- output.innerHTML = ""
- if (display.map) {
- 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"]}])
- return
- }
- 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) {
- if (line["latitude"]) {
- page.openLocation(line.latitude, line.longitude, line.location)
- }
- page.Sync("plugin_"+exports[0]).set(plugin.onexport[exports[2]||""](value, name))
- });
- (display.show_result || !msg.append) && msg.result && kit.AppendChild(output, [{view: ["code", "div", msg.Results()]}])
- },
- },
- onexport: {
- "": function(value, name) {
- return value
- },
- "pod": function(value, name) {
- if (option[exports[0]].value) {
- return option[exports[0]].value+"."+value
- }
- return value
- },
- "dir": function(value, name) {
- if (value.endsWith("/")) {
- return option[exports[0]] + value
- }
- },
- },
-
- Location: function(event) {
- output.className = "output long"
- page.getLocation(function(res) {
- field.Run(event, [parseInt(res.latitude*1000000+1400)/1000000.0, parseInt(res.longitude*1000000+6250)/1000000.0].concat(
- kit.Selector(option, ".args", function(item) {return item.value}))
- , plugin.ondaemon)
- })
- },
- init: function() {},
- }
-
- var meta = field.Meta
- var args = meta.args || []
- var display = JSON.parse(meta.display||'{}')
- var exports = JSON.parse(meta.exports||'["",""]')
- JSON.parse(meta.inputs || "[]").map(plugin.Append)
-
- plugin.init(page, pane, field, option, output)
- return page[field.id] = pane[field.id] = plugin.Field = field, field.Plugin = plugin
-}
+function Page(page) {
+ var id = 1
+ var conf = {}, conf_cb = {}
+ var sync = {}
+ page.__proto__ = {
+ __proto__: kit,
+ ID: function() {
+ return id++
+ },
+ Conf: function(key, value, cb) {
+ if (key == undefined) {
+ return conf
+ }
+ if (cb != undefined) {
+ conf_cb[key] = cb
+ }
+ if (value != undefined) {
+ var old = conf[key]
+ conf[key] = value
+ conf_cb[key] && conf_cb[key](value, old)
+ }
+ return conf[key]
+ },
+ 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
+ },
+ set: function(value, force) {
+ 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++) {
+ list[i](value, old_value)
+ }
+ return value
+ },
+ })
+ },
+ View: function(parent, type, line, key, cb) {
+ var text = line, list = [], ui = {}
+ switch (type) {
+ case "icon":
+ list.push({img: [line[key[0]], function(event) {
+ // event.target.scrollIntoView()
+ }]})
+ break
+
+ case "text":
+ list.push({text: [key.length>1? line[key[0]]+"("+line[key[1]]+")":
+ (key.length>0? line[key[0]]: "null"), "span"], click: cb})
+ break
+
+ case "code":
+ list.push({view: ["code", key.length>1? line[key[0]]+"("+line[key[1]]+")":
+ (key.length>0? line[key[0]]: "null")], click: cb})
+ break
+
+ case "table":
+ list.push({type: "table", list: JSON.parse(line.text || "[]").map(function(item, index) {
+ return {type: "tr", list: item.map(function(value) {
+ return {text: [value, index == 0? "th": "td"]}
+ })}
+ })})
+ break
+
+ case "field":
+ var text = JSON.parse(line.text)
+
+ case "plugin":
+ var id = "plugin"+page.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"}}]},
+ {view: ["output", "div", "", "output"]},
+ {script: ""+id+".Script="+(text.init||"{}")},
+ ]})
+ break
+ }
+
+ parent.DisplayUser && (list = [{view: ["user", "div", line.create_nick||line.create_user]}, {view: ["text"], list:list}])
+ !parent.DisplayRaw && (list = [{view: ["item"], list:list}])
+ ui = kit.AppendChild(parent, list)
+ ui.field && (ui.field.Meta = text)
+ return ui
+ },
+ Include: function(src, cb) {
+ kit.AppendChild(document.body, [{include: [src[0], function(event) {
+ src.length == 1? cb(event): page.Include(src.slice(1), cb)
+ }]}])
+ },
+ ontoast: function(text, title, duration) {
+ var args = typeof text == "object"? text: {text: text, title: title, duration: duration}
+ var toast = kit.ModifyView("fieldset.toast", {
+ display: "block", dialog: [args.width||200, args.height||40], padding: 10,
+ })
+ if (!text) {
+ toast.style.display = "none"
+ return
+ }
+
+ var list = [{text: [args.text||""]}]
+ args.inputs && args.inputs.forEach(function(input) {
+ if (typeof input == "string") {
+ list.push({inner: input, type: "label", style: {"margin-right": "5px"}})
+ list.push({input: [input, page.oninput]})
+ } else {
+ list.push({inner: input[0], type: "label", style: {"margin-right": "5px"}})
+ var option = []
+ for (var i = 1; i < input.length; i++) {
+ option.push({type: "option", inner: input[i]})
+ }
+ list.push({name: input[0], type: "select", list: option})
+ }
+ list.push({type: "br"})
+ })
+ args.button && args.button.forEach(function(input) {
+ list.push({type: "button", inner: input, click: function(event) {
+ var values = {}
+ toast.querySelectorAll("input").forEach(function(input) {
+ values[input.name] = input.value
+ })
+ toast.querySelectorAll("select").forEach(function(input) {
+ values[input.name] = input.value
+ })
+ typeof args.cb == "function" && args.cb(input, values)
+ toast.style.display = "none"
+ }})
+ })
+
+ kit.ModifyNode(toast.querySelector("legend"), args.title||"tips")
+ var ui = kit.AppendChild(kit.ModifyNode(toast.querySelector("div.output"), ""), list)
+ args.duration !=- 1 && setTimeout(function(){toast.style.display = "none"}, args.duration||3000)
+ page.toast = toast
+ return true
+ },
+ ondebug: function() {
+ if (!this.debug) {
+ var pane = Pane(page)
+ pane.Field.style.position = "absolute"
+ pane.Field.style["background-color"] = "#ffffff00"
+ pane.Field.style["color"] = "red"
+ pane.ShowDialog(400, 400)
+ this.debug = pane
+ }
+ kit.AppendChild(this.debug.Field, [{text: [JSON.stringify(arguments.length==1? arguments[0]: arguments)]}])
+ },
+ oninput: function(event, local) {
+ var target = event.target
+ kit.History.add("key", (event.ctrlKey? "Control+": "")+(event.shiftKey? "Shift+": "")+event.key)
+
+ if (event.ctrlKey) {
+ if (typeof local == "function" && local(event)) {
+ event.stopPropagation()
+ event.preventDefault()
+ return true
+ }
+ switch (event.key) {
+ case "a":
+ case "e":
+ case "f":
+ case "b":
+ case "h":
+ case "d":
+ break
+ case "k":
+ kit.DelText(target, target.selectionStart)
+ break
+ case "u":
+ kit.DelText(target, 0, target.selectionEnd)
+ break
+ case "w":
+ var start = target.selectionStart-2
+ var end = target.selectionEnd-1
+ for (var i = start; i >= 0; i--) {
+ if (target.value[end] == " " && target.value[i] != " ") {
+ break
+ }
+ if (target.value[end] != " " && target.value[i] == " ") {
+ break
+ }
+ }
+ kit.DelText(target, i+1, end-i)
+ break
+ default:
+ return false
+
+ }
+ event.stopPropagation()
+ return true
+ }
+ switch (event.key) {
+ case "Escape":
+ target.blur()
+ event.stopPropagation()
+ return true
+ default:
+ if (kit.HitText(target, "jk")) {
+ kit.DelText(target, target.selectionStart-2, 2)
+ target.blur()
+ event.stopPropagation()
+ return true
+ }
+ }
+ return false
+ },
+ onscroll: function(event, target, action) {
+ switch (event.key) {
+ case "h":
+ if (event.ctrlKey) {
+ target.scrollBy(-conf.scroll_x*10, 0)
+ } else {
+ target.scrollBy(-conf.scroll_x, 0)
+ }
+ break
+ case "H":
+ target.scrollBy(-document.body.scrollWidth, 0)
+ break
+ case "l":
+ if (event.ctrlKey) {
+ target.scrollBy(conf.scroll_x*10, 0)
+ } else {
+ target.scrollBy(conf.scroll_x, 0)
+ }
+ break
+ case "L":
+ target.scrollBy(document.body.scrollWidth, 0)
+ break
+ case "j":
+ if (event.ctrlKey) {
+ target.scrollBy(0, conf.scroll_y*10)
+ } else {
+ target.scrollBy(0, conf.scroll_y)
+ }
+ break
+ case "J":
+ target.scrollBy(0, document.body.scrollHeight)
+ break
+ case "k":
+ if (event.ctrlKey) {
+ target.scrollBy(0, -conf.scroll_y*10)
+ } else {
+ target.scrollBy(0, -conf.scroll_y)
+ }
+ break
+ case "K":
+ target.scrollBy(0, -document.body.scrollHeight)
+ break
+ }
+ },
+
+ 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)
+ }
+ return {
+ Order: function(value, order, cbs) {
+ state = value, list = order, cb = cbs || cb, this.Show()
+ },
+ Show: function() {
+ output.innerHTML = "", kit.AppendChild(output, [
+ {"view": ["title", "div", "shycontext"], click: function(event) {
+ cb(event, "title", "shycontext")
+ }},
+ {"view": ["state"], list: list.map(function(item) {return {text: [state[item], "div"], click: function(event) {
+ cb(event, item, state[item])
+ }}})},
+ ])
+ },
+ 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)
+ }
+ return {
+ Order: function(value, order, cbs) {
+ state = value, list = order, cb = cbs || cb, this.Show()
+ },
+ Show: function() {
+ output.innerHTML = "", kit.AppendChild(output, [
+ {"view": ["title", "div", "shylinux@163.com>"]},
+ {"view": ["state"], list: list.map(function(item) {return {text: [item+":"+state[item], "div"], click: function(item) {
+ cb(event, item, state[item])
+ }}})},
+ ])
+ },
+ 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"},
+ {type: "img", data: {"src": "/chat/qrcode?text=hi"}}
+ ])
+ 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) {
+ page.oncontrol && page.oncontrol(event, document.body, "control")
+ }
+ }
+ return 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 conf = {}, conf_cb = {}
+ var name = option.dataset.componet_name
+ var pane = (page[field.dataset.init] || function() {
+ })(page, field, option, output) || {}; pane.__proto__ = {
+ __proto__: page,
+ Conf: function(key, value, cb) {
+ if (key == undefined) {
+ return conf
+ }
+ if (cb != undefined) {
+ conf_cb[key] = cb
+ }
+ if (value != undefined) {
+ var old = conf[key]
+ conf[key] = value
+ conf_cb[key] && conf_cb[key](value, old)
+ }
+ return conf[key]
+ },
+ ShowDialog: 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]})
+ return true
+ }
+ field.style.display = "none"
+ 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"
+ },
+ View: function(parent, type, line, key, cb) {
+ var ui = page.View(parent, 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.View(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()
+ }
+ })
+ },
+ Share: function(objs) {
+ objs = objs || {}
+ objs.componet_name = option.dataset.componet_name
+ objs.componet_group = option.dataset.componet_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,
+ }
+
+ for (var k in pane.Listen) {
+ page.Sync(k).change(pane.Listen[k])
+ }
+ pane.Button && pane.Button.length > 0 && (kit.InsertChild(field, output, "div", pane.Button.map(function(value) {
+ return typeof value == "object"? {className: value[0], select: [value.slice(1), function(event) {
+ value = event.target.value
+ typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
+ }]}: value == ""? {view: ["space"]} :value == "br"? {type: "br"}: {button: [value, function(event) {
+ typeof pane.Action == "function"? pane.Action(value, event): pane.Action[value](event, value)
+ }]}
+ })).className="action "+name)
+ option.onsubmit = function(event) {
+ event.preventDefault()
+ };
+ return page[name] = field, pane.Field = field, field.Pane = pane
+}
+function Plugin(page, pane, field) {
+ var option = field.querySelector("form.option")
+ var output = field.querySelector("div.output")
+
+ var count = 0
+ var wait = false
+ var plugin = field.Script || {}; plugin.__proto__ = {
+ __proto__: pane,
+ Append: function(item, name) {
+ name = name || item.name
+
+ item.onfocus = function(event) {
+ page.pane = pane.Field, page.plugin = field, page.input = event.target
+ }
+ item.onkeydown = function(event) {
+ page.oninput(event, function(event) {
+ switch (event.key) {
+ case "p":
+ action.Back()
+ break
+ case "i":
+ var next = field.nextSibling;
+ next && next.Plugin.Select()
+ break
+ case "o":
+ var prev = field.previousSibling;
+ prev && prev.Plugin.Select()
+ break
+ case "c":
+ output.innerHTML = ""
+ break
+ case "r":
+ output.innerHTML = ""
+ case "j":
+ plugin.Runs(event)
+ break
+ case "l":
+ page.action.scrollTo(0, field.offsetTop)
+ break
+ case "b":
+ plugin.Append(item).focus()
+ break
+ case "m":
+ plugin.Clone().plugin.Plugin.Select()
+ break
+ default:
+ return false
+ }
+ event.stopPropagation()
+ event.preventDefault()
+ return true
+ })
+ event.key == "Enter" && 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)
+ }
+
+ default:
+ if (item.type == "text") {
+ item.onclick = function(event) {
+ if (event.ctrlKey) {
+ action.value = kit.History.get("txt", -1).data
+ }
+ }
+ }
+ 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] || {}
+
+ action.History = [""], action.Goto = function(value) {
+ action.History.push(action.value = value)
+ plugin.Check(action)
+ return value
+ }, action.Back = function() {
+ action.History.pop(), action.History.length > 0 && action.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)
+ 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.View(field.parentNode, "plugin", field.Meta, [], field.Run).field.Plugin
+ },
+ Check: function(target) {
+ option.querySelectorAll(".args").forEach(function(item, index, list) {
+ item == target && (index == list.length-1? plugin.Runs(event): page.plugin == field && list[index+1].focus())
+ })
+ },
+ Runs: function(event, cb) {
+ if (wait) {
+ return
+ }
+ wait = true, event.Plugin = plugin, this.Clear(), field.Run(event, kit.Selector(option, ".args", function(item, index) {
+ return item.value
+ }), function(msg) {
+ wait = false, typeof cb == "function" && cb(msg)
+ plugin.ondaemon[display.deal||"table"](msg)
+ })
+ },
+ Delay: function(time, event, text) {
+ page.ontoast(text, "run", -1)
+ setTimeout(function() {
+ plugin.Runs(event)
+ page.ontoast("")
+ }, time)
+ return time
+ },
+ Clear: function() {
+ output.innerHTML = ""
+ },
+ ondaemon: {
+ table: function(msg) {
+ output.innerHTML = ""
+ if (display.map) {
+ 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"]}])
+ return
+ }
+ 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) {
+ if (line["latitude"]) {
+ page.openLocation(line.latitude, line.longitude, line.location)
+ }
+ page.Sync("plugin_"+exports[0]).set(plugin.onexport[exports[2]||""](value, name, line))
+ });
+ (display.show_result || !msg.append) && msg.result && kit.AppendChild(output, [{view: ["code", "div", msg.Results()]}])
+ },
+ },
+ onexport: {
+ "": function(value, name) {
+ return value
+ },
+ you: function(value, name, line) {
+ window.event.Plugin = plugin
+ name == "status" && (line.status == "start"? function() {
+ plugin.Delay(2000, window.event, line.you+" stop...") && field.Run(window.event, [line.you, "stop"])
+ }(): field.Run(window.event, [line.you], function(msg) {
+ plugin.Delay(1000, window.event, line.you+" start...") && plugin.Runs(window.event)
+ }))
+ return name == "you"? value: undefined
+ },
+ pod: function(value, name) {
+ if (option[exports[0]].value) {
+ return option[exports[0]].value+"."+value
+ }
+ return value
+ },
+ dir: function(value, name) {
+ if (value.endsWith("/")) {
+ return option[exports[0]] + value
+ }
+ },
+ },
+
+ Location: function(event) {
+ output.className = "output long"
+ page.getLocation(function(res) {
+ field.Run(event, [parseInt(res.latitude*1000000+1400)/1000000.0, parseInt(res.longitude*1000000+6250)/1000000.0].concat(
+ kit.Selector(option, ".args", function(item) {return item.value}))
+ , plugin.ondaemon)
+ })
+ },
+ init: function() {},
+ }
+
+ var meta = field.Meta
+ var args = meta.args || []
+ var display = JSON.parse(meta.display||'{}')
+ var exports = JSON.parse(meta.exports||'["",""]')
+ JSON.parse(meta.inputs || "[]").map(plugin.Append)
+
+ plugin.init(page, pane, field, option, output)
+ return page[field.id] = pane[field.id] = plugin.Field = field, field.Plugin = plugin
+}
diff --git a/usr/librarys/toolkit.js b/usr/librarys/toolkit.js
index ecf79894..83a8b38b 100644
--- a/usr/librarys/toolkit.js
+++ b/usr/librarys/toolkit.js
@@ -1,620 +1,620 @@
-kit = toolkit = {
- isMobile: navigator.userAgent.indexOf("Mobile") > -1,
- isWeiXin: navigator.userAgent.indexOf("MicroMessenger") > -1,
- isMacOSX: navigator.userAgent.indexOf("Mac OS X") > -1,
- isWindows: navigator.userAgent.indexOf("Windows") > -1,
- isIPhone: navigator.userAgent.indexOf("iPhone") > -1,
- isSpace: function(c) {
- return c == " " || c == "Enter"
- },
- History: {dir: [], pod: [], ctx: [], cmd: [], txt: [], key: [], lay: [],
- add: function(type, data) {
- var list = this[type] || []
- data && list.push({time: Date.now(), data: data})
- this[type] = list
- return list.length-1
- },
- get: function(type, index) {
- var list = this[type] || []
- var len = list.length
- return index == undefined? this[type]: this[type][(index+len)%len]
- },
- },
- Log: function() {
- var args = []
- for (var i = 0; i < arguments.length; i++) {
- args.push(arguments[i])
- }
- console.log(arguments.length == 1? args[0]: args)
- return args
- },
-
- ModifyView: function(which, args) {
- var height = document.body.clientHeight-4
- var width = document.body.clientWidth-4
- for (var k in args) {
- switch (k) {
- case "dialog":
- var w = h = args[k]
- if (typeof(args[k]) == "object") {
- w = args[k][0]
- h = args[k][1]
- }
- if (w > width) {
- w = width
- }
- if (h > height) {
- h = height
- }
-
- args["top"] = (height-h)/2
- args["left"] = (width-w)/2
- args["width"] = w
- args["height"] = h
- args[k] = undefined
- break
- case "window":
- var w = h = args[k]
- if (typeof(args[k]) == "object") {
- w = args[k][0]
- h = args[k][1]
- }
-
- args["top"] = h/2
- args["left"] = w/2
- args["width"] = width-w-20
- args["height"] = height-h-20
- args[k] = undefined
- break
- }
- }
-
- for (var k in args) {
- switch (k) {
- case "top":
- case "left":
- case "width":
- case "height":
- case "padding":
- args[k] = args[k]+"px"
- break
- }
- }
- return kit.ModifyNode(which, {style: args})
- },
- ModifyNode: function(which, html) {
- var node = typeof which == "string"? document.querySelector(which): which
- switch (typeof html) {
- case "string":
- node.innerHTML = html
- break
- case "object":
- for (var k in html) {
- if (typeof html[k] == "object") {
- for (var d in html[k]) {
- node[k] && (node[k][d] = html[k][d])
- }
- continue
- }
- node[k] = html[k]
- }
- break
- }
- return node
- },
- CreateNode: function(element, html) {
- return this.ModifyNode(document.createElement(element), html)
- },
- AppendChild: function(parent, children, subs) {
- if (typeof children == "string") {
- var elm = this.CreateNode(children, subs)
- parent.append(elm)
- return elm
- }
-
- // 基本属性: name value inner style
- //
- // dataset click
- // button input label img
- // select
- //
- // 树状结构: tree fork leaf
- // 普通视图: view text code
- // 加载文件: include require styles
- //
- // 基本结构: type data list
-
- var kit = this
-
- subs = subs || {}
- children.forEach(function(child, i) {
- if (!child) {
- return
- }
- child.data = child.data || {}
- child.type = child.type || "div"
-
- if (child.name) {
- child.data["name"] = child.name
- }
- if (child.value) {
- child.data["value"] = child.value
- }
- if (child.inner) {
- child.data["innerHTML"] = child.inner
- }
- if (child.className) {
- child.data["className"] = child.className
- }
- if (typeof(child.style) == "object") {
- var str = []
- for (var k in child.style) {
- str.push(k)
- str.push(":")
- str.push(child.style[k] + (typeof child.style[k] == "number"? "px": ""))
- str.push(";")
- }
- child.data["style"] = str.join("")
- }
- if (child.dataset) {
- child.data["dataset"] = child.dataset
- }
- if (child.click) {
- child.data["onclick"] = child.click
- }
-
- if (child.button) {
- child.type = "button"
- child.data["onclick"] = child.button[1]
- child.data["innerText"] = child.button[0]
- child.name = child.name || child.button[0]
-
- } else if (child.select) {
- child.type = "select"
- child.list = child.select[0].map(function(value) {
- return {type: "option", value: value, inner: value}
- })
- child.data["onchange"] = child.select[1]
-
- } else if (child.input) {
- child.type = "input"
- child.data["onkeyup"] = child.input[1]
- child.data["name"] = child.input[0]
- child.name = child.name || child.input[0]
-
- } else if (child.password) {
- child.type = "input"
- child.data["onkeyup"] = child.password[1]
- child.data["name"] = child.password[0]
- child.data["type"] = "password"
- child.name = child.name || child.password[0]
-
- } else if (child.label) {
- child.type = "label"
- child.data["innerText"] = child.label
-
- } else if (child.img) {
- child.type = "img"
- child.data["src"] = child.img[0]
- child.img.length > 1 && (child.data["onload"] = child.img[1])
-
- } else if (child.tree) {
- child.type = "ul"
- child.list = child.tree
-
- } else if (child.fork) {
- child.type = "li"
- child.list = [
- {"text": [child.fork[0], "div"], "click": (child.fork.length>2? child.fork[2]: "")},
- {"type": "ul", "list": child.fork[1]},
- ]
-
- } else if (child.leaf) {
- child.type = "li"
- child.list = [{"text": [child.leaf[0], "div"]}]
- if (child.leaf.length > 1 && typeof child.leaf[1] == "function") {
- child.data["onclick"] = function(event) {
- child.leaf[1](event, node)
- }
- }
-
- } else if (child.view) {
- child.data["className"] = child.view[0]
- child.type = child.view.length > 1? child.view[1]: "div"
- child.view.length > 2 && (child.data["innerHTML"] = child.view[2])
- child.view.length > 3 && (child.name = child.view[3])
-
- } else if (child.text) {
- child.data["innerText"] = child.text[0]
- child.type = child.text.length > 1? child.text[1]: "pre"
- child.text.length > 2 && (child.data["className"] = child.text[2])
-
- } else if (child.code) {
- child.type = "code"
- child.list = [{"type": "pre" ,"data": {"innerText": child.code[0]}, "name": child.code[1]}]
- child.code.length > 2 && (child.data["className"] = child.code[2])
-
- } else if (child.script) {
- child.type = "script"
- child.data.innerHTML = child.script
-
- } else if (child.include) {
- child.type = "script"
- child.data["src"] = child.include[0]
- child.data["type"] = "text/javascript"
- child.include.length > 1 && (child.data["onload"] = child.include[1])
-
- } else if (child.require) {
- child.data["href"] = child.require[0]
- child.data["rel"] = child.require.length > 1? child.require[1]: "stylesheet"
- child.data["type"] = child.require.length > 2? child.require[2]: "text/css"
- child.type = "link"
-
- } else if (child.styles) {
- var str = []
- for (var key in child.styles) {
- str.push(key)
- str.push(" {")
- for (var k in child.styles[key]) {
- str.push(k)
- str.push(":")
- str.push(child.styles[key][k] + (typeof child.styles[key][k] == "number"? "px": ""))
- str.push(";")
- }
- str.push("}\n")
- }
- child.data["innerHTML"] = str.join("")
- child.data["type"] = "text/css"
- child.type = "style"
-
- }
-
- var node = kit.CreateNode(child.type, child.data)
- child.list && kit.AppendChild(node, child.list, subs)
- child.name && (subs[child.name] = node)
- subs.first || (subs.first = node)
- subs.last, subs.last = node
- parent.append(node)
- })
- return subs
- },
- AppendChilds: function(parent, children, subs) {
- return parent.innerHTML = "", this.AppendChild(parent, children, subs)
- },
- InsertChild: function (parent, position, element, children) {
- var elm = this.CreateNode(element)
- this.AppendChild(elm, children)
- return parent.insertBefore(elm, position || parent.firstElementChild)
- },
-
- AppendTable: function(table, data, fields, cb) {
- if (!data || !fields) {
- return
- }
- var kit = this
- var tr = kit.AppendChild(table, "tr")
- fields.forEach(function(key, j) {
- var td = kit.AppendChild(tr, "th", key)
- })
- data.forEach(function(row, i) {
- var tr = kit.AppendChild(table, "tr", {className: "normal"})
- tr.Meta = row
- fields.forEach(function(key, j) {
- var td = kit.AppendChild(tr, "td", kit.Color(row[key]))
- if (typeof cb == "function") {
- td.onclick = function(event) {
- cb(row[key], key, row, i, tr, event)
- }
- }
- })
- })
- return table
- },
- RangeTable: function(table, index, sort_asc) {
- var list = table.querySelectorAll("tr")
-
- var is_time = true, is_number = true
- for (var i = 1; i < list.length; i++) {
- var text = list[i].childNodes[index].innerText
- var value = Date.parse(text)
- if (!(value > 0)) {
- is_time = false
- }
-
- var value = parseInt(text)
- if (text != "" && !(value >= 0 || value <= 0)) {
- is_number = false
- }
- }
-
- var num_list = [], new_list = []
- for (var i = 1; i < list.length; i++) {
- var text = list[i].childNodes[index].innerText
- if (is_time) {
- num_list.push(Date.parse(text))
- } else if (is_number) {
- num_list.push(parseInt(text) || 0)
- } else {
- num_list.push(text)
- }
- new_list.push(list[i])
- }
-
- for (var i = 0; i < new_list.length; i++) {
- for (var j = i+1; j < new_list.length; j++) {
- if (sort_asc? num_list[i] < num_list[j]: num_list[i] > num_list[j]) {
- var temp = num_list[i]
- num_list[i] = num_list[j]
- num_list[j] = temp
- var temp = new_list[i]
- new_list[i] = new_list[j]
- new_list[j] = temp
- }
- }
- new_list[i].parentElement && new_list[i].parentElement.removeChild(new_list[i])
- table.appendChild(new_list[i])
- }
- },
- OrderTable: function(table, field, cb) {
- if (!table) {return}
- table.onclick = function(event) {
- var target = event.target
- var dataset = target.dataset
- var head = target.parentElement.parentElement.querySelector("tr")
- target.parentElement.childNodes.forEach(function(item, i) {
- if (item != target) {
- return
- }
- if (target.tagName == "TH") {
- dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1
- kit.RangeTable(table, i, dataset["sort_asc"] == "1")
- return
- }
- var name = head.childNodes[i].innerText
- if (name.startsWith(field)) {
- typeof cb == "function" && cb(event, item.innerText, name,item.parentNode.Meta)
- }
- kit.CopyText()
- })
- }
- },
-
- OrderCode: function(code) {
- if (!code) {return}
-
- var kit = this
- code.onclick = function(event) {
- kit.CopyText()
- }
- },
- OrderLink: function(link) {
- link.target = "_blank"
- },
- OrderText: function(pane, text) {
- text.querySelectorAll("a").forEach(function(value, index, array) {
- kit.OrderLink(value, pane)
- })
- text.querySelectorAll("table").forEach(function(value, index, array) {
- kit.OrderTable(value)
- })
-
- var i = 0, j = 0, k = 0
- var h0 = [], h2 = [], h3 = []
- text.querySelectorAll("h2,h3,h4").forEach(function(value, index, array) {
- var id = ""
- var text = value.innerText
- var ratio = parseInt(value.offsetTop/pane.scrollHeight*100)
- if (value.tagName == "H2") {
- j=k=0
- h2 = []
- id = ++i+"."
- text = id+" "+text
- h0.push({"fork": [text+" ("+ratio+"%)", h2, function(event) {
- location.hash = id
- }]})
- } else if (value.tagName == "H3") {
- k=0
- h3 = []
- id = i+"."+(++j)
- text = id+" "+text
- h2.push({"fork": [text+" ("+ratio+"%)", h3, function(event) {
- location.hash = id
- }]})
- } else if (value.tagName == "H4") {
- id = i+"."+j+"."+(++k)
- text = id+" "+text
- h3.push({"leaf": [text+" ("+ratio+"%)", function(event) {
- location.hash = id
- }]})
- }
- value.innerText = text
- value.id = id
- })
- return h0
-
- text.querySelectorAll("table.wiki_list").forEach(function(value, index, array) {
- kit.OrderTable(value, "path", function(event) {
- var text = event.target.innerText
- ctx.Search({"wiki_class": text})
- })
- })
- },
- Position: function(which) {
- return (parseInt((which.scrollTop + which.clientHeight) / which.scrollHeight * 100)||0)+"%"
- },
- Color: function(s) {
- s = s.replace(/\033\[1m/g, "")
- s = s.replace(/\033\[36m/g, "")
- s = s.replace(/\033\[32m/g, "")
- s = s.replace(/\033\[31m/g, "")
- s = s.replace(/\033\[0m/g, "")
- s = s.replace(/\033\[m/g, "")
- return s
- },
-
- CopyText: function(text) {
- text = window.getSelection().toString()
- if (text == "") {return}
- kit.History.add("txt", text)
- document.execCommand("copy")
- },
- DelText: function(target, start, count) {
- target.value = target.value.substring(0, start)+target.value.substring(start+(count||target.value.length), target.value.length)
- target.setSelectionRange(start, start)
- },
- HitText: function(target, text) {
- var start = target.selectionStart
- for (var i = 1; i < text.length+1; i++) {
- var ch = text[text.length-i]
- if (target.value[start-i] != ch && kit.History.get("key", -i).data != ch) {
- return false
- }
- }
- return true
- },
-
- Selector: function(obj, item, cb) {
- var list = []
- obj.querySelectorAll(item).forEach(function(item, index) {
- if (typeof cb == "function") {
- var value = cb(item)
- value != undefined && list.push(value)
- } else {
- list.push(item)
- }
- })
- for (var i = list.length-1; i >= 0; i--) {
- if (list[i] == "") {
- list.pop()
- } else {
- break
- }
- }
- return list
- },
- Format: function(objs) {
- return json.stringify(objs)
- },
- List: function(obj, cb) {
- var list = []
- for (var i = 0; i < obj.length; i++) {
- list.push(typeof cb == "function"? cb(obj[i]): obj[i])
- }
- return list
- },
- alert: function(text) {
- alert(JSON.stringify(text))
- },
- prompt: function(text) {
- return prompt(text)
- },
- confirm: function(text) {
- return confirm(text)
- },
- reload: function() {
- location.reload()
- },
-
- right: function(arg) {
- if (arg == "true") {
- return true
- }
- if (arg == "false") {
- return false
- }
- if (arg) {
- return true
- }
- return false
- },
- format_date: function(arg) {
- var date = arg.getDate()
- if (date < 10) {
- date = "0"+date
- }
- var month = arg.getMonth()+1
- if (month < 10) {
- month = "0"+month
- }
- var hour = arg.getHours()
- if (hour < 10) {
- hour = "0"+hour
- }
- var minute = arg.getMinutes()
- if (minute < 10) {
- minute = "0"+minute
- }
- var second = arg.getSeconds()
- if (second < 10) {
- second = "0"+second
- }
- return arg.getFullYear()+"-"+month+"-"+date+" "+hour+":"+minute+":"+second
- },
- OrderForm: function(page, field, option, append, result) {
- if (!option) {return}
- option.ondaemon = option.ondaemon || function(msg) {
- append.innerHTML = ""
- msg && msg.append && kit.AppendTable(append, ctx.Table(msg), msg.append, function(value, key, row, index, event) {
- typeof option.daemon_action[key] == "function" && option.daemon_action[key](value, key, row, index, event)
- })
- result && (result.innerText = (msg && msg.result)? msg.result.join(""): "")
- }
-
- option.querySelectorAll("select").forEach(function(select, index, array) {
- select.onchange = select.onchange || function(event) {
- if (index == array.length-1) {
- ctx.Runs(page, option)
- return
- }
- if (array[index+1].type == "button") {
- array[index+1].click()
- return
- }
- array[index+1].focus()
- }
- })
- option.querySelectorAll("input").forEach(function(input, index, array) {
- switch (input.type) {
- case "button":
- input.onclick = input.onclick || function(event) {
- if (index == array.length-1) {
- if (input.value == "login") {
- ctx.Runs(page, option, function(msg) {
- if (document.referrer) {
- location.href = document.referrer
- } else {
- ctx.Search("componet_group", "")
- }
- })
- return
- }
-
- ctx.Runs(page, option)
- return
- }
- if (array[index+1].type == "button") {
- array[index+1].click()
- return
- }
- array[index+1].focus()
- }
- default:
- input.onkeyup = input.onkeyup || function(event) {
- if (event.key != "Enter") {
- return
- }
- if (index == array.length-1) {
- ctx.Runs(page, option)
- return
- }
- if (array[index+1].type == "button") {
- array[index+1].click()
- return
- }
- array[index+1].focus()
- }
- }
- })
- },
-}
-
+kit = toolkit = {
+ isMobile: navigator.userAgent.indexOf("Mobile") > -1,
+ isWeiXin: navigator.userAgent.indexOf("MicroMessenger") > -1,
+ isMacOSX: navigator.userAgent.indexOf("Mac OS X") > -1,
+ isWindows: navigator.userAgent.indexOf("Windows") > -1,
+ isIPhone: navigator.userAgent.indexOf("iPhone") > -1,
+ isSpace: function(c) {
+ return c == " " || c == "Enter"
+ },
+ History: {dir: [], pod: [], ctx: [], cmd: [], txt: [], key: [], lay: [],
+ add: function(type, data) {
+ var list = this[type] || []
+ data && list.push({time: Date.now(), data: data})
+ this[type] = list
+ return list.length-1
+ },
+ get: function(type, index) {
+ var list = this[type] || []
+ var len = list.length
+ return index == undefined? this[type]: this[type][(index+len)%len]
+ },
+ },
+ Log: function() {
+ var args = []
+ for (var i = 0; i < arguments.length; i++) {
+ args.push(arguments[i])
+ }
+ console.log(arguments.length == 1? args[0]: args)
+ return args
+ },
+
+ ModifyView: function(which, args) {
+ var height = document.body.clientHeight-4
+ var width = document.body.clientWidth-4
+ for (var k in args) {
+ switch (k) {
+ case "dialog":
+ var w = h = args[k]
+ if (typeof(args[k]) == "object") {
+ w = args[k][0]
+ h = args[k][1]
+ }
+ if (w > width) {
+ w = width
+ }
+ if (h > height) {
+ h = height
+ }
+
+ args["top"] = (height-h)/2
+ args["left"] = (width-w)/2
+ args["width"] = w
+ args["height"] = h
+ args[k] = undefined
+ break
+ case "window":
+ var w = h = args[k]
+ if (typeof(args[k]) == "object") {
+ w = args[k][0]
+ h = args[k][1]
+ }
+
+ args["top"] = h/2
+ args["left"] = w/2
+ args["width"] = width-w-20
+ args["height"] = height-h-20
+ args[k] = undefined
+ break
+ }
+ }
+
+ for (var k in args) {
+ switch (k) {
+ case "top":
+ case "left":
+ case "width":
+ case "height":
+ case "padding":
+ args[k] = args[k]+"px"
+ break
+ }
+ }
+ return kit.ModifyNode(which, {style: args})
+ },
+ ModifyNode: function(which, html) {
+ var node = typeof which == "string"? document.querySelector(which): which
+ switch (typeof html) {
+ case "string":
+ node.innerHTML = html
+ break
+ case "object":
+ for (var k in html) {
+ if (typeof html[k] == "object") {
+ for (var d in html[k]) {
+ node[k] && (node[k][d] = html[k][d])
+ }
+ continue
+ }
+ node[k] = html[k]
+ }
+ break
+ }
+ return node
+ },
+ CreateNode: function(element, html) {
+ return this.ModifyNode(document.createElement(element), html)
+ },
+ AppendChild: function(parent, children, subs) {
+ if (typeof children == "string") {
+ var elm = this.CreateNode(children, subs)
+ parent.append(elm)
+ return elm
+ }
+
+ // 基本属性: name value inner style
+ //
+ // dataset click
+ // button input label img
+ // select
+ //
+ // 树状结构: tree fork leaf
+ // 普通视图: view text code
+ // 加载文件: include require styles
+ //
+ // 基本结构: type data list
+
+ var kit = this
+
+ subs = subs || {}
+ children.forEach(function(child, i) {
+ if (!child) {
+ return
+ }
+ child.data = child.data || {}
+ child.type = child.type || "div"
+
+ if (child.name) {
+ child.data["name"] = child.name
+ }
+ if (child.value) {
+ child.data["value"] = child.value
+ }
+ if (child.inner) {
+ child.data["innerHTML"] = child.inner
+ }
+ if (child.className) {
+ child.data["className"] = child.className
+ }
+ if (typeof(child.style) == "object") {
+ var str = []
+ for (var k in child.style) {
+ str.push(k)
+ str.push(":")
+ str.push(child.style[k] + (typeof child.style[k] == "number"? "px": ""))
+ str.push(";")
+ }
+ child.data["style"] = str.join("")
+ }
+ if (child.dataset) {
+ child.data["dataset"] = child.dataset
+ }
+ if (child.click) {
+ child.data["onclick"] = child.click
+ }
+
+ if (child.button) {
+ child.type = "button"
+ child.data["onclick"] = child.button[1]
+ child.data["innerText"] = child.button[0]
+ child.name = child.name || child.button[0]
+
+ } else if (child.select) {
+ child.type = "select"
+ child.list = child.select[0].map(function(value) {
+ return {type: "option", value: value, inner: value}
+ })
+ child.data["onchange"] = child.select[1]
+
+ } else if (child.input) {
+ child.type = "input"
+ child.data["onkeyup"] = child.input[1]
+ child.data["name"] = child.input[0]
+ child.name = child.name || child.input[0]
+
+ } else if (child.password) {
+ child.type = "input"
+ child.data["onkeyup"] = child.password[1]
+ child.data["name"] = child.password[0]
+ child.data["type"] = "password"
+ child.name = child.name || child.password[0]
+
+ } else if (child.label) {
+ child.type = "label"
+ child.data["innerText"] = child.label
+
+ } else if (child.img) {
+ child.type = "img"
+ child.data["src"] = child.img[0]
+ child.img.length > 1 && (child.data["onload"] = child.img[1])
+
+ } else if (child.tree) {
+ child.type = "ul"
+ child.list = child.tree
+
+ } else if (child.fork) {
+ child.type = "li"
+ child.list = [
+ {"text": [child.fork[0], "div"], "click": (child.fork.length>2? child.fork[2]: "")},
+ {"type": "ul", "list": child.fork[1]},
+ ]
+
+ } else if (child.leaf) {
+ child.type = "li"
+ child.list = [{"text": [child.leaf[0], "div"]}]
+ if (child.leaf.length > 1 && typeof child.leaf[1] == "function") {
+ child.data["onclick"] = function(event) {
+ child.leaf[1](event, node)
+ }
+ }
+
+ } else if (child.view) {
+ child.data["className"] = child.view[0]
+ child.type = child.view.length > 1? child.view[1]: "div"
+ child.view.length > 2 && (child.data["innerHTML"] = child.view[2])
+ child.view.length > 3 && (child.name = child.view[3])
+
+ } else if (child.text) {
+ child.data["innerText"] = child.text[0]
+ child.type = child.text.length > 1? child.text[1]: "pre"
+ child.text.length > 2 && (child.data["className"] = child.text[2])
+
+ } else if (child.code) {
+ child.type = "code"
+ child.list = [{"type": "pre" ,"data": {"innerText": child.code[0]}, "name": child.code[1]}]
+ child.code.length > 2 && (child.data["className"] = child.code[2])
+
+ } else if (child.script) {
+ child.type = "script"
+ child.data.innerHTML = child.script
+
+ } else if (child.include) {
+ child.type = "script"
+ child.data["src"] = child.include[0]
+ child.data["type"] = "text/javascript"
+ child.include.length > 1 && (child.data["onload"] = child.include[1])
+
+ } else if (child.require) {
+ child.data["href"] = child.require[0]
+ child.data["rel"] = child.require.length > 1? child.require[1]: "stylesheet"
+ child.data["type"] = child.require.length > 2? child.require[2]: "text/css"
+ child.type = "link"
+
+ } else if (child.styles) {
+ var str = []
+ for (var key in child.styles) {
+ str.push(key)
+ str.push(" {")
+ for (var k in child.styles[key]) {
+ str.push(k)
+ str.push(":")
+ str.push(child.styles[key][k] + (typeof child.styles[key][k] == "number"? "px": ""))
+ str.push(";")
+ }
+ str.push("}\n")
+ }
+ child.data["innerHTML"] = str.join("")
+ child.data["type"] = "text/css"
+ child.type = "style"
+
+ }
+
+ var node = kit.CreateNode(child.type, child.data)
+ child.list && kit.AppendChild(node, child.list, subs)
+ child.name && (subs[child.name] = node)
+ subs.first || (subs.first = node)
+ subs.last, subs.last = node
+ parent.append(node)
+ })
+ return subs
+ },
+ AppendChilds: function(parent, children, subs) {
+ return parent.innerHTML = "", this.AppendChild(parent, children, subs)
+ },
+ InsertChild: function (parent, position, element, children) {
+ var elm = this.CreateNode(element)
+ this.AppendChild(elm, children)
+ return parent.insertBefore(elm, position || parent.firstElementChild)
+ },
+
+ AppendTable: function(table, data, fields, cb) {
+ if (!data || !fields) {
+ return
+ }
+ var kit = this
+ var tr = kit.AppendChild(table, "tr")
+ fields.forEach(function(key, j) {
+ var td = kit.AppendChild(tr, "th", key)
+ })
+ data.forEach(function(row, i) {
+ var tr = kit.AppendChild(table, "tr", {className: "normal"})
+ tr.Meta = row
+ fields.forEach(function(key, j) {
+ var td = kit.AppendChild(tr, "td", kit.Color(row[key]))
+ if (typeof cb == "function") {
+ td.onclick = function(event) {
+ cb(row[key], key, row, i, tr, event)
+ }
+ }
+ })
+ })
+ return table
+ },
+ RangeTable: function(table, index, sort_asc) {
+ var list = table.querySelectorAll("tr")
+
+ var is_time = true, is_number = true
+ for (var i = 1; i < list.length; i++) {
+ var text = list[i].childNodes[index].innerText
+ var value = Date.parse(text)
+ if (!(value > 0)) {
+ is_time = false
+ }
+
+ var value = parseInt(text)
+ if (text != "" && !(value >= 0 || value <= 0)) {
+ is_number = false
+ }
+ }
+
+ var num_list = [], new_list = []
+ for (var i = 1; i < list.length; i++) {
+ var text = list[i].childNodes[index].innerText
+ if (is_time) {
+ num_list.push(Date.parse(text))
+ } else if (is_number) {
+ num_list.push(parseInt(text) || 0)
+ } else {
+ num_list.push(text)
+ }
+ new_list.push(list[i])
+ }
+
+ for (var i = 0; i < new_list.length; i++) {
+ for (var j = i+1; j < new_list.length; j++) {
+ if (sort_asc? num_list[i] < num_list[j]: num_list[i] > num_list[j]) {
+ var temp = num_list[i]
+ num_list[i] = num_list[j]
+ num_list[j] = temp
+ var temp = new_list[i]
+ new_list[i] = new_list[j]
+ new_list[j] = temp
+ }
+ }
+ new_list[i].parentElement && new_list[i].parentElement.removeChild(new_list[i])
+ table.appendChild(new_list[i])
+ }
+ },
+ OrderTable: function(table, field, cb) {
+ if (!table) {return}
+ table.onclick = function(event) {
+ var target = event.target
+ var dataset = target.dataset
+ var head = target.parentElement.parentElement.querySelector("tr")
+ target.parentElement.childNodes.forEach(function(item, i) {
+ if (item != target) {
+ return
+ }
+ if (target.tagName == "TH") {
+ dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1
+ kit.RangeTable(table, i, dataset["sort_asc"] == "1")
+ return
+ }
+ var name = head.childNodes[i].innerText
+ if (name.startsWith(field)) {
+ typeof cb == "function" && cb(event, item.innerText, name,item.parentNode.Meta)
+ }
+ kit.CopyText()
+ })
+ }
+ },
+
+ OrderCode: function(code) {
+ if (!code) {return}
+
+ var kit = this
+ code.onclick = function(event) {
+ kit.CopyText()
+ }
+ },
+ OrderLink: function(link) {
+ link.target = "_blank"
+ },
+ OrderText: function(pane, text) {
+ text.querySelectorAll("a").forEach(function(value, index, array) {
+ kit.OrderLink(value, pane)
+ })
+ text.querySelectorAll("table").forEach(function(value, index, array) {
+ kit.OrderTable(value)
+ })
+
+ var i = 0, j = 0, k = 0
+ var h0 = [], h2 = [], h3 = []
+ text.querySelectorAll("h2,h3,h4").forEach(function(value, index, array) {
+ var id = ""
+ var text = value.innerText
+ var ratio = parseInt(value.offsetTop/pane.scrollHeight*100)
+ if (value.tagName == "H2") {
+ j=k=0
+ h2 = []
+ id = ++i+"."
+ text = id+" "+text
+ h0.push({"fork": [text+" ("+ratio+"%)", h2, function(event) {
+ location.hash = id
+ }]})
+ } else if (value.tagName == "H3") {
+ k=0
+ h3 = []
+ id = i+"."+(++j)
+ text = id+" "+text
+ h2.push({"fork": [text+" ("+ratio+"%)", h3, function(event) {
+ location.hash = id
+ }]})
+ } else if (value.tagName == "H4") {
+ id = i+"."+j+"."+(++k)
+ text = id+" "+text
+ h3.push({"leaf": [text+" ("+ratio+"%)", function(event) {
+ location.hash = id
+ }]})
+ }
+ value.innerText = text
+ value.id = id
+ })
+ return h0
+
+ text.querySelectorAll("table.wiki_list").forEach(function(value, index, array) {
+ kit.OrderTable(value, "path", function(event) {
+ var text = event.target.innerText
+ ctx.Search({"wiki_class": text})
+ })
+ })
+ },
+ Position: function(which) {
+ return (parseInt((which.scrollTop + which.clientHeight) / which.scrollHeight * 100)||0)+"%"
+ },
+ Color: function(s) {
+ s = s.replace(/\033\[1m/g, "")
+ s = s.replace(/\033\[36m/g, "")
+ s = s.replace(/\033\[32m/g, "")
+ s = s.replace(/\033\[31m/g, "")
+ s = s.replace(/\033\[0m/g, "")
+ s = s.replace(/\033\[m/g, "")
+ return s
+ },
+
+ CopyText: function(text) {
+ text = window.getSelection().toString()
+ if (text == "") {return}
+ kit.History.add("txt", text)
+ document.execCommand("copy")
+ },
+ DelText: function(target, start, count) {
+ target.value = target.value.substring(0, start)+target.value.substring(start+(count||target.value.length), target.value.length)
+ target.setSelectionRange(start, start)
+ },
+ HitText: function(target, text) {
+ var start = target.selectionStart
+ for (var i = 1; i < text.length+1; i++) {
+ var ch = text[text.length-i]
+ if (target.value[start-i] != ch && kit.History.get("key", -i).data != ch) {
+ return false
+ }
+ }
+ return true
+ },
+
+ Selector: function(obj, item, cb) {
+ var list = []
+ obj.querySelectorAll(item).forEach(function(item, index) {
+ if (typeof cb == "function") {
+ var value = cb(item)
+ value != undefined && list.push(value)
+ } else {
+ list.push(item)
+ }
+ })
+ for (var i = list.length-1; i >= 0; i--) {
+ if (list[i] == "") {
+ list.pop()
+ } else {
+ break
+ }
+ }
+ return list
+ },
+ Format: function(objs) {
+ return json.stringify(objs)
+ },
+ List: function(obj, cb) {
+ var list = []
+ for (var i = 0; i < obj.length; i++) {
+ list.push(typeof cb == "function"? cb(obj[i]): obj[i])
+ }
+ return list
+ },
+ alert: function(text) {
+ alert(JSON.stringify(text))
+ },
+ prompt: function(text) {
+ return prompt(text)
+ },
+ confirm: function(text) {
+ return confirm(text)
+ },
+ reload: function() {
+ location.reload()
+ },
+
+ right: function(arg) {
+ if (arg == "true") {
+ return true
+ }
+ if (arg == "false") {
+ return false
+ }
+ if (arg) {
+ return true
+ }
+ return false
+ },
+ format_date: function(arg) {
+ var date = arg.getDate()
+ if (date < 10) {
+ date = "0"+date
+ }
+ var month = arg.getMonth()+1
+ if (month < 10) {
+ month = "0"+month
+ }
+ var hour = arg.getHours()
+ if (hour < 10) {
+ hour = "0"+hour
+ }
+ var minute = arg.getMinutes()
+ if (minute < 10) {
+ minute = "0"+minute
+ }
+ var second = arg.getSeconds()
+ if (second < 10) {
+ second = "0"+second
+ }
+ return arg.getFullYear()+"-"+month+"-"+date+" "+hour+":"+minute+":"+second
+ },
+ OrderForm: function(page, field, option, append, result) {
+ if (!option) {return}
+ option.ondaemon = option.ondaemon || function(msg) {
+ append.innerHTML = ""
+ msg && msg.append && kit.AppendTable(append, ctx.Table(msg), msg.append, function(value, key, row, index, event) {
+ typeof option.daemon_action[key] == "function" && option.daemon_action[key](value, key, row, index, event)
+ })
+ result && (result.innerText = (msg && msg.result)? msg.result.join(""): "")
+ }
+
+ option.querySelectorAll("select").forEach(function(select, index, array) {
+ select.onchange = select.onchange || function(event) {
+ if (index == array.length-1) {
+ ctx.Runs(page, option)
+ return
+ }
+ if (array[index+1].type == "button") {
+ array[index+1].click()
+ return
+ }
+ array[index+1].focus()
+ }
+ })
+ option.querySelectorAll("input").forEach(function(input, index, array) {
+ switch (input.type) {
+ case "button":
+ input.onclick = input.onclick || function(event) {
+ if (index == array.length-1) {
+ if (input.value == "login") {
+ ctx.Runs(page, option, function(msg) {
+ if (document.referrer) {
+ location.href = document.referrer
+ } else {
+ ctx.Search("componet_group", "")
+ }
+ })
+ return
+ }
+
+ ctx.Runs(page, option)
+ return
+ }
+ if (array[index+1].type == "button") {
+ array[index+1].click()
+ return
+ }
+ array[index+1].focus()
+ }
+ default:
+ input.onkeyup = input.onkeyup || function(event) {
+ if (event.key != "Enter") {
+ return
+ }
+ if (index == array.length-1) {
+ ctx.Runs(page, option)
+ return
+ }
+ if (array[index+1].type == "button") {
+ array[index+1].click()
+ return
+ }
+ array[index+1].focus()
+ }
+ }
+ })
+ },
+}
+