Commit a876ca99 authored by techird's avatar techird

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

parents df63a21c b88ee449
(function(){ ( function () {
function getKMBasePath ( docUrl, confUrl ) { function getKMBasePath( docUrl, confUrl ) {
return getBasePath( docUrl || self.document.URL || self.location.href, confUrl || getConfigFilePath() ); return getBasePath( docUrl || self.document.URL || self.location.href, confUrl || getConfigFilePath() );
} }
function getConfigFilePath () { function getConfigFilePath() {
var configPath = document.getElementsByTagName('script'); var configPath = document.getElementsByTagName( 'script' );
return configPath[ configPath.length -1 ].src; return configPath[ configPath.length - 1 ].src;
} }
function getBasePath ( docUrl, confUrl ) { function getBasePath( docUrl, confUrl ) {
var basePath = confUrl; var basePath = confUrl;
if(/^(\/|\\\\)/.test(confUrl)){ if ( /^(\/|\\\\)/.test( confUrl ) ) {
basePath = /^.+?\w(\/|\\\\)/.exec(docUrl)[0] + confUrl.replace(/^(\/|\\\\)/,''); basePath = /^.+?\w(\/|\\\\)/.exec( docUrl )[ 0 ] + confUrl.replace( /^(\/|\\\\)/, '' );
}else if ( !/^[a-z]+:/i.test( confUrl ) ) { } else if ( !/^[a-z]+:/i.test( confUrl ) ) {
docUrl = docUrl.split( "#" )[0].split( "?" )[0].replace( /[^\\\/]+$/, '' ); docUrl = docUrl.split( "#" )[ 0 ].split( "?" )[ 0 ].replace( /[^\\\/]+$/, '' );
basePath = docUrl + "" + confUrl; basePath = docUrl + "" + confUrl;
...@@ -34,15 +34,15 @@ ...@@ -34,15 +34,15 @@
} }
function optimizationPath ( path ) { function optimizationPath( path ) {
var protocol = /^[a-z]+:\/\//.exec( path )[ 0 ], var protocol = /^[a-z]+:\/\//.exec( path )[ 0 ],
tmp = null, tmp = null,
res = []; res = [];
path = path.replace( protocol, "" ).split( "?" )[0].split( "#" )[0]; path = path.replace( protocol, "" ).split( "?" )[ 0 ].split( "#" )[ 0 ];
path = path.replace( /\\/g, '/').split( /\// ); path = path.replace( /\\/g, '/' ).split( /\// );
path[ path.length - 1 ] = ""; path[ path.length - 1 ] = "";
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
'KITYMINDER_HOME_URL': getKMBasePath(), 'KITYMINDER_HOME_URL': getKMBasePath(),
//定义工具栏 //定义工具栏
toolbars: [ toolbars: [
'hand zoom-in zoom-out | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers | node' 'hand zoom-in zoom-out | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers | node | switchlayout'
] ]
//设置主题 //设置主题
...@@ -79,4 +79,4 @@ ...@@ -79,4 +79,4 @@
//设置km整体的z-index大小 //设置km整体的z-index大小
//,zIndex : 1000 //,zIndex : 1000
}; };
})() } )()
\ No newline at end of file
...@@ -62,9 +62,11 @@ $dependency = Array( ...@@ -62,9 +62,11 @@ $dependency = Array(
,'src/adapter/view.js' ,'src/adapter/view.js'
,'src/adapter/dialog.js' ,'src/adapter/dialog.js'
,'src/adapter/tooltips.js' ,'src/adapter/tooltips.js'
,'src/adapter/layout.js'
,'src/adapter/node.js' ,'src/adapter/node.js'
,'src/protocal/plain.js' ,'src/protocal/plain.js'
,'src/protocal/json.js' ,'src/protocal/json.js'
,'src/protocal/png.js'
); );
$content = ""; $content = "";
......
...@@ -10,12 +10,13 @@ KityMinder.LANG[ 'zh-cn' ] = { ...@@ -10,12 +10,13 @@ KityMinder.LANG[ 'zh-cn' ] = {
'fontfamily': '字体', 'fontfamily': '字体',
'fontsize': '字号', 'fontsize': '字号',
'layoutstyle': '主题', 'layoutstyle': '主题',
'node':'节点操作', 'node': '节点操作',
'saveto': '导出', 'saveto': '导出',
'hand': '允许拖拽', 'hand': '允许拖拽',
'zoom-in': '放大', 'zoom-in': '放大',
'zoom-out': '缩小', 'zoom-out': '缩小',
'markers': '添加标签' 'markers': '添加标签',
'switchlayout': '切换主题'
}, },
'popupcolor': { 'popupcolor': {
'clearColor': '清空颜色', 'clearColor': '清空颜色',
...@@ -40,10 +41,10 @@ KityMinder.LANG[ 'zh-cn' ] = { ...@@ -40,10 +41,10 @@ KityMinder.LANG[ 'zh-cn' ] = {
} }
} }
}, },
'node':{ 'node': {
'appendsiblingnode':'插入兄弟节点', 'appendsiblingnode': '插入兄弟节点',
'appendchildnode':'插入孩子节点', 'appendchildnode': '插入孩子节点',
'removenode':'删除节点' 'removenode': '删除节点'
} }
}; };
\ No newline at end of file
KM.registerToolbarUI( 'layoutstyle fontfamily fontsize inserttopic', function ( name ) { KM.registerToolbarUI( 'fontfamily fontsize', function ( name ) {
var me = this, var me = this,
label = me.getLang( 'tooltips.' + name ), label = me.getLang( 'tooltips.' + name ),
...@@ -19,9 +19,7 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize inserttopic', function ( ...@@ -19,9 +19,7 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize inserttopic', function (
} }
switch ( name ) { switch ( name ) {
case 'layoutstyle':
options = transForLayoutstyle( options );
break;
case 'fontfamily': case 'fontfamily':
options = transForFontfamily( options ); options = transForFontfamily( options );
...@@ -31,8 +29,6 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize inserttopic', function ( ...@@ -31,8 +29,6 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize inserttopic', function (
options = transForFontsize( options ); options = transForFontsize( options );
break; break;
case 'inserttopic':
optons
} }
//实例化 //实例化
...@@ -64,24 +60,6 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize inserttopic', function ( ...@@ -64,24 +60,6 @@ KM.registerToolbarUI( 'layoutstyle fontfamily fontsize inserttopic', function (
return comboboxWidget.button().addClass( 'kmui-combobox' ); return comboboxWidget.button().addClass( 'kmui-combobox' );
function transForLayoutstyle( options ) {
var tempItems = [];
utils.each( options.items, function ( k, v ) {
options.value.push( k );
tempItems.push( k );
options.autowidthitem.push( $.wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) );
} );
options.items = tempItems;
return options;
}
//字体参数转换 //字体参数转换
function transForFontfamily( options ) { function transForFontfamily( options ) {
......
KM.registerToolbarUI( 'switchlayout', function ( name ) {
var me = this,
label = me.getLang( 'tooltips.' + name ),
options = {
label: label,
title: label,
comboboxName: name,
items: me.getLayoutStyleItems() || [],
itemStyles: [],
value: me.getLayoutStyleItems(),
autowidthitem: [],
enabledRecord:false
},
$combox = null;
if ( options.items.length == 0 ) {
return null;
}
//实例化
$combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( name, res.value );
} ).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
}
} );
//状态反射
me.on( 'interactchange', function () {
var state = this.queryCommandState( name ),
value = this.queryCommandValue( name );
//设置按钮状态
comboboxWidget.button().kmui().disabled( state == -1 ).active( state == 1 );
if ( value ) {
//设置label
value = value.replace( /['"]/g, '' ).toLowerCase().split( /['|"]?\s*,\s*[\1]?/ );
comboboxWidget.selectItemByLabel( value );
}
} );
return comboboxWidget.button().addClass( 'kmui-combobox' );
} );
\ No newline at end of file
KM.registerToolbarUI( 'node', function ( name ) { KM.registerToolbarUI( 'node', function ( name ) {
var shortcutKeys = { var shortcutKeys = {
"appendsiblingnode": "enter", "appendsiblingnode": "enter",
"appendchildnode": "tab", "appendchildnode": "tab",
"removenode":"del|backspace" "removenode": "del|backspace"
}; };
var me = this, var me = this,
msg = me.getLang('node'), msg = me.getLang( 'node' ),
label = me.getLang( 'tooltips.' + name ), label = me.getLang( 'tooltips.' + name ),
options = { options = {
label: label, label: label,
...@@ -15,10 +15,10 @@ KM.registerToolbarUI( 'node', function ( name ) { ...@@ -15,10 +15,10 @@ KM.registerToolbarUI( 'node', function ( name ) {
items: me.getOptions( name ) || [], items: me.getOptions( name ) || [],
itemStyles: [], itemStyles: [],
value: [], value: [],
autowidthitem: [] autowidthitem: [],
enabledRecord: false
}, },
$combox = null; $combox = null;
if ( options.items.length == 0 ) { if ( options.items.length == 0 ) {
return null; return null;
} }
...@@ -28,21 +28,21 @@ KM.registerToolbarUI( 'node', function ( name ) { ...@@ -28,21 +28,21 @@ KM.registerToolbarUI( 'node', function ( name ) {
comboboxWidget = $combox.kmui(); comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) { comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( res.value ); me.execCommand( res.value, new MinderNode( me.getLang().topic ) );
}).on( "beforeshow", function () { } ).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) { if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) ); $combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
} }
var combox = $combox.kmui(); var combox = $combox.kmui();
combox.traverseItems(function(label,value){ combox.traverseItems( function ( label, value ) {
if(me.queryCommandState(value) == -1){ if ( me.queryCommandState( value ) == -1 ) {
combox.disableItemByLabel(label) combox.disableItemByLabel( label )
}else{ } else {
combox.enableItemByLabel(label) combox.enableItemByLabel( label )
} }
}) } )
}); } );
return comboboxWidget.button().addClass( 'kmui-combobox' ); return comboboxWidget.button().addClass( 'kmui-combobox' );
...@@ -55,7 +55,7 @@ KM.registerToolbarUI( 'node', function ( name ) { ...@@ -55,7 +55,7 @@ KM.registerToolbarUI( 'node', function ( name ) {
utils.each( options.items, function ( k, v ) { utils.each( options.items, function ( k, v ) {
options.value.push( v ); options.value.push( v );
tempItems.push( (msg[k]||k) + '(' + shortcutKeys[v].toUpperCase() + ')'); tempItems.push( ( msg[ k ] || k ) + '(' + shortcutKeys[ v ].toUpperCase() + ')' );
options.autowidthitem.push( $.wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) ); options.autowidthitem.push( $.wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) );
} ); } );
...@@ -64,5 +64,4 @@ KM.registerToolbarUI( 'node', function ( name ) { ...@@ -64,5 +64,4 @@ KM.registerToolbarUI( 'node', function ( name ) {
} }
}); } );
\ No newline at end of file
...@@ -30,6 +30,53 @@ KM.registerToolbarUI( 'saveto', function ( name ) { ...@@ -30,6 +30,53 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
comboboxWidget = $combox.kmui(); comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) { comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
if ( res.value === "png" ) {
var svghtml = $( "#kityminder .kmui-editor-body" ).html();
var rootBox = me.getRoot().getRenderContainer().getRenderBox();
var svg = $( svghtml ).attr( {
width: rootBox.x + me.getRenderContainer().getWidth() + 20,
height: rootBox.y + me.getRenderContainer().getHeight() + 20,
viewBox: null
} );
var div = $( "<div></div>" ).append( svg );
svghtml = div.html();
var canvas = $( '<canvas style="border:2px solid black;" width="' + svg.attr( "width" ) + '" height="' + svg.attr( "height" ) + '"></canvas>' );
var ctx = canvas[ 0 ].getContext( "2d" );
var DOMURL = self.URL || self.webkitURL || self;
var img = new Image();
var svg = new Blob( [ svghtml ], {
type: "image/svg+xml;charset=utf-8"
} );
var url = DOMURL.createObjectURL( svg );
img.onload = function () {
ctx.drawImage( img, 0, 0 );
DOMURL.revokeObjectURL( url );
var type = 'png';
var imgData = canvas[ 0 ].toDataURL( type );
var _fixType = function ( type ) {
type = type.toLowerCase().replace( /jpg/i, 'jpeg' );
var r = type.match( /png|jpeg|bmp|gif/ )[ 0 ];
return 'image/' + r;
};
imgData = imgData.replace( _fixType( type ), 'image/octet-stream' );
var saveFile = function ( data, filename ) {
var save_link = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'a' );
save_link.href = data;
save_link.download = filename;
var event = document.createEvent( 'MouseEvents' );
event.initMouseEvent( 'click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null );
save_link.dispatchEvent( event );
};
// 下载后的问题名
var filename = 'kityminder_' + ( new Date() ).getTime() + '.' + type;
// download
saveFile( imgData, filename );
};
img.src = url;
return "png";
}
var data = me.exportData( res.value ); var data = me.exportData( res.value );
var p = KityMinder.findProtocal( res.value ); var p = KityMinder.findProtocal( res.value );
var a = downloadLink; var a = downloadLink;
......
...@@ -69,6 +69,9 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { ...@@ -69,6 +69,9 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this._shortcutkeys = {}; this._shortcutkeys = {};
this._bindshortcutKeys(); this._bindshortcutKeys();
}, },
isTextEditStatus:function(){
return false;
},
addShortcutKeys: function ( cmd, keys ) { addShortcutKeys: function ( cmd, keys ) {
var obj = {},km = this; var obj = {},km = this;
if ( keys ) { if ( keys ) {
...@@ -122,6 +125,10 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { ...@@ -122,6 +125,10 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
current++; current++;
} }
}); });
//todo 暂时通过receiver判断
if(me.isTextEditStatus()){
return;
}
if(current == keys.length){ if(current == keys.length){
if ( me.queryCommandState( i ) != -1 ) if ( me.queryCommandState( i ) != -1 )
me.execCommand( i ); me.execCommand( i );
......
...@@ -32,7 +32,7 @@ var MoveToParentCommand = kity.createClass( 'MoveToParentCommand', { ...@@ -32,7 +32,7 @@ var MoveToParentCommand = kity.createClass( 'MoveToParentCommand', {
function boxMapper( node ) { function boxMapper( node ) {
return node.getRenderContainer().getRenderBox(); return node.getRenderContainer().getRenderBox( 'top' );
} }
// 对拖动对象的一个替代盒子,控制整个拖放的逻辑,包括: // 对拖动对象的一个替代盒子,控制整个拖放的逻辑,包括:
......
...@@ -14,6 +14,12 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -14,6 +14,12 @@ KityMinder.registerModule( "TextEditModule", function () {
km.isTextEditStatus = function(){
return km.receiver.isTextEditStatus();
};
var selectionByClick = false;
return { return {
//插入光标 //插入光标
"init":function(){ "init":function(){
...@@ -23,12 +29,19 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -23,12 +29,19 @@ KityMinder.registerModule( "TextEditModule", function () {
'beforemousedown':function(e){ 'beforemousedown':function(e){
sel.setHide(); sel.setHide();
var node = e.getTargetNode(); var node = e.getTargetNode();
if(!node){
var selectionShape = e.kityEvent.targetShape;
if(selectionShape && selectionShape.getType() == 'Selection'){
selectionByClick = true;
node = selectionShape.getData('relatedNode');
e.stopPropagationImmediately();
}
}
if(node){ if(node){
var textShape = node.getTextShape(); var textShape = node.getTextShape();
textShape.setStyle('cursor','default'); textShape.setStyle('cursor','default');
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');
receiver.setTextEditStatus(true) receiver.setTextEditStatus(true)
...@@ -42,27 +55,44 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -42,27 +55,44 @@ KityMinder.registerModule( "TextEditModule", function () {
.setCurrentIndex(e.getPosition()) .setCurrentIndex(e.getPosition())
.updateSelection() .updateSelection()
.setRange(range); .setRange(range);
sel.setData('relatedNode',node);
mouseDownStatus = true; mouseDownStatus = true;
lastEvtPosition = e.getPosition(); lastEvtPosition = e.getPosition();
if(selectionByClick){
sel.setShow();
selectionByClick = false;
}
} }
} }
}, },
'mouseup':function(e){ 'mouseup':function(e){
if(!sel.collapsed && mouseDownStatus){ if(mouseDownStatus){
receiver.updateRange(range) if(!sel.collapsed ){
receiver.updateRange(range)
}else
sel.setShow()
} }
mouseDownStatus = false; mouseDownStatus = false;
oneTime = 0; oneTime = 0;
}, },
'beforemousemove':function(e){ 'beforemousemove':function(e){
if(mouseDownStatus){ if(mouseDownStatus){
e.stopPropagationImmediately(); e.stopPropagationImmediately();
var offset = e.getPosition(); var offset = e.getPosition();
if(Math.abs(offset.y - lastEvtPosition.y) > 2 && Math.abs(lastEvtPosition.x - offset.x) < 1 ){
sel.setHide();
mouseDownStatus = false;
return;
}
dir = offset.x > lastEvtPosition.x ? 1 : (offset.x < lastEvtPosition.x ? -1 : dir); dir = offset.x > lastEvtPosition.x ? 1 : (offset.x < lastEvtPosition.x ? -1 : dir);
receiver.updateSelectionByMousePosition(offset,dir) receiver.updateSelectionByMousePosition(offset,dir)
.updateSelectionShow(dir); .updateSelectionShow(dir);
sel.stroke('none',0);
lastEvtPosition = e.getPosition(); lastEvtPosition = e.getPosition();
} }
}, },
'dblclick':function(e){ 'dblclick':function(e){
...@@ -73,8 +103,8 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -73,8 +103,8 @@ KityMinder.registerModule( "TextEditModule", function () {
sel.setStartOffset(0); sel.setStartOffset(0);
sel.setEndOffset(text.getContent().length); sel.setEndOffset(text.getContent().length);
sel.setShow(); sel.setShow();
receiver.updateSelectionShow(1) receiver.setContainerTxt(text.getContent()).updateSelectionShow(1)
.updateRange(range); .updateRange(range).setTextEditStatus(true)
} }
}, },
...@@ -117,7 +147,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -117,7 +147,7 @@ KityMinder.registerModule( "TextEditModule", function () {
receiver.updateSelectionShow(1) receiver.updateSelectionShow(1)
.updateRange(range); .updateRange(range);
return;
} }
...@@ -130,10 +160,11 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -130,10 +160,11 @@ KityMinder.registerModule( "TextEditModule", function () {
}else{ }else{
receiver.updateSelectionShow(1) receiver.updateSelectionShow(1)
} }
return;
} }
receiver.clear().setTextEditStatus(false);
}, },
'selectionclear':function(){ 'selectionclear':function(){
receiver.setTextEditStatus(false).clear() receiver.setTextEditStatus(false).clear()
......
...@@ -16,7 +16,12 @@ Minder.Range = kity.createClass('Range',{ ...@@ -16,7 +16,12 @@ Minder.Range = kity.createClass('Range',{
return this; return this;
}, },
setStart:function(node,index){ setStart:function(node,index){
this.nativeRange.setStart(node,index); try{
this.nativeRange.setStart(node,index);
}catch(e){
console.log(e)
}
return this; return this;
}, },
setEnd:function(node,index){ setEnd:function(node,index){
......
...@@ -223,16 +223,17 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -223,16 +223,17 @@ Minder.Receiver = kity.createClass('Receiver',{
return false; return false;
} }
if(offset.x >= v.x && offset.x <= v.x + v.width){ if(offset.x >= v.x && offset.x <= v.x + v.width){
if(me.index == i){ if(me.index == i){
if(i == 0){ if(i == 0){
me.selection.setStartOffset(i) me.selection.setStartOffset(i)
} }
me.selection.setEndOffset(i + (dir == 1 ? 1 : 0)) me.selection.setEndOffset(i + (dir == 1 ? 1 : 0))
}else if(i > me.index){ }else if(i > me.index){
me.selection.setStartOffset(me.index);
me.selection.setEndOffset(i + (dir == 1 ? 1 : 0)) me.selection.setEndOffset(i + (dir == 1 ? 1 : 0))
}else{ }else{
me.selection.setStartOffset(i + (dir == 1 ? 1 : 0)) me.selection.setStartOffset(i + (dir == 1 ? 1 : 0));
me.selection.setEndOffset(me.index)
} }
return false; return false;
...@@ -246,7 +247,7 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -246,7 +247,7 @@ Minder.Receiver = kity.createClass('Receiver',{
width = 0 ; width = 0 ;
if(this.selection.collapsed){ if(this.selection.collapsed){
this.selection.updateShow(startOffset,0); this.selection.updateShow(startOffset||this.textData[this.textData.length-1],0);
return this; return this;
} }
if(!endOffset){ if(!endOffset){
...@@ -269,5 +270,9 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -269,5 +270,9 @@ Minder.Receiver = kity.createClass('Receiver',{
setIndex:function(index){ setIndex:function(index){
this.index = index; this.index = index;
return this return this
},
setContainerTxt:function(txt){
this.container.textContent = txt;
return this;
} }
}); });
\ No newline at end of file
...@@ -5,18 +5,20 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -5,18 +5,20 @@ Minder.Selection = kity.createClass( 'Selection', {
this.callBase(); this.callBase();
this.height = height || 20; this.height = height || 20;
this.stroke( color || 'blue', width || 1 ); this.stroke( color || 'rgb(27,171,255)', width || 1 );
this.width = 1; this.width = 0;
this.fill('#99C8FF'); this.fill('rgb(27,171,255)');
this.setHide(); this.setHide();
this.timer = null; this.timer = null;
this.collapsed = true; this.collapsed = true;
this.startOffset = this.endOffset = 0; this.startOffset = this.endOffset = 0;
this.setOpacity(0.5) this.setOpacity(0.5);
this.setStyle('cursor','text');
}, },
collapse : function(toEnd){ collapse : function(toEnd){
this.stroke( 'blue', 1 ); this.stroke( 'rgb(27,171,255)', 1 );
this.setOpacity(1);
this.width = 1; this.width = 1;
this.collapsed = true; this.collapsed = true;
if(toEnd){ if(toEnd){
...@@ -37,7 +39,8 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -37,7 +39,8 @@ Minder.Selection = kity.createClass( 'Selection', {
return this; return this;
} }
this.collapsed = false; this.collapsed = false;
this.stroke('none'); this.stroke('none',0);
this.setOpacity(0.5);
return this; return this;
}, },
setEndOffset:function(offset){ setEndOffset:function(offset){
...@@ -51,10 +54,14 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -51,10 +54,14 @@ Minder.Selection = kity.createClass( 'Selection', {
return this; return this;
} }
this.collapsed = false; this.collapsed = false;
this.stroke('none'); this.stroke('none',0);
this.setOpacity(0.5);
return this; return this;
}, },
updateShow : function(offset,width){ updateShow : function(offset,width){
if(width){
this.setShowHold();
}
this.setPosition(offset).setWidth(width); this.setPosition(offset).setWidth(width);
return this; return this;
}, },
...@@ -64,7 +71,7 @@ Minder.Selection = kity.createClass( 'Selection', { ...@@ -64,7 +71,7 @@ Minder.Selection = kity.createClass( 'Selection', {
this.y = offset.y; this.y = offset.y;
} catch ( e ) { } catch ( e ) {
console.log(e) debugger
} }
return this.update(); return this.update();
......
This diff is collapsed.
...@@ -8,7 +8,11 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -8,7 +8,11 @@ KityMinder.registerModule( "LayoutModule", function () {
return this._layoutStyles[ name ]; return this._layoutStyles[ name ];
}, },
getLayoutStyleItems: function () { getLayoutStyleItems: function () {
return this._layoutStyles; var items = [];
for ( var key in this._layoutStyles ) {
items.push( key );
}
return items;
}, },
getCurrentStyle: function () { getCurrentStyle: function () {
var _root = this.getRoot(); var _root = this.getRoot();
...@@ -90,7 +94,10 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -90,7 +94,10 @@ KityMinder.registerModule( "LayoutModule", function () {
var SwitchLayoutCommand = kity.createClass( "SwitchLayoutCommand", ( function () { var SwitchLayoutCommand = kity.createClass( "SwitchLayoutCommand", ( function () {
return { return {
base: Command, base: Command,
execute: switchLayout execute: switchLayout,
queryValue: function ( km ) {
return km.getCurrentStyle();
}
}; };
} )() ); } )() );
var AppendChildNodeCommand = kity.createClass( "AppendChildNodeCommand", ( function () { var AppendChildNodeCommand = kity.createClass( "AppendChildNodeCommand", ( function () {
...@@ -98,9 +105,6 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -98,9 +105,6 @@ KityMinder.registerModule( "LayoutModule", function () {
base: Command, base: Command,
execute: function ( km, node ) { execute: function ( km, node ) {
var parent = km.getSelectedNode(); var parent = km.getSelectedNode();
if ( !parent ) {
return false;
}
km.appendChildNode( parent, node ); km.appendChildNode( parent, node );
km.select( node, true ); km.select( node, true );
return node; return node;
...@@ -120,9 +124,6 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -120,9 +124,6 @@ KityMinder.registerModule( "LayoutModule", function () {
base: Command, base: Command,
execute: function ( km, node ) { execute: function ( km, node ) {
var selectedNode = km.getSelectedNode(); var selectedNode = km.getSelectedNode();
if ( !selectedNode ) {
return false;
}
if ( selectedNode.isRoot() ) { if ( selectedNode.isRoot() ) {
node.setType( "main" ); node.setType( "main" );
km.appendChildNode( selectedNode, node ); km.appendChildNode( selectedNode, node );
...@@ -134,8 +135,9 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -134,8 +135,9 @@ KityMinder.registerModule( "LayoutModule", function () {
return node; return node;
}, },
queryState: function ( km ) { queryState: function ( km ) {
var selectedNode = km.getSelectedNode(); var selectedNodes = km.getSelectedNodes();
if ( !selectedNode || selectedNode === km.getRoot() ) { //没选中节点和单选root的时候返回不可执行
if ( selectedNodes.length === 0 || ( selectedNodes.length === 1 && selectedNodes[ 0 ] === km.getRoot() ) ) {
return -1; return -1;
} else { } else {
return 0; return 0;
...@@ -149,10 +151,6 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -149,10 +151,6 @@ KityMinder.registerModule( "LayoutModule", function () {
execute: function ( km ) { execute: function ( km ) {
var selectedNodes = km.getSelectedNodes(); var selectedNodes = km.getSelectedNodes();
var _root = km.getRoot(); var _root = km.getRoot();
if ( selectedNodes.length === 0 || ( selectedNodes.length === 1 && !selectedNodes[ 0 ].getParent() ) ) {
km.select( _root );
return false;
}
var _buffer = []; var _buffer = [];
for ( var i = 0; i < selectedNodes.length; i++ ) { for ( var i = 0; i < selectedNodes.length; i++ ) {
_buffer.push( selectedNodes[ i ] ); _buffer.push( selectedNodes[ i ] );
...@@ -167,7 +165,7 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -167,7 +165,7 @@ KityMinder.registerModule( "LayoutModule", function () {
}, },
queryState: function ( km ) { queryState: function ( km ) {
var selectedNodes = km.getSelectedNodes(); var selectedNodes = km.getSelectedNodes();
if ( ( selectedNodes.length === 1 && selectedNodes[ 0 ] === km.getRoot() ) || selectedNodes.length === 0 ) { if ( selectedNodes.length === 0 || ( selectedNodes.length === 1 && selectedNodes[ 0 ] === km.getRoot() ) ) {
return -1; return -1;
} else { } else {
return 0; return 0;
......
...@@ -29,9 +29,11 @@ KityMinder.registerModule( "Select", function () { ...@@ -29,9 +29,11 @@ KityMinder.registerModule( "Select", function () {
startPosition = g.snapToSharp( e.getPosition() ); startPosition = g.snapToSharp( e.getPosition() );
}, },
selectMove: function ( e ) { selectMove: function ( e ) {
if ( minder.isTextEditStatus() ) {
return;
}
if ( !startPosition ) return; if ( !startPosition ) return;
var p1 = startPosition, var p1 = startPosition,
p2 = e.getPosition(); p2 = e.getPosition();
...@@ -65,7 +67,7 @@ KityMinder.registerModule( "Select", function () { ...@@ -65,7 +67,7 @@ KityMinder.registerModule( "Select", function () {
// 计算选中范围 // 计算选中范围
minder.getRoot().traverse( function ( node ) { minder.getRoot().traverse( function ( node ) {
var renderBox = node.getRenderContainer().getRenderBox(); var renderBox = node.getRenderContainer().getRenderBox( "top" );
if ( g.isBoxIntersect( renderBox, marquee ) ) { if ( g.isBoxIntersect( renderBox, marquee ) ) {
selectedNodes.push( node ); selectedNodes.push( node );
} }
...@@ -80,7 +82,7 @@ KityMinder.registerModule( "Select", function () { ...@@ -80,7 +82,7 @@ KityMinder.registerModule( "Select", function () {
} }
if ( marqueeMode ) { if ( marqueeMode ) {
marqueeShape.fadeOut( 200, 'ease', 0, function () { marqueeShape.fadeOut( 200, 'ease', 0, function () {
if(marqueeShape.remove) marqueeShape.remove(); if ( marqueeShape.remove ) marqueeShape.remove();
} ); } );
marqueeMode = false; marqueeMode = false;
} }
......
KityMinder.registerProtocal( "png", function () {
var LINE_ENDING = '\n',
TAB_CHAR = '\t';
function repeat( s, n ) {
var result = "";
while ( n-- ) result += s;
return result;
}
function encode( json, level ) {
var local = "";
level = level || 0;
local += repeat( TAB_CHAR, level );
local += json.data.text + LINE_ENDING;
if ( json.children ) {
json.children.forEach( function ( child ) {
local += encode( child, level + 1 );
} );
}
return local;
}
function isEmpty( line ) {
return !/\S/.test( line );
}
function getLevel( line ) {
var level = 0;
while ( line.charAt( level ) === TAB_CHAR ) level++;
return level;
}
function getNode( line ) {
return {
data: {
text: line.replace( new RegExp( '^' + TAB_CHAR + '*' ), '' )
}
};
}
function decode( local ) {
var json,
parentMap = {},
lines = local.split( LINE_ENDING ),
line, level, node;
function addChild( parent, child ) {
var children = parent.children || ( parent.children = [] );
children.push( child );
}
for ( var i = 0; i < lines.length; i++ ) {
line = lines[ i ];
if ( isEmpty( line ) ) continue;
level = getLevel( line );
node = getNode( line );
if ( level === 0 ) {
if ( json ) {
throw new Error( 'Invalid local format' );
}
json = node;
} else {
if ( !parentMap[ level - 1 ] ) {
throw new Error( 'Invalid local format' );
}
addChild( parentMap[ level - 1 ], node );
}
parentMap[ level ] = node;
}
return json;
}
var lastTry, lastResult;
function recognize( local ) {
if ( !Utils.isString( local ) ) return false;
lastTry = local;
try {
lastResult = decode( local );
} catch ( e ) {
lastResult = null;
}
return !!lastResult;
}
return {
fileDescription: 'png',
fileExtension: '.png',
encode: function ( json ) {
return encode( json, 0 );
},
decode: function ( local ) {
if ( lastTry == local && lastResult ) {
return lastResult;
}
return decode( local );
},
recognize: recognize,
recognizePriority: -1
};
} );
\ No newline at end of file
...@@ -51,7 +51,8 @@ ...@@ -51,7 +51,8 @@
//自动记录 //自动记录
autoRecord: true, autoRecord: true,
//最多记录条数 //最多记录条数
recordCount: 5 recordCount: 5,
enabledRecord:true
}, },
init: function( options ){ init: function( options ){
...@@ -133,6 +134,7 @@ ...@@ -133,6 +134,7 @@
*/ */
select: function( index ){ select: function( index ){
var options = this.data( 'options' ), var options = this.data( 'options' ),
itemCount = options.itemCount, itemCount = options.itemCount,
items = options.autowidthitem; items = options.autowidthitem;
...@@ -162,6 +164,7 @@ ...@@ -162,6 +164,7 @@
this.trigger( 'changebefore', items[ index ] ); this.trigger( 'changebefore', items[ index ] );
this._update( index ); this._update( index );
this.trigger( 'changeafter', items[ index ] ); this.trigger( 'changeafter', items[ index ] );
...@@ -330,22 +333,25 @@ ...@@ -330,22 +333,25 @@
var options = this.data("options"), var options = this.data("options"),
newStack = []; newStack = [];
$.each( options.recordStack, function( i, item ){ if(this.data('options').enabledRecord){
$.each( options.recordStack, function( i, item ){
if( item != index ) { if( item != index ) {
newStack.push( item ); newStack.push( item );
} }
} ); } );
//压入最新的记录
newStack.unshift( index );
//压入最新的记录 if( newStack.length > options.recordCount ) {
newStack.unshift( index ); newStack.length = options.recordCount;
}
if( newStack.length > options.recordCount ) { options.recordStack = newStack;
newStack.length = options.recordCount;
} }
options.recordStack = newStack;
options.selected = index; options.selected = index;
this._repaint(); this._repaint();
......
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