Commit fc92e76f authored by campaign's avatar campaign

by zhanyi

parent 0e45f978
...@@ -62,18 +62,8 @@ KM.registerUI( 'contextmenu', function () { ...@@ -62,18 +62,8 @@ KM.registerUI( 'contextmenu', function () {
$menu.kmui().hide(); $menu.kmui().hide();
}); });
me.on('beforemousedown',function(e){ me.on('beforemousedown',function(e){
var isRightMB; if(e.isRightMB()){
if ("which" in e.originEvent) // Gecko (Firefox), WebKit (Safari/Chrome) & Opera
isRightMB = e.originEvent.which == 3;
else if ("button" in e.originEvent) // IE, Opera
isRightMB = e.originEvent.button == 2;
if(isRightMB){
e.stopPropagationImmediately(); e.stopPropagationImmediately();
} }
}) })
} ); } );
......
...@@ -41,5 +41,16 @@ var MinderEvent = kity.createClass( 'MindEvent', { ...@@ -41,5 +41,16 @@ var MinderEvent = kity.createClass( 'MindEvent', {
}, },
preventDefault:function(){ preventDefault:function(){
this.originEvent.preventDefault(); this.originEvent.preventDefault();
},
isRightMB:function(){
var isRightMB = false;
if(!this.originEvent){
return false;
}
if ("which" in this.originEvent)
isRightMB = this.originEvent.which == 3;
else if ("button" in this.originEvent)
isRightMB = this.originEvent.button == 2;
return isRightMB;
} }
} ); } );
\ No newline at end of file
...@@ -68,6 +68,7 @@ kity.extendClass( Minder, { ...@@ -68,6 +68,7 @@ kity.extendClass( Minder, {
var callbacks = this._eventCallbacks[ e.type.toLowerCase() ] || []; var callbacks = this._eventCallbacks[ e.type.toLowerCase() ] || [];
if(status){ if(status){
callbacks = callbacks.concat(this._eventCallbacks[ status + '.' + e.type.toLowerCase() ] || []); callbacks = callbacks.concat(this._eventCallbacks[ status + '.' + e.type.toLowerCase() ] || []);
} }
......
...@@ -26,17 +26,9 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -26,17 +26,9 @@ KityMinder.registerModule( "TextEditModule", function () {
this.getPaper().addShape(sel); this.getPaper().addShape(sel);
}, },
"events": { "events": {
'normal.beforemousedown':function(e){ 'normal.beforemousedown textedit.beforemousedown':function(e){
var isRightMB; if(e.isRightMB()){
if ("which" in e.originEvent) // Gecko (Firefox), WebKit (Safari/Chrome) & Opera
isRightMB = e.originEvent.which == 3;
else if ("button" in e.originEvent) // IE, Opera
isRightMB = e.originEvent.button == 2;
if(isRightMB){
e.stopPropagationImmediately(); e.stopPropagationImmediately();
return; return;
} }
...@@ -49,6 +41,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -49,6 +41,7 @@ KityMinder.registerModule( "TextEditModule", function () {
node = selectionShape.getData('relatedNode'); node = selectionShape.getData('relatedNode');
e.stopPropagationImmediately(); e.stopPropagationImmediately();
} }
km.setStatus('normal')
} }
if(node){ if(node){
var textShape = node.getTextShape(); var textShape = node.getTextShape();
...@@ -57,6 +50,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -57,6 +50,7 @@ KityMinder.registerModule( "TextEditModule", function () {
if ( this.isSingleSelect() && node.isSelected()) {// && e.kityEvent.targetShape.getType().toLowerCase()== 'text' if ( this.isSingleSelect() && node.isSelected()) {// && e.kityEvent.targetShape.getType().toLowerCase()== 'text'
sel.collapse(); sel.collapse();
node.getTextShape().setStyle('cursor','text'); node.getTextShape().setStyle('cursor','text');
km.setStatus('textedit');
receiver.setTextEditStatus(true) receiver.setTextEditStatus(true)
.setSelection(sel) .setSelection(sel)
.setKityMinder(this) .setKityMinder(this)
...@@ -75,10 +69,11 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -75,10 +69,11 @@ KityMinder.registerModule( "TextEditModule", function () {
sel.setShow(); sel.setShow();
selectionByClick = false; selectionByClick = false;
} }
km.setStatus('textedit')
} }
} }
}, },
'normal.mouseup':function(e){ 'normal.mouseup textedit.mouseup':function(e){
if(mouseDownStatus){ if(mouseDownStatus){
if(!sel.collapsed ){ if(!sel.collapsed ){
try{ try{
...@@ -94,7 +89,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -94,7 +89,7 @@ KityMinder.registerModule( "TextEditModule", function () {
mouseDownStatus = false; mouseDownStatus = false;
oneTime = 0; oneTime = 0;
}, },
'normal.beforemousemove':function(e){ 'textedit.beforemousemove':function(e){
if(mouseDownStatus){ if(mouseDownStatus){
e.stopPropagationImmediately(); e.stopPropagationImmediately();
...@@ -113,7 +108,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -113,7 +108,7 @@ KityMinder.registerModule( "TextEditModule", function () {
} }
}, },
'normal.dblclick':function(e){ 'normal.dblclick textedit.dblclick':function(e){
var text = e.kityEvent.targetShape; var text = e.kityEvent.targetShape;
if ( text.getType().toLowerCase()== 'text') { if ( text.getType().toLowerCase()== 'text') {
...@@ -122,8 +117,8 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -122,8 +117,8 @@ KityMinder.registerModule( "TextEditModule", function () {
sel.setEndOffset(text.getContent().length); sel.setEndOffset(text.getContent().length);
sel.setShow(); sel.setShow();
receiver.setContainerTxt(text.getContent()).updateSelectionShow(1) receiver.setContainerTxt(text.getContent()).updateSelectionShow(1)
.updateRange(range).setTextEditStatus(true) .updateRange(range).setTextEditStatus(true);
km.setStatus('textedit');
} }
}, },
'restoreScene':function(){ 'restoreScene':function(){
...@@ -132,6 +127,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -132,6 +127,7 @@ KityMinder.registerModule( "TextEditModule", function () {
'stopTextEdit':function(){ 'stopTextEdit':function(){
sel.setHide(); sel.setHide();
receiver.clear().setTextEditStatus(false); receiver.clear().setTextEditStatus(false);
km.setStatus('normal');
}, },
"resize": function ( e ) { "resize": function ( e ) {
sel.setHide(); sel.setHide();
...@@ -149,6 +145,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -149,6 +145,7 @@ KityMinder.registerModule( "TextEditModule", function () {
textShape.setStyle('cursor','default'); textShape.setStyle('cursor','default');
node.getTextShape().setStyle('cursor','text'); node.getTextShape().setStyle('cursor','text');
km.setStatus('textedit');
receiver.setTextEditStatus(true) receiver.setTextEditStatus(true)
.setSelection(sel) .setSelection(sel)
.setKityMinder(this) .setKityMinder(this)
...@@ -188,6 +185,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -188,6 +185,7 @@ KityMinder.registerModule( "TextEditModule", function () {
receiver.clear().setTextEditStatus(false); receiver.clear().setTextEditStatus(false);
}, },
'selectionclear':function(){ 'selectionclear':function(){
km.setStatus('normal');
receiver.setTextEditStatus(false).clear() receiver.setTextEditStatus(false).clear()
} }
} }
......
...@@ -21,7 +21,7 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -21,7 +21,7 @@ Minder.Receiver = kity.createClass('Receiver',{
_div.className = 'km_receiver'; _div.className = 'km_receiver';
this.container = document.body.insertBefore(_div,document.body.firstChild); this.container = document.body.insertBefore(_div,document.body.firstChild);
utils.addCssRule('km_receiver_css',' .km_receiver{position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);}');// utils.addCssRule('km_receiver_css',' .km_receiver{position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);}');//
this.km.on('beforekeyup', utils.proxy(this.keyboardEvents,this)); this.km.on('textedit.beforekeyup textedit.keydown', utils.proxy(this.keyboardEvents,this));
this.timer = null; this.timer = null;
this.index = 0; this.index = 0;
}, },
...@@ -72,51 +72,65 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -72,51 +72,65 @@ Minder.Receiver = kity.createClass('Receiver',{
var me = this; var me = this;
var orgEvt = e.originEvent; var orgEvt = e.originEvent;
var keyCode = orgEvt.keyCode; var keyCode = orgEvt.keyCode;
switch(e.type){ var keys = KityMinder.keymap;
switch(e.type){
case 'keydown':
switch ( e.originEvent.keyCode ) {
case keys.Enter:
case keys.Tab:
this.selection.setHide();
this.clear().setTextEditStatus(false);
this.km.setStatus('normal');
e.preventDefault();
break;
}
break;
case 'beforekeyup': case 'beforekeyup':
if(this.isTextEditStatus()){ switch(keyCode){
switch(keyCode){ case keymap.Enter:
case keymap.Enter: case keymap.Tab:
case keymap.Tab: if(this.keydownNode === this.minderNode){
if(this.keydownNode === this.minderNode){ this.rollbackStatus();
this.setTextEditStatus(false); this.setTextEditStatus(false);
this.clear(); this.clear();
} }
e.preventDefault(); e.preventDefault();
return; return;
case keymap.Shift: case keymap.Shift:
case keymap.Control: case keymap.Control:
case keymap.Alt: case keymap.Alt:
case keymap.Cmd: case keymap.Cmd:
return; return;
} }
var text = this.container.textContent.replace(/\u200b/g,''); var text = this.container.textContent.replace(/\u200b/g,'');
if(this.textShape.getOpacity() == 0){ if(this.textShape.getOpacity() == 0){
this.textShape.setOpacity(1); this.textShape.setOpacity(1);
} }
this.textShape.setContent(text); this.textShape.setContent(text);
this.setContainerStyle(); this.setContainerStyle();
this.minderNode.setText(text); this.minderNode.setText(text);
if(text.length == 0){ if(text.length == 0){
this.textShape.setContent('a'); this.textShape.setContent('a');
this.textShape.setOpacity(0); this.textShape.setOpacity(0);
} }
this.km.updateLayout(this.minderNode); this.km.updateLayout(this.minderNode);
this.setBaseOffset(); this.setBaseOffset();
this.updateTextData(); this.updateTextData();
this.updateIndex(); this.updateIndex();
this.updateSelection(); this.updateSelection();
this.timer = setTimeout(function(){ this.timer = setTimeout(function(){
me.selection.setShow() me.selection.setShow()
},500); },500);
return true; return true;
}
} }
}, },
updateIndex:function(){ updateIndex:function(){
this.index = this.range.getStart().startOffset; this.index = this.range.getStart().startOffset;
......
...@@ -66,26 +66,10 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -66,26 +66,10 @@ KityMinder.registerModule( "KeyboardModule", function () {
contentchange: function () { contentchange: function () {
buildPositionNetwork( this.getRoot() ); buildPositionNetwork( this.getRoot() );
}, },
keydown: function ( e ) { "normal.keydown": function ( e ) {
var keys = KityMinder.keymap; var keys = KityMinder.keymap;
if ( this.receiver.isTextEditStatus() ) {
switch ( e.originEvent.keyCode ) {
case keys.Enter:
case keys.Tab:
this.fire( 'stopTextEdit' );
e.preventDefault();
break;
case keys.Backspace:
case keys.Del:
case keys.Left:
case keys.Up:
case keys.Right:
case keys.Down:
break;
}
return;
}
var node = e.getTargetNode(); var node = e.getTargetNode();
this.receiver.keydownNode = node; this.receiver.keydownNode = node;
switch ( e.originEvent.keyCode ) { switch ( e.originEvent.keyCode ) {
......
...@@ -93,7 +93,7 @@ KityMinder.registerModule( "Select", function () { ...@@ -93,7 +93,7 @@ KityMinder.registerModule( "Select", function () {
var lastDownNode = null; var lastDownNode = null;
return { return {
"events": { "events": {
mousedown: function ( e ) { "normal.mousedown textedit.mousedown": function ( e ) {
var downNode = e.getTargetNode(); var downNode = e.getTargetNode();
// 没有点中节点: // 没有点中节点:
...@@ -101,6 +101,7 @@ KityMinder.registerModule( "Select", function () { ...@@ -101,6 +101,7 @@ KityMinder.registerModule( "Select", function () {
if ( !downNode ) { if ( !downNode ) {
this.removeAllSelectedNodes(); this.removeAllSelectedNodes();
marqueeActivator.selectStart( e ); marqueeActivator.selectStart( e );
this.setStatus('normal')
} }
// 点中了节点,并且按了 shift 键: // 点中了节点,并且按了 shift 键:
...@@ -122,8 +123,8 @@ KityMinder.registerModule( "Select", function () { ...@@ -122,8 +123,8 @@ KityMinder.registerModule( "Select", function () {
lastDownNode = downNode; lastDownNode = downNode;
} }
}, },
mousemove: marqueeActivator.selectMove, "normal.mousemove textedit.mousemove": marqueeActivator.selectMove,
mouseup: function ( e ) { "normal.mouseup textedit.mouseup": function ( e ) {
var upNode = e.getTargetNode(); var upNode = e.getTargetNode();
// 如果 mouseup 发生在 lastDownNode 外,是无需理会的 // 如果 mouseup 发生在 lastDownNode 外,是无需理会的
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment