diff --git a/frame.js b/frame.js index 393f76ac..687564fa 100644 --- a/frame.js +++ b/frame.js @@ -19,7 +19,7 @@ Volcanos("onengine", {help: "搜索引擎", list: [], _init: function(can, meta, 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) }); if (!sub || !mod || !fun) { - can.misc.Warn("not found", cmds[1]) + can.misc.Warn("not found", cmds) can.base.isFunc(cb) && cb(msg.Echo("warn: ", "not found: ", cmds[1])) return } @@ -40,7 +40,7 @@ Volcanos("onengine", {help: "搜索引擎", list: [], _init: function(can, meta, return typeof cb == "function" && cb(msg) } - can.misc.Run(event, can, {names: (can.Conf("iceberg")||"/chat/")+panel._name, daemon: can._daemon+"."+msg._daemon}, cmds, function(msg) { + can.misc.Run(event, can, {names: (can.Conf("iceberg")||"/chat/")+panel._name, daemon: can.ondaemon._list[0]+"."+msg._daemon}, cmds, function(msg) { Volcanos.meta.pack[key] = msg can.base.isFunc(cb) && cb(msg) }) @@ -193,7 +193,7 @@ Volcanos("ondaemon", {help: "推荐引擎", list: [], _init: function(can) { } }) }, - _list: [{}], + _list: [""], toast: function(can, msg, arg) { arg[0] = can Volcanos.meta.float.toast && can.page.Remove(can, Volcanos.meta.float.toast._target) Volcanos.meta.float.toast = can.core.CallFunc(can.user.toast, {can: can, msg: msg, cmds: arg}) @@ -206,8 +206,7 @@ Volcanos("ondaemon", {help: "推荐引擎", list: [], _init: function(can) { out.onimport._grow(out, arg.join("")) }, pwd: function(can, msg, arg) { - can.misc.Log(msg) - can._daemon = arg[0] + can.ondaemon._list[0] = arg[0] }, }) Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, list, cb, target, field) { diff --git a/lib/base.js b/lib/base.js index 2e2761eb..878deed8 100644 --- a/lib/base.js +++ b/lib/base.js @@ -116,7 +116,7 @@ Volcanos("base", {help: "数据类型", return res }, AddUniq: function(list, value) { list = list || [] - return list.indexOf(value) > -1 && list.push(value), list + return list.indexOf(value) == -1 && list.push(value), list }, Date: function(time) { var now = new Date() diff --git a/lib/core.js b/lib/core.js index 180dda4c..7abd856e 100644 --- a/lib/core.js +++ b/lib/core.js @@ -4,7 +4,6 @@ Volcanos("core", {help: "数据结构", switch (typeof v) { case "object": for (var j = 0; j < v.length; j++) { - // list.push(arguments.callee.apply({}, v[j])) list.push(v[j]) } break @@ -43,7 +42,7 @@ Volcanos("core", {help: "数据结构", var sups = _list(arg[2]||"'\"`") // 引用符 var res = [], begin = 0; function push(obj) { - obj != "" && res.push(typeof obj == "string" || opt.detail? obj: obj.text), begin = -1 + obj && res.push(typeof obj == "string" || opt.detail? obj: obj.text), begin = -1 } // 开始分词 @@ -120,7 +119,7 @@ Volcanos("core", {help: "数据结构", } else { // 选择序列 var slice = [], res for (var i = 0; i < list.length; i++) { - typeof cb == "function" && (res = cb(list[i], i, list)) != undefined? slice.push(res): slice.push(list[i]) + typeof cb == "function"? (res = cb(list[i], i, list)) != undefined && slice.push(res): slice.push(list[i]) } list = slice } @@ -129,8 +128,8 @@ Volcanos("core", {help: "数据结构", }), Next: shy("迭代器", function(list, cb, cbs) { function next(i) { - i < list.length? cb(list[i], function(skip) { - next(i+1+(skip||0)) + i < list.length? cb(list[i], function() { + next(i+1) }, i, list): typeof cbs == "function" && cbs(list) } @@ -149,11 +148,12 @@ Volcanos("core", {help: "数据结构", typeof cb == "function" && setTimeout(function() { loop(0) }, interval.interval||interval[0]) return timer }), - Delay: shy("延时器", function(list, interval, cb, cbs) { + Delay: shy("延时器", function(list, interval, cb, cbs) { list = list || [] list.push(cb); this.Timer(interval, function() { var cb = list.pop(); list.length = 0 typeof cb == "function" && cb() }, cbs) + return list }), Items: shy("迭代器", function(obj, cb) { var list = [] for (var k in obj) { diff --git a/lib/misc.js b/lib/misc.js index 736a360a..7bad36bd 100644 --- a/lib/misc.js +++ b/lib/misc.js @@ -1,4 +1,4 @@ -Volcanos("misc", {help: "工具模块", Message: function(event, can) { var msg = {} +Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg = {} var proto = {_event: event, _can: can, Option: function(key, val) { if (key == undefined) { return msg && msg.option || [] } @@ -132,21 +132,20 @@ Volcanos("misc", {help: "工具模块", Message: function(event, can) { var msg var data = {"detail": [event.data]} } - var msg = can.request(event); msg.Reply = function() { + var msg = can.request(event); msg.Reply = function() { // 回复命令 msg.result = (msg.result||[]).concat(can.core.List(arguments)) - // 回复命令 - delete(msg._can) - delete(msg._event) - msg.Option("_handle", true) - msg.Option("_target", msg.Option("_source")) + msg.Option({_handle: true, _target: msg.Option("_source")}) can.misc.Log("wss", "result", msg.result, msg) + + delete(msg._event), delete(msg._can) socket.send(JSON.stringify(msg)) }, msg.detail = data.detail, msg.Copy(data) // 执行命令 - try { can.misc.Log("wss", "detail", msg.detail, msg) - can.isFunc(cb) && cb(event, msg, msg.detail[0], msg.detail.slice(1)) + try { + can.misc.Log("wss", "detail", msg.detail, msg) + can.base.isFunc(cb) && cb(event, msg, msg.detail[0], msg.detail.slice(1)) } catch (e) { // 执行失败 can.misc.Log(e), msg.Reply(e) } diff --git a/lib/page.js b/lib/page.js index c2921f3a..476b0106 100644 --- a/lib/page.js +++ b/lib/page.js @@ -24,12 +24,18 @@ Volcanos("page", {help: "网页模块", ClassList: { target = typeof target == "string"? document.querySelector(target): target typeof value == "string"? (target.innerHTML = value): can.core.Item(value, function(key, val) { typeof val != "object"? (target[key] = val): can.core.Item(val, function(k, v) { + var size = { + "width": true, "max-width": true, "min-width": true, + "height": true, "max-height": true, "min-height": true, + } + if (size[k] && parseInt(v) < 0) { return target[key] && (target[key][k] = "") } + var size = { "width": true, "max-width": true, "min-width": true, "height": true, "max-height": true, "min-height": true, "left": true, "right": true, "top": true, "bottom": true, "margin-top": true, "margin-left": true, - }; if (size[k] && parseInt(v) < 0) { return target[key] && (target[key][k] = "") } + } if (size[k] && v && (typeof v == "number" || v.indexOf && v.indexOf("px") == -1)) { v += "px" @@ -140,7 +146,7 @@ Volcanos("page", {help: "网页模块", ClassList: { if (type == "input") { data.type == "button" && (data.value = can.user.trans(can, data.value)) data.type == "text" && (data.autocomplete = data.autocomplete||"off") - (data.placeholder = can.user.trans(can, (data.placeholder||data.name).split(".").pop())) + data.placeholder = can.user.trans(can, (data.placeholder||data.name||"").split(".").pop()) data.title = can.user.trans(can, data.title||data.placeholder) } @@ -169,7 +175,7 @@ Volcanos("page", {help: "网页模块", ClassList: { if (!msg.append || msg.append.length == 0) {return} var table = can.page.Append(can, target, "table") - can.page.Append(can, table, [{type: "tr", {dataset: {index: -1}}, list: + can.page.Append(can, table, [{type: "tr", data: {dataset: {index: -1}}, list: can.core.List(list, function(key) { return key[0] == "_"? undefined: {text: [key.trim(), "th"]} }) @@ -248,7 +254,7 @@ Volcanos("page", {help: "网页模块", ClassList: { text = ""+ls[0]+""+ls.slice(1).join(" ") }; text = text.replace(/\\n/g, "
") - if (!text.indexOf("\033\[")) { return text } + // if (!text.indexOf("\033\[")) { return text } text = text.replace(/\033\[31m/g, "") text = text.replace(/\033\[32m/g, "") text = text.replace(/\033\[33m/g, "") diff --git a/lib/user.js b/lib/user.js index 3561b711..f9f322f9 100644 --- a/lib/user.js +++ b/lib/user.js @@ -1,4 +1,4 @@ -Volcanos("user", {help: "用户模块", agent: { +Volcanos("user", {help: "用户操作", agent: { scanQRCode: function(cb, can) { can.user.input(event, can, [{type: "textarea"}], function(ev, button, data, list, args) { cb(list[0]) @@ -62,7 +62,7 @@ Volcanos("user", {help: "用户模块", agent: { ]}, ] }]) - var action = can.onappend._action(can, meta.action||["close"], ui.action, { + var action = can.onappend._action(can, meta.action||[], ui.action, { close: function(event) { can.page.Remove(can, action._target), action.timer.stop = true }, timer: can.core.Timer({interval: 100, length: (parseInt(meta.duration||1000))/100}, function(event, interval, index) { if (index > 30) { ui.duration.innerHTML = parseInt(index/10)+"."+(index%10)+"s..." } @@ -79,7 +79,7 @@ Volcanos("user", {help: "用户模块", agent: { can.run(msg._event, cmd||["action", "share"], function(msg) { can.user.toast(can, {height: 300, width: 500, title: msg.Append("name"), duration: -1, - content: msg.Append("text"), button: ["close"], + content: msg.Append("text"), action: ["close"], }) }) }, @@ -154,15 +154,18 @@ Volcanos("user", {help: "用户模块", agent: { }, input: function(event, can, form, cb, button) { // form [ string, array, object, {_input: "select", values: []} var msg = can.request(event, can.Option()) + var option = {}; can.core.List(msg.Option(), function(key) { + option[key] = msg.Option(key) + }) var ui = can.page.Append(can, document.body, [{view: ["input"], style: {left: 0, top: 0}, list: [ {view: ["option", "table"], list: can.core.List(form, function(item) { item._input == "select" && (item = {select: [[item.name].concat(item.values)], data: item, name: item.name}) item = typeof item == "string"? {input: item, name: item}: item.length > 0? {select: [item], name: item[0]}: item item.type = item.type||"input", item.type == "input" && (item.data=item.data||{}, item.data.type = item.data.type||"text") - item._init = item._init||function(target) { + item._init = function(target) { item.run = function(event, cmds, cb) { - var msg = can.request(event, function() { var value = {_handle: "true"} + var res = can.request(event, msg, option, function() { var value = {_handle: "true"} can.page.Select(can, ui.table, "textarea,input,select", function(item) { item.name && item.value && (value[item.name] = item.value) }); return value diff --git a/page/index.css b/page/index.css index 614b55ff..1a3d77d9 100644 --- a/page/index.css +++ b/page/index.css @@ -196,7 +196,7 @@ h1 { h2 { clear:both; } -h2 { +h3 { clear:both; } h1:hover { diff --git a/panel/Header.js b/panel/Header.js index 61865ba1..9cee0bb6 100644 --- a/panel/Header.js +++ b/panel/Header.js @@ -140,12 +140,12 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, menu: function(can, cmds, cb) { // type item... return can.page.Append(can, can._output, [{type: cmds[0], list: can.core.List(cmds.slice(1), function(item) { if (typeof item == "string") { - return {view: ["menu", "div", item], onclick: function(event) { + return {view: ["menu", "div", can.user.trans(can, item)], onclick: function(event) { can.base.isFunc(cb) && cb(event, item) }} } else if (item.length > 0) { - return {view: ["menu", "div", item[0]], onmouseenter: function(event) { + return {view: ["menu", "div", can.user.trans(can, item[0])], onmouseenter: function(event) { can.onaction.carte(event, can, item.slice(1), cb) }} diff --git a/panel/River.js b/panel/River.js index 051db9db..176618a7 100644 --- a/panel/River.js +++ b/panel/River.js @@ -65,6 +65,8 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, // 左键点击 can.onaction.action(event, can, river, meta.hash) can.user.title(can._main_title || meta.name) + + can.onmotion.select(can, event.target.parentNode, "div.item", event.target) }, onmouseenter: function(event) { can.onaction.carte(event, can, ["共享应用", "添加工具", "保存参数", "重命名应用", "删除应用"], function(event, button, module) { module[button](event, can, button, river, meta.hash) @@ -151,7 +153,7 @@ Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, msg, carte: function(event, can, list, cb) { var carte = can.user.carte(event, can, can.ondetail, list, cb) can.page.Modify(can, carte._target, {style: { - left: event.clientX-event.offsetX+event.target.offsetWidth-3, top: event.clientY-event.offsetY, + left: event.clientX-event.offsetX+event.target.offsetWidth-3, }}) }, diff --git a/plugin/local/code/inner.js b/plugin/local/code/inner.js index 40c57769..6428ce2d 100644 --- a/plugin/local/code/inner.js +++ b/plugin/local/code/inner.js @@ -17,7 +17,6 @@ Volcanos("onimport", {help: "导入数据", _init: function(can, msg, list, cb, var height = can.Conf("height")-320; height < 240 && (height = 240) can.page.Modify(can, can.ui.project, {style: {"max-height": height}}) can.page.Modify(can, can.ui.content, {style: {"max-height": height}}) - // can.page.Modify(can, can.ui.content, {style: {"min-width": can.Conf("width")-170}}) can.page.Modify(can, can.ui.display, {style: {display: "none"}}) }, _output: function(can, target) { diff --git a/plugin/story/spide.js b/plugin/story/spide.js index 78d9a1c6..24db9ad7 100644 --- a/plugin/story/spide.js +++ b/plugin/story/spide.js @@ -142,13 +142,25 @@ Volcanos("ondetail", {help: "用户交互", list: [], plugin: function(event, can, args) { can.onappend.plugin(can, {type: "float", index: "web.code.inner", args: args, _action: ["关闭"]}, function(sub) { sub.run = function(event, cmds, cb) { - can.run(event, ["action", "inner"].concat(cmds), cb, true) - can.onlayout.figure(event, sub, sub._target) + can.run(event, ["action", "inner"].concat(cmds), function(msg) { + can.search(event, ["Action.onexport.size"], function(msg, left, top, width, height) { left = left||0 + var top = 120; if (can.user.isMobile) { + if (can.user.isLandscape) { + sub.Conf("height", window.innerHeight+240), top = 0 + } else { + sub.Conf("height", window.innerHeight+160), top = 48 + } + } else { + sub.Conf("height", height+120) + } + // can.misc.Debug(sub.Conf("height"), cmds) + + can.page.Modify(can, sub._target, {style: {position: "fixed", left: left+20, top: top}}) + can.page.Modify(can, sub._output, {style: {"max-width": width-40}}) + can.base.isFunc(cb) && cb(msg) + }) + }, true) - can.search(event, ["Action.onexport.size"], function(msg, left, top, width, height) { left = left||0 - can.page.Modify(can, sub._target, {style: {position: "fixed", left: left, top: can.user.isMobile&&can.user.isLandscape? 0: 120}}) - can.page.Modify(can, sub._output, {style: {"max-width": width}}) - }) } }) }, diff --git a/proto.js b/proto.js index a88f37d7..0df77e20 100644 --- a/proto.js +++ b/proto.js @@ -63,8 +63,11 @@ var Volcanos = shy("火山架", {args: {}, pack: {}, libs: [], cache: {}, float: request: function(event, option) { event = event || {} event._msg = event._msg || can.misc.Message(event, can) - can.core.List(arguments, function(option, index) { - index > 0 && can.core.Item(can.base.isFunc(option)? option(): option, event._msg.Option) + can.core.List(arguments, function(option, index) { if (index == 0) { return } + can.base.isFunc(option.Option)? can.core.List(option.Option(), function(key) { + event._msg.Option(key, option.Option(key)) + }): can.core.Item(can.base.isFunc(option)? option(): option, event._msg.Option) + }); return event._msg }, const: function() {