diff --git a/src/contexts/aaa/aaa.go b/src/contexts/aaa/aaa.go
index 5288b9a8..caba23e2 100644
--- a/src/contexts/aaa/aaa.go
+++ b/src/contexts/aaa/aaa.go
@@ -689,6 +689,31 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
}
return
}},
+ "location": &ctx.Command{Name: "clip", Help: "授权", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ h := m.Cmdx("aaa.auth", "username", m.Option("username"))
+
+ if len(arg) < 2 { // 会话列表
+ m.Confm("auth", []string{h, "data", "location"}, func(index int, value map[string]interface{}) {
+ m.Add("append", "create_time", value["create_time"])
+ m.Add("append", "location", value["location"])
+ m.Add("append", "latitude", value["latitude"])
+ m.Add("append", "longitude", value["longitude"])
+ })
+ m.Table()
+ return
+ }
+
+ switch arg[0] {
+ default:
+ m.Conf("auth", []string{h, "data", "location", "-2"}, map[string]interface{}{
+ "create_time": m.Time(),
+ "latitude": arg[0], "longitude": arg[1],
+ "location": kit.Select("", arg, 2),
+ })
+ m.Echo("%d", len(m.Confv("auth", []string{h, "data", "location"}).([]interface{}))-1)
+ }
+ return
+ }},
"relay": &ctx.Command{Name: "relay check hash | share role", Help: "授权", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if len(arg) == 0 { // 会话列表
diff --git a/src/contexts/cli/cli.go b/src/contexts/cli/cli.go
index 8ac073c5..74671801 100644
--- a/src/contexts/cli/cli.go
+++ b/src/contexts/cli/cli.go
@@ -148,7 +148,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
}, Help: "运行环境"},
"compile": &ctx.Config{Name: "compile", Value: map[string]interface{}{
"bench": "src/examples/app/bench.go",
- "tmp": "var/tmp/go",
+ "tmp": "var/tmp/go",
"env": []interface{}{"GOPATH", "PATH"},
}, Help: "运行环境"},
"publish": &ctx.Config{Name: "publish", Value: map[string]interface{}{
@@ -628,7 +628,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
m.Confm("publish", "list", func(key string, value string) {
list = append(list, []string{key})
})
- m.Cmdp(time.Second, []string{"copy"}, []string{"cli.publish"}, list)
+ m.Cmdp(0, []string{"copy"}, []string{"cli.publish"}, list)
return
}
@@ -738,7 +738,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
m.Echo(", wait 1s\n")
m.Table()
fmt.Printf("\n")
- for _, v:=range m.Meta["result"] {
+ for _, v := range m.Meta["result"] {
fmt.Printf("%v", v)
}
diff --git a/src/contexts/ctx/ctx.go b/src/contexts/ctx/ctx.go
index 0588ee9a..66353bf5 100644
--- a/src/contexts/ctx/ctx.go
+++ b/src/contexts/ctx/ctx.go
@@ -1556,10 +1556,11 @@ func (m *Message) Cmdp(t time.Duration, head []string, prefix []string, suffix [
for i, v := range suffix {
m.Show(fmt.Sprintf("%v/%v %v...\n", i+1, len(suffix), v))
- m.Cmd(prefix, v)
+ m.CopyFuck(m.Cmd(prefix, v), "append")
time.Sleep(t)
}
m.Show("\n")
+ m.Table()
return m
}
func (m *Message) Cmdm(args ...interface{}) *Message {
diff --git a/src/contexts/mdb/mdb.go b/src/contexts/mdb/mdb.go
index 1be6c17b..3ec24226 100644
--- a/src/contexts/mdb/mdb.go
+++ b/src/contexts/mdb/mdb.go
@@ -98,6 +98,38 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
}, Help: "数据视图"},
},
Commands: map[string]*ctx.Command{
+ "redis": &ctx.Command{Name: "redis conn address [protocol]", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
+ if mdb, ok := m.Target().Server.(*MDB); m.Assert(ok) {
+ switch arg[0] {
+ case "conn":
+ c, e := net.Dial(kit.Select("tcp", arg, 2), arg[1])
+ m.Assert(e)
+ mdb.conn = redis.NewConn(c, time.Second*10, time.Second*10)
+ default:
+ if mdb.conn == nil {
+ m.Echo("not open")
+ break
+ }
+ if mdb.conn.Err() != nil {
+ m.Echo("%v", mdb.conn.Err())
+ return
+ }
+ args := []interface{}{}
+ for _, v := range arg[1:] {
+ args = append(args, v)
+ }
+ res, err := mdb.conn.Do(arg[0], args...)
+ m.Assert(err)
+ switch val := res.(type) {
+ case redis.Error:
+ m.Echo("%v", val)
+ default:
+ m.Echo("%v", kit.Format(res))
+ }
+ }
+ }
+ return
+ }},
"open": &ctx.Command{Name: "open [database [username [password [address [protocol [driver]]]]]]",
Help: "打开数据库, database: 数据库名, username: 用户名, password: 密码, address: 服务地址, protocol: 服务协议, driver: 数据库类型",
Form: map[string]int{"dbname": 1, "dbhelp": 1},
@@ -126,38 +158,6 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
kit.Select("数据源", m.Option("dbhelp")), arg...)
return
}},
- "redis": &ctx.Command{Name: "redis conn address [protocol]", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
- if mdb, ok := m.Target().Server.(*MDB); m.Assert(ok) {
- switch arg[0] {
- case "conn":
- c, e := net.Dial(kit.Select("tcp", arg, 2), arg[1])
- m.Assert(e)
- mdb.conn = redis.NewConn(c, time.Second*10, time.Second*10)
- default:
- if mdb.conn == nil {
- m.Echo("not open")
- break
- }
- if mdb.conn.Err() != nil {
- m.Echo("%v", mdb.conn.Err())
- return
- }
- args := []interface{}{}
- for _, v:=range arg[1:] {
- args = append(args, v)
- }
- res, err := mdb.conn.Do(arg[0], args...)
- m.Assert(err)
- switch val := res.(type) {
- case redis.Error:
- m.Echo("%v", val)
- default:
- m.Echo("%v", kit.Format(res))
- }
- }
- }
- return
- }},
"exec": &ctx.Command{Name: "exec sql [arg]", Help: "操作数据库, sql: SQL语句, arg: 操作参数", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if mdb, ok := m.Target().Server.(*MDB); m.Assert(ok) && mdb.DB != nil {
which := make([]interface{}, 0, len(arg))
diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go
index 3745eed8..7fc2a4b3 100644
--- a/src/contexts/ssh/ssh.go
+++ b/src/contexts/ssh/ssh.go
@@ -176,15 +176,35 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
map[string]interface{}{"type": "button", "value": "运行"},
},
},
+ map[string]interface{}{"componet_name": "location", "componet_help": "地理位置",
+ "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
+ "componet_type": "public", "componet_ctx": "aaa", "componet_cmd": "location",
+ "componet_args": []interface{}{}, "inputs": []interface{}{
+ map[string]interface{}{"type": "text", "name": "content", "view": "long"},
+ map[string]interface{}{"type": "button", "value": "位置", "click": "Location"},
+ map[string]interface{}{"type": "button", "value": "查看"},
+ },
+ },
+ map[string]interface{}{"componet_name": "baidu", "componet_help": "百度地图",
+ "componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
+ "componet_type": "public", "componet_ctx": "aaa", "componet_cmd": "location",
+ "componet_args": []interface{}{}, "inputs": []interface{}{
+ map[string]interface{}{"type": "text", "name": "content", "view": "long"},
+ map[string]interface{}{"type": "button", "value": "位置", "click": "Location"},
+ map[string]interface{}{"type": "button", "value": "查看"},
+ },
+ "display": map[string]interface{}{"map": true},
+ },
},
"index": []interface{}{
map[string]interface{}{"componet_name": "pod", "componet_help": "pod",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
- "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "remote",
- "componet_args": []interface{}{}, "inputs": []interface{}{
+ "componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
+ "componet_args": []interface{}{"$$", "context", "ssh", "remote"}, "inputs": []interface{}{
+ map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
map[string]interface{}{"type": "button", "value": "执行"},
},
- "exports": []interface{}{"pod", "key"},
+ "exports": []interface{}{"pod", "key", "pod"},
},
map[string]interface{}{"componet_name": "ctx", "componet_help": "ctx",
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
@@ -210,13 +230,13 @@ 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": "button", "value": "回退", "click": "Back"},
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": "button", "value": "查看"},
+ map[string]interface{}{"type": "button", "value": "回退", "click": "Back"},
},
- "display": map[string]interface{}{"hide_result": true},
- "exports": []interface{}{"dir", "filename", "dir"},
+ "display": map[string]interface{}{"hide_result": true},
+ "exports": []interface{}{"dir", "filename", "dir"},
"dir_root": []interface{}{"/"},
},
map[string]interface{}{"componet_name": "status", "componet_help": "git",
@@ -462,7 +482,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
}
msg.Cmd(tool["componet_cmd"], args, arg).CopyTo(m)
-
default:
m.Confm("componet", arg[0:], func(value map[string]interface{}) {
m.Add("append", "name", value["componet_name"])
diff --git a/src/examples/chat/chat.go b/src/examples/chat/chat.go
index 10612899..cbbba141 100644
--- a/src/examples/chat/chat.go
+++ b/src/examples/chat/chat.go
@@ -171,7 +171,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
// m.Option("nickname", m.Option("username"))
// }
m.Append("remote_ip", m.Option("remote_ip"))
- m.Append("nickname", m.Option("nickname"))
+ m.Append("nickname", kit.Select(m.Option("username"), m.Option("nickname")))
m.Echo(m.Option("username"))
return
}},
diff --git a/src/toolkit/kit.go b/src/toolkit/kit.go
index d915505f..4e41526b 100644
--- a/src/toolkit/kit.go
+++ b/src/toolkit/kit.go
@@ -213,6 +213,16 @@ func Format(arg ...interface{}) string {
result = append(result, string(val))
case []string:
result = append(result, val...)
+ // case []interface{}:
+ //
+ // result = append(result, "[")
+ // for i, value := range val {
+ // result = append(result, Format(value))
+ // if i < len(val)-1 {
+ // result = append(result, ",")
+ // }
+ // }
+ // result = append(result, "]")
case time.Time:
result = append(result, fmt.Sprintf("%s", val.Format("2006-01-02 15:03:04")))
case *os.File:
@@ -318,6 +328,8 @@ func Struct(arg ...interface{}) map[string]interface{} {
switch val := arg[0].(type) {
case map[string]interface{}:
return val
+ case string:
+ json.Unmarshal([]byte(val), value)
}
return value
diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js
index e3041974..ee9c9376 100644
--- a/usr/librarys/chat.js
+++ b/usr/librarys/chat.js
@@ -1,6 +1,7 @@
-var page = Page({
+Page({
conf: {border: 4, layout: {header:30, river:180, action:180, source:60, storm:180, footer:30}},
onlayout: function(event, sizes) {
+ var page = this
kit.isWindows && (document.body.style.overflow = "hidden")
var height = document.body.clientHeight-page.conf.border
@@ -11,24 +12,24 @@ var page = Page({
sizes = sizes || {}
sizes.header == undefined && (sizes.header = page.header.clientHeight)
sizes.footer == undefined && (sizes.footer = page.footer.clientHeight)
- page.header.Size(width, sizes.header)
- page.footer.Size(width, sizes.footer)
+ 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.Size(sizes.river, height)
- page.storm.Size(sizes.storm, height)
+ 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.Size(width, sizes.action)
- page.source.Size(width, sizes.source)
+ page.action.Pane.Size(width, sizes.action)
+ page.source.Pane.Size(width, sizes.source)
height -= page.source.offsetHeight+page.action.offsetHeight
- page.target.Size(width, height)
+ page.target.Pane.Size(width, height)
kit.History.add("lay", sizes)
},
oncontrol: function(event, target, action) {
@@ -37,7 +38,7 @@ var page = Page({
if (event.ctrlKey) {
switch (event.key) {
case "0":
- page.source.Select()
+ page.source.Pane.Select()
break
case "1":
case "2":
@@ -48,13 +49,13 @@ var page = Page({
case "7":
case "8":
case "9":
- page.action.Select(parseInt(event.key))
+ page.action.Pane.Select(parseInt(event.key))
break
case "n":
- page.ocean.Show()
+ page.ocean.Pane.Show()
break
case "m":
- page.steam.Show()
+ page.steam.Pane.Show()
break
case "i":
page.storm.Next()
@@ -70,102 +71,16 @@ var page = Page({
} else {
switch (event.key) {
case "Escape":
- page.dialog && page.dialog.Show()
+ page.dialog && page.dialog.Pane.Show()
}
}
break
}
},
- initLogin: function(page, pane, form, output) {
- var ui = kit.AppendChild(form, [
- {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
- }
- form.Run([ui.username.value, ui.password.value], function(msg) {
- if (msg.result && msg.result[0]) {
- pane.ShowDialog(1, 1)
- ctx.Cookie("sessid", msg.result[0])
- location.reload()
- return
- }
- page.alert("用户或密码错误")
- })
- }]},
- {button: ["scan", function(event) {
- scan(event, function(text) {
- alert(text)
- })
- }]},
- {type: "br"},
- {type: "img", data: {"src": "/chat/qrcode?text=hi"}}
- ])
-
-
- if (kit.isWeiXin) {
- pane.Run(["weixin"], function(msg) {
- // if (!ctx.Search("state")) {
- // location.href = msg["auth2.0"][0]
- // }
- // return
- kit.AppendChild(document.body, [{include: ["https://res.wx.qq.com/open/js/jweixin-1.4.0.js", function(event) {
- kit.AppendChild(document.body, [{include: ["/static/librarys/weixin.js", function(event) {
- wx.error(function(res){
- })
- wx.ready(function(){
- wx.getNetworkType({success: function (res) {
- }})
- return
- wx.getLocation({
- success: function (res) {
- page.footer.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",
- ]
- })
- }]}])
- }]}])
- })
- }
- form.Run([], function(msg) {
- if (msg.result && msg.result[0]) {
- page.header.State("user", msg.nickname[0])
- page.river.Show()
- page.footer.State("ip", msg.remote_ip[0])
- return
- }
- pane.ShowDialog(1, 1)
- })
- pane.Exit = function() {
- ctx.Cookie("sessid", "")
- page.reload()
-
- }
- },
- initOcean: function(page, pane, form, output) {
+ initOcean: function(page, field, option, output) {
var table = kit.AppendChild(output, "table")
- var ui = kit.AppendChild(pane, [{view: ["create ocean"], list: [
+ var ui = kit.AppendChild(field, [{view: ["create ocean"], list: [
{input: ["name", function(event) {
page.oninput(event, function(event) {
switch (event.key) {
@@ -181,10 +96,10 @@ var page = Page({
tr && tr.childNodes[0].click()
return true
case "9":
- pane.Action["全选"](event)
+ field.Pane.Action["全选"](event)
return true
case "0":
- pane.Action["清空"](event)
+ field.Pane.Action["清空"](event)
return true
case "-":
var pre = ui.list.querySelector("pre")
@@ -209,239 +124,235 @@ var page = Page({
cmd.push(item.innerText)
})
if (cmd.length == 3) {
- alert("请添加组员")
+ kit.alert("请添加组员")
return
}
- form.Run(cmd, function(msg) {
- page.river.Show()
- pane.Show()
+ field.Pane.Run(cmd, function(msg) {
+ page.river.Pane.Show()
+ field.Pane.Show()
})
}]}, {name: "list", view: ["list"]},
]}])
- pane.Show = function() {
- pane.ShowDialog() && (table.innerHTML = "", ui.list.innerHTML = "", ui.name.value = "good", ui.name.focus(), form.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)
- }}])
- })
- }))
+ 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: ["取消", "全选", "清空"],
}
- pane.Action = {
- "取消": function(event) {
- 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()
- })
- },
- }
- return {"button": ["取消", "全选", "清空"], "action": pane.Action}
},
- initRiver: function(page, pane, form, output) {
- pane.Show = function() {
- output.Update([], "text", ["name", "count"], "key", ctx.Search("river")||true, function(line, index, event) {})
- }
- pane.Action = {
- "创建": function(event) {
- page.ocean.Show()
+ 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: ["创建"],
}
- return {"button": ["创建"], "action": pane.Action}
},
- initTarget: function(page, pane, form, output) {
- output.DisplayUser = true
+ initTarget: function(page, field, option, output) {
var river = ""
- pane.Listen = {
- river: function(value, old) {
- river = value, pane.Show()
+ 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(1000, cmds, function(line, index, msg) {
+ pane.Append("", line, ["text"], "index")
+ 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)
+ })
},
}
-
- pane.Stop = false
- pane.Show = function() {
- var cmds = ["brow", river, 0]
- output.innerHTML = "", pane.Times(1000, cmds, function(line, index, msg) {
- output.Append("", line, ["text"], "index", fun)
- cmds[2] = parseInt(line.index)+1
- page.footer.State("text", cmds[2])
- })
- }
-
- function fun(line, index, event, args, cbs) {
- var data = JSON.parse(line.text)
- form.Run(["wave", river, data.node, data.group, data.index].concat(args), cbs)
- }
-
- pane.Send = function(type, text, cb) {
- form.Run(["flow", river, type, text], function(msg) {
- // output.Append(type, {create_user: msg.create_user[0], text:text, index: msg.result[0]}, ["text"], "index", fun)
- typeof cb == "function" && cb()
- })
- }
- return [{"text": ["target"]}]
},
- initSource: function(page, pane, form, output) {
- var ui = kit.AppendChild(pane, [{"view": ["input", "textarea"], "data": {"onkeyup": function(event){
- kit.isSpace(event.key) && pane.which.set(event.target.value)
- event.key == "Enter" && !event.shiftKey && page.target.Send("text", event.target.value, pane.Clear)
+ 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()
}}}])
- pane.Size = function(width, height) {
- pane.style.display = (width<=0 || height<=0)? "none": "block"
- pane.style.width = width+"px"
- pane.style.height = height+"px"
- ui.first.style.width = (width-7)+"px"
- ui.first.style.height = (height-7)+"px"
+ 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 = ""
+ },
}
- pane.Select = function() {
- ui.first.focus()
- }
-
- pane.Clear = function(value) {
- ui.first.value = value || ""
- }
- return
},
- initAction: function(page, pane, form, output) {
- var cache = {}
+ initAction: function(page, field, option, output) {
var river = "", storm = 0, input = "", share = ""
- pane.Listen = {
- river: function(value, old) {
- river = value
- },
- storm: function(value, old) {
- var temp = document.createDocumentFragment()
- while (output.childNodes.length>0) {
- item = output.childNodes[0]
- item.parentNode.removeChild(item)
- temp.appendChild(item)
- }
- cache[river+storm] = temp
- storm = value, pane.Show()
- },
- source: function(value, old) {
- input = value, kit.Log(value)
- },
- target: function(value, old) {
- share = value, kit.Log(value)
- },
- }
- pane.Show = function() {
- if (cache[river+storm]) {
- while (cache[river+storm].childNodes.length>0) {
- item = cache[river+storm].childNodes[0]
- item.parentNode.removeChild(item)
- output.appendChild(item)
- }
- cache[river+storm] = undefined
- return
- }
-
- output.Update([river, storm], "plugin", ["node", "name"], "index", false, function(line, index, event, args, cbs) {
- event.shiftKey? page.target.Send("field", JSON.stringify({
- name: line.name, help: line.help, view: line.view, init: line.init,
- node: line.node, group: line.group, index: line.index,
- inputs: line.inputs, args: args,
- })): form.Run([river, storm, index].concat(args), function(msg) {
- event.ctrlKey && (msg.append && msg.append[0]?
- page.target.Send("table", JSON.stringify(ctx.Tables(msg))):
- page.target.Send("code", msg.result.join("")))
- cbs(msg)
- })
- })
- }
-
- pane.Select = function(index) {
- output.querySelectorAll("fieldset")[index-1].Select()
- }
-
var toggle = true
- pane.Action = {
- "恢复": function(event, value) {
- page.onlayout(event, page.conf.layout)
- },
- "缩小": function(event, value) {
- page.onlayout(event, {action:60, source:60})
- },
- "放大": function(event, value) {
- page.onlayout(event, {action:300, source:60})
- },
- "最高": function(event, value) {
- page.onlayout(event, {action: -1})
- },
- "最宽": function(event, value) {
- page.onlayout(event, {river:0, storm:0})
- },
- "最大": function(event, value) {
- (toggle = !toggle)? page.onlayout(event, page.conf.layout): page.onlayout(event, {river:0, action:-1, source:60})
- page.target.Stop = !toggle
- },
- "全屏": function(event, value) {
- page.onlayout(event, {header:0, footer:0, river:0, action: -1, storm:0})
- },
- "添加": function(event, value) {
- page.plugin && page.plugin.Clone()
- },
- "删除": function(event, value) {
- page.plugin && page.plugin.Clear()
- },
- "加参": function(event, value) {
- page.plugin.Append({})
- },
- "去参": function(event, value) {
- page.input && page.plugin.Remove(page.input)
- },
- }
- return {"button": ["恢复", "缩小", "放大", "最高", "最宽", "最大", "全屏", "br", "添加", "删除", "加参", "去参"], "action": pane.Action}
- },
- initStorm: function(page, pane, form, output) {
- var river = "", index = -1
- pane.Listen = {
- river: function(value, old) {
- pane.which.set(""), river = value, pane.Show()
- },
- }
- pane.Show = function(which) {
- output.Update([river], "text", ["key", "count"], "key", which||ctx.Search("storm")||true)
- }
- pane.Next = function() {
- var next = output.querySelector("div.item.select").nextSibling
- next? next.click(): output.firstChild.click()
- }
- pane.Prev = function() {
- var prev = output.querySelector("div.item.select").previousSibling
- prev? prev.click(): output.lastChild.click()
- }
- pane.Action = {
- "创建": function(event) {
- page.steam.Show()
- },
- }
- return {"button": ["创建"], "action": pane.Action}
- },
- initSteam: function(page, pane, form, output) {
- var river = ""
- pane.Listen = {
- river: function(value, old) {
- river = value
- },
- }
+ 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) {
+ event.shiftKey? page.target.Send("field", JSON.stringify({
+ name: line.name, help: line.help, view: line.view, init: line.init,
+ node: line.node, group: line.group, index: line.index,
+ inputs: line.inputs, args: args,
+ })): field.Pane.Run([river, storm, index].concat(args), function(msg) {
+ event.ctrlKey && (msg.append && msg.append[0]?
+ page.target.Send("table", JSON.stringify(ctx.Tables(msg))):
+ page.target.Send("code", msg.result.join("")))
+ 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, {action:60, source:60})
+ },
+ "放大": function(event, value) {
+ page.onlayout(event, {action:300, source:60})
+ },
+ "最高": function(event, value) {
+ page.onlayout(event, {action: -1})
+ },
+ "最宽": function(event, value) {
+ page.onlayout(event, {river:0, storm:0})
+ },
+ "最大": function(event, value) {
+ (toggle = !toggle)? page.onlayout(event, page.conf.layout): page.onlayout(event, {river:0, action:-1, source:60})
+ },
+ "全屏": function(event, value) {
+ page.onlayout(event, {header:0, footer:0, river:0, action: -1, storm:0})
+ },
+ "添加": function(event, value) {
+ page.plugin && page.plugin.Plugin.Clone().Select()
+ },
+ "删除": function(event, value) {
+ page.plugin && page.plugin.Clear()
+ },
+ "加参": function(event, value) {
+ page.plugin.Append({})
+ },
+ "去参": function(event, value) {
+ page.input && page.plugin.Remove(page.input)
+ },
+ "位置": function(event, value) {
+ page.getLocation(function(res) {
+ alert(res.latitude)
+ alert(res.longitude)
+ })
+ },
+ },
+ Button: [["layout", "恢复", "缩小", "放大", "最高", "最宽", "最大", "全屏"], "br", "添加", "删除", "加参", "去参", "位置"],
+ }
+ },
+ 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.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(pane, [{"view": ["device", "table"]}]).last
- var ui = kit.AppendChild(pane, [{view: ["create steam"], list: [
+ 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) {
@@ -465,10 +376,10 @@ var page = Page({
tr && tr.childNodes[0].click()
return true
case "9":
- pane.Action["全选"](event)
+ field.Pane.Action["全选"](event)
return true
case "0":
- pane.Action["清空"](event)
+ field.Pane.Action["清空"](event)
return true
case "-":
var tr = ui.list.querySelectorAll("tr")[1]
@@ -496,130 +407,125 @@ var page = Page({
})
if (cmd.length == 4) {
- alert("请添加命令")
+ kit.alert("请添加命令")
return
}
- form.Run(cmd, function(msg) {
- pane.Show()
- page.storm.Show(ui.name.value)
+ field.Pane.Run(cmd, function(msg) {
+ field.Pane.Show()
+ page.storm.Pane.Show(ui.name.value)
})
}]}, {name: "list", view: ["list", "table"]},
]}])
- pane.Show = function() {
- pane.ShowDialog() && (table.innerHTML = "", ui.name.value = "nice", form.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"), form.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
+ 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()
- }))
+ 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: ["取消", "全选", "清空"],
}
-
- pane.Action = {
- "取消": function(event) {
- pane.Show()
- },
- "全选": function(event) {
- ui.list.innerHTML = "", device.querySelectorAll("tr").forEach(function(item) {
- item.firstChild.click()
- })
- },
- "清空": function(event) {
- ui.list.innerHTML = ""
- },
- }
- return {"button": ["取消", "全选", "清空"], "action": pane.Action}
},
init: function(page) {
- page.initField(page, function(init, pane, form) {
- var output = pane.querySelector("div.output")
-
- var list = [], last = -1
- output.Clear = function() {
- output.innerHTML = "", list = [], last = -1
- }
- output.Select = function(index) {
- -1 < last && last < list.length && (list[last].className = "item")
- last = index
- list[index] && (list[index].className = "item select")
- }
- output.Append = function(type, line, key, which, cb) {
- var index = list.length, ui = page.View(output, line.type || type, line, key, function(event, cmds, cbs) {
- output.Select(index), pane.which.set(line[which])
- typeof cb == "function" && cb(line, index, event, cmds, cbs)
- })
- list.push(ui.last), pane.scrollBy(0, pane.scrollHeight+100)
- return ui
- }
- output.Update = function(cmds, type, key, which, first, cb) {
- output.Clear(), form.Runs(cmds, function(line, index, msg) {
- var ui = output.Append(type, line, key, which, cb)
- if (typeof first == "string") {
- (line.key == first || line.name == first) && ui.first.click()
- } else {
- first && index == 0 && ui.first.click()
- }
- })
- }
-
- if (typeof init == "function") {
- var conf = init(page, pane, form, output)
- if (conf && conf["button"]) {
- var buttons = []
- conf.button.forEach(function(value, index) {
- if (value == "br") {
- buttons.push({type: "br"})
- } else {
- buttons.push({"button": [value, function(event) {
- typeof conf["action"] == "function" && conf["action"](value, event)
- typeof conf["action"] == "object" && conf["action"][value](event, value)
- pane.Button = value
- }]})
- }
- })
- kit.InsertChild(pane, output, "div", buttons).className = "action "+form.dataset.componet_name
- } else if (conf) {
- kit.AppendChild(output, conf)
- }
- }
- return conf
- })
-
page.onlayout(null, page.conf.layout)
- kit.isMobile && page.action.Action["最宽"]()
- page.action.Action["最大"]()
- ctx.Search("layout") && page.action.Action[ctx.Search("layout")]()
-
- page.footer.Order({"text": "", "ip": "", ".": "", ":":""}, ["ip", "text", ":", "."])
- kit.isMobile && page.footer.Order({"text": "", "site": "", "ip": ""}, ["ip", "text", "site"])
- page.header.Order({"user": "", "logout": "logout"}, ["logout", "user"], function(event, item, value) {
+ 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.which.get(), "storm": page.storm.which.get(), "layout": page.action.Button})
+ ctx.Search({"river": page.river.Pane.which.get(), "storm": page.storm.Pane.which.get(), "layout": page.action.Pane.Layout()})
break
case "user":
- var name = page.prompt("new name")
- name && page.login.Run(["rename", name], function(msg) {
- page.header.State("user", name)
+ var name = kit.prompt("new name")
+ name && page.login.Pane.Run(["rename", name], function(msg) {
+ page.header.Pane.State("user", name)
})
break
case "logout":
- page.confirm("logout?") && page.login.Exit()
+ kit.confirm("logout?") && page.login.Pane.Exit()
break
default:
}
})
+ 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 a1c42771..8accf157 100644
--- a/usr/librarys/context.js
+++ b/usr/librarys/context.js
@@ -95,7 +95,13 @@ ctx = context = {
var as = []
for (var k in args) {
- as.push(k+"="+encodeURIComponent(args[k]));
+ if (typeof args[k] == "object") {
+ for (var i = 0; i < args[k].length; i++) {
+ as.push(k+"="+encodeURIComponent(args[k][i]));
+ }
+ } else {
+ as.push(k+"="+encodeURIComponent(args[k]));
+ }
}
var arg = as.join("&");
return location.origin+location.pathname+"?"+arg
diff --git a/usr/librarys/example.css b/usr/librarys/example.css
index 6b990c65..8d08b41f 100644
--- a/usr/librarys/example.css
+++ b/usr/librarys/example.css
@@ -66,6 +66,10 @@ fieldset div.output table td {
word-break:break-all;
min-width:40px;
}
+fieldset div.output table td {
+ word-break:keep-all;
+ min-width:40px;
+}
fieldset.toast {
background-color:#ffffff00;
diff --git a/usr/librarys/example.js b/usr/librarys/example.js
index 7558cde8..b4e38582 100644
--- a/usr/librarys/example.js
+++ b/usr/librarys/example.js
@@ -1,25 +1,25 @@
function Page(page) {
var id = 1
- var conf = {}
- var conf_cb = {}
+ 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)
}
- if (cb != undefined) {
- conf_cb[key] = cb
- }
- if (key != undefined) {
- return conf[key]
- }
- return conf
+ return conf[key]
},
Sync: function(m) {
var meta = m, data = "", list = []
@@ -38,6 +38,9 @@ function Page(page) {
return data
},
set: function(value, force) {
+ if (value == undefined) {
+ return
+ }
if (value == data && !force) {
return value
}
@@ -51,32 +54,30 @@ function Page(page) {
})
},
View: function(parent, type, line, key, cb) {
- var ui = {}
- var result = []
- var text = line
+ var text = line, list = [], ui = {}
switch (type) {
case "icon":
- result = [{view: ["item", "div"], list: [{img: [line[key[0]], function(event) {
- event.target.scrollIntoView()
- }]}]}]
+ list.push({img: [line[key[0]], function(event) {
+ // event.target.scrollIntoView()
+ }]})
break
case "text":
- result = [{text: [key.length>1? line[key[0]]+"("+line[key[1]]+")": (key.length>0? line[key[0]]: "null"), "span"], click: cb}]
+ 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":
- result = [{type: "code", list: [{text: [key.length>1? line[key[0]]+"("+line[key[1]]+")": (key.length>0? line[key[0]]: "null")], click: cb}]}]
+ 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":
- result = [{view: [""], list: [
- {view: ["", "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"]}
- })}
- })},
- ]}]
+ 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":
@@ -84,37 +85,65 @@ function Page(page) {
case "plugin":
var id = "plugin"+page.ID()
- result = [{name: "field", view: [text.view, "fieldset"], data: {id: id}, list: [
+ list.push({view: [text.view+" item", "fieldset", "", "field"], data: {id: id, Run: cb}, list: [
{text: [text.name+"("+text.help+")", "legend"]},
- {name: "option", view: ["option", "form"], data: {Run: cb}, list: [{type: "input", style: {"display": "none"}}]},
- {name: "output", view: ["output", "div"]},
- {script: "Plugin("+id+","+JSON.stringify(text)+","+"[\""+(text.args||[]).join("\",\"")+"\"]"+","+(text.init||"")+")"},
- ]}]
+ {view: ["option", "form", "", "option"], list: [{type: "input", style: {"display": "none"}}]},
+ {view: ["output", "div", "", "output"]},
+ {script: ""+id+".Script="+(text.init||"{}")},
+ ]})
break
}
- if (parent.DisplayUser) {
- ui = kit.AppendChild(parent, [{view: ["item"], list:[
- {view: ["user", "div", line.create_nick]},
- {view: ["text"], list:result}
- ]}])
- } else {
- ui = kit.AppendChild(parent, [{view: ["item"], list:result}])
- }
+ 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
},
- alert: function(text) {
- alert(text)
+ Include: function(src, cb) {
+ kit.AppendChild(document.body, [{include: [src[0], function(event) {
+ src.length == 1? cb(event): page.Include(src.slice(1), cb)
+ }]}])
},
- prompt: function(text) {
- return prompt(text)
- },
- confirm: function(text) {
- return confirm(text)
- },
- reload: function() {
- location.reload()
+ 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
},
oninput: function(event, local) {
var target = event.target
@@ -123,6 +152,7 @@ function Page(page) {
if (event.ctrlKey) {
if (typeof local == "function" && local(event)) {
event.stopPropagation()
+ event.preventDefault()
return true
}
switch (event.key) {
@@ -168,212 +198,166 @@ function Page(page) {
if (kit.HitText(target, "jk")) {
kit.DelText(target, target.selectionStart-2, 2)
target.blur()
+ event.stopPropagation()
return true
}
}
return false
},
- 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
- },
onscroll: function(event, target, action) {
- switch (action) {
- case "scroll":
- if (event.target == document.body) {
- kit.ScrollPage(event, page.conf)
+ 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, pane, form, output) {
- var state = {}, list = [], cb = function(event, item, value) {
+ initHeader: function(page, field, option, output) {
+ var state = {}, list = [], cb = function(event, item, value) {}
+ field.onclick = function(event) {
+ page.pane.scrollTo(0,0)
}
- pane.Order = function(value, order, cbs) {
- state = value, list = order, cb = cbs || cb, pane.Show()
- }
- pane.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])
- }}})},
- ])
- }
- pane.State = function(name, value) {
- state[name] = value, pane.Show()
- }
- return
- },
- initBanner: function(page, field, option, output) {
- field.querySelectorAll("li").forEach(function(item) {
- item.onclick = function(event) {
- ctx.Search("componet_group", item.innerText)
- if (item.innerText == "login") {
- ctx.Cookie("sessid", "")
- }
- }
- })
- return [{"text": ["shylinux", "div", "title"]}]
- },
- initFooter: function(page, pane, form, output) {
- var state = {}, list = [], cb = function(event, item, value) {
- }
- pane.Order = function(value, order, cbs) {
- state = value, list = order, cb = cbs || cb, pane.Show()
- }
- pane.State = function(name, value) {
- if (value != undefined) {
- state[name] = value, pane.Show()
- }
- if (name != undefined) {
- return state[name]
- }
- return state
- }
-
- pane.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"]}})},
- ])
- }
- return
- },
- initField: function(page, cb) {
- document.querySelectorAll("body>fieldset").forEach(function(pane) {
- var form = pane.querySelector("form.option")
- page[form.dataset.componet_name] = pane
-
- // pane init
- pane.which = page.Sync(form.dataset.componet_name)
- pane.ShowDialog = function(width, height) {
- if (pane.style.display != "block") {
- page.dialog && page.dialog != pane && page.dialog.style.display == "block" && page.dialog.Show()
- pane.style.display = "block", page.dialog = pane
- kit.ModifyView(pane, {window: [width||80, height||200]})
- return true
- }
- pane.style.display = "none"
- delete(page.dialog)
- return false
- }
- pane.Size = function(width, height) {
- pane.style.display = (width<=0 || height<=0)? "none": "block"
- pane.style.width = width+"px"
- pane.style.height = height+"px"
- }
-
- var conf = {}
- var conf_cb = {}
- pane.Conf = function(key, value, cb) {
+ 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) {
- var old = conf[key]
- conf[key] = value
- conf_cb[key] && conf_cb[key](value, old)
+ state[name] = value, this.Show()
}
- if (cb != undefined) {
- conf_cb[key] = cb
+ if (name != undefined) {
+ return state[name]
}
- if (key != undefined) {
- return conf[key]
- }
- return conf
- }
-
- // form init
- pane.Run = form.Run = function(cmds, cb) {
- ctx.Run(page, form.dataset, cmds, cb)
- }
- pane.Runs = form.Runs = function(cmds, cb) {
- ctx.Run(page, form.dataset, cmds, function(msg) {
- ctx.Table(msg, function(line, index) {
- cb(line, index, msg)
- })
- })
- }
- pane.Time = form.Time = function(time, cmds, cb) {
- function loop() {
- ctx.Run(page, form.dataset, cmds, cb)
- setTimeout(loop, time)
- }
- setTimeout(loop, time)
- }
-
- var timer = ""
- pane.Times = form.Times = function(time, cmds, cb) {
- timer && clearTimeout(timer)
- function loop() {
- !pane.Stop && ctx.Run(page, form.dataset, cmds, function(msg) {
- ctx.Table(msg, function(line, index) {
- cb(line, index, msg)
- })
- })
- timer = setTimeout(loop, time)
- }
- time && (timer = setTimeout(loop, time))
- }
- form.onsubmit = function(event) {
- event.preventDefault()
- }
-
- cb(page[pane.dataset.init], pane, form)
- })
-
- document.querySelectorAll("body>fieldset").forEach(function(pane) {
- for (var k in pane.Listen) {
- page[k].which.change(pane.Listen[k])
- }
- })
+ 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, document.body, "scroll")
+ page.onscroll && page.onscroll(event, window, "scroll")
}
document.body.onkeyup = function(event) {
page.oncontrol && page.oncontrol(event, document.body, "control")
@@ -381,74 +365,170 @@ function Page(page) {
}
return page
}
-function Plugin(field, tool, args, plugin) {
+function Pane(page, field) {
+ var option = field.querySelector("form.option")
+ var action = field.querySelector("div.action")
+ var output = field.querySelector("div.output")
+
+ var cache = []
+ var timer = ""
+ var list = [], last = -1
+ var name = option.dataset.componet_name
+ var pane = (page[field.dataset.init] || function() {
+ })(page, field, option, output) || {}; pane.__proto__ = {
+ __proto__: page,
+ 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) {
+ ctx.Run(page, option.dataset, 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])
+ }
+ 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 == "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 exports = JSON.parse(tool.exports||'["",""]')
- var display = JSON.parse(tool.display||'{}')
- option.Runs = function(event) {
- option.Run(event, kit.Selector(option, ".args", function(item, index) {
- return item.value
- }), function(msg) {
- (option.ondaemon || function(msg) {
- 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) {
- if (exports.length > 2) {
- if (value.endsWith("/")) {
- value = option[exports[2]].value + value
- } else {
- return
- }
- }
- page.Sync("plugin_"+exports[0]).set(value)
- });
- (display.show_result || !msg.append) && msg.result && kit.AppendChild(output, [{view: ["code", "div", msg.Results()]}])
- })(msg)
- })
- }
-
- var total = 0, count = 0
- plugin = plugin || {}, plugin.__proto__ = {
- show: function() {},
- init: function() {},
- Clone: function() {
- field.Meta.args = kit.Selector(option, ".args", function(item, index) {
- return item.value
- })
- page.View(field.parentNode, "plugin", field.Meta, [], option.Run)
- },
- Clear: function() {
- field.parentNode && field.parentNode.removeChild(field)
- },
- Check: function(event, index) {
- index == total-1 || (index == total-2 && event.target.parentNode.nextSibling.childNodes[1].type == "button")?
- option.Runs(event): event.target.parentNode.nextSibling.childNodes[1].focus()
- },
- Remove: function(who) {
- who.parentNode && who.parentNode.removeChild(who)
- },
+ var count = 0
+ var wait = false
+ var plugin = field.Script || {}; plugin.__proto__ = {
+ __proto__: pane,
Append: function(item, name) {
- var index = total
- total += 1
name = name || item.name
item.onfocus = function(event) {
- page.plugin = plugin
- page.input = event.target
- page.footer.State(".", field.id)
- page.footer.State(":", index)
+ page.pane = pane.Field, page.plugin = field, page.input = event.target
}
item.onkeyup = function(event) {
page.oninput(event, function(event) {
switch (event.key) {
+ case "p":
+ action.Back()
+ break
case "i":
var next = field.nextSibling;
- next && next.Select()
+ next && next.Plugin.Select()
break
case "o":
var prev = field.previousSibling;
- prev && prev.Select()
+ prev && prev.Plugin.Select()
break
case "c":
output.innerHTML = ""
@@ -456,23 +536,24 @@ function Plugin(field, tool, args, plugin) {
case "r":
output.innerHTML = ""
case "j":
- run(event)
+ plugin.Runs(event)
break
case "l":
- page.action.scrollTo(0, option.parentNode.offsetTop)
- break
- case "m":
- plugin.Clone()
+ page.action.scrollTo(0, field.offsetTop)
break
case "b":
- plugin.Append(item, "args"+total).focus()
+ plugin.Append(item).focus()
+ break
+ case "m":
+ plugin.Clone().Plugin.Select()
break
default:
return false
}
+ event.stopPropagation()
return true
})
- event.key == "Enter" && plugin.Check(event, index)
+ event.key == "Enter" && plugin.Check(action)
}
var input = {type: "input", name: name, data: item}
@@ -480,19 +561,16 @@ function Plugin(field, tool, args, plugin) {
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): option.Runs(event)
+ plugin[item.click]? plugin[item.click](event, item, option, field): plugin.Runs(event)
}
break
case "select":
- input = {type: "select", name: name, data: {className: "args", onchange: function(event) {
- plugin.Check(event, index)
-
- }}, list: item.values.map(function(value) {
+ input.type = "select", input.list = item.values.map(function(value) {
return {type: "option", value: value, inner: value}
- })}
- args && count < args.length && (item.value = args[count++])
- break
+ }), item.onchange = function(event) {
+ plugin.Check(action)
+ }
default:
args && count < args.length && (item.value = args[count++]||item.value||"")
@@ -502,39 +580,100 @@ function Plugin(field, tool, args, plugin) {
var ui = kit.AppendChild(option, [{view: [item.view||""], list: [{type: "label", inner: item.label||""}, input]}])
var action = ui[name] || {}
- page.plugin = field
- page.input = action
- index == 0 && action && action.focus && action.focus()
-
- action.History = []
- action.Goto = function(value) {
- action.value = value;
- (index == total-1 || (index == total-2 && action.parentNode.nextSibling.childNodes[1].type == "button")) && option.Runs(event)
- action.History.push(value)
- plugin.Back = function() {
- action.History.pop()
- action.History.length > 0 && action.Goto(action.History.pop())
- }
+ 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())
+ };
- item.imports && typeof item.imports == "object" && item.imports.forEach(function(imports) {
+ (typeof item.imports == "object"? item.imports: typeof item.imports == "string"? [item.imports]: []).forEach(function(imports) {
page.Sync(imports).change(action.Goto)
})
- item.imports && typeof item.imports == "string" && page.Sync(item.imports).change(action.Goto)
return action
},
Select: function() {
- page.plugin = field
- page.footer.State(".", field.id)
+ option.querySelectorAll("input")[1].focus()
},
+ Format: function() {
+ arguments.length > 0 && (field.Meta.args = kit.List(arguments))
+ return JSON.stringify(field.Meta)
+ },
+ Remove: function() {
+ 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) {
+ field.Run(event, kit.Selector(option, ".args", function(item, index) {
+ return item.value
+ }), plugin.ondaemon)
+ },
+ 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)
+ })
+ },
+
+ Clear: function() {
+ output.innerHTML = ""
+ },
+ ondaemon: function(msg) {
+ output.innerHTML = ""
+ if (display.map) {
+ var id = "map"+page.ID()
+ kit.AppendChild(output, [{type: "view", data: {id: id}}])
+ var mp = new BMap.Map(id);
+ mp.centerAndZoom(new BMap.Point(121.491, 31.233), 11);
+ 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
+ }
+ },
+ },
+ init: function() {},
}
- var inputs = JSON.parse(tool.inputs || "[]")
- inputs.map(function(item, index, inputs) {
- plugin.Append(item)
- })
+ 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, page.action, field, option, output)
- page[field.id] = plugin
+ 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/plugin/initQRCode.js b/usr/librarys/plugin/initQRCode.js
index 3110a3fb..2783b62e 100644
--- a/usr/librarys/plugin/initQRCode.js
+++ b/usr/librarys/plugin/initQRCode.js
@@ -1,9 +1,9 @@
-{
- init: function(page, pane, plug, form, output) {
- form.Runs = function(event) {
- var url = "/chat/?componet_group=index&componet_name=login&cmds=qrcode&cmds="+form.content.value
- output.innerHTML = "", kit.AppendChild(output, [{img: [url]}])
- event.ctrlKey? page.target.Send("icon", url): form.Run(event, [form.content.value])
- }
- },
-}
+{init: function(page, pane, field, option, output) {
+ this.Runs = function(event) {
+ var value = option.content.value
+ var url = page.login.Pane.Share({cmds: ["qrcode", value]})
+ kit.AppendChilds(output, [{img: [url]}])
+ event.ctrlKey && page.target.Pane.Send("icon", url)
+ event.shiftKey && page.target.Pane.Send("field", this.Format(value))
+ }
+}}
diff --git a/usr/librarys/toolkit.js b/usr/librarys/toolkit.js
index 7ef5e52b..87fe5373 100644
--- a/usr/librarys/toolkit.js
+++ b/usr/librarys/toolkit.js
@@ -29,54 +29,6 @@ kit = toolkit = {
return args
},
- Position: function(which) {
- return (parseInt((which.scrollTop + which.clientHeight) / which.scrollHeight * 100)||0)+"%"
- },
- ScrollPage: function(event, conf) {
- switch (event.key) {
- case "h":
- if (event.ctrlKey) {
- window.scrollBy(-conf.scroll_x*10, 0)
- } else {
- window.scrollBy(-conf.scroll_x, 0)
- }
- break
- case "H":
- window.scrollBy(-document.body.scrollWidth, 0)
- break
- case "l":
- if (event.ctrlKey) {
- window.scrollBy(conf.scroll_x*10, 0)
- } else {
- window.scrollBy(conf.scroll_x, 0)
- }
- break
- case "L":
- window.scrollBy(document.body.scrollWidth, 0)
- break
- case "j":
- if (event.ctrlKey) {
- window.scrollBy(0, conf.scroll_y*10)
- } else {
- window.scrollBy(0, conf.scroll_y)
- }
- break
- case "J":
- window.scrollBy(0, document.body.scrollHeight)
- break
- case "k":
- if (event.ctrlKey) {
- window.scrollBy(0, -conf.scroll_y*10)
- } else {
- window.scrollBy(0, -conf.scroll_y)
- }
- break
- case "K":
- window.scrollBy(0, -document.body.scrollHeight)
- break
- }
- return true
- },
ModifyView: function(which, args) {
var height = document.body.clientHeight-4
var width = document.body.clientWidth-4
@@ -164,6 +116,7 @@ kit = toolkit = {
//
// dataset click
// button input label img
+ // select
//
// 树状结构: tree fork leaf
// 普通视图: view text code
@@ -190,6 +143,9 @@ kit = toolkit = {
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) {
@@ -213,6 +169,13 @@ kit = toolkit = {
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]
@@ -272,14 +235,14 @@ kit = toolkit = {
child.code.length > 2 && (child.data["className"] = child.code[2])
} else if (child.script) {
- child.data.innerHTML = 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])
- child.type = "script"
} else if (child.require) {
child.data["href"] = child.require[0]
@@ -315,6 +278,9 @@ kit = toolkit = {
})
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)
@@ -332,6 +298,7 @@ kit = toolkit = {
})
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", row[key])
if (typeof cb == "function") {
@@ -403,14 +370,133 @@ kit = toolkit = {
kit.RangeTable(table, i, dataset["sort_asc"] == "1")
return
}
- if (field && head.childNodes[i].innerText.startsWith(field)) {
- typeof cb == "function" && cb(event, item.innerText)
+ 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})
+ })
+ })
+ },
+
+ 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
+ },
+ Position: function(which) {
+ return (parseInt((which.scrollTop + which.clientHeight) / which.scrollHeight * 100)||0)+"%"
+ },
+
+ alert: function(text) {
+ alert(JSON.stringify(text))
+ },
+ prompt: function(text) {
+ return prompt(text)
+ },
+ confirm: function(text) {
+ return confirm(text)
+ },
+ reload: function() {
+ location.reload()
+ },
+
OrderForm: function(page, field, option, append, result) {
if (!option) {return}
option.ondaemon = option.ondaemon || function(msg) {
@@ -477,106 +563,17 @@ kit = toolkit = {
}
})
},
- OrderCode: function(code) {
- if (!code) {return}
- var kit = this
- code.onclick = function(event) {
- kit.CopyText()
- }
- },
- 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})
- })
- })
- },
- OrderLink: function(link) {
- link.target = "_blank"
- },
-
- 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) {
+ List: function(obj, 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
- }
+ for (var i = 0; i < obj.length; i++) {
+ list.push(typeof cb == "function"? cb(obj[i]): obj[i])
}
return list
},
+ Format: function(objs) {
+ return json.stringify(objs)
+ },
}
function right(arg) {
diff --git a/usr/template/common.tmpl b/usr/template/common.tmpl
index 10366792..8681f014 100644
--- a/usr/template/common.tmpl
+++ b/usr/template/common.tmpl
@@ -43,6 +43,7 @@
{{range $index, $lib := option . "scripts"}}
{{end}}
+