From b2a6b7a00672c4af0a3b117a0f366b7a32bb542f Mon Sep 17 00:00:00 2001 From: shylinux Date: Mon, 31 Jan 2022 22:50:16 +0800 Subject: [PATCH] opt some --- frame.js | 210 ++++++++++++++---------------------- lib/base.js | 92 +++++----------- lib/core.js | 26 ++--- lib/misc.js | 77 ++++--------- lib/page.js | 32 +++--- lib/user.js | 24 ++--- page/index.css | 34 +++--- plugin/input/key.js | 10 +- plugin/local/code/inner.css | 8 +- proto.js | 2 + 10 files changed, 187 insertions(+), 328 deletions(-) diff --git a/frame.js b/frame.js index d738e936..52129a78 100644 --- a/frame.js +++ b/frame.js @@ -15,7 +15,7 @@ Volcanos("onengine", {help: "搜索引擎", list: [], _init: function(can, meta, can.onengine.listen(can, key, function(msg) { can.core.CallFunc(cb, {can: panel, msg: msg}) }) }), can.core.CallFunc([panel.onaction, "_init"], {can: panel, cb: next, target: panel._target}) - can.page.Modify(can, panel._target, {style: panel.Conf(ctx.STYLE)}) + can.page.style(can, panel._target, panel.Conf(ctx.STYLE)) }, target) }, function() { can.misc.Log(can.user.title(), ice.RUN, can) can.require([can.volcano], null, function(can, name, sub) { can[name] = sub }) @@ -405,8 +405,8 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, ui.close = function() { can.page.Remove(can, ui.first) } can.getActionSize(function(left, top, height, width) { - can.page.Modify(can, ui.output, {style: kit.Dict(html.MAX_HEIGHT, height-28, html.MAX_WIDTH, width)}) - can.page.Modify(can, ui.first, {style: {left: left, top: top}}) + can.page.style(can, ui.output, html.MAX_HEIGHT, height-28, html.MAX_WIDTH, width) + can.page.style(can, ui.first, html.LEFT, left, html.TOP, top) }) can.onappend._action(can, [cli.CLOSE, cli.REFRESH, {input: html.TEXT, placeholder: "filter", _init: function(input) { @@ -480,7 +480,7 @@ Volcanos("onlayout", {help: "页面布局", list: [], _init: function(can, targe can.page.ClassList.add(can, document.body, can.user.language(can)) }, background: function(can, url, target) { - can.page.Modify(can, target||document.body, {style: {background: url == "" || url == "void"? "": 'url("'+url+'")'}}) + can.page.style(can, target||document.body, html.BACKGROUND, url == "" || url == "void"? "": 'url("'+url+'")') }, figure: function(event, can, target, right, layout) { target = target||can._target if (layout) { return can.page.style(can, target, layout), can.onmotion.move(can, target, layout), layout } @@ -498,6 +498,7 @@ Volcanos("onlayout", {help: "页面布局", list: [], _init: function(can, targe } if (top+target.offsetHeight>window.innerHeight-100) { layout.bottom = window.innerHeight - event.clientY+event.offsetY, layout.top = "" + if (right) { layout.bottom -= target.offsetHeight } } return can.page.style(can, target, layout), can.onmotion.move(can, target, layout), layout }, @@ -552,66 +553,51 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe focus: function(can, target) { if (!target) { return } target.setSelectionRange && target.setSelectionRange(0, -1), target.focus() }, - clear: function(can, target) { - return can.page.Modify(can, target||can._output, ""), true - }, share: function(event, can, input, args) { return can.user.input(event, can, input, function(ev, button, data, list, _args) { - can.search(can.request(event, {args: [mdb.TYPE, chat.FIELD].concat(args||[], _args||[])})._event, ["Header.onaction.share"]) + can.search(can.request(event, {args: [mdb.TYPE, chat.FIELD].concat(args||[], _args||[])})._event, [["Header", chat.ONACTION, web.SHARE]]) }) }, story: { _hash: { spark: function(can, meta, target) { - if (meta[mdb.NAME] == html.INNER) { - target.title = "点击复制", target.onclick = function(event) { - can.user.copy(event, can, target.innerText) - } - } else { - can.page.Select(can, target, html.SPAN, function(item) { - item.title = "点击复制", item.onclick = function(event) { - can.user.copy(event, can, item.innerText) - } - }) - } + meta[mdb.NAME] == html.INNER? can.onmotion.copy(can, target): can.page.Select(can, target, html.SPAN, function(item) { + can.onmotion.copy(can, item) + }) }, }, auto: function(can, target) { var that = this can.page.Select(can, target||can._output, ".story", function(item) { var meta = item.dataset - can.page.Modify(can, item, {style: can.base.Obj(meta.style)}) + can.page.style(can, item, can.base.Obj(meta.style)) can.core.CallFunc(that._hash[meta.type], [can, meta, target||can._output]) }) can.page.Select(can, target||can._output, html.IFRAME, function(item) { - can.page.Modify(can, item, {style: {height: can.Conf(html.HEIGHT)-88, width: can.Conf(html.WIDTH)-30}}) + can.page.style(can, item, html.HEIGHT, can.Conf(html.HEIGHT)-88, html.WIDTH, can.Conf(html.WIDTH)-30) }) can.page.Select(can, target||can._output, html.SVG, function(item) { item.oncontextmenu = function(event) { - can.user.carte(event, can, {"导出": function(event, can, button) { + can.user.carte(event, can, kit.Dict(mdb.EXPORT, function(event, can, button) { - }}, ["导出"]) + }), [mdb.EXPORT]) } - // can.page.Modify(can, item, {style: {height: can.Conf(html.HEIGHT)-88, width: can.Conf(html.WIDTH)-30}}) }) }, }, float: {_hash: {}, del: function(can, key) { - if (key == chat.CARTE) { - can.page.Select(can, document.body, can.core.Keys(html.DIV, chat.CARTE), function(item) { - can.page.Remove(can, item) - }) - } + key == chat.CARTE && can.page.Select(can, document.body, can.core.Keys(html.DIV, chat.CARTE), function(item) { + can.page.Remove(can, item) + }) this._hash[key] && can.page.Remove(can, this._hash[key]._target) }, add: function(can, key, value) { this.del(can, key), this._hash[key] = value }, - auto: function(can, target, key) { var that = this var list = can.core.List(arguments).slice(2) if (list.length == 0) { list = [chat.CARTE, chat.INPUT] } can.page.Modify(can, target, {onmouseover: function(event) { - if (event.target.tagName == "IMG") { return } + if (can.page.tagis(html.IMG, event.target)) { return } can.core.List(list, function(key, index) { that.del(can, key) }) }}) }, @@ -623,35 +609,22 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe if (pos) { item.scrollTo && item.scrollTo(0, pos-1); return item } }).length > 0 }, - delay: function(can, cb) { - can.core.Timer(50, cb) - }, - toimage: function(event, can, name, target) { - can.user.input(event, can, [{name: "name", value: name}], function(ev, button, data) { - can.require(["https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js"], function() { - html2canvas(target||can._target).then(function (canvas) { - can.page.Create(can, html.A, {href: canvas.toDataURL("image/png"), download: data.name}).click() - }) - }) - }) - }, + clear: function(can, target) { return can.page.Modify(can, target||can._output, ""), true }, + delay: function(can, cb) { can.core.Timer(100, cb) }, hidden: function(can, target, show) { - can.page.Modify(can, target||can._target, {style: {display: show? "": html.NONE}}) + can.page.styleDisplay(can, target||can._target, show? "": html.NONE) }, toggle: function(can, target, show, hide) { target = target||can._target var status = target.style.display == html.NONE - can.page.Modify(can, target, {style: {display: status? "": html.NONE}}) - status? can.base.isFunc(show) && show(): can.base.isFunc(hide) && hide() + if (!(status? can.base.isFunc(show) && show(): can.base.isFunc(hide) && hide())) { + can.page.styleDisplay(can, target, status? "": html.NONE) + } return status }, select: function(can, target, name, which) { can.page.Select(can, target, name, function(item, index) { - if (item == which || which == index) { - can.page.ClassList.add(can, item, html.SELECT) - } else { - can.page.ClassList.del(can, item, html.SELECT) - } + can.page.ClassList.set(can, item, html.SELECT, item == which || which == index) }) }, modify: function(can, target, cb, item) { var back = target.innerHTML, text = target.innerText @@ -679,8 +652,7 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe }, onkeydown: function(event) { switch (event.key) { case lang.ENTER: - if (event.ctrlKey) { - target.innerHTML = event.target.value + if (event.ctrlKey) { target.innerHTML = event.target.value event.target.value == back || cb(event, event.target.value, back) } break @@ -692,6 +664,15 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe can.onmotion.focus(can, target) }}]) }, + toimage: function(event, can, name, target) { + can.user.input(event, can, [{name: "name", value: name}], function(ev, button, data) { + can.require(["https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js"], function() { + html2canvas(target||can._target).then(function (canvas) { + can.page.Create(can, html.A, {href: canvas.toDataURL("image/png"), download: data.name}).click() + }) + }) + }) + }, link: function(can, target, text) { if (target.innerText == "") { target.innerText = target.href } @@ -702,9 +683,8 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe can.user.copy(event, can, text||target.innerText) } }, - move: function(can, target, layout, cb) { var begin - can.page.Modify(can, target, {style: layout}) - target.onmousedown = function(event) { + move: function(can, target, layout, cb) { var begin; layout = layout||{} + can.page.style(can, target, layout), target.onmousedown = function(event) { layout.height = target.offsetHeight, layout.width = target.offsetWidth layout.left = target.offsetLeft, layout.top = target.offsetTop begin = can.base.Copy({x: event.x, y: event.y}, layout) @@ -714,80 +694,59 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe if (event.shiftKey) { layout.width = layout.width + event.x - begin.x layout.height = layout.height + event.y - begin.y - can.page.Modify(can, target, {style: {width: layout.width, height: layout.height}}) + can.page.style(can, target, html.HEIGHT, layout.height, html.WIDTH, layout.width) } else { layout.top = begin.top + event.y - begin.y layout.left = begin.left + event.x - begin.x - can.page.Modify(can, target, {style: {left: layout.left, top: layout.top}}) + can.page.style(can, target, html.LEFT, layout.left, html.TOP, layout.top) } - can.base.isFunc(cb) && cb(target) - can.onkeymap.prevent(event) + can.onkeymap.prevent(event), can.base.isFunc(cb) && cb(target, layout) } - can.base.isFunc(cb) && cb(target) + can.base.isFunc(cb) && cb(target, layout) }, show: function(can, time, cb, target) { target = target||can._target time = can.base.isObject(time)? time: {interval: 10, length: time||30} - - can.page.Modify(can, target, {style: {opacity: 0, display: html.BLOCK}}) + can.page.style(can, target, html.OPACITY, 0, html.DISPLAY, html.BLOCK) can.core.Timer(time, function(event, value, index) { - can.page.Modify(can, target, {style: {opacity: (index+1)/time.length}}) + can.page.style(can, target, html.OPACITY, (index+1)/time.length) }, cb) }, hide: function(can, time, cb, target) { target = target||can._target time = can.base.isObject(time)? time: {value: 10, length: time||20} - - can.page.Modify(can, target, {style: {opacity: 1}}) + can.page.style(can, target, html.OPACITY, 1) can.core.Timer(time, function(event, value, index) { - can.page.Modify(can, target, {style: {opacity: 1-(index+1)/time.length}}) - }, function() { - can.page.Modify(can, target, {style: {display: html.NONE}}) - can.base.isFunc(cb) && cb() - }) + can.page.style(can, target, html.OPACITY, 1-(index+1)/time.length) + }, function() { can.base.isFunc(cb) && cb(), can.page.style(can, target, html.DISPLAY, html.NONE) }) }, - selectField: function(event, can) { - if (event.ctrlKey && event.key >= "0" && event.key <= "9") { - if (event.shiftKey) { - can.page.Select(can, can._option, "input[type=button]", function(item, index) { - index == event.key && (item.click()) - }) - return - } - if (event.key == "0") { return can.onimport._back(can) } + if (!event.ctrlKey || event.key < "0" || event.key > "9") { return } + if (event.shiftKey) { + return can.page.Select(can, can._option, "input[type=button]", function(item, index) { + index == event.key && (item.click()) + }) + } + if (event.key == "0") { return can.onimport._back(can) } - can.page.Select(can, can._output, html.TR, function(tr, index) { if (index == event.key) { - var head = can.page.Select(can, can._output, html.TH, function(th, order) { return th.innerText }) - can.page.Select(can, tr, html.TD, function(td, index) { can.Option(head[index], td.innerText) }) - can.Update(event) - } }) - } + can.page.Select(can, can._output, html.TR, function(tr, index) { if (index == event.key) { + var head = can.page.Select(can, can._output, html.TH, function(th, order) { return th.innerText }) + can.page.Select(can, tr, html.TD, function(td, index) { can.Option(head[index], td.innerText) }) + can.Update(event) + } }) }, - selectTable: function(event, can, target, cb) { - if (event.ctrlKey) { - function select(order) { - var index = 0; return can.page.Select(can, can._output, html.TR, function(tr) { - if (can.page.ClassList.has(can, tr, html.HIDDEN)) { return } - if (!can.page.ClassList.set(can, tr, html.SELECT, order == index++)) { return tr} - can.base.isFunc(cb) && cb(tr) - can.Status("index", index-1) - return tr - }).length - } - switch (event.key) { - case "n": - var total = select(target._index) - select(target._index = ((target._index)+1) % total) - can.onkeymap.prevent(event) - break - case "p": - var total = select(target._index) - select(target._index = (target._index-1) < 0? total-1: (target._index-1)) - can.onkeymap.prevent(event) - break - default: target._index = 0 - } + selectTable: function(event, can, target, cb) { if (!event.ctrlKey) { return } + function select(order) { var index = 0 + return can.page.Select(can, can._output, html.TR, function(tr) { + if (can.page.ClassList.has(can, tr, html.HIDDEN)) { return } + if (!can.page.ClassList.set(can, tr, html.SELECT, order == index++)) { return tr } + return can.Status(mdb.INDEX, index-1), can.base.isFunc(cb) && cb(tr), tr + }).length } + var total = select(target._index); switch (event.key) { + case "n": select(target._index = ((target._index)+1) % total); break + case "p": select(target._index = (target._index-1) < 0? total-1: (target._index-1)); break + default: target._index = 0; return + } can.onkeymap.prevent(event) }, selectTableInput: function(event, can, target, cb) { if (event.ctrlKey) { @@ -800,18 +759,11 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe }); return tr }).length } - switch (event.key) { - case "n": - var total = select(target._index) - select(target._index = ((target._index)+1) % total) - break - case "p": - var total = select(target._index) - select(target._index = (target._index-1) < 0? total-1: (target._index-1)) - break + var total = select(target._index); switch (event.key) { + case "n": select(target._index = ((target._index)+1) % total); break + case "p": select(target._index = (target._index-1) < 0? total-1: (target._index-1)); break default: target._index = 0, target._value = ""; return - } - return can.onkeymap.prevent(event) + } return can.onkeymap.prevent(event) } target._index = 0, target._value = "" @@ -823,16 +775,15 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe var total = can.page.Select(can, can._output, html.TR, function(tr) { if (!can.page.ClassList.has(can, tr, html.HIDDEN)) { return tr} - }).length-1 - total == 0 && can.base.isFunc(cb) && cb() + }).length-1; total == 0 && can.base.isFunc(cb) && cb() can.Status(kit.Dict(mdb.TOTAL, total, mdb.INDEX, target._index)) }, }) Volcanos("onkeymap", {help: "键盘交互", list: [], _focus: [], _init: function(can, target) { can.onkeymap._build(can), document.body.onkeydown = function(event) { if (event.metaKey) { return } - if (event.target.tagName == "SELECT" || event.target.tagName == "INPUT" || event.target.tagName == "TEXTAREA") { return } + if (can.page.tagis([html.SELECT, html.INPUT, html.TEXTAREA], event.target)) { return } var msg = can.request(event, {"model": "normal"}); if (msg.Option(ice.MSG_HANDLE) == ice.TRUE) { return } - can.onengine.signal(can, "onkeydown", msg); if (msg.Option(ice.MSG_HANDLE) == ice.TRUE) { return } + can.onengine.signal(can, chat.ONKEYDOWN, msg); if (msg.Option(ice.MSG_HANDLE) == ice.TRUE) { return } can._keylist = can.onkeymap._parse(event, can, msg.Option("model"), can._keylist, can._output) } }, @@ -852,13 +803,11 @@ Volcanos("onkeymap", {help: "键盘交互", list: [], _focus: [], _init: functio if ("0" <= list[pre] && list[pre] <= "9") { continue } break }; var count = parseInt(list.slice(0, pre).join(""))||1 - var map = can.onkeymap._mode[mode] function repeat(cb, count) { list = []; for (var i = 1; i <= count; i++) { if (cb(event, can, target, count)) { break } } } var cb = map && map[event.key]; if (can.base.isFunc(cb) && event.key.length > 1) { repeat(cb, count); return list } var cb = map && map[event.key.toLowerCase()]; if (can.base.isFunc(cb) && event.key.length > 1) { repeat(cb, count); return list } - can.misc.Log("keys", count, list) var map = can.onkeymap._engine[mode]; if (!map) { return [] } for (var i = pre; i < list.length; i++ ) { var map = map.list[list[i]]; if (!map) { return [] } @@ -870,10 +819,9 @@ Volcanos("onkeymap", {help: "键盘交互", list: [], _focus: [], _init: functio insert: { jk: function(event, can, target) { target.blur(), can.onkeymap.deleteText(target, target.selectionStart-1, target.selectionStart) }, Escape: function(event, can, target) { target.blur() }, - Enter: function(event, can, target) { - var his = target._history||[]; his.push(target.value) - event.target.tagName == "INPUT" && can.onmotion.focus(can, target) - target._history = his, target._current = his.length + Enter: function(event, can, target) { var his = target._history||[] + his.push(target.value), target._history = his, target._current = his.length + can.page.tagis(html.INPUT, event.target) && can.onmotion.focus(can, target) }, }, insert_ctrl: { diff --git a/lib/base.js b/lib/base.js index 736eeca8..30e6f43a 100644 --- a/lib/base.js +++ b/lib/base.js @@ -1,15 +1,10 @@ Volcanos("base", {help: "数据类型", - Int: function(val, def) { - return parseInt(val)||def||0 - }, + Int: function(val, def) { return parseInt(val)||def||0 }, Obj: function(val, def) { try { - val = typeof val == lang.STRING && val != ""? JSON.parse(val): val - if (val && val.length == 0 && def && def.length > 0) { return def } - return val||def - } catch (e) { - return [val] - } + if (typeof val == lang.STRING) { if (val == "") { return def } val = JSON.parse(val) } + if (val.length > 0) { return val } for (var k in val) { return val } return def + } catch (e) { return val && val.split && val.split(ice.FS) || def } }, Copy: function(to, from) { if (arguments.length == 2) { @@ -23,7 +18,6 @@ Volcanos("base", {help: "数据类型", }, 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++) { @@ -37,18 +31,21 @@ Volcanos("base", {help: "数据类型", return to === from }, - Ext: function(path) { - return (path.split(ice.PS).pop().split(ice.PT).pop()).toLowerCase() - }, + Ext: function(path) { return (path.split(ice.PS).pop().split(ice.PT).pop()).toLowerCase() }, Path: function(path) { var res = "" for (var i = 0; i < arguments.length; i++) { res += (arguments[i][0]==ice.PS || res=="" || res[res.length-1]==ice.PS? "": ice.PS) + arguments[i].trim() } return res }, - Args: function(obj) { var res = [] - for (var k in obj) { - res.push(encodeURIComponent(k)+"="+encodeURIComponent(obj[k])) + 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)+"="+encodeURIComponent(arguments[i][k])) } + i--; continue + } else if (arguments[i]) { + res.push(encodeURIComponent(arguments[i])+"="+encodeURIComponent(arguments[i+1])) + } } return res.join("&") }, @@ -58,25 +55,17 @@ Volcanos("base", {help: "数据类型", }) 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.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) { args[arguments[i][j]] = arguments[i][j] } } else { - for (var k in arguments[i]) { - args[k] = arguments[i][k] - } + for (var k in arguments[i]) { args[k] = arguments[i][k] } } break } } - var list = []; for (var k in args) { - list.push(encodeURIComponent(k)+"="+encodeURIComponent(args[k])) - } + var list = []; for (var k in args) { list.push(encodeURIComponent(k)+"="+encodeURIComponent(args[k])) } return url.split("?")[0]+(list.length>0? "?"+list.join("&"): "") }, ParseURL: function(url) { var res = {link: url} @@ -96,12 +85,8 @@ Volcanos("base", {help: "数据类型", }) return res } - try { res = JSON.parse(str) - res.text = res.text||str - res.type = res.type||nfs.JSON - } catch (e) { - res = {type: mdb.TEXT, text: str} - } + try { res = JSON.parse(str), res.text = res.text||str, res.type = res.type||nfs.JSON + } catch (e) { res = {type: mdb.TEXT, text: str} } return res }, ParseSize: function(size) { size = size.toLowerCase() @@ -137,9 +122,7 @@ Volcanos("base", {help: "数据类型", while (n > 0) { result.push("0"); n-- } return result.reverse(), result.join("") }, - Format: function(obj) { - return JSON.stringify(obj) - }, + Format: function(obj) { return JSON.stringify(obj) }, Simple: function() { var res = [] for (var i = 0; i < arguments.length; i++) { var arg = arguments[i]; switch (typeof arguments[i]) { @@ -154,9 +137,7 @@ Volcanos("base", {help: "数据类型", } return res }, - AddUniq: function(list, value) { list = list||[] - return list.indexOf(value) == -1 && list.push(value), list - }, + AddUniq: function(list, value) { list = list||[]; return list.indexOf(value) == -1 && list.push(value), list }, Date: function(time) { var now = new Date() if (typeof time == lang.STRING && time != "") { var ls = time.split(ice.SP) @@ -186,9 +167,7 @@ Volcanos("base", {help: "数据类型", fmt = fmt.replace("%S", this.Number(now.getSeconds(), 2)) return fmt }, - TimeAdd: function(t, d) { - return new Date(t - t%(24*3600*1000) - 8*3600*1000 + d*24*3600*1000) - }, + TimeAdd: function(t, d) { return new Date(t - t%(24*3600*1000) - 8*3600*1000 + d*24*3600*1000) }, Duration: function(n) { var res = "", h = 0 h = parseInt(n/3600000/24), h > 0 && (res += h+"d"), n = n % (3600000*24) h = parseInt(n/3600000), h > 0 && (res += h+"h"), n = n % 3600000 @@ -229,31 +208,16 @@ Volcanos("base", {help: "数据类型", return str }, - isNight: function() { var now = new Date() - return now.getHours() < 7 || now.getHours() > 17 - }, - beginWith: function(str, begin) { - return str.trim().indexOf(begin) == 0 - }, - endWith: function(str, end) { - return str.lastIndexOf(end) + end.length == str.length - }, + random: function(max, min) { min = min||0, parseInt(Math.random()*(max-min))+min }, + isNight: function() { var now = new Date(); return now.getHours() < 7 || now.getHours() > 17 }, + beginWith: function(str, begin) { return str.trim().indexOf(begin) == 0 }, + endWith: function(str, end) { return str.lastIndexOf(end) + end.length == str.length }, trim: function(args) { if (this.isString(args)) { return args.trim() } if (this.isArray(args)) { for (var i = args.length-1; i >= 0; i--) { if (!args[i]) { args.pop() } else { break } } } return args }, - trimPrefix: function(str, pre) { - if (str.indexOf(pre) == -1) { - return str - } - return str.slice(pre.length) - }, - trimSuffix: function(str, end) { - if (str.indexOf(end) == -1) { - return str - } - return str.slice(0, str.indexOf(end)) - }, + trimPrefix: function(str, pre) { if (str.indexOf(pre) == -1) { return str } return str.slice(pre.length) }, + trimSuffix: function(str, end) { if (str.indexOf(end) == -1) { return str } return str.slice(0, str.indexOf(end)) }, join: function(list, sp) { return (list||[]).join(sp||ice.SP) }, joins: function(list, inner, outer) { for (var i = 0; i < list.length; i++) { diff --git a/lib/core.js b/lib/core.js index 9830a9ac..45e5e8f7 100644 --- a/lib/core.js +++ b/lib/core.js @@ -2,11 +2,7 @@ Volcanos("core", {help: "数据结构", Keys: shy("连接器", function() { var list = [] for (var i = 0; i < arguments.length; i++) { var v = arguments[i] switch (typeof v) { - case lang.OBJECT: - for (var j = 0; j < v.length; j++) { - list.push(v[j]) - } - break + case lang.OBJECT: for (var j = 0; j < v.length; j++) { list.push(v[j]) } break case lang.FUNCTION: v = v() default: v && list.push(v+"") } @@ -18,10 +14,7 @@ Volcanos("core", {help: "数据结构", if (key == undefined) { return data } if (typeof key == lang.OBJECT && key.length > 0) { key = key.join(ice.PT) } - - if (typeof key == lang.OBJECT) { for (var k in key) { - arguments.callee.call(this, data, k, key[k]) - }; return data } + if (typeof key == lang.OBJECT) { for (var k in key) { arguments.callee.call(this, data, k, key[k]) } return data } if (value != undefined) { data[key] = value } if (data[key] != undefined) { return data[key] } @@ -29,7 +22,7 @@ Volcanos("core", {help: "数据结构", var p = data, ls = key.split(ice.PT); while (p && ls.length > 0) { if (ls[0] == "-1") { ls[0] = p.length-1 } p = p[ls[0]], ls = ls.slice(1) - }; return p + } return p }), Split: shy("分词器", function(str) { if (!str || !str.length) { return [] } var opt = {detail: false}, arg = []; for (var i = 1; i < arguments.length; i++) { @@ -52,7 +45,7 @@ Volcanos("core", {help: "数据结构", if (space[str[i]]) { // 空白符 if (s) { continue } begin > -1 && push(str.slice(begin, i)) - opt.detail && push({type: "space", text: str.slice(i, i+1)}) + opt.detail && push({type: html.SPACE, text: str.slice(i, i+1)}) } else if (block[str[i]]) { // 分隔符 if (s) { continue } @@ -61,6 +54,7 @@ Volcanos("core", {help: "数据结构", } else if (quote[str[i]]) { // 引用符 if (s == "") { + begin > -1 && push(str.slice(begin, i)) s = str[i], begin = i+1 } else if (s == str[i]) { push({type: lang.STRING, text: str.slice(begin, i), left: s, right: str[i]}) @@ -80,7 +74,7 @@ Volcanos("core", {help: "数据结构", return res }), CallFunc: shy("调用器", function(func, args, mod) { args = args||{} - var can = args["can"]||args[0], msg = args["msg"]||args[1], cmds = args["cmds"]||[], event = args["event"]||{} + var event = args["event"]||{}, can = args["can"]||args[0], msg = args["msg"]||args[1], cmds = args["cmds"]||[] // 查找调用 func = typeof func == lang.FUNCTION? func: typeof func == lang.STRING? this.Value(mod||can, func): @@ -112,7 +106,6 @@ Volcanos("core", {help: "数据结构", } list = list||[] - if (interval > 0) { // 时间序列 function loop(i) { if (i >= list.length) { return typeof cbs == lang.FUNCTION && cbs(list) } cb(list[i], i, list), setTimeout(function() { loop(i+1) }, interval) @@ -182,12 +175,5 @@ Volcanos("core", {help: "数据结构", typeof cb == lang.FUNCTION && setTimeout(function() { loop(0) }, interval.interval||interval[0]) return timer }), - 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 == lang.FUNCTION && cb() - }, cbs) - return list - }), }) diff --git a/lib/misc.js b/lib/misc.js index 8b2e67a6..cb81f8d8 100644 --- a/lib/misc.js +++ b/lib/misc.js @@ -65,8 +65,7 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg Push: function(key, value, detail) { if (can.base.isObject(key)) { value = value||can.core.Item(key), can.core.List(value, function(item) { - detail? msg.Push(mdb.KEY, item).Push(mdb.VALUE, key[item]||""): - msg.Push(item, key[item]||"") + detail? msg.Push(mdb.KEY, item).Push(mdb.VALUE, key[item]||""): msg.Push(item, key[item]||"") }) return msg } @@ -79,7 +78,7 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg for (var i = 0; i < arguments.length; i++) { msg.result.push(arguments[i]) } return msg._hand = true, msg }, - }; + } return can.misc.proto(msg, proto) }, POST: function(can, msg, url, form, cb) { // _method _accept _upload _progress @@ -101,7 +100,7 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg if (msg._upload) { // 上传文件 var data = new FormData(); can.core.Items(form, function(value, index, key) { data.append(key, value) - }), data.append(html.UPLOAD, msg._upload), data.append(ice.MSG_UPLOAD, "upload") + }), data.append(html.UPLOAD, msg._upload), data.append(ice.MSG_UPLOAD, mdb.UPLOAD) xhr.upload.onprogress = function(event) { can.base.isFunc(msg._progress) && msg._progress(event, parseInt(event.loaded*100/event.total), event.total, event.loaded) @@ -131,7 +130,7 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg var socket = new WebSocket(can.base.MergeURL(url, args)) socket.onclose = function() { can.misc.Log(html.WSS, cli.CLOSE, args) - can.base.isFunc(onclose)? onclose(socket): can.core.Timer(1000, function() { + can.base.isFunc(onclose)? onclose(socket): can.core.Timer(can.base.random(3000, 1000), function() { can.misc.WSS(can, args, cb, onopen, onerror, onclose) }) }, socket.onerror = function() { can.misc.Log(html.WSS, cli.ERROR, args) @@ -141,48 +140,31 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg can.base.isFunc(onopen) && onopen(socket) } - socket.onmessage = function(event) { - try { // 解析命令 - var data = JSON.parse(event.data) - } catch (e) { - var data = {detail: [event.data]} - } + socket.onmessage = function(event) { // 解析命令 + try { var data = JSON.parse(event.data) } catch (e) { var data = {detail: [event.data]} } var msg = can.request(event); msg.Reply = function() { // 回复命令 - msg.result = (msg.result||[]).concat(can.core.List(arguments)) - - msg.Option({_handle: true, _source: (msg[ice.MSG_TARGET]||[]).reverse().slice(1).join(ice.PT)||"",_target: (msg[ice.MSG_SOURCE]||[]).reverse().join(".")}) - can.misc.Log(html.WSS, ice.MSG_RESULT, msg.result, msg) - - delete(msg._event), delete(msg._can) - socket.send(JSON.stringify(msg)) + msg.Option({_handle: true, _source: (msg[ice.MSG_TARGET]||[]).reverse().slice(1).join(ice.PT)||"", _target: (msg[ice.MSG_SOURCE]||[]).reverse().join(ice.PT)}) + msg.result = (msg.result||[]).concat(can.core.List(arguments)), can.misc.Log(html.WSS, ice.MSG_RESULT, msg.result, msg) + delete(msg._event), delete(msg._can), socket.send(JSON.stringify(msg)) }, msg.detail = data.detail, msg.Copy(data) - // 执行命令 - try { + try { // 执行命令 can.misc.Log(html.WSS, ice.MSG_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() - } + } catch (e) { can.misc.Log(e), msg.Reply() } } }, CookieSessid: shy("会话变量", function(can, value, path) { - var name = ice.MSG_SESSID+"_"+location.host.replaceAll(".", "_").replaceAll(":", "_") - return can.misc.Cookie(can, name, value, path) + return can.misc.Cookie(can, ice.MSG_SESSID+"_"+location.host.replaceAll(ice.PT, "_").replaceAll(ice.DF, "_"), value, path) }), Cookie: shy("会话变量", function(can, key, value, path) { function set(k, v) { document.cookie = k+"="+v+";path="+(path||ice.PS) } + if (can.base.isObject(key)) { for (var k in key) { set(k, key[k]) } key = undefined } - if (can.base.isObject(key)) { - for (var k in key) { set(k, key[k]) } - key = undefined - } if (key == undefined) { var cs = {} - document.cookie.split("; ").forEach(function(item) { - var ls = item.split("="); cs[ls[0]] = ls[1] - }) + document.cookie.split("; ").forEach(function(item) { var ls = item.split("="); cs[ls[0]] = ls[1] }) return cs } @@ -190,36 +172,27 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg var val = (new RegExp(key+"=([^;]*);?")).exec(document.cookie) return val && val.length > 0? val[1]: "" }), - SearchOrConf: function(can, key, def) { - can.base.getValid(can.misc.Search(can, key), can.Conf(key), def) - }, + SearchOrConf: function(can, key, def) { can.base.getValid(can.misc.Search(can, key), can.Conf(key), def) }, Search: shy("请求参数", function(can, key, value) { var args = {} if (value == undefined && can.base.isString(key)) { - var ls = location.pathname.split(ice.PS) - if (ls[1] == chat.SHARE) { args[chat.SHARE] = ls[2] } - if (ls[1] == "chat" && ls[2] == ice.POD) { args[ice.POD] = ls[3] } + var ls = location.pathname.split(ice.PS); if (ls[1] == chat.SHARE) { args[chat.SHARE] = ls[2] } + for (var i = 2; i < ls.length; i += 2) { if ({"pod": true, "cmd": true}[ls[i]]) { args[ls[i]] + ls[i+1] } } } - location.search && location.search.slice(1).split("&").forEach(function(item) { var x = item.split("=") x[1] != "" && (args[x[0]] = decodeURIComponent(x[1])) }) if (can.base.isObject(key)) { can.core.Item(key, function(key, value) { - if (value != undefined) {args[key] = value} - args[key] == "" && delete(args[key]) + if (value != undefined) { args[key] = value } args[key] == "" && delete(args[key]) }) - } else if (key == undefined) { - return args - } else if (value == undefined) { - return args[key] } else { + if (key == undefined) { return args } + if (value == undefined) { return args[key] } args[key] = value, args[key] == "" && delete(args[key]) } - return location.search = can.core.Item(args, function(key, value) { - return key+"="+encodeURIComponent(value) - }).join("&") + return location.search = can.core.Item(args, function(key, value) { return key+"="+encodeURIComponent(value) }).join("&") }), MergeURL: shy("地址链接", function(can, objs, clear) { var path = location.pathname; objs._path && (path = objs._path, delete(objs._path)) @@ -232,12 +205,8 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg if (list[cmds[0]]) { return list[cmds[0]](cmds.slice(1)), true } }, concat: function(can, to, from) { to = to||[], from = from||[] - if (from[0] == ctx.ACTION && from[1] == ice.RUN && can.onengine.plugin.meta[from[2]]) { - return from - } - if (can.onengine.plugin.meta[from[0]]) { - return from - } + if (from[0] == ctx.ACTION && from[1] == ice.RUN && can.onengine.plugin.meta[from[2]]) { return from } + if (can.onengine.plugin.meta[from[0]]) { return from } if (from[0] == "_search") { return from } return to.concat(from) }, diff --git a/lib/page.js b/lib/page.js index 9cd05b14..4f9cc264 100644 --- a/lib/page.js +++ b/lib/page.js @@ -7,9 +7,7 @@ Volcanos("page", {help: "用户界面", ClassList: { return value != obj.className && (obj.className = value), value }, del: function(can, obj, key) { var list = obj.className? obj.className.split(ice.SP): [] - return obj.className = can.core.List(list, function(value) { - return value == key? undefined: value - }).join(ice.SP).trim() + return obj.className = can.core.List(list, function(value) { return value == key? undefined: value }).join(ice.SP).trim() }, set: function(can, obj, key, condition) { return (condition? this.add(can, obj, key): this.del(can, obj, key)).indexOf(key) > -1 @@ -59,9 +57,7 @@ Volcanos("page", {help: "用户界面", ClassList: { "width": true, "max-width": true, "min-width": true, } - if (size[k] && v && (can.base.isNumber(v) || v.indexOf && v.indexOf("px") == -1)) { - v += "px" - } + if (size[k] && v && (can.base.isNumber(v) || v.indexOf && v.indexOf("px") == -1)) { v += "px" } target[key] && (target[key][k] = v) }) }) @@ -305,8 +301,7 @@ Volcanos("page", {help: "用户界面", ClassList: { } }, replace: function(can, text, key, value) { - text = can.base.replaceAll(text, "<", "<", ">", ">", key, value) - return text + return can.base.replaceAll(text, "<", "<", ">", ">", key, value) }, Color: function(text) { if (typeof text != lang.STRING) { return "" } if (text.indexOf("http://") == 0 || text.indexOf("https://") == 0 || text.indexOf("ftp://") == 0) { @@ -333,8 +328,8 @@ Volcanos("page", {help: "用户界面", ClassList: { switch (item.type = item.type||html.TEXT) { case html.TEXTAREA: input.type = html.TEXTAREA - input.style.height = input.style.height||can.Conf(["feature", html.TEXTAREA, item.name, html.HEIGHT].join(ice.PT))||can.Conf(["feature", html.TEXTAREA, html.HEIGHT].join(ice.PT)) - input.style.width = input.style.width||can.Conf(["feature", html.TEXTAREA, item.name, html.WIDTH].join(ice.PT))||can.Conf(["feature", html.TEXTAREA, html.WIDTH].join(ice.PT)) + input.style.height = input.style.height||can.Conf([ctx.FEATURE, html.TEXTAREA, item.name, html.HEIGHT].join(ice.PT))||can.Conf(["feature", html.TEXTAREA, html.HEIGHT].join(ice.PT)) + input.style.width = input.style.width||can.Conf([ctx.FEATURE, html.TEXTAREA, item.name, html.WIDTH].join(ice.PT))||can.Conf(["feature", html.TEXTAREA, html.WIDTH].join(ice.PT)) // no break case html.USERNAME: case html.PASSWORD: @@ -355,7 +350,7 @@ Volcanos("page", {help: "用户界面", ClassList: { return {type: html.OPTION, value: value, inner: value} }), item.className || can.page.ClassList.add(can, item, ctx.ARGS) break - case html.BUTTON: item.value = item.value||item.name||"list"; break + case html.BUTTON: item.value = item.value||item.name||mdb.LIST; break case "upfile": item.type = html.FILE; break case html.UPLOAD: item.type = html.FILE, input.name = html.UPLOAD; break default: @@ -363,13 +358,14 @@ Volcanos("page", {help: "用户界面", ClassList: { return input }, + styleDisplay: function(can, target, value) { + return can.page.style(can, target, html.DISPLAY, value), target.style.display + }, styleHeight: function(can, target, value) { - can.page.style(can, target, html.HEIGHT, value) - return target.offsetHeight + return can.page.style(can, target, html.HEIGHT, value), target.offsetHeight }, styleWidth: function(can, target, value) { - can.page.style(can, target, html.WIDTH, value) - return target.offsetWidth + return can.page.style(can, target, html.WIDTH, value), target.offsetWidth }, style: function(can, target, style) { var value = {} for (var i = 2; i < arguments.length; i += 2) { @@ -379,8 +375,7 @@ Volcanos("page", {help: "用户界面", ClassList: { value[arguments[i]] = arguments[i+1] } } - can.page.Modify(can, target, {style: value}) - return value + return can.page.Modify(can, target, {style: value}), value }, Keys: function() { var list = [] for (var i = 0; i < arguments.length; i++) { var v = arguments[i] @@ -405,6 +400,9 @@ Volcanos("page", {help: "用户界面", ClassList: { styleSheet.type = "text/css", styleSheet.innerText = text document.head.appendChild(styleSheet) }, + tagis: function(type, target) { type = typeof type == lang.OBJECT? type: [type] + if (type.indexOf(target.tagName.toLowerCase()) > -1) { return true } + }, offsetTop: function(item) { var res = 0 while (item) { res += item.offsetTop||0, item = item.parentNode } return res diff --git a/lib/user.js b/lib/user.js index 6bacc9cc..770c09b0 100644 --- a/lib/user.js +++ b/lib/user.js @@ -46,19 +46,15 @@ Volcanos("user", {help: "用户操作", agent: { return can.base.Time(time, (fmt||"%y-%m-%d %H:%M:%S").replace("%w", list[now.getDay()])) }, - title: function(text) { - return text && (document.title = text), document.title - }, + title: function(text) { return text && (document.title = text), document.title }, topic: function(can, name) { can.user.isMobile && (name += " mobile") && can.user.isLandscape() && (name += " landscape") can.page.Modify(can, document.body, {className: name}) }, - language: function(can) { - return can.misc.Search(can, "language") - }, + language: function(can) { return can.misc.Search(can, "language") }, trans: function(can, text, list) { if (can.base.isObject(text)) { - return can.core.Item(text, function(k, v) { can.core.Value(can._trans, k, v) }) - } + 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.base.isFunction(text)) { text = text.name||"" } @@ -78,12 +74,8 @@ Volcanos("user", {help: "用户操作", agent: { "label": "标签", "exec": "执行", }[text]||text }, - toastProcess: function(can, title) { - return can.user.toast(can, ice.PROCESS, title) - }, - toastSuccess: function(can, title) { - return can.user.toast(can, ice.SUCCESS, title) - }, + toastProcess: function(can, title) { return can.user.toast(can, ice.PROCESS, title) }, + toastSuccess: function(can, title) { return can.user.toast(can, ice.SUCCESS, title) }, 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, height = meta.height||100; if (width < 0) { width = window.innerWidth + width } @@ -124,9 +116,7 @@ Volcanos("user", {help: "用户操作", agent: { }) }, login: function(can, cb, method) { - var ui = can.user.input({}, can, [ - {type: html.USERNAME}, {type: html.PASSWORD}, - ], function(event, button, data, list) { return { + var ui = can.user.input({}, can, [{type: html.USERNAME}, {type: html.PASSWORD}], function(event, button, data, list) { return { "登录": function() { can.run({}, [aaa.LOGIN, data[html.USERNAME], data[html.PASSWORD]], function(msg) { if (msg.Option(ice.MSG_USERNAME)) { diff --git a/page/index.css b/page/index.css index 4050422e..9f03fda9 100644 --- a/page/index.css +++ b/page/index.css @@ -24,7 +24,7 @@ div.story[data-type=spark] { select { background-color:black; color:cyan; box-shadow:4px 4px 10px 1px #626bd0; - height:1.7em; padding:0 10px; + height:1.7rem; padding:0 10px; cursor:pointer; } textarea { background-color:cyan; width:400px; height:60px; white-space:pre; } @@ -32,7 +32,7 @@ input[type=button] { background-color:black; color:cyan; cursor:pointer; } input[type=text] { background-color:cyan; color:black; box-shadow:4px 4px 10px 1px #626bd0; - height:1.4em; width:82px; + height:1.4rem; width:82px; padding:0 4px; } input[name=date] { width:150px; } @@ -122,6 +122,7 @@ fieldset>div.status>div.item { float:left; padding:4px; height:18px; } fieldset.panel>legend { display:none; } fieldset.plugin { margin:10px; padding:10px; background-color:#061c3c9e; box-shadow:2px 2px 10px 4px #626bd0; } +fieldset.plugin>div.action { float:none; display:block; height:1.8rem; overflow:auto; } fieldset.plugin>div.status { border-top:1px solid darkcyan; } fieldset.output { margin:0; padding:0; } fieldset.output>legend { display:none; } @@ -132,6 +133,7 @@ fieldset.story>legend { display:block; padding:2px 20px; letter-spacing:4px; } fieldset.story>div.status { border-top:1px solid darkcyan; } fieldset.float { background-color:#023531cf; margin:0px; padding:0px; position:absolute; } fieldset.float>legend { float:left; } +fieldset.float>div.action { display:block; float:none; height:2rem; overflow:auto; } fieldset.float table { color:white; } fieldset.input { background-color:#0d4142a6; position:fixed; top:32px; } @@ -140,6 +142,7 @@ fieldset.input div.output { max-height:400px; } fieldset.input table { color:white; } fieldset.input td { word-break:keep-all; } fieldset.input.date table { text-align:center; width:280px; } +fieldset.input.date>div.action { height:4rem; } body>div.toast { background-color:#0e3369b3; color:yellow; padding:5px; overflow:auto; position:fixed; } body>div.toast div.title { float:left; cursor:copy; word-break:break-all; } @@ -176,9 +179,9 @@ body>div.upload input[type=file] { width:240px; } * { tab-size:4; } textarea { tab-size:2; } -input, select, option, table.content, div.item, div.code, code.story, div.story[data-type=spark] { font-size:1.1em; font-family:monospace; } -legend { font-size:1.4em; } -fieldset>div.status>div.item>label { font-size:0.6em; color:#bdb8b8e0; } +input, select, option, table.content, div.item, div.code, code.story, div.story[data-type=spark] { font-size:1.1rem; font-family:monospace; } +legend { font-size:1.2rem; } +fieldset>div.status>div.item>label { font-size:0.6rem; color:#bdb8b8e0; } body>div.toast div.title { color:#cae850; } body>div.toast div.duration { color:gray; } @@ -208,12 +211,13 @@ body.white table td>input[type=button][value=启动] { background-color:#52ce78; body.white table td>input[type=button][name=create] { background-color:blue; } body.white table td>input[type=button][name=remove] { background-color:red; } -body.white fieldset>div.status>div.item>label { font-size:0.6em; color:#cefbfbe0; } +body.white fieldset>div.status>div.item>label { font-size:0.6rem; color:#cefbfbe0; } body.white fieldset.Action { color:black; } body.white fieldset.Action>div.action { color:white; } body.white fieldset.Action>div.action div.item { height:21px; } body.white fieldset.Action fieldset.plugin { background-color:#ffffff78; } body.white fieldset.Action fieldset.plugin legend { background-color:#339999; color:white; border-radius:10px 10px 10px 10px; } +body.white fieldset.input table { color:white; } body.white>div.input textarea { border:2px solid #14a58e; border-radius:6px; } body.print { background-color:white; color:black; } @@ -235,22 +239,22 @@ body.white table.content tr:hover { background-color:green; } body.white fieldset.Action fieldset.plugin legend:hover { background-color:#6ee4e4; } body.print fieldset.River>div.output div.item.select { background-color:white; border:solid 2px red; } -body.mobile select { font-size:1.4rem; height:1.4em; margin-top:3px; } +body.mobile select { font-size:1.4rem; height:1.4rem; margin-top:3px; } body.mobile legend { font-size:2rem; } body.mobile input { font-size:1.2rem; } -body.mobile input[type=text] { margin-top:5px; height:1.4em; } +body.mobile input[type=text] { margin-top:5px; height:1.4rem; } body.mobile fieldset.Header.head { width:-webkit-fill-available; } -body.mobile fieldset.Header.head { background-color:#000000b8; font-size:2rem; height:2em; position:fixed; top:0; } -body.mobile fieldset.Header.head div.output { height:2em; } -body.mobile fieldset.Header.head>div.output>div { height:1.5em; } -body.mobile fieldset.Header.head>div.output div.menu { height:1.5em; } +body.mobile fieldset.Header.head { background-color:#000000b8; font-size:2rem; height:2rem; position:fixed; top:0; } +body.mobile fieldset.Header.head div.output { height:2rem; } +body.mobile fieldset.Header.head>div.output>div { height:1.5rem; } +body.mobile fieldset.Header.head>div.output div.menu { height:1.5rem; } body.mobile fieldset.Header.head div.state.time { display:none; } -body.mobile fieldset.River.left { position:fixed; top:2em; background-color:#243950bf; min-width:240px; font-size:2rem; } +body.mobile fieldset.River.left { position:fixed; top:2rem; background-color:#243950bf; min-width:240px; font-size:2rem; } body.mobile fieldset.River>div.output div.list div.item { font-size:2rem; } -body.mobile fieldset.Action.main { margin-top:4em; } +body.mobile fieldset.Action.main { margin-top:4rem; } body.mobile fieldset.Action.main.cmd { margin-top:0; margin-bottom:0; } body.mobile fieldset.Footer.foot { width:-webkit-fill-available; } -body.mobile fieldset.Footer.foot { background-color:#000000b8; font-size:2rem; height:2em; position:fixed; bottom:0; } +body.mobile fieldset.Footer.foot { background-color:#000000b8; font-size:2rem; height:2rem; position:fixed; bottom:0; } body.mobile fieldset.Footer.foot { display:none; } body.mobile.landscape fieldset.Header.head { position:unset; } body.mobile.landscape fieldset.Header.head div.state.time { display:block; } diff --git a/plugin/input/key.js b/plugin/input/key.js index 06eb4cac..b4f4815d 100644 --- a/plugin/input/key.js +++ b/plugin/input/key.js @@ -20,10 +20,14 @@ Volcanos("onfigure", {help: "控件详情", list: [], key: { }, onfocus: function(event, can, meta, cb, target) { if (target._figure) { return } target._figure = {}; cb(function(can, cbs) { target._figure = can.onlayout.figure(event, can, can._target, false, {top: can.page.offsetTop(target)+target.offsetHeight, left: can.page.offsetLeft(target)}) - can.onfigure.key._show(can, meta, cbs, target) - can.onmotion.focus(can, target) + can.onfigure.key._show(can, meta, cbs, target), can.onmotion.focus(can, target) + target.click() }) }, - onblur: function(event, can, meta, cb, target) { delete(target._figure), target._can && target._can.close() }, + onblur: function(event, can, meta, cb, target) { + can.core.Timer(100, function() { + delete(target._figure), target._can && target._can.close() + }) + }, onclick: function(event, can, meta, cb, target) { if (target._figure) { target._figure = can.onlayout.figure(event, can, can.core.Value(target, "_can._target")||{}); return } target._figure = {}; cb(function(can, cbs) { target._figure = can.onlayout.figure(event, can) can.onfigure.key._show(can, meta, cbs, target) diff --git a/plugin/local/code/inner.css b/plugin/local/code/inner.css index 41db241a..6472440c 100644 --- a/plugin/local/code/inner.css +++ b/plugin/local/code/inner.css @@ -1,9 +1,3 @@ -fieldset.inner>div.action { - float:none; - display:block; - /* height:1.65em; */ - overflow:auto; -} fieldset.inner>div.action div.tabs { border:solid 2px red; padding:2px; } @@ -33,7 +27,7 @@ fieldset.inner>div.output div.project { fieldset.inner>div.output div.content { position:relative; padding-right:25px; - font-size:1.2em; font-family:monospace; + font-size:1.2rem; font-family:monospace; overflow:auto; color:white; } diff --git a/proto.js b/proto.js index d2a01866..a0a88871 100644 --- a/proto.js +++ b/proto.js @@ -88,6 +88,7 @@ var mdb = { CREATE: "create", REMOVE: "remove", INSERT: "insert", DELETE: "delete", MODIFY: "modify", SELECT: "select", INPUTS: "inputs", PRUNES: "prunes", EXPORT: "export", IMPORT: "import", + UPLOAD: "upload", SEARCH: "search", ENGINE: "engine", RENDER: "render", PLUGIN: "plugin", NEXT: "next", PREV: "prev", PAGE: "page", MAIN: "main", @@ -220,6 +221,7 @@ var html = { CLASS: "class", FLOAT: "float", CLEAR: "clear", BOTH: "both", BACKGROUND: "background", SELECT: "select", HIDDEN: "hidden", DISPLAY: "display", BLOCK: "block", NONE: "none", FIXED: "fixed", + OPACITY: "opacity", STROKE_WIDTH: "stroke-width", STROKE: "stroke", FILL: "fill", FONT_SIZE: "font-size", MONOSPACE: "monospace", SCROLL: "scroll", HEIGHT: "height", WIDTH: "width", LEFT: "left", TOP: "top", RIGHT: "right", BOTTOM: "bottom", MAX_HEIGHT: "max-height", MAX_WIDTH: "max-width", MARGIN_X: "margin-x", MARGIN_Y: "margin-y",