Commit 0ec90d2d authored by campaign's avatar campaign

by zhanyi

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