diff --git a/frame.js b/frame.js index 32dc628a..6f244aef 100644 --- a/frame.js +++ b/frame.js @@ -182,7 +182,7 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) { run(event, item) }, onkeydown: function(event) { if (event.key == lang.ENTER) { target.click() }}}: item.length > 0? /* 3.列表 */ {type: html.SELECT, name: item[0], values: item.slice(1), onchange: function(event) { can.misc.Event(event, can, function(msg) { - var button = item[event.target.selectedIndex+1]; meta[item[0]]? can.core.CallFunc(meta[item[0]], [event, can, item[0], button]): meta[button] && can.core.CallFunc(meta[button], [event, can, button]) + var button = event.target.value; meta[item[0]]? can.core.CallFunc(meta[item[0]], [event, can, item[0], button]): meta[button] && can.core.CallFunc(meta[button], [event, can, button]) }) }}: /* 4.其它 */(item.type == html.BUTTON && (item.value = item.value||can.user.trans(can, item.name, meta._trans), item.onclick = item.onclick||function(event) { run(event, item.name) }), item), "", action) @@ -199,7 +199,7 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) { } return can.onengine._plugin(event, can, msg, can, cmds, cb) || can.run(event, cmds, cb||function(msg) { if (silent) { return } var _can = can._fields? can.sup: can if (_can == (msg._can._fields? msg._can._fields.sup: msg._can._fields) && can.core.CallFunc([_can, chat.ONIMPORT, ice.MSG_PROCESS], {can: _can, msg: msg})) { return } - if (cmds && cmds[0] == ctx.ACTION) { if (can.base.isIn(cmds[1], mdb.CREATE, mdb.INSERT, mdb.IMPORT) || msg.Length() == 0 && msg.Result() == "") { return can.user.toastSuccess(can, cmds[1]), can.Update() } } + if (cmds && cmds[0] == ctx.ACTION) { if (can.base.isIn(cmds[1], mdb.CREATE, mdb.INSERT, mdb.IMPORT, nfs.TRASH) || msg.Length() == 0 && msg.Result() == "") { return can.user.toastSuccess(can, cmds[1]), can.Update() } } can.onappend._output(can, msg, meta.display||msg.Option(ice.MSG_DISPLAY)||meta.feature.display) }) }, @@ -316,8 +316,9 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) { }, input: function(can, item, value, target, style) { if ([html.BR, html.HR].indexOf(item.type) > -1) { return can.page.Append(can, target, [item]) } var icon = [] - var input = can.page.input(can, can.base.Copy({className: "", type: "", name: ""}, item), value); input.title = can.Conf(can.core.Keys(ctx.FEATURE, chat.TITLE, item.name))||"" - if (item.type == html.SELECT && (value || item.value)) { input._init = function(target) { target.value = value||item.value } } + var _item = can.base.Copy({className: "", type: "", name: ""}, item) + var input = can.page.input(can, _item, value); input.title = can.Conf(can.core.Keys(ctx.FEATURE, chat.TITLE, item.name))||"" + if (item.type == html.SELECT && (value || _item.value)) { input._init = function(target) { target.value = value||_item.value } } if (item.type == html.TEXT) { input.onkeydown = item.onkeydown||function(event) { can.onkeymap.input(event, can), can.onkeymap.selectOutput(event, can), event.key == lang.ENTER && can.onkeymap.prevent(event) }, input.onfocus = input.onfocus||function(event) { @@ -328,6 +329,14 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) { if (item.range) { input._init = function(target) { can.onappend.figure(can, item, target, function(sub, value, old) { target.value = value, can.core.CallFunc([can.onaction, item.name], [event, can, item.name]) }) } } + if (item.type == html.SELECT) { var ui = can.page.Append(can, target, [{view: [[html.ITEM, item.type, item.name].concat(style)], + list: [input].concat([{type: html.INPUT, value: _item.value||_item.values[0], data: {type: html.BUTTON}, onclick: function(event) { var target = event.target + var carte = can.user.carte(event, can, {}, _item.values, function(event, button) { target.value = button, ui.select.value = button, ui.select.onchange({target: ui.select}) }) + can.onappend.style(can, [html.SELECT, item.name], carte._target), can.page.style(can, carte._target, html.MIN_WIDTH, event.target.offsetWidth) + }, _init: function(target) { can.onmotion.delay(can, function() { + target.value = ui.select.value, can.page.style(can, target, html.WIDTH, ui.select.offsetWidth+10), can.onappend.style(can, html.HIDE, ui.select) + }) }}, {text: ["\u25BF", html.SPAN, html.ICON]}]) + }]); return ui[item.name] } var _input = can.page.Append(can, target, [{view: [[html.ITEM, item.type, item.name].concat(style)], list: [input].concat(icon)}])[item.name]; return _input }, table: function(can, msg, cb, target, keys) { if (!msg || msg.Length() == 0) { return } var meta = can.base.Obj(msg.Option(mdb.META)) @@ -368,7 +377,7 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) { append(can.page.Append(can, target, [html.LAYOUT])._target, type==FLOW? FLEX: FLOW, item) } else if (can.base.isObject(item)) { if (item.index) { item._index = count++, ui.size[item._index] = item.height||item.width - can.onappend.plugin(can, item, function(sub) { can._plugins = can.misc.concat(can, can._plugins, [sub]) + can.onappend.plugin(can, item, function(sub) { can._plugins = (can._plugins||[]).concat([sub]) item.layout = function(width, height) { sub.onimport.size(sub, height, width) } }, target, ui[item._index] = can.onappend.field(can, item.type, {name: item.index.split(ice.PT).pop(), help: item.help}, target)._target) } else { can.page.Append(can, target, [item]) } @@ -435,6 +444,7 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) { (meta.run||can.run)(sub.request(event, can.Option()), cmds, cb, true) }, target._can = sub, can.base.Copy(sub, can.onfigure[input], true), sub._name = sub._path = path sub.hidden = function() { return !can.page.isDisplay(sub._target) }, sub.close = function() { can.page.Remove(can, sub._target), delete(target._can) } + meta.mode && can.onappend.style(sub, meta.mode) can.page.style(sub, sub._target, meta.style), can.base.isFunc(meta._init) && meta._init(sub, sub._target), show(sub, cb) }, can._root._target) }}) @@ -459,7 +469,7 @@ Volcanos(chat.ONLAYOUT, {_init: function(can, target) { target = target||can._ro var rect = event.target == document.body? {left: can.page.width()/2, top: can.page.height()/2, right: can.page.width()/2, bottom: can.page.height()/2}: event.target.getBoundingClientRect() var layout = right? {left: rect.right, top: rect.top}: {left: rect.left, top: rect.bottom} can.getActionSize(function(left, top, width, height) { left = left||0, top = top||0, height = can.base.Max(height, can.page.height()-top) - can.page.style(can, target, html.MAX_HEIGHT, can.base.Max(top+height-layout.top, height*(max||0.5))) + can.page.style(can, target, html.MAX_HEIGHT, can.base.Max(max > 0.5 || layout.top > (top+height)*0.5? height: top+height-layout.top, height*(max||0.5))) if (layout.top+target.offsetHeight > top+height) { layout.top = top+height-target.offsetHeight } if (layout.left+target.offsetWidth > left+width) { layout.left = left+width-target.offsetWidth } }); return can.onmotion.move(can, target, layout), layout @@ -505,7 +515,7 @@ Volcanos(chat.ONMOTION, {_init: function(can, target) { }, }, auto: function(can, target) { var that = this; target = target||can._output - can.page.Select(can, target, wiki.STORY_ITEM, function(item) { var meta = item.dataset; can.page.style(can, item, can.base.Obj(meta.style)) + can.page.Select(can, target, wiki.STORY_ITEM, function(item) { var meta = item.dataset; meta.style && can.page.style(can, item, can.base.Obj(meta.style)) can.core.CallFunc(that._hash[meta.type]||that._hash[target.tagName], [can, meta, item]) }) can.page.Select(can, target, html.INPUT_BUTTON, function(target) { diff --git a/index.css b/index.css index 3f31fdee..f7d2e520 100644 --- a/index.css +++ b/index.css @@ -93,6 +93,7 @@ body>div.toast div.action { display:block; } body>div.carte { padding:0; } body>div.carte input[name=filter] { margin:5px; width:calc(100% - 10px); position:sticky; top:5px; } body>div.carte div.item { padding:5px 10px; } +body>div.carte div.item span.icon.gt { float:right; } body>div.input td { padding:5px; } body>div.input td span.icon { font-size:14px; margin-left:-25px; margin-right:10px; visibility:hidden; } body>div.input td:hover span.icon { visibility:visible; } @@ -102,7 +103,7 @@ body>div.input input:not([type=button]) { width:200px; } body>div.input div.action input[type=button] { width:90px; } body>div.input div.action div { margin:5px; float:right; } body>div.upload div.item { float:left; } -body>div.upload div.output { border:red solid 1px; } +body>div.upload div.output { border:red solid 1px; clear:both; } body>div.upload div.progress { background-color:red; height:10px; width:0; } body>div.upload div.status div.cost { float:left; } body>div.upload div.status div.show { float:right; } @@ -119,7 +120,7 @@ div.status>div.item>label { font-size:0.6rem; } form.option, div.action { display:contents; } form.option.hide, div.action.hide { display:none; } form.option>div.item>label, div.action>div.item>label, .hidden, .hide { display:none; } form.option>div.cmd, form.option>div.textarea { width:100%; } textarea { resize:vertical; } -legend, form.option, form.option>div.item, div.action, div.action>div.item, div.action>div.tabs, div.status>div.item, div.layout.flex>* { float:left; } +legend, form.option, form.option>div.item, div.action, div.action>div.item, div.action>div.tabs, fieldset>div.status>div.item, div.layout.flex>* { float:left; } div.action, div.output, div.status, div.project, div.display, div.profile, div.content, table.content, table.content td, div.code, div.plug, div.story, div.toast, div.carte, fieldset.input { overflow:auto; } fieldset>div.output, fieldset>div.status, div.item.textarea, div.project div.item, div.content:not(.item), div.code, div.story[data-type=spark] { clear:both; } fieldset>div.status>legend { margin-left:2px; margin-right:0; float:right; clear:none; } @@ -145,6 +146,10 @@ fieldset.story>form.option>div.icon { display:block; } fieldset.float>form.option>div.icon { display:block; } fieldset.full>form.option>div.icon { display:block; } fieldset.plug>form.option>div.icon { margin-left:5px; } +div.carte.select.float { border-radius:0; } +div.carte.select.float>div.item { text-align:center; } +div.item.select span { margin-left:-20px; margin-right:10px; } +div.item.select input { font-family:monospace; border-radius:0; } /* hover */ legend:hover { background-color:skyblue; } select:hover { background-color:gray; color:cyan; } @@ -160,6 +165,7 @@ body.black a { color:yellow; } body.black div.project div.zone>div.list>div.zone>div.item { background-color:#09466fc2; } body.white { background-color:rgba(5,34,56,0.75); color:white; } body.white select { background-color:yellowgreen; color:white; } +body.white div.item.select div { background-color:yellowgreen; color:white; float:right; height:31px; text-align:center; } body.white input { background-color:white; } body.white input[name=cmd] { background-color:black; color:white; } body.white input[type=button] { background-color:cornflowerblue; color:white; } @@ -267,6 +273,7 @@ fieldset.plugin.parse.cmd>div.status { display:none; } fieldset.plugin.inner.cmd>legend { display:none; } fieldset.plugin.inner.cmd>div.action { display:none; } fieldset.plugin.inner.cmd>form.option { display:none; } +fieldset.plan div.output table.content { width:100%; } fieldset.xterm div.toggle { display:none; } fieldset.draw td.content { position:relative; } fieldset.draw div.output div.content svg { background-color:#1b5b738c; } diff --git a/lib/base.js b/lib/base.js index 683370f6..70357a08 100644 --- a/lib/base.js +++ b/lib/base.js @@ -4,78 +4,72 @@ Volcanos("base", { Max: function(val, max) { return val < max? val: max }, Obj: function(val, def) { try { - if (typeof val == lang.STRING) { if (val == "") { return def } val = JSON.parse(val) } + if (typeof val == code.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 } + } catch (e) { return typeof val == code.STRING && val.split(ice.FS) || def } }, Copy: function(to, from, merge) { if (!from) { return to } - if (arguments.length == 2 || typeof merge == lang.BOOLEAN) { for (var k in from) { if (k == undefined) { continue } + if (arguments.length == 2 || typeof merge == code.BOOLEAN) { for (var k in from) { if (k == undefined) { continue } if (merge && to.hasOwnProperty(k) && to[k] != undefined && to[k] != "") { 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, skip) { var call = arguments.callee; if (typeof to != typeof from) { return false } - if (typeof to == lang.OBJECT) { if (to.length != from.length) { return false } + if (typeof to == code.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 (k != skip && !call(to[k], from[k])) { return false } } return true } return to === from }, - Dir: function(path) { return path.endsWith(ice.PS)? path: path.slice(0, path.lastIndexOf(ice.PS)+1) }, Ext: function(path) { return path.split(ice.PS).pop().split(ice.PT).pop().toLowerCase() }, - Path: function(path) { var res = "", arg = arguments - for (var i = 0; i < arguments.length; i++) { if (!arguments[i]) { continue } - res += (arguments[i][0]==ice.PS || res=="" || res[res.length-1]==ice.PS? "": ice.PS) + arguments[i].trim() - } return res + Dir: function(path) { return path.endsWith(ice.PS)? path: path.slice(0, path.lastIndexOf(ice.PS)+1) }, + Path: function(path) { var res = "", arg = arguments; for (var i = 0; i < arg.length; i++) { if (!arg[i]) { continue } + res += (arg[i][0]==ice.PS || res=="" || res[res.length-1]==ice.PS? "": ice.PS) + arg[i].trim() + } return res }, + Args: function() { var res = [], arg = arguments; function encode(k, v) { k && v != undefined && v != null && res.push(encodeURIComponent(k)+ice.EQ+encodeURIComponent(v)) } + for (var i = 0; i < arg.length; i += 2) { if (typeof arg[i] == code.OBJECT) { + if (arg[i].length > 0) { for (var j = 0; j < arg[i].length; j += 2) { encode(arg[i][j], arg[i][j+1]) } } else { for (var k in arg[i]) { encode(k, arg[i][k]) } } i-- + } else { encode(arg[i], arg[i+1]) } } return res.join("&") }, - Args: function() { var args = arguments, res = []; function encode(k, v) { k && v != undefined && res.push(encodeURIComponent(k)+ice.EQ+encodeURIComponent(v)) } - for (var i = 0; i < args.length; i += 2) { if (typeof args[i] == lang.OBJECT) { - if (args[i].length > 0) { for (var j = 0; j < args[i].length; j += 2) { encode(args[i][j], args[i][j+1]) } } else { for (var k in args[i]) { encode(k, args[i][k]) } } i-- - } else { encode(args[i], args[i+1]) } } return res.join("&") - }, - _parse: function(url, res) { var list = url.split("?"); res = res||{}, res["_origin"] = list[0] + _parse: function(url, res) { var list = url.split(ice.QS); 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: "") + MergeURL: function(url) { var arg = this._parse(url); delete(arg._origin); for (var i = 1; i < arguments.length; i += 2) { delete(arg[arguments[i]]) } + var arg = this.Args.apply(this, [arg].concat(Array.prototype.slice.call(arguments, 1))); return url.split(ice.QS)[0]+(arg? ice.QS+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 } + ParseJSON: function(str) { var res; if (typeof str == code.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 } 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() - if (size.endsWith("tb") || size.endsWith("t")) { return parseInt(size) * 1024 * 1024 * 1024 * 1024 } - if (size.endsWith("gb") || size.endsWith("g")) { return parseInt(size) * 1024 * 1024 * 1024 } - if (size.endsWith("mb") || size.endsWith("m")) { return parseInt(size) * 1024 * 1024 } - if (size.endsWith("kb") || size.endsWith("k")) { return parseInt(size) * 1024 } + if (size.endsWith("tb") || size.endsWith("t")) { return parseInt(size) * this._unit.t } + if (size.endsWith("gb") || size.endsWith("g")) { return parseInt(size) * this._unit.g } + if (size.endsWith("mb") || size.endsWith("m")) { return parseInt(size) * this._unit.m } + if (size.endsWith("kb") || size.endsWith("k")) { return parseInt(size) * this._unit.k } return parseInt(size) - }, - Size: function(size) { size = parseInt(size) - if (size > 1000000000) { return parseInt(size/1000000000) + ice.PT + parseInt(size/10000000%100) + "G" } - if (size > 1000000) { return parseInt(size/1000000) + ice.PT + parseInt(size/10000%100) + "M" } - if (size > 1000) { return parseInt(size/1000) + ice.PT + parseInt(size/10%100) + "K" } + }, _unit: {k: 1024, m: 1024*1024, g: 1024*1024*1024, t: 1024*1024*1024*1024}, + Size: function(size) { size = parseInt(size); var n = 100, k = this._unit.k, m = this._unit.m, g = this._unit.g, t = this._unit.t + if (size > t) { return parseInt(size/t) + ice.PT + parseInt(size/g%k*n/k) + "T" } + if (size > g) { return parseInt(size/g) + ice.PT + parseInt(size/m%k*n/k) + "G" } + if (size > m) { return parseInt(size/m) + ice.PT + parseInt(size/k%k*n/k) + "M" } + if (size > k) { return parseInt(size/k) + ice.PT + parseInt(size%k*n/k) + "K" } return size + "B" }, - Number: function(d, n) { var result = [] - while (d > 0) { result.push(d%10); d = parseInt(d/10); n-- } - while (n > 0) { result.push("0"); n-- } - return result.reverse(), result.join("") + Number: function(d, n) { var res = [] + while (d > 0) { res.push(d%10); d = parseInt(d/10); n-- } while (n > 0) { res.push("0"); n-- } + return res.reverse(), res.join("") }, Format: function(obj) { return JSON.stringify(obj) }, - Simple: function() { var res = [] - for (var i = 0; i < arguments.length; i++) { var val = arguments[i]; switch (typeof val) { - case lang.OBJECT: - if (val.length > 0) { res = res.concat(val); break } - for (var k in val) { k && val[k] && res.push(k, val[k]) } break - default: res.push(val) - } } return res - }, - AddUniq: function(list, value) { list = list||[]; return list.indexOf(value) == -1 && list.push(value), list }, - isIn: function(item) { var args = arguments; for (var i = 1; i < args.length; i++) { - if (typeof args[i] == lang.OBJECT && args[i].length > 0 && args[i].indexOf(item) > -1) { return true } - if (item == args[i]) { return true } + Simple: function() { var res = []; for (var i = 0; i < arguments.length; i++) { var val = arguments[i]; switch (typeof val) { + case code.OBJECT: if (val.length > 0) { res = res.concat(val); break } + for (var k in val) { k && val[k] && res.push(k, val[k]) } break + default: res.push(val) + } } return res }, + AddUniq: function(list, value) { list = list||[], list.indexOf(value) == -1 && list.push(value); return list }, + isIn: function(item) { var arg = arguments; for (var i = 1; i < arg.length; i++) { + if (typeof arg[i] == code.OBJECT && arg[i].length > 0 && arg[i].indexOf(item) > -1) { return true } + if (item == arg[i]) { return true } } }, Time: function(time, fmt) { var now = this.Date(time) fmt = fmt||"%y-%m-%d %H:%M:%S" @@ -89,12 +83,10 @@ Volcanos("base", { fmt = fmt.replace("%s", this.Number(now.getMilliseconds(), 3)) return fmt }, - Date: function(time) { var now = new Date() - if (typeof time == lang.STRING && time != "") { var ls = time.split(ice.SP) - var vs = ls[0].split("-"); now.setFullYear(parseInt(vs[0])), now.setMonth(parseInt(vs[1])-1), now.setDate(parseInt(vs[2])) - var vs = ls[1].split(ice.DF); now.setHours(parseInt(vs[0])), now.setMinutes(parseInt(vs[1])), now.setSeconds(parseInt(vs[2])) - } else if (time) { now = time } return now - }, + Date: function(time) { var now = new Date(); if (typeof time == code.STRING && time != "") { var ls = time.split(ice.SP) + var vs = ls[0].split("-"); now.setFullYear(parseInt(vs[0])), now.setMonth(parseInt(vs[1])-1), now.setDate(parseInt(vs[2])) + var vs = ls[1].split(ice.DF); now.setHours(parseInt(vs[0])), now.setMinutes(parseInt(vs[1])), now.setSeconds(parseInt(vs[2])) + } else if (time) { now = time } return now }, DateAdd: function(stamp, days) { return new Date(stamp - stamp%(24*3600*1000) - 8*3600*1000 + days*24*3600*1000) }, Duration: function(n) { var res = "", h = 0 h = parseInt(n/3600000/24), h > 0 && (res += h+"d"), n = n % (3600000*24) @@ -104,47 +96,38 @@ Volcanos("base", { return res + (n > 0? ice.PT+parseInt(n/10): "") + "s" }, isNight: function() { var now = new Date(); return now.getHours() < 7 || now.getHours() > 17 }, - isNumber: function(val) { return typeof val == lang.NUMBER }, - isString: function(val) { return typeof val == lang.STRING }, - isObject: function(val) { return typeof val == lang.OBJECT }, - isArray: function(val) { return typeof val == lang.OBJECT && val.length != undefined }, - isFunc: function(val) { return typeof val == lang.FUNCTION }, + isNumber: function(val) { return typeof val == code.NUMBER }, + isString: function(val) { return typeof val == code.STRING }, + isObject: function(val) { return typeof val == code.OBJECT }, + isArray: function(val) { return typeof val == code.OBJECT && val.length != undefined }, + isFunc: function(val) { return typeof val == code.FUNCTION }, isUndefined: function(val) { return val == undefined }, isNull: function(val) { return val == null }, - getValid: function() { - for (var i = 0; i < arguments.length; i++) { var v = arguments[i] - if (typeof v == lang.OBJECT) { if (v == null) { continue } - if (v.length > 0) { return v } for (var k in v) { return v } - } else if (typeof v == lang.STRING) { if (v == "") { continue } else { return v } - } else if (v == undefined) { continue } else { return v } - } - }, - replaceAll: function(str) { - for (var i = 1; i < arguments.length; i += 2) { if (!arguments[i]) { continue } - if (str.replaceAll) { str = str.replaceAll(arguments[i], arguments[i+1]); continue } - if (arguments[i] && str.replace) { while (str.indexOf(arguments[i]) > -1) { str = str.replace(arguments[i], arguments[i+1]) } } - } return str - }, - contains: function(str) { var arg = arguments - for (var i = 1; i < arg.length; i++) { if (!arg[i] || str.indexOf(arg[i]) > -1) { return true } } - }, - beginWith: function(str) { for (var i = 1; i < arguments.length; i++) { if (typeof str == lang.STRING && str.trim().indexOf(arguments[i]) == 0) { return true } } }, - endWith: function(str) { for (var i = 1; i < arguments.length; i++) { if (typeof str == lang.STRING && str.lastIndexOf(arguments[i]) + arguments[i].length == str.length) { return true } } }, - trimPrefix: function(str, pre) { if (typeof str != lang.STRING) { return str } var callee = arguments.callee + getValid: function() { for (var i = 0; i < arguments.length; i++) { var v = arguments[i] + if (typeof v == code.OBJECT) { if (v == null) { continue } + if (v.length > 0) { return v } for (var k in v) { return v } + } else if (typeof v == code.STRING) { if (v == "") { continue } else { return v } + } else if (v == undefined) { continue } else { return v } + } }, + replaceAll: function(str) { var arg = arguments; for (var i = 1; i < arg.length; i += 2) { if (!arg[i]) { continue } + if (str.replaceAll) { str = str.replaceAll(arg[i], arg[i+1]); continue } + if (arg[i] && str.replace) { while (str.indexOf(arg[i]) > -1) { str = str.replace(arg[i], arg[i+1]) } } + } return str }, + contains: function(str) { var arg = arguments; for (var i = 1; i < arg.length; i++) { if (!arg[i] || str.indexOf(arg[i]) > -1) { return true } } }, + beginWith: function(str) { for (var i = 1; i < arguments.length; i++) { if (typeof str == code.STRING && str.trim().indexOf(arguments[i]) == 0) { return true } } }, + endWith: function(str) { for (var i = 1; i < arguments.length; i++) { if (typeof str == code.STRING && str.lastIndexOf(arguments[i]) + arguments[i].length == str.length) { return true } } }, + trimPrefix: function(str, pre) { if (typeof str != code.STRING) { return str } var callee = arguments.callee if (arguments.length > 2) { for (var i = 1; i < arguments.length; i++) { str = callee(str, arguments[i]) } return str } if (str.indexOf(pre) == -1) { return str } return str.slice(pre.length) }, trimSuffix: function(str, end) { while (str) { var index = str.lastIndexOf(end) if (index == -1 || index+end.length != str.length) { break } str = str.slice(0, index) } return str }, - 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 + trim: function(arg) { if (this.isString(arg)) { return arg.trim() } + if (this.isArray(arg)) { for (var i = arg.length-1; i >= 0; i--) { if (!arg[i]) { arg.pop() } else { break } } } return arg }, - join: function(list, sp) { return typeof list == lang.STRING? list: (list||[]).join(sp||ice.SP) }, - joins: function(list, inner, outer) { for (var i = 0; i < list.length; i++) { list[i] = typeof list[i] == lang.STRING? list[i]: list[i].join(inner||ice.FS) } return list.join(outer||ice.SP) }, + join: function(list, sp) { return typeof list == code.STRING? list: (list||[]).join(sp||ice.SP) }, + joins: function(list, inner, outer) { for (var i = 0; i < list.length; i++) { list[i] = typeof list[i] == code.STRING? list[i]: list[i].join(inner||ice.FS) } return list.join(outer||ice.SP) }, joinKV: function(list, inner, outer) { var res = []; for (var i = 0; i < list.length-1; i += 2) { res.push(list[i]+(inner||": ")+list[i+1]) } return res.join(outer||ice.SP) }, - count: function(str, s) { var n = 0; for (var i = 0; i < str.length; i++) { if (str[i] == s) { n++ } } return n }, random: function(max, min) { return min = min||0, parseInt(Math.random()*(max-min))+min }, - mod: function(index, total) { return (index+total) % total }, }) diff --git a/lib/core.js b/lib/core.js index 2ede56d8..b7f14b7f 100644 --- a/lib/core.js +++ b/lib/core.js @@ -8,7 +8,7 @@ Volcanos("core", { } } return list.join(ice.PT) }, Value: function(data, key, value) { if (data == undefined) { return } if (key == undefined) { return data } - if (typeof key == lang.OBJECT && key.length != undefined) { key = key.join(ice.PT) } else 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) { if (key.length != undefined) { key = key.join(ice.PT) } else { for (var k in key) { arguments.callee.call(this, data, k, key[k]) } return data } } if (value != undefined) { var _node = data, keys = key.split(ice.PT) for (var i = 0; i < keys.length; i++) { var _next = _node[keys[i]]||{}; _node[keys[i]] = _next if (i < keys.length - 1) { _node = _next } else { _node[keys[i]] = value } @@ -58,19 +58,18 @@ Volcanos("core", { case ice.AT: res[ctx.ACTION] = ls[i+1]; break } } return res } }, - CallFunc: function(func, args, mod) { args = args||{}; var can = args["can"]||args[0], msg = args["msg"]||args[1] + CallFunc: function(func, args, mod) { args = args||{}; var can = args["can"]||args[0], msg = args["msg"]||args[1], cb = args["cb"] + if (Array.isArray(args)) { this.List(args, function(arg) { if (arg.request && arg.run) { can = arg } else if (arg.Append && arg.Result) { msg = arg } else if (typeof arg == code.FUNCTION) { cb = arg } }) } func = typeof func == lang.FUNCTION? func: typeof func == lang.OBJECT && func.length > 0? this.Value(func[0], this.Keys(func.slice(1))): typeof func == lang.STRING? this.Value(mod||can, func): null - if (typeof func != lang.FUNCTION) { if (typeof args["cb"] == lang.FUNCTION) { args["cb"]() } return } - var list = [], echo = false, cb = args["cb"]; args.length > 0? list = args: this.List(func.toString().split(")")[0].split("(")[1].split(ice.FS), function(item, index) { item = item.trim(); if (item == "") { return } + if (typeof func != lang.FUNCTION) { if (typeof cb == lang.FUNCTION) { cb() } return } + var list = [], echo = false; args.length > 0? list = args: this.List(func.toString().split(")")[0].split("(")[1].split(ice.FS), function(item, index) { item = item.trim(); if (item == "") { return } list.push(args[item] || msg&&msg.Option&&msg.Option(item) || can&&can.Conf&&can.Conf(item) || null); if (item == "cb") { echo = true } - }); var res = func.apply(mod||can, list); - if (msg && msg.Defer) { msg.Defer() } + }); var res = func.apply(mod||can, list); if (msg && msg.Defer) { msg.Defer() } if (!echo && typeof cb == lang.FUNCTION) { res && msg&&msg.Echo&&msg.Echo(res), arguments.callee.apply(this, [cb, {msg: msg, res: res}]) } return res }, List: function(list, cb, interval, cbs) { if (typeof list == lang.STRING) { list = [list] } else if (typeof list == lang.NUMBER) { // [end cb interval]|[begin end interval] - var begin = 0, end = list, step = typeof interval == lang.NUMBER? interval: 1; - if (typeof cb == lang.NUMBER) { begin = list, end = cb, cb = null } + var begin = 0, end = list, step = typeof interval == lang.NUMBER? interval: 1; if (typeof cb == lang.NUMBER) { begin = list, end = cb, cb = null } list = []; for (var i = begin; i < end; i += step) { list.push(i) } } list = list||[] if (interval > 0) { @@ -93,8 +92,7 @@ Volcanos("core", { for (var k in obj) { var res = typeof cb == lang.FUNCTION? cb(k, obj[k], list): k; res != undefined && list.push(res) } return list }, - ItemKeys: function(obj, cb) { var list = [] - var keys = []; for (var k in obj) { keys.push(k) } keys.sort() + ItemKeys: function(obj, cb) { var list = [], keys = []; for (var k in obj) { keys.push(k) } keys.sort() for (var i in keys) { var k = keys[i]; var res = typeof cb == lang.FUNCTION? cb(k, obj[k]): k; res != undefined && list.push(res) } return list }, diff --git a/lib/misc.js b/lib/misc.js index d1d2960e..5bbe955f 100644 --- a/lib/misc.js +++ b/lib/misc.js @@ -1,127 +1,72 @@ -Volcanos("misc", {Message: function(event, can) { var msg = {} - var proto = {_event: event, _can: can, _target: can._target, - RunAction: function(event, sub, cmds, meta) { var msg = can.request(event); meta = meta || sub&&sub.onaction || {} - if (msg.Option(ice.MSG_HANDLE) == ice.TRUE) { return } - if (cmds && cmds[0] == ctx.ACTION && can.base.isFunc(meta[cmds[1]])) { msg.Option(ice.MSG_HANDLE, ice.TRUE) - return can.core.CallFunc(meta[cmds[1]], {event: event._event||event, can: sub, msg: msg, button: cmds[1], cmd: cmds[1]}), true - } return false - }, - Display: function(file) { msg.Option(ice.MSG_DISPLAY, file) }, - DisplayStory: function(file) { msg.Option(ice.MSG_DISPLAY, chat.PLUGIN_STORY+file) }, - OptionStatus: function() { return msg.Option(ice.MSG_STATUS) }, - OptionProcess: function() { return msg.Option(ice.MSG_PROCESS) }, - SearchOrOption: function(key) { return can.misc.Search(can, key)||msg.Option(key) }, - StatusTimeCount: function(obj) { msg.append && msg.Status(can.base.Copy(kit.Dict(mdb.TIME, can.base.Time(), mdb.COUNT, msg.Length()+"x"+msg.append.length), obj)) }, - Status: function(obj) { msg.Option(ice.MSG_STATUS, JSON.stringify(can.core.Item(obj, function(key, value) { return {name: key, value: value} }))) }, - - OptionDefault(key, val) { var arg = arguments - for (var i = 0; i < arg.length; i += 2) { msg.Option(arg[i]) || msg.Option(arg[i], arg[i+1]) } - return msg.Option(key) || msg.Option(key, val) - }, - Option: function(key, val) { - if (key == undefined) { return msg && msg.option || [] } - if (can.base.isObject(key)) { can.core.Item(key, msg.Option) } - if (val == undefined) { return msg && msg[key] && msg.option && msg.option.indexOf(key) > -1 && msg[key][0] || "" } - return msg.option = can.base.AddUniq(msg.option, key), msg[key] = can.core.List(arguments).slice(1), val - }, - Append: function(key, val) { - if (key == undefined) { return msg && msg.append || [] } - if (can.base.isObject(key)) { can.core.Item(key, msg.Append) } - if (val == undefined) { return msg && msg[key] && msg[key][0] || "" } - return msg.append = can.base.AddUniq(msg.append, key), msg[key] = can.core.List(arguments).slice(1), val - }, - Result: function() { - if (msg.result && msg.result[0] == ice.ErrWarn) { return msg.result.join(ice.SP) } - return msg.result && msg.result.join("") || "" - }, - Results: function() { return msg.result && msg.result[0] == ice.ErrWarn? "": msg.Result() }, - TableDetail: function() { var item = can.Option() - return msg.Table(function(value) { can.core.Value(item, value.key, value.value) }), item - }, - Table: function(cb) { - return can.core.List(msg.Length(), function(index) { var value = {} - can.core.List(msg.append, function(k) { value[k] = msg[k]&&msg[k][index]||"" }) - return can.base.isFunc(cb)? cb(value, index): value - }) - }, - Length: function() { - var max = 0; can.core.List(msg.append, function(k) { if (msg[k] && msg[k].length > max) { max = msg[k].length } }); return max - }, - Clear: function(key) { switch (key||ice.MSG_APPEND) { - case ice.MSG_APPEND: - case ice.MSG_OPTION: - can.core.List(msg[key], function(key) { delete(msg[key]) }) - default: delete(msg[key]) - } }, - Copy: function(res) { if (!res) { return msg } - res.append && (msg.append = res.append) && res.append.forEach(function(item) { - var i = msg.option && msg.option.indexOf(item); if (i > -1) { msg.option[i] = "", delete(msg[item]) } - res[item] && (msg[item] = (msg[item]||[]).concat(res[item])) - }), res.result && (msg.result = (msg.result||[]).concat(res.result)) - res.option && (msg.option = res.option) && res.option.forEach(function(item) { res[item] && (msg[item] = res[item]) }) - res._option && (msg._option = res._option) && res._option.forEach(function(item) { res[item] && (msg[item] = res[item]) }) - return msg - }, - Push: function(key, value, detail) { - if (can.base.isObject(key)) { - can.core.List(value||can.base.Obj(msg.Option(ice.MSG_FIELDS))||can.core.Item(key), function(item) { - detail? msg.Push(mdb.KEY, item).Push(mdb.VALUE, key[item]||""): msg.Push(item, key[item]||"") - }); return msg - } msg.append = can.base.AddUniq(msg.append, key), msg[key] = msg[key]||[] - var i = msg.option && msg.option.indexOf(key); if (i > -1) { msg.option[i] = "", msg[key] = [] } - msg[key].push(can.base.isString(value)||can.base.isFunc(value)? value: JSON.stringify(value)) - return msg - }, - PushAction: function(button) { can.core.List(msg.Length(), function() { - msg.Push(ctx.ACTION, can.page.Format(html.INPUT, "", mdb.TYPE, html.BUTTON, mdb.NAME, button, mdb.VALUE, can.user.trans(can, button))) - }); return msg }, - Echo: function(res) { msg.result = msg.result||[] - for (var i = 0; i < arguments.length; i++) { msg.result.push(arguments[i]) } - return msg._hand = true, msg - }, - Dump: function(can) { - can.onmotion.clear(can) - can.onappend.table(can, msg) - can.onappend.board(can, msg) - can.onmotion.story.auto(can) - }, - _caller: function(skip) { - msg.Option("log.caller") || msg.Option("log.caller", can.misc.fileLine((skip||2)+1).link) - return msg - }, - _callers: function(skip) { - msg.Option("log.caller") || msg.Option("log.caller", can.misc._fileLine((skip||2)+1).link) - return msg - }, - Defer: function(cb) { msg._defer = msg._defer||[] - if (arguments.length == 0) { msg._defer = can.core.List(msg._defer.reverse(), function(cb) { can.base.isFunc(cb) && cb() }) } else { msg._defer.push(cb) } - }, _defer: [], - }; return kit.proto(msg, proto) - }, - concat: function(can, to, from) { to = to||[], from = from||[] - if (arguments.length > 3) { for (var i = 2; i < arguments.length; i++) { to = can.misc.concat(can, to, arguments[i]) } return to } - if (from[0] == ctx.ACTION && from[1] == ice.RUN && can.onengine.plugin(can, from[2])) { return from } - if (can.onengine.plugin(can, from[0])) { return from } - if (from[0] == "_search") { return from } - return to.concat(from) - }, - runAction: function(can, msg, cmds, cb, meta) { - if (cmds[0] == ctx.ACTION && meta[cmds[1]]) { return meta[cmds[1]](cmds.slice(2)), true } - if (meta[cmds[0]]) { return meta[cmds[0]](cmds.slice(1)), true } - }, - Event: function(event, can, cb) { - for (var i = 3; i < arguments.length; i++) { can.request(event, arguments[i]) } - cb(can.request(event)) - }, - Run: function(event, can, dataset, cmds, cb) { var msg = can.request(event) - var form = {}; msg.option && msg.option.forEach(function(key) { - if ([ice.MSG_HANDLE, ice.MSG_DAEMON].indexOf(key) > -1) { return } - if (can.base.isObject(msg.Option(key))) { return } - if (can.base.isFunc(msg.Option(key))) { return } - msg[key] && (form[key] = msg[key]) - }), form.cmds = cmds||form.cmds; var _can = msg._can._outputs? msg._can: msg._can.sup||msg._can - can.misc.POST(can, msg, can.base.MergeURL(dataset.names.toLowerCase(), - "_name", _can._name, "_index", _can._index, ice.MSG_DAEMON, dataset.daemon), form, cb) +Volcanos("misc", { + Message: function(event, can) { var msg = kit.proto({}, {_event: event, _can: can, _target: can._target, + RunAction: function(event, sub, cmds, meta) { var msg = can.request(event); meta = meta || sub&&sub.onaction || {} + if (msg.Option(ice.MSG_HANDLE) != ice.TRUE && cmds && cmds[0] == ctx.ACTION && can.base.isFunc(meta[cmds[1]])) { msg.Option(ice.MSG_HANDLE, ice.TRUE) + return can.core.CallFunc(meta[cmds[1]], {event: event._event||event, can: sub, msg: msg, button: cmds[1], cmd: cmds[1]}), true + } + }, + Display: function(file) { return msg.Option(ice.MSG_DISPLAY, file) }, + DisplayStory: function(file) { return msg.Option(ice.MSG_DISPLAY, chat.PLUGIN_STORY+file) }, + SearchOrOption: function(key) { return can.misc.Search(can, key)||msg.Option(key) }, + OptionProcess: function() { return msg.Option(ice.MSG_PROCESS) }, + OptionStatus: function() { return msg.Option(ice.MSG_STATUS) }, + StatusTimeCount: function(obj) { msg.append && msg.Status(can.base.Copy(kit.Dict(mdb.TIME, can.base.Time(), mdb.COUNT, msg.Length()+"x"+msg.append.length), obj)) }, + Status: function(obj) { return msg.Option(ice.MSG_STATUS, JSON.stringify(can.core.Item(obj, function(key, value) { return {name: key, value: value} }))) }, + OptionDefault(key, val) { var arg = arguments; for (var i = 0; i < arg.length; i += 2) { msg.Option(arg[i]) || msg.Option(arg[i], arg[i+1]) } return msg.Option(key) }, + Option: function(key, val) { if (key == undefined) { return msg.option || [] } + if (can.base.isObject(key)) { return can.core.Item(key, msg.Option) } + if (val == undefined) { return can.base.isIn(key, msg.option) && msg[key] && msg[key][0] || "" } + return msg.option = can.base.AddUniq(msg.option, key), msg[key] = can.core.List(arguments).slice(1), val + }, + Append: function(key, val) { if (key == undefined) { return msg.append || [] } + if (can.base.isObject(key)) { return can.core.Item(key, msg.Append) } + if (val == undefined) { return can.base.isIn(key, msg.append) && msg[key] && msg[key][0] || "" } + return msg.append = can.base.AddUniq(msg.append, key), msg[key] = can.core.List(arguments).slice(1), val + }, + Result: function() { if (!msg.result) { return } return msg.result[0] == ice.ErrWarn? msg.result.join(ice.SP): msg.result.join("") }, + Results: function() { return msg.result && msg.result[0] == ice.ErrWarn? "": msg.Result() }, + TableDetail: function() { var item = can.Option(); return msg.Table(function(value) { can.core.Value(item, value.key, value.value) }), item }, + Table: function(cb) { return can.core.List(msg.Length(), function(index) { var item = {} + can.core.List(msg.append, function(k) { item[k] = msg[k]&&msg[k][index]||"" }) + return can.base.isFunc(cb)? cb(item, index): item + }) }, + Length: function() { var max = 0; can.core.List(msg.append, function(k) { if (msg[k] && msg[k].length > max) { max = msg[k].length } }); return max }, + Clear: function(key) { switch (key||ice.MSG_APPEND) { + case ice.MSG_OPTION: + case ice.MSG_APPEND: can.core.List(msg[key], function(key) { delete(msg[key]) }) + default: delete(msg[key]) + } }, + Copy: function(res) { if (!res) { return msg } + res.append && (msg.append = res.append) && res.append.forEach(function(key) { + var i = msg.option && msg.option.indexOf(key); if (i > -1) { msg.option[i] = "", delete(msg[key]) } + res[key] && (msg[key] = (msg[key]||[]).concat(res[key])) + }), res.result && (msg.result = (msg.result||[]).concat(res.result)) + res.option && (msg.option = res.option) && res.option.forEach(function(key) { res[key] && (msg[key] = res[key]) }) + res._option && (msg._option = res._option) && res._option.forEach(function(key) { res[key] && (msg[key] = res[key]) }) + return msg + }, + Push: function(key, value, detail) { + if (can.base.isObject(key)) { can.core.List(value||msg.append||can.base.Obj(msg.Option(ice.MSG_FIELDS))||can.core.Item(key), function(item) { + detail? msg.Push(mdb.KEY, item).Push(mdb.VALUE, key[item]||""): msg.Push(item, key[item]||"") + }); return msg } + var i = msg.option && msg.option.indexOf(key); if (i > -1) { msg.option[i] = "", msg[key] = [] } + msg.append = can.base.AddUniq(msg.append, key), msg[key] = msg[key]||[] + msg[key].push(can.base.isString(value)||can.base.isFunc(value)? value: JSON.stringify(value)); return msg + }, + PushAction: function(button) { can.core.List(msg.Length(), function() { + msg.Push(ctx.ACTION, can.page.Format(html.INPUT, "", mdb.TYPE, html.BUTTON, mdb.NAME, button, mdb.VALUE, can.user.trans(can, button))) + }); return msg }, + Echo: function(res) { msg.result = (msg.result||[]).concat(can.core.List(arguments)); return msg._hand = true, msg }, + Dump: function(can) { can = can||msg._can, can.onmotion.clear(can), can.onappend.table(can, msg), can.onappend.board(can, msg), can.onmotion.story.auto(can) }, + Defer: function(cb) { msg._defer = msg._defer||[] + if (arguments.length == 0) { msg._defer = can.core.List(msg._defer.reverse(), function(cb) { can.base.isFunc(cb) && cb() }) } else { msg._defer.push(cb) } + }, + _caller: function(skip) { msg.Option("log.caller") || msg.Option("log.caller", can.misc.fileLine((skip||2)+1).link); return msg }, + }); return msg }, + Event: function(event, can, cb) { for (var i = 3; i < arguments.length; i++) { can.request(event, arguments[i]) } cb(can.request(event)) }, + Run: function(event, can, dataset, cmds, cb) { var msg = can.request(event), _can = msg._can; _can._fields && _can.sup && (_can = _can.sup) + var form = {cmds: cmds}; can.core.List(msg.option, function(key) { msg[key] && (form[key] = msg[key]) }) + can.misc.POST(can, msg, can.base.MergeURL(dataset.names.toLowerCase(), "_name", _can._name, "_index", _can._index), form, cb) }, POST: function(can, msg, url, form, cb) { var xhr = new XMLHttpRequest(), begin = new Date(); msg._xhr = xhr xhr.open(msg._method||web.POST, url), xhr.onreadystatechange = function() { if (xhr.readyState != 4) { return } @@ -129,28 +74,19 @@ Volcanos("misc", {Message: function(event, can) { var msg = {} if (xhr.status == 200) { return msg.detail || (msg.detail = res.detail), can.base.isFunc(cb) && cb(msg.Copy(res)) } can.user.toastFailure(can, xhr.response), can.misc.Warn(xhr.status, res, url, form) }, xhr.setRequestHeader(web.Accept, msg._accept||web.ContentJSON) - if (msg._upload) { - var data = new FormData(); can.core.ItemForm(form, function(v, i, k) { data.append(k, v) }) + if (msg._upload) { var data = new FormData(); can.core.ItemForm(form, function(v, i, k) { data.append(k, v) }) data.append(ice.MSG_UPLOAD, web.UPLOAD), data.append(web.UPLOAD, msg._upload) xhr.upload.onprogress = function(event) { can.base.isFunc(msg._progress) && msg._progress(event, parseInt(event.loaded*100/event.total), event.total, event.loaded) } - } else if (can.user.isMailMaster) { - var data = can.core.ItemForm(form, function(value, index, key) { return key+ice.EQ+encodeURIComponent(value) }).join("&") - if (data) { xhr.open(msg._method||web.POST, url += (url.indexOf(url, "?") == -1? "?": "&")+data) } - } else { - var data = can.core.ItemForm(form, function(v, i, k) { return k+ice.EQ+encodeURIComponent(v) }).join("&") + } else if (can.user.isMailMaster) { var data = can.core.ItemForm(form, function(value, index, key) { return key+ice.EQ+encodeURIComponent(value) }).join("&") + if (data) { xhr.open(msg._method||web.POST, url += (url.indexOf(url, ice.QS) == -1? ice.QS: "&")+data) } + } else { var data = can.core.ItemForm(form, function(v, i, k) { return k+ice.EQ+encodeURIComponent(v) }).join("&") xhr.setRequestHeader(web.ContentType, web.ContentFORM) } try { xhr.send(data) } catch(e) { can.misc.Warn(e) } }, - GET: function(can, url, cb) { var xhr = new XMLHttpRequest() - xhr.open(msg._method||web.GET, url), xhr.onreadystatechange = function() { if (xhr.readyState != 4) { return } - if (xhr.status == 200) { return can.base.isFunc(cb) && cb(xhr.responseText) } can.misc.Warn(xhr.status, res, url, form) - }; try { xhr.send() } catch(e) { can.misc.Warn(e) } - }, WSS: function(can, args, cb, onopen, onclose, onerror, _msg) { if (can.user.isIE) { return } var url = location.protocol.replace(ice.HTTP, "ws")+"//"+location.host+"/space/" if (url.indexOf(html.CHROME) == 0) { url = "ws://localhost:9020/space/" } - var socket = new WebSocket(can.base.MergeURL(url, args)) - _msg = _msg || can.request()._caller() + var socket = new WebSocket(can.base.MergeURL(url, args)); _msg = _msg || can.request()._caller() socket.onclose = function() { can.misc.Log(html.WSS, cli.CLOSE, args) can.base.isFunc(onclose)? onclose(socket): can.core.Timer(can.base.random(3000, 100), function() { args.name = args.name||can._wss_name, can.misc.WSS(can, args, cb, onopen, onerror, onclose, _msg) @@ -167,62 +103,44 @@ Volcanos("misc", {Message: function(event, can) { var msg = {} res.Option(ice.LOG_DISABLE, msg.Option(ice.LOG_DISABLE)) != ice.TRUE && can.misc.Log(html.WSS, ice.MSG_RESULT, msg.result&&msg.result.length>0? msg.result: undefined, msg, _msg) socket.send(JSON.stringify(res)) }, msg.detail = data.detail, msg.Copy(data) - try { - msg.Option(ice.LOG_DISABLE) != ice.TRUE && can.misc.Log(html.WSS, ice.MSG_DETAIL, msg.detail, msg, _msg) + try { msg.Option(ice.LOG_DISABLE) != ice.TRUE && can.misc.Log(html.WSS, ice.MSG_DETAIL, msg.detail, msg, _msg) can.core.CallFunc(cb, {event: event, msg: msg, cmd: msg.detail[0], arg: msg.detail.slice(1), cb: function() { msg.Reply() }}) } catch (e) { can.misc.Warn(e), msg.Reply() } }) } }, MergePath: function(can, file, path) { return file.indexOf(ice.PS) == 0 || file.indexOf(ice.HTTP) == 0? file: can.base.Path(path, file) }, MergeCache: function(can, hash) { return can.misc.MergeURL(can, {_path: can.base.Path(web.SHARE_CACHE, hash)}, true) }, - MergePodCmd: function(can, objs) { - objs.pod = can.core.Keys(can.misc.Search(can, ice.POD), objs.pod) - objs.theme = objs.theme||can.misc.Search(can, chat.THEME) - return can.misc.MergeURL(can, objs, true) - }, - MergeURL: function(can, objs, clear) { var pod = "" - var path = location.pathname; objs._path && (path = objs._path), delete(objs._path) - objs.pod && (path = can.base.Path("/chat/pod/", objs.pod)), delete(objs.pod) - var ls = path.split(ice.PS); ls[1] == "chat" && ls[2] == ice.POD && (pod = ls[3]) - objs.cmd && (path = can.base.Path("/chat", pod? "pod/"+pod: "", ice.CMD, objs.cmd)), delete(objs.cmd) - objs.website && (path = can.base.Path("/chat", pod? "pod/"+pod: "", web.WEBSITE, objs.website)), delete(objs.website) + MergePodCmd: function(can, obj) { obj.pod = can.core.Keys(can.misc.Search(can, ice.POD), obj.pod); return can.misc.MergeURL(can, obj, true) }, + MergeURL: function(can, obj, clear) { var path = location.pathname; obj._path && (path = obj._path), delete(obj._path) + var args = [web.CHAT]; can.core.List([ice.POD, ice.CMD, web.WEBSITE], function(key) { obj[key] && args.push(key, obj[key]), delete(obj[key]) }) var _location = location; if (can.user.isExtension) { var _location = new URL(Volcanos.meta.iceberg) } - return can.base.MergeURL(_location.origin+path+(clear?"":_location.search), objs) + return can.base.MergeURL(_location.origin+(args.length == 1? path: ice.PS+args.join(ice.PS))+(clear? "": _location.search), obj) }, - ParseURL: function(can, url) { var _url = can.base.ParseURL(url) - var _ls = (_url._origin.split("/chat/")[1]||"").split(ice.PS) - for (var i = 0; i < _ls.length; i += 2) { _url[_ls[i]] = _ls[i+1] } - return _url + ParseURL: function(can, url) { var args = can.base.ParseURL(url), _location = new URL(url) + var ls = can.core.Split(_location.pathname, ice.PS); if (ls[0] == chat.SHARE) { args[chat.SHARE] = ls[1] } + for (var i = 1; i < ls.length; i += 2) { if (can.base.isIn(ls[i], [ice.POD, ice.CMD, web.WEBSITE])) { args[ls[i]] = ls[i+1] } } + return args }, - SearchOrConf: function(can, key, def) { - return can.misc.Search(can, key)||Volcanos.meta.args[key]||can.misc.localStorage(can, "can."+key)||can.Conf(key)||def - }, - SearchHash: function(can) { if (!can.isCmdMode()) { return [] } - if (arguments.length > 1) { location.hash = encodeURIComponent(can.core.List(arguments).slice(1).join(ice.FS)) } - return can.core.Split(decodeURIComponent(location.hash.slice(1)), ":,")||[] - }, - Search: function(can, key, value) { var args = {} - if (value == undefined && can.base.isString(key)) { var ls = can.core.Split(location.pathname, ice.PS); if (ls[0] == chat.SHARE) { args[chat.SHARE] = ls[1] } - for (var i = 1; i < ls.length; i += 2) { if (kit.Dict(ice.POD, true, ice.CMD, true, web.WEBSITE, true)[ls[i]]) { args[ls[i]] = ls[i+1] } } - } location.search && location.search.slice(1).split("&").forEach(function(item) { var ls = item.split(ice.EQ); ls[1] != "" && (args[decodeURIComponent(ls[0])] = decodeURIComponent(ls[1])) }) + Search: function(can, key, value) { var args = this.ParseURL(can, location.href) if (can.base.isUndefined(key)) { return args } else if (can.base.isObject(key)) { can.core.Item(key, function(k, v) { args[k] === ""? delete(args[k]): (args[k] = v) }) } else if (can.base.isUndefined(value)) { return args[key] } else { value === ""? delete(args[key]): (args[key] = value) - } - var search = can.base.Args(args); return search? location.search = search: location.href = location.pathname + } var search = can.base.Args(args); return location.search = search }, - CookieSessid: function(can, value, path) { - return can.misc.Cookie(can, ice.MSG_SESSID+"_"+(location.port||(location.protocol == "https:"? "443": "80")), value, path) + SearchHash: function(can) { if (!can.isCmdMode()) { return [] } + if (arguments.length > 1) { location.hash = encodeURIComponent(can.core.List(arguments).slice(1).join(ice.DF)) } + return can.core.Split(decodeURIComponent(location.hash.slice(1)), ice.DF)||[] }, + SearchOrConf: function(can, key, def) { return can.misc.Search(can, key)||Volcanos.meta.args[key]||can.misc.localStorage(can, "can."+key)||can.Conf(key)||def }, + CookieSessid: function(can, value, path) { return can.misc.Cookie(can, ice.MSG_SESSID+"_"+(location.port||(location.protocol == "https:"? "443": "80")), value, path) }, Cookie: function(can, key, value, path) { function set(k, v) { document.cookie = k+ice.EQ+v+";path="+(path||ice.PS) } if (can.base.isObject(key)) { for (var k in key) { set(k, key[k]) } key = undefined } if (can.base.isUndefined(key)) { var cs = {}; if (!document.cookie) { return } return document.cookie.split("; ").forEach(function(item) { var ls = item.split(ice.EQ); cs[ls[0]] = ls[1] }), cs } - if (value === "") { var expires = new Date(); expires.setTime(expires.getTime() - 10); + if (value === "") { var expires = new Date(); expires.setTime(expires.getTime() - 10) return document.cookie = key+ice.EQ+value+";path="+(path||ice.PS)+";expires=" + expires.toGMTString(); } can.base.isUndefined(value) || set(key, value) - var val = (new RegExp(key+"=([^;]*);?")).exec(document.cookie) - return val && val.length > 1? val[1]: "" + var val = (new RegExp(key+"=([^;]*);?")).exec(document.cookie); return val && val.length > 1? val[1]: "" }, localStorage: function(can, key, value) { if (can.base.isUndefined(key)) { var res = {}; can.core.Item(localStorage, function(name, value) { can.base.isFunc(value) || name == "length" || (res[name] = value) }); return res } @@ -232,59 +150,25 @@ Volcanos("misc", {Message: function(event, can) { var msg = {} if (can.base.isUndefined(key)) { var res = {}; can.core.Item(sessionStorage, function(name, value) { can.base.isFunc(value) || name == "length" || (res[name] = value) }); return res } if (!can.base.isUndefined(value)) { if (value === "") { return sessionStorage.removeItem(key) } sessionStorage.setItem(key, value) } return sessionStorage.getItem(key) }, - _signal: function(args) { - this._list.push(args) - }, _list: [], - Log: function() { var pos = arguments[0] && arguments[0].indexOf && arguments[0].indexOf("on") == 0? arguments[0] == "onremote"? 5: 3: 2 - var args = [this._time(), this.fileLine(pos).link] - for (var i in arguments) { var arg = arguments[i]; if (!arg) { continue } args.push(arg) - if (arg.Option && arg.Option("log.caller")) { args[1] = arg.Option("log.caller") } - } + Log: function() { var args = this._args("", arguments) + if (arguments[0].indexOf && arguments[0].indexOf("on") == 0) { args[1] = this.FileLine((arguments[0] == "onremote"? 4: 2)+this._skip) } + for (var i in arguments) { var arg = arguments[i]; if (arg && arg.Option && arg.Option("log.caller")) { args[1] = arg.Option("log.caller") } } console.log.apply(console, args), this._signal(args) }, - Info: function() { var args = [this._time(), this.FileLine(2, 3), log.INFO] - for (var i in arguments) { arguments[i] != undefined && args.push(arguments[i]) } - console.info.apply(console, args), this._signal(args) - }, - Warn: function() { var args = [this._time(), this.fileLine(2, 3).link, log.WARN] - for (var i in arguments) { arguments[i] != undefined && args.push(arguments[i]) } - console.warn.apply(console, args), this._signal(args) - debugger - }, - Error: function() { var args = [this._time(), this.fileLine(2, 3).link, log.ERROR] - for (var i in arguments) { arguments[i] != undefined && args.push(arguments[i]) } - args.push(ice.NL, this._stacks().slice(1).join(ice.NL)) - console.error.apply(console, args), this._signal(args) - debugger - }, - Debug: function() { var args = [this._time(), this.fileLine(2, 3).link, log.DEBUG] - for (var i in arguments) { arguments[i] != undefined && args.push(arguments[i]) } - args.push(ice.NL, this._stacks().slice(1, 4).join(ice.NL)) - console.debug.apply(console, args), this._signal(args) - }, - Trace: function() { var filter = "", output = false - var args = [this._time(), this.fileLine(2, 3).link, log.TRACE] - for (var i in arguments) { var arg = arguments[i]; if (!arg) { continue } args.push(arg) - if (arg.Option && arg.Option("log.trace") == ice.TRUE) { output = true } - if (arg.Conf && arg.Conf("log.trace") == ice.TRUE) { output = true } - } if (!output) { return } - args.push(ice.NL, this._stacks().slice(1, 4).join(ice.NL)) - console.debug.apply(console, args), this._signal(args) - debugger + Info: function() { var args = this._args(log.INFO, arguments); console.info.apply(console, args), this._signal(args) }, + Warn: function() { var args = this._args(log.WARN, arguments); console.warn.apply(console, args), this._signal(args); debugger }, + Error: function() { var args = this._args(log.ERROR, arguments); args.push(ice.NL, this._stacks().slice(1).join(ice.NL)), console.error.apply(console, args), this._signal(args); debugger }, + Debug: function() { var args = this._args(log.DEBUG, arguments); args.push(ice.NL, this._stacks().slice(1, 4).join(ice.NL)), console.debug.apply(console, args), this._signal(args) }, + Trace: function() { var output = false + for (var i in arguments) { var arg = arguments[i]; if (arg.Conf && arg.Conf("log.trace") == ice.TRUE || arg.Option && arg.Option("log.trace") == ice.TRUE) { output = true } } if (!output) { return } + var args = this._args(log.TRACE, arguments); args.push(ice.NL, this._stacks().slice(1, 4).join(ice.NL)), console.debug.apply(console, args), this._signal(args) }, FileLine: function(depth, length) { var file = this.fileLine(depth+1, length||9); return file.link }, - _fileLine: function(depth, length) { - var file = this.fileLine(depth+1, length||9) - for (var i = depth+1; i < 10; i++) { - var _file = this.fileLine(i+1, length||9) - if (_file && _file.path && _file.link != file.link && !_file.path.indexOf("/lib/") == 0) { return _file } - } - return file - }, fileLine: function(depth, length) { var list = this._stacks() function split(i) { if (!list[i]) { return {} } var ls = /(https*:\/\/[^/]+)*([^:]+):([0-9]+):([0-9]+)/.exec(list[i]) var name = ""; list[i].lastIndexOf(ice.TB) > 0 && (name = list[i].split(ice.TB).pop()) + if (ls[0].indexOf(ice.QS) > -1) { ls[0] = ls[0].split(ice.QS)[0]+ice.DF+ls[3]+ice.DF+ls[4] } return {name: name, link: ls[0], path: ls[2], file: ls[2].split(ice.PS).slice(-length).join(ice.PS), line: ls[3], cols: ls[4]} } if (depth < 0) { var current = split(-depth) @@ -304,4 +188,8 @@ Volcanos("misc", {Message: function(event, can) { var msg = {} var mill = now.getMilliseconds(); mill < 10 && (mill = "00"+mill) || mill < 100 && (mill = "0"+mill) return [hour, minute, second].join(ice.DF)+ice.PT+mill }, + _args: function(level, arg) { var args = [this._time(), this.FileLine(this._skip+1, 3)].concat(level? [level]: []) + for (var i in arg) { arg[i] != undefined && args.push(arg[i]) } return args + }, + _signal: function(args) { this._list.push(args) }, _list: [], _skip: navigator.userAgent.indexOf("Chrome") > -1? 1: 0, }) diff --git a/lib/page.js b/lib/page.js index 84e7b237..91eb06c2 100644 --- a/lib/page.js +++ b/lib/page.js @@ -1,37 +1,33 @@ -Volcanos("page", {ClassList: { - has: function(can, obj, key) { var list = obj.className? obj.className.split(ice.SP): []; return list.indexOf(key) > -1 }, - add: function(can, obj, key) { typeof key == lang.OBJECT && (key = key.join(ice.SP)) - var list = obj.className? obj.className.split(ice.SP): [], value = can.base.AddUniq(list, key).join(ice.SP).trim() - return value != obj.className && (obj.className = value), value +Volcanos("page", { + ClassList: { + has: function(can, target, key) { var list = target.className? target.className.split(ice.SP): []; return list.indexOf(key) > -1 }, + add: function(can, target, key) { Array.isArray(key) && (key = key.join(ice.SP)) + var list = target.className? target.className.split(ice.SP): []; can.core.List(can.core.Split(key), function(key) { can.base.AddUniq(list, key) }) + var value = list.join(ice.SP).trim(); return value != target.className && (target.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() + del: function(can, target, key) { var list = target.className? target.className.split(ice.SP): [] + return target.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 }, - neg: function(can, obj, key) { return (this.has(can, obj, key)? this.del(can, obj, key): this.add(can, obj, key)).indexOf(key) > -1 }, + set: function(can, target, key, condition) { return (condition? this.add(can, target, key): this.del(can, target, key)).indexOf(key) > -1 }, + neg: function(can, target, key) { return (this.has(can, target, key)? this.del(can, target, key): this.add(can, target, key)).indexOf(key) > -1 }, }, - SelectArgs: function(can, option, key, cb) { - if (can.base.isUndefined(option)) { return can.page.SelectArgs(can, can._option, "").concat(can.page.SelectArgs(can, can._action, "")) } - if (can.base.isUndefined(key)) { var value = {}; can.page.SelectArgs(can, option, "", function(item) { item.name && item.value && (value[item.name] = item.value) }); return [value] } - if (can.base.isObject(key)) { return can.core.Item(key, function(key, value) { can.page.SelectArgs(can, option, key, value) }), [key] } - if (!can.base.isFunc(cb)) { var value = cb; cb = function(item) { if (item.type == html.BUTTON) { return } return item.name && (can.base.isUndefined(value)? item.value: (item.value = value))||"" } } + SelectArgs: function(can, target, key, cb) { + if (can.base.isUndefined(target)) { return can.page.SelectArgs(can, can._option, "").concat(can.page.SelectArgs(can, can._action, "")) } + if (can.base.isUndefined(key)) { var value = {}; can.page.SelectArgs(can, target, "", function(item) { item.name && item.value && (value[item.name] = item.value) }); return [value] } + if (can.base.isObject(key)) { return can.core.Item(key, function(key, value) { can.page.SelectArgs(can, target, key, value) }), [key] } + if (!can.base.isFunc(cb)) { var value = cb; cb = function(item) { return item.name && (can.base.isUndefined(value)? item.value: (item.value = value))||"" } } if (key.indexOf(ice.PT) > -1) { return [""]} - return can.page.Select(can, option, key? "textarea[name="+key+"],"+"input[name="+key+"],"+"select[name="+key+"]": ".args", cb) + return can.page.Select(can, target, key? "select[name="+key+"],"+"input[name="+key+"],"+"textarea[name="+key+"]": ".args", cb) }, SelectInput: function(can, target, name, cb) { return can.page.Select(can, target, "input[name="+name+"]", cb)[0] }, SelectChild: function(can, target, key, cb) { var i = 0; return can.page.Select(can, target, key, function(node) { if (node.parentNode == target) { return cb(node, i++) } }) }, - SelectAll: function(can, target, key, cb, interval, cbs) { - can.page.Select(can, target, html.IFRAME, function(item) { can.page.SelectAll(can, item.contentWindow.document.body, key, cb, interval, cbs) }) - return can.core.List(target && target.querySelectorAll(key), cb, interval, cbs) - }, SelectOne: function(can, target, key, cb) { return can.page.Select(can, target, key, function(target, index) { return index == 0 && can.base.isFunc(cb) && cb(target), target })[0] }, - Select: function(can, target, key, cb, interval, cbs) { target = target || document.body; if (key == ice.PT) { cb(target); return [] } - return can.core.List(target.querySelectorAll(can.page.Keys(key)), cb, interval, cbs) + Select: function(can, target, key, cb, interval, cbs) { target = target || document.body + return can.core.List(key == ice.PT? [target]: target.querySelectorAll(can.page.Keys(key)), cb, interval, cbs) }, Modify: function(can, target, value) { target = can.base.isString(target)? document.querySelector(target): target; if (!target) { return } can.base.isString(value)? (target.innerHTML = value): can.core.Item(value, function(key, val) { - key == "className" && can.base.isArray(val) && (val = val.join(ice.SP)) - !can.base.isObject(val)? (target[key] = val): can.core.Item(val, function(k, v) { + key == "className" && can.base.isArray(val) && (val = val.join(ice.SP)), !can.base.isObject(val)? (target[key] = val): can.core.Item(val, function(k, v) { if (can.base.isIn(k, "height", "width", "min-height", "max-height", "min-width", "max-width") && parseInt(v) < 0) { return target[key] && (target[key][k] = "") } if (can.base.isIn(k, "height", "width", "min-height", "max-height", "min-width", "max-width", "left", "top", "right", "bottom", "margin-left", "margin-top", "margin", "padding", "font-size") && v && (can.base.isNumber(v) || !can.base.endWith(v, "px"))) { v += "px" } target[key] && (target[key][k] = v) @@ -40,10 +36,8 @@ Volcanos("page", {ClassList: { }, Create: function(can, key, value) { return can.page.Modify(can, document.createElement(key), value) }, Remove: function(can, target) { return target && target.parentNode && target.parentNode.removeChild(target), target }, - Append: function(can, target, key, value) { value = value||{} - if (can.base.isString(key)) { var res = can.page.Create(can, key, value); return target.appendChild(res), res } - can.core.List(key, function(item) { if (!item) { return } - if (item.nodeName) { target.appendChild(item); return } + Append: function(can, target, key, value) { if (can.base.isString(key)) { var res = can.page.Create(can, key, value); return target.appendChild(res), res } + value = value||{}, can.core.List(key, function(item) { if (!item) { return } if (item.nodeName) { target.appendChild(item); return } if (can.base.isString(item)) { item = {view: [item]} } var type = item.type||html.DIV, data = item.data||{}, name = item.name||data.name||""; data.className = data.className||"" can.core.Item(item, function(key, value) { switch (key) { @@ -56,201 +50,40 @@ Volcanos("page", {ClassList: { default: can.base.isUndefined(item[key]) || (data[key] = item[key]) } }) if (item.view) { var list = can.core.List(item.view); if (can.base.isArray(list[0])) { list[0] = list[0].join(ice.SP) } - list[0] && can.page.ClassList.add(can, data, list[0]), type = list[1]||html.DIV, data.innerHTML = list[2]||data.innerHTML||"", name = name||list[3]||"" + list[0] && can.page.ClassList.add(can, data, list[0]), type = list[1]||type, data.innerHTML = list[2]||data.innerHTML||"", name = list[3]||name } else if (item.text) { var list = can.core.List(item.text); if (can.base.isArray(list[2])) { list[2] = list[2].join(ice.SP) } - data.innerHTML = list[0]||data.innerHTML||"", type = list[1]||html.SPAN, list[2] && can.page.ClassList.add(can, data, list[2]) - } else if (item.button) { var list = can.core.List(item.button); type = html.BUTTON, name = name||list[0] - data.innerText = can.user.trans(can, list[0]), data.onclick = function(event) { can.misc.Event(event, can, function(msg) { - can.base.isFunc(list[1]) && list[1](event, name), can.onkeymap.prevent(event); return true - }) } - } else if (item.select) { var list = item.select; type = html.SELECT - data.name = name = name||list[0][0], data.className = data.className||list[0][0]||"", data.title = can.user.trans(can, data.title||name) + data.innerHTML = list[0]||data.innerHTML||"", type = list[1]||item.type||html.SPAN, list[2] && can.page.ClassList.add(can, data, list[2]) + } else if (item.button) { var list = can.core.List(item.button); type = html.BUTTON, name = list[0]||name, data.innerText = can.user.trans(can, name) + data.onclick = function(event) { can.misc.Event(event, can, function(msg) { can.base.isFunc(list[1]) && list[1](event, name), can.onkeymap.prevent(event) }) } + } else if (item.select) { var list = item.select; type = html.SELECT, name = list[0][0], data.className = data.className||list[0][0] + data.onchange = function(event) { can.misc.Event(event, can, function(msg) { can.base.isFunc(list[1]) && list[1](event, event.target.value, name) }) } item.list = list[0].slice(1).map(function(value) { return {type: html.OPTION, value: value, inner: can.user.trans(can, value)} }) - data.onchange = function(event) { can.misc.Event(event, can, function(msg) { - can.base.isFunc(list[1]) && list[1](event, event.target.value, name) - }) } - } else if (item.input) { var list = can.core.List(item.input); type = html.INPUT, name = name||list[0]||"" - data.type = data.type||"text", data.name = data.name||name, data.className = data.className||data.name + } else if (item.input) { var list = can.core.List(item.input); type = html.INPUT, name = list[0], data.className = data.className||list[0], data.type = data.type||html.TEXT data.onfocus = data.onfocus||function(event) { event.target.setSelectionRange(0, -1) } data.onkeydown = function(event) { can.base.isFunc(list[1]) && list[1](event) } data.onkeyup = function(event) { can.base.isFunc(list[2]) && list[2](event) } - } else if (item.username) { var list = can.core.List(item.username); type = html.INPUT, name = name||list[0]||html.USERNAME - data.name = data.name||name, data.autocomplete = data.autocomplete||html.USERNAME, data.className = list[1]||data.className||data.name - } else if (item.password) { var list = can.core.List(item.password); type = html.INPUT, name = name||list[0]||html.PASSWORD - data.type = html.PASSWORD, data.name = data.name||name, data.autocomplete = data.autocomplete||"current-password", data.className = list[1]||data.className||data.name + } else if (item.username) { var list = can.core.List(item.username); type = html.INPUT, name = list[0]||name||html.USERNAME + data.className = list[1]||data.className||name, data.autocomplete = data.autocomplete||html.USERNAME + } else if (item.password) { var list = can.core.List(item.password); type = html.INPUT, name = list[0]||name||html.PASSWORD + data.className = list[1]||data.className||name, data.type = html.PASSWORD, data.autocomplete = data.autocomplete||"current-password" } else if (item.img) { var list = can.core.List(item.img); type = html.IMG, data.src = list[0] } else if (item.row) { type = html.TR, item.list = item.row.map(function(text) { return {text: [text, item.sub||html.TD]} }) } else if (item.th) { type = html.TR, item.list = item.th.map(function(text) { return {text: [text, html.TH]} }) - } else if (item.td) { type = html.TR, item.list = item.td.map(function(text) { return {text: [text, html.TD]} }) } - if (type == html.SELECT) { data.title = can.user.trans(can, data.title||data.name) } - if (type == html.INPUT) { data.type == html.BUTTON && (data.value = can.user.trans(can, data.value)) + } else if (item.td) { type = html.TR, item.list = item.td.map(function(text) { return can.base.isObject(text)? text: {text: [text, html.TD]} }) } + if (type == html.SELECT) { data.title = can.user.trans(can, data.title||name) } + if (type == html.INPUT) { if (data.type == html.TEXT||data.type == html.PASSWORD||!data.type) { - data.placeholder = (data.placeholder||data.name||"").split(ice.PT).pop(), data.title = can.user.trans(can, data.title||data.placeholder) - data.placeholder == "" && delete(data.placeholder), data.title == "" && delete(data.title) + data.placeholder = (data.placeholder||name||"").split(ice.PT).pop(), data.title = can.user.trans(can, data.title||data.placeholder) data.autocomplete = data.autocomplete||"off" - } - } else if (type == html.TEXTAREA) { data.placeholder = can.user.trans(can, (data.placeholder||data.name||"").split(ice.PT).pop()) } - if (!data.className) { delete(data.className) } - !data.name && item.name && (data.name = item.name); var node = can.page.Create(can, type, data) - value[name||""] = value[can.core.Split(data.className)[0]||""] = value[type] = node, value._target = value._target||node, value.first = value.first||node, value.last = node + } else if (data.type == html.BUTTON) { data.value = can.user.trans(can, data.value) } + } if (type == html.TEXTAREA) { data.placeholder = can.user.trans(can, (data.placeholder||name||"").split(ice.PT).pop()) } + can.core.List(["className", "placeholder", "title"], function(key) { data[key] || delete(data[key]) }) + name && (data.name = name); var node = can.page.Create(can, type, data) + value[type] = value[name] = value[can.core.Split(data.className)[0]] = node, value._target = value._target||node, value.first = value.first||node, value.last = node item.list && can.page.Append(can, node, item.list, value), target && target.appendChild && target.appendChild(node), can.base.isFunc(item._init) && item._init(node, value) }); return value }, Appends: function(can, target, key, value) { return target.innerHTML = "", can.page.Append(can, target, key, value) }, - AppendTable: function(can, msg, target, list, cb) { if (!msg.append||msg.append.length == 0) { return } - var table = can.page.Append(can, target, html.TABLE), thead = can.page.Append(can, table, html.THEAD), tbody = can.page.Append(can, table, html.TBODY) - can.page.Append(can, thead, [{type: html.TR, data: {dataset: {index: -1}}, list: can.core.List(list, function(key) { return key[0] != "_" && {text: [key.trim(), html.TH]} }) }]) - can.page.Append(can, tbody, can.core.List(msg.Table(), function(line, index, array) { return {type: html.TR, dataset: {index: index}, list: can.core.List(list, function(key) { return key[0] != "_" && cb(can.page.Color(line[key]).trim(), key, index, line, array) }) } })) - return can.page.OrderTable(can, table) - }, - OrderTable: function(can, table) { - can.page.Select(can, table, html.TH, function(th, index) { th.onclick = function(event) { var dataset = event.target.dataset - can.page.RangeTable(can, table, index, (dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1) == "1") - } }); return table - }, - RangeTable: function(can, table, index, sort_asc) { index = can.base.isArray(index)? can.core.List(index, function(item) { if (item > -1) { return item } }): [index]; if (index.length == 0) { return } - var list = can.page.Select(can, table, html.TR, function(tr) { if (tr.style.display != html.NONE && !can.page.ClassList.has(can, tr, html.HIDE)) { return tr } }).slice(1) - var is_time = true, is_number = true; can.core.List(list, function(tr) { var text = tr.childNodes[index[0]].innerHTML; is_time = is_time && Date.parse(text) > 0, is_number = is_number && !isNaN(parseInt(text)) }) - var num_list = can.core.List(list, function(tr) { var text = tr.childNodes[index[0]].innerHTML; return is_time? Date.parse(text): is_number? can.base.ParseSize(text): text }) - function isless(a, b, index) { if (a.childNodes[index[0]] && b.childNodes[index[0]]) { - if (a.childNodes[index[0]].innerHTML < b.childNodes[index[0]].innerHTML) { return true } - if (a.childNodes[index[0]].innerHTML > b.childNodes[index[0]].innerHTML) { return false } - } return index.length > 1 && isless(a, b, index.slice(1)) } - for (var i = 0; i < num_list.length; i++) { var min = i - for (var j = i+1; j < num_list.length; j++) { - if (sort_asc? num_list[min] < num_list[j]: num_list[j] < num_list[min]) { min = j; continue } - if (num_list[min] == num_list[j] && index.length > 1) { if (sort_asc? isless(list[min], list[j], index.slice(1)): isless(list[j], list[min], index.slice(1))) { min = j } } - } - if (min != i) { - var temp = num_list[i]; num_list[i] = num_list[min]; num_list[min] = temp - var temp = list[i]; list[i] = list[min]; list[min] = temp - } - var tbody = list[i].parentElement; list[i].parentElement && tbody.removeChild(list[i]), tbody.appendChild(list[i]) - } - }, - inputs: function(can, list, type) { - var _list = []; for (var i = 0; i < list.length; i++) { switch (list[i]) { - case "": _list.push(""); break - case ice.AUTO: - _list.push({type: html.BUTTON, name: ice.LIST}) - _list.push({type: html.BUTTON, name: ice.BACK}) - break - case mdb.PAGE: - _list.push({type: html.TEXT, name: mdb.LIMIT, value: can._msg.Option(mdb.LIMIT)}) - _list.push({type: html.TEXT, name: mdb.OFFEND, value: can._msg.Option(mdb.OFFEND)}) - _list.push(mdb.NEXT, mdb.PREV) - break - default: - (function() { var item = can.core.SplitInput(list[i], type||html.BUTTON) - if (item.type == html.SELECT) { item._init = function(target) { target.value = item.value||item.values[0], target.onchange = function(event) { can.misc.Event(event, can, function(msg) { - can.run(event) - }) } } } - item.action && (function() { item._init = function(target) { can.onappend.figure(can, item, target) } })() - // item.type == html.BUTTON? _list.push(item.name): _list.push(item) - _list.push(item) - type = item.type - })() - } } return _list - }, - input: function(can, item, value) { - var input = {type: html.INPUT, name: item.name, data: item, dataset: {}, _init: item._init, style: item.style||{}} - item.value == ice.AUTO && (item.value = "", item.action = ice.AUTO), item.action == ice.AUTO && (input.dataset.action = ice.AUTO) - switch (item.type = item.type||html.TEXT) { - case html.TEXTAREA: input.type = html.TEXTAREA - input.style.height = input.style.height||can.Conf([ctx.FEATURE, html.TEXTAREA, item.name, html.HEIGHT].join(ice.PT))||can.Conf([ctx.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([ctx.FEATURE, html.TEXTAREA, html.WIDTH].join(ice.PT)) - // no break - case html.USERNAME: // no break - case html.PASSWORD: // no break - case html.TEXT: - item.className||can.page.ClassList.add(can, item, ctx.ARGS) - item.name = item.name||item.type - item.value = value||item.value||"" - item.placeholder = item.placeholder||item.name||item.type - item.title = item.title||item.placeholder||item.name||item.type - break - case html.SELECT: input.type = html.SELECT - item.values = can.base.isString(item.values)? can.core.Split(item.values): item.values - if (!item.values && item.value) { item.values = can.core.Split(item.value), item.value = item.values[0] } - if (item.values.slice(1).indexOf(item.values[0]) > -1) { item.value = item.value||item.values[0], item.values = item.values.slice(1) } - item.value = value||item.value, input.list = item.values.map(function(value) { 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||mdb.LIST; break - case html.UPLOAD: item.type = html.FILE, input.name = html.UPLOAD; break - case html.ICON: input = {view: html.ICON+" s"+(item.value||18)+ice.SP+item.name, onclick: function(event) { - if (item.name == "refresh") { can.Update() } else { - !can.sup && can.request(event).RunAction(event, can, [ctx.ACTION, item.name]) || can.runAction(event, item.name) - } - }}; break - } return input - }, - Format: function(type) { var args = arguments; switch (type) { - case html.A: return ""+(args[2]||args[1])+"" - case html.IMG: return args[2]? "": "" - case html.SPAN: return args[2]? ""+args[1]+"": args[1] - default: /* type inner arg... */ - var list = ["<"+type]; for (var i = 2; i < args.length; i += 2) { list.push(ice.SP+args[i]+ice.EQ+args[i+1]) } - return list.concat(">", args[1], "").join("") - } }, - Color: function(text) { if (typeof text != lang.STRING) { return "" } text = text.replace(/\\n/g, "
") - if (text.indexOf(ice.HTTP) == 0 && text.length > 10) { var ls = text.split(ice.SP); text = ""+ls[0]+""+ls.slice(1).join(ice.SP) } - if (text.indexOf("\033\[") == -1) { return text } - text = text.replace(/\033\[31m/g, "") - text = text.replace(/\033\[32m/g, "") - text = text.replace(/\033\[33m/g, "") - text = text.replace(/\033\[34m/g, "") - text = text.replace(/\033\[36m/g, "") - text = text.replace(/\033\[34;1m/g, "") - text = text.replace(/\033\[37;1m/g, "") - text = text.replace(/\033\[1m/g, "") - text = text.replace(/\033\[0m/g, "") - text = text.replace(/\033\[m/g, "") - return text - }, - Keys: function() { var list = [] // FS SP GT PT - for (var i = 0; i < arguments.length; i++) { var v = arguments[i] - if (typeof v == lang.OBJECT) { - for (var j = 0; j < v.length; j++) { if (typeof v[j] == lang.OBJECT) { - for (var k = 0; k < v[j].length; k++) { if (typeof v[j][k] == lang.OBJECT) { v[j][k] = v[j][k].join(ice.PT) } } - v[j] = v[j].join(ice.GT) - } } list.push(v.join(ice.SP)) - } else { list.push(v+"") } - } return list.join(ice.FS) - }, - Cache: function(name, output, data) { if (!name) { return } var cache = output._cache||{}; output._cache = cache - if (data) { if (output.children.length == 0) { return } var temp = document.createDocumentFragment() - while (output.childNodes.length > 0) { var item = output.childNodes[0]; item.parentNode.removeChild(item), temp.appendChild(item) } - return cache[name] = {node: temp, data: data}, name - } output.innerHTML = ""; var list = cache[name]; if (!list) { return } - while (list.node.childNodes.length > 0) { var item = list.node.childNodes[0]; item.parentNode.removeChild(item), output.appendChild(item) } - return delete(cache[name]), list.data - }, - insertBefore: function(can, list, before, parent) { parent = parent||before.parentNode - var target = can.base.isArray(list)? can.page.Append(can, parent, list)._target: list - return before && parent.insertBefore(target, before), target - }, - styleDisplay: function(can, target, value) { return can.page.style(can, target, html.DISPLAY, value), target.style.display }, - styleHeight: function(can, target, value) { return can.page.style(can, target, html.HEIGHT, value), target.offsetHeight }, - styleWidth: function(can, target, value) { return can.page.style(can, target, html.WIDTH, value), target.offsetWidth }, - styleClass: function(can, target, value) { return can.page.Modify(can, target, {className: value}), target.className }, - style: function(can, target, style) { var value = {} - for (var i = 2; i < arguments.length; i += 2) { - if (typeof arguments[i] == lang.OBJECT) { - can.page.Modify(can, target, {style: arguments[i--]}) - } else if (can.base.isUndefined(arguments[i])) { continue - } else { value[arguments[i]] = arguments[i+1] } - } return can.page.Modify(can, target, {style: value}), value - }, - tagis: function(target) { if (!target || !target.tagName) { return } - var type = target.tagName.toLowerCase(); for (var i = 1; i < arguments.length; i++) { if (type == arguments[i]) { return true } } - }, - editable: function(can, item, ok) { item.setAttribute("contenteditable", ok) }, - draggable: function(can, item, ok) { item.setAttribute("draggable", ok) }, - height: function() { return window.innerHeight }, - width: function() { return window.innerWidth }, - ismodkey: function(event) { return [lang.META, lang.ALT, lang.CONTROL, lang.SHIFT].indexOf(event.key) > -1 }, - isDisplay: function(target) { return target && target.style.display != html.NONE && target.className.indexOf(html.HIDE) == -1 }, - unicode: {menu: "☰", back: "◀", refresh: "↻", reback: "▶", delete: "✕", lt: "❮", gt: "❯", open: "▾", close: "▸", inner: ".."}, AppendData: function(can, target, prefix, key, value, cb) { var open = can.page.unicode.open, close = can.page.unicode.close function short(value, length) { if (length == undefined) { @@ -319,15 +152,137 @@ Volcanos("page", {ClassList: { isclose && {view: [[html.ITEM, html.HIDE]], list: [{text: " "}, {className: code.KEYWORD, text: can.page.replace(can, ice.LT+ice.PS+tag+ice.GT)}], _init: function(target) { ui.close = target }}, ]} }, - requireModules: function(can, libs, cb, cbs) { - for (var i = 0; i < libs.length; i++) { if (libs[i].indexOf(ice.PS) == 0 || libs[i].indexOf(ice.HTTP) == 0) { continue } - if (libs[i].indexOf(nfs._CSS) == -1 && libs[i].indexOf(nfs._JS) == -1) { libs[i] = libs[i]+"/lib/"+libs[i]+nfs._JS } - libs[i] = "/require/node_modules/"+libs[i] - } can.require(libs, cb, cbs) - }, - requireDraw: function(can, cb) { can.page.ClassList.add(can, can._fields, "draw") - can.require(["/plugin/local/wiki/draw.js", "/plugin/local/wiki/draw/path.js"], function() { - can.onmotion.clear(can), can.onimport._show(can, can._msg), cb() - }) - }, + AppendTable: function(can, msg, target, list, cb) { if (!msg.append||msg.append.length == 0) { return } + var ui = can.page.Append(can, target, [{type: html.TABLE, list: [{type: html.THEAD}, {type: html.TBODY}]}]) + can.page.Append(can, ui.thead, [{data: {dataset: {index: -1}}, th: can.core.List(list, function(key) { if (key[0] != "_") { return key } }) }]) + can.page.Append(can, ui.tbody, can.core.List(msg.Table(), function(item, index, array) { + return {dataset: {index: index}, td: can.core.List(list, function(key) { if (key[0] != "_") { return cb(can.page.Color(item[key]).trim(), key, index, item, array) } }) } + })); return can.page.OrderTable(can, ui.table) + }, + OrderTable: function(can, table) { can.page.Select(can, table, html.TH, function(th, index) { th.onclick = function(event) { var dataset = event.target.dataset + can.page.RangeTable(can, table, index, (dataset["asc"] = (dataset["asc"] == "1") ? 0: 1) == "1") + } }); return table }, + RangeTable: function(can, table, index, asc) { index = can.base.isArray(index)? can.core.List(index, function(item) { if (item > -1) { return item } }): [index]; if (index.length == 0) { return } + var list = can.page.Select(can, table, html.TR, function(tr) { if (can.page.isDisplay(tr)) { return tr } }).slice(1) + var is_time = true, is_number = true; can.core.List(list, function(tr) { var text = tr.childNodes[index[0]].innerHTML; is_time = is_time && Date.parse(text) > 0, is_number = is_number && !isNaN(parseInt(text)) }) + var num_list = can.core.List(list, function(tr) { var text = tr.childNodes[index[0]].innerHTML; return is_time? Date.parse(text): is_number? can.base.ParseSize(text): text }) + function isless(a, b, index) { if (a.childNodes[index[0]] && b.childNodes[index[0]]) { + if (a.childNodes[index[0]].innerHTML < b.childNodes[index[0]].innerHTML) { return true } + if (a.childNodes[index[0]].innerHTML > b.childNodes[index[0]].innerHTML) { return false } + } return index.length > 1 && isless(a, b, index.slice(1)) } + for (var i = 0; i < num_list.length; i++) { var min = i + for (var j = i+1; j < num_list.length; j++) { + if (asc? num_list[min] < num_list[j]: num_list[j] < num_list[min]) { min = j; continue } + if (num_list[min] == num_list[j] && index.length > 1) { if (asc? isless(list[min], list[j], index.slice(1)): isless(list[j], list[min], index.slice(1))) { min = j } } + } + if (min != i) { + var temp = num_list[i]; num_list[i] = num_list[min]; num_list[min] = temp + var temp = list[i]; list[i] = list[min]; list[min] = temp + } + var tbody = list[i].parentElement; list[i].parentElement && tbody.removeChild(list[i]), tbody.appendChild(list[i]) + } + }, + Format: function(type) { var arg = arguments; switch (type) { + case html.A: return ""+(arg[2]||arg[1])+"" + case html.IMG: return arg[2]? "": "" + case html.SPAN: return arg[2]? ""+arg[1]+"": arg[1] + default: /* type inner arg... */ + var list = ["<"+type]; for (var i = 2; i < arg.length; i += 2) { list.push(ice.SP+arg[i]+ice.EQ+arg[i+1]) } + return list.concat(">", arg[1], "").join("") + } }, + Color: function(text) { if (typeof text != lang.STRING) { return "" } text = text.replace(/\\n/g, "
") + if (text.indexOf(ice.HTTP) == 0 && text.length > 10) { var ls = text.split(ice.SP); text = ""+ls[0]+""+ls.slice(1).join(ice.SP) } + if (text.indexOf("\033\[") == -1) { return text } + text = text.replace(/\033\[31m/g, "") + text = text.replace(/\033\[32m/g, "") + text = text.replace(/\033\[33m/g, "") + text = text.replace(/\033\[34m/g, "") + text = text.replace(/\033\[36m/g, "") + text = text.replace(/\033\[34;1m/g, "") + text = text.replace(/\033\[37;1m/g, "") + text = text.replace(/\033\[1m/g, "") + text = text.replace(/\033\[0m/g, "") + text = text.replace(/\033\[m/g, "") + return text + }, + Keys: function() { var list = []; /* FS SP GT PT */ for (var i = 0; i < arguments.length; i++) { var v = arguments[i]; if (typeof v == lang.OBJECT) { + for (var j = 0; j < v.length; j++) { if (typeof v[j] == lang.OBJECT) { + for (var k = 0; k < v[j].length; k++) { if (typeof v[j][k] == lang.OBJECT) { v[j][k] = v[j][k].join(ice.PT) } } + v[j] = v[j].join(ice.GT) + } } list.push(v.join(ice.SP)) + } else { list.push(v+"") } } return list.join(ice.FS) }, + Cache: function(name, output, data) { if (!name) { return } var cache = output._cache||{}; output._cache = cache + if (data) { if (output.children.length == 0) { return } var temp = document.createDocumentFragment() + while (output.childNodes.length > 0) { var item = output.childNodes[0]; item.parentNode.removeChild(item), temp.appendChild(item) } + return cache[name] = {node: temp, data: data}, name + } output.innerHTML = ""; var list = cache[name]; if (!list) { return } + while (list.node.childNodes.length > 0) { var item = list.node.childNodes[0]; item.parentNode.removeChild(item), output.appendChild(item) } + return delete(cache[name]), list.data + }, + insertBefore: function(can, list, before, parent) { parent = parent||before.parentNode + var target = can.base.isArray(list)? can.page.Append(can, parent, list)._target: list + return before && parent.insertBefore(target, before), target + }, + styleHeight: function(can, target, value) { return can.page.style(can, target, html.HEIGHT, value), target.offsetHeight }, + styleWidth: function(can, target, value) { return can.page.style(can, target, html.WIDTH, value), target.offsetWidth }, + styleClass: function(can, target, value) { return can.page.Modify(can, target, {className: value}), target.className }, + style: function(can, target, style) { var value = {}; for (var i = 2; i < arguments.length; i += 2) { + if (typeof arguments[i] == lang.OBJECT) { can.page.Modify(can, target, {style: arguments[i--]}) } else { value[arguments[i]] = arguments[i+1] } + } return can.page.Modify(can, target, {style: value}), value }, + tagis: function(target) { if (!target || !target.tagName) { return } + var type = target.tagName.toLowerCase(); for (var i = 1; i < arguments.length; i++) { if (type == arguments[i]) { return true } } + }, + isDisplay: function(target) { return target && target.style.display != html.NONE && target.className.indexOf(html.HIDE) == -1 }, + editable: function(can, item, ok) { item.setAttribute("contenteditable", ok) }, + draggable: function(can, item, ok) { item.setAttribute("draggable", ok) }, + height: function() { return window.innerHeight }, + width: function() { return window.innerWidth }, + ismodkey: function(event) { return [lang.META, lang.ALT, lang.CONTROL, lang.SHIFT].indexOf(event.key) > -1 }, + unicode: {menu: "☰", back: "◀", refresh: "↻", reback: "▶", delete: "✕", lt: "❮", gt: "❯", open: "▾", close: "▸", inner: ".."}, + inputs: function(can, list, type) { var _list = []; for (var i = 0; i < list.length; i++) { switch (list[i]) { + case "": _list.push(""); break + case ice.AUTO: + _list.push({type: html.BUTTON, name: ice.LIST}) + _list.push({type: html.BUTTON, name: ice.BACK}) + break + case mdb.PAGE: + _list.push({type: html.TEXT, name: mdb.LIMIT, value: can._msg.Option(mdb.LIMIT)}) + _list.push({type: html.TEXT, name: mdb.OFFEND, value: can._msg.Option(mdb.OFFEND)}) + _list.push(mdb.NEXT, mdb.PREV) + break + default: + (function() { var item = can.core.SplitInput(list[i], type||html.BUTTON) + if (item.type == html.SELECT) { item._init = function(target) { target.value = item.value||item.values[0], target.onchange = function(event) { can.misc.Event(event, can, function(msg) { + can.run(event) + }) } } } item.action && (function() { item._init = function(target) { can.onappend.figure(can, item, target) } })() + _list.push(item), type = item.type + })() + } } return _list }, + input: function(can, item, value) { var input = {type: html.INPUT, name: item.name, data: item, style: item.style||{}, dataset: {}, _init: item._init} + item.value == ice.AUTO && (item.value = "", item.action = ice.AUTO), item.action == ice.AUTO && (input.dataset.action = ice.AUTO) + switch (item.type = item.type||html.TEXT) { + case html.SELECT: input.type = html.SELECT, item.className||can.page.ClassList.add(can, item, ctx.ARGS) + item.values = can.base.isString(item.values)? can.core.Split(item.values): item.values + if (!item.values && item.value) { item.values = can.core.Split(item.value), item.value = item.values[0] } + if (item.values.slice(1).indexOf(item.values[0]) > -1) { item.value = item.value||item.values[0], item.values = item.values.slice(1) } + item.value = value||item.value, input.list = item.values.map(function(value) { return {type: html.OPTION, value: value, inner: value} }); break + case html.TEXTAREA: input.type = html.TEXTAREA // no break + case html.USERNAME: // no break + case html.PASSWORD: // no break + case html.TEXT: item.className||can.page.ClassList.add(can, item, ctx.ARGS), item.name = item.name||item.type, item.value = value||item.value||""; break + case html.UPLOAD: item.type = html.FILE, input.name = html.UPLOAD; break + case html.BUTTON: item.value = item.value||item.name||mdb.LIST; break + } return input + }, + requireModules: function(can, libs, cb, cbs) { + for (var i = 0; i < libs.length; i++) { if (libs[i].indexOf(ice.PS) == 0 || libs[i].indexOf(ice.HTTP) == 0) { continue } + if (libs[i].indexOf(nfs._CSS) == -1 && libs[i].indexOf(nfs._JS) == -1) { libs[i] = libs[i]+"/lib/"+libs[i]+nfs._JS } + libs[i] = "/require/node_modules/"+libs[i] + } can.require(libs, cb, cbs) + }, + requireDraw: function(can, cb) { can.page.ClassList.add(can, can._fields, "draw") + can.require(["/plugin/local/wiki/draw.js", "/plugin/local/wiki/draw/path.js"], function() { + can.onmotion.clear(can), can.onimport._show(can, can._msg), cb() + }) + }, }) diff --git a/lib/user.js b/lib/user.js index 83619eae..0a5412a4 100644 --- a/lib/user.js +++ b/lib/user.js @@ -1,6 +1,7 @@ -Volcanos("user", {info: {}, agent: { +Volcanos("user", { + agent: { chooseImage: function(can, cb) { can.base.isFunc(cb) && cb([]) }, - scanQRCode: function(can, cb) { can.user.input(event, can, [{type: html.TEXTAREA, name: "text", text: ""}], function(list) { cb(can.base.ParseJSON(list[0])) }) }, + scanQRCode: function(can, cb) { can.user.input(event, can, [{type: html.TEXTAREA, name: mdb.TEXT, text: ""}], function(list) { cb(can.base.ParseJSON(list[0])) }) }, getLocation: function(can, cb) { var call = arguments.callee; if (call._res) { return cb(call._res) } navigator.geolocation.getCurrentPosition(function(res) { cb(call._res = {latitude: parseInt(res.coords.latitude*100000), longitude: parseInt(res.coords.longitude*100000)}) @@ -10,7 +11,7 @@ Volcanos("user", {info: {}, agent: { window.open("https://map.baidu.com/search/"+encodeURIComponent(msg.Option(mdb.TEXT)) +"/@12958750.085,4825785.55,16z?querytype=s&da_src=shareurl&wd="+encodeURIComponent(msg.Option(mdb.TEXT))) }, - }, + }, info: {}, isTesla: navigator.userAgent.indexOf("Tesla") > -1, isMailMaster: navigator.userAgent.indexOf("MailMaster") > -1, isWeiXin: navigator.userAgent.indexOf("MicroMessenger") > -1, @@ -35,14 +36,13 @@ Volcanos("user", {info: {}, agent: { opens: function(url) { window.openurl? window.openurl(url): (window.open(url) || (location.href = url)) }, open: function(url) { window.open(url) || (location.href = url) }, close: function(url) { window.close() }, - title: function(text) { if (window.webview) { return title(text) } return text && (document.title = text), document.title }, theme: function(can, name) { can.base.isString(name) && (name = [name]) || name || [] can.user.isWebview && name.push(html.WEBVIEW), can.user.isMobile && name.push(html.MOBILE) && can.user.isLandscape() && name.push(html.LANDSCAPE) - can.Conf(chat.DISPLAY) && name.push(can.Conf(chat.DISPLAY)), can.user.mod.isCmd && name.push(chat.SIMPLE) can.user.language(can) && name.push(can.user.language(can)), can.page.styleClass(can, document.body, name.join(ice.SP)) }, + title: function(text) { if (window.webview) { return title(text) } return text && (document.title = text), document.title }, language: function(can) { return can.misc.SearchOrConf(can, aaa.LANGUAGE)||can.user.info.language||"zh" }, - trans: function(can, text, list) { if (can.user.language(can) == "en") { return text } + trans: function(can, text, list) { if (can.base.isNumber(text)) { return text+"" } if (can.user.language(can) != "zh") { return text } if (can.base.isObject(text)) { return can.core.Item(text, function(k, v) { can.core.Value(can._trans, k, v) }) } if (can.base.isFunc(text)) { text = text.name||"" } 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) || kit.Dict( @@ -61,12 +61,12 @@ Volcanos("user", {info: {}, agent: { var list = can.user.language(can) == "en"? ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"] return fmt == "%W"? list: can.base.Time(time, (fmt||"%y-%m-%d %H:%M:%S").replace("%w", list[now.getDay()])) }, - toastConfirm: function(can, content, title, action) { return can.user.toast(can, {content: content, title: title, action: action||[cli.CLOSE], duration: -1, width: -300}) }, - toastProcess: function(can, content, title) { return can.user.toast(can, content||ice.PROCESS, title, -1) }, - toastSuccess: function(can, content, title) { return can.user.toast(can, "\u2705 "+(content||ice.SUCCESS), title) }, - toastFailure: function(can, content, title) { return can.user.toast(can, "\u274C "+(content||ice.FAILURE), title, 10000) }, - toast: function(can, content, title, duration, progress) { - var meta = can.base.isObject(content)? content: {content: content, title: title||can._name.split(ice.PS).slice(-2).join(ice.PS), duration: duration, progress: progress} + toastConfirm: function(can, content, title, action) { return can.user.toast(can, {content: content, title: title, action: action||[cli.CLOSE], duration: -1}) }, + toastProcess: function(can, content, title) { return can.user.toast(can, {content: content||ice.PROCESS, title: title||can._name, duration: -1, caller: 2}) }, + toastSuccess: function(can, content, title) { return can.user.toast(can, {content: "\u2705 "+(content||ice.SUCCESS), title: title||can._name, caller: 2}) }, + toastFailure: function(can, content, title) { return can.user.toast(can, {content: "\u274C "+(content||ice.FAILURE), title: title||can._name, duration: 10000, caller: 2}) }, + toast: function(can, content, title, duration, progress, caller) { + var meta = can.base.isObject(content)? content: {content: content, title: title||can._name.split(ice.PS).slice(-2).join(ice.PS), duration: duration, progress: progress, caller: caller} var width = meta.width||400; if (width < 0) { width = window.innerWidth + width } var ui = can.page.Append(can, document.body, [{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) }}, @@ -75,11 +75,11 @@ Volcanos("user", {info: {}, agent: { html.ACTION, !can.base.isUndefined(meta.progress) && {view: "progress", style: {width: width-10}, list: [ {view: "current", style: {width: (meta.progress||0)*(width-12)/100}}, ]}, - ] }]); can.onengine.signal(can, chat.ONTOAST, can.request({}, {time: can.misc._time(), title: meta.title, content: meta.content, fileline: can.misc.FileLine(-3)})._callers(1)) + ] }]); can.onengine.signal(can, chat.ONTOAST, can.request({}, {time: can.misc._time(), title: meta.title, content: meta.content})._caller(meta.caller||1)) var action = can.onappend._action(can, meta.action && meta.action.list? meta.action.list: meta.action||[""], ui.action, { _engine: function(event, button) { can.core.CallFunc(meta.action[button]||meta.action, [event, button]) }, open: function(event) { meta.content.indexOf(ice.HTTP) == 0 && can.user.open(meta.content), meta.title.indexOf(ice.HTTP) == 0 && can.user.open(meta.title) }, - close: function(event) { can.page.Remove(can, action._target), action.timer.stop = true }, + close: function(event) { can.page.Remove(can, ui._target), action.timer.stop = true }, timer: can.core.Timer({interval: 100, length: (meta.duration||1000)/100}, function(event, interval, index) { if (index > 30) { ui.duration.innerHTML = index/10+"s..." } }, function() { action.close() }), _target: ui._target, @@ -93,51 +93,49 @@ Volcanos("user", {info: {}, agent: { 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(nfs.COPY, text), text } } - var input = can.page.Append(can, event.target.parentNode, [{type: html.TEXTAREA, value: text}])._target + var input = can.page.Append(can, document.body, [{type: html.TEXTAREA, value: text}])._target can.onmotion.focus(can, input), document.execCommand("Copy"), can.page.Remove(can, input) return can.user.toastSuccess(can, text, "copy success"), can.misc.Log(nfs.COPY, text), text }, carte: function(event, can, meta, list, cb, parent, trans) { parent || can.onmotion.clearCarte(can) meta = meta||can.ondetail||can.onaction||{}, list = can.base.getValid(list, meta.list, can.core.Item(meta)); if (!list || list.length == 0) { return } function click(event, button) { can.misc.Event(event, can, function(msg) { can.onkeymap.prevent(event) - meta[button]? meta[button](event, can, button): can.base.isFunc(cb)? cb(event, button, meta, carte): + meta[button]? can.core.CallFunc([meta, button], [event, can, button]): can.base.isFunc(cb)? cb(event, button, meta, carte): can.onaction && can.onaction[button] && can.core.CallFunc([can.onaction, button], [event, can, button]) - parent || can.onmotion.clearCarte(can) - // , can.onmotion.delay(can, function() { carte._sub || can.page.Remove(can, ui._target) }) - }) } - function remove_sub(carte) { carte._sub && can.page.Remove(can, carte._sub._target), delete(carte._sub) } + can.onmotion.clearCarte(can) + }) } function remove_sub(carte) { carte._sub && can.page.Remove(can, carte._sub._target), delete(carte._sub) } var ui = can.page.Append(can, document.body, [{view: [[chat.CARTE, meta._style||"", chat.FLOAT]], list: can.core.List(list, function(item, index) { - return item ==""? /* 0.space */ {type: html.HR}: can.base.isString(item)? /* 1.string */ {view: [html.ITEM, html.DIV, can.user.trans(can, item, trans)], onclick: function(event) { click(event, item) }, onmouseenter: function(event) { remove_sub(carte) } }: - can.base.isArray(item)? /* 2.array */ {view: html.ITEM, list: [{text: can.user.trans(can, item[0], trans)+" "+can.page.unicode.gt}], onmouseenter: function(event) { - var sub = can.user.carte(event, can, meta, item.slice(1), cb||function(event, button) { - can.onimport && can.onimport[item[0]] && can.onimport[item[0]](can, button) - }, carte, trans); can.onlayout.figure(event, can, sub._target, true), remove_sub(carte), carte._sub = sub - } }: /* 3.object */ item + function subs(event) { var sub = can.user.carte(event, can, meta, item.slice(1), cb||function(event, button) { + can.onimport && can.onimport[item[0]] && can.onimport[item[0]](can, button) + }, carte, trans); can.onlayout.figure(event, can, sub._target, true), remove_sub(carte), carte._sub = sub } + return item === ""? /* 0.space */ {type: html.HR}: can.base.isString(item)||can.base.isNumber(item)? /* 1.string */ {view: [html.ITEM, html.DIV, can.user.trans(can, item, trans)], onclick: function(event) { click(event, item) }, onmouseenter: function(event) { remove_sub(carte) } }: + can.base.isArray(item)? /* 2.array */ {view: html.ITEM, list: [{text: can.user.trans(can, item[0], trans)}, {text: [ice.SP+can.page.unicode.gt, "", [html.ICON, "gt"]]}], onmouseenter: subs, onclick: subs}: /* 3.object */ item })}]); can.onkeymap.prevent(event), can.page.Select(can, ui._target, html.IMG, function(target) { target.onload = function() { can.onlayout.figure(event, can, ui._target) } }) - var carte = {_target: ui._target, _parent: parent, layout: can.onlayout.figure(event, can, ui._target), close: function() { can.page.Remove(can, ui._target) }}; return carte + var carte = {_target: ui._target, _parent: parent, layout: can.onlayout.figure(event, can, ui._target, false, 0.8), close: function() { can.page.Remove(can, ui._target) }}; return carte }, carteRight: function(event, can, meta, list, cb, parent) { var carte = can.user.carte(event, can, meta, list, cb, parent) - return can.page.style(can, carte._target, can.onlayout.figure(event, can, carte._target, true)), carte + return can.onlayout.figure(event, can, carte._target, true), carte }, input: function(event, can, form, cb, button) { if (!form || form.length == 0) { return cb() } var msg = can.request(event); event = event._event||event; var need = {} var ui = can.page.Append(can, document.body, [{view: [[html.INPUT, chat.FLOAT]], list: [ - {view: nfs.CONTENT, list: [{view: [html.OPTION, html.TABLE], list: can.core.List(form, function(item) { + {view: html.OPTION, list: [{type: html.TABLE, list: can.core.List(form, function(item) { item = can.base.isString(item)? {type: html.TEXT, name: item}: item.length > 0? {type: html.SELECT, name: item[0], values: item.slice(1)}: item item.type = item.type||(item.values? html.SELECT: item.name == html.TEXT? html.TEXTAREA: html.TEXT), need[item.name] = item.need - item.onkeydown = function(event) { if (event.key == lang.ESCAPE) { event.target.blur() } } item._init = function(target) { if (item.type == html.PASSWORD || item.type == html.USERNAME) { return } if (item.name && item.name != ctx.ACTION) { target.value = msg.Option(item.name)||can.Option(item.name)||target.value||"" } item.mode = chat.SIMPLE, can.onappend.figure(can, can.base.Copy({run: function(event, cmds, cb) { var _msg = can.request(event, {_handle: ice.TRUE, action: msg.Option(html.ACTION)}, msg, can.Option()) can.page.Select(can, ui.table, html.OPTION_ARGS, function(item) { item.name && item.value && _msg.Option(item.name, item.value) }) - ;(item.run||can.run)(event, cmds, cb, true) + can.run(event, cmds, cb, true) }, _enter: function(event) { return action.submit(event, can, html.SUBMIT), true }}, item), target) - }; return {type: html.TR, list: [ - {type: html.TD, list: [{text: [item.name||"", html.LABEL]}, - {text: item.need == "must"? "*": "", style: {color: cli.RED}}]}, + }, item.onkeydown = function(event) { if (event.key == lang.ESCAPE) { event.target.blur() } } + return {type: html.TR, list: [ + {type: html.TD, list: [{text: [item.name||"", html.LABEL]}]}, + {type: html.TD, list: [{text: item.need == "must"? "*": "", style: {color: cli.RED}}]}, {type: html.TD, list: [can.page.input(can, item), item.type == html.TEXT && {view: [html.ICON, html.SPAN, can.page.unicode.delete], onclick: function(event) { event.target.previousSibling.value = "" - }}]}]} + }}]}, + ]} })}]}, html.ACTION, ]}]) var action = can.onappend._action(can, button||[html.SUBMIT, html.CANCEL], ui.action, { @@ -150,8 +148,8 @@ Volcanos("user", {info: {}, agent: { }); if (err) { return } can.onkeymap.prevent(event) can.core.CallFunc(cb, {event: can.request(event, {_handle: ice.TRUE})._event, button: button, data: data, list: list, args: args, input: action}) || action.cancel() }, _target: ui._target, _engine: function(event, can, button) { action.submit(event, can, button) }, - }); can.onlayout.figure(event, can, ui._target), can.onmotion.delay(can, function() { action.focus() }) - return button === true && action.submit(event, can, html.SUBMIT), action + }); can.onlayout.figure(event, can, ui._target, false, 1), can.onmotion.delay(can, function() { action.focus() }) + return button === true && action.submit(event, can, html.SUBMIT), action }, select: function(event, can, type, fields, cb, cbs) { can.search(can.request(event, {fields: fields||"type,name,text"}), ["Search.onimport.select", type, "", ""], function(list) { @@ -176,11 +174,11 @@ Volcanos("user", {info: {}, agent: { }, _target: ui._target, }); can.page.Select(can, ui.action, html.INPUT_FILE)[0].click(), silent && can.onmotion.hidden(can, ui._target); return action }, + downloads: function(can, text, name, ext) { return text && can.user.download(can, URL.createObjectURL(new Blob([text])), name, ext) }, download: function(can, path, name, ext) { var a = can.page.Append(can, document.body, [{type: html.A, href: path, download: can.core.Keys(name, ext)||path.split(ice.PS).pop()}])._target return a.click(), can.page.Remove(can, a), path }, - downloads: function(can, text, name, ext) { return text && can.user.download(can, URL.createObjectURL(new Blob([text])), name, ext) }, toimage: function(can, name, target, silent) { var toast = can.user.toastProcess(can, "生成中...") can.require(["https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js"], function() { toast.close() html2canvas(target||can._target).then(function (canvas) { var url = canvas.toDataURL("image/png") @@ -188,22 +186,13 @@ Volcanos("user", {info: {}, agent: { }) }) }, - toastImage: function(can, name, url) { url = can.base.isString(url)? url: url.toDataURL("image/png") - var toast = can.user.toast(can, {content: {img: url, style: {"max-height": window.innerHeight/2, display: html.BLOCK}}, title: name, duration: -1, - action: shy([cli.CLOSE, web.DOWNLOAD], function(event, button) { - can.user.input(event, can, [{name: mdb.NAME, value: name}], function(list) { can.user.download(can, url, list[0], nfs.PNG) }) - }), resize: html.IMG, - }) - }, - toPNG: function(can, name, text, height, width) { - if (text.indexOf("" } - var img = can.page.Create(can, html.IMG, {src: "data:image/svg+xml,"+encodeURIComponent(text), onload: function() { - var canvas = can.page.Create(can, html.CANVAS, {height: height, width: width}); canvas.getContext("2d").drawImage(img, 0, 0) - can.user.download(can, canvas, name, nfs.PNG) - }}) - }, + toastImage: function(can, name, url) { var toast = can.user.toast(can, {content: {img: url, style: {"max-height": window.innerHeight/2, display: html.BLOCK}}, title: name, duration: -1, + action: shy([cli.CLOSE, web.DOWNLOAD], function(event, button) { + can.user.input(event, can, [{name: mdb.NAME, value: name}], function(list) { can.user.download(can, url, list[0], nfs.PNG) }) + }), resize: html.IMG, + }) }, login: function(can, cb, method) { var trans = kit.Dict(aaa.USERNAME, "用户", aaa.PASSWORD, "密码", aaa.LOGIN, "登录") - function layout() { can.page.style(can, ui._target, {left: (window.innerWidth-ui._target.offsetWidth)/2, top: window.innerHeight/6}) } + function layout() { can.page.style(can, ui._target, {left: (window.innerWidth-ui._target.offsetWidth)/2, top: window.innerHeight/8}) } function button(list) { return {view: [html.ITEM, html.TR], list: [{type: html.TD}, {type: html.TD, list: can.core.Item(list, function(key, cb) { return {type: html.INPUT, value: can.user.trans(can, key, trans), data: {type: html.BUTTON}, onclick: cb} }) }]} } @@ -224,7 +213,8 @@ Volcanos("user", {info: {}, agent: { }) }))]) }, - }, can.base.Obj(method, can.user.isMobile? ["密码登录"]: ["扫码授权"]), can.page.Append(can, document.body, [{view: "input login float"}])._target); layout() + }, can.base.Obj(method, can.user.isMobile? ["密码登录"]: ["扫码授权"]), can.page.Append(can, document.body, [{view: "input login float"}])._target) + can.onmotion.delay(can, function() { layout() }) }, logout: function(can, force) { if (force||can.user.confirm("logout?")) { can.runAction({}, aaa.LOGOUT, [], function(msg) { can.misc.Search(can, chat.SHARE)? can.misc.Search(can, chat.SHARE, ""): can.user.reload(true) diff --git a/panel/action.js b/panel/action.js index dc10886e..bc0c4d9d 100644 --- a/panel/action.js +++ b/panel/action.js @@ -1,8 +1,8 @@ (function() { const TABS = "tabs", TABVIEW = "tabview", HORIZON = "horizon", VERTICAL = "vertical", GRID = "grid", FREE = "free", FLOW = "flow", PAGE = "page", CAN_LAYOUT = "can.layout" Volcanos(chat.ONIMPORT, {_init: function(can, msg) { can.onmotion.clear(can) var river = can.Conf(chat.RIVER), storm = can.Conf(chat.STORM); can.core.Next(msg.Table(), function(item, next) { item.type = chat.PLUGIN, item.mode = can.Mode() - can.onappend.plugin(can, item, function(sub, meta, skip) { can._plugins = can.misc.concat(can, can._plugins, [sub]), can.onimport._tabs(can, sub, meta), skip || next() - sub.run = function(event, cmds, cb) { return can.run(event, can.misc.concat(can, river == web.SHARE? [ctx.ACTION]: [], [river, storm, meta.id||meta.index], cmds), cb) } + can.onappend.plugin(can, item, function(sub, meta, skip) { can._plugins = (can._plugins||[]).concat([sub]), can.onimport._tabs(can, sub, meta), skip || next() + sub.run = function(event, cmds, cb) { return can.run(event, (river == web.SHARE? [ctx.ACTION]: []).concat([river, storm, meta.id||meta.index], cmds), cb) } sub._target.onclick = function(event) { event.target == sub._target && sub._tabs.click() } }) }, function() { can.isCmdMode() || can.onmotion.delay(can, function() { can.onaction.layout(can) }) }) diff --git a/panel/footer.js b/panel/footer.js index 95da282b..b856e7b1 100644 --- a/panel/footer.js +++ b/panel/footer.js @@ -25,7 +25,7 @@ Volcanos(chat.ONIMPORT, {_init: function(can, msg, target) { can.ui = {}, can.db }}, "", target, [chat.TITLE]) }, _data: function(can, name, item) { can[name] = can[name]||can.request(), can[name].Push(item), can.onimport.count(can, name) }, count: function(can, name) { can.page.Select(can, can._output, can.core.Keys(html.SPAN, name), function(item) { item.innerHTML = can.Conf(name, parseInt(can.Conf(name)||"0")+1+"")+"" }) }, - toast: function(can, msg, title, content, fileline, time) { can.onimport._data(can, NTIP, {time: time, fileline: fileline, title: title, content: content}), can.page.Modify(can, can.toast, [time, title, content].join(ice.SP)) }, + toast: function(can, msg, title, content, fileline, time) { can.onimport._data(can, NTIP, {time: time, fileline: can.base.trimPrefix(msg.Option("log.caller"), location.origin+ice.PS), title: title, content: content}), can.page.Modify(can, can.toast, [time, title, content].join(ice.SP)) }, ncmd: function(can, msg, _follow, _cmds) { can.onimport._data(can, NCMD, {time: can.base.Time(), follow: _follow, cmds: _cmds}), can.onimport.nlog(can, NLOG) }, nlog: function(can, name) { can.onimport.count(can, name) }, }) diff --git a/panel/header.js b/panel/header.js index 23c1261e..f391fb23 100644 --- a/panel/header.js +++ b/panel/header.js @@ -33,7 +33,7 @@ Volcanos(chat.ONIMPORT, {_init: function(can, msg, target) { menu: function(can, cmds, cb, trans) { can.base.isString(cmds) && (cmds = [cmds]) return can.page.Append(can, can._output, [{view: cmds[0], list: can.core.List(can.base.getValid(cmds.slice(1), [cmds[0]]), function(item) { if (can.base.isString(item)) { return {view: [html.MENU, html.DIV, can.user.trans(can, item, trans)], onclick: function(event) { can.base.isFunc(cb) && cb(event, item, [item]) }} } - if (can.base.isArray(item)) { return {view: [html.MENU, html.DIV, can.user.trans(can, item[0], trans)], onclick: function(event) { can.onkeymap.prevent(event) }, onmouseenter: function(event) { + if (can.base.isArray(item)) { return {view: [html.MENU, html.DIV, can.user.trans(can, item[0], trans)], onclick: function(event) { can.onkeymap.prevent(event) can.onaction.carte(event, can, item.slice(1), function(event, button, meta) { can.base.isFunc(cb) && cb(event, button, item) }, trans) }} } if (can.base.isObject(item)) { return item } }) }])._target @@ -49,7 +49,7 @@ Volcanos(chat.ONACTION, {_init: function(can) { var themeMedia = window.matchMed can.run({}, [], function(msg) { if (!can.Conf(aaa.USERNICK, msg.Option(aaa.USERNICK)||msg.Option(ice.MSG_USERNICK)||msg.Option(ice.MSG_USERNAME))) { return msg.Option(chat.SSO)? can.user.jumps(msg.Option(chat.SSO)): can.user.login(can, function() { can.onengine.signal(can, chat.ONMAIN, msg) }, msg.Option(aaa.LOGIN)) } can.user.info.usernick = can.Conf(aaa.USERNICK), can.user.info.avatar = msg.Option(aaa.AVATAR), can.user.info.background = msg.Option(aaa.BACKGROUND) - can.user.info.language = msg.SearchOrOption(aaa.LANGUAGE), msg.Option(nfs.SCRIPT) && can.require(can.base.Obj(msg.Option(nfs.SCRIPT)), function(can) { can.onaction.source(can, msg) }) + can.user.info.language = msg.SearchOrOption(aaa.LANGUAGE)||navigator.language.split("-")[0], msg.Option(nfs.SCRIPT) && can.require(can.base.Obj(msg.Option(nfs.SCRIPT)), function(can) { can.onaction.source(can, msg) }) can.onmotion.clear(can), can.onimport._init(can, msg, can._output), can.onengine.signal(can, chat.ONLOGIN, msg) }) }, diff --git a/plugin/local/code/inner.js b/plugin/local/code/inner.js index bb38e0e4..5b195a68 100644 --- a/plugin/local/code/inner.js +++ b/plugin/local/code/inner.js @@ -90,7 +90,7 @@ Volcanos(chat.ONIMPORT, {_init: function(can, msg, cb, target) { can.onmotion.cl var func = can.onexport.func(can); if (func.list.length == 0) { return } can.db.tabFunc = can.db.tabFunc||{} var last = can.db.tabFunc[can.Option(nfs.PATH)+can.Option(nfs.FILE)]||{}; can.db.tabFunc[can.Option(nfs.PATH)+can.Option(nfs.FILE)] = last var carte, list = [{input: [html.FILTER, function(event) { if (event.key == lang.ESCAPE) { return carte.close() } can.onkeymap.selectItems(event, can, carte._target) - }], _init: function(target) { can.onmotion.delay(can, function() { target.placeholder = "search in "+list.length+" items", target.focus() }) }}] + }], _init: function(target) { can.onmotion.delay(can, function() { target.placeholder = "search in "+(can.core.List(list, function(item) { if (item) { return item } }).length-1)+" items", target.focus() }) }}] can.core.Item(last, function(key) { list.push(key) }), list = list.concat(func.list) can.page.Append(can, target, [{view: [[html.ITEM, "func"], html.SPAN, (func.current||"func")+" / "+can.db.max+func.percent], onclick: function(event) { carte = can.user.carte(event, can, {_style: nfs.PATH}, list, function(ev, button) { last[button] = true, carte.close() @@ -212,7 +212,11 @@ Volcanos(chat.ONIMPORT, {_init: function(can, msg, cb, target) { can.onmotion.cl if (sub._delay_init == true) { sub._delay_init = false, sub.Update() } }) }, sub._delay_init = true sub.onexport.record = function(sub, value, key, line) { if (!line.file && !line.line) { return } + if (line.file.indexOf("require/src") == 0) { + line.path = nfs.SRC, line.file = line.file.slice(12) + } can.onimport.tabview(can, line.path||can.Option(nfs.PATH), can.base.trimPrefix(line.file, nfs.PWD)||can.Option(nfs.FILE), parseInt(line.line)) + return true }, sub.onaction.close = sub.select = function() { return sub._legend.click(), sub } sub.hidden = function() { can.onmotion.hidden(can, sub._target), can.page.ClassList.del(can, sub._legend, html.SELECT) } sub.onimport.size(sub, can.ConfHeight()/2, can.ConfWidth()-can.ui.project.offsetWidth, true), can.base.isFunc(cb) && cb(sub) @@ -489,14 +493,14 @@ Volcanos(chat.ONEXPORT, {list: [mdb.COUNT, mdb.TYPE, nfs.FILE, nfs.LINE, ice.BAC var package = "", block = "", current = "", percent = "" can.page.Select(can, can.ui.content, "tr.line>td.text", function(item, index) { var text = item.innerText, _indent = indent(text) function push(item) { list.push(item); if (index < can.Option(nfs.LINE)) { current = list[list.length-1], percent = " = "+parseInt((index+1)*100/(can.db.max||1))+"%" } } - if (can.db.parse == nfs.JS) { var ls = can.core.Split(text, "\t ({:}),") + if (can.db.parse == nfs.JS) { var ls = can.core.Split(text, "\t (,", ice.DF) if (_indent == 0 && can.base.beginWith(text, "Volcanos")) { var _block = can.base.trimPrefix(ls[1], "chat.").toLowerCase() if (_block != block) { push("") } block = _block if (text.indexOf(chat._INIT) > -1) { push(block+ice.PT+chat._INIT+ice.DF+(index+1)) } } else if (_indent == 0 && can.base.beginWith(text, "var ")) { block = ls[1] - } else if (_indent == 4) { + } else if (_indent == 4 && ls[1] == ice.DF) { ls[0] && push(block+ice.PT+ls[0]+ice.DF+(index+1)) } } else if (can.db.parse == nfs.GO) { var ls = can.core.Split(text, "\t *", "({:})") diff --git a/plugin/local/code/inner/syntax.js b/plugin/local/code/inner/syntax.js index 9db2a637..eb3a6c83 100644 --- a/plugin/local/code/inner/syntax.js +++ b/plugin/local/code/inner/syntax.js @@ -364,6 +364,7 @@ Volcanos(chat.ONSYNTAX, { "length": code.FUNCTION, "split": code.FUNCTION, "trim": code.FUNCTION, + "isArray": code.FUNCTION, "kit": code.DATATYPE, "ice": code.DATATYPE, diff --git a/plugin/local/team/plan.js b/plugin/local/team/plan.js index 358f59a0..9170e5fb 100644 --- a/plugin/local/team/plan.js +++ b/plugin/local/team/plan.js @@ -11,6 +11,7 @@ Volcanos(chat.ONIMPORT, {_init: function(can, msg, target) { can.onmotion.clear( return can.onimport._task(can, msg, get(begin_time, col, row, hash), set(begin_time, col, row)) })} }) }])._target, can.onmotion.delay(can, function() { var target = can.sup.task && can.sup.task._target; target && target.click(), can.Status(mdb.COUNT, msg.Length()) + return can.user.isMobile || can.isCmdMode() && can.page.Append(can, can._action, [{view: [["item", "time", "select"]], style: {"float": html.RIGHT, "padding": 5, "height": 21}, _init: function(target) { can.onappend.figure(can, {action: "date"}, target, function(sub, value) { }), target.onmouseenter = target.click can.core.Timer({interval: 100}, function() { @@ -26,7 +27,7 @@ Volcanos(chat.ONIMPORT, {_init: function(can, msg, target) { can.onmotion.clear( ondrop: function(event) { can.onkeymap.prevent(event), can.drop(event, event.target, time) }, ondragover: function(event) { can.onkeymap.prevent(event), can.page.Select(can, can.ui.content, html.TD, function(td) { can.page.ClassList.set(can, td, "over", td == event.target) }) }, list: can.core.List(list, function(task) { return can.base.isString(task)? {text: [task, html.DIV, "date"]}: - {text: [can.onexport[can.Action(ice.VIEW)||mdb.TEXT](can, task), html.DIV, can.onexport.style(can, task)], + {text: [can.core.CallFunc([can.onexport, can.Action(ice.VIEW)||mdb.TEXT], [can, task])||task.name, html.DIV, can.onexport.style(can, task)], ondragstart: function(event) { var target = event.target; can.drop = function(event, td, time) { td.append(target) can.onaction.modifyTask(event, can, task, team.BEGIN_TIME, time+task.begin_time.slice(time.length), task.begin_time) } }, draggable: time != undefined, title: can.onexport.title(can, task), _init: function(target) { @@ -123,7 +124,7 @@ Volcanos(chat.ONACTION, {list: [mdb.PREV, mdb.NEXT, mdb.INSERT, mdb.EXPORT, mdb. ["status", "all", "prepare", "process", "cancel", "finish"], ["level", "all", "l1", "l2", "l3", "l4", "l5"], ["score", "all", "s1", "s2", "s3", "s4", "s5"], - ["view", "", "name", "text", "level", "score"], + ["view", "text", "name", "text", "level", "score"], ], _trans: {"task": "任务", "hour": "时间", "month": "月份", "order": "周序"}, prev: function(event, can) { var begin = can.base.Date(can.Option(team.BEGIN_TIME)||can.base.Time()) can.Option(team.BEGIN_TIME, can.base.Time(new Date(begin-can.onexport.span(can)))), can.Update() @@ -151,7 +152,7 @@ Volcanos(chat.ONACTION, {list: [mdb.PREV, mdb.NEXT, mdb.INSERT, mdb.EXPORT, mdb. status: function(event, can, key, value) { can.onaction._filter(event, can, key, value) }, level: function(event, can, key, value) { value && can.onaction._filter(event, can, key, value) }, score: function(event, can, key, value) { value && can.onaction._filter(event, can, key, value) }, - view: function(event, can, key, value) { can.Action(key, value), can.onmotion.clear(can, can.ui.project), can.onmotion.clear(can, can.ui.content), can.onimport[can.Option("scale")](can, can._msg) }, + view: function(event, can, key, value) { can.Action(key, value), can.onmotion.clear(can, can.ui.project), can.onmotion.clear(can, can.ui.content), can.core.CallFunc([can.onimport, can.Option("scale")], [can, can._msg]) }, }) Volcanos(chat.ONEXPORT, {list: [mdb.COUNT, team.BEGIN_TIME, mdb.ZONE, mdb.ID, mdb.TYPE, mdb.NAME, mdb.TEXT], span: function(can) { return kit.Dict(team.DAY, 24*3600*1000, team.WEEK, 7*24*3600*1000, team.MONTH, 30*24*3600*1000, team.YAER, 365*24*3600*1000, team.LONG, 365*24*3600*1000)[can.Option("scale")]||0 }, diff --git a/plugin/local/wiki/word.js b/plugin/local/wiki/word.js index f51fb93e..f4c205c5 100644 --- a/plugin/local/wiki/word.js +++ b/plugin/local/wiki/word.js @@ -2,7 +2,7 @@ Volcanos(chat.ONIMPORT, {_init: function(can, msg, target) { can.onmotion.clear( can.page.Modify(can, target, msg.Result()) can.page.Select(can, target, wiki.STORY_ITEM, function(target) { var meta = target.dataset||{} can.core.CallFunc([can.onimport, meta.type||target.tagName.toLowerCase()], [can, meta, target]) - can.page.style(can, target, can.base.Obj(meta.style)) + meta.style && can.page.style(can, target, can.base.Obj(meta.style)) }) }, navmenu: function(can, meta, target) { var nav = can.sup._navmenu @@ -83,7 +83,7 @@ Volcanos(chat.ONIMPORT, {_init: function(can, msg, target) { can.onmotion.clear( can.onappend._init(can, item, [chat.PLUGIN_STATE_JS], function(sub) { sub.run = function(event, cmds, cb, silent) { var msg = sub.request(event) if (msg.Option(nfs.PATH) == can.Option(nfs.PATH)) { msg.Option(nfs.PATH, "") } - can.runAction(event, chat.STORY, can.misc.concat(can, [meta.type, meta.name, meta.text], cmds), cb||function(msg) { + can.runAction(event, chat.STORY, [meta.type, meta.name, meta.text].concat(cmds), cb||function(msg) { if (msg._can == sub && can.core.CallFunc([sub, chat.ONIMPORT, ice.MSG_PROCESS], {can: sub, msg: msg})) { return } }, true) }, can._plugins = (can._plugins||[]).concat([sub]) diff --git a/plugin/story/video.js b/plugin/story/video.js index 7b50c869..c75fb187 100644 --- a/plugin/story/video.js +++ b/plugin/story/video.js @@ -33,7 +33,7 @@ Volcanos(chat.ONACTION, { }) }, play: function(event, can) { - can.page.SelectAll(can, can._root._target, html.VIDEO, function(video) { + can.page.Select(can, can._root._target, html.VIDEO, function(video) { video.playbackRate = parseFloat(can.Option("rate")) video.currentTime = parseInt(can.Option("skip")) video.ontimeupdate = function(event) { can.misc.Event(event, can, function(msg) { diff --git a/proto.js b/proto.js index 0c5c4ed2..944179d2 100644 --- a/proto.js +++ b/proto.js @@ -70,7 +70,7 @@ var mdb = { MAIN: "main", PAGE: "page", NEXT: "next", PREV: "prev", LIMIT: "limit", OFFEND: "offend", FOREACH: "*", RANDOMS: "%", } -var web = { +var web = {CHAT: "chat", SHARE: "share", SPACE: "space", DREAM: "dream", WEBSITE: "website", DRAW: "draw", CLEAR: "clear", REFRESH: "refresh", RESIZE: "resize", FILTER: "filter", CANCEL: "cancel", SUBMIT: "submit", UPLOAD: "upload", DOWNLOAD: "download", TOIMAGE: "toimage", @@ -128,6 +128,7 @@ var code = { FAVOR: "favor", XTERM: "xterm", INNER: "inner", VIMER: "vimer", WEBPACK: "webpack", BINPACK: "binpack", AUTOGEN: "autogen", COMPILE: "compile", PUBLISH: "publish", COMMENT: "comment", KEYWORD: "keyword", PACKAGE: "package", DATATYPE: "datatype", FUNCTION: "function", CONSTANT: "constant", STRING: "string", OBJECT: "object", + SPACE: "space", UNDEFINED: "undefined", STRING: "string", NUMBER: "number", BOOLEAN: "boolean", FUNCTION: "function", OBJECT: "object", ARRAY: "array", TEMPLATE: "template", COMPLETE: "complete", NAVIGATE: "navigate", CURRENT: "current", } var wiki = { @@ -294,15 +295,15 @@ var Volcanos = shy({version: window._version||"", iceberg: "/chat/", volcano: "/ } can.runAction(event, cmds[1], cmds.slice(2), cb, true) }, runActionCommand: function(event, index, args, cb) { can.request(event)._caller() - can.runAction(event, ice.RUN, can.misc.concat(can, [index], args), cb, true) + can.runAction(event, ice.RUN, [index].concat(args), cb, true) }, runAction: function(event, action, args, cb, silent) { can.request(event, {_handle: ice.TRUE}, can.Option())._caller() - can.run(event, can.misc.concat(can, [ctx.ACTION].concat(action), args), cb, silent) + can.run(event, [ctx.ACTION].concat(action, args), cb, silent) }, search: function(event, cmds, cb) { if (cmds && typeof cmds == lang.OBJECT && cmds.length > 0 && typeof cmds[0] == lang.OBJECT && cmds[0].length > 0 ) { cmds[0] = cmds[0].join(ice.PT) } - return can.run && can.run(event, [chat._SEARCH].concat(cmds), cb, true) + return (can._root||can).run(event, [chat._SEARCH].concat(cmds), cb, true) }, get: function(name, key, cb) { var value; can.search({}, [can.core.Keys(name, chat.ONEXPORT, key)], cb||function(msg) { value = msg.Result() }); return value }, set: function(name, key, value) { var msg = can.request(); msg.Option(key, value); return can.search(msg, [[name, chat.ONIMPORT, key]]) }, @@ -337,9 +338,11 @@ var Volcanos = shy({version: window._version||"", iceberg: "/chat/", volcano: "/ }) try { if (typeof(window) == lang.OBJECT) { // chrome Volcanos.meta.target = document.body, Volcanos.meta._height = window.innerHeight, Volcanos.meta._width = window.innerWidth - Volcanos.meta._load = function(url, cb) { switch (url.split("?")[0].split(ice.PT).pop().toLowerCase()) { - case nfs.CSS: var item = document.createElement(mdb.LINK); item.href = url+Volcanos.meta.version, item.rel = "stylesheet", item.onload = cb, document.head.appendChild(item); break - case nfs.JS: var item = document.createElement(nfs.SCRIPT); item.src = url+Volcanos.meta.version, item.onerror = cb, item.onload = cb, document.body.appendChild(item); break + Volcanos.meta._load = function(url, cb) { + var v = Volcanos.meta.version? Volcanos.meta.version+"&_tt="+(new Date()).getTime(): "" + switch (url.split("?")[0].split(ice.PT).pop().toLowerCase()) { + case nfs.CSS: var item = document.createElement(mdb.LINK); item.href = url+v, item.rel = "stylesheet", item.onload = cb, document.head.appendChild(item); break + case nfs.JS: var item = document.createElement(nfs.SCRIPT); item.src = url+v, item.onerror = cb, item.onload = cb, document.body.appendChild(item); break } } window.onerror = function(message, source, lineno, colno, error) { window._version && alert([[source, lineno, colno].join(ice.DF), message].join(ice.NL)) } Volcanos.meta._init = function(can) { window.onerror = function(message, source, lineno, colno, error) { can.misc.Error(message, source, lineno, colno, error) } diff --git a/publish/chrome/contexts.js b/publish/chrome/contexts.js index 58f30b4b..b550fd29 100644 --- a/publish/chrome/contexts.js +++ b/publish/chrome/contexts.js @@ -93,7 +93,7 @@ setTimeout(function() { Volcanos({ }, }, function(can) { can.run = function(event, cmds, cb) { if (cmds[0] == "_search") { return } - var msg = can.request(event, {domain: location.host}); msg.detail = can.misc.concat(can, ["page"], cmds) + var msg = can.request(event, {domain: location.host}); msg.detail = ["page"].concat(cmds) chrome.runtime.sendMessage(msg, function(res) { can.base.isFunc(cb) && cb(msg.Copy(res)) }) }, can._motion(can), can._daemon(can) }) }, 100)