forked from x/ContextOS
opt js
This commit is contained in:
parent
f92e2a0dd4
commit
1e226b5167
@ -1,6 +1,6 @@
|
||||
#! /bin/bash
|
||||
|
||||
export ctx_dev=${ctx_dev:="-"}
|
||||
export ctx_dev=${ctx_dev:="https://shylinux.com"}
|
||||
export ctx_root="/usr/local/context"
|
||||
export ctx_home=~/context
|
||||
export ctx_bin="bench"
|
||||
|
@ -149,22 +149,31 @@ set keywordprg=man\ -a
|
||||
set splitbelow
|
||||
set splitright
|
||||
|
||||
let javaScript_fold=1
|
||||
function! Config(type)
|
||||
if a:type == "go"
|
||||
set foldmethod=syntax
|
||||
set foldnestmax=3
|
||||
elseif a:type == "shy"
|
||||
set filetype=shy
|
||||
set commentstring=#%s
|
||||
elseif a:type == "json"
|
||||
set foldmethod=syntax
|
||||
elseif a:type == "tmpl"
|
||||
set foldmethod=indent
|
||||
elseif a:type == "conf"
|
||||
set filetype=nginx
|
||||
elseif a:type == "json"
|
||||
set foldmethod=syntax
|
||||
elseif a:type == "xml"
|
||||
set filetype=xml
|
||||
elseif a:type == "css"
|
||||
set filetype=css
|
||||
set foldmethod=marker
|
||||
set foldmarker={,}
|
||||
elseif a:type == "txt"
|
||||
set noexpandtab
|
||||
elseif a:type == "js"
|
||||
set foldmethod=marker
|
||||
set foldmarker={,}
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@ -172,12 +181,14 @@ autocmd BufReadPost * normal `"
|
||||
|
||||
autocmd BufNewFile,BufReadPost *.go call Config("go")
|
||||
autocmd BufNewFile,BufReadPost *.shy call Config("shy")
|
||||
autocmd BufNewFile,BufReadPost *.tmpl call Config("tmpl")
|
||||
autocmd BufNewFile,BufReadPost *.conf call Config("conf")
|
||||
autocmd BufNewFile,BufReadPost *.json call Config("json")
|
||||
|
||||
autocmd BufNewFile,BufReadPost *.wxml call Config("xml")
|
||||
autocmd BufNewFile,BufReadPost *.wxss call Config("css")
|
||||
autocmd BufNewFile,BufReadPost *.txt call Config("txt")
|
||||
autocmd BufNewFile,BufReadPost *.js call Config("js")
|
||||
|
||||
command! RR wa | source ~/.vimrc |e
|
||||
command! SS mksession! etc/session.vim
|
||||
|
@ -1,5 +1,5 @@
|
||||
~mdb
|
||||
# config save note.json note
|
||||
~code
|
||||
config save tmp/flash.json flash
|
||||
~aaa
|
||||
config save auth.json auth
|
||||
config save tmp/auth.json auth
|
||||
|
||||
|
10
etc/init.shy
10
etc/init.shy
@ -1,8 +1,8 @@
|
||||
# ~aaa
|
||||
# config load auth.json auth
|
||||
# ~mdb
|
||||
# config load note.json note
|
||||
#
|
||||
~aaa
|
||||
config load tmp/auth.json auth
|
||||
~code
|
||||
config load tmp/flash.json flash
|
||||
|
||||
source common.shy
|
||||
~ssh
|
||||
remote auto
|
||||
|
@ -124,7 +124,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
"auth": &ctx.Config{Name: "auth", Value: map[string]interface{}{}, Help: "散列"},
|
||||
"auth_expire": &ctx.Config{Name: "auth_expire", Value: "10m", Help: "权限超时"},
|
||||
"auth_type": &ctx.Config{Name: "auth_type", Value: map[string]interface{}{
|
||||
"unique": map[string]interface{}{"session": true, "bench": true},
|
||||
"unique": map[string]interface{}{"session": true, "bench": true, "relay": true},
|
||||
"public": map[string]interface{}{"userrole": true, "username": true, "cert": true},
|
||||
"single": map[string]interface{}{"password": true, "token": true, "uuid": true, "ppid": true},
|
||||
"secrete": map[string]interface{}{"password": true, "token": true, "uuid": true, "ppid": true},
|
||||
@ -424,18 +424,20 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
componets, commands := []string{}, []string{}
|
||||
for i := 0; i < len(arg); i++ { // 解析参数
|
||||
if arg[i] == "command" {
|
||||
for i := i + 1; i < len(arg); i++ {
|
||||
for i = i + 1; i < len(arg); i++ {
|
||||
if arg[i] == "componet" {
|
||||
break
|
||||
}
|
||||
commands = append(commands, arg[i])
|
||||
}
|
||||
continue
|
||||
}
|
||||
if arg[i] == "componet" {
|
||||
continue
|
||||
}
|
||||
componets = append(componets, arg[i])
|
||||
}
|
||||
m.Log("info", "componet: %v, command: %v", componets, commands)
|
||||
|
||||
if len(componets) == 0 { // 查看组件
|
||||
m.Cmdy("aaa.auth", "ship", "userrole", role, "componet")
|
||||
@ -654,6 +656,33 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
return
|
||||
}},
|
||||
|
||||
"relay": &ctx.Command{Name: "relay check hash | share role", Help: "授权", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 { // 会话列表
|
||||
m.Cmdy("aaa.auth", "relay")
|
||||
return
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "check":
|
||||
if relay := m.Confm("auth", []string{arg[1], "data"}); relay != nil {
|
||||
if kit.Select("", arg, 2) == "userrole" && kit.Int(relay["count"]) > 0 {
|
||||
relay["count"] = kit.Int(relay["count"]) - 1
|
||||
m.Echo("%s", relay["userrole"])
|
||||
}
|
||||
for k, v := range relay {
|
||||
m.Append(k, v)
|
||||
}
|
||||
}
|
||||
case "share":
|
||||
m.Echo(m.Cmd("aaa.auth", "relay", "right").Result(0))
|
||||
m.Conf("auth", []string{m.Result(0), "data"}, map[string]interface{}{
|
||||
"userrole": kit.Select("tech", arg, 1),
|
||||
"username": kit.Select("", arg, 2),
|
||||
"count": kit.Select("1", arg, 3),
|
||||
})
|
||||
}
|
||||
return
|
||||
}},
|
||||
"login": &ctx.Command{Name: "login nodesess", Help: "登录", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
m.Cmd("aaa.auth", "username", m.Option("username"), "session", "nodes").Table(func(sess map[string]string) {
|
||||
@ -717,8 +746,8 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
|
||||
// 生成证书
|
||||
template := x509.Certificate{
|
||||
SerialNumber: big.NewInt(1),
|
||||
IsCA: true,
|
||||
SerialNumber: big.NewInt(1),
|
||||
IsCA: true,
|
||||
BasicConstraintsValid: true,
|
||||
KeyUsage: x509.KeyUsageCertSign,
|
||||
Subject: pkix.Name{CommonName: kit.Format(common)},
|
||||
|
@ -1167,7 +1167,6 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, "")
|
||||
}
|
||||
m.Magic("session", "current.dir", arg[0])
|
||||
|
||||
wd, e := os.Getwd()
|
||||
m.Assert(e)
|
||||
@ -1264,33 +1263,39 @@ var Index = &ctx.Context{Name: "nfs", Help: "存储中心",
|
||||
return
|
||||
}},
|
||||
|
||||
"path": &ctx.Command{Name: "path filename", Help: "查找文件路径",
|
||||
Auto: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (ok bool) {
|
||||
if len(arg) == 0 {
|
||||
m.Add("append", "value", "")
|
||||
m.Add("append", "name", "filename")
|
||||
m.Add("append", "help", "文件名")
|
||||
return false
|
||||
}
|
||||
m.Add("append", "value", "")
|
||||
m.Add("append", "name", "no more arg")
|
||||
return true
|
||||
},
|
||||
Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
return
|
||||
}
|
||||
"temp": &ctx.Command{Name: "temp data", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
h, _ := kit.Hash("uniq")
|
||||
name := fmt.Sprintf("var/tmp/file/%s", h)
|
||||
|
||||
m.Confm("paths", func(index int, value string) bool {
|
||||
p := path.Join(value, arg[0])
|
||||
if _, e := os.Stat(p); e == nil {
|
||||
m.Echo(p)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
m.Assert(os.MkdirAll("var/tmp/file/", 0777))
|
||||
f, e := os.Create(name)
|
||||
m.Assert(e)
|
||||
defer f.Close()
|
||||
f.Write([]byte(arg[0]))
|
||||
|
||||
m.Echo(name)
|
||||
return
|
||||
}},
|
||||
"trash": &ctx.Command{Name: "trash file", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
os.Remove(arg[0])
|
||||
return
|
||||
}},
|
||||
|
||||
"path": &ctx.Command{Name: "path filename", Help: "查找文件路径", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
return
|
||||
}},
|
||||
}
|
||||
|
||||
m.Confm("paths", func(index int, value string) bool {
|
||||
p := path.Join(value, arg[0])
|
||||
if _, e := os.Stat(p); e == nil {
|
||||
m.Echo(p)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
return
|
||||
}},
|
||||
"load": &ctx.Command{Name: "load file [buf_size [pos]]", Help: "加载文件, buf_size: 加载大小, pos: 加载位置", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if p, f, e := open(m, arg[0]); e == nil {
|
||||
defer f.Close()
|
||||
|
@ -118,20 +118,38 @@ func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request)
|
||||
if msg.Cmds("aaa.auth", "username", msg.Option("username"), "password", msg.Option("password")) {
|
||||
msg.Log("info", "login: %s", msg.Option("username"))
|
||||
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Cmdx("aaa.user", "session", "select"), Path: "/"})
|
||||
if msg.Options("relay") {
|
||||
if role := msg.Cmdx("aaa.relay", "check", msg.Option("relay"), "userrole"); role != "" {
|
||||
msg.Cmd("aaa.role", role, "user", msg.Option("username"))
|
||||
msg.Log("info", "relay: %s", role)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
if msg.Options("sessid") {
|
||||
msg.Log("info", "sessid: %s", msg.Option("sessid"))
|
||||
msg.Log("info", "username: %s", msg.Option("username", msg.Cmd("aaa.sess", "user").Append("meta")))
|
||||
}
|
||||
|
||||
if !msg.Options("username") && msg.Options("relay") {
|
||||
if relay := msg.Cmd("aaa.relay", "check", msg.Option("relay")); relay.Appends("username") {
|
||||
if role := msg.Cmdx("aaa.relay", "check", msg.Option("relay"), "userrole"); role != "" {
|
||||
msg.Log("info", "login: %s", msg.Option("username", relay.Append("username")))
|
||||
http.SetCookie(w, &http.Cookie{Name: "sessid", Value: msg.Cmdx("aaa.user", "session", "select"), Path: "/"})
|
||||
msg.Cmd("aaa.role", role, "user", msg.Option("username"))
|
||||
msg.Log("info", "relay: %s", role)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
|
||||
web.HandleFunc(key, func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
m.TryCatch(m.Spawn(m.Conf("serve", "autofree")), true, func(msg *ctx.Message) {
|
||||
msg.Option("remote_addr", r.RemoteAddr)
|
||||
msg.Option("remote_ip", r.Header.Get("remote_ip"))
|
||||
@ -143,23 +161,13 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
|
||||
msg.Option("path", r.URL.Path)
|
||||
msg.Optionv("debug", false)
|
||||
|
||||
msg.Option("GOOS", m.Conf("runtime", "host.GOOS"))
|
||||
msg.Option("GOARCH", m.Conf("runtime", "host.GOARCH"))
|
||||
agent := r.Header.Get("User-Agent")
|
||||
switch {
|
||||
case strings.Contains(agent, "Macintosh"):
|
||||
msg.Option("GOOS", "darwin")
|
||||
}
|
||||
switch {
|
||||
case strings.Contains(agent, "Intel"):
|
||||
msg.Option("GOARCH", "386")
|
||||
}
|
||||
|
||||
// 请求环境
|
||||
msg.Option("dir_root", msg.Cap("directory"))
|
||||
for _, v := range r.Cookies() {
|
||||
msg.Option(v.Name, v.Value)
|
||||
}
|
||||
|
||||
// 请求参数
|
||||
r.ParseMultipartForm(int64(msg.Confi("serve", "form_size")))
|
||||
if r.ParseForm(); len(r.PostForm) > 0 {
|
||||
for k, v := range r.PostForm {
|
||||
@ -171,6 +179,7 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
|
||||
msg.Add("option", k, v)
|
||||
}
|
||||
|
||||
// 请求数据
|
||||
switch r.Header.Get("Content-Type") {
|
||||
case "application/json":
|
||||
var data interface{}
|
||||
@ -187,11 +196,27 @@ func (web *WEB) HandleCmd(m *ctx.Message, key string, cmd *ctx.Command) {
|
||||
}
|
||||
}
|
||||
|
||||
// 请求系统
|
||||
// msg.Option("GOOS", m.Conf("runtime", "host.GOOS"))
|
||||
// msg.Option("GOARCH", m.Conf("runtime", "host.GOARCH"))
|
||||
// agent := r.Header.Get("User-Agent")
|
||||
// switch {
|
||||
// case strings.Contains(agent, "Macintosh"):
|
||||
// msg.Option("GOOS", "darwin")
|
||||
// }
|
||||
// switch {
|
||||
// case strings.Contains(agent, "Intel"):
|
||||
// msg.Option("GOARCH", "386")
|
||||
// }
|
||||
//
|
||||
|
||||
// 用户登录
|
||||
if msg.Put("option", "request", r).Put("option", "response", w).Sess("web", msg); web.Login(msg, w, r) {
|
||||
msg.Log("cmd", "%s [] %v", key, msg.Meta["option"])
|
||||
cmd.Hand(msg, msg.Target(), msg.Option("path"))
|
||||
}
|
||||
|
||||
// 返回响应
|
||||
switch {
|
||||
case msg.Has("redirect"):
|
||||
http.Redirect(w, r, msg.Append("redirect"), http.StatusTemporaryRedirect)
|
||||
|
@ -101,8 +101,27 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
},
|
||||
map[string]interface{}{"name": "tail", "template": "tail"},
|
||||
},
|
||||
"flash": []interface{}{
|
||||
map[string]interface{}{"name": "flash", "template": "head"},
|
||||
map[string]interface{}{"name": "ask", "help": "ask", "template": "componet",
|
||||
"componet_view": "flasktext", "componet_init": "initFlashText",
|
||||
"componet_ctx": "web.code", "componet_cmd": "flash", "arguments": []interface{}{"text", "@text"}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "textarea", "name": "text", "value": "", "cols": 50, "rows": 5},
|
||||
map[string]interface{}{"type": "button", "value": "添加请求"},
|
||||
},
|
||||
"display_result": "", "display_append": "",
|
||||
},
|
||||
map[string]interface{}{"name": "tip", "help": "tip", "template": "componet",
|
||||
"componet_view": "flasklist", "componet_init": "initFlashList",
|
||||
"componet_ctx": "web.code", "componet_cmd": "flash", "arguments": []interface{}{}, "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
"display_result": "", "display_append": "",
|
||||
},
|
||||
map[string]interface{}{"name": "tail", "template": "tail"},
|
||||
},
|
||||
"index": []interface{}{
|
||||
map[string]interface{}{"name": "head", "template": "head"},
|
||||
map[string]interface{}{"name": "code", "template": "head"},
|
||||
map[string]interface{}{"name": "toolkit", "help": "toolkit", "template": "toolkit"},
|
||||
// map[string]interface{}{"name": "login", "help": "login", "template": "componet",
|
||||
// "componet_ctx": "aaa", "componet_cmd": "login", "arguments": []interface{}{"@username", "@password"},
|
||||
@ -126,27 +145,9 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
},
|
||||
"pre_run": true,
|
||||
},
|
||||
// map[string]interface{}{"name": "time", "help": "time", "template": "componet",
|
||||
// "componet_ctx": "cli", "componet_cmd": "time", "arguments": []interface{}{"@string"},
|
||||
// "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "text", "name": "time_format",
|
||||
// "label": "format", "value": "2006-01-02 15:04:05",
|
||||
// },
|
||||
// map[string]interface{}{"type": "text", "name": "string", "label": "string"},
|
||||
// map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
// },
|
||||
// },
|
||||
// map[string]interface{}{"name": "json", "help": "json", "template": "componet",
|
||||
// "componet_ctx": "nfs", "componet_cmd": "json", "arguments": []interface{}{"@string"},
|
||||
// "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "text", "name": "string", "label": "string"},
|
||||
// map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
// },
|
||||
// },
|
||||
map[string]interface{}{"name": "dir", "help": "dir", "template": "componet",
|
||||
"componet_ctx": "nfs", "componet_cmd": "dir", "arguments": []interface{}{"@current.dir", "dir_sort", "@sort_field", "@sort_order"},
|
||||
"pre_run": true, "display_result": "",
|
||||
"inputs": []interface{}{
|
||||
"componet_view": "DirList", "componet_init": "initDirList",
|
||||
"pre_run": false, "componet_ctx": "nfs", "componet_cmd": "dir", "arguments": []interface{}{"@current.dir", "dir_sort", "@sort_field", "@sort_order"}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "choice", "name": "dir_type",
|
||||
"label": "dir_type", "value": "both", "choice": []interface{}{
|
||||
map[string]interface{}{"name": "all", "value": "all"},
|
||||
@ -176,25 +177,15 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
},
|
||||
map[string]interface{}{"type": "text", "name": "current.dir", "value": "@current.dir", "label": "dir"},
|
||||
},
|
||||
"display_result": "",
|
||||
},
|
||||
map[string]interface{}{"name": "upload", "help": "upload", "template": "componet",
|
||||
"componet_ctx": "web", "componet_cmd": "upload", "form_type": "upload",
|
||||
"inputs": []interface{}{
|
||||
"componet_ctx": "web", "componet_cmd": "upload", "form_type": "upload", "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "file", "name": "upload"},
|
||||
map[string]interface{}{"type": "submit", "value": "submit"},
|
||||
},
|
||||
"display_result": "",
|
||||
},
|
||||
// map[string]interface{}{"name": "download", "help": "download", "template": "componet",
|
||||
// "componet_ctx": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmds"},,
|
||||
// "display_result": "", "download_file": "",
|
||||
// "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "text", "name": "download_file", "value": "data_2006_0102_1504.txt", "class": "file_name"},
|
||||
// map[string]interface{}{"type": "text", "name": "cmds", "value": "",
|
||||
// "class": "file_cmd", "clipstack": "clistack",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
map[string]interface{}{"name": "cmd", "help": "cmd", "template": "componet",
|
||||
"componet_ctx": "cli.shy", "componet_cmd": "source", "arguments": []interface{}{"@cmd"},
|
||||
"inputs": []interface{}{
|
||||
@ -204,81 +195,21 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"name": "pod", "help": "pod", "template": "componet",
|
||||
"componet_ctx": "ssh", "componet_cmd": "remote",
|
||||
"inputs": []interface{}{
|
||||
"componet_view": "PodList", "componet_init": "initPodList",
|
||||
"pre_run": true, "componet_ctx": "ssh", "componet_cmd": "remote", "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "pod", "value": "@current.pod"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
"pre_run": true, "display_result": "",
|
||||
"display_result": "",
|
||||
},
|
||||
map[string]interface{}{"name": "ctx", "help": "ctx", "template": "componet",
|
||||
"componet_pod": "true", "componet_ctx": "ssh", "componet_cmd": "context", "arguments": []interface{}{"@ctx", "list"},
|
||||
"display_result": "",
|
||||
"inputs": []interface{}{
|
||||
"componet_view": "CtxList", "componet_init": "initCtxList",
|
||||
"componet_pod": "true", "componet_ctx": "ssh", "componet_cmd": "context", "arguments": []interface{}{"@ctx", "list"}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "ctx", "value": "@current.ctx"},
|
||||
map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
},
|
||||
"display_result": "",
|
||||
},
|
||||
// map[string]interface{}{"name": "ccc", "help": "ccc", "template": "componet",
|
||||
// "componet_ctx": "cli.shy", "componet_cmd": "context", "arguments": []interface{}{"@current_ctx", "@ccc"},
|
||||
// "display_result": "",
|
||||
// "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "choice", "name": "ccc",
|
||||
// "label": "ccc", "value": "cmd", "choice": []interface{}{
|
||||
// map[string]interface{}{"name": "cmd", "value": "cmd"},
|
||||
// map[string]interface{}{"name": "config", "value": "config"},
|
||||
// map[string]interface{}{"name": "cache", "value": "cache"},
|
||||
// },
|
||||
// },
|
||||
// map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
// },
|
||||
// },
|
||||
// map[string]interface{}{"name": "cmd", "help": "cmd", "template": "componet",
|
||||
// "componet_ctx": "cli.shy", "componet_cmd": "context", "arguments": []interface{}{"@current_ctx", "cmd", "list"},
|
||||
// "pre_run": true, "display_result": "",
|
||||
// "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
// },
|
||||
// },
|
||||
// map[string]interface{}{"name": "history", "help": "history", "template": "componet",
|
||||
// "componet_ctx": "cli", "componet_cmd": "config", "arguments": []interface{}{"source_list"},
|
||||
// "pre_run": true, "display_result": "",
|
||||
// "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
// },
|
||||
// },
|
||||
// map[string]interface{}{"name": "develop", "help": "develop", "template": "componet",
|
||||
// "componet_ctx": "web.code", "componet_cmd": "config", "arguments": []interface{}{"counter"},
|
||||
// "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
// },
|
||||
// "pre_run": true,
|
||||
// "display_result": "",
|
||||
// },
|
||||
// map[string]interface{}{"name": "windows", "help": "windows", "template": "componet",
|
||||
// "componet_ctx": "cli", "componet_cmd": "windows",
|
||||
// "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
// },
|
||||
// "pre_run": true,
|
||||
// "display_result": "",
|
||||
// },
|
||||
// map[string]interface{}{"name": "runtime", "help": "runtime", "template": "componet",
|
||||
// "componet_ctx": "cli", "componet_cmd": "runtime",
|
||||
// "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
// },
|
||||
// "pre_run": true,
|
||||
// "display_result": "",
|
||||
// },
|
||||
// map[string]interface{}{"name": "sysinfo", "help": "sysinfo", "template": "componet",
|
||||
// "componet_ctx": "cli", "componet_cmd": "sysinfo",
|
||||
// "inputs": []interface{}{
|
||||
// map[string]interface{}{"type": "button", "value": "refresh"},
|
||||
// },
|
||||
// "pre_run": true,
|
||||
// "display_result": "",
|
||||
// },
|
||||
// map[string]interface{}{"name": "mp", "template": "mp"},
|
||||
map[string]interface{}{"name": "tail", "template": "tail"},
|
||||
},
|
||||
@ -299,6 +230,10 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
"context_js": "usr/librarys/context.js",
|
||||
},
|
||||
}, Help: "日志地址"},
|
||||
"flash": &ctx.Config{Name: "flash", Value: map[string]interface{}{
|
||||
"data": []interface{}{},
|
||||
"view": map[string]interface{}{"default": []interface{}{"index", "time", "text", "code", "output"}},
|
||||
}, Help: "闪存"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"mux": &ctx.Command{Name: "mux [session [window [pane]]] args...", Help: "终端管理", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
@ -475,6 +410,67 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
|
||||
}
|
||||
return
|
||||
}},
|
||||
"flash": &ctx.Command{Name: "flash", Help: "闪存", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
total := len(m.Confv("flash", "data").([]interface{}))
|
||||
// 查看列表
|
||||
if len(arg) == 0 {
|
||||
if index := m.Option("flash_index"); index != "" {
|
||||
arg = append(arg, index)
|
||||
} else {
|
||||
m.Confm("flash", "data", func(index int, item map[string]interface{}) {
|
||||
for _, k := range kit.View([]string{}, m.Confm("flash", "view")) {
|
||||
m.Add("append", k, kit.Format(item[k]))
|
||||
}
|
||||
})
|
||||
m.Table()
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
index, item := -1, map[string]interface{}{"time": m.Time()}
|
||||
if i, e := strconv.Atoi(arg[0]); e == nil && 0 <= i && i < total {
|
||||
// 查看索引
|
||||
index, arg = total-1-i, arg[1:]
|
||||
if item = m.Confm("flash", []interface{}{"data", index}); len(arg) == 0 {
|
||||
// 查看数据
|
||||
for _, k := range kit.View([]string{}, m.Confm("flash", "view")) {
|
||||
m.Add("append", k, kit.Format(item[k]))
|
||||
}
|
||||
m.Table()
|
||||
return e
|
||||
}
|
||||
}
|
||||
|
||||
switch arg[0] {
|
||||
case "vim": // 编辑数据
|
||||
name := m.Cmdx("nfs.temp", kit.Format(item[kit.Select("code", arg, 1)]))
|
||||
m.Cmd("cli.system", "vi", name)
|
||||
item[kit.Select("code", arg, 1)] = m.Cmdx("nfs.load", name)
|
||||
m.Cmd("nfs.trash", name)
|
||||
|
||||
case "run": // 运行代码
|
||||
code := kit.Format(item[kit.Select("code", arg, 1)])
|
||||
if code == "" {
|
||||
break
|
||||
}
|
||||
name := m.Cmdx("nfs.temp", code)
|
||||
m.Cmdy("cli.system", "python", name)
|
||||
item["output"] = m.Result(0)
|
||||
m.Cmd("nfs.trash", name)
|
||||
|
||||
default:
|
||||
// 修改数据
|
||||
for i := 0; i < len(arg)-1; i += 2 {
|
||||
item[arg[i]] = arg[i+1]
|
||||
}
|
||||
m.Conf("flash", []interface{}{"data", index}, item)
|
||||
item["index"] = total - 1 - index
|
||||
m.Echo("%d", total-1-index)
|
||||
}
|
||||
|
||||
return
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
|
119
usr/librarys/code.css
Normal file
119
usr/librarys/code.css
Normal file
@ -0,0 +1,119 @@
|
||||
fieldset {
|
||||
margin-top:8px;
|
||||
}
|
||||
fieldset legend {
|
||||
font-size:16px;
|
||||
font-weight:bold;
|
||||
font-family:monospace;
|
||||
}
|
||||
fieldset form.option div {
|
||||
float:left;
|
||||
}
|
||||
fieldset form.option input {
|
||||
margin-right:10px;
|
||||
}
|
||||
fieldset form.option select {
|
||||
margin-right:10px;
|
||||
}
|
||||
fieldset form.option hr {
|
||||
clear:both;
|
||||
}
|
||||
|
||||
fieldset table.append {
|
||||
font-size:14px;
|
||||
overflow: auto;
|
||||
}
|
||||
fieldset table.append tr:hover {
|
||||
background-color:lightgreen;
|
||||
}
|
||||
fieldset table.append th {
|
||||
font-family:monospace;
|
||||
background-color:lightgreen;
|
||||
cursor:pointer;
|
||||
}
|
||||
fieldset table.append th.order {
|
||||
background-color:red;
|
||||
cursor:pointer;
|
||||
}
|
||||
fieldset table.append td {
|
||||
max-width:1200px;
|
||||
font-family:monospace;
|
||||
padding-left: 10px;
|
||||
padding-right: 20px;
|
||||
}
|
||||
fieldset table.append td.clip {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset table.append td:hover {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset code.result pre {
|
||||
color:white;
|
||||
font-size:14px;
|
||||
background-color:#272822;
|
||||
overflow:scroll;
|
||||
padding:5px;
|
||||
border:solid 2px green;
|
||||
border-left:solid 4px green;
|
||||
margin:0;
|
||||
}
|
||||
fieldset code.result pre.clipboard {
|
||||
height:2em;
|
||||
}
|
||||
|
||||
fieldset.flasktext {
|
||||
}
|
||||
|
||||
fieldset.flasklist div.detail {
|
||||
border:ridge 2px green;
|
||||
border-bottom:0px;
|
||||
margin-top:20px;
|
||||
padding:5px;
|
||||
}
|
||||
fieldset.flasklist div.action {
|
||||
border:ridge 2px green;
|
||||
border-top:0px;
|
||||
border-bottom:0px;
|
||||
}
|
||||
fieldset.flasklist code.output pre {
|
||||
border:ridge 2px green;
|
||||
margin:0px;
|
||||
padding:5px;
|
||||
border-top: 0px;
|
||||
}
|
||||
|
||||
|
||||
textarea.clipboard {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
width:600px;
|
||||
}
|
||||
|
||||
form.option label.keymap {
|
||||
color:red;
|
||||
display:none;
|
||||
}
|
||||
form.option label.keymap.show {
|
||||
display:inline;
|
||||
}
|
||||
form.option input.cmd {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
padding-left:10px;
|
||||
width:600px;
|
||||
}
|
||||
form.option input.file_cmd {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
padding-left:10px;
|
||||
width:400px;
|
||||
}
|
||||
form.option input.file_name {
|
||||
width:200px;
|
||||
}
|
||||
form.option.exec input {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
padding-left:10px;
|
||||
width:600px;
|
||||
}
|
@ -76,18 +76,6 @@ function copy_to_clipboard(text, skip_blur, skip_toolkit) {
|
||||
})
|
||||
}
|
||||
|
||||
function add_keymap(input) {
|
||||
if (code.ninput < code.keymap.length && input.style.display != "none") {
|
||||
input.title = "keymap: "+code.keymap[code.ninput]
|
||||
input.dataset["keymap"] = code.keymap[code.ninput]
|
||||
insert_before(input, "label", {
|
||||
"innerText": "("+code.keymap[code.ninput]+")",
|
||||
"className": "keymap" + (code.showmap? " show": " hide"),
|
||||
})
|
||||
code.inputs[code.keymap[code.ninput++]] = input
|
||||
}
|
||||
return input
|
||||
}
|
||||
function add_sort(append, field, cb) {
|
||||
append.onclick = function(event) {
|
||||
var target = event.target
|
||||
@ -181,11 +169,11 @@ function add_command(init) {
|
||||
})
|
||||
|
||||
append_child(option, "input", {"style": {"display": "none"}})
|
||||
add_keymap(append_child(option, "input", {
|
||||
append_child(option, "input", {
|
||||
"name": "cmd", "className": "cmd",
|
||||
"onkeyup": function(event) {onaction(event, "input")},
|
||||
"onfocus": function(event) {code.current_cmd=order}
|
||||
})).focus()
|
||||
}).focus()
|
||||
|
||||
add_sort(append_child(fieldset, "table", {"className": "append "+name}))
|
||||
append_child(append_child(fieldset, "code", {"className": "result "+name}), "pre")
|
||||
@ -404,13 +392,13 @@ function onaction(event, action, arg) {
|
||||
return
|
||||
}
|
||||
|
||||
switch (event.key) {
|
||||
default:
|
||||
if (code.inputs[event.key]) {
|
||||
code.inputs[event.key].focus()
|
||||
}
|
||||
break
|
||||
}
|
||||
// switch (event.key) {
|
||||
// default:
|
||||
// if (code.inputs[event.key]) {
|
||||
// code.inputs[event.key].focus()
|
||||
// }
|
||||
// break
|
||||
// }
|
||||
break
|
||||
case "input":
|
||||
if (event.key == "Escape") {
|
||||
@ -580,6 +568,7 @@ function onaction(event, action, arg) {
|
||||
if (target["value"] == "login") {
|
||||
location.reload()
|
||||
}
|
||||
typeof target.form.onactions == "function" && target.form.onactions(msg)
|
||||
})
|
||||
break
|
||||
case "toolkit":
|
||||
@ -593,22 +582,6 @@ function onaction(event, action, arg) {
|
||||
}
|
||||
}
|
||||
|
||||
function init_option() {
|
||||
code.inputs = {}
|
||||
code.ninput = 0
|
||||
code.keymap =[]
|
||||
for (var i = 97; i < 123; i++) {
|
||||
switch (i) {
|
||||
case "j".charCodeAt(0):
|
||||
case "k".charCodeAt(0):
|
||||
case "h".charCodeAt(0):
|
||||
case "l".charCodeAt(0):
|
||||
continue
|
||||
}
|
||||
code.keymap.push(String.fromCharCode(i))
|
||||
}
|
||||
document.querySelectorAll("form.option input").forEach(add_keymap)
|
||||
}
|
||||
function init_append(event) {
|
||||
var append = document.querySelectorAll("table.append").forEach(add_sort)
|
||||
}
|
||||
@ -623,130 +596,6 @@ function init_result(event) {
|
||||
})
|
||||
}
|
||||
|
||||
function init_userinfo() {
|
||||
var option = document.querySelector("form.option.userinfo")
|
||||
var append = document.querySelector("table.append.userinfo")
|
||||
if (!append) {return}
|
||||
|
||||
insert_button(append, "logout", function(event) {
|
||||
context.Cookie("sessid", "")
|
||||
location.reload()
|
||||
})
|
||||
}
|
||||
function init_download(event) {
|
||||
var option = document.querySelector("form.option.dir")
|
||||
var append = document.querySelector("table.append.dir")
|
||||
if (!append) {return}
|
||||
|
||||
function change(dir, show, run) {
|
||||
if ((dir.endsWith(".sh") || dir.endsWith(".shy") || dir.endsWith(".py")) && !show) {
|
||||
var command = document.querySelector("form.option.cmd")
|
||||
var cmd = command["cmd"]
|
||||
cmd.value = "run "+ dir.split("/").pop()
|
||||
cmd.focus()
|
||||
if (run) {
|
||||
check_option(command)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
option["current.dir"].value = dir
|
||||
send_command(option)
|
||||
}
|
||||
insert_button(append, "root", function(event) {
|
||||
change("")
|
||||
})
|
||||
insert_button(append, "back", function(event) {
|
||||
var path = option["current.dir"].value.split("/")
|
||||
while (path.pop() == "") {}
|
||||
change(path.join("/")+(path.length? "/": ""))
|
||||
})
|
||||
|
||||
var sort_order = option["sort_order"]
|
||||
var sort_field = option["sort_field"]
|
||||
sort_field.innerHTML = ""
|
||||
sort_field.onchange = function(event) {
|
||||
switch (event.target.selectedOptions[0].value) {
|
||||
case "filename":
|
||||
case "type":
|
||||
sort_order.value = (sort_order.value == "str")? "str_r": "str"
|
||||
break
|
||||
case "line":
|
||||
case "size":
|
||||
sort_order.value = (sort_order.value == "int")? "int_r": "int"
|
||||
break
|
||||
case "time":
|
||||
sort_order.value = (sort_order.value == "time")? "time_r": "time"
|
||||
break
|
||||
}
|
||||
send_command(option)
|
||||
}
|
||||
|
||||
var th = append.querySelectorAll("th")
|
||||
for (var i = 0; i < th.length; i++) {
|
||||
var value = th[i].innerText.trim()
|
||||
var opt = append_child(sort_field, "option", {
|
||||
"value": value, "innerText": value,
|
||||
})
|
||||
}
|
||||
|
||||
add_sort(append, "filename", function(event) {
|
||||
var dir = event.target.innerText
|
||||
if (option["current.dir"].value && !option["current.dir"].value.endsWith("/")) {
|
||||
change(option["current.dir"].value+"/"+dir, event.altKey, event.shiftKey)
|
||||
} else {
|
||||
change(option["current.dir"].value+dir, event.altKey, event.shiftKey)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function init_contain() {
|
||||
var option = document.querySelector("form.option.pod")
|
||||
var append = document.querySelector("table.append.pod")
|
||||
if (!append) {return}
|
||||
|
||||
function change(pod) {
|
||||
option["pod"].value = pod
|
||||
context.GET("", {
|
||||
"componet_group": "index",
|
||||
"componet_name": "cmd",
|
||||
"cmd": "sess current pod "+option["pod"].value,
|
||||
})
|
||||
return pod
|
||||
}
|
||||
|
||||
add_sort(append, "key", function(event) {
|
||||
change(event.target.innerText.trim())
|
||||
})
|
||||
}
|
||||
function init_context() {
|
||||
var option = document.querySelector("form.option.ctx")
|
||||
var append = document.querySelector("table.append.ctx")
|
||||
if (!append) {return}
|
||||
|
||||
function change(ctx) {
|
||||
option["ctx"].value = ctx
|
||||
send_command(option)
|
||||
context.GET("", {
|
||||
"componet_group": "index",
|
||||
"componet_name": "cmd",
|
||||
"cmd": "sess current ctx "+option["ctx"].value,
|
||||
})
|
||||
return ctx
|
||||
}
|
||||
|
||||
var contexts = ["ctx", "shy", "web", "mdb"]
|
||||
for (var i = 0; i < contexts.length; i++) {
|
||||
insert_button(append, contexts[i], function(event) {
|
||||
change(event.target.value)
|
||||
})
|
||||
}
|
||||
add_sort(append, "name", function(event) {
|
||||
change(event.target.innerText.trim())
|
||||
})
|
||||
|
||||
send_command(option)
|
||||
}
|
||||
function init_command() {
|
||||
var option = document.querySelector("form.option.cmd")
|
||||
if (!option) {
|
||||
@ -914,17 +763,94 @@ function init_toolkit() {
|
||||
})
|
||||
}
|
||||
|
||||
window.onload = function() {
|
||||
init_option()
|
||||
init_append()
|
||||
init_result()
|
||||
Page({
|
||||
initFlashText: function(page, field, option, append, result) {
|
||||
option.onactions = function(msg) {
|
||||
page.reload()
|
||||
}
|
||||
},
|
||||
initFlashList: function(page, field, option, append, result) {
|
||||
option.dataset.flash_index = ctx.Search("flash_index")
|
||||
option.onactions = function(msg) {
|
||||
page.onFlashShow(msg, field, option, append, result)
|
||||
}
|
||||
ctx.Run(page, option.dataset, [], option.onactions)
|
||||
},
|
||||
onFlashShow: function(msg, field, option, append, result) {
|
||||
var page = this
|
||||
result.innerHTML = ""
|
||||
ctx.Table(msg, function(tip) {
|
||||
var ui = kit.AppendChild(result, [{"list": [
|
||||
{"view": ["detail", "div", tip.text]},
|
||||
{"code": [tip.output, "result", "result"]},
|
||||
{"view": ["action"], "list": [
|
||||
{"click": ["查看详情", function(event) {
|
||||
ctx.Search("flash_index", tip.index)
|
||||
}]},
|
||||
{"click": ["执行代码", function(event) {
|
||||
tip.code && ctx.Run(page, option.dataset, [tip.index, "run"], function(msg) {
|
||||
ui.output.innerText = msg.result
|
||||
})
|
||||
}]},
|
||||
{"click": ["清空结果", function(event) {
|
||||
ui.output.innerText = ""
|
||||
}]},
|
||||
]},
|
||||
{"code": [tip.output, "output", "output"]},
|
||||
]}])
|
||||
})
|
||||
},
|
||||
|
||||
init_userinfo()
|
||||
init_download()
|
||||
initDirList: function(page, field, option, append, result) {
|
||||
var history = []
|
||||
function change(value) {
|
||||
option["current.dir"].value = value
|
||||
ctx.Runs(page, option)
|
||||
ctx.Current("dir", value)
|
||||
return value
|
||||
}
|
||||
function brow(value, dir, event) {
|
||||
option["current.dir"].value = value
|
||||
ctx.Runs(page, option)
|
||||
option["current.dir"].value = dir
|
||||
ctx.Runs(page, option)
|
||||
}
|
||||
return {
|
||||
"button": ["root", "back"], "action": function(value) {
|
||||
switch (value) {
|
||||
case "back": history.length > -1 && change(history.pop() || "/"); break
|
||||
case "root": change("/"); break
|
||||
}
|
||||
},
|
||||
"table": {"filename": function(value, key, row, index, event) {
|
||||
var dir = option["current.dir"].value
|
||||
var file = dir + ((dir && !dir.endsWith("/"))? "/": "") + value
|
||||
file.endsWith("/")? history.push(change(file)): brow(file, dir, event)
|
||||
}},
|
||||
}
|
||||
},
|
||||
initPodList: function(page, field, option, append, result) {
|
||||
function change(value) {
|
||||
option.pod.value = value
|
||||
ctx.Runs(page, option)
|
||||
ctx.Current("pod", value)
|
||||
}
|
||||
return {"table": {"key": change}}
|
||||
},
|
||||
initCtxList: function(page, field, option, append, result) {
|
||||
function change(value) {
|
||||
option.ctx.value = value
|
||||
ctx.Runs(page, option)
|
||||
ctx.Current("ctx", value)
|
||||
}
|
||||
return {"button": ["ctx", "shy", "web", "mdb"], "action": change, "table": {"names": change}}
|
||||
},
|
||||
|
||||
init_contain()
|
||||
init_context()
|
||||
init_command()
|
||||
init_toolkit()
|
||||
}
|
||||
init: function(exp) {
|
||||
init_append()
|
||||
init_result()
|
||||
|
||||
init_command()
|
||||
init_toolkit()
|
||||
},
|
||||
})
|
||||
|
@ -1,38 +1,109 @@
|
||||
context = {
|
||||
Bench: function(key, value) {
|
||||
ctx = context = {
|
||||
__proto__: kit,
|
||||
Table: function(msg, cb) {
|
||||
var rows = this.PackAppend(msg)
|
||||
if (typeof cb == "function") {
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
if (cb(rows[i], i)) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return rows
|
||||
},
|
||||
Search: function(key, value) {
|
||||
var args = {};
|
||||
var search = location.search.split("?");
|
||||
if (search.length > 1) {
|
||||
var searchs = search[1].split("&");
|
||||
for (var i = 0; i < searchs.length; i++) {
|
||||
var keys = searchs[i].split("=");
|
||||
args[keys[0]] = decodeURIComponent(keys[1]);
|
||||
}
|
||||
}
|
||||
PackAppend: function(msg) {
|
||||
var ret = []
|
||||
if (!msg || !msg.append || !msg.append.length || !msg[msg.append[0]]) {
|
||||
return ret
|
||||
}
|
||||
|
||||
var ncol = msg.append.length
|
||||
var nrow = msg[msg.append[0]].length
|
||||
for (var i = 0; i < nrow; i++) {
|
||||
var one = {}
|
||||
for (var j = 0; j < ncol; j++) {
|
||||
one[msg.append[j]] = msg[msg.append[j]][i]
|
||||
}
|
||||
ret.push(one)
|
||||
}
|
||||
return ret
|
||||
},
|
||||
Run: function(page, dataset, cmd, cb) {
|
||||
var option = {"cmds": cmd}
|
||||
for (var k in dataset) {
|
||||
option[k] = dataset[k]
|
||||
}
|
||||
this.GET("", option, function(msg) {
|
||||
msg = msg && msg[0]
|
||||
msg && (msg.__proto__ = page || {})
|
||||
typeof cb == "function" && cb(msg || {})
|
||||
})
|
||||
},
|
||||
Runs: function(page, form, cb) {
|
||||
var data = {}
|
||||
for (var key in form.dataset) {
|
||||
data[key] = form.dataset[key]
|
||||
}
|
||||
for (var i = 0; i < form.length; i++) {
|
||||
if (form[i].name) {
|
||||
data[form[i].name] = form[i].value
|
||||
}
|
||||
}
|
||||
this.Run(page, data, [], cb || form.onactions)
|
||||
},
|
||||
Current: function(key, value) {
|
||||
context.GET("", {
|
||||
"componet_group": "index",
|
||||
"componet_name": "cmd",
|
||||
"cmds": ["sess", "current", key, value],
|
||||
})
|
||||
return value
|
||||
},
|
||||
Share: function(objs) {
|
||||
var args = this.Search()
|
||||
for (var k in objs) {
|
||||
args[k] = objs[k]
|
||||
}
|
||||
|
||||
var as = []
|
||||
for (var k in args) {
|
||||
as.push(k+"="+encodeURIComponent(args[k]));
|
||||
}
|
||||
var arg = as.join("&");
|
||||
return location.origin+location.pathname+"?"+arg
|
||||
},
|
||||
Search: function(key, value) {
|
||||
var args = {};
|
||||
var search = location.search.split("?");
|
||||
if (search.length > 1) {
|
||||
var searchs = search[1].split("&");
|
||||
for (var i = 0; i < searchs.length; i++) {
|
||||
var keys = searchs[i].split("=");
|
||||
args[keys[0]] = decodeURIComponent(keys[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (key == undefined) {
|
||||
return args
|
||||
} else if (typeof key == "object") {
|
||||
for (var k in key) {
|
||||
if (key[k] != undefined) {
|
||||
args[k] = key[k];
|
||||
}
|
||||
}
|
||||
} else if (value == undefined) {
|
||||
return args[key] || this.Cookie(key);
|
||||
} else {
|
||||
args[key] = value;
|
||||
}
|
||||
for (var k in key) {
|
||||
if (key[k] != undefined) {
|
||||
args[k] = key[k];
|
||||
}
|
||||
}
|
||||
} else if (value == undefined) {
|
||||
return args[key] || this.Cookie(key);
|
||||
} else {
|
||||
args[key] = value;
|
||||
}
|
||||
|
||||
var arg = [];
|
||||
for (var k in args) {
|
||||
arg.push(k+"="+encodeURIComponent(args[k]));
|
||||
}
|
||||
location.search = arg.join("&");
|
||||
},
|
||||
Cookie: function(key, value) {
|
||||
var arg = [];
|
||||
for (var k in args) {
|
||||
arg.push(k+"="+encodeURIComponent(args[k]));
|
||||
}
|
||||
location.search = arg.join("&");
|
||||
},
|
||||
Cookie: function(key, value) {
|
||||
if (key == undefined) {
|
||||
cs = {}
|
||||
cookies = document.cookie.split("; ")
|
||||
@ -49,18 +120,18 @@ context = {
|
||||
return this.Cookie()
|
||||
}
|
||||
|
||||
if (value == undefined) {
|
||||
var pattern = new RegExp(key+"=([^;]*);?");
|
||||
var result = pattern.exec(document.cookie);
|
||||
if (result && result.length > 0) {
|
||||
return result[1];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if (value == undefined) {
|
||||
var pattern = new RegExp(key+"=([^;]*);?");
|
||||
var result = pattern.exec(document.cookie);
|
||||
if (result && result.length > 0) {
|
||||
return result[1];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
document.cookie = key+"="+value+";path=/";
|
||||
return this.Cookie(key);
|
||||
},
|
||||
document.cookie = key+"="+value+";path=/";
|
||||
return this.Cookie(key);
|
||||
},
|
||||
Command: function(cmd, option, cb) {
|
||||
if (typeof option == "function") {
|
||||
cb = option
|
||||
@ -100,7 +171,7 @@ context = {
|
||||
}
|
||||
typeof cb == "function" && cb(that.cache[key])
|
||||
})
|
||||
},
|
||||
},
|
||||
GET: function(url, form, cb) {
|
||||
form = form || {}
|
||||
|
||||
@ -150,227 +221,3 @@ context = {
|
||||
xhr.send(arg);
|
||||
},
|
||||
}
|
||||
|
||||
context.isMobile = navigator.userAgent.indexOf("Mobile") > -1
|
||||
context.scroll_by = window.innerHeight/2
|
||||
|
||||
function right(arg) {
|
||||
if (arg == "true") {
|
||||
return true
|
||||
}
|
||||
if (arg == "false") {
|
||||
return false
|
||||
}
|
||||
if (arg) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
function format_date(arg) {
|
||||
var date = arg.getDate()
|
||||
if (date < 10) {
|
||||
date = "0"+date
|
||||
}
|
||||
var month = arg.getMonth()+1
|
||||
if (month < 10) {
|
||||
month = "0"+month
|
||||
}
|
||||
var hour = arg.getHours()
|
||||
if (hour < 10) {
|
||||
hour = "0"+hour
|
||||
}
|
||||
var minute = arg.getMinutes()
|
||||
if (minute < 10) {
|
||||
minute = "0"+minute
|
||||
}
|
||||
var second = arg.getSeconds()
|
||||
if (second < 10) {
|
||||
second = "0"+second
|
||||
}
|
||||
return arg.getFullYear()+"-"+month+"-"+date+" "+hour+":"+minute+":"+second
|
||||
}
|
||||
|
||||
function modify_node(which, html) {
|
||||
var node = which
|
||||
if (typeof which == "string") {
|
||||
node = document.querySelector(which)
|
||||
}
|
||||
|
||||
html && typeof html == "string" && (node.innerHTML = html)
|
||||
if (html && typeof html == "object") {
|
||||
for (var k in html) {
|
||||
if (typeof html[k] == "object") {
|
||||
for (var d in html[k]) {
|
||||
node[k][d] = html[k][d]
|
||||
}
|
||||
continue
|
||||
}
|
||||
node[k] = html[k]
|
||||
}
|
||||
}
|
||||
return node
|
||||
}
|
||||
function create_node(element, html) {
|
||||
var node = document.createElement(element)
|
||||
return modify_node(node, html)
|
||||
}
|
||||
|
||||
function insert_child(parent, element, html, position) {
|
||||
var elm = create_node(element, html)
|
||||
return parent.insertBefore(elm, position || parent.firstElementChild)
|
||||
}
|
||||
function append_child(parent, element, html) {
|
||||
var elm = create_node(element, html)
|
||||
parent.append(elm)
|
||||
return elm
|
||||
}
|
||||
function insert_before(self, element, html) {
|
||||
var elm = create_node(element, html)
|
||||
return self.parentElement.insertBefore(elm, self)
|
||||
}
|
||||
function insert_button(which, value, callback) {
|
||||
insert_before(which, "input", {
|
||||
"type": "button", "value": value, "onclick": callback,
|
||||
})
|
||||
}
|
||||
|
||||
function format(str) {
|
||||
if (str.indexOf("http") == 0 && str.indexOf("<a href") == -1) {
|
||||
return "<a href='"+str+"' target='_blank'>"+str+"</a>"
|
||||
}
|
||||
return str
|
||||
}
|
||||
function sort_table(table, index, sort_asc) {
|
||||
var list = table.querySelectorAll("tr")
|
||||
var new_list = []
|
||||
|
||||
var is_time = true
|
||||
var is_number = true
|
||||
for (var i = 1; i < list.length; i++) {
|
||||
var value = Date.parse(list[i].childNodes[index].innerText)
|
||||
if (!(value > 0)) {
|
||||
is_time = false
|
||||
}
|
||||
|
||||
var value = parseInt(list[i].childNodes[index].innerText)
|
||||
if (!(value >= 0 || value <= 0)) {
|
||||
is_number = false
|
||||
}
|
||||
|
||||
new_list.push(list[i])
|
||||
}
|
||||
|
||||
var sort_order = ""
|
||||
if (is_time) {
|
||||
if (sort_asc) {
|
||||
method = function(a, b) {return Date.parse(a) > Date.parse(b)}
|
||||
sort_order = "time"
|
||||
} else {
|
||||
method = function(a, b) {return Date.parse(a) < Date.parse(b)}
|
||||
sort_order = "time_r"
|
||||
}
|
||||
} else if (is_number) {
|
||||
if (sort_asc) {
|
||||
method = function(a, b) {return parseInt(a) > parseInt(b)}
|
||||
sort_order = "int"
|
||||
} else {
|
||||
method = function(a, b) {return parseInt(a) < parseInt(b)}
|
||||
sort_order = "int_r"
|
||||
}
|
||||
} else {
|
||||
if (sort_asc) {
|
||||
method = function(a, b) {return a > b}
|
||||
sort_order = "str"
|
||||
} else {
|
||||
method = function(a, b) {return a < b}
|
||||
sort_order = "str_r"
|
||||
}
|
||||
}
|
||||
|
||||
list = new_list
|
||||
new_list = []
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
list[i].parentElement && list[i].parentElement.removeChild(list[i])
|
||||
for (var j = i+1; j < list.length; j++) {
|
||||
if (typeof method == "function" && method(list[i].childNodes[index].innerText, list[j].childNodes[index].innerText)) {
|
||||
var temp = list[i]
|
||||
list[i] = list[j]
|
||||
list[j] = temp
|
||||
}
|
||||
}
|
||||
new_list.push(list[i])
|
||||
}
|
||||
|
||||
for (var i = 0; i < new_list.length; i++) {
|
||||
table.appendChild(new_list[i])
|
||||
}
|
||||
return sort_order
|
||||
}
|
||||
function add_sort(append, field, cb) {
|
||||
append.onclick = function(event) {
|
||||
var target = event.target
|
||||
var dataset = target.dataset
|
||||
var nodes = target.parentElement.childNodes
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
if (nodes[i] == target) {
|
||||
if (target.tagName == "TH") {
|
||||
dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1
|
||||
sort_table(append, i, dataset["sort_asc"] == "1")
|
||||
} else if (target.tagName == "TD") {
|
||||
var tr = target.parentElement.parentElement.querySelector("tr")
|
||||
if (tr.childNodes[i].innerText.startsWith(field)) {
|
||||
typeof cb == "function" && cb(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function scroll_page(event, page) {
|
||||
var body = document.querySelector("body")
|
||||
|
||||
switch (event.key) {
|
||||
case "h":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(-page.scroll_x*10, 0)
|
||||
} else {
|
||||
window.scrollBy(-page.scroll_x, 0)
|
||||
}
|
||||
break
|
||||
case "H":
|
||||
window.scrollBy(-body.scrollWidth, 0)
|
||||
break
|
||||
case "l":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(page.scroll_x*10, 0)
|
||||
} else {
|
||||
window.scrollBy(page.scroll_x, 0)
|
||||
}
|
||||
break
|
||||
case "L":
|
||||
window.scrollBy(body.scrollWidth, 0)
|
||||
break
|
||||
case "j":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(0, page.scroll_y*10)
|
||||
} else {
|
||||
window.scrollBy(0, page.scroll_y)
|
||||
}
|
||||
break
|
||||
case "J":
|
||||
window.scrollBy(0, body.scrollHeight)
|
||||
break
|
||||
case "k":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(0, -page.scroll_y*10)
|
||||
} else {
|
||||
window.scrollBy(0, -page.scroll_y)
|
||||
}
|
||||
break
|
||||
case "K":
|
||||
window.scrollBy(0, -body.scrollHeight)
|
||||
break
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
6
usr/librarys/example.css
Normal file
6
usr/librarys/example.css
Normal file
@ -0,0 +1,6 @@
|
||||
html, body {
|
||||
height:100%;
|
||||
width:100%;
|
||||
margin:0px;
|
||||
background-color:#d8d8d8;
|
||||
}
|
46
usr/librarys/example.js
Normal file
46
usr/librarys/example.js
Normal file
@ -0,0 +1,46 @@
|
||||
exp = example = {
|
||||
__proto__: ctx,
|
||||
_init: function(page) {
|
||||
page.__proto__ = this
|
||||
document.querySelectorAll("body>fieldset").forEach(function(field) {
|
||||
var init = page[field.dataset.init]
|
||||
if (typeof init == "function") {
|
||||
var option = field.querySelector("form.option")
|
||||
var append = field.querySelector("table.append")
|
||||
var result = field.querySelector("div.result")
|
||||
var conf = init(page, field, option, append, result)
|
||||
if (conf && conf["button"]) {
|
||||
var buttons = []
|
||||
conf.button.forEach(function(value, index) {
|
||||
buttons.push({"click": [value, function(event) {
|
||||
typeof conf["action"] == "function" && conf["action"](value, event)
|
||||
}]})
|
||||
})
|
||||
kit.InsertChild(field, append, "div", buttons)
|
||||
}
|
||||
if (conf && conf["table"]) {
|
||||
option.onactions = function(msg) {
|
||||
append.innerHTML = ""
|
||||
kit.AppendTable(append, ctx.PackAppend(msg), msg.append, function(value, key, row, index, event) {
|
||||
typeof conf["table"][key] && conf["table"][key](value, key, row, index, event)
|
||||
})
|
||||
}
|
||||
ctx.Runs(page, option)
|
||||
}
|
||||
}
|
||||
})
|
||||
return this
|
||||
},
|
||||
reload: function() {
|
||||
location.reload()
|
||||
},
|
||||
_exit: function(page) {
|
||||
},
|
||||
}
|
||||
|
||||
function Page(page) {
|
||||
window.onload = function() {
|
||||
page.init(exp._init(page))
|
||||
}
|
||||
return page
|
||||
}
|
314
usr/librarys/toolkit.js
Normal file
314
usr/librarys/toolkit.js
Normal file
@ -0,0 +1,314 @@
|
||||
kit = toolkit = {
|
||||
isMobile: navigator.userAgent.indexOf("Mobile") > -1,
|
||||
ModifyNode: function(which, html) {
|
||||
var node = typeof which == "string"? document.querySelector(which): which
|
||||
switch (typeof html) {
|
||||
case "string":
|
||||
node.innerHTML = html
|
||||
break
|
||||
case "object":
|
||||
for (var k in html) {
|
||||
if (typeof html[k] == "object") {
|
||||
for (var d in html[k]) {
|
||||
node[k][d] = html[k][d]
|
||||
}
|
||||
continue
|
||||
}
|
||||
node[k] = html[k]
|
||||
}
|
||||
break
|
||||
}
|
||||
return node
|
||||
},
|
||||
CreateNode: function(element, html) {
|
||||
return this.ModifyNode(document.createElement(element), html)
|
||||
},
|
||||
AppendChild: function(parent, children, subs) {
|
||||
if (typeof children == "string") {
|
||||
var elm = this.CreateNode(children, subs)
|
||||
parent.append(elm)
|
||||
return elm
|
||||
}
|
||||
|
||||
// code, text, view, click
|
||||
// type, name, data, list
|
||||
|
||||
subs = subs || {}
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i]
|
||||
child.data = child.data || {}
|
||||
child.type = child.type || "div"
|
||||
|
||||
if (child.click) {
|
||||
child.type = "button"
|
||||
child.data["innerText"] = child.click[0]
|
||||
child.data["onclick"] = child.click[1]
|
||||
} else if (child.view) {
|
||||
child.data["className"] = child.view[0]
|
||||
child.type = child.view.length > 1? child.view[1]: "div"
|
||||
child.view.length > 2 && (child.data["innerText"] = child.view[2])
|
||||
} else if (child.text) {
|
||||
child.data["innerText"] = child.text[0]
|
||||
child.type = child.text.length > 1? child.text[1]: "pre"
|
||||
child.text.length > 2 && (child.data["className"] = child.text[2])
|
||||
} else if (child.code) {
|
||||
child.type = "code"
|
||||
child.list = [{"type": "pre" ,"data": {"innerText": child.code[0]}, "name": child.code[1]}]
|
||||
child.code.length > 2 && (child.data["className"] = child.code[2])
|
||||
}
|
||||
|
||||
var node = this.CreateNode(child.type, child.data)
|
||||
child.list && this.AppendChild(node, child.list, subs)
|
||||
child.name && (subs[child.name] = node)
|
||||
parent.append(node)
|
||||
}
|
||||
return subs
|
||||
},
|
||||
InsertChild: function (parent, position, element, children) {
|
||||
var elm = this.CreateNode(element)
|
||||
this.AppendChild(elm, children)
|
||||
return parent.insertBefore(elm, position || parent.firstElementChild)
|
||||
},
|
||||
AppendTable: function(table, data, fields, cb) {
|
||||
if (!data || !fields) {
|
||||
return
|
||||
}
|
||||
var kit = this
|
||||
var tr = kit.AppendChild(table, "tr")
|
||||
fields.forEach(function(key, j) {
|
||||
var td = kit.AppendChild(tr, "th", key)
|
||||
})
|
||||
data.forEach(function(row, i) {
|
||||
var tr = kit.AppendChild(table, "tr")
|
||||
fields.forEach(function(key, j) {
|
||||
var td = kit.AppendChild(tr, "td", row[key])
|
||||
if (typeof cb == "function") {
|
||||
td.onclick = function(event) {
|
||||
cb(row[key], key, row, i, event)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
function right(arg) {
|
||||
if (arg == "true") {
|
||||
return true
|
||||
}
|
||||
if (arg == "false") {
|
||||
return false
|
||||
}
|
||||
if (arg) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
function format_date(arg) {
|
||||
var date = arg.getDate()
|
||||
if (date < 10) {
|
||||
date = "0"+date
|
||||
}
|
||||
var month = arg.getMonth()+1
|
||||
if (month < 10) {
|
||||
month = "0"+month
|
||||
}
|
||||
var hour = arg.getHours()
|
||||
if (hour < 10) {
|
||||
hour = "0"+hour
|
||||
}
|
||||
var minute = arg.getMinutes()
|
||||
if (minute < 10) {
|
||||
minute = "0"+minute
|
||||
}
|
||||
var second = arg.getSeconds()
|
||||
if (second < 10) {
|
||||
second = "0"+second
|
||||
}
|
||||
return arg.getFullYear()+"-"+month+"-"+date+" "+hour+":"+minute+":"+second
|
||||
}
|
||||
|
||||
function modify_node(which, html) {
|
||||
var node = which
|
||||
if (typeof which == "string") {
|
||||
node = document.querySelector(which)
|
||||
}
|
||||
|
||||
html && typeof html == "string" && (node.innerHTML = html)
|
||||
if (html && typeof html == "object") {
|
||||
for (var k in html) {
|
||||
if (typeof html[k] == "object") {
|
||||
for (var d in html[k]) {
|
||||
node[k][d] = html[k][d]
|
||||
}
|
||||
continue
|
||||
}
|
||||
node[k] = html[k]
|
||||
}
|
||||
}
|
||||
return node
|
||||
}
|
||||
function create_node(element, html) {
|
||||
var node = document.createElement(element)
|
||||
return modify_node(node, html)
|
||||
}
|
||||
|
||||
function insert_child(parent, element, html, position) {
|
||||
var elm = create_node(element, html)
|
||||
return parent.insertBefore(elm, position || parent.firstElementChild)
|
||||
}
|
||||
function append_child(parent, element, html) {
|
||||
var elm = create_node(element, html)
|
||||
parent.append(elm)
|
||||
return elm
|
||||
}
|
||||
function insert_before(self, element, html) {
|
||||
var elm = create_node(element, html)
|
||||
return self.parentElement.insertBefore(elm, self)
|
||||
}
|
||||
function insert_button(which, value, callback) {
|
||||
insert_before(which, "input", {
|
||||
"type": "button", "value": value, "onclick": callback,
|
||||
})
|
||||
}
|
||||
|
||||
function format(str) {
|
||||
if (str.indexOf("http") == 0 && str.indexOf("<a href") == -1) {
|
||||
return "<a href='"+str+"' target='_blank'>"+str+"</a>"
|
||||
}
|
||||
return str
|
||||
}
|
||||
function sort_table(table, index, sort_asc) {
|
||||
var list = table.querySelectorAll("tr")
|
||||
var new_list = []
|
||||
|
||||
var is_time = true
|
||||
var is_number = true
|
||||
for (var i = 1; i < list.length; i++) {
|
||||
var value = Date.parse(list[i].childNodes[index].innerText)
|
||||
if (!(value > 0)) {
|
||||
is_time = false
|
||||
}
|
||||
|
||||
var value = parseInt(list[i].childNodes[index].innerText)
|
||||
if (!(value >= 0 || value <= 0)) {
|
||||
is_number = false
|
||||
}
|
||||
|
||||
new_list.push(list[i])
|
||||
}
|
||||
|
||||
var sort_order = ""
|
||||
if (is_time) {
|
||||
if (sort_asc) {
|
||||
method = function(a, b) {return Date.parse(a) > Date.parse(b)}
|
||||
sort_order = "time"
|
||||
} else {
|
||||
method = function(a, b) {return Date.parse(a) < Date.parse(b)}
|
||||
sort_order = "time_r"
|
||||
}
|
||||
} else if (is_number) {
|
||||
if (sort_asc) {
|
||||
method = function(a, b) {return parseInt(a) > parseInt(b)}
|
||||
sort_order = "int"
|
||||
} else {
|
||||
method = function(a, b) {return parseInt(a) < parseInt(b)}
|
||||
sort_order = "int_r"
|
||||
}
|
||||
} else {
|
||||
if (sort_asc) {
|
||||
method = function(a, b) {return a > b}
|
||||
sort_order = "str"
|
||||
} else {
|
||||
method = function(a, b) {return a < b}
|
||||
sort_order = "str_r"
|
||||
}
|
||||
}
|
||||
|
||||
list = new_list
|
||||
new_list = []
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
list[i].parentElement && list[i].parentElement.removeChild(list[i])
|
||||
for (var j = i+1; j < list.length; j++) {
|
||||
if (typeof method == "function" && method(list[i].childNodes[index].innerText, list[j].childNodes[index].innerText)) {
|
||||
var temp = list[i]
|
||||
list[i] = list[j]
|
||||
list[j] = temp
|
||||
}
|
||||
}
|
||||
new_list.push(list[i])
|
||||
}
|
||||
|
||||
for (var i = 0; i < new_list.length; i++) {
|
||||
table.appendChild(new_list[i])
|
||||
}
|
||||
return sort_order
|
||||
}
|
||||
function add_sort(append, field, cb) {
|
||||
append.onclick = function(event) {
|
||||
var target = event.target
|
||||
var dataset = target.dataset
|
||||
var nodes = target.parentElement.childNodes
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
if (nodes[i] == target) {
|
||||
if (target.tagName == "TH") {
|
||||
dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1
|
||||
sort_table(append, i, dataset["sort_asc"] == "1")
|
||||
} else if (target.tagName == "TD") {
|
||||
var tr = target.parentElement.parentElement.querySelector("tr")
|
||||
if (tr.childNodes[i].innerText.startsWith(field)) {
|
||||
typeof cb == "function" && cb(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function scroll_page(event, page) {
|
||||
var body = document.querySelector("body")
|
||||
|
||||
switch (event.key) {
|
||||
case "h":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(-page.scroll_x*10, 0)
|
||||
} else {
|
||||
window.scrollBy(-page.scroll_x, 0)
|
||||
}
|
||||
break
|
||||
case "H":
|
||||
window.scrollBy(-body.scrollWidth, 0)
|
||||
break
|
||||
case "l":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(page.scroll_x*10, 0)
|
||||
} else {
|
||||
window.scrollBy(page.scroll_x, 0)
|
||||
}
|
||||
break
|
||||
case "L":
|
||||
window.scrollBy(body.scrollWidth, 0)
|
||||
break
|
||||
case "j":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(0, page.scroll_y*10)
|
||||
} else {
|
||||
window.scrollBy(0, page.scroll_y)
|
||||
}
|
||||
break
|
||||
case "J":
|
||||
window.scrollBy(0, body.scrollHeight)
|
||||
break
|
||||
case "k":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(0, -page.scroll_y*10)
|
||||
} else {
|
||||
window.scrollBy(0, -page.scroll_y)
|
||||
}
|
||||
break
|
||||
case "K":
|
||||
window.scrollBy(0, -body.scrollHeight)
|
||||
break
|
||||
}
|
||||
return
|
||||
}
|
||||
|
44
usr/librarys/wexin.js
Normal file
44
usr/librarys/wexin.js
Normal file
@ -0,0 +1,44 @@
|
||||
function scan(event) {
|
||||
alert("begin scan")
|
||||
wx.scanQRCode({
|
||||
needResult: 0,
|
||||
scanType: ["qrCode", "barCode"],
|
||||
desc: "what",
|
||||
success: function(res) {
|
||||
alert(res.resultStr)
|
||||
},
|
||||
fail: function(res) {
|
||||
alert(res.errMsg)
|
||||
},
|
||||
})
|
||||
}
|
||||
function close() {
|
||||
wx.closeWindow({
|
||||
success: function(res) {
|
||||
alert(res.resultStr)
|
||||
},
|
||||
fail: function(res) {
|
||||
alert(res.errMsg)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function choose() {
|
||||
wx.chooseImage({
|
||||
count: 1, // 默认9
|
||||
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
||||
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
|
||||
success: function (res) {
|
||||
var localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
|
||||
},
|
||||
fail: function(res) {
|
||||
alert(res.errMsg)
|
||||
},
|
||||
});
|
||||
}
|
||||
function wopen(event) {
|
||||
wx.openAddress({success: function(res) {
|
||||
context.Command("show", res)
|
||||
}})
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ function init_link() {
|
||||
})
|
||||
}
|
||||
function init_code() {
|
||||
var fuck = context.isMobile? 22: 16
|
||||
var fuck = kit.isMobile? 22: 16
|
||||
|
||||
document.querySelectorAll("article pre").forEach(function(item, i) {
|
||||
var nu = insert_before(item, "div", {"className": "number1"})
|
||||
@ -181,8 +181,8 @@ function init_code() {
|
||||
for (var j = 1; j <= line; j++) {
|
||||
append_child(nu, "div", {
|
||||
"style": {
|
||||
"fontSize": context.isMobile?"20px":"14px",
|
||||
"lineHeight": context.isMobile?"22px":"16px",
|
||||
"fontSize": kit.isMobile?"20px":"14px",
|
||||
"lineHeight": kit.isMobile?"22px":"16px",
|
||||
},
|
||||
"id": "code"+i+"_"+"line"+j,
|
||||
"onclick": function(event) {
|
||||
|
@ -4,23 +4,9 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=0.7">
|
||||
<link rel="shortcut icon" type="image/ico" href="/favicon.ico">
|
||||
<title>code</title>
|
||||
<style>
|
||||
html, body {
|
||||
height:100%;
|
||||
width:100%;
|
||||
margin:0px;
|
||||
background-color:#d8d8d8;
|
||||
}
|
||||
fieldset {
|
||||
margin-top:8px;
|
||||
}
|
||||
legend {
|
||||
font-size:16px;
|
||||
font-weight:bold;
|
||||
font-family:monospace;
|
||||
}
|
||||
</style>
|
||||
<title>{{option . "componet_name"}}</title>
|
||||
<link rel="stylesheet" type="text/css" href="/static/librarys/example.css"></link>
|
||||
<link rel="stylesheet" type="text/css" href="/static/librarys/code.css"></link>
|
||||
<style>
|
||||
{{$toolkit_view := conf . "route" "toolkit_view"}}
|
||||
div.workflow {
|
||||
@ -55,97 +41,6 @@
|
||||
div.workflow li>input {
|
||||
background-color:rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
|
||||
form.option div {
|
||||
float:left;
|
||||
}
|
||||
textarea.clipboard {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
width:600px;
|
||||
}
|
||||
form.option div {
|
||||
float:left;
|
||||
}
|
||||
form.option hr {
|
||||
clear:both;
|
||||
}
|
||||
form.option label.keymap {
|
||||
color:red;
|
||||
display:none;
|
||||
}
|
||||
form.option label.keymap.show {
|
||||
display:inline;
|
||||
}
|
||||
form.option input {
|
||||
margin-right:10px;
|
||||
}
|
||||
form.option input.cmd {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
padding-left:10px;
|
||||
width:600px;
|
||||
}
|
||||
form.option input.file_cmd {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
padding-left:10px;
|
||||
width:400px;
|
||||
}
|
||||
form.option input.file_name {
|
||||
width:200px;
|
||||
}
|
||||
form.option.exec input {
|
||||
color:white;
|
||||
background-color:#272822;
|
||||
padding-left:10px;
|
||||
width:600px;
|
||||
}
|
||||
form.option select {
|
||||
margin-right:10px;
|
||||
}
|
||||
table.append {
|
||||
font-size:14px;
|
||||
overflow: auto;
|
||||
}
|
||||
table.append tr:hover {
|
||||
background-color:lightgreen;
|
||||
}
|
||||
table.append th {
|
||||
font-family:monospace;
|
||||
background-color:lightgreen;
|
||||
cursor:pointer;
|
||||
}
|
||||
table.append th.order {
|
||||
background-color:red;
|
||||
cursor:pointer;
|
||||
}
|
||||
table.append td {
|
||||
max-width:1200px;
|
||||
font-family:monospace;
|
||||
padding-left: 10px;
|
||||
padding-right: 20px;
|
||||
}
|
||||
table.append td.clip {
|
||||
background-color:red;
|
||||
}
|
||||
table.append td:hover {
|
||||
background-color:red;
|
||||
}
|
||||
code.result pre {
|
||||
color:white;
|
||||
font-size:14px;
|
||||
background-color:#272822;
|
||||
overflow:scroll;
|
||||
padding:5px;
|
||||
border:solid 2px green;
|
||||
border-left:solid 4px green;
|
||||
margin:0;
|
||||
}
|
||||
code.result pre.clipboard {
|
||||
height:2em;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body onkeydown="return onaction(event, 'scroll')" onkeyup="return onaction(event, 'keymap')">
|
||||
@ -155,13 +50,6 @@
|
||||
</script>
|
||||
{{end}}
|
||||
|
||||
{{define "void"}}{{end}}
|
||||
|
||||
{{define "detail"}}{{detail .}}{{end}}
|
||||
{{define "option"}}{{option .}}{{end}}
|
||||
{{define "append"}}{{append .}}{{end}}
|
||||
{{define "result"}}{{result .}}{{end}}
|
||||
|
||||
{{define "clipboard"}}
|
||||
<fieldset><legend>clipboard</legend>
|
||||
<datalist id="clipstack"></datalist>
|
||||
@ -212,19 +100,18 @@
|
||||
{{end}}
|
||||
|
||||
{{define "componet"}}
|
||||
<fieldset><legend title="{{option .Meta "help"}}">{{option .Meta "name"}}({{option .Meta "help"}})</legend>
|
||||
{{$form_type := option . "form_type"|meta}}
|
||||
<fieldset class="{{option . "componet_view"|meta}}" data-init="{{option . "componet_init"|meta}}">
|
||||
<legend title="{{option .Meta "help"}}">{{option .Meta "name"}}({{option .Meta "help"}})</legend>
|
||||
{{$msg := .}}
|
||||
{{$form_type := option . "form_type"|meta}}
|
||||
|
||||
<form class="option {{option .Meta "componet_name"}}"
|
||||
data-componet_group="{{option . "componet_group"|meta}}"
|
||||
data-componet_name="{{option . "componet_name"|meta}}"
|
||||
{{if eq $form_type "upload"}}
|
||||
method="POST" action="/upload" enctype="multipart/form-data"
|
||||
onsubmit="onaction(event, 'upload')"
|
||||
target="_blank"
|
||||
{{end}}
|
||||
>
|
||||
method="POST" action="/upload" enctype="multipart/form-data" target="_blank"
|
||||
{{end}}>
|
||||
|
||||
<input style="display:none"></input>
|
||||
{{range $index, $input := option . "inputs"}}
|
||||
<div>
|
||||
@ -233,6 +120,7 @@
|
||||
{{if index $input "label"}}
|
||||
<label>{{index $input "label"}} : </label>
|
||||
{{end}}
|
||||
|
||||
{{if eq $type "button"}}
|
||||
<input type="button" onclick="return onaction(event, 'cmd')" value="{{$value}}">
|
||||
{{else if eq $type "submit"}}
|
||||
@ -259,6 +147,14 @@
|
||||
class="{{index $input "class"}}"
|
||||
onclick="return onaction(event, 'click')"
|
||||
onkeyup="return onaction(event, 'input')">
|
||||
{{else if eq $type "textarea"}}
|
||||
<textarea
|
||||
rows="{{index $input "rows"}}"
|
||||
cols="{{index $input "cols"}}"
|
||||
name="{{index $input "name"}}"
|
||||
class="{{index $input "class"}}"
|
||||
onclick="return onaction(event, 'click')"
|
||||
onkeyup="return onaction(event, 'input')">{{$value}}</textarea>
|
||||
{{else}}
|
||||
<input
|
||||
name="{{index $input "name"}}"
|
||||
@ -276,12 +172,8 @@
|
||||
{{end}}
|
||||
<hr/>
|
||||
</form>
|
||||
{{if eq $form_type "upload"}}
|
||||
{{end}}
|
||||
|
||||
{{if index .Meta "display_append"}}
|
||||
{{option .Meta "display_append"}}
|
||||
{{else}}
|
||||
{{if index .Meta "display_append"}} {{option .Meta "display_append"}} {{else}}
|
||||
<table class="append {{option .Meta "componet_name"}}">
|
||||
{{$msg := .}}
|
||||
<tr>{{range $field := append .}}<th>{{$field}}</th>{{end}}</tr>
|
||||
@ -290,17 +182,18 @@
|
||||
{{end}}
|
||||
</table>
|
||||
{{end}}
|
||||
|
||||
{{if index .Meta "display_result"}}
|
||||
{{option .Meta "display_result"}}
|
||||
{{else}}
|
||||
{{if index .Meta "display_result"}} {{option .Meta "display_result"}} {{else}}
|
||||
<code class="result {{option .Meta "componet_name"}}"><pre>{{result .Meta}}</pre></code>
|
||||
{{end}}
|
||||
{{if index .Meta "display_div"}} {{option .Meta "display_div"}} {{else}}
|
||||
<div class="result {{option .Meta "componet_name"}}"></div>
|
||||
{{end}}
|
||||
</fieldset>
|
||||
{{end}}
|
||||
|
||||
{{define "mp"}}
|
||||
<script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
|
||||
<script src="/static/librarys/wexin.js"></script>
|
||||
<script>
|
||||
{{$token := cmd . "context chat js_token"}}
|
||||
wx.config({
|
||||
@ -316,59 +209,15 @@ wx.config({
|
||||
"openAddress",
|
||||
],
|
||||
})
|
||||
wx.ready(function(){
|
||||
})
|
||||
wx.error(function(res){
|
||||
})
|
||||
|
||||
function scan(event) {
|
||||
alert("begin scan")
|
||||
wx.scanQRCode({
|
||||
needResult: 0,
|
||||
scanType: ["qrCode", "barCode"],
|
||||
desc: "what",
|
||||
success: function(res) {
|
||||
alert(res.resultStr)
|
||||
},
|
||||
fail: function(res) {
|
||||
alert(res.errMsg)
|
||||
},
|
||||
})
|
||||
}
|
||||
function close() {
|
||||
wx.closeWindow({
|
||||
success: function(res) {
|
||||
alert(res.resultStr)
|
||||
},
|
||||
fail: function(res) {
|
||||
alert(res.errMsg)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function choose() {
|
||||
wx.chooseImage({
|
||||
count: 1, // 默认9
|
||||
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
|
||||
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
|
||||
success: function (res) {
|
||||
var localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
|
||||
},
|
||||
fail: function(res) {
|
||||
alert(res.errMsg)
|
||||
},
|
||||
});
|
||||
}
|
||||
function wopen(event) {
|
||||
wx.openAddress({success: function(res) {
|
||||
context.Command("show", res)
|
||||
}})
|
||||
}
|
||||
wx.ready(function(){})
|
||||
wx.error(function(res){})
|
||||
</script>
|
||||
{{end}}
|
||||
|
||||
{{define "tail"}}
|
||||
<script src="/static/librarys/toolkit.js"></script>
|
||||
<script src="/static/librarys/context.js"></script>
|
||||
<script src="/static/librarys/example.js"></script>
|
||||
<script src="/static/librarys/code.js"></script>
|
||||
</body>
|
||||
{{end}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user