diff --git a/frame.js b/frame.js index 4a98a607..e79995f6 100644 --- a/frame.js +++ b/frame.js @@ -11,7 +11,7 @@ Volcanos("onengine", {help: "解析引擎", list: [], _init: function(can, meta, }, target) }, function() { var pane = can[meta.main.name], msg = can.request({}) - pane.onkeypop._init(pane, target), pane.onmotion._init(pane) + pane.onmotion._init(pane, target), pane.onkeypop._init(pane, target) pane.onaction._init(pane, msg, [], cb, pane._target) }) }, @@ -23,15 +23,6 @@ Volcanos("onengine", {help: "解析引擎", list: [], _init: function(can, meta, }) }, - listen: shy("", {}, [], function(can, name, cb) { - arguments.callee.meta[name] = (arguments.callee.meta[name]||[]).concat(cb) - }), - trigger: function(can, msg, name) { - can.core.List(can.onengine.listen.meta[name], function(cb) { - can.core.CallFunc(cb, {"msg": msg}) - }) - }, - search: function(event, can, msg, pane, cmds, cb) { var sub, mod = can, fun = can, key = ""; can.core.List(cmds[1].split("."), function(value) { fun && (sub = mod, mod = fun, fun = mod[value], key = value) @@ -39,7 +30,7 @@ Volcanos("onengine", {help: "解析引擎", list: [], _init: function(can, meta, return can.core.CallFunc(fun, { "event": event, "can": sub, "msg": msg, - "cmd": key, "button": key, "cmds": cmds.slice(2), + "button": key, "cmd": key, "cmds": cmds.slice(2), "list": cmds.slice(2), "cb": cb, "target": sub._target, }, mod) }, @@ -49,6 +40,15 @@ Volcanos("onengine", {help: "解析引擎", list: [], _init: function(can, meta, // pane.run(event, ["search", "Footer.onimport.ncmd"]) }, engine: function(event, can, msg, pane, cmds, cb) { return false }, + listen: shy("", {}, [], function(can, name, cb) { + arguments.callee.meta[name] = (arguments.callee.meta[name]||[]).concat(cb) + }), + trigger: function(can, name, msg) { + can.core.List(can.onengine.listen.meta[name], function(cb) { + can.core.CallFunc(cb, {msg: msg}) + }) + }, + river: { "serivce": {name: "运营群", storm: { "wx": {name: "公众号 wx", action: [ @@ -396,6 +396,19 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, return text && can.page.Append(can, target, [{view: ["code", "div", text]}]).code }, + figure: function(can, meta, key, target) { + if (key.indexOf("@") != 0) { return } + var list = can.core.Split(key, "@=", "@=", {simple: true}) + var pkey = list[0], pval = list[1]||"" + + can.page.Modify(can, target, {autocomplete: "off"}) + target.type != "button" && target.value.startsWith("@") && (target.value = pval||"") + pkey && can.require(["/plugin/input/"+pkey+".js"], function(can) { + can.onfigure && can.core.Item(can.onfigure[pkey], function(key, cb) { if (key.startsWith("on")) { + target[key] = function(event) { cb(event, can, meta, target) } + } }) + }) + }, plugin: function(can, meta, cb, target) { meta = meta || {} can.run({}, ["action", "command", meta.index], function(msg) { meta.feature = can.base.Obj(msg.meta&&msg.meta[0] || "{}", {}) @@ -429,7 +442,7 @@ Volcanos("onlayout", {help: "页面布局", list: [], _init: function(can, targe }) if (can.user.isMobile) { return } - can.onengine.trigger(can, can.request(event, {width: width, height: height}), "resize") + can.onengine.trigger(can, "resize", can.request(event, {width: width, height: height})) can.page.Select(can, target, ["fieldset.main"], function(field, index) { can.page.Modify(can, field, {style: {height: height}}) @@ -442,6 +455,12 @@ Volcanos("onlayout", {help: "页面布局", list: [], _init: function(can, targe topic: function(can, topic) { topic && (can._topic = topic) can.user.topic(can, can._topic || can.user.Search(can, "topic") || ((can.user.Search(can, "pod")||can.base.isNight())? "black": "white")) }, + figure: function(can, ui, event) { + var layout = {top: event.clientY+10, left: event.clientX} + can.page.Modify(can, ui.fieldset, {style: layout}) + can.onmotion.move(can, ui.fieldset, layout) + can.page.Remove(can, ui.legend) + }, profile: function(can, target) { return can.page.Append(can, target, [{view: ["void", "table"], list: [{type: "tr", list: [ @@ -621,18 +640,18 @@ Volcanos("onkeypop", {help: "键盘交互", list: [], _init: function(can, targe if (target._keys.length == 0) { event.stopPropagation(), event.preventDefault() } }, }) -Volcanos("onmotion", {help: "动态交互", list: [], _init: function(can) { +Volcanos("onmotion", {help: "动态交互", list: [], _init: function(can, target) { if ((can.user.Search(can, "topic")||"").indexOf("print") > -1) { return } var count = 0, add = true can.user.isMobile || can.user.Search(can, "share") || can.core.Timer({interval: 100}, function() { - if (document.body.className.indexOf("print") > -1) { return } + if (target.className.indexOf("print") > -1) { return } add? count++: count-- count < 0 && (add = true) count > 100 && (add = false) - can.page.Select(can, document.body, "fieldset.story", function(item) { + can.page.Select(can, target, "fieldset.story", function(item) { can.page.Modify(can, item, {style: { "box-shadow": "40px 10px 10px "+(count/10+1)+"px #626bd0", }}) diff --git a/lib/user.js b/lib/user.js index 486bb5f9..ede7e1ca 100644 --- a/lib/user.js +++ b/lib/user.js @@ -40,10 +40,11 @@ Volcanos("user", {help: "用户模块", agent: { return value }, copy: function(event, can, text) { - var input = can.page.Append(can, event.target.parentNode, [{type: "input", value: text}]).first + var input = can.page.Append(can, event.target, [{type: "input", value: text}]).first input.setSelectionRange(0,-1), input.focus() document.execCommand("Copy"), can.page.Remove(can, input) can.user.toast(can, text, "复制成功") + event.stopPropagation(), event.preventDefault() }, camera: function(can, msg, cb) { @@ -161,25 +162,8 @@ Volcanos("user", {help: "用户模块", agent: { return {button: typeof item == "object"? item: [item, function(event) { cbs(event, item) }]} }); return } - function _init(target) { var pval = "" - if (item.value && item.value.indexOf("@") == 0) { - var pkey = item.value.slice(1).split("=")[0] - if (item.value.indexOf("=") > 0) { - var pval = item.value.slice(1).split("=")[1] - } - item._action = msg.Option("action") + function _init(target) { can.onappend.figure(can, item, item.value, target) } - target.type != "button" && (target.value = pval || msg.Option(item.name)) - can.page.Modify(can, target, {autocomplete: "off"}) - can.require(["/plugin/input/"+pkey], function(can) { - can.onfigure._init(can, item, target, function(event) { - var msg = can.request(event); can.page.Select(can, ui.table, "select,input,textarea", function(item) { - item.name && msg.Option(item.name, item.value||"") - }) - }) - }) - } - } return {type: ["tr"], list: [ {type: "td", list: [{text: typeof item == "string"? item: item.length > 0? item[0]: item.name || ""}]}, {type: "td", list: [typeof item == "string"? /* input */ {input: item, data: {autofocus: true}, _init: _init}: diff --git a/pane/Action.js b/pane/Action.js index d7a08ae2..17d95bd6 100644 --- a/pane/Action.js +++ b/pane/Action.js @@ -100,10 +100,10 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg, can.core.CallFunc(can.onaction[key], {event: event, can: can, key: key}) }) - can._target.ontouchstart = function(event) { can.onengine.trigger(can, {}, "action.touch") } + can._target.ontouchstart = function(event) { can.onengine.trigger(can, "action.touch", {}) } can.Conf({width: can._output.offsetWidth-33, height: window.innerHeight}) can.onengine.listen(can, "resize", function(width, height) { can.Conf({width: width, height: height}) - can.onengine.trigger(can, can.request({}, {width: width, height: height}), "action.resize") + can.onengine.trigger(can, "action.resize", can.request({}, {width: width, height: height})) }) can.onengine.listen(can, "search", function(msg, word) { diff --git a/pane/River.js b/pane/River.js index ffe6eb68..1c1efd58 100644 --- a/pane/River.js +++ b/pane/River.js @@ -106,7 +106,7 @@ Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, msg, }, action: function(event, can, river, storm) { var msg = can.request(event, {river: can.Conf(RIVER, river), storm: can.Conf(STORM, storm)}) - can.onengine.trigger(can, msg, "storm.select") + can.onengine.trigger(can, "storm.select", msg) can.page.Select(can, can._output, "div.item.select", function(item) { can.page.ClassList.del(can, item, "select") diff --git a/pane/Search.js b/pane/Search.js index c5b3efa7..43d6fee6 100644 --- a/pane/Search.js +++ b/pane/Search.js @@ -1,34 +1,33 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { - can.ui = can.onlayout.profile(can, can._output) - can.ui.table = can.page.Append(can, can.ui.display, [{type: "table"}]).first - - can.ui.word = can.page.Append(can, can._action, [{input: ["word", function(event) { can.onkeypop.input(event, can) - if (event.key == "Escape") { can.onmotion.hide(can) } - - if (event.key == "Enter") { event.stopPropagation(), event.preventDefault() - if (event.ctrlKey && can.onaction.choice(event, can, 0)) { return } - can.input(event, event.target.value) - } - }]}]).first + can.ui = can.page.Append(can, can._output, [ + {input: ["word", function(event) { can.onkeypop.input(event, can) + if (event.key == "Escape") { can.onmotion.hide(can) } + if (event.key == "Enter") { event.stopPropagation(), event.preventDefault() + if (event.ctrlKey && can.onaction.choice(event, can, 0)) { return } + can.input(event, event.target.value) + } + }]}, + {view: "content"}, {view: "display", list: [{type: "table"}]}, + ]) typeof cb == "function" && cb(msg) }, _table: function(can, msg, fields) { can.onmotion.clear(can, can.ui.content) - var table = can.onappend.table(can, msg, can.ui.content, "table", function(value, key, index, line) { can.Status("count", index+1) + var table = can.onappend.table(can, msg, can.ui.content, "table", function(value, key, index, line) { + can.Status("count", index+1) return {text: [key == "text" && typeof line.text == "function" && line.text.help || value, "td"], onclick: function(event) { - // if (event.shiftKey) { - can.onappend.plugin(can, {index: msg.Option("index")||line.ctx+"."+line.cmd, arg: [line.type, line.name]}, function(story, meta) { + if (event.shiftKey) { var msg = can.request(event, line) + can.onappend.plugin(can, {index: line.ctx+"."+line.cmd}, function(story, meta) { story.run = function(event, cmds, cb, silent) { - can.run(event, ["action", "command", "run", meta.index].concat(cmds), function(msg) { + can.run(event, ["command", "run", meta.index].concat(cmds), function(msg) { typeof cb == "function" && cb(msg) }) } - }, can.ui.profile) - can.onmotion.clear(can, can.ui.profile) - // return - // } + }, can.ui.display) + return + } if (line.ctx == "web.chat" && line.cmd == "/search") { - can.onimport.select(can, can.request(), [line.type, line.name, line.text], can.cb) + can.onimport.select(can, msg, [line.type, line.name, line.text], can.cb) return } if (typeof line.text == "function") { @@ -51,11 +50,10 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, can.page.Modify(can, can.ui.table, {style: {width: table.offsetWidth}}) }, _word: function(can, msg, cmds, fields) { - can.request(msg._event, {fields: fields.join(","), word: cmds}) - can.onengine.trigger(can, msg, "search") + var msg = can.request({}, {fields: fields.join(","), word: cmds}) + can.onengine.trigger(can, "search", msg) can.onmotion.clear(can, can.ui.content) - can.onmotion.clear(can, can.ui.profile) can.run(msg._event, cmds, function(msg) { can.list = msg.Table() can.onimport._table(can, msg, fields) }) @@ -79,7 +77,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, can.page.Modify(can, can._target, {style: {left: item.offsetWidth}}) }) - can.onmotion.show(can), can.ui.word.focus() + can.onmotion.show(can), can.ui.input.focus() can.onimport._word(can, msg, cmds, fields) }, }) diff --git a/plugin/input.js b/plugin/input.js index 674fc3b5..a3732327 100644 --- a/plugin/input.js +++ b/plugin/input.js @@ -18,17 +18,7 @@ Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, meta, case "select": meta.value && (target.value = meta.value); break } - if (meta.figure.indexOf("@") == 0) { - var ls = meta.figure.slice(1).split("=") - var pkey = ls[0], pval = ls[1]||"" - - target.type != "button" && target.value.startsWith("@") && (target.value = pval) - can.require(["/plugin/input/"+pkey+".js"], function(can) { - can.onfigure && can.core.Item(can.onfigure[pkey], function(key, value) { if (key.startsWith("on")) { - target[key] = function(event) { value(event, can, meta, target) } - } }) - }) - } + can.onappend.figure(can, meta, meta.figure, target) }, "upload": function(event, can) { can.user.upload(event, can) }, diff --git a/plugin/input/date.js b/plugin/input/date.js index 97b640a5..6e8aebf0 100644 --- a/plugin/input/date.js +++ b/plugin/input/date.js @@ -1,4 +1,4 @@ -Volcanos("onfigure", {help: "控件详情", list: [], date: {onclick: function(event, can, item, target) { target = target || event.target +Volcanos("onfigure", {help: "控件详情", list: [], date: {onclick: function(event, can, item, target) { // 设置输入 function set(now) { @@ -7,10 +7,10 @@ Volcanos("onfigure", {help: "控件详情", list: [], date: {onclick: function(e } // 添加插件 + can._figure && can.page.Remove(can, can._figure.fieldset) var figure = can.onappend.field(can, document.body, "input date", {}) + can._figure = figure; can.onlayout.figure(can, figure, event) figure.table = can.page.Append(can, figure.output, [{type: "table"}]).first - can.page.Modify(can, figure.fieldset, {style: {top: event.clientY+10, left: event.clientX}}) - can.page.Remove(can, figure.legend) // 添加控件 var now = target.value? new Date(target.value): new Date() @@ -19,7 +19,7 @@ Volcanos("onfigure", {help: "控件详情", list: [], date: {onclick: function(e "关闭", {type: "hr", style: {margin: 0}}, "上一月", ["year"].concat(can.core.List(now.getFullYear() - 20, now.getFullYear() + 20)), ["month"].concat(can.core.List(1, 13)), "下一月", {view: ["", "br"]}, - ], function(event, value, cmd) {can.stick = true + ], function(event, value, cmd) { can.stick = true // 设置时间 switch (cmd) { case "year": now.setFullYear(parseInt(value)), show(now); return @@ -73,6 +73,5 @@ Volcanos("onfigure", {help: "控件详情", list: [], date: {onclick: function(e for (var day = new Date(end); end.getDay() != 0 && day < tail; day.setDate(day.getDate()+1)) {add(day, "next")} return now }; show(now) - return figure }} }, ["/plugin/input/date.css"]) diff --git a/plugin/input/key.js b/plugin/input/key.js index fc9104e1..2bf46b2e 100644 --- a/plugin/input/key.js +++ b/plugin/input/key.js @@ -1,38 +1,23 @@ -Volcanos("onfigure", {help: "控件详情", list: [], _init: function(can, item, target, cb) { - can.core.Item(can.onfigure.key, function(key, value) { if (key.startsWith("on")) { - target[key] = function(event) { - cb(event), value(event, can, item, target) - } - } }) - }, - key: {onclick: function(event, can, item, target) { - function run() { var msg = can.request(event); msg.Option(can.Option()) - msg.Option("action", item._action) - can.run(event, ["action", "inputs", item.name, target.value], function(msg) { - if (!msg.append) { return } +Volcanos("onfigure", {help: "控件详情", list: [], key: {onclick: function(event, can, item, target) { function run() { + var msg = can.request(event, can.Option()); msg.Option("action", item._action) + can.run(event, ["action", "inputs", item.name, target.value], function(msg) { + if (!msg.append) { return } - can._figure && can.page.Remove(can, can._figure.fieldset) - can._figure = can.onappend.field(can, document.body, "input key", {}) + can._figure && can.page.Remove(can, can._figure.fieldset) + var figure = can.onappend.field(can, document.body, "input key", {}) + can._figure = figure; can.onlayout.figure(can, figure, event) - var layout = {top: event.clientY+10, left: event.clientX} - can.onmotion.move(can, can._figure.fieldset, layout) - can.page.Modify(can, can._figure.fieldset, {style: layout}) - can.page.Remove(can, can._figure.legend) + can.onappend._action(can, [ + {button: ["清空", function(event) { target.value = "" }]}, + {button: ["关闭", function(event) { can.page.Remove(can, can._figure.fieldset) }]}, + ], can._figure.action) - can.page.Append(can, can._figure.action, [ - {button: ["清空", function(event) { target.value = "" }]}, - {button: ["关闭", function(event) { can.page.Remove(can, can._figure.fieldset) }]}, - ]) - - can.page.AppendTable(can, msg, can._figure.output, msg.append, function(value, key, index, line) { - return {type: "td", inner: value, onclick: function() { - target.value = value; msg.Option("_refresh") && run() - can.page.Remove(can, can._figure.fieldset) - }} - }) - }, true) - } - run() - }}, -}, ["/plugin/input/key.css"]) + can.onappend.table(can, msg, can._figure.output, "table", function(value, key, index, line) { + return {type: "td", inner: value, onclick: function() { + target.value = value; msg.Option("_refresh") && run() + can.page.Remove(can, can._figure.fieldset) + }} + }) + }, true) +}; run() }}, }, ["/plugin/input/key.css"])