mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
opt js
This commit is contained in:
parent
7976a90397
commit
861ff0b2ac
@ -1,4 +1,4 @@
|
||||
Script["love/index.js"] = function(field, option, output) {return {
|
||||
Plugin["love/index.js"] = function(field, option, output) {return {
|
||||
data: function(event) {var plugin = field.Plugin
|
||||
plugin.Run(event, [option.table.value], function(msg) {
|
||||
plugin.ondaemon(msg)
|
||||
@ -7,7 +7,7 @@ Script["love/index.js"] = function(field, option, output) {return {
|
||||
show: function(event) {var plugin = field.Plugin
|
||||
plugin.Check(undefined, function(msg) {
|
||||
plugin.Run(event, [option.table.value], function(msg) {
|
||||
kit.List(ctx.Table(msg), function(line) {
|
||||
kit.List(msg.Table(), function(line) {
|
||||
kit.Selector(output, ".s"+line.when.split(" ")[0].split("-").join(""), function(item) {
|
||||
kit.classList.add(item.parentNode, "select")
|
||||
item.parentNode.title = line.what
|
||||
@ -17,7 +17,7 @@ Script["love/index.js"] = function(field, option, output) {return {
|
||||
})
|
||||
},
|
||||
show_after: function(msg) {
|
||||
kit.Selector(output, ".s"+ kit.format_date().split(" ")[0].split("-").join(""), function(item) {
|
||||
kit.Selector(output, ".s"+ kit.time().split(" ")[0].split("-").join(""), function(item) {
|
||||
kit.classList.add(item.parentNode, "today")
|
||||
})
|
||||
},
|
||||
@ -61,7 +61,7 @@ Script["love/index.js"] = function(field, option, output) {return {
|
||||
kit.Opacity(cb([{text: [list.join(""), "div", "day"]}]).last)
|
||||
},
|
||||
Order: function(t, cb, cbs) {var plugin = field.Plugin
|
||||
kit.List(ctx.Table(plugin.msg).concat([{when: "9999-01-08", what: "最后一次爱你", where: "北京市"}]), function(line, index, array) {
|
||||
kit.List(plugin.msg.Table().concat([{when: "9999-01-08", what: "最后一次爱你", where: "北京市"}]), function(line, index, array) {
|
||||
plugin.flash(line, cb, index, array)
|
||||
}, t, cbs)
|
||||
},
|
||||
|
@ -1,4 +1,4 @@
|
||||
Script["love/maps.js"] = function(field, option, output) {
|
||||
Plugin["love/maps.js"] = function(field, option, output) {
|
||||
var id
|
||||
return {
|
||||
initMap: function() {var plugin = field.Plugin
|
||||
|
@ -1,4 +1,4 @@
|
||||
Script["love/pics.js"] = function(field, option, output) {return {
|
||||
Plugin["love/pics.js"] = function(field, option, output) {return {
|
||||
onexport: {"": function(value, name, line) {var plugin = field.Plugin
|
||||
kit.AppendChilds(output, [{img: ["/download/"+line.hash], data: {width: output.clientWidth, onclick: function() {
|
||||
plugin.display("table")
|
||||
@ -7,11 +7,11 @@ Script["love/pics.js"] = function(field, option, output) {return {
|
||||
show: function() {var plugin = field.Plugin
|
||||
var msg = plugin.msg
|
||||
var width = output.clientWidth
|
||||
output.innerHTML = "", kit.List(ctx.Table(msg), function(line) {
|
||||
output.innerHTML = "", kit.List(msg.Table(), function(line) {
|
||||
kit.Opacity(kit.AppendChilds(output, [{img: ["/download/"+line.hash], data: {width: width, onclick: function(event) {
|
||||
}}}]).last)
|
||||
}, 1000, function() {
|
||||
output.innerHTML = "", kit.List(ctx.Table(msg), function(line) {
|
||||
output.innerHTML = "", kit.List(msg.Table(), function(line) {
|
||||
kit.Opacity(kit.AppendChild(output, [{img: ["/download/"+line.hash], data: {width: 200, onclick: function(event) {
|
||||
plugin.ontoast({width: width, height: width*3/5+40,
|
||||
text: {img: ["/download/"+line.hash], data: {width: width-20, onclick: function(event) {
|
||||
|
@ -23,7 +23,7 @@ var page = Page({check: true,
|
||||
sizes.action == undefined && (sizes.action = page.action.offsetHeight-page.conf.border)
|
||||
sizes.source == undefined && (sizes.source = page.source.clientHeight)
|
||||
sizes.target == undefined && (sizes.target = page.target.clientHeight)
|
||||
sizes.source == 0 && sizes.target == 0 && (sizes.action = height)
|
||||
sizes.source == 0 && sizes.target == 0 && !kit.device.isMobile && (sizes.action = height)
|
||||
page.action.Pane.Size(width, sizes.action)
|
||||
page.source.Pane.Size(width, sizes.source)
|
||||
height -= sizes.target==0? height: page.source.offsetHeight+page.action.offsetHeight
|
||||
@ -146,7 +146,7 @@ var page = Page({check: true,
|
||||
return {
|
||||
Append: function(msg) {
|
||||
kit.AppendChilds(table, [{text: ["1. 选择用户节点 ->", "caption"]}])
|
||||
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, row, i, tr, event) {
|
||||
kit.AppendTable(table, msg.Table(), ["key", "user.route"], function(value, key, row, i, tr, event) {
|
||||
tr.className = "hidden"
|
||||
var uis = kit.AppendChild(ui.list, [{row: [row.key, row["user.route"]], dataset: {user: row.key}, click: function(event) {
|
||||
tr.className = "normal", uis.last.parentNode.removeChild(uis.last)
|
||||
@ -188,8 +188,8 @@ var page = Page({check: true,
|
||||
"river": page.river.Pane.which.get(),
|
||||
"layout": page.action.Pane.Layout(),
|
||||
})], function(msg) {
|
||||
page.ontoast({text: location.origin+location.pathname+"?relay="+msg.result.join(""), title: "共享链接", button: ["确定"], cb: function(which) {
|
||||
page.ontoast()
|
||||
page.toast.Pane.Show({text: location.origin+location.pathname+"?relay="+msg.result.join(""), title: "共享链接", button: ["确定"], cb: function(which) {
|
||||
page.toast.Pane.Show()
|
||||
}})
|
||||
})
|
||||
},
|
||||
@ -431,10 +431,9 @@ var page = Page({check: true,
|
||||
Show: function() {var pane = field.Pane
|
||||
if (field.Pane.Back(river+storm, output)) {return}
|
||||
|
||||
ctx.Event(event, {}, {name: "action.show"})
|
||||
pane.clear(), pane.Update([river, storm], "plugin", ["node", "name"], "index", false, function(line, index, event, args, cbs) {
|
||||
pane.Core(event, line, args, cbs)
|
||||
}, function(msg) {
|
||||
!page.plugin && output.querySelector("fieldset.item").Plugin.Select()
|
||||
})
|
||||
},
|
||||
Layout: function(name) {var pane = field.Pane
|
||||
@ -586,8 +585,8 @@ var page = Page({check: true,
|
||||
"layout": page.action.Pane.Layout(),
|
||||
})], function(msg) {
|
||||
var url = location.origin+location.pathname+"?relay="+msg.result.join("")
|
||||
page.ontoast({text: "<img src=\""+ctx.Share({"group": "index", "names": "login", cmds: ["share", url]})+"\">", height: 320, width: 320, title: url, button: ["确定"], cb: function(which) {
|
||||
page.ontoast()
|
||||
page.toast.Pane.Show({text: "<img src=\""+ctx.Share({"group": "index", "names": "login", cmds: ["share", url]})+"\">", height: 320, width: 320, title: url, button: ["确定"], cb: function(which) {
|
||||
page.toast.Pane.Show()
|
||||
}})
|
||||
})
|
||||
},
|
||||
@ -671,17 +670,17 @@ var page = Page({check: true,
|
||||
kit.AppendTable(device, list, ["key", "index", "name", "help"], function(value, key, com, i, tr, event) {
|
||||
pane.Select(com, pod)
|
||||
}, function(value, key, com, i, tr, event) {
|
||||
page.oncarte(event, ["创建"], function(event, item) {
|
||||
page.carte.Pane.Show(event, ["创建"], function(event, item) {
|
||||
pane.Create(com.key)
|
||||
})
|
||||
})
|
||||
},
|
||||
Append: function(msg) {var pane = field.Pane
|
||||
kit.AppendChilds(table, [{text: ["1. 选择用户节点 ->", "caption"]}])
|
||||
kit.AppendTable(table, ctx.Table(msg), ["user", "node"], function(value, key, pod, i, tr, event) {
|
||||
kit.AppendTable(table, msg.Table(), ["user", "node"], function(value, key, pod, i, tr, event) {
|
||||
kit.Selector(table, "tr.select", function(item) {item.className = "normal"})
|
||||
tr.className = "select", pane.Run([river, pod.user, pod.node], function(msg) {
|
||||
pane.Update(ctx.Table(msg), pod)
|
||||
pane.Update(msg.Table(), pod)
|
||||
})
|
||||
}), table.querySelector("td").click()
|
||||
},
|
||||
@ -711,7 +710,7 @@ var page = Page({check: true,
|
||||
init: function(page) {
|
||||
page.action.Pane.Layout(ctx.Search("layout")? ctx.Search("layout"): kit.device.isMobile? page.conf.first: page.conf.mobile)
|
||||
page.footer.Pane.Order({"ncmd": "0", "ntxt": "0"}, ["ncmd", "ntxt"], function(event, item, value) {})
|
||||
page.header.Pane.Order({"logout": "logout", "user": ""}, ["logout", "user"], function(event, item, value) {
|
||||
page.header.Pane.Order({"logout": "logout", "user": "", "title": "github.com/shylinux/context"}, ["logout", "user"], function(event, item, value) {
|
||||
page.onaction[item] && page.onaction[item](event, item, value, page)
|
||||
})
|
||||
page.river.Pane.Show()
|
||||
|
@ -1,39 +1,6 @@
|
||||
ctx = context = {__proto__: kit,
|
||||
Event: Wrap(function(event, msg, proto) {
|
||||
event = event || document.createEvent("Event")
|
||||
if (event.msg && !msg) {return event.msg}
|
||||
|
||||
var meta = arguments.callee
|
||||
var order = ++meta.order
|
||||
|
||||
event.msg = msg = msg || {}, proto = proto || {}, msg.__proto__ = proto, proto.__proto__ = {
|
||||
Push: function(key, value) {
|
||||
msg.append || (msg.append = [])
|
||||
msg[key]? msg[key].push(value): (msg[key] = [value], msg.append.push(key))
|
||||
return msg
|
||||
},
|
||||
Echo: function(res) {
|
||||
res != null && res != undefined && (msg.result = (msg.result || []).concat(kit.Trans(res)))
|
||||
return msg
|
||||
},
|
||||
Result: function() {
|
||||
return msg.result? msg.result.join(""): ""
|
||||
},
|
||||
Results: function() {
|
||||
var s = msg.Result()
|
||||
s = s.replace(/</g, "<")
|
||||
s = s.replace(/>/g, ">")
|
||||
s = kit.Color(s)
|
||||
return s
|
||||
},
|
||||
}, msg.event = event
|
||||
kit.Log("event", order, event.type, proto.name, msg)
|
||||
return msg
|
||||
}, {order: 0}),
|
||||
Run: Wrap(function(dataset, cmd, cb) {
|
||||
var meta = arguments.callee
|
||||
var order = ++meta.order
|
||||
var msg = ctx.Event(event||document.createEvent("Event"), null, {name: "ctx.run"})
|
||||
ctx = context = (function(kit) {var ctx = {__proto__: kit,
|
||||
Run: shy("请求后端", {order: 0}, function(dataset, cmd, cb) {
|
||||
var msg = ctx.Event(event, null, {name: "ctx.run"})
|
||||
|
||||
var option = {"cmds": cmd}
|
||||
msg.option && msg.option.forEach(function(item) {
|
||||
@ -42,249 +9,156 @@ ctx = context = {__proto__: kit,
|
||||
for (var k in dataset) {
|
||||
option[k] = dataset[k].split(",")
|
||||
}
|
||||
msg.Order = ++arguments.callee.meta.order
|
||||
|
||||
msg.option = []
|
||||
for (var k in option) {
|
||||
msg.option.push(k)
|
||||
msg[k] = option[k]
|
||||
}
|
||||
msg.detail = ["run", order].concat(option.group).concat(option.names).concat(option.cmds)
|
||||
msg.Order = order
|
||||
|
||||
msg.detail = ["run", msg.Order].concat(option.group).concat(option.names).concat(option.cmds)
|
||||
kit.Log(msg.detail.concat([msg]))
|
||||
|
||||
this.POST("", option, function(msg) {
|
||||
kit.Log("run", order, "result", msg.result? msg.result[0]: "", msg)
|
||||
typeof cb == "function" && cb(msg || {})
|
||||
kit.Log("run", msg.Order, "result", msg.result? msg.result[0]: "", msg)
|
||||
kit._call(cb, [msg])
|
||||
}, msg)
|
||||
}, {order: 0}),
|
||||
Runs: function(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(data, [], cb || form.ondaemon)
|
||||
},
|
||||
Table: function(msg, cb) {
|
||||
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)
|
||||
}
|
||||
|
||||
var list = []
|
||||
typeof cb == "function" && ret.forEach(function(value, index, array) {
|
||||
var item = cb(value, index, array)
|
||||
item && list.push(item)
|
||||
})
|
||||
if (list.length > 0) {
|
||||
return list
|
||||
}
|
||||
return ret
|
||||
},
|
||||
Tables: function(msg, cb) {
|
||||
var ret = []
|
||||
if (!msg || !msg.append || !msg.append.length || !msg[msg.append[0]]) {
|
||||
return ret
|
||||
}
|
||||
ret.push(msg.append)
|
||||
|
||||
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.push(msg[msg.append[j]][i])
|
||||
}
|
||||
ret.push(one)
|
||||
}
|
||||
|
||||
var list = []
|
||||
typeof cb == "function" && ret.forEach(function(value, index, array) {
|
||||
var item = cb(value, index, array)
|
||||
item && list.push(item)
|
||||
})
|
||||
if (list.length > 0) {
|
||||
return list
|
||||
}
|
||||
return ret
|
||||
},
|
||||
Upload: function(form, file, cb, detail) {
|
||||
var data = new FormData()
|
||||
data.append("upload", file)
|
||||
for (var k in form) {
|
||||
data.append(k, form[k])
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.onload = function(event) {
|
||||
var msg = JSON.parse(xhr.responseText||'{"result":[]}')
|
||||
typeof cb == "function" && cb(event, msg)
|
||||
}
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) {
|
||||
return
|
||||
}
|
||||
if (xhr.status != 200) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
xhr.upload.onprogress = function(event) {
|
||||
typeof detail == "function" && detail(event)
|
||||
}
|
||||
|
||||
xhr.open("POST", "/upload", true)
|
||||
xhr.send(data)
|
||||
},
|
||||
Share: function(objs) {
|
||||
var args = this.Search()
|
||||
for (var k in objs) {
|
||||
args[k] = objs[k]
|
||||
}
|
||||
|
||||
var as = []
|
||||
for (var k in args) {
|
||||
if (typeof args[k] == "object") {
|
||||
for (var i = 0; i < args[k].length; i++) {
|
||||
as.push(k+"="+encodeURIComponent(args[k][i]));
|
||||
}
|
||||
} else {
|
||||
as.push(k+"="+encodeURIComponent(args[k]));
|
||||
}
|
||||
}
|
||||
var arg = as.join("&");
|
||||
return location.origin+location.pathname+"?"+arg
|
||||
},
|
||||
|
||||
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("=")
|
||||
if (keys[1] == "") {continue}
|
||||
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
|
||||
}
|
||||
|
||||
var arg = []
|
||||
for (var k in args) {
|
||||
arg.push(k+"="+encodeURIComponent(args[k]))
|
||||
}
|
||||
location.search = arg.join("&");
|
||||
return value
|
||||
},
|
||||
Cookie: function(key, value, expire) {
|
||||
if (key == undefined) {
|
||||
cs = {}
|
||||
cookies = document.cookie.split("; ")
|
||||
for (var i = 0; i < cookies.length; i++) {
|
||||
cookie = cookies[i].split("=")
|
||||
cs[cookie[0]] = cookie[1]
|
||||
}
|
||||
return cs
|
||||
}
|
||||
if (typeof key == "object") {
|
||||
for (var k in key) {
|
||||
document.cookie = k+"="+key[k];
|
||||
}
|
||||
return arguments.callee()
|
||||
}
|
||||
if (value == undefined) {
|
||||
var pattern = new RegExp(key+"=([^;]*);?")
|
||||
var result = pattern.exec(document.cookie)
|
||||
return result && result.length > 0? result[1]: ""
|
||||
}
|
||||
document.cookie = key+"="+value+";path=/"
|
||||
return arguments.callee(key)
|
||||
},
|
||||
POST: function(url, form, cb, msg) {
|
||||
var args = []
|
||||
for (var k in form) {
|
||||
if (form[k] instanceof Array) {
|
||||
for (i in form[k]) {
|
||||
args.push(k+"="+encodeURIComponent(form[k][i]))
|
||||
}
|
||||
} else if (form[k] != undefined) {
|
||||
args.push(k+"="+encodeURIComponent(form[k]))
|
||||
}
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) {
|
||||
return
|
||||
}
|
||||
if (xhr.status != 200) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
var res = JSON.parse(xhr.responseText||'[{"result":[]}]')
|
||||
res.length > 0 && res[0] && (res = res[0])
|
||||
} catch (e) {
|
||||
var res = {"result": [xhr.responseText]}
|
||||
}
|
||||
}),
|
||||
Event: shy("封装事件", {order: 0}, function(event, msg, proto) {
|
||||
event = event || document.createEvent("Event")
|
||||
if (event.msg && !msg) {return event.msg}
|
||||
|
||||
event.msg = msg = msg || {}, proto = proto || {}, msg.__proto__ = proto, proto.__proto__ = {
|
||||
Copy: function(res) {
|
||||
res.result && (msg.result = res.result)
|
||||
res.append && (msg.append = res.append) && res.append.forEach(function(item) {
|
||||
res[item] && (msg[item] = res[item])
|
||||
})
|
||||
return msg
|
||||
},
|
||||
Push: function(key, value) {msg.append = msg.append || []
|
||||
msg[key]? msg[key].push(value): (msg[key] = [value], msg.append.push(key))
|
||||
return msg
|
||||
},
|
||||
Echo: function(res) {
|
||||
kit.notNone(res) && (msg.result = (msg.result || []).concat(kit._call(kit.List, arguments)))
|
||||
return msg
|
||||
},
|
||||
Result: function() {return msg.result? msg.result.join(""): ""},
|
||||
Results: function() {return kit.Color(msg.Result().replace(/</g, "<").replace(/>/g, ">"))},
|
||||
Table: function(cb) {if (!msg.append || !msg.append.length || !msg[msg.append[0]]) {return}
|
||||
return kit.List(msg[msg.append[0]], function(value, index, array) {var one = {}
|
||||
msg.append.forEach(function(key) {one[key] = msg[key][index]})
|
||||
return kit._call(cb, [one, index, array])
|
||||
})
|
||||
},
|
||||
}, msg.event = event
|
||||
|
||||
if (msg.download_file) {
|
||||
window.open(msg.download_file.join(""))
|
||||
} else if (msg.page_redirect) {
|
||||
location.href = msg.page_redirect.join("")
|
||||
} else if (msg.page_refresh) {
|
||||
kit.Log("event", ++arguments.callee.meta.order, event.type, proto.name, msg)
|
||||
return msg
|
||||
}),
|
||||
Share: shy("共享链接", function(objs, clear) {objs = objs || {}
|
||||
!clear && kit.Item(this.Search(), function(key, value) {objs[key] = value})
|
||||
return location.origin+location.pathname+"?"+kit.Item(objs, function(key, value) {
|
||||
return kit.List(value, function(value) {return key+"="+encodeURIComponent(value)}).join("&")
|
||||
}).join("&")
|
||||
}),
|
||||
|
||||
Search: shy("请求变量", function(key, value) {var args = {}
|
||||
location.search && location.search.slice(1).split("&").forEach(function(item) {var x = item.split("=")
|
||||
x[1] != "" && (args[x[0]] = decodeURIComponent(x[1]))
|
||||
})
|
||||
|
||||
if (typeof key == "object") {
|
||||
kit.Item(key, function(key, value) {
|
||||
if (kit.notNone(value)) {args[key] = value}
|
||||
})
|
||||
} else if (kit.isNone(key)) {
|
||||
return args
|
||||
} else if (kit.isNone(value)) {
|
||||
return args[key] || ctx.Cookie(key)
|
||||
} else {
|
||||
args[key] = value
|
||||
}
|
||||
|
||||
return location.search = kit.Item(args, function(key, value) {
|
||||
return key+"="+encodeURIComponent(value)
|
||||
}).join("&")
|
||||
}),
|
||||
Cookie: shy("会话变量", function(key, value, path) {
|
||||
function set(k, v) {document.cookie = k+"="+v+";path="+(path||"/")}
|
||||
|
||||
if (typeof key == "object") {
|
||||
for (var k in key) {set(k, key[k])}
|
||||
key = null
|
||||
}
|
||||
if (kit.isNone(key)) {var cs = {}
|
||||
document.cookie.split("; ").forEach(function(item) {
|
||||
var cookie = item.split("=")
|
||||
cs[cookie[0]] = cookie[1]
|
||||
})
|
||||
return cs
|
||||
}
|
||||
|
||||
kit.notNone(value) && set(key, value)
|
||||
var result = (new RegExp(key+"=([^;]*);?")).exec(document.cookie)
|
||||
return result && result.length > 0? result[1]: ""
|
||||
}),
|
||||
Upload: shy("上传文件", function(form, file, cb, detail) {
|
||||
var data = new FormData()
|
||||
for (var k in form) {data.append(k, form[k])}
|
||||
data.append("upload", file)
|
||||
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) {return}
|
||||
if (xhr.status != 200) {return}
|
||||
}
|
||||
xhr.upload.onprogress = function(event) {kit._call(detail, [event])}
|
||||
xhr.onload = function(event) {kit._call(cb, [event, JSON.parse(xhr.responseText||'{"result":[]}')])}
|
||||
xhr.open("POST", "/upload", true)
|
||||
xhr.send(data)
|
||||
}),
|
||||
POST: shy("请求后端", {order: 0}, function(url, form, cb, msg) {
|
||||
var args = kit.Items(form, function(value, index, key) {
|
||||
return key+"="+encodeURIComponent(value)
|
||||
})
|
||||
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) {return}
|
||||
if (xhr.status != 200) {return}
|
||||
|
||||
try {
|
||||
var res = JSON.parse(xhr.responseText||'[{"result":[]}]')
|
||||
res.length > 0 && res[0] && (res = res[0])
|
||||
|
||||
if (res.download_file) {
|
||||
window.open(res.download_file.join(""))
|
||||
} else if (res.page_redirect) {
|
||||
location.href = res.page_redirect.join("")
|
||||
} else if (res.page_refresh) {
|
||||
location.reload()
|
||||
}
|
||||
typeof cb == "function" && cb(msg || {})
|
||||
} catch (e) {
|
||||
var res = {"result": [xhr.responseText]}
|
||||
}
|
||||
|
||||
kit._call(cb, [msg.Copy(res)])
|
||||
}
|
||||
|
||||
xhr.open("POST", url)
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
xhr.setRequestHeader("Accept", "application/json")
|
||||
xhr.send(args.join("&"))
|
||||
},
|
||||
WSS: Wrap(function(cb, onerror, onclose) {
|
||||
var meta = arguments.callee
|
||||
var s = new WebSocket(location.protocol.replace("http", "ws")+"//"+location.host+"/wss?wssid="+(page.wssid||""))
|
||||
s.onopen = function(event) {
|
||||
kit.Log("wss", "open")
|
||||
page.ontoast("wss open")
|
||||
}
|
||||
++arguments.callee.meta.order
|
||||
}),
|
||||
WSS: shy("响应后端", {order: 0, wssid: ""}, function(cb, onerror, onclose) {var meta = arguments.callee.meta
|
||||
var s = new WebSocket(location.protocol.replace("http", "ws")+"//"+location.host+"/wss?wssid="+meta.wssid)
|
||||
s.onopen = function(event) {kit.Tip("wss open"), kit.Log("wss", "open")}
|
||||
s.onerror = function(event) {kit.Log("wss", "error", event), kit._call(onerror, [event])}
|
||||
s.onclose = function(event) {kit.Tip("wss close"), kit.Log("wss", "close"), kit._call(onclose, [event])}
|
||||
s.onmessage = function(event) {
|
||||
var order = ++meta.order
|
||||
try {
|
||||
var msg = JSON.parse(event.data||'{}')
|
||||
} catch (e) {
|
||||
@ -292,31 +166,18 @@ ctx = context = {__proto__: kit,
|
||||
}
|
||||
|
||||
// Event入口 -1.0
|
||||
msg = ctx.Event(event, msg, {
|
||||
name: document.title,
|
||||
Order: order,
|
||||
Reply: function(msg) {
|
||||
kit.Log(["wss", order, "result"].concat(msg.result).concat([msg]))
|
||||
msg = ctx.Event(event, msg, {name: document.title, Order: ++meta.order, Reply: function(msg) {
|
||||
kit.Log(["wss", msg.Order, "result"].concat(msg.result).concat([msg]))
|
||||
delete(msg.event), s.send(JSON.stringify(msg))
|
||||
},
|
||||
})
|
||||
}})
|
||||
|
||||
// try {
|
||||
kit.Log(["wss", order].concat(msg.detail).concat([msg]))
|
||||
typeof cb == "function" && cb(msg)
|
||||
// } catch (e) {
|
||||
// msg.Reply(kit.Log("err", e))
|
||||
// }
|
||||
try {
|
||||
kit.Log(["wss", msg.Order].concat(msg.detail).concat([msg]))
|
||||
kit._call(cb, [msg])
|
||||
} catch (e) {
|
||||
msg.Reply(kit.Log("err", e))
|
||||
}
|
||||
s.onerror = function(event) {
|
||||
kit.Log("wss", "error", event)
|
||||
typeof onerror == "function" && onerror(event)
|
||||
}
|
||||
s.onclose = function(event) {
|
||||
kit.Log("wss", "close")
|
||||
page.ontoast("wss close")
|
||||
typeof onclose == "function" && onclose(event)
|
||||
}
|
||||
return s
|
||||
}, {order: 0}),
|
||||
}
|
||||
}),
|
||||
}; return ctx})(kit)
|
||||
|
@ -251,8 +251,6 @@ fieldset.item.select {
|
||||
border:solid 2px red;
|
||||
}
|
||||
fieldset.item>div.output {
|
||||
margin-top:2px;
|
||||
border-top:solid 2px gray;
|
||||
overflow:auto;
|
||||
}
|
||||
fieldset.item>div.output>canvas {
|
||||
|
@ -1,29 +1,29 @@
|
||||
Script = {}
|
||||
function Meta(target, obj) {
|
||||
// 级连对象
|
||||
var a = obj
|
||||
for (var i = 2; i < arguments.length; i++) {
|
||||
a.__proto__ = arguments[i], a = arguments[i]
|
||||
}
|
||||
|
||||
// 构造对象
|
||||
var id = 1
|
||||
var conf = {}, conf_cb = {}
|
||||
var conf = {}, conf_cb = {}, old
|
||||
var sync = {}
|
||||
var cache = {}
|
||||
return {__proto__: obj, target: target,
|
||||
ID: function() {return id++},
|
||||
Conf: function(key, value, cb) {
|
||||
if (key == undefined) {return conf}
|
||||
|
||||
cb != undefined && (conf_cb[key] = cb)
|
||||
|
||||
if (value != undefined) {
|
||||
var old = conf[key]
|
||||
conf[key] = value
|
||||
conf_cb[key] && conf_cb[key](value, old)
|
||||
var history = []
|
||||
var meta = {__proto__: obj, target: target,
|
||||
ID: shy("单一序列", function() {return id++}),
|
||||
Conf: shy("配置变量", function(key, value, cb) {
|
||||
if (kit.isNone(key)) {return conf}
|
||||
kit.notNone(cb) && (conf_cb[key] = cb)
|
||||
if (kit.notNone(value)) {
|
||||
old = conf[key], conf[key] = value
|
||||
kit.Log("config", key, value, old)
|
||||
kit._call(conf_cb[key], [value, old])
|
||||
}
|
||||
return conf[key] == undefined && obj && obj.Conf? obj.Conf(key): conf[key]
|
||||
},
|
||||
Sync: function(m) {
|
||||
return kit.isNone(conf[key]) && obj && obj.Conf? obj.Conf(key): conf[key]
|
||||
}),
|
||||
Sync: shy("同步变量", function(m) {
|
||||
var meta = m, data = "", list = []
|
||||
return sync[m] || (sync[m] = {
|
||||
change: function(cb) {list.push(cb); return list.length-1},
|
||||
@ -31,19 +31,35 @@ function Meta(target, obj) {
|
||||
neq: function(value) {return data != value},
|
||||
get: function() {return data},
|
||||
set: function(value, force) {
|
||||
if (value == undefined) {return}
|
||||
if (kit.isNone(value)) {return}
|
||||
if (value == data && !force) {return}
|
||||
|
||||
old_value = data, data = value
|
||||
meta && kit.Log("key", meta, value, old_value)
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
list[i](value, old_value)
|
||||
}
|
||||
old = data, data = value
|
||||
meta && kit.Log("key", meta, value, old)
|
||||
kit.List(list, function(cb) {cb(value, old)})
|
||||
return value
|
||||
},
|
||||
})
|
||||
},
|
||||
View: function(output, type, line, key, cb) {
|
||||
}),
|
||||
Save: shy("保存视图", function(name, output) {if (name === "") {return cache = {}}
|
||||
var temp = document.createDocumentFragment()
|
||||
while (output.childNodes.length>0) {
|
||||
var item = output.childNodes[0]
|
||||
item.parentNode.removeChild(item)
|
||||
temp.appendChild(item)
|
||||
}
|
||||
cache[name] = temp
|
||||
return name
|
||||
}),
|
||||
Back: shy("恢复视图", function(name, output) {if (kit.isNone(cache[name])) {return}
|
||||
while (cache[name].childNodes.length>0) {
|
||||
var item = cache[name].childNodes[0]
|
||||
item.parentNode.removeChild(item)
|
||||
output.appendChild(item)
|
||||
}
|
||||
delete(cache[name])
|
||||
return name
|
||||
}),
|
||||
View: shy("添加视图", function(output, type, line, key, cb) {
|
||||
var text = line, list = [], ui = {}
|
||||
switch (type) {
|
||||
case "icon":
|
||||
@ -94,59 +110,27 @@ function Meta(target, obj) {
|
||||
ui = kit.AppendChild(output, list)
|
||||
ui.field && (ui.field.Meta = text)
|
||||
return ui
|
||||
},
|
||||
Save: function(name, output) {
|
||||
if (name === "") {return cache = {}}
|
||||
|
||||
var temp = document.createDocumentFragment()
|
||||
while (output.childNodes.length>0) {
|
||||
var item = output.childNodes[0]
|
||||
item.parentNode.removeChild(item)
|
||||
temp.appendChild(item)
|
||||
}
|
||||
cache[name] = temp
|
||||
return name
|
||||
},
|
||||
Back: function(name, output) {
|
||||
if (!cache[name]) {return}
|
||||
|
||||
while (cache[name].childNodes.length>0) {
|
||||
item = cache[name].childNodes[0]
|
||||
item.parentNode.removeChild(item)
|
||||
output.appendChild(item)
|
||||
}
|
||||
delete(cache[name])
|
||||
return name
|
||||
},
|
||||
Include: function(src, cb) {
|
||||
typeof src == "string" && (src = [src])
|
||||
kit.AppendChild(target, [{include: [src[0], function(event) {
|
||||
src.length == 1? cb(event): page.Include(src.slice(1), cb)
|
||||
}]}])
|
||||
},
|
||||
Require: function(file, cb) {
|
||||
if (!file || Script[file]) {return kit._call(cb, [Script[file]])}
|
||||
file.endsWith(".css")? kit.AppendChild(document.body, [{require: ["/require/"+file, function(event) {
|
||||
return Script[file] = file, kit._call(cb, [Script[file]])
|
||||
}]}]): kit.AppendChild(document.body, [{data: {what: id++}, include: ["/require/"+file, function(event) {
|
||||
return kit._call(cb, [Script[file]])
|
||||
}]}])
|
||||
},
|
||||
History: shy("操作历史", {}, [], function(value, target) {
|
||||
var list = arguments.callee.list, item
|
||||
return value == undefined? (item = list.pop()) && (item.target.value = item.value):
|
||||
list.push({value: value, target: target})
|
||||
}),
|
||||
Include: shy("加载脚本", function(src, cb) {src = kit.List(src)
|
||||
function next(event) {src.length > 1? meta.Include(src.slice(1), cb): cb(event)}
|
||||
kit.AppendChild(target, [file.endsWith(".css")? {require: [src[0], next]}: {include: [src[0], next]}])
|
||||
}),
|
||||
History: shy("操作历史", function(value, target) {var item
|
||||
return kit.isNone(value)? (item = history.pop()) && (item.target.value = item.value):
|
||||
history.push({value: value, target: target})
|
||||
}),
|
||||
}
|
||||
|
||||
// 注册事件
|
||||
meta.onaction && kit.Item(meta.onaction.meta, function(key, cb) {target[key] = function(event) {
|
||||
meta.onaction(event, key, cb)
|
||||
}})
|
||||
return meta
|
||||
}
|
||||
function Page(page) {
|
||||
var script = {}, record = ""
|
||||
var carte = document.querySelector("fieldset.carte")
|
||||
carte.onmouseleave = function(event) {
|
||||
kit.ModifyView(carte, {display: "none"})
|
||||
}
|
||||
page = Meta(document.body, page, {__proto__: ctx,
|
||||
onload: function() {
|
||||
onload: function(event) {
|
||||
// Event入口 0
|
||||
ctx.Event(event, {}, {name: document.title})
|
||||
if (page.check && !ctx.Cookie("sessid")) {
|
||||
@ -197,93 +181,25 @@ function Page(page) {
|
||||
}, document.body.onmouseup = function(event) {
|
||||
}
|
||||
},
|
||||
oncarte: function(event, cb) {
|
||||
kit.Selector(carte, "div.output", function(output) {if (!cb.list || cb.list.length == 0) {return}
|
||||
kit.AppendChilds(output, kit.List(cb.list, function(item) {
|
||||
return item === ""? {view: ["line"]}: {text: [item, "div", "item"], click: function(event) {
|
||||
kit._call(cb, [item, cb.meta, event]) && kit.ModifyView(carte, {display: "none"})
|
||||
}}
|
||||
}))
|
||||
kit.ModifyView(carte, {display: "block", left: event.x, top: event.y})
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
})
|
||||
},
|
||||
ontoast: function(text, title, duration) {
|
||||
// {text, title, duration, inputs, buttons}
|
||||
if (!text) {page.toast.style.display = "none"; return}
|
||||
|
||||
var args = typeof text == "object"? text: {text: text, title: title, duration: duration}
|
||||
var toast = kit.ModifyView("fieldset.toast", {
|
||||
display: "block", dialog: [args.width||text.length*10+100, args.height||80], padding: 10,
|
||||
})
|
||||
if (!args.duration && args.button) {args.duration = -1}
|
||||
|
||||
var main = typeof args.text == "string"? {text: [args.text||"", "div", "content"]}: args.text
|
||||
|
||||
var list = [{text: [args.title||"", "div", "title"]}, main]
|
||||
args.inputs && args.inputs.forEach(function(input) {
|
||||
if (typeof input == "string") {
|
||||
list.push({inner: input, type: "label", style: {"margin-right": "5px"}})
|
||||
list.push({input: [input, page.oninput]})
|
||||
} else {
|
||||
list.push({inner: input[0], type: "label", style: {"margin-right": "5px"}})
|
||||
var option = []
|
||||
for (var i = 1; i < input.length; i++) {
|
||||
option.push({type: "option", inner: input[i]})
|
||||
}
|
||||
list.push({name: input[0], type: "select", list: option})
|
||||
}
|
||||
list.push({type: "br"})
|
||||
})
|
||||
args.button && args.button.forEach(function(input) {
|
||||
list.push({type: "button", inner: input, click: function(event) {
|
||||
var values = {}
|
||||
toast.querySelectorAll("input").forEach(function(input) {
|
||||
values[input.name] = input.value
|
||||
})
|
||||
toast.querySelectorAll("select").forEach(function(input) {
|
||||
values[input.name] = input.value
|
||||
})
|
||||
typeof args.cb == "function" && args.cb(input, values)
|
||||
toast.style.display = "none"
|
||||
}})
|
||||
})
|
||||
list.push({view: ["tick"], name: "tick"})
|
||||
|
||||
var ui = kit.AppendChild(kit.ModifyNode(toast.querySelector("div.output"), ""), list)
|
||||
var tick = 1
|
||||
var begin = kit.time(0,"%H:%M:%S")
|
||||
var timer = args.duration ==- 1? setTimeout(function() {
|
||||
function ticker() {
|
||||
toast.style.display != "none" && (ui.tick.innerText = begin+" ... "+(tick++)+"s") && setTimeout(ticker, 1000)
|
||||
}
|
||||
ticker()
|
||||
}, 10): setTimeout(function(){toast.style.display = "none"}, args.duration||3000)
|
||||
return page.toast = toast
|
||||
},
|
||||
oninput: function(event, local) {
|
||||
var target = event.target
|
||||
oninput: function(event, local) {var target = event.target
|
||||
kit.History.add("key", (event.ctrlKey? "Control+": "")+(event.shiftKey? "Shift+": "")+event.key)
|
||||
|
||||
if (event.ctrlKey) {
|
||||
if (typeof local == "function" && local(event)) {
|
||||
if (local && kit._call(local, [event])) {
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
return true
|
||||
}
|
||||
|
||||
var his = target.History
|
||||
var his = target.History || []
|
||||
var pos = target.Current || -1
|
||||
switch (event.key) {
|
||||
case "p":
|
||||
if (!his) { break }
|
||||
pos = (pos-1+his.length+1) % (his.length+1)
|
||||
target.value = pos < his.length? his[pos]: ""
|
||||
target.Current = pos
|
||||
break
|
||||
case "n":
|
||||
if (!his) { break }
|
||||
pos = (pos+1) % (his.length+1)
|
||||
target.value = pos < his.length? his[pos]: ""
|
||||
target.Current = pos
|
||||
@ -388,6 +304,14 @@ function Page(page) {
|
||||
}
|
||||
},
|
||||
|
||||
Require: function(file, cb) {
|
||||
if (!file || Plugin[file]) {return kit._call(cb, [Plugin[file]])}
|
||||
file.endsWith(".css")? kit.AppendChild(document.body, [{require: ["/require/"+file, function(event) {
|
||||
return Plugin[file] = file, kit._call(cb, [Plugin[file]])
|
||||
}]}]): kit.AppendChild(document.body, [{include: ["/require/"+file, function(event) {
|
||||
return kit._call(cb, [Plugin[file]])
|
||||
}]}])
|
||||
},
|
||||
script: function(action, name, time) {
|
||||
switch (action) {
|
||||
case "create":
|
||||
@ -411,7 +335,7 @@ function Page(page) {
|
||||
kit.Log("script", action, name, item)
|
||||
page.action.Pane.Core(event, {}, ["_cmd", item]);
|
||||
}, time||1000, function() {
|
||||
page.ontoast("run "+name+" done")
|
||||
page.toast.Pane.Show("run "+name+" done")
|
||||
})
|
||||
break
|
||||
default:
|
||||
@ -419,16 +343,13 @@ function Page(page) {
|
||||
}
|
||||
return true
|
||||
},
|
||||
Help: function(pane, type, action) {
|
||||
return []
|
||||
},
|
||||
Jshy: function(event, args) {
|
||||
var msg = event.msg || {}
|
||||
Help: function(pane, type, action) {return []},
|
||||
Jshy: function(event, args) {var msg = ctx.Event(event)
|
||||
if (page[args[0]] && page[args[0]].type == "fieldset") {
|
||||
if (args.length > 1) {
|
||||
return page[args[0]].Pane.Jshy(event, args.slice(1))
|
||||
} else {
|
||||
msg.result = ["pane", args[0]]
|
||||
msg.Echo("pane", args[0])
|
||||
return page[args[0]].Pane.Show()
|
||||
}
|
||||
}
|
||||
@ -441,20 +362,77 @@ function Page(page) {
|
||||
if (m.detail) {
|
||||
page.action.Pane.Core(event, m, ["_cmd", m.detail], m.Reply)
|
||||
} else {
|
||||
page.ontoast(m.result.join(""))
|
||||
page.toast.Pane.Show(m.result.join(""))
|
||||
}
|
||||
|
||||
}), onerror || (function() {
|
||||
page.socket.close()
|
||||
|
||||
}), onclose || (function() {
|
||||
page.socket = undefined, setTimeout(function() {
|
||||
delete(page.socket), setTimeout(function() {
|
||||
page.WSS(cb, onerror, onclose)
|
||||
}, 1000)
|
||||
})))
|
||||
},
|
||||
|
||||
initToast: function() {},
|
||||
initCarte: function(page, field, option, output) {
|
||||
field.onmouseleave = function(event) {field.Pane.Hide()}
|
||||
return {
|
||||
Show: function(event, cb) {if (!cb.list || cb.list.length == 0) {return}
|
||||
kit.AppendChilds(output, kit.List(cb.list, function(item) {
|
||||
return item === ""? {view: "space"}: {text: [item, "div", "item"], click: function(event) {
|
||||
kit._call(cb, [item, cb.meta, event]) && field.Pane.Hide()
|
||||
}}
|
||||
}))
|
||||
kit.ModifyView(carte, {display: "block", left: event.x, top: event.y})
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
},
|
||||
}
|
||||
},
|
||||
initToast: function(page, field, option, output) {
|
||||
return {
|
||||
Dialog: function(width, height) {
|
||||
kit.ModifyView(field, {display: "block", dialog: [width, height], padding: 10})
|
||||
},
|
||||
Ticker: function(text, duration) {
|
||||
var tick = 1
|
||||
var begin = kit.time(0, "%H:%M:%S")
|
||||
function ticker() {
|
||||
field.style.display != "none" && (text.innerText = begin+" ... "+(tick++)+"s") && setTimeout(ticker, 1000)
|
||||
}
|
||||
return duration == -1? setTimeout(ticker, 10): setTimeout(field.Pane.Hide, duration||3000)
|
||||
},
|
||||
Show: function(text, title, duration) {if (!text) {return field.Pane.Hide()}
|
||||
var args = typeof text == "object"? text: {text: text, title: title, duration: duration}
|
||||
|
||||
var list = [{text: [args.title||"", "div", "title"]},
|
||||
typeof args.text == "string"? {text: [args.text||"", "div", "content"]}: args.text]
|
||||
|
||||
kit.List(args.inputs, function(input) {
|
||||
typeof input == "string"? list.push({label: input}, {input: [input, page.oninput]}):
|
||||
list.push({label: input[0]}, {select: input.slice(1)})
|
||||
list.push({type: "br"})
|
||||
})
|
||||
kit.List(args.button, function(input) {
|
||||
list.push({button: [input, function(event) {
|
||||
var values = {}
|
||||
toast.querySelectorAll("input").forEach(function(input) {
|
||||
values[input.name] = input.value
|
||||
})
|
||||
toast.querySelectorAll("select").forEach(function(input) {
|
||||
values[input.name] = input.value
|
||||
})
|
||||
kit._call(args.cb, [input, values]) && field.Pane.Hide()
|
||||
}]})
|
||||
})
|
||||
list.push({view: ["tick"], name: "tick"})
|
||||
|
||||
field.Pane.Dialog(args.width||text.length*10+100, args.height||80)
|
||||
return field.Pane.Ticker(kit.AppendChilds(output, list).tick, args.button? -1: args.duration || 3000)
|
||||
},
|
||||
}
|
||||
},
|
||||
initLogin: function(page, field, option, output) {
|
||||
var ui = kit.AppendChilds(option, [
|
||||
{label: "username"}, {input: ["username"]}, {type: "br"},
|
||||
@ -465,7 +443,6 @@ function Page(page) {
|
||||
|
||||
field.Pane.Login(ui.username.value, ui.password.value, function(sessid) {
|
||||
if (!sessid) {kit.alert("用户或密码错误"); return}
|
||||
// ctx.Cookie("sessid", sessid),
|
||||
page.login.Pane.Dialog(1, 1), page.onload()
|
||||
})
|
||||
}]}, {type: "br"},
|
||||
@ -482,20 +459,20 @@ function Page(page) {
|
||||
}
|
||||
},
|
||||
initHeader: function(page, field, option, output) {
|
||||
var state = {}, list = [], cb = function(event, item, value) {}
|
||||
field.onclick = function(event) {page.pane && page.pane.scrollTo(0,0)}
|
||||
var state = {title: "github.com/shylinux/context"}, list = [], cb = function(event, item, value) {}
|
||||
field.onclick = function(event) {page.pane && page.pane.scrollTo(0, 0)}
|
||||
return {
|
||||
Order: function(value, order, cbs) {
|
||||
state = value, list = order, cb = cbs || cb, field.Pane.Show()
|
||||
},
|
||||
State: function(name, value) {
|
||||
value != undefined && (state[name] = value, field.Pane.Show())
|
||||
return name == undefined? state: state[name]
|
||||
kit.notNone(value) && (state[name] = value, field.Pane.Show())
|
||||
return kit.isNone(name)? state: state[name]
|
||||
},
|
||||
Show: function() {
|
||||
output.innerHTML = "", kit.AppendChild(output, [
|
||||
{"view": ["title", "div", "github.com/shylinux/context"], click: function(event) {
|
||||
cb(event, "title", "shycontext")
|
||||
kit.AppendChilds(output, [
|
||||
{"view": ["title", "div", state.title], click: function(event) {
|
||||
cb(event, "title", state.title)
|
||||
}},
|
||||
{"view": ["state"], list: list.map(function(item) {return {text: [state[item], "div"], click: function(event) {
|
||||
cb(event, item, state[item])
|
||||
@ -506,10 +483,10 @@ function Page(page) {
|
||||
}
|
||||
},
|
||||
initFooter: function(page, field, option, output) {
|
||||
var state = {}, list = [], cb = function(event, item, value) {}
|
||||
var ui = kit.AppendChild(output, [
|
||||
{"view": ["title", "div", "<a href='mailto:shylinux@163.com'>shylinux@163.com</>"]},
|
||||
{"view": ["magic"], style: {"margin-top": "-4px"}, list: [{text: ["0", "label"], name: "count"}, {input: ["magic", function(event) {
|
||||
var state = {title: "<a href='mailto:shylinux@163.com'>shylinux@163.com</>"}, list = [], cb = function(event, item, value) {}
|
||||
var ui = kit.AppendChilds(output, [
|
||||
{"view": ["title", "div", state.title]},
|
||||
{"view": ["magic"], list: [{label: "0", name: "count"}, {input: ["magic", function(event) {
|
||||
if (event.key == "Enter" || event.ctrlKey && event.key == "j") {
|
||||
page.action.Pane.Core(event, {}, ["_cmd", event.target.value]);
|
||||
(ui.magic.History.length == 0 || ui.magic.History[ui.magic.History.length-1] != event.target.value) && ui.magic.History.push(event.target.value)
|
||||
@ -530,8 +507,7 @@ function Page(page) {
|
||||
}
|
||||
ui.count.innerHTML = ui.magic.Current || 0
|
||||
field.Pane.Show()
|
||||
|
||||
}], style: {"margin-top": "-2px", "font-size": "16px"}}]},
|
||||
}]}]},
|
||||
{"view": ["state"]},
|
||||
])
|
||||
|
||||
@ -551,7 +527,7 @@ function Page(page) {
|
||||
ui && kit.size(ui.magic, (width - ui.count.offsetWidth - ui.first.offsetWidth - ui.last.offsetWidth - 20), height-6)
|
||||
},
|
||||
Show: function() {
|
||||
ui.last.innerHTML = "", kit.AppendChild(ui.last, list.map(function(item) {return {text: [item+":"+state[item], "div"], click: function(item) {
|
||||
kit.AppendChilds(ui.last, list.map(function(item) {return {text: [item+":"+state[item], "div"], click: function(item) {
|
||||
cb(event, item, state[item])
|
||||
}}}))
|
||||
field.Pane.Size(field.clientWidth, field.clientHeight)
|
||||
@ -560,8 +536,8 @@ function Page(page) {
|
||||
}
|
||||
},
|
||||
Pane: Pane,
|
||||
})
|
||||
page.which = page.Sync("layout")
|
||||
}), page.which = page.Sync("layout")
|
||||
|
||||
kit.Log("init", "page", page)
|
||||
return window.onload = page.onload, page
|
||||
}
|
||||
@ -571,12 +547,11 @@ function Pane(page, field) {
|
||||
var output = field.querySelector("div.output")
|
||||
|
||||
var timer = ""
|
||||
var list = [], last = -1, member = {}
|
||||
var name = option.dataset.names
|
||||
var list = [], last = -1, member = {}
|
||||
var pane = Meta(field, (page[field.dataset.init] || function() {
|
||||
})(page, field, option, output) || {}, {
|
||||
Append: function(type, line, key, which, cb) {
|
||||
type = type || line.type
|
||||
Append: function(type, line, key, which, cb) {type = type || line.type
|
||||
var index = list.length, ui = pane.View(output, type, line, key, function(event, cmds, cbs) {
|
||||
(type != "plugin" && type != "field") && pane.Select(index, line[which])
|
||||
page.script("record", [name, line[key[0]]])
|
||||
@ -588,9 +563,10 @@ function Pane(page, field) {
|
||||
|
||||
(type == "plugin" && line.name || type == "field") && page.Require(line.init? line.group+"/"+line.init: "", function(init) {
|
||||
page.Require(line.view? line.group+"/"+line.view: "", function(view) {
|
||||
pane.Plugin(page, pane, ui.field, init, function(event, cmds, cbs) {
|
||||
var p = pane.Plugin(page, pane, ui.field, init, function(event, cmds, cbs) {
|
||||
kit._call(cb, [line, index, event, cmds, cbs])
|
||||
})
|
||||
index == 0 && p.Select()
|
||||
})
|
||||
})
|
||||
return ui
|
||||
@ -615,9 +591,7 @@ function Pane(page, field) {
|
||||
ctx.Event(event, {}, {name: name+"."+key})
|
||||
key && pane.which.set(key)
|
||||
},
|
||||
clear: function() {
|
||||
output.innerHTML = "", list = [], last = -1
|
||||
},
|
||||
clear: function() {output.innerHTML = "", list = [], last = -1},
|
||||
|
||||
Help: function(type, action) {
|
||||
var text = []
|
||||
@ -638,8 +612,7 @@ function Pane(page, field) {
|
||||
}
|
||||
return text
|
||||
},
|
||||
Jshy: function(event, args) {
|
||||
var msg = event.msg || {}
|
||||
Jshy: function(event, args) {var msg = ctx.Event(event)
|
||||
if (pane[args[0]] && pane[args[0]].type == "fieldset") {
|
||||
msg.result = ["plugin", args[0]]
|
||||
pane[args[0]].scrollIntoView(), pane[args[0]].Plugin.Select(true)
|
||||
@ -658,32 +631,26 @@ function Pane(page, field) {
|
||||
},
|
||||
|
||||
Tickers: function(time, cmds, cb) {
|
||||
pane.Ticker(time, cmds, function(msg) {
|
||||
ctx.Table(msg, function(line, index) {
|
||||
pane.Ticker(time, cmds, function(msg) {msg.Table(function(line, index) {
|
||||
cb(line, index, msg)
|
||||
})
|
||||
})
|
||||
})})
|
||||
},
|
||||
Ticker: function(time, cmds, cb) {
|
||||
timer && clearTimeout(timer)
|
||||
function loop() {
|
||||
!pane.Stop() && pane.Run(cmds, function(msg) {
|
||||
Ticker: function(time, cmds, cb) {timer && clearTimeout(timer)
|
||||
function loop() {!pane.Stop() && pane.Run(cmds, function(msg) {
|
||||
cb(msg), timer = setTimeout(loop, time)
|
||||
})
|
||||
}
|
||||
})}
|
||||
time && (timer = setTimeout(loop, 10))
|
||||
},
|
||||
Runs: function(cmds, cb) {
|
||||
pane.Run(cmds, function(msg) {
|
||||
ctx.Table(msg, function(line, index) {
|
||||
pane.Run(cmds, function(msg) {msg.Table(function(line, index) {
|
||||
(cb||pane.ondaemon)(line, index, msg)
|
||||
})
|
||||
})
|
||||
},
|
||||
Run: function(cmds, cb) {
|
||||
ctx.Run(option.dataset, cmds, cb||pane.ondaemon)
|
||||
})})
|
||||
},
|
||||
Run: function(cmds, cb) {ctx.Run(option.dataset, cmds, cb||pane.ondaemon)},
|
||||
|
||||
Hide: function() {
|
||||
kit.ModifyView(field, {display: "none"})
|
||||
},
|
||||
Size: function(width, height) {
|
||||
if (width > 0) {
|
||||
field.style.width = width+"px"
|
||||
@ -721,9 +688,6 @@ function Pane(page, field) {
|
||||
Plugin: Plugin,
|
||||
})
|
||||
|
||||
for (var k in pane.Listen) {
|
||||
page.Sync(k).change(pane.Listen[k])
|
||||
}
|
||||
function call(value, event) {
|
||||
// Event入口 1.1
|
||||
ctx.Event(event, {}, {name: name+"."+value})
|
||||
@ -734,15 +698,9 @@ function Pane(page, field) {
|
||||
return typeof value == "object"? {className: value[0], select: [value.slice(1), call]}:
|
||||
value == ""? {view: ["space"]} :value == "br"? {type: "br"}: {button: [value, call]}
|
||||
})).className="action")
|
||||
field.oncontextmenu = function(event) {
|
||||
page.oncarte(event, pane.Choice, function(event, value) {
|
||||
call(value, event)
|
||||
return true
|
||||
}) && (event.stopPropagation(), event.preventDefault())
|
||||
}
|
||||
option.onsubmit = function(event) {
|
||||
event.preventDefault()
|
||||
};
|
||||
|
||||
kit.Item(pane.Listen, function(key, cb) {page.Sync(key).change(cb)})
|
||||
option.onsubmit = function(event) {event.preventDefault()};
|
||||
kit.Log("init", "pane", name, pane)
|
||||
return page[name] = field, pane.Field = field, field.Pane = pane
|
||||
}
|
||||
@ -752,16 +710,12 @@ function Plugin(page, pane, field, inits, runs) {
|
||||
var output = field.querySelector("div.output")
|
||||
|
||||
var meta = field.Meta
|
||||
var name = meta.name
|
||||
var args = meta.args || []
|
||||
var name = meta.name, args = meta.args || []
|
||||
var inputs = JSON.parse(meta.inputs || "[]")
|
||||
var feature = JSON.parse(meta.feature||'{}')
|
||||
var display = JSON.parse(meta.display||'{}')
|
||||
var deal = (feature && feature.display) || "table"
|
||||
kit.classList.add(field, meta.group, name, feature.style)
|
||||
|
||||
var plugin = Meta(field, (inits || function() {
|
||||
})(field, option, output)||{}, {Inputs: {},
|
||||
var plugin = Meta(field, inits && inits(field, option, output) || {}, {Inputs: {},
|
||||
Appends: function() {
|
||||
var name = "args"+kit.Selector(option, "input.args.temp").length
|
||||
plugin.Append({type: "text", name: name, className: "args temp"}).focus()
|
||||
@ -828,7 +782,7 @@ function Plugin(page, pane, field, inits, runs) {
|
||||
page.input.focus()
|
||||
},
|
||||
Reveal: function(msg) {
|
||||
return msg.append && msg.append[0]? ["table", JSON.stringify(ctx.Tables(msg))]: ["code", msg.result? msg.result.join(""): ""]
|
||||
return msg.append && msg.append[0]? ["table", JSON.stringify(msg.Table())]: ["code", msg.result? msg.result.join(""): ""]
|
||||
},
|
||||
Format: function() {
|
||||
field.Meta.args = arguments.length > 0? kit.List(arguments):
|
||||
@ -902,77 +856,63 @@ function Plugin(page, pane, field, inits, runs) {
|
||||
},
|
||||
|
||||
Option: function(key, value) {
|
||||
if (value != undefined) {
|
||||
option[key] && (option[key].value = value)
|
||||
}
|
||||
kit.notNone(value) && option[key] && (option[key].value = value)
|
||||
return option[key]? option[key].value: ""
|
||||
},
|
||||
Check: function(target, cb) {
|
||||
kit.Selector(option, ".args", function(item, index, list) {
|
||||
target == undefined && index == list.length-1 && plugin.Runs(window.event, cb)
|
||||
kit.isNone(target)? index == list.length-1 && plugin.Runs(window.event, cb):
|
||||
item == target && (index == list.length-1? plugin.Runs(window.event, cb): page.plugin == field && list[index+1].focus())
|
||||
return item
|
||||
}).length == 0 && plugin.Runs(window.event, cb)
|
||||
},
|
||||
Delay: function(time, event, text) {
|
||||
page.ontoast(text, "", -1)
|
||||
plugin.ontoast(text, "", -1)
|
||||
return setTimeout(function() {
|
||||
plugin.Runs(event), page.ontoast("")
|
||||
plugin.Runs(event), plugin.ontoast("")
|
||||
}, time)
|
||||
},
|
||||
Last: function() {
|
||||
plugin.History() != undefined && plugin.Check()
|
||||
},
|
||||
Runs: function(event, cb) {
|
||||
plugin.Run(event, kit.Selector(option, ".args", function(item, index) {return item.value}), cb)
|
||||
},
|
||||
Run: function(event, args, cb, silent) {
|
||||
Last: function() {kit.notNone(plugin.History()) && plugin.Check()},
|
||||
Runs: function(event, cb) {plugin.Run(event, kit.Selector(option, ".args", function(item, index) {return item.value}), cb)},
|
||||
Run: function(event, args, cb, silent) {var show = true
|
||||
page.script("record", ["action", name].concat(args))
|
||||
var show = true
|
||||
setTimeout(function() {
|
||||
show && page.ontoast(kit.Format(args||["running..."]), meta.name, -1)
|
||||
}, 1000)
|
||||
setTimeout(function() {show && plugin.ontoast(kit.Format(args||["running..."]), meta.name, -1)}, 1000)
|
||||
event.Plugin = plugin, runs(event, args, function(msg) {
|
||||
page.footer.Pane.State("ncmd", kit.History.get("cmd").length)
|
||||
silent? kit._call(cb, [msg]): plugin.ondaemon(msg, cb)
|
||||
show = false, page.ontoast("")
|
||||
silent? kit._call(cb, [msg]): plugin.ondaemon(msg, cb), show = false, plugin.ontoast()
|
||||
})
|
||||
},
|
||||
clear: function() {
|
||||
output.innerHTML = ""
|
||||
},
|
||||
clear: function() {output.innerHTML = ""},
|
||||
Download: function() {
|
||||
var text = kit.Selector(output, "tr", function(tr) {
|
||||
var type = "csv", text = kit.Selector(output, "tr", function(tr) {
|
||||
return kit.Selector(tr, "td,th", function(td) {
|
||||
return td.innerText
|
||||
}).join(",")
|
||||
}).join("\n"), type = ".csv"
|
||||
}).join("\n")
|
||||
!text && (type = ".txt", text = plugin.msg.result.join(""))
|
||||
|
||||
!text && (text = plugin.msg.result.join(""), type = ".txt")
|
||||
page.ontoast({text:'<a href="'+URL.createObjectURL(new Blob([text]))+'" target="_blank" download="'+name+type+'">'+name+type+'</a>', title: "下载中...", width: 200})
|
||||
kit.Selector(page.toast, "a", function(item) {
|
||||
item.click()
|
||||
})
|
||||
plugin.ontoast({text:'<a href="'+URL.createObjectURL(new Blob([text]))+'" target="_blank" download="'+name+type+'">'+name+type+'</a>', title: "下载中...", width: 200})
|
||||
kit.Selector(page.toast, "a", function(item) {item.click()})
|
||||
},
|
||||
upload: function(event) {
|
||||
ctx.Upload({river: meta.river, table: plugin.Option("table")}, option.upload.files[0], function(event, msg) {
|
||||
kit.OrderTable(kit.AppendTable(kit.AppendChilds(output, "table"), ctx.Table(msg), msg.append))
|
||||
page.ontoast("上传成功")
|
||||
Output(plugin, "table", msg, null, output, option)
|
||||
plugin.ontoast("上传成功")
|
||||
}, function(event) {
|
||||
page.ontoast(), page.ontoast("上传进度 "+parseInt(event.loaded*100/event.total)+"%")
|
||||
plugin.ontoast("上传进度 "+parseInt(event.loaded*100/event.total)+"%")
|
||||
})
|
||||
},
|
||||
|
||||
ontoast: page.ontoast,
|
||||
ontoast: function() {kit._call(page.toast.Pane.Show, arguments)},
|
||||
oncarte: function() {kit._call(page.carte.Pane.Show, arguments)},
|
||||
onformat: shy("数据转换", {
|
||||
none: function(value) {return value||""},
|
||||
date: function(value) {return kit.format_date(new Date())},
|
||||
date: function(value) {return kit.time()},
|
||||
}, function(which, value) {var meta = arguments.callee.meta
|
||||
return (meta[which||"none"]||meta["none"])(value)
|
||||
}),
|
||||
|
||||
ondaemon: shy("接收数据", function(msg, cb) {
|
||||
plugin.msg = msg, plugin.Save(""), plugin.onfigure.meta.type = "", plugin.onfigure(deal, msg, cb)
|
||||
plugin.msg = msg, plugin.Save(""), plugin.onfigure.meta.type = "", plugin.onfigure(feature.display||"table", msg, cb)
|
||||
}),
|
||||
onfigure: shy("显示数据", {type: "",
|
||||
max: function(output) {
|
||||
@ -985,25 +925,20 @@ function Plugin(page, pane, field, inits, runs) {
|
||||
}),
|
||||
onchoice: shy("菜单列表", {
|
||||
"添加": "Clone",
|
||||
"删除": "Delete",
|
||||
"加参": "Appends",
|
||||
"减参": "Remove",
|
||||
}, ["添加", "删除", "加参", "减参"], function(value, meta, event) {
|
||||
"删除": "Delete",
|
||||
}, ["添加", "加参", "减参", "删除"], function(value, meta, event) {
|
||||
kit._call(plugin, plugin[meta[value]])
|
||||
return true
|
||||
}),
|
||||
onaction: shy("事件列表", {
|
||||
oncontextmenu: function(event) {
|
||||
page.oncarte(event, plugin.onchoice)
|
||||
plugin.oncarte(event, plugin.onchoice)
|
||||
},
|
||||
}, function() {
|
||||
kit.Item(arguments.callee.meta, function(k, cb) {field[k] = function(event) {
|
||||
cb(event)
|
||||
}})
|
||||
}),
|
||||
}, function(event, key, cb) {cb(event)}),
|
||||
})
|
||||
|
||||
plugin.onaction()
|
||||
plugin.which = plugin.Sync("input")
|
||||
page[field.id] = pane[field.id] = pane[name] = field, field.Plugin = plugin
|
||||
inputs.map(function(item) {plugin.Append(item)})
|
||||
@ -1111,17 +1046,13 @@ function Inputs(plugin, item, target) {
|
||||
return true
|
||||
})
|
||||
},
|
||||
}, function() {
|
||||
kit.Item(arguments.callee.meta, function(k, cb) {target[k] = function(event) {
|
||||
cb(event)
|
||||
}})
|
||||
}),
|
||||
}, function(event, key, cb) {cb(event)}),
|
||||
Event: shy("事件入口", {name: plug+"."+name}, function(event, msg) {
|
||||
return ctx.Event(event, msg||{}, arguments.callee.meta)
|
||||
}),
|
||||
which: plugin.Sync(name),
|
||||
}, plugin)
|
||||
input.onaction()
|
||||
|
||||
input.onimport()
|
||||
target.value = plugin.onformat(item.init, item.value)
|
||||
plugin.Inputs[item.name] = target, target.Input = input
|
||||
@ -1145,8 +1076,8 @@ function Output(plugin, type, msg, cb, target, option) {
|
||||
event.Plugin = plugin
|
||||
|
||||
line.you && name == "status" && (line.status == "start"? function() {
|
||||
plugin.Delay(3000, event, line.you+" stop...") && field.Run(event, [option.pod.value, line.you, "stop"])
|
||||
}(): field.Run(event, [option.pod.value, line.you], function(msg) {
|
||||
plugin.Delay(3000, event, line.you+" stop...") && plugin.Run(event, [option.pod.value, line.you, "stop"])
|
||||
}(): plugin.Run(event, [option.pod.value, line.you], function(msg) {
|
||||
plugin.Delay(3000, event, line.you+" start...")
|
||||
}))
|
||||
return name == "status" || line.status == "stop" ? undefined: line.you
|
||||
@ -1168,7 +1099,7 @@ function Output(plugin, type, msg, cb, target, option) {
|
||||
}),
|
||||
onimport: shy("导入数据", {
|
||||
_table: function(msg, list) {
|
||||
return list && list.length > 0 && kit.OrderTable(kit.AppendTable(kit.AppendChild(target, "table"), ctx.Table(msg), list), "", output.onexport)
|
||||
return list && list.length > 0 && kit.OrderTable(kit.AppendTable(kit.AppendChild(target, "table"), msg.Table(), list), "", output.onexport)
|
||||
},
|
||||
_code: function(msg) {
|
||||
return msg.result && msg.result.length > 0 && kit.OrderCode(kit.AppendChild(target, [{view: ["code", "div", msg.Results()]}]).first)
|
||||
@ -1202,15 +1133,10 @@ function Output(plugin, type, msg, cb, target, option) {
|
||||
}),
|
||||
onaction: shy("事件列表", {
|
||||
oncontextmenu: function(event) {
|
||||
page.oncarte(event, output.onchoice)
|
||||
plugin.oncarte(event, output.onchoice)
|
||||
},
|
||||
}, function() {
|
||||
kit.Item(arguments.callee.meta, function(k, cb) {target[k] = function(event) {
|
||||
cb(event)
|
||||
}})
|
||||
}),
|
||||
}, function(event, key, cb) {cb(event)}),
|
||||
}, plugin)
|
||||
output.onaction()
|
||||
output.onimport(type, msg, cb)
|
||||
return output
|
||||
}
|
||||
|
@ -1,9 +1,3 @@
|
||||
Wrap = function(cb, obj) {
|
||||
for (var k in obj) {
|
||||
cb[k] = obj[k]
|
||||
}
|
||||
return cb
|
||||
}
|
||||
shy = function(help, meta, list, cb) {
|
||||
var index = -1, value = "", type = "string", args = arguments
|
||||
function next(check) {
|
||||
@ -16,18 +10,10 @@ shy = function(help, meta, list, cb) {
|
||||
cb.help = next("string") || "还没有写"
|
||||
cb.meta = next("object") || {}
|
||||
cb.list = next("object") || {}
|
||||
cb.runs = function() {
|
||||
}
|
||||
cb.runs = function() {}
|
||||
return cb
|
||||
}
|
||||
|
||||
kit = toolkit = {__proto__: document,
|
||||
meta: function(cb, obj) {
|
||||
for (var k in obj) {
|
||||
cb[k] = obj[k]
|
||||
}
|
||||
return cb
|
||||
},
|
||||
kit = toolkit = (function() {var kit = {__proto__: document,
|
||||
// 用户终端
|
||||
device: {
|
||||
isWeiXin: navigator.userAgent.indexOf("MicroMessenger") > -1,
|
||||
@ -36,161 +22,96 @@ kit = toolkit = {__proto__: document,
|
||||
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()
|
||||
},
|
||||
alert: function(text) {alert(JSON.stringify(text))},
|
||||
confirm: function(text) {return confirm(text)},
|
||||
prompt: function(text) {return prompt(text)},
|
||||
reload: function() {location.reload()},
|
||||
// 日志调试
|
||||
History: {dir: [], pod: [], ctx: [], cmd: [], txt: [], key: [], lay: [],
|
||||
add: function(type, data) {
|
||||
var list = this[type] || []
|
||||
data && list.push({time: Date.now(), data: data})
|
||||
this[type] = list
|
||||
return list.length-1
|
||||
},
|
||||
get: function(type, index) {
|
||||
var list = this[type] || []
|
||||
var len = list.length
|
||||
return index == undefined? this[type]: this[type][(index+len)%len]
|
||||
},
|
||||
},
|
||||
Debug: Wrap(function(key) {
|
||||
var list = arguments.callee.list
|
||||
if (list[key]) {debugger}
|
||||
}, {list: {why: true, msg: true}}),
|
||||
Log: Wrap(function(type, arg) {
|
||||
var args = [kit.time().split(" ")[1]]
|
||||
if (arg == undefined) {
|
||||
args = args.concat(kit.Trans(type))
|
||||
} else {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
args.push(arguments[i])
|
||||
History: shy("历史记录", {lay: [], cmd: [], txt: [], key: []}, function(type, index, value) {var meta = arguments.callee.meta
|
||||
if (kit.isNone(index)) {return meta[type]}
|
||||
var list = meta[type] || []
|
||||
if (kit.isNone(value)) {var len = list.length
|
||||
return list[(index+len)%len]
|
||||
}
|
||||
}
|
||||
|
||||
var mine = arguments.callee
|
||||
!mine.hide[args[1]] && console[mine.func[args[1]]||"log"](args)
|
||||
|
||||
return meta[type] = list, list.push({time: Date.now(), data: data})-1
|
||||
}),
|
||||
Debug: shy("调试断点", {why: true, msg: true}, function(key) {
|
||||
if (arguments.callee.meta[key]) {debugger}
|
||||
}),
|
||||
Log: shy("输出日志", {hide: {"init": true, "wss": false},
|
||||
func: {debug: "debug", info: "info", parn: "warn", err: "error"},
|
||||
}, function(type, arg) {var meta = arguments.callee.meta
|
||||
var args = [kit.time().split(" ")[1]].concat(kit.List(kit.isNone(arg)? type: arguments))
|
||||
!meta.hide[args[1]] && console[meta.func[args[1]]||"log"](args)
|
||||
kit.Debug(args[1])
|
||||
return args.slice(1)
|
||||
}, {hide: {"init": true, "wss": false}, func: {debug: "debug", info: "info", warn: "warn", err: "error"}}),
|
||||
Delay: function(time, cb) {
|
||||
return setTimeout(cb, time)
|
||||
},
|
||||
}),
|
||||
Tip: shy("用户提示", function() {}),
|
||||
|
||||
// HTML节点操作
|
||||
classList: {
|
||||
add: function(obj) {
|
||||
var list = obj.className? obj.className.split(" "): []
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
arguments[i] && list.indexOf(arguments[i]) == - 1 && list.push(arguments[i])
|
||||
}
|
||||
return obj.className = list.join(" ")
|
||||
add: function(obj, key) {var list = (obj.className||"").split(" ")
|
||||
return obj.className = list.concat(kit.List(arguments, function(value, index) {
|
||||
return index > 0 && list.indexOf(value) == -1? value: undefined
|
||||
})).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(" ")
|
||||
del: function(obj, key) {
|
||||
var list = kit.List(arguments, function(value, index) {return index > 0? value: undefined})
|
||||
return obj.className = kit.List(obj.className.split(" "), function(value) {
|
||||
return list.indexOf(value) == -1? value: undefined
|
||||
}).join(" ")
|
||||
},
|
||||
},
|
||||
ModifyView: function(which, args) {
|
||||
var height = document.body.clientHeight-4
|
||||
var width = document.body.clientWidth-4
|
||||
for (var k in args) {
|
||||
switch (k) {
|
||||
case "dialog":
|
||||
var w = h = args[k]
|
||||
if (typeof(args[k]) == "object") {
|
||||
w = args[k][0]
|
||||
h = args[k][1]
|
||||
}
|
||||
if (w > width) {
|
||||
w = width
|
||||
}
|
||||
if (h > height) {
|
||||
h = height
|
||||
}
|
||||
|
||||
var height = document.body.clientHeight-4
|
||||
kit.Item(args, function(key, value) {var w = h = value
|
||||
if (typeof(value) == "object") {w = value[0], h = value[1]}
|
||||
switch (key) {
|
||||
case "dialog": // 设置宽高
|
||||
if (w > width) {w = width}
|
||||
if (h > height) {h = height}
|
||||
args["top"] = (height-h)/2
|
||||
args["left"] = (width-w)/2
|
||||
args["width"] = w
|
||||
args["height"] = h
|
||||
args[k] = undefined
|
||||
break
|
||||
case "window":
|
||||
var w = h = args[k]
|
||||
if (typeof(args[k]) == "object") {
|
||||
w = args[k][0]
|
||||
h = args[k][1]
|
||||
}
|
||||
|
||||
case "window": // 设置边距
|
||||
args["top"] = h/2
|
||||
args["left"] = w/2
|
||||
args["width"] = width-w-20
|
||||
args["height"] = height-h-20
|
||||
args[k] = undefined
|
||||
break
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
delete(args[key])
|
||||
})
|
||||
|
||||
for (var k in args) {
|
||||
switch (k) {
|
||||
case "top":
|
||||
case "left":
|
||||
case "width":
|
||||
case "height":
|
||||
case "padding":
|
||||
args[k] = args[k]+"px"
|
||||
break
|
||||
}
|
||||
}
|
||||
var list = ["top", "left", "width", "height", "padding", "margin"]
|
||||
kit.Item(args, function(key, value) {
|
||||
typeof value == "number" && list.indexOf(key) != -1 && (args[key] = value+"px")
|
||||
})
|
||||
return kit.ModifyNode(which, {style: args})
|
||||
},
|
||||
ModifyNode: function(which, html) {
|
||||
var node = typeof which == "string"? document.querySelector(which): which
|
||||
switch (typeof html) {
|
||||
case "string":
|
||||
node.innerHTML = html
|
||||
break
|
||||
case "object":
|
||||
for (var k in html) {
|
||||
if (typeof html[k] == "object") {
|
||||
for (var d in html[k]) {
|
||||
node[k] && (node[k][d] = html[k][d])
|
||||
}
|
||||
continue
|
||||
}
|
||||
node[k] = html[k]
|
||||
}
|
||||
break
|
||||
}
|
||||
typeof html == "string"? (node.innerHTML = html): kit.Item(html, function(key, value) {
|
||||
typeof value != "object"? (node[key] = value): kit.Item(value, function(item, value) {
|
||||
node[key] && (node[key][item] = value)
|
||||
})
|
||||
})
|
||||
return node
|
||||
},
|
||||
CreateNode: function(element, html) {
|
||||
return this.ModifyNode(document.createElement(element), html)
|
||||
},
|
||||
CreateNode: function(element, html) {return kit.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
|
||||
var elm = kit.CreateNode(children, subs)
|
||||
return parent.append(elm), elm
|
||||
}
|
||||
|
||||
// 基本属性: name value title inner
|
||||
// 基本属性: name value title
|
||||
// 基本内容: inner innerHTML
|
||||
// 基本样式: style className
|
||||
// 基本事件: dataset click
|
||||
//
|
||||
@ -204,239 +125,159 @@ kit = toolkit = {__proto__: document,
|
||||
//
|
||||
// 基本结构: type data list
|
||||
|
||||
var kit = this
|
||||
|
||||
subs = subs || {}
|
||||
children.forEach(function(child, i) {
|
||||
if (!child) {
|
||||
return
|
||||
}
|
||||
child.data = child.data || {}
|
||||
child.type = child.type || "div"
|
||||
children.forEach(function(child, i) {if (kit.isNone(child)) {return}
|
||||
var type = child.type || "div", name = child.name, data = child.data || {}
|
||||
|
||||
if (child.name) {
|
||||
child.data["name"] = child.name
|
||||
}
|
||||
if (child.value) {
|
||||
child.data["value"] = child.value
|
||||
}
|
||||
if (child.title) {
|
||||
child.data["title"] = child.title
|
||||
}
|
||||
if (child.inner) {
|
||||
child.data["innerHTML"] = child.inner
|
||||
}
|
||||
if (typeof(child.style) == "object") {
|
||||
var str = []
|
||||
for (var k in child.style) {
|
||||
str.push(k)
|
||||
str.push(":")
|
||||
str.push(child.style[k] + (typeof child.style[k] == "number"? "px": ""))
|
||||
str.push(";")
|
||||
}
|
||||
child.data["style"] = str.join("")
|
||||
}
|
||||
if (child.className) {
|
||||
child.data["className"] = child.className
|
||||
}
|
||||
if (child.dataset) {
|
||||
child.data["dataset"] = child.dataset
|
||||
}
|
||||
if (child.click) {
|
||||
child.data["onclick"] = child.click
|
||||
kit.List([
|
||||
"name", "value", "title",
|
||||
"innerHTML",
|
||||
"className",
|
||||
"dataset",
|
||||
], function(key) {
|
||||
kit.notNone(child[key]) && (data[key] = child[key])
|
||||
})
|
||||
kit.notNone(child.click) && (data.onclick = child.click)
|
||||
kit.notNone(child.inner) && (data.innerHTML = child.inner)
|
||||
kit.notNone(child.style) && (data.style = typeof child.style == "string"? child.style: kit.Item(child.style, function(key, value) {
|
||||
return [key, ": ", kit.pixs(key, value)].join("")
|
||||
}).join("; "))
|
||||
|
||||
if (kit.notNone(child.button)) {var list = kit.List(child.button)
|
||||
type = "button", name = name || list[0]
|
||||
data.innerText = list[0], data.onclick = function(event) {
|
||||
kit._call(list[1], [list[0], event])
|
||||
}
|
||||
|
||||
if (child.button) {
|
||||
child.type = "button"
|
||||
child.data["onclick"] = function(event) {
|
||||
child.button[1](child.button[0], event)
|
||||
} else if (child.select) {var list = child.select
|
||||
type = "select", name = name || list[0][0]
|
||||
data.onchange = function(event) {
|
||||
kit._call(list[1], [event.target.value, event])
|
||||
}
|
||||
child.data["innerText"] = child.button[0]
|
||||
child.name = child.name || child.button[0]
|
||||
|
||||
} else if (child.select) {
|
||||
child.type = "select"
|
||||
child.name = child.select[0][0]
|
||||
child.list = child.select[0].map(function(value) {
|
||||
child.list = list[0].map(function(value) {
|
||||
return {type: "option", value: value, inner: value}
|
||||
})
|
||||
child.data["onchange"] = function(event) {
|
||||
child.select[1](event.target.value, event)
|
||||
|
||||
} else if (child.input) {var list = kit.List(child.input)
|
||||
type = "input", name = name || list[0]
|
||||
data.onkeydown = function(event) {
|
||||
kit._call(list[1], [event])
|
||||
}
|
||||
data.onkeyup = function(event) {
|
||||
kit._call(list[2], [event])
|
||||
}
|
||||
|
||||
} else if (child.input) {
|
||||
child.type = "input"
|
||||
child.data["name"] = child.input[0]
|
||||
// child.data["onkeyup"] = child.input[1]
|
||||
child.data["onkeydown"] = child.input[1]
|
||||
child.name = child.name || child.input[0]
|
||||
} else if (child.password) {var list = kit.List(child.password)
|
||||
type = "input", name = name || list[0]
|
||||
data.type = "password"
|
||||
|
||||
} else if (child.password) {
|
||||
child.type = "input"
|
||||
child.data["onkeyup"] = child.password[1]
|
||||
child.data["name"] = child.password[0]
|
||||
child.data["type"] = "password"
|
||||
child.name = child.name || child.password[0]
|
||||
} else if (child.label) {var list = kit.List(child.label)
|
||||
type = "label", data.innerText = list[0]
|
||||
|
||||
} else if (child.label) {
|
||||
child.type = "label"
|
||||
child.data["innerText"] = child.label
|
||||
|
||||
} else if (child.img) {
|
||||
child.type = "img"
|
||||
child.data["src"] = child.img[0]
|
||||
child.img.length > 1 && (child.data["onload"] = child.img[1])
|
||||
} else if (child.img) {var list = kit.List(child.img)
|
||||
type = "img", data.src = list[0], data.onload = function(event) {
|
||||
kit._call(list[1], [event])
|
||||
}
|
||||
|
||||
} else if (child.row) {
|
||||
child.type = "tr"
|
||||
child.list = child.row.map(function(item) {return {text: [item, "td"]}})
|
||||
type = "tr"
|
||||
child.list = child.row.map(function(item) {return {text: [item, child.sub||"td"]}})
|
||||
|
||||
} else if (child.tree) {
|
||||
child.type = "ul"
|
||||
child.list = child.tree
|
||||
type = "ul", child.list = child.tree
|
||||
|
||||
} else if (child.fork) {
|
||||
child.type = "li"
|
||||
child.list = [
|
||||
{"text": [child.fork[0], "div"], "click": (child.fork.length>2? child.fork[2]: "")},
|
||||
{"type": "ul", "list": child.fork[1]},
|
||||
} else if (child.fork) {var list = kit.List(child.fork)
|
||||
type = "li", child.list = [
|
||||
{"text": [list[0], "div"], "click": function(event) {
|
||||
kit._call(list[2], [event])
|
||||
}},
|
||||
{"type": "ul", "list": list[1]},
|
||||
]
|
||||
|
||||
} else if (child.leaf) {
|
||||
child.type = "li"
|
||||
child.list = [{"text": [child.leaf[0], "div"]}]
|
||||
if (child.leaf.length > 1 && typeof child.leaf[1] == "function") {
|
||||
child.data["onclick"] = function(event) {
|
||||
child.leaf[1](event, node)
|
||||
}
|
||||
} else if (child.leaf) {var list = kit.List(child.leaf)
|
||||
type = "li"
|
||||
child.list = [{"text": [list[0], "div"]}]
|
||||
data.onclick = function(event) {
|
||||
kit._call(list[1], [event])
|
||||
}
|
||||
|
||||
} else if (child.view) {
|
||||
(child.view.length > 0 && child.view[0]) && (child.data["className"] = child.view[0])
|
||||
child.type = child.view.length > 1? child.view[1]: "div"
|
||||
child.view.length > 2 && (child.data["innerHTML"] = child.view[2])
|
||||
child.view.length > 3 && (child.name = child.view[3])
|
||||
} else if (child.view) {var list = kit.List(child.view);
|
||||
(list.length > 0 && list[0]) && (data.className = list[0])
|
||||
type = list[1] || "div"
|
||||
data.innerHTML = list[2] || ""
|
||||
name = name || list[3] || ""
|
||||
|
||||
} else if (child.text) {
|
||||
child.data["innerHTML"] = 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.text) {var list = kit.List(child.text)
|
||||
data.innerHTML = list[0]
|
||||
type = list[1] || "pre"
|
||||
list.length > 2 && (data.className = list[2])
|
||||
|
||||
} else if (child.code) {
|
||||
child.type = "code"
|
||||
child.list = [{"type": "pre" ,"data": {"innerText": child.code[0]}, "name": child.code[1]}]
|
||||
child.code.length > 2 && (child.data["className"] = child.code[2])
|
||||
} else if (child.code) {var list = kit.List(child.code)
|
||||
type = "code"
|
||||
child.list = [{type: "pre" ,data: {innerText: list[0]}, name: list[1]||""}]
|
||||
list.length > 2 && (data.className = list[2])
|
||||
|
||||
} else if (child.script) {
|
||||
child.type = "script"
|
||||
child.data.innerHTML = child.script
|
||||
type = "script", data.innerHTML = child.script
|
||||
|
||||
} else if (child.include) {
|
||||
child.type = "script"
|
||||
child.data["src"] = child.include[0]
|
||||
child.data["type"] = "text/javascript"
|
||||
child.include.length > 1 && (child.data["onload"] = child.include[1])
|
||||
} else if (child.include) {var list = kit.List(child.include)
|
||||
type = "script", data.type = "text/javascript"
|
||||
data.src = list[0], data.onload = function(event) {
|
||||
kit._call(list[1], [event])
|
||||
}
|
||||
|
||||
} else if (child.require) {
|
||||
child.data["href"] = child.require[0]
|
||||
child.data["rel"] = "stylesheet"
|
||||
child.data["type"] = "text/css"
|
||||
child.require.length > 1 && (child.data["onload"] = child.require[1])
|
||||
child.type = "link"
|
||||
} else if (child.require) {var list = kit.List(child.require)
|
||||
type = "link", data.type = "text/css", data.rel = "stylesheet"
|
||||
data.href = list[0], data.onload = function(event) {
|
||||
kit._call(list[1], [event])
|
||||
}
|
||||
|
||||
// child.data["rel"] = child.require.length > 1? child.require[1]: "stylesheet"
|
||||
// child.data["type"] = child.require.length > 2? child.require[2]: "text/css"
|
||||
// child.require.length > 1 && (child.data["onload"] = child.require[1])
|
||||
//
|
||||
} else if (child.styles) {
|
||||
var str = []
|
||||
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")
|
||||
}
|
||||
}
|
||||
child.data["innerHTML"] = str.join("")
|
||||
child.data["type"] = "text/css"
|
||||
child.type = "style"
|
||||
|
||||
type = "style", data.type = "text/css"
|
||||
data.innerHTML = typeof child.styles == "string"? child.styles: kit.Item(child.styles, function(key, value) {
|
||||
return key + " {\n" + kit.Item(value, function(item, value) {
|
||||
return [" ", item, ": ", kit.pixs(value)].join("")
|
||||
}).join(";\n") + "\n}\n"
|
||||
}).join("")
|
||||
}
|
||||
|
||||
var node = kit.CreateNode(child.type, child.data)
|
||||
data.name = data.name || name || ""
|
||||
var node = kit.CreateNode(type, data)
|
||||
child.list && kit.AppendChild(node, child.list, subs)
|
||||
child.name && (subs[child.name] = node)
|
||||
subs.first || (subs.first = node)
|
||||
subs.last, subs.last = node
|
||||
subs.first || (subs.first = node), subs.last = node
|
||||
name && (subs[name] = node)
|
||||
parent.append(node)
|
||||
})
|
||||
return subs
|
||||
},
|
||||
AppendChilds: function(parent, children, subs) {
|
||||
return parent.innerHTML = "", this.AppendChild(parent, children, subs)
|
||||
return parent.innerHTML = "", kit.AppendChild(parent, children, subs)
|
||||
},
|
||||
InsertChild: function (parent, position, element, children) {
|
||||
var elm = this.CreateNode(element)
|
||||
this.AppendChild(elm, children)
|
||||
var elm = kit.CreateNode(element)
|
||||
kit.AppendChild(elm, children)
|
||||
return parent.insertBefore(elm, position || parent.firstElementChild)
|
||||
},
|
||||
// HTML控件操作
|
||||
AppendAction: function(parent, list, cb) {
|
||||
var result = []
|
||||
list.forEach(function(item, index) {
|
||||
if (item == "") {
|
||||
result.push({view: ["space"]})
|
||||
} else if (typeof item == "string") {
|
||||
result.push({button: [item, cb]})
|
||||
} else if (item.forEach) {
|
||||
result.push({select: [item, cb]})
|
||||
} else {
|
||||
result.push(item)
|
||||
}
|
||||
})
|
||||
return kit.AppendChild(parent, result)
|
||||
return kit.AppendChild(parent, kit.List(list, function(item, index) {
|
||||
return item === ""? {view: ["space"]}:
|
||||
typeof item == "string"? {button: [item, cb]}:
|
||||
item.forEach? {select: [item, cb]}: item
|
||||
}))
|
||||
},
|
||||
AppendStatus: function(parent, list, cb) {
|
||||
var result = []
|
||||
list.forEach(function(item, index) {
|
||||
if (item == "") {
|
||||
result.push({view: ["space"]})
|
||||
} else if (typeof item == "string") {
|
||||
result.push({button: [item, cb]})
|
||||
} else if (item.forEach) {
|
||||
result.push({select: [item, cb]})
|
||||
} else {
|
||||
result.push(item)
|
||||
}
|
||||
})
|
||||
return kit.AppendChild(parent, result)
|
||||
},
|
||||
AppendTable: function(table, data, fields, cb, cbs) {
|
||||
if (!data || !fields) {
|
||||
return
|
||||
}
|
||||
var kit = this
|
||||
var tr = kit.AppendChild(table, "tr")
|
||||
fields.forEach(function(key, j) {
|
||||
var td = kit.AppendChild(tr, "th", kit.Color(key))
|
||||
})
|
||||
AppendTable: function(table, data, fields, cb, cbs) {if (!data || !fields) {return}
|
||||
kit.AppendChild(table, [{row: fields, sub: "th"}])
|
||||
data.forEach(function(row, i) {
|
||||
var tr = kit.AppendChild(table, "tr", {className: "normal"})
|
||||
tr.Meta = row
|
||||
fields.forEach(function(key, j) {
|
||||
tr.Meta = row, fields.forEach(function(key, j) {
|
||||
var td = kit.AppendChild(tr, "td", kit.Color(row[key]))
|
||||
|
||||
if (key == "when") {td.className = "when"}
|
||||
if (row[key].startsWith("http")) {
|
||||
td.innerHTML = "<a href='"+row[key]+"' target='_blank'>"+row[key]+"</a>"
|
||||
}
|
||||
|
||||
cb && (td.onclick = function(event) {
|
||||
kit._call(cb, [row[key], key, row, i, tr, event])
|
||||
})
|
||||
@ -450,74 +291,46 @@ kit = toolkit = {__proto__: document,
|
||||
return table
|
||||
},
|
||||
RangeTable: function(table, index, sort_asc) {
|
||||
var list = table.querySelectorAll("tr")
|
||||
var list = kit.Selector(table, "tr").slice(1)
|
||||
|
||||
var is_time = true, is_number = true
|
||||
for (var i = 1; i < list.length; i++) {
|
||||
var text = list[i].childNodes[index].innerText
|
||||
var value = Date.parse(text)
|
||||
if (!(value > 0)) {
|
||||
is_time = false
|
||||
}
|
||||
kit.List(list, function(tr) {
|
||||
var text = tr.childNodes[index].innerText
|
||||
is_time = is_time && Date.parse(text) > 0
|
||||
is_number = is_number && !isNaN(parseInt(text))
|
||||
})
|
||||
|
||||
var value = parseInt(text)
|
||||
if (text != "" && !(value >= 0 || value <= 0)) {
|
||||
is_number = false
|
||||
}
|
||||
}
|
||||
var num_list = kit.List(list, function(tr) {
|
||||
var text = tr.childNodes[index].innerText
|
||||
return is_time? Date.parse(text):
|
||||
is_number? parseInt(text): text
|
||||
})
|
||||
|
||||
var num_list = [], new_list = []
|
||||
for (var i = 1; i < list.length; i++) {
|
||||
var text = list[i].childNodes[index].innerText
|
||||
if (is_time) {
|
||||
num_list.push(Date.parse(text))
|
||||
} else if (is_number) {
|
||||
num_list.push(parseInt(text) || 0)
|
||||
} else {
|
||||
num_list.push(text)
|
||||
}
|
||||
new_list.push(list[i])
|
||||
}
|
||||
|
||||
for (var i = 0; i < new_list.length; i++) {
|
||||
for (var j = i+1; j < new_list.length; j++) {
|
||||
for (var i = 0; i < num_list.length; i++) {
|
||||
for (var j = i+1; j < num_list.length; j++) {
|
||||
if (sort_asc? num_list[i] < num_list[j]: num_list[i] > num_list[j]) {
|
||||
var temp = num_list[i]
|
||||
num_list[i] = num_list[j]
|
||||
num_list[j] = temp
|
||||
var temp = new_list[i]
|
||||
new_list[i] = new_list[j]
|
||||
new_list[j] = temp
|
||||
var temp = list[i]
|
||||
list[i] = list[j]
|
||||
list[j] = temp
|
||||
}
|
||||
}
|
||||
new_list[i].parentElement && new_list[i].parentElement.removeChild(new_list[i])
|
||||
table.appendChild(new_list[i])
|
||||
list[i].parentElement && list[i].parentElement.removeChild(list[i])
|
||||
table.appendChild(list[i])
|
||||
}
|
||||
},
|
||||
OrderTable: function(table, field, cb) {
|
||||
if (!table) {return}
|
||||
table.onclick = function(event) {
|
||||
var index = 0
|
||||
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", function(item, i) {item == target.parentElement && (index = i)})
|
||||
|
||||
target.parentElement.childNodes.forEach(function(item, i) {
|
||||
if (item != target) {return}
|
||||
|
||||
if (target.tagName == "TH") {
|
||||
OrderTable: function(table, field, cb) {if (!table) {return}
|
||||
table.onclick = function(event) {var target = event.target
|
||||
target.parentElement.childNodes.forEach(function(item, i) {if (item != target) {return}
|
||||
if (target.tagName == "TH") {var dataset = target.dataset
|
||||
dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1
|
||||
kit.RangeTable(table, i, dataset["sort_asc"] == "1")
|
||||
return
|
||||
}
|
||||
var name = head.childNodes[i].innerText
|
||||
if (name.startsWith(field)) {
|
||||
// item.className = "select"
|
||||
// item.parentElement.className = "select"
|
||||
typeof cb == "function" && cb(event, item.innerText, name, item.parentNode.Meta, index)
|
||||
} else {var index = 0
|
||||
kit.Selector(table, "tr", function(item, i) {item == target.parentElement && (index = i)})
|
||||
var name = target.parentElement.parentElement.querySelector("tr").childNodes[i].innerText
|
||||
name.startsWith(field) && kit._call(cb, [event, item.innerText, name, item.parentNode.Meta, index])
|
||||
}
|
||||
kit.CopyText()
|
||||
})
|
||||
@ -526,33 +339,17 @@ kit = toolkit = {__proto__: document,
|
||||
},
|
||||
|
||||
// HTML显示文本
|
||||
Color: function(s) {
|
||||
if (!s) {return 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}
|
||||
|
||||
var kit = this
|
||||
code.onclick = function(event) {
|
||||
kit.CopyText()
|
||||
}
|
||||
},
|
||||
OrderLink: function(link) {
|
||||
link.target = "_blank"
|
||||
OrderCode: function(code) {if (!code) {return}
|
||||
code.onclick = function(event) {kit.CopyText()}
|
||||
},
|
||||
OrderLink: function(link) {link.target = "_blank"},
|
||||
OrderText: function(pane, text) {
|
||||
text.querySelectorAll("a").forEach(function(value, index, array) {
|
||||
kit.OrderLink(value, pane)
|
||||
})
|
||||
text.querySelectorAll("code").forEach(function(value, index, array) {
|
||||
kit.OrderCode(value)
|
||||
})
|
||||
text.querySelectorAll("table").forEach(function(value, index, array) {
|
||||
kit.OrderTable(value)
|
||||
})
|
||||
@ -590,13 +387,6 @@ kit = toolkit = {__proto__: document,
|
||||
value.id = id
|
||||
})
|
||||
return h0
|
||||
|
||||
text.querySelectorAll("table.wiki_list").forEach(function(value, index, array) {
|
||||
kit.OrderTable(value, "path", function(event) {
|
||||
var text = event.target.innerText
|
||||
ctx.Search({"class": text})
|
||||
})
|
||||
})
|
||||
},
|
||||
Position: function(which) {
|
||||
return (parseInt((which.scrollTop + which.clientHeight) / which.scrollHeight * 100)||0)+"%"
|
||||
@ -622,68 +412,48 @@ kit = toolkit = {__proto__: document,
|
||||
}
|
||||
return true
|
||||
},
|
||||
// HTML修改文本
|
||||
Delay: function(time, cb) {
|
||||
return setTimeout(cb, time)
|
||||
},
|
||||
|
||||
// 数据容器迭代
|
||||
Selector: function(obj, item, cb, interval, cbs) {
|
||||
var list = []
|
||||
kit.List(obj.querySelectorAll(item), function(item, index, array) {
|
||||
if (typeof cb == "function") {
|
||||
var value = cb(item, index, array)
|
||||
value != undefined && list.push(value)
|
||||
} else {
|
||||
list.push(item)
|
||||
}
|
||||
}, interval, cbs)
|
||||
|
||||
for (var i = list.length-1; i >= 0; i--) {
|
||||
if (list[i] == "") {
|
||||
list.pop()
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return list
|
||||
Push: function(list, value, check) {list = list || []
|
||||
return (kit.notNone||check)(value) && list.push(value), list
|
||||
},
|
||||
List: function(obj, cb, interval, cbs) {
|
||||
if (interval) {
|
||||
function loop(i) {
|
||||
if (i >= obj.length) {typeof cbs == "function" && cbs(); return}
|
||||
typeof cb == "function" && cb(obj[i], i, obj)
|
||||
setTimeout(function() {loop(i+1)}, interval)
|
||||
List: function(obj, cb, interval, cbs) {obj = typeof obj == "string"? [obj]: (obj || [])
|
||||
if (interval > 0) {
|
||||
function loop(i) {if (i >= obj.length) {return kit._call(cbs)}
|
||||
kit._call(cb, [obj[i], i, obj]), setTimeout(function() {loop(i+1)}, interval)
|
||||
}
|
||||
obj.length > 0 && setTimeout(function() {loop(0)}, interval/4)
|
||||
return obj
|
||||
}
|
||||
|
||||
obj = typeof obj == "string"? [obj]: (obj || [])
|
||||
|
||||
var list = []
|
||||
for (var i = 0; i < obj.length; i++) {
|
||||
list.push(typeof cb == "function"? cb(obj[i], i, obj): obj[i])
|
||||
kit.Push(list, kit._call(cb, [obj[i], i, obj]))
|
||||
}
|
||||
return list
|
||||
},
|
||||
Item: function(obj, cb) {
|
||||
var list = []
|
||||
Item: function(obj, cb) {var list = []
|
||||
for (var k in obj) {
|
||||
var v = typeof cb == "function"? cb(k, obj[k]): k
|
||||
v != undefined && list.push(v)
|
||||
kit.Push(list, kit._call(cb, [k, obj[k]]))
|
||||
}
|
||||
return list
|
||||
},
|
||||
Span: function(list) {
|
||||
list = list || []
|
||||
list.span = function(value, style) {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
if (typeof arguments[i] == "string") {
|
||||
list.push(arguments[i])
|
||||
} else {
|
||||
list.push('<span class="'+arguments[i][1]+'">', arguments[i][0], "</span>")
|
||||
Items: function(obj, cb) {var list = []
|
||||
for (var key in obj) {
|
||||
list = list.concat(kit.List(obj[key], function(value, index, array) {
|
||||
return kit._call(cb, [value, index, key, obj])
|
||||
}))
|
||||
}
|
||||
}
|
||||
list.push("<br/>")
|
||||
return list
|
||||
},
|
||||
Span: function(list) {list = list || []
|
||||
list.span = function(value, style) {
|
||||
return kit.List(arguments, function(item) {
|
||||
kit._call(list, list.push, typeof item == "string"? [item]: ['<span class="'+item[1]+'">', item[0], "</span>"])
|
||||
}), list.push("<br/>"), list
|
||||
}
|
||||
return list
|
||||
},
|
||||
@ -692,7 +462,33 @@ kit = toolkit = {__proto__: document,
|
||||
obj.style.opacity = value
|
||||
}, kit.Value(interval, 150))
|
||||
},
|
||||
Selector: function(obj, item, cb, interval, cbs) {var list = []
|
||||
kit.List(obj.querySelectorAll(item), function(item, index, array) {
|
||||
kit.Push(list, kit._call(cb, [item, index, array]))
|
||||
}, interval, cbs)
|
||||
|
||||
for (var i = list.length-1; i >= 0; i--) {
|
||||
if (list[i] !== "") {break}
|
||||
list.pop()
|
||||
}
|
||||
return list
|
||||
},
|
||||
// 数据类型转换
|
||||
isNone: function(c) {return c === undefined || c === null},
|
||||
notNone: function(c) {return !kit.isNone(c)},
|
||||
isSpace: function(c) {return c == " " || c == "Enter"},
|
||||
Format: function(objs) {return JSON.stringify(objs)},
|
||||
Color: function(s) {if (!s) {return 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
|
||||
},
|
||||
Value: function() {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
switch (arguments[i]) {
|
||||
@ -705,21 +501,7 @@ kit = toolkit = {__proto__: document,
|
||||
}
|
||||
}
|
||||
},
|
||||
isSpace: function(c) {
|
||||
return c == " " || c == "Enter"
|
||||
},
|
||||
right: function(arg) {
|
||||
if (arg == "true") {
|
||||
return true
|
||||
}
|
||||
if (arg == "false") {
|
||||
return false
|
||||
}
|
||||
if (arg) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
},
|
||||
distance: function(x0, y0, x1, y1) {return Math.sqrt(Math.pow(x1-x0, 2)+Math.pow(y1-y0, 2))},
|
||||
number: function(d, n) {
|
||||
var result = []
|
||||
while (d>0) {
|
||||
@ -734,68 +516,6 @@ kit = toolkit = {__proto__: document,
|
||||
result.reverse()
|
||||
return result.join("")
|
||||
},
|
||||
distance: function(x0, y0, x1, y1) {
|
||||
return Math.sqrt(Math.pow(x1-x0, 2)+Math.pow(y1-y0, 2))
|
||||
},
|
||||
format_date: function(arg) {
|
||||
arg = arg || new Date()
|
||||
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
|
||||
},
|
||||
Format: function(objs) {
|
||||
return JSON.stringify(objs)
|
||||
},
|
||||
Trans: function(arg) {
|
||||
var res = []
|
||||
if (arg != undefined && arg != null) {
|
||||
switch (typeof arg) {
|
||||
case "string":
|
||||
res.push(arg)
|
||||
break
|
||||
case "object":
|
||||
if (arg.length > 0) {
|
||||
for (var i = 0; i < arg.length; i++) {
|
||||
res.push(arg[i])
|
||||
}
|
||||
} else {
|
||||
for (var k in arg) {
|
||||
res.push(k)
|
||||
res.push(arg[k])
|
||||
}
|
||||
}
|
||||
break
|
||||
default:
|
||||
res.push(arg)
|
||||
}
|
||||
}
|
||||
for (var i = res.length - 1; i > -1; i--) {
|
||||
if (res[i] == undefined) {
|
||||
res.pop()
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return res
|
||||
},
|
||||
time: function(t, fmt) {
|
||||
var now = t? new Date(t): new Date()
|
||||
fmt = fmt || "%y-%m-%d %H:%M:%S"
|
||||
@ -807,28 +527,25 @@ kit = toolkit = {__proto__: document,
|
||||
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"
|
||||
},
|
||||
type: function(obj, type) {
|
||||
if (type == undefined) {return typeof obj}
|
||||
return typeof obj == type? obj: null
|
||||
size: function(obj, width, height) {obj.style.width = width+"px", obj.style.height = height+"px"},
|
||||
pixs: function(key, value) {
|
||||
var list = ["top", "left", "width", "height", "padding", "margin"]
|
||||
return typeof value == "number" && list.indexOf(key) != -1? value+"px": value
|
||||
},
|
||||
type: function(obj, type) {return type == undefined? typeof obj: typeof obj == type? obj: null},
|
||||
_call: function() {// obj, cb, arg
|
||||
var index = 0, obj, cb, arg;
|
||||
(obj = kit.type(arguments[index], "object")) && index++
|
||||
(cb = kit.type(arguments[index], "function")) && index++
|
||||
(cb = kit.type(arguments[index], "function")), index++
|
||||
(arg = kit.type(arguments[index], "object")) && index++
|
||||
|
||||
arg = arg || []
|
||||
while (index < arguments.length) {
|
||||
arg.push(arguments[index++])
|
||||
}
|
||||
cb = cb || function(){}
|
||||
return cb.apply(obj||window, arg||[])
|
||||
return typeof cb == "function"? cb.apply(obj||window, arg||[]): arg && arg.length > 0? arg[0]: null
|
||||
},
|
||||
}
|
||||
}; return kit})()
|
||||
|
||||
function Editor(run, plugin, option, output, width, height, space, msg) {
|
||||
exports = ["dir", "path", "dir"]
|
||||
@ -1569,7 +1286,7 @@ function Canvas(plugin, option, output, width, height, space, msg) {
|
||||
},
|
||||
}}]).last.getContext("2d")
|
||||
|
||||
var status = kit.AppendStatus(kit.AppendChild(output, [{view: ["status"]}]).last, [{name: "nshape"}, {"className": "cmd", style: {width: (output.clientWidth - 100)+"px"}, data: {autocomplete: "off"}, input: ["cmd", function(event) {
|
||||
var status = kit.AppendAction(kit.AppendChild(output, [{view: ["status"]}]).last, [{name: "nshape"}, {"className": "cmd", style: {width: (output.clientWidth - 100)+"px"}, data: {autocomplete: "off"}, input: ["cmd", function(event) {
|
||||
var target = event.target
|
||||
event.type == "keyup" && event.key == "Enter" && what.parse(target.value) && (!target.History && (target.History=[]),
|
||||
target.History.push(target.value), target.Current=target.History.length, target.value = "")
|
||||
|
@ -53,7 +53,7 @@ var page = Page({
|
||||
page.onlayout()
|
||||
})
|
||||
|
||||
ctx.Runs(form, function(msg) {
|
||||
ctx.Run(form.dataset, [], function(msg) {
|
||||
ui.back.innerHTML = "", kit.AppendChild(ui.back, [
|
||||
{"button": ["知识", function(event) {
|
||||
ctx.Search({"level": "", "class": "", "favor": ""})
|
||||
@ -129,7 +129,7 @@ var page = Page({
|
||||
|
||||
ctx.Search("layout") == "max" && (page.Conf("tree.display", "none"), page.Conf("menu.display", "none"))
|
||||
|
||||
ctx.Runs(form, function(msg) {
|
||||
ctx.Run(form.dataset, [], function(msg) {
|
||||
ui.menu.innerHTML = "", ui.text.innerHTML = msg.result? msg.result.join(""): ""
|
||||
kit.AppendChild(ui.menu, [{"tree": kit.OrderText(field, ui.text)}])
|
||||
page.footer.Pane.State("count", msg.visit_count)
|
||||
|
@ -13,11 +13,11 @@
|
||||
{{end}}
|
||||
</head>
|
||||
<body>
|
||||
<fieldset class="carte"><legend></legend>
|
||||
<fieldset class="carte" data-init="initCarte"><legend></legend>
|
||||
<form class="option" data-names="carte"></form>
|
||||
<div class="output"></div>
|
||||
</fieldset>
|
||||
<fieldset class="toast"><legend></legend>
|
||||
<fieldset class="toast" data-init="initToast"><legend></legend>
|
||||
<form class="option" data-names="toast"></form>
|
||||
<div class="output"></div>
|
||||
</fieldset>
|
||||
|
Loading…
x
Reference in New Issue
Block a user