diff --git a/frame.js b/frame.js index f8b3d86e..965fd51a 100644 --- a/frame.js +++ b/frame.js @@ -1,10 +1,8 @@ Volcanos(chat.ONENGINE, {_init: function(can, meta, list, cb, target) { if (can.misc.Search(can, ice.MSG_SESSID)) { can.misc.CookieSessid(can, can.misc.Search(can, ice.MSG_SESSID)); return can.misc.Search(can, ice.MSG_SESSID, "") } can.user.title(can.misc.Search(can, chat.TITLE)||can.misc.Search(can, ice.POD)||location.host) - can.run = function(event, cmds, cb) { var msg = can.request(event); cmds = cmds||[]; return (can.onengine[cmds[0]]||can.onengine._remote)(event, can, msg, can, cmds, cb) } can.require([can.volcano], null, function(can, key, sub) { can[key] = sub }) - can.core.Next(list, function(item, next) { item.type = chat.PANEL can.onappend._init(can, can.base.Copy(item, can.core.Value(can, [chat.RIVER, item.name])), item.list, function(sub) { can[item.name] = sub sub.run = function(event, cmds, cb) { var msg = sub.request(event); cmds = cmds||[]; return (can.onengine[cmds[0]]||can.onengine._remote)(event, can, msg, sub, cmds, cb) } @@ -40,9 +38,8 @@ Volcanos(chat.ONENGINE, {_init: function(can, meta, list, cb, target) { }) }, _static: function(event, can, msg, panel, cmds, cb) { if (!can.user.isLocalFile) { return false } - var msg = can.request(event); msg.Clear(ice.MSG_APPEND) - var res = Volcanos.meta.pack[can.core.Keys(panel._name, cmds.join(ice.FS))]; res? msg.Copy(res): can.user.toast(can, "miss data") - return can.base.isFunc(cb) && cb(msg), true + var res = Volcanos.meta.pack[can.core.Keys(panel._name, cmds.join(ice.FS))], msg = can.request(event); msg.Clear(ice.MSG_APPEND) + return res? msg.Copy(res): can.user.toast(can, "miss data"), can.base.isFunc(cb) && cb(msg), true }, _engine: function(event, can, msg, panel, cmds, cb) { return false }, _plugin: function(event, can, msg, panel, cmds, cb) { @@ -209,14 +206,12 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) { field: function(can, type, item, target) { type = type||html.PLUGIN, item = item||{} var name = (item.nick||item.name||"").split(ice.SP)[0], title = !item.help || can.user.language(can) == "en"? name: name+"("+item.help.split(ice.SP)[0]+")" return can.page.Append(can, target||can._output, [{view: [can.base.join([type||"", item.name||"", item.pos||""]), html.FIELDSET], list: [ - {text: [name == "word"? item.help.split(ice.SP)[0]: title, html.LEGEND]}, {view: [html.OPTION, html.FORM]}, html.ACTION, html.OUTPUT, html.STATUS, + title && {text: [name == "word"? item.help.split(ice.SP)[0]: title, html.LEGEND]}, {view: [html.OPTION, html.FORM]}, html.ACTION, html.OUTPUT, html.STATUS, ]}]) }, input: function(can, item, value, target, style) { - switch (item.type) { - case "": return can.page.Append(can, target, [item]) - case html.SPACE: return can.page.Append(can, target, [{view: can.base.join([html.ITEM, html.SPACE])}]) - } + // switch (item.type) { case "": return can.page.Append(can, target, [item]) } + if (item.type == html.SPACE) { return can.page.Append(can, target, [{view: can.base.join([html.ITEM, html.SPACE])}]) } var input = can.page.input(can, can.base.Copy({}, item), value) if (item.type == html.SELECT && item.value) { input._init = function(target) { target.value = item.value } } if (item.type == html.TEXT) { input.onkeydown = item.onkeydown||function(event) { @@ -542,12 +537,10 @@ Volcanos(chat.ONKEYMAP, {_init: function(can, target) { selectCtrlN: function(event, can, target, key, cb) { if (!event.ctrlKey || event.key < "0" || event.key > "9") { return } return can.page.Select(can, target, key, function(target, index) { if (index+1 == event.key) { return cb(target) } })[0] }, - selectInputs: function(event, can, cb, target) { if (can.page.ismodkey(event)) { return } - if (event.key == lang.ESCAPE) { return target.blur() } + selectInputs: function(event, can, cb, target) { if (can.page.ismodkey(event)) { return } if (event.key == lang.ESCAPE) { return target.blur() } if (event.ctrlKey || event.key == lang.TAB) { if (can.base.isUndefined(target._index)) { target._index = -1, target._value = target.value } function select(order) { if (order == -1) { target.value = target._value } - var index = 0; return can.page.Select(can, can._output, [html.TBODY, html.TR], function(tr) { - if (can.page.ClassList.has(can, tr, html.HIDDEN)) { return } + var index = 0; return can.page.Select(can, can._output, [html.TBODY, html.TR], function(tr) { if (can.page.ClassList.has(can, tr, html.HIDDEN)) { return } can.page.ClassList.del(can, tr, html.SELECT); if (order == index++) { can.page.ClassList.add(can, tr, html.SELECT) can.page.Select(can, tr, html.TD, function(td, index) { index == 0 && (target.value = td.innerText) }) } return tr diff --git a/lib/base.js b/lib/base.js index 28ebaaf9..914854a4 100644 --- a/lib/base.js +++ b/lib/base.js @@ -10,15 +10,13 @@ Volcanos("base", { }, Copy: function(to, from, hold) { if (!from) { return to } if (arguments.length == 2 || typeof hold == lang.BOOLEAN) { - for (var k in from) { - if (k == undefined) { continue } + for (var k in from) { if (k == undefined) { continue } if (hold && to.hasOwnProperty(k) && to[k] != undefined) { continue } if (from[k] === "") { delete(to[k]) } else { to[k] = from[k] } } return to } for (var i = 2; i < arguments.length; i++) { var k = arguments[i]; to[k] = from[k] } return to }, - Eq: function(to, from) { var call = arguments.callee - if (typeof to != typeof from) { return false } + Eq: function(to, from) { var call = arguments.callee; if (typeof to != typeof from) { return false } if (typeof to == lang.OBJECT) { if (to.length != from.length) { return false } for (var i = 0; i < to.length; i++) { if (!call(to[i], from[i])) { return false } } for (var k in to) { if (!call(to[k], from[k])) { return false } } @@ -35,29 +33,22 @@ Volcanos("base", { Args: function() { var res = [] for (var i = 0; i < arguments.length; i += 2) { if (typeof arguments[i] == lang.OBJECT) { - for (var k in arguments[i]) { res.push(encodeURIComponent(k)+ice.EQ+encodeURIComponent(arguments[i][k])) } i--; continue - } else if (arguments[i]) { - res.push(encodeURIComponent(arguments[i])+ice.EQ+encodeURIComponent(arguments[i+1])) - } - } return res.join("&") - }, - MergeURL: function(url) { var args = this._parse(url); delete(args["_origin"]) - for (var i = 1; i < arguments.length; i++) { switch (typeof arguments[i]) { - case lang.STRING: args[arguments[i]] = arguments[i+1], i++; break - case lang.OBJECT: if (arguments[i].length > 0) { - for (var j = 0; j < arguments[i].length; j += 2) { args[arguments[i][j]] = arguments[i][j] } + for (var j = 0; j < arguments[i].length; j += 2) { res[arguments[i][j]] = arguments[i][j] } } else { - for (var k in arguments[i]) { args[k] = arguments[i][k] } - } - } } - var list = []; for (var k in args) { k &&args[k] && list.push(encodeURIComponent(k)+ice.EQ+encodeURIComponent(args[k])) } - return url.split("?")[0]+(list.length>0? "?"+list.join("&"): "") + for (var k in arguments[i]) { res[k] = arguments[i][k] } + } i-- + } else if (arguments[i]) { res.push(encodeURIComponent(arguments[i])+ice.EQ+encodeURIComponent(arguments[i+1])) } + } return res.join("&") }, _parse: function(url, res) { var list = url.split("?"); res = res||{}, res["_origin"] = list[0] list[1] && list[1].split("&").forEach(function(item) { var ls = item.split(ice.EQ); res[decodeURIComponent(ls[0])] = decodeURIComponent(ls[1]) }) return res }, + MergeURL: function(url) { var args = this._parse(url); delete(args["_origin"]) + var arg = this.Args.apply(this, [args].concat(Array.prototype.slice.call(arguments, 1))) + return url.split("?")[0]+(arg? "?"+arg: "") + }, ParseURL: function(url) { var res = this._parse(url); res.link = url, res.origin = res._origin; return res }, ParseJSON: function(str) { var res; if (typeof str == lang.OBJECT) { return str } if (str.indexOf(ice.HTTP) == 0) { var res = this._parse(str, {type: mdb.LINK, name: "", text: str}); return res.name = res._origin.split("://").pop().split(ice.PS)[0], res } diff --git a/lib/core.js b/lib/core.js index 5ce43d52..6d068523 100644 --- a/lib/core.js +++ b/lib/core.js @@ -109,8 +109,7 @@ Volcanos("core", { })(k) } } return list }, Timer: shy("定时器, value, [1,2,3,4], {interval, length}", function(interval, cb, cbs) { var timer = {stop: false} - function loop(i) { - timer.stop || i >= interval.length && interval.length >= 0 || cb(timer, interval.interval||interval[i], i, interval)? + function loop(i) { timer.stop || i >= interval.length && interval.length >= 0 || cb(timer, interval.interval||interval[i], i, interval)? typeof cbs == lang.FUNCTION && cbs(timer, interval): setTimeout(function() { loop(i+1) }, interval.interval||interval[i+1]) } interval = typeof interval == lang.OBJECT? interval: [interval]; if (interval.interval == 0) { return cb(), timer } return typeof cb == lang.FUNCTION && setTimeout(function() { loop(0) }, interval.interval||interval[0]), timer diff --git a/lib/page.js b/lib/page.js index b9cdbf4a..7d6fe8d0 100644 --- a/lib/page.js +++ b/lib/page.js @@ -188,7 +188,7 @@ Volcanos("page", {ClassList: { } return input }, - replace: function(can, text, key, value) { return can.base.replaceAll(text, "<", "<", ">", ">", key, value) }, + replace: function(can, text, key, value) { return can.base.replaceAll(text, "<", "<", ">", ">", key, value) }, Format: function(type) { var args = arguments; switch (type) { case html.A: return ""+(args[2]||args[1])+"" case html.IMG: return args[2]? "": "" diff --git a/lib/user.js b/lib/user.js index 8fb34abb..902af58c 100644 --- a/lib/user.js +++ b/lib/user.js @@ -48,7 +48,7 @@ Volcanos("user", {info: {}, agent: { language: function(can) { return can.misc.Search(can, "language") }, trans: function(can, text, list) { if (can.base.isFunc(text)) { text = text.name||"" } if (can.base.isObject(text)) { return can.core.Item(text, function(k, v) { can.core.Value(can._trans, k, v) }) } - if (can.user.language(can) == "en") { return text } + if (can.user.language(can) == "en") { return text } if (can.base.isString(list)) { return list } return list&&list[text] || can._trans&&can._trans[text] || can.Conf("trans."+text) || can.Conf("feature._trans."+text) || { "plugin": "插件", "label": "标签", "height": "高度", "width": "宽度", "show": "显示", "hide": "隐藏", "project": "项目", "profile": "详情", "actions": "参数", "create": "创建", "remove": "删除", "insert": "添加", "delete": "删除", "modify": "修改", "prunes": "清理", "export": "导出", "import": "导入", @@ -77,12 +77,9 @@ Volcanos("user", {info: {}, agent: { toast: function(can, content, title, duration, progress) { var meta = can.base.isObject(content)? content: {content: content, title: title||can._help, duration: duration, progress: progress} var width = meta.width||400; if (width < 0) { width = window.innerWidth + width } - var ui = can.page.Append(can, can._root._target, [{view: [[chat.TOAST, chat.FLOAT]], style: { - width: width, left: (window.innerWidth-width)/2, bottom: 100, - }, list: [ - {text: [meta.title||"", html.DIV, html.TITLE], title: "点击复制", onclick: function(event) { - can.user.copy(event, can, meta.title) - }}, {view: "duration", title: "点击关闭", onclick: function() { action.close() }}, + var ui = can.page.Append(can, can._root._target, [{view: [[chat.TOAST, chat.FLOAT]], style: {left: (window.innerWidth-width)/2, width: width, bottom: 100}, list: [ + {text: [meta.title||"", html.DIV, html.TITLE], title: "点击复制", onclick: function(event) { can.user.copy(event, can, meta.title) }}, + {view: "duration", title: "点击关闭", onclick: function() { action.close() }}, can.base.isObject(meta.content)? meta.content: {text: [meta.content||"", html.DIV, nfs.CONTENT]}, html.ACTION, !can.base.isUndefined(meta.progress) && {view: "progress", style: {width: width}, list: [ {view: "current", style: {width: (meta.progress||0)/100*width}}, @@ -98,12 +95,10 @@ Volcanos("user", {info: {}, agent: { }); can.onmotion.story.auto(can, ui._target) return can._toast && (can._toast.close(), delete(can._toast)), can._toast = action }, - share: function(can, msg, cmd) { - can.run(msg, cmd||[ctx.ACTION, chat.SHARE], function(msg) { - can.user.toast(can, {title: msg.Append(mdb.NAME), duration: -1, content: msg.Append(mdb.TEXT), action: [cli.CLOSE, cli.OPEN]}) - can.user.copy(msg._event, can, msg.Append(mdb.NAME)) - }) - }, + share: function(can, msg, cmd) { can.run(msg, cmd||[ctx.ACTION, chat.SHARE], function(msg) { + can.user.toast(can, {title: msg.Append(mdb.NAME), duration: -1, content: msg.Append(mdb.TEXT), action: [cli.CLOSE, cli.OPEN]}) + can.user.copy(msg._event, can, msg.Append(mdb.NAME)) + }) }, copy: function(event, can, text) { if (!text) { return } if (navigator.clipboard) { var ok = false; navigator.clipboard.writeText(text).then(function() { ok = true }) if (ok) { return can.user.toastSuccess(can, text, "copy success"), can.misc.Log("copy", text), text } @@ -117,21 +112,16 @@ Volcanos("user", {info: {}, agent: { meta = meta||can.ondetail||can.onaction||{}, list = can.base.getValid(list, meta.list, can.core.Item(meta))||[]; if (list.length == 0) { return } cb = cb||function(event, button, meta) { var cb = meta[button]||meta[chat._ENGINE]; can.base.isFunc(cb) && cb(event, can, button) } parent || can.page.Select(can, can._root._target, can.page.Keys("div.carte.float"), function(target) { can.page.Remove(can, target) }) - var ui = can.page.Append(can, can._root._target, [{view: [[chat.CARTE, chat.FLOAT]], onmouseleave: function(event) { - // can.page.Remove(can, ui._target) - }, list: can.core.List(list, function(item, index) { + var ui = can.page.Append(can, can._root._target, [{view: [[chat.CARTE, chat.FLOAT]], list: can.core.List(list, function(item, index) { return can.base.isString(item)? item ==""? /* space */ {view: html.SPACE}: /* string */ {view: html.ITEM, list: [{text: can.user.trans(can, item), onclick: function(event) { can.base.isFunc(cb) && cb(event, item, meta, index), can.onkeymap.prevent(event), can.user.isMobile && can.page.Remove(can, ui._target) - }, onmouseenter: function(event) { - carte._float && can.page.Remove(can, carte._float._target) - } }] }: can.base.isArray(item)? /* array */ {view: html.ITEM, list: [{text: can.user.trans(can, item[0])+" -> "}], onmouseenter: function(event) { + }, onmouseenter: function(event) { carte._float && can.page.Remove(can, carte._float._target) } }] }: + can.base.isArray(item)? /* array */ {view: html.ITEM, list: [{text: can.user.trans(can, item[0])+" -> "}], onmouseenter: function(event) { var sub = can.user.carte(event, can, meta, item.slice(1), cb, carte); can.onlayout.figure(event, can, sub._target, true) carte._float && can.page.Remove(can, carte._float._target), carte._float = sub } }: /* object */ {view: html.ITEM, list: [{text: can.user.trans(can, item.name), onclick: function(event) { can.base.isFunc(cb) && cb(event, item.name, meta, index), can.user.isMobile && can.page.Remove(can, ui._target) - }, onmouseenter: function(event) { - carte._float && can.page.Remove(can, carte._float._target) - } }] } + }, onmouseenter: function(event) { carte._float && can.page.Remove(can, carte._float._target) } }] } }), onmouseover: function(event) { can.onkeymap.prevent(event) } }] ) var carte = {_target: ui._target, _parent: parent, layout: can.onlayout.figure(event, can, ui._target)} return can.onkeymap.prevent(event), carte diff --git a/proto.js b/proto.js index c62bc11d..43db1b70 100644 --- a/proto.js +++ b/proto.js @@ -284,11 +284,11 @@ var Volcanos = shy({iceberg: "/chat/", volcano: "/frame.js", cache: {}, pack: {} setHeaderMenu: function(list, cb) { can._menu && can.page.Remove(can, can._menu) return can._menu = can.search(can.request({}, {trans: can.onaction._trans}), [[chat.HEADER, chat.ONIMPORT, html .MENU], can._name].concat(list), cb) }, - setHeader: function(key, value) { return can.set("Header", key, value) }, - getHeader: function(key, cb) { return can.get("Header", key, cb) }, - setAction: function(key, value) { return can.set("Action", key, value) }, - getAction: function(key, cb) { return can.get("Action", key, cb) }, - getActionSize: function(cb) { return can.get("Action", "size", cb) }, + setHeader: function(key, value) { return can.set(chat.HEADER, key, value) }, + getHeader: function(key, cb) { return can.get(chat.HEADER, key, cb) }, + setAction: function(key, value) { return can.set(chat.ACTION, key, value) }, + getAction: function(key, cb) { return can.get(chat.ACTION, key, cb) }, + getActionSize: function(cb) { return can.get(chat.ACTION, nfs.SIZE, cb) }, isStoryType: function(value) { return can.page.ClassList.has(can, can._fields, chat.STORY) }, isSimpleMode: function(value) { return can.Mode() == chat.SIMPLE }, @@ -307,9 +307,7 @@ var Volcanos = shy({iceberg: "/chat/", volcano: "/frame.js", cache: {}, pack: {} res = can.core.Value(can._conf, arguments[i], arguments[i+1]) } return can.base.isUndefined(res) && key.indexOf(ctx.FEATURE+ice.PT) == -1? can.Conf(can.core.Keys(ctx.FEATURE, key)): res }, _conf: {}, - }, meta)) - - if (_can_name) { meta.cache[_can_name] = meta.cache[_can_name]||[], meta.cache[_can_name].push(can) } else { list.push(can) } + }, meta)); if (_can_name) { meta.cache[_can_name] = meta.cache[_can_name]||[], meta.cache[_can_name].push(can) } else { list.push(can) } return can.require(can._follow? libs.concat(meta.libs, meta.volcano): libs, cb), can }) try { if (typeof(window) == lang.OBJECT) { // chrome