diff --git a/frame.js b/frame.js index e7145f50..c8211358 100644 --- a/frame.js +++ b/frame.js @@ -68,7 +68,7 @@ Volcanos("onengine", {help: "搜索引擎", list: [], _init: function(can, meta, }), }) Volcanos("ondaemon", {help: "推荐引擎", list: [], _init: function(can, name) { if (can.user.isLocalFile) { return } - can.misc.WSS(can, {type: "chrome", name: can.user.Search(can, "daemon")||name||""}, function(event, msg, cmd, arg) { if (!msg) { return } + can.misc.WSS(can, {type: "chrome", name: can.misc.Search(can, "daemon")||name||""}, function(event, msg, cmd, arg) { if (!msg) { return } can.base.isFunc(can.ondaemon[cmd])? can.core.CallFunc(can.ondaemon[cmd], { "can": can, "msg": msg, "cmd": cmd, "arg": arg, "cb": function() { msg.Reply() }, }): can.onengine._search({}, can, msg, can, ["_search", cmd].concat(arg), function() { @@ -274,7 +274,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, if (key == "extra.cmd") { can.onappend.plugin(can, {ctx: line["extra.ctx"], cmd: line["extra.cmd"], arg: line["extra.arg"]}, function(sub) { sub.run = function(event, cmds, cb) { var msg = can.request(event, line, can.Option()) - can.run(event, can.misc.Concat([ctx.ACTION, ice.RUN, can.core.Keys(line["extra.ctx"], line["extra.cmd"])], cmds), cb, true) + can.run(event, can.misc.concat([ctx.ACTION, ice.RUN, can.core.Keys(line["extra.ctx"], line["extra.cmd"])], cmds), cb, true) } }, target) } @@ -351,7 +351,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, meta.type = meta.type||chat.PLUGIN can.onappend._init(can, meta, ["/plugin/state.js"], function(sub, skip) { - sub.run = function(event, cmds, cb) { can.run(event, can.misc.Concat([ctx.ACTION, ice.RUN, meta.index], cmds), cb) } + sub.run = function(event, cmds, cb) { can.run(event, can.misc.concat([ctx.ACTION, ice.RUN, meta.index], cmds), cb) } can.base.isFunc(cb) && cb(sub, meta, skip) }, target||can._output) }, @@ -432,7 +432,7 @@ Volcanos("onlayout", {help: "页面布局", list: [], _init: function(can, targe can.onengine.signal(can, chat.ONSIZE, can.request({}, {width: width, height: height})) }, topic: function(can, topic) { topic && (can._topic = topic) - can.user.topic(can, can._topic || can.user.Search(can, chat.TOPIC) || ((can.base.isNight()||can.user.mod.isPod)? chat.BLACK: chat.WHITE)) + can.user.topic(can, can._topic || can.misc.Search(can, chat.TOPIC) || ((can.base.isNight()||can.user.mod.isPod)? chat.BLACK: chat.WHITE)) can.page.ClassList.add(can, document.body, can.user.language(can)) }, background: function(can, url, target) { diff --git a/lib/base.js b/lib/base.js index 59a7551d..29b13770 100644 --- a/lib/base.js +++ b/lib/base.js @@ -1,17 +1,17 @@ Volcanos("base", {help: "数据类型", - Int: function(value, def) { - return parseInt(value)||def||0 + Int: function(val, def) { + return parseInt(val)||def||0 }, - Obj: function(value, def) { + Obj: function(val, def) { try { - value = typeof value == lang.STRING && value != ""? JSON.parse(value): value - if (value && value.length == 0 && def && def.length > 0) { return def } - return value||def + val = typeof val == lang.STRING && val != ""? JSON.parse(val): val + if (val && val.length == 0 && def && def.length > 0) { return def } + return val||def } catch (e) { - return [value] + return [val] } }, - Copy: function(to, from, fields) { + Copy: function(to, from) { if (arguments.length == 2) { for (var k in from) { to[k] = from[k] } return to @@ -20,7 +20,6 @@ Volcanos("base", {help: "数据类型", var list = []; for (var i = 2; i < arguments.length; i++) { list.push(arguments[i]) } - for (var i = 0; i < list.length; i++) { to[list[i]] = from[list[i]] } @@ -29,12 +28,11 @@ Volcanos("base", {help: "数据类型", Eq: function(to, from) { var self = arguments.callee if (typeof to != typeof from) { return false } - if (typeof to == "object") { + if (typeof to == lang.OBJECT) { if (to.length != from.length) { return false } for (var i = 0; i < to.length; i++) { if (!self(to[i], from[i])) { return false } } - for (var k in to) { if (!self(to[k], from[k])) { return false } } @@ -44,11 +42,11 @@ Volcanos("base", {help: "数据类型", }, Ext: function(file) { - return (file.split("/").pop().split(".").pop()).toLowerCase() + return (file.split(ice.PT).pop().split(ice.PT).pop()).toLowerCase() }, - Path: function() { var res = "" + Path: function(str) { var res = "" for (var i = 0; i < arguments.length; i++) { - res += (arguments[i][0]=="/" || res=="" || res[res.length-1]=="/"? "": "/") + arguments[i].trim() + res += (arguments[i][0]==ice.PS || res=="" || res[res.length-1]==ice.PS? "": ice.PS) + arguments[i].trim() } return res }, @@ -58,25 +56,18 @@ Volcanos("base", {help: "数据类型", } return res.join("&") }, - ParseURL: function(url) { var res = {link: url} - var list = url.split("?"); res["origin"] = list[0] - list[1] && list[1].split("&").forEach(function(item) { - var ls = item.split("="); res[decodeURIComponent(ls[0])] = decodeURIComponent(ls[1]) - }) - return res - }, - MergeURL: function(url) { var args = {} - var arg = url.split("?")[1]||"" + MergeURL: function(str) { var args = {} + var arg = str.split("?")[1]||"" arg && arg.split("&").forEach(function(item) { var ls = item.split("=") args[decodeURIComponent(ls[0])] = decodeURIComponent(ls[1]) }) for (var i = 1; i < arguments.length; i++) { switch (typeof arguments[i]) { - case "string": + case lang.STRING: args[arguments[i]] = arguments[i+1], i++ break - case "object": + case lang.OBJECT: if (arguments[i].length > 0) { for (var j = 0; j < arguments[i].length; j += 2) { args[arguments[i][j]] = arguments[i][j] @@ -92,50 +83,75 @@ Volcanos("base", {help: "数据类型", var list = []; for (var k in args) { list.push(encodeURIComponent(k)+"="+encodeURIComponent(args[k])) } - return url.split("?")[0]+(list.length>0? "?"+list.join("&"): "") + return str.split("?")[0]+(list.length>0? "?"+list.join("&"): "") + }, + ParseURL: function(str) { var res = {link: str} + var list = str.split("?"); res["origin"] = list[0] + list[1] && list[1].split("&").forEach(function(item) { + var ls = item.split("="); res[decodeURIComponent(ls[0])] = decodeURIComponent(ls[1]) + }) + return res + }, + ParseJSON: function(str) { var res + if (typeof str == lang.OBJECT) { return str } + if (str.indexOf("http") == 0) { var ls = str.split("?") + res = {type: "link", name: "", text: str} + res.name = ls[0].split("://").pop().split(ice.PS)[0] + ls[1] && ls[1].split("&").forEach(function(item) { var ls = item.split("=") + res[decodeURIComponent(ls[0])] = decodeURIComponent(ls[1]) + }) + return res + } + try { res = JSON.parse(str) + res.text = res.text||str + res.type = res.type||"json" + } catch (e) { + res = {type: "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 + } + return parseInt(size) }, - Size: function(size) {size = parseInt(size) + Size: function(size) { size = parseInt(size) if (size > 1000000000) { - return parseInt(size / 1000000000) + "." + parseInt(size / 10000000 % 100) + "G" + return parseInt(size/1000000000) + ice.PT + parseInt(size/10000000%100) + "G" } if (size > 1000000) { - return parseInt(size / 1000000) + "." + parseInt(size / 10000 % 100) + "M" + return parseInt(size/1000000) + ice.PT + parseInt(size/10000%100) + "M" } if (size > 1000) { - return parseInt(size / 1000) + "." + parseInt(size / 10 % 100) + "K" + return parseInt(size/1000) + ice.PT + parseInt(size/10%100) + "K" } return size + "B" }, Number: function(d, n) { var result = [] - while (d > 0) { result.push(d % 10); d = parseInt(d / 10); n-- } + while (d > 0) { result.push(d%10); d = parseInt(d/10); n-- } while (n > 0) { result.push("0"); n-- } return result.reverse(), result.join("") }, Format: function(obj) { return JSON.stringify(obj) }, - endWith: function(str, end) { - return str.lastIndexOf(end) + end.length == str.length - }, - trimPrefix: function(str, pre) { - if (str.indexOf(pre) == -1) { - return str - } - return str.slice(pre.length) - }, - trimSuffix: function(str, end) { - if (str.indexOf(end) == -1) { - return str - } - return str.slice(0, str.indexOf(end)) - }, Simple: function() { var res = [] for (var i = 0; i < arguments.length; i++) { var arg = arguments[i]; switch (typeof arguments[i]) { - case "number": res.push(arg); break - case "string": res.push(arg); break - case "object": + case lang.NUMBER: res.push(arg); break + case lang.STRING: res.push(arg); break + case lang.OBJECT: if (arg.length > 0) { res = res.concat(arg); break } for (var k in arg) { k && arg[k] && res.push(k, arg[k]) } break @@ -144,12 +160,12 @@ Volcanos("base", {help: "数据类型", } return res }, - AddUniq: function(list, value) { list = list || [] + AddUniq: function(list, value) { list = list||[] return list.indexOf(value) == -1 && list.push(value), list }, Date: function(time) { var now = new Date() - if (typeof time == "string" && time != "") { var ls = time.split(" ") + 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) @@ -184,59 +200,42 @@ Volcanos("base", {help: "数据类型", h = parseInt(n/3600000), h > 0 && (res += h+"h"), n = n % 3600000 h = parseInt(n/60000), h > 0 && (res += h+"m"), n = n % 60000 h = parseInt(n/1000), h > 0 && (res += h), n = n % 1000 - return res + (n > 0? "."+parseInt(n/10): "") + "s" + return res + (n > 0? ice.PT+parseInt(n/10): "") + "s" }, - 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 - } - return parseInt(size) - }, - parseJSON: function(str) { var res - if (typeof str == "object") { return str } - if (str.indexOf("http") == 0) { var ls = str.split("?") - res = {type: "link", name: "", text: str} - res.name = ls[0].split("://").pop().split("/")[0] - ls[1] && ls[1].split("&").forEach(function(item) { var ls = item.split("=") - res[decodeURIComponent(ls[0])] = decodeURIComponent(ls[1]) - }) - return res - } - try { res = JSON.parse(str) - res.text = res.text||str - res.type = res.type||"json" - } catch (e) { - res = {type: "text", text: str} - } - return res - }, + 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(cb) { return typeof cb == lang.FUNCTION }, + isFunction: function(val) { return typeof val == lang.FUNCTION }, + isCallback: function(key, value) { return key.indexOf("on") == 0 && typeof value == lang.FUNCTION }, + isUndefined: function(val) { return val == undefined }, + isNull: function(val) { return val == null }, + isNight: function() { var now = new Date() return now.getHours() < 7 || now.getHours() > 17 }, - - join: function(list, sp) { return (list||[]).join(sp||" ") }, + endWith: function(str, end) { + return str.lastIndexOf(end) + end.length == str.length + }, trim: function(args) { if (this.isString(args)) { return args.trim() } if (this.isArray(args)) { for (var i = args.length-1; i >= 0; i--) { if (!args[i]) { args.pop() } else { break } } } return args }, - isString: function(arg) { return typeof arg == "string" }, - isObject: function(arg) { return typeof arg == "object" }, - isArray: function(arg) { return typeof arg == "object" && arg.length != undefined }, - isFunction: function(arg) { return typeof arg == "function" }, - isCallback: function(key, value) { return key.indexOf("on") == 0 && can.base.isFunc(value) }, - isFunc: function(cb) { return typeof cb == "function" }, - isUndefined: function(arg) { return arg == undefined }, - isNull: function(arg) { return arg == null }, + trimPrefix: function(str, pre) { + if (str.indexOf(pre) == -1) { + return str + } + return str.slice(pre.length) + }, + trimSuffix: function(str, end) { + if (str.indexOf(end) == -1) { + return str + } + return str.slice(0, str.indexOf(end)) + }, + join: function(list, sp) { return (list||[]).join(sp||ice.SP) }, joins: function(list) { for (var i = 0; i < list.length; i++) { list[i] = typeof list[i] == lang.STRING? list[i]: list[i].join(ice.FS) diff --git a/lib/core.js b/lib/core.js index d37d6ca2..31e251cb 100644 --- a/lib/core.js +++ b/lib/core.js @@ -2,22 +2,22 @@ Volcanos("core", {help: "数据结构", Keys: shy("连接器", function() { var list = [] for (var i = 0; i < arguments.length; i++) { var v = arguments[i] switch (typeof v) { - case "object": + case lang.OBJECT: for (var j = 0; j < v.length; j++) { list.push(v[j]) } break - case "function": v = v() + case lang.FUNCTION: v = v() default: v && list.push(v+"") } } - return list.join(".") + return list.join(ice.PT) }), Value: shy("存储器", function(data, key, value) { if (data == undefined) { return } if (key == undefined) { return data } - if (typeof key == "object") { for (var k in key) { + if (typeof key == lang.OBJECT) { for (var k in key) { arguments.callee.call(this, data, k, key[k]) }; return data } @@ -31,7 +31,7 @@ Volcanos("core", {help: "数据结构", }), Split: shy("分词器", function(str) { if (!str || !str.length) { return [] } var opt = {detail: false}, arg = []; for (var i = 1; i < arguments.length; i++) { - typeof arguments[i] == "object"? opt = arguments[i]: arg.push(arguments[i]) + typeof arguments[i] == lang.OBJECT? opt = arguments[i]: arg.push(arguments[i]) } // 字符定义 @@ -42,7 +42,7 @@ Volcanos("core", {help: "数据结构", var sups = _list(arg[2]||"'\"`") // 引用符 var res = [], begin = 0; function push(obj) { - obj && res.push(typeof obj == "string" || opt.detail? obj: obj.text), begin = -1 + obj && res.push(typeof obj == lang.STRING || opt.detail? obj: obj.text), begin = -1 } // 开始分词 @@ -64,7 +64,7 @@ Volcanos("core", {help: "数据结构", if (s == "") { s = str[i], begin = i+1 } else if (s == str[i]) { - push({type: "string", text: str.slice(begin, i), left: s, right: str[i]}) + push({type: lang.STRING, text: str.slice(begin, i), left: s, right: str[i]}) s = "", begin = -1 } @@ -74,21 +74,20 @@ Volcanos("core", {help: "数据结构", } // 剩余字符 - // begin > 0 && (s? push({type: "string", text: str.slice(begin), left: s, right: ""}) - begin >= 0 && (s? push({type: "string", text: str.slice(begin), left: s, right: ""}): push(str.slice(begin))) + begin >= 0 && (s? push({type: lang.STRING, text: str.slice(begin), left: s, right: ""}): push(str.slice(begin))) return res }), CallFunc: shy("调用器", function(func, args, mod) { args = args||{} var can = args["can"]||args[0], msg = args["msg"]||args[1], cmds = args["cmds"]||[] // 查找调用 - func = typeof func == "function"? func: typeof func == "string"? this.Value(mod||can, func): - typeof func == "object" && func.length > 0? this.Value(func[0], this.Keys(func.slice(1))): null - if (typeof func != "function") { return } + func = typeof func == lang.FUNCTION? func: typeof func == lang.STRING? this.Value(mod||can, func): + typeof func == lang.OBJECT && func.length > 0? this.Value(func[0], this.Keys(func.slice(1))): null + if (typeof func != lang.FUNCTION) { return } // 解析参数 var list = [], echo = false, cb = args["cb"] - this.List(func.toString().split(")")[0].split("(")[1].split(","), function(item, index) { item = item.trim(); if (item == "") { return } + this.List(func.toString().split(")")[0].split("(")[1].split(ice.FS), function(item, index) { item = item.trim(); if (item == "") { return } var arg = msg&&msg.Option&&msg.Option(item) || event&&!(event instanceof Event)&&event[item] || args[item] || can&&can.Conf&&can.Conf(item) || args[index] || cmds[index] || null if (item == "cb") { echo = true } @@ -99,17 +98,17 @@ Volcanos("core", {help: "数据结构", var res = func.apply(mod||can, list) // 执行回调 - if (!echo && typeof cb == "function") { res && msg && msg.Echo(res), arguments.callee.apply(this, [cb, {msg: msg, res: res}]) } + if (!echo && typeof cb == lang.FUNCTION) { res && msg && msg.Echo(res), arguments.callee.apply(this, [cb, {msg: msg, res: res}]) } return res }), List: shy("迭代器", function(list, cb, interval, cbs) { - if (typeof list == "string") { // 默认序列 + if (typeof list == lang.STRING) { // 默认序列 list = [list] - } else if (typeof list == "number") { // 等差序列 - var begin = 0, end = list, step = typeof interval == "number"? interval: 1 - if (typeof cb == "number") { begin = list, end = cb, cb = null } + } else if (typeof list == lang.NUMBER) { // 等差序列 + 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) @@ -119,14 +118,14 @@ Volcanos("core", {help: "数据结构", list = list || [] if (interval > 0) { // 时间序列 - function loop(i) { if (i >= list.length) { return typeof cbs == "function" && cbs(list) } + function loop(i) { if (i >= list.length) { return typeof cbs == lang.FUNCTION && cbs(list) } cb(list[i], i, list), setTimeout(function() { loop(i+1) }, interval) } - typeof cb == "function" && list.length > 0 && setTimeout(function() { loop(0) }, interval/4) + typeof cb == lang.FUNCTION && list.length > 0 && setTimeout(function() { loop(0) }, interval/4) } else { // 选择序列 var slice = [], res for (var i = 0; i < list.length; i++) { - typeof cb == "function"? (res = cb(list[i], i, list)) != undefined && slice.push(res): slice.push(list[i]) + typeof cb == lang.FUNCTION? (res = cb(list[i], i, list)) != undefined && slice.push(res): slice.push(list[i]) }; list = slice } return list @@ -135,49 +134,29 @@ Volcanos("core", {help: "数据结构", function next(i) { i < list.length? cb(list[i], function() { next(i+1) - }, i, list): typeof cbs == "function" && cbs(list) + }, i, list): typeof cbs == lang.FUNCTION && cbs(list) } switch (typeof list) { - case "undefined": list = []; break - case "object": break + case undefined: list = []; break + case lang.OBJECT: break default: list = [list] } - list && list.length > 0 && typeof cb == "function"? next(0): typeof cbs == "function" && cbs(list) - }), - Timer: shy("定时器, value, [1,2,3,4], {interval, length}", function(interval, cb, cbs) { - var timer = {stop: false}; function loop(i) { - timer.stop || i >= interval.length && interval.length >= 0 || cb(timer, interval.interval||interval[i], i, interval)? - typeof cbs == "function" && cbs(timer, interval): setTimeout(function() { loop(i+1) }, interval.interval||interval[i+1]) - } - - interval = typeof interval == "object"? interval: [interval] - if (interval.interval == 0) { cb(); return timer } - - typeof cb == "function" && setTimeout(function() { loop(0) }, interval.interval||interval[0]) - return timer - }), - Timer300ms: function(cb) { this.Timer(300, cb) }, - Delay: shy("延时器", function(list, interval, cb, cbs) { list = list || [] - list.push(cb); this.Timer(interval, function() { - var cb = list.pop(); list.length = 0 - typeof cb == "function" && cb() - }, cbs) - return list + list && list.length > 0 && typeof cb == lang.FUNCTION? next(0): typeof cbs == lang.FUNCTION && cbs(list) }), Items: shy("迭代器", function(obj, cb) { var list = [] for (var k in obj) { list = list.concat(this.List(obj[k], function(v, i) { - return typeof cb == "function" && cb(v, i, k, obj) + return typeof cb == lang.FUNCTION && cb(v, i, k, obj) })) } return list }), Item: shy("迭代器", function(obj, cb) { var list = [] for (var k in obj) { - var res = typeof cb == "function"? cb(k, obj[k]): k + var res = typeof cb == lang.FUNCTION? cb(k, obj[k]): k res != undefined && list.push(res) } return list @@ -195,5 +174,26 @@ Volcanos("core", {help: "数据结构", })(k) } return list }), + + Timer300ms: function(cb) { this.Timer(300, cb) }, + Timer: shy("定时器, value, [1,2,3,4], {interval, length}", function(interval, cb, cbs) { + var timer = {stop: false}; function loop(i) { + timer.stop || i >= interval.length && interval.length >= 0 || cb(timer, interval.interval||interval[i], i, interval)? + typeof cbs == lang.FUNCTION && cbs(timer, interval): setTimeout(function() { loop(i+1) }, interval.interval||interval[i+1]) + } + + interval = typeof interval == lang.OBJECT? interval: [interval] + if (interval.interval == 0) { cb(); return timer } + + typeof cb == lang.FUNCTION && setTimeout(function() { loop(0) }, interval.interval||interval[0]) + return timer + }), + Delay: shy("延时器", function(list, interval, cb, cbs) { list = list || [] + list.push(cb); this.Timer(interval, function() { + var cb = list.pop(); list.length = 0 + typeof cb == lang.FUNCTION && cb() + }, cbs) + return list + }), }) diff --git a/lib/misc.js b/lib/misc.js index 75e8325f..bb2b8383 100644 --- a/lib/misc.js +++ b/lib/misc.js @@ -6,17 +6,17 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg } return false }, - OptionStatus: function() { return msg.Option("_status") }, - OptionProcess: function() { return msg.Option("_process") }, + OptionStatus: function() { return msg.Option(ice.MSG_STATUS) }, + OptionProcess: function() { return msg.Option(ice.MSG_PROCESS) }, Option: function(key, val) { if (key == undefined) { return msg && msg.option || [] } - if (typeof key == "object") { can.core.Item(key, msg.Option) } + if (can.base.isObject(key)) { can.core.Item(key, msg.Option) } if (val == undefined) { return msg && 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 && msg.append || [] } - if (typeof key == "object") { can.core.Item(key, 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 }, @@ -39,8 +39,8 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg }) }, Clear: function(key) { switch (key) { - case "append": - case "option": + case ice.MSG_APPEND: + case ice.MSG_OPTION: can.core.List(msg[key], function(item) { delete(msg[item]) }) default: msg[key] = [] } }, @@ -61,16 +61,16 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg return msg }, Push: function(key, value, detail) { - if (typeof key == "object") { + if (can.base.isObject(key)) { value = value || can.core.Item(key), can.core.List(value, function(item) { - detail? msg.Push("key", item).Push("value", key[item]||""): + detail? msg.Push(kit.MDB_KEY, item).Push(kit.MDB_VALUE, key[item]||""): msg.Push(item, key[item]||"") }) return msg } msg.append = can.base.AddUniq(msg.append, key), msg[key] = msg[key] || [] - msg[key].push(typeof value == "string" || typeof value == "function"? value: JSON.stringify(value)) + msg[key].push(can.base.isString(value)||can.base.isFunction(value)? value: JSON.stringify(value)) return msg }, Echo: function(res) { msg.result = msg.result || [] @@ -96,16 +96,13 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg if (msg._upload) { // 上传文件 var data = new FormData(); can.core.Items(form, function(value, index, key) { data.append(key, value) - }), data.append("upload", msg._upload), data.append("_upload", "some") + }), data.append(html.UPLOAD, msg._upload), data.append(ice.MSG_UPLOAD, "some") xhr.upload.onprogress = function(event) { can.base.isFunc(msg._progress) && msg._progress(event, parseInt(event.loaded*100/event.total), event.total, event.loaded) } } else { // 请求数据 - var data = can.core.Items(form, function(value, index, key) { - return key+"="+encodeURIComponent(value) - }).join("&") - + var data = can.core.Items(form, function(value, index, key) { return key+"="+encodeURIComponent(value) }).join("&") xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") } @@ -114,14 +111,13 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg try { xhr.send(data) } catch(e) { can.misc.Log(e) } }, Run: function(event, can, dataset, cmds, cb) { - var skip = {_handle: true} - var msg = can.request(event||{}) + var msg = can.request(event||{}), skip = {_handle: true} var form = {cmds: cmds||msg.cmd}; msg.option && msg.option.forEach(function(item) { !skip[item] && msg[item] && (form[item] = msg[item]) }) can.misc.POST(can, msg, can.base.MergeURL(dataset.names.toLowerCase(), - "_", (msg._can.sup||msg._can)._name, "_daemon", msg.__daemon||dataset.daemon||"" + "_", (msg._can.sup||msg._can)._name, ice.MSG_DAEMON, msg.__daemon||dataset.daemon||"" ), form, cb) }, WSS: function(can, args, cb, onopen, onclose, onerror) { if (can.user.isIE) { return } @@ -129,14 +125,14 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg if (url.indexOf("chrome") == 0) { url = "ws://localhost:9020/space/" } var socket = new WebSocket(can.base.MergeURL(url, args)) - socket.onclose = function() { can.misc.Log("wss", "close", args) + socket.onclose = function() { can.misc.Log(html.WSS, cli.CLOSE, args) can.base.isFunc(onclose)? onclose(socket): can.core.Timer(1000, function() { can.misc.WSS(can, args, cb, onopen, onerror, onclose) }) - }, socket.onerror = function() { can.misc.Log("wss", "error", args) + }, socket.onerror = function() { can.misc.Log(html.WSS, cli.ERROR, args) can.base.isFunc(onerror)? onerror(socket): socket.close() - }, socket.onopen = function() { can.misc.Log("wss", "open", args) + }, socket.onopen = function() { can.misc.Log(html.WSS, cli.OPEN, args) can.base.isFunc(onopen) && onopen(socket) } @@ -150,8 +146,8 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg var msg = can.request(event); msg.Reply = function() { // 回复命令 msg.result = (msg.result||[]).concat(can.core.List(arguments)) - msg.Option({_handle: true, _source: (msg["_target"]||[]).reverse().slice(1).join(".")||"",_target: (msg["_source"]||[]).reverse().join(".")}) - can.misc.Log("wss", "result", msg.result, msg) + msg.Option({_handle: true, _source: (msg[ice.MSG_TARGET]||[]).reverse().slice(1).join(ice.PT)||"",_target: (msg[ice.MSG_SOURCE]||[]).reverse().join(".")}) + can.misc.Log(html.WSS, ice.MSG_RESULT, msg.result, msg) delete(msg._event), delete(msg._can) socket.send(JSON.stringify(msg)) @@ -159,7 +155,7 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg // 执行命令 try { - can.misc.Log("wss", "detail", msg.detail, msg) + can.misc.Log(html.WSS, ice.MSG_DETAIL, msg.detail, msg) can.base.isFunc(cb) && cb(event, msg, msg.detail[0], msg.detail.slice(1)) } catch (e) { // 执行失败 can.misc.Log(e), msg.Reply() @@ -167,7 +163,59 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg } }, - Concat: function(to, from) { + Cookie: shy("会话变量", function(can, key, value, path) { + function set(k, v) {document.cookie = k+"="+v+";path="+(path||ice.PS)} + + if (can.base.isObject(key)) { + for (var k in key) {set(k, key[k])} + key = null + } + if (key == undefined) {var cs = {} + document.cookie.split("; ").forEach(function(item) { + var cookie = item.split("=") + cs[cookie[0]] = cookie[1] + }) + return cs + } + + value != undefined && set(key, value) + var result = (new RegExp(key+"=([^;]*);?")).exec(document.cookie) + return result && result.length > 0? result[1]: "" + }), + Search: shy("请求参数", function(can, key, value) { var args = {} + if (value == undefined && can.base.isString(key)) { + var ls = location.pathname.split(ice.PS) + if (ls[1] == chat.SHARE) { args[chat.SHARE] = ls[2] } + if (ls[1] == "chat" && ls[2] == ice.POD) { args[ice.POD] = ls[3] } + } + + location.search && location.search.slice(1).split("&").forEach(function(item) { var x = item.split("=") + x[1] != "" && (args[x[0]] = decodeURIComponent(x[1])) + }) + + if (can.base.isObject(key)) { + can.core.Item(key, function(key, value) { + if (value != undefined) {args[key] = value} + args[key] == "" && delete(args[key]) + }) + } else if (key == undefined) { + return args + } else if (value == undefined) { + return args[key] + } else { + args[key] = value, args[key] == "" && delete(args[key]) + } + + return location.search = can.core.Item(args, function(key, value) { + return key+"="+encodeURIComponent(value) + }).join("&") + }), + MergeURL: shy("地址链接", function(can, objs, clear) { + var path = location.pathname; objs._path && (path = objs._path, delete(objs._path)) + return can.base.MergeURL(location.origin+path+(clear?"":location.search), objs) + }), + + concat: function(to, from) { if (from[0] == "_search") { return from } return to.concat(from) }, @@ -188,7 +236,7 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg Warn: function() { var args = [this._time(), this.FileLine(2, 3), "warn"] for (var i in arguments) { args.push(arguments[i]) } - args.push("\n", this._fileLine().split("\n").slice(2).join("\n")) + args.push(ice.NL, this._fileLine().split(ice.NL).slice(2).join(ice.NL)) console.log.apply(console, args) }, Debug: function() { @@ -196,13 +244,13 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg for (var i in arguments) { args.push(arguments[i]) } args.push(this.fileLine(2, 3)) console.log.apply(console, args) - navigator.userAgent.indexOf("Mobile") > -1 && alert(JSON.stringify(args.join(" "))) + navigator.userAgent.indexOf("Mobile") > -1 && alert(JSON.stringify(args.join(ice.SP))) }, FileLine: function(depth, length) { - return this.fileLine(depth+1).split("/").slice(3).slice(-length).join("/").split(")")[0] + return this.fileLine(depth+1).split(ice.PS).slice(3).slice(-length).join(ice.PS).split(")")[0] }, fileLine: function(depth) { - return (this._fileLine().split("\n")[1+depth]||"").trim() + return (this._fileLine().split(ice.NL)[1+depth]||"").trim() }, _fileLine: function() { var obj = {} Error.captureStackTrace && Error.captureStackTrace(obj, arguments.callee) diff --git a/lib/page.js b/lib/page.js index a1a20c52..0e69a9be 100644 --- a/lib/page.js +++ b/lib/page.js @@ -1,15 +1,15 @@ Volcanos("page", {help: "用户界面", ClassList: { - has: function(can, obj, key) { var list = obj.className? obj.className.split(" "): [] + has: function(can, obj, key) { var list = obj.className? obj.className.split(ice.SP): [] return list.indexOf(key) > -1 }, - add: function(can, obj, key) { var list = obj.className? obj.className.split(" "): [] - var value = can.base.AddUniq(list, key).join(" ").trim() + add: function(can, obj, key) { var list = obj.className? obj.className.split(ice.SP): [] + var value = can.base.AddUniq(list, key).join(ice.SP).trim() return value != obj.className && (obj.className = value), value }, - del: function(can, obj, key) { var list = obj.className? obj.className.split(" "): [] + 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(" ").trim() + }).join(ice.SP).trim() }, set: function(can, obj, key, condition) { condition? this.add(can, obj, key): this.del(can, obj, key) @@ -18,13 +18,28 @@ Volcanos("page", {help: "用户界面", ClassList: { return (this.has(can, obj, key)? this.del(can, obj, key): this.add(can, obj, key)).indexOf > -1 }, }, - Select: shy("选择节点", function(can, target, key, cb, interval, cbs) { if (key == ".") { cb(target); return [] } + SelectArgs: function(can, option, key, cb) { + 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))||"" + } } + 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) + }, + Select: shy("选择节点", function(can, target, key, cb, interval, cbs) { if (key == ice.PT) { cb(target); return [] } return can.core.List(target && target.querySelectorAll(key), cb, interval, cbs) }), - Modify: shy("修改节点", function(can, target, value) { target = target || {} - target = typeof target == "string"? document.querySelector(target): target - typeof value == "string"? (target.innerHTML = value): can.core.Item(value, function(key, val) { - typeof val != "object"? (target[key] = val): can.core.Item(val, function(k, v) { + Modify: shy("修改节点", function(can, target, value) { target = target||{} + target = can.base.isObject(target)? target: document.querySelector(target) + can.base.isString(value)? (target.innerHTML = value): can.core.Item(value, function(key, val) { + !can.base.isObject(val)? (target[key] = val): can.core.Item(val, function(k, v) { var size = { "width": true, "max-width": true, "min-width": true, "height": true, "max-height": true, "min-height": true, @@ -38,7 +53,7 @@ Volcanos("page", {help: "用户界面", ClassList: { "margin-top": true, "margin-left": true, } - if (size[k] && v && (typeof v == "number" || v.indexOf && v.indexOf("px") == -1)) { + if (size[k] && v && (can.base.isNumber(v) || v.indexOf && v.indexOf("px") == -1)) { v += "px" } target[key] && (target[key][k] = v) @@ -46,23 +61,22 @@ Volcanos("page", {help: "用户界面", ClassList: { }) return target }), - Create: shy("创建节点", function(can, key, value) { - return can.page.Modify(can, document.createElement(key), value) - }), Remove: shy("删除节点", function(can, target) { target && target.parentNode && target.parentNode.removeChild(target) }), - Append: shy("添加节点", function(can, target, key, value) { - if (typeof key == "string") { var res = can.page.Create(can, key, value); return target.appendChild(res), res } + Create: shy("创建节点", function(can, key, value) { + return can.page.Modify(can, document.createElement(key), value) + }), + Append: shy("添加节点", 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 } - value = value || {} can.core.List(key, function(item, index) { if (!item) { return } - if (typeof item == "string") { target.innerHTML = item; return } + if (can.base.isString(item)) { target.innerHTML = item; return } if (item.nodeName) { target.appendChild(item); return } // 基本结构: type name data list - var type = item.type || "div", data = item.data || {} - var name = item.name || data.name || "" + var type = item.type||html.DIV, data = item.data||{} + var name = item.name||data.name||"" // 数据调整 can.core.Item(item, function(key, value) { @@ -79,79 +93,79 @@ Volcanos("page", {help: "用户界面", ClassList: { if (item.view) { var list = can.core.List(item.view) list.length > 0 && list[0] && can.page.ClassList.add(can, data, list[0]) - type = list[1] || "div" - data.innerHTML = list[2] || data.innerHTML || "" - name = name || list[3] || "" + type = list[1]||html.DIV + data.innerHTML = list[2]||data.innerHTML||"" + name = name||list[3]||"" } else if (item.text) { var list = can.core.List(item.text) - data.innerHTML = list[0] || data.innerHTML || "" - type = list[1] || "span" + 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 = "button", name = name || list[0] + type = html.BUTTON, name = name||list[0] data.innerText = can.user.trans(can, list[0]), data.onclick = function(event) { - typeof list[1] == "function" && list[1](event, name) + can.base.isFunction(list[1]) && list[1](event, name) event.stopPropagation(), event.preventDefault() return true } } else if (item.select) { var list = item.select - type = "select", data.name = name = name || list[0][0] - data.title = can.user.trans(can, data.title || name) - data.className = data.className || list[0][0] || "" + type = html.SELECT, data.name = name = name||list[0][0] + data.title = can.user.trans(can, data.title||name) + data.className = data.className||list[0][0]||"" item.list = list[0].slice(1).map(function(value) { - return {type: "option", value: value, inner: can.user.trans(can, value)} + return {type: html.OPTION, value: value, inner: can.user.trans(can, value)} }) data.onchange = function(event) { - typeof list[1] == "function" && list[1](event, event.target.value, name) + can.base.isFunction(list[1]) && list[1](event, event.target.value, name) } } else if (item.input) { var list = can.core.List(item.input) - type = "input", name = name || list[0] || "", data.name = data.name || name - data.className = data.className || data.name + type = html.INPUT, name = name||list[0]||"", data.name = data.name||name + data.className = data.className||data.name data.autocomplete = "off" - data.onfocus = data.onfocus || function(event) { + data.onfocus = data.onfocus||function(event) { event.target.setSelectionRange(0, -1) } data.onkeydown = function(event) { - typeof list[1] == "function" && list[1](event) + can.base.isFunction(list[1]) && list[1](event) } data.onkeyup = function(event) { - typeof list[2] == "function" && list[2](event) + can.base.isFunction(list[2]) && list[2](event) } } else if (item.username) { var list = can.core.List(item.username) - type = "input", name = name || list[0] || "username", data.name = data.name || name - data.className = list[1] || data.className || data.name - data.autocomplete = data.autocomplete || "username" + type = html.INPUT, name = name||list[0]||html.USERNAME, data.name = data.name||name + data.className = list[1]||data.className||data.name + data.autocomplete = data.autocomplete||html.USERNAME } else if (item.password) { var list = can.core.List(item.password) - type = "input", name = name || list[0] || "password", data.name = data.name || name - data.className = list[1] || data.className || data.name - data.autocomplete = data.autocomplete || "current-password" - data.type = "password" + type = html.INPUT, name = name||list[0]||html.PASSWORD, data.name = data.name||name + data.className = list[1]||data.className||data.name + data.autocomplete = data.autocomplete||"current-password" + data.type = html.PASSWORD } else if (item.img) { var list = can.core.List(item.img) - type = "img", data.src = list[0] + type = html.IMG, data.src = list[0] - } else if (item.row) { type = "tr" - item.list = item.row.map(function(text) { return {text: [text, item.sub||"td"]} }) - } else if (item.th) { type = "tr" - item.list = item.th.map(function(text) { return {text: [text, "th"]} }) - } else if (item.td) { type = "tr" - item.list = item.td.map(function(text) { return {text: [text, "td"]} }) + } 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 == "input") { data.type == "button" && (data.value = can.user.trans(can, data.value)) - if (data.type == "text" || data.type == "password" || !data.type) { data.autocomplete = data.autocomplete||"off" - data.placeholder = can.user.trans(can, (data.placeholder||data.name||"").split(".").pop()) + if (type == html.INPUT) { data.type == html.BUTTON && (data.value = can.user.trans(can, data.value)) + if (data.type == html.TEXT||data.type == html.PASSWORD||!data.type) { data.autocomplete = data.autocomplete||"off" + data.placeholder = can.user.trans(can, (data.placeholder||data.name||"").split(ice.PT).pop()) data.title = can.user.trans(can, data.title||data.placeholder) } } - if (type == "textarea") { - data.placeholder = can.user.trans(can, (data.placeholder||data.name||"").split(".").pop()) + if (type == html.TEXTAREA) { + data.placeholder = can.user.trans(can, (data.placeholder||data.name||"").split(ice.PT).pop()) } // 创建节点 @@ -159,10 +173,10 @@ Volcanos("page", {help: "用户界面", ClassList: { var node = can.page.Create(can, type, data) // 创建索引 - name = name || data.className || type || "" + name = name||data.className||type||"" value[name||""] = value[data.className||""] = value[type] = node - value.first = value.first || node, value.last = node - value._target = value._target || node + value.first = value.first||node, value.last = node + value._target = value._target||node // 递归节点 item.list && can.page.Append(can, node, item.list, value) @@ -176,23 +190,23 @@ Volcanos("page", {help: "用户界面", ClassList: { }), AppendTable: shy("添加表格", function(can, msg, target, list, cb) { - if (!msg.append || msg.append.length == 0) {return} + if (!msg.append||msg.append.length == 0) {return} - var table = can.page.Append(can, target, "table") - can.page.Append(can, table, [{type: "tr", data: {dataset: {index: -1}}, list: + var table = can.page.Append(can, target, html.TABLE) + can.page.Append(can, table, [{type: html.TR, data: {dataset: {index: -1}}, list: can.core.List(list, function(key) { - return key[0] == "_"? undefined: {text: [key.trim(), "th"]} + return key[0] == "_"? undefined: {text: [key.trim(), html.TH]} }) }]) can.page.Append(can, table, can.core.List(msg.Table(), function(line, index, array) { - return {type: "tr", dataset: {index: index}, list: can.core.List(list, function(key) { if (key.indexOf("_") == 0) { return } + return {type: html.TR, dataset: {index: index}, list: can.core.List(list, function(key) { if (key.indexOf("_") == 0) { return } return 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, "th", function(th, index) { + can.page.Select(can, table, html.TH, function(th, index) { th.onclick = function(event) { var dataset = event.target.dataset dataset["sort_asc"] = (dataset["sort_asc"] == "1") ? 0: 1 can.page.RangeTable(can, table, index, dataset["sort_asc"] == "1") @@ -201,11 +215,11 @@ Volcanos("page", {help: "用户界面", ClassList: { return table }, RangeTable: function(can, table, index, sort_asc) { - var list = can.page.Select(can, table, "tr", function(tr) { - return tr.style.display == "none" || can.page.ClassList.has(can, tr, "hide")? null: tr + var list = can.page.Select(can, table, html.TR, function(tr) { + return tr.style.display == html.NONE||can.page.ClassList.has(can, tr, "hide")? null: tr }).slice(1) - index = typeof index == "object"? index: [index] + index = can.base.isObject(index)? index: [index] index = can.core.List(index, function(item) { if (item > -1) { return item} }) if (index.length == 0) { return } @@ -219,7 +233,7 @@ Volcanos("page", {help: "用户界面", ClassList: { var num_list = can.core.List(list, function(tr) { var text = tr.childNodes[index[0]].innerText return is_time? Date.parse(text): - is_number? can.base.parseSize(text): text + is_number? can.base.ParseSize(text): text }) function isless(a, b, index) { if (a.childNodes[index[0]] && b.childNodes[index[0]]) { @@ -252,16 +266,36 @@ Volcanos("page", {help: "用户界面", ClassList: { } }, - Format: function(type, src) { + Cache: function(name, output, data) { 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 + }, + Format: function(type) { switch (type) { - case "a": return ""+(arguments[2]||arguments[1])+"" - case "img": return arguments[2]? "": "" + case html.A: return ""+(arguments[2]||arguments[1])+"" + case html.IMG: return arguments[2]? "": "" } }, - Color: function(text) { if (typeof text != "string") { return "" } + Color: function(text) { if (typeof text != lang.STRING) { return "" } if (text.indexOf("http://") == 0 || text.indexOf("https://") == 0 || text.indexOf("ftp://") == 0) { - var ls = text.split(" "); - text = ""+ls[0]+""+ls.slice(1).join(" ") + var ls = text.split(ice.SP); + text = ""+ls[0]+""+ls.slice(1).join(ice.SP) }; text = text.replace(/\\n/g, "
") if (text.indexOf("\033\[") == -1) { return text } @@ -277,48 +311,26 @@ Volcanos("page", {help: "用户界面", ClassList: { text = text.replace(/\033\[m/g, "") return text }, - Cache: function(name, output, data) { 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 - }, - input: function(can, item, value) { var input = {type: html.INPUT, name: item.name, data: item, dataset: {}, _init: item._init, style: item.style||{}} - item.value == "auto" && (item.value = "", item.action = "auto"), item.action == "auto" && (input.dataset.action = "auto") + 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(["feature", html.TEXTAREA, item.name, "height"].join("."))||can.Conf(["feature", html.TEXTAREA, "height"].join(".")) - input.style.width = input.style.width||can.Conf(["feature", html.TEXTAREA, item.name, "width"].join("."))||can.Conf(["feature", html.TEXTAREA, "width"].join(".")) + input.style.height = input.style.height||can.Conf(["feature", html.TEXTAREA, item.name, html.HEIGHT].join(ice.PT))||can.Conf(["feature", html.TEXTAREA, html.HEIGHT].join(ice.PT)) + input.style.width = input.style.width||can.Conf(["feature", html.TEXTAREA, item.name, html.WIDTH].join(ice.PT))||can.Conf(["feature", html.TEXTAREA, html.WIDTH].join(ice.PT)) // no break - case "password": + case html.PASSWORD: // no break case html.TEXT: - if (item.username) { item.type = "text"; return item } + if (item.username) { item.type = html.TEXT; return item } if (item.password) { return item } item.autocomplete = "off" item.value = value||item.value||"" item.className || can.page.ClassList.add(can, item, "args") break case html.SELECT: input.type = html.SELECT - item.values = typeof item.values == "string"? can.core.Split(item.values): item.values + 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] } item.value = value||item.value, input.list = item.values.map(function(value) { @@ -327,26 +339,10 @@ Volcanos("page", {help: "用户界面", ClassList: { break case html.BUTTON: item.value = item.value||item.name||"list"; break case "upfile": item.type = html.FILE; break - case "upload": item.type = html.FILE, input.name = "upload"; break + case html.UPLOAD: item.type = html.FILE, input.name = html.UPLOAD; break default: } return input }, - - SelectArgs: function(can, option, key, cb) { - 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 == "button" ) { return } - return item.name && (can.base.isUndefined(value)? item.value: (item.value = value)) || "" - } } - if (key.indexOf(".") > -1) { return [""]} - return can.page.Select(can, option, key? "textarea[name="+key+"],"+"input[name="+key+"],"+"select[name="+key+"]": ".args", cb) - }, }) diff --git a/lib/user.js b/lib/user.js index 4e9c1ddb..8380df2c 100644 --- a/lib/user.js +++ b/lib/user.js @@ -1,33 +1,33 @@ Volcanos("user", {help: "用户操作", agent: { scanQRCode: function(cb, can) { - can.user.input(event, can, [{type: "textarea", name: "text", text: ""}], function(ev, button, data, list, args) { - cb(list[0], can.base.parseJSON(list[0])) + can.user.input(event, can, [{type: html.TEXTAREA, name: "text", text: ""}], function(ev, button, data, list, args) { + cb(list[0], can.base.ParseJSON(list[0])) }) }, getLocation: function(cb) { navigator.geolocation.getCurrentPosition(function(res) { cb({latitude: parseInt(res.coords.latitude*100000), longitude: parseInt(res.coords.longitude*100000)}) }, function(some) { - typeof cb == "function" && cb({name: "some"}) + typeof cb == lang.FUNCTION && cb({name: "some"}) } ); }, openLocation: function(msg) { - window.open("https://map.baidu.com/search/"+encodeURIComponent(msg.Option("text")) - +"/@12958750.085,4825785.55,16z?querytype=s&da_src=shareurl&wd="+encodeURIComponent(msg.Option("text"))) + window.open("https://map.baidu.com/search/"+encodeURIComponent(msg.Option(kit.MDB_TEXT)) + +"/@12958750.085,4825785.55,16z?querytype=s&da_src=shareurl&wd="+encodeURIComponent(msg.Option(kit.MDB_TEXT))) }, chooseImage: function(cb) { - typeof cb == "function" && cb([]) + typeof cb == lang.FUNCTION && cb([]) }, }, - isIE: navigator.userAgent.indexOf("MSIE") > -1, - isLandscape: function() { return window.innerWidth > window.innerHeight }, isWeiXin: navigator.userAgent.indexOf("MicroMessenger") > -1, isIPhone: navigator.userAgent.indexOf("iPhone") > -1, isMobile: navigator.userAgent.indexOf("Mobile") > -1, isMacOSX: navigator.userAgent.indexOf("Mac OS X") > -1, isWindows: navigator.userAgent.indexOf("Windows") > -1, + isIE: navigator.userAgent.indexOf("MSIE") > -1, isExtension: location && location.protocol && location.protocol == "chrome-extension:", isLocalFile: location && location.protocol && location.protocol == "file:", + isLandscape: function() { return window.innerWidth > window.innerHeight }, mod: { isPod: location && location.pathname && (location.pathname.indexOf("/chat/pod/") == 0), isDiv: location && location.pathname && (location.pathname.indexOf("/chat/div/") == 0), @@ -37,7 +37,7 @@ Volcanos("user", {help: "用户操作", agent: { alert: function(text) { alert(JSON.stringify(text)) }, confirm: function(text) { return confirm(JSON.stringify(text)) }, - prompt: function(text, cb, def, silent) { (text = silent? def: prompt(text, def||"")) != undefined && typeof cb == "function" && cb(text); return text }, + prompt: function(text, cb, def, silent) { (text = silent? def: prompt(text, def||"")) != undefined && typeof cb == lang.FUNCTION && cb(text); return text }, reload: function(force) { (force || confirm("重新加载页面?")) && location.reload() }, jumps: function(url) { location.href = url }, open: function(url) { window.open(url) }, @@ -54,15 +54,15 @@ Volcanos("user", {help: "用户操作", agent: { can.page.Modify(can, document.body, {className: name}) }, language: function(can) { - return can.user.Search(can, "language") + return can.misc.Search(can, "language") }, trans: function(can, text) { if (can.user.language(can) == "en") { return text } - if (typeof text == "object") { + if (can.base.isObject(text)) { return can.core.Item(text, function(k, v) { can.core.Value(can._trans, k, v) }) } - if (typeof text == "function") { text = text.name || "" } + if (can.base.isFunction(text)) { text = text.name||"" } return can._trans&&can._trans[text] || can.Conf("trans."+text) || can.Conf("feature._trans."+text) || { "create": "创建", "remove": "删除", "insert": "添加", "delete": "删除", "modify": "编辑", "list": "查看", "back": "返回", "run": "执行", "done": "完成", "share": "共享", @@ -77,18 +77,21 @@ Volcanos("user", {help: "用户操作", agent: { "label": "标签", "exec": "执行", }[text]||text }, + toastSuccess: function(can) { + can.user.toast(can, ice.SUCCESS) + }, toast: function(can, content, title, duration, progress) { - var meta = typeof content == "object"? content: {content: content, title: title||can._help, duration: duration, progress: progress} + var meta = can.base.isObject(content)? content: {content: content, title: title||can._help, duration: duration, progress: progress} var width = meta.width||400, height = meta.height||100; if (width < 0) { width = window.innerWidth + width } - var ui = can.page.Append(can, document.body, [{view: "toast", style: { + var ui = can.page.Append(can, document.body, [{view: chat.TOAST, style: { left: (window.innerWidth-width)/2, width: width, bottom: 100, }, list: [ - {text: [meta.title||"", "div", "title"], title: "点击复制", onclick: function(event) { + {text: [meta.title||"", html.DIV, html.TITLE], title: "点击复制", onclick: function(event) { can.user.copy(event, can, meta.title) }}, {view: "duration", title: "点击关闭", onclick: function() { action.close() }}, - typeof meta.content == "object"? meta.content: {text: [meta.content||"执行成功", "div", "content"]}, + can.base.isObject(meta.content)? meta.content: {text: [meta.content||"执行成功", html.DIV, "content"]}, {view: "action"}, meta.progress != undefined && {view: "progress", style: {width: width}, list: [ {view: "current", style: {width: (meta.progress||0)/100*width}}, @@ -98,7 +101,7 @@ Volcanos("user", {help: "用户操作", agent: { var action = can.onappend._action(can, meta.action||[], ui.action, { close: function(event) { can.page.Remove(can, action._target), action.timer.stop = true }, timer: can.core.Timer({interval: 100, length: (parseInt(meta.duration||1000))/100}, function(event, interval, index) { - if (index > 30) { ui.duration.innerHTML = parseInt(index/10)+"."+(index%10)+"s..." } + if (index > 30) { ui.duration.innerHTML = parseInt(index/10)+ice.PT+(index%10)+"s..." } }, function() { action.close() }), _target: ui._target, ui: ui, }); can.onmotion.story.auto(can, ui._target) @@ -113,16 +116,16 @@ Volcanos("user", {help: "用户操作", agent: { can.user.toast(can, {height: 300, width: 500, title: msg.Append(kit.MDB_NAME), duration: -1, content: msg.Append(kit.MDB_TEXT), action: [cli.CLOSE], - }) + }), can.user.copy(msg._event, can, msg.Append(kit.MDB_NAME)) }) }, login: function(can, cb, method) { var ui = can.user.input({}, can, [ - {username: "username"}, {password: "password"}, + {username: html.USERNAME}, {password: html.PASSWORD}, ], function(event, button, data, list) { return { "登录": function() { - can.run({}, ["login", data["username"], data["password"]], function(msg) { - if (msg.Option("user.name")) { + can.run({}, [aaa.LOGIN, data[html.USERNAME], data[html.PASSWORD]], function(msg) { + if (msg.Option(ice.MSG_USERNAME)) { can.page.Remove(can, ui._target), can.base.isFunc(cb) && cb() } else { can.user.toast(can, "用户名或密码错误") @@ -135,12 +138,10 @@ Volcanos("user", {help: "用户操作", agent: { if (cmd == "pwd") { return can.user.toast(can, arg[2], arg[1], -1), msg.Reply() } - - if (cmd == "sessid") { - return can.user.Cookie(can, "sessid", arg[0]), msg.Reply(), can.user.reload(true) + if (cmd == ice.MSG_SESSID) { + return can.misc.Cookie(can, ice.MSG_SESSID, arg[0]), msg.Reply(), can.user.reload(true) } - - can.search(event, msg["detail"]||[], function(msg) { msg.Reply() }) + can.search(event, msg[ice.MSG_DETAIL]||[], function(msg) { msg.Reply() }) }) }, "飞书": function() { @@ -151,35 +152,30 @@ Volcanos("user", {help: "用户操作", agent: { can.page.Modify(can, ui._target, {className: "input login", style: {left: (window.innerWidth-ui._target.offsetWidth)/2, top: window.innerHeight/6}}) }, logout: function(can, force) { if (force||can.user.confirm("logout?")) { - can.run({}, [ctx.ACTION, "logout"], function(msg) { can.user.Cookie(can, "sessid", "") - can.user.Search(can, "share")? can.user.Search(can, "share", ""): can.user.reload(true) + can.run({}, [ctx.ACTION, aaa.LOGOUT], function(msg) { can.misc.Cookie(can, ice.MSG_SESSID, "") + can.misc.Search(can, chat.SHARE)? can.misc.Search(can, chat.SHARE, ""): can.user.reload(true) }) } }, - camera: function(can, msg, cb) { - navigator.getUserMedia({video: true}, cb, function(error) { - can.misc.Log(error) - }) - }, copy: function(event, can, text) { if (navigator.clipboard) { var ok = false navigator.clipboard.writeText(text).then(function() { ok = true }) - if (ok) { return can.user.toast(can, text, "复制成功") } + if (ok) { return can.user.toastSuccess(can) } } - var input = can.page.Append(can, event.target.parentNode, [{type: "textarea", value: text}]).first + var input = can.page.Append(can, event.target.parentNode, [{type: html.TEXTAREA, value: text}]).first input.setSelectionRange(0,-1), input.focus(), document.execCommand("Copy") - can.page.Remove(can, input), can.user.toast(can, text, "复制成功") + can.page.Remove(can, input), can.user.toastSuccess(can) event.stopPropagation(), event.preventDefault() }, carte: function(event, can, meta, list, cb, parent) { meta = meta||can.ondetail||can.onaction||{}, list = list&&list.length > 0? list: meta.list||[]; if (list.length == 0) { return } cb = cb||function(event, item, meta) { var cb = meta[item]||meta["_engine"]; can.base.isFunc(cb) && cb(event, can, item) } - var ui = can.page.Append(can, document.body, [{view: "carte", style: {left: 0, top: 0}, onmouseleave: function(event) { + var ui = can.page.Append(can, document.body, [{view: chat.CARTE, style: {left: 0, top: 0}, onmouseleave: function(event) { // can.page.Remove(can, ui._target) }, list: can.core.List(list, function(item) { - return typeof item == "string"? {view: "item", list: [{text: can.user.trans(can, item), click: function(event) { + return can.base.isString(item)? {view: "item", list: [{text: can.user.trans(can, item), click: function(event) { can.user.isMobile && can.page.Remove(can, ui._target) can.base.isFunc(cb) && cb(event, item, meta) // can.onmotion.float.del(can, "carte") @@ -193,7 +189,7 @@ Volcanos("user", {help: "用户操作", agent: { }) }] ); can.onlayout.figure(event, can, ui._target) var carte = {_target: ui._target, _parent: parent} - null && can.onmotion.float.add(can, "carte", carte) + null && can.onmotion.float.add(can, chat.CARTE, carte) ui._target.onmouseover = function(event) { event.stopPropagation(), event.preventDefault() } @@ -209,14 +205,14 @@ Volcanos("user", {help: "用户操作", agent: { }, input: function(event, can, form, cb, button) { // form [ string, array, object, {type: "select", values: []} var msg = can.request(event) - var ui = can.page.Append(can, document.body, [{view: ["input"], style: {left: 0, top: 0}, list: [ + var ui = can.page.Append(can, document.body, [{view: [html.INPUT], style: {left: 0, top: 0}, list: [ {view: [chat.OPTION, html.TABLE], list: can.core.List(form, function(item) { - item = typeof item == lang.STRING? {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 == "text"? html.TEXTAREA: html.TEXT) + 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) item._init = function(target) { item.run = function(event, cmds, cb) { - can.request(event, function() { var value = {_handle: "true", action: msg.Option(chat.ACTION)} + can.request(event, function() { var value = {_handle: ice.TRUE, action: msg.Option(chat.ACTION)} can.page.Select(can, ui.table, "textarea,input,select", function(item) { item.name && item.value && (value[item.name] = item.value) }); return value @@ -227,11 +223,11 @@ Volcanos("user", {help: "用户操作", agent: { can.onappend.figure(can, item, target) } - return {type: html.TR, list: [{type: html.TD, list: [{text: item._trans||can.user.trans(can, item.name)||""}]}, {type: "td", list: [can.page.input(can, item)]} ]} + return {type: html.TR, list: [{type: html.TD, list: [{text: item._trans||can.user.trans(can, item.name)||""}]}, {type: html.TD, list: [can.page.input(can, item)]} ]} })}, {view: chat.ACTION}, ]}]); can.onlayout.figure(event, can, ui._target) - var action = can.onappend._action(can, button||["submit", "cancel"], ui.action, { + var action = can.onappend._action(can, button||[html.SUBMIT, html.CANCEL], ui.action, { cancel: function(event) { can.page.Remove(can, ui._target) }, _engine: function(event, can, button) { action.submit(event, can, button) }, submit: function(event, can, button) { var data = {}, args = [], list = [] @@ -252,20 +248,20 @@ Volcanos("user", {help: "用户操作", agent: { var msg = can.request(event, {fields: fields||"type,name,text"}) can.search(msg._event, ["Search.onimport.select", type, "", ""], function(list) { can.core.Next(list, cb, cbs||function() { - can.user.toast(can, "添加成功") + can.user.toastSuccess(can) }) }) }, upload: function(event, can) { var begin = new Date() - var ui = can.page.Append(can, document.body, [{view: "upload", style: {left: 0, top: 0}, list: [ + var ui = can.page.Append(can, document.body, [{view: html.UPLOAD, style: {left: 0, top: 0}, list: [ {view: "action"}, {view: "output", list: [{view: "progress"}]}, {view: "status", list: [{view: "show"}, {view: "cost"}, {view: "size"}]}, ]}]); can.onlayout.figure(event, can, ui._target) var action = can.onappend._action(can, [ - {type: "upload", onchange: function(event) { + {type: html.UPLOAD, onchange: function(event) { action.show(event, 0, event.target.files[0].size, 0) - }}, "close", + }}, cli.CLOSE, ], ui.action, { close: function(event) { can.page.Remove(can, ui._target) }, begin: function(event) { begin = new Date() @@ -275,9 +271,8 @@ Volcanos("user", {help: "用户操作", agent: { var msg = can.request(event, can.Option(), {_handle: "true"}) msg._upload = upload[0].files[0], msg._progress = action.show - can.run(event, [ctx.ACTION, "upload"], function(msg) { - can.user.toast(can, "上传成功"), can.Update() - action.close() + can.run(event, [ctx.ACTION, html.UPLOAD], function(msg) { + can.user.toastSuccess(can), can.Update(), action.close() }, true) }, show: function (event, value, total, loaded) { now = new Date() @@ -285,7 +280,7 @@ Volcanos("user", {help: "用户操作", agent: { ui.show.innerHTML = value+"%" ui.cost.innerHTML = can.base.Duration(now - begin) - ui.size.innerHTML = can.base.Size(loaded)+"/"+can.base.Size(total) + ui.size.innerHTML = can.base.Size(loaded)+ice.PS+can.base.Size(total) can.page.Modify(can, ui.progress, {style: {width: value*(ui.output.offsetWidth-2)/100}}) }, }); can.page.Select(can, ui.action, "input[type=file]")[0].click() @@ -293,61 +288,14 @@ Volcanos("user", {help: "用户操作", agent: { return action }, download: function(can, path, name) { - var a = can.page.Append(can, document.body, [{type: "a", href: path, download: name||path.split("/").pop()}]).first + var a = can.page.Append(can, document.body, [{type: html.A, href: path, download: name||path.split(ice.PS).pop()}]).first a.click(), can.page.Remove(can, a) }, downloads: function(can, text, name) { can.user.download(can, URL.createObjectURL(new Blob([text])), name) }, - - MergeURL: shy("地址链接", function(can, objs, clear) { - var path = location.pathname; objs._path && (path = objs._path, delete(objs._path)) - return can.base.MergeURL(location.origin+path+(clear?"":location.search), objs) - }), - Search: shy("请求参数", function(can, key, value) { var args = {} - if (value == undefined && typeof key == "string") { - var ls = location.pathname.split("/") - if (ls[1] == "share") { args["share"] = ls[2] } - if (ls[1] == "chat" && ls[2] == "pod") { args["pod"] = ls[3] } - } - - location.search && location.search.slice(1).split("&").forEach(function(item) { var x = item.split("=") - x[1] != "" && (args[x[0]] = decodeURIComponent(x[1])) + camera: function(can, msg, cb) { + navigator.getUserMedia({video: true}, cb, function(error) { + can.misc.Log(error) }) - - if (typeof key == "object") { - can.core.Item(key, function(key, value) { - if (value != undefined) {args[key] = value} - args[key] == "" && delete(args[key]) - }) - } else if (key == undefined) { - return args - } else if (value == undefined) { - return args[key] - } else { - args[key] = value, args[key] == "" && delete(args[key]) - } - - return location.search = can.core.Item(args, function(key, value) { - return key+"="+encodeURIComponent(value) - }).join("&") - }), - Cookie: shy("会话变量", function(can, key, value, path) { - function set(k, v) {document.cookie = k+"="+v+";path="+(path||"/")} - - if (typeof key == "object") { - for (var k in key) {set(k, key[k])} - key = null - } - if (key == undefined) {var cs = {} - document.cookie.split("; ").forEach(function(item) { - var cookie = item.split("=") - cs[cookie[0]] = cookie[1] - }) - return cs - } - - value != undefined && set(key, value) - var result = (new RegExp(key+"=([^;]*);?")).exec(document.cookie) - return result && result.length > 0? result[1]: "" - }), + }, }) diff --git a/panel/action.js b/panel/action.js index c19b855e..fb3197a2 100644 --- a/panel/action.js +++ b/panel/action.js @@ -1,7 +1,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg) { var river = can.Conf(chat.RIVER), storm = can.Conf(chat.STORM) can.onmotion.clear(can), can.core.Next(msg.Table(), function(item, next) { item.type = chat.PLUGIN - item.height = parseInt(can.Conf(chat.HEIGHT))-40, item.width = parseInt(can.Conf(chat.WIDTH))-40 + item.height = parseInt(can.Conf(html.HEIGHT))-40, item.width = parseInt(can.Conf(html.WIDTH))-40 item.feature = can.base.Obj(item.feature||item.meta) item.inputs = can.base.Obj(item.inputs||item.list) @@ -9,7 +9,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg) can.onimport._plugin(can, river, storm, sub, meta), skip || next() }) }, function() { - can.onaction.layout(can, can.user.Search(can, chat.LAYOUT)||can.Conf(chat.LAYOUT)) + can.onaction.layout(can, can.misc.Search(can, chat.LAYOUT)||can.Conf(chat.LAYOUT)) !can.user.isMobile && can.onimport._menu(can, msg) }) @@ -18,7 +18,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg) _plugin: function(can, river, storm, sub, meta) { sub.run = function(event, cmds, cb) { var msg = sub.request(event); cmds = cmds||[] var toast = msg.Option("_toast") && can.user.toast(can, msg.Option("_toast"), "", -1) - return can.run(event, can.misc.Concat([river, storm, meta.id||meta.index||can.core.Keys(meta.key, meta.name)], cmds), function(msg) { + return can.run(event, can.misc.concat([river, storm, meta.id||meta.index||can.core.Keys(meta.key, meta.name)], cmds), function(msg) { toast && toast.close(), can.base.isFunc(cb) && cb(msg) }) }, can._plugins = (can._plugins||[]).concat([sub]) @@ -49,8 +49,8 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg) }, _share: function(can, share) { if (!share) { return } can.run({}, ["_share", share], function(msg) { - can.user.topic(can, can.user.Search(can, chat.TOPIC)||msg.Option(chat.TOPIC)) - can.user.title(can.user.Search(can, chat.TITLE)||msg.Option(chat.TITLE)) + can.user.topic(can, can.misc.Search(can, chat.TOPIC)||msg.Option(chat.TOPIC)) + can.user.title(can.misc.Search(can, chat.TITLE)||msg.Option(chat.TITLE)) can.onaction.layout(can, "auto") if (msg[kit.MDB_INDEX].length == 1) { can.require(["/panel/cmd.css"]) @@ -95,7 +95,7 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg, } can.base.isFunc(cb) && cb() }, - onmain: function(can, msg) { can.onimport._share(can, can.user.Search(can, web.SHARE)) }, + onmain: function(can, msg) { can.onimport._share(can, can.misc.Search(can, web.SHARE)) }, onsize: function(can, msg, width, height) { can.Conf({width: width, height: height}) }, onsearch: function(can, msg, word) { if (word[0] == "*" || word[0] == mdb.PLUGIN) { can.onexport.plugin(can, msg, word) } @@ -157,8 +157,8 @@ Volcanos("onexport", {help: "导出数据", list: [], size: function(can, msg) { msg.Option(chat.TOP, can._target.offsetTop) msg.Option(chat.LEFT, can._target.offsetLeft) - msg.Option(chat.WIDTH, can._target.offsetWidth) - msg.Option(chat.HEIGHT, can._target.offsetHeight) + msg.Option(html.WIDTH, can._target.offsetWidth) + msg.Option(html.HEIGHT, can._target.offsetHeight) msg.Option(chat.SCROLL, can.user.isMobile? can._target.parentNode.parentNode.scrollTop: can._output.scrollTop) }, layout: function(can, msg) { return can.Conf(chat.LAYOUT) }, diff --git a/panel/cmd.js b/panel/cmd.js index b4a78872..d3807161 100644 --- a/panel/cmd.js +++ b/panel/cmd.js @@ -18,7 +18,7 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg, can.page.ClassList.add(can, can._target, "Action") }, _plugin: function(can, item, next) { - item.height = window.innerHeight, item.width = window.innerWidth, item.opts = can.user.Search() + item.height = window.innerHeight, item.width = window.innerWidth, item.opts = can.misc.Search() can.onappend.plugin(can, item, function(sub, meta) { can.user.title(meta.name), next() }) }, }) diff --git a/panel/footer.js b/panel/footer.js index 293f3559..e39833d7 100644 --- a/panel/footer.js +++ b/panel/footer.js @@ -75,7 +75,7 @@ Volcanos("onaction", {help: "交互数据", list: [], _init: function(can, msg, can.get("Action", "size", function(msg, top, left, width, height) { can.onappend.plugin(can, {index: cmds[0], args: cmds.slice(1), height: height-100, width: width}, function(sub) { sub.run = function(event, cmd, cb) { - can.run(event, can.misc.Concat([ctx.ACTION, ice.RUN, cmds[0]], cmd), cb) + can.run(event, can.misc.concat([ctx.ACTION, ice.RUN, cmds[0]], cmd), cb) } can.page.Modify(can, sub._target, {style: {top: top+100, left: left}}) diff --git a/panel/header.js b/panel/header.js index 9a032f5d..f7f1f921 100644 --- a/panel/header.js +++ b/panel/header.js @@ -27,15 +27,15 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, }) }, _grant: function(can, msg, target) { - if (can.user.Search(can, chat.GRANT)) { - if (can.user.confirm(chat.GRANT+ice.SP+can.user.Search(can, chat.GRANT))) { - can.run(event, [ctx.ACTION, chat.GRANT, web.SPACE, can.user.Search(can, chat.GRANT)]) + if (can.misc.Search(can, chat.GRANT)) { + if (can.user.confirm(chat.GRANT+ice.SP+can.misc.Search(can, chat.GRANT))) { + can.run(event, [ctx.ACTION, chat.GRANT, web.SPACE, can.misc.Search(can, chat.GRANT)]) } - can.user.Search(can, chat.GRANT, "") + can.misc.Search(can, chat.GRANT, "") } }, _title: function(can, msg, target) { - can.user.title(can.user.Search(can, chat.TITLE)||can.user.Search(can, ice.POD)) + can.user.title(can.misc.Search(can, chat.TITLE)||can.misc.Search(can, ice.POD)) !can.user.isMobile && can.core.List(msg.result||["shylinux.com/x/contexts"], function(item) { can.page.Append(can, target, [{view: [chat.TITLE, html.DIV, item], title: "返回主页", onclick: function(event) { can.onaction.title(event, can) @@ -161,16 +161,16 @@ Volcanos("onaction", {help: "交互数据", list: [], _init: function(can, meta, title: function(event, can) { var args = {}; can.core.List([chat.TITLE, chat.TOPIC, chat.LAYOUT], function(key) { - var value = can.user.Search(can, key); value && (args[key] = value) + var value = can.misc.Search(can, key); value && (args[key] = value) }) - can.user.jumps(can.user.MergeURL(can, args, true)) + can.user.jumps(can.misc.MergeURL(can, args, true)) }, river: function(event, can) { can.onaction.River(can) }, black: function(event, can, button) { can.onlayout.topic(can, button), can.onlayout._init(can) }, white: function(event, can, button) { can.onlayout.topic(can, button), can.onlayout._init(can) }, print: function(event, can, button) { can.onlayout.topic(can, can.base.join([chat.WHITE, button])) - can.set("River", chat.HEIGHT, -1), can.set("Action", chat.HEIGHT, -1) + can.set("River", html.HEIGHT, -1), can.set("Action", html.HEIGHT, -1) }, webpack: function(event, can) { can.user.input(event, can, [{name: kit.MDB_NAME, value: can.user.title()}], function(ev, button, meta, list) { @@ -202,13 +202,13 @@ Volcanos("onaction", {help: "交互数据", list: [], _init: function(can, meta, can.run(event, [aaa.USERNICK, list[0]], function(msg) { can.page.Select(can, can._output, can.core.Keys(html.DIV, aaa.USERNICK), function(item) { can.page.Modify(can, item, can.Conf(aaa.USERNICK, list[0])) - }), can.user.toast(can, "修改成功") + }), can.user.toastSuccess(can) }, true) }) can.user.isMobile && can.page.Modify(can, ui._target, {style: {top: 40, right: 0, left: ""}}) }, - chinese: function(event, can) { can.user.Search(can, aaa.LANGUAGE, "zh") }, - english: function(event, can) { can.user.Search(can, aaa.LANGUAGE, "en") }, + chinese: function(event, can) { can.misc.Search(can, aaa.LANGUAGE, "zh") }, + english: function(event, can) { can.misc.Search(can, aaa.LANGUAGE, "en") }, clear: function(event, can) { can.onimport.background(event, can, ""), can.onimport.avatar(event, can, ""), can.user.reload(true) }, logout: function(event, can) { can.user.logout(can) }, diff --git a/panel/river.js b/panel/river.js index 9f9468f0..3c146aff 100644 --- a/panel/river.js +++ b/panel/river.js @@ -16,9 +16,9 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, if (can.user.isMobile) { can._main_river = "product", can._main_storm = "office" } if (can.user.isWeiXin) { can._main_river = "service", can._main_storm = "wx" } - can._main_title = can.user.Search(can, chat.TITLE)||msg.Option(ice.MSG_TITLE)||Volcanos.meta.args.title||can.user.Search(can, ice.POD)||can._main_title - can._main_river = can.user.Search(can, chat.RIVER)||msg.Option(ice.MSG_RIVER)||Volcanos.meta.args.river||can._main_river - can._main_storm = can.user.Search(can, chat.STORM)||msg.Option(ice.MSG_STORM)||Volcanos.meta.args.storm||can._main_storm + can._main_title = can.misc.Search(can, chat.TITLE)||msg.Option(ice.MSG_TITLE)||Volcanos.meta.args.title||can.misc.Search(can, ice.POD)||can._main_title + can._main_river = can.misc.Search(can, chat.RIVER)||msg.Option(ice.MSG_RIVER)||Volcanos.meta.args.river||can._main_river + can._main_storm = can.misc.Search(can, chat.STORM)||msg.Option(ice.MSG_STORM)||Volcanos.meta.args.storm||can._main_storm }, _menu: function(can, msg) { if (can.user.mod.isPod) { return } can.search({}, ["Header.onimport.menu"].concat(can.base.Obj(msg.Option(chat.MENUS), can.ondetail.menus)), function(event, button) { @@ -121,7 +121,7 @@ Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, msg, {name: kit.MDB_NAME, value: "hi", _trans: "群名"}, {name: kit.MDB_TEXT, value: "hello", _trans: "简介"}, ], function(event, button, meta, list, args) { can.run(event, [ctx.ACTION, mdb.CREATE].concat(args), function(msg) { - can.user.Search(can, {river: msg.Result()}) + can.misc.Search(can, {river: msg.Result()}) }) }) }, @@ -130,7 +130,7 @@ Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, msg, topic: can.get("Header", "topic"), layout: can.get("Action", "layout"), } if (can.user.isExtension) { localStorage.setItem("args", JSON.stringify(args)) } - can.user.Search(can, args) + can.misc.Search(can, args) }, }) Volcanos("ondetail", {help: "菜单交互", @@ -161,7 +161,7 @@ Volcanos("ondetail", {help: "菜单交互", next() }) }, function() { - can.user.Search(can, {river: river, storm: storm}) + can.misc.Search(can, {river: river, storm: storm}) }) }, "共享工具": function(event, can, button, river, storm) { @@ -190,7 +190,7 @@ Volcanos("ondetail", {help: "菜单交互", "创建空间": function(event, can, button, river, storm) { can.request(event, {action: button}) can.user.input(event, can, [{name: "name", value: "hi"}, {name: "repos"}, {name: "template"}], function(event, button, data, list, args) { can.run(event, [ctx.ACTION, cli.START].concat(args, chat.RIVER, river), function(msg) { - var link = can.user.MergeURL(can, {_path: "/chat/pod/"+can.core.Keys(can.user.Search(can, ice.POD), msg.Option(kit.MDB_NAME))}) + var link = can.misc.MergeURL(can, {_path: "/chat/pod/"+can.core.Keys(can.misc.Search(can, ice.POD), msg.Option(kit.MDB_NAME))}) can.user.toast(can, link), can.user.open(link) }) }) @@ -210,18 +210,18 @@ Volcanos("ondetail", {help: "菜单交互", "重命名群组": function(event, can, button, river) { can.user.input(event, can, [kit.MDB_NAME], function(event, button, meta, list) { can.run(can.request(event, {hash: river})._event, [ctx.ACTION, mdb.MODIFY, kit.MDB_NAME, meta.name], function(msg) { - can.user.Search(can, {river: river}) + can.misc.Search(can, {river: river}) }) }) }, "删除群组": function(event, can, button, river) { - can.run(can.request(event, {hash: river})._event, [ctx.ACTION, mdb.REMOVE], function(msg) { can.user.Search(can, {}) }) + can.run(can.request(event, {hash: river})._event, [ctx.ACTION, mdb.REMOVE], function(msg) { can.misc.Search(can, {}) }) }, "保存参数": function(event, can, button, river, storm) { can.search(event, ["Action.onexport.args"], function(item, next, index, array) { var msg = can.request({}, {hash: storm, id: item.dataset.id}) - var toast = can.user.toast(can, (index+1)+"/"+array.length, "保存参数", 10000, (index+1)/array.length) + var toast = can.user.toast(can, (index+1)+ice.PS+array.length, "保存参数", 10000, (index+1)/array.length) can.run(msg._event, [river, chat.STORM, ctx.ACTION, mdb.MODIFY, ice.ARG, item.dataset.args], function(msg) { toast.close(), next() }) @@ -230,13 +230,13 @@ Volcanos("ondetail", {help: "菜单交互", "重命名应用": function(event, can, button, river, storm) { can.user.input(event, can, [kit.MDB_NAME], function(ev, button, meta, list, args) { can.run(can.request(event, {hash: storm})._event, [river, chat.STORM, ctx.ACTION, mdb.MODIFY].concat(args), function(msg) { - can.user.Search(can, {river: river, storm: storm}) + can.misc.Search(can, {river: river, storm: storm}) }) }) }, "删除应用": function(event, can, button, river, storm) { can.run(can.request(event, {hash: storm})._event, [river, chat.STORM, ctx.ACTION, mdb.REMOVE], function(msg) { - can.user.Search(can, {river: river}) + can.misc.Search(can, {river: river}) }) }, @@ -248,7 +248,7 @@ Volcanos("ondetail", {help: "菜单交互", {name: kit.MDB_NAME, value: "hi", _trans: "名称"}, {name: kit.MDB_TEXT, value: "hello", _trans: "简介"}, ], function(event, button, meta, list, args) { can.run({}, [river, chat.STORM, ctx.ACTION, mdb.CREATE].concat(args), function(msg) { - can.user.Search(can, {river: river, storm: msg.Result()}) + can.misc.Search(can, {river: river, storm: msg.Result()}) }) }) }, diff --git a/panel/search.css b/panel/search.css index 2a5b266a..bf75c78c 100644 --- a/panel/search.css +++ b/panel/search.css @@ -13,7 +13,6 @@ fieldset.Search div.output { overflow:auto; } fieldset.Search div.output div.content { - max-height:400px; overflow:auto; } fieldset.Search div.output div.content a { diff --git a/panel/search.js b/panel/search.js index 948112d6..0f12345b 100644 --- a/panel/search.js +++ b/panel/search.js @@ -90,10 +90,15 @@ Volcanos("onaction", {help: "交互操作", list: [cli.CLEAR, cli.CLOSE, cli.DON var cmd = line.cmd == ctx.COMMAND? can.core.Keys(line.type, line.name.split(" ")[0]): can.core.Keys(line.ctx, line.cmd) can.onappend.plugin(can, {type: chat.PLUGIN, index: cmd||msg.Option(kit.MDB_INDEX)}, function(sub, meta) { - can.get("Action", "size", function(msg, width) { sub.Conf(chat.WIDTH, width-60) }) + can.get("Action", "size", function(msg, height, width) { + height -= can.ui.content.offsetHeight+204 + can.page.Modify(can, sub._output, {style: {"max-height": height}}) + sub.Conf(html.HEIGHT, height+28) + sub.Conf(html.WIDTH, width-60) + }) sub.run = function(event, cmds, cb) { var msg = can.request(event, line) - can.run(event, can.misc.Concat([ctx.ACTION, ice.RUN, meta.index], cmds), cb, true) + can.run(event, can.misc.concat([ctx.ACTION, ice.RUN, meta.index], cmds), cb, true) } }, can.ui.profile) }, diff --git a/plugin/input.js b/plugin/input.js index a13e85ab..76ab7281 100644 --- a/plugin/input.js +++ b/plugin/input.js @@ -11,7 +11,7 @@ Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, meta, run: function(event, can) { var title = can.sup._name+ice.SP+can.sup.Input([], true) var toast = can.user.toast(can, "执行中...", title, -1) - can.run(event, [], function() { toast.close(), can.user.toast(can, "执行成功...", title) }) + can.run(event, [], function() { toast.close(), can.user.toastSuccess(can) }) }, list: function(event, can) { can.run(event) }, back: function(event, can) { can.sup.onimport._back(can.sup) }, diff --git a/plugin/local/chat/div.js b/plugin/local/chat/div.js index a57bf1c8..7c6acd42 100644 --- a/plugin/local/chat/div.js +++ b/plugin/local/chat/div.js @@ -12,9 +12,9 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, can.onimport._item(can, can._meta, can.ui.project, can.onimport._size(can)).click() }, _size: function(can) { - var width = can.Conf(chat.WIDTH)-260, height = can.Conf(chat.HEIGHT)-100 + var width = can.Conf(html.WIDTH)-260, height = can.Conf(html.HEIGHT)-100 if (can.Conf("auto.cmd")) { - width = can.Conf(chat.WIDTH), height = can.Conf(chat.HEIGHT) + width = can.Conf(html.WIDTH), height = can.Conf(html.HEIGHT) can.onmotion.hidden(can, can.ui.project) can.onmotion.hidden(can, can.ui.profile) can.onmotion.hidden(can, can._option) @@ -69,7 +69,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, }, size), ["/plugin/state.js"], function(sub) { can.page.Modify(can, sub._output, {style: size}) sub.run = function(event, cmds, cb) { - can.run(event, can.misc.Concat([ctx.ACTION, ice.RUN, meta.index], cmds), cb, true) + can.run(event, can.misc.concat([ctx.ACTION, ice.RUN, meta.index], cmds), cb, true) } }, target, field) }, true) @@ -84,11 +84,11 @@ Volcanos("onaction", {help: "操作数据", list: [], }, "保存": function(event, can) { var msg = can.request(event, can.Option()) can.run(event, [mdb.MODIFY, kit.MDB_TEXT, JSON.stringify(can._meta)], function(msg) { - can.user.toast(can, "保存成功") + can.user.toastSuccess(can) }, true) }, "预览": function(event, can) { - can.request(event, {link: can.user.MergeURL(can, {_path: "/chat/div/"+can.Option("hash")})}) + can.request(event, {link: can.misc.MergeURL(can, {_path: "/chat/div/"+can.Option("hash")})}) can.search(event, ["Header.onaction.share"]) }, }) diff --git a/plugin/local/chat/trans.js b/plugin/local/chat/trans.js index fd754d64..16123535 100644 --- a/plugin/local/chat/trans.js +++ b/plugin/local/chat/trans.js @@ -16,7 +16,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, if (can.onaction[cmds[1]]) { return can.onaction[cmds[1]](can, from, to, event, cmds, cb) } var msg = sub.request(event, {_pod: can.Option(from)}) - can.run(event, can.misc.Concat([ctx.ACTION, ice.RUN, index], cmds), cb, true) + can.run(event, can.misc.concat([ctx.ACTION, ice.RUN, index], cmds), cb, true) } }) }, diff --git a/plugin/local/chat/wx.js b/plugin/local/chat/wx.js index 9137c2a2..23703a40 100644 --- a/plugin/local/chat/wx.js +++ b/plugin/local/chat/wx.js @@ -6,7 +6,7 @@ Volcanos("onaction", {source: function(can, msg) { jsApiList: can.core.Item({ scanQRCode: function(cb) { wx.scanQRCode({needResult: cb? 1: 0, scanType: ["qrCode","barCode"], success: function (res) { - can.base.isFunc(cb) && cb(res.resultStr, can.base.parseJSON(res.resultStr)) + can.base.isFunc(cb) && cb(res.resultStr, can.base.ParseJSON(res.resultStr)) } }) }, getLocation: function(cb) { wx.getLocation({type: "gcj02", success: function (res) { can.base.isFunc(cb) && cb({type: "gcj02", name: "当前位置", text: "当前位置", latitude: parseInt(res.latitude*100000), longitude: parseInt(res.longitude*100000) }) diff --git a/plugin/local/code/inner.js b/plugin/local/code/inner.js index 5ed263f0..2b69521b 100644 --- a/plugin/local/code/inner.js +++ b/plugin/local/code/inner.js @@ -15,7 +15,7 @@ Volcanos("onimport", {help: "导入数据", _init: function(can, msg, list, cb, can.base.isFunc(cb) && cb(msg) }, _content: function(can, target) { - var height = can.Conf(chat.HEIGHT)-(can.user.mod.isCmd? 54: 320); height < 240 && (height = 240) + var height = can.Conf(html.HEIGHT)-(can.user.mod.isCmd? 54: 320); height < 240 && (height = 240) can.page.Modify(can, can.ui.project, {style: {"max-height": height}}) can.page.Modify(can, can.ui.content, {style: {"max-height": height}}) can.page.Modify(can, can.ui.display, {style: {display: chat.NONE}}) @@ -36,7 +36,7 @@ Volcanos("onimport", {help: "导入数据", _init: function(can, msg, list, cb, case code.INNER: can.onimport.tabview(can, msg.Option(nfs.PATH), msg.Option(nfs.FILE), msg.Option(nfs.LINE)); return } } - can.run(event, can.misc.Concat([ctx.ACTION, code.FAVOR], cmds), function(msg) { + can.run(event, can.misc.concat([ctx.ACTION, code.FAVOR], cmds), function(msg) { can.base.isFunc(cb) && cb(msg), can.core.Timer(10, function() { can.onappend._action(sub, [cli.CLOSE], sub._action, { close: function(event) { can.onmotion.hidden(sub, sub._target) }, @@ -165,7 +165,7 @@ Volcanos("onaction", {help: "控件交互", list: ["项目", "收藏"], can.Status("跳转数", can.history.length) }, "项目": function(event, can) { - var width = can.Conf(chat.WIDTH)-(can.onmotion.toggle(can, can.ui.project)? 170: 0) + var width = can.Conf(html.WIDTH)-(can.onmotion.toggle(can, can.ui.project)? 170: 0) }, "收藏": function(event, can) { can.onmotion.toggle(can, can.ui.favor._target) }, "搜索": function(event, can) { can.onmotion.toggle(can, can.ui.search) }, @@ -304,7 +304,7 @@ Volcanos("onaction", {help: "控件交互", list: ["项目", "收藏"], kit.MDB_TYPE, can.parse, kit.MDB_NAME, meta.name||"", kit.MDB_TEXT, (value||"").trimRight(), nfs.PATH, can.Option(nfs.PATH), nfs.FILE, can.Option(nfs.FILE), nfs.LINE, can.Option(nfs.LINE), ], function(msg) { - can.user.toast(can, "收藏成功") + can.user.toastSuccess(can) }, true) }) }, diff --git a/plugin/local/code/snippet.js b/plugin/local/code/snippet.js index 537edd91..807fd73b 100644 --- a/plugin/local/code/snippet.js +++ b/plugin/local/code/snippet.js @@ -4,7 +4,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, can.onappend.plugin(can, {index: "web.code.vimer", style: "full"}, function(sub) { sub.run = function(event, cmds, cb) { var res = can.request(event) if (cmds[1] == "plugin") { - can.run(event, can.misc.Concat(["action", "vimer"], cmds), cb, true) + can.run(event, can.misc.concat(["action", "vimer"], cmds), cb, true) return } if (cmds[1] == "main.go") { res.Echo(msg.Option("content")) diff --git a/plugin/local/code/vimer.js b/plugin/local/code/vimer.js index 9bda1081..1b177361 100644 --- a/plugin/local/code/vimer.js +++ b/plugin/local/code/vimer.js @@ -122,7 +122,7 @@ Volcanos("onkeymap", {help: "键盘交互", list: ["command", "normal", "insert" var map = can.onkeymap[can.mode]._engine; for (var i = can.keylist.length-1; i > pre-1; i--) { var cb = map[can.keylist[i]]; if (can.base.isFunc(cb)) { return repeat(cb, can.count) - }; if (typeof cb == "object") { map = cb; continue }; break + }; if (can.base.isObject(cb)) { map = cb; continue }; break } }, command: { @@ -300,7 +300,7 @@ Volcanos("onkeymap", {help: "键盘交互", list: ["command", "normal", "insert" Volcanos("onaction", {help: "控件交互", list: ["run"], save: function(event, can) { var msg = can.request(event, {content: can.onexport.content(can)}) can.run(event, [ctx.ACTION, "save", can.parse, can.Option("file"), can.Option("path")], function(msg) { - can.user.toast(can, "保存成功") + can.user.toastSuccess(can) }, true) }, }) diff --git a/plugin/local/team/plan.js b/plugin/local/team/plan.js index 9aac3ab1..76796531 100644 --- a/plugin/local/team/plan.js +++ b/plugin/local/team/plan.js @@ -75,7 +75,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, task.extra && can.core.Item(can.base.Obj(task.extra), function(key, value) { task["extra."+key] = value }), delete(task.extra) var table = can.page.Appends(can, can.ui.profile, [{view: [chat.CONTENT, html.TABLE], list: [{th: ["key", "value"]}]}]).first can.core.Item(task, function(key, value) { key != "_target" && can.page.Append(can, table, [{ - td: [key, key == "pod" && value != ""? can.page.Format("a", can.user.MergeURL(can, {pod: value}), value): value], + td: [key, key == "pod" && value != ""? can.page.Format("a", can.misc.MergeURL(can, {pod: value}), value): value], onclick: function(event) { if (event.target.type == "button") { var msg = can.request(event, can.sup.task) can.run(event, [ctx.ACTION, event.target.name], function(msg) { can.Update() }, true) } }, @@ -87,7 +87,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, _display: function(can, task) { if (!task["extra.cmd"]) { return } can.onappend.plugin(can, {type: "story", ctx: task["extra.ctx"], cmd: task["extra.cmd"], arg: task["extra.arg"]}, function(sub, meta) { sub.run = function(event, cmds, cb) { var msg = can.request(event, {"task.zone": task.zone, "task.id": task.id}) - can.run(event, can.misc.Concat([ctx.ACTION, ice.RUN, task["zone"], task["id"]], cmds), cb, true) + can.run(event, can.misc.concat([ctx.ACTION, ice.RUN, task["zone"], task["id"]], cmds), cb, true) } }, can.ui.display) can.page.Modify(can, can.ui.display, {style: {display: "block"}}) diff --git a/plugin/local/wiki/data.js b/plugin/local/wiki/data.js index 1ab340ef..ca01bc11 100644 --- a/plugin/local/wiki/data.js +++ b/plugin/local/wiki/data.js @@ -55,7 +55,7 @@ Volcanos("onaction", {help: "组件菜单", list: ["保存", ["mode", "全选", "保存": function(event, can, cmd) { can.run(event, [ctx.ACTION, cmd, can.Option("path"), can.onexport.file(can)], function(msg) { - can.user.toast(can, "保存成功") + can.user.toastSuccess(can) }, true) }, some: function(event, can, cmd) { diff --git a/plugin/local/wiki/draw.js b/plugin/local/wiki/draw.js index bdbc0910..ae58d8dd 100644 --- a/plugin/local/wiki/draw.js +++ b/plugin/local/wiki/draw.js @@ -13,7 +13,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, can.svg = can.group = can.onimport._block(can, svg), can.onimport._group(can, svg).click() can.core.ItemCB(can.onaction, function(key, cb) { svg[key] = function(event) { cb(event, can) } }) can.page.Select(can, svg, "*", function(item, index) { can.onimport._block(can, item) - item.tagName == html.G && item.Value(html.CLASS) && can.onimport._group(can, item) + item.tagName == svg.G && item.Value(html.CLASS) && can.onimport._group(can, item) }) }) // 默认参数 @@ -52,7 +52,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, target.Val = function(key, value) { return parseInt(target.Value(key, value == undefined? value: parseInt(value)||0))||0 } - target.Value = function(key, value) { if (typeof key == undefined) { return } + target.Value = function(key, value) { if (can.base.isUndefined(key)) { return } if (can.base.isObject(key)) { can.core.Item(key, target.Value); return } var figure = can.onfigure._get(can, target) @@ -71,12 +71,12 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, || target[key]&&target[key].baseVal&&target[key].baseVal.value || target[key]&&target[key].baseVal || "" } target.Group = function() { var item = target - while (item) { if ([html.SVG, html.G].indexOf(item.tagName) > -1) { return item }; item = item.parentNode } + while (item) { if ([html.SVG, svg.G].indexOf(item.tagName) > -1) { return item }; item = item.parentNode } return can.svg } target.Groups = function() { var item = target var list = []; while (item && item.tagName != html.SVG) { - item.tagName == html.G && item.Value(html.CLASS) && list.push(item.Value(html.CLASS)) + item.tagName == svg.G && item.Value(html.CLASS) && list.push(item.Value(html.CLASS)) item = item.parentNode } return list.reverse().join(ice.PT) @@ -93,7 +93,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, }}) var figure = can.onfigure._get(can, target) - list = (list||[]).concat(figure.data.copy, [html.X, html.Y, kit.MDB_INDEX, kit.MDB_ARGS]) + list = (list||[]).concat(figure.data.copy, [svg.X, svg.Y, kit.MDB_INDEX, kit.MDB_ARGS]) can.page.Append(can, can.ui.profile, [{type: html.TABLE, className: "content", list: [ {th: [kit.MDB_KEY, kit.MDB_VALUE]}, {td: [kit.MDB_TYPE, target.tagName]}, {td: ["pid", target.Value("pid")]}, ].concat(can.core.List(list, function(key) { @@ -132,8 +132,8 @@ Volcanos("onfigure", {help: "图形绘制", list: [], _copy: function(event, can, target) { var data = {}, figure = can.onfigure._get(can, target), size = figure.data.size can.core.List(figure.data.copy, function(item) { data[item] = target.Value(item) }) - data[size.x||html.X] = target.Val(size.x||html.X)+10 - data[size.y||html.Y] = target.Val(size.y||html.Y)+10 + data[size.x||svg.X] = target.Val(size.x||svg.X)+10 + data[size.y||svg.Y] = target.Val(size.y||svg.Y)+10 return can.onfigure._push(can, target.tagName, data, can.group||can.svg) }, _move: function(can, target, list) { @@ -161,7 +161,7 @@ Volcanos("onfigure", {help: "图形绘制", list: [], show: function(can, target, figure) { return can.onexport._position(can, target, figure) } }, circle: { // - data: {points: 2, size: {height: html.R, width: html.R, x: "cx", y: "cy"}, copy: [html.R]}, + data: {points: 2, size: {height: svg.R, width: svg.R, x: "cx", y: "cy"}, copy: [svg.R]}, draw: function(event, can, point) { if (point.length < 2) { return } var p0 = point[0], p1 = point[1] return {r: parseInt(Math.sqrt(Math.pow(p0.x-p1.x, 2)+Math.pow(p0.y-p1.y, 2))), cx: p0.x, cy: p0.y} @@ -175,7 +175,7 @@ Volcanos("onfigure", {help: "图形绘制", list: [], }, }, rect: { // - data: {points: 2, ry: 4, rx: 4, size: {}, copy: [chat.HEIGHT, chat.WIDTH, "ry", "rx"]}, + data: {points: 2, ry: 4, rx: 4, size: {}, copy: [html.HEIGHT, html.WIDTH, "ry", "rx"]}, draw: function(event, can, point) { if (point.length < 2) { return } var p0 = point[0], p1 = point[1] return { @@ -183,13 +183,13 @@ Volcanos("onfigure", {help: "图形绘制", list: [], x: p0.x > p1.x? p1.x: p0.x, y: p0.y > p1.y? p1.y: p0.y, } }, - text: function(can, data, target) { return data.x = target.Val(html.X)+target.Val(chat.WIDTH)/2, data.y = target.Val(html.Y)+target.Val(chat.HEIGHT)/2, data }, + text: function(can, data, target) { return data.x = target.Val(svg.X)+target.Val(html.WIDTH)/2, data.y = target.Val(svg.Y)+target.Val(html.HEIGHT)/2, data }, }, block: { // - data: {points: 2, ry: 4, rx: 4, size: {}, copy: [chat.HEIGHT, chat.WIDTH, "ry", "rx"]}, + data: {points: 2, ry: 4, rx: 4, size: {}, copy: [html.HEIGHT, html.WIDTH, "ry", "rx"]}, draw: function(event, can, point) { if (point.length < 2) { return } this._temp && can.page.Remove(can, this._temp) && delete(this._temp) - this._temp = can.onfigure._push(can, html.G, {}, can.group||can.svg) + this._temp = can.onfigure._push(can, svg.G, {}, can.group||can.svg) var rect = can.onfigure._push(can, "rect", can.onfigure.rect.draw(event, can, point), this._temp) if (event.type == html.CLICK) { @@ -277,7 +277,7 @@ Volcanos("onaction", {help: "组件菜单", list: [ save: function(event, can, button) { var msg = can.request(event, {content: can.onexport.content(can, can.svg)}) can.run(event, [ctx.ACTION, button, can.Option(nfs.PATH)], function(msg) { - can.user.toast(can, ice.SUCCESS, button) + can.user.toastSuccess(can) }, true) }, @@ -287,7 +287,7 @@ Volcanos("onaction", {help: "组件菜单", list: [ hide: function(event, can) { can.onmotion.hide(can, {interval: 100, length: 10}, null, can.group) }, create: function(event, can) { can.user.prompt("group", function(name) { - var group = document.createElementNS('http://www.w3.org/2000/svg', html.G) + var group = document.createElementNS('http://www.w3.org/2000/svg', svg.G) can.group.append(group), can.onimport._block(can, group) group.Value(html.CLASS, name), can.core.List([html.STROKE_WIDTH, html.STROKE, html.FILL, html.FONT_SIZE], function(name) { group.Value(name, can.Action(name)) @@ -321,9 +321,9 @@ Volcanos("onaction", {help: "组件菜单", list: [ resize: function(event, can, point, target) { target = target||event.target if (event.type == html.CLICK) { if (point.length == 1) { - can.current = {target: target, begin: can.core.List([target], function(item) { if (item.tagName == html.G) { return } + can.current = {target: target, begin: can.core.List([target], function(item) { if (item.tagName == svg.G) { return } return { - height: item.Val(chat.HEIGHT), width: item.Val(chat.WIDTH), x: item.Val(html.X), y: item.Val(html.Y), + height: item.Val(html.HEIGHT), width: item.Val(html.WIDTH), x: item.Val(svg.X), y: item.Val(svg.Y), target: item, ship: can.core.List(item.Value(ice.SHIP), function(ship) { return ship.pid && (ship.target = can.page.Select(can, can.svg, ice.PT+ship.pid)[0]) && ship }) @@ -416,7 +416,7 @@ Volcanos("ondetail", {help: "组件详情", list: [cli.START, ice.RUN, ice.COPY, can.onmotion.clear(can, can.ui.display), can.svg.Value("pid", target.Value("pid")) var index = target.Value(kit.MDB_INDEX); index && can.onappend.plugin(can, {type: chat.STORY, index: index, args: target.Value(kit.MDB_ARGS)}, function(sub) { sub.Conf("height", can.Conf("height")-can.svg.Val("height")-52), sub.Conf("width", can.Conf("width")) - sub.run = function(event, cmds, cb) { can.run(event, can.misc.Concat([ice.RUN, index], cmds), cb, true) } + sub.run = function(event, cmds, cb) { can.run(event, can.misc.concat([ice.RUN, index], cmds), cb, true) } can.onmotion.hidden(can, sub._legend), can.onmotion.hidden(can, can.ui.display, true) }, can.ui.display) }, @@ -462,14 +462,14 @@ Volcanos("onexport", {help: "导出数据", list: ["group", "figure", "index", " can.Status("index", target.Value("index")) }, _size: function(can, target, figure) { var size = figure.data.size||{} - return "<("+target.Val(size[chat.HEIGHT]||chat.HEIGHT)+ice.FS+target.Val(size[chat.WIDTH]||chat.WIDTH)+")" + return "<("+target.Val(size[html.HEIGHT]||html.HEIGHT)+ice.FS+target.Val(size[html.WIDTH]||html.WIDTH)+")" }, _position: function(can, target, figure) { var size = figure.data.size||{} - return "@("+target.Val(size[html.X]||html.X)+ice.FS+target.Val(size[html.Y]||html.Y)+")" + return "@("+target.Val(size[svg.X]||svg.X)+ice.FS+target.Val(size[svg.Y]||svg.Y)+")" }, _text: function(can, target, figure, data) { var size = figure.data.size||{} if (figure.text) { return figure.text(can, data, target) } - return data.x = target.Val(size[html.X]||html.X), data.y = target.Val(size[html.Y]||html.Y), data + return data.x = target.Val(size[svg.X]||svg.X), data.y = target.Val(size[svg.Y]||svg.Y), data }, _point: function(event, can) { var p = can.svg.getBoundingClientRect() @@ -481,9 +481,9 @@ Volcanos("onexport", {help: "导出数据", list: ["group", "figure", "index", " content: function(can, svg) { return ['"]).join("") + }): [" height="+((can.Conf(html.HEIGHT)||450)-50)+" width="+(can.Conf(html.WIDTH)||600)]).concat(['>', svg? svg.innerHTML: "", ""]).join("") }, cursor: function(event, can, item, show) { var p = item.getBoundingClientRect() @@ -514,17 +514,17 @@ Volcanos("onexport", {help: "导出数据", list: ["group", "figure", "index", " case 1: case 2: case 3: - point.y = target.Val(html.Y) + point.y = target.Val(svg.Y) break case 4: case 5: case 6: - point.y = target.Val(html.Y) + target.Val(chat.HEIGHT) / 2 + point.y = target.Val(svg.Y) + target.Val(html.HEIGHT) / 2 break case 7: case 8: case 9: - point.y = target.Val(html.Y) + target.Val(chat.HEIGHT) + point.y = target.Val(svg.Y) + target.Val(html.HEIGHT) break } @@ -532,17 +532,17 @@ Volcanos("onexport", {help: "导出数据", list: ["group", "figure", "index", " case 1: case 4: case 7: - point.x = target.Val(html.X) + point.x = target.Val(svg.X) break case 2: case 5: case 8: - point.x = target.Val(html.X) + target.Val(chat.WIDTH) / 2 + point.x = target.Val(svg.X) + target.Val(html.WIDTH) / 2 break case 3: case 6: case 9: - point.x = target.Val(html.X) + target.Val(chat.WIDTH) + point.x = target.Val(svg.X) + target.Val(html.WIDTH) break } return point @@ -550,8 +550,8 @@ Volcanos("onexport", {help: "导出数据", list: ["group", "figure", "index", " resize: function(event, item, begin, p0, p1, pos) { switch (pos) { case 5: - item.Value(html.X, begin.x + p1.x - p0.x) - item.Value(html.Y, begin.y + p1.y - p0.y) + item.Value(svg.X, begin.x + p1.x - p0.x) + item.Value(svg.Y, begin.y + p1.y - p0.y) return } @@ -559,30 +559,30 @@ Volcanos("onexport", {help: "导出数据", list: ["group", "figure", "index", " case 1: case 2: case 3: - item.Value(html.Y, begin.y + p1.y - p0.y) - item.Value(chat.HEIGHT, begin.height - p1.y + p0.y) + item.Value(svg.Y, begin.y + p1.y - p0.y) + item.Value(html.HEIGHT, begin.height - p1.y + p0.y) break } switch (pos) { case 1: case 4: case 7: - item.Value(html.X, begin.x + p1.x - p0.x) - item.Value(chat.WIDTH, begin.width - p1.x + p0.x) + item.Value(sve.X, begin.x + p1.x - p0.x) + item.Value(html.WIDTH, begin.width - p1.x + p0.x) break } switch (pos) { case 3: case 6: case 9: - item.Value(chat.WIDTH, begin.width + p1.x - p0.x) + item.Value(html.WIDTH, begin.width + p1.x - p0.x) break } switch (pos) { case 7: case 8: case 9: - item.Value(chat.HEIGHT, begin.height + p1.y - p0.y) + item.Value(html.HEIGHT, begin.height + p1.y - p0.y) break } }, diff --git a/plugin/local/wiki/feel.js b/plugin/local/wiki/feel.js index f31436be..03e71368 100644 --- a/plugin/local/wiki/feel.js +++ b/plugin/local/wiki/feel.js @@ -1,6 +1,6 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { can.path = can.request(), can.list = [], msg.Table(function(value) { - value.path.lastIndexOf("/")==value.path.length-1? can.path.Push(value): can.list.push(value) + value.path.lastIndexOf(ice.PS)==value.path.length-1? can.path.Push(value): can.list.push(value) }) can.base.isFunc(cb) && cb(msg) @@ -95,7 +95,7 @@ Volcanos("ondetail", {help: "组件菜单", list: ["关闭", "下载", "删除", can.order = index, can.show = function(order) { path = can.onimport._file(can, can.list[order].path) sub.page.Appends(sub, sub._output, [{img: path, style: {"max-width": width-40, "max-height": height-55}}]) - sub.Status("begin", order+1+"/"+can.list.length), sub.Status("file", path) + sub.Status("begin", order+1+ice.PS+can.list.length), sub.Status("file", path) }, can.show(can.order) }) }, document.body) @@ -114,12 +114,12 @@ Volcanos("ondetail", {help: "组件菜单", list: ["关闭", "下载", "删除", can.search(event, ["Header.onimport.background"], null, true) }, "复制链接": function(event, can) { - can.user.copy(event, can, can.user.MergeURL(can, {_path: can.onimport._file(can, can.list[can.order].path)}, true)) + can.user.copy(event, can, can.misc.MergeURL(can, {_path: can.onimport._file(can, can.list[can.order].path)}, true)) }, }) Volcanos("onexport", {help: "导出数据", list: ["begin", "limit", "total", "position", "file"], position: function(can, index, total) { total = total || can.max - return parseInt((index+1)*100/total)+"%"+" = "+(parseInt(index)+1)+"/"+parseInt(total) + return parseInt((index+1)*100/total)+"%"+" = "+(parseInt(index)+1)+ice.PS+parseInt(total) }, }) diff --git a/plugin/local/wiki/json.js b/plugin/local/wiki/json.js index 1980b545..b58c4711 100644 --- a/plugin/local/wiki/json.js +++ b/plugin/local/wiki/json.js @@ -5,7 +5,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, show: function(can, data, target) { function show(data, target, index, total) { var list switch (typeof data) { - case "object": + case lang.OBJECT: if (data == null) { return can.page.Append(can, list, [{text: "null"}]).node return @@ -33,7 +33,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, can.page.Append(can, node, [{text: ['"'+key+'"', "span", "key"], onclick: function(event) { toggle(sub) }}, {text: ': '}]) var sub = show(value, node, count++, length) }) }); break - case "string": /* 字串 */ can.page.Append(can, target, [{text: ['"'+data+'"', "span", "string"]}]); break + case lang.STRING: /* 字串 */ can.page.Append(can, target, [{text: ['"'+data+'"', "span", lang.STRING]}]); break default: /* 其它 */ can.page.Append(can, target, [{text: [''+data+'', "span", "const"]}]) } (index < total-1) && can.page.Append(can, target, [{text: ","}]) diff --git a/plugin/local/wiki/word.js b/plugin/local/wiki/word.js index e86d75b9..9e67739e 100644 --- a/plugin/local/wiki/word.js +++ b/plugin/local/wiki/word.js @@ -32,7 +32,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, can.page.Modify(can, can._output, {style: {float: "left", clear: "none"}}) can.onappend.list(can, can.base.Obj(data.data), function(event, item) { - var link = item.meta.link, cmd = link.split("/").pop() + var link = item.meta.link, cmd = link.split(ice.PS).pop() can.onmotion.select(can, nav, "div.item", event.target) if (can.onaction[cmd]) { return can.onaction[cmd](event, can) } @@ -94,7 +94,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, item.type = chat.PLUGIN can.onappend._init(can, item, ["/plugin/state.js"], function(sub) { sub.run = function(event, cmds, cb, silent) { - can.run(event, can.misc.Concat([ctx.ACTION, "story", data.type, data.name, data.text], cmds), cb, true) + can.run(event, can.misc.concat([ctx.ACTION, "story", data.type, data.name, data.text], cmds), cb, true) } sub.Conf("width", item.width=can.Conf("width")-20) @@ -131,7 +131,7 @@ Volcanos("onkeypop", {help: "键盘交互", list: [], }) Volcanos("onaction", {help: "控件交互", list: [], home: function(event, can) { - location.href = "/" + location.href = ice.PS }, "play": function(event, can) { var list = [], current = [] @@ -207,7 +207,7 @@ Volcanos("onaction", {help: "控件交互", list: [], sub.page.Select(sub, page, "h1,h2,h3", function(item) { sub.Action("菜单", item.innerHTML) }) sub.onmotion.select(sub, sub.ui.project, "div.item", index) sub.page.ClassList.add(sub, page, "select") - sub.Status("page", index+1+"/"+sub.list.length) + sub.Status("page", index+1+ice.PS+sub.list.length) } else { sub.page.ClassList.del(sub, page, "select") } diff --git a/plugin/state.js b/plugin/state.js index 1f312a82..6f0f2a8a 100644 --- a/plugin/state.js +++ b/plugin/state.js @@ -22,8 +22,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, conf, _display: function(can, msg) { Volcanos("some", {}, [msg.Option(ice.MSG_DISPLAY)].concat(Volcanos.meta.libs, Volcanos.meta.volcano), function(sub) { sub.Conf(can.Conf()), sub.run = can.run - sub._option = can._option - sub._action = can._action + sub._option = can._option, sub._action = can._action sub.onimport._init(sub, msg, [], function() {}, can._output) }) return true @@ -31,8 +30,8 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, conf, _field: function(can, msg) { msg.Table(function(item) { can.onappend._plugin(can, item, {arg: can.base.Obj(item[ice.ARG], [])}, function(sub, meta) { var opt = can.base.Obj(item[ice.OPT], []) - sub.Conf("height", can.Conf("height")) - sub.Conf("width", can.Conf("width")) + sub.Conf(html.HEIGHT, can.Conf(html.HEIGHT)) + sub.Conf(html.WIDTH, can.Conf(html.WIDTH)) sub.run = function(event, cmds, cb, silent) { var res = can.request(event, can.Option()) for (var i = 0; i < opt.length; i += 2) { res.Option(opt[i], opt[i+1]) } @@ -70,9 +69,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, conf, }).length == 0) { can.onappend.board(can, str) } - // can.onmotion.story.auto(can, can._output) }, - }) Volcanos("onaction", {help: "交互操作", list: [ "共享工具", "生成链接", "生成脚本", "保存参数", "清空参数", "刷新数据", [ @@ -92,13 +89,12 @@ Volcanos("onaction", {help: "交互操作", list: [ }); can.onlayout.figure(event, can, ui._target, true) }, "生成链接": function(event, can) { var meta = can.Conf() - var pre = "/chat/cmd/"; if (can.user.mod.isPod) { pre = "/chat/pod/"+can.user.Search(can, ice.POD)+"/cmd/" } + var pre = "/chat/cmd/"; if (can.user.mod.isPod) { pre = "/chat/pod/"+can.misc.Search(can, ice.POD)+"/cmd/" } var args = can.Option(); args._path = pre+(meta.index||can.core.Keys(meta.ctx, meta.cmd)) args._path.indexOf("/cmd/web.wiki.word") > -1 && (args = {_path: pre+args.path}) - var msg = can.request(event, {link: can.user.MergeURL(can, args)}) + var msg = can.request(event, {link: can.misc.MergeURL(can, args)}) can.search(event, ["Header.onaction.share"]) - can.user.copy(event, can, msg.Option("link")) }, "生成脚本": function(event, can, button) { var conf = can.Conf() var args = can.Input("", true).join(ice.SP); var list = [ @@ -115,7 +111,7 @@ Volcanos("onaction", {help: "交互操作", list: [ }, "保存参数": function(event, can) { var meta = can.Conf() var msg = can.request(event, {river: can.Conf(chat.RIVER), storm: can.Conf(chat.STORM), id: meta.id}) - can.search(event, ["River.ondetail.保存参数"], function(msg) { can.user.toast(can, "保存成功") }, true) + can.search(event, ["River.ondetail.保存参数"], function(msg) { can.user.toastSuccess(can) }, true) }, "清空参数": function(event, can) { can.page.SelectArgs(can, can._option, "", function(item) { return item.value = "" }) @@ -167,7 +163,6 @@ Volcanos("onaction", {help: "交互操作", list: [ }) }, - "参数": function(event, can) { can.onmotion.toggle(can, can._action) }, actions: function(event, can) { can.onmotion.toggle(can, can._action) }, clear: function(event, can, name) { can.onmotion.clear(can, can._output) }, close: function(event, can) { can.page.Remove(can, can._target) }, @@ -203,26 +198,26 @@ Volcanos("onaction", {help: "交互操作", list: [ }) var msg = can.request(event, {_handle: true, content: can.base.Format(list)}) can.run(event, [button], function() { - can.user.toast(can, "添加成功") + can.user.toastSuccess(can) }) }, getClipboardData: function(event, can, button) { function add(text) { - can.run(event, can.base.Simple(ctx.ACTION, button, can.base.parseJSON(text)), function(msg) { - can.user.toast(can, text, "添加成功"), can.Update() + can.run(event, can.base.Simple(ctx.ACTION, button, can.base.ParseJSON(text)), function(msg) { + can.user.toastSuccess(can), can.Update() }, true) } if (navigator.clipboard) { navigator.clipboard.readText().then(add).catch(function(err) { can.misc.Log(err) }) } else { - can.user.input(event, can, [{type: "textarea", name: "text"}], function(ev, button, data, list, args) { add(list[0]) }) + can.user.input(event, can, [{type: html.TEXTAREA, name: kit.MDB_TEXT}], function(ev, button, data, list, args) { add(list[0]) }) } }, getLocation: function(event, can, button) { can.user.agent.getLocation(function(data) { can.request(event, data) can.user.input(event, can, [kit.MDB_TYPE, kit.MDB_NAME, kit.MDB_TEXT, "latitude", "longitude"], function(ev, bu, data, list, args) { can.run(event, [ctx.ACTION, button].concat(can.base.Simple(args, data)), function(msg) { - can.user.toast(can, "添加成功"), can.Update() + can.user.toastSuccess(can), can.Update() }, true) }) }) diff --git a/plugin/story/pie.js b/plugin/story/pie.js index cfaa5388..5624c5d1 100644 --- a/plugin/story/pie.js +++ b/plugin/story/pie.js @@ -1,7 +1,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { can.require(["/plugin/local/wiki/draw.js", "/plugin/local/wiki/draw/path.js"], function() { can.onmotion.clear(can), can.onimport._show(can, msg) - var r = 200, margin = 20; can.svg.Val(chat.WIDTH, 2*(r+margin)), can.svg.Val(chat.HEIGHT, 2*(r+margin)) + var r = 200, margin = 20; can.svg.Val(html.WIDTH, 2*(r+margin)), can.svg.Val(html.HEIGHT, 2*(r+margin)) can.onimport._draw(can, msg, "value", r+margin, r+margin, r, margin, 0) can.onmotion.clear(can, can.ui.project), can.onappend.table(can, msg, null, can.ui.project) can.onmotion.hidden(can, can.ui.project, true) diff --git a/plugin/story/spide.js b/plugin/story/spide.js index e3ec2b02..72bb8414 100644 --- a/plugin/story/spide.js +++ b/plugin/story/spide.js @@ -66,17 +66,17 @@ Volcanos("onaction", {help: "用户操作", list: ["编辑", [ice.VIEW, "横向" can.onimport._height(can, can._tree[""]) can.sup.view = "横向", can.onmotion.clear(can, can.svg) - can.svg.Val(chat.HEIGHT, can._tree[""].height*can.size+2*can.margin) + can.svg.Val(html.HEIGHT, can._tree[""].height*can.size+2*can.margin) can.width = 0, can.onaction._draw_horizontal(can, can._tree[""], can.margin, can.margin) - can.svg.Val(chat.WIDTH, can.width+can.margin) + can.svg.Val(html.WIDTH, can.width+can.margin) }, "纵向": function(event, can) { can.onimport._width(can, can._tree[""]) can.sup.view = "纵向", can.onmotion.clear(can, can.svg) - can.svg.Val(chat.WIDTH, can._tree[""].width+2*can.margin) + can.svg.Val(html.WIDTH, can._tree[""].width+2*can.margin) can.height = 0, can.onaction._draw_vertical(can, can._tree[""], can.margin, can.margin+can.size) - can.svg.Val(chat.HEIGHT, can.height+can.margin) + can.svg.Val(html.HEIGHT, can.height+can.margin) }, _draw: function(can, tree, x, y, style) { var color = can.onimport._color(can, tree) @@ -124,7 +124,7 @@ Volcanos("onaction", {help: "用户操作", list: ["编辑", [ice.VIEW, "横向" Volcanos("ondetail", {help: "用户交互", list: [], onmouseenter: function(event, can, tree) { var y = tree.y+tree.height*can.size/2 can.page.Remove(can, can.pos), can.pos = can.onimport.draw({}, can, { - shape: html.RECT, point: [ + shape: svg.RECT, point: [ {x: tree.x-can.margin/4, y: y-can.size/2}, {x: tree.x+tree.width+can.margin/8, y: y+can.size/2}, ], style: {stroke: cli.RED, fill: html.NONE}, @@ -168,7 +168,7 @@ Volcanos("ondetail", {help: "用户交互", list: [], } can.onappend.plugin(can, can.base.Copy(value, {type: chat.FLOAT, index: index, args: args}), function(sub) { sub.run = function(event, cmds, cb) { can.request(event, value, can.Option()) - can.run(event, can.misc.Concat(prefix, cmds), cb, true) + can.run(event, can.misc.concat(prefix, cmds), cb, true) }, can.ondetail.figure(can, sub) }) }, @@ -178,14 +178,14 @@ Volcanos("ondetail", {help: "用户交互", list: [], var top = 120, margin = 20; if (can.user.isMobile) { margin = 0 if (can.user.isLandscape()) { height += (can.user.mod.isCmd? -20: 200) - top = 24, sub.Conf(chat.HEIGHT, height-top) + top = 24, sub.Conf(html.HEIGHT, height-top) } else { height += (can.user.mod.isCmd? -80: 200) - top = 48, sub.Conf(chat.HEIGHT, height-top) + top = 48, sub.Conf(html.HEIGHT, height-top) } } else { height += (can.user.mod.isCmd? 0: 300) - sub.Conf(chat.HEIGHT, height-top) + sub.Conf(html.HEIGHT, height-top) } var layout = {position: "fixed", left: left+margin, top: top} diff --git a/plugin/story/trend.js b/plugin/story/trend.js index 353df735..6809f56e 100644 --- a/plugin/story/trend.js +++ b/plugin/story/trend.js @@ -4,7 +4,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, can.onappend._status(can, ["from", "commit", "total", "max", "date", "text", "add", "del"]) can.msg = msg, can.data = msg.Table(), can.onimport._sum(can) - can.Action(chat.HEIGHT, msg.Option(chat.HEIGHT)||can.user.mod.isCmd? "max": can.user.isMobile&&can.user.isLandscape()? "200": "400") + can.Action(html.HEIGHT, msg.Option(html.HEIGHT)||can.user.mod.isCmd? "max": can.user.isMobile&&can.user.isLandscape()? "200": "400") can.Action("speed", parseInt(msg.Option("speed")||"100")) can.require(["/plugin/local/wiki/draw.js", "/plugin/local/wiki/draw/path.js"], function() { @@ -44,16 +44,16 @@ Volcanos("onaction", {help: "组件菜单", list: ["编辑", ["view", "趋势图 can.onmotion.toggle(can, can._action) can.onmotion.toggle(can, can._status) }, - "趋势图": function(event, can) { var height = can.Action(chat.HEIGHT) - if (height == "max") { height = can.Conf(chat.HEIGHT) - chat.CMD_MARGIN } + "趋势图": function(event, can) { var height = can.Action(html.HEIGHT) + if (height == "max") { height = can.Conf(html.HEIGHT) - chat.CMD_MARGIN } height = parseInt(height) - var space = 10, width = parseInt(can.Conf(chat.WIDTH)) + var space = 10, width = parseInt(can.Conf(html.WIDTH)) var step = parseInt((width-2*space) / can.list.length) can.onmotion.clear(can, can.svg) - can.svg.Val(chat.HEIGHT, height) - can.svg.Val(chat.WIDTH, width) + can.svg.Val(html.HEIGHT, height) + can.svg.Val(html.WIDTH, width) function scale(y) { return (y - can.min)/(can.max - can.min)*(height-2*space) } function order(index, x, y) { return {x: space+step*index+x, y: height-space-scale(y)} } @@ -98,13 +98,13 @@ Volcanos("onaction", {help: "组件菜单", list: ["编辑", ["view", "趋势图 }) }) - var height = parseInt(can.Action(chat.HEIGHT)) - var space = 10, width = parseInt(can.Conf(chat.WIDTH)) + var height = parseInt(can.Action(html.HEIGHT)) + var space = 10, width = parseInt(can.Conf(html.WIDTH)) var step = parseInt((width-2*space) / can.list.length) can.onmotion.clear(can, can.svg) - can.svg.Val(chat.HEIGHT, height) - can.svg.Val(chat.WIDTH, width) + can.svg.Val(html.HEIGHT, height) + can.svg.Val(html.WIDTH, width) function scale(key, y) { return (y - min[key])/(max[key] - min[key])*(height-2*space) } function order(index, key, x, y) { return {x: space+step*index+x, y: space+scale(key, y)} } diff --git a/plugin/table.js b/plugin/table.js index d01ff42c..d42c46b7 100644 --- a/plugin/table.js +++ b/plugin/table.js @@ -2,7 +2,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, can.onmotion.clear(can) can.onappend.table(can, msg) can.onappend.board(can, msg) - can.onmotion.story.auto(can, target) + can.onmotion.story.auto(can) can.base.isFunc(cb) && cb(msg) }, diff --git a/proto.js b/proto.js index 32ca0fe1..2e0ca730 100644 --- a/proto.js +++ b/proto.js @@ -1,8 +1,8 @@ var kit = { MDB_ID: "id", MDB_KEY: "key", - MDB_TIME: "time", MDB_ZONE: "zone", + MDB_TIME: "time", MDB_TYPE: "type", MDB_NAME: "name", MDB_TEXT: "text", @@ -34,13 +34,19 @@ var ice = { MSG_RIVER: "sess.river", MSG_STORM: "sess.storm", MSG_TOAST: "sess.toast", + + MSG_DETAIL: "detail", + MSG_OPTION: "option", + MSG_APPEND: "append", + MSG_RESULT: "result", MSG_FIELDS: "fields", MSG_SESSID: "sessid", - MSG_APPEND: "append", MSG_SOURCE: "_source", MSG_TARGET: "_target", MSG_HANDLE: "_handle", + MSG_DAEMON: "_daemon", + MSG_UPLOAD: "_upload", MSG_ACTION: "_action", MSG_STATUS: "_status", @@ -54,9 +60,9 @@ var ctx = { CONTEXT: "context", COMMAND: "command", ACTION: "action", CONFIG: "config", } var cli = { - DONE: "done", START: "start", STOP: "stop", OPEN: "open", CLOSE: "close", + DONE: "done", ERROR: "error", CLEAR: "clear", REFRESH: "refresh", RED: "red", GREEN: "green", BLUE: "blue", @@ -64,8 +70,7 @@ var cli = { WHITE: "white", BLACK: "black", } var web = { - SHARE: "share", - SPACE: "space", + SPACE: "space", SHARE: "share", } var aaa = { USERNAME: "username", USERNICK: "usernick", BACKGROUND: "background", AVATAR: "avatar", @@ -84,8 +89,7 @@ var ssh = { } var nfs = { PATH: "path", FILE: "file", LINE: "line", - TRASH: "trash", - DIR: "dir", CAT: "cat", + DIR: "dir", CAT: "cat", TRASH: "trash", DIR_ROOT: "dir_root", } var tcp = { @@ -104,13 +108,8 @@ var wiki = { var chat = { LIB: "lib", PAGE: "page", PANEL: "panel", PLUGIN: "plugin", STORY: "story", FLOAT: "float", CONTEXTS: "contexts", CARTE: "carte", INPUT: "input", OUTPUT: "output", - HEAD: "head", LEFT: "left", MAIN: "main", AUTO: "auto", FOOT: "foot", - LAYOUT: "layout", PROJECT: "project", CONTENT: "content", DISPLAY: "display", PROFILE: "profile", - SCROLL: "scroll", HEIGHT: "height", WIDTH: "width", LEFT: "left", TOP: "top", RIGHT: "right", BOTTOM: "bottom", OPTION: "option", ACTION: "action", OUTPUT: "output", STATUS: "status", - - HEADER: "header", FOOTER: "footer", - ONMAIN: "onmain", ONSIZE: "onsize", ONLOGIN: "onlogin", ONSEARCH: "onsearch", + LAYOUT: "layout", PROJECT: "project", CONTENT: "content", DISPLAY: "display", PROFILE: "profile", TITLE: "title", TOPIC: "topic", BLACK: "black", WHITE: "white", PRINT: "print", SHARE: "share", RIVER: "river", STORM: "storm", FIELD: "field", TOAST: "toast", @@ -120,6 +119,12 @@ var chat = { AGENT: "agent", CHECK: "check", GRANT: "grant", STATE: "state", MENUS: "menus", TRANS: "trans", + ONMAIN: "onmain", ONSIZE: "onsize", ONLOGIN: "onlogin", ONSEARCH: "onsearch", + + HEAD: "head", LEFT: "left", MAIN: "main", AUTO: "auto", FOOT: "foot", + SCROLL: "scroll", LEFT: "left", TOP: "top", RIGHT: "right", BOTTOM: "bottom", + HEADER: "header", FOOTER: "footer", + SSO: "sso", CMD_MARGIN: 53, } @@ -131,27 +136,31 @@ var mall = { } var svg = { + G: "g", X: "x", Y: "y", R: "r", RECT: "rect", M: "M", Q: "Q", T: "T", } var html = { FIELDSET: "fieldset", LEGEND: "legend", OPTION: "option", ACTION: "action", OUTPUT: "output", STATUS: "status", FORM_OPTION: "form.option", DIV_ACTION: "div.action", DIV_OUTPUT: "div.output", DIV_STATUS: "div.status", + UPLOAD: "upload", USERNAME: "username", PASSWORD: "password", INPUT: "input", INPUT_ARGS: ".args", TEXT: "text", TEXTAREA: "textarea", SELECT: "select", BUTTON: "button", FORM: "form", FILE: "file", SPACE: "space", CLICK: "click", + DIV: "div", IMG: "img", CODE: "code", SPAN: "span", VIDEO: "video", + TABLE: "table", TR: "tr", TH: "th", TD: "td", BR: "br", + SCROLL: "scroll", HEIGHT: "height", WIDTH: "width", LEFT: "left", TOP: "top", RIGHT: "right", BOTTOM: "bottom", - TABLE: "table", TR: "tr", TH: "th", TD: "td", BR: "br", - DIV: "div", IMG: "img", CODE: "code", SPAN: "span", VIDEO: "video", - SVG: "svg", G: "g", X: "x", Y: "y", R: "r", RECT: "rect", - LABEL: "label", INNER: "inner", - CLASS: "class", BLOCK: "block", NONE: "none", + TITLE: "title", A: "a", LABEL: "label", INNER: "inner", STROKE_WIDTH: "stroke-width", STROKE: "stroke", FILL: "fill", FONT_SIZE: "font-size", MONOSPACE: "monospace", LIST: "list", ITEM: "item", MENU: "menu", + SUBMIT: "submit", CANCEL: "cancel", + WSS: "wss", SVG: "svg", } var lang = { - STRING: "string", OBJECT: "object", FUNCTION: "function", + STRING: "string", NUMBER: "number", + OBJECT: "object", FUNCTION: "function", ESCAPE: "Escape", ENTER: "Enter", } function shy(help, meta, list, cb) { @@ -256,8 +265,8 @@ var Volcanos = shy("火山架", {iceberg: "/chat/", volcano: "/frame.js", args: } else if (libs[i] == "") { libs[i] = _can_path.replace(".js", ".css") - } else if (libs[i][0] != "/" && libs[i].indexOf("http") != 0) { - libs[i] = _can_path.slice(0, _can_path.lastIndexOf("/")+1)+libs[i] + } else if (libs[i][0] != ice.PS && libs[i].indexOf("http") != 0) { + libs[i] = _can_path.slice(0, _can_path.lastIndexOf(ice.PS)+1)+libs[i] } } } diff --git a/publish/chrome/contexts.js b/publish/chrome/contexts.js index 0800dd01..a8e0e263 100644 --- a/publish/chrome/contexts.js +++ b/publish/chrome/contexts.js @@ -34,7 +34,7 @@ setTimeout(function() { Volcanos({ can.onmotion.float.auto(can, sub._target, chat.CARTE) sub.run = function(event, cmds, cb) { - can.run(event, can.misc.Concat([ctx.ACTION, ice.RUN, meta.index], cmds), cb) + can.run(event, can.misc.concat([ctx.ACTION, ice.RUN, meta.index], cmds), cb) } msg.Option("selection") && (can.onengine.listen(can, "onselection", function() { @@ -46,14 +46,14 @@ setTimeout(function() { Volcanos({ can.run(event, [chat.FIELD, mdb.MODIFY, chat.TOP, sub._target.offsetTop]) can.run(event, [chat.FIELD, mdb.MODIFY, chat.LEFT, sub._target.offsetLeft]) can.run(event, [chat.FIELD, mdb.MODIFY, "args", JSON.stringify(sub.Input([], true))]) - can.user.toast(can, "保存成功") + can.user.toastSuccess(can) } }, document.body) }, order: function(can, msg, arg) { var ui = can.user.input(event, can, ["index", "args", "selection", "left", "top"], function(event, button, data, list, args) { can.run(event, [chat.FIELD, mdb.INSERT, kit.MDB_ZONE, location.host].concat(args), function(res) { - can.user.toast(can, "添加成功") + can.user.toastSuccess(can) }) }); can.page.Modify(can, ui._target, {style: {left: 200, top: 200}}) can.page.ClassList.add(can, ui._target, chat.CONTEXTS) @@ -98,7 +98,7 @@ setTimeout(function() { Volcanos({ }) can.run = function(event, cmds, cb) { if (cmds[0] == "_search") { return } - var msg = can.request(event, {host: location.host}); msg.detail = can.misc.Concat(["page"], cmds) + var msg = can.request(event, {host: location.host}); msg.detail = can.misc.concat(["page"], cmds) chrome.runtime.sendMessage(msg, function(res) { can.base.isFunc(cb) && cb(msg.Copy(res)) }) } can.run({}, [ctx.ACTION, ctx.COMMAND], function(msg) {