Commit 838632b3 authored by techird's avatar techird

目录结构和文件调整

parent 9719d582
.idea .idea
*.sublime-project *.sublime-project
*.sublime-workspace *.sublime-workspace
\ No newline at end of file node_modules/
\ No newline at end of file
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
* livereload Default Setting * livereload Default Setting
*-----------------------------------------------------*/ *-----------------------------------------------------*/
'use strict'; 'use strict';
var path = require('path'); var path = require( 'path' );
var lrSnippet = require('grunt-contrib-livereload/lib/utils').livereloadSnippet; var lrSnippet = require( 'grunt-contrib-livereload/lib/utils' ).livereloadSnippet;
/*----------------------------------------------------- /*-----------------------------------------------------
* Module Setting * Module Setting
*-----------------------------------------------------*/ *-----------------------------------------------------*/
module.exports = function (grunt) { module.exports = function ( grunt ) {
var banner = '/*!\n' + var banner = '/*!\n' +
' * ====================================================\n' + ' * ====================================================\n' +
...@@ -20,27 +20,27 @@ module.exports = function (grunt) { ...@@ -20,27 +20,27 @@ module.exports = function (grunt) {
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n' + ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n' +
' * ====================================================\n' + ' * ====================================================\n' +
' */\n\n', ' */\n\n',
buildPath = 'dist/dev.php'; buildPath = 'dev/import.php';
var getPath = function ( readFile) { var getPath = function ( readFile ) {
var sources = require("fs").readFileSync(readFile); var sources = require( "fs" ).readFileSync( readFile );
sources = /Array\(([^)]+)\)/.exec( sources ); sources = /Array\(([^)]+)\)/.exec( sources );
sources = sources[1].replace( /\/\/.*\n/g, '\n' ).replace( /'|"|\n|\t|\s/g, '' ); sources = sources[ 1 ].replace( /\/\/.*\n/g, '\n' ).replace( /'|"|\n|\t|\s/g, '' );
sources = sources.split( "," ); sources = sources.split( "," );
sources.forEach( function ( filepath, index ) { sources.forEach( function ( filepath, index ) {
sources[ index ] = filepath; sources[ index ] = filepath;
}); } );
return sources; return sources;
}; };
// Project configuration. // Project configuration.
grunt.initConfig({ grunt.initConfig( {
// Metadata. // Metadata.
pkg: grunt.file.readJSON('package.json'), pkg: grunt.file.readJSON( 'package.json' ),
concat: { concat: {
...@@ -48,7 +48,7 @@ module.exports = function (grunt) { ...@@ -48,7 +48,7 @@ module.exports = function (grunt) {
options: { options: {
banner: banner + '(function(kity, window) {\n\n', banner: banner + '(function(kity, window) {\n\n',
footer: '\n\n})(kity, window)', footer: '\n\n})(kity, window)',
process: function(src, filepath) { process: function ( src, filepath ) {
return src + "\n"; return src + "\n";
} }
}, },
...@@ -60,6 +60,9 @@ module.exports = function (grunt) { ...@@ -60,6 +60,9 @@ module.exports = function (grunt) {
uglify: { uglify: {
minimize: { minimize: {
options: {
banner: banner
},
files: { files: {
'dist/kityminder.all.min.js': 'dist/kityminder.all.js' 'dist/kityminder.all.min.js': 'dist/kityminder.all.js'
} }
...@@ -76,37 +79,37 @@ module.exports = function (grunt) { ...@@ -76,37 +79,37 @@ module.exports = function (grunt) {
hostname: '*', hostname: '*',
port: 9001, port: 9001,
base: '.', base: '.',
middleware: function(connect, options, middlewares) { middleware: function ( connect, options, middlewares ) {
return [ return [
lrSnippet, lrSnippet,
connect.static(options.base.toString()), connect.static( options.base.toString() ),
connect.directory(options.base.toString()) connect.directory( options.base.toString() )
] ];
} }
} }
} }
}, },
regarde: { regarde: {
js:{ js: {
files: 'src/**/*.js', files: 'src/**/*.js',
tasks: ['default', 'livereload'] tasks: [ 'default', 'livereload' ]
} }
} }
/* End [Task liverload] ------------------------------------*/ /* End [Task liverload] ------------------------------------*/
}); } );
// These plugins provide necessary tasks. // These plugins provide necessary tasks.
/* [Build plugin & task ] ------------------------------------*/ /* [Build plugin & task ] ------------------------------------*/
grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks( 'grunt-contrib-concat' );
grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks( 'grunt-contrib-uglify' );
// Build task(s). // Build task(s).
grunt.registerTask( 'default', [ 'concat:js', 'uglify:minimize' ] ); grunt.registerTask( 'default', [ 'concat:js', 'uglify:minimize' ] );
/* [liverload plugin & task ] ------------------------------------*/ /* [liverload plugin & task ] ------------------------------------*/
grunt.loadNpmTasks('grunt-regarde'); grunt.loadNpmTasks( 'grunt-regarde' );
grunt.loadNpmTasks('grunt-contrib-connect'); grunt.loadNpmTasks( 'grunt-contrib-connect' );
grunt.loadNpmTasks('grunt-contrib-livereload'); grunt.loadNpmTasks( 'grunt-contrib-livereload' );
grunt.registerTask('live', ['livereload-start', 'connect', 'regarde']); grunt.registerTask( 'live', [ 'livereload-start', 'connect', 'regarde' ] );
}; };
\ No newline at end of file
Kity Minder Kity Minder
========== ==========
##简介 ## 简介
KityMinder 是百度FEX团队的f-cube小组(原UEditor小组)的又一力作。作为一款在线的脑图编辑工具,它有着很多Native编辑工具的交互体验。KM与UE有着一样的宗旨,就是注重最终用户的使用体验。同时,它充分发挥了Web云存储的优势,可以直接将编辑中的脑图同步到云端。此外,借由独创的 “云盘分享”功能,用户可以一键将当前编辑的脑图直接生成在线链接共享给其他用户,实现无缝沟通 KityMinder 是百度 FEX 团队的 f-cube 小组(原UEditor小组)的又一力作。作为一款在线的脑图编辑工具,它有着很多Native编辑工具的交互体验。KM与UE有着一样的宗旨,就是注重最终用户的使用体验。同时,它充分发挥了Web云存储的优势,可以直接将编辑中的脑图同步到云端。此外,借由独创的 “云盘分享”功能,用户可以一键将当前编辑的脑图直接生成在线链接共享给其他用户,实现无缝沟通。
![Alt text](summary.jpg "简介图") ![Alt text](summary.jpg "简介图")
KM是基于SVG技术实现,使用JavaScript+html实现。支持绝大多数的主流浏览器。 KM是基于SVG技术实现,使用JavaScript+html实现。支持绝大多数的主流浏览器。
支持列表如下 支持列表如下
1. chrome 1. Chrome
2. firefox 2. Firefox
3. safari 3. Safari
4. ie9-11 4. IE9+
##项目链接 ## 项目链接
[直接使用链接](http://kitygraph.github.io/kityminder/dist/) [直接使用链接](http://fex-team.github.io/kityminder/dist/)
##联系我们 ## 联系我们
邮件:kity@baidu.com 邮件: kity@baidu.com
讨论群:374918234 讨论群: 374918234
var fs = require('fs');
var dependience = [
'src/core/km.js',
'src/core/command.js',
'src/core/mindernode.js',
'src/core/minderevent.js',
'src/core/kityminder.js'
];
var buildPath = 'dist/kityminder.js';
var contents = [], content;
while(dependience.length) {
contents.push(fs.readFileSync(dependience.shift()));
}
content = contents.join('\n\n');
content = '(function(kity, window) {\n\n' + content + '\n\n})(kity, window);';
fs.writeFileSync(buildPath, content);
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../lib/jquery-2.1.0.min.js" charset="utf-8"></script>
<script src="../kity/dist/kitygraph.all.js" charset="utf-8"></script>
<script src="../dev/import.php" 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/baidu-frontia-js-full-1.0.0.js" charset="utf-8"></script>
<script src="../social/social.js" charset="utf-8"></script>
<link href="../social/social.css" rel="stylesheet">
<link href="../themes/default/css/import.css" type="text/css" rel="stylesheet" />
<link href="../dialogs/dialogs.css" rel="stylesheet" type="text/css" />
<script>
$(function () {
// create km instance
window.km = KM.getKityMinder('kityminder');
});
</script>
</head>
<body>
<div id="kityminder" onselectstart="return false"></div>
<body>
</html>
\ No newline at end of file
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<script src="jquery-2.1.0.min.js" charset="utf-8"></script>
<script src="baidu-frontia-js-full-1.0.0.js" charset="utf-8"></script> <script src="../lib/jquery-2.1.0.min.js" charset="utf-8"></script>
<script src="social.js" charset="utf-8"></script>
<script src="../kity/dist/kitygraph.all.js" charset="utf-8"></script> <script src="../kity/dist/kitygraph.all.min.js" charset="utf-8"></script>
<script src="../configure.js" charset="utf-8"></script> <script src="../dist/kityminder.all.min.js" charset="utf-8"></script>
<script src="./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="../lang/zh-cn/zh-cn.js" charset="utf-8"></script>
<link href="../themes/default/css/import.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" href="social.css"> <script src="../lib/baidu-frontia-js-full-1.0.0.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="../dialogs/dialogs.css"> <script src="../social/social.js" charset="utf-8"></script>
<style> <link href="../social/social.css" rel="stylesheet">
.km_receiver{
width:0; <link href="../themes/default/css/import.css" type="text/css" rel="stylesheet" />
height:0; <link href="../dialogs/dialogs.css" rel="stylesheet" type="text/css" />
}
.km-minderNode{ <script>
cursor:default; $(function () {
} // create km instance
.kmui-container { window.km = KM.getKityMinder('kityminder');
height: 100%; });
} </script>
html, body, div {
margin: 0;
padding: 0;
}
html, body, div.kmui-editor-body {
height: 100%;
-moz-user-select: none;
}
</style>
</head> </head>
<body >
<div id="kityminder" style="height:100%;width:100%" onselectstart="return false"> <body>
</div> <div id="kityminder" onselectstart="return false"></div>
<div id="social"></div> <body>
</body>
<script>
window.km = KM.getKityMinder('kityminder');
</script>
</html> </html>
\ No newline at end of file
var KityMinder = /*!
window.KM = * ====================================================
window.KityMinder = function () { * kityminder - v1.0.0 - 2014-03-07
var instanceMap = {}, instanceId = 0; * https://github.com/fex-team/kityminder
return { * GitHub: https://github.com/fex-team/kityminder.git
version: '1.0.0', * Copyright (c) 2014 f-cube @ FEX; Licensed MIT
createMinder: function ( renderTarget, options ) { * ====================================================
options = options || {}; */
options.renderTo = Utils.isString( renderTarget ) ? document.getElementById( renderTarget ) : renderTarget;
var minder = new Minder( options ); (function(kity, window) {
this.addMinder( options.renderTo, minder );
return minder; var KityMinder = window.KM = window.KityMinder = function () {
}, var instanceMap = {}, instanceId = 0;
addMinder: function ( target, minder ) { return {
var id; version: '1.0.0',
if ( typeof ( target ) === 'string' ) { createMinder: function ( renderTarget, options ) {
id = target; options = options || {};
} else { options.renderTo = Utils.isString( renderTarget ) ? document.getElementById( renderTarget ) : renderTarget;
id = target.id || ( "KM_INSTANCE_" + instanceId++ ); var minder = new Minder( options );
} this.addMinder( options.renderTo, minder );
instanceMap[ id ] = minder; return minder;
}, },
getMinder: function ( target, options ) { addMinder: function ( target, minder ) {
var id; var id;
if ( typeof ( target ) === 'string' ) { if ( typeof ( target ) === 'string' ) {
id = target; id = target;
} else { } else {
id = target.id || ( "KM_INSTANCE_" + instanceId++ ); id = target.id || ( "KM_INSTANCE_" + instanceId++ );
} }
return instanceMap[ id ] || this.createMinder( target, options ); instanceMap[ id ] = minder;
}, },
//挂接多语言 getMinder: function ( target, options ) {
LANG: {} var id;
} if ( typeof ( target ) === 'string' ) {
id = target;
} else {
id = target.id || ( "KM_INSTANCE_" + instanceId++ );
}
return instanceMap[ id ] || this.createMinder( target, options );
},
//挂接多语言
LANG: {}
};
}(); }();
var utils = Utils = KityMinder.Utils = { var utils = Utils = KityMinder.Utils = {
...@@ -314,41 +323,41 @@ Utils.each( [ 'String', 'Function', 'Array', 'Number', 'RegExp', 'Object' ], fun ...@@ -314,41 +323,41 @@ Utils.each( [ 'String', 'Function', 'Array', 'Number', 'RegExp', 'Object' ], fun
} ); } );
var Command = kity.createClass( "Command", { var Command = kity.createClass( "Command", {
constructor: function () { constructor: function () {
this._isContentChange = true; this._isContentChange = true;
this._isSelectionChange = false; this._isSelectionChange = false;
}, },
execute: function ( minder, args ) { execute: function ( minder, args ) {
}, },
setContentChanged: function ( val ) { setContentChanged: function ( val ) {
this._isContentChange = !! val; this._isContentChange = !! val;
}, },
isContentChanged: function () { isContentChanged: function () {
return this._isContentChange; return this._isContentChange;
}, },
setSelectionChanged: function ( val ) { setSelectionChanged: function ( val ) {
this._isSelectionChange = !! val; this._isSelectionChange = !! val;
}, },
isSelectionChanged: function () { isSelectionChanged: function () {
return this._isContentChange; return this._isContentChange;
}, },
queryState: function ( km ) { queryState: function ( km ) {
return 0; return 0;
}, },
queryValue: function ( km ) { queryValue: function ( km ) {
return 0; return 0;
}, },
isNeedUndo: function () { isNeedUndo: function () {
return true; return true;
} }
} ); } );
var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", { var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
...@@ -757,6 +766,17 @@ var MinderEvent = kity.createClass( 'MindEvent', { ...@@ -757,6 +766,17 @@ var MinderEvent = kity.createClass( 'MindEvent', {
}, },
preventDefault:function(){ preventDefault:function(){
this.originEvent.preventDefault(); this.originEvent.preventDefault();
},
isRightMB:function(){
var isRightMB = false;
if(!this.originEvent){
return false;
}
if ("which" in this.originEvent)
isRightMB = this.originEvent.which == 3;
else if ("button" in this.originEvent)
isRightMB = this.originEvent.button == 2;
return isRightMB;
} }
} ); } );
...@@ -767,6 +787,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { ...@@ -767,6 +787,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this._initEvents(); this._initEvents();
this._initMinder(); this._initMinder();
this._initSelection(); this._initSelection();
this._initStatus();
this._initShortcutKey(); this._initShortcutKey();
this._initContextmenu(); this._initContextmenu();
this._initModules(); this._initModules();
...@@ -871,6 +892,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { ...@@ -871,6 +892,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
return false return false
} }
me.on( 'keydown', function ( e ) { me.on( 'keydown', function ( e ) {
var originEvent = e.originEvent; var originEvent = e.originEvent;
var keyCode = originEvent.keyCode || originEvent.which; var keyCode = originEvent.keyCode || originEvent.which;
for ( var i in shortcutkeys ) { for ( var i in shortcutkeys ) {
...@@ -881,10 +903,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { ...@@ -881,10 +903,7 @@ 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 );
...@@ -909,6 +928,25 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { ...@@ -909,6 +928,25 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
}, },
getContextmenu:function(){ getContextmenu:function(){
return this.contextmenus; return this.contextmenus;
},
_initStatus:function(){
this._status = "normal";
this._rollbackStatus = "normal";
},
setStatus:function(status){
if(status){
this._rollbackStatus = this._status;
this._status = status;
}else{
this._status = '';
}
return this;
},
rollbackStatus:function(){
this._status = this._rollbackStatus;
},
getStatus:function(){
return this._status;
} }
} ); } );
...@@ -1065,6 +1103,7 @@ kity.extendClass( Minder, { ...@@ -1065,6 +1103,7 @@ kity.extendClass( Minder, {
_firePharse: function ( e ) { _firePharse: function ( e ) {
var beforeEvent, preEvent, executeEvent; var beforeEvent, preEvent, executeEvent;
beforeEvent = new MinderEvent( 'before' + e.type, e, true ); beforeEvent = new MinderEvent( 'before' + e.type, e, true );
if ( this._fire( beforeEvent ) ) { if ( this._fire( beforeEvent ) ) {
return; return;
...@@ -1082,6 +1121,7 @@ kity.extendClass( Minder, { ...@@ -1082,6 +1121,7 @@ kity.extendClass( Minder, {
}, },
_interactChange: function ( e ) { _interactChange: function ( e ) {
var minder = this; var minder = this;
clearTimeout( this._interactTimeout ); clearTimeout( this._interactTimeout );
this._interactTimeout = setTimeout( function () { this._interactTimeout = setTimeout( function () {
var stoped = minder._fire( new MinderEvent( 'beforeinteractchange' ) ); var stoped = minder._fire( new MinderEvent( 'beforeinteractchange' ) );
...@@ -1097,30 +1137,49 @@ kity.extendClass( Minder, { ...@@ -1097,30 +1137,49 @@ kity.extendClass( Minder, {
callbacks.push( callback ); callbacks.push( callback );
}, },
_fire: function ( e ) { _fire: function ( e ) {
var callbacks = this._eventCallbacks[ e.type.toLowerCase() ];
if ( !callbacks ) {
return false; var status = this.getStatus();
var callbacks = this._eventCallbacks[ e.type.toLowerCase() ] || [];
if(status){
callbacks = callbacks.concat(this._eventCallbacks[ status + '.' + e.type.toLowerCase() ] || []);
}
if(callbacks.length == 0){
return;
} }
var lastStatus = this.getStatus();
for ( var i = 0; i < callbacks.length; i++ ) { for ( var i = 0; i < callbacks.length; i++ ) {
callbacks[ i ].call( this, e ); callbacks[ i ].call( this, e );
if ( e.shouldStopPropagationImmediately() ) {
if ( this.getStatus() != lastStatus || e.shouldStopPropagationImmediately() ) {
break; break;
} }
} }
return e.shouldStopPropagation(); return e.shouldStopPropagation();
}, },
on: function ( name, callback ) { on: function ( name, callback ) {
var types = name.split( ' ' ); var km = this;
for ( var i = 0; i < types.length; i++ ) { utils.each(name.split(/\s+/),function(i,n){
this._listen( types[ i ].toLowerCase(), callback ); km._listen( n.toLowerCase(), callback );
} });
return this; return this;
}, },
off: function ( name, callback ) { off: function ( name, callback ) {
var types = name.split( ' ' );
var types = name.split( /\s+/);
var i, j, callbacks, removeIndex; var i, j, callbacks, removeIndex;
for ( i = 0; i < types.length; i++ ) { for ( i = 0; i < types.length; i++ ) {
callbacks = this._eventCallbacks[ types[ i ].toLowerCase() ];
callbacks = this._eventCallbacks[ types[ i ].toLowerCase() ];
if ( callbacks ) { if ( callbacks ) {
removeIndex = null; removeIndex = null;
for ( j = 0; j < callbacks.length; j++ ) { for ( j = 0; j < callbacks.length; j++ ) {
...@@ -1923,6 +1982,9 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -1923,6 +1982,9 @@ 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.getType() !== "root" && parent.getChildren().length !== 0 && parent.getData( "expand" ) === false ) {
km.expandNode( parent );
}
km.appendChildNode( parent, node ); km.appendChildNode( parent, node );
km.select( node, true ); km.select( node, true );
return node; return node;
...@@ -1946,7 +2008,6 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -1946,7 +2008,6 @@ KityMinder.registerModule( "LayoutModule", function () {
node.setType( "main" ); node.setType( "main" );
km.appendChildNode( selectedNode, node ); km.appendChildNode( selectedNode, node );
} else { } else {
node.setType( "sub" );
km.appendSiblingNode( selectedNode, node ); km.appendSiblingNode( selectedNode, node );
} }
km.select( node, true ); km.select( node, true );
...@@ -2020,29 +2081,26 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -2020,29 +2081,26 @@ KityMinder.registerModule( "LayoutModule", function () {
this.initStyle( this.getRoot() ); this.initStyle( this.getRoot() );
} }
}, },
'contextmenu':[ 'contextmenu': [ {
{ label: this.getLang( 'node.appendsiblingnode' ),
label:this.getLang('node.appendsiblingnode'), exec: function () {
exec:function(){ this.execCommand( 'appendsiblingnode', new MinderNode( this.getLang( 'topic' ) ) )
this.execCommand('appendsiblingnode',new MinderNode(this.getLang('topic'))) },
}, cmdName: 'appendsiblingnode'
cmdName:'appendsiblingnode' }, {
}, label: this.getLang( 'node.appendchildnode' ),
{ exec: function () {
label:this.getLang('node.appendchildnode'), this.execCommand( 'appendchildnode', new MinderNode( this.getLang( 'topic' ) ) )
exec:function(){ },
this.execCommand('appendchildnode',new MinderNode(this.getLang('topic'))) cmdName: 'appendchildnode'
}, }, {
cmdName:'appendchildnode' label: this.getLang( 'node.removenode' ),
}, cmdName: 'removenode'
{ }, {
label:this.getLang('node.removenode'), divider: 1
cmdName:'removenode' }
},{
divider:1
}
], ],
"defaultOptions": { "defaultOptions": {
"defaultlayoutstyle": "default", "defaultlayoutstyle": "default",
"node": { "node": {
...@@ -2292,8 +2350,9 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -2292,8 +2350,9 @@ KityMinder.registerModule( "LayoutDefault", function () {
} }
prt = prt.getParent(); prt = prt.getParent();
} }
//自顶向下更新受影响一侧的y值 }
var sideList = root.getLayout()[ appendside + "List" ]; //自顶向下更新受影响一侧的y值
var updateSide = function ( appendside ) {
var _buffer = [ root ]; var _buffer = [ root ];
while ( _buffer.length > 0 ) { while ( _buffer.length > 0 ) {
var _buffer0Layout = _buffer[ 0 ].getLayout(); var _buffer0Layout = _buffer[ 0 ].getLayout();
...@@ -2308,6 +2367,13 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -2308,6 +2367,13 @@ KityMinder.registerModule( "LayoutDefault", function () {
if ( _buffer[ 0 ] !== root ) effectSet.push( _buffer[ 0 ] ); if ( _buffer[ 0 ] !== root ) effectSet.push( _buffer[ 0 ] );
_buffer.shift(); _buffer.shift();
} }
};
var sideList;
if ( appendside ) {
updateSide( appendside );
} else {
updateSide( "left" );
updateSide( "right" );
} }
return effectSet; return effectSet;
}; };
...@@ -2468,6 +2534,12 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -2468,6 +2534,12 @@ KityMinder.registerModule( "LayoutDefault", function () {
default: default:
break; break;
} }
this._fire( new MinderEvent( "beforeRenderNode", {
node: node
}, false ) );
this._fire( new MinderEvent( "RenderNode", {
node: node
}, false ) );
}, },
updateLayout: function ( node ) { updateLayout: function ( node ) {
this._fire( new MinderEvent( "beforeRenderNode", { this._fire( new MinderEvent( "beforeRenderNode", {
...@@ -2593,6 +2665,14 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -2593,6 +2665,14 @@ KityMinder.registerModule( "LayoutDefault", function () {
node.setType( "main" ); node.setType( "main" );
} else { } else {
node.setType( "sub" ); node.setType( "sub" );
var isExpand = parent.getData( "expand" );
if ( isExpand === undefined ) {
isExpand = true;
parent.setData( "expand", isExpand );
}
// if ( !isExpand ) {
// return false;
// }
} }
//计算位置等流程 //计算位置等流程
updateBg( node ); updateBg( node );
...@@ -2656,8 +2736,15 @@ KityMinder.registerModule( "LayoutDefault", function () { ...@@ -2656,8 +2736,15 @@ KityMinder.registerModule( "LayoutDefault", function () {
} }
}, },
expandNode: function ( ico ) { expandNode: function ( ico ) {
var isExpand = ico.icon.switchState(); var isExpand, node;
var node = ico.icon._node; if ( ico instanceof MinderNode ) {
node = ico;
isExpand = node.getLayout().shicon.switchState();
} else {
isExpand = ico.icon.switchState();
node = ico.icon._node;
}
node.setData( "expand", isExpand );
var _buffer = node.getChildren(); var _buffer = node.getChildren();
var _cleanbuffer = []; var _cleanbuffer = [];
...@@ -3048,6 +3135,12 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -3048,6 +3135,12 @@ KityMinder.registerModule( "LayoutBottom", function () {
default: default:
break; break;
} }
this._fire( new MinderEvent( "beforeRenderNode", {
node: node
}, false ) );
this._fire( new MinderEvent( "RenderNode", {
node: node
}, false ) );
}, },
updateLayout: function ( node ) { updateLayout: function ( node ) {
this._fire( new MinderEvent( "beforeRenderNode", { this._fire( new MinderEvent( "beforeRenderNode", {
...@@ -3108,9 +3201,11 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -3108,9 +3201,11 @@ KityMinder.registerModule( "LayoutBottom", function () {
appendChildNode: function ( parent, node, sibling ) { appendChildNode: function ( parent, node, sibling ) {
node.clearLayout(); node.clearLayout();
var parentLayout = parent.getLayout(); var parentLayout = parent.getLayout();
var expand = parent.getData( "expand" );
//设置分支类型 //设置分支类型
if ( parent.getType() === "root" ) { if ( parent.getType() === "root" ) {
node.setType( "main" ); node.setType( "main" );
node.setData( "expand", true );
minder.handelNodeInsert( node ); minder.handelNodeInsert( node );
} else { } else {
node.setType( "sub" ); node.setType( "sub" );
...@@ -3190,8 +3285,15 @@ KityMinder.registerModule( "LayoutBottom", function () { ...@@ -3190,8 +3285,15 @@ KityMinder.registerModule( "LayoutBottom", function () {
} }
}, },
expandNode: function ( ico ) { expandNode: function ( ico ) {
var isExpand = ico.icon.switchState(); var isExpand, node;
var node = ico.icon._node; if ( ico instanceof MinderNode ) {
node = ico;
isExpand = node.getLayout().shicon.switchState();
} else {
isExpand = ico.icon.switchState();
node = ico.icon._node;
}
node.setData( "expand", isExpand );
var _buffer = node.getChildren(); var _buffer = node.getChildren();
var _cleanbuffer = []; var _cleanbuffer = [];
...@@ -3367,24 +3469,30 @@ var ViewDragger = kity.createClass( "ViewDragger", { ...@@ -3367,24 +3469,30 @@ var ViewDragger = kity.createClass( "ViewDragger", {
lastPosition = null, lastPosition = null,
currentPosition = null; currentPosition = null;
this._minder.on( 'beforemousedown', function ( e ) { this._minder.on( 'normal.beforemousedown', function ( e ) {
// 已经被用户打开拖放模式
if ( dragger.isEnabled() ) {
lastPosition = e.getPosition();
e.stopPropagation();
e.originEvent.preventDefault();
}
// 点击未选中的根节点临时开启 // 点击未选中的根节点临时开启
else if ( e.getTargetNode() == this.getRoot() && if ( e.getTargetNode() == this.getRoot() &&
( !this.getRoot().isSelected() || !this.isSingleSelect() ) ) { ( !this.getRoot().isSelected() || !this.isSingleSelect() ) ) {
lastPosition = e.getPosition(); lastPosition = e.getPosition();
dragger.setEnabled( true ); dragger.setEnabled( true );
isRootDrag = true; isRootDrag = true;
var me = this;
setTimeout(function() {
me.setStatus('hand');
}, 1);
} }
} );
this._minder.on( 'hand.beforemousedown', function ( e ) {
// 已经被用户打开拖放模式
if ( dragger.isEnabled() ) {
lastPosition = e.getPosition();
e.stopPropagation();
e.originEvent.preventDefault();
}
} ) } )
.on( 'beforemousemove', function ( e ) { .on( 'hand.beforemousemove', function ( e ) {
if ( lastPosition ) { if ( lastPosition ) {
currentPosition = e.getPosition(); currentPosition = e.getPosition();
...@@ -3396,23 +3504,34 @@ var ViewDragger = kity.createClass( "ViewDragger", { ...@@ -3396,23 +3504,34 @@ var ViewDragger = kity.createClass( "ViewDragger", {
} }
} ) } )
.on( 'mouseup', function ( e ) { .on( 'hand.mouseup', function ( e ) {
lastPosition = null; lastPosition = null;
// 临时拖动需要还原状态 // 临时拖动需要还原状态
if ( isRootDrag ) { if ( isRootDrag ) {
dragger.setEnabled( false ); dragger.setEnabled( false );
isRootDrag = false; isRootDrag = false;
this.rollbackStatus();
} }
} ); } );
} }
} ); } );
KityMinder.registerModule( 'Hand', function () { KityMinder.registerModule( 'Hand', function () {
var km = this;
var ToggleHandCommand = kity.createClass( "ToggleHandCommand", { var ToggleHandCommand = kity.createClass( "ToggleHandCommand", {
base: Command, base: Command,
execute: function ( minder ) { execute: function ( minder ) {
minder._viewDragger.setEnabled( !minder._viewDragger.isEnabled() ); minder._viewDragger.setEnabled( !minder._viewDragger.isEnabled() );
if ( minder._viewDragger.isEnabled() ) {
minder.setStatus( 'hand' );
} else {
minder.rollbackStatus();
}
}, },
queryState: function ( minder ) { queryState: function ( minder ) {
return minder._viewDragger.isEnabled() ? 1 : 0; return minder._viewDragger.isEnabled() ? 1 : 0;
...@@ -3434,8 +3553,8 @@ KityMinder.registerModule( 'Hand', function () { ...@@ -3434,8 +3553,8 @@ KityMinder.registerModule( 'Hand', function () {
} }
}, },
mousewheel: function ( e ) { mousewheel: function ( e ) {
var dx = e.originEvent.wheelDeltaX || e.originEvent.wheelDelta, var dx = e.originEvent.wheelDeltaX || 0,
dy = e.originEvent.wheelDeltaY || 0; dy = e.originEvent.wheelDeltaY || e.originEvent.wheelDelta;
this._viewDragger.move( { this._viewDragger.move( {
x: dx / 2.5, x: dx / 2.5,
y: dy / 2.5 y: dy / 2.5
...@@ -3443,12 +3562,12 @@ KityMinder.registerModule( 'Hand', function () { ...@@ -3443,12 +3562,12 @@ KityMinder.registerModule( 'Hand', function () {
e.originEvent.preventDefault(); e.originEvent.preventDefault();
}, },
dblclick: function() { dblclick: function () {
var viewport = this.getPaper().getViewPort(); var viewport = this.getPaper().getViewPort();
var offset = this.getRoot().getRenderContainer(this.getRenderContainer()).getTransform().getTranslate(); var offset = this.getRoot().getRenderContainer( this.getRenderContainer() ).getTransform().getTranslate();
var dx = viewport.center.x - offset.x, var dx = viewport.center.x - offset.x,
dy = viewport.center.y - offset.y; dy = viewport.center.y - offset.y;
this.getRenderContainer().fxTranslate(dx, dy, 300); //this.getRenderContainer().fxTranslate(dx, dy, 300);
} }
} }
}; };
...@@ -3717,10 +3836,10 @@ KityMinder.registerModule( "DragTree", function () { ...@@ -3717,10 +3836,10 @@ KityMinder.registerModule( "DragTree", function () {
this._dragBox.dragStart( e.getPosition() ); this._dragBox.dragStart( e.getPosition() );
} }
}, },
mousemove: function ( e ) { 'mousemove': function ( e ) {
this._dragBox.dragMove( e.getPosition() ); this._dragBox.dragMove( e.getPosition() );
}, },
mouseup: function ( e ) { 'mouseup': function ( e ) {
this._dragBox.dragEnd(); this._dragBox.dragEnd();
} }
}, },
...@@ -3832,26 +3951,10 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -3832,26 +3951,10 @@ KityMinder.registerModule( "KeyboardModule", function () {
contentchange: function () { contentchange: function () {
buildPositionNetwork( this.getRoot() ); buildPositionNetwork( this.getRoot() );
}, },
keydown: function ( e ) { "normal.keydown": function ( e ) {
var keys = KityMinder.keymap; var keys = KityMinder.keymap;
if ( this.receiver.isTextEditStatus() ) {
switch ( e.originEvent.keyCode ) {
case keys.Enter:
case keys.Tab:
this.fire( 'stopTextEdit' );
e.preventDefault();
break;
case keys.Backspace:
case keys.Del:
case keys.Left:
case keys.Up:
case keys.Right:
case keys.Down:
break;
}
return;
}
var node = e.getTargetNode(); var node = e.getTargetNode();
this.receiver.keydownNode = node; this.receiver.keydownNode = node;
switch ( e.originEvent.keyCode ) { switch ( e.originEvent.keyCode ) {
...@@ -3987,7 +4090,7 @@ KityMinder.registerModule( "Select", function () { ...@@ -3987,7 +4090,7 @@ KityMinder.registerModule( "Select", function () {
var lastDownNode = null; var lastDownNode = null;
return { return {
"events": { "events": {
mousedown: function ( e ) { "normal.mousedown textedit.mousedown": function ( e ) {
var downNode = e.getTargetNode(); var downNode = e.getTargetNode();
// 没有点中节点: // 没有点中节点:
...@@ -3995,6 +4098,7 @@ KityMinder.registerModule( "Select", function () { ...@@ -3995,6 +4098,7 @@ KityMinder.registerModule( "Select", function () {
if ( !downNode ) { if ( !downNode ) {
this.removeAllSelectedNodes(); this.removeAllSelectedNodes();
marqueeActivator.selectStart( e ); marqueeActivator.selectStart( e );
this.setStatus('normal')
} }
// 点中了节点,并且按了 shift 键: // 点中了节点,并且按了 shift 键:
...@@ -4016,8 +4120,8 @@ KityMinder.registerModule( "Select", function () { ...@@ -4016,8 +4120,8 @@ KityMinder.registerModule( "Select", function () {
lastDownNode = downNode; lastDownNode = downNode;
} }
}, },
mousemove: marqueeActivator.selectMove, "normal.mousemove textedit.mousemove": marqueeActivator.selectMove,
mouseup: function ( e ) { "normal.mouseup textedit.mouseup": function ( e ) {
var upNode = e.getTargetNode(); var upNode = e.getTargetNode();
// 如果 mouseup 发生在 lastDownNode 外,是无需理会的 // 如果 mouseup 发生在 lastDownNode 外,是无需理会的
...@@ -4033,282 +4137,98 @@ KityMinder.registerModule( "Select", function () { ...@@ -4033,282 +4137,98 @@ KityMinder.registerModule( "Select", function () {
}; };
} ); } );
KityMinder.registerModule( "HistoryModule", function () { KityMinder.registerModule( "TextEditModule", function () {
var km = this; var km = this;
var sel = new Minder.Selection();
var receiver = new Minder.Receiver(this);
var range = new Minder.Range();
var Scene = kity.createClass( 'Scene', { this.receiver = receiver;
constructor: function ( root ) {
this.data = root.clone(); var mouseDownStatus = false;
},
getData: function () { var oneTime = 0;
return this.data;
}, var lastEvtPosition,dir = 1;
cloneData: function () {
return this.getData().clone();
},
equals: function ( scene ) { km.isTextEditStatus = function(){
return this.getData().equals( scene.getData() ) return km.receiver.isTextEditStatus();
} };
} );
var HistoryManager = kity.createClass( 'HistoryManager', { var selectionByClick = false;
constructor: function ( km ) {
this.list = []; return {
this.index = 0; //插入光标
this.hasUndo = false; "init":function(){
this.hasRedo = false; this.getPaper().addShape(sel);
this.km = km;
}, },
undo: function () { "events": {
if ( this.hasUndo ) { 'normal.beforemousedown textedit.beforemousedown':function(e){
if ( !this.list[ this.index - 1 ] && this.list.length == 1 ) {
this.reset(); if(e.isRightMB()){
e.stopPropagationImmediately();
return; return;
} }
while ( this.list[ this.index ].equals( this.list[ this.index - 1 ] ) ) { sel.setHide();
this.index--; var node = e.getTargetNode();
if ( this.index == 0 ) { if(!node){
return this.restore( 0 ); var selectionShape = e.kityEvent.targetShape;
if(selectionShape && selectionShape.getType() == 'Selection'){
selectionByClick = true;
node = selectionShape.getData('relatedNode');
e.stopPropagationImmediately();
} }
km.setStatus('normal')
} }
this.restore( --this.index ); if(node){
} var textShape = node.getTextShape();
}, textShape.setStyle('cursor','default');
redo: function () {
if ( this.hasRedo ) { if ( this.isSingleSelect() && node.isSelected()) {// && e.kityEvent.targetShape.getType().toLowerCase()== 'text'
while ( this.list[ this.index ].equals( this.list[ this.index + 1 ] ) ) { sel.collapse();
this.index++; node.getTextShape().setStyle('cursor','text');
if ( this.index == this.list.length - 1 ) { km.setStatus('textedit');
return this.restore( this.index ); receiver.setTextEditStatus(true)
.setSelection(sel)
.setKityMinder(this)
.setMinderNode(node)
.setTextShape(textShape)
.setBaseOffset()
.setContainerStyle()
.setSelectionHeight()
.setCurrentIndex(e.getPosition())
.updateSelection()
.setRange(range);
sel.setData('relatedNode',node);
mouseDownStatus = true;
lastEvtPosition = e.getPosition();
if(selectionByClick){
sel.setShow();
selectionByClick = false;
}
km.setStatus('textedit')
} }
} }
this.restore( ++this.index ); },
} 'normal.mouseup textedit.mouseup':function(e){
}, if(mouseDownStatus){
restore: function () { if(!sel.collapsed ){
var scene = this.list[ this.index ]; try{
receiver.updateRange(range)
}catch(e){
console.log(e)
}
this.km.setRoot( scene.cloneData() ); }else
this.km.removeAllSelectedNodes(); sel.setShow()
this.km.initStyle(); }
this.update();
this.km.fire('restoreScene');
this.km.fire('contentChange');
},
getScene: function () {
return new Scene( this.km.getRoot() )
},
saveScene: function () {
var currentScene = this.getScene();
var lastScene = this.list[ this.index ];
if ( lastScene && lastScene.equals( currentScene ) ) {
return
}
this.list = this.list.slice( 0, this.index + 1 );
this.list.push( currentScene );
//如果大于最大数量了,就把最前的剔除
if ( this.list.length > this.km.getOptions( 'maxUndoCount' ) ) {
this.list.shift();
}
this.index = this.list.length - 1;
//跟新undo/redo状态
this.update();
},
update: function () {
this.hasRedo = !! this.list[ this.index + 1 ];
this.hasUndo = !! this.list[ this.index - 1 ];
},
reset: function () {
this.list = [];
this.index = 0;
this.hasUndo = false;
this.hasRedo = false;
}
} );
//为km实例添加history管理
this.historyManager = new HistoryManager( this );
var keys = {
/*Shift*/ 16:1, /*Ctrl*/ 17:1, /*Alt*/ 18:1,/*Command*/91:1,
37:1, 38:1, 39:1, 40:1
},
keycont = 0,
lastKeyCode,
saveSceneTimer;
return {
defaultOptions: {
maxUndoCount: 20,
maxInputCount:20
},
"commands": {
"undo": kity.createClass( "UndoCommand", {
base: Command,
execute: function ( km ) {
km.historyManager.undo()
},
queryState: function ( km ) {
return km.historyManager.hasUndo ? 0 : -1;
},
isNeedUndo: function () {
return false;
}
} ),
"redo": kity.createClass( "RedoCommand", {
base: Command,
execute: function ( km ) {
km.historyManager.redo()
},
queryState: function ( km ) {
return km.historyManager.hasRedo ? 0 : -1;
},
isNeedUndo: function () {
return false;
}
} )
},
addShortcutKeys: {
"Undo": "ctrl+z", //undo
"Redo": "ctrl+y" //redo
},
"events": {
"saveScene": function ( e ) {
this.historyManager.saveScene();
},
"renderNode":function(e){
var node = e.node;
if(node.isHighlight()){
km.select(node);
}
},
"keydown":function(e){
var orgEvt = e.originEvent;
var keyCode = orgEvt.keyCode || orgEvt.which;
if (!keys[keyCode] && !orgEvt.ctrlKey && !orgEvt.metaKey && !orgEvt.shiftKey && !orgEvt.altKey) {
if (km.historyManager.list.length == 0) {
km.historyManager.saveScene();
}
clearTimeout(saveSceneTimer);
saveSceneTimer = setTimeout(function(){
km.historyManager.saveScene();
},200);
lastKeyCode = keyCode;
keycont++;
if (keycont >= km.getOptions('maxInputCount') ) {
km.historyManager.saveScene()
}
}
}
}
};
} );
KityMinder.registerModule( "TextEditModule", function () {
var km = this;
var sel = new Minder.Selection();
var receiver = new Minder.Receiver(this);
var range = new Minder.Range();
this.receiver = receiver;
var mouseDownStatus = false;
var oneTime = 0;
var lastEvtPosition,dir = 1;
km.isTextEditStatus = function(){
return km.receiver.isTextEditStatus();
};
var selectionByClick = false;
return {
//插入光标
"init":function(){
this.getPaper().addShape(sel);
},
"events": {
'beforemousedown':function(e){
var isRightMB;
if ("which" in e.originEvent) // Gecko (Firefox), WebKit (Safari/Chrome) & Opera
isRightMB = e.originEvent.which == 3;
else if ("button" in e.originEvent) // IE, Opera
isRightMB = e.originEvent.button == 2;
if(isRightMB){
e.stopPropagationImmediately();
return;
}
sel.setHide();
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){
var textShape = node.getTextShape();
textShape.setStyle('cursor','default');
if ( this.isSingleSelect() && node.isSelected()) {// && e.kityEvent.targetShape.getType().toLowerCase()== 'text'
sel.collapse();
node.getTextShape().setStyle('cursor','text');
receiver.setTextEditStatus(true)
.setSelection(sel)
.setKityMinder(this)
.setMinderNode(node)
.setTextShape(textShape)
.setBaseOffset()
.setContainerStyle()
.setSelectionHeight()
.setCurrentIndex(e.getPosition())
.updateSelection()
.setRange(range);
sel.setData('relatedNode',node);
mouseDownStatus = true;
lastEvtPosition = e.getPosition();
if(selectionByClick){
sel.setShow();
selectionByClick = false;
}
}
}
},
'mouseup':function(e){
if(mouseDownStatus){
if(!sel.collapsed ){
try{
receiver.updateRange(range)
}catch(e){
console.log(e)
}
}else
sel.setShow()
}
mouseDownStatus = false; mouseDownStatus = false;
oneTime = 0; oneTime = 0;
}, },
'beforemousemove':function(e){ 'textedit.beforemousemove':function(e){
if(mouseDownStatus){ if(mouseDownStatus){
e.stopPropagationImmediately(); e.stopPropagationImmediately();
...@@ -4327,7 +4247,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -4327,7 +4247,7 @@ KityMinder.registerModule( "TextEditModule", function () {
} }
}, },
'dblclick':function(e){ 'normal.dblclick textedit.dblclick':function(e){
var text = e.kityEvent.targetShape; var text = e.kityEvent.targetShape;
if ( text.getType().toLowerCase()== 'text') { if ( text.getType().toLowerCase()== 'text') {
...@@ -4336,8 +4256,8 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -4336,8 +4256,8 @@ KityMinder.registerModule( "TextEditModule", function () {
sel.setEndOffset(text.getContent().length); sel.setEndOffset(text.getContent().length);
sel.setShow(); sel.setShow();
receiver.setContainerTxt(text.getContent()).updateSelectionShow(1) receiver.setContainerTxt(text.getContent()).updateSelectionShow(1)
.updateRange(range).setTextEditStatus(true) .updateRange(range).setTextEditStatus(true);
km.setStatus('textedit');
} }
}, },
'restoreScene':function(){ 'restoreScene':function(){
...@@ -4346,6 +4266,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -4346,6 +4266,7 @@ KityMinder.registerModule( "TextEditModule", function () {
'stopTextEdit':function(){ 'stopTextEdit':function(){
sel.setHide(); sel.setHide();
receiver.clear().setTextEditStatus(false); receiver.clear().setTextEditStatus(false);
km.setStatus('normal');
}, },
"resize": function ( e ) { "resize": function ( e ) {
sel.setHide(); sel.setHide();
...@@ -4363,6 +4284,7 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -4363,6 +4284,7 @@ KityMinder.registerModule( "TextEditModule", function () {
textShape.setStyle('cursor','default'); textShape.setStyle('cursor','default');
node.getTextShape().setStyle('cursor','text'); node.getTextShape().setStyle('cursor','text');
km.setStatus('textedit');
receiver.setTextEditStatus(true) receiver.setTextEditStatus(true)
.setSelection(sel) .setSelection(sel)
.setKityMinder(this) .setKityMinder(this)
...@@ -4400,8 +4322,12 @@ KityMinder.registerModule( "TextEditModule", function () { ...@@ -4400,8 +4322,12 @@ KityMinder.registerModule( "TextEditModule", function () {
} }
receiver.clear().setTextEditStatus(false); receiver.clear().setTextEditStatus(false);
if(this.getStatus() == 'textedit'){
this.setStatus('normal')
}
}, },
'selectionclear':function(){ 'selectionclear':function(){
km.setStatus('normal');
receiver.setTextEditStatus(false).clear() receiver.setTextEditStatus(false).clear()
} }
} }
...@@ -4460,6 +4386,7 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -4460,6 +4386,7 @@ Minder.Receiver = kity.createClass('Receiver',{
clear : function(){ clear : function(){
this.container.innerHTML = ''; this.container.innerHTML = '';
this.selection && this.selection.setHide(); this.selection && this.selection.setHide();
this.range && this.range.nativeSel.removeAllRanges();
this.index = 0; this.index = 0;
return this; return this;
}, },
...@@ -4478,7 +4405,7 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -4478,7 +4405,7 @@ Minder.Receiver = kity.createClass('Receiver',{
_div.className = 'km_receiver'; _div.className = 'km_receiver';
this.container = document.body.insertBefore(_div,document.body.firstChild); this.container = document.body.insertBefore(_div,document.body.firstChild);
utils.addCssRule('km_receiver_css',' .km_receiver{position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);}');// utils.addCssRule('km_receiver_css',' .km_receiver{position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);}');//
this.km.on('beforekeyup', utils.proxy(this.keyboardEvents,this)); this.km.on('textedit.beforekeyup textedit.keydown', utils.proxy(this.keyboardEvents,this));
this.timer = null; this.timer = null;
this.index = 0; this.index = 0;
}, },
...@@ -4529,51 +4456,65 @@ Minder.Receiver = kity.createClass('Receiver',{ ...@@ -4529,51 +4456,65 @@ Minder.Receiver = kity.createClass('Receiver',{
var me = this; var me = this;
var orgEvt = e.originEvent; var orgEvt = e.originEvent;
var keyCode = orgEvt.keyCode; var keyCode = orgEvt.keyCode;
switch(e.type){ var keys = KityMinder.keymap;
switch(e.type){
case 'keydown':
switch ( e.originEvent.keyCode ) {
case keys.Enter:
case keys.Tab:
this.selection.setHide();
this.clear().setTextEditStatus(false);
this.km.setStatus('normal');
e.preventDefault();
break;
}
break;
case 'beforekeyup': case 'beforekeyup':
if(this.isTextEditStatus()){ switch(keyCode){
switch(keyCode){ case keymap.Enter:
case keymap.Enter: case keymap.Tab:
case keymap.Tab: if(this.keydownNode === this.minderNode){
if(this.keydownNode === this.minderNode){ this.rollbackStatus();
this.setTextEditStatus(false); this.setTextEditStatus(false);
this.clear(); this.clear();
} }
e.preventDefault(); e.preventDefault();
return; return;
case keymap.Shift: case keymap.Shift:
case keymap.Control: case keymap.Control:
case keymap.Alt: case keymap.Alt:
case keymap.Cmd: case keymap.Cmd:
return; return;
} }
var text = this.container.textContent.replace(/\u200b/g,''); var text = this.container.textContent.replace(/\u200b/g,'');
if(this.textShape.getOpacity() == 0){ if(this.textShape.getOpacity() == 0){
this.textShape.setOpacity(1); this.textShape.setOpacity(1);
}
this.textShape.setContent(text);
this.setContainerStyle();
this.minderNode.setText(text);
if(text.length == 0){
this.textShape.setContent('a');
this.textShape.setOpacity(0);
}
this.km.updateLayout(this.minderNode);
this.setBaseOffset();
this.updateTextData();
this.updateIndex();
this.updateSelection();
this.timer = setTimeout(function(){
me.selection.setShow()
},500);
return true;
} }
this.textShape.setContent(text);
this.setContainerStyle();
this.minderNode.setText(text);
if(text.length == 0){
this.textShape.setContent('a');
this.textShape.setOpacity(0);
}
this.km.updateLayout(this.minderNode);
this.setBaseOffset();
this.updateTextData();
this.updateIndex();
this.updateSelection();
this.timer = setTimeout(function(){
me.selection.setShow()
},500);
return true;
} }
}, },
updateIndex:function(){ updateIndex:function(){
this.index = this.range.getStart().startOffset; this.index = this.range.getStart().startOffset;
...@@ -4894,6 +4835,9 @@ KityMinder.registerModule( "basestylemodule", function () { ...@@ -4894,6 +4835,9 @@ KityMinder.registerModule( "basestylemodule", function () {
queryState: function ( ) { queryState: function ( ) {
var nodes = km.getSelectedNodes(), var nodes = km.getSelectedNodes(),
result = 0; result = 0;
if(nodes.length == 0){
return -1;
}
utils.each(nodes,function(i,n){ utils.each(nodes,function(i,n){
if(n.getData('bold')){ if(n.getData('bold')){
result = 1; result = 1;
...@@ -4926,6 +4870,9 @@ KityMinder.registerModule( "basestylemodule", function () { ...@@ -4926,6 +4870,9 @@ KityMinder.registerModule( "basestylemodule", function () {
queryState: function ( ) { queryState: function ( ) {
var nodes = km.getSelectedNodes(), var nodes = km.getSelectedNodes(),
result = 0; result = 0;
if(nodes.length == 0){
return -1;
}
utils.each(nodes,function(i,n){ utils.each(nodes,function(i,n){
if(n.getData('italic')){ if(n.getData('italic')){
result = 1; result = 1;
...@@ -5008,6 +4955,9 @@ KityMinder.registerModule( "fontmodule", function () { ...@@ -5008,6 +4955,9 @@ KityMinder.registerModule( "fontmodule", function () {
n.setData( 'fontcolor', color ); n.setData( 'fontcolor', color );
n.getTextShape().fill( color ) n.getTextShape().fill( color )
} ) } )
},
queryState:function(km){
return km.getSelectedNodes().length == 0 ? -1 : 0
} }
} ), } ),
...@@ -5021,6 +4971,9 @@ KityMinder.registerModule( "fontmodule", function () { ...@@ -5021,6 +4971,9 @@ KityMinder.registerModule( "fontmodule", function () {
n.getTextShape().setAttr( 'font-family', family ); n.getTextShape().setAttr( 'font-family', family );
km.updateLayout( n ) km.updateLayout( n )
} ) } )
},
queryState:function(km){
return km.getSelectedNodes().length == 0 ? -1 : 0
} }
} ), } ),
"fontsize": kity.createClass( "fontsizeCommand", { "fontsize": kity.createClass( "fontsizeCommand", {
...@@ -5033,6 +4986,9 @@ KityMinder.registerModule( "fontmodule", function () { ...@@ -5033,6 +4986,9 @@ KityMinder.registerModule( "fontmodule", function () {
n.getTextShape().setSize( size ); n.getTextShape().setSize( size );
km.updateLayout( n ) km.updateLayout( n )
} ) } )
},
queryState:function(km){
return km.getSelectedNodes().length == 0 ? -1 : 0
} }
} ) } )
}, },
...@@ -5117,11 +5073,21 @@ KityMinder.registerModule( 'Zoom', function () { ...@@ -5117,11 +5073,21 @@ KityMinder.registerModule( 'Zoom', function () {
'zoom-in': ZoomInCommand, 'zoom-in': ZoomInCommand,
'zoom-out': ZoomOutCommand 'zoom-out': ZoomOutCommand
}, },
addShortcutKeys: {
"zoom-in": "=", //=
"zoom-out": "-" //-
},
events: { events: {
'normal.keydown':function(e){
var me = this;
var originEvent = e.originEvent;
var keyCode = originEvent.keyCode || originEvent.which;
if(keymap['='] == keyCode){
me.execCommand('zoom-in');
}
if(keymap['-'] == keyCode){
me.execCommand('zoom-out');
}
},
'ready': function () { 'ready': function () {
this._zoomValue = 1; this._zoomValue = 1;
}, },
...@@ -5304,7 +5270,7 @@ KityMinder.registerModule( 'Zoom', function () { ...@@ -5304,7 +5270,7 @@ KityMinder.registerModule( 'Zoom', function () {
return obj.root()[_prefix + className].apply(obj.root(), arguments) return obj.root()[_prefix + className].apply(obj.root(), arguments)
} else { } else {
$el && obj.root($el); $el && obj.root($el);
obj.init && obj.init(!options || $.isPlainObject(options) ? $.extend2(options || {}, obj.defaultOpt || {}, true) : options); obj.init && obj.init(utils.clonePlainObject(!options || $.isPlainObject(options) ? $.extend2(options || {}, obj.defaultOpt || {}, true) : options));
try{ try{
obj.root().find('a').click(function (evt) { obj.root().find('a').click(function (evt) {
evt.preventDefault() evt.preventDefault()
...@@ -6738,172 +6704,6 @@ KM.ui.define('separator', { ...@@ -6738,172 +6704,6 @@ KM.ui.define('separator', {
} }
}); });
//scale 类
KM.ui.define('scale', {
tpl: '<div class="kmui-scale" unselectable="on">' +
'<span class="kmui-scale-hand0"></span>' +
'<span class="kmui-scale-hand1"></span>' +
'<span class="kmui-scale-hand2"></span>' +
'<span class="kmui-scale-hand3"></span>' +
'<span class="kmui-scale-hand4"></span>' +
'<span class="kmui-scale-hand5"></span>' +
'<span class="kmui-scale-hand6"></span>' +
'<span class="kmui-scale-hand7"></span>' +
'</div>',
defaultOpt: {
$doc: $(document),
$wrap: $(document)
},
init: function (options) {
if(options.$doc) this.defaultOpt.$doc = options.$doc;
if(options.$wrap) this.defaultOpt.$wrap = options.$wrap;
this.root($($.parseTmpl(this.tpl, options)));
this.initStyle();
this.startPos = this.prePos = {x: 0, y: 0};
this.dragId = -1;
return this;
},
initStyle: function () {
utils.cssRule('kmui-style-scale', '.kmui-scale{display:none;position:absolute;border:1px solid #38B2CE;cursor:hand;}' +
'.kmui-scale span{position:absolute;left:0;top:0;width:7px;height:7px;overflow:hidden;font-size:0px;display:block;background-color:#3C9DD0;}'
+ '.kmui-scale .kmui-scale-hand0{cursor:nw-resize;top:0;margin-top:-4px;left:0;margin-left:-4px;}'
+ '.kmui-scale .kmui-scale-hand1{cursor:n-resize;top:0;margin-top:-4px;left:50%;margin-left:-4px;}'
+ '.kmui-scale .kmui-scale-hand2{cursor:ne-resize;top:0;margin-top:-4px;left:100%;margin-left:-3px;}'
+ '.kmui-scale .kmui-scale-hand3{cursor:w-resize;top:50%;margin-top:-4px;left:0;margin-left:-4px;}'
+ '.kmui-scale .kmui-scale-hand4{cursor:e-resize;top:50%;margin-top:-4px;left:100%;margin-left:-3px;}'
+ '.kmui-scale .kmui-scale-hand5{cursor:sw-resize;top:100%;margin-top:-3px;left:0;margin-left:-4px;}'
+ '.kmui-scale .kmui-scale-hand6{cursor:s-resize;top:100%;margin-top:-3px;left:50%;margin-left:-4px;}'
+ '.kmui-scale .kmui-scale-hand7{cursor:se-resize;top:100%;margin-top:-3px;left:100%;margin-left:-3px;}');
},
_eventHandler: function (e) {
var me = this,
$doc = me.defaultOpt.$doc;
switch (e.type) {
case 'mousedown':
var hand = e.target || e.srcElement, hand;
if (hand.className.indexOf('kmui-scale-hand') != -1) {
me.dragId = hand.className.slice(-1);
me.startPos.x = me.prePos.x = e.clientX;
me.startPos.y = me.prePos.y = e.clientY;
$doc.bind('mousemove', $.proxy(me._eventHandler, me));
}
break;
case 'mousemove':
if (me.dragId != -1) {
me.updateContainerStyle(me.dragId, {x: e.clientX - me.prePos.x, y: e.clientY - me.prePos.y});
me.prePos.x = e.clientX;
me.prePos.y = e.clientY;
me.updateTargetElement();
}
break;
case 'mouseup':
if (me.dragId != -1) {
me.dragId = -1;
me.updateTargetElement();
var $target = me.data('$scaleTarget');
if ($target.parent()) me.attachTo(me.data('$scaleTarget'));
}
$doc.unbind('mousemove', $.proxy(me._eventHandler, me));
break;
default:
break;
}
},
updateTargetElement: function () {
var me = this,
$root = me.root(),
$target = me.data('$scaleTarget');
$target.css({width: $root.width(), height: $root.height()});
me.attachTo($target);
},
updateContainerStyle: function (dir, offset) {
var me = this,
$dom = me.root(),
tmp,
rect = [
//[left, top, width, height]
[0, 0, -1, -1],
[0, 0, 0, -1],
[0, 0, 1, -1],
[0, 0, -1, 0],
[0, 0, 1, 0],
[0, 0, -1, 1],
[0, 0, 0, 1],
[0, 0, 1, 1]
];
if (rect[dir][0] != 0) {
tmp = parseInt($dom.offset().left) + offset.x;
$dom.css('left', me._validScaledProp('left', tmp));
}
if (rect[dir][1] != 0) {
tmp = parseInt($dom.offset().top) + offset.y;
$dom.css('top', me._validScaledProp('top', tmp));
}
if (rect[dir][2] != 0) {
tmp = $dom.width() + rect[dir][2] * offset.x;
$dom.css('width', me._validScaledProp('width', tmp));
}
if (rect[dir][3] != 0) {
tmp = $dom.height() + rect[dir][3] * offset.y;
$dom.css('height', me._validScaledProp('height', tmp));
}
},
_validScaledProp: function (prop, value) {
var $ele = this.root(),
$wrap = this.defaultOpt.$doc,
calc = function(val, a, b){
return (val + a) > b ? b - a : value;
};
value = isNaN(value) ? 0 : value;
switch (prop) {
case 'left':
return value < 0 ? 0 : calc(value, $ele.width(), $wrap.width());
case 'top':
return value < 0 ? 0 : calc(value, $ele.height(),$wrap.height());
case 'width':
return value <= 0 ? 1 : calc(value, $ele.offset().left, $wrap.width());
case 'height':
return value <= 0 ? 1 : calc(value, $ele.offset().top, $wrap.height());
}
},
show: function ($obj) {
var me = this;
if ($obj) me.attachTo($obj);
me.root().bind('mousedown', $.proxy(me._eventHandler, me));
me.defaultOpt.$doc.bind('mouseup', $.proxy(me._eventHandler, me));
me.root().show();
me.trigger("aftershow");
},
hide: function () {
var me = this;
me.root().unbind('mousedown', $.proxy(me._eventHandler, me));
me.defaultOpt.$doc.unbind('mouseup', $.proxy(me._eventHandler, me));
me.root().hide();
me.trigger('afterhide')
},
attachTo: function ($obj) {
var me = this,
imgPos = $obj.offset(),
$root = me.root(),
$wrap = me.defaultOpt.$wrap,
posObj = $wrap.offset();
me.data('$scaleTarget', $obj);
me.root().css({
position: 'absolute',
width: $obj.width(),
height: $obj.height(),
left: imgPos.left - posObj.left - parseInt($wrap.css('border-left-width')) - parseInt($root.css('border-left-width')),
top: imgPos.top - posObj.top - parseInt($wrap.css('border-top-width')) - parseInt($root.css('border-top-width'))
});
},
getScaleTarget: function () {
return this.data('$scaleTarget')[0];
}
});
/** /**
* 宽度自适应工具函数 * 宽度自适应工具函数
* @param word 单词内容 * @param word 单词内容
...@@ -7224,7 +7024,7 @@ KM.registerToolbarUI( 'forecolor', function ( name ) { ...@@ -7224,7 +7024,7 @@ KM.registerToolbarUI( 'forecolor', function ( name ) {
title: this.getLang( 'tooltips' )[ name ] || '', title: this.getLang( 'tooltips' )[ name ] || '',
click: function () { click: function () {
var color = kity.Color.parse(getCurrentColor()).toHEX(); var color = kity.Color.parse(getCurrentColor()).toHEX();
if(!color == '#000000'){ if( color != '#000000'){
me.execCommand( name, color ); me.execCommand( name, color );
} }
} }
...@@ -7304,10 +7104,11 @@ KM.registerToolbarUI( 'saveto', function ( name ) { ...@@ -7304,10 +7104,11 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
var renderBox = me.getRenderContainer().getRenderBox( "top" ); var renderBox = me.getRenderContainer().getRenderBox( "top" );
var renderContainer = me.getRenderContainer(); var renderContainer = me.getRenderContainer();
var transform = renderContainer.getTransform(); var transform = renderContainer.getTransform();
renderContainer.resetTransform(); renderContainer.clearTransform();
var loop = 0;
var svg = $( svghtml ).attr( { var svg = $( svghtml ).attr( {
width: renderBox.x + renderBox.width, width: renderBox.width,
height: renderBox.y + renderBox.height, height: renderBox.height,
viewBox: null viewBox: null
} ); } );
var div = $( "<div></div>" ).append( svg ); var div = $( "<div></div>" ).append( svg );
...@@ -7626,18 +7427,8 @@ KM.registerUI( 'contextmenu', function () { ...@@ -7626,18 +7427,8 @@ KM.registerUI( 'contextmenu', function () {
$menu.kmui().hide(); $menu.kmui().hide();
}); });
me.on('beforemousedown',function(e){ me.on('beforemousedown',function(e){
var isRightMB; if(e.isRightMB()){
if ("which" in e.originEvent) // Gecko (Firefox), WebKit (Safari/Chrome) & Opera
isRightMB = e.originEvent.which == 3;
else if ("button" in e.originEvent) // IE, Opera
isRightMB = e.originEvent.button == 2;
if(isRightMB){
e.stopPropagationImmediately(); e.stopPropagationImmediately();
} }
}) })
} ); } );
...@@ -8023,3 +7814,5 @@ KityMinder.registerProtocal( "svg", function () { ...@@ -8023,3 +7814,5 @@ KityMinder.registerProtocal( "svg", function () {
}; };
} ); } );
})(kity, window)
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
"name": "kityminder", "name": "kityminder",
"title": "kityminder", "title": "kityminder",
"description": "Kity Minder", "description": "Kity Minder",
"version": "1.1.0", "version": "1.0.0",
"homepage": "https://github.com/kitygraph/kityminder", "homepage": "https://github.com/fex-team/kityminder",
"author": { "author": {
"name": "Baidu UEditor Group", "name": "f-cube @ FEX",
"url": "http://ueditor.baidu.com" "url": "http://fex.baidu.com"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/kitygraph/kityminder.git" "url": "https://github.com/fex-team/kityminder.git"
}, },
"keywords": [ "keywords": [
"kityminder", "kityminder",
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
"javascript" "javascript"
], ],
"bugs": { "bugs": {
"url": "https://github.com/kitygraph/kityminder/issues" "url": "https://github.com/fex-team/kityminder/issues"
}, },
"licenses": [ "licenses": [
{ {
"type": "MIT", "type": "MIT",
"url": "https://github.com/kitygraph/kityminder/blob/dev/LICENSE" "url": "https://github.com/fex-team/kityminder/blob/dev/LICENSE"
} }
], ],
"dependencies": {}, "dependencies": {},
......
...@@ -36,7 +36,7 @@ $.extend( $.fn, { ...@@ -36,7 +36,7 @@ $.extend( $.fn, {
} ); } );
$( function () { $( function () {
var $panel = $( '#social' ); var $panel = $( '<div id="social"></div>' ).appendTo( 'body' );
var $login_btn, $save_btn, $share_btn, $user_btn, $user_menu; var $login_btn, $save_btn, $share_btn, $user_btn, $user_menu;
var baseUrl = ( function () { var baseUrl = ( function () {
...@@ -322,7 +322,7 @@ $( function () { ...@@ -322,7 +322,7 @@ $( function () {
if ( currentUser ) { if ( currentUser ) {
setCurrentUser( currentUser ); setCurrentUser( currentUser );
loadPath(); loadPath();
if(thisMapFilename) { if ( thisMapFilename ) {
loadPersonal( thisMapFilename ); loadPersonal( thisMapFilename );
} }
} else { } else {
......
html, body, div {
margin: 0;
padding: 0;
}
html, body, #kity-minder, div.kmui-editor-body {
height:100%;
width:100%
-moz-user-select: none;
}
.km_receiver{
width:0;
height:0;
}
.km-minderNode{
cursor:default;
}
.kmui-container {
height: 100%;
}
.kmui-container { .kmui-container {
} }
.kmui-container .kmui-toolbar{ .kmui-container .kmui-toolbar{
......
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