1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-26 01:04:06 +08:00

opt toolkit.js

This commit is contained in:
shaoying 2019-09-11 23:00:07 +08:00
parent 6b6d1f3b8c
commit 2bdd44814e
15 changed files with 233 additions and 285 deletions

View File

@ -1,7 +1,8 @@
package cli
var Template = []interface{}{
map[string]interface{}{"name": "index.go", "text": `package main
map[string]interface{}{"name": "index.go", "text":
`package main
import (
"contexts/cli"
@ -17,7 +18,7 @@ var Index = &ctx.Context{Name: "test", Help: "测试工具",
Configs: map[string]*ctx.Config{
"_index": &ctx.Config{Name: "index", Value: []interface{}{
map[string]interface{}{"name": "demo", "help": "demo",
"tmpl": "componet", "view": "componet", "init": "",
"tmpl": "componet", "view": "", "init": "",
"type": "public", "ctx": "demo", "cmd": "demo",
"args": []interface{}{}, "inputs": []interface{}{
map[string]interface{}{"type": "text", "name": "pod", "value": "hello world"},
@ -37,16 +38,20 @@ var Index = &ctx.Context{Name: "test", Help: "测试工具",
func main() {
fmt.Print(cli.Index.Plugin(Index, os.Args[1:]))
}
`}, map[string]interface{}{"name": "index.shy", "text": `
fun hello world "" "" \
public \
`}, map[string]interface{}{"name": "index.shy", "text":
`fun hello world "" "" public \
text "" \
button "执行"
copy pwd
end
`}, map[string]interface{}{"name": "index.js", "text": `
{init: function(page, pane, field, option, output) {
kit.Log("hello world")
}}
`}, map[string]interface{}{"name": "local.shy", "text": ` `},
`}, map[string]interface{}{"name": "index.css", "text":
`fieldset.item.demo div.output {
}
`}, map[string]interface{}{"name": "index.js", "text":
`{init: function(run, field, option, output) {
kit.Log("hello world")
return {}
}}
`}, map[string]interface{}{"name": "local.shy", "text":
``},
}

View File

@ -4,5 +4,5 @@ var version = struct {
host string
self int
}{
"2019-09-10 22:40:18", "com.mac", 491,
"2019-09-11 22:06:20", "centos", 522,
}

View File

@ -347,7 +347,10 @@ func (m *Message) Set(meta string, arg ...interface{}) *Message {
}
case "option", "append":
if len(arg) > 0 {
delete(m.Meta, kit.Format(arg[0]))
for _, k := range arg {
delete(m.Data, kit.Format(k))
delete(m.Meta, kit.Format(k))
}
} else {
for _, k := range m.Meta[meta] {
delete(m.Data, k)

View File

@ -360,7 +360,8 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
args = append(args, msg.Parse(v))
}
}
m.Log("time", "check: %v", m.Format("cost"))
msg.Log("time", "check: %v", m.Format("cost"))
msg.Log("time", "check: %v %v %v", tool["componet_cmd"], args, arg)
msg.Cmd(tool["componet_cmd"], args, arg).CopyTo(m)
default:
@ -371,7 +372,6 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
m.Push("name", value["componet_name"])
m.Push("help", value["componet_help"])
m.Push("view", value["componet_view"])
if kit.Right(value["componet_init"]) {
script := m.Cmdx("nfs.load", path.Join(m.Conf("cli.project", "plugin.path"), arg[0], kit.Format(value["componet_init"])), -1)
if script == "" {
@ -381,6 +381,15 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
} else {
m.Push("init", "")
}
if kit.Right(value["componet_view"]) {
script := m.Cmdx("nfs.load", path.Join(m.Conf("cli.project", "plugin.path"), arg[0], kit.Format(value["componet_view"])), -1)
if script == "" {
script = m.Cmdx("nfs.load", path.Join("usr/librarys/plugin", kit.Format(value["componet_view"])), -1)
}
m.Push("view", script)
} else {
m.Push("view", "")
}
m.Push("inputs", kit.Format(value["inputs"]))
m.Push("feature", kit.Format(value["feature"]))
m.Push("exports", kit.Format(value["exports"]))

View File

@ -1094,7 +1094,7 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
p.Data = self
return
}},
"kit": &ctx.Command{Name: "kit name help [init [show]] [public|protected|private] cmd arg... [input value [key val]...]...", Help: "小功能", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
"kit": &ctx.Command{Name: "kit name help [init [view]] [public|protected|private] cmd arg... [input value [key val]...]...", Help: "小功能", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Log("info", "_index: %v", arg)
args := []interface{}{}
@ -1102,18 +1102,18 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
exports := []interface{}{}
feature := map[string]interface{}{}
view, init, show, cmd := "", "", "", ""
init, view, right, cmd := "", "", "", ""
begin := 3
switch arg[3] {
case "private", "protected", "public":
begin, show, cmd = 5, arg[3], arg[4]
begin, right, cmd = 5, arg[3], arg[4]
default:
switch arg[4] {
case "private", "protected", "public":
begin, init, show, cmd = 6, arg[3], arg[4], arg[5]
begin, init, right, cmd = 6, arg[3], arg[4], arg[5]
default:
begin, init, view, show, cmd = 7, arg[3], arg[4], arg[5], arg[6]
begin, init, view, right, cmd = 7, arg[3], arg[4], arg[5], arg[6]
}
}
@ -1172,7 +1172,7 @@ var Index = &ctx.Context{Name: "yac", Help: "语法中心",
"componet_help": kit.Select("", arg, 2),
"componet_view": view,
"componet_init": init,
"componet_type": show,
"componet_type": right,
"componet_ctx": m.Cap("module"),
"componet_cmd": cmd,

View File

@ -298,6 +298,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
// 命令列表
m.Set("option", "name")
m.Set("option", "init")
m.Set("option", "view")
if len(arg) == 1 {
m.Confm("flow", []string{rid, "tool", arg[0], "list"}, func(index int, tool map[string]interface{}) {
m.Push("river", rid)

View File

@ -0,0 +1,5 @@
fieldset.item.mind div.output table td {
text-align:center;
min-width:16px;
height:16px;
}

View File

@ -15,14 +15,6 @@ var Index = &ctx.Context{Name: "mind", Help: "思维导图",
Configs: map[string]*ctx.Config{},
Commands: map[string]*ctx.Command{
"doc": {Name: "doc", Help: "文档", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
switch len(arg) {
case 0:
m.Cmdy("ssh.data", "show", "doc")
case 1:
m.Cmdy("ssh.data", "show", "doc", arg[0])
case 2:
m.Cmdy("ssh.data", "insert", "doc", "title", arg[0], "content", arg[1])
}
return
}},
"xls": {Name: "xls", Help: "表格", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
@ -74,7 +66,6 @@ var Index = &ctx.Context{Name: "mind", Help: "思维导图",
return
}},
"ppt": {Name: "ppt", Help: "文稿", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
m.Echo(kit.Select("hello world", arg, 0))
return
}},
},

View File

@ -1,71 +1,56 @@
{init: function(run, field, option, output) {
return {
ondaemon: {
table: function(msg, cb) {
if (msg.event.type == "blur") {return}
var plugin = field.Plugin
output.innerHTML = "", msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), "", function(event, value, name, line, index) {
if (name == "id") {
page.Sync("plugin_"+plugin.exports[0]).set(plugin.onexport[plugin.exports[2]||""](value, name, line))
} else {
var td = event.target
function submit(event) {
td.innerText = event.target.value
if (event.target.value != value) {
plugin.Run(event, [option.title.value, name, index-1, event.target.value], function() {
plugin.Check()
})
}
{init: function(run, field, option, output) {return {
ondaemon: {
table: function(msg, cb) {if (msg.event.type == "blur") {return}
var plugin = field.Plugin
output.innerHTML = "", msg.append && kit.OrderTable(kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append), "", function(event, value, name, line, index) {
if (name == "id") {
page.Sync("plugin_"+plugin.exports[0]).set(plugin.onexport[plugin.exports[2]||""](value, name, line))
} else {
var td = event.target
function submit(event) {
(td.innerText = event.target.value) != value && plugin.Run(event, [option.title.value, name, index-1, event.target.value], plugin.Check)
}
kit.AppendChilds(td, [{type: "input", value: value, data: {onblur: submit, onkeyup: function(event) {
switch (event.key) {
case "Enter":
case "Tab":
break
default:
return
}
kit.AppendChilds(td, [{type: "input", value: value, data: {onblur: function(event) {
submit(event)
}, onkeyup: function(event) {
switch (event.key) {
case "Enter":
break
case "Tab":
break
default:
return
}
event.stopPropagation()
event.preventDefault()
}, onkeydown: function(event) {
console.log(event.key)
switch (event.key) {
case "Enter":
if (event.shiftKey) {
event.stopPropagation()
event.preventDefault()
}, onkeydown: function(event) {
switch (event.key) {
case "Enter":
td.parentNode[event.shiftKey?"previousSibling":"nextSibling"].querySelector("td").click()
break
case "Tab":
if (event.shiftKey) {
if (td.previousSibling) {
td.previousSibling.click()
} else {
td.parentNode.previousSibling.querySelector("td").click()
}
} else {
if (td.nextSibling) {
td.nextSibling.click()
} else {
td.parentNode.nextSibling.querySelector("td").click()
}
break
case "Tab":
if (event.shiftKey) {
if (td.previousSibling) {
td.previousSibling.click()
} else {
td.parentNode.previousSibling.querySelector("td").click()
}
} else {
if (td.nextSibling) {
td.nextSibling.click()
} else {
td.parentNode.nextSibling.querySelector("td").click()
}
}
break
default:
return
}
event.stopPropagation()
event.preventDefault()
}}}]).first.focus()
}
})
typeof cb == "function" && cb(msg)
},
}
break
default:
return
}
event.stopPropagation()
event.preventDefault()
}}}]).first.focus()
}
}), typeof cb == "function" && cb(msg)
},
}
}}
},
}}}

View File

@ -1,15 +1,7 @@
kit doc "文档" private \
text "" name title imports plugin_doc_id action auto \
text "" name content \
button "执行" \
button "返回" click Last \
exports doc_id id
kit xls "表格" "index.js" private \
kit xls "表格" "index.js" "index.css" private \
text "" name title imports plugin_xls_id action auto \
text "" name content \
button "执行" \
button "返回" click Last \
feature style "output full" \
feature style "mind" \
exports xls_id id

View File

@ -6,7 +6,7 @@ var page = Page({
kit.isWindows && (document.body.style.overflow = "hidden")
var height = document.body.clientHeight-page.conf.border
var width = document.body.clientWidth-page.conf.border-2
var width = document.body.clientWidth-page.conf.border
page.conf.height = height
page.conf.width = width
@ -586,6 +586,8 @@ var page = Page({
page.onaction[item] && page.onaction[item](event, item, value, page)
})
page.river.Pane.Show(), page.pane = page.action, page.plugin = kit.Selector(page.action, "fieldset")[0]
page.action.Pane.Layout(ctx.Search("layout")? ctx.Search("layout"): kit.isMobile? "办公": "工作")
page.onlayout(event)
page.action.Pane.Layout(ctx.Search("layout")? ctx.Search("layout"): kit.device.isMobile? "办公": "工作")
page.onlayout(event)
},
})

View File

@ -227,6 +227,9 @@ fieldset.Footer>div.output div.state div {
fieldset.item {
float:left;
}
fieldset.item.select {
background-color:gold;
}
fieldset.item>div.output {
overflow:auto;
}
@ -253,13 +256,6 @@ fieldset.item>div.output>div.status>input.cmd {
font-size:16px;
width:250px;
}
fieldset.item div.output.full table td {
height:16px;
}
fieldset.item.select {
background-color:gold;
}
fieldset table {
font-size:14px;
@ -287,7 +283,6 @@ fieldset table th.order {
cursor:pointer;
}
fieldset table td {
min-height:16px;
max-width:1200px;
font-family:monospace;
padding-left: 10px;

View File

@ -79,11 +79,12 @@ function Meta(target, obj) {
return {}
}
var id = "plugin"+this.ID()
list.push({view: [text.view+" item", "fieldset", "", "field"], data: {id: id, Run: cb}, list: [
list.push({view: ["item", "fieldset", "", "field"], data: {id: id, Run: cb}, list: [
{text: [text.name+"("+text.help+")", "legend"]},
{view: ["option", "form", "", "option"], list: [{type: "input", style: {"display": "none"}}]},
{view: ["output", "div", "", "output"]},
{script: ""+id+".Script="+(text.init||"{}")},
{styles: text.view},
]})
break
}
@ -143,7 +144,7 @@ function Page(page) {
}
if (page.check) {
false && kit.isWeiXin? page.login.Pane.Run(["weixin"], function(msg) {
false && kit.device.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",
@ -578,8 +579,8 @@ function Pane(page, field) {
})
},
Select: function(index, key) {
-1 < last && last < list.length && (list[last].className = "item")
last = index, list[index] && (list[index].className = "item select")
-1 < last && last < list.length && (kit.classList.del(list[last], "select"))
last = index, list[index] && (kit.classList.add(list[index], "select"))
key && pane.which.set(key)
},
clear: function() {
@ -685,10 +686,6 @@ function Pane(page, field) {
return page[name] = field, pane.Field = field, field.Pane = pane
}
function Plugin(page, pane, field, runs) {
var run = function(event, cmds, cbs) {
event.Plugin = plugin, runs(event, cmds, cbs)
}
var option = field.querySelector("form.option")
var action = field.querySelector("div.action")
var output = field.querySelector("div.output")
@ -697,14 +694,16 @@ function Plugin(page, pane, field, runs) {
var name = meta.name
var args = meta.args || []
var inputs = JSON.parse(meta.inputs || "[]")
var display = JSON.parse(meta.display||'{}')
var feature = JSON.parse(meta.feature||'{}')
var display = JSON.parse(meta.display||'{}')
var exports = JSON.parse(meta.exports||'["",""]')
var deal = (feature && feature.display) || "table"
var history = []
output.className = (feature.style || "") + " output"
kit.classList.add(field, feature.style)
var history = []
var run = function(event, cmds, cbs) {
event.Plugin = plugin, runs(event, cmds, cbs)
}
var plugin = Meta(field, (field.Script && field.Script.init || function() {
})(run, field, option, output)||{}, {
Append: function(item, name, value) {
@ -733,6 +732,7 @@ function Plugin(page, pane, field, runs) {
case "textarea":
input.type = "textarea", item.style = "height:100px;"+"width:"+(pane.target.clientWidth-30)+"px"
item.className = "args"
// no break
case "text":
item.className = "args"
item.autocomplete = "off"
@ -763,8 +763,8 @@ function Plugin(page, pane, field, runs) {
field.parentNode.removeChild(field)
},
Select: function(silent) {
page.plugin && (page.plugin.className = "item")
page.plugin = field, field.className = "item select"
page.plugin && (kit.classList.del(page.plugin, "select"))
page.plugin = field, kit.classList.add(field, "select")
!silent && (option.querySelectorAll("input")[1].focus())
},
Reveal: function(msg) {
@ -938,7 +938,7 @@ function Plugin(page, pane, field, runs) {
action.target.value = kit.History.get("txt", -1).data.trim()
},
onchange: function(event, action, type, name, item) {
plugin.Check(item.action == "auto"? undefined: action)
type == "select" && plugin.Check(item.action == "auto"? undefined: action)
},
onkeyup: function(event, action, type, name, item) {
switch (event.key) {
@ -1012,8 +1012,6 @@ function Plugin(page, pane, field, runs) {
exports: JSON.parse(meta.exports||'["",""]'),
})
inputs.map(function(item) {
plugin.Append(item, item.name, item.value)
})
inputs.map(plugin.Append)
return page[field.id] = pane[field.id] = pane[name] = field, field.Plugin = plugin
}

View File

@ -1,11 +1,35 @@
kit = toolkit = {
isMobile: navigator.userAgent.indexOf("Mobile") > -1,
isWeiXin: navigator.userAgent.indexOf("MicroMessenger") > -1,
isMacOSX: navigator.userAgent.indexOf("Mac OS X") > -1,
isWindows: navigator.userAgent.indexOf("Windows") > -1,
isIPhone: navigator.userAgent.indexOf("iPhone") > -1,
isSpace: function(c) {
return c == " " || c == "Enter"
// 用户终端
device: {
isWeiXin: navigator.userAgent.indexOf("MicroMessenger") > -1,
isMobile: navigator.userAgent.indexOf("Mobile") > -1,
isIPhone: navigator.userAgent.indexOf("iPhone") > -1,
isMacOSX: navigator.userAgent.indexOf("Mac OS X") > -1,
isWindows: navigator.userAgent.indexOf("Windows") > -1,
},
alert: function(text) {
alert(JSON.stringify(text))
},
prompt: function(text) {
return prompt(text)
},
confirm: function(text) {
return confirm(text)
},
reload: function() {
location.reload()
},
// 操作日志
Log: function() {
var args = []
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i])
}
console.log(arguments.length == 1? args[0]: args)
return args
},
Delay: function(time, cb) {
return setTimeout(cb, time)
},
History: {dir: [], pod: [], ctx: [], cmd: [], txt: [], key: [], lay: [],
add: function(type, data) {
@ -20,18 +44,28 @@ kit = toolkit = {
return index == undefined? this[type]: this[type][(index+len)%len]
},
},
Log: function() {
var args = []
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i])
}
console.log(arguments.length == 1? args[0]: args)
return args
},
Delay: function(time, cb) {
return setTimeout(cb, time)
},
// HTML节点操作
classList: {
add: function(obj) {
var list = obj.className.split(" ")
for (var i = 1; i < arguments.length; i++) {
list.push(arguments[i])
}
return obj.className = list.join(" ")
},
del: function(obj) {
var res = []
var list = arguments
obj.className.split(" ").forEach(function(item) {
for (var i = 1; i < list.length; i++) {
if (item == list[i]) {return}
}
res.push(item)
})
return obj.className = res.join(" ")
},
},
ModifyView: function(which, args) {
var height = document.body.clientHeight-4
var width = document.body.clientWidth-4
@ -267,16 +301,20 @@ kit = toolkit = {
} else if (child.styles) {
var str = []
for (var key in child.styles) {
str.push(key)
str.push(" {")
for (var k in child.styles[key]) {
str.push(k)
str.push(":")
str.push(child.styles[key][k] + (typeof child.styles[key][k] == "number"? "px": ""))
str.push(";")
if (typeof child.styles == "string") {
str.push(child.styles)
} else {
for (var key in child.styles) {
str.push(key)
str.push(" {")
for (var k in child.styles[key]) {
str.push(k)
str.push(":")
str.push(child.styles[key][k] + (typeof child.styles[key][k] == "number"? "px": ""))
str.push(";")
}
str.push("}\n")
}
str.push("}\n")
}
child.data["innerHTML"] = str.join("")
child.data["type"] = "text/css"
@ -301,7 +339,7 @@ kit = toolkit = {
this.AppendChild(elm, children)
return parent.insertBefore(elm, position || parent.firstElementChild)
},
// HTML控件操作
AppendAction: function(parent, list, cb) {
var result = []
list.forEach(function(item, index) {
@ -411,8 +449,8 @@ kit = toolkit = {
var target = event.target
var dataset = target.dataset
var head = target.parentElement.parentElement.querySelector("tr")
kit.Selector(table, "tr.select", function(item) {item.className = ""})
kit.Selector(table, "td.select", function(item) {item.className = ""})
// kit.Selector(table, "tr.select", function(item) {item.className = ""})
// kit.Selector(table, "td.select", function(item) {item.className = ""})
kit.Selector(table, "tr", function(item, i) {item == target.parentElement && (index = i)})
target.parentElement.childNodes.forEach(function(item, i) {
@ -425,8 +463,8 @@ kit = toolkit = {
}
var name = head.childNodes[i].innerText
if (name.startsWith(field)) {
item.className = "select"
item.parentElement.className = "select"
// item.className = "select"
// item.parentElement.className = "select"
typeof cb == "function" && cb(event, item.innerText, name, item.parentNode.Meta, index)
}
kit.CopyText()
@ -434,6 +472,18 @@ kit = toolkit = {
}
},
// HTML显示文本
Color: function(s) {
s = s.replace(/\033\[1m/g, "<span style='font-weight:bold'>")
s = s.replace(/\033\[36m/g, "<span style='color:#0ff'>")
s = s.replace(/\033\[33m/g, "<span style='color:#ff0'>")
s = s.replace(/\033\[32m/g, "<span style='color:#0f0'>")
s = s.replace(/\033\[32;1m/g, "<span style='color:#0f0'>")
s = s.replace(/\033\[31m/g, "<span style='color:#f00'>")
s = s.replace(/\033\[0m/g, "</span>")
s = s.replace(/\033\[m/g, "</span>")
return s
},
OrderCode: function(code) {
if (!code) {return}
@ -497,18 +547,7 @@ kit = toolkit = {
Position: function(which) {
return (parseInt((which.scrollTop + which.clientHeight) / which.scrollHeight * 100)||0)+"%"
},
Color: function(s) {
s = s.replace(/\033\[1m/g, "<span style='font-weight:bold'>")
s = s.replace(/\033\[36m/g, "<span style='color:#0ff'>")
s = s.replace(/\033\[33m/g, "<span style='color:#ff0'>")
s = s.replace(/\033\[32m/g, "<span style='color:#0f0'>")
s = s.replace(/\033\[32;1m/g, "<span style='color:#0f0'>")
s = s.replace(/\033\[31m/g, "<span style='color:#f00'>")
s = s.replace(/\033\[0m/g, "</span>")
s = s.replace(/\033\[m/g, "</span>")
return s
},
// HTML输入文本
CopyText: function(text) {
text = window.getSelection().toString()
if (text == "") {return}
@ -530,6 +569,7 @@ kit = toolkit = {
return true
},
// 数据容器迭代
Selector: function(obj, item, cb) {
var list = []
obj.querySelectorAll(item).forEach(function(item, index, array) {
@ -549,10 +589,6 @@ kit = toolkit = {
}
return list
},
Format: function(objs) {
return JSON.stringify(objs)
wa
},
List: function(obj, cb, interval, cbs) {
if (interval) {
function loop(i) {
@ -576,21 +612,21 @@ kit = toolkit = {
}
return list
},
alert: function(text) {
alert(JSON.stringify(text))
// 数据类型转换
isSpace: function(c) {
return c == " " || c == "Enter"
},
prompt: function(text) {
return prompt(text)
},
confirm: function(text) {
return confirm(text)
},
reload: function() {
location.reload()
},
distance: function(x0, y0, x1, y1) {
return Math.sqrt(Math.pow(x1-x0, 2)+Math.pow(y1-y0, 2))
right: function(arg) {
if (arg == "true") {
return true
}
if (arg == "false") {
return false
}
if (arg) {
return true
}
return false
},
number: function(d, n) {
var result = []
@ -606,28 +642,8 @@ kit = toolkit = {
result.reverse()
return result.join("")
},
right: function(arg) {
if (arg == "true") {
return true
}
if (arg == "false") {
return false
}
if (arg) {
return true
}
return false
},
time: function(t, fmt) {
var now = t? new Date(t): new Date()
fmt = fmt || "%y-%m-%d %H:%M:%S"
fmt = fmt.replace("%y", now.getFullYear())
fmt = fmt.replace("%m", kit.number(now.getMonth()+1, 2))
fmt = fmt.replace("%d", kit.number(now.getDate(), 2))
fmt = fmt.replace("%H", kit.number(now.getHours(), 2))
fmt = fmt.replace("%M", kit.number(now.getMinutes(), 2))
fmt = fmt.replace("%S", kit.number(now.getSeconds(), 2))
return fmt
distance: function(x0, y0, x1, y1) {
return Math.sqrt(Math.pow(x1-x0, 2)+Math.pow(y1-y0, 2))
},
format_date: function(arg) {
var date = arg.getDate()
@ -652,6 +668,20 @@ kit = toolkit = {
}
return arg.getFullYear()+"-"+month+"-"+date+" "+hour+":"+minute+":"+second
},
Format: function(objs) {
return JSON.stringify(objs)
},
time: function(t, fmt) {
var now = t? new Date(t): new Date()
fmt = fmt || "%y-%m-%d %H:%M:%S"
fmt = fmt.replace("%y", now.getFullYear())
fmt = fmt.replace("%m", kit.number(now.getMonth()+1, 2))
fmt = fmt.replace("%d", kit.number(now.getDate(), 2))
fmt = fmt.replace("%H", kit.number(now.getHours(), 2))
fmt = fmt.replace("%M", kit.number(now.getMinutes(), 2))
fmt = fmt.replace("%S", kit.number(now.getSeconds(), 2))
return fmt
},
size: function(obj, width, height) {
obj.style.width = width+"px"
obj.style.height = height+"px"
@ -670,73 +700,6 @@ kit = toolkit = {
}
return res || true
},
OrderForm: function(page, field, option, append, result) {
if (!option) {return}
option.ondaemon = option.ondaemon || function(msg) {
append.innerHTML = ""
msg && msg.append && kit.AppendTable(append, ctx.Table(msg), msg.append, function(value, key, row, index, event) {
typeof option.daemon_action[key] == "function" && option.daemon_action[key](value, key, row, index, event)
})
result && (result.innerText = (msg && msg.result)? msg.result.join(""): "")
}
option.querySelectorAll("select").forEach(function(select, index, array) {
select.onchange = select.onchange || function(event) {
if (index == array.length-1) {
ctx.Runs(page, option)
return
}
if (array[index+1].type == "button") {
array[index+1].click()
return
}
array[index+1].focus()
}
})
option.querySelectorAll("input").forEach(function(input, index, array) {
switch (input.type) {
case "button":
input.onclick = input.onclick || function(event) {
if (index == array.length-1) {
if (input.value == "login") {
ctx.Runs(page, option, function(msg) {
if (document.referrer) {
location.href = document.referrer
} else {
ctx.Search("group", "")
}
})
return
}
ctx.Runs(page, option)
return
}
if (array[index+1].type == "button") {
array[index+1].click()
return
}
array[index+1].focus()
}
default:
input.onkeyup = input.onkeyup || function(event) {
if (event.key != "Enter") {
return
}
if (index == array.length-1) {
ctx.Runs(page, option)
return
}
if (array[index+1].type == "button") {
array[index+1].click()
return
}
array[index+1].focus()
}
}
})
},
}
function Editor(run, plugin, option, output, width, height, space, msg) {
@ -1491,4 +1454,3 @@ function Canvas(plugin, option, output, width, height, space, msg) {
return what.reset().refresh()
}

View File

@ -94,7 +94,7 @@ var page = Page({
page.Conf("menu.display", value || (page.Conf("menu.display")? "": "none"))
},
Size: function(width, height) {
if (kit.isMobile) {
if (kit.device.isMobile) {
return
}
if (page.Conf("menu.float")) {
@ -120,7 +120,7 @@ var page = Page({
page.Conf("menu.display", "", function(value, old) {
ui.menu.style.display = value
})
page.Conf("menu.float", !kit.isMobile, function(value, old) {
page.Conf("menu.float", !kit.device.isMobile, function(value, old) {
page.onlayout()
})
page.Conf("menu.scroll", true, function(value, old) {