Commit cda653fa authored by Akikonata's avatar Akikonata

Merge branch 'dev' of https://github.com/kitygraph/kityminder into dev

parents a2cfa6d8 35a67ae8
......@@ -22,6 +22,7 @@
"Utils",
"utils",
"$",
"KM"
"KM",
"keymap"
]
}
\ No newline at end of file
......@@ -63,7 +63,7 @@
'KITYMINDER_HOME_URL': getKMBasePath(),
//定义工具栏
toolbars: [
'hand zoom-in zoom-out | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers'
'hand zoom-in zoom-out | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers | node'
]
//设置主题
......
......@@ -23,7 +23,7 @@ $dependency = Array(
,'src/module/layout.default.js'
,'src/module/layout.bottom.js'
,'src/core/minder.select.js'
,'src/module/dragview.js'
,'src/module/hand.js'
,'src/module/dragtree.js'
,'src/module/dropfile.js'
,'src/module/keyboard.js'
......@@ -59,9 +59,10 @@ $dependency = Array(
,'src/adapter/button.js'
,'src/adapter/combobox.js'
,'src/adapter/saveto.js'
,'src/adapter/hand.js'
,'src/adapter/view.js'
,'src/adapter/dialog.js'
,'src/adapter/tooltips.js'
,'src/adapter/node.js'
,'src/protocal/plain.js'
,'src/protocal/json.js'
);
......
......@@ -10,8 +10,11 @@ KityMinder.LANG[ 'zh-cn' ] = {
'fontfamily': '字体',
'fontsize': '字号',
'layoutstyle': '主题',
'node':'节点操作',
'saveto': '导出',
'hand': '允许拖拽',
'zoom-in': '放大',
'zoom-out': '缩小',
'markers': '添加标签'
},
'popupcolor': {
......@@ -33,9 +36,14 @@ KityMinder.LANG[ 'zh-cn' ] = {
'quarterdone': '完成1/4',
'halfdone': '完成1/2',
'threequartersdone': '完成3/4',
'done': '已完成',
'done': '已完成'
}
}
},
'node':{
'appendsiblingnode':'插入兄弟节点',
'appendchildnode':'插入孩子节点',
'removenode':'删除节点'
}
};
\ No newline at end of file
......@@ -30,7 +30,6 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize', function ( name ) {
case 'fontsize':
options = transForFontsize( options );
break;
}
//实例化
......
function zoom( paper, rate ) {
var viewbox = paper.getViewBox();
var zoomValue = paper._zoom || 1;
var w = viewbox.width,
h = viewbox.height,
x = viewbox.x,
y = viewbox.y;
var ww = w * rate,
hh = h * rate,
xx = x + ( w - ww ) / 2,
yy = y + ( h - hh ) / 2;
var animator = new kity.Animator( {
beginValue: viewbox,
finishValue: {
width: ww,
height: hh,
x: xx,
y: yy
},
setter: function ( target, value ) {
target.setViewBox( value.x, value.y, value.width, value.height );
}
} );
animator.start( paper, 100, 'ease' );
paper._zoom = zoomValue *= rate;
return zoomValue;
}
KM.registerToolbarUI( 'hand zoom-in zoom-out',
function ( name ) {
var me = this;
var $btn = $.kmuibutton( {
icon: name,
click: {
'hand': function ( e ) {
var drag = me._onDragMode = !me._onDragMode;
me._paper.setStyle( 'cursor', drag ? 'pointer' : 'default' );
me._paper.setStyle( 'cursor', drag ? '-webkit-grab' : 'default' );
$btn.kmui().active( drag );
if ( drag ) {
me._paper.drag();
} else {
me._paper.undrag();
}
},
'zoom-in': function ( e ) {
var value = zoom( me.getPaper(), 0.707 );
me.fire( 'zoom', {
zoom: value
} );
},
'zoom-out': function ( e ) {
var value = zoom( me.getPaper(), 1 / 0.707 );
me.fire( 'zoom', {
zoom: value
} );
}
}[ name ],
title: this.getLang( 'tooltips.' )[ name ] || ''
} );
switch ( name ) {
case 'hand':
me.on( 'beforemousemove', function ( e ) {
if ( this._onDragMode ) {
e.stopPropagation();
}
} );
me.on('keyup', function(e) {
if(e.keyCode == keymap.Space && me.getSelectedNodes().length == 0) {
$btn.click();
e.preventDefault();
}
});
kity.extendClass( kity.Paper, kity.Draggable );
break;
case 'zoom-in':
me.on( 'zoom', function ( e ) {
$btn.kmui().disabled( e.zoom <= 0.5 );
} );
break;
case 'zoom-out':
me.on( 'zoom', function ( e ) {
$btn.kmui().disabled( e.zoom >= 2 );
} );
me.on( 'mousewheel', function ( e ) {
var delta = e.originEvent.wheelDelta;
if ( Math.abs( delta ) > 100 ) {
clearTimeout( me._wheelZoomTimeout );
} else {
return;
}
me._wheelZoomTimeout = setTimeout( function () {
var value;
var lastValue = me.getPaper()._zoom || 1;
if ( delta < 0 && lastValue > 0.5 ) {
value = zoom( me.getPaper(), 0.707 );
me.fire( 'zoom', {
zoom: value
} );
} else if ( delta > 0 && lastValue < 2 ) {
value = zoom( me.getPaper(), 1 / 0.707 );
me.fire( 'zoom', {
zoom: value
} );
}
}, 100 );
e.originEvent.preventDefault();
} );
}
return $btn;
}
);
\ No newline at end of file
KM.registerToolbarUI( 'node', function ( name ) {
var shortcutKeys = {
"appendsiblingnode": "enter",
"appendchildnode": "tab",
"removenode":"del|backspace"
};
debugger
var me = this,
msg = me.getLang('node'),
label = me.getLang( 'tooltips.' + name ),
options = {
label: label,
title: label,
comboboxName: name,
items: me.getOptions( name ) || [],
itemStyles: [],
value: [],
autowidthitem: []
},
$combox = null;
if ( options.items.length == 0 ) {
return null;
}
//实例化
$combox = $.kmuibuttoncombobox( transForInserttopic( options ) ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( res.value );
}).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
}
});
return comboboxWidget.button().addClass( 'kmui-combobox' );
function transForInserttopic( options ) {
var tempItems = [];
utils.each( options.items, function ( k, v ) {
options.value.push( v );
tempItems.push( (msg[k]||k) + '(' + shortcutKeys[v].toUpperCase() + ')');
options.autowidthitem.push( $.wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) );
} );
options.items = tempItems;
return options;
}
});
KM.registerToolbarUI( 'hand zoom-in zoom-out',
function ( name ) {
var me = this;
var $btn = $.kmuibutton( {
icon: name,
click: function () {
me.execCommand( name );
},
title: this.getLang( 'tooltips.' )[ name ] || ''
} );
me.on('interactchange', function() {
var state = me.queryCommandState( name );
$btn.kmui().disabled( state == -1 ).active( state == 1 );
});
return $btn;
}
);
\ No newline at end of file
......@@ -28,5 +28,14 @@ var keymap = KityMinder.keymap = {
'NumLock':144,
'Cmd':91
'Cmd':91,
'=':187,
'-':189,
"b":66,
'i':73,
'z':90,
'y':89
};
\ No newline at end of file
......@@ -87,25 +87,46 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
_bindshortcutKeys: function () {
var me = this,
shortcutkeys = this._shortcutkeys;
me.on( 'keydown', function ( e ) {
function checkkey(key,keyCode,e){
switch(key){
case 'ctrl':
case 'cmd':
if(e.ctrlKey || e.metaKey){
return true;
}
break;
case 'alt':
if(e.altKey){
return true
}
break;
case 'shift':
if(e.shiftKey){
return true;
}
}
if(keyCode == keymap[key]){
return true;
}
return false
}
me.on( 'keydown', function ( e ) {
var originEvent = e.originEvent;
var keyCode = originEvent.keyCode || originEvent.which;
for ( var i in shortcutkeys ) {
var tmp = shortcutkeys[ i ].split( ',' );
for ( var t = 0, ti; ti = tmp[ t++ ]; ) {
ti = ti.split( ':' );
var key = ti[ 0 ],
param = ti[ 1 ];
if ( /^(ctrl)(\+shift)?\+(\d+)$/.test( key.toLowerCase() ) || /^(\d+)$/.test( key ) ) {
if ( ( ( RegExp.$1 == 'ctrl' ? ( originEvent.ctrlKey || originEvent.metaKey ) : 0 ) && ( RegExp.$2 != "" ? originEvent[ RegExp.$2.slice( 1 ) + "Key" ] : 1 ) && keyCode == RegExp.$3 ) ||
keyCode == RegExp.$1
) {
if ( me.queryCommandState( i, param ) != -1 )
me.execCommand( i, param );
e.preventDefault();
}
var keys = shortcutkeys[ i ].toLowerCase().split('+');
var current = 0;
utils.each(keys,function(i,k){
if(checkkey(k,keyCode,originEvent)){
current++;
}
});
if(current == keys.length){
if ( me.queryCommandState( i ) != -1 )
me.execCommand( i );
originEvent.preventDefault();
break;
}
}
......
......@@ -69,8 +69,8 @@ KityMinder.registerModule( "basestylemodule", function () {
} )
},
addShortcutKeys: {
"bold": "ctrl+66", //bold
"italic": "ctrl+73" //italic
"bold": "ctrl+b", //bold
"italic": "ctrl+i" //italic
},
"events": {
"beforeRenderNode": function ( e ) {
......
......@@ -101,9 +101,11 @@ kity.Draggable = ( function () {
paper.off( DRAG_MOVE_EVENT, dragFn );
dragTarget.trigger( 'dragend' );
if ( e ) {
e.stopPropagation();
e.preventDefault();
}
}
} );
}
......@@ -128,6 +130,7 @@ kity.Draggable = ( function () {
undrag: function () {
var target = this.dragTarget;
target.off( DRAG_START_EVENT, target._dragStartHandler );
target._dragEndHandler();
target.getPaper().off( DRAG_END_EVENT, target._dragEndHandler );
delete target._dragStartHandler;
delete target._dragEndHandler;
......@@ -136,3 +139,45 @@ kity.Draggable = ( function () {
}
} );
} )();
KityMinder.registerModule( 'Hand', function () {
var ToggleHandCommand = kity.createClass( "ToggleHandCommand", {
base: Command,
execute: function ( minder ) {
var drag = minder._onDragMode = !minder._onDragMode;
minder.getPaper().setStyle( 'cursor', drag ? 'pointer' : 'default' );
minder.getPaper().setStyle( 'cursor', drag ? '-webkit-grab' : 'default' );
if ( drag ) {
minder.getPaper().drag();
} else {
minder.getPaper().undrag();
}
},
queryState: function ( minder ) {
return minder._onDragMode ? 1 : 0;
}
} );
return {
init: function () {
this._onDragMode = false;
kity.extendClass( kity.Paper, kity.Draggable );
},
commands: {
'hand': ToggleHandCommand
},
events: {
keyup: function ( e ) {
if ( e.originEvent.keyCode == keymap.Spacebar && this.getSelectedNodes().length === 0 ) {
this.execCommand( 'hand' );
e.preventDefault();
}
},
beforemousemove: function ( e ) {
if ( this._onDragMode ) {
e.stopPropagation();
}
}
}
};
} );
\ No newline at end of file
......@@ -138,8 +138,8 @@ KityMinder.registerModule( "HistoryModule", function () {
} )
},
addShortcutKeys: {
"Undo": "ctrl+90", //undo
"Redo": "ctrl+89" //redo
"Undo": "ctrl+z", //undo
"Redo": "ctrl+y" //redo
},
"events": {
"saveScene": function ( e ) {
......
......@@ -205,7 +205,12 @@ KityMinder.registerModule( "LayoutModule", function () {
}
},
"defaultOptions": {
"defaultlayoutstyle": "default"
"defaultlayoutstyle": "default",
"node":{
'appendsiblingnode':'appendsiblingnode',
'appendchildnode':'appendchildnode',
'removenode':'removenode'
}
}
};
} );
\ No newline at end of file
KityMinder.registerModule( 'Zoom', function () {
var MAX_ZOOM = 2,
MIN_ZOOM = 0.5,
ZOOM_STEP = Math.sqrt( 2 );
function zoom( minder, rate ) {
var paper = minder.getPaper();
var viewbox = paper.getViewBox();
var zoomValue = minder._zoomValue;
var w = viewbox.width,
h = viewbox.height,
x = viewbox.x,
y = viewbox.y;
var ww = w * rate,
hh = h * rate,
xx = x + ( w - ww ) / 2,
yy = y + ( h - hh ) / 2;
var animator = new kity.Animator( {
beginValue: viewbox,
finishValue: {
width: ww,
height: hh,
x: xx,
y: yy
},
setter: function ( target, value ) {
target.setViewBox( value.x, value.y, value.width, value.height );
}
} );
animator.start( paper, 100, 'ease' );
minder._zoomValue = zoomValue *= rate;
}
var ZoomInCommand = kity.createClass( 'ZoomInCommand', {
base: Command,
execute: function ( minder ) {
if( !this.queryState( minder ) ) {
zoom( minder, 1 / ZOOM_STEP );
}
},
queryState: function ( minder ) {
return (minder._zoomValue > MIN_ZOOM) ? 0 : -1;
}
} );
var ZoomOutCommand = kity.createClass( 'ZoomOutCommand', {
base: Command,
execute: function ( minder ) {
if( !this.queryState( minder ) ) {
zoom( minder, ZOOM_STEP );
}
},
queryState: function ( minder ) {
return (minder._zoomValue < MAX_ZOOM) ? 0 : -1;
}
} );
return {
commands: {
'zoom-in': ZoomInCommand,
'zoom-out': ZoomOutCommand
},
addShortcutKeys: {
"zoom-in": "=", //=
"zoom-out": "-" //-
},
events: {
'ready': function () {
this._zoomValue = 1;
},
'mousewheel': function ( e ) {
var delta = e.originEvent.wheelDelta;
var me = this;
// 稀释
if ( Math.abs( delta ) > 100 ) {
clearTimeout( this._wheelZoomTimeout );
} else {
return;
}
this._wheelZoomTimeout = setTimeout( function () {
var value;
var lastValue = me.getPaper()._zoom || 1;
if ( delta < 0 ) {
me.execCommand('zoom-in');
} else if ( delta > 0 ) {
me.execCommand('zoom-out');
}
}, 100 );
e.originEvent.preventDefault();
},
'ready': function () {
this._zoom = 1;
}
}
};
......
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