mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-26 01:04:06 +08:00
opt example.js
This commit is contained in:
parent
341447415f
commit
a24fc9cdcf
@ -689,6 +689,31 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
|||||||
}
|
}
|
||||||
return
|
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) {
|
"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 { // 会话列表
|
if len(arg) == 0 { // 会话列表
|
||||||
|
@ -148,7 +148,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
}, Help: "运行环境"},
|
}, Help: "运行环境"},
|
||||||
"compile": &ctx.Config{Name: "compile", Value: map[string]interface{}{
|
"compile": &ctx.Config{Name: "compile", Value: map[string]interface{}{
|
||||||
"bench": "src/examples/app/bench.go",
|
"bench": "src/examples/app/bench.go",
|
||||||
"tmp": "var/tmp/go",
|
"tmp": "var/tmp/go",
|
||||||
"env": []interface{}{"GOPATH", "PATH"},
|
"env": []interface{}{"GOPATH", "PATH"},
|
||||||
}, Help: "运行环境"},
|
}, Help: "运行环境"},
|
||||||
"publish": &ctx.Config{Name: "publish", Value: map[string]interface{}{
|
"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) {
|
m.Confm("publish", "list", func(key string, value string) {
|
||||||
list = append(list, []string{key})
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -738,7 +738,7 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
|||||||
m.Echo(", wait 1s\n")
|
m.Echo(", wait 1s\n")
|
||||||
m.Table()
|
m.Table()
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
for _, v:=range m.Meta["result"] {
|
for _, v := range m.Meta["result"] {
|
||||||
fmt.Printf("%v", v)
|
fmt.Printf("%v", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1556,10 +1556,11 @@ func (m *Message) Cmdp(t time.Duration, head []string, prefix []string, suffix [
|
|||||||
|
|
||||||
for i, v := range suffix {
|
for i, v := range suffix {
|
||||||
m.Show(fmt.Sprintf("%v/%v %v...\n", i+1, len(suffix), v))
|
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)
|
time.Sleep(t)
|
||||||
}
|
}
|
||||||
m.Show("\n")
|
m.Show("\n")
|
||||||
|
m.Table()
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
func (m *Message) Cmdm(args ...interface{}) *Message {
|
func (m *Message) Cmdm(args ...interface{}) *Message {
|
||||||
|
@ -98,6 +98,38 @@ var Index = &ctx.Context{Name: "mdb", Help: "数据中心",
|
|||||||
}, Help: "数据视图"},
|
}, Help: "数据视图"},
|
||||||
},
|
},
|
||||||
Commands: map[string]*ctx.Command{
|
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]]]]]]",
|
"open": &ctx.Command{Name: "open [database [username [password [address [protocol [driver]]]]]]",
|
||||||
Help: "打开数据库, database: 数据库名, username: 用户名, password: 密码, address: 服务地址, protocol: 服务协议, driver: 数据库类型",
|
Help: "打开数据库, database: 数据库名, username: 用户名, password: 密码, address: 服务地址, protocol: 服务协议, driver: 数据库类型",
|
||||||
Form: map[string]int{"dbname": 1, "dbhelp": 1},
|
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...)
|
kit.Select("数据源", m.Option("dbhelp")), arg...)
|
||||||
return
|
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) {
|
"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 {
|
if mdb, ok := m.Target().Server.(*MDB); m.Assert(ok) && mdb.DB != nil {
|
||||||
which := make([]interface{}, 0, len(arg))
|
which := make([]interface{}, 0, len(arg))
|
||||||
|
@ -176,15 +176,35 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
|||||||
map[string]interface{}{"type": "button", "value": "运行"},
|
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{}{
|
"index": []interface{}{
|
||||||
map[string]interface{}{"componet_name": "pod", "componet_help": "pod",
|
map[string]interface{}{"componet_name": "pod", "componet_help": "pod",
|
||||||
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
|
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
|
||||||
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "remote",
|
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
||||||
"componet_args": []interface{}{}, "inputs": []interface{}{
|
"componet_args": []interface{}{"$$", "context", "ssh", "remote"}, "inputs": []interface{}{
|
||||||
|
map[string]interface{}{"type": "text", "name": "pod", "imports": "plugin_pod"},
|
||||||
map[string]interface{}{"type": "button", "value": "执行"},
|
map[string]interface{}{"type": "button", "value": "执行"},
|
||||||
},
|
},
|
||||||
"exports": []interface{}{"pod", "key"},
|
"exports": []interface{}{"pod", "key", "pod"},
|
||||||
},
|
},
|
||||||
map[string]interface{}{"componet_name": "ctx", "componet_help": "ctx",
|
map[string]interface{}{"componet_name": "ctx", "componet_help": "ctx",
|
||||||
"componet_tmpl": "componet", "componet_view": "Context", "componet_init": "",
|
"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_tmpl": "componet", "componet_view": "Context", "componet_init": "",
|
||||||
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
"componet_type": "private", "componet_ctx": "ssh", "componet_cmd": "_route",
|
||||||
"componet_args": []interface{}{"$$", "context", "nfs", "dir"}, "inputs": []interface{}{
|
"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": "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": "dir", "value": "", "view": "long", "imports": []interface{}{"plugin_dir", "plugin_you"}},
|
||||||
map[string]interface{}{"type": "button", "value": "查看"},
|
map[string]interface{}{"type": "button", "value": "查看"},
|
||||||
|
map[string]interface{}{"type": "button", "value": "回退", "click": "Back"},
|
||||||
},
|
},
|
||||||
"display": map[string]interface{}{"hide_result": true},
|
"display": map[string]interface{}{"hide_result": true},
|
||||||
"exports": []interface{}{"dir", "filename", "dir"},
|
"exports": []interface{}{"dir", "filename", "dir"},
|
||||||
"dir_root": []interface{}{"/"},
|
"dir_root": []interface{}{"/"},
|
||||||
},
|
},
|
||||||
map[string]interface{}{"componet_name": "status", "componet_help": "git",
|
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)
|
msg.Cmd(tool["componet_cmd"], args, arg).CopyTo(m)
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
m.Confm("componet", arg[0:], func(value map[string]interface{}) {
|
m.Confm("componet", arg[0:], func(value map[string]interface{}) {
|
||||||
m.Add("append", "name", value["componet_name"])
|
m.Add("append", "name", value["componet_name"])
|
||||||
|
@ -171,7 +171,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
|||||||
// m.Option("nickname", m.Option("username"))
|
// m.Option("nickname", m.Option("username"))
|
||||||
// }
|
// }
|
||||||
m.Append("remote_ip", m.Option("remote_ip"))
|
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"))
|
m.Echo(m.Option("username"))
|
||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
|
@ -213,6 +213,16 @@ func Format(arg ...interface{}) string {
|
|||||||
result = append(result, string(val))
|
result = append(result, string(val))
|
||||||
case []string:
|
case []string:
|
||||||
result = append(result, val...)
|
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:
|
case time.Time:
|
||||||
result = append(result, fmt.Sprintf("%s", val.Format("2006-01-02 15:03:04")))
|
result = append(result, fmt.Sprintf("%s", val.Format("2006-01-02 15:03:04")))
|
||||||
case *os.File:
|
case *os.File:
|
||||||
@ -318,6 +328,8 @@ func Struct(arg ...interface{}) map[string]interface{} {
|
|||||||
switch val := arg[0].(type) {
|
switch val := arg[0].(type) {
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
return val
|
return val
|
||||||
|
case string:
|
||||||
|
json.Unmarshal([]byte(val), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
var page = Page({
|
Page({
|
||||||
conf: {border: 4, layout: {header:30, river:180, action:180, source:60, storm:180, footer:30}},
|
conf: {border: 4, layout: {header:30, river:180, action:180, source:60, storm:180, footer:30}},
|
||||||
onlayout: function(event, sizes) {
|
onlayout: function(event, sizes) {
|
||||||
|
var page = this
|
||||||
kit.isWindows && (document.body.style.overflow = "hidden")
|
kit.isWindows && (document.body.style.overflow = "hidden")
|
||||||
|
|
||||||
var height = document.body.clientHeight-page.conf.border
|
var height = document.body.clientHeight-page.conf.border
|
||||||
@ -11,24 +12,24 @@ var page = Page({
|
|||||||
sizes = sizes || {}
|
sizes = sizes || {}
|
||||||
sizes.header == undefined && (sizes.header = page.header.clientHeight)
|
sizes.header == undefined && (sizes.header = page.header.clientHeight)
|
||||||
sizes.footer == undefined && (sizes.footer = page.footer.clientHeight)
|
sizes.footer == undefined && (sizes.footer = page.footer.clientHeight)
|
||||||
page.header.Size(width, sizes.header)
|
page.header.Pane.Size(width, sizes.header)
|
||||||
page.footer.Size(width, sizes.footer)
|
page.footer.Pane.Size(width, sizes.footer)
|
||||||
|
|
||||||
sizes.river == undefined && (sizes.river = page.river.clientWidth)
|
sizes.river == undefined && (sizes.river = page.river.clientWidth)
|
||||||
sizes.storm == undefined && (sizes.storm = page.storm.clientWidth)
|
sizes.storm == undefined && (sizes.storm = page.storm.clientWidth)
|
||||||
height -= page.header.offsetHeight+page.footer.offsetHeight
|
height -= page.header.offsetHeight+page.footer.offsetHeight
|
||||||
page.river.Size(sizes.river, height)
|
page.river.Pane.Size(sizes.river, height)
|
||||||
page.storm.Size(sizes.storm, height)
|
page.storm.Pane.Size(sizes.storm, height)
|
||||||
|
|
||||||
sizes.action == undefined && (sizes.action = page.action.clientHeight)
|
sizes.action == undefined && (sizes.action = page.action.clientHeight)
|
||||||
sizes.source == undefined && (sizes.source = page.source.clientHeight);
|
sizes.source == undefined && (sizes.source = page.source.clientHeight);
|
||||||
(sizes.action == -1 || sizes.source == 0) && (sizes.action = height, sizes.source = 0)
|
(sizes.action == -1 || sizes.source == 0) && (sizes.action = height, sizes.source = 0)
|
||||||
width -= page.river.offsetWidth+page.storm.offsetWidth
|
width -= page.river.offsetWidth+page.storm.offsetWidth
|
||||||
page.action.Size(width, sizes.action)
|
page.action.Pane.Size(width, sizes.action)
|
||||||
page.source.Size(width, sizes.source)
|
page.source.Pane.Size(width, sizes.source)
|
||||||
|
|
||||||
height -= page.source.offsetHeight+page.action.offsetHeight
|
height -= page.source.offsetHeight+page.action.offsetHeight
|
||||||
page.target.Size(width, height)
|
page.target.Pane.Size(width, height)
|
||||||
kit.History.add("lay", sizes)
|
kit.History.add("lay", sizes)
|
||||||
},
|
},
|
||||||
oncontrol: function(event, target, action) {
|
oncontrol: function(event, target, action) {
|
||||||
@ -37,7 +38,7 @@ var page = Page({
|
|||||||
if (event.ctrlKey) {
|
if (event.ctrlKey) {
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case "0":
|
case "0":
|
||||||
page.source.Select()
|
page.source.Pane.Select()
|
||||||
break
|
break
|
||||||
case "1":
|
case "1":
|
||||||
case "2":
|
case "2":
|
||||||
@ -48,13 +49,13 @@ var page = Page({
|
|||||||
case "7":
|
case "7":
|
||||||
case "8":
|
case "8":
|
||||||
case "9":
|
case "9":
|
||||||
page.action.Select(parseInt(event.key))
|
page.action.Pane.Select(parseInt(event.key))
|
||||||
break
|
break
|
||||||
case "n":
|
case "n":
|
||||||
page.ocean.Show()
|
page.ocean.Pane.Show()
|
||||||
break
|
break
|
||||||
case "m":
|
case "m":
|
||||||
page.steam.Show()
|
page.steam.Pane.Show()
|
||||||
break
|
break
|
||||||
case "i":
|
case "i":
|
||||||
page.storm.Next()
|
page.storm.Next()
|
||||||
@ -70,102 +71,16 @@ var page = Page({
|
|||||||
} else {
|
} else {
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
case "Escape":
|
case "Escape":
|
||||||
page.dialog && page.dialog.Show()
|
page.dialog && page.dialog.Pane.Show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
initLogin: function(page, pane, form, output) {
|
initOcean: function(page, field, option, 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) {
|
|
||||||
var table = kit.AppendChild(output, "table")
|
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) {
|
{input: ["name", function(event) {
|
||||||
page.oninput(event, function(event) {
|
page.oninput(event, function(event) {
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
@ -181,10 +96,10 @@ var page = Page({
|
|||||||
tr && tr.childNodes[0].click()
|
tr && tr.childNodes[0].click()
|
||||||
return true
|
return true
|
||||||
case "9":
|
case "9":
|
||||||
pane.Action["全选"](event)
|
field.Pane.Action["全选"](event)
|
||||||
return true
|
return true
|
||||||
case "0":
|
case "0":
|
||||||
pane.Action["清空"](event)
|
field.Pane.Action["清空"](event)
|
||||||
return true
|
return true
|
||||||
case "-":
|
case "-":
|
||||||
var pre = ui.list.querySelector("pre")
|
var pre = ui.list.querySelector("pre")
|
||||||
@ -209,239 +124,235 @@ var page = Page({
|
|||||||
cmd.push(item.innerText)
|
cmd.push(item.innerText)
|
||||||
})
|
})
|
||||||
if (cmd.length == 3) {
|
if (cmd.length == 3) {
|
||||||
alert("请添加组员")
|
kit.alert("请添加组员")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
form.Run(cmd, function(msg) {
|
field.Pane.Run(cmd, function(msg) {
|
||||||
page.river.Show()
|
page.river.Pane.Show()
|
||||||
pane.Show()
|
field.Pane.Show()
|
||||||
})
|
})
|
||||||
}]}, {name: "list", view: ["list"]},
|
}]}, {name: "list", view: ["list"]},
|
||||||
]}])
|
]}])
|
||||||
|
|
||||||
pane.Show = function() {
|
return {
|
||||||
pane.ShowDialog() && (table.innerHTML = "", ui.list.innerHTML = "", ui.name.value = "good", ui.name.focus(), form.Run([], function(msg) {
|
Show: function() {
|
||||||
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, row, i, tr, event) {
|
this.ShowDialog() && (table.innerHTML = "", ui.list.innerHTML = "", ui.name.value = "good", ui.name.focus(), this.Run([], function(msg) {
|
||||||
tr.className = "hidden"
|
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, row, i, tr, event) {
|
||||||
var uis = kit.AppendChild(ui.list, [{text: [row.key], click: function(event) {
|
tr.className = "hidden"
|
||||||
tr.className = "normal", uis.last.parentNode.removeChild(uis.last)
|
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) {
|
initRiver: function(page, field, option, output) {
|
||||||
pane.Show = function() {
|
return {
|
||||||
output.Update([], "text", ["name", "count"], "key", ctx.Search("river")||true, function(line, index, event) {})
|
Show: function() {
|
||||||
}
|
this.Update([], "text", ["name", "count"], "key", ctx.Search("river")||true)
|
||||||
pane.Action = {
|
|
||||||
"创建": function(event) {
|
|
||||||
page.ocean.Show()
|
|
||||||
},
|
},
|
||||||
|
Action: {
|
||||||
|
"创建": function(event) {
|
||||||
|
page.ocean.Pane.Show()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Button: ["创建"],
|
||||||
}
|
}
|
||||||
return {"button": ["创建"], "action": pane.Action}
|
|
||||||
},
|
},
|
||||||
initTarget: function(page, pane, form, output) {
|
initTarget: function(page, field, option, output) {
|
||||||
output.DisplayUser = true
|
|
||||||
var river = ""
|
var river = ""
|
||||||
pane.Listen = {
|
var which = {}
|
||||||
river: function(value, old) {
|
output.DisplayUser = true
|
||||||
river = value, pane.Show()
|
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) {
|
initSource: function(page, field, option, output) {
|
||||||
var ui = kit.AppendChild(pane, [{"view": ["input", "textarea"], "data": {"onkeyup": function(event){
|
var ui = kit.AppendChild(field, [{"view": ["input", "textarea"], "data": {"onkeyup": function(event){
|
||||||
kit.isSpace(event.key) && pane.which.set(event.target.value)
|
page.oninput(event), kit.isSpace(event.key) && field.Pane.which.set(event.target.value)
|
||||||
event.key == "Enter" && !event.shiftKey && page.target.Send("text", event.target.value, pane.Clear)
|
event.key == "Enter" && !event.shiftKey && page.target.Pane.Send("text", event.target.value, field.Pane.Clear)
|
||||||
}, "onkeydown": function(event) {
|
}, "onkeydown": function(event) {
|
||||||
event.key == "Enter" && !event.shiftKey && event.preventDefault()
|
event.key == "Enter" && !event.shiftKey && event.preventDefault()
|
||||||
}}}])
|
}}}])
|
||||||
|
|
||||||
pane.Size = function(width, height) {
|
return {
|
||||||
pane.style.display = (width<=0 || height<=0)? "none": "block"
|
Size: function(width, height) {
|
||||||
pane.style.width = width+"px"
|
field.style.display = (width<=0 || height<=0)? "none": "block"
|
||||||
pane.style.height = height+"px"
|
field.style.width = width+"px"
|
||||||
ui.first.style.width = (width-7)+"px"
|
field.style.height = height+"px"
|
||||||
ui.first.style.height = (height-7)+"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) {
|
initAction: function(page, field, option, output) {
|
||||||
var cache = {}
|
|
||||||
var river = "", storm = 0, input = "", share = ""
|
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
|
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 table = kit.AppendChild(output, "table")
|
||||||
var device = kit.AppendChild(pane, [{"view": ["device", "table"]}]).last
|
var device = kit.AppendChild(field, [{"view": ["device", "table"]}]).last
|
||||||
var ui = kit.AppendChild(pane, [{view: ["create steam"], list: [
|
var ui = kit.AppendChild(field, [{view: ["create steam"], list: [
|
||||||
{input: ["name", function(event) {
|
{input: ["name", function(event) {
|
||||||
page.oninput(event, function(event) {
|
page.oninput(event, function(event) {
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
@ -465,10 +376,10 @@ var page = Page({
|
|||||||
tr && tr.childNodes[0].click()
|
tr && tr.childNodes[0].click()
|
||||||
return true
|
return true
|
||||||
case "9":
|
case "9":
|
||||||
pane.Action["全选"](event)
|
field.Pane.Action["全选"](event)
|
||||||
return true
|
return true
|
||||||
case "0":
|
case "0":
|
||||||
pane.Action["清空"](event)
|
field.Pane.Action["清空"](event)
|
||||||
return true
|
return true
|
||||||
case "-":
|
case "-":
|
||||||
var tr = ui.list.querySelectorAll("tr")[1]
|
var tr = ui.list.querySelectorAll("tr")[1]
|
||||||
@ -496,130 +407,125 @@ var page = Page({
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (cmd.length == 4) {
|
if (cmd.length == 4) {
|
||||||
alert("请添加命令")
|
kit.alert("请添加命令")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
form.Run(cmd, function(msg) {
|
field.Pane.Run(cmd, function(msg) {
|
||||||
pane.Show()
|
field.Pane.Show()
|
||||||
page.storm.Show(ui.name.value)
|
page.storm.Pane.Show(ui.name.value)
|
||||||
})
|
})
|
||||||
}]}, {name: "list", view: ["list", "table"]},
|
}]}, {name: "list", view: ["list", "table"]},
|
||||||
]}])
|
]}])
|
||||||
|
|
||||||
pane.Show = function() {
|
return {
|
||||||
pane.ShowDialog() && (table.innerHTML = "", ui.name.value = "nice", form.Run([river], function(msg) {
|
Listen: {
|
||||||
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, pod, i, tr, event) {
|
river: function(value, old) {
|
||||||
var old = table.querySelector("tr.select")
|
river = value
|
||||||
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: [
|
Show: function() {
|
||||||
{text: [com.key, "td"]}, {text: [com.index, "td"]}, {text: [com.name, "td"]}, {text: [com.help, "td"]},
|
this.ShowDialog() && (table.innerHTML = "", ui.name.value = "nice", this.Run([river], function(msg) {
|
||||||
], dataset: {pod: pod["user.route"], group: com.key, index: com.index, name: com.name}, click: function(event) {
|
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, pod, i, tr, event) {
|
||||||
last.parentNode.removeChild(last)
|
var old = table.querySelector("tr.select")
|
||||||
}}]).last
|
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()
|
||||||
table.querySelector("td").click()
|
ui.name.focus()
|
||||||
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) {
|
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)
|
page.onlayout(null, page.conf.layout)
|
||||||
kit.isMobile && page.action.Action["最宽"]()
|
page.action.Pane.Layout(ctx.Search("layout")? ctx.Search("layout"): kit.isMobile? "最宽": "最大")
|
||||||
page.action.Action["最大"]()
|
page.footer.Pane.Order({"site": "", "ip": "", "text": "", ":":""}, kit.isMobile? ["site", "ip", "text"]: ["ip", "text", ":"], function(event, item, value) {
|
||||||
ctx.Search("layout") && page.action.Action[ctx.Search("layout")]()
|
})
|
||||||
|
page.header.Pane.Order({"logout": "logout", "user": ""}, ["logout", "user"], function(event, item, value) {
|
||||||
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) {
|
|
||||||
switch (item) {
|
switch (item) {
|
||||||
case "title":
|
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
|
break
|
||||||
case "user":
|
case "user":
|
||||||
var name = page.prompt("new name")
|
var name = kit.prompt("new name")
|
||||||
name && page.login.Run(["rename", name], function(msg) {
|
name && page.login.Pane.Run(["rename", name], function(msg) {
|
||||||
page.header.State("user", name)
|
page.header.Pane.State("user", name)
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case "logout":
|
case "logout":
|
||||||
page.confirm("logout?") && page.login.Exit()
|
kit.confirm("logout?") && page.login.Pane.Exit()
|
||||||
break
|
break
|
||||||
default:
|
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)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -95,7 +95,13 @@ ctx = context = {
|
|||||||
|
|
||||||
var as = []
|
var as = []
|
||||||
for (var k in args) {
|
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("&");
|
var arg = as.join("&");
|
||||||
return location.origin+location.pathname+"?"+arg
|
return location.origin+location.pathname+"?"+arg
|
||||||
|
@ -66,6 +66,10 @@ fieldset div.output table td {
|
|||||||
word-break:break-all;
|
word-break:break-all;
|
||||||
min-width:40px;
|
min-width:40px;
|
||||||
}
|
}
|
||||||
|
fieldset div.output table td {
|
||||||
|
word-break:keep-all;
|
||||||
|
min-width:40px;
|
||||||
|
}
|
||||||
|
|
||||||
fieldset.toast {
|
fieldset.toast {
|
||||||
background-color:#ffffff00;
|
background-color:#ffffff00;
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
function Page(page) {
|
function Page(page) {
|
||||||
var id = 1
|
var id = 1
|
||||||
var conf = {}
|
var conf = {}, conf_cb = {}
|
||||||
var conf_cb = {}
|
|
||||||
var sync = {}
|
var sync = {}
|
||||||
page.__proto__ = {
|
page.__proto__ = {
|
||||||
|
__proto__: kit,
|
||||||
ID: function() {
|
ID: function() {
|
||||||
return id++
|
return id++
|
||||||
},
|
},
|
||||||
Conf: function(key, value, cb) {
|
Conf: function(key, value, cb) {
|
||||||
|
if (key == undefined) {
|
||||||
|
return conf
|
||||||
|
}
|
||||||
|
if (cb != undefined) {
|
||||||
|
conf_cb[key] = cb
|
||||||
|
}
|
||||||
if (value != undefined) {
|
if (value != undefined) {
|
||||||
var old = conf[key]
|
var old = conf[key]
|
||||||
conf[key] = value
|
conf[key] = value
|
||||||
conf_cb[key] && conf_cb[key](value, old)
|
conf_cb[key] && conf_cb[key](value, old)
|
||||||
}
|
}
|
||||||
if (cb != undefined) {
|
return conf[key]
|
||||||
conf_cb[key] = cb
|
|
||||||
}
|
|
||||||
if (key != undefined) {
|
|
||||||
return conf[key]
|
|
||||||
}
|
|
||||||
return conf
|
|
||||||
},
|
},
|
||||||
Sync: function(m) {
|
Sync: function(m) {
|
||||||
var meta = m, data = "", list = []
|
var meta = m, data = "", list = []
|
||||||
@ -38,6 +38,9 @@ function Page(page) {
|
|||||||
return data
|
return data
|
||||||
},
|
},
|
||||||
set: function(value, force) {
|
set: function(value, force) {
|
||||||
|
if (value == undefined) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (value == data && !force) {
|
if (value == data && !force) {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
@ -51,32 +54,30 @@ function Page(page) {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
View: function(parent, type, line, key, cb) {
|
View: function(parent, type, line, key, cb) {
|
||||||
var ui = {}
|
var text = line, list = [], ui = {}
|
||||||
var result = []
|
|
||||||
var text = line
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "icon":
|
case "icon":
|
||||||
result = [{view: ["item", "div"], list: [{img: [line[key[0]], function(event) {
|
list.push({img: [line[key[0]], function(event) {
|
||||||
event.target.scrollIntoView()
|
// event.target.scrollIntoView()
|
||||||
}]}]}]
|
}]})
|
||||||
break
|
break
|
||||||
|
|
||||||
case "text":
|
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
|
break
|
||||||
|
|
||||||
case "code":
|
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
|
break
|
||||||
|
|
||||||
case "table":
|
case "table":
|
||||||
result = [{view: [""], list: [
|
list.push({type: "table", list: JSON.parse(line.text || "[]").map(function(item, index) {
|
||||||
{view: ["", "table"], list: JSON.parse(line.text || "[]").map(function(item, index) {
|
return {type: "tr", list: item.map(function(value) {
|
||||||
return {type: "tr", list: item.map(function(value) {
|
return {text: [value, index == 0? "th": "td"]}
|
||||||
return {text: [value, index == 0? "th": "td"]}
|
})}
|
||||||
})}
|
})})
|
||||||
})},
|
|
||||||
]}]
|
|
||||||
break
|
break
|
||||||
|
|
||||||
case "field":
|
case "field":
|
||||||
@ -84,37 +85,65 @@ function Page(page) {
|
|||||||
|
|
||||||
case "plugin":
|
case "plugin":
|
||||||
var id = "plugin"+page.ID()
|
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"]},
|
{text: [text.name+"("+text.help+")", "legend"]},
|
||||||
{name: "option", view: ["option", "form"], data: {Run: cb}, list: [{type: "input", style: {"display": "none"}}]},
|
{view: ["option", "form", "", "option"], list: [{type: "input", style: {"display": "none"}}]},
|
||||||
{name: "output", view: ["output", "div"]},
|
{view: ["output", "div", "", "output"]},
|
||||||
{script: "Plugin("+id+","+JSON.stringify(text)+","+"[\""+(text.args||[]).join("\",\"")+"\"]"+","+(text.init||"")+")"},
|
{script: ""+id+".Script="+(text.init||"{}")},
|
||||||
]}]
|
]})
|
||||||
break
|
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)
|
ui.field && (ui.field.Meta = text)
|
||||||
return ui
|
return ui
|
||||||
},
|
},
|
||||||
alert: function(text) {
|
Include: function(src, cb) {
|
||||||
alert(text)
|
kit.AppendChild(document.body, [{include: [src[0], function(event) {
|
||||||
|
src.length == 1? cb(event): page.Include(src.slice(1), cb)
|
||||||
|
}]}])
|
||||||
},
|
},
|
||||||
prompt: function(text) {
|
ontoast: function(text, title, duration) {
|
||||||
return prompt(text)
|
var args = typeof text == "object"? text: {text: text, title: title, duration: duration}
|
||||||
},
|
var toast = kit.ModifyView("fieldset.toast", {
|
||||||
confirm: function(text) {
|
display: "block", dialog: [args.width||200, args.height||40], padding: 10,
|
||||||
return confirm(text)
|
})
|
||||||
},
|
|
||||||
reload: function() {
|
var list = [{text: [args.text||""]}]
|
||||||
location.reload()
|
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) {
|
oninput: function(event, local) {
|
||||||
var target = event.target
|
var target = event.target
|
||||||
@ -123,6 +152,7 @@ function Page(page) {
|
|||||||
if (event.ctrlKey) {
|
if (event.ctrlKey) {
|
||||||
if (typeof local == "function" && local(event)) {
|
if (typeof local == "function" && local(event)) {
|
||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
|
event.preventDefault()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
@ -168,212 +198,166 @@ function Page(page) {
|
|||||||
if (kit.HitText(target, "jk")) {
|
if (kit.HitText(target, "jk")) {
|
||||||
kit.DelText(target, target.selectionStart-2, 2)
|
kit.DelText(target, target.selectionStart-2, 2)
|
||||||
target.blur()
|
target.blur()
|
||||||
|
event.stopPropagation()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
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) {
|
onscroll: function(event, target, action) {
|
||||||
switch (action) {
|
switch (event.key) {
|
||||||
case "scroll":
|
case "h":
|
||||||
if (event.target == document.body) {
|
if (event.ctrlKey) {
|
||||||
kit.ScrollPage(event, page.conf)
|
target.scrollBy(-conf.scroll_x*10, 0)
|
||||||
|
} else {
|
||||||
|
target.scrollBy(-conf.scroll_x, 0)
|
||||||
}
|
}
|
||||||
break
|
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) {
|
initHeader: function(page, field, option, output) {
|
||||||
var state = {}, list = [], cb = function(event, item, value) {
|
var state = {}, list = [], cb = function(event, item, value) {}
|
||||||
|
field.onclick = function(event) {
|
||||||
|
page.pane.scrollTo(0,0)
|
||||||
}
|
}
|
||||||
pane.Order = function(value, order, cbs) {
|
return {
|
||||||
state = value, list = order, cb = cbs || cb, pane.Show()
|
Order: function(value, order, cbs) {
|
||||||
}
|
state = value, list = order, cb = cbs || cb, this.Show()
|
||||||
pane.Show = function() {
|
},
|
||||||
output.innerHTML = "", kit.AppendChild(output, [
|
Show: function() {
|
||||||
{"view": ["title", "div", "shycontext"], click: function(event) {
|
output.innerHTML = "", kit.AppendChild(output, [
|
||||||
cb(event, "title", "shycontext")
|
{"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])
|
{"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()
|
State: function(name, value) {
|
||||||
}
|
|
||||||
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", "<a href='mailto:shylinux@163.com'>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) {
|
|
||||||
if (value != undefined) {
|
if (value != undefined) {
|
||||||
var old = conf[key]
|
state[name] = value, this.Show()
|
||||||
conf[key] = value
|
|
||||||
conf_cb[key] && conf_cb[key](value, old)
|
|
||||||
}
|
}
|
||||||
if (cb != undefined) {
|
if (name != undefined) {
|
||||||
conf_cb[key] = cb
|
return state[name]
|
||||||
}
|
}
|
||||||
if (key != undefined) {
|
return state
|
||||||
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])
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
|
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", "<a href='mailto:shylinux@163.com'>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() {
|
window.onload = function() {
|
||||||
|
document.querySelectorAll("body>fieldset").forEach(function(field) {
|
||||||
|
page.Pane(page, field)
|
||||||
|
})
|
||||||
page.init(page)
|
page.init(page)
|
||||||
|
|
||||||
window.onresize = function(event) {
|
window.onresize = function(event) {
|
||||||
page.onlayout && page.onlayout(event)
|
page.onlayout && page.onlayout(event)
|
||||||
}
|
}
|
||||||
document.body.onkeydown = function(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) {
|
document.body.onkeyup = function(event) {
|
||||||
page.oncontrol && page.oncontrol(event, document.body, "control")
|
page.oncontrol && page.oncontrol(event, document.body, "control")
|
||||||
@ -381,74 +365,170 @@ function Page(page) {
|
|||||||
}
|
}
|
||||||
return 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 option = field.querySelector("form.option")
|
||||||
var output = field.querySelector("div.output")
|
var output = field.querySelector("div.output")
|
||||||
|
|
||||||
var exports = JSON.parse(tool.exports||'["",""]')
|
var count = 0
|
||||||
var display = JSON.parse(tool.display||'{}')
|
var wait = false
|
||||||
option.Runs = function(event) {
|
var plugin = field.Script || {}; plugin.__proto__ = {
|
||||||
option.Run(event, kit.Selector(option, ".args", function(item, index) {
|
__proto__: pane,
|
||||||
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)
|
|
||||||
},
|
|
||||||
Append: function(item, name) {
|
Append: function(item, name) {
|
||||||
var index = total
|
|
||||||
total += 1
|
|
||||||
name = name || item.name
|
name = name || item.name
|
||||||
|
|
||||||
item.onfocus = function(event) {
|
item.onfocus = function(event) {
|
||||||
page.plugin = plugin
|
page.pane = pane.Field, page.plugin = field, page.input = event.target
|
||||||
page.input = event.target
|
|
||||||
page.footer.State(".", field.id)
|
|
||||||
page.footer.State(":", index)
|
|
||||||
}
|
}
|
||||||
item.onkeyup = function(event) {
|
item.onkeyup = function(event) {
|
||||||
page.oninput(event, function(event) {
|
page.oninput(event, function(event) {
|
||||||
switch (event.key) {
|
switch (event.key) {
|
||||||
|
case "p":
|
||||||
|
action.Back()
|
||||||
|
break
|
||||||
case "i":
|
case "i":
|
||||||
var next = field.nextSibling;
|
var next = field.nextSibling;
|
||||||
next && next.Select()
|
next && next.Plugin.Select()
|
||||||
break
|
break
|
||||||
case "o":
|
case "o":
|
||||||
var prev = field.previousSibling;
|
var prev = field.previousSibling;
|
||||||
prev && prev.Select()
|
prev && prev.Plugin.Select()
|
||||||
break
|
break
|
||||||
case "c":
|
case "c":
|
||||||
output.innerHTML = ""
|
output.innerHTML = ""
|
||||||
@ -456,23 +536,24 @@ function Plugin(field, tool, args, plugin) {
|
|||||||
case "r":
|
case "r":
|
||||||
output.innerHTML = ""
|
output.innerHTML = ""
|
||||||
case "j":
|
case "j":
|
||||||
run(event)
|
plugin.Runs(event)
|
||||||
break
|
break
|
||||||
case "l":
|
case "l":
|
||||||
page.action.scrollTo(0, option.parentNode.offsetTop)
|
page.action.scrollTo(0, field.offsetTop)
|
||||||
break
|
|
||||||
case "m":
|
|
||||||
plugin.Clone()
|
|
||||||
break
|
break
|
||||||
case "b":
|
case "b":
|
||||||
plugin.Append(item, "args"+total).focus()
|
plugin.Append(item).focus()
|
||||||
|
break
|
||||||
|
case "m":
|
||||||
|
plugin.Clone().Plugin.Select()
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
event.stopPropagation()
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
event.key == "Enter" && plugin.Check(event, index)
|
event.key == "Enter" && plugin.Check(action)
|
||||||
}
|
}
|
||||||
|
|
||||||
var input = {type: "input", name: name, data: item}
|
var input = {type: "input", name: name, data: item}
|
||||||
@ -480,19 +561,16 @@ function Plugin(field, tool, args, plugin) {
|
|||||||
case "button":
|
case "button":
|
||||||
item.onclick = function(event) {
|
item.onclick = function(event) {
|
||||||
action[item.click]? action[item.click](event, item, option, field):
|
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
|
break
|
||||||
|
|
||||||
case "select":
|
case "select":
|
||||||
input = {type: "select", name: name, data: {className: "args", onchange: function(event) {
|
input.type = "select", input.list = item.values.map(function(value) {
|
||||||
plugin.Check(event, index)
|
|
||||||
|
|
||||||
}}, list: item.values.map(function(value) {
|
|
||||||
return {type: "option", value: value, inner: value}
|
return {type: "option", value: value, inner: value}
|
||||||
})}
|
}), item.onchange = function(event) {
|
||||||
args && count < args.length && (item.value = args[count++])
|
plugin.Check(action)
|
||||||
break
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
args && count < args.length && (item.value = args[count++]||item.value||"")
|
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 ui = kit.AppendChild(option, [{view: [item.view||""], list: [{type: "label", inner: item.label||""}, input]}])
|
||||||
var action = ui[name] || {}
|
var action = ui[name] || {}
|
||||||
|
|
||||||
page.plugin = field
|
action.History = [""], action.Goto = function(value) {
|
||||||
page.input = action
|
action.History.push(action.value = value)
|
||||||
index == 0 && action && action.focus && action.focus()
|
plugin.Check(action)
|
||||||
|
|
||||||
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())
|
|
||||||
}
|
|
||||||
return value
|
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)
|
page.Sync(imports).change(action.Goto)
|
||||||
})
|
})
|
||||||
item.imports && typeof item.imports == "string" && page.Sync(item.imports).change(action.Goto)
|
|
||||||
return action
|
return action
|
||||||
},
|
},
|
||||||
Select: function() {
|
Select: function() {
|
||||||
page.plugin = field
|
option.querySelectorAll("input")[1].focus()
|
||||||
page.footer.State(".", field.id)
|
|
||||||
},
|
},
|
||||||
|
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 || "[]")
|
var meta = field.Meta
|
||||||
inputs.map(function(item, index, inputs) {
|
var args = meta.args || []
|
||||||
plugin.Append(item)
|
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)
|
plugin.init(page, pane, field, option, output)
|
||||||
page[field.id] = plugin
|
return page[field.id] = pane[field.id] = plugin.Field = field, field.Plugin = plugin
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{
|
{init: function(page, pane, field, option, output) {
|
||||||
init: function(page, pane, plug, form, output) {
|
this.Runs = function(event) {
|
||||||
form.Runs = function(event) {
|
var value = option.content.value
|
||||||
var url = "/chat/?componet_group=index&componet_name=login&cmds=qrcode&cmds="+form.content.value
|
var url = page.login.Pane.Share({cmds: ["qrcode", value]})
|
||||||
output.innerHTML = "", kit.AppendChild(output, [{img: [url]}])
|
kit.AppendChilds(output, [{img: [url]}])
|
||||||
event.ctrlKey? page.target.Send("icon", url): form.Run(event, [form.content.value])
|
event.ctrlKey && page.target.Pane.Send("icon", url)
|
||||||
}
|
event.shiftKey && page.target.Pane.Send("field", this.Format(value))
|
||||||
},
|
}
|
||||||
}
|
}}
|
||||||
|
@ -29,54 +29,6 @@ kit = toolkit = {
|
|||||||
return args
|
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) {
|
ModifyView: function(which, args) {
|
||||||
var height = document.body.clientHeight-4
|
var height = document.body.clientHeight-4
|
||||||
var width = document.body.clientWidth-4
|
var width = document.body.clientWidth-4
|
||||||
@ -164,6 +116,7 @@ kit = toolkit = {
|
|||||||
//
|
//
|
||||||
// dataset click
|
// dataset click
|
||||||
// button input label img
|
// button input label img
|
||||||
|
// select
|
||||||
//
|
//
|
||||||
// 树状结构: tree fork leaf
|
// 树状结构: tree fork leaf
|
||||||
// 普通视图: view text code
|
// 普通视图: view text code
|
||||||
@ -190,6 +143,9 @@ kit = toolkit = {
|
|||||||
if (child.inner) {
|
if (child.inner) {
|
||||||
child.data["innerHTML"] = child.inner
|
child.data["innerHTML"] = child.inner
|
||||||
}
|
}
|
||||||
|
if (child.className) {
|
||||||
|
child.data["className"] = child.className
|
||||||
|
}
|
||||||
if (typeof(child.style) == "object") {
|
if (typeof(child.style) == "object") {
|
||||||
var str = []
|
var str = []
|
||||||
for (var k in child.style) {
|
for (var k in child.style) {
|
||||||
@ -213,6 +169,13 @@ kit = toolkit = {
|
|||||||
child.data["innerText"] = child.button[0]
|
child.data["innerText"] = child.button[0]
|
||||||
child.name = child.name || 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) {
|
} else if (child.input) {
|
||||||
child.type = "input"
|
child.type = "input"
|
||||||
child.data["onkeyup"] = child.input[1]
|
child.data["onkeyup"] = child.input[1]
|
||||||
@ -272,14 +235,14 @@ kit = toolkit = {
|
|||||||
child.code.length > 2 && (child.data["className"] = child.code[2])
|
child.code.length > 2 && (child.data["className"] = child.code[2])
|
||||||
|
|
||||||
} else if (child.script) {
|
} else if (child.script) {
|
||||||
child.data.innerHTML = child.script
|
|
||||||
child.type = "script"
|
child.type = "script"
|
||||||
|
child.data.innerHTML = child.script
|
||||||
|
|
||||||
} else if (child.include) {
|
} else if (child.include) {
|
||||||
|
child.type = "script"
|
||||||
child.data["src"] = child.include[0]
|
child.data["src"] = child.include[0]
|
||||||
child.data["type"] = "text/javascript"
|
child.data["type"] = "text/javascript"
|
||||||
child.include.length > 1 && (child.data["onload"] = child.include[1])
|
child.include.length > 1 && (child.data["onload"] = child.include[1])
|
||||||
child.type = "script"
|
|
||||||
|
|
||||||
} else if (child.require) {
|
} else if (child.require) {
|
||||||
child.data["href"] = child.require[0]
|
child.data["href"] = child.require[0]
|
||||||
@ -315,6 +278,9 @@ kit = toolkit = {
|
|||||||
})
|
})
|
||||||
return subs
|
return subs
|
||||||
},
|
},
|
||||||
|
AppendChilds: function(parent, children, subs) {
|
||||||
|
return parent.innerHTML = "", this.AppendChild(parent, children, subs)
|
||||||
|
},
|
||||||
InsertChild: function (parent, position, element, children) {
|
InsertChild: function (parent, position, element, children) {
|
||||||
var elm = this.CreateNode(element)
|
var elm = this.CreateNode(element)
|
||||||
this.AppendChild(elm, children)
|
this.AppendChild(elm, children)
|
||||||
@ -332,6 +298,7 @@ kit = toolkit = {
|
|||||||
})
|
})
|
||||||
data.forEach(function(row, i) {
|
data.forEach(function(row, i) {
|
||||||
var tr = kit.AppendChild(table, "tr", {className: "normal"})
|
var tr = kit.AppendChild(table, "tr", {className: "normal"})
|
||||||
|
tr.Meta = row
|
||||||
fields.forEach(function(key, j) {
|
fields.forEach(function(key, j) {
|
||||||
var td = kit.AppendChild(tr, "td", row[key])
|
var td = kit.AppendChild(tr, "td", row[key])
|
||||||
if (typeof cb == "function") {
|
if (typeof cb == "function") {
|
||||||
@ -403,14 +370,133 @@ kit = toolkit = {
|
|||||||
kit.RangeTable(table, i, dataset["sort_asc"] == "1")
|
kit.RangeTable(table, i, dataset["sort_asc"] == "1")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (field && head.childNodes[i].innerText.startsWith(field)) {
|
var name = head.childNodes[i].innerText
|
||||||
typeof cb == "function" && cb(event, item.innerText)
|
if (name.startsWith(field)) {
|
||||||
|
typeof cb == "function" && cb(event, item.innerText, name,item.parentNode.Meta)
|
||||||
}
|
}
|
||||||
kit.CopyText()
|
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) {
|
OrderForm: function(page, field, option, append, result) {
|
||||||
if (!option) {return}
|
if (!option) {return}
|
||||||
option.ondaemon = option.ondaemon || function(msg) {
|
option.ondaemon = option.ondaemon || function(msg) {
|
||||||
@ -477,106 +563,17 @@ kit = toolkit = {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
OrderCode: function(code) {
|
|
||||||
if (!code) {return}
|
|
||||||
|
|
||||||
var kit = this
|
List: function(obj, cb) {
|
||||||
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) {
|
|
||||||
var list = []
|
var list = []
|
||||||
obj.querySelectorAll(item).forEach(function(item, index) {
|
for (var i = 0; i < obj.length; i++) {
|
||||||
if (typeof cb == "function") {
|
list.push(typeof cb == "function"? cb(obj[i]): obj[i])
|
||||||
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
|
return list
|
||||||
},
|
},
|
||||||
|
Format: function(objs) {
|
||||||
|
return json.stringify(objs)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function right(arg) {
|
function right(arg) {
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
{{range $index, $lib := option . "scripts"}}
|
{{range $index, $lib := option . "scripts"}}
|
||||||
<script src="/static/librarys/{{$lib}}"></script>
|
<script src="/static/librarys/{{$lib}}"></script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=LTkHoAidsaDWfEEIwY7u4Lx3Vuo05Iq6"></script>
|
||||||
</body>
|
</body>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user