Commit 4540940b authored by Ronny's avatar Ronny

Merge remote-tracking branch 'origin/dev' into dev

parents 96fdebdb dc9d662f
# KityMinder 更新日志
## v1.2.0
## v1.1.2
### 功能更新
1. 支持本地格式文件导入
* 支持文件拖拽和网盘文件导入
* 格式支持xmind/freemind/mindmanager,其他格式不支持
* 支持标签,包括优先级和任务进度
* 格式支持 xmind/freemind/mindmanager,其他格式不支持
2. 新增节点移动到视野中
3. 当前文件名加到 Title 中
4. 分享链接直接到粘贴板(针对已经支持的浏览器)
5. 分享到社交网络
6. 用户登出功能
7. 添加只读模式,配置项 readOnly,添加动态调用接口setEnabled,setDisabled
8. 优化当下拉菜单不可执行时,下拉菜单按钮会自动变灰
9. 新图标
### 问题修复
1. 导出 png 和 svg 图片时,文本中如果包含 ` ` 字符会报错的问题
2. 删除中心节点导致页面卡住
3. 文件在IE下无法导出(.txt,.svg,.km)
4. 拖入文件导入之后,草稿箱和社会化文件名不同步
5. 仅有根节点时,将其删除,再添加节点报错
6. 本地部署,127.0.0.1退出后不能登录
7. 去掉了“导出”菜单上的打勾
## v1.1.1
......
The MIT License (MIT)
Copyright (c) 2014, FEX,Baidu.
All rights reserved.
Copyright (c) 2013 KityMinder
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
......@@ -44,6 +44,7 @@
<a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a>
</p>
</div>
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdMini":"2","bdMiniList":[],"bdPic":"","bdStyle":"1","bdSize":"32"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
</body>
<script>
......
......@@ -2,14 +2,20 @@
<html>
<head>
<meta charset="utf-8">
<script src="../lib/jquery-2.1.0.min.js" charset="utf-8"></script>
<script src="../lib/ZeroClipboard.min.js" charset="utf-8"></script>
<script type="text/javascript">
ZeroClipboard.setDefaults( { moviePath: '../lib/ZeroClipboard.swf' } );
</script>
<script src="../kity/dist/kitygraph.all.min.js" charset="utf-8"></script>
<script src="../dist/kityminder.all.min.js" charset="utf-8"></script>
<script src="../kityminder.config.js" charset="utf-8"></script>
<script src="../lang/zh-cn/zh-cn.js" charset="utf-8"></script>
<script src="../lib/zip.js" charset="utf-8"></script>
<script src="../lib/jquery.xml2json.js" charset="utf-8"></script>
<script src="../lib/baidu-frontia-js-full-1.0.0.js" charset="utf-8"></script>
<script src="../social/draftmanager.js" charset="utf-8"></script>
<script src="../social/social.js" charset="utf-8"></script>
......@@ -30,7 +36,7 @@
<h3>URL分享:</h3>
<p>
<input id="share-url" type="url" value="" />
<button id="copy-share-url" type="button">复制</button>
<button id="copy-share-url" data-clipboard-target="share-url" type="button">复制</button>
</p>
<h3>社交分享:</h3>
<p id="share-platform" class="bdsharebuttonbox">
......
/*!
* ====================================================
* kityminder - v1.0.0 - 2014-03-25
* kityminder - v1.0.0 - 2014-04-15
* https://github.com/fex-team/kityminder
* GitHub: https://github.com/fex-team/kityminder.git
* Copyright (c) 2014 f-cube @ FEX; Licensed MIT
......@@ -792,6 +792,9 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this._initContextmenu();
this._initModules();
if ( this.getOptions( 'readOnly' ) === true ) {
this.setDisabled();
}
this.fire( 'ready' );
},
getOptions: function ( key ) {
......@@ -948,6 +951,46 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
},
getStatus: function () {
return this._status;
},
setDisabled: function () {
var me = this;
//禁用命令
me.bkqueryCommandState = me.queryCommandState;
me.bkqueryCommandValue = me.queryCommandValue;
me.queryCommandState = function ( type ) {
var cmd = this._getCommand( type );
if ( cmd && cmd.enableReadOnly === false ) {
return me.bkqueryCommandState.apply( me, arguments );
}
return -1;
};
me.queryCommandValue = function ( type ) {
var cmd = this._getCommand( type );
if ( cmd && cmd.enableReadOnly === false ) {
return me.bkqueryCommandValue.apply( me, arguments );
}
return null;
};
this.setStatus( 'readonly' );
me.fire( 'interactchange' );
},
setEnabled: function () {
var me = this;
if ( me.bkqueryCommandState ) {
me.queryCommandState = me.bkqueryCommandState;
delete me.bkqueryCommandState;
}
if ( me.bkqueryCommandValue ) {
me.queryCommandValue = me.bkqueryCommandValue;
delete me.bkqueryCommandValue;
}
this.rollbackStatus();
me.fire( 'interactchange' );
}
} );
......@@ -993,7 +1036,8 @@ function exportNode( node ) {
var DEFAULT_TEXT = {
'root': 'maintopic',
'main': 'topic'
'main': 'topic',
'sub': 'topic'
};
function importNode( node, json, km ) {
......@@ -1001,14 +1045,14 @@ function importNode( node, json, km ) {
for ( var field in data ) {
node.setData( field, data[ field ] );
}
node.setText( data.text || km.getLang( DEFAULT_TEXT[ data.type ] ) );
node.setText( data.text || km.getLang( DEFAULT_TEXT[ node.getType() ] ) );
var childrenTreeData = json.children;
if ( !childrenTreeData ) return;
for ( var i = 0; i < childrenTreeData.length; i++ ) {
var childNode = new MinderNode();
importNode( childNode, childrenTreeData[ i ], km );
node.appendChild( childNode );
importNode( childNode, childrenTreeData[ i ], km );
}
return node;
}
......@@ -1058,14 +1102,27 @@ kity.extendClass( Minder, {
json = params.json || ( params.json = protocal.decode( local ) );
this._fire( new MinderEvent( 'preimport', params, false ) );
if ( typeof json === 'object' && 'then' in json ) {
var self = this;
json.then( local, function ( data ) {
self._afterImportData( data, params );
} );
} else {
this._afterImportData( json, params );
}
return this;
},
_afterImportData: function ( json, params ) {
this._fire( new MinderEvent( 'preimport', params, false ) );
// 删除当前所有节点
while ( this._root.getChildren().length ) {
this._root.removeChild( 0 );
}
var curLayout = this._root.getData( "currentstyle" );
this._root.setData();
this._root.setData( "currentstyle", curLayout );
importNode( this._root, json, this );
this._fire( new MinderEvent( 'import', params, false ) );
......@@ -1075,9 +1132,8 @@ kity.extendClass( Minder, {
this._firePharse( {
type: 'interactchange'
} );
return this;
}
} );
// 事件机制
......@@ -1107,6 +1163,10 @@ kity.extendClass( Minder, {
}
},
_firePharse: function ( e ) {
// //只读模式下强了所有的事件操作
// if(this.readOnly === true){
// return false;
// }
var beforeEvent, preEvent, executeEvent;
if ( e.type == 'DOMMouseScroll' ) {
......@@ -1477,7 +1537,8 @@ kity.extendClass( Minder, {
//这里只放不是由模块产生的默认参数
KM.defaultOptions = {
zIndex : 1000,
lang:'zh-cn'
lang:'zh-cn',
readyOnly:false
};
KityMinder.Geometry = ( function () {
......@@ -1797,7 +1858,6 @@ KityMinder.registerModule( "IconModule", function () {
_rc.addShapes( [ _bg, _percent ] );
node.getIconRc().addShape( _rc );
_rc.setTransform( new kity.Matrix().translate( left, 10 ) );
_percent.setTransform( 10, 10 );
switch ( val ) {
case 1:
break;
......@@ -1936,13 +1996,13 @@ KityMinder.registerModule( "LayoutModule", function () {
} );
this.getLayoutStyle( curStyle ).initStyle.call( this );
},
appendChildNode: function ( parent, node, index ) {
appendChildNode: function ( parent, node, focus, index ) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).appendChildNode.call( this, parent, node, index );
this.getLayoutStyle( curStyle ).appendChildNode.call( this, parent, node, focus, index );
},
appendSiblingNode: function ( sibling, node ) {
appendSiblingNode: function ( sibling, node, focus ) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).appendSiblingNode.call( this, sibling, node );
this.getLayoutStyle( curStyle ).appendSiblingNode.call( this, sibling, node, focus );
},
removeNode: function ( nodes ) {
var curStyle = this.getCurrentStyle();
......@@ -2000,12 +2060,18 @@ KityMinder.registerModule( "LayoutModule", function () {
var AppendChildNodeCommand = kity.createClass( "AppendChildNodeCommand", ( function () {
return {
base: Command,
execute: function ( km, node ) {
execute: function ( km, node, focus, silbling ) {
var parent = km.getSelectedNode();
if( !parent ){
return null;
}
if ( parent.getType() !== "root" && parent.getChildren().length !== 0 && parent.getData( "expand" ) === false ) {
km.expandNode( parent );
}
km.appendChildNode( parent, node );
km.appendChildNode( parent, node, focus, silbling );
km.select( node, true );
return node;
},
......@@ -2022,13 +2088,17 @@ KityMinder.registerModule( "LayoutModule", function () {
var AppendSiblingNodeCommand = kity.createClass( "AppendSiblingNodeCommand", ( function () {
return {
base: Command,
execute: function ( km, node ) {
execute: function ( km, node, focus ) {
var selectedNode = km.getSelectedNode();
if( !selectedNode ){
return null;
}
if ( selectedNode.isRoot() ) {
node.setType( "main" );
km.appendChildNode( selectedNode, node );
km.appendChildNode( selectedNode, node, focus );
} else {
km.appendSiblingNode( selectedNode, node );
km.appendSiblingNode( selectedNode, node, focus );
}
km.select( node, true );
return node;
......@@ -2048,6 +2118,11 @@ KityMinder.registerModule( "LayoutModule", function () {
return {
base: Command,
execute: function ( km ) {
if( km.getRoot().children.length == 0 ){
return;
}
var selectedNodes = km.getSelectedNodes();
var _root = km.getRoot();
var _buffer = [];
......@@ -2527,6 +2602,21 @@ KityMinder.registerModule( "LayoutDefault", function () {
Layout.shicon.update();
}
};
var showNodeInView = function( node ){
var padding = 5;
var viewport = minder.getPaper().getViewPort();
var offset = node.getRenderContainer().getRenderBox( minder.getRenderContainer() );
var tmpX = viewport.center.x * 2 - (offset.x + offset.width);
var tmpY = viewport.center.y * 2 - (offset.y + offset.height);
var dx = offset.x < 0 ? -offset.x : Math.min(tmpX, 0);
var dy = offset.y < 0 ? -offset.y : Math.min(tmpY, 0);
km.getRenderContainer().fxTranslate( dx, dy, 100, "easeOutQuint" );
};
var _style = {
highlightNode: function ( node ) {
var highlight = node.isHighlight();
......@@ -2619,7 +2709,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
}
_root.setPoint( _root.getLayout().x, _root.getLayout().y );
},
appendChildNode: function ( parent, node, sibling ) {
appendChildNode: function ( parent, node, focus, sibling ) {
minder.handelNodeInsert( node );
node.clearLayout();
var Layout = node.getLayout();
......@@ -2703,10 +2793,14 @@ KityMinder.registerModule( "LayoutDefault", function () {
translateNode( set[ i ] );
updateConnectAndshIcon( set[ i ] );
}
if( focus ){
showNodeInView( node );
}
},
appendSiblingNode: function ( sibling, node ) {
appendSiblingNode: function ( sibling, node, focus ) {
var parent = sibling.getParent();
this.appendChildNode( parent, node, sibling );
this.appendChildNode( parent, node, focus, sibling );
},
removeNode: function ( nodes ) {
while ( nodes.length !== 0 ) {
......@@ -3217,7 +3311,7 @@ KityMinder.registerModule( "LayoutBottom", function () {
this.appendChildNode( _cleanbuffer[ j ].getLayout().parent, _cleanbuffer[ j ] );
}
},
appendChildNode: function ( parent, node, sibling ) {
appendChildNode: function ( parent, node, focus, sibling ) {
node.clearLayout();
var parentLayout = parent.getLayout();
var expand = parent.getData( "expand" );
......@@ -3361,14 +3455,18 @@ KityMinder.registerModule( "LayoutBottom", function () {
// 选区管理
kity.extendClass( Minder, function () {
function highlightNode( km, node ) {
if( node ){
node.setTmpData( "highlight", true );
km.highlightNode( node );
}
}
function unhighlightNode( km, node ) {
if( node ){
node.setTmpData( "highlight", false );
km.highlightNode( node );
}
}
return {
_initSelection: function () {
this._selectedNodes = [];
......@@ -3493,7 +3591,7 @@ var ViewDragger = kity.createClass( "ViewDragger", {
lastPosition = null,
currentPosition = null;
this._minder.on( 'normal.beforemousedown', function ( e ) {
this._minder.on( 'normal.beforemousedown readonly.beforemousedown', function ( e ) {
// 点击未选中的根节点临时开启
if ( e.getTargetNode() == this.getRoot() &&
( !this.getRoot().isSelected() || !this.isSingleSelect() ) ) {
......@@ -3560,7 +3658,8 @@ KityMinder.registerModule( 'View', function () {
},
queryState: function ( minder ) {
return minder._viewDragger.isEnabled() ? 1 : 0;
}
},
enableReadOnly : false
} );
var CameraCommand = kity.createClass( "CameraCommand", {
......@@ -3572,7 +3671,8 @@ KityMinder.registerModule( 'View', function () {
dy = viewport.center.y - offset.y;
km.getRenderContainer().fxTranslate( dx, dy, 1000, "easeOutQuint" );
this.setContentChanged( false );
}
},
enableReadOnly : false
} );
return {
......@@ -3614,7 +3714,7 @@ KityMinder.registerModule( 'View', function () {
e.preventDefault();
},
'normal.dblclick': function ( e ) {
'normal.dblclick readonly.dblclick': function ( e ) {
if ( e.getTargetNode() ) return;
this.execCommand( 'camera', this.getRoot() );
}
......@@ -3900,6 +4000,10 @@ KityMinder.registerModule( "DragTree", function () {
KityMinder.registerModule( "DropFile", function () {
var social,
draftManager,
importing = false;
function init() {
var container = this.getPaper().getContainer();
container.addEventListener( 'dragover', onDragOver );
......@@ -3916,23 +4020,72 @@ KityMinder.registerModule( "DropFile", function () {
e.preventDefault();
e.stopPropagation();
var minder = this;
if ( e.dataTransfer.files ) {
var files = e.dataTransfer.files;
if ( files ) {
var file = files[ 0 ];
var ext = file.type || ( /(.)\w+$/ ).exec( file.name )[ 0 ];
if ( ( /xmind/g ).test( ext ) ) { //xmind zip
importSync( minder, file, 'xmind' );
} else if ( ( /mmap/g ).test( ext ) ) { // mindmanager zip
importSync( minder, file, 'mindmanager' );
} else if ( ( /mm/g ).test( ext ) ) { //freemind xml
importAsync( minder, file, 'freemind' );
} else { // txt json
importAsync( minder, file );
}
}
}
function afterImport() {
if ( !importing ) return;
createDraft( this );
social.setRemotePath( null, false );
this.execCommand( 'camera', this.getRoot() );
setTimeout(function() {
social.watchChanges( true );
}, 10);
importing = false;
}
// 同步加载文件
function importSync( minder, file, protocal ) {
social = social || window.social;
social.watchChanges( false );
importing = true;
minder.importData( file, protocal ); //zip文件的import是同步的
}
// 异步加载文件
function importAsync( minder, file, protocal ) {
var reader = new FileReader();
reader.onload = function ( e ) {
minder.importData( e.target.result );
importSync( minder, e.target.result, protocal );
};
reader.readAsText( e.dataTransfer.files[ 0 ] );
reader.readAsText( file );
}
function createDraft( minder ) {
draftManager = window.draftManager;
draftManager.create();
}
return {
events: {
ready: init
'ready': init,
'import': afterImport
}
};
} );
KityMinder.registerModule( "KeyboardModule", function () {
var min = Math.min,
max = Math.max,
abs = Math.abs,
sqrt = Math.sqrt,
exp = Math.exp;
function buildPositionNetwork( root ) {
var pointIndexes = [],
......@@ -3940,9 +4093,14 @@ KityMinder.registerModule( "KeyboardModule", function () {
root.traverse( function ( node ) {
p = node.getRenderContainer().getRenderBox( 'top' );
pointIndexes.push( {
x: p.x + p.width / 2,
y: p.y + p.height / 2,
node: node
left: p.x,
top: p.y,
right: p.x + p.width,
bottom: p.y + p.height,
width: p.width,
height: p.height,
node: node,
text: node.getText()
} );
} );
for ( var i = 0; i < pointIndexes.length; i++ ) {
......@@ -3950,34 +4108,84 @@ KityMinder.registerModule( "KeyboardModule", function () {
}
}
function quadOf( p ) {
return p.x > 0 ?
( p.y > 0 ? 1 : 2 ) :
( p.y < 0 ? 3 : 4 );
// 这是金泉的点子,赞!
// 求两个不相交矩形的最近距离
function getCoefedDistance( box1, box2 ) {
var xMin, xMax, yMin, yMax, xDist, yDist, dist, cx, cy;
xMin = min( box1.left, box2.left );
xMax = max( box1.right, box2.right );
yMin = min( box1.top, box2.top );
yMax = max( box1.bottom, box2.bottom );
xDist = xMax - xMin - box1.width - box2.width;
yDist = yMax - yMin - box1.height - box2.height;
if ( xDist < 0 ) dist = yDist;
else if ( yDist < 0 ) dist = xDist;
else dist = sqrt( xDist * xDist + yDist * yDist );
return {
cx: dist,
cy: dist
};
}
function findClosestPointsFor( pointIndexes, iFind ) {
var find = pointIndexes[ iFind ];
var matrix = new kity.Matrix().translate( -find.x, -find.y ).rotate( 45 );
var most = {}, quad;
var current;
var current, dist;
for ( var i = 0; i < pointIndexes.length; i++ ) {
if ( i == iFind ) continue;
current = matrix.transformPoint( pointIndexes[ i ].x, pointIndexes[ i ].y );
quad = quadOf( current );
if ( !most[ quad ] || current.length() < most[ quad ].point.length() ) {
most[ quad ] = {
point: current,
node: pointIndexes[ i ].node
current = pointIndexes[ i ];
dist = getCoefedDistance( current, find );
// left check
if ( current.right < find.left ) {
if ( !most.left || dist.cx < most.left.dist ) {
most.left = {
dist: dist.cx,
node: current.node
};
}
}
// right check
if ( current.left > find.right ) {
if ( !most.right || dist.cx < most.right.dist ) {
most.right = {
dist: dist.cx,
node: current.node
};
}
}
// top check
if ( current.bottom < find.top ) {
if ( !most.top || dist.cy < most.top.dist ) {
most.top = {
dist: dist.cy,
node: current.node
};
}
}
// bottom check
if ( current.top > find.bottom ) {
if ( !most.down || dist.cy < most.down.dist ) {
most.down = {
dist: dist.cy,
node: current.node
};
}
}
}
find.node._nearestNodes = {
right: most[ 1 ] && most[ 1 ].node || null,
top: most[ 2 ] && most[ 2 ].node || null,
left: most[ 3 ] && most[ 3 ].node || null,
down: most[ 4 ] && most[ 4 ].node || null
right: most.right && most.right.node || null,
top: most.top && most.top.node || null,
left: most.left && most.left.node || null,
down: most.down && most.down.node || null
};
}
......@@ -4008,11 +4216,11 @@ KityMinder.registerModule( "KeyboardModule", function () {
this.receiver.keydownNode = node;
switch ( e.originEvent.keyCode ) {
case keys.Enter:
this.execCommand( 'appendSiblingNode', new MinderNode( this.getLang().topic ) );
this.execCommand( 'appendSiblingNode', new MinderNode( this.getLang().topic ), true );
e.preventDefault();
break;
case keys.Tab:
this.execCommand( 'appendChildNode', new MinderNode( this.getLang().topic ) );
this.execCommand( 'appendChildNode', new MinderNode( this.getLang().topic ), true );
e.preventDefault();
break;
case keys.Backspace:
......@@ -4216,7 +4424,6 @@ KityMinder.registerModule( "TextEditModule", function () {
},
"events": {
'normal.beforemousedown textedit.beforemousedown':function(e){
if(e.isRightMB()){
e.stopPropagationImmediately();
return;
......@@ -4331,6 +4538,9 @@ KityMinder.registerModule( "TextEditModule", function () {
if(cmds[e.commandName]){
var node = km.getSelectedNode();
if( !node ){
return;
}
var textShape = node.getTextShape();
......@@ -4915,75 +5125,74 @@ Minder.Selection = kity.createClass( 'Selection', {
KityMinder.registerModule( "basestylemodule", function () {
var km = this;
return {
"commands": {
"bold": kity.createClass( "boldCommand", {
base: Command,
execute: function ( ) {
execute: function () {
var nodes = km.getSelectedNodes();
if(this.queryState('bold') == 1){
utils.each(nodes,function(i,n){
n.setData('bold');
n.getTextShape().setAttr('font-weight');
km.updateLayout(n)
})
}else{
utils.each(nodes,function(i,n){
n.setData('bold',true);
n.getTextShape().setAttr('font-weight','bold');
km.updateLayout(n)
})
if ( this.queryState( 'bold' ) == 1 ) {
utils.each( nodes, function ( i, n ) {
n.setData( 'bold' );
n.getTextShape().setAttr( 'font-weight' );
km.updateLayout( n )
} )
} else {
utils.each( nodes, function ( i, n ) {
n.setData( 'bold', true );
n.getTextShape().setAttr( 'font-weight', 'bold' );
km.updateLayout( n )
} )
}
},
queryState: function ( ) {
queryState: function () {
var nodes = km.getSelectedNodes(),
result = 0;
if(nodes.length == 0){
if ( nodes.length == 0 ) {
return -1;
}
utils.each(nodes,function(i,n){
if(n.getData('bold')){
utils.each( nodes, function ( i, n ) {
if ( n && n.getData( 'bold' ) ) {
result = 1;
return false;
}
});
} );
return result;
}
} ),
"italic": kity.createClass( "italicCommand", {
base: Command,
execute: function ( ) {
execute: function () {
var nodes = km.getSelectedNodes();
if(this.queryState('italic') == 1){
utils.each(nodes,function(i,n){
n.setData('italic');
n.getTextShape().setAttr('font-style');
km.updateLayout(n)
})
}else{
utils.each(nodes,function(i,n){
n.setData('italic',true);
n.getTextShape().setAttr('font-style','italic');
km.updateLayout(n)
})
if ( this.queryState( 'italic' ) == 1 ) {
utils.each( nodes, function ( i, n ) {
n.setData( 'italic' );
n.getTextShape().setAttr( 'font-style' );
km.updateLayout( n )
} )
} else {
utils.each( nodes, function ( i, n ) {
n.setData( 'italic', true );
n.getTextShape().setAttr( 'font-style', 'italic' );
km.updateLayout( n )
} )
}
},
queryState: function ( ) {
queryState: function () {
var nodes = km.getSelectedNodes(),
result = 0;
if(nodes.length == 0){
if ( nodes.length == 0 ) {
return -1;
}
utils.each(nodes,function(i,n){
if(n.getData('italic')){
utils.each( nodes, function ( i, n ) {
if ( n && n.getData( 'italic' ) ) {
result = 1;
return false;
}
});
} );
return result;
}
} )
......@@ -4995,12 +5204,12 @@ KityMinder.registerModule( "basestylemodule", function () {
"events": {
"beforeRenderNode": function ( e ) {
//加粗
if(e.node.getData('bold')){
e.node.getTextShape().setAttr('font-weight','bold');
if ( e.node.getData( 'bold' ) ) {
e.node.getTextShape().setAttr( 'font-weight', 'bold' );
}
if(e.node.getData('italic')){
e.node.getTextShape().setAttr('font-style','italic');
if ( e.node.getData( 'italic' ) ) {
e.node.getTextShape().setAttr( 'font-style', 'italic' );
}
}
}
......@@ -5158,7 +5367,8 @@ KityMinder.registerModule( 'Zoom', function () {
},
queryState: function ( minder ) {
return ( minder._zoomValue > 1 / MAX_ZOOM ) ? 0 : -1;
}
},
enableReadOnly : false
} );
var ZoomOutCommand = kity.createClass( 'ZoomOutCommand', {
......@@ -5170,7 +5380,8 @@ KityMinder.registerModule( 'Zoom', function () {
},
queryState: function ( minder ) {
return ( minder._zoomValue < 1 / MIN_ZOOM ) ? 0 : -1;
}
},
enableReadOnly : false
} );
return {
......@@ -5196,7 +5407,7 @@ KityMinder.registerModule( 'Zoom', function () {
'ready': function () {
this._zoomValue = 1;
},
'normal.mousewheel': function ( e ) {
'normal.mousewheel readonly.mousewheel': function ( e ) {
if ( !e.originEvent.ctrlKey ) return;
var delta = e.originEvent.wheelDelta;
var me = this;
......@@ -6909,8 +7120,11 @@ utils.extend( KityMinder, function () {
} );
btns.length && $toolbar.kmui().appendToBtnmenu( btns );
} );
}
$toolbar.append( $( '<div class="kmui-dialog-container"></div>' ) );
}else{
$toolbar.hide()
}
},
_createStatusbar: function ( $statusbar, km ) {
......@@ -7197,10 +7411,12 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
utils.each( KityMinder.getAllRegisteredProtocals(), function ( k ) {
var p = KityMinder.findProtocal( k );
if( p.encode ){
var text = p.fileDescription + '(' + p.fileExtension + ')';
options.value.push( k );
options.items.push( text );
options.autowidthitem.push( $.wordCountAdaptive( text ), true );
}
} );
......@@ -7309,7 +7525,7 @@ KM.registerToolbarUI( 'switchlayout', function ( name ) {
});
//实例化
$combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui();
var comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( name, res.value );
......@@ -7324,6 +7540,7 @@ KM.registerToolbarUI( 'switchlayout', function ( name ) {
var state = this.queryCommandState( name ),
value = this.queryCommandValue( name );
//设置按钮状态
comboboxWidget.button().kmui().disabled( state == -1 ).active( state == 1 );
if ( value ) {
......@@ -7331,6 +7548,7 @@ KM.registerToolbarUI( 'switchlayout', function ( name ) {
value = value.replace( /['"]/g, '' ).toLowerCase().split( /['|"]?\s*,\s*[\1]?/ );
comboboxWidget.selectItemByLabel( value );
}
} );
var data = [];
......@@ -7377,10 +7595,10 @@ KM.registerToolbarUI( 'node', function ( name ) {
//实例化
$combox = $.kmuibuttoncombobox( transForInserttopic( options ) ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui();
var comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( res.value, new MinderNode( me.getLang().topic ) );
me.execCommand( res.value, new MinderNode( me.getLang().topic ), true );
} ).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
......@@ -7395,7 +7613,20 @@ KM.registerToolbarUI( 'node', function ( name ) {
}
} )
} );
//状态反射
me.on( 'interactchange', function () {
var state = 0;
utils.each(shortcutKeys,function(k){
state = me.queryCommandState(k);
if(state!=-1){
return false;
}
});
//设置按钮状态
comboboxWidget.button().kmui().disabled( state == -1 ).active( state == 1 );
} );
//comboboxWidget.button().kmui().disabled(-1);
return comboboxWidget.button().addClass( 'kmui-combobox' );
......@@ -7536,6 +7767,316 @@ KM.registerToolbarUI( 'markers help', function ( name ) {
return $btn;
} );
/*
http://www.xmind.net/developer/
Parsing XMind file
XMind files are generated in XMind Workbook (.xmind) format, an open format that is based on the principles of OpenDocument. It consists of a ZIP compressed archive containing separate XML documents for content and styles, a .jpg image file for thumbnails, and directories for related attachments.
*/
KityMinder.registerProtocal( 'xmind', function () {
// 标签 map
var markerMap = {
'priority-1' : ['PriorityIcon', 1]
,'priority-2' : ['PriorityIcon', 2]
,'priority-3' : ['PriorityIcon', 3]
,'priority-4' : ['PriorityIcon', 4]
,'priority-5' : ['PriorityIcon', 5]
,'task-start' : ['ProgressIcon', 1]
,'task-quarter' : ['ProgressIcon', 2]
,'task-half' : ['ProgressIcon', 3]
,'task-3quar' : ['ProgressIcon', 4]
,'task-done' : ['ProgressIcon', 5]
,'task-oct' : null
,'task-3oct' : null
,'task-5oct' : null
,'task-7oct' : null
};
function processTopic(topic, obj){
//处理文本
obj.data = { text : topic.title };
// 处理标签
if(topic.marker_refs && topic.marker_refs.marker_ref){
var markers = topic.marker_refs.marker_ref;
if( markers.length && markers.length > 0 ){
for (var i in markers) {
var type = markerMap[ markers[i]['marker_id'] ];
type && (obj.data[ type[0] ] = type[1]);
}
}else{
var type = markerMap[ markers['marker_id'] ];
type && (obj.data[ type[0] ] = type[1]);
}
}
//处理子节点
if( topic.children && topic.children.topics && topic.children.topics.topic ){
var tmp = topic.children.topics.topic;
if( tmp.length && tmp.length > 0 ){ //多个子节点
obj.children = [];
for(var i in tmp){
obj.children.push({});
processTopic(tmp[i], obj.children[i]);
}
}else{ //一个子节点
obj.children = [{}];
processTopic(tmp, obj.children[0]);
}
}
}
function xml2km(xml){
var json = $.xml2json(xml);
var result = {};
var sheet = json.sheet;
var topic = utils.isArray(sheet) ? sheet[0].topic : sheet.topic;
processTopic(topic, result);
return result;
}
function getEntries(file, onend) {
zip.createReader(new zip.BlobReader(file), function(zipReader) {
zipReader.getEntries(onend);
}, onerror);
}
return {
fileDescription: 'xmind格式文件',
fileExtension: '.xmind',
decode: function ( local ) {
return {
then : function(local, callback){
getEntries( local, function( entries ) {
entries.forEach(function( entry ) {
if(entry.filename == 'content.xml'){
entry.getData(new zip.TextWriter(), function(text) {
var km = xml2km($.parseXML(text));
callback && callback( km );
});
}
});
});
}
};
},
// recognize: recognize,
recognizePriority: -1
};
} );
/*
http://freemind.sourceforge.net/
freemind文件后缀为.mm,实际格式为xml
*/
KityMinder.registerProtocal( 'freemind', function () {
// 标签 map
var markerMap = {
'full-1' : ['PriorityIcon', 1]
,'full-2' : ['PriorityIcon', 2]
,'full-3' : ['PriorityIcon', 3]
,'full-4' : ['PriorityIcon', 4]
,'full-5' : ['PriorityIcon', 5]
,'full-6' : null
,'full-7' : null
,'full-8' : null
,'full-9' : null
,'full-0' : null
};
function processTopic(topic, obj){
//处理文本
obj.data = { text : topic.TEXT };
// 处理标签
if(topic.icon){
var icons = topic.icon;
if(icons.length && icons.length > 0){
for (var i in icons) {
var type = markerMap[ icons[i]['BUILTIN'] ];
type && (obj.data[ type[0] ] = type[1]);
}
}else{
var type = markerMap[ icons['BUILTIN'] ];
type && (obj.data[ type[0] ] = type[1]);
}
}
//处理子节点
if( topic.node ){
var tmp = topic.node;
if( tmp.length && tmp.length > 0 ){ //多个子节点
obj.children = [];
for(var i in tmp){
obj.children.push({});
processTopic(tmp[i], obj.children[i]);
}
}else{ //一个子节点
obj.children = [{}];
processTopic(tmp, obj.children[0]);
}
}
}
function xml2km(xml){
var json = $.xml2json(xml);
var result = {};
processTopic(json.node, result);
return result;
}
return {
fileDescription: 'xmind格式文件',
fileExtension: '.xmind',
decode: function ( local ) {
var json = xml2km( local );
return json;
},
// recognize: recognize,
recognizePriority: -1
};
} );
/*
http://www.mindjet.com/mindmanager/
mindmanager的后缀为.mmap,实际文件格式是zip,解压之后核心文件是Document.xml
*/
KityMinder.registerProtocal( 'mindmanager', function () {
// 标签 map
var markerMap = {
'urn:mindjet:Prio1' : ['PriorityIcon', 1]
,'urn:mindjet:Prio2' : ['PriorityIcon', 2]
,'urn:mindjet:Prio3' : ['PriorityIcon', 3]
,'urn:mindjet:Prio4' : ['PriorityIcon', 4]
,'urn:mindjet:Prio5' : ['PriorityIcon', 5]
,'0' : ['ProgressIcon', 1]
,'25' : ['ProgressIcon', 2]
,'50' : ['ProgressIcon', 3]
,'75' : ['ProgressIcon', 4]
,'100' : ['ProgressIcon', 5]
};
function processTopic(topic, obj){
//处理文本
obj.data = { text : topic.Text && topic.Text.PlainText || '' }; // 节点默认的文本,没有Text属性
// 处理标签
if(topic.Task){
var type;
if(topic.Task.TaskPriority){
type = markerMap[ topic.Task.TaskPriority ];
type && (obj.data[ type[0] ] = type[1]);
}
if(topic.Task.TaskPercentage){
type = markerMap[ topic.Task.TaskPercentage ];
type && (obj.data[ type[0] ] = type[1]);
}
}
//处理子节点
if( topic.SubTopics && topic.SubTopics.Topic ){
var tmp = topic.SubTopics.Topic;
if( tmp.length && tmp.length > 0 ){ //多个子节点
obj.children = [];
for(var i in tmp){
obj.children.push({});
processTopic(tmp[i], obj.children[i]);
}
}else{ //一个子节点
obj.children = [{}];
processTopic(tmp, obj.children[0]);
}
}
}
function xml2km(xml){
var json = $.xml2json(xml);
var result = {};
processTopic(json.OneTopic.Topic, result);
return result;
}
function getEntries(file, onend) {
zip.createReader(new zip.BlobReader(file), function(zipReader) {
zipReader.getEntries(onend);
}, onerror);
}
return {
fileDescription: 'mindmanager格式文件',
fileExtension: '.mmap',
decode: function ( local ) {
return {
then : function(local, callback){
getEntries( local, function( entries ) {
entries.forEach(function( entry ) {
if(entry.filename == 'Document.xml'){
entry.getData(new zip.TextWriter(), function(text) {
var km = xml2km($.parseXML(text));
callback && callback( km );
});
}
});
});
}
};
},
// recognize: recognize,
recognizePriority: -1
};
} );
KityMinder.registerProtocal( "plain", function () {
var LINE_ENDING = '\n',
TAB_CHAR = '\t';
......@@ -7708,6 +8249,9 @@ KityMinder.registerProtocal( "png", function () {
// need a xml with width and height
svgXml = $( '<div></div' ).append( $svg ).html();
// svg 含有 &nbsp; 符号导出报错 Entity 'nbsp' not defined
svgXml = svgXml.replace(/&nbsp;/g, '&#xa0;');
blob = new Blob( [ svgXml ], {
type: "image/svg+xml;charset=utf-8"
} );
......@@ -7764,7 +8308,8 @@ KityMinder.registerProtocal( "svg", function () {
fileDescription: 'SVG 矢量图',
fileExtension: '.svg',
encode: function ( json, km ) {
return km.getPaper().container.innerHTML;
// svg 含有 &nbsp; 符号导出报错 Entity 'nbsp' not defined
return km.getPaper().container.innerHTML.replace( /&nbsp;/g, '&#xa0;' );
},
recognizePriority: -1
};
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -62,11 +62,12 @@
window.KITYMINDER_CONFIG = {
'KITYMINDER_HOME_URL': getKMBasePath()
//定义工具栏
,toolbars: [
,
toolbars: [
'hand zoom-in zoom-out | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers | node | switchlayout | help'
]
],
//只读模式,默认是false
//readOnly : false
//readOnly: true
//设置主题
//,defaultlayoutstyle : 'default' //设置默认的主题
......@@ -81,4 +82,4 @@
//设置km整体的z-index大小
//,zIndex : 1000
};
} )()
\ No newline at end of file
} )();
\ No newline at end of file
......@@ -77,7 +77,7 @@ $( function () {
// 脑图实例
minder = window.km,
// 草稿箱
draftManager = window.draftManager || new window.DraftManager( minder ),
draftManager = window.draftManager || ( window.draftManager = new window.DraftManager( minder ) ),
// 当前是否要检测文档内容是否变化的开关
watchingChanges = true,
......@@ -681,4 +681,10 @@ $( function () {
return "很久之前";
}
window.social = {
setRemotePath: setRemotePath,
watchChanges: function ( value ) {
watchingChanges = value;
}
};
} );
\ No newline at end of file
/**
* Created by dongyancen on 14-3-26.
*/
var fs = require('fs');
var browsers = ['Chrome', 'Firefox', 'PhantomJS', 'IE'];
var result_forBrowser = {};
var jsonFileBasePath = './spec/coverage/json_files/';
var jsonFiles = fs.readdirSync(jsonFileBasePath);
var finalJsonFile = 'defaultFileName';
var curPath = '/spec';
var resultPath = 'spec/coverage';
//找出所有的json文件
for (var i = 0; i < jsonFiles.length; i++) {
// json文件名必须是有8位的日期和6位的时间戳如:-20140326_161249
if (!isJsonFiles(jsonFiles[i])) {
jsonFiles.splice(i, 1);
i--;
}
}
//没有找到合适的文件
if(jsonFiles.length==0)return;
//先排序 按时间从小到大 及从旧到新
jsonFiles.sort(function (f1, f2) {
var t1 = getFileTime(f1);//形如['-20140326_161249','20140326','161249']
var t2 = getFileTime(f2);
var dateDiff = parseInt(t1[1]) - parseInt(t2[1]);
if (dateDiff != 0)return dateDiff;
else return parseInt(t1[2]) - parseInt(t2[2]);
});
//以时间命名新的文件
finalJsonFile = getFileTime(jsonFiles[jsonFiles.length-1])[0].substring(1);
//如:20140326_161249
//取最新的
// 按浏览器类型分类 result_forBrowser属性形如:{'Crome':'filename1','Firefox':'filename2'}
for (i = 0; i < jsonFiles.length; i++) {
for (var j = 0; j < browsers.length; j++) {
if (eval('/' + browsers[j] + '/.test("' + jsonFiles[i] + '");')) {
eval('result_forBrowser.' + browsers[j] + '="' + jsonFiles[i] + '";');
}
}
}
//以上得到所有要合计的json文件
//读取,合计数字,需要合计的属性: 's' 'b' 'f' 'l'
//修正路径
var jsonToWrite = null;
for (var a in result_forBrowser) {
var r = fs.readFileSync(jsonFileBasePath + result_forBrowser[a]);
if (!jsonToWrite) {
jsonToWrite = JSON.parse(r);
continue;
} else {
jsonToWrite = mergeResult(jsonToWrite, JSON.parse(r));
}
}
//写文件
fs.writeFileSync(jsonFileBasePath+finalJsonFile+'.json',JSON.stringify(jsonToWrite));
function isJsonFiles(fileName) {
var e = fileName.substring(fileName.lastIndexOf(".") + 1);
// json文件名必须是有8位的日期和6位的时间戳如:-20140326_161249
//否则无法判断文件生成时间,也就无法合并同一次运行产生的结果
return e == 'json' && getFileTime(fileName);
}
function getFileTime(fileName) {
// json文件名必须是有8位的日期和6位的时间戳如:-20140326_161249
return fileName.match(/-(\d{8})_(\d{6})/);
}
function mergeResult(allR, addR) {
var resultR = {};
for (var allRKey in allR) {
if (addR[allRKey]) {
allR[allRKey] = mergeDetail(allR[allRKey], addR[allRKey], 's', 1);
allR[allRKey] = mergeDetail(allR[allRKey], addR[allRKey], 'f', 1);
allR[allRKey] = mergeDetail(allR[allRKey], addR[allRKey], 'l', 1);
allR[allRKey] = mergeDetail(allR[allRKey], addR[allRKey], 'b', 2);
}
//修正路径
resultR[fixPath(allRKey)] = allR[allRKey]
}
return resultR;
}
//type = 1 合并 s f l ,如:{"1":1,"2":1,"3":1}
//type = 2 合并 b ,如:{"1":[0,0],"2":[0,0]}
function mergeDetail(allEle, addEle, attrName, type) {
if (allEle[attrName] && addEle[attrName]) {
if (type == 1) {
for (var k in allEle[attrName]) {
//todo 现在没有考虑两个文件中同一项覆盖率的统计行数不一致的问题
if ( parseInt(allEle[attrName][k])==0 && parseInt(addEle[attrName][k]) ==1) {
allEle[attrName][k] = 1;
}
}
}
else if (type == 2) {
for (var k in allEle[attrName]) {
//todo 现在没有考虑两个文件中同一项覆盖率的统计行数不一致的问题
if (addEle[attrName][k]) {
if (parseInt(allEle[attrName][k][0])==0 &&parseInt(addEle[attrName][k][0])==1 ) {
allEle[attrName][k][0] = 1;
}
if (parseInt(allEle[attrName][k][1])==0 &&parseInt(addEle[attrName][k][1])==1 ) {
allEle[attrName][k][1] = 1;
}
}
}
}
}
return allEle;
}
//修正路径
function fixPath(oldPath){
//例如把 "D:/workspace/ufinder/_src/core/finder.js" 修正为
// spec/coverage/_src/core/finder.js 注意这里一定要用相对路径(相对于_spec/coverage)
var s = __dirname.replace(/\\/g,'/');
if(s.lastIndexOf(curPath)){
s = s.substring(0,s.lastIndexOf(curPath) );
}
oldPath = oldPath.replace(s,resultPath);
return oldPath;
}
console.log(finalJsonFile);
\ No newline at end of file
setlocal EnableDelayedExpansion
del /q /s .\spec\coverage\json_files\*.json
rd /s /q .\coverage
for /f %%j in ('karma start ./spec/karma.conf.js') do set karmaRe=%%j
for /f %%i in ('node ./spec/mergeCoverageForIstanbul.js') do set re=%%i
for /f %%i in ('node ./spec/_mergeCoverageForIstanbul.js') do set re=%%i
istanbul report html spec/coverage/json_files/%re%.json
\ No newline at end of file
......@@ -4,7 +4,7 @@
var fs = require('fs');
var browsers = ['Chrome', 'Firefox', 'PhantomJS', 'IE'];
var result_forBrowser = {};
var jsonFileBasePath = './spec/coverage/json_files/';
var jsonFileBasePath = './coverage/json_files/';
var jsonFiles = fs.readdirSync(jsonFileBasePath);
var finalJsonFile = 'defaultFileName';
var curPath = '/spec';
......
......@@ -3,4 +3,3 @@ del /q /s .\coverage\json_files\*.json
for /f %%j in ('karma start ./karma.conf.js') do set karmaRe=%%j
for /f %%i in ('node ./mergeCoverageForIstanbul.js') do set re=%%i
istanbul report html coverage/json_files/%re%.json
pause
......@@ -55,8 +55,11 @@ utils.extend( KityMinder, function () {
} );
btns.length && $toolbar.kmui().appendToBtnmenu( btns );
} );
}
$toolbar.append( $( '<div class="kmui-dialog-container"></div>' ) );
}else{
$toolbar.hide()
}
},
_createStatusbar: function ( $statusbar, km ) {
......
......@@ -22,7 +22,7 @@ KM.registerToolbarUI( 'switchlayout', function ( name ) {
});
//实例化
$combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui();
var comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( name, res.value );
......@@ -37,6 +37,7 @@ KM.registerToolbarUI( 'switchlayout', function ( name ) {
var state = this.queryCommandState( name ),
value = this.queryCommandValue( name );
//设置按钮状态
comboboxWidget.button().kmui().disabled( state == -1 ).active( state == 1 );
if ( value ) {
......@@ -44,6 +45,7 @@ KM.registerToolbarUI( 'switchlayout', function ( name ) {
value = value.replace( /['"]/g, '' ).toLowerCase().split( /['|"]?\s*,\s*[\1]?/ );
comboboxWidget.selectItemByLabel( value );
}
} );
var data = [];
......
......@@ -25,7 +25,7 @@ KM.registerToolbarUI( 'node', function ( name ) {
//实例化
$combox = $.kmuibuttoncombobox( transForInserttopic( options ) ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui();
var comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( res.value, new MinderNode( me.getLang().topic ), true );
......@@ -43,7 +43,20 @@ KM.registerToolbarUI( 'node', function ( name ) {
}
} )
} );
//状态反射
me.on( 'interactchange', function () {
var state = 0;
utils.each( shortcutKeys, function ( k ) {
state = me.queryCommandState( k );
if ( state != -1 ) {
return false;
}
} );
//设置按钮状态
comboboxWidget.button().kmui().disabled( state == -1 ).active( state == 1 );
} );
//comboboxWidget.button().kmui().disabled(-1);
return comboboxWidget.button().addClass( 'kmui-combobox' );
......
......@@ -10,14 +10,15 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
itemStyles: [],
value: [],
autowidthitem: [],
enabledRecord: false
enabledRecord: false,
enabledSelected:false
},
$combox = null,
comboboxWidget = null;
utils.each( KityMinder.getAllRegisteredProtocals(), function ( k ) {
var p = KityMinder.findProtocal( k );
if( p.encode ){
if ( p.encode ) {
var text = p.fileDescription + '(' + p.fileExtension + ')';
options.value.push( k );
options.items.push( text );
......@@ -34,20 +35,58 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
var a = document.createElement( 'a' );
a.setAttribute( 'download', filename );
a.setAttribute( 'href', url );
a.dispatchEvent( new MouseEvent( 'click' ) );
var evt;
try {
evt = new MouseEvent( 'click' );
} catch ( error ) {
evt = document.createEvent( 'MouseEvents' );
evt.initEvent( 'click', true, true );
}
a.dispatchEvent( evt );
}
var ie_ver = function () {
var iev = 0;
var ieold = ( /MSIE (\d+\.\d+);/.test( navigator.userAgent ) );
var trident = !! navigator.userAgent.match( /Trident\/7.0/ );
var rv = navigator.userAgent.indexOf( "rv:11.0" );
if ( ieold ) iev = new Number( RegExp.$1 );
if ( navigator.appVersion.indexOf( "MSIE 10" ) != -1 ) iev = 10;
if ( trident && rv != -1 ) iev = 11;
return iev;
};
var doSave = function ( urltype, d, filename ) {
var iframe = document.createElement( 'iframe' );
iframe.style.display = 'none';
document.body.appendChild( iframe );
iframe.contentDocument.open( urltype, 'replace' );
iframe.contentDocument.writeln( d );
iframe.contentDocument.execCommand( 'saveas', '', filename );
};
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
var data = me.exportData( res.value );
var p = KityMinder.findProtocal( res.value );
var filename = me.getMinderTitle() + p.fileExtension;
if ( typeof ( data ) == 'string' ) {
var url = 'data:text/plain; utf-8,' + encodeURI( data );
var url = 'data:text/plain; utf-8,' + encodeURIComponent( data );
if ( ie_ver() > 0 ) {
if ( p.fileExtension === '.km' ) {
console.log( "KM" );
doSave( 'application/x-javascript', data, me.getMinderTitle() );
} else {
doSave( 'text/html', data, filename );
}
} else {
doDownload( url, filename );
}
} else if ( data && data.then ) {
data.then( function ( url ) {
console.log( url );
if ( ie_ver() > 0 ) {
//doSave( 'application/base64', url.replace( 'image/octet-stream,', '' ), filename );
} else {
doDownload( url, filename );
}
} );
}
} ).on( "beforeshow", function () {
......
......@@ -10,7 +10,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this._initContextmenu();
this._initModules();
if(this.getOptions('readOnly') === true){
if ( this.getOptions( 'readOnly' ) === true ) {
this.setDisabled();
}
this.fire( 'ready' );
......@@ -41,6 +41,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this._root.setType( "root" );
if ( this._options.renderTo ) {
this.renderTo( this._options.renderTo );
//this._paper.setStyle( 'font-family', 'Arial,"Microsoft YaHei",sans-serif' );
}
},
_addRenderContainer: function () {
......@@ -170,45 +171,45 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
getStatus: function () {
return this._status;
},
setDisabled : function(){
setDisabled: function () {
var me = this;
//禁用命令
me.bkqueryCommandState = me.queryCommandState;
me.bkqueryCommandValue = me.queryCommandValue;
me.queryCommandState = function (type) {
var cmd = this._getCommand(type);
if(cmd && cmd.enableReadOnly === false){
return me.bkqueryCommandState.apply(me, arguments);
me.queryCommandState = function ( type ) {
var cmd = this._getCommand( type );
if ( cmd && cmd.enableReadOnly === false ) {
return me.bkqueryCommandState.apply( me, arguments );
}
return -1;
};
me.queryCommandValue = function (type) {
var cmd = this._getCommand(type);
if(cmd && cmd.enableReadOnly === false){
return me.bkqueryCommandValue.apply(me, arguments);
me.queryCommandValue = function ( type ) {
var cmd = this._getCommand( type );
if ( cmd && cmd.enableReadOnly === false ) {
return me.bkqueryCommandValue.apply( me, arguments );
}
return null;
};
this.setStatus('readonly');
this.setStatus( 'readonly' );
me.fire('interactchange');
me.fire( 'interactchange' );
},
setEnabled : function(){
setEnabled: function () {
var me = this;
if (me.bkqueryCommandState) {
if ( me.bkqueryCommandState ) {
me.queryCommandState = me.bkqueryCommandState;
delete me.bkqueryCommandState;
}
if (me.bkqueryCommandValue) {
if ( me.bkqueryCommandValue ) {
me.queryCommandValue = me.bkqueryCommandValue;
delete me.bkqueryCommandValue;
}
this.rollbackStatus();
me.fire('interactchange');
me.fire( 'interactchange' );
}
} );
......
KityMinder.registerModule( "basestylemodule", function () {
var km = this;
return {
"commands": {
"bold": kity.createClass( "boldCommand", {
base: Command,
execute: function ( ) {
execute: function () {
var nodes = km.getSelectedNodes();
if(this.queryState('bold') == 1){
utils.each(nodes,function(i,n){
n.setData('bold');
n.getTextShape().setAttr('font-weight');
km.updateLayout(n)
})
}else{
utils.each(nodes,function(i,n){
n.setData('bold',true);
n.getTextShape().setAttr('font-weight','bold');
km.updateLayout(n)
})
if ( this.queryState( 'bold' ) == 1 ) {
utils.each( nodes, function ( i, n ) {
n.setData( 'bold' );
n.getTextShape().setAttr( 'font-weight' );
km.updateLayout( n )
} )
} else {
utils.each( nodes, function ( i, n ) {
n.setData( 'bold', true );
n.getTextShape().setAttr( 'font-weight', 'bold' );
km.updateLayout( n )
} )
}
},
queryState: function ( ) {
queryState: function () {
var nodes = km.getSelectedNodes(),
result = 0;
if(nodes.length == 0){
if ( nodes.length == 0 ) {
return -1;
}
utils.each(nodes,function(i,n){
if( n && n.getData('bold') ){
utils.each( nodes, function ( i, n ) {
if ( n && n.getData( 'bold' ) ) {
result = 1;
return false;
}
});
} );
return result;
}
} ),
"italic": kity.createClass( "italicCommand", {
base: Command,
execute: function ( ) {
execute: function () {
var nodes = km.getSelectedNodes();
if(this.queryState('italic') == 1){
utils.each(nodes,function(i,n){
n.setData('italic');
n.getTextShape().setAttr('font-style');
km.updateLayout(n)
})
}else{
utils.each(nodes,function(i,n){
n.setData('italic',true);
n.getTextShape().setAttr('font-style','italic');
km.updateLayout(n)
})
if ( this.queryState( 'italic' ) == 1 ) {
utils.each( nodes, function ( i, n ) {
n.setData( 'italic' );
n.getTextShape().setAttr( 'font-style' );
km.updateLayout( n )
} )
} else {
utils.each( nodes, function ( i, n ) {
n.setData( 'italic', true );
n.getTextShape().setAttr( 'font-style', 'italic' );
km.updateLayout( n )
} )
}
},
queryState: function ( ) {
queryState: function () {
var nodes = km.getSelectedNodes(),
result = 0;
if(nodes.length == 0){
if ( nodes.length == 0 ) {
return -1;
}
utils.each(nodes,function(i,n){
if( n && n.getData('italic') ){
utils.each( nodes, function ( i, n ) {
if ( n && n.getData( 'italic' ) ) {
result = 1;
return false;
}
});
} );
return result;
}
} )
......@@ -81,12 +80,12 @@ KityMinder.registerModule( "basestylemodule", function () {
"events": {
"beforeRenderNode": function ( e ) {
//加粗
if(e.node.getData('bold')){
e.node.getTextShape().setAttr('font-weight','bold');
if ( e.node.getData( 'bold' ) ) {
e.node.getTextShape().setAttr( 'font-weight', 'bold' );
}
if(e.node.getData('italic')){
e.node.getTextShape().setAttr('font-style','italic');
if ( e.node.getData( 'italic' ) ) {
e.node.getTextShape().setAttr( 'font-style', 'italic' );
}
}
}
......
KityMinder.registerModule( "DropFile", function () {
var social,
draftManager,
importing = false;
function init() {
var container = this.getPaper().getContainer();
container.addEventListener( 'dragover', onDragOver );
......@@ -25,51 +29,58 @@ KityMinder.registerModule( "DropFile", function () {
var files = e.dataTransfer.files;
if ( files ) {
var file = files[0];
var ext = file.type || (/(.)\w+$/).exec(file.name)[0];
var file = files[ 0 ];
var ext = file.type || ( /(.)\w+$/ ).exec( file.name )[ 0 ];
if( (/xmind/g).test(ext) ){ //xmind zip
if ( ( /xmind/g ).test( ext ) ) { //xmind zip
importSync( minder, file, 'xmind' );
}else if( (/mmap/g).test(ext) ){ // mindmanager zip
} else if ( ( /mmap/g ).test( ext ) ) { // mindmanager zip
importSync( minder, file, 'mindmanager' );
}else if( (/mm/g).test(ext) ){ //freemind xml
} else if ( ( /mm/g ).test( ext ) ) { //freemind xml
importAsync( minder, file, 'freemind' );
}else{// txt json
} else { // txt json
importAsync( minder, file );
}
}
}
function afterImport() {
if ( !importing ) return;
createDraft( this );
social.setRemotePath( null, false );
this.execCommand( 'camera', this.getRoot() );
setTimeout(function() {
social.watchChanges( true );
}, 10);
importing = false;
}
// 同步加载文件
function importSync( minder, file, protocal ){
minder.importData( file, protocal );//zip文件的import是同步的
manageDraft( minder );
minder.execCommand( 'camera', minder.getRoot() );
function importSync( minder, file, protocal ) {
social = social || window.social;
social.watchChanges( false );
importing = true;
minder.importData( file, protocal ); //zip文件的import是同步的
}
// 异步加载文件
function importAsync( minder, file, protocal ){
function importAsync( minder, file, protocal ) {
var reader = new FileReader();
reader.onload = function ( e ) {
minder.importData( e.target.result, protocal );//纯文本文件的import是同步的
manageDraft( minder );
minder.execCommand( 'camera', minder.getRoot() );
importSync( minder, e.target.result, protocal );
};
reader.readAsText( file );
}
function manageDraft( minder ){
if( !window.draftManager ){
window.draftManager = new window.DraftManager( minder );
}
window.draftManager.create();
function createDraft( minder ) {
draftManager = window.draftManager;
draftManager.create();
}
return {
events: {
ready: init
'ready': init,
'import': afterImport
}
};
} );
\ No newline at end of file
......@@ -143,8 +143,8 @@ KityMinder.registerModule( "KeyboardModule", function () {
break;
case keys.Backspace:
case keys.Del:
this.execCommand( 'removenode' );
e.preventDefault();
if ( this.queryCommandState( 'removenode' ) !== -1 ) this.execCommand( 'removenode' );
break;
case keys.Left:
......
......@@ -411,7 +411,7 @@ KityMinder.registerModule( "LayoutBottom", function () {
this.appendChildNode( _cleanbuffer[ j ].getLayout().parent, _cleanbuffer[ j ] );
}
},
appendChildNode: function ( parent, node, sibling ) {
appendChildNode: function ( parent, node, focus, sibling ) {
node.clearLayout();
var parentLayout = parent.getLayout();
var expand = parent.getData( "expand" );
......
......@@ -10,68 +10,69 @@ KityMinder.registerProtocal( 'mindmanager', function () {
// 标签 map
var markerMap = {
'urn:mindjet:Prio1' : ['PriorityIcon', 1]
,'urn:mindjet:Prio2' : ['PriorityIcon', 2]
,'urn:mindjet:Prio3' : ['PriorityIcon', 3]
,'urn:mindjet:Prio4' : ['PriorityIcon', 4]
,'urn:mindjet:Prio5' : ['PriorityIcon', 5]
,'0' : ['ProgressIcon', 1]
,'25' : ['ProgressIcon', 2]
,'50' : ['ProgressIcon', 3]
,'75' : ['ProgressIcon', 4]
,'100' : ['ProgressIcon', 5]
'urn:mindjet:Prio1': [ 'PriorityIcon', 1 ],
'urn:mindjet:Prio2': [ 'PriorityIcon', 2 ],
'urn:mindjet:Prio3': [ 'PriorityIcon', 3 ],
'urn:mindjet:Prio4': [ 'PriorityIcon', 4 ],
'urn:mindjet:Prio5': [ 'PriorityIcon', 5 ],
'0': [ 'ProgressIcon', 1 ],
'25': [ 'ProgressIcon', 2 ],
'50': [ 'ProgressIcon', 3 ],
'75': [ 'ProgressIcon', 4 ],
'100': [ 'ProgressIcon', 5 ]
};
function processTopic(topic, obj){
function processTopic( topic, obj ) {
//处理文本
obj.data = { text : topic.Text && topic.Text.PlainText || '' }; // 节点默认的文本,没有Text属性
obj.data = {
text: topic.Text && topic.Text.PlainText || ''
}; // 节点默认的文本,没有Text属性
// 处理标签
if(topic.Task){
if ( topic.Task ) {
var type;
if(topic.Task.TaskPriority){
if ( topic.Task.TaskPriority ) {
type = markerMap[ topic.Task.TaskPriority ];
type && (obj.data[ type[0] ] = type[1]);
type && ( obj.data[ type[ 0 ] ] = type[ 1 ] );
}
if(topic.Task.TaskPercentage){
if ( topic.Task.TaskPercentage ) {
type = markerMap[ topic.Task.TaskPercentage ];
type && (obj.data[ type[0] ] = type[1]);
type && ( obj.data[ type[ 0 ] ] = type[ 1 ] );
}
}
//处理子节点
if( topic.SubTopics && topic.SubTopics.Topic ){
if ( topic.SubTopics && topic.SubTopics.Topic ) {
var tmp = topic.SubTopics.Topic;
if( tmp.length && tmp.length > 0 ){ //多个子节点
if ( tmp.length && tmp.length > 0 ) { //多个子节点
obj.children = [];
for(var i in tmp){
obj.children.push({});
processTopic(tmp[i], obj.children[i]);
for ( var i in tmp ) {
obj.children.push( {} );
processTopic( tmp[ i ], obj.children[ i ] );
}
}else{ //一个子节点
obj.children = [{}];
processTopic(tmp, obj.children[0]);
} else { //一个子节点
obj.children = [ {} ];
processTopic( tmp, obj.children[ 0 ] );
}
}
}
function xml2km(xml){
var json = $.xml2json(xml);
function xml2km( xml ) {
var json = $.xml2json( xml );
var result = {};
processTopic(json.OneTopic.Topic, result);
processTopic( json.OneTopic.Topic, result );
return result;
}
function getEntries(file, onend) {
zip.createReader(new zip.BlobReader(file), function(zipReader) {
zipReader.getEntries(onend);
}, onerror);
function getEntries( file, onend ) {
zip.createReader( new zip.BlobReader( file ), function ( zipReader ) {
zipReader.getEntries( onend );
}, onerror );
}
return {
......@@ -81,18 +82,18 @@ KityMinder.registerProtocal( 'mindmanager', function () {
decode: function ( local ) {
return {
then : function(local, callback){
then: function ( local, callback ) {
getEntries( local, function( entries ) {
entries.forEach(function( entry ) {
if(entry.filename == 'Document.xml'){
entry.getData(new zip.TextWriter(), function(text) {
var km = xml2km($.parseXML(text));
getEntries( local, function ( entries ) {
entries.forEach( function ( entry ) {
if ( entry.filename == 'Document.xml' ) {
entry.getData( new zip.TextWriter(), function ( text ) {
var km = xml2km( $.parseXML( text ) );
callback && callback( km );
});
} );
}
});
});
} );
} );
}
};
......@@ -102,5 +103,3 @@ KityMinder.registerProtocal( 'mindmanager', function () {
};
} );
\ No newline at end of file
......@@ -6,7 +6,7 @@ KityMinder.registerProtocal( "png", function () {
}
return {
fileDescription: 'PNG 图片',
fileDescription: 'PNG 图片(暂不支持IE)',
fileExtension: '.png',
encode: function ( json, km ) {
var domContainer = km.getPaper().container,
......@@ -38,14 +38,14 @@ KityMinder.registerProtocal( "png", function () {
$svg.attr( {
width: renderBox.width,
height: renderBox.height,
style: 'font-family: Arial, "Heiti SC", "Microsoft Yahei";'
style: 'font-family: Arial, "Microsoft Yahei","Heiti SC";'
} );
// need a xml with width and height
svgXml = $( '<div></div' ).append( $svg ).html();
svgXml = $( '<div></div>' ).append( $svg ).html();
// svg 含有 &nbsp; 符号导出报错 Entity 'nbsp' not defined
svgXml = svgXml.replace(/&nbsp;/g, '&#xa0;');
svgXml = svgXml.replace( /&nbsp;/g, '&#xa0;' );
blob = new Blob( [ svgXml ], {
type: "image/svg+xml;charset=utf-8"
......
......@@ -31,7 +31,7 @@
"<%}%>" +
"<%}%>" +
"<%for( var i=0, label; label = items[i]; i++ ) {%>" +
"<li class=\"<%=itemClassName%><%if( selected == i ) {%> kmui-combobox-checked<%}%> kmui-combobox-item-<%=i%><%if( disabled[ i ] === true ) {%> kmui-combobox-item-disabled<%}%>\" data-item-index=\"<%=i%>\" unselectable=\"on\" onmousedown=\"return false\">" +
"<li class=\"<%=itemClassName%><%if( selected == i && enabledSelected ) {%> kmui-combobox-checked<%}%> kmui-combobox-item-<%=i%><%if( disabled[ i ] === true ) {%> kmui-combobox-item-disabled<%}%>\" data-item-index=\"<%=i%>\" unselectable=\"on\" onmousedown=\"return false\">" +
"<span class=\"kmui-combobox-icon\" unselectable=\"on\" onmousedown=\"return false\"></span>" +
"<label class=\"<%=labelClassName%>\" style=\"<%=itemStyles[ i ]%>\" unselectable=\"on\" onmousedown=\"return false\"><%=label%></label>" +
"</li>" +
......@@ -52,7 +52,8 @@
autoRecord: true,
//最多记录条数
recordCount: 5,
enabledRecord:true
enabledRecord:true,
enabledSelected:true
},
init: function( options ){
......@@ -332,7 +333,7 @@
var options = this.data("options"),
newStack = [];
debugger
if(this.data('options').enabledRecord){
$.each( options.recordStack, function( i, item ){
......
......@@ -42,5 +42,5 @@ html, body, #kityminder, div.kmui-editor-body {
overflow: hidden;
}
svg {
font-family: Arial, "Heiti SC", "Microsoft Yahei";
font-family: Arial, "Microsoft Yahei","Heiti SC",sans-serif;
}
\ No newline at end of file
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