From 7c4a8caaadb70f106b527825ac4b2076f960e52e Mon Sep 17 00:00:00 2001 From: shaoying Date: Sun, 6 Oct 2019 23:48:41 +0800 Subject: [PATCH] opt View.Meta.js --- src/plugin/context/index.js | 3 +- src/plugin/favor/index.js | 16 ++-- src/plugin/favor/index.shy | 2 +- src/plugin/favor/macro.js | 60 ++++++------ src/plugin/love/index.js | 4 +- src/plugin/mind/index.js | 4 +- src/plugin/storage/index.js | 4 +- src/plugin/tmux/index.js | 5 +- src/plugin/weixin/index.js | 4 +- usr/librarys/chat.js | 46 ++++++---- usr/librarys/context.js | 9 +- usr/librarys/example.css | 3 + usr/librarys/example.js | 172 +++++++++++++++++------------------ usr/librarys/toolkit.js | 14 ++- usr/template/plugin/index.js | 4 +- 15 files changed, 174 insertions(+), 176 deletions(-) diff --git a/src/plugin/context/index.js b/src/plugin/context/index.js index 5147fb34..37ee2e2a 100644 --- a/src/plugin/context/index.js +++ b/src/plugin/context/index.js @@ -1,5 +1,4 @@ Script["context/index.js"] = function(field, option, output) { - return { - } + return {} } diff --git a/src/plugin/favor/index.js b/src/plugin/favor/index.js index 114a7e29..c3792c06 100644 --- a/src/plugin/favor/index.js +++ b/src/plugin/favor/index.js @@ -1,10 +1,8 @@ -{init: function(field, option, output) { - return { - share: function() {var plugin = field.Plugin - plugin.Run(event, ["share", args[0]], function(msg) { - kit.AppendChilds(output, [{img: [msg.result.join("")]}]) - typeof cb == "function" && cb({}) - }) - }, - } +Plugin["favor/index.js"] = function(field, option, output) {return { + share: function(event) {var plugin = field.Plugin + plugin.Run(event, ["share", option.txt.value], function(msg) { + kit.AppendChilds(output, [{img: [msg.result.join("")]}]) + typeof cb == "function" && cb({}) + }) + }, }} diff --git a/src/plugin/favor/index.shy b/src/plugin/favor/index.shy index 13fb78f6..945d6414 100644 --- a/src/plugin/favor/index.shy +++ b/src/plugin/favor/index.shy @@ -1,7 +1,7 @@ fun qrcode "二维码" "index.js" public \ text "" name txt view long \ - button "生成" + button "生成" cb share append qrcode ($1 || $referer) end diff --git a/src/plugin/favor/macro.js b/src/plugin/favor/macro.js index a1bd5cae..2fa73caa 100644 --- a/src/plugin/favor/macro.js +++ b/src/plugin/favor/macro.js @@ -1,35 +1,33 @@ -{init: function(field, option, output) { - return { - Record: function() { - if (confirm("run script "+option.mac.value)) { - page.script("record", option.mac.value) - } - }, - Replay: function() { - if (confirm("run script "+option.mac.value)) { - page.script("replay", option.mac.value) - } - }, - all: function() {var plugin = field.Plugin - option.mac.value = "", plugin.Runs(window.event, function() { - page.Sync("plugin_"+plugin.exports[0]).set(plugin.onexport[plugin.exports[2]||""]("", "name", {name: ""})) - }) - }, - Run: function(event, args, cb) {var plugin = field.Plugin - var script = page.script() - if (args[0] && !script[args[0]]) { - return confirm("create script "+args[0]) && page.script("create", args[0]) - } +Plugin["favor/macro.js"] = function(field, option, output) {return { + Record: function() { + if (confirm("run script "+option.mac.value)) { + page.script("record", option.mac.value) + } + }, + Replay: function() { + if (confirm("run script "+option.mac.value)) { + page.script("replay", option.mac.value) + } + }, + all: function() {var plugin = field.Plugin + option.mac.value = "", plugin.Runs(window.event, function() { + page.Sync("plugin_"+plugin.exports[0]).set(plugin.onexport[plugin.exports[2]||""]("", "name", {name: ""})) + }) + }, + Run: function(event, args, cb) {var plugin = field.Plugin + var script = page.script() + if (args[0] && !script[args[0]]) { + return confirm("create script "+args[0]) && page.script("create", args[0]) + } - plugin.msg = args[0]? ({append: ["index", "script"], - index: kit.List(script[args[0]], function(item, index) {return index+""}), - script: kit.List(script[args[0]], function(item) {return item.join(" ")}), + plugin.msg = args[0]? ({append: ["index", "script"], + index: kit.List(script[args[0]], function(item, index) {return index+""}), + script: kit.List(script[args[0]], function(item) {return item.join(" ")}), - }): ({append: ["name", "count"], - name: kit.Item(script), - count: kit.Item(script, function(key, list) {return list.length+""}), + }): ({append: ["name", "count"], + name: kit.Item(script), + count: kit.Item(script, function(key, list) {return list.length+""}), - }), plugin.display("table", cb) - }, - } + }), plugin.display("table", cb) + }, }} diff --git a/src/plugin/love/index.js b/src/plugin/love/index.js index fd9dc109..659ed1a7 100644 --- a/src/plugin/love/index.js +++ b/src/plugin/love/index.js @@ -5,7 +5,7 @@ Plugin["love/index.js"] = function(field, option, output) {return { }) }, show: function(event) {var plugin = field.Plugin - plugin.Check(undefined, function(msg) { + plugin.Check(event, undefined, function(msg) { plugin.Run(event, [option.table.value], function(msg) { kit.List(msg.Table(), function(line) { kit.Selector(output, ".s"+line.when.split(" ")[0].split("-").join(""), function(item) { @@ -27,7 +27,7 @@ Plugin["love/index.js"] = function(field, option, output) {return { return kit.AppendChilds(output, list) }); break case "date": - plugin.Check(undefined, function(msg) { + plugin.Check(event, undefined, function(msg) { kit.Selector(output, ".s"+line.when.split(" ")[0].split("-").join(""), function(item) { kit.classList.add(item.parentNode, "select") item.parentNode.title = line.what diff --git a/src/plugin/mind/index.js b/src/plugin/mind/index.js index 6859100d..12e78022 100644 --- a/src/plugin/mind/index.js +++ b/src/plugin/mind/index.js @@ -1,4 +1,4 @@ -{init: function(field, option, output) {return { +Plugin["mind/index.js"] = function(field, option, output) {return { ondaemon: { table: function(msg, cb) {if (msg.event && msg.event.type == "blur") {return} var plugin = field.Plugin @@ -53,4 +53,4 @@ }), typeof cb == "function" && cb(msg) }, }, -}}} +}} diff --git a/src/plugin/storage/index.js b/src/plugin/storage/index.js index 8c8f3659..1b2378e3 100644 --- a/src/plugin/storage/index.js +++ b/src/plugin/storage/index.js @@ -1,4 +1,2 @@ - -{init: function(page, pane, field, option, output) { - kit.Log("hello world") +Plugin["storage/index.js"] = function(field, option, output) {return { }} diff --git a/src/plugin/tmux/index.js b/src/plugin/tmux/index.js index 8c8f3659..805daf7a 100644 --- a/src/plugin/tmux/index.js +++ b/src/plugin/tmux/index.js @@ -1,4 +1,3 @@ - -{init: function(page, pane, field, option, output) { - kit.Log("hello world") +Plugin["tmux/index.js"] = function(field, option, output) {return { }} + diff --git a/src/plugin/weixin/index.js b/src/plugin/weixin/index.js index 6fe84818..28420fca 100644 --- a/src/plugin/weixin/index.js +++ b/src/plugin/weixin/index.js @@ -1,4 +1,2 @@ -{init: function(field, option, output) { - kit.Log("hello world") - return {} +Plugin["weixin/index.js"] = function(field, option, output) {return { }} diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index 5afaaf14..6c964ac4 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -85,13 +85,19 @@ var page = Page({check: true, ctx.Search({"river": page.river.Pane.which.get(), "storm": page.storm.Pane.which.get(), "layout": page.action.Pane.Layout()}) }, user: function(event, item, value, page) { - var name = kit.prompt("new name") - name && page.login.Pane.Run(["rename", name], function(msg) { - page.header.Pane.State("user", name) - }) - }, - logout: function(event, item, value, page) { - kit.confirm("logout?") && page.login.Pane.Exit() + page.carte.Pane.Show(event, shy({ + "修改昵称": function(event) { + var name = kit.prompt("new name") + name && page.login.Pane.Run(event, ["rename", name], function(msg) { + page.header.Pane.State("user", name) + }) + }, + "退出登录": function(event) { + kit.confirm("logout?") && page.login.Pane.Exit() + }, + }, ["修改昵称", "退出登录"], function(value, meta, event) { + meta[value](event) + })) }, }, @@ -154,12 +160,12 @@ var page = Page({check: true, }) }, Create: function(name, list) { - field.Pane.Run(["spawn", "", name].concat(list), function(msg) { + field.Pane.Run(event, ["spawn", "", name].concat(list), function(msg) { field.Pane.Show(), page.river.Pane.Show(name) }) }, Show: function(name) {var pane = field.Pane - pane.Dialog(), ui.name.focus(), ui.name.value = name||"good", pane.Run([], pane.Append) + pane.Dialog(), ui.name.focus(), ui.name.value = name||"good", pane.Run(event, [], pane.Append) }, Action: { "取消": function(event) {field.Pane.Show()}, @@ -184,7 +190,7 @@ var page = Page({check: true, page.ocean.Pane.Show() }, "共享": function(event) { - page.login.Pane.Run(["relay", "river", "username", kit.prompt("分享给用户"), "url", ctx.Share({ + page.login.Pane.Run(event, ["relay", "river", "username", kit.prompt("分享给用户"), "url", ctx.Share({ "river": page.river.Pane.which.get(), "layout": page.action.Pane.Layout(), })], function(msg) { @@ -203,7 +209,7 @@ var page = Page({check: true, output.DisplayTime = true return { Send: function(type, text, cb) {var pane = field.Pane - pane.Run([river, "flow", type, text], function(msg) { + pane.Run(event, [river, "flow", type, text], function(msg) { pane.Show(), typeof cb == "function" && cb(msg) }) }, @@ -421,7 +427,7 @@ var page = Page({check: true, }, _run: function() { var meta = plugin && plugin.target && plugin.target.Meta || {} - field.Pane.Run([meta.river||river, meta.storm||storm, meta.action].concat(args), function(msg) { + field.Pane.Run(event, [meta.river||river, meta.storm||storm, meta.action].concat(args), function(msg) { engine._msg(msg), typeof cbs == "function" && cbs(msg) }) }, @@ -433,8 +439,8 @@ var page = Page({check: true, if (river && storm && field.Pane.Load(river+"."+storm, output)) {return} pane.Event(event, {}, {name: pane.Zone("show", river, storm)}) - pane.clear(), pane.Update([river, storm], "plugin", ["node", "name"], "index", false, function(line, index, event, args, cbs) { - pane.Core(event, line, args, cbs) + pane.clear(), pane.Update([river, storm], "plugin", ["name", "help"], "name", true, function(line, index, event, args, cbs) { + kit.notNone(args) && pane.Core(event, line, args, cbs) }) }, Layout: function(name) {var pane = field.Pane @@ -550,7 +556,7 @@ var page = Page({check: true, ], Choice: [ ["layout", "聊天", "办公", "工作"], - "刷新", "清屏", "并行", "串行", "调试", + "", "刷新", "清屏", "并行", "串行", "调试", ], } }, @@ -588,7 +594,7 @@ var page = Page({check: true, var user = kit.prompt("分享给用户") if (user == null) {return} - page.login.Pane.Run(["relay", "storm", "username", user, "url", ctx.Share({ + page.login.Pane.Run(event, ["relay", "storm", "username", user, "url", ctx.Share({ "river": page.river.Pane.which.get(), "storm": page.storm.Pane.which.get(), "layout": page.action.Pane.Layout(), @@ -694,19 +700,19 @@ var page = Page({check: true, user = pod.user, node = pod.node, tr.className = "select" if (field.Pane.Load(river+"."+user+"."+node, device)) {return} - pane.Run([river, pod.user, pod.node], function(msg) { + pane.Run(event, [river, pod.user, pod.node], function(msg) { pane.Update(msg.Table(), pod) }) }), table.querySelector("td").click() }, Create: function(name, list) { - field.Pane.Run([river, "spawn", name].concat(list||[]), function(msg) { + field.Pane.Run(event, [river, "spawn", name].concat(list||[]), function(msg) { field.Pane.Show(), page.storm.Pane.Show(name) }) }, Show: function(name) {var pane = field.Pane pane.Event(event, {}, {name: pane.Zone("show", river)}) - pane.Dialog(), ui.name.focus(), ui.name.value = name||"nice", pane.Run([river], pane.Append) + pane.Dialog(), ui.name.focus(), ui.name.value = name||"nice", pane.Run(event, [river], pane.Append) }, Listen: { river: function(value, old) {river = value}, @@ -726,7 +732,7 @@ var page = Page({check: true, init: function(page) { page.action.Pane.Layout(ctx.Search("layout")? ctx.Search("layout"): kit.device.isMobile? page.conf.first: page.conf.mobile) page.footer.Pane.Order({"ncmd": "0", "ntxt": "0"}, ["ncmd", "ntxt"], function(event, item, value) {}) - page.header.Pane.Order({"logout": "logout", "user": "", "title": "github.com/shylinux/context"}, ["logout", "user"], function(event, item, value) { + page.header.Pane.Order({"user": "", "title": "github.com/shylinux/context"}, ["user"], function(event, item, value) { page.onaction[item] && page.onaction[item](event, item, value, page) }) page.river.Pane.Show() diff --git a/usr/librarys/context.js b/usr/librarys/context.js index 1993e892..40921376 100644 --- a/usr/librarys/context.js +++ b/usr/librarys/context.js @@ -1,6 +1,6 @@ ctx = context = (function(kit) {var ctx = {__proto__: kit, - Run: shy("请求后端", {order: 0}, function(dataset, cmd, cb) { - var msg = ctx.Event(event, null, {name: "ctx.run"}) + Run: shy("请求后端", {order: 0}, function(event, dataset, cmd, cb) { + var msg = ctx.Event(event) var option = {"cmds": cmd} msg.option && msg.option.forEach(function(item) { @@ -24,10 +24,9 @@ ctx = context = (function(kit) {var ctx = {__proto__: kit, this.POST("", option, function(msg) { kit.Log("run", what, "result", msg.result? msg.result[0]: "", msg) kit._call(cb, [msg]) - }, msg) + }, msg), delete(event.msg) }), Event: shy("封装事件", {order: 0}, function(event, msg, proto) { - event = event || document.createEvent("Event") if (event.msg && !msg) {return event.msg} event.msg = msg = msg || {}, proto = proto || {}, msg.__proto__ = proto, proto.__proto__ = { @@ -117,7 +116,7 @@ ctx = context = (function(kit) {var ctx = {__proto__: kit, 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.onload = function(event) {kit._call(cb, [event, ctx.Event(event, JSON.parse(xhr.responseText||'{"result":[]}'), {name: [document.title]})])} xhr.open("POST", "/upload", true) xhr.send(data) }), diff --git a/usr/librarys/example.css b/usr/librarys/example.css index 00af4927..3ad35086 100644 --- a/usr/librarys/example.css +++ b/usr/librarys/example.css @@ -215,6 +215,7 @@ fieldset.dialog.Carte>div.output div.item { fieldset.dialog.Carte>div.output div.space { border:solid 1px gray; margin-top:8px; + clear:both; } fieldset.dialog.Debug { height:300px; @@ -264,7 +265,9 @@ fieldset.Header>div.output>div.title { float:left; } fieldset.Header>div.output>div.title:hover { + cursor:pointer; background-color:red; + border:ridge 2px yellow; } fieldset.Header>div.output>div.state { float:right; diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 8a67063f..af945a9f 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -62,23 +62,21 @@ function Meta(zone, target, obj) { delete(cache[name]) return datas[name] }), - View: shy("添加视图", function(output, type, line, key, cb) { - var text = line, list = [], ui = {} + View: shy("添加视图", function(output, type, line, key) { + var text = line, list = [], item = false switch (type) { case "icon": - list.push({img: [line[key[0]], function(event) { - // event.target.scrollIntoView() - }]}) + list.push({img: [line[key[0]]]}) break case "text": list.push({text: [key.length>1? line[key[0]]+"("+line[key[1]]+")": - (key.length>0? line[key[0]]: "null"), "span"], click: cb}) + (key.length>0? line[key[0]]: "null"), "span"]}) break case "code": list.push({view: ["code", "div", key.length>1? line[key[0]]+"("+line[key[1]]+")": - (key.length>0? line[key[0]]: "null")], click: cb}) + (key.length>0? line[key[0]]: "null")]}) break case "table": @@ -89,30 +87,19 @@ function Meta(zone, target, obj) { })}) break - case "field": - var text = JSON.parse(line.text) - - case "plugin": - if (!text.name) {return {}} - - var id = "plugin"+this.ID() - list.push({view: ["item", "fieldset", "", "field"], data: {id: id, Run: cb}, list: [ + case "field": text = JSON.parse(line.text) + case "plugin": if (!text.name) {return {}} + var id = "plugin"+meta.ID() + list.push({view: ["item", "fieldset"], data: {id: id}, list: [ {text: [text.name+"("+text.help+")", "legend"]}, - {view: ["option", "form", "", "option"], list: [{type: "input", style: {"display": "none"}}]}, - {view: ["output", "div", "", "output"]}, - ]}) + {view: ["option", "form"], list: [{type: "input", style: {"display": "none"}}]}, + {view: ["output", "div"]}, + ]}), item = true break } - var item = [] - output.DisplayUser && item.push({view: ["user", "div", line.create_nick||line.create_user]}) - output.DisplayTime && (item.push({text: [line.create_time, "div", "time"]})) - item.push({view: ["text"], list:list}) - - !output.DisplayRaw && (list = [{view: ["item"], list:item}]) - ui = kit.AppendChild(output, list) - ui.field && (ui.field.Meta = text) - return ui + var ui = kit.AppendChild(output, item? list: [{view: ["item"], list:list}]) + return ui.item.Meta = text, ui }), Include: shy("加载脚本", function(src, cb) {src = kit.List(src) function next(event) {src.length > 1? meta.Include(src.slice(1), cb): cb(event)} @@ -149,14 +136,14 @@ function Page(page) { // 登录成功 document.querySelectorAll("body>fieldset").forEach(function(field) { page.Pane(page, field) - }), page.check? page.login.Pane.Run([], function(msg) { + }), page.check? page.login.Pane.Run(event, [], function(msg) { msg.result && msg.result[0]? (page.init(page), page.who.set(msg.nickname[0])) :page.login.Pane.Dialog(1, 1) }): page.init(page) } // 微信接口 - kit.device.isWeiXin && page.login.Pane.Run(["weixin"], function(msg) { + kit.device.isWeiXin && page.login.Pane.Run(event, ["weixin"], function(msg) { msg.appid[0] && page.Include(["https://res.wx.qq.com/open/js/jweixin-1.4.0.js"], function(event) { wx.error(function(res){}) wx.ready(function(){ @@ -409,10 +396,10 @@ function Page(page) { kit.List(args.button, function(input) { list.push({button: [input, function(event) { var values = {} - toast.querySelectorAll("input").forEach(function(input) { + output.querySelectorAll("input").forEach(function(input) { values[input.name] = input.value }) - toast.querySelectorAll("select").forEach(function(input) { + output.querySelectorAll("select").forEach(function(input) { values[input.name] = input.value }) kit._call(args.cb, [input, values]) && field.Pane.Hide() @@ -429,10 +416,17 @@ function Page(page) { field.onmouseleave = function(event) {field.Pane.Hide()} return { Show: function(event, cb) {if (!cb.list || cb.list.length == 0) {return} + output.innerHTML = "" kit.AppendActions(output, cb.list, function(value, event) { kit._call(cb, [value, cb.meta, event]) && field.Pane.Hide() }, true) - kit.ModifyView(field, {display: "block", left: event.x, top: event.y}) + + var pos = {display: "block", left: event.x, top: event.y} + if (document.body.clientWidth - event.x < 60) { + var pos = {display: "block", right: event.x, top: event.y} + } + + kit.ModifyView(field, pos) event.stopPropagation() event.preventDefault() }, @@ -496,13 +490,13 @@ function Page(page) { var ui = kit.AppendChilds(option, [ {label: "username"}, {input: ["username"], data: {autocomplete: "username"}}, {type: "br"}, {label: "password"}, {password: ["password"], data: {autocomplete: "current-password"}}, {type: "br"}, - {button: ["login", function(event) { + {button: ["login", function(value, event) { if (!ui.username.value) {ui.username.focus(); return} if (!ui.password.value) {ui.password.focus(); return} field.Pane.Login(ui.username.value, ui.password.value, function(sessid) { if (!sessid) {kit.alert("用户或密码错误"); return} - page.login.Pane.Dialog(1, 1), page.onload() + page.login.Pane.Dialog(1, 1), page.onload(event) }) }]}, {type: "br"}, ]) @@ -512,7 +506,7 @@ function Page(page) { } return { Login: function(username, password, cb) { - field.Pane.Run([username, password], function(msg) {cb(msg.result && msg.result[0] || "")}) + field.Pane.Run(event, [username, password], function(msg) {cb(msg.result && msg.result[0] || "")}) }, Exit: function() {ctx.Cookie("sessid", ""), kit.reload()}, } @@ -606,55 +600,54 @@ function Pane(page, field) { var option = field.querySelector("form.option") var action = field.querySelector("div.action") var output = field.querySelector("div.output") + var itemkeys = "fieldset.item.select, div.item.select" + var itemkey = "fieldset.item, div.item" var timer = "" var name = option.dataset.names - var member = {} var pane = Meta(page.Zone(name), field, (page[field.dataset.init] || function() { })(page, field, option, output) || {}, { Append: function(type, line, key, which, cb) {type = type || line.type - var index = kit.Selector(output, "div.item").length - var ui = pane.View(output, type, line, key, function(event, cmds, cbs) { - (type != "plugin" && type != "field") && pane.Select(index, line[which]) + var index = kit.Selector(output, itemkey).length + var ui = pane.View(output, type, line, key) + + ui.item.onclick = function(event) { + if (!pane.which.set(line[which])) {return} + kit.Selector(output, itemkeys, function(item) {kit.classList.del(item, "select")}) + kit.Selector(output, itemkey, function(item, i) {i == index && kit.classList.add(item, "select")}) + + pane.Event(event, {}, {name: pane.Zone("select", line[key[0]])}) page.script("record", [name, line[key[0]]]) - kit._call(cb, [line, index, event, cmds, cbs]) - }) + kit._call(cb, [line, index, event]) + } - field.scrollBy(0, field.scrollHeight+100) - key && key.length > 0 && (member[line[which]] = member[line[key[0]]] = {key:line[which]}); - - (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) { - var p = pane.Plugin(page, pane, ui.field, init, function(event, cmds, cbs) { - kit._call(cb, [line, index, event, cmds, cbs]) + if (type == "plugin" && line.name || type == "field") { + page.Require(line.init? line.group+"/"+line.init: "", function(init) { + page.Require(line.view? line.group+"/"+line.view: "", function(view) { + pane.Plugin(page, pane, ui.item, init, function(event, cmds, cbs) { + kit._call(cb, [line, index, event, cmds, cbs]) + }) }) - index == 0 && p.Select() }) - }) + } return ui }, Update: function(cmds, type, key, which, first, cb, cbs) { - pane.Runs(cmds, function(line, index, msg) { + pane.Runs(event, cmds, function(line, index, msg) { var ui = pane.Append(type, line, key, which, cb) if (typeof first == "string") { - (line.key == first || line.name == first || line[which] == first || line[key[0]] == first) && ui.first.click() + (line.key == first || line.name == first || line[which] == first || line[key[0]] == first) && ui.item.click() } else { - first && index == 0 && ui.first.click() + first && index == 0 && ui.item.click() } if (index == msg[msg.append[0]].length-1) { + kit.Selector(output, itemkeys).length == 0 && pane.Select(0) kit._call(cbs, [msg]) } }) }, - Select: function(index, key) { - kit.Selector(output, "div.item.select", function(item) {kit.classList.del(item, "select")}) - kit.Selector(output, "div.item", function(item, i) { - if (i == index) {kit.classList.add(item, "select")} - }) - - // Event入口 1.0 - pane.Event(event, {}, {name: pane.Zone("select", key)}) - key && pane.which.set(key) + Select: function(index) { + kit.Selector(output, itemkey, function(item, i) {i == index && item.click()}) }, clear: function() {output.innerHTML = ""}, @@ -702,21 +695,21 @@ function Pane(page, field) { }, Ticker: function(time, cmds, cb) {timer && clearTimeout(timer) function loop() { - window.event = document.createEvent("Event") + event = document.createEvent("Event") pane.Event(event, {}, {name: pane.Zone("ticker")}) - !pane.Stop() && pane.Run(cmds, function(msg) { + !pane.Stop() && pane.Run(event, cmds, function(msg) { cb(msg), timer = setTimeout(loop, time) })} time && (timer = setTimeout(loop, 10)) }, - Runs: function(cmds, cb) { - pane.Run(cmds, function(msg) {msg.Table(function(line, index) { + Runs: function(event, cmds, cb) { + pane.Run(event, cmds, function(msg) {msg.Table(function(line, index) { (cb||pane.ondaemon)(line, index, msg) })}) }, - Run: function(cmds, cb) { + Run: function(event, cmds, cb) { pane.Event(event, null, {name: pane.Zone(cmds[0])}) - ctx.Run(option.dataset, cmds, cb||pane.ondaemon) + ctx.Run(event, option.dataset, cmds, cb||pane.ondaemon) }, Show: function() { @@ -874,7 +867,7 @@ function Plugin(page, pane, field, inits, runs) { Clone: function() { return pane.Append("field", {text: plugin.Format()}, [], "", function(line, index, event, cmds, cbs) { plugin.Run(event, cmds, cbs, true) - }).field.Plugin.Select() + }).item.Plugin.Select() }, Next: function() { return field.nextSibling || field.parentNode.firstChild @@ -947,12 +940,12 @@ function Plugin(page, pane, field, inits, runs) { kit.notNone(value) && option[key] && (option[key].value = value) return option[key]? option[key].value: "" }, - Check: function(target, cb) { + Check: function(event, target, cb) { kit.Selector(option, ".args", function(item, index, list) { - 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()) + kit.isNone(target)? index == list.length-1 && plugin.Runs(event, cb): + item == target && (index == list.length-1? plugin.Runs(event, cb): page.plugin == field && list[index+1].focus()) return item - }).length == 0 && plugin.Runs(window.event, cb) + }).length == 0 && plugin.Runs(event, cb) }, Delay: function(time, event, text) { plugin.ontoast(text, "", -1) @@ -960,7 +953,7 @@ function Plugin(page, pane, field, inits, runs) { plugin.Runs(event), plugin.ontoast("") }, time) }, - Last: function() {kit.notNone(plugin.History()) && plugin.Check()}, + Last: function() {kit.notNone(plugin.History()) && plugin.Check(event)}, Runs: function(event, cb) {plugin.Run(event, kit.Selector(option, ".args", function(item, index) {return item.value}), cb)}, Run: function(event, args, cb, silent) {var show = true page.script("record", ["action", name].concat(args)) @@ -1015,11 +1008,12 @@ function Plugin(page, pane, field, inits, runs) { !plugin.Load(type, output) && Output(plugin, type || feature.display, msg || plugin.msg, cb, output, option) }), onchoice: shy("菜单列表", { + "返回": "Last", "添加": "Clone", "加参": "Appends", "减参": "Remove", "删除": "Delete", - }, ["添加", "加参", "减参", "删除"], function(value, meta, event) { + }, ["返回", "添加", "加参", "减参", "删除"], function(value, meta, event) { kit._call(plugin, plugin[meta[value]]) return true }), @@ -1043,7 +1037,8 @@ function Inputs(plugin, meta, item, target) { kit.List(arguments.callee.list, function(imports) { page.Sync(imports).change(function(value) { plugin.History(target.value, target), target.value = value - item.action == "auto" && plugin.Runs(document.createEvent("Event")) + input.Event(event = document.createEvent("Event")) + item.action == "auto" && plugin.Runs(event) }) }), item.type == "button" && item.action == "auto" && target.click() }), @@ -1051,21 +1046,22 @@ function Inputs(plugin, meta, item, target) { onfocus: function(event) {plugin.Select(target)}, onblur: function(event) {type == "text" && input.which.set(target.value)}, onclick: function(event) { + type == "text" // Event入口 2.0 - type == "button" && input.Event(event) && kit.Value(input[item.cb], plugin[item.cb], function() { - plugin.Check() + type == "button" && input.Event(event, {}) && kit.Value(input[item.cb], plugin[item.cb], function() { + plugin.Check(event) })(event, input) }, onchange: function(event) { // Event入口 2.1 - type == "select" && input.Event(event) && plugin.Check(item.action == "auto"? undefined: target) + type == "select" && input.Event(event, {}) && plugin.Check(event, item.action == "auto"? undefined: target) }, ondblclick: function(event) { var txt = kit.History("txt", -1) type == "text" && txt && (target.value = txt.data.trim()) }, - oncontextmenu: function(event) { - type == "text" && event.stopPropagation() + onselect: function(event) { + kit.CopyText() }, onkeydown: function(event) { switch (event.key) { @@ -1114,7 +1110,7 @@ function Inputs(plugin, meta, item, target) { if (event.key == "Enter" && (event.ctrlKey || item.type == "text")) { // Event入口 2.1 input.which.set(target.value) != undefined && plugin.History(target.value, target) - input.Event(event) && plugin.Check(target) + input.Event(event, {}) && plugin.Check(target) } }, onkeyup: function(event) { @@ -1160,7 +1156,6 @@ function Output(plugin, type, msg, cb, target, option) { return value.split("/")[0] }, you: function(value, name, line) { - var event = window.event event.Plugin = plugin line.you && name == "status" && (line.status == "start"? function() { @@ -1183,7 +1178,7 @@ function Output(plugin, type, msg, cb, target, option) { }, JSON.parse(exports||'["",""]'), function(event, value, name, line) { var meta = arguments.callee.meta var list = arguments.callee.list - ;(!list[1] || list[1] == name) && page.Sync("plugin_"+list[0]).set(meta[list[2]||""](value, name, line)) + ;(!list[1] || list[1] == name) && page.Sync("plugin_"+list[0]).set(meta[list[2]||""](value, name, line, list)) }), onimport: shy("导入数据", { _table: function(msg, list) { @@ -1195,7 +1190,7 @@ function Output(plugin, type, msg, cb, target, option) { inner: function(msg, cb) { target.innerHTML = "", plugin.onfigure.meta.max(target) output.onimport.meta._table(msg, msg.append) || (target.innerHTML = msg.result.join("")) - typeof cb == "function" && cb(msg) + kit._call(cb, [msg]) }, table: function(msg, cb) { target.innerHTML = "" @@ -1215,12 +1210,11 @@ function Output(plugin, type, msg, cb, target, option) { meta[type](msg, cb) }), onchoice: shy("菜单列表", { - "返回": "Last", - "清空": "clear", - "下载": "Download", "表格": "_table", "绘图": "_canvas", - }, ["返回", "表格", "绘图", "清空", "下载"], function(value, meta, event) { + "下载": "Download", + "清空": "clear", + }, ["表格", "绘图", "下载", "清空"], function(value, meta, event) { kit._call(output, output[meta[value]]) return true }), diff --git a/usr/librarys/toolkit.js b/usr/librarys/toolkit.js index 5264f762..75121c51 100644 --- a/usr/librarys/toolkit.js +++ b/usr/librarys/toolkit.js @@ -33,6 +33,7 @@ kit = toolkit = (function() {var kit = {__proto__: document, if (kit.isNone(data)) {var len = list.length return list[(index+len)%len] } + kit.Log("history", type, data) return meta[type] = list, list.push({time: Date.now(), data: data})-1 }), Debug: shy("调试断点", {why: true, msg: true}, function(key) { @@ -253,6 +254,7 @@ kit = toolkit = (function() {var kit = {__proto__: document, }).join("") } + name = name || data.className || type var node = kit.CreateNode(type, data) child.list && kit.AppendChild(node, child.list, subs) subs.first || (subs.first = node), subs.last = node @@ -356,8 +358,8 @@ kit = toolkit = (function() {var kit = {__proto__: document, var name = target.parentElement.parentElement.querySelector("tr").childNodes[i].innerText name.startsWith(field) && kit._call(cb, [event, item.innerText, name, item.parentNode.Meta, index]) } - kit.CopyText() }) + kit.CopyText() } return true }, @@ -417,10 +419,16 @@ kit = toolkit = (function() {var kit = {__proto__: document, }, // HTML输入文本 CopyText: function(text) { + if (text) { + var input = kit.AppendChild(document.body, [{type: "input", value: text}]).input + input.focus(), input.setSelectionRange(0, text.length) + } + text = window.getSelection().toString() if (text == "") {return} - kit.History("txt", -1, text) - document.execCommand("copy") + + kit.History("txt", -1) && kit.History("txt", -1).data == text || kit.History("txt", -1, text) && document.execCommand("copy") + input && document.body.removeChild(input) }, DelText: function(target, start, count) { target.value = target.value.substring(0, start)+target.value.substring(start+(count||target.value.length), target.value.length) diff --git a/usr/template/plugin/index.js b/usr/template/plugin/index.js index ab13e13f..d4f87396 100644 --- a/usr/template/plugin/index.js +++ b/usr/template/plugin/index.js @@ -1,5 +1,3 @@ -{init: function(run, field, option, output) { - kit.Log("hello world") - return {} +Script["{{options . "name"}}/index.js"] = function(field, option, output) {return { }}