1
0
mirror of https://shylinux.com/x/volcanos synced 2025-04-26 01:04:06 +08:00
This commit is contained in:
shaoying 2021-02-01 21:42:50 +08:00
parent d5ad6a18a9
commit eb4a37c708
9 changed files with 215 additions and 546 deletions

View File

@ -380,6 +380,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta,
input: function(can, item, value, target) { input: function(can, item, value, target) {
switch (item.type) { switch (item.type) {
case "space": return can.page.Append(can, target, [{view: "item space"}]) case "space": return can.page.Append(can, target, [{view: "item space"}])
case "": return can.page.Append(can, target, [item])
} }
var input = {type: "input", name: item.name, data: item, dataset: {}} var input = {type: "input", name: item.name, data: item, dataset: {}}
@ -416,8 +417,12 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta,
return can.page.Append(can, target, [{view: ["item "+item.type], list: [input]}])[item.name] return can.page.Append(can, target, [{view: ["item "+item.type], list: [input]}])[item.name]
}, },
table: function(can, msg, cb, target, list) { table: function(can, msg, cb, target, list) {
var table = can.page.AppendTable(can, msg, target||can._output, msg.append, cb||function(value) { var table = can.page.AppendTable(can, msg, target||can._output, msg.append, cb||function(value, key) {
return {text: [value, "td"]} return {text: [value, "td"], onclick: function(event) {
can.sup.onaction.change(event, can.sup, key, value, function(msg) {
can.onimport._init(can, msg, list, cb, can._output)
})
}}
}); table && can.page.Modify(can, table, {className: "content"}) }); table && can.page.Modify(can, table, {className: "content"})
list && can.page.RangeTable(can, table, list) list && can.page.RangeTable(can, table, list)
return table return table
@ -455,7 +460,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta,
meta.name = meta.name||value.name||"story" meta.name = meta.name||value.name||"story"
meta.help = meta.help||value.help||"story" meta.help = meta.help||value.help||"story"
meta.width = meta.width||can.Conf("width") meta.width = meta.width||can.Conf("width")
meta.height = meta.width||can.Conf("height") meta.height = meta.height||can.Conf("height")
meta.type = meta.type||"story" meta.type = meta.type||"story"
can.onappend._init(can, meta, ["/plugin/state.js"], function(sub) { can.onappend._init(can, meta, ["/plugin/state.js"], function(sub) {

View File

@ -50,7 +50,7 @@ Volcanos("core", {help: "核心模块",
function next(list, cb, index) { function next(list, cb, index) {
list && list.length > 0? typeof cb == "function" && cb(list[0], function() { list && list.length > 0? typeof cb == "function" && cb(list[0], function() {
list.length > 0 && next(list.slice(1), cb, index+1) list.length > 0 && next(list.slice(1), cb, index+1)
}, index): typeof cbs == "function" && cbs() }, index, obj): typeof cbs == "function" && cbs()
} }
next(obj, cb, 0) next(obj, cb, 0)
}), }),

View File

@ -322,7 +322,7 @@ div.toast {
position:fixed; position:fixed;
overflow:auto; overflow:auto;
padding:5px; padding:5px;
z-index:20; z-index:100;
} }
div.toast div.title { div.toast div.title {
font-size:14px; font-size:14px;

View File

@ -8,14 +8,16 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg)
can.onappend.plugin(can, item, function(sub, meta) { can.onappend.plugin(can, item, function(sub, meta) {
can.onimport._plugin(can, river, storm, sub, meta), next() can.onimport._plugin(can, river, storm, sub, meta), next()
sub._option.dataset.id = item.id
}) })
}) })
}, },
_plugin: function(can, river, storm, sub, item) { _plugin: function(can, river, storm, sub, item) {
sub.run = function(event, cmds, cb) { var msg = sub.request(event) sub.run = function(event, cmds, cb) { var msg = sub.request(event)
var toast = msg.Option("_toast") && can.user.toast(can, msg.Option("_toast"), "", 1000000) var toast = msg.Option("_toast") && can.user.toast(can, msg.Option("_toast"), "", 1000000)
return can.run(event, (can.onengine[cmds[0]]? []: [river, storm, item.id||item.index||item.key+"."+item.name]).concat(cmds), function(msg) { return can.run(event, (can.onengine[cmds[0]]? []: [river, storm, item.id||item.index||item.key+"."+item.name]).concat(cmds), function(msg) {
console.log(sub)
console.log(item)
toast && toast.Close(), typeof cb == "function" && cb(msg) toast && toast.Close(), typeof cb == "function" && cb(msg)
}) })
}, can._plugins = (can._plugins||[]).concat([sub]) }, can._plugins = (can._plugins||[]).concat([sub])
@ -129,9 +131,9 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg,
}) })
Volcanos("onexport", {help: "导出数据", list: [], Volcanos("onexport", {help: "导出数据", list: [],
args: function(can, msg, list, cb, target) { args: function(can, msg, list, cb, target) {
can.core.Next(can.page.Select(can, target, "fieldset.plugin>form.option"), function(item, next) { can.core.Next(can.page.Select(can, target, "fieldset.plugin>form.option"), function(item, next, index, array) {
var list = can.page.Select(can, item, '.args', function(item) { return item.value||"" }) var list = can.page.Select(can, item, '.args', function(item) { return item.value||"" })
item.dataset.args = JSON.stringify(list), cb(item, next) item.dataset.args = JSON.stringify(list), cb(item, next, index, array)
}) })
}, },
plugin: function(can, msg, word) { plugin: function(can, msg, word) {

View File

@ -172,9 +172,10 @@ Volcanos("ondetail", {help: "菜单交互", list: ["共享群组", "添加用户
}) })
}, },
"保存参数": function(event, can, button, river, storm) { "保存参数": function(event, can, button, river, storm) {
can.run(event, ["search", "Action.onexport.args"], function(item, next) { can.run(event, ["search", "Action.onexport.args"], function(item, next, index, array) {
var msg = can.request({}, {hash: storm, id: item.dataset.id}) var msg = can.request({}, {hash: storm, id: item.dataset.id})
can.run(msg._event, [river, "tool", "action", "modify", "arg", item.dataset.args], function(msg) { can.run(msg._event, [river, "tool", "action", "modify", "arg", item.dataset.args], function(msg) {
can.user.toast(can, "保存"+(index+1)+"/"+array.length)
next() next()
}) })
}) })

View File

@ -4,6 +4,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg,
typeof cb == "function" && cb(msg) typeof cb == "function" && cb(msg)
can.onmotion.hidden(can, can._action) can.onmotion.hidden(can, can._action)
can.onimport[can.Option("scale")||"week"](can, msg) can.onimport[can.Option("scale")||"week"](can, msg)
can.page.Modify(can, can.ui.profile, {style: {display: "block"}})
}, },
_content: function(can, msg, head, list, key, get, set) { _content: function(can, msg, head, list, key, get, set) {
var hash = {}; msg.Table(function(value, index) { var hash = {}; msg.Table(function(value, index) {

View File

@ -1,83 +1,55 @@
Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { can._output.innerHTML = "" Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) {
can.ui = can.onlayout.project(can) can.onmotion.clear(can)
can.ui = can.onlayout.profile(can)
typeof cb == "function" && cb(msg)
can.onmotion.hidden(can, can._action) can.onmotion.hidden(can, can._action)
// 交互数据 // 交互数据
can.point = [], can.keys = []
can.svg = null, can.group = null can.svg = null, can.group = null
can.last = null, can.temp = null can.last = null, can.temp = null
can.current = null can.point = [], can.current = null
// 加载绘图 // 加载绘图
can.page.Modify(can, can.ui.content, msg.Result()||can.onexport.content(can)) can.page.Modify(can, can.ui.content, msg.Result()||can.onexport.content(can))
can.page.Select(can, can.ui.content, "svg", function(svg) { can.svg = can.group = svg can.page.Select(can, can.ui.content, "svg", function(svg) {
can.onimport.block(can, svg), can.onimport.group(can, svg).click()
can.page.Select(can, svg, "*", function(item, index) { can.page.Select(can, svg, "*", function(item, index) {
can.onimport.block(can, item); if (item.tagName == "g" && item.Value("class") != "") { item.tagName == "g"? can.onimport._group(can, item): can.onimport._block(can, item)
can.onimport.group(can, item)
}
}) })
can.core.Item(can.onimport, function(key, value) {
key.indexOf("on") == 0 && (svg[key] = function(event) { value(event, can) })
})
can.svg = can.group = svg, can.onimport._group(can, svg).click()
}) })
// 加载事件
can.core.Item(can.onaction, function(key, value) {
if (key.indexOf("on") == -1 || !can.onaction.hasOwnProperty(key)) { return }
can.svg[key] = can.ui.content[key] || function(event) {
value(event, can)
}
})
can.core.Timer(10, function() {
// 默认参数 // 默认参数
can.core.Item({ can.core.Timer(10, function() { can.core.Item({
"font-size": "24", "stroke-width": 2, "stroke": "yellow", "fill": "purple", "font-size": "24",
"stroke-width": 2, "shape": "rect", "grid": "10", "go": "run",
"stroke": "yellow", }, function(key, value) { can.svg.Value(key, can.Action(key, can.svg.Value(key)||value)) }) })
"fill": "purple",
"shape": "rect",
"grid": "10",
"go": "run",
}, function(key, value) {
can.svg.Value(key, can.Action(key, can.svg.Value(key)||value))
})
})
return typeof cb == "function" && cb(msg)
}, },
group: function(can, target) { var name = target.Groups() || "svg" _group: function(can, target) { can.onimport._block(can, target)
return can.onappend.item(can, "item", {name: name}, function(event) { function show(event) { can.group = target, can.ondetail["显示"](event, can)
can.group = target, can.core.List(["font-size", "storke-width", "stroke", "fill"], function(key) { can.core.List(["stroke-width", "stroke", "fill", "font-size"], function(key) {
can.Action(key, target.Value(key)||can.Action(key)) can.Action(key, target.Value(key)||can.Action(key))
}), can.onmotion.show(can, 10, null, target)
}, function(event) {
can.user.carte(event, can, can.onaction||{}, ["隐藏", "显示", "添加", "删除", "清空"], function(ev, item, meta) {
switch (item) {
case "显示":
can.page.Select(can, can.ui.content, "g."+name, function(item) {
can.onmotion.show(can, 10, null, target)
}); break
case "隐藏":
can.page.Select(can, can.ui.content, "g."+name, function(item) {
can.onmotion.hide(can, {value: 100, length: 10}, null, target)
}); break
default:
can.onaction[item](event, can, item)
}
}) })
}
return can.onappend.item(can, "item", {name: target.Groups()}, show, function(event) { show(event)
can.user.carte(event, can, can.ondetail, ["隐藏", "显示", "添加", "删除", "清空"])
}, can.ui.project) }, can.ui.project)
}, },
block: function(can, target) { _block: function(can, target) {
target.Val = function(key, value) { target.Val = function(key, value) {
return parseInt(target.Value(key, value == undefined? value: parseInt(value)||0)) || 0 return parseInt(target.Value(key, value == undefined? value: parseInt(value)||0)) || 0
} }
target.Value = function(key, value) { target.Value = function(key, value) { if (typeof key == undefined) { return }
if (typeof key == "object") { can.core.Item(key, target.Value); return } if (typeof key == "object") { can.core.Item(key, target.Value); return }
var figure = can.onfigure._get(can, target) var figure = can.onfigure._get(can, target)
key && (key = figure && figure.data && figure.data.size && figure.data.size[key] || key) key = figure && figure.data && figure.data.size && figure.data.size[key] || key
if (figure && figure.data && typeof figure.data[key] == "function") { if (figure && figure.data && typeof figure.data[key] == "function") {
return figure.data[key](event, can, value, key, target) return figure.data[key](can, value, key, target)
} }
if (key == "inner") { if (key == "inner") {
return value != undefined && (target.innerHTML = value), target.innerHTML return value != undefined && (target.innerHTML = value), target.innerHTML
} }
@ -89,124 +61,69 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg,
|| target[key]&&target[key].baseVal || "" || target[key]&&target[key].baseVal || ""
} }
target.Group = function() { var item = target target.Group = function() { var item = target
while (item) { if (["svg", "g"].indexOf(item.tagName) > -1) { while (item) { if (["svg", "g"].indexOf(item.tagName) > -1) { return item }; item = item.parentNode }
return item
}; item = item.parentNode }
return can.svg return can.svg
} }
target.Groups = function() { var item = target target.Groups = function() { var item = target
var list = [] var list = []; while (item && item.tagName != "svg") {
while (item && item.tagName != "svg") { item.tagName == "g" && item.Value("class") && list.push(item.Value("class"))
item.tagName == "g" && list.push(item.Value("class"))
item = item.parentNode item = item.parentNode
} }
return list.reverse().join(".") return list.reverse().join(".")
} }
target.ondblclick = function(event) {
if (can.Action("go") == "run") { return }
can.ondetail["标签"](event, can)
event.stopPropagation()
event.preventDefault()
}
return target return target
}, },
_point: function(event, can) {
var p = can.svg.getBoundingClientRect()
var point = {x: event.clientX-p.x, y: event.clientY-p.y}
point.x = point.x - point.x % parseInt(can.Action("grid"))
point.y = point.y - point.y % parseInt(can.Action("grid"))
return can.Status("坐标", point.x+","+point.y), point
},
_figure: function(event, can, points, target) {
can.temp && can.page.Remove(can, can.temp) && delete(can.temp)
can.temp = can.onaction._mode[can.Action("mode")](event, can, points, target)
can.point.length == 0 && delete(can.temp)
},
draw: function(event, can, value) { draw: function(event, can, value) {
var figure = can.onfigure[value.shape] var figure = can.onfigure[value.shape]
var data = figure.draw(event, can, value.point, value.style) var data = figure.draw(event, can, value.point, value.style)
can.core.Item(value.style, function(key, value) { data[key] = value }) can.core.Item(value.style, function(key, value) { data[key] = value })
return can.onfigure._push(can, data, value.shape, can.group||can.svg) return can.onfigure._push(can, data, value.shape, can.group||can.svg)
}, },
keydown: function(event, can, value) {
if (["Control", "Shift", "Meta", "Alt"].indexOf(value) > -1 ) {return}
can.keys.push((event.ctrlKey? "C-": "") + (event.shiftKey? value.toUpperCase(): value))
if (value == "Escape") {
can.point = [], delete(can.temp)
return
}
var list = { ondblclick: function(event, can) {
g: {prefix: ["go", "go"], if (can.Action("go") == "run") { return }
r: {list: ["run"]}, can.ondetail["标签"](event, can)
a: {list: ["auto"]},
m: {list: ["manual"]},
}, },
a: {prefix: ["mode", "mode"], onclick: function(event, can) { var point = can.onimport._point(event, can)
d: {list: ["draw"]}, if (can.Action("go") == "run") { return can.onaction._mode.run(event, can) }
r: {list: ["resize"]}, can.onimport._figure(event, can, can.point = can.point.concat(point), event.target)
}, },
s: {prefix: ["shape", "shape"], onmousemove: function(event, can) { var point = can.onimport._point(event, can)
s: {list: ["line"]}, if (can.Action("go") == "run") { return can.page.Modify(can, event.target, {style: {cursor: ""}}) }
r: {list: ["rect"]}, if (can.Action("go") == "auto") { can.onaction._auto(can, event.target) }
c: {list: ["circle"]}, can.onimport._figure(event, can, can.point.concat(point))
e: {list: ["ellipse"]},
l: {list: ["line"]},
p: {list: ["path"]},
},
c: {prefix: ["stroke", "stroke"],
r: {list: ["red"]},
b: {list: ["blue"]},
g: {list: ["green"]},
y: {list: ["yellow"]},
p: {list: ["purple"]},
c: {list: ["cyan"]},
h: {list: ["black"]},
w: {list: ["white"]},
},
f: {prefix: ["fill", "fill"],
r: {list: ["red"]},
b: {list: ["blue"]},
g: {list: ["green"]},
y: {list: ["yellow"]},
p: {list: ["purple"]},
c: {list: ["cyan"]},
h: {list: ["black"]},
w: {list: ["white"]},
},
}
var prefix = []
can.core.List(can.keys, function(key) {
if (!list) {
// 查找失败
return can.keys = [], can.Status("按键", can.keys)
}
// 查找递进
prefix = prefix.concat(can.core.List(list.prefix))
list = list[key]
})
if (!list || !list.list) {
// 等待输入
return can.Status("按键", can.keys+"("+can.core.Item(list).join(",")+")")
}
function call(cmds) {
cmds && can.onaction[cmds[0]] && can.onaction[cmds[0]].apply(can, [event, can].concat(cmds.slice(1)))
}
// 执行命令
call(prefix.concat(list.list))
return can.keys = [], can.Status("按键", can.keys)
}, },
onmouseover: function(event, can) { can.onexport._show(can, event.target) },
oncontextmenu: function(event, can) { can.onexport._show(can, event.target) },
}, ["/plugin/local/wiki/draw.css"]) }, ["/plugin/local/wiki/draw.css"])
Volcanos("onfigure", {help: "图形绘制", list: [], Volcanos("onfigure", {help: "图形绘制", list: [],
_get: function(can, item, name) { _get: function(can, item, name) {
return can.onfigure[name]||can.onfigure[item.getAttribute("name")]||can.onfigure[item.tagName] return can.onfigure[name]||can.onfigure[item.getAttribute("name")]||can.onfigure[item.tagName]
}, },
_ship: function(can, target, value) {
return target.Value("ship", target.Value("ship").concat([value]))
},
_push: function(can, data, cmd, target) { _push: function(can, data, cmd, target) {
var rect = document.createElementNS("http://www.w3.org/2000/svg", cmd) var rect = document.createElementNS("http://www.w3.org/2000/svg", cmd)
target.appendChild(can.onimport.block(can, rect)) target.appendChild(can.onimport._block(can, rect))
rect.Value(data); if (can.point.length == 0) { rect.Value(data); if (can.point.length == 0) {
var pid = "p"+can.svg.Val("count", can.svg.Val("count")+1) var pid = "p"+can.svg.Val("count", can.svg.Val("count")+1)
rect.Value("class", (rect.Value("class") + " " + rect.Value("pid", pid)).trim()) rect.Value("class", (rect.Value("class") + " " + rect.Value("pid", pid)).trim())
} }
return can.last = rect return can.last = rect
}, },
_ship: function(can, target, value) {
return target.Value("ship", target.Value("ship").concat([value]))
},
_copy: function(event, can, target) { _copy: function(event, can, target) {
var figure = can.onfigure._get(can, target).data var figure = can.onfigure._get(can, target).data
@ -222,30 +139,29 @@ Volcanos("onfigure", {help: "图形绘制", list: [],
return p return p
}, },
svg: { svg: { // <svg width="600" height="200" count="0" grid="10" stroke-width="2" stroke="yellow" fill="purple" font-size="24"/>
data: { data: {size: {}, copy: []},
size: {}, show: function(can, target) { return target.Val("width") +","+ target.Val("height") },
}, // <svg font-size="24" stroke-width="2" stroke="yellow" fill="purple" grid="10"/>
show: function(can, target) {
return target.Val("width") +","+ target.Val("height")
}, },
text: { // <text x="60" y="10">hi<text>
data: {size: {x: "x", y: "y"}, copy: ["inner"]},
draw: function(event, can, point, style) { if (point.length < 1 || event.type == "mousemove") { return }
var p0 = point[0]; var data = {"x": p0.x, "y": p0.y, "inner": style&&style.inner || can.user.prompt("text")}
return can.point = [], data
}, },
rect: { show: function(can, target) { return ": (" + target.Val("x") + "," + target.Val("y")+ ")" }
data: { size: {x: "x", y: "y"}, rx: 4, ry: 4, },
copy: ["width", "height", "rx", "ry"], rect: { // <rect rx="10" ry="10" x="60" y="10" width="30" height="30"/>
}, // <rect x="60" y="10" rx="10" ry="10" width="30" height="30" rx="4" ry="4"/> data: {rx: 4, ry: 4, size: {x: "x", y: "y"}, copy: ["width", "height", "rx", "ry"]},
draw: function(event, can, point) { if (point.length < 2) { return } draw: function(event, can, point) { if (point.length < 2) { return }
var p0 = point[0], p1 = point[1]; var data = { var p0 = point[0], p1 = point[1]; var data = {
"x": p0.x > p1.x? p1.x: p0.x, "rx": this.data.rx, "ry": this.data.ry,
"y": p0.y > p1.y? p1.y: p0.y, "x": p0.x > p1.x? p1.x: p0.x, "y": p0.y > p1.y? p1.y: p0.y,
"width": Math.abs(p0.x-p1.x), "width": Math.abs(p0.x-p1.x), "height": Math.abs(p0.y-p1.y),
"height": Math.abs(p0.y-p1.y),
"rx": this.data.rx,
"ry": this.data.ry,
} }
return event.type == "click" && point.length == 2 && (can.point = []), data return event.type == "click" && point.length == 2 && (can.point = []), data
}, },
text: function(can, target, data) { text: function(can, data, target) {
data.x = target.Val("x")+target.Val("width")/2 data.x = target.Val("x")+target.Val("width")/2
data.y = target.Val("y")+target.Val("height")/2 data.y = target.Val("y")+target.Val("height")/2
return data return data
@ -255,59 +171,41 @@ Volcanos("onfigure", {help: "图形绘制", list: [],
+ " + (" + target.Val("width") + "," + target.Val("height") + ")" + " + (" + target.Val("width") + "," + target.Val("height") + ")"
}, },
}, },
text: { line: { // <line x1="10" y1="50" x2="110" y2="150" xx="100" yy="100"/>
data: { size: {x: "x", y: "y"}, copy: ["inner"],
}, // <text x="60" y="10">hi<text>
draw: function(event, can, point, style) { if (point.length < 1 || event.type == "mousemove") { return }
var p0 = point[0]; var data = {
"x": p0.x, "y": p0.y,
"inner": style&&style.inner || can.user.prompt("text"),
}
return can.point = [], data
},
show: function(can, target) {
return ": (" + target.Val("x") + "," + target.Val("y")+ ")"
}
},
line: {
data: {size: {}, copy: ["x1", "y1", "x2", "y2"], data: {size: {}, copy: ["x1", "y1", "x2", "y2"],
x: function(event, can, value, cmd, target) { x: function(can, value, cmd, target) {
if (value != undefined) { if (value != undefined) {
var offset = value - target.Val("xx") var offset = value - target.Val("xx")
target.Val("x1", target.Val("x1") + offset) target.Val("x1", target.Val("x1") + offset)
// target.Val("x2", target.Val("x2") + offset) target.Val("x2", target.Val("x2") + offset)
target.Val("xx", value) target.Val("xx", value)
} }
return target.Val("xx") return target.Val("xx")
}, },
y: function(event, can, value, cmd, target) { y: function(can, value, cmd, target) {
if (value != undefined) { if (value != undefined) {
var offset = value - target.Val("yy") var offset = value - target.Val("yy")
target.Val("y1", target.Val("y1") + offset) target.Val("y1", target.Val("y1") + offset)
// target.Val("y2", target.Val("y2") + offset) target.Val("y2", target.Val("y2") + offset)
target.Val("yy", value) target.Val("yy", value)
} }
return target.Val("yy") return target.Val("yy")
}, },
width: function(event, can, value, cmd, target) { width: function(can, value, cmd, target) {
return value != undefined && target.Val("x2", target.Val("x1") + parseInt(value)), target.Val("x2") - target.Val("x1") return value != undefined && target.Val("x2", target.Val("x1") + parseInt(value)), target.Val("x2") - target.Val("x1")
}, },
height: function(event, can, value, cmd, target) { height: function(can, value, cmd, target) {
return value != undefined && target.Val("y2", target.Val("y1") + parseInt(value)), target.Val("y2") - target.Val("y1") return value != undefined && target.Val("y2", target.Val("y1") + parseInt(value)), target.Val("y2") - target.Val("y1")
}, },
}, // <line x1="10" y1="50" x2="110" y2="150"/> },
grid: function(event, can, point) { var target = event.target grid: function(event, can, point) { var target = event.target
if (target == can.svg) { return } if (target == can.svg) { return }
var p = point[point.length-1] var p = point[point.length-1], pos = can.page.Prepos(event, target)
var pos = can.page.Prepos(event, target)
target.Val && can.page.Anchor(event, target, pos, p) target.Val && can.page.Anchor(event, target, pos, p)
return p.target = target, p.anchor = pos, point return p.target = target, p.anchor = pos, point
}, },
draw: function(event, can, point) { if (point.length < 2) { return } draw: function(event, can, point) { if (point.length < 2) { return }
var p0 = point[0], p1 = point[1]; var data = { var p0 = point[0], p1 = point[1]; var data = {"x1": p0.x, "y1": p0.y, "x2": p1.x, "y2": p1.y}
"x1": p0.x, "y1": p0.y,
"x2": p1.x, "y2": p1.y,
}
return event.type == "click" && point.length == 2 && (can.point = []), data return event.type == "click" && point.length == 2 && (can.point = []), data
}, },
text: function(can, target, data) { text: function(can, target, data) {
@ -320,216 +218,34 @@ Volcanos("onfigure", {help: "图形绘制", list: [],
+ " - (" + target.Val("x2") + "," + target.Val("y2") + ")" + " - (" + target.Val("x2") + "," + target.Val("y2") + ")"
}, },
}, },
path: { circle: { // <circle cx="25" cy="75" r="20"/>
data: { size: {}, copy: ["d", "name", "meta", "tt", "xx", "yy"], data: {size: {x: "cx", y: "cy", width: "r", height: "r"}, copy: ["r"]},
x: function(event, can, value, cmd, target) {
var tt = JSON.parse(target.Value("tt")||'{"tx":0, "ty":0}')
if (value != undefined) {
tt.tx = value-target.Val("xx")
target.Value("tt", JSON.stringify(tt))
target.Value("transform", "translate("+tt.tx+","+tt.ty+")")
}
return target.Val("xx")+tt.tx
},
y: function(event, can, value, cmd, target) {
var tt = JSON.parse(target.Value("tt")||'{"tx":0, "ty":0}')
if (value != undefined) {
tt.ty = value-target.Val("yy")
target.Value("tt", JSON.stringify(tt))
target.Value("transform", "translate("+tt.tx+","+tt.ty+")")
}
return target.Val("yy")+tt.ty
},
}, // <path d="M10 10 H 90 V 90 H 10 Z" fill="transparent" stroke="black"/>
draw: function(event, can, point, style) {
if (style && style.d) { return style }
if (point.length == 1) { can._temp = {} }
if (point.length < 2) {return}
if (can.keys && can.keys.length > 0) { var k;
k = can._temp[point.length-1] = can.keys[0]
switch (k.toUpperCase()) {
case "C": can._temp[point.length+1] = ","
case "Q": can._temp[point.length] = ","; break
default:
}
can.keys = can.keys.slice(1)
}
var skip = 0
var end = false
var data = {
d: can.core.List(point, function(p, i) { var k = p.k
if (i < skip) {return}
switch (i) {
case 0: k = "M"; break
default: k = can._temp[i] || p.k || "L"; break
}
if (end) {return}
k = k.toUpperCase()
switch (k) {
case "Z": return can.point = [], can._temp = {}, k
case "L": return k+" " + p.x + " " + p.y
case "M": return k+" " + p.x + " " + p.y
case "H": return k+" " + p.x
case "V": return k+" " + p.y
case "A":
switch (point.length - i) {
case 1: end = true
return k+" " + (point[i-1].x+p.x)/2 + " " + (point[i-1].y+p.y)/2 + " 0 0 0 " + p.x + " " + p.y
case 2: end = true
var r = Math.sqrt(Math.pow(point[i+1].x - p.x, 2) + Math.pow(point[i+1].y - p.y, 2))
return k+" " + r + " " + r + " 0 0 0 " + p.x + " " + p.y
case 3:
if (!p.done) {
var r = Math.sqrt(Math.pow(point[i+1].x - p.x, 2) + Math.pow(point[i+1].y - p.y, 2))
var temp = point[i]
p = point[i] = point[i+1]
point[i+1] = temp
var temp = can.point[i]
p = can.point[i] = can.point[i+1]
can.point[i+1] = temp
p.x = r
p.y = r
p.done = true
p.arg = " 0 0 0 "
}
default:
skip = i + 2
return k+" " + p.x + " " + p.y + " 0 0 0 " + point[i+1].x + " " + point[i+1].y
}
break
case "C":
switch (point.length - i) {
case 1: end = true
return k+" " + (point[i-1].x+p.x)/2 + " " + (point[i-1].y+p.y)/2 + "," + (point[i-1].x+p.x)/2 + " " + (point[i-1].y+p.y)/2 + "," + p.x + " " + p.y
case 2: end = true
return k+" " + point[i+1].x + " " + point[i+1].y + "," + (point[i-1].x+p.x)/2 + " " + (point[i-1].y+p.y)/2 + "," + p.x + " " + p.y
case 3:
return k+" " + point[i+1].x + " " + point[i+1].y + "," + point[i+2].x + " " + point[i+2].y + "," + p.x + " " + p.y
case 4:
if (!p.done) {
var temp = point[i]
p = point[i] = point[i+1]
point[i+1] = temp
var temp = point[i+1]
point[i+1] = point[i+2]
point[i+2] = temp
p.done = true
}
default:
return k+" " + p.x + " " + p.y
}
case "Q":
switch (point.length - i) {
case 1: end = true
return k+" " + (point[i-1].x+p.x)/2 + " " + (point[i-1].y+p.y)/2 + "," + p.x + " " + p.y
case 2: end = true
return k+" " + point[i+1].x + " " + point[i+1].y + "," + p.x + " " + p.y
case 3:
if (!p.done) {
var temp = point[i]
p = point[i] = point[i+1]
point[i+1] = temp
p.done = true
}
default:
return k+" " + p.x + " " + p.y
}
default: return k+" " + p.x + " " + p.y
}
}).join(" ")
}
return data
},
text: function(can, target, data) {
data.x = (target.x1.baseVal.value + target.x2.baseVal.value) / 2
data.y = (target.y1.baseVal.value + target.y2.baseVal.value) / 2
return data
},
show: function(can, target) {
return target.tagName + " " + target.Value("d")
},
},
circle: {
data: { size: {x: "cx", y: "cy", width: "r", height: "r"}, copy: ["r"],
}, // <circle cx="25" cy="75" r="20"/>
draw: function(event, can, point) { if (point.length < 2) { return } draw: function(event, can, point) { if (point.length < 2) { return }
var p0 = point[0], p1 = point[1]; var data = { var p0 = point[0], p1 = point[1]; var data = {"cx": p0.x, "cy": p0.y, "r": Math.sqrt(Math.pow(p0.x-p1.x, 2)+Math.pow(p0.y-p1.y, 2))}
"cx": p0.x, "cy": p0.y,
"r": Math.sqrt(Math.pow(p0.x-p1.x, 2)+Math.pow(p0.y-p1.y, 2)),
}
return event.type == "click" && point.length == 2 && (can.point = []), data return event.type == "click" && point.length == 2 && (can.point = []), data
}, },
text: function(can, target, data) { text: function(can, target, data) { return data.x = target.Val("cx"), data.y = target.Val("cy"), data },
data.x = target.Val("cx") show: function(can, target) { return ": (" + target.Val("cx") + "," + target.Val("cy") + ")" + " > (" + parseInt(target.Val("r")) + ")" },
data.y = target.Val("cy")
return data
}, },
show: function(can, target) { ellipse: { // <ellipse cx="75" cy="75" rx="20" ry="5"/>
return ": (" + target.Val("cx") + "," + target.Val("cy") + ")" data: {size: {x: "cx", y: "cy", width: "rx", height: "ry"}, copy: ["rx", "ry"]},
+ " > (" + parseInt(target.Val("r")) + ")"
},
},
ellipse: {
data: { size: {x: "cx", y: "cy", width: "rx", height: "ry"}, copy: ["rx", "ry"],
}, // <ellipse cx="75" cy="75" rx="20" ry="5"/>
draw: function(event, can, point) { if (point.length < 2) { return } draw: function(event, can, point) { if (point.length < 2) { return }
var p0 = point[0], p1 = point[1]; var data = { var p0 = point[0], p1 = point[1]; var data = {"cx": p0.x, "cy": p0.y, "rx": Math.abs(p0.x - p1.x), "ry": Math.abs(p0.y - p1.y)}
"cx": p0.x, "cy": p0.y,
"rx": Math.abs(p0.x - p1.x), "ry": Math.abs(p0.y - p1.y),
}
return event.type == "click" && point.length == 2 && (can.point = []), data return event.type == "click" && point.length == 2 && (can.point = []), data
}, },
text: function(can, target, data) { text: function(can, target, data) { return data.x = target.Val("cx"), data.y = target.Val("cy"), data },
data.x = target.Val("cx") show: function(can, target) { return ": (" + target.Val("cx") + "," + target.Val("cy") + ")" + " > (" + target.Val("rx") + "," + target.Val("ry") + ")" },
data.y = target.Val("cy")
return data
}, },
show: function(can, target) {
return ": (" + target.Val("cx") + "," + target.Val("cy") + ")" block: { // <rect rx="10" ry="10" x="60" y="10" width="30" height="30"/>
+ " > (" + target.Val("rx") + "," + target.Val("ry") + ")" data: {rx: 4, ry: 4, size: {x: "x", y: "y"}, copy: ["width", "height", "rx", "ry"]},
},
},
block: {
data: { size: {x: "x", y: "y"}, rx: 4, ry: 4, copy: ["width", "height", "rx", "ry"],
}, // <rect x="60" y="10" rx="10" ry="10" width="30" height="30" rx="4" ry="4"/>
draw: function(event, can, point) { if (point.length < 2) { return } draw: function(event, can, point) { if (point.length < 2) { return }
this._temp && can.page.Remove(can, this._temp) && delete(this._temp) this._temp && can.page.Remove(can, this._temp) && delete(this._temp)
this._temp = can.onfigure._push(can, {}, "g", can.group||can.svg) this._temp = can.onfigure._push(can, {}, "g", can.group||can.svg)
var temp = this._temp var rect = can.onfigure._push(can, can.onfigure.rect.draw(event, can, point), "rect", this._temp)
var rect = can.onfigure._push(can, can.onfigure.rect.draw(event, can, point), "rect", temp) if (event.type != "click" && point.length != 2) { return }
if (event.type == "click" && point.length == 2) { var point = can.onfigure.rect.text(can, rect, {})
can.require(["/plugin/input/key"])
can.run(event, ["action", "plugin"], function(msg) {
var ui = can.user.input(event, can, [
{name: "zone", select: [["zone"].concat(msg.append), function(event, value) {
can.page.Appends(can, ui.type, can.core.List(msg[value], function(item) {
return {type: "option", value: item, inner: item}
}))
}]},
{name: "type", select: [["type"].concat(msg[msg.append[0]]), function(event, value) {
}]},
{name: "name", type: "input", onclick: function(event) {
can.onfigure.key.onclick(event, can, {name: "name", zone: ui.zone.value, type: ui.type.value}, event.target)
}, autocomplete: "off"},
{name: "text", type: "input", onclick: function(event) {
can.onfigure.key.onclick(event, can, {name: "text", zone: ui.zone.value, type: ui.type.value}, event.target)
}, autocomplete: "off"},
], function(event, button, data, list) {
var text = can.onfigure._push(can, can.onfigure.text.draw(event, can, [point], {inner: data.name}), "text", temp)
rect.Value(data)
text.Value(data)
return true
})
}, true)
delete(this._temp) delete(this._temp)
}
}, },
text: function(can, target, data) { text: function(can, target, data) {
data.x = target.Val("x")+target.Val("width")/2 data.x = target.Val("x")+target.Val("width")/2
@ -543,58 +259,59 @@ Volcanos("onfigure", {help: "图形绘制", list: [],
}, },
}, []) }, [])
Volcanos("onaction", {help: "组件菜单", list: [ Volcanos("onaction", {help: "组件菜单", list: [
["grid", 1, 2, 3, 4, 5, 10, 20],
["stroke-width", 1, 2, 3, 4, 5], ["stroke-width", 1, 2, 3, 4, 5],
["stroke", "red", "yellow", "green", "purple", "blue", "cyan", "white", "black"],
["fill", "red", "yellow", "green", "purple", "blue", "cyan", "white", "black", "#0000"],
["font-size", 12, 16, 18, 24, 32], ["font-size", 12, 16, 18, 24, 32],
{text: [" c:", "div", "item"]}, ["stroke", "red", "yellow", "green", "purple", "blue", "cyan", "white", "black"],
{text: [" f:", "div", "item"]}, ["fill", "red", "yellow", "green", "purple", "blue", "cyan", "white", "black", "#0000"], ["shape", "text", "rect", "line", "circle", "ellipse", "block"],
{text: [" g:", "div", "item"]}, ["go", "run", "auto", "manual"], ["mode", "translate", "draw", "resize", "delete"],
{text: [" a:", "div", "item"]}, ["mode", "translate", "draw", "resize", "delete"], ["grid", 1, 2, 3, 4, 5, 10, 20],
{text: [" s:", "div", "item"]}, ["shape", "block", "rect", "text", "line", "path", "circle", "ellipse", "heart"], ["go", "run", "auto", "manual"],
], ],
"编辑": function(event, can, key) { can.Action("go", "auto") }, "编辑": function(event, can, key) { can.Action("go", "auto") },
"save": function(event, can, key) { "save": function(event, can, key) {
var msg = can.request(event); msg.Option("content", can.onexport.content(can, can.svg)) var msg = can.request(event, {content: can.onexport.content(can, can.svg)})
can.run(event, ["action", "save", can.Option("path"), can.Option("file")], function() { can.run(event, ["action", "save", can.Option("path"), can.Option("file")], function(msg) {
can.user.toast(can, "保存成功") can.user.toast(can, "保存成功")
}, true) }, true)
}, },
"项目": function(event, can, key) { "项目": function(event, can) { can.page.Toggle(can, can.ui.project) },
can.page.Modify(can, can.ui.project, {style: {display: can.ui.project.style.display=="none"? "block": "none"}})
},
"变参": function(event, can, key) {
can.page.Modify(can, can._action, {style: {display: can._action.style.display=="none"? "": "none"}})
},
"清空": function(event, can) {
can.group.innerHTML = "", can.point = [], can.keys = [], delete(can.temp)
},
"删除": function(event, can) { if (can.group == can.svg) { return }
can.page.Remove(can, event.target)
can.page.Remove(can, can.group), can.page.Select(can, can.action, "option[value="+can.group.Value("class")+"]", function(item) {
can.page.Remove(can, item)
})
can.Action("group", "svg")
},
"添加": function(event, can) {
can.user.prompt("add group", function(name) {
var group = document.createElementNS('http://www.w3.org/2000/svg', 'g')
can.group.append(can.onimport.block(can, group))
group.Value("class", name), can.core.List(["font-size", "stroke-width", "stroke", "fill"], function(name) {
group.Value(name, can.Action(name))
})
can.onimport.group(can, group).click()
})
},
"font-size": function(event, can, key, value) { can.Action(key, value), can.group.Value(key, value) }, "font-size": function(event, can, key, value) { can.Action(key, value), can.group.Value(key, value) },
"stroke-width": function(event, can, key, value) { can.Action(key, value), can.group.Value(key, value) }, "stroke-width": function(event, can, key, value) { can.Action(key, value), can.group.Value(key, value) },
stroke: function(event, can, key, value) { can.Action(key, value), can.group.Value(key, value) }, stroke: function(event, can, key, value) { can.Action(key, value), can.group.Value(key, value) },
fill: function(event, can, key, value) { can.Action(key, value), can.group.Value(key, value) }, fill: function(event, can, key, value) { can.Action(key, value), can.group.Value(key, value) },
shape: function(event, can, key, value) { can.Action(key, value) }, shape: function(event, can, key, value) { can.Action(key, value) },
mode: function(event, can, key, value) { can.Action(key, value) }, mode: function(event, can, key, value) { can.Action(key, value) },
go: function(event, can, key, value) { can.Action(key, value) }, go: function(event, can, key, value) { can.Action(key, value) },
_auto: function(can, target) {
if (can.point.length > 0) { return }
var pos = can.page.Prepos(event, event.target)
if (target.tagName == "text") {
} else if (target == can.svg) {
if (pos == 5) {
can.Action("mode", "draw")
can.Action("shape", "rect")
can.page.Modify(can, can.svg, {style: {cursor: "crosshair"}})
} else {
can.Action("mode", "resize")
}
} else {
switch (pos) {
case 5:
case 9:
can.Action("mode", "resize")
break
default:
can.Action("mode", "draw")
can.Action("shape", "line")
}
}
},
_mode: { _mode: {
run: function(event, can) { var target = event.target run: function(event, can) { var target = event.target
event.type == "click" && target.Value("type") && can.run(event, ["action", "run", target.Value("zone"), target.Value("type"), target.Value("name"), target.Value("text")], function(msg) { event.type == "click" && target.Value("type") && can.run(event, ["action", "run", target.Value("zone"), target.Value("type"), target.Value("name"), target.Value("text")], function(msg) {
@ -667,7 +384,7 @@ Volcanos("onaction", {help: "组件菜单", list: [
can.core.List(can.current.begin, function(item) { var figure = can.onfigure._get(can, item.target) can.core.List(can.current.begin, function(item) { var figure = can.onfigure._get(can, item.target)
can.page.Resizes(event, item.target, item, point[0], point[1], can.current.pos) can.page.Resizes(event, item.target, item, point[0], point[1], can.current.pos)
can.page.Select(can, can.svg, "."+item.target.Value("text"), function(text) { can.page.Select(can, can.svg, "."+item.target.Value("text"), function(text) {
text.Value(figure.text(can, item.target, {})) text.Value(figure.text(can, {}, item.target))
}) })
can.core.List(item.ship, function(ship) { can.core.List(item.ship, function(ship) {
var p = can.page.Anchor(event, item.target, ship.anchor, {}) var p = can.page.Anchor(event, item.target, ship.anchor, {})
@ -686,81 +403,33 @@ Volcanos("onaction", {help: "组件菜单", list: [
can.point = [], event.target != can.svg && can.page.Remove(can, event.target) can.point = [], event.target != can.svg && can.page.Remove(can, event.target)
}, },
}, },
_action: function(event, can, points, target) {
can.temp && can.page.Remove(can, can.temp) && delete(can.temp)
can.temp = can.onaction._mode[can.Action("mode")](event, can, points, target)
can.point.length == 0 && delete(can.temp)
},
_point: function(event, can) {
var p = can.svg.getBoundingClientRect()
var point = {x: event.clientX-p.x, y: event.clientY-p.y}
if (can.Action("mode") == "view") { return point }
point.x = point.x - point.x % parseInt(can.Action("grid"))
point.y = point.y - point.y % parseInt(can.Action("grid"))
return point
},
_show: function(can, target) { var figure = can.onfigure._get(can, target)
can.Status("分组", target.Groups() || can.group.Value("class") )
can.Status("图形", target.tagName + " " + (
figure? figure.show(can, target): ""))
},
_auto: function(can, target, pos) {
if (target.tagName == "text") {
} else if (target == can.svg) {
if (pos == 5) {
can.Action("mode", "draw")
can.Action("shape", "rect")
can.page.Modify(can, can.svg, {style: {cursor: "crosshair"}})
} else {
can.Action("mode", "resize")
}
} else {
switch (pos) {
case 5:
case 9:
can.Action("mode", "resize")
break
default:
can.Action("mode", "draw")
can.Action("shape", "line")
}
}
},
onclick: function(event, can) {
if (can.Action("go") == "run") {
can.onaction._mode.run(event, can)
return
}
var target = event.target
if (event.altKey) {
target = can.onfigure._copy(event, can, event.target)
can.Action("mode", "resize")
}
if (event.target == can._target) { return }
var point = can.onaction._point(event, can)
can.onaction._action(event, can, can.point = can.point.concat(point), target)
},
onmousemove: function(event, can) {
var point = can.onaction._point(event, can)
can.Status("坐标", point.x+","+point.y)
if (can.Action("go") == "run") { return can.page.Modify(can, event.target, {style: {cursor: ""}}) }
var pos = can.page.Prepos(event, event.target)
if (can.Action("go") == "auto" && can.point.length == 0) {
can.onaction._auto(can, event.target, pos)
}
can.onaction._action(event, can, can.point.concat(point))
},
onmouseover: function(event, can) {
can.onaction._show(can, event.target)
},
oncontextmenu: function(event, can) {
can.onaction._show(can, event.target)
},
}) })
Volcanos("ondetail", {help: "组件详情", list: ["复制", "标签", "编辑", "删除"], Volcanos("ondetail", {help: "组件详情", list: ["复制", "标签", "编辑", "删除"],
"显示": function(event, can) { can.onmotion.show(can, 10, null, event.target) },
"隐藏": function(event, can) { can.onmotion.show(can, {value:100, length: 10}, null, event.target) },
"添加": function(event, can) {
can.user.prompt("add group", function(name) {
var group = document.createElementNS('http://www.w3.org/2000/svg', 'g')
can.group.append(can.onimport._block(can, group))
group.Value("class", name), can.core.List(["font-size", "stroke-width", "stroke", "fill"], function(name) {
group.Value(name, can.Action(name))
})
can.onimport._group(can, group).click()
})
},
"清空": function(event, can) {
can.group.innerHTML = "", can.point = [], delete(can.temp)
},
"删除": function(event, can) { if (can.group == can.svg) { return }
can.page.Remove(can, event.target)
can.page.Remove(can, can.group), can.page.Select(can, can.action, "option[value="+can.group.Value("class")+"]", function(item) {
can.page.Remove(can, item)
})
can.Action("group", "svg")
},
"复制": function(event, can) { "复制": function(event, can) {
can.onfigure._copy(event, can, event.target) can.onfigure._copy(event, can, event.target)
}, },
@ -778,11 +447,12 @@ Volcanos("ondetail", {help: "组件详情", list: ["复制", "标签", "编辑",
} }
var figure = can.onfigure._get(can, target) var figure = can.onfigure._get(can, target)
var data = figure.text(can, target, {inner: text}) var data = figure.text(can, {inner: text}, target)
var obj = can.onfigure._push(can, data, "text", target.Group()) var obj = can.onfigure._push(can, data, "text", target.Group())
target.Value("text", obj.Value("pid")) target.Value("text", obj.Value("pid"))
}, def) }, def)
}, },
"编辑": function(event, can) { var target = event.target "编辑": function(event, can) { var target = event.target
var figure = can.onfigure._get(can, target) var figure = can.onfigure._get(can, target)
can.user.input(event, can, can.core.List(["x", "y", "transform", "translate_x", "translate_y"].concat(figure.data.copy||[]), function(item) { can.user.input(event, can, can.core.List(["x", "y", "transform", "translate_x", "translate_y"].concat(figure.data.copy||[]), function(item) {
@ -805,11 +475,16 @@ Volcanos("ondetail", {help: "组件详情", list: ["复制", "标签", "编辑",
can.page.Remove(can, event.target) can.page.Remove(can, event.target)
}, },
}) })
Volcanos("onexport", {help: "导出数据", list: ["坐标", "分组", "图形", "按键"], Volcanos("onexport", {help: "导出数据", list: ["分组", "图形", "坐标", "按键"],
_show: function(can, target) { var figure = can.onfigure._get(can, target)
can.Status("分组", target.Groups() || can.group.Value("class") )
can.Status("图形", target.tagName + " " + (figure? figure.show(can, target): ""))
},
content: function(can, svg) { content: function(can, svg) {
return ['<svg vertion="1.1" xmlns="https://www.w3.org/2000/svg" text-anchor="middle" dominant-baseline="middle"'].concat( return ['<svg vertion="1.1" xmlns="https://www.w3.org/2000/svg" text-anchor="middle" dominant-baseline="middle"'].concat(
svg? can.core.List([ svg? can.core.List(["width", "height", "count", "grid",
"count", "width", "height", "font-size", "stroke-width", "stroke", "fill", "stroke-width", "stroke", "fill", "font-size",
"transform", "translate_x", "translate_y", "transform", "translate_x", "translate_y",
], function(item) { ], function(item) {
return svg.Value(item)? ' ' + item + '="' + svg.Value(item) + '"': "" return svg.Value(item)? ' ' + item + '="' + svg.Value(item) + '"': ""

View File

@ -5,13 +5,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg,
}) })
can.ui = can.onlayout.display(can, target) can.ui = can.onlayout.display(can, target)
can.onappend.table(can, can.path, function(value, key) { can.onappend.table(can, can.path, null, can.ui.content)
return {type: "td", inner: value, onclick: function(event) {
can.sup.onaction.change(event, can.sup, key, value, function(msg) {
can.onimport._init(can, msg, list, cb, target)
})
}}
}, can.ui.content)
var feature = can.Conf("feature") || {} var feature = can.Conf("feature") || {}
can.onmotion.hidden(can, can._action) can.onmotion.hidden(can, can._action)
@ -22,21 +16,18 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg,
can.Action("数量", can.limit = parseInt(msg.Option("limit"))||feature["limit"]||6) can.Action("数量", can.limit = parseInt(msg.Option("limit"))||feature["limit"]||6)
can.Action("高度", can.height = parseInt(msg.Option("height"))||feature["height"]||100) can.Action("高度", can.height = parseInt(msg.Option("height"))||feature["height"]||100)
can.Option("path") != "最近/" && can.onimport._page(can, can.list, can.begin, can.limit) can.Option("path") != "最近/" && can.onimport._page(can, can.list, can.begin, can.limit)
}, },
_page: function(can, list, begin, limit) { can.onmotion.clear(can, can.ui.display) _page: function(can, list, begin, limit) { can.onmotion.clear(can, can.ui.content)
if (!list || list.length == 0) { return } if (!list || list.length == 0) { return }
for (var i = begin; i < begin+limit; i++) { list && list[i] && can.onimport.file(can, list[i].path, i) } for (var i = begin; i < begin+limit; i++) { list && list[i] && can.onimport.file(can, list[i].path, i) }
can.Status("begin", begin), can.Status("limit", limit), can.Status("total", can.list.length) can.Status("begin", begin), can.Status("limit", limit), can.Status("total", can.list.length)
}, },
_file: function(can, path, index) { _file: function(can, path, index) { var p = location.href.indexOf("http") == 0? "": "http://localhost:9020"
var p = location.href.indexOf("http") == 0? "": "http://localhost:9020" return path.indexOf("http") == 0? path: p+can.base.Path("/share/local", " "+(can._msg.Option("prefix")||""), path)
path = path.indexOf("http") == 0? path: p+can.base.Path("/share/local", " "+(can._msg.Option("prefix")||""), path)
return path
}, },
file: function(can, path, index) { path = can.onimport._file(can, path, index) file: function(can, path, index) { path = can.onimport._file(can, path, index)
var cb = can.onfigure[can.base.Ext(path)]; can.Status("file", path) var cb = can.onfigure[can.base.Ext(path)]; can.Status("file", path)
typeof cb == "function" && can.page.Append(can, can.ui.display, [cb(can, path, index)]) typeof cb == "function" && can.page.Append(can, can.ui.content, [cb(can, path, index)])
}, },
}, ["/plugin/local/wiki/feel.css"]) }, ["/plugin/local/wiki/feel.css"])
Volcanos("onfigure", {help: "组件菜单", list: [], Volcanos("onfigure", {help: "组件菜单", list: [],
@ -46,18 +37,14 @@ Volcanos("onfigure", {help: "组件菜单", list: [],
jpeg: function(can, path, index) { return can.onfigure.image(can, path, index) }, jpeg: function(can, path, index) { return can.onfigure.image(can, path, index) },
image: function(can, path, index) { return {img: path, height: can.height, onclick: function(event) { image: function(can, path, index) { return {img: path, height: can.height, onclick: function(event) {
can.onappend._init(can, {}, [], function(sub) { can.onappend._init(can, {}, [], function(sub) {
sub.run = function(event, cmds, cb) { sub.run = function(event, cmds, cb) { return can.run(event, cmds, cb, true) }
return can.run(event, cmds, cb, true)
}
var header = sub.run({}, ["search", "Header.onexport.height"]) var header = sub.run({}, ["search", "Header.onexport.height"])
var footer = sub.run({}, ["search", "Footer.onexport.height"]) var footer = sub.run({}, ["search", "Footer.onexport.height"])
var river = sub.run({}, ["search", "River.onexport.width"]) var river = sub.run({}, ["search", "River.onexport.width"])
var height = window.innerHeight-header-footer var height = window.innerHeight-header-footer
sub.page.Modify(sub, sub._output, {style: { sub.page.Modify(sub, sub._output, {style: {"max-height": height}})
"max-height": height,
}})
sub.page.Modify(sub, sub._target, {style: { sub.page.Modify(sub, sub._target, {style: {
left: river, top: header, height: height, background: "#4eaad0c2", left: river, top: header, height: height, background: "#4eaad0c2",
margin: "0 10px", padding: "0 10px", margin: "0 10px", padding: "0 10px",
@ -66,14 +53,14 @@ Volcanos("onfigure", {help: "组件菜单", list: [],
var order = index; function show(order) { var order = index; function show(order) {
path = can.onimport._file(can, can.list[order].path) path = can.onimport._file(can, can.list[order].path)
sub.page.Appends(sub, sub._output, [{img: path, height: height-55}]) sub.page.Appends(sub, sub._output, [{img: path, height: height-55}])
sub.core.Timer(100, function() { sub.Status("位置", order+1+"/"+can.list.length), sub.Status("file", path) }) sub.Status("位置", order+1+"/"+can.list.length), sub.Status("file", path)
}; show(order) }; show(order)
sub.onappend._action(sub, ["关闭", "下载", "上一个", "下一个", "设置背景"], sub._action, { sub.onappend._action(sub, ["关闭", "下载", "上一个", "下一个", "设置背景"], sub._action, {
"关闭": function(event) { sub.page.Remove(sub, sub._target) }, "关闭": function(event) { sub.page.Remove(sub, sub._target) },
"下载": function(event) { can.user.download(can, path) }, "下载": function(event) { can.user.download(can, path) },
"上一个": function(event) { order > 0? show(--order): show(order = can.list.length-1) }, "上一个": function(event) { order > 0? show(--order): can.user.toast(can, "已经是第一张啦!") },
"下一个": function(event) { order < can.list.length-1? show(++order): show(order = 0) }, "下一个": function(event) { order < can.list.length-1? show(++order): can.user.toast(can, "已经是最后一张啦!") },
"设置背景": function(event) { var msg = can.request(event, {url: can.onimport._file(can, can.list[order].path)}) "设置背景": function(event) { var msg = can.request(event, {url: can.onimport._file(can, can.list[order].path)})
sub.run(event, ["search", "Header.onimport.background"]) sub.run(event, ["search", "Header.onimport.background"])
}, },
@ -83,8 +70,7 @@ Volcanos("onfigure", {help: "组件菜单", list: [],
onmouseover: function(event) { can.Status("file", path) }, onmouseover: function(event) { can.Status("file", path) },
} }, } },
video: function(can, path) { var auto = true, loop = true, total = 0 video: function(can, path) { var auto = true, loop = true, total = 0; function cb(event) { }
function cb(event) { }
return {className: "preview", type: "video", style: {height: can.height}, return {className: "preview", type: "video", style: {height: can.height},
data: {src: path, controls: "controls", autoplay: auto, loop: loop, playbackRate: can.rate}, data: {src: path, controls: "controls", autoplay: auto, loop: loop, playbackRate: can.rate},
oncontextmenu: cb, onplay: cb, onpause: cb, onended: cb, oncontextmenu: cb, onplay: cb, onpause: cb, onended: cb,
@ -105,12 +91,6 @@ Volcanos("onaction", {help: "组件菜单", list: [
["高度", 100, 200, 400, 600, 800], ["高度", 100, 200, 400, 600, 800],
["倍速", 0.1, 0.2, 0.5, 1, 2, 3, 5, 10], ["倍速", 0.1, 0.2, 0.5, 1, 2, 3, 5, 10],
], ],
chooseImage: function(event, can) { var msg = can.request(event)
can.user.agent.chooseImage(function(list) { can.core.List(list, function(item) {
can.page.Append(can, can._output, [{img: item, height: 200}])
}) })
},
upload: function(event, can) { can.user.upload(event, can) },
"上一页": function(event, can, key, value) { "上一页": function(event, can, key, value) {
can.begin > 0 && (can.begin -= can.limit, can.onimport._page(can, can.list, can.begin, can.limit)) can.begin > 0 && (can.begin -= can.limit, can.onimport._page(can, can.list, can.begin, can.limit))
}, },
@ -118,9 +98,6 @@ Volcanos("onaction", {help: "组件菜单", list: [
can.begin + can.limit < can.list.length && (can.begin += can.limit, can.onimport._page(can, can.list, can.begin, can.limit)) can.begin + can.limit < can.list.length && (can.begin += can.limit, can.onimport._page(can, can.list, can.begin, can.limit))
}, },
"参数": function(event, can) {
can.page.Toggle(can, can._action)
},
"数量": function(event, can, key, value) { "数量": function(event, can, key, value) {
can.limit = parseInt(value), can.onimport._page(can, can.list, can.begin, can.limit) can.limit = parseInt(value), can.onimport._page(can, can.list, can.begin, can.limit)
}, },
@ -130,6 +107,12 @@ Volcanos("onaction", {help: "组件菜单", list: [
"倍速": function(event, can, key, value) { "倍速": function(event, can, key, value) {
can.rate = parseInt(value), can.onimport._page(can, can.list, can.begin, can.limit) can.rate = parseInt(value), can.onimport._page(can, can.list, can.begin, can.limit)
}, },
chooseImage: function(event, can) { var msg = can.request(event)
can.user.agent.chooseImage(function(list) { can.core.List(list, function(item) {
can.page.Append(can, can._output, [{img: item, height: 200}])
}) })
},
}) })
Volcanos("onexport", {help: "导出数据", list: ["begin", "limit", "total", "position", "file"], Volcanos("onexport", {help: "导出数据", list: ["begin", "limit", "total", "position", "file"],
position: function(can, index, total) { total = total || can.max position: function(can, index, total) { total = total || can.max

View File

@ -54,6 +54,7 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg,
} }
}) })
}, },
upload: function(event, can) { can.user.upload(event, can) },
getLocation: function(event, can, cmd) { var msg = can.request(can) getLocation: function(event, can, cmd) { var msg = can.request(can)
can.user.agent.getLocation(function(res) { can.user.agent.getLocation(function(res) {
@ -74,6 +75,7 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg,
}) })
}, },
"参数": function(event, can) { can.page.Toggle(can, can._action) },
"清空": function(event, can, name) { can._output.innerHTML = "" }, "清空": function(event, can, name) { can._output.innerHTML = "" },
"结束": function(event, can, name) { can.user.confirm("确定结束?") && can.run(event, ["action", name], function(msg) { "结束": function(event, can, name) { can.user.confirm("确定结束?") && can.run(event, ["action", name], function(msg) {
can.run({}) can.run({})