1
0
mirror of https://shylinux.com/x/volcanos synced 2025-04-25 16:58:06 +08:00
This commit is contained in:
IT 老营长 @云轩领航-创始人 2022-01-31 22:50:16 +08:00
parent d85ad69278
commit b2a6b7a006
10 changed files with 187 additions and 328 deletions

210
frame.js
View File

@ -15,7 +15,7 @@ Volcanos("onengine", {help: "搜索引擎", list: [], _init: function(can, meta,
can.onengine.listen(can, key, function(msg) { can.core.CallFunc(cb, {can: panel, msg: msg}) }) can.onengine.listen(can, key, function(msg) { can.core.CallFunc(cb, {can: panel, msg: msg}) })
}), can.core.CallFunc([panel.onaction, "_init"], {can: panel, cb: next, target: panel._target}) }), can.core.CallFunc([panel.onaction, "_init"], {can: panel, cb: next, target: panel._target})
can.page.Modify(can, panel._target, {style: panel.Conf(ctx.STYLE)}) can.page.style(can, panel._target, panel.Conf(ctx.STYLE))
}, target) }, target)
}, function() { can.misc.Log(can.user.title(), ice.RUN, can) }, function() { can.misc.Log(can.user.title(), ice.RUN, can)
can.require([can.volcano], null, function(can, name, sub) { can[name] = sub }) can.require([can.volcano], null, function(can, name, sub) { can[name] = sub })
@ -405,8 +405,8 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta,
ui.close = function() { can.page.Remove(can, ui.first) } ui.close = function() { can.page.Remove(can, ui.first) }
can.getActionSize(function(left, top, height, width) { can.getActionSize(function(left, top, height, width) {
can.page.Modify(can, ui.output, {style: kit.Dict(html.MAX_HEIGHT, height-28, html.MAX_WIDTH, width)}) can.page.style(can, ui.output, html.MAX_HEIGHT, height-28, html.MAX_WIDTH, width)
can.page.Modify(can, ui.first, {style: {left: left, top: top}}) can.page.style(can, ui.first, html.LEFT, left, html.TOP, top)
}) })
can.onappend._action(can, [cli.CLOSE, cli.REFRESH, {input: html.TEXT, placeholder: "filter", _init: function(input) { can.onappend._action(can, [cli.CLOSE, cli.REFRESH, {input: html.TEXT, placeholder: "filter", _init: function(input) {
@ -480,7 +480,7 @@ Volcanos("onlayout", {help: "页面布局", list: [], _init: function(can, targe
can.page.ClassList.add(can, document.body, can.user.language(can)) can.page.ClassList.add(can, document.body, can.user.language(can))
}, },
background: function(can, url, target) { background: function(can, url, target) {
can.page.Modify(can, target||document.body, {style: {background: url == "" || url == "void"? "": 'url("'+url+'")'}}) can.page.style(can, target||document.body, html.BACKGROUND, url == "" || url == "void"? "": 'url("'+url+'")')
}, },
figure: function(event, can, target, right, layout) { target = target||can._target figure: function(event, can, target, right, layout) { target = target||can._target
if (layout) { return can.page.style(can, target, layout), can.onmotion.move(can, target, layout), layout } if (layout) { return can.page.style(can, target, layout), can.onmotion.move(can, target, layout), layout }
@ -498,6 +498,7 @@ Volcanos("onlayout", {help: "页面布局", list: [], _init: function(can, targe
} }
if (top+target.offsetHeight>window.innerHeight-100) { if (top+target.offsetHeight>window.innerHeight-100) {
layout.bottom = window.innerHeight - event.clientY+event.offsetY, layout.top = "" layout.bottom = window.innerHeight - event.clientY+event.offsetY, layout.top = ""
if (right) { layout.bottom -= target.offsetHeight }
} }
return can.page.style(can, target, layout), can.onmotion.move(can, target, layout), layout return can.page.style(can, target, layout), can.onmotion.move(can, target, layout), layout
}, },
@ -552,66 +553,51 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe
focus: function(can, target) { if (!target) { return } focus: function(can, target) { if (!target) { return }
target.setSelectionRange && target.setSelectionRange(0, -1), target.focus() target.setSelectionRange && target.setSelectionRange(0, -1), target.focus()
}, },
clear: function(can, target) {
return can.page.Modify(can, target||can._output, ""), true
},
share: function(event, can, input, args) { share: function(event, can, input, args) {
return can.user.input(event, can, input, function(ev, button, data, list, _args) { return can.user.input(event, can, input, function(ev, button, data, list, _args) {
can.search(can.request(event, {args: [mdb.TYPE, chat.FIELD].concat(args||[], _args||[])})._event, ["Header.onaction.share"]) can.search(can.request(event, {args: [mdb.TYPE, chat.FIELD].concat(args||[], _args||[])})._event, [["Header", chat.ONACTION, web.SHARE]])
}) })
}, },
story: { story: {
_hash: { _hash: {
spark: function(can, meta, target) { spark: function(can, meta, target) {
if (meta[mdb.NAME] == html.INNER) { meta[mdb.NAME] == html.INNER? can.onmotion.copy(can, target): can.page.Select(can, target, html.SPAN, function(item) {
target.title = "点击复制", target.onclick = function(event) { can.onmotion.copy(can, item)
can.user.copy(event, can, target.innerText) })
}
} else {
can.page.Select(can, target, html.SPAN, function(item) {
item.title = "点击复制", item.onclick = function(event) {
can.user.copy(event, can, item.innerText)
}
})
}
}, },
}, },
auto: function(can, target) { var that = this auto: function(can, target) { var that = this
can.page.Select(can, target||can._output, ".story", function(item) { var meta = item.dataset can.page.Select(can, target||can._output, ".story", function(item) { var meta = item.dataset
can.page.Modify(can, item, {style: can.base.Obj(meta.style)}) can.page.style(can, item, can.base.Obj(meta.style))
can.core.CallFunc(that._hash[meta.type], [can, meta, target||can._output]) can.core.CallFunc(that._hash[meta.type], [can, meta, target||can._output])
}) })
can.page.Select(can, target||can._output, html.IFRAME, function(item) { can.page.Select(can, target||can._output, html.IFRAME, function(item) {
can.page.Modify(can, item, {style: {height: can.Conf(html.HEIGHT)-88, width: can.Conf(html.WIDTH)-30}}) can.page.style(can, item, html.HEIGHT, can.Conf(html.HEIGHT)-88, html.WIDTH, can.Conf(html.WIDTH)-30)
}) })
can.page.Select(can, target||can._output, html.SVG, function(item) { can.page.Select(can, target||can._output, html.SVG, function(item) {
item.oncontextmenu = function(event) { item.oncontextmenu = function(event) {
can.user.carte(event, can, {"导出": function(event, can, button) { can.user.carte(event, can, kit.Dict(mdb.EXPORT, function(event, can, button) {
}}, ["导出"]) }), [mdb.EXPORT])
} }
// can.page.Modify(can, item, {style: {height: can.Conf(html.HEIGHT)-88, width: can.Conf(html.WIDTH)-30}})
}) })
}, },
}, },
float: {_hash: {}, float: {_hash: {},
del: function(can, key) { del: function(can, key) {
if (key == chat.CARTE) { key == chat.CARTE && can.page.Select(can, document.body, can.core.Keys(html.DIV, chat.CARTE), function(item) {
can.page.Select(can, document.body, can.core.Keys(html.DIV, chat.CARTE), function(item) { can.page.Remove(can, item)
can.page.Remove(can, item) })
})
}
this._hash[key] && can.page.Remove(can, this._hash[key]._target) this._hash[key] && can.page.Remove(can, this._hash[key]._target)
}, },
add: function(can, key, value) { add: function(can, key, value) {
this.del(can, key), this._hash[key] = value this.del(can, key), this._hash[key] = value
}, },
auto: function(can, target, key) { var that = this auto: function(can, target, key) { var that = this
var list = can.core.List(arguments).slice(2) var list = can.core.List(arguments).slice(2)
if (list.length == 0) { list = [chat.CARTE, chat.INPUT] } if (list.length == 0) { list = [chat.CARTE, chat.INPUT] }
can.page.Modify(can, target, {onmouseover: function(event) { can.page.Modify(can, target, {onmouseover: function(event) {
if (event.target.tagName == "IMG") { return } if (can.page.tagis(html.IMG, event.target)) { return }
can.core.List(list, function(key, index) { that.del(can, key) }) can.core.List(list, function(key, index) { that.del(can, key) })
}}) }})
}, },
@ -623,35 +609,22 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe
if (pos) { item.scrollTo && item.scrollTo(0, pos-1); return item } if (pos) { item.scrollTo && item.scrollTo(0, pos-1); return item }
}).length > 0 }).length > 0
}, },
delay: function(can, cb) { clear: function(can, target) { return can.page.Modify(can, target||can._output, ""), true },
can.core.Timer(50, cb) delay: function(can, cb) { can.core.Timer(100, cb) },
},
toimage: function(event, can, name, target) {
can.user.input(event, can, [{name: "name", value: name}], function(ev, button, data) {
can.require(["https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js"], function() {
html2canvas(target||can._target).then(function (canvas) {
can.page.Create(can, html.A, {href: canvas.toDataURL("image/png"), download: data.name}).click()
})
})
})
},
hidden: function(can, target, show) { hidden: function(can, target, show) {
can.page.Modify(can, target||can._target, {style: {display: show? "": html.NONE}}) can.page.styleDisplay(can, target||can._target, show? "": html.NONE)
}, },
toggle: function(can, target, show, hide) { target = target||can._target toggle: function(can, target, show, hide) { target = target||can._target
var status = target.style.display == html.NONE var status = target.style.display == html.NONE
can.page.Modify(can, target, {style: {display: status? "": html.NONE}}) if (!(status? can.base.isFunc(show) && show(): can.base.isFunc(hide) && hide())) {
status? can.base.isFunc(show) && show(): can.base.isFunc(hide) && hide() can.page.styleDisplay(can, target, status? "": html.NONE)
}
return status return status
}, },
select: function(can, target, name, which) { select: function(can, target, name, which) {
can.page.Select(can, target, name, function(item, index) { can.page.Select(can, target, name, function(item, index) {
if (item == which || which == index) { can.page.ClassList.set(can, item, html.SELECT, item == which || which == index)
can.page.ClassList.add(can, item, html.SELECT)
} else {
can.page.ClassList.del(can, item, html.SELECT)
}
}) })
}, },
modify: function(can, target, cb, item) { var back = target.innerHTML, text = target.innerText modify: function(can, target, cb, item) { var back = target.innerHTML, text = target.innerText
@ -679,8 +652,7 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe
}, onkeydown: function(event) { }, onkeydown: function(event) {
switch (event.key) { switch (event.key) {
case lang.ENTER: case lang.ENTER:
if (event.ctrlKey) { if (event.ctrlKey) { target.innerHTML = event.target.value
target.innerHTML = event.target.value
event.target.value == back || cb(event, event.target.value, back) event.target.value == back || cb(event, event.target.value, back)
} }
break break
@ -692,6 +664,15 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe
can.onmotion.focus(can, target) can.onmotion.focus(can, target)
}}]) }}])
}, },
toimage: function(event, can, name, target) {
can.user.input(event, can, [{name: "name", value: name}], function(ev, button, data) {
can.require(["https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js"], function() {
html2canvas(target||can._target).then(function (canvas) {
can.page.Create(can, html.A, {href: canvas.toDataURL("image/png"), download: data.name}).click()
})
})
})
},
link: function(can, target, text) { link: function(can, target, text) {
if (target.innerText == "") { target.innerText = target.href } if (target.innerText == "") { target.innerText = target.href }
@ -702,9 +683,8 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe
can.user.copy(event, can, text||target.innerText) can.user.copy(event, can, text||target.innerText)
} }
}, },
move: function(can, target, layout, cb) { var begin move: function(can, target, layout, cb) { var begin; layout = layout||{}
can.page.Modify(can, target, {style: layout}) can.page.style(can, target, layout), target.onmousedown = function(event) {
target.onmousedown = function(event) {
layout.height = target.offsetHeight, layout.width = target.offsetWidth layout.height = target.offsetHeight, layout.width = target.offsetWidth
layout.left = target.offsetLeft, layout.top = target.offsetTop layout.left = target.offsetLeft, layout.top = target.offsetTop
begin = can.base.Copy({x: event.x, y: event.y}, layout) begin = can.base.Copy({x: event.x, y: event.y}, layout)
@ -714,80 +694,59 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe
if (event.shiftKey) { if (event.shiftKey) {
layout.width = layout.width + event.x - begin.x layout.width = layout.width + event.x - begin.x
layout.height = layout.height + event.y - begin.y layout.height = layout.height + event.y - begin.y
can.page.Modify(can, target, {style: {width: layout.width, height: layout.height}}) can.page.style(can, target, html.HEIGHT, layout.height, html.WIDTH, layout.width)
} else { } else {
layout.top = begin.top + event.y - begin.y layout.top = begin.top + event.y - begin.y
layout.left = begin.left + event.x - begin.x layout.left = begin.left + event.x - begin.x
can.page.Modify(can, target, {style: {left: layout.left, top: layout.top}}) can.page.style(can, target, html.LEFT, layout.left, html.TOP, layout.top)
} }
can.base.isFunc(cb) && cb(target) can.onkeymap.prevent(event), can.base.isFunc(cb) && cb(target, layout)
can.onkeymap.prevent(event)
} }
can.base.isFunc(cb) && cb(target) can.base.isFunc(cb) && cb(target, layout)
}, },
show: function(can, time, cb, target) { target = target||can._target show: function(can, time, cb, target) { target = target||can._target
time = can.base.isObject(time)? time: {interval: 10, length: time||30} time = can.base.isObject(time)? time: {interval: 10, length: time||30}
can.page.style(can, target, html.OPACITY, 0, html.DISPLAY, html.BLOCK)
can.page.Modify(can, target, {style: {opacity: 0, display: html.BLOCK}})
can.core.Timer(time, function(event, value, index) { can.core.Timer(time, function(event, value, index) {
can.page.Modify(can, target, {style: {opacity: (index+1)/time.length}}) can.page.style(can, target, html.OPACITY, (index+1)/time.length)
}, cb) }, cb)
}, },
hide: function(can, time, cb, target) { target = target||can._target hide: function(can, time, cb, target) { target = target||can._target
time = can.base.isObject(time)? time: {value: 10, length: time||20} time = can.base.isObject(time)? time: {value: 10, length: time||20}
can.page.style(can, target, html.OPACITY, 1)
can.page.Modify(can, target, {style: {opacity: 1}})
can.core.Timer(time, function(event, value, index) { can.core.Timer(time, function(event, value, index) {
can.page.Modify(can, target, {style: {opacity: 1-(index+1)/time.length}}) can.page.style(can, target, html.OPACITY, 1-(index+1)/time.length)
}, function() { }, function() { can.base.isFunc(cb) && cb(), can.page.style(can, target, html.DISPLAY, html.NONE) })
can.page.Modify(can, target, {style: {display: html.NONE}})
can.base.isFunc(cb) && cb()
})
}, },
selectField: function(event, can) { selectField: function(event, can) {
if (event.ctrlKey && event.key >= "0" && event.key <= "9") { if (!event.ctrlKey || event.key < "0" || event.key > "9") { return }
if (event.shiftKey) { if (event.shiftKey) {
can.page.Select(can, can._option, "input[type=button]", function(item, index) { return can.page.Select(can, can._option, "input[type=button]", function(item, index) {
index == event.key && (item.click()) index == event.key && (item.click())
}) })
return }
} if (event.key == "0") { return can.onimport._back(can) }
if (event.key == "0") { return can.onimport._back(can) }
can.page.Select(can, can._output, html.TR, function(tr, index) { if (index == event.key) { can.page.Select(can, can._output, html.TR, function(tr, index) { if (index == event.key) {
var head = can.page.Select(can, can._output, html.TH, function(th, order) { return th.innerText }) var head = can.page.Select(can, can._output, html.TH, function(th, order) { return th.innerText })
can.page.Select(can, tr, html.TD, function(td, index) { can.Option(head[index], td.innerText) }) can.page.Select(can, tr, html.TD, function(td, index) { can.Option(head[index], td.innerText) })
can.Update(event) can.Update(event)
} }) } })
}
}, },
selectTable: function(event, can, target, cb) { selectTable: function(event, can, target, cb) { if (!event.ctrlKey) { return }
if (event.ctrlKey) { function select(order) { var index = 0
function select(order) { return can.page.Select(can, can._output, html.TR, function(tr) {
var index = 0; return can.page.Select(can, can._output, html.TR, function(tr) { if (can.page.ClassList.has(can, tr, html.HIDDEN)) { return }
if (can.page.ClassList.has(can, tr, html.HIDDEN)) { return } if (!can.page.ClassList.set(can, tr, html.SELECT, order == index++)) { return tr }
if (!can.page.ClassList.set(can, tr, html.SELECT, order == index++)) { return tr} return can.Status(mdb.INDEX, index-1), can.base.isFunc(cb) && cb(tr), tr
can.base.isFunc(cb) && cb(tr) }).length
can.Status("index", index-1)
return tr
}).length
}
switch (event.key) {
case "n":
var total = select(target._index)
select(target._index = ((target._index)+1) % total)
can.onkeymap.prevent(event)
break
case "p":
var total = select(target._index)
select(target._index = (target._index-1) < 0? total-1: (target._index-1))
can.onkeymap.prevent(event)
break
default: target._index = 0
}
} }
var total = select(target._index); switch (event.key) {
case "n": select(target._index = ((target._index)+1) % total); break
case "p": select(target._index = (target._index-1) < 0? total-1: (target._index-1)); break
default: target._index = 0; return
} can.onkeymap.prevent(event)
}, },
selectTableInput: function(event, can, target, cb) { selectTableInput: function(event, can, target, cb) {
if (event.ctrlKey) { if (event.ctrlKey) {
@ -800,18 +759,11 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe
}); return tr }); return tr
}).length }).length
} }
switch (event.key) { var total = select(target._index); switch (event.key) {
case "n": case "n": select(target._index = ((target._index)+1) % total); break
var total = select(target._index) case "p": select(target._index = (target._index-1) < 0? total-1: (target._index-1)); break
select(target._index = ((target._index)+1) % total)
break
case "p":
var total = select(target._index)
select(target._index = (target._index-1) < 0? total-1: (target._index-1))
break
default: target._index = 0, target._value = ""; return default: target._index = 0, target._value = ""; return
} } return can.onkeymap.prevent(event)
return can.onkeymap.prevent(event)
} }
target._index = 0, target._value = "" target._index = 0, target._value = ""
@ -823,16 +775,15 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe
var total = can.page.Select(can, can._output, html.TR, function(tr) { var total = can.page.Select(can, can._output, html.TR, function(tr) {
if (!can.page.ClassList.has(can, tr, html.HIDDEN)) { return tr} if (!can.page.ClassList.has(can, tr, html.HIDDEN)) { return tr}
}).length-1 }).length-1; total == 0 && can.base.isFunc(cb) && cb()
total == 0 && can.base.isFunc(cb) && cb()
can.Status(kit.Dict(mdb.TOTAL, total, mdb.INDEX, target._index)) can.Status(kit.Dict(mdb.TOTAL, total, mdb.INDEX, target._index))
}, },
}) })
Volcanos("onkeymap", {help: "键盘交互", list: [], _focus: [], _init: function(can, target) { Volcanos("onkeymap", {help: "键盘交互", list: [], _focus: [], _init: function(can, target) {
can.onkeymap._build(can), document.body.onkeydown = function(event) { if (event.metaKey) { return } can.onkeymap._build(can), document.body.onkeydown = function(event) { if (event.metaKey) { return }
if (event.target.tagName == "SELECT" || event.target.tagName == "INPUT" || event.target.tagName == "TEXTAREA") { return } if (can.page.tagis([html.SELECT, html.INPUT, html.TEXTAREA], event.target)) { return }
var msg = can.request(event, {"model": "normal"}); if (msg.Option(ice.MSG_HANDLE) == ice.TRUE) { return } var msg = can.request(event, {"model": "normal"}); if (msg.Option(ice.MSG_HANDLE) == ice.TRUE) { return }
can.onengine.signal(can, "onkeydown", msg); if (msg.Option(ice.MSG_HANDLE) == ice.TRUE) { return } can.onengine.signal(can, chat.ONKEYDOWN, msg); if (msg.Option(ice.MSG_HANDLE) == ice.TRUE) { return }
can._keylist = can.onkeymap._parse(event, can, msg.Option("model"), can._keylist, can._output) can._keylist = can.onkeymap._parse(event, can, msg.Option("model"), can._keylist, can._output)
} }
}, },
@ -852,13 +803,11 @@ Volcanos("onkeymap", {help: "键盘交互", list: [], _focus: [], _init: functio
if ("0" <= list[pre] && list[pre] <= "9") { continue } break if ("0" <= list[pre] && list[pre] <= "9") { continue } break
}; var count = parseInt(list.slice(0, pre).join(""))||1 }; var count = parseInt(list.slice(0, pre).join(""))||1
var map = can.onkeymap._mode[mode] var map = can.onkeymap._mode[mode]
function repeat(cb, count) { list = []; for (var i = 1; i <= count; i++) { if (cb(event, can, target, count)) { break } } } function repeat(cb, count) { list = []; for (var i = 1; i <= count; i++) { if (cb(event, can, target, count)) { break } } }
var cb = map && map[event.key]; if (can.base.isFunc(cb) && event.key.length > 1) { repeat(cb, count); return list } var cb = map && map[event.key]; if (can.base.isFunc(cb) && event.key.length > 1) { repeat(cb, count); return list }
var cb = map && map[event.key.toLowerCase()]; if (can.base.isFunc(cb) && event.key.length > 1) { repeat(cb, count); return list } var cb = map && map[event.key.toLowerCase()]; if (can.base.isFunc(cb) && event.key.length > 1) { repeat(cb, count); return list }
can.misc.Log("keys", count, list)
var map = can.onkeymap._engine[mode]; if (!map) { return [] } var map = can.onkeymap._engine[mode]; if (!map) { return [] }
for (var i = pre; i < list.length; i++ ) { for (var i = pre; i < list.length; i++ ) {
var map = map.list[list[i]]; if (!map) { return [] } var map = map.list[list[i]]; if (!map) { return [] }
@ -870,10 +819,9 @@ Volcanos("onkeymap", {help: "键盘交互", list: [], _focus: [], _init: functio
insert: { insert: {
jk: function(event, can, target) { target.blur(), can.onkeymap.deleteText(target, target.selectionStart-1, target.selectionStart) }, jk: function(event, can, target) { target.blur(), can.onkeymap.deleteText(target, target.selectionStart-1, target.selectionStart) },
Escape: function(event, can, target) { target.blur() }, Escape: function(event, can, target) { target.blur() },
Enter: function(event, can, target) { Enter: function(event, can, target) { var his = target._history||[]
var his = target._history||[]; his.push(target.value) his.push(target.value), target._history = his, target._current = his.length
event.target.tagName == "INPUT" && can.onmotion.focus(can, target) can.page.tagis(html.INPUT, event.target) && can.onmotion.focus(can, target)
target._history = his, target._current = his.length
}, },
}, },
insert_ctrl: { insert_ctrl: {

View File

@ -1,15 +1,10 @@
Volcanos("base", {help: "数据类型", Volcanos("base", {help: "数据类型",
Int: function(val, def) { Int: function(val, def) { return parseInt(val)||def||0 },
return parseInt(val)||def||0
},
Obj: function(val, def) { Obj: function(val, def) {
try { try {
val = typeof val == lang.STRING && val != ""? JSON.parse(val): val if (typeof val == lang.STRING) { if (val == "") { return def } val = JSON.parse(val) }
if (val && val.length == 0 && def && def.length > 0) { return def } if (val.length > 0) { return val } for (var k in val) { return val } return def
return val||def } catch (e) { return val && val.split && val.split(ice.FS) || def }
} catch (e) {
return [val]
}
}, },
Copy: function(to, from) { Copy: function(to, from) {
if (arguments.length == 2) { if (arguments.length == 2) {
@ -23,7 +18,6 @@ Volcanos("base", {help: "数据类型",
}, },
Eq: function(to, from) { var call = arguments.callee Eq: function(to, from) { var call = arguments.callee
if (typeof to != typeof from) { return false } if (typeof to != typeof from) { return false }
if (typeof to == lang.OBJECT) { if (typeof to == lang.OBJECT) {
if (to.length != from.length) { return false } if (to.length != from.length) { return false }
for (var i = 0; i < to.length; i++) { for (var i = 0; i < to.length; i++) {
@ -37,18 +31,21 @@ Volcanos("base", {help: "数据类型",
return to === from return to === from
}, },
Ext: function(path) { Ext: function(path) { return (path.split(ice.PS).pop().split(ice.PT).pop()).toLowerCase() },
return (path.split(ice.PS).pop().split(ice.PT).pop()).toLowerCase()
},
Path: function(path) { var res = "" Path: function(path) { var res = ""
for (var i = 0; i < arguments.length; i++) { for (var i = 0; i < arguments.length; i++) {
res += (arguments[i][0]==ice.PS || res=="" || res[res.length-1]==ice.PS? "": ice.PS) + arguments[i].trim() res += (arguments[i][0]==ice.PS || res=="" || res[res.length-1]==ice.PS? "": ice.PS) + arguments[i].trim()
} }
return res return res
}, },
Args: function(obj) { var res = [] Args: function() { var res = []
for (var k in obj) { for (var i = 0; i < arguments.length; i += 2) {
res.push(encodeURIComponent(k)+"="+encodeURIComponent(obj[k])) if (typeof arguments[i] == lang.OBJECT) {
for (var k in arguments[i]) { res.push(encodeURIComponent(k)+"="+encodeURIComponent(arguments[i][k])) }
i--; continue
} else if (arguments[i]) {
res.push(encodeURIComponent(arguments[i])+"="+encodeURIComponent(arguments[i+1]))
}
} }
return res.join("&") return res.join("&")
}, },
@ -58,25 +55,17 @@ Volcanos("base", {help: "数据类型",
}) })
for (var i = 1; i < arguments.length; i++) { for (var i = 1; i < arguments.length; i++) {
switch (typeof arguments[i]) { switch (typeof arguments[i]) {
case lang.STRING: case lang.STRING: args[arguments[i]] = arguments[i+1], i++; break
args[arguments[i]] = arguments[i+1], i++
break
case lang.OBJECT: case lang.OBJECT:
if (arguments[i].length > 0) { if (arguments[i].length > 0) {
for (var j = 0; j < arguments[i].length; j += 2) { for (var j = 0; j < arguments[i].length; j += 2) { args[arguments[i][j]] = arguments[i][j] }
args[arguments[i][j]] = arguments[i][j]
}
} else { } else {
for (var k in arguments[i]) { for (var k in arguments[i]) { args[k] = arguments[i][k] }
args[k] = arguments[i][k]
}
} }
break break
} }
} }
var list = []; for (var k in args) { var list = []; for (var k in args) { list.push(encodeURIComponent(k)+"="+encodeURIComponent(args[k])) }
list.push(encodeURIComponent(k)+"="+encodeURIComponent(args[k]))
}
return url.split("?")[0]+(list.length>0? "?"+list.join("&"): "") return url.split("?")[0]+(list.length>0? "?"+list.join("&"): "")
}, },
ParseURL: function(url) { var res = {link: url} ParseURL: function(url) { var res = {link: url}
@ -96,12 +85,8 @@ Volcanos("base", {help: "数据类型",
}) })
return res return res
} }
try { res = JSON.parse(str) try { res = JSON.parse(str), res.text = res.text||str, res.type = res.type||nfs.JSON
res.text = res.text||str } catch (e) { res = {type: mdb.TEXT, text: str} }
res.type = res.type||nfs.JSON
} catch (e) {
res = {type: mdb.TEXT, text: str}
}
return res return res
}, },
ParseSize: function(size) { size = size.toLowerCase() ParseSize: function(size) { size = size.toLowerCase()
@ -137,9 +122,7 @@ Volcanos("base", {help: "数据类型",
while (n > 0) { result.push("0"); n-- } while (n > 0) { result.push("0"); n-- }
return result.reverse(), result.join("") return result.reverse(), result.join("")
}, },
Format: function(obj) { Format: function(obj) { return JSON.stringify(obj) },
return JSON.stringify(obj)
},
Simple: function() { var res = [] Simple: function() { var res = []
for (var i = 0; i < arguments.length; i++) { for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i]; switch (typeof arguments[i]) { var arg = arguments[i]; switch (typeof arguments[i]) {
@ -154,9 +137,7 @@ Volcanos("base", {help: "数据类型",
} }
return res return res
}, },
AddUniq: function(list, value) { list = list||[] AddUniq: function(list, value) { list = list||[]; return list.indexOf(value) == -1 && list.push(value), list },
return list.indexOf(value) == -1 && list.push(value), list
},
Date: function(time) { var now = new Date() Date: function(time) { var now = new Date()
if (typeof time == lang.STRING && time != "") { var ls = time.split(ice.SP) if (typeof time == lang.STRING && time != "") { var ls = time.split(ice.SP)
@ -186,9 +167,7 @@ Volcanos("base", {help: "数据类型",
fmt = fmt.replace("%S", this.Number(now.getSeconds(), 2)) fmt = fmt.replace("%S", this.Number(now.getSeconds(), 2))
return fmt return fmt
}, },
TimeAdd: function(t, d) { TimeAdd: function(t, d) { return new Date(t - t%(24*3600*1000) - 8*3600*1000 + d*24*3600*1000) },
return new Date(t - t%(24*3600*1000) - 8*3600*1000 + d*24*3600*1000)
},
Duration: function(n) { var res = "", h = 0 Duration: function(n) { var res = "", h = 0
h = parseInt(n/3600000/24), h > 0 && (res += h+"d"), n = n % (3600000*24) h = parseInt(n/3600000/24), h > 0 && (res += h+"d"), n = n % (3600000*24)
h = parseInt(n/3600000), h > 0 && (res += h+"h"), n = n % 3600000 h = parseInt(n/3600000), h > 0 && (res += h+"h"), n = n % 3600000
@ -229,31 +208,16 @@ Volcanos("base", {help: "数据类型",
return str return str
}, },
isNight: function() { var now = new Date() random: function(max, min) { min = min||0, parseInt(Math.random()*(max-min))+min },
return now.getHours() < 7 || now.getHours() > 17 isNight: function() { var now = new Date(); return now.getHours() < 7 || now.getHours() > 17 },
}, beginWith: function(str, begin) { return str.trim().indexOf(begin) == 0 },
beginWith: function(str, begin) { endWith: function(str, end) { return str.lastIndexOf(end) + end.length == str.length },
return str.trim().indexOf(begin) == 0
},
endWith: function(str, end) {
return str.lastIndexOf(end) + end.length == str.length
},
trim: function(args) { if (this.isString(args)) { return args.trim() } 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 } } } if (this.isArray(args)) { for (var i = args.length-1; i >= 0; i--) { if (!args[i]) { args.pop() } else { break } } }
return args return args
}, },
trimPrefix: function(str, pre) { trimPrefix: function(str, pre) { if (str.indexOf(pre) == -1) { return str } return str.slice(pre.length) },
if (str.indexOf(pre) == -1) { trimSuffix: function(str, end) { if (str.indexOf(end) == -1) { return str } return str.slice(0, str.indexOf(end)) },
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) }, join: function(list, sp) { return (list||[]).join(sp||ice.SP) },
joins: function(list, inner, outer) { joins: function(list, inner, outer) {
for (var i = 0; i < list.length; i++) { for (var i = 0; i < list.length; i++) {

View File

@ -2,11 +2,7 @@ Volcanos("core", {help: "数据结构",
Keys: shy("连接器", function() { var list = [] Keys: shy("连接器", function() { var list = []
for (var i = 0; i < arguments.length; i++) { var v = arguments[i] for (var i = 0; i < arguments.length; i++) { var v = arguments[i]
switch (typeof v) { switch (typeof v) {
case lang.OBJECT: case lang.OBJECT: for (var j = 0; j < v.length; j++) { list.push(v[j]) } break
for (var j = 0; j < v.length; j++) {
list.push(v[j])
}
break
case lang.FUNCTION: v = v() case lang.FUNCTION: v = v()
default: v && list.push(v+"") default: v && list.push(v+"")
} }
@ -18,10 +14,7 @@ Volcanos("core", {help: "数据结构",
if (key == undefined) { return data } if (key == undefined) { return data }
if (typeof key == lang.OBJECT && key.length > 0) { key = key.join(ice.PT) } if (typeof key == lang.OBJECT && key.length > 0) { key = key.join(ice.PT) }
if (typeof key == lang.OBJECT) { for (var k in key) { arguments.callee.call(this, data, k, key[k]) } return data }
if (typeof key == lang.OBJECT) { for (var k in key) {
arguments.callee.call(this, data, k, key[k])
}; return data }
if (value != undefined) { data[key] = value } if (value != undefined) { data[key] = value }
if (data[key] != undefined) { return data[key] } if (data[key] != undefined) { return data[key] }
@ -29,7 +22,7 @@ Volcanos("core", {help: "数据结构",
var p = data, ls = key.split(ice.PT); while (p && ls.length > 0) { var p = data, ls = key.split(ice.PT); while (p && ls.length > 0) {
if (ls[0] == "-1") { ls[0] = p.length-1 } if (ls[0] == "-1") { ls[0] = p.length-1 }
p = p[ls[0]], ls = ls.slice(1) p = p[ls[0]], ls = ls.slice(1)
}; return p } return p
}), }),
Split: shy("分词器", function(str) { if (!str || !str.length) { return [] } Split: shy("分词器", function(str) { if (!str || !str.length) { return [] }
var opt = {detail: false}, arg = []; for (var i = 1; i < arguments.length; i++) { var opt = {detail: false}, arg = []; for (var i = 1; i < arguments.length; i++) {
@ -52,7 +45,7 @@ Volcanos("core", {help: "数据结构",
if (space[str[i]]) { // 空白符 if (space[str[i]]) { // 空白符
if (s) { continue } if (s) { continue }
begin > -1 && push(str.slice(begin, i)) begin > -1 && push(str.slice(begin, i))
opt.detail && push({type: "space", text: str.slice(i, i+1)}) opt.detail && push({type: html.SPACE, text: str.slice(i, i+1)})
} else if (block[str[i]]) { // 分隔符 } else if (block[str[i]]) { // 分隔符
if (s) { continue } if (s) { continue }
@ -61,6 +54,7 @@ Volcanos("core", {help: "数据结构",
} else if (quote[str[i]]) { // 引用符 } else if (quote[str[i]]) { // 引用符
if (s == "") { if (s == "") {
begin > -1 && push(str.slice(begin, i))
s = str[i], begin = i+1 s = str[i], begin = i+1
} else if (s == str[i]) { } else if (s == str[i]) {
push({type: lang.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]})
@ -80,7 +74,7 @@ Volcanos("core", {help: "数据结构",
return res return res
}), }),
CallFunc: shy("调用器", function(func, args, mod) { args = args||{} CallFunc: shy("调用器", function(func, args, mod) { args = args||{}
var can = args["can"]||args[0], msg = args["msg"]||args[1], cmds = args["cmds"]||[], event = args["event"]||{} var event = args["event"]||{}, can = args["can"]||args[0], msg = args["msg"]||args[1], cmds = args["cmds"]||[]
// 查找调用 // 查找调用
func = typeof func == lang.FUNCTION? func: typeof func == lang.STRING? this.Value(mod||can, func): func = typeof func == lang.FUNCTION? func: typeof func == lang.STRING? this.Value(mod||can, func):
@ -112,7 +106,6 @@ Volcanos("core", {help: "数据结构",
} }
list = list||[] list = list||[]
if (interval > 0) { // 时间序列 if (interval > 0) { // 时间序列
function loop(i) { if (i >= list.length) { return typeof cbs == lang.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) cb(list[i], i, list), setTimeout(function() { loop(i+1) }, interval)
@ -182,12 +175,5 @@ Volcanos("core", {help: "数据结构",
typeof cb == lang.FUNCTION && setTimeout(function() { loop(0) }, interval.interval||interval[0]) typeof cb == lang.FUNCTION && setTimeout(function() { loop(0) }, interval.interval||interval[0])
return timer 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
}),
}) })

View File

@ -65,8 +65,7 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg
Push: function(key, value, detail) { Push: function(key, value, detail) {
if (can.base.isObject(key)) { if (can.base.isObject(key)) {
value = value||can.core.Item(key), can.core.List(value, function(item) { value = value||can.core.Item(key), can.core.List(value, function(item) {
detail? msg.Push(mdb.KEY, item).Push(mdb.VALUE, key[item]||""): detail? msg.Push(mdb.KEY, item).Push(mdb.VALUE, key[item]||""): msg.Push(item, key[item]||"")
msg.Push(item, key[item]||"")
}) })
return msg return msg
} }
@ -79,7 +78,7 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg
for (var i = 0; i < arguments.length; i++) { msg.result.push(arguments[i]) } for (var i = 0; i < arguments.length; i++) { msg.result.push(arguments[i]) }
return msg._hand = true, msg return msg._hand = true, msg
}, },
}; }
return can.misc.proto(msg, proto) return can.misc.proto(msg, proto)
}, },
POST: function(can, msg, url, form, cb) { // _method _accept _upload _progress POST: function(can, msg, url, form, cb) { // _method _accept _upload _progress
@ -101,7 +100,7 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg
if (msg._upload) { // 上传文件 if (msg._upload) { // 上传文件
var data = new FormData(); can.core.Items(form, function(value, index, key) { var data = new FormData(); can.core.Items(form, function(value, index, key) {
data.append(key, value) data.append(key, value)
}), data.append(html.UPLOAD, msg._upload), data.append(ice.MSG_UPLOAD, "upload") }), data.append(html.UPLOAD, msg._upload), data.append(ice.MSG_UPLOAD, mdb.UPLOAD)
xhr.upload.onprogress = function(event) { xhr.upload.onprogress = function(event) {
can.base.isFunc(msg._progress) && msg._progress(event, parseInt(event.loaded*100/event.total), event.total, event.loaded) can.base.isFunc(msg._progress) && msg._progress(event, parseInt(event.loaded*100/event.total), event.total, event.loaded)
@ -131,7 +130,7 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg
var socket = new WebSocket(can.base.MergeURL(url, args)) var socket = new WebSocket(can.base.MergeURL(url, args))
socket.onclose = function() { can.misc.Log(html.WSS, cli.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.base.isFunc(onclose)? onclose(socket): can.core.Timer(can.base.random(3000, 1000), function() {
can.misc.WSS(can, args, cb, onopen, onerror, onclose) can.misc.WSS(can, args, cb, onopen, onerror, onclose)
}) })
}, socket.onerror = function() { can.misc.Log(html.WSS, cli.ERROR, args) }, socket.onerror = function() { can.misc.Log(html.WSS, cli.ERROR, args)
@ -141,48 +140,31 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg
can.base.isFunc(onopen) && onopen(socket) can.base.isFunc(onopen) && onopen(socket)
} }
socket.onmessage = function(event) { socket.onmessage = function(event) { // 解析命令
try { // 解析命令 try { var data = JSON.parse(event.data) } catch (e) { var data = {detail: [event.data]} }
var data = JSON.parse(event.data)
} catch (e) {
var data = {detail: [event.data]}
}
var msg = can.request(event); msg.Reply = function() { // 回复命令 var msg = can.request(event); msg.Reply = function() { // 回复命令
msg.result = (msg.result||[]).concat(can.core.List(arguments)) msg.Option({_handle: true, _source: (msg[ice.MSG_TARGET]||[]).reverse().slice(1).join(ice.PT)||"", _target: (msg[ice.MSG_SOURCE]||[]).reverse().join(ice.PT)})
msg.result = (msg.result||[]).concat(can.core.List(arguments)), can.misc.Log(html.WSS, ice.MSG_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(".")}) delete(msg._event), delete(msg._can), socket.send(JSON.stringify(msg))
can.misc.Log(html.WSS, ice.MSG_RESULT, msg.result, msg)
delete(msg._event), delete(msg._can)
socket.send(JSON.stringify(msg))
}, msg.detail = data.detail, msg.Copy(data) }, msg.detail = data.detail, msg.Copy(data)
// 执行命令 try { // 执行命令
try {
can.misc.Log(html.WSS, ice.MSG_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)) can.base.isFunc(cb) && cb(event, msg, msg.detail[0], msg.detail.slice(1))
} catch (e) { // 执行失败 } catch (e) { can.misc.Log(e), msg.Reply() }
can.misc.Log(e), msg.Reply()
}
} }
}, },
CookieSessid: shy("会话变量", function(can, value, path) { CookieSessid: shy("会话变量", function(can, value, path) {
var name = ice.MSG_SESSID+"_"+location.host.replaceAll(".", "_").replaceAll(":", "_") return can.misc.Cookie(can, ice.MSG_SESSID+"_"+location.host.replaceAll(ice.PT, "_").replaceAll(ice.DF, "_"), value, path)
return can.misc.Cookie(can, name, value, path)
}), }),
Cookie: shy("会话变量", function(can, key, value, path) { Cookie: shy("会话变量", function(can, key, value, path) {
function set(k, v) { document.cookie = k+"="+v+";path="+(path||ice.PS) } function set(k, v) { document.cookie = k+"="+v+";path="+(path||ice.PS) }
if (can.base.isObject(key)) { for (var k in key) { set(k, key[k]) } key = undefined }
if (can.base.isObject(key)) {
for (var k in key) { set(k, key[k]) }
key = undefined
}
if (key == undefined) { var cs = {} if (key == undefined) { var cs = {}
document.cookie.split("; ").forEach(function(item) { document.cookie.split("; ").forEach(function(item) { var ls = item.split("="); cs[ls[0]] = ls[1] })
var ls = item.split("="); cs[ls[0]] = ls[1]
})
return cs return cs
} }
@ -190,36 +172,27 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg
var val = (new RegExp(key+"=([^;]*);?")).exec(document.cookie) var val = (new RegExp(key+"=([^;]*);?")).exec(document.cookie)
return val && val.length > 0? val[1]: "" return val && val.length > 0? val[1]: ""
}), }),
SearchOrConf: function(can, key, def) { SearchOrConf: function(can, key, def) { can.base.getValid(can.misc.Search(can, key), can.Conf(key), def) },
can.base.getValid(can.misc.Search(can, key), can.Conf(key), def)
},
Search: shy("请求参数", function(can, key, value) { var args = {} Search: shy("请求参数", function(can, key, value) { var args = {}
if (value == undefined && can.base.isString(key)) { if (value == undefined && can.base.isString(key)) {
var ls = location.pathname.split(ice.PS) var ls = location.pathname.split(ice.PS); if (ls[1] == chat.SHARE) { args[chat.SHARE] = ls[2] }
if (ls[1] == chat.SHARE) { args[chat.SHARE] = ls[2] } for (var i = 2; i < ls.length; i += 2) { if ({"pod": true, "cmd": true}[ls[i]]) { args[ls[i]] + ls[i+1] } }
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("=") location.search && location.search.slice(1).split("&").forEach(function(item) { var x = item.split("=")
x[1] != "" && (args[x[0]] = decodeURIComponent(x[1])) x[1] != "" && (args[x[0]] = decodeURIComponent(x[1]))
}) })
if (can.base.isObject(key)) { if (can.base.isObject(key)) {
can.core.Item(key, function(key, value) { can.core.Item(key, function(key, value) {
if (value != undefined) {args[key] = value} if (value != undefined) { args[key] = value } args[key] == "" && delete(args[key])
args[key] == "" && delete(args[key])
}) })
} else if (key == undefined) {
return args
} else if (value == undefined) {
return args[key]
} else { } else {
if (key == undefined) { return args }
if (value == undefined) { return args[key] }
args[key] = value, args[key] == "" && delete(args[key]) args[key] = value, args[key] == "" && delete(args[key])
} }
return location.search = can.core.Item(args, function(key, value) { return location.search = can.core.Item(args, function(key, value) { return key+"="+encodeURIComponent(value) }).join("&")
return key+"="+encodeURIComponent(value)
}).join("&")
}), }),
MergeURL: shy("地址链接", function(can, objs, clear) { MergeURL: shy("地址链接", function(can, objs, clear) {
var path = location.pathname; objs._path && (path = objs._path, delete(objs._path)) var path = location.pathname; objs._path && (path = objs._path, delete(objs._path))
@ -232,12 +205,8 @@ Volcanos("misc", {help: "通信协议", Message: function(event, can) { var msg
if (list[cmds[0]]) { return list[cmds[0]](cmds.slice(1)), true } if (list[cmds[0]]) { return list[cmds[0]](cmds.slice(1)), true }
}, },
concat: function(can, to, from) { to = to||[], from = from||[] concat: function(can, to, from) { to = to||[], from = from||[]
if (from[0] == ctx.ACTION && from[1] == ice.RUN && can.onengine.plugin.meta[from[2]]) { if (from[0] == ctx.ACTION && from[1] == ice.RUN && can.onengine.plugin.meta[from[2]]) { return from }
return from if (can.onengine.plugin.meta[from[0]]) { return from }
}
if (can.onengine.plugin.meta[from[0]]) {
return from
}
if (from[0] == "_search") { return from } if (from[0] == "_search") { return from }
return to.concat(from) return to.concat(from)
}, },

View File

@ -7,9 +7,7 @@ Volcanos("page", {help: "用户界面", ClassList: {
return value != obj.className && (obj.className = value), value return value != obj.className && (obj.className = value), value
}, },
del: function(can, obj, key) { var list = obj.className? obj.className.split(ice.SP): [] del: function(can, obj, key) { var list = obj.className? obj.className.split(ice.SP): []
return obj.className = can.core.List(list, function(value) { return obj.className = can.core.List(list, function(value) { return value == key? undefined: value }).join(ice.SP).trim()
return value == key? undefined: value
}).join(ice.SP).trim()
}, },
set: function(can, obj, key, condition) { set: function(can, obj, key, condition) {
return (condition? this.add(can, obj, key): this.del(can, obj, key)).indexOf(key) > -1 return (condition? this.add(can, obj, key): this.del(can, obj, key)).indexOf(key) > -1
@ -59,9 +57,7 @@ Volcanos("page", {help: "用户界面", ClassList: {
"width": true, "max-width": true, "min-width": true, "width": true, "max-width": true, "min-width": true,
} }
if (size[k] && v && (can.base.isNumber(v) || v.indexOf && v.indexOf("px") == -1)) { if (size[k] && v && (can.base.isNumber(v) || v.indexOf && v.indexOf("px") == -1)) { v += "px" }
v += "px"
}
target[key] && (target[key][k] = v) target[key] && (target[key][k] = v)
}) })
}) })
@ -305,8 +301,7 @@ Volcanos("page", {help: "用户界面", ClassList: {
} }
}, },
replace: function(can, text, key, value) { replace: function(can, text, key, value) {
text = can.base.replaceAll(text, "<", "&lt;", ">", "&gt;", key, value) return can.base.replaceAll(text, "<", "&lt;", ">", "&gt;", key, value)
return text
}, },
Color: function(text) { if (typeof text != lang.STRING) { return "" } Color: function(text) { if (typeof text != lang.STRING) { return "" }
if (text.indexOf("http://") == 0 || text.indexOf("https://") == 0 || text.indexOf("ftp://") == 0) { if (text.indexOf("http://") == 0 || text.indexOf("https://") == 0 || text.indexOf("ftp://") == 0) {
@ -333,8 +328,8 @@ Volcanos("page", {help: "用户界面", ClassList: {
switch (item.type = item.type||html.TEXT) { switch (item.type = item.type||html.TEXT) {
case html.TEXTAREA: input.type = html.TEXTAREA case html.TEXTAREA: input.type = html.TEXTAREA
input.style.height = input.style.height||can.Conf(["feature", html.TEXTAREA, item.name, html.HEIGHT].join(ice.PT))||can.Conf(["feature", html.TEXTAREA, html.HEIGHT].join(ice.PT)) input.style.height = input.style.height||can.Conf([ctx.FEATURE, html.TEXTAREA, item.name, html.HEIGHT].join(ice.PT))||can.Conf(["feature", html.TEXTAREA, html.HEIGHT].join(ice.PT))
input.style.width = input.style.width||can.Conf(["feature", html.TEXTAREA, item.name, html.WIDTH].join(ice.PT))||can.Conf(["feature", html.TEXTAREA, html.WIDTH].join(ice.PT)) input.style.width = input.style.width||can.Conf([ctx.FEATURE, html.TEXTAREA, item.name, html.WIDTH].join(ice.PT))||can.Conf(["feature", html.TEXTAREA, html.WIDTH].join(ice.PT))
// no break // no break
case html.USERNAME: case html.USERNAME:
case html.PASSWORD: case html.PASSWORD:
@ -355,7 +350,7 @@ Volcanos("page", {help: "用户界面", ClassList: {
return {type: html.OPTION, value: value, inner: value} return {type: html.OPTION, value: value, inner: value}
}), item.className || can.page.ClassList.add(can, item, ctx.ARGS) }), item.className || can.page.ClassList.add(can, item, ctx.ARGS)
break break
case html.BUTTON: item.value = item.value||item.name||"list"; break case html.BUTTON: item.value = item.value||item.name||mdb.LIST; break
case "upfile": item.type = html.FILE; break case "upfile": item.type = html.FILE; break
case html.UPLOAD: item.type = html.FILE, input.name = html.UPLOAD; break case html.UPLOAD: item.type = html.FILE, input.name = html.UPLOAD; break
default: default:
@ -363,13 +358,14 @@ Volcanos("page", {help: "用户界面", ClassList: {
return input return input
}, },
styleDisplay: function(can, target, value) {
return can.page.style(can, target, html.DISPLAY, value), target.style.display
},
styleHeight: function(can, target, value) { styleHeight: function(can, target, value) {
can.page.style(can, target, html.HEIGHT, value) return can.page.style(can, target, html.HEIGHT, value), target.offsetHeight
return target.offsetHeight
}, },
styleWidth: function(can, target, value) { styleWidth: function(can, target, value) {
can.page.style(can, target, html.WIDTH, value) return can.page.style(can, target, html.WIDTH, value), target.offsetWidth
return target.offsetWidth
}, },
style: function(can, target, style) { var value = {} style: function(can, target, style) { var value = {}
for (var i = 2; i < arguments.length; i += 2) { for (var i = 2; i < arguments.length; i += 2) {
@ -379,8 +375,7 @@ Volcanos("page", {help: "用户界面", ClassList: {
value[arguments[i]] = arguments[i+1] value[arguments[i]] = arguments[i+1]
} }
} }
can.page.Modify(can, target, {style: value}) return can.page.Modify(can, target, {style: value}), value
return value
}, },
Keys: function() { var list = [] Keys: function() { var list = []
for (var i = 0; i < arguments.length; i++) { var v = arguments[i] for (var i = 0; i < arguments.length; i++) { var v = arguments[i]
@ -405,6 +400,9 @@ Volcanos("page", {help: "用户界面", ClassList: {
styleSheet.type = "text/css", styleSheet.innerText = text styleSheet.type = "text/css", styleSheet.innerText = text
document.head.appendChild(styleSheet) document.head.appendChild(styleSheet)
}, },
tagis: function(type, target) { type = typeof type == lang.OBJECT? type: [type]
if (type.indexOf(target.tagName.toLowerCase()) > -1) { return true }
},
offsetTop: function(item) { var res = 0 offsetTop: function(item) { var res = 0
while (item) { res += item.offsetTop||0, item = item.parentNode } while (item) { res += item.offsetTop||0, item = item.parentNode }
return res return res

View File

@ -46,19 +46,15 @@ Volcanos("user", {help: "用户操作", agent: {
return can.base.Time(time, (fmt||"%y-%m-%d %H:%M:%S").replace("%w", list[now.getDay()])) return can.base.Time(time, (fmt||"%y-%m-%d %H:%M:%S").replace("%w", list[now.getDay()]))
}, },
title: function(text) { title: function(text) { return text && (document.title = text), document.title },
return text && (document.title = text), document.title
},
topic: function(can, name) { topic: function(can, name) {
can.user.isMobile && (name += " mobile") && can.user.isLandscape() && (name += " landscape") can.user.isMobile && (name += " mobile") && can.user.isLandscape() && (name += " landscape")
can.page.Modify(can, document.body, {className: name}) can.page.Modify(can, document.body, {className: name})
}, },
language: function(can) { language: function(can) { return can.misc.Search(can, "language") },
return can.misc.Search(can, "language")
},
trans: function(can, text, list) { if (can.base.isObject(text)) { trans: function(can, text, list) { if (can.base.isObject(text)) {
return can.core.Item(text, function(k, v) { can.core.Value(can._trans, k, v) }) return can.core.Item(text, function(k, v) { can.core.Value(can._trans, k, v) })
} }
if (can.user.language(can) == "en") { return text } if (can.user.language(can) == "en") { return text }
if (can.base.isFunction(text)) { text = text.name||"" } if (can.base.isFunction(text)) { text = text.name||"" }
@ -78,12 +74,8 @@ Volcanos("user", {help: "用户操作", agent: {
"label": "标签", "exec": "执行", "label": "标签", "exec": "执行",
}[text]||text }[text]||text
}, },
toastProcess: function(can, title) { toastProcess: function(can, title) { return can.user.toast(can, ice.PROCESS, title) },
return can.user.toast(can, ice.PROCESS, title) toastSuccess: function(can, title) { return can.user.toast(can, ice.SUCCESS, title) },
},
toastSuccess: function(can, title) {
return can.user.toast(can, ice.SUCCESS, title)
},
toast: function(can, content, title, duration, progress) { 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._help, duration: duration, progress: progress}
var width = meta.width||400, height = meta.height||100; if (width < 0) { width = window.innerWidth + width } var width = meta.width||400, height = meta.height||100; if (width < 0) { width = window.innerWidth + width }
@ -124,9 +116,7 @@ Volcanos("user", {help: "用户操作", agent: {
}) })
}, },
login: function(can, cb, method) { login: function(can, cb, method) {
var ui = can.user.input({}, can, [ var ui = can.user.input({}, can, [{type: html.USERNAME}, {type: html.PASSWORD}], function(event, button, data, list) { return {
{type: html.USERNAME}, {type: html.PASSWORD},
], function(event, button, data, list) { return {
"登录": function() { "登录": function() {
can.run({}, [aaa.LOGIN, data[html.USERNAME], data[html.PASSWORD]], function(msg) { can.run({}, [aaa.LOGIN, data[html.USERNAME], data[html.PASSWORD]], function(msg) {
if (msg.Option(ice.MSG_USERNAME)) { if (msg.Option(ice.MSG_USERNAME)) {

View File

@ -24,7 +24,7 @@ div.story[data-type=spark] {
select { select {
background-color:black; color:cyan; background-color:black; color:cyan;
box-shadow:4px 4px 10px 1px #626bd0; box-shadow:4px 4px 10px 1px #626bd0;
height:1.7em; padding:0 10px; height:1.7rem; padding:0 10px;
cursor:pointer; cursor:pointer;
} }
textarea { background-color:cyan; width:400px; height:60px; white-space:pre; } textarea { background-color:cyan; width:400px; height:60px; white-space:pre; }
@ -32,7 +32,7 @@ input[type=button] { background-color:black; color:cyan; cursor:pointer; }
input[type=text] { input[type=text] {
background-color:cyan; color:black; background-color:cyan; color:black;
box-shadow:4px 4px 10px 1px #626bd0; box-shadow:4px 4px 10px 1px #626bd0;
height:1.4em; width:82px; height:1.4rem; width:82px;
padding:0 4px; padding:0 4px;
} }
input[name=date] { width:150px; } input[name=date] { width:150px; }
@ -122,6 +122,7 @@ fieldset>div.status>div.item { float:left; padding:4px; height:18px; }
fieldset.panel>legend { display:none; } fieldset.panel>legend { display:none; }
fieldset.plugin { margin:10px; padding:10px; background-color:#061c3c9e; box-shadow:2px 2px 10px 4px #626bd0; } fieldset.plugin { margin:10px; padding:10px; background-color:#061c3c9e; box-shadow:2px 2px 10px 4px #626bd0; }
fieldset.plugin>div.action { float:none; display:block; height:1.8rem; overflow:auto; }
fieldset.plugin>div.status { border-top:1px solid darkcyan; } fieldset.plugin>div.status { border-top:1px solid darkcyan; }
fieldset.output { margin:0; padding:0; } fieldset.output { margin:0; padding:0; }
fieldset.output>legend { display:none; } fieldset.output>legend { display:none; }
@ -132,6 +133,7 @@ fieldset.story>legend { display:block; padding:2px 20px; letter-spacing:4px; }
fieldset.story>div.status { border-top:1px solid darkcyan; } fieldset.story>div.status { border-top:1px solid darkcyan; }
fieldset.float { background-color:#023531cf; margin:0px; padding:0px; position:absolute; } fieldset.float { background-color:#023531cf; margin:0px; padding:0px; position:absolute; }
fieldset.float>legend { float:left; } fieldset.float>legend { float:left; }
fieldset.float>div.action { display:block; float:none; height:2rem; overflow:auto; }
fieldset.float table { color:white; } fieldset.float table { color:white; }
fieldset.input { background-color:#0d4142a6; position:fixed; top:32px; } fieldset.input { background-color:#0d4142a6; position:fixed; top:32px; }
@ -140,6 +142,7 @@ fieldset.input div.output { max-height:400px; }
fieldset.input table { color:white; } fieldset.input table { color:white; }
fieldset.input td { word-break:keep-all; } fieldset.input td { word-break:keep-all; }
fieldset.input.date table { text-align:center; width:280px; } fieldset.input.date table { text-align:center; width:280px; }
fieldset.input.date>div.action { height:4rem; }
body>div.toast { background-color:#0e3369b3; color:yellow; padding:5px; overflow:auto; position:fixed; } body>div.toast { background-color:#0e3369b3; color:yellow; padding:5px; overflow:auto; position:fixed; }
body>div.toast div.title { float:left; cursor:copy; word-break:break-all; } body>div.toast div.title { float:left; cursor:copy; word-break:break-all; }
@ -176,9 +179,9 @@ body>div.upload input[type=file] { width:240px; }
* { tab-size:4; } * { tab-size:4; }
textarea { tab-size:2; } textarea { tab-size:2; }
input, select, option, table.content, div.item, div.code, code.story, div.story[data-type=spark] { font-size:1.1em; font-family:monospace; } input, select, option, table.content, div.item, div.code, code.story, div.story[data-type=spark] { font-size:1.1rem; font-family:monospace; }
legend { font-size:1.4em; } legend { font-size:1.2rem; }
fieldset>div.status>div.item>label { font-size:0.6em; color:#bdb8b8e0; } fieldset>div.status>div.item>label { font-size:0.6rem; color:#bdb8b8e0; }
body>div.toast div.title { color:#cae850; } body>div.toast div.title { color:#cae850; }
body>div.toast div.duration { color:gray; } body>div.toast div.duration { color:gray; }
@ -208,12 +211,13 @@ body.white table td>input[type=button][value=启动] { background-color:#52ce78;
body.white table td>input[type=button][name=create] { background-color:blue; } body.white table td>input[type=button][name=create] { background-color:blue; }
body.white table td>input[type=button][name=remove] { background-color:red; } body.white table td>input[type=button][name=remove] { background-color:red; }
body.white fieldset>div.status>div.item>label { font-size:0.6em; color:#cefbfbe0; } body.white fieldset>div.status>div.item>label { font-size:0.6rem; color:#cefbfbe0; }
body.white fieldset.Action { color:black; } body.white fieldset.Action { color:black; }
body.white fieldset.Action>div.action { color:white; } body.white fieldset.Action>div.action { color:white; }
body.white fieldset.Action>div.action div.item { height:21px; } body.white fieldset.Action>div.action div.item { height:21px; }
body.white fieldset.Action fieldset.plugin { background-color:#ffffff78; } body.white fieldset.Action fieldset.plugin { background-color:#ffffff78; }
body.white fieldset.Action fieldset.plugin legend { background-color:#339999; color:white; border-radius:10px 10px 10px 10px; } body.white fieldset.Action fieldset.plugin legend { background-color:#339999; color:white; border-radius:10px 10px 10px 10px; }
body.white fieldset.input table { color:white; }
body.white>div.input textarea { border:2px solid #14a58e; border-radius:6px; } body.white>div.input textarea { border:2px solid #14a58e; border-radius:6px; }
body.print { background-color:white; color:black; } body.print { background-color:white; color:black; }
@ -235,22 +239,22 @@ body.white table.content tr:hover { background-color:green; }
body.white fieldset.Action fieldset.plugin legend:hover { background-color:#6ee4e4; } body.white fieldset.Action fieldset.plugin legend:hover { background-color:#6ee4e4; }
body.print fieldset.River>div.output div.item.select { background-color:white; border:solid 2px red; } body.print fieldset.River>div.output div.item.select { background-color:white; border:solid 2px red; }
body.mobile select { font-size:1.4rem; height:1.4em; margin-top:3px; } body.mobile select { font-size:1.4rem; height:1.4rem; margin-top:3px; }
body.mobile legend { font-size:2rem; } body.mobile legend { font-size:2rem; }
body.mobile input { font-size:1.2rem; } body.mobile input { font-size:1.2rem; }
body.mobile input[type=text] { margin-top:5px; height:1.4em; } body.mobile input[type=text] { margin-top:5px; height:1.4rem; }
body.mobile fieldset.Header.head { width:-webkit-fill-available; } body.mobile fieldset.Header.head { width:-webkit-fill-available; }
body.mobile fieldset.Header.head { background-color:#000000b8; font-size:2rem; height:2em; position:fixed; top:0; } body.mobile fieldset.Header.head { background-color:#000000b8; font-size:2rem; height:2rem; position:fixed; top:0; }
body.mobile fieldset.Header.head div.output { height:2em; } body.mobile fieldset.Header.head div.output { height:2rem; }
body.mobile fieldset.Header.head>div.output>div { height:1.5em; } body.mobile fieldset.Header.head>div.output>div { height:1.5rem; }
body.mobile fieldset.Header.head>div.output div.menu { height:1.5em; } body.mobile fieldset.Header.head>div.output div.menu { height:1.5rem; }
body.mobile fieldset.Header.head div.state.time { display:none; } body.mobile fieldset.Header.head div.state.time { display:none; }
body.mobile fieldset.River.left { position:fixed; top:2em; background-color:#243950bf; min-width:240px; font-size:2rem; } body.mobile fieldset.River.left { position:fixed; top:2rem; background-color:#243950bf; min-width:240px; font-size:2rem; }
body.mobile fieldset.River>div.output div.list div.item { font-size:2rem; } body.mobile fieldset.River>div.output div.list div.item { font-size:2rem; }
body.mobile fieldset.Action.main { margin-top:4em; } body.mobile fieldset.Action.main { margin-top:4rem; }
body.mobile fieldset.Action.main.cmd { margin-top:0; margin-bottom:0; } body.mobile fieldset.Action.main.cmd { margin-top:0; margin-bottom:0; }
body.mobile fieldset.Footer.foot { width:-webkit-fill-available; } body.mobile fieldset.Footer.foot { width:-webkit-fill-available; }
body.mobile fieldset.Footer.foot { background-color:#000000b8; font-size:2rem; height:2em; position:fixed; bottom:0; } body.mobile fieldset.Footer.foot { background-color:#000000b8; font-size:2rem; height:2rem; position:fixed; bottom:0; }
body.mobile fieldset.Footer.foot { display:none; } body.mobile fieldset.Footer.foot { display:none; }
body.mobile.landscape fieldset.Header.head { position:unset; } body.mobile.landscape fieldset.Header.head { position:unset; }
body.mobile.landscape fieldset.Header.head div.state.time { display:block; } body.mobile.landscape fieldset.Header.head div.state.time { display:block; }

View File

@ -20,10 +20,14 @@ Volcanos("onfigure", {help: "控件详情", list: [], key: {
}, },
onfocus: function(event, can, meta, cb, target) { if (target._figure) { return } target._figure = {}; cb(function(can, cbs) { onfocus: function(event, can, meta, cb, target) { if (target._figure) { return } target._figure = {}; cb(function(can, cbs) {
target._figure = can.onlayout.figure(event, can, can._target, false, {top: can.page.offsetTop(target)+target.offsetHeight, left: can.page.offsetLeft(target)}) target._figure = can.onlayout.figure(event, can, can._target, false, {top: can.page.offsetTop(target)+target.offsetHeight, left: can.page.offsetLeft(target)})
can.onfigure.key._show(can, meta, cbs, target) can.onfigure.key._show(can, meta, cbs, target), can.onmotion.focus(can, target)
can.onmotion.focus(can, target) target.click()
}) }, }) },
onblur: function(event, can, meta, cb, target) { delete(target._figure), target._can && target._can.close() }, onblur: function(event, can, meta, cb, target) {
can.core.Timer(100, function() {
delete(target._figure), target._can && target._can.close()
})
},
onclick: function(event, can, meta, cb, target) { if (target._figure) { target._figure = can.onlayout.figure(event, can, can.core.Value(target, "_can._target")||{}); return } target._figure = {}; cb(function(can, cbs) { onclick: function(event, can, meta, cb, target) { if (target._figure) { target._figure = can.onlayout.figure(event, can, can.core.Value(target, "_can._target")||{}); return } target._figure = {}; cb(function(can, cbs) {
target._figure = can.onlayout.figure(event, can) target._figure = can.onlayout.figure(event, can)
can.onfigure.key._show(can, meta, cbs, target) can.onfigure.key._show(can, meta, cbs, target)

View File

@ -1,9 +1,3 @@
fieldset.inner>div.action {
float:none;
display:block;
/* height:1.65em; */
overflow:auto;
}
fieldset.inner>div.action div.tabs { fieldset.inner>div.action div.tabs {
border:solid 2px red; padding:2px; border:solid 2px red; padding:2px;
} }
@ -33,7 +27,7 @@ fieldset.inner>div.output div.project {
fieldset.inner>div.output div.content { fieldset.inner>div.output div.content {
position:relative; position:relative;
padding-right:25px; padding-right:25px;
font-size:1.2em; font-family:monospace; font-size:1.2rem; font-family:monospace;
overflow:auto; overflow:auto;
color:white; color:white;
} }

View File

@ -88,6 +88,7 @@ var mdb = {
CREATE: "create", REMOVE: "remove", INSERT: "insert", DELETE: "delete", CREATE: "create", REMOVE: "remove", INSERT: "insert", DELETE: "delete",
MODIFY: "modify", SELECT: "select", MODIFY: "modify", SELECT: "select",
INPUTS: "inputs", PRUNES: "prunes", EXPORT: "export", IMPORT: "import", INPUTS: "inputs", PRUNES: "prunes", EXPORT: "export", IMPORT: "import",
UPLOAD: "upload",
SEARCH: "search", ENGINE: "engine", RENDER: "render", PLUGIN: "plugin", SEARCH: "search", ENGINE: "engine", RENDER: "render", PLUGIN: "plugin",
NEXT: "next", PREV: "prev", PAGE: "page", MAIN: "main", NEXT: "next", PREV: "prev", PAGE: "page", MAIN: "main",
@ -220,6 +221,7 @@ var html = {
CLASS: "class", FLOAT: "float", CLEAR: "clear", BOTH: "both", CLASS: "class", FLOAT: "float", CLEAR: "clear", BOTH: "both",
BACKGROUND: "background", SELECT: "select", HIDDEN: "hidden", BACKGROUND: "background", SELECT: "select", HIDDEN: "hidden",
DISPLAY: "display", BLOCK: "block", NONE: "none", FIXED: "fixed", DISPLAY: "display", BLOCK: "block", NONE: "none", FIXED: "fixed",
OPACITY: "opacity",
STROKE_WIDTH: "stroke-width", STROKE: "stroke", FILL: "fill", FONT_SIZE: "font-size", MONOSPACE: "monospace", STROKE_WIDTH: "stroke-width", STROKE: "stroke", FILL: "fill", FONT_SIZE: "font-size", MONOSPACE: "monospace",
SCROLL: "scroll", HEIGHT: "height", WIDTH: "width", LEFT: "left", TOP: "top", RIGHT: "right", BOTTOM: "bottom", SCROLL: "scroll", HEIGHT: "height", WIDTH: "width", LEFT: "left", TOP: "top", RIGHT: "right", BOTTOM: "bottom",
MAX_HEIGHT: "max-height", MAX_WIDTH: "max-width", MARGIN_X: "margin-x", MARGIN_Y: "margin-y", MAX_HEIGHT: "max-height", MAX_WIDTH: "max-width", MARGIN_X: "margin-x", MARGIN_Y: "margin-y",