diff --git a/frame.js b/frame.js index d23ae1e4..02a0b5e7 100644 --- a/frame.js +++ b/frame.js @@ -133,7 +133,7 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) { Clone: function() { meta.args = can.page.SelectArgs(can) can.onappend._init(can, meta, list, function(sub) { can.base.isFunc(cb) && cb(sub, true), can.onmotion.delay(can, sub.Focus) }, target) }, - }, list, function(sub) { meta.feature = can.base.Obj(meta.feature, {}), sub.Conf(meta) + }, list, function(sub) { meta.feature = can.base.Obj(meta.feature, {}), sub.Conf(meta), field._can = sub can.onappend.style(sub, meta.index? meta.index.split(nfs.PT): meta.name), can.onappend.style(sub, sub.Conf(ctx.STYLE)), can.onappend.style(sub, sub.Mode()) sub._trans = can.base.Copy(sub._trans||{}, can.core.Value(sub, [chat.ONACTION, chat._TRANS])) can.core.Item(meta.feature, function(key, cb) { cb.help && sub.user.trans(sub, kit.Dict(key, cb.help)) }) @@ -670,6 +670,52 @@ Volcanos(chat.ONMOTION, {_init: function(can, target) { time = can.base.isObject(time)? time: {interval: 10, length: time||30} can.core.Timer(time, function(event, value, index) { can.page.style(can, target, html.OPACITY, (index+1)/time.length) }, cb) }, + resize: function(can, _window, cb, top) { var target, begin, action + function findTarget(event) { for (var target = event.target; target; target = target.parentNode) { if (target == document.body) { target = null; return } + if (can.page.tagis(event.target, html.INPUT, html.TEXTAREA, html.TABLE, html.TR)) { target = null; return } + if (can.page.tagis(target, html.FIELDSET) || can.page.ClassList.has(can, target, "move")) { break } + } return target } + _window.onmousedown = function(event) { target = findTarget(event); if (!target) { return } + begin = {left: target.offsetLeft, top: target.offsetTop, width: target.offsetWidth, height: target.offsetHeight, x: event.x, y: event.y} + can.page.SelectChild(can, target.parentNode, html.FIELDSET, function(target) { can.page.style(can, target, "z-index") && can.page.style(can, target, "z-index", 9) }), can.page.style(can, target, "z-index", 10) + window._scroll = _window.onmousemove + }, _window.onmouseup = function(event) { target = null, begin = {} } + _window.onmousemove = function(event) { + if (target) { can.onkeymap.prevent(event) + switch (action) { + case "left": + can.page.style(can, target, html.LEFT, can.base.Min(begin.left + event.x - begin.x, 0, window.innerWidth-target.offsetWidth)) + cb? cb(target.offsetHeight, begin.width + begin.x - event.x): can.page.style(can, target, html.WIDTH, begin.width + begin.x - event.x) + break + case "right": + cb? cb(target.offsetHeight, begin.width + event.x - begin.x): can.page.style(can, target, html.WIDTH, begin.width + event.x - begin.x); + break + case "bottom": + cb? cb(begin.height + event.y - begin.y, target.offsetWidth): can.page.style(can, target, html.HEIGHT, begin.height + event.y - begin.y) + break + default: + can.page.style(can, target, + html.LEFT, can.base.Min(begin.left + event.x - begin.x, 0, window.innerWidth-target.offsetWidth), + html.TOP, can.base.Min(begin.top + event.y - begin.y, top||0, window.innerHeight-html.ACTION_HEIGHT) + ) + } + } else { var _target = findTarget(event); if (!_target) { return } + var x = event.x - _target.offsetLeft, y = event.y - _target.offsetTop, margin = 32 + if (-margin < x && x < margin) { action = "left" + can.page.style(can, _target, "cursor", "ew-resize") + } else if (_target.offsetWidth-margin < x && x < _target.offsetWidth+margin) { action = "right" + can.page.style(can, _target, "cursor", "ew-resize") + } else if (_target.offsetHeight-margin < y && y < _target.offsetHeight+margin) { action = "bottom" + can.page.style(can, _target, "cursor", "ns-resize") + } else if (-margin < y && y < margin) { action = "top" + can.page.style(can, _target, "cursor", "move") + } else { action = "" + can.page.style(can, _target, "cursor", "") + } + } + } + + }, }) Volcanos(chat.ONKEYMAP, {_init: function(can, target) { target = target||document.body can.onkeymap._build(can), target.onkeydown = function(event) { can.misc.Event(event, can, function(msg) { diff --git a/lib/user.js b/lib/user.js index 2ca06a2a..91e464e7 100644 --- a/lib/user.js +++ b/lib/user.js @@ -113,14 +113,16 @@ Volcanos("user", { can.onmotion.focus(can, input), document.execCommand("Copy"), can.page.Remove(can, input) return can.user.toastSuccess(can, text, "copy success"), can.misc.Log(nfs.COPY, text), text }, - carte: function(event, can, meta, list, cb, parent, trans) { parent || can.onmotion.clearCarte(can) + carte: function(event, can, meta, list, cb, parent, trans) { + function remove_sub(carte) { carte._sub && can.page.Remove(can, carte._sub._target), delete(carte._sub) } + parent? remove_sub(parent): can.onmotion.clearCarte(can) var msg = can.request(event); trans = trans||meta._trans meta = meta||can.ondetail||can.onaction||{}, list = can.base.getValid(list, meta.list, can.core.Item(meta)); if (!list || list.length == 0) { return } function click(event, button) { can.misc.Event(event, can, function() { can.onkeymap.prevent(event) meta[button]? can.core.CallFunc([meta, button], {event: event, can: can, msg: msg, button: button}): can.base.isFunc(cb)? cb(event, button, meta, carte): can.onaction && can.onaction[button] && can.core.CallFunc([can.onaction, button], [event, can, button]) - meta._style == nfs.PATH || can.onmotion.clearCarte(can) - }) } function remove_sub(carte) { carte._sub && can.page.Remove(can, carte._sub._target), delete(carte._sub) } + // meta._style == nfs.PATH || can.onmotion.clearCarte(can) + }) } var ui = can.page.Append(can, document.body, [{view: [[chat.CARTE, meta._style||can.base.replaceAll(can._index||"", nfs.PT, lex.SP)||"", chat.FLOAT]], list: can.core.List(list, function(item, index) { if (item == web.FILTER) { return {input: [html.FILTER, function(event) { if (event.key == lang.ESCAPE) { return carte.close() } can.onkeymap.selectItems(event, can, carte._target) }], @@ -129,14 +131,16 @@ Volcanos("user", { } function subs(event) { var sub = can.user.carte(event, can, meta, item.slice(1), cb||function(event, button) { can.onimport && can.onimport[item[0]] && can.onimport[item[0]](can, button) - }, carte, trans); can.onlayout.figure(event, can, sub._target, true), remove_sub(carte), carte._sub = sub } + }, carte, trans); can.onlayout.figure(event, can, sub._target, true), carte._sub = sub } return item === ""? /* 0.space */ {type: html.HR}: can.base.isString(item)||can.base.isNumber(item)? /* 1.string */ {view: [html.ITEM, html.DIV, meta._style == ice.CMD? item: can.user.trans(can, item, trans)], onclick: function(event) { click(event, item) }, onmouseenter: function(event) { remove_sub(carte) } }: can.base.isArray(item)? /* 2.array */ {view: html.ITEM, list: [{text: can.user.trans(can, item[0], trans)}, {text: [lex.SP+can.page.unicode.next, "", [html.ICON, "next"]]}], onmouseenter: subs, onclick: subs}: /* 3.object */ item })}]); can.onkeymap.prevent(event), can.page.Select(can, ui._target, html.IMG, function(target) { target.onload = function() { can.onlayout.figure(event, can, ui._target) } }) - var carte = {_target: ui._target, _parent: parent, layout: can.onlayout.figure(event, can, ui._target, false, 0.8), close: function() { can.page.Remove(can, ui._target) }}; return carte + var carte = {_target: ui._target, _parent: parent, layout: can.onlayout.figure(event, can, ui._target, false, 0.8), close: function() { can.page.Remove(can, ui._target) }} + parent && (parent._sub = carte) + return carte }, carteRight: function(event, can, meta, list, cb, parent) { var carte = can.user.carte(event, can, meta, list, cb, parent) - return can.onlayout.figure(event, can, carte._target, true), carte + return carte && can.onlayout.figure(event, can, carte._target, true), carte }, input: function(event, can, form, cb, button) { if (!form || form.length == 0) { return cb() } var msg = can.request(event); event = event._event||event; var need = {} diff --git a/plugin/state.js b/plugin/state.js index 7c99dde0..fa365f30 100644 --- a/plugin/state.js +++ b/plugin/state.js @@ -23,9 +23,7 @@ Volcanos(chat.ONIMPORT, { }, can.run(event, (!msg.Option("_index") || msg.Option("_index") == can._index || can._index.indexOf("can.") == 0? msg[ice.MSG_PREFIX]||[]: [ice.RUN, msg.Option("_index")]).concat(cmds), cb, true) } sub._target.onclick = function() { - can.page.SelectChild(can, can._output, "fieldset", function(target) { - can.page.style(can, target, "z-index", "9") - }) + can.page.SelectChild(can, can._output, html.FIELDSET, function(target) { can.page.style(can, target, "z-index", "9") }) can.page.style(can, sub._target, "z-index", "10") } can.page.style(can, sub._target, "z-index", "10") @@ -83,7 +81,7 @@ Volcanos(chat.ONACTION, {list: [ html.ACTION, can.page.isDisplay(can._action), html.STATUS, can.page.isDisplay(can._status), html.OUTPUT, can.base.Copy({}, can._output.style, html.HEIGHT, html.WIDTH, html.MAX_HEIGHT, html.MAX_WIDTH), ctx.STYLE, can.base.Copy({}, can._target.style, html.LEFT, html.TOP, html.RIGHT, html.BOTTOM), save(), - )), can.onimport.size(can, can.ConfHeight()+html.ACTION_HEIGHT+can.onexport.statusHeight(can), can.ConfWidth(), false, mode) + )), can.onimport.size(can, can.ConfHeight()+can.onexport.actionHeight(can)+can.onexport.statusHeight(can), can.ConfWidth(), false, mode) } else { var back = (can._mode_list = can._mode_list||[]).pop(); if (!back) { return } can.ConfHeight(back.height), can.ConfWidth(back.width), can.Mode(back.mode), can.onmotion.toggle(can, can._action, back.action), can.onmotion.toggle(can, can._status, back.status) diff --git a/proto.js b/proto.js index 281a49c5..c2d31734 100644 --- a/proto.js +++ b/proto.js @@ -379,20 +379,8 @@ try { if (typeof(window) == lang.OBJECT) { var meta = Volcanos.meta } } meta._init = function(can) { - var target, begin - window.onmousedown = function(event) { - for (target = event.target; target; target = target.parentNode) { if (target == document.body) { target = null; return } - // if (can.page.tagis(target, html.DIV) && can.page.ClassList.has(can, target, html.OUTPUT)) { target = null; return } - if (can.page.tagis(event.target, html.TABLE, html.TR, html.INPUT, html.TEXTAREA)) { target = null; return } - if (can.page.ClassList.has(can, target, "move")) { break } - } begin = {left: target.offsetLeft, top: target.offsetTop, x: event.x, y: event.y} - can.page.SelectChild(can, target.parentNode, html.FIELDSET, function(target) { can.page.style(can, target, "z-index") && can.page.style(can, target, "z-index", 9) }), can.page.style(can, target, "z-index", 10) - }, window.onmouseup = function(event) { target = null, begin = {}, delete(window._scroll) } - window.onmousemove = function(event) { target && can.page.style(can, target, - html.LEFT, can.base.Min(begin.left + event.x - begin.x, 0, window.innerWidth-target.offsetWidth), - html.TOP, can.base.Min(begin.top + event.y - begin.y, 0, window.innerHeight-html.ACTION_HEIGHT) - ) && can.onkeymap.prevent(event), window._scroll && (window._scroll(event)) } - + window.onmousemove = function(event) { window._scroll && (window._scroll(event)) } + window.onmouseup = function(event) { delete(window._scroll) } window.ondblclick = function(event) { can.onkeymap.prevent(event) } window.onerror = function(message, source, lineno, colno, error) { meta.version? alert([message].concat(can.misc._stacks(0, error)).join(lex.NL)): can.misc.Error(message, lex.NL+[source, lineno, colno].join(ice.DF), error)