mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 16:58:06 +08:00
add can.dir
This commit is contained in:
parent
ff638822af
commit
25cdf367d7
1
frame.js
1
frame.js
@ -174,6 +174,7 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) {
|
||||
_target: can.onappend.input(can, item, args[index]||opts[item.name], option||can._option), _option: option||can._option, _action: can._action, _output: can._output, _status: can._status,
|
||||
CloneField: can.Clone, CloneInput: function() { can.onmotion.focus(can, add(item)._target) }, Input: can.Input, Option: can.Option, Action: can.Action, Status: can.Status,
|
||||
}, [item.display, chat.PLUGIN_INPUT_JS], function(sub) { sub.Conf(item)
|
||||
sub._fields = can
|
||||
if (item.type == html.TEXT) { can.page.Append(can, sub._target.parentNode, [{text: [sub._target.value, html.SPAN, mdb.VALUE]}]) }
|
||||
if (item.type == html.BUTTON && can.base.isIn(item.name, mdb.CREATE, mdb.INSERT, mdb.PRUNES, mdb.PRUNE)) {
|
||||
can.onappend.icons(can, sub._target, item.name, function(event) {
|
||||
|
10
lib/page.js
10
lib/page.js
@ -197,18 +197,22 @@ Volcanos("page", {
|
||||
} }); return table },
|
||||
RangeTable: function(can, table, index, asc) { index = can.base.isArray(index)? can.core.List(index, function(item) { if (item > -1) { return item } }): [index]; if (index.length == 0) { return }
|
||||
var list = can.page.Select(can, table, html.TR, function(tr) { if (can.page.isDisplay(tr)) { return tr } }).slice(1)
|
||||
var is_time = true, is_number = true; can.core.List(list, function(tr) {
|
||||
var text = tr.childNodes[index[0]].innerHTML;
|
||||
var is_time = true, is_number = true; can.core.List(list, function(tr) { var text = tr.childNodes[index[0]].innerHTML;
|
||||
is_time = is_time && Date.parse(text) > 0, is_number = is_number && !isNaN(parseFloat(text||"0"))
|
||||
})
|
||||
var num_list = can.core.List(list, function(tr) { var text = tr.childNodes[index[0]].innerHTML; return is_time? Date.parse(text): is_number? can.base.ParseSize(text)||0: text })
|
||||
function less(a, b) {
|
||||
if (can.base.endWith(a, nfs.PS) && !can.base.endWith(b, nfs.PS)) { return true }
|
||||
if (!can.base.endWith(a, nfs.PS) && can.base.endWith(b, nfs.PS)) { return false }
|
||||
return a < b
|
||||
}
|
||||
function isless(a, b, index) { if (a.childNodes[index[0]] && b.childNodes[index[0]]) {
|
||||
if (a.childNodes[index[0]].innerHTML < b.childNodes[index[0]].innerHTML) { return true }
|
||||
if (a.childNodes[index[0]].innerHTML > b.childNodes[index[0]].innerHTML) { return false }
|
||||
} return index.length > 1 && isless(a, b, index.slice(1)) }
|
||||
for (var i = 0; i < num_list.length; i++) { var min = i
|
||||
for (var j = i+1; j < num_list.length; j++) {
|
||||
if (asc? num_list[min] < num_list[j]: num_list[j] < num_list[min]) { min = j; continue }
|
||||
if (asc? less(num_list[min], num_list[j]): less(num_list[j], num_list[min])) { min = j; continue }
|
||||
if (num_list[min] == num_list[j] && index.length > 1) { if (asc? isless(list[min], list[j], index.slice(1)): isless(list[j], list[min], index.slice(1))) { min = j } }
|
||||
}
|
||||
if (min != i) {
|
||||
|
@ -164,36 +164,33 @@ Volcanos(chat.ONPLUGIN, {
|
||||
boot: can.db._boot,
|
||||
})).Display("/plugin/story/json.js")
|
||||
}),
|
||||
dir: shy("网页目录", [nfs.PATH, ice.LIST, ice.BACK], async function(can, msg, arg, cb) {
|
||||
async function list(key, root) {
|
||||
msg._can._handle[key] = root
|
||||
for await (const [name, handle] of root) {
|
||||
if (can.base.beginWith(name, nfs.PT)) { continue }
|
||||
if (handle.kind === 'file') {
|
||||
msg.Push(nfs.PATH, key+name)
|
||||
dir: shy("网页目录", [nfs.PATH, ice.LIST, ice.BACK], async function(can, msg, arg, cb) { var can = msg._can._fields? msg._can.sup: msg._can
|
||||
async function list(key, root) { can._handle[key] = root
|
||||
for await (const [name, handle] of root) { if (can.base.beginWith(name, nfs.PT)) { continue }
|
||||
if (handle.kind == nfs.FILE) { var _file = await handle.getFile()
|
||||
msg.Push(mdb.TIME, can.base.Time(new Date(_file.lastModified))), msg.Push(nfs.PATH, key+name), msg.Push(nfs.SIZE, can.base.Size(_file.size))
|
||||
} else {
|
||||
msg.Push(nfs.PATH, key+name+nfs.PS)
|
||||
msg.Push(mdb.TIME, can.base.Time()), msg.Push(nfs.PATH, key+name+nfs.PS), msg.Push(nfs.SIZE, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
msg._can._handle = msg._can._handle||{}
|
||||
var raw = arg[0]||""
|
||||
arg[0] = can.base.trimSuffix(raw, nfs.PS)
|
||||
var key = arg[0].indexOf(nfs.PS) > -1? arg[0].slice(0, arg[0].lastIndexOf(nfs.PS)): ""
|
||||
var handle = msg._can._handle[key]
|
||||
|
||||
if (raw == "") { if (!msg._event.isTrusted) { return }
|
||||
await list("", handle || await window.showDirectoryPicker())
|
||||
cb(msg)
|
||||
} can.onmotion.delay(can, function() { can.page.Select(can, can._output, "tr>th")[1].click(), can.page.Select(can, msg._can._output, "tr>th")[1].click() }, 50)
|
||||
} can._handle = can._handle||{}; if (arg[0] == ctx.ACTION && arg[1] == ice.LIST) { arg = [] }
|
||||
if (arg.length == 0) { if (!msg._event.isTrusted) { return msg.Echo(can.page.Format(html.INPUT, "", mdb.TYPE, html.BUTTON, mdb.NAME, ice.LIST, mdb.VALUE, "list")), cb(msg) }
|
||||
await list("", can._handle[""] || await window.showDirectoryPicker()), cb(msg)
|
||||
} else {
|
||||
if (can.base.endWith(raw, nfs.PS)) {
|
||||
await list(key, await handle.getDirectoryHandle(arg[0]))
|
||||
cb(msg)
|
||||
if (can.base.endWith(arg[0], nfs.PS)) { var path = can.base.trimSuffix(arg[0], nfs.PS)
|
||||
if (path.indexOf(nfs.PS) == -1) {
|
||||
var file = path, path = ""
|
||||
} else {
|
||||
var file = path.slice(path.lastIndexOf(nfs.PS)+1), path = path.slice(0, path.lastIndexOf(nfs.PS)+1)
|
||||
} var handle = can._handle[path]
|
||||
await list(arg[0], await handle.getDirectoryHandle(file)), cb(msg)
|
||||
} else {
|
||||
const file = await handle.getFileHandle(arg[0])
|
||||
const reader = new FileReader()
|
||||
reader.onload = () => { msg.Echo(reader.result), cb(msg) }
|
||||
reader.readAsText(await file.getFile())
|
||||
if (arg[0].indexOf(nfs.PS) == -1) {
|
||||
var file = arg[0], path = ""
|
||||
} else { var path = can.base.trimSuffix(arg[0], nfs.PS)
|
||||
var file = path.slice(path.lastIndexOf(nfs.PS)+1), path = path.slice(0, path.lastIndexOf(nfs.PS)+1)
|
||||
} var handle = can._handle[path], _file = await handle.getFileHandle(file)
|
||||
var reader = new FileReader(); reader.onload = () => { msg.Echo(reader.result), cb(msg) }, reader.readAsText(await _file.getFile())
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
Loading…
x
Reference in New Issue
Block a user