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