mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 16:58:06 +08:00
opt lib
This commit is contained in:
parent
4bb9ed7ca4
commit
4e44a7fbe2
5
frame.js
5
frame.js
@ -462,6 +462,11 @@ Volcanos(chat.ONMOTION, {_init: function(can, target) {
|
||||
index > 0 && can.page.ClassList.set(can, tr, html.HIDDEN, can.page.Select(can, tr, html.TD, function(td) { if (td.innerText.indexOf(value) > -1) { return td } }) == 0)
|
||||
}) },
|
||||
|
||||
delayResize: function(can, target, key) {
|
||||
can.onmotion.delay(can, function() { can.page.Select(can, target, key, function(_target) {
|
||||
can.page.style(can, target, html.WIDTH, _target.offsetWidth, html.LEFT, (window.innerWidth-_target.offsetWidth)/2)
|
||||
}) })
|
||||
},
|
||||
delay: function(can, cb, interval) { can.core.Timer(interval||30, cb) },
|
||||
clear: function(can, target) { return can.page.Modify(can, target||can._output, ""), target },
|
||||
cache: function(can, next) { var list = can.base.getValid(can.base.Obj(can.core.List(arguments).slice(2)), [can._output])
|
||||
|
70
lib/misc.js
70
lib/misc.js
@ -127,10 +127,9 @@ Volcanos("misc", {Message: function(event, can) { var msg = {}
|
||||
WSS: function(can, args, cb, onopen, onclose, onerror) { if (can.user.isIE) { return }
|
||||
var url = location.protocol.replace(ice.HTTP, "ws")+"//"+location.host+"/space/"
|
||||
if (url.indexOf(html.CHROME) == 0) { url = "ws://localhost:9020/space/" }
|
||||
|
||||
var socket = new WebSocket(can.base.MergeURL(url, args))
|
||||
socket.onclose = function() { can.misc.Log(html.WSS, cli.CLOSE, args)
|
||||
can.base.isFunc(onclose)? onclose(socket): can.core.Timer(can.base.random(3000, 1000), function() {
|
||||
can.base.isFunc(onclose)? onclose(socket): can.core.Timer(can.base.random(3000, 100), function() {
|
||||
args.name = args.name||can._wss_name, can.misc.WSS(can, args, cb, onopen, onerror, onclose)
|
||||
})
|
||||
}, socket.onerror = function() { can.misc.Log(html.WSS, log.ERROR, args)
|
||||
@ -139,16 +138,12 @@ Volcanos("misc", {Message: function(event, can) { var msg = {}
|
||||
can.base.isFunc(onopen) && onopen(socket)
|
||||
}, socket.onmessage = function(event) {
|
||||
try { var data = JSON.parse(event.data) } catch (e) { var data = {detail: [event.data]} }
|
||||
|
||||
var msg = can.request(event); msg.Reply = function() {
|
||||
var res = can.request({}); res._source = (msg[ice.MSG_TARGET]||[]).reverse().slice(1)||[]
|
||||
res.Option({_handle: ice.TRUE, _target: (msg[ice.MSG_SOURCE]||[]).reverse().join(ice.PT)})
|
||||
var msg = can.request(event); msg.Reply = function() { var res = can.request({}, {_handle: ice.TRUE})
|
||||
res._target = (msg[ice.MSG_SOURCE]||[]).reverse(), res._source = (msg[ice.MSG_TARGET]||[]).reverse().slice(1)||[]
|
||||
res.append = msg.append, can.core.List(msg.append, function(key) { res[key] = msg[key] }), res.result = (msg.result||[]).concat(can.core.List(arguments))
|
||||
res.Option(ice.LOG_DISABLE, msg.Option(ice.LOG_DISABLE)) != ice.TRUE && can.misc.Log(html.WSS, ice.MSG_RESULT, msg.result||[], msg)
|
||||
var e = socket.send(JSON.stringify(res))
|
||||
can.misc.Log(e)
|
||||
var e = socket.send(JSON.stringify(res)); can.misc.Log(e)
|
||||
}, msg.detail = data.detail, msg.Copy(data)
|
||||
|
||||
try {
|
||||
msg.Option(ice.LOG_DISABLE) != ice.TRUE && can.misc.Log(html.WSS, ice.MSG_DETAIL, msg.detail, msg)
|
||||
can.core.CallFunc(cb, {event: event, msg: msg, cmd: msg.detail[0], arg: msg.detail.slice(1), cb: function() { msg.Reply() }})
|
||||
@ -165,7 +160,7 @@ Volcanos("misc", {Message: function(event, can) { var msg = {}
|
||||
MergeURL: function(can, objs, clear) { var pod = ""
|
||||
var path = location.pathname; objs._path && (path = objs._path), delete(objs._path)
|
||||
objs.pod && (path = can.base.Path("/chat/pod/", objs.pod)), delete(objs.pod)
|
||||
var ls = path.split("/"); ls[1] == "chat" && ls[2] == "pod" && (pod = ls[3])
|
||||
var ls = path.split(ice.PS); ls[1] == "chat" && ls[2] == "pod" && (pod = ls[3])
|
||||
objs.cmd && (path = can.base.Path("/chat", pod? "pod/"+pod: "", ice.CMD, objs.cmd)), delete(objs.cmd)
|
||||
objs.website && (path = can.base.Path("/chat", pod? "pod/"+pod: "", web.WEBSITE, objs.website)), delete(objs.website)
|
||||
return can.base.MergeURL(location.origin+path+(clear?"":location.search), objs)
|
||||
@ -178,27 +173,23 @@ Volcanos("misc", {Message: function(event, can) { var msg = {}
|
||||
Search: function(can, key, value) { var args = {}
|
||||
if (value == undefined && can.base.isString(key)) { var ls = can.core.Split(location.pathname, ice.PS); if (ls[0] == chat.SHARE) { args[chat.SHARE] = ls[1] }
|
||||
for (var i = 1; i < ls.length; i += 2) { if (kit.Dict(ice.POD, true, ice.CMD, true, web.WEBSITE, true)[ls[i]]) { args[ls[i]] = ls[i+1] } }
|
||||
} location.search && location.search.slice(1).split("&").forEach(function(item) { var x = item.split(ice.EQ); x[1] != "" && (args[x[0]] = decodeURIComponent(x[1])) })
|
||||
|
||||
} location.search && location.search.slice(1).split("&").forEach(function(item) { var ls = item.split(ice.EQ); ls[1] != "" && (args[decodeURIComponent(ls[0])] = decodeURIComponent(ls[1])) })
|
||||
if (can.base.isUndefined(key)) { return args } else if (can.base.isObject(key)) {
|
||||
can.core.Item(key, function(key, value) { can.base.isUndefined(value) || (args[key] = value), args[key] == "" && delete(args[key]) })
|
||||
can.core.Item(key, function(k, v) { args[k] === ""? delete(args[k]): (args[k] = v) })
|
||||
} else if (can.base.isUndefined(value)) { return args[key] } else {
|
||||
args[key] = value, args[key] == "" && delete(args[key])
|
||||
args[key] == ""? delete(args[key]): (args[key] = value)
|
||||
}
|
||||
var search = can.core.Item(args, function(key, value) { return key+ice.EQ+encodeURIComponent(value) }).join("&")
|
||||
return search? location.search = search: location.href = location.pathname
|
||||
var search = can.base.Args(args); return search? location.search = search: location.href = location.pathname
|
||||
},
|
||||
CookieSessid: function(can, value, path) {
|
||||
return can.misc.Cookie(can, ice.MSG_SESSID+"_"+(can.base.replaceAll(location.port, ice.PT, "_", ice.DF, "_")||(location.protocol == "https:"? "443": "80")), value, path)
|
||||
return can.misc.Cookie(can, ice.MSG_SESSID+"_"+can.base.replaceAll(location.host, ice.PT, "_", ice.DF, "_"), value, path)
|
||||
return can.misc.Cookie(can, ice.MSG_SESSID+"_"+(location.port||(location.protocol == "https:"? "443": "80")), value, path)
|
||||
},
|
||||
Cookie: function(can, key, value, path) {
|
||||
function set(k, v) { document.cookie = k+ice.EQ+v+";path="+(path||ice.PS) }
|
||||
if (can.base.isObject(key)) { for (var k in key) { set(k, key[k]) } key = undefined }
|
||||
if (can.base.isUndefined(key)) { var cs = {}
|
||||
return document.cookie.split("; ").forEach(function(item) { var ls = item.split(ice.EQ); cs[ls[0]] = ls[1] }), cs
|
||||
}
|
||||
can.base.isUndefined(value) || set(key, value)
|
||||
} can.base.isUndefined(value) || set(key, value)
|
||||
var val = (new RegExp(key+"=([^;]*);?")).exec(document.cookie)
|
||||
return val && val.length > 1? val[1]: ""
|
||||
},
|
||||
@ -206,37 +197,33 @@ Volcanos("misc", {Message: function(event, can) { var msg = {}
|
||||
if (value != undefined) { localStorage.setItem(key, value) }
|
||||
return localStorage.getItem(key)
|
||||
},
|
||||
Log: function() {
|
||||
var args = [this._time(), this.FileLine(2, 3), ""]
|
||||
for (var i in arguments) { arguments[i] != undefined && args.push(arguments[i]) }
|
||||
console.log.apply(console, args)
|
||||
if (arguments[0] && arguments[0].onengine) { var can = arguments[0]; can.onengine.signal(can, chat.ONDEBUG, can.request({}, {time: can.misc._time(), fileline: can.misc.FileLine(-3), _args: args})) }
|
||||
_signal: function(can, args) {
|
||||
if (can && can.onengine) { can.onengine.signal(can, chat.ONDEBUG, can.request({}, {time: this._time(), fileline: this.FileLine(-4), _args: args})) }
|
||||
},
|
||||
Info: function() {
|
||||
var args = [this._time(), this.FileLine(2, 3), log.INFO]
|
||||
Log: function() { var args = [this._time(), this.FileLine(2, 3), ""]
|
||||
for (var i in arguments) { arguments[i] != undefined && args.push(arguments[i]) }
|
||||
console.info.apply(console, args)
|
||||
if (arguments[0] && arguments[0].onengine) { var can = arguments[0]; can.onengine.signal(can, chat.ONDEBUG, can.request({}, {time: can.misc._time(), fileline: can.misc.FileLine(-3), _args: args})) }
|
||||
console.log.apply(console, args), this._signal(arguments[0], args)
|
||||
},
|
||||
Warn: function() {
|
||||
var args = [this._time(), this.fileLine(2, 3).link, log.WARN]
|
||||
Info: function() { var args = [this._time(), this.FileLine(2, 3), log.INFO]
|
||||
for (var i in arguments) { arguments[i] != undefined && args.push(arguments[i]) }
|
||||
console.warn.apply(console, args)
|
||||
if (arguments[0] && arguments[0].onengine) { var can = arguments[0]; can.onengine.signal(can, chat.ONDEBUG, can.request({}, {time: can.misc._time(), fileline: can.misc.FileLine(-3), _args: args})) }
|
||||
console.info.apply(console, args), this._signal(arguments[0], args)
|
||||
},
|
||||
Error: function() {
|
||||
var args = [this._time(), this.fileLine(2, 3).link, log.ERROR]
|
||||
Warn: function() { var args = [this._time(), this.fileLine(2, 3).link, log.WARN]
|
||||
for (var i in arguments) { arguments[i] != undefined && args.push(arguments[i]) }
|
||||
console.warn.apply(console, args), this._signal(arguments[0], args)
|
||||
debugger
|
||||
},
|
||||
Error: function() { var args = [this._time(), this.fileLine(2, 3).link, log.ERROR]
|
||||
for (var i in arguments) { arguments[i] != undefined && args.push(arguments[i]) }
|
||||
args.push(ice.NL, this._stack().slice(1).join(ice.NL))
|
||||
console.error.apply(console, args)
|
||||
if (arguments[0] && arguments[0].onengine) { var can = arguments[0]; can.onengine.signal(can, chat.ONDEBUG, can.request({}, {time: can.misc._time(), fileline: can.misc.FileLine(-3), _args: args})) }
|
||||
console.error.apply(console, args), this._signal(arguments[0], args)
|
||||
debugger
|
||||
},
|
||||
Debug: function() {
|
||||
var args = [this._time(), this.fileLine(2, 3).link, log.DEBUG]
|
||||
Debug: function() { var args = [this._time(), this.fileLine(2, 3).link, log.DEBUG]
|
||||
for (var i in arguments) { arguments[i] != undefined && args.push(arguments[i]) }
|
||||
args.push(ice.NL, this._stacks().slice(1, 4).join(ice.NL))
|
||||
console.debug.apply(console, args)
|
||||
if (arguments[0] && arguments[0].onengine) { var can = arguments[0]; can.onengine.signal(can, chat.ONDEBUG, can.request({}, {time: can.misc._time(), fileline: can.misc.FileLine(-3), _args: args})) }
|
||||
console.debug.apply(console, args), this._signal(arguments[0], args)
|
||||
debugger
|
||||
},
|
||||
Trace: function() { var filter = "", output = false
|
||||
var args = [this._time(), this.fileLine(2, 3).link, log.TRACE]
|
||||
@ -250,6 +237,7 @@ Volcanos("misc", {Message: function(event, can) { var msg = {}
|
||||
output = true
|
||||
} args.push(arguments[i])
|
||||
} if (output) { return console.trace.apply(console, args), true }
|
||||
debugger
|
||||
},
|
||||
FileLine: function(depth, length) { var file = this.fileLine(depth+1, length||9); return file.file+ice.DF+file.line },
|
||||
fileLine: function(depth, length) { var list = this._stack()
|
||||
|
44
lib/page.js
44
lib/page.js
@ -9,11 +9,6 @@ Volcanos("page", {ClassList: {
|
||||
set: function(can, obj, key, condition) { return (condition? this.add(can, obj, key): this.del(can, obj, key)).indexOf(key) > -1 },
|
||||
neg: function(can, obj, key) { return (this.has(can, obj, key)? this.del(can, obj, key): this.add(can, obj, key)).indexOf(key) > -1 },
|
||||
},
|
||||
SelectAll: function(can, target, key, cb, interval, cbs) {
|
||||
can.page.Select(can, target, html.IFRAME, function(item) { can.page.SelectAll(can, item.contentWindow.document.body, key, cb, interval, cbs) })
|
||||
return can.core.List(target && target.querySelectorAll(key), cb, interval, cbs)
|
||||
},
|
||||
SelectInput: function(can, target, name, cb) { return can.page.Select(can, target, "input[name="+name+"]", cb)[0] },
|
||||
SelectArgs: function(can, option, key, cb) {
|
||||
if (can.base.isUndefined(option)) { return can.page.SelectArgs(can, can._option, "").concat(can.page.SelectArgs(can, can._action, "")) }
|
||||
if (can.base.isUndefined(key)) { var value = {}; can.page.SelectArgs(can, option, "", function(item) { item.name && item.value && (value[item.name] = item.value) }); return [value] }
|
||||
@ -22,10 +17,15 @@ Volcanos("page", {ClassList: {
|
||||
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)
|
||||
},
|
||||
SelectInput: function(can, target, name, cb) { return can.page.Select(can, target, "input[name="+name+"]", cb)[0] },
|
||||
SelectChild: function(can, target, key, cb) { var i = 0; return can.page.Select(can, target, key, function(node) { if (node.parentNode == target) { return cb(node, i++) } }) },
|
||||
SelectAll: function(can, target, key, cb, interval, cbs) {
|
||||
can.page.Select(can, target, html.IFRAME, function(item) { can.page.SelectAll(can, item.contentWindow.document.body, key, cb, interval, cbs) })
|
||||
return can.core.List(target && target.querySelectorAll(key), cb, interval, cbs)
|
||||
},
|
||||
SelectOne: function(can, target, key, cb) { return can.page.Select(can, target, key, function(target, index) { index == 0 && can.base.isFunc(cb) && cb(target) })[0] },
|
||||
Select: function(can, target, key, cb, interval, cbs) { if (key == ice.PT) { cb(target); return [] }
|
||||
return can.core.List(target && target.querySelectorAll(can.page.Keys(key)), cb, interval, cbs)
|
||||
Select: function(can, target, key, cb, interval, cbs) { target = target || document.body; if (key == ice.PT) { cb(target); return [] }
|
||||
return can.core.List(target.querySelectorAll(can.page.Keys(key)), cb, interval, cbs)
|
||||
},
|
||||
Modify: function(can, target, value) { target = can.base.isString(target)? document.querySelector(target): target; if (!target) { return }
|
||||
can.base.isString(value)? (target.innerHTML = value): can.core.Item(value, function(key, val) {
|
||||
@ -43,10 +43,9 @@ Volcanos("page", {ClassList: {
|
||||
Remove: function(can, target) { return target && target.parentNode && target.parentNode.removeChild(target), target },
|
||||
Append: function(can, target, key, value) { value = value||{}
|
||||
if (can.base.isString(key)) { var res = can.page.Create(can, key, value); return target.appendChild(res), res }
|
||||
can.core.List(key, function(item, index) { if (!item) { return }
|
||||
can.core.List(key, function(item) { if (!item) { return }
|
||||
if (item.nodeName) { target.appendChild(item); return }
|
||||
if (can.base.isString(item)) { item = {view: [item]} }
|
||||
|
||||
var type = item.type||html.DIV, data = item.data||{}, name = item.name||data.name||""
|
||||
can.core.Item(item, function(key, value) { switch (key) {
|
||||
case mdb.TYPE: break
|
||||
@ -57,7 +56,6 @@ Volcanos("page", {ClassList: {
|
||||
case html.INNER: data.innerHTML = item.inner; break
|
||||
default: can.base.isUndefined(item[key]) || (data[key] = item[key])
|
||||
} })
|
||||
|
||||
if (item.view) { var list = can.core.List(item.view); if (can.base.isArray(list[0])) { list[0] = list[0].join(ice.SP) }
|
||||
list[0] && can.page.ClassList.add(can, data, list[0]), type = list[1]||html.DIV, data.innerHTML = list[2]||data.innerHTML||"", name = name||list[3]||""
|
||||
} else if (item.text) { var list = can.core.List(item.text); if (can.base.isArray(list[2])) { list[2] = list[2].join(ice.SP) }
|
||||
@ -83,21 +81,19 @@ Volcanos("page", {ClassList: {
|
||||
} else if (item.row) { type = html.TR, item.list = item.row.map(function(text) { return {text: [text, item.sub||html.TD]} })
|
||||
} else if (item.th) { type = html.TR, item.list = item.th.map(function(text) { return {text: [text, html.TH]} })
|
||||
} else if (item.td) { type = html.TR, item.list = item.td.map(function(text) { return {text: [text, html.TD]} }) }
|
||||
|
||||
if (type == html.SELECT) { data.title = can.user.trans(can, data.title||data.name) }
|
||||
if (type == html.INPUT) { data.type == html.BUTTON && (data.value = can.user.trans(can, data.value))
|
||||
if (data.type == html.TEXT||data.type == html.PASSWORD||!data.type) { data.autocomplete = data.autocomplete||"off"
|
||||
data.placeholder = (data.placeholder||data.name||"").split(ice.PT).pop(), data.title = can.user.trans(can, data.title||data.placeholder)
|
||||
}
|
||||
} else if (type == html.TEXTAREA) { data.placeholder = can.user.trans(can, (data.placeholder||data.name||"").split(ice.PT).pop()) }
|
||||
|
||||
!data.name && item.name && (data.name = item.name); var node = can.page.Create(can, type, data)
|
||||
value[name||""] = value[can.core.Split(data.className)[0]||""] = value[type] = node, value._target = value._target||node, value.first = value.first||node, value.last = node
|
||||
item.list && can.page.Append(can, node, item.list, value), target && target.appendChild && target.appendChild(node), can.base.isFunc(item._init) && item._init(node, value)
|
||||
}); return value
|
||||
},
|
||||
Appends: function(can, target, key, value) { return target.innerHTML = "", can.page.Append(can, target, key, value) },
|
||||
AppendTable: function(can, msg, target, list, cb) { if (!msg.append||msg.append.length == 0) {return}
|
||||
AppendTable: function(can, msg, target, list, cb) { if (!msg.append||msg.append.length == 0) { return }
|
||||
var table = can.page.Append(can, target, html.TABLE), thead = can.page.Append(can, table, html.THEAD), tbody = can.page.Append(can, table, html.TBODY)
|
||||
can.page.Append(can, thead, [{type: html.TR, data: {dataset: {index: -1}}, list: can.core.List(list, function(key) { return key[0] != "_" && {text: [key.trim(), html.TH]} }) }])
|
||||
can.page.Append(can, tbody, can.core.List(msg.Table(), function(line, index, array) { return {type: html.TR, dataset: {index: index}, list: can.core.List(list, function(key) { return key[0] != "_" && cb(can.page.Color(line[key]).trim(), key, index, line, array) }) } }))
|
||||
@ -116,7 +112,6 @@ Volcanos("page", {ClassList: {
|
||||
if (a.childNodes[index[0]].innerHTML < b.childNodes[index[0]].innerHTML) { return true }
|
||||
if (a.childNodes[index[0]].innerHTML > b.childNodes[index[0]].innerHTML) { return false }
|
||||
} return index.length > 1 && isless(a, b, index.slice(1)) }
|
||||
|
||||
for (var i = 0; i < num_list.length; i++) { var min = i
|
||||
for (var j = i+1; j < num_list.length; j++) {
|
||||
if (sort_asc? num_list[min] < num_list[j]: num_list[j] < num_list[min]) { min = j; continue }
|
||||
@ -129,7 +124,6 @@ Volcanos("page", {ClassList: {
|
||||
var tbody = list[i].parentElement; list[i].parentElement && tbody.removeChild(list[i]), tbody.appendChild(list[i])
|
||||
}
|
||||
},
|
||||
|
||||
inputs: function(can, list) {
|
||||
var _list = []; for (var i = 0; i < list.length; i++) { switch (list[i]) {
|
||||
case "": _list.push(""); break
|
||||
@ -143,7 +137,7 @@ Volcanos("page", {ClassList: {
|
||||
_list.push(mdb.NEXT, mdb.PREV)
|
||||
break
|
||||
default:
|
||||
(function() { var item = can.core.SplitInput(list[i], html.BUTTON);
|
||||
(function() { var item = can.core.SplitInput(list[i], html.BUTTON)
|
||||
if (item.type == html.SELECT) { item._init = function(target) { target.value = item.value||item.values[0], target.onchange = function(event) { can.run(event) } } }
|
||||
item.action && (function() { item._init = function(target) { can.onappend.figure(can, item, target) } })()
|
||||
item.type == html.BUTTON? _list.push(list[i]): _list.push(item)
|
||||
@ -175,10 +169,8 @@ Volcanos("page", {ClassList: {
|
||||
item.className || can.page.ClassList.add(can, item, ctx.ARGS); break
|
||||
case html.BUTTON: item.value = item.value||item.name||mdb.LIST; break
|
||||
case html.UPLOAD: item.type = html.FILE, input.name = html.UPLOAD; break
|
||||
case "upfile": item.type = html.FILE; break
|
||||
} return input
|
||||
},
|
||||
|
||||
Format: function(type) { var args = arguments; switch (type) {
|
||||
case html.A: return "<a href='"+args[1]+"' target='_blank'>"+(args[2]||args[1])+"</a>"
|
||||
case html.IMG: return args[2]? "<img src='"+args[1]+"' height="+args[2]+">": "<img src='"+args[1]+"'>"
|
||||
@ -209,26 +201,22 @@ Volcanos("page", {ClassList: {
|
||||
} else { list.push(v+"") }
|
||||
} return list.join(ice.FS)
|
||||
},
|
||||
Cache: function(name, output, data) { if (!name) { return }
|
||||
var cache = output._cache||{}; output._cache = cache
|
||||
if (data) { if (output.children.length == 0) { return }
|
||||
var temp = document.createDocumentFragment()
|
||||
Cache: function(name, output, data) { if (!name) { return } var cache = output._cache||{}; output._cache = cache
|
||||
if (data) { if (output.children.length == 0) { return } var temp = document.createDocumentFragment()
|
||||
while (output.childNodes.length > 0) { var item = output.childNodes[0]; item.parentNode.removeChild(item), temp.appendChild(item) }
|
||||
return cache[name] = {node: temp, data: data}, name
|
||||
} output.innerHTML = ""
|
||||
var list = cache[name]; if (!list) { return }
|
||||
} output.innerHTML = ""; var list = cache[name]; if (!list) { return }
|
||||
while (list.node.childNodes.length > 0) { var item = list.node.childNodes[0]; item.parentNode.removeChild(item), output.appendChild(item) }
|
||||
return delete(cache[name]), list.data
|
||||
},
|
||||
|
||||
insertBefore: function(can, list, before, parent) { parent = parent||before.parentNode
|
||||
var item = can.base.isArray(list)? can.page.Append(can, parent, list)._target: list
|
||||
return before && parent.insertBefore(item, before), item
|
||||
var target = can.base.isArray(list)? can.page.Append(can, parent, list)._target: list
|
||||
return before && parent.insertBefore(target, before), target
|
||||
},
|
||||
styleDisplay: function(can, target, value) { return can.page.style(can, target, html.DISPLAY, value), target.style.display },
|
||||
styleHeight: function(can, target, value) { return can.page.style(can, target, html.HEIGHT, value), target.offsetHeight },
|
||||
styleWidth: function(can, target, value) { return can.page.style(can, target, html.WIDTH, value), target.offsetWidth },
|
||||
styleClass: function(can, target, value) { can.page.Modify(can, target, {className: value}) },
|
||||
styleClass: function(can, target, value) { return can.page.Modify(can, target, {className: value}), target.className },
|
||||
style: function(can, target, style) { var value = {}
|
||||
for (var i = 2; i < arguments.length; i += 2) {
|
||||
if (typeof arguments[i] == lang.OBJECT) {
|
||||
|
130
lib/user.js
130
lib/user.js
@ -26,10 +26,7 @@ Volcanos("user", {info: {}, agent: {
|
||||
mod: {
|
||||
isPod: location && location.pathname && (location.pathname.indexOf("/chat/pod/") == 0 || location.pathname.indexOf("/x/") == 0),
|
||||
isCmd: location && location.pathname && (location.pathname.indexOf("/chat/pod/") == 0 && location.pathname.indexOf("/cmd/") > 0 || location.pathname.indexOf("/chat/cmd/") == 0 || location.pathname.indexOf("/help/") == 0),
|
||||
isWeb: location && location.pathname && (location.pathname.indexOf("/chat/pod/") == 0 && location.pathname.indexOf("/website/") > 0 || location.pathname.indexOf("/chat/website/") == 0),
|
||||
isDiv: location && location.pathname && (location.pathname.indexOf("/chat/div/") == 0),
|
||||
},
|
||||
|
||||
alert: function(text) { alert(JSON.stringify(text)) },
|
||||
confirm: function(text) { return confirm(JSON.stringify(text)) },
|
||||
prompt: function(tip, def, cb, silent) { (text = silent? def: prompt(tip, def||"")) != undefined && typeof cb == lang.FUNCTION && cb(text); return text },
|
||||
@ -37,74 +34,59 @@ Volcanos("user", {info: {}, agent: {
|
||||
jumps: function(url) { location.href = url },
|
||||
open: function(url) { window.open(url) || (location.href = url) },
|
||||
close: function(url) { window.close() },
|
||||
|
||||
title: function(text) { if (window.webview) { return title(text) } return text && (document.title = text), document.title },
|
||||
topic: function(can, name) { can.base.isString(name) && (name = [name]) || name || []
|
||||
can.user.isMobile && name.push(html.MOBILE) && can.user.isLandscape() && name.push(html.LANDSCAPE)
|
||||
can.user.language(can) && name.push(can.user.language(can))
|
||||
can.Conf(chat.DISPLAY) && name.push(can.Conf(chat.DISPLAY))
|
||||
can.user.isWebview && name.push(html.WEBVIEW)
|
||||
can.user.mod.isCmd && name.push(chat.SIMPLE)
|
||||
can.page.styleClass(can, can._root._target, name.join(ice.SP))
|
||||
can.user.isWebview && name.push(html.WEBVIEW), can.user.isMobile && name.push(html.MOBILE) && can.user.isLandscape() && name.push(html.LANDSCAPE)
|
||||
can.Conf(chat.DISPLAY) && name.push(can.Conf(chat.DISPLAY)), can.user.mod.isCmd && name.push(chat.SIMPLE)
|
||||
can.user.language(can) && name.push(can.user.language(can)), can.page.styleClass(can, document.body, name.join(ice.SP))
|
||||
},
|
||||
language: function(can) { return can.misc.Search(can, aaa.LANGUAGE)||can.user.info.language },
|
||||
trans: function(can, text, list) { if (can.base.isFunc(text)) { text = text.name||"" }
|
||||
trans: function(can, text, list) { if (can.user.language(can) == "en") { return text }
|
||||
if (can.base.isObject(text)) { return can.core.Item(text, function(k, v) { can.core.Value(can._trans, k, v) }) }
|
||||
if (can.user.language(can) == "en") { return text } if (can.base.isString(list)) { return list }
|
||||
if (can.base.isFunc(text)) { text = text.name||"" } if (can.base.isString(list)) { return list }
|
||||
return list&&list[text] || can._trans&&can._trans[text] || can.Conf("trans."+text) || can.Conf("feature._trans."+text) || kit.Dict(
|
||||
mdb.CREATE, "创建", mdb.REMOVE, "删除", mdb.INSERT, "添加", mdb.DELETE, "删除", mdb.MODIFY, "修改", mdb.PRUNES, "清理", mdb.EXPORT, "导出", mdb.IMPORT, "导入", mdb.SEARCH, "搜索",
|
||||
html.PLUGIN, "插件", html.LABEL, "标签", html.HEIGHT, "高度", html.WIDTH, "宽度", ice.SHOW, "显示", ice.HIDE, "隐藏", chat.PROJECT, "项目", chat.PROFILE, "详情", chat.ACTIONS, "参数",
|
||||
ctx.ACTION, "操作", ice.RUN, "执行", ice.LIST, "查看", ice.BACK, "返回", mdb.PREV, "上一页", mdb.NEXT, "下一页", mdb.LINK, "链接",
|
||||
nfs.COPY, "复制", nfs.EDIT, "编辑", nfs.SAVE, "保存", nfs.TRASH, "删除", nfs.SOURCE, "源码", nfs.MODULE, "模块", nfs.RECENT, "最近",
|
||||
cli.BEGIN, "开始", cli.START, "启动", cli.OPEN, "打开", cli.CLOSE, "关闭", cli.STOP, "停止", cli.END, "结束", cli.EXEC, "执行", cli.DONE, "完成", cli.RESTART, "重启",
|
||||
mdb.CREATE, "创建", mdb.REMOVE, "删除", mdb.INSERT, "添加", mdb.DELETE, "删除", mdb.MODIFY, "修改", mdb.PRUNES, "清理", mdb.REVERT, "恢复", mdb.EXPORT, "导出", mdb.IMPORT, "导入", mdb.SEARCH, "搜索",
|
||||
aaa.INVITE, "邀请", ctx.ACTION, "操作", ice.RUN, "执行", ice.LIST, "查看", ice.BACK, "返回", mdb.PREV, "上一页", mdb.NEXT, "下一页", mdb.LINK, "链接",
|
||||
web.CLEAR, "清空", web.REFRESH, "刷新", web.SUBMIT, "提交", web.CANCEL, "取消", web.UPLOAD, "上传", web.DOWNLOAD, "下载", web.TOIMAGE, "截图", web.SHARE, "共享",
|
||||
"Close", "关闭", "Close others", "关闭其它", "Close all", "关闭所有",
|
||||
chat.IFRAME, "浏览", chat.LOCATION, "地图",
|
||||
code.INNER, "源码",
|
||||
nfs.SAVE, "保存", nfs.LOAD, "加载",
|
||||
nfs.SAVE, "保存", nfs.LOAD, "加载", nfs.COPY, "复制", nfs.EDIT, "编辑", nfs.SAVE, "保存", nfs.TRASH, "删除", nfs.SOURCE, "源码", nfs.MODULE, "模块", nfs.RECENT, "最近",
|
||||
cli.BEGIN, "开始", cli.START, "启动", cli.OPEN, "打开", cli.CLOSE, "关闭", cli.STOP, "停止", cli.END, "结束", cli.EXEC, "执行", cli.DONE, "完成", cli.RESTART, "重启",
|
||||
cli.SYSTEM, "命令", cli.ORDER, "加载", cli.BUILD, "构建",
|
||||
aaa.INVITE, "邀请",
|
||||
mdb.REVERT, "恢复",
|
||||
"full", "全屏",
|
||||
code.INNER, "源码", chat.IFRAME, "浏览", chat.LOCATION, "地图",
|
||||
html.PLUGIN, "插件", html.LABEL, "标签", html.HEIGHT, "高度", html.WIDTH, "宽度", ice.SHOW, "显示", ice.HIDE, "隐藏", chat.PROJECT, "项目", chat.PROFILE, "详情", chat.ACTIONS, "参数",
|
||||
"full", "全屏", "Close", "关闭", "Close others", "关闭其它", "Close all", "关闭所有",
|
||||
)[text]||text
|
||||
},
|
||||
time: function(can, time, fmt) { var now = can.base.Date(time)
|
||||
var list = can.user.language(can) == "en"? ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]
|
||||
return fmt == "%W"? list: can.base.Time(time, (fmt||"%y-%m-%d %H:%M:%S").replace("%w", list[now.getDay()]))
|
||||
},
|
||||
|
||||
toastConfirm: function(can, content, title, action) { return can.user.toast(can, {content: content, title: title, action: action||[cli.CLOSE], duration: -1, width: -300}) },
|
||||
toastProcess: function(can, content, title) { return can.user.toast(can, content||ice.PROCESS, title||can._name.split(ice.PS).slice(-2).join(ice.PS), -1) },
|
||||
toastSuccess: function(can, content, title) { return can.user.toast(can, "\u2705 "+(content||ice.SUCCESS), (title||can._name.split(ice.PS).slice(-2).join(ice.PS))) },
|
||||
toastFailure: function(can, content, title) { return can.user.toast(can, "\u274C "+(content||ice.FAILURE), (title||can._name.split(ice.PS).slice(-2).join(ice.PS)), 5000) },
|
||||
toastProcess: function(can, content, title) { return can.user.toast(can, content||ice.PROCESS, title, -1) },
|
||||
toastSuccess: function(can, content, title) { return can.user.toast(can, "\u2705 "+(content||ice.SUCCESS), title) },
|
||||
toastFailure: function(can, content, title) { return can.user.toast(can, "\u274C "+(content||ice.FAILURE), title, 10000) },
|
||||
toast: function(can, content, title, duration, progress) {
|
||||
var meta = can.base.isObject(content)? content: {content: content, title: title||can._help, duration: duration, progress: progress}
|
||||
var meta = can.base.isObject(content)? content: {content: content, title: title||can._name.split(ice.PS).slice(-2).join(ice.PS), duration: duration, progress: progress}
|
||||
var width = meta.width||400; if (width < 0) { width = window.innerWidth + width }
|
||||
var ui = can.page.Append(can, document.body, [{view: [[chat.TOAST, chat.FLOAT]], style: {left: (window.innerWidth-width)/2, width: width, bottom: 100}, list: [
|
||||
{text: [meta.title||"", html.DIV, html.TITLE], title: "点击复制", onclick: function(event) { can.user.copy(event, can, meta.title) }},
|
||||
{view: "duration", title: "点击关闭", onclick: function() { action.close() }},
|
||||
can.base.isObject(meta.content)? meta.content: {text: [meta.content||"", html.DIV, nfs.CONTENT]},
|
||||
html.ACTION, !can.base.isUndefined(meta.progress) && {view: "progress", style: {width: width}, list: [
|
||||
{view: "current", style: {width: (meta.progress||0)/100*width}},
|
||||
{view: "current", style: {width: (meta.progress||0)*width/100}},
|
||||
]},
|
||||
] }]); can.onengine.signal(can, chat.ONTOAST, can.request({}, {time: can.misc._time(), title: meta.title, content: meta.content, fileline: can.misc.FileLine(-3)}))
|
||||
var action = can.onappend._action(can, meta.action && meta.action.list? meta.action.list: meta.action||[""], ui.action, {
|
||||
_engine: function(event, button) { can.core.CallFunc(meta.action[button]||meta.action, [event, button]) },
|
||||
open: function(event) { meta.content.indexOf(ice.HTTP) == 0 && can.user.open(meta.content), meta.title.indexOf(ice.HTTP) == 0 && can.user.open(meta.title) },
|
||||
close: function(event) { can.page.Remove(can, action._target), action.timer.stop = true },
|
||||
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)+ice.PT+(index%10)+"s..." }
|
||||
timer: can.core.Timer({interval: 100, length: (meta.duration||1000)/100}, function(event, interval, index) {
|
||||
if (index > 30) { ui.duration.innerHTML = index/10+ice.PT+index%10+"s..." }
|
||||
}, function() { action.close() }), _target: ui._target, ui: ui,
|
||||
}); can.onmotion.story.auto(can, ui._target)
|
||||
}); can.onmotion.story.auto(can, ui._target), meta.resize && can.onmotion.delayResize(can, ui._target, meta.resize)
|
||||
return can._toast && (can._toast.close(), delete(can._toast)), can._toast = action
|
||||
},
|
||||
share: function(can, msg, cmd) { can.run(msg, cmd||[ctx.ACTION, chat.SHARE], function(msg) { can.user.copy(msg._event, can, msg.Append(mdb.NAME))
|
||||
var toast = can.user.toast(can, {title: msg.Append(mdb.NAME), duration: -1, content: msg.Append(mdb.TEXT), action: [cli.CLOSE, cli.OPEN]})
|
||||
can.onmotion.delay(can, function() {
|
||||
can.page.Select(can, toast._target, html.IMG, function(target) {
|
||||
can.page.style(can, toast._target, html.WIDTH, target.offsetWidth, html.LEFT, (window.innerWidth-target.offsetWidth)/2)
|
||||
})
|
||||
})
|
||||
share: function(can, msg, cmds) { can.run(msg, cmds||[ctx.ACTION, chat.SHARE], function(msg) { can.user.copy(msg._event, can, msg.Append(mdb.NAME))
|
||||
can.user.toast(can, {title: msg.Append(mdb.NAME), duration: -1, content: msg.Append(mdb.TEXT), action: [cli.CLOSE, cli.OPEN], resize: html.IMG})
|
||||
}) },
|
||||
copy: function(event, can, text) { if (!text) { return }
|
||||
if (navigator.clipboard) { var ok = false; navigator.clipboard.writeText(text).then(function() { ok = true })
|
||||
@ -114,32 +96,26 @@ Volcanos("user", {info: {}, agent: {
|
||||
can.onmotion.focus(can, input), document.execCommand("Copy"), can.page.Remove(can, input)
|
||||
return can.user.toastSuccess(can, text, "copy success"), can.misc.Log(nfs.COPY, text), text
|
||||
},
|
||||
|
||||
carte: function(event, can, meta, list, cb, parent) {
|
||||
meta = meta||can.ondetail||can.onaction||{}, list = can.base.getValid(list, meta.list, can.core.Item(meta))||[]; if (list.length == 0) { return }
|
||||
cb = cb||function(event, button, meta) { var cb = meta[button]||meta[chat._ENGINE]; can.base.isFunc(cb) && cb(event, can, button) }
|
||||
parent || can.page.Select(can, can._root._target, can.page.Keys("div.carte.float"), function(target) { can.onmotion.delay(can, function () { can.page.Remove(can, target) }) })
|
||||
var ui = can.page.Append(can, can._root._target, [{view: [[chat.CARTE, chat.FLOAT]], list: can.core.List(list, function(item, index) {
|
||||
return can.base.isString(item)? item ==""? /* space */ {view: html.SPACE}: /* string */ {view: [html.ITEM, html.DIV, can.user.trans(can, item)], onclick: function(event) {
|
||||
can.base.isFunc(cb) && cb(event, item, meta, index), can.onkeymap.prevent(event), can.user.isMobile && can.page.Remove(can, ui._target)
|
||||
}, onmouseenter: function(event) { carte._float && can.page.Remove(can, carte._float._target) } }:
|
||||
parent || can.page.Select(can, document.body, "div.carte.float", function(target) { can.onmotion.delay(can, function () { can.page.Remove(can, target) }) })
|
||||
function remove_sub(carte) { carte._sub && can.page.Remove(can, carte._sub._target), delete(carte._sub) }
|
||||
function click(event, item) { can.base.isFunc(cb) && cb(event, item, meta), can.onkeymap.prevent(event), can.user.isMobile && can.page.Remove(can, ui._target) }
|
||||
var ui = can.page.Append(can, document.body, [{view: [[chat.CARTE, chat.FLOAT]], list: can.core.List(list, function(item, index) {
|
||||
return can.base.isString(item)? item ==""? /* space */ {view: html.SPACE}: /* string */ {view: [html.ITEM, html.DIV, can.user.trans(can, item)], onclick: function(event) { click(event, item) }, onmouseenter: function(event) { remove_sub(carte) } }:
|
||||
can.base.isArray(item)? /* array */ {view: html.ITEM, list: [{text: can.user.trans(can, item[0])+" -> "}], onmouseenter: function(event) {
|
||||
var sub = can.user.carte(event, can, meta, item.slice(1), cb, carte); can.onlayout.figure(event, can, sub._target, true)
|
||||
carte._float && can.page.Remove(can, carte._float._target), carte._float = sub
|
||||
} }: /* object */ {view: html.ITEM, list: [{text: can.user.trans(can, item.name), onclick: function(event) {
|
||||
can.base.isFunc(cb) && cb(event, item.name, meta, index), can.user.isMobile && can.page.Remove(can, ui._target)
|
||||
}, onmouseenter: function(event) { carte._float && can.page.Remove(can, carte._float._target) } }] }
|
||||
}), onmouseover: function(event) { can.onkeymap.prevent(event) } }] )
|
||||
var carte = {_target: ui._target, _parent: parent, layout: can.onlayout.figure(event, can, ui._target)}
|
||||
return can.onkeymap.prevent(event), carte
|
||||
var sub = can.user.carte(event, can, meta, item.slice(1), cb, carte); can.onlayout.figure(event, can, sub._target, true), remove_sub(carte), carte._sub = sub
|
||||
} }: /* object */ {view: html.ITEM, list: [{text: can.user.trans(can, item.name), onclick: function(event) { click(event, item.name) }, onmouseenter: function(event) { remove_sub(carte) } }] }
|
||||
}), onmouseover: function(event) { can.onkeymap.prevent(event) } }]); can.onkeymap.prevent(event)
|
||||
var carte = {_target: ui._target, _parent: parent, layout: can.onlayout.figure(event, can, ui._target)}; return carte
|
||||
},
|
||||
carteRight: function(event, can, meta, list, cb, parent) { var carte = can.user.carte(event, can, meta, list, cb, parent)
|
||||
return can.page.style(can, carte._target, can.onlayout.figure(event, can, carte._target, true)), carte
|
||||
},
|
||||
|
||||
input: function(event, can, form, cb, button) { if (!form || form.length == 0) { return cb() }
|
||||
var msg = can.request(event); event = event._event||event; var need = {}
|
||||
var ui = can.page.Append(can, can._root._target, [{view: [[html.INPUT, chat.FLOAT]], list: [
|
||||
var ui = can.page.Append(can, document.body, [{view: [[html.INPUT, chat.FLOAT]], list: [
|
||||
{view: nfs.CONTENT, list: [{view: [html.OPTION, html.TABLE], list: can.core.List(form, function(item) {
|
||||
item = can.base.isString(item)? {type: html.TEXT, name: item}: item.length > 0? {type: html.SELECT, name: item[0], values: item.slice(1)}: item
|
||||
item.type = item.type||(item.values? html.SELECT: item.name == html.TEXT? html.TEXTAREA: html.TEXT), need[item.name] = item.need
|
||||
@ -172,19 +148,15 @@ Volcanos("user", {info: {}, agent: {
|
||||
})
|
||||
},
|
||||
upload: function(event, can, cb, silent) { var begin = new Date()
|
||||
var ui = can.page.Append(can, can._root._target, [{view: [[html.UPLOAD, chat.FLOAT]], list: [
|
||||
var ui = can.page.Append(can, document.body, [{view: [[html.UPLOAD, chat.FLOAT]], list: [
|
||||
html.ACTION, {view: html.OUTPUT, list: ["progress"]}, {view: html.STATUS, list: [ice.SHOW, cli.COST, nfs.SIZE]},
|
||||
]}]); can.onlayout.figure(event, can, ui._target)
|
||||
var action = can.onappend._action(can, [{type: html.UPLOAD, onchange: function(event) { action.show(event, 0, event.target.files[0].size, 0) }}, cli.CLOSE], ui.action, {
|
||||
close: function(event) { can.page.Remove(can, ui._target) },
|
||||
begin: function(event) { begin = new Date()
|
||||
var upload = can.page.Select(can, ui.action, html.INPUT_FILE)[0]; if (upload.files.length == 0) { return upload.focus() }
|
||||
var msg = can.request(event, can.Option(), {_handle: ice.TRUE}); msg._upload = upload.files[0], msg._progress = action.show
|
||||
can.runAction(event, html.UPLOAD, [], function(msg) { action.close()
|
||||
if (can.base.isFunc(cb)) { return cb(msg) }
|
||||
can.user.toastSuccess(can), can.Update()
|
||||
})
|
||||
},
|
||||
can.runAction(event, html.UPLOAD, [], function(msg) { can.base.isFunc(cb)? cb(msg): can.Update(), action.close(), can.user.toastSuccess(can) })
|
||||
}, close: function(event) { can.page.Remove(can, ui._target) },
|
||||
show: function (event, value, total, loaded) {
|
||||
ui.cost.innerHTML = can.base.Duration(new Date() - begin)
|
||||
ui.show.innerHTML = value+"%", value == 0 && action.begin(event)
|
||||
@ -194,12 +166,10 @@ Volcanos("user", {info: {}, agent: {
|
||||
}); can.page.Select(can, ui.action, html.INPUT_FILE)[0].click(), silent && can.onmotion.hidden(can, ui._target); return action
|
||||
},
|
||||
download: function(can, path, name, ext) {
|
||||
var a = can.page.Append(can, can._root._target, [{type: html.A, href: path, download: can.core.Keys(name, ext)||path.split(ice.PS).pop()}])._target
|
||||
var a = can.page.Append(can, document.body, [{type: html.A, href: path, download: can.core.Keys(name, ext)||path.split(ice.PS).pop()}])._target
|
||||
return a.click(), can.page.Remove(can, a), path
|
||||
},
|
||||
downloads: function(can, text, name, ext) { if (!text) { return }
|
||||
return can.user.download(can, URL.createObjectURL(new Blob([text])), name, ext)
|
||||
},
|
||||
downloads: function(can, text, name, ext) { return text && can.user.download(can, URL.createObjectURL(new Blob([text])), name, ext) },
|
||||
toimage: function(can, name, target, silent) { var toast = can.user.toastProcess(can, "生成中...")
|
||||
can.require(["https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js"], function() { toast.close()
|
||||
html2canvas(target||can._target).then(function (canvas) { var url = canvas.toDataURL("image/png")
|
||||
@ -207,6 +177,13 @@ Volcanos("user", {info: {}, agent: {
|
||||
})
|
||||
})
|
||||
},
|
||||
toastImage: function(can, name, url) { url = can.base.isString(url)? url: url.toDataURL("image/png")
|
||||
var toast = can.user.toast(can, {content: {img: url, style: {"max-height": window.innerHeight/2, display: html.BLOCK}}, title: name, duration: -1,
|
||||
action: shy([cli.CLOSE, web.DOWNLOAD], function(event, button) {
|
||||
can.user.input(event, can, [{name: mdb.NAME, value: name}], function(list) { can.user.download(can, url, list[0], nfs.PNG) })
|
||||
}), resize: html.IMG,
|
||||
})
|
||||
},
|
||||
toPNG: function(can, name, text, height, width) {
|
||||
if (text.indexOf("<svg") != 0) { text = '<svg xmlns="http://www.w3.org/2000/svg">'+text+"</svg>" }
|
||||
var img = can.page.Create(can, html.IMG, {src: "data:image/svg+xml,"+encodeURIComponent(text), onload: function() {
|
||||
@ -214,19 +191,6 @@ Volcanos("user", {info: {}, agent: {
|
||||
can.user.download(can, canvas, name, nfs.PNG)
|
||||
}})
|
||||
},
|
||||
toastImage: function(can, name, url) { url = can.base.isString(url)? url: url.toDataURL("image/png")
|
||||
var toast = can.user.toast(can, {content: {img: url, style: {"max-height": window.innerHeight/2, display: html.BLOCK}}, title: name, duration: -1,
|
||||
action: shy({}, [cli.CLOSE, web.DOWNLOAD], function(event, button) {
|
||||
can.user.input(event, can, [{name: mdb.NAME, value: name}], function(list) {
|
||||
can.user.download(can, url, list[0], nfs.PNG)
|
||||
})
|
||||
}),
|
||||
})
|
||||
can.onmotion.delay(can, function() { can.page.Select(can, toast._target, html.IMG, function(target) {
|
||||
can.page.style(can, toast._target, html.WIDTH, target.offsetWidth, html.LEFT, (window.innerWidth-target.offsetWidth)/2)
|
||||
}) })
|
||||
},
|
||||
|
||||
login: function(can, cb, method) { var trans = kit.Dict(aaa.USERNAME, "用户", aaa.PASSWORD, "密码", aaa.LOGIN, "登录")
|
||||
function layout() { can.page.style(can, ui._target, {left: (window.innerWidth-ui._target.offsetWidth)/2, top: window.innerHeight/6}) }
|
||||
function button(list) { return {view: [html.ITEM, html.TR], list: [{type: html.TD}, {type: html.TD, list: can.core.Item(list, function(key, cb) {
|
||||
@ -242,14 +206,12 @@ Volcanos("user", {info: {}, agent: {
|
||||
if (cmd == ice.MSG_SESSID) { return can.misc.CookieSessid(can, arg[0]), can.page.Remove(can, ui._target), can.base.isFunc(cb) && cb() }
|
||||
}) },
|
||||
"密码登录": function(target) {
|
||||
var _ui = can.page.Append(can, target, [input(aaa.USERNAME), input(aaa.PASSWORD, aaa.PASSWORD),
|
||||
button(kit.Dict(aaa.LOGIN, function(event) {
|
||||
var _ui = can.page.Append(can, target, [input(aaa.USERNAME), input(aaa.PASSWORD, aaa.PASSWORD), button(kit.Dict(aaa.LOGIN, function(event) {
|
||||
can.runAction(event, aaa.LOGIN, [_ui.username.value, _ui.password.value], function(msg) {
|
||||
if (!msg.Option(ice.MSG_USERNAME)) { return can.user.toastFailure(can, "用户或密码错误") }
|
||||
can.page.Remove(can, ui._target), can.base.isFunc(cb) && cb()
|
||||
})
|
||||
})),
|
||||
])
|
||||
}))])
|
||||
},
|
||||
}, can.base.Obj(method, can.user.isMobile? ["密码登录"]: ["扫码授权"]), can.page.Append(can, document.body, [{view: "input login"}])._target); layout()
|
||||
},
|
||||
|
@ -393,6 +393,7 @@ Volcanos(chat.ONSYNTAX, {
|
||||
"Date": code.DATATYPE,
|
||||
"Math": code.DATATYPE,
|
||||
"XMLHttpRequest": code.DATATYPE,
|
||||
"WebSocket": code.DATATYPE,
|
||||
|
||||
"encodeURIComponent": code.FUNCTION,
|
||||
"decodeURIComponent": code.FUNCTION,
|
||||
|
Loading…
x
Reference in New Issue
Block a user