Commit fc92e76f authored by campaign's avatar campaign

by zhanyi

parent 0e45f978
......@@ -62,18 +62,8 @@ KM.registerUI( 'contextmenu', function () {
$menu.kmui().hide();
});
me.on('beforemousedown',function(e){
var 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){
if(e.isRightMB()){
e.stopPropagationImmediately();
}
})
} );
......
......@@ -41,5 +41,16 @@ var MinderEvent = kity.createClass( 'MindEvent', {
},
preventDefault:function(){
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, {
var callbacks = this._eventCallbacks[ e.type.toLowerCase() ] || [];
if(status){
callbacks = callbacks.concat(this._eventCallbacks[ status + '.' + e.type.toLowerCase() ] || []);
}
......
......@@ -26,17 +26,9 @@ KityMinder.registerModule( "TextEditModule", function () {
this.getPaper().addShape(sel);
},
"events": {
'normal.beforemousedown':function(e){
'normal.beforemousedown textedit.beforemousedown':function(e){
var 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){
if(e.isRightMB()){
e.stopPropagationImmediately();
return;
}
......@@ -49,6 +41,7 @@ KityMinder.registerModule( "TextEditModule", function () {
node = selectionShape.getData('relatedNode');
e.stopPropagationImmediately();
}
km.setStatus('normal')
}
if(node){
var textShape = node.getTextShape();
......@@ -57,6 +50,7 @@ KityMinder.registerModule( "TextEditModule", function () {
if ( this.isSingleSelect() && node.isSelected()) {// && e.kityEvent.targetShape.getType().toLowerCase()== 'text'
sel.collapse();
node.getTextShape().setStyle('cursor','text');
km.setStatus('textedit');
receiver.setTextEditStatus(true)
.setSelection(sel)
.setKityMinder(this)
......@@ -75,10 +69,11 @@ KityMinder.registerModule( "TextEditModule", function () {
sel.setShow();
selectionByClick = false;
}
km.setStatus('textedit')
}
}
},
'normal.mouseup':function(e){
'normal.mouseup textedit.mouseup':function(e){
if(mouseDownStatus){
if(!sel.collapsed ){
try{
......@@ -94,7 +89,7 @@ KityMinder.registerModule( "TextEditModule", function () {
mouseDownStatus = false;
oneTime = 0;
},
'normal.beforemousemove':function(e){
'textedit.beforemousemove':function(e){
if(mouseDownStatus){
e.stopPropagationImmediately();
......@@ -113,7 +108,7 @@ KityMinder.registerModule( "TextEditModule", function () {
}
},
'normal.dblclick':function(e){
'normal.dblclick textedit.dblclick':function(e){
var text = e.kityEvent.targetShape;
if ( text.getType().toLowerCase()== 'text') {
......@@ -122,8 +117,8 @@ KityMinder.registerModule( "TextEditModule", function () {
sel.setEndOffset(text.getContent().length);
sel.setShow();
receiver.setContainerTxt(text.getContent()).updateSelectionShow(1)
.updateRange(range).setTextEditStatus(true)
.updateRange(range).setTextEditStatus(true);
km.setStatus('textedit');
}
},
'restoreScene':function(){
......@@ -132,6 +127,7 @@ KityMinder.registerModule( "TextEditModule", function () {
'stopTextEdit':function(){
sel.setHide();
receiver.clear().setTextEditStatus(false);
km.setStatus('normal');
},
"resize": function ( e ) {
sel.setHide();
......@@ -149,6 +145,7 @@ KityMinder.registerModule( "TextEditModule", function () {
textShape.setStyle('cursor','default');
node.getTextShape().setStyle('cursor','text');
km.setStatus('textedit');
receiver.setTextEditStatus(true)
.setSelection(sel)
.setKityMinder(this)
......@@ -188,6 +185,7 @@ KityMinder.registerModule( "TextEditModule", function () {
receiver.clear().setTextEditStatus(false);
},
'selectionclear':function(){
km.setStatus('normal');
receiver.setTextEditStatus(false).clear()
}
}
......
......@@ -21,7 +21,7 @@ Minder.Receiver = kity.createClass('Receiver',{
_div.className = 'km_receiver';
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);}');//
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.index = 0;
},
......@@ -72,51 +72,65 @@ Minder.Receiver = kity.createClass('Receiver',{
var me = this;
var orgEvt = e.originEvent;
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':
if(this.isTextEditStatus()){
switch(keyCode){
case keymap.Enter:
case keymap.Tab:
if(this.keydownNode === this.minderNode){
this.setTextEditStatus(false);
this.clear();
}
e.preventDefault();
return;
case keymap.Shift:
case keymap.Control:
case keymap.Alt:
case keymap.Cmd:
return;
switch(keyCode){
case keymap.Enter:
case keymap.Tab:
if(this.keydownNode === this.minderNode){
this.rollbackStatus();
this.setTextEditStatus(false);
this.clear();
}
e.preventDefault();
return;
case keymap.Shift:
case keymap.Control:
case keymap.Alt:
case keymap.Cmd:
return;
}
var text = this.container.textContent.replace(/\u200b/g,'');
}
var text = this.container.textContent.replace(/\u200b/g,'');
if(this.textShape.getOpacity() == 0){
this.textShape.setOpacity(1);
}
this.textShape.setContent(text);
this.setContainerStyle();
this.minderNode.setText(text);
if(text.length == 0){
this.textShape.setContent('a');
this.textShape.setOpacity(0);
}
this.km.updateLayout(this.minderNode);
this.setBaseOffset();
this.updateTextData();
this.updateIndex();
this.updateSelection();
if(this.textShape.getOpacity() == 0){
this.textShape.setOpacity(1);
}
this.textShape.setContent(text);
this.setContainerStyle();
this.minderNode.setText(text);
if(text.length == 0){
this.textShape.setContent('a');
this.textShape.setOpacity(0);
}
this.km.updateLayout(this.minderNode);
this.setBaseOffset();
this.updateTextData();
this.updateIndex();
this.updateSelection();
this.timer = setTimeout(function(){
me.selection.setShow()
this.timer = setTimeout(function(){
me.selection.setShow()
},500);
return true;
}
return true;
}
},
updateIndex:function(){
this.index = this.range.getStart().startOffset;
......
......@@ -66,26 +66,10 @@ KityMinder.registerModule( "KeyboardModule", function () {
contentchange: function () {
buildPositionNetwork( this.getRoot() );
},
keydown: function ( e ) {
"normal.keydown": function ( e ) {
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();
this.receiver.keydownNode = node;
switch ( e.originEvent.keyCode ) {
......
......@@ -93,7 +93,7 @@ KityMinder.registerModule( "Select", function () {
var lastDownNode = null;
return {
"events": {
mousedown: function ( e ) {
"normal.mousedown textedit.mousedown": function ( e ) {
var downNode = e.getTargetNode();
// 没有点中节点:
......@@ -101,6 +101,7 @@ KityMinder.registerModule( "Select", function () {
if ( !downNode ) {
this.removeAllSelectedNodes();
marqueeActivator.selectStart( e );
this.setStatus('normal')
}
// 点中了节点,并且按了 shift 键:
......@@ -122,8 +123,8 @@ KityMinder.registerModule( "Select", function () {
lastDownNode = downNode;
}
},
mousemove: marqueeActivator.selectMove,
mouseup: function ( e ) {
"normal.mousemove textedit.mousemove": marqueeActivator.selectMove,
"normal.mouseup textedit.mouseup": function ( e ) {
var upNode = e.getTargetNode();
// 如果 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