Commit 0ec90d2d authored by campaign's avatar campaign

by zhanyi

parent 2173a133
...@@ -27,6 +27,7 @@ kity.extendClass( Minder, { ...@@ -27,6 +27,7 @@ kity.extendClass( Minder, {
_firePharse: function ( e ) { _firePharse: function ( e ) {
var beforeEvent, preEvent, executeEvent; var beforeEvent, preEvent, executeEvent;
beforeEvent = new MinderEvent( 'before' + e.type, e, true ); beforeEvent = new MinderEvent( 'before' + e.type, e, true );
if ( this._fire( beforeEvent ) ) { if ( this._fire( beforeEvent ) ) {
return; return;
...@@ -44,6 +45,7 @@ kity.extendClass( Minder, { ...@@ -44,6 +45,7 @@ kity.extendClass( Minder, {
}, },
_interactChange: function ( e ) { _interactChange: function ( e ) {
var minder = this; var minder = this;
clearTimeout( this._interactTimeout ); clearTimeout( this._interactTimeout );
this._interactTimeout = setTimeout( function () { this._interactTimeout = setTimeout( function () {
var stoped = minder._fire( new MinderEvent( 'beforeinteractchange' ) ); var stoped = minder._fire( new MinderEvent( 'beforeinteractchange' ) );
...@@ -59,10 +61,22 @@ kity.extendClass( Minder, { ...@@ -59,10 +61,22 @@ kity.extendClass( Minder, {
callbacks.push( callback ); callbacks.push( callback );
}, },
_fire: function ( e ) { _fire: function ( e ) {
var callbacks = this._eventCallbacks[ e.type.toLowerCase() ];
if ( !callbacks ) {
return false; var status = this.getStatus();
var callbacks = this._eventCallbacks[ e.type.toLowerCase() ] || [];
if(status){
callbacks = callbacks.concat(this._eventCallbacks[ status + '.' + e.type.toLowerCase() ] || []);
} }
if(callbacks.length == 0){
return;
}
for ( var i = 0; i < callbacks.length; i++ ) { for ( var i = 0; i < callbacks.length; i++ ) {
callbacks[ i ].call( this, e ); callbacks[ i ].call( this, e );
if ( e.shouldStopPropagationImmediately() ) { if ( e.shouldStopPropagationImmediately() ) {
...@@ -72,17 +86,19 @@ kity.extendClass( Minder, { ...@@ -72,17 +86,19 @@ kity.extendClass( Minder, {
return e.shouldStopPropagation(); return e.shouldStopPropagation();
}, },
on: function ( name, callback ) { on: function ( name, callback ) {
var types = name.split( ' ' ); var km = this;
for ( var i = 0; i < types.length; i++ ) { utils.each(name.split(/\s+/),function(i,n){
this._listen( types[ i ].toLowerCase(), callback ); km._listen( n.toLowerCase(), callback );
} });
return this; return this;
}, },
off: function ( name, callback ) { off: function ( name, callback ) {
var types = name.split( ' ' );
var types = name.split( /\s+/);
var i, j, callbacks, removeIndex; var i, j, callbacks, removeIndex;
for ( i = 0; i < types.length; i++ ) { for ( i = 0; i < types.length; i++ ) {
callbacks = this._eventCallbacks[ types[ i ].toLowerCase() ];
callbacks = this._eventCallbacks[ types[ i ].toLowerCase() ];
if ( callbacks ) { if ( callbacks ) {
removeIndex = null; removeIndex = null;
for ( j = 0; j < callbacks.length; j++ ) { for ( j = 0; j < callbacks.length; j++ ) {
......
...@@ -5,6 +5,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { ...@@ -5,6 +5,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this._initEvents(); this._initEvents();
this._initMinder(); this._initMinder();
this._initSelection(); this._initSelection();
this._initStatus();
this._initShortcutKey(); this._initShortcutKey();
this._initContextmenu(); this._initContextmenu();
this._initModules(); this._initModules();
...@@ -147,6 +148,25 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { ...@@ -147,6 +148,25 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
}, },
getContextmenu:function(){ getContextmenu:function(){
return this.contextmenus; return this.contextmenus;
},
_initStatus:function(){
this._status = "normal";
this._rollbackStatus = "normal";
},
setStatus:function(status){
if(status){
this._rollbackStatus = this._status;
this._status = status;
}else{
this._status = '';
}
return this;
},
rollbackStatus:function(){
this._status = this._rollbackStatus;
},
getStatus:function(){
return this._status;
} }
} ); } );
......
...@@ -26,7 +26,8 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -26,7 +26,8 @@ KityMinder.registerModule( "TextEditModule", function () {
this.getPaper().addShape(sel); this.getPaper().addShape(sel);
}, },
"events": { "events": {
'beforemousedown':function(e){ 'normal.beforemousedown':function(e){
var isRightMB; var isRightMB;
...@@ -77,7 +78,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -77,7 +78,7 @@ KityMinder.registerModule( "TextEditModule", function () {
} }
} }
}, },
'mouseup':function(e){ 'normal.mouseup':function(e){
if(mouseDownStatus){ if(mouseDownStatus){
if(!sel.collapsed ){ if(!sel.collapsed ){
try{ try{
...@@ -93,7 +94,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -93,7 +94,7 @@ KityMinder.registerModule( "TextEditModule", function () {
mouseDownStatus = false; mouseDownStatus = false;
oneTime = 0; oneTime = 0;
}, },
'beforemousemove':function(e){ 'normal.beforemousemove':function(e){
if(mouseDownStatus){ if(mouseDownStatus){
e.stopPropagationImmediately(); e.stopPropagationImmediately();
...@@ -112,7 +113,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -112,7 +113,7 @@ KityMinder.registerModule( "TextEditModule", function () {
} }
}, },
'dblclick':function(e){ 'normal.dblclick':function(e){
var text = e.kityEvent.targetShape; var text = e.kityEvent.targetShape;
if ( text.getType().toLowerCase()== 'text') { if ( text.getType().toLowerCase()== 'text') {
......
...@@ -24,7 +24,7 @@ var ViewDragger = kity.createClass( "ViewDragger", { ...@@ -24,7 +24,7 @@ var ViewDragger = kity.createClass( "ViewDragger", {
lastPosition = null, lastPosition = null,
currentPosition = null; currentPosition = null;
this._minder.on( 'beforemousedown', function ( e ) { this._minder.on( 'hand.beforemousedown', function ( e ) {
// 已经被用户打开拖放模式 // 已经被用户打开拖放模式
if ( dragger.isEnabled() ) { if ( dragger.isEnabled() ) {
lastPosition = e.getPosition(); lastPosition = e.getPosition();
...@@ -41,7 +41,7 @@ var ViewDragger = kity.createClass( "ViewDragger", { ...@@ -41,7 +41,7 @@ var ViewDragger = kity.createClass( "ViewDragger", {
} ) } )
.on( 'beforemousemove', function ( e ) { .on( 'hand.beforemousemove', function ( e ) {
if ( lastPosition ) { if ( lastPosition ) {
currentPosition = e.getPosition(); currentPosition = e.getPosition();
...@@ -54,7 +54,7 @@ var ViewDragger = kity.createClass( "ViewDragger", { ...@@ -54,7 +54,7 @@ var ViewDragger = kity.createClass( "ViewDragger", {
} }
} ) } )
.on( 'mouseup', function ( e ) { .on( 'hand.mouseup', function ( e ) {
lastPosition = null; lastPosition = null;
// 临时拖动需要还原状态 // 临时拖动需要还原状态
...@@ -67,10 +67,20 @@ var ViewDragger = kity.createClass( "ViewDragger", { ...@@ -67,10 +67,20 @@ var ViewDragger = kity.createClass( "ViewDragger", {
} ); } );
KityMinder.registerModule( 'Hand', function () { KityMinder.registerModule( 'Hand', function () {
var km = this;
var ToggleHandCommand = kity.createClass( "ToggleHandCommand", { var ToggleHandCommand = kity.createClass( "ToggleHandCommand", {
base: Command, base: Command,
execute: function ( minder ) { execute: function ( minder ) {
minder._viewDragger.setEnabled( !minder._viewDragger.isEnabled() ); minder._viewDragger.setEnabled( !minder._viewDragger.isEnabled() );
if(minder._viewDragger.isEnabled()){
minder.setStatus('hand')
}else{
minder.rollbackStatus()
}
}, },
queryState: function ( minder ) { queryState: function ( minder ) {
return minder._viewDragger.isEnabled() ? 1 : 0; return minder._viewDragger.isEnabled() ? 1 : 0;
......
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