Commit e74b0527 authored by techird's avatar techird

1.2.0 preview

parent 869129ba
( function ( utils ) {
(function(utils) {
//todo 这里先写死成中文
var content = '<div class="hyperlink-content" style="padding:20px;width:360px;">';
content += '<style>';
......@@ -35,36 +35,51 @@
KM.registerWidget( 'hyperlink', {
KM.registerWidget('hyperlink', {
tpl: content,
initContent: function ( km ) {
var lang = km.getLang( 'dialogs.hyperlink' ),
initContent: function(km) {
var lang = km.getLang('dialogs.hyperlink'),
html;
if ( lang ) {
html = $.parseTmpl( this.tpl, utils.extend( {
if (lang) {
html = $.parseTmpl(this.tpl, utils.extend({
'container': 'hyperlink'
}, lang ) );
}, lang));
}
this.root().html( html );
this.root().html(html);
},
initEvent: function ( km, $w ) {
$w.find( '#hyperlink_insert' ).on( 'click', function () {
km.execCommand( 'hyperlink', $w.find( '#hyperlink_href' ).val() );
initEvent: function(km, $w) {
var $btn = $w.find('#hyperlink_insert');
$btn.attr('disabled', 'disabled');
var $href = $w.find('#hyperlink_href').on('input', function() {
var url = $href.val();
if (!/^https?\:\/\/(\w+\.)+\w+/.test(url)) {
$href.css('color', 'red');
$href.data('error', true);
$btn.attr('disabled', 'disabled');
} else {
$href.css('color', 'black');
$href.data('error', false);
$btn.removeAttr('disabled');
}
});
$btn.on('click', function() {
if ($btn.attr('disabled')) return;
var url = $w.find('#hyperlink_href').val();
km.execCommand('hyperlink', url);
$w.kmui().hide();
} );
$w.find( '#hyperlink_href' ).on( 'keydown', function ( e ) {
if ( e.keyCode === 13 ) {
km.execCommand( 'hyperlink', $w.find( '#hyperlink_href' ).val() );
$w.kmui().hide();
});
$w.find('#hyperlink_href').on('keydown', function(e) {
if (e.keyCode === 13) {
$btn.click();
}
} );
var url = km.queryCommandValue( 'hyperlink' );
var $input = $w.find( '#hyperlink_href' );
$input.val( url || 'http://' );
setTimeout( function () {
$input.focus()
} )
});
var url = km.queryCommandValue('hyperlink');
var $input = $w.find('#hyperlink_href');
$input.val(url || 'http://');
setTimeout(function() {
$input.select();
});
},
width: 400
} );
} )( KM.Utils );
\ No newline at end of file
});
})(KM.Utils);
\ No newline at end of file
......@@ -49,24 +49,39 @@
this.root().html(html);
},
initEvent: function(km, $w) {
$w.find('#image_insert').on('click', function() {
km.execCommand('image', $w.find('#image_href').val());
var $btn = $w.find('#image_insert').attr('disabled', 'disabled');
var $href = $w.find('#image_href').on('input', function() {
var url = $href.val();
if (!/^https?\:\/\/(\w+\.)+\w+/.test(url)) {
$href.css('color', 'red');
$href.data('error', true);
} else {
$href.css('color', 'black');
$href.data('error', false);
}
$w.find('#image_preview').attr('src', $href.val());
});
$w.find('#image_preview').on('load', function() {
$btn.removeAttr('disabled');
}).on('error', function() {
$btn.attr('disabled', 'disabled');
});
$btn.on('click', function() {
if ($btn.attr('disabled')) return;
km.execCommand('image', $href.val());
$w.kmui().hide();
});
$w.find('#image_href').on('keydown', function(e) {
$href.on('keydown', function(e) {
if (e.keyCode === 13) {
km.execCommand('image', $w.find('#image_href').val());
$w.kmui().hide();
$btn.click();
}
}).on('input', function() {
$w.find('#image_preview').attr('src', $w.find('#image_href').val());
});
var url = km.queryCommandValue('image');
var $input = $w.find('#image_href');
$input.val(url || 'http://');
if (url) $w.find('#image_preview').attr('src', url);
setTimeout(function() {
$input.focus();
$input.select();
});
},
width: 400
......
......@@ -9,8 +9,7 @@ button img{position:relative;top:3px;border-radius:2px;margin-right:7px}
button.user-file{position:relative;padding-right:28px}button.user-file img{border:none;outline:none}
button.user-file span.text{display:inline-block;height:24px;line-height:24px}
button.user-file:after{content:' ';display:block;position:absolute;right:10px;top:15px;width:0;height:0;border:solid;border-width:4px 5px;border-color:#fff transparent transparent transparent}
#draft-btn{position:absolute;left:10px;bottom:10px;padding-left:35px;padding-right:28px}#draft-btn:before{content:' ';display:block;width:24px;height:24px;background:url(../themes/default/images/draft.png) no-repeat;position:absolute;left:7px;top:5px}
#draft-btn:after{content:' ';display:block;position:absolute;right:10px;top:15px;width:0;height:0;border:solid;border-width:4px 5px;border-color:#fff transparent transparent transparent}
#draft-btn{padding-right:28px}#draft-btn:after{content:' ';display:block;position:absolute;right:10px;top:15px;width:0;height:0;border:solid;border-width:4px 5px;border-color:#fff transparent transparent transparent}
.draft-menu span.update-time{float:right;color:#ccc;margin-left:20px;padding-right:16px}
.draft-menu li.draft-item a{position:relative}.draft-menu li.draft-item a:before{content:' ';display:block;width:24px;height:24px;background:url(../themes/default/images/draft.png) no-repeat 0 -24px;position:absolute;left:4px;top:2px}
.draft-menu li.draft-item:hover a:before{background-position:0 -48px}
......
......@@ -113,20 +113,6 @@ button {
}
}
#draft-btn {
position: absolute;
left: 10px;
bottom: 10px;
&:before {
content: ' ';
display: block;
width: 24px;
height: 24px;
background: url(../themes/default/images/draft.png) no-repeat;
position: absolute;
left: 7px;
top: 5px;
}
padding-left: 35px;
.dropdown;
}
.draft-menu {
......
......@@ -31,10 +31,9 @@
'layout/bottom.js',
'layout/filetree.js',
'theme/default.js',
'theme/bottom.js',
'theme/filetree.js',
'theme/snow.js',
'theme/fresh.js',
'template/bottom.js',
'template/structure.js',
'module/node.js',
'module/text.js',
'module/expand.js',
......@@ -58,7 +57,6 @@
'module/basestyle.js',
'module/font.js',
'module/zoom.js',
'module/nodetext.js',
'module/hyperlink.js',
'module/arrange.js',
'ui/jquery-ui-1.10.4.custom.min.js',
......@@ -86,7 +84,7 @@
'adapter/color.js',
'adapter/saveto.js',
'adapter/tooltips.js',
//'adapter/layout.js',
'adapter/face.js',
'adapter/node.js',
'adapter/contextmenu.js',
'adapter/dialog.js',
......
......@@ -6,7 +6,6 @@
<meta name="keyword" content="脑图,kity,svg,minder,百度,fex,前端,在线">
<meta name="description" content="百度脑图,便捷的脑图编辑工具。让您在线上直接创建、保存并分享你的思路。">
<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">
......@@ -36,6 +35,7 @@
<body>
<div id="kityminder" onselectstart="return false"></div>
<div id="share-dialog" >
<h3>URL分享:</h3>
<p>
......
......@@ -63,7 +63,7 @@
'KITYMINDER_HOME_URL': getKMBasePath(),
//定义工具栏
toolbars: [
'hand | zoom-in zoom zoom-out | collapsenode expandnode | undo redo | bold italic | fontfamily fontsize forecolor | saveto | hyperlink unhyperlink image removeimage | markers resource | node | help'
'hand | zoom-in zoom zoom-out | saveto | collapsenode expandnode | undo redo | template theme | bold italic | fontfamily fontsize forecolor| hyperlink unhyperlink image removeimage | markers resource | node | help'
]
//只读模式,默认是false
//readOnly: true
......
KityMinder.LANG['zh-cn'] = {
'template': {
'default': '思维导图',
'structure': '组织结构图'
},
'theme': {
'default': '脑图经典',
'snow': '温柔冷光',
'fresh': '文艺小清新'
},
'maintopic': '中心主题',
'topic': '分支主题',
'tooltips': {
......@@ -21,9 +30,11 @@ KityMinder.LANG['zh-cn'] = {
'preference': '偏好设置',
'image': '插入图片',
'hyperlink': '插入链接',
'unhyperlink': "删除链接",
'expandnode': "展开节点",
'collapsenode': "收起节点"
'unhyperlink': '删除链接',
'expandnode': '展开节点',
'collapsenode': '收起节点',
'template': '模板',
'theme': '皮肤'
},
'popupcolor': {
'clearColor': '清空颜色',
......@@ -72,11 +83,17 @@ KityMinder.LANG['zh-cn'] = {
},
'hyperlink': {
'hyperlink': '插入超链接',
'unhyperlink': "取消超链接"
'unhyperlink': '取消超链接'
},
'image': {
'image': '插入图片',
'removeimage': '删除图片'
},
'marker': {
'marker': '设置进度/优先级'
},
'resource': {
'resource': '设置资源'
}
};
\ No newline at end of file
......@@ -9,27 +9,6 @@ function DraftManager( minder ) {
function init() {
drafts = localStorage.getItem( 'drafts' );
drafts = drafts ? JSON.parse( drafts ) : [];
loadDraftForOldVersion();
}
/**
* @todo 1.2 版本中删除该方法
*
* 加载老版本的草稿
*/
function loadDraftForOldVersion() {
var path = localStorage.getItem( 'draft_filename' ),
data = localStorage.getItem( 'draft_data' );
if ( path && data ) {
drafts.push( {
path: path,
data: data,
name: JSON.parse( data ).data.text,
update: new Date()
} );
localStorage.removeItem( 'draft_filename' );
localStorage.removeItem( 'draft_data' );
}
}
function store() {
......@@ -58,7 +37,8 @@ function DraftManager( minder ) {
function load() {
if ( current ) {
minder.importData( current.data, "json" );
minder.importData( current.data, 'json' );
minder.execCommand('camera');
}
return current;
}
......@@ -80,8 +60,9 @@ function DraftManager( minder ) {
} else {
current.path = path || current.path;
current.name = minder.getMinderTitle();
current.data = minder.exportData( "json" );
current.sync = false;
var data = minder.exportData( 'json' );
current.sync = current.sync && (data == current.data);
current.data = data;
current.update = new Date();
store();
}
......
#social{position:absolute;right:10px;top:10px;line-height:20px;text-align:right;overflow:hidden}
.dropdown{padding-right:28px}.dropdown:after{content:' ';display:block;position:absolute;right:10px;top:15px;width:0;height:0;border:solid;border-width:4px 5px;border-color:#fff transparent transparent transparent}
button{font-family:Arial,"Heiti SC","Microsoft Yahei";outline:none;display:inline-block;vertical-align:middle;padding:0 15px;height:35px;font-size:13px;line-height:35px;text-align:center;border-radius:5px;color:#fff;text-decoration:none;border:none;margin-left:5px;cursor:pointer;background:#0099f2;background:url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzAwOTlmMiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjNDA5NmVlIiBzdG9wLW9wYWNpdHk9IjEiLz4KICAgIDxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzAwNzZkZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);background:-moz-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0, #0099f2), color-stop(0, #4096ee), color-stop(100%, #0076dd));background:-webkit-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:-o-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:-ms-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:linear-gradient(to bottom, #0099f2 0, #4096ee 0, #0076dd 100%);}button:hover,button.hover{background:#009fff}
button:active,button.active{background:#007fcc;box-shadow:inset 0 2px 3px rgba(0,0,0,0.2)}
button[disabled]{background:#aaa;cursor:default}
button.baidu-cloud{padding-left:35px;position:relative}button.baidu-cloud:before{content:' ';display:block;width:24px;height:24px;background:url(../themes/default/images/baiducloud.png);position:absolute;left:7px;top:5px}
#social{position:absolute;height:30px;left:0;right:0;top:0;line-height:30px;overflow:hidden;background:#fafafa;border-bottom:1px solid #fff;box-shadow:inset 0 -1px #f0f0f0;z-index:1000}#social h2{margin:0 200px;padding:0;color:#999;text-shadow:0 1px #fff;font-size:12px;text-align:center;font-weight:normal}
#social #menu{float:left}
#social #user{float:right;padding-right:10px}#social #user a{color:#333;font-size:12px;text-decoration:underline;padding:0 5px;cursor:pointer}#social #user a img{vertical-align:text-bottom;margin-right:5px}
#social #user #logout-button,#social #user #user-button{display:none}
#social #user.logined #logout-button,#social #user.logined #user-button{display:inline-block}
#social #user.logined #login-button{display:none}
.niceblue{color:#fff;background:-moz-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0, #0099f2), color-stop(0, #4096ee), color-stop(100%, #0076dd));background:-webkit-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:-o-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:-ms-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:linear-gradient(to bottom, #0099f2 0, #4096ee 0, #0076dd 100%);}.niceblue:after{border-color:#fff transparent transparent transparent}
.dropdown{padding-right:28px;position:relative}.dropdown:after{content:' ';display:block;position:absolute;right:10px;top:12px;width:0;height:0;border:solid;border-width:4px 5px;border-color:#333 transparent transparent transparent}
.dropdown:active:after,.dropdown.active:after{border-color:#fff transparent transparent transparent}
button{font-family:Arial,"Heiti SC","Microsoft Yahei";outline:none;display:inline-block;vertical-align:middle;padding:0 15px;height:30px;font-size:13px;line-height:30px;text-align:center;color:#000;text-decoration:none;border:none;margin-left:5px;background:none;border-radius:2px}
button:active,button.active{box-shadow:inset 0 1px 3px rgba(0,0,0,0.2);background:#ccc;color:#fff}
button[disabled]{cursor:default}
button.share{padding-left:35px;position:relative}button.share:before{content:' ';display:block;width:24px;height:24px;background:url(../themes/default/images/share.png) no-repeat;position:absolute;left:7px;top:5px}
button img{position:relative;top:3px;border-radius:2px;margin-right:7px}
button.user-file{position:relative;padding-right:28px}button.user-file img{border:none;outline:none}
button.user-file span.text{display:inline-block;height:24px;line-height:24px}
button.user-file:after{content:' ';display:block;position:absolute;right:10px;top:15px;width:0;height:0;border:solid;border-width:4px 5px;border-color:#fff transparent transparent transparent}
#draft-btn{position:absolute;left:10px;bottom:10px;padding-left:35px;padding-right:28px}#draft-btn:before{content:' ';display:block;width:24px;height:24px;background:url(../themes/default/images/draft.png) no-repeat;position:absolute;left:7px;top:5px}
#draft-btn:after{content:' ';display:block;position:absolute;right:10px;top:15px;width:0;height:0;border:solid;border-width:4px 5px;border-color:#fff transparent transparent transparent}
.draft-menu span.update-time{float:right;color:#ccc;margin-left:20px;padding-right:16px}
.draft-menu li.draft-item a{position:relative}.draft-menu li.draft-item a:before{content:' ';display:block;width:24px;height:24px;background:url(../themes/default/images/draft.png) no-repeat 0 -24px;position:absolute;left:4px;top:2px}
.draft-menu li.draft-item:hover a:before{background-position:0 -48px}
.draft-menu li.draft-item{position:relative}.draft-menu li.draft-item:hover a.delete{display:block}
.draft-menu li.draft-item a.delete{display:none;cursor:pointer;position:absolute;width:20px;height:20px;right:4px;top:4px;padding:0;background:url(../themes/default/images/close-button.png) no-repeat 0 0}.draft-menu li.draft-item a.delete:before{display:none}
.draft-menu li.draft-item a.delete:hover{background-position:0 -20px}
.draft-menu.kmui-combobox-menu .kmui-combobox-checked{overflow:hidden;opacity:1;color:#ccc}.draft-menu.kmui-combobox-menu .kmui-combobox-checked .kmui-combobox-icon{float:left;margin:5px 0;width:28px;background-position:center 0;opacity:.3}
.draft-menu.kmui-combobox-menu .kmui-combobox-checked .kmui-combobox-item-label{display:block;margin-left:28px}
.draft-menu.kmui-combobox-menu .kmui-combobox-checked:hover{color:#ccc}.draft-menu.kmui-combobox-menu .kmui-combobox-checked:hover .kmui-combobox-icon{background-position:center 0}
.user-file-menu{margin-top:20px;margin-left:1px}
#share-dialog{position:absolute;padding:20px;border-radius:4px;right:10px;top:65px;background:#fff;width:350px;box-shadow:1px 2px 16px rgba(0,0,0,0.5);display:none}#share-dialog h3{margin:0;font-size:16px;color:#666}
button.file-button{padding-right:28px;position:relative;color:#fff;background:-moz-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0, #0099f2), color-stop(0, #4096ee), color-stop(100%, #0076dd));background:-webkit-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:-o-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:-ms-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:linear-gradient(to bottom, #0099f2 0, #4096ee 0, #0076dd 100%);border-radius:5px 5px 0 0;margin-left:5px}button.file-button:after{content:' ';display:block;position:absolute;right:10px;top:12px;width:0;height:0;border:solid;border-width:4px 5px;border-color:#333 transparent transparent transparent}
button.file-button:active:after,button.file-button.active:after{border-color:#fff transparent transparent transparent}
button.file-button:after{border-color:#fff transparent transparent transparent}
button.file-button:hover,button.file-button.hover{background:#009fff}
button.file-button:active,button.file-button.active{background:#007fcc;box-shadow:inset 0 2px 3px rgba(0,0,0,0.2)}
#save-button a{position:relative}#save-button a:before{content:' ';display:block;width:24px;height:24px;background:url(../themes/default/images/baiducloud.png);position:absolute;left:4px;top:2px}
#save-button:hover a:before{background-position:0 -24px}
#share-button a{position:relative}#share-button a:before{content:' ';display:block;width:24px;height:24px;background:url(../themes/default/images/share.png);position:absolute;left:4px;top:2px}
#share-button:hover a:before{background-position:0 -24px}
#draft-btn{padding-right:28px;position:relative;border-radius:5px 5px 0 0}#draft-btn:after{content:' ';display:block;position:absolute;right:10px;top:12px;width:0;height:0;border:solid;border-width:4px 5px;border-color:#333 transparent transparent transparent}
#draft-btn:active:after,#draft-btn.active:after{border-color:#fff transparent transparent transparent}
.draft-menu.kmui-dropdown-menu{margin-top:14px;margin-left:-1px}.draft-menu.kmui-dropdown-menu span.update-time{float:right;color:#ccc;margin-left:20px;padding-right:16px}
.draft-menu.kmui-dropdown-menu li.draft-item a{position:relative}.draft-menu.kmui-dropdown-menu li.draft-item a:before{content:' ';display:block;width:24px;height:24px;background:url(../themes/default/images/draft.png) no-repeat 0 -24px;position:absolute;left:4px;top:2px}
.draft-menu.kmui-dropdown-menu li.draft-item:hover a:before{background-position:0 -48px}
.draft-menu.kmui-dropdown-menu li.draft-item{position:relative}.draft-menu.kmui-dropdown-menu li.draft-item:hover a.delete{display:block}
.draft-menu.kmui-dropdown-menu li.draft-item a.delete{display:none;cursor:pointer;position:absolute;width:20px;height:20px;right:4px;top:4px;padding:0;background:url(../themes/default/images/close-button.png) no-repeat 0 0}.draft-menu.kmui-dropdown-menu li.draft-item a.delete:before{display:none}
.draft-menu.kmui-dropdown-menu li.draft-item a.delete:hover{background-position:0 -20px}
.draft-menu.kmui-dropdown-menu.kmui-combobox-menu .kmui-combobox-checked{overflow:hidden;opacity:1;color:#ccc}.draft-menu.kmui-dropdown-menu.kmui-combobox-menu .kmui-combobox-checked .kmui-combobox-icon{float:left;margin:5px 0;width:28px;background-position:center 0;opacity:.3}
.draft-menu.kmui-dropdown-menu.kmui-combobox-menu .kmui-combobox-checked .kmui-combobox-item-label{display:block;margin-left:28px}
.draft-menu.kmui-dropdown-menu.kmui-combobox-menu .kmui-combobox-checked:hover{color:#ccc}.draft-menu.kmui-dropdown-menu.kmui-combobox-menu .kmui-combobox-checked:hover .kmui-combobox-icon{background-position:center 0}
.file-menu.kmui-dropdown-menu{margin-top:14px;margin-left:1px;box-shadow:0 1px 5px rgba(0,0,0,0.3)}.file-menu.kmui-dropdown-menu #save-button,.file-menu.kmui-dropdown-menu #manage-file-button,.file-menu.kmui-dropdown-menu #share-button+.kmui-divider{display:none}
.file-menu.kmui-dropdown-menu.logined #save-button,.file-menu.kmui-dropdown-menu.logined #manage-file-button,.file-menu.kmui-dropdown-menu.logined #share-button+.kmui-divider{display:block}
#share-dialog{position:absolute;padding:20px;border-radius:4px;left:50%;top:40%;margin-left:-175px;margin-top:-100px;background:#fff;width:350px;box-shadow:1px 2px 16px rgba(0,0,0,0.5);display:none}#share-dialog h3{margin:0;font-size:16px;color:#666}
#share-dialog input{width:260px;height:22px;line-height:22px;padding:4px 4px 0;border:1px solid #999;vertical-align:middle;margin-right:3px;background:#eee}#share-dialog input:focus{border:1px solid #99f;outline:none}
#share-dialog p,#share-dialog #share-platform{margin:20px 0 30px}
#share-dialog #copy-share-url{display:inline-block;margin:0;width:70px;height:28px;line-height:28px;border-radius:2px;vertical-align:middle}
#share-dialog #copy-share-url{display:inline-block;margin:0;width:70px;height:28px;line-height:28px;border-radius:2px;vertical-align:middle;border-radius:5px;color:#fff;background:-moz-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:-webkit-gradient(linear, left top, left bottom, color-stop(0, #0099f2), color-stop(0, #4096ee), color-stop(100%, #0076dd));background:-webkit-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:-o-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:-ms-linear-gradient(top, #0099f2 0, #4096ee 0, #0076dd 100%);background:linear-gradient(to bottom, #0099f2 0, #4096ee 0, #0076dd 100%);}#share-dialog #copy-share-url:after{border-color:#fff transparent transparent transparent}
#share-dialog #copy-share-url:hover,#share-dialog #copy-share-url.hover{background:#009fff}
#share-dialog #copy-share-url:active,#share-dialog #copy-share-url.active{background:#007fcc;box-shadow:inset 0 2px 3px rgba(0,0,0,0.2)}
#share-dialog #share-platform{margin-bottom:0}
#share-dialog:before{position:absolute;content:' ';width:0;height:0;line-height:0;display:block;border:10px solid transparent;border-bottom-color:#fff;right:30px;top:-20px}
......@@ -11,48 +11,48 @@
*/
$.extend( $.fn, {
disabled: function ( value ) {
if ( value === undefined ) return !!this.attr( 'disabled' );
if ( value ) {
this.attr( 'disabled', 'disabled' );
$.extend($.fn, {
disabled: function(value) {
if (value === undefined) return !!this.attr('disabled');
if (value) {
this.attr('disabled', 'disabled');
} else {
this.removeAttr( 'disabled' );
this.removeAttr('disabled');
}
return this;
},
loading: function ( text ) {
if ( text ) {
this.disabled( true );
this.attr( 'origin-text', this.text() );
this.text( text );
loading: function(text) {
if (text) {
this.disabled(true);
this.attr('origin-text', this.text());
this.text(text);
} else {
this.text( this.attr( 'origin-text' ) );
this.removeAttr( 'origin-text' );
this.disabled( false );
this.text(this.attr('origin-text'));
this.removeAttr('origin-text');
this.disabled(false);
}
return this;
},
text: ( function () {
text: (function() {
var originFn = $.fn.text;
return function () {
var textSpan = this.children( 'span.text' );
if ( textSpan.length ) {
return originFn.apply( textSpan, arguments );
return function() {
var textSpan = this.children('span.text');
if (textSpan.length) {
return originFn.apply(textSpan, arguments);
} else {
return originFn.apply( this, arguments );
return originFn.apply(this, arguments);
}
};
} )()
} );
})()
});
/**
* 核心业务逻辑
*/
$( function () {
$(function() {
// UI 元素
var $panel, $login_btn, $save_btn, $share_btn, $user_btn, $user_menu,
var $panel, $title, $menu, $user, $share_btn, $save_btn, $file_btn, $file_menu, $login_btn, $user_btn, $logout_btn,
$draft_btn, $draft_menu, $share_dialog, $share_url, $copy_url_btn,
// 当前文件的远端路径
......@@ -66,8 +66,8 @@ $( function () {
isPathLink,
uuid = function () {
return ( ( +new Date() * 10000 ) + ( Math.random() * 9999 ) ).toString( 36 );
uuid = function() {
return ((+new Date() * 10000) + (Math.random() * 9999)).toString(36);
},
// 当前脑图的分享ID
......@@ -84,145 +84,159 @@ $( function () {
// 当前是否要检测文档内容是否变化的开关
watchingChanges = true,
notice = ( function () {
notice = (function() {
return window.alert;
} )();
})();
start();
function start() {
initUI();
initFrontia();
if ( checkLogin() ) {
if (checkLogin()) {
return;
}
loadShare();
bindShortCuts();
bindDraft();
if ( draftManager ) watchChanges();
if ( draftManager && !loadPath() && !isShareLink ) loadDraft( 0 );
if (draftManager) watchChanges();
loadDraft(0);
}
// 创建 UI
function initUI() {
$panel = $( '<div id="social"></div>' ).appendTo( 'body' );
$panel = $('<div id="social"></div>').appendTo('body');
$login_btn = $( '<button>登录</button>' ).addClass( 'login' ).click( login ).appendTo( $panel );
$menu = $('<div id="menu"></div>').appendTo($panel);
$user = $('<div id="user"></div>').appendTo($panel);
$title = $('<h2>百度脑图</h2>').appendTo($panel);
$user_btn = $( '<button><span class="text"></span></button>' ).addClass( 'user-file' );
$file_btn = $('<button>文件</button>').addClass('file-button').appendTo($menu);
$user_menu = $.kmuidropmenu( {
data: [ {
label: '新建脑图',
$file_menu = $.kmuidropmenu({
data: [{
label: '新建 (Ctrl + N)',
click: newFile
}, {
label: '到网盘管理文件...',
click: function () {
window.open( 'http://pan.baidu.com/disk/home#dir/path=/apps/kityminder' );
}
divider: true
}, {
label: '分享...',
click: share,
id: 'share-button'
}, {
divider: true,
id: 'cloud-divider'
}, {
label: '保存到百度云 (Ctrl + S)',
click: save,
id: 'save-button'
}, {
label: '注销',
click: logout
label: '到百度云管理文件...',
click: function() {
window.open('http://pan.baidu.com/disk/home#dir/path=/apps/kityminder');
},
id: 'manage-file-button'
}, {
divider: true
} ]
} ).addClass( 'user-file-menu' ).appendTo( 'body' ).kmui();
}]
}).addClass('file-menu').appendTo('body');
$user_menu.attachTo( $user_btn );
$file_menu.kmui().attachTo($file_btn);
$save_btn = $( '<button id="save-btn">保存</button>' ).click( save )
.addClass( 'baidu-cloud' );
$save_btn = $('#save-button').addClass('baidu-cloud').find('a');
$share_btn = $('#share-button').addClass('share').find('a');
$share_btn = $( '<button id="share-btn">分享</button>' ).click( share )
.addClass( 'share' ).appendTo( $panel );
$draft_btn = $('<button id="draft-btn">草稿箱</button>').appendTo($menu);
$draft_btn = $( '<button id="draft-btn">草稿箱</button>' ).appendTo( 'body' );
$draft_menu = $.kmuidropmenu().addClass('draft-menu kmui-combobox-menu').appendTo('body');
$draft_menu.kmui().attachTo($draft_btn);
$draft_menu.on('aftershow', showDraftList);
$draft_menu = $.kmuidropmenu().addClass( 'draft-menu kmui-combobox-menu' ).appendTo( 'body' );
$draft_menu.kmui().attachTo( $draft_btn );
$draft_menu.on( 'aftershow', showDraftList );
$login_btn = $('<a id="login-button">登录</a>').appendTo($user).click(login);
$user_btn = $('<a id="user-button" href="http://i.baidu.com/" target="_blank"></a>').appendTo($user);
$logout_btn = $('<a id="logout-button">注销</a>').appendTo($user).click(logout);
$share_dialog = $( '#share-dialog' );
$share_url = $( '#share-url' );
$copy_url_btn = $( '#copy-share-url' );
$share_dialog = $('#share-dialog');
$share_url = $('#share-url');
$copy_url_btn = $('#copy-share-url');
$share_dialog.mousedown( function ( e ) {
$share_dialog.mousedown(function(e) {
e.stopPropagation();
} );
});
var copyTrickTimer = 0;
$( 'body' ).on( 'mousedown', function ( e ) {
copyTrickTimer = setTimeout( function () {
$('body').on('mousedown', function(e) {
copyTrickTimer = setTimeout(function() {
$share_dialog.hide();
$share_btn.loading( false );
$copy_url_btn.loading( false );
}, 30 );
} );
$share_btn.loading(false);
$copy_url_btn.loading(false);
}, 30);
});
if ( window.ZeroClipboard ) {
var clip = new window.ZeroClipboard( $copy_url_btn, {
if (window.ZeroClipboard) {
var clip = new window.ZeroClipboard($copy_url_btn, {
hoverClass: 'hover',
activeClass: 'active'
} );
clip.on( 'dataRequested', function ( client, args ) {
$copy_url_btn.loading( '已复制' );
clearTimeout( copyTrickTimer );
} );
});
clip.on('dataRequested', function(client, args) {
$copy_url_btn.loading('已复制');
clearTimeout(copyTrickTimer);
});
}
}
// 初始化云平台 frontia
function initFrontia() {
var AK = 'wiE55BGOG8BkGnpPs6UNtPbb';
baidu.frontia.init( AK );
baidu.frontia.social.setLoginCallback( {
baidu.frontia.init(AK);
baidu.frontia.social.setLoginCallback({
success: setAccount,
error: function ( error ) {
notice( '登录失败!' );
error: function(error) {
notice('登录失败!');
}
} );
});
}
// 检查 URL 是否分享连接,是则加载分享内容
function loadShare() {
var pattern = /(?:shareId|share_id)=(\w+)([&#]|$)/;
var match = pattern.exec( window.location ) || pattern.exec( document.referrer );
if ( !match ) return;
var match = pattern.exec(window.location) || pattern.exec(document.referrer);
if (!match) return;
var shareId = match[ 1 ];
var shareId = match[1];
$.ajax( {
$.ajax({
url: 'http://naotu.baidu.com/mongo.php',
data: {
action: 'find',
id: shareId
},
dataType: 'json',
success: function ( data ) {
if ( data.error ) {
return notice( data.error );
success: function(data) {
if (data.error) {
return notice(data.error);
}
if ( draftManager ) {
var draft = draftManager.openByPath( 'share/' + shareId );
if ( draft ) {
if (draftManager) {
var draft = draftManager.openByPath('share/' + shareId);
if (draft) {
draftManager.load();
} else {
draftManager.create( 'share/' + shareId );
minder.importData( data.shareMinder.data, 'json' );
draftManager.create('share/' + shareId);
minder.importData(data.shareMinder.data, 'json');
}
} else {
minder.importData( data.shareMinder.data, 'json' );
minder.importData(data.shareMinder.data, 'json');
}
setRemotePath( null, false );
$share_btn.loading( false );
$title.loading(false);
setRemotePath(null, false);
},
error: function () {
notice( '请求分享文件失败,请重试!' );
error: function() {
notice('请求分享文件失败,请重试!');
}
} );
});
$share_btn.loading( '正在加载分享内容...' );
$title.loading('正在加载分享内容...');
isShareLink = true;
}
......@@ -231,47 +245,43 @@ $( function () {
function loadPath() {
var pattern = /path=(.+?)([&#]|$)/;
// documemt.referrer 是为了支持被嵌在 iframe 里的情况
var match = pattern.exec( window.location ) || pattern.exec( document.referrer );
if ( !match ) return;
if ( !currentAccount ) {
setTimeout( function () {
if ( !currentAccount ) return login();
setRemotePath( decodeURIComponent( match[ 1 ], true ) );
var match = pattern.exec(window.location) || pattern.exec(document.referrer);
if (!match) return;
if (!currentAccount) {
setTimeout(function() {
if (!currentAccount) return login();
setRemotePath(decodeURIComponent(match[1], true));
loadRemote();
}, 1000 );
}, 1000);
return false;
}
setRemotePath( decodeURIComponent( match[ 1 ], true ) );
setRemotePath(decodeURIComponent(match[1], true));
loadRemote();
return true;
}
function setRemotePath( path, saved ) {
function setRemotePath(path, saved) {
var filename;
remotePath = path;
if ( remotePath ) {
filename = getFileName( remotePath );
if ( !saved ) {
if (remotePath) {
filename = getFileName(remotePath);
if (!saved) {
filename = '* ' + filename;
}
$user_btn.text( filename );
} else if ( currentAccount ) {
$user_btn.text( '* ' + minder.getMinderTitle() );
}
document.title = [ filename || minder.getMinderTitle(), titleSuffix ].join( ' - ' );
if ( saved ) {
$save_btn.disabled( true ).text( '已保存' );
$title.text(filename);
} else if (currentAccount) {
$title.text('* ' + minder.getMinderTitle());
} else {
$save_btn.disabled( false ).text( '保存' );
$title.text(filename || minder.getMinderTitle());
}
document.title = [filename || minder.getMinderTitle(), titleSuffix].join(' - ');
}
// 检查是否在 Cookie 中登录过了
function checkLogin() {
var account = baidu.frontia.getCurrentAccount();
if ( account ) {
if (account) {
login();
return true;
}
......@@ -280,88 +290,83 @@ $( function () {
// 用户点击登录按钮主动登录
function login() {
baidu.frontia.social.login( {
baidu.frontia.social.login({
response_type: 'token',
media_type: 'baidu',
redirect_uri: window.location.href,
client_type: 'web'
} );
});
$login_btn.text('正在登录...').css('text-decoration', 'none');
}
function logout() {
baidu.frontia.logOutCurrentAccount();
setAccount( null );
setAccount(null);
$file_menu.removeClass('logined');
$user.removeClass('logined');
}
// 设置用户后为其初始化
function setAccount( account ) {
function setAccount(account) {
currentAccount = account;
if ( account ) {
$user_btn.prependTo( $panel );
$save_btn.appendTo( $panel );
$share_btn.appendTo( $panel );
$login_btn.detach();
if (account) {
loadAvator();
loadUserFiles();
window.location.hash = '';
} else {
$user_btn.detach();
$save_btn.detach();
$login_btn.prependTo( $panel );
$user_btn.text(account.accountName);
}
$file_menu.addClass('logined');
$user.addClass('logined');
}
// 加载用户头像
function loadAvator() {
var $img = $( '<img />' ).attr( {
'src': 'social/loading.gif',
'width': 16,
'height': 16
} ).prependTo( $user_btn );
currentAccount.getDetailInfo( {
success: function ( user ) {
$img.attr( {
'src': user.extra.tinyurl
} );
currentAccount.getDetailInfo({
success: function(user) {
$('<img />').attr({
'src': user.extra.tinyurl,
'width': 16,
'height': 16
}).prependTo($user_btn);
}
} );
});
}
// 加载用户最近使用的文件
function loadUserFiles() {
if ( loadUserFiles.tryCount ) {
console.warn( '加载用户最近使用的文件失败:第 ' + loadUserFiles.tryCount + '次' );
if (loadUserFiles.tryCount) {
console.warn('加载用户最近使用的文件失败:第 ' + loadUserFiles.tryCount + '次');
}
if ( loadUserFiles.tryCount > 3 ) {
notice( '加载最近脑图失败!' );
if (loadUserFiles.tryCount > 3) {
notice('加载最近脑图失败!');
loadUserFiles.tryCount = 0;
}
var sto = baidu.frontia.personalStorage;
if ( loadUserFiles.tryCount === 0 ) {
loadUserFiles.$loadingMenuItem = $user_menu.appendItem( {
if (loadUserFiles.tryCount === 0) {
loadUserFiles.$loadingMenuItem = $file_menu.kmui().appendItem({
item: {
label: '正在加载最近脑图...',
disabled: 'disabled'
}
} );
});
}
sto.listFile( 'apps/kityminder/', {
sto.listFile('apps/kityminder/', {
by: 'time',
success: function ( result ) {
if ( result.list.length ) {
success: function(result) {
if (result.list.length) {
loadUserFiles.$loadingMenuItem.remove();
addToRecentMenu( result.list.filter( function ( file ) {
return getFileFormat( file.path ) in fileLoader;
} ) );
syncPreference( result.list );
addToRecentMenu(result.list.filter(function(file) {
return getFileFormat(file.path) in fileLoader;
}));
syncPreference(result.list);
}
},
error: loadUserFiles
} );
});
loadUserFiles.tryCount++;
}
......@@ -369,7 +374,7 @@ $( function () {
loadUserFiles.tryCount = 0;
// 同步用户配置文件
function syncPreference( fileList ) {
function syncPreference(fileList) {
// frontia 接口对象引用
var sto = baidu.frontia.personalStorage;
......@@ -378,9 +383,9 @@ $( function () {
var remotePreferencesPath = '/apps/kityminder/app.preferences';
// 检查是否存在线上的配置文件
var hasRemotePreferences = ~fileList.map( function ( file ) {
var hasRemotePreferences = ~fileList.map(function(file) {
return file.path;
} ).indexOf( remotePreferencesPath );
}).indexOf(remotePreferencesPath);
// 记录远端配置的和本地配置的版本
// - 远端配置保存在 json 内容的 version 字段中
......@@ -393,15 +398,15 @@ $( function () {
// 远端有配置,下载远端配置
if ( hasRemotePreferences ) {
if (hasRemotePreferences) {
downloadPreferences();
}
// 绑定实例上配置改变的事件,配置有变需要上传
minder.on( 'preferenceschange', function () {
minder.on('preferenceschange', function() {
localStorage.preferencesVersion = ++localVersion;
uploadPreferences();
} );
});
// 下载远端配置
function downloadPreferences() {
......@@ -409,16 +414,16 @@ $( function () {
// 比较远端和本地版本
// - 远端版本较新则设置本地版本为远端版本
// - 本地版本较新则上传本地版本
function merge( remote ) {
function merge(remote) {
remoteVersion = remote.version;
remotePreferences = remote.preferences;
localPreferences = minder.getPreferences();
if ( localVersion < remoteVersion ) {
minder.resetPreferences( remotePreferences );
} else if ( localVersion > remoteVersion ) {
if (localVersion < remoteVersion) {
minder.resetPreferences(remotePreferences);
} else if (localVersion > remoteVersion) {
uploadPreferences();
}
......@@ -426,19 +431,19 @@ $( function () {
// 下载配置的过程
// 需要先获得下载的 URL 再使用 ajax 请求内容
sto.getFileUrl( remotePreferencesPath, {
success: function ( url ) {
$.ajax( {
sto.getFileUrl(remotePreferencesPath, {
success: function(url) {
$.ajax({
url: url,
cache: false,
dataType: 'json',
success: merge,
error: function () {
notice( '下载配置失败!' );
error: function() {
notice('下载配置失败!');
}
} );
});
}
} );
});
}
// 上传本地配置
......@@ -452,58 +457,58 @@ $( function () {
preferences: localPreferences
};
var text = JSON.stringify( data );
var text = JSON.stringify(data);
sto.uploadTextFile( text, remotePreferencesPath, {
sto.uploadTextFile(text, remotePreferencesPath, {
// 文件重复选择覆盖
ondup: sto.constant.ONDUP_OVERWRITE,
success: function ( savedFile ) {
console && console.log( '配置已上传' );
success: function(savedFile) {
console && console.log('配置已上传');
},
error: function ( e ) {
notice( '上传配置失败' );
error: function(e) {
notice('上传配置失败');
}
} );
});
}
}
// 加载当前 remoteUrl 中制定的文件
function loadRemote() {
if ( loadRemote.tryCount ) {
console.warn( '加载用户文件失败:第 ' + loadUserFiles.tryCount + '次' );
if (loadRemote.tryCount) {
console.warn('加载用户文件失败:第 ' + loadUserFiles.tryCount + '次');
}
// 失败重试判断
if ( loadRemote.tryCount > 3 ) {
notice( '加载脑图失败!' );
if (loadRemote.tryCount > 3) {
notice('加载脑图失败!');
loadRemote.tryCount = 0;
}
var sto = baidu.frontia.personalStorage;
$user_btn.loading( '加载“' + getFileName( remotePath ) + '”...' );
$title.loading('加载“' + getFileName(remotePath) + '”...');
sto.getFileUrl( remotePath, {
success: function ( url ) {
sto.getFileUrl(remotePath, {
success: function(url) {
// the url to download the file on cloud dist
var format = getFileFormat( remotePath );
if ( format in fileLoader ) {
fileLoader[ format ]( url );
var format = getFileFormat(remotePath);
if (format in fileLoader) {
fileLoader[format](url);
}
loadRemote.tryCount = 0;
},
error: loadRemote
} );
});
loadRemote.tryCount++;
}
loadRemote.tryCount = 0;
function getFileFormat( fileUrl ) {
return fileUrl.split( '.' ).pop();
function getFileFormat(fileUrl) {
return fileUrl.split('.').pop();
}
var fileLoader = {
......@@ -514,109 +519,109 @@ $( function () {
'mm': loadFreeMind
};
function loadPlainType( url ) {
$.ajax( {
function loadPlainType(url) {
$.ajax({
cache: false,
url: url,
dataType: 'text',
success: function ( result ) {
importFile( result, 'json' );
success: function(result) {
importFile(result, 'json');
}
} );
});
}
function loadXMind( url ) {
function loadXMind(url) {
var xhr = new XMLHttpRequest();
xhr.open( "get", url, true );
xhr.open("get", url, true);
xhr.responseType = "blob";
xhr.onload = function () {
if ( this.status == 200 && this.readyState ) {
xhr.onload = function() {
if (this.status == 200 && this.readyState) {
var blob = this.response;
importFile( blob, 'xmind' );
importFile(blob, 'xmind');
}
};
xhr.send();
}
function loadMindManager( url ) {
function loadMindManager(url) {
var xhr = new XMLHttpRequest();
xhr.open( "get", url, true );
xhr.open("get", url, true);
xhr.responseType = "blob";
xhr.onload = function () {
if ( this.status == 200 && this.readyState ) {
xhr.onload = function() {
if (this.status == 200 && this.readyState) {
var blob = this.response;
importFile( blob, 'mindmanager' );
importFile(blob, 'mindmanager');
}
};
xhr.send();
}
function loadFreeMind( url ) {
$.ajax( {
function loadFreeMind(url) {
$.ajax({
cache: false,
url: url,
dataType: 'text',
success: function ( result ) {
importFile( result, 'freemind' );
success: function(result) {
importFile(result, 'freemind');
}
} );
});
}
// 见文件数据导入minder
function importFile( data, format ) {
function importFile(data, format) {
watchingChanges = false;
minder.importData( data, format );
minder.importData(data, format);
if ( draftManager ) {
if ( !draftManager.openByPath( remotePath ) ) {
if (draftManager) {
if (!draftManager.openByPath(remotePath)) {
draftManager.create();
}
draftManager.save( remotePath );
draftManager.save(remotePath);
draftManager.sync();
}
minder.execCommand( 'camera', minder.getRoot() );
$user_btn.loading( false ).text( getFileName( remotePath ) );
minder.execCommand('camera', minder.getRoot());
$title.loading(false).text(getFileName(remotePath));
watchingChanges = true;
}
// 添加文件到最近文件列表
function addToRecentMenu( list ) {
list.splice( 12 );
list.forEach( function ( file ) {
$user_menu.appendItem( {
function addToRecentMenu(list) {
list.splice(12);
list.forEach(function(file) {
$file_menu.kmui().appendItem({
item: {
label: getFileName( file.path ),
label: getFileName(file.path),
value: file.path
},
click: openFile
} );
} );
});
});
}
// 从路径中抽取文件名
function getFileName( path ) {
return path.split( '/' ).pop();
function getFileName(path) {
return path.split('/').pop();
}
// 点击文件菜单
function openFile( e ) {
var path = $( this ).data( 'value' );
function openFile(e) {
var path = $(this).data('value');
var draft = draftManager && draftManager.getCurrent();
if ( draft && draft.path == path ) {
if ( !draft.sync && window.confirm( '“' + getFileName( path ) + '”在草稿箱包含未保存的更改,确定加载网盘版本覆盖草稿箱中的版本吗?' ) ) {
setRemotePath( path, true );
if (draft && draft.path == path) {
if (!draft.sync && window.confirm('“' + getFileName(path) + '”在草稿箱包含未保存的更改,确定加载网盘版本覆盖草稿箱中的版本吗?')) {
setRemotePath(path, true);
loadRemote();
}
} else if ( draftManager ) {
draft = draftManager.openByPath( path );
setRemotePath( path, !draft || draft.sync );
if ( draft ) {
} else if (draftManager) {
draft = draftManager.openByPath(path);
setRemotePath(path, !draft || draft.sync);
if (draft) {
watchingChanges = false;
draftManager.load();
watchingChanges = true;
......@@ -624,65 +629,67 @@ $( function () {
loadRemote();
}
} else {
setRemotePath( path, true );
setRemotePath(path, true);
loadRemote();
}
}
// 新建文件
function newFile() {
setRemotePath( null, true );
setRemotePath(null, true);
draftManager.create();
minder.importData( '新建脑图', 'plain' );
minder.execCommand( 'camera', minder.getRoot() );
minder.importData('新建脑图', 'plain');
minder.execCommand('camera', minder.getRoot());
}
function generateRemotePath() {
var filename = window.prompt( "请输入文件名: ", minder.getMinderTitle() ) || minder.getMinderTitle();
var filename = window.prompt("请输入文件名: ", minder.getMinderTitle()) || minder.getMinderTitle();
return '/apps/kityminder/' + filename + '.km';
}
function save() {
if ( !currentAccount || save.busy ) return;
if (!currentAccount || save.busy) return;
save.busy = true;
var data = minder.exportData( 'json' );
var data = minder.exportData('json');
var sto = baidu.frontia.personalStorage;
function error( reason ) {
notice( '保存到云盘失败,可能是网络问题导致!\n建议您将脑图以 .km 格式导出到本地!' );
$save_btn.loading( false );
clearTimeout( timeout );
function error(reason) {
notice('保存到云盘失败,可能是网络问题导致!\n建议您将脑图以 .km 格式导出到本地!');
$title.loading(false);
clearTimeout(timeout);
save.busy = false;
}
var timeout = setTimeout( function () {
error( '保存到云盘超时,可能是网络不稳定导致。' );
}, 15000 );
var timeout = setTimeout(function() {
error('保存到云盘超时,可能是网络不稳定导致。');
}, 15000);
function upload() {
if ( upload.tryCount ) {
console.warn( '保存文件失败!(第 ' + upload.tryCount + ' 次)' );
if (upload.tryCount) {
console.warn('保存文件失败!(第 ' + upload.tryCount + ' 次)');
}
if ( upload.tryCount > 3 ) {
if (upload.tryCount > 3) {
error();
upload.tryCount = 0;
return;
}
sto.uploadTextFile( data, remotePath || generateRemotePath(), {
var uploadPath = remotePath || generateRemotePath();
$title.loading('正在保存 “' + getFileName(uploadPath) + '” ...');
sto.uploadTextFile(data, uploadPath, {
ondup: remotePath ? sto.constant.ONDUP_OVERWRITE : sto.constant.ONDUP_NEWCOPY,
success: function ( savedFile ) {
if ( savedFile.path ) {
if ( !remotePath ) {
addToRecentMenu( [ savedFile ] );
success: function(savedFile) {
if (savedFile.path) {
if (!remotePath) {
addToRecentMenu([savedFile]);
}
setRemotePath( savedFile.path, true );
if ( draftManager ) {
draftManager.save( remotePath );
setRemotePath(savedFile.path, true);
if (draftManager) {
draftManager.save(remotePath);
draftManager.sync();
}
clearTimeout( timeout );
clearTimeout(timeout);
save.busy = false;
upload.tryCount = 0;
} else {
......@@ -690,62 +697,62 @@ $( function () {
}
},
error: upload
} );
});
upload.tryCount++;
}
upload.tryCount = 0;
upload();
$save_btn.loading( '正在保存...' );
}
function share() {
if ( $share_btn.disabled() ) {
if ($share_btn.disabled()) {
return;
}
var baseUrl = /^(.*?)(\?|\#|$)/.exec( window.location.href )[ 1 ];
var baseUrl = /^(.*?)(\?|\#|$)/.exec(window.location.href)[1];
var shareUrl = baseUrl + '?shareId=' + shareId,
shareData = new baidu.frontia.Data( {
shareData = new baidu.frontia.Data({
shareMinder: {
id: shareId,
data: minder.exportData( 'json' )
data: minder.exportData('json')
}
} );
});
var shareConfig = window._bd_share_config.common,
resetShare = window._bd_share_main.init;
$share_btn.loading( '正在分享...' );
$title.loading('正在分享 “' + getFileName(remotePath) + '”...');
$.ajax( {
$.ajax({
url: 'http://naotu.baidu.com/mongo.php',
type: 'POST',
data: {
action: 'insert',
record: JSON.stringify( {
record: JSON.stringify({
shareMinder: {
id: shareId,
data: minder.exportData( 'json' )
data: minder.exportData('json')
}
} )
})
},
success: function ( result ) {
if ( result.error ) {
notice( result.error );
success: function(result) {
if (result.error) {
notice(result.error);
} else {
$share_dialog.show();
$share_url.val( shareUrl )[ 0 ].select();
$share_url.val(shareUrl)[0].select();
}
$title.loading(false);
},
error: function () {
notice( '分享失败,可能是当前的环境不支持该操作。' );
error: function() {
notice('分享失败,可能是当前的环境不支持该操作。');
$title.loading(false);
}
} );
});
shareConfig.bdTitle = shareConfig.bdText = minder.getMinderTitle();
shareConfig.bdDesc = shareConfig.bdText = '“' + minder.getMinderTitle() + '” - 我用百度脑图制作的思维导图,快看看吧!(地址:' + shareUrl + ')';
......@@ -755,147 +762,152 @@ $( function () {
function bindShortCuts() {
$( document.body ).keydown( function ( e ) {
$(document.body).keydown(function(e) {
var keyCode = e.keyCode || e.which;
//添加快捷键
if ( ( e.ctrlKey || e.metaKey ) ) {
switch ( keyCode ) {
if ((e.ctrlKey || e.metaKey)) {
switch (keyCode) {
//保存
case KM.keymap.s:
if ( e.shiftKey ) {
share();
} else {
save();
}
e.preventDefault();
break;
case KM.keymap.n:
newFile();
e.preventDefault();
break;
case KM.keymap.s:
if (e.shiftKey) {
share();
} else {
save();
}
e.preventDefault();
break;
case KM.keymap.n:
newFile();
e.preventDefault();
break;
}
}
} );
});
}
function watchChanges() {
minder.on( 'contentchange', function () {
if ( !watchingChanges ) return;
var lastContent = minder.exportData('json');
minder.on('contentchange', function() {
if (!watchingChanges || lastContent == minder.exportData('json')) return;
var current = draftManager.save();
if ( currentAccount ) {
$save_btn.disabled( current.sync ).text( '保存' );
setRemotePath( remotePath, current.sync );
if (currentAccount) {
setRemotePath(remotePath, current.sync);
}
} );
lastContent = minder.exportData('json');
});
}
function showDraftList() {
var list = draftManager.list(),
draft, $draft, index;
if ( !list.length ) {
if (!list.length) {
draftManager.create();
list = draftManager.list();
}
$draft_menu.empty();
draft = list.shift();
$draft_menu.empty().append( '<li disabled="disabled" class="current-draft kmui-combobox-item kmui-combobox-item-disabled kmui-combobox-checked">' +
'<span class="kmui-combobox-icon"></span>' +
'<label class="kmui-combobox-item-label">' + draft.name +
'<span class="update-time">' + getFriendlyTimeSpan( +new Date( draft.update ), +new Date() ) + '</span>' +
'</label>' +
'</li>' );
$draft_menu.append( '<li class="kmui-divider"></li>' );
if (draftManager.getCurrent()) {
draft = list.shift();
$draft_menu.append('<li disabled="disabled" class="current-draft kmui-combobox-item kmui-combobox-item-disabled kmui-combobox-checked">' +
'<span class="kmui-combobox-icon"></span>' +
'<label class="kmui-combobox-item-label">' + draft.name +
'<span class="update-time">' + getFriendlyTimeSpan(+new Date(draft.update), +new Date()) + '</span>' +
'</label>' +
'</li>');
$draft_menu.append('<li class="kmui-divider"></li>');
index = 1;
} else {
index = 0;
}
index = 1;
while ( list.length ) {
while (list.length) {
draft = list.shift();
$draft = $( '<li class="draft-item">' +
'<a href="#">' + draft.name + '<span class="update-time">' + getFriendlyTimeSpan( +new Date( draft.update ), +new Date() ) + '</span></a><a class="delete" title="删除该草稿"></a></li>' );
$draft.data( 'draft-index', index++ );
$draft.appendTo( $draft_menu );
$draft = $('<li class="draft-item">' +
'<a href="#">' + draft.name + '<span class="update-time">' + getFriendlyTimeSpan(+new Date(draft.update), +new Date()) + '</span></a><a class="delete" title="删除该草稿"></a></li>');
$draft.data('draft-index', index++);
$draft.appendTo($draft_menu);
}
if ( index > 1 ) {
$draft_menu.append( '<li class="kmui-divider"></li>' );
$draft_menu.append( '<li class="draft-clear"><a href="#">清空草稿箱</a></li>' );
if (index > 1) {
$draft_menu.append('<li class="kmui-divider"></li>');
$draft_menu.append('<li class="draft-clear"><a href="#">清空草稿箱</a></li>');
}
adjustDraftMenu();
//adjustDraftMenu();
}
function adjustDraftMenu() {
var pos = $draft_btn.offset();
pos.top -= $draft_menu.outerHeight() + 5;
$draft_menu.offset( pos );
$draft_menu.offset(pos);
}
function bindDraft() {
draftManager = window.draftManager;
if ( !draftManager ) {
if ( window.DraftManager ) {
draftManager = window.draftManager = new window.DraftManager( minder );
if (!draftManager) {
if (window.DraftManager) {
draftManager = window.draftManager = new window.DraftManager(minder);
}
}
$draft_menu.delegate( 'a.delete', 'click', function ( e ) {
var $li = $( this ).closest( 'li.draft-item' );
draftManager.remove( +$li.data( 'draft-index' ) );
$draft_menu.delegate('a.delete', 'click', function(e) {
var $li = $(this).closest('li.draft-item');
draftManager.remove(+$li.data('draft-index'));
$li.remove();
showDraftList();
e.stopPropagation();
} )
})
.delegate( 'li.draft-clear', 'click', function ( e ) {
if ( window.confirm( '确认清除草稿箱吗?' ) ) {
.delegate('li.draft-clear', 'click', function(e) {
if (window.confirm('确认清除草稿箱吗?')) {
draftManager.clear();
showDraftList();
}
e.stopPropagation();
} )
})
.delegate( 'li.draft-item', 'click', function ( e ) {
loadDraft( +$( this ).data( 'draft-index' ) );
} );
.delegate('li.draft-item', 'click', function(e) {
loadDraft(+$(this).data('draft-index'));
});
}
function loadDraft( index ) {
var draft = draftManager.open( index ),
function loadDraft(index) {
var draft = draftManager.open(index),
isRemote;
if ( !draft ) {
if (!draft) {
minder.initStyle();
return;
}
isRemote = draft.path.indexOf( '/apps/kityminder' ) === 0;
if ( isRemote ) {
setRemotePath( draft.path, draft.sync );
isRemote = draft.path.indexOf('/apps/kityminder') === 0;
if (isRemote) {
setRemotePath(draft.path, draft.sync);
}
watchingChanges = false;
draftManager.load();
watchingChanges = true;
if ( !isRemote ) {
setRemotePath( null, false );
if (!isRemote) {
setRemotePath(null, false);
}
}
function getFriendlyTimeSpan( t1_in_ms, t2_in_ms ) {
var ms = Math.abs( t1_in_ms - t2_in_ms ),
function getFriendlyTimeSpan(t1_in_ms, t2_in_ms) {
var ms = Math.abs(t1_in_ms - t2_in_ms),
s = ms / 1000,
m = s / 60,
h = m / 60,
d = h / 24;
if ( s < 60 ) return "刚刚";
if ( m < 60 ) return ( m | 0 ) + "分钟前";
if ( h < 24 ) return ( h | 0 ) + "小时前";
if ( d <= 30 ) return ( d | 0 ) + "天前";
if (s < 60) return "刚刚";
if (m < 60) return (m | 0) + "分钟前";
if (h < 24) return (h | 0) + "小时前";
if (d <= 30) return (d | 0) + "天前";
return "很久之前";
}
window.social = {
setRemotePath: setRemotePath,
watchChanges: function ( value ) {
watchChanges: function(value) {
watchingChanges = value;
}
};
} );
\ No newline at end of file
});
\ No newline at end of file
#social {
position: absolute;
right: 10px;
top: 10px;
line-height: 20px;
text-align: right;
height: 30px;
left: 0;
right: 0;
top: 0;
line-height: 30px;
overflow: hidden;
background: #fafafa;
border-bottom: 1px solid #fff;
box-shadow: inset 0 -1px #f0f0f0;
z-index: 1000;
h2 {
margin: 0 200px;
padding: 0;
color: #999;
text-shadow: 0 1px white;
font-size: 12px;
text-align: center;
font-weight: normal;
}
#menu {
float: left;
}
#user {
float: right;
padding-right: 10px;
a {
color: #333;
font-size: 12px;
text-decoration: underline;
padding: 0 5px;
cursor: pointer;
img {
vertical-align: text-bottom;
margin-right: 5px;
}
}
#logout-button, #user-button {
display: none;
}
&.logined {
#logout-button, #user-button {
display: inline-block;
}
#login-button {
display: none;
}
}
}
}
.niceblue {
color: white;
background: -moz-linear-gradient(top, #0099f2 0%, #4096ee 0%, #0076dd 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#0099f2), color-stop(0%,#4096ee), color-stop(100%,#0076dd)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #0099f2 0%,#4096ee 0%,#0076dd 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #0099f2 0%,#4096ee 0%,#0076dd 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #0099f2 0%,#4096ee 0%,#0076dd 100%); /* IE10+ */
background: linear-gradient(to bottom, #0099f2 0%,#4096ee 0%,#0076dd 100%); /* W3C */
&:after {
border-color: #fff transparent transparent transparent;
}
}
.dropdown {
padding-right: 28px;
position: relative;
&:after {
content: ' ';
display: block;
position: absolute;
right: 10px;
top: 15px;
top: 12px;
width: 0;
height: 0;
border: solid;
border-width: 4px 5px;
border-color: #FFFFFF transparent transparent transparent;
border-color: #333 transparent transparent transparent;
}
&:active, &.active {
&:after {
border-color: #fff transparent transparent transparent;
}
}
}
......@@ -29,41 +99,31 @@ button {
display: inline-block;
vertical-align: middle;
padding: 0 15px;
height: 35px;
height: 30px;
font-size: 13px;
line-height: 35px;
line-height: 30px;
text-align: center;
border-radius: 5px;
color: #ffffff;
color: #000;
text-decoration: none;
border: none;
margin-left: 5px;
cursor: pointer;
background: #0099f2; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzAwOTlmMiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjAlIiBzdG9wLWNvbG9yPSIjNDA5NmVlIiBzdG9wLW9wYWNpdHk9IjEiLz4KICAgIDxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzAwNzZkZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background: -moz-linear-gradient(top, #0099f2 0%, #4096ee 0%, #0076dd 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#0099f2), color-stop(0%,#4096ee), color-stop(100%,#0076dd)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #0099f2 0%,#4096ee 0%,#0076dd 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #0099f2 0%,#4096ee 0%,#0076dd 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #0099f2 0%,#4096ee 0%,#0076dd 100%); /* IE10+ */
background: linear-gradient(to bottom, #0099f2 0%,#4096ee 0%,#0076dd 100%); /* W3C */
background: none;
border-radius: 2px;
&:hover, &.hover {
background: #009fff;
}
&:active, &.active {
background: darken(#009fff, 10%);
box-shadow: inset 0 2px 3px rgba(0,0,0, .2);
box-shadow: inset 0 1px 3px rgba(0,0,0,.2);
background: #ccc;
color: white;
}
&[disabled] {
background: #AAA;
cursor: default;
}
&.baidu-cloud {
&.share {
padding-left: 35px;
position: relative;
&:before {
......@@ -71,65 +131,79 @@ button {
display: block;
width: 24px;
height: 24px;
background: url(../themes/default/images/baiducloud.png);
background: url(../themes/default/images/share.png) no-repeat;
position: absolute;
left: 7px;
top: 5px;
}
}
img {
position: relative;
top: 3px;
border-radius: 2px;
margin-right: 7px;
}
&.file-button {
.dropdown;
.niceblue;
&.share {
padding-left: 35px;
border-radius: 5px 5px 0 0;
margin-left: 5px;
&:hover, &.hover {
background: #009fff;
}
&:active, &.active {
background: darken(#009fff, 10%);
box-shadow: inset 0 2px 3px rgba(0,0,0, .2);
}
}
}
#save-button {
a {
position: relative;
&:before {
content: ' ';
display: block;
width: 24px;
height: 24px;
background: url(../themes/default/images/share.png) no-repeat;
background: url(../themes/default/images/baiducloud.png);
position: absolute;
left: 7px;
top: 5px;
left: 4px;
top: 2px;
}
}
img {
position: relative;
top: 3px;
border-radius: 2px;
margin-right: 7px;
&:hover a:before {
background-position: 0 -24px;
}
&.user-file {
}
#share-button {
a {
position: relative;
img {
border: none;
outline: none;
}
span.text {
display: inline-block;
&:before {
content: ' ';
display: block;
width: 24px;
height: 24px;
line-height: 24px;
background: url(../themes/default/images/share.png);
position: absolute;
left: 4px;
top: 2px;
}
.dropdown;
}
&:hover a:before {
background-position: 0 -24px;
}
}
#draft-btn {
position: absolute;
left: 10px;
bottom: 10px;
&:before {
content: ' ';
display: block;
width: 24px;
height: 24px;
background: url(../themes/default/images/draft.png) no-repeat;
position: absolute;
left: 7px;
top: 5px;
}
padding-left: 35px;
.dropdown;
border-radius: 5px 5px 0 0;
}
.draft-menu {
.draft-menu.kmui-dropdown-menu {
margin-top: 14px;
margin-left: -1px;
span.update-time {
float: right;
color: #CCC;
......@@ -198,17 +272,30 @@ button {
}
}
}
.user-file-menu {
margin-top: 20px;
.file-menu.kmui-dropdown-menu {
margin-top: 14px;
margin-left: 1px;
box-shadow: 0px 1px 5px rgba(0,0,0, .3);
#save-button, #manage-file-button, #share-button + .kmui-divider {
display: none;
}
&.logined {
#save-button, #manage-file-button, #share-button + .kmui-divider {
display: block;
}
}
}
#share-dialog {
position: absolute;
padding: 20px;
border-radius: 4px;
right: 10px;
top: 65px;
left: 50%;
top: 40%;
margin-left: -175px;
margin-top: -100px;
background: white;
width: 350px;
box-shadow: 1px 2px 16px rgba(0, 0, 0, .5);
......@@ -247,22 +334,24 @@ button {
line-height: 28px;
border-radius: 2px;
vertical-align: middle;
color: white;
border-radius: 5px;
.niceblue;
&:hover, &.hover {
background: #009fff;
}
&:active, &.active {
background: darken(#009fff, 10%);
box-shadow: inset 0 2px 3px rgba(0,0,0, .2);
}
}
#share-platform {
margin-bottom: 0;
}
&:before {
position: absolute;
content: ' ';
width: 0;
height: 0;
line-height: 0;
display: block;
border: 10px solid transparent;
border-bottom-color: white;
right: 30px;
top: -20px;
}
}
\ No newline at end of file
KM.registerToolbarUI( 'markers help preference resource', function ( name ) {
KM.registerToolbarUI('markers help preference resource', function(name) {
var me = this,
currentRange, $dialog,
opt = {
title: this.getLang( 'tooltips' )[ name ] || '',
url: me.getOptions( 'KITYMINDER_HOME_URL' ) + 'dialogs/' + name + '/' + name + '.js',
title: this.getLang('tooltips')[name] || '',
url: me.getOptions('KITYMINDER_HOME_URL') + 'dialogs/' + name + '/' + name + '.js',
};
var $btn = $.kmuibutton( {
var $btn = $.kmuibutton({
icon: name,
title: this.getLang( 'tooltips' )[ name ] || ''
} );
title: this.getLang('tooltips')[name] || ''
});
//加载模版数据
utils.loadFile( document, {
utils.loadFile(document, {
src: opt.url,
tag: "script",
type: "text/javascript",
defer: "defer"
}, function () {
tag: 'script',
type: 'text/javascript',
defer: 'defer'
}, function() {
$dialog = $.kmuimodal( opt );
$dialog = $.kmuimodal(opt);
$dialog.attr( 'id', 'kmui-dialog-' + name ).addClass( 'kmui-dialog-' + name )
.find( '.kmui-modal-body' ).addClass( 'kmui-dialog-' + name + '-body' );
$dialog.attr('id', 'kmui-dialog-' + name).addClass('kmui-dialog-' + name)
.find('.kmui-modal-body').addClass('kmui-dialog-' + name + '-body');
$dialog.kmui().on( 'beforeshow', function () {
$dialog.kmui().on('beforeshow', function() {
var $root = this.root(),
win = null,
offset = null;
if ( !$root.parent()[ 0 ] ) {
me.$container.find( '.kmui-dialog-container' ).append( $root );
if (!$root.parent()[0]) {
me.$container.find('.kmui-dialog-container').append($root);
}
KM.setWidgetBody( name, $dialog, me );
} ).attachTo( $btn )
} );
KM.setWidgetBody(name, $dialog, me);
}).attachTo($btn);
});
me.on( 'interactchange', function () {
var state = this.queryCommandState( name );
$btn.kmui().disabled( state == -1 ).active( state == 1 )
} );
me.on('interactchange', function() {
var state = this.queryCommandState(name);
$btn.kmui().disabled(state == -1).active(state == 1);
});
switch (name) {
case 'markers':
me.addContextmenu([{
label: me.getLang('marker.marker'),
exec: function() {
$dialog.kmui().show();
},
cmdName: 'markers'
}]);
break;
case 'resource':
me.addContextmenu([{
label: me.getLang('resource.resource'),
exec: function() {
$dialog.kmui().show();
},
cmdName: 'resource'
}]);
}
return $btn;
} );
\ No newline at end of file
});
\ No newline at end of file
KM.registerToolbarUI('template theme', function(name) {
var values = utils.keys(name == 'template' ? KM.getTemplateList() : KM.getThemeList());
var me = this,
label = me.getLang('tooltips.' + name),
options = {
label: label,
title: label,
comboboxName: name,
items: values.map(function(value) {
return me.getLang(name)[value];
}),
itemStyles: [],
value: values,
autowidthitem: [],
enabledRecord: false
},
$combox = null;
//实例化
$combox = $.kmuibuttoncombobox(options).css('zIndex', me.getOptions('zIndex') + 1);
var comboboxWidget = $combox.kmui();
comboboxWidget.on('comboboxselect', function(evt, res) {
me.execCommand(name, res.value);
}).on('beforeshow', function() {
if ($combox.parent().length === 0) {
$combox.appendTo(me.$container.find('.kmui-dialog-container'));
}
});
//状态反射
me.on('interactchange', function() {
var state = this.queryCommandState(name),
value = this.queryCommandValue(name);
//设置按钮状态
comboboxWidget.button().kmui().disabled(state == -1).active(state == 1);
if (value) {
comboboxWidget.selectItemByValue(value);
}
});
return comboboxWidget.button().addClass('kmui-combobox');
});
\ No newline at end of file
KM.registerToolbarUI('switchlayout', function(name) {
// var me = this,
// label = me.getLang('tooltips.' + name),
// options = {
// label: label,
// title: label,
// comboboxName: name,
// items: me.getLayoutStyleItems() || [],
// itemStyles: [],
// value: me.getLayoutStyleItems(),
// autowidthitem: [],
// enabledRecord: false
// },
// $combox = null;
// if (options.items.length == 0) {
// return null;
// }
// utils.each(options.items, function(i, item) {
// options.items[i] = me.getLang('layout')[item];
// });
// //实例化
// $combox = $.kmuibuttoncombobox(options).css('zIndex', me.getOptions('zIndex') + 1);
// var comboboxWidget = $combox.kmui();
// comboboxWidget.on('comboboxselect', function(evt, res) {
// me.execCommand(name, res.value);
// me.initStyle();
// }).on("beforeshow", function() {
// if ($combox.parent().length === 0) {
// $combox.appendTo(me.$container.find('.kmui-dialog-container'));
// }
// });
// //状态反射
// me.on('interactchange', function() {
// var state = this.queryCommandState(name),
// value = this.queryCommandValue(name);
// //设置按钮状态
// comboboxWidget.button().kmui().disabled(state == -1).active(state == 1);
// if (value) {
// //设置label
// value = value.replace(/['"]/g, '').toLowerCase().split(/['|"]?\s*,\s*[\1]?/);
// comboboxWidget.selectItemByLabel(value);
// }
// });
// // var data = [];
// // utils.each(me.getLayoutStyleItems(), function (i, v) {
// // data.push({
// // label: me.getLang('tooltips.' + name) + ' ' + v,
// // cmdName: 'switchlayout',
// // exec: function () {
// // me.execCommand('switchlayout', v);
// // }
// // });
// // });
// // data.push({
// // divider: 1
// // });
// // me.addContextmenu(data);
// return comboboxWidget.button().addClass('kmui-combobox');
});
\ No newline at end of file
KM.registerToolbarUI( 'saveto', function ( name ) {
KM.registerToolbarUI('saveto', function(name) {
var me = this,
label = me.getLang( 'tooltips.' + name ),
label = me.getLang('tooltips.' + name),
options = {
label: label,
title: label,
......@@ -16,92 +16,81 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
$combox = null,
comboboxWidget = null;
utils.each( KityMinder.getAllRegisteredProtocals(), function ( k ) {
var p = KityMinder.findProtocal( k );
if ( p.encode ) {
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 );
options.value.push(k);
options.items.push(text);
options.autowidthitem.push($.wordCountAdaptive(text), true);
}
} );
});
//实例化
$combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
$combox = $.kmuibuttoncombobox(options).css('zIndex', me.getOptions('zIndex') + 1);
comboboxWidget = $combox.kmui();
function doDownload( url, filename ) {
var a = document.createElement( 'a' );
a.setAttribute( 'download', filename );
a.setAttribute( 'href', url );
document.body.appendChild(a);
var evt;
try {
evt = new MouseEvent( 'click' );
} catch ( error ) {
evt = document.createEvent( 'MouseEvents' );
evt.initEvent( 'click', true, true );
}
a.dispatchEvent( evt );
document.body.removeChild(a);
function doProxyDownload(url, filename, type) {
var content = url.split(',')[1];
var $form = $('<form></form>').attr({
'action': 'http://172.22.73.36/naotu/download.php',
'method': 'POST'
});
var $content = $('<input />').attr({
name: 'content',
type: 'hidden',
value: decodeURIComponent(content)
}).appendTo($form);
var $type = $('<input />').attr({
name: 'type',
type: 'hidden',
value: type
}).appendTo($form);
var $filename = $('<input />').attr({
name: 'filename',
type: 'hidden',
value: filename
}).appendTo($form);
$form.appendTo('body').submit().remove();
}
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 );
};
function doDownload(url, filename, type) {
if (kity.Browser.ie || ~window.location.href.indexOf('naotu.baidu.com')) {
return doProxyDownload(url, filename, type);
}
var a = document.createElement('a');
a.setAttribute('download', filename);
a.setAttribute('href', url);
a.click();
}
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
var data = me.exportData( res.value );
var p = KityMinder.findProtocal( res.value );
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:' + (p.mineType || 'text/plain') + '; utf-8,' + encodeURIComponent( data );
if ( ie_ver() > 0 ) {
if ( p.fileExtension === '.km' ) {
doSave( 'application/x-javascript', data, me.getMinderTitle() );
} else if ( p.fileExtension === '.svg' ) {
//doSave( 'image/svg+xml', data, filename );
} else {
doSave( 'text/html', data, filename );
}
} else {
doDownload( url, filename );
}
} else if ( data && data.then ) {
data.then( function ( url ) {
if ( ie_ver() > 0 ) {
//doSave( 'application/base64', url.replace( 'image/octet-stream,', '' ), filename );
} else {
doDownload( url, filename );
}
} );
if (typeof(data) == 'string') {
var url = 'data:' + (p.mineType || 'text/plain') + '; utf-8,' + encodeURIComponent(data);
doDownload(url, filename, 'text');
} else if (data && data.then) {
data.then(function(url) {
doDownload(url, filename, 'base64');
});
}
} ).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
}).on('beforeshow', function() {
if ($combox.parent().length === 0) {
$combox.appendTo(me.$container.find('.kmui-dialog-container'));
}
} ).on( 'aftercomboboxselect', function () {
}).on('aftercomboboxselect', function() {
this.setLabelWithDefaultValue();
} );
});
return comboboxWidget.button().addClass( 'kmui-combobox' );
return comboboxWidget.button().addClass('kmui-combobox');
} );
\ No newline at end of file
});
\ No newline at end of file
......@@ -39,7 +39,7 @@ kity.extendClass(MinderNode, {
},
getOrderHint: function(refer) {
return this.getLayoutInstance().getOrderHint(this);
return this.parent.getLayoutInstance().getOrderHint(this);
},
getExpandPosition: function() {
......@@ -169,13 +169,22 @@ kity.extendClass(Minder, {
refresh: function(duration) {
this.getRoot().preTraverse(function(node) { node.render(); });
return this.layout(duration);
this.layout(duration).fire('contentchange').fire('interactchange');
return this;
},
applyLayoutResult: function(root, duration) {
root = root || this.getRoot();
var me = this;
function applyMatrix(node, matrix) {
node.getRenderContainer().setMatrix(node._lastLayoutTransform = matrix);
me.fire('layoutapply', {
node: node,
matrix: matrix
});
}
function apply(node, pMatrix) {
var matrix = node.getLayoutTransform().merge(pMatrix);
var lastMatrix = node._lastLayoutTransform || new kity.Matrix();
......@@ -193,33 +202,23 @@ kity.extendClass(Minder, {
// 如果要求以动画形式来更新,创建动画
if (duration > 0) {
node._layoutTimeline = new kity.Animator(lastMatrix, matrix, function(node, value) {
node.getRenderContainer().setMatrix(node._lastLayoutTransform = value);
me.fire('layoutapply', {
node: node,
matrix: value
});
}).start(node, duration, 'ease').on('finish', function() {
// 可能性能低的时候会丢帧
me.fire('layoutapply', {
node: node,
matrix: matrix
});
me.fire('layoutfinish', {
node: node,
matrix: matrix
node._layoutTimeline = new kity.Animator(lastMatrix, matrix, applyMatrix)
.start(node, duration, 'ease')
.on('finish', function() {
// 可能性能低的时候会丢帧
setTimeout(function() {
applyMatrix(node, matrix);
me.fire('layoutfinish', {
node: node,
matrix: matrix
});
});
});
});
}
// 否则直接更新
else {
node.getRenderContainer().setMatrix(matrix);
node._lastLayoutTransform = matrix;
me.fire('layoutapply', {
node: node,
matrix: matrix
});
applyMatrix(node, matrix);
me.fire('layoutfinish', {
node: node,
matrix: matrix
......
......@@ -16,46 +16,30 @@ Utils.extend(KityMinder, {
}
});
// 这里的 Json 是一个对象
function exportNode(node) {
var exported = {};
exported.data = node.getData();
var childNodes = node.getChildren();
if (childNodes.length) {
exported.children = [];
for (var i = 0; i < childNodes.length; i++) {
exported.children.push(exportNode(childNodes[i]));
}
}
return exported;
}
var DEFAULT_TEXT = {
'root': 'maintopic',
'main': 'topic',
'sub': 'topic'
};
function importNode(node, json, km) {
var data = json.data;
node.data = {};
for (var field in data) {
node.setData(field, data[field]);
}
node.setData('text', data.text || km.getLang(DEFAULT_TEXT[node.getType()]));
var childrenTreeData = json.children || [];
for (var i = 0; i < childrenTreeData.length; i++) {
var childNode = km.createNode(null, node);
importNode(childNode, childrenTreeData[i], km);
}
return node;
}
// 导入导出
kity.extendClass(Minder, {
exportData: function(protocalName) {
// 这里的 Json 是一个对象
function exportNode(node) {
var exported = {};
exported.data = node.getData();
var childNodes = node.getChildren();
if (childNodes.length) {
exported.children = [];
for (var i = 0; i < childNodes.length; i++) {
exported.children.push(exportNode(childNodes[i]));
}
}
return exported;
}
var json, protocal;
json = exportNode(this.getRoot());
......@@ -67,6 +51,9 @@ kity.extendClass(Minder, {
protocal: protocal
}, true)) === true) return;
json.template = this.getTemplate();
json.theme = this.getTheme();
if (protocal) {
return protocal.encode(json, this);
} else {
......@@ -119,6 +106,24 @@ kity.extendClass(Minder, {
},
_doImport: function(json, params) {
function importNode(node, json, km) {
var data = json.data;
node.data = {};
for (var field in data) {
node.setData(field, data[field]);
}
node.setData('text', data.text || km.getLang(DEFAULT_TEXT[node.getType()]));
var childrenTreeData = json.children || [];
for (var i = 0; i < childrenTreeData.length; i++) {
var childNode = km.createNode(null, node);
importNode(childNode, childrenTreeData[i], km);
}
return node;
}
this._fire(new MinderEvent('preimport', params, false));
// 删除当前所有节点
......@@ -126,9 +131,20 @@ kity.extendClass(Minder, {
this.removeNode(this._root.getChildren()[0]);
}
// compality for v1.1.3
var ocs = json.data.currentstyle; // old current-style
delete json.data.currentstyle;
importNode(this._root, json, this);
this.refresh(500);
if (ocs == 'bottom') {
json.template = 'structure';
json.theme = 'snow';
}
this.setTemplate(json.template || null);
this.setTheme(json.theme || null);
this.refresh();
this.fire('import', params);
......
......@@ -2,20 +2,28 @@ utils.extend(KityMinder, {
_templates: {},
registerTemplate: function(name, supports) {
KityMinder._templates[name] = supports;
},
getTemplateList: function() {
return KityMinder._templates;
}
});
KityMinder.registerTemplate('default', {});
kity.extendClass(Minder, (function() {
var originGetTheme = Minder.prototype.getTheme;
return {
useTemplate: function(name) {
this._template = name;
useTemplate: function(name, duration) {
this.setTemplate(name);
this.refresh(duration || 800);
},
this.getRoot().traverse(function(node) {
node.render();
});
getTemplate: function() {
return this._template || null;
},
this.layout(300);
setTemplate: function(name) {
this._template = name || null;
},
getTemplateSupports: function() {
......@@ -55,8 +63,8 @@ KityMinder.registerModule('TemplateModule', {
minder.useTemplate(name);
},
queryCommandValue: function(minder) {
return minder._template;
queryValue: function(minder) {
return minder.getTemplate() || 'default';
}
})
}
......
......@@ -36,6 +36,10 @@ Utils.extend(KityMinder, {
// 首个注册的主题为默认主题
if (!KityMinder._defaultTheme) KityMinder._defaultTheme = name;
},
getThemeList: function() {
return KityMinder._themes;
}
});
......@@ -46,21 +50,16 @@ kity.extendClass(Minder, {
* @param {String} name 要使用的主题的名称
*/
useTheme: function(name) {
if (!KityMinder._themes[name]) {
return false;
}
this._theme = name;
this.setTheme(name);
this.refresh(800);
this.getRoot().traverse(function(node) {
node.render();
});
this.getRoot().layout();
return true;
},
setTheme: function(name) {
this._theme = name || null;
this.getPaper().getContainer().style.background = this.getStyle('background');
return true;
},
/**
......@@ -68,7 +67,12 @@ kity.extendClass(Minder, {
* @return {[type]} [description]
*/
getTheme: function(node) {
return this._theme || KityMinder._defaultTheme;
return this._theme || null;
},
getThemeItems: function(node) {
var theme = this.getTheme(node);
return KityMinder._themes[this.getTheme(node)] || KityMinder._themes[KityMinder._defaultTheme];
},
/**
......@@ -76,10 +80,10 @@ kity.extendClass(Minder, {
* @param {String} item 样式名称
*/
getStyle: function(item, node) {
var theme = KityMinder._themes[this.getTheme(node)];
var items = this.getThemeItems(node);
var segment, dir, selector, value, matcher;
if (item in theme) return theme[item];
if (item in items) return items[item];
// 尝试匹配 CSS 数组形式的值
// 比如 item 为 'pading-left'
......@@ -90,8 +94,8 @@ kity.extendClass(Minder, {
dir = segment.pop();
item = segment.join('-');
if (item in theme) {
value = theme[item];
if (item in items) {
value = items[item];
if (Utils.isArray(value) && (matcher = cssLikeValueMatcher[dir])) {
return matcher(value);
}
......@@ -127,7 +131,7 @@ KityMinder.registerModule('Theme', {
},
queryValue: function(km) {
return km.getTheme();
return km.getTheme() || 'default';
}
})
}
......
......@@ -33,12 +33,13 @@ KityMinder.registerLayout('bottom', kity.createClass({
return box;
});
var nodeContentBox = node.getContentBox();
node.setLayoutVector(new kity.Vector(nodeContentBox.cx - 5, nodeContentBox.bottom));
node.setLayoutVector(new kity.Vector(nodeContentBox.cx, nodeContentBox.bottom));
var i, x, y, child, childTreeBox, childContentBox;
var transform = new kity.Matrix();
x = -totalTreeWidth / 2;
for (var i = 0; i < children.length; i++) {
for (i = 0; i < children.length; i++) {
child = children[i];
childTreeBox = childTreeBoxes[i];
childContentBox = child.getContentBox();
......@@ -52,7 +53,47 @@ KityMinder.registerLayout('bottom', kity.createClass({
children[i].setLayoutTransform(new kity.Matrix().translate(x, y));
x += childTreeBox.width / 2 + children[i].getStyle('margin-right');
}
if (node.isRoot()) {
var branchBox = this.getBranchBox(children);
var dx = branchBox.cx - nodeContentBox.cx;
children.forEach(function(child) {
child.getLayoutTransform().translate(-dx, 0);
});
}
}
},
getOrderHint: function(node) {
var hint = [];
var box = node.getLayoutBox();
var offset = 3;
hint.push({
type: 'up',
node: node,
area: {
x: box.left - node.getStyle('margin-left') - offset,
y: box.top,
width: node.getStyle('margin-left'),
height: box.height
},
path: ['M', box.left - offset, box.top, 'L', box.left - offset, box.bottom]
});
hint.push({
type: 'down',
node: node,
area: {
x: box.right + offset,
y: box.top,
width: node.getStyle('margin-right'),
height: box.height
},
path: ['M', box.right + offset, box.top, 'L', box.right + offset, box.bottom]
});
return hint;
}
}));
......@@ -64,5 +105,6 @@ KityMinder.registerConnectProvider('bottom', function(node, parent, connection)
pathData.push('L', new kity.Point(pBox.cx, pBox.bottom + parent.getStyle('margin-bottom')));
pathData.push('L', new kity.Point(box.cx, pBox.bottom + parent.getStyle('margin-bottom')));
pathData.push('L', new kity.Point(box.cx, box.top));
connection.setMarker(null);
connection.setPathData(pathData);
});
\ No newline at end of file
......@@ -88,19 +88,19 @@ KityMinder.registerLayout('default', kity.createClass({
x -= parent.getStyle('margin-left') + child.getStyle('margin-right');
}
// 竖直方向上的布局
y += childTreeBox.height / 2;
if (i > 0) {
y += children[i].getStyle('margin-top');
}
// 竖直方向上的布局
y -= childTreeBox.top;
// 设置布局结果
transform = new kity.Matrix().translate(x, y);
child.setLayoutTransform(transform);
y += childTreeBox.height / 2 + child.getStyle('margin-bottom');
y += childTreeBox.bottom + child.getStyle('margin-bottom');
}
if (parent.isRoot()) {
......
......@@ -21,27 +21,36 @@ KityMinder.registerLayout('filetree', kity.createClass({
if (!children.length) {
return false;
} else {
var totalTreeWidth = 0;
// 计算每个 child 的树所占的矩形区域
var childTreeBoxes = children.map(function(node, index, children) {
var box = _this.getTreeBox([node]);
return box;
});
var nodeContentBox = node.getContentBox();
node.setLayoutVector(new kity.Vector(nodeContentBox.left + 6, nodeContentBox.bottom));
node.setLayoutVector(new kity.Vector(0, nodeContentBox.bottom));
var i, x, y, child, childTreeBox, childContentBox;
var transform = new kity.Matrix();
y = nodeContentBox.bottom + node.getStyle('margin-bottom');
for (var i = 0; i < children.length; i++) {
for (i = 0; i < children.length; i++) {
child = children[i];
childTreeBox = childTreeBoxes[i];
childContentBox = child.getContentBox();
x = child.getStyle('margin-left') - childContentBox.left;
if (!childContentBox.width) continue;
x = 10;
y += child.getStyle('margin-top');
child.setLayoutTransform(new kity.Matrix().translate(x, y));
y += childTreeBox.height + children[i].getStyle('margin-bottom');
y -= childTreeBox.top;
// 设置布局结果
transform = new kity.Matrix().translate(x, y);
child.setLayoutTransform(transform);
y += childTreeBox.bottom + child.getStyle('margin-bottom');
}
}
},
......@@ -81,8 +90,8 @@ KityMinder.registerConnectProvider('filetree', function(node, parent, connection
var box = node.getLayoutBox(),
pBox = parent.getLayoutBox();
var pathData = [];
var left = pBox.left + 5;
pathData.push('M', new kity.Point(left, pBox.bottom));
var left = parent.getLayoutPoint().x;
pathData.push('M', new kity.Point(left, pBox.bottom + 1));
pathData.push('L', new kity.Point(left, box.cy));
pathData.push('L', new kity.Point(box.left, box.cy));
connection.setPathData(pathData);
......
......@@ -228,6 +228,7 @@ var TreeDragger = kity.createClass('TreeDragger', {
var sources = this._dragSources;
var ancestor = MinderNode.getCommonAncestor(sources);
// 只有一个元素选中,公共祖先是其父
if (ancestor == sources[0]) ancestor = sources[0].parent;
if (sources.length === 0 || ancestor != sources[0].parent) {
......
......@@ -61,7 +61,7 @@ KityMinder.registerModule('Expand', function() {
/**
* 策略 2:把操作进行到儿子
*/
DEEP_TO_CHILD: generateDeepPolicy(1),
DEEP_TO_CHILD: generateDeepPolicy(2),
/**
* 策略 3:把操作进行到叶子
......@@ -118,6 +118,7 @@ KityMinder.registerModule('Expand', function() {
base: Command,
execute: function(km) {
var nodes = km.getSelectedNodes();
if (!nodes.length) nodes.push(km.getRoot());
nodes.forEach(function(node) {
node.expand(EXPAND_POLICY.DEEP_TO_LEAF);
});
......@@ -129,9 +130,9 @@ KityMinder.registerModule('Expand', function() {
var CollapseNodeCommand = kity.createClass('CollapseNodeCommand', {
base: Command,
execute: function(km) {
var nodes = km.getSelectedNodes();
var nodes = km.getRoot().getChildren();
nodes.forEach(function(node) {
node.collapse(EXPAND_POLICY.DEEP_TO_LEAF);
node.collapse();
});
},
queryState: function(km) {
......
KityMinder.registerModule( "hyperlink", function () {
KityMinder.registerModule("hyperlink", function() {
var linkShapePath = "M16.614,10.224h-1.278c-1.668,0-3.07-1.07-3.599-2.556h4.877c0.707,0,1.278-0.571,1.278-1.278V3.834 c0-0.707-0.571-1.278-1.278-1.278h-4.877C12.266,1.071,13.668,0,15.336,0h1.278c2.116,0,3.834,1.716,3.834,3.834V6.39 C20.448,8.508,18.73,10.224,16.614,10.224z M5.112,5.112c0-0.707,0.573-1.278,1.278-1.278h7.668c0.707,0,1.278,0.571,1.278,1.278 S14.765,6.39,14.058,6.39H6.39C5.685,6.39,5.112,5.819,5.112,5.112z M2.556,3.834V6.39c0,0.707,0.573,1.278,1.278,1.278h4.877 c-0.528,1.486-1.932,2.556-3.599,2.556H3.834C1.716,10.224,0,8.508,0,6.39V3.834C0,1.716,1.716,0,3.834,0h1.278 c1.667,0,3.071,1.071,3.599,2.556H3.834C3.129,2.556,2.556,3.127,2.556,3.834z";
return {
"commands": {
"hyperlink": kity.createClass( "hyperlink", {
"hyperlink": kity.createClass("hyperlink", {
base: Command,
execute: function ( km, url ) {
execute: function(km, url) {
var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) {
n.setData( 'hyperlink', url );
utils.each(nodes, function(i, n) {
n.setData('hyperlink', url);
n.render();
} );
});
km.layout();
},
queryState: function ( km ) {
queryState: function(km) {
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( 'hyperlink' ) ) {
utils.each(nodes, function(i, n) {
if (n && n.getData('hyperlink')) {
result = 0;
return false;
}
} );
});
return result;
},
queryValue: function ( km ) {
queryValue: function(km) {
var node = km.getSelectedNode();
return node.getData( 'hyperlink' );
return node.getData('hyperlink');
}
} ),
"unhyperlink": kity.createClass( "hyperlink", {
}),
"unhyperlink": kity.createClass("hyperlink", {
base: Command,
execute: function ( km ) {
execute: function(km) {
var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) {
n.setData( 'hyperlink' );
utils.each(nodes, function(i, n) {
n.setData('hyperlink');
n.render();
} );
});
km.layout();
},
queryState: function ( km ) {
queryState: function(km) {
var nodes = km.getSelectedNodes();
if ( nodes.length === 0 ) {
if (nodes.length === 0) {
return -1;
}
var link = false;
utils.each( nodes, function ( i, n ) {
if ( n.getData( 'hyperlink' ) ) {
utils.each(nodes, function(i, n) {
if (n.getData('hyperlink')) {
link = true;
return false;
}
} );
if ( link ) {
});
if (link) {
return 0;
}
return -1;
}
} )
})
},
'renderers': {
right: kity.createClass('hyperlinkrender', {
......@@ -74,11 +74,11 @@ KityMinder.registerModule( "hyperlink", function () {
var outline = new kity.Rect(24, 22, -2, -6, 4).fill('rgba(255, 255, 255, 0)');
linkshape.setPathData( linkShapePath ).fill( '#666' );
link.addShape( outline );
link.addShape( linkshape );
link.setTarget( '_blank' );
link.setStyle( 'cursor', 'pointer' );
linkshape.setPathData(linkShapePath).fill('#666');
link.addShape(outline);
link.addShape(linkshape);
link.setTarget('_blank');
link.setStyle('cursor', 'pointer');
link.on('mouseover', function() {
......@@ -91,7 +91,7 @@ KityMinder.registerModule( "hyperlink", function () {
shouldRender: function(node) {
return node.getData( 'hyperlink' );
return node.getData('hyperlink');
},
update: function(link, node, box) {
......@@ -113,4 +113,4 @@ KityMinder.registerModule( "hyperlink", function () {
}
};
} );
\ No newline at end of file
});
\ No newline at end of file
......@@ -104,7 +104,7 @@ KityMinder.registerModule('image', function() {
base: KityMinder.Renderer,
create: function(node) {
return new kity.Image();
return new kity.Image(node.getData('image'));
},
shouldRender: function(node) {
......
KityMinder.registerModule("LayoutBottom", function () {
var _target = this.getRenderTarget();
function getMinderSize() {
return {
width: _target.clientWidth,
height: _target.clientHeight
};
}
var minder = this;
//收缩-展开子树的节点
var ShIcon = kity.createClass("DefaultshIcon", (function () {
return {
constructor: function (node) {
this._show = false;
this._node = node;
var iconShape = this.shape = new kity.Group();
iconShape.class = "shicon";
iconShape.icon = this;
var rect = this._rect = new kity.Rect().fill("white").stroke("gray").setRadius(2).setWidth(10).setHeight(10);
var plus = this._plus = new kity.Path();
plus.getDrawer()
.moveTo(2, 5)
.lineTo(8, 5)
.moveTo(5, 2)
.lineTo(5, 8);
plus.stroke("gray");
var dec = this._dec = new kity.Path();
dec.getDrawer()
.moveTo(2, 5)
.lineTo(8, 5);
dec.stroke("gray");
if (node.getType() === "main") minder.getRenderContainer().addShape(iconShape);
else {
node.getLayout().subgroup.addShape(iconShape);
}
iconShape.addShapes([rect, plus, dec]);
this.update();
//this.switchState();
},
switchState: function (val) {
if (val === true || val === false)
this._show = !val;
if (!this._show) {
this._plus.setOpacity(0);
this._dec.setOpacity(1);
this._show = true;
} else {
this._plus.setOpacity(1);
this._dec.setOpacity(0);
this._show = false;
}
return this._show;
},
update: function () {
var node = this._node;
var Layout = node.getLayout();
var nodeShape = node.getRenderContainer();
var nodeType = node.getType();
var nodeX = nodeShape.getRenderBox().closurePoints[1].x + 5;
var nodeY = nodeShape.getRenderBox().closurePoints[0].y;
this.shape.setTranslate(nodeX, nodeY);
},
remove: function () {
this.shape.remove();
}
};
})());
//样式的配置(包括颜色、字号等)
var nodeStyles = {
"root": {
color: '#430',
fill: '#e9df98',
fontSize: 24,
padding: [15.5, 25.5, 15.5, 25.5],
margin: [0, 0, 20, 0],
radius: 0,
highlight: 'rgb(254, 219, 0)',
spaceLeft: 3,
spaceRight: 0,
spaceTop: 3,
spaceBottom: 10
},
"main": {
stroke: new kity.Pen("white", 2).setLineCap("round").setLineJoin("round"),
fill: '#A4c5c0',
color: "#333",
padding: [6.5, 20, 6.5, 20],
fontSize: 16,
margin: [20, 20, 10, 10],
radius: 0,
highlight: 'rgb(254, 219, 0)',
spaceLeft: 3,
spaceRight: 0,
spaceTop: 3,
spaceBottom: 10
},
"sub": {
stroke: new kity.Pen("white", 2).setLineCap("round").setLineJoin("round"),
color: "#333",
fontSize: 12,
margin: [10, 10, 10, 30],
padding: [5, 10, 5.5, 10],
highlight: 'rgb(254, 219, 0)',
fill: 'rgb(231, 243, 255)',
spaceLeft: 3,
spaceRight: 0,
spaceTop: 3,
spaceBottom: 10
}
};
//更新背景
var updateBg = function (node) {
var nodeType = node.getType();
var nodeStyle = nodeStyles[nodeType];
var Layout = node.getLayout();
switch (node.getType()) {
case "root":
case "main":
var bg = node.getBgRc().clear();
bg.addShape(Layout.bgShadow = new kity.Rect());
bg.addShape(Layout.bgRect = new kity.Rect());
Layout.bgRect.fill(nodeStyle.fill).setRadius(nodeStyle.radius);
Layout.bgShadow.fill('black').setOpacity(0.2).setRadius(nodeStyle.radius).translate(3, 5);
break;
case "sub":
var bgRc = node.getBgRc().clear();
bgRc.addShape(Layout.bgRect = new kity.Rect());
Layout.bgRect.fill(nodeStyle.fill);
break;
default:
break;
}
};
//初始化样式
var initLayout = function (node) {
var Layout = node.getLayout();
var nodeType = node.getType();
var nodeStyle = nodeStyles[nodeType];
if (nodeType === "main") {
var subgroup = Layout.subgroup = new kity.Group();
minder.getRenderContainer().addShape(subgroup);
}
};
//根据内容调整节点尺寸
var updateShapeByCont = function (node) {
var contRc = node.getContRc();
var nodeType = node.getType();
var nodeStyle = nodeStyles[nodeType];
var _contRCWidth = contRc.getWidth();
var _contRCHeight = contRc.getHeight();
var Layout = node.getLayout();
switch (nodeType) {
case "root":
case "main":
var width = _contRCWidth + nodeStyle.padding[1] + nodeStyle.padding[3],
height = _contRCHeight + nodeStyle.padding[0] + nodeStyle.padding[2];
Layout.bgRect.setWidth(width).setHeight(height);
Layout.bgShadow.setWidth(width).setHeight(height);
break;
case "sub":
width = _contRCWidth + nodeStyle.padding[1] + nodeStyle.padding[3];
height = _contRCHeight + nodeStyle.padding[0] + nodeStyle.padding[2];
Layout.bgRect.setWidth(width).setHeight(height);
break;
default:
break;
}
var rBox = contRc.getRenderBox();
// Todo:很坑的改法,不知为何就对了,需要处理
contRc.setTranslate(nodeStyle.padding[3], 0);
contRc.translate(0, nodeStyle.padding[0] - rBox.top);
};
var updateLayoutMain = function () {
var _root = minder.getRoot();
var mainnodes = (function () {
var main_added = [];
var children = _root.getChildren();
for (var i = 0; i < children.length; i++) {
if (children[i].getLayout().added) main_added.push(children[i]);
}
return main_added;
})();
var countMainWidth = function (node) {
var nLayout = node.getLayout();
var selfwidth = node.getRenderContainer().getWidth() + nodeStyles.main.margin[1] + nodeStyles.main.margin[3];
var childwidth = 0;
if (nLayout.added) {
childwidth = nLayout.subgroup.getWidth() + nodeStyles.main.margin[1] + nodeStyles.sub.margin[3];
}
var branchwidth = nLayout.branchwidth = (selfwidth > childwidth ? selfwidth : childwidth);
return branchwidth;
};
var rootLayout = _root.getLayout();
var rootbranchwidth = 0;
for (var j = 0; j < mainnodes.length; j++) {
rootbranchwidth += countMainWidth(mainnodes[j]);
}
var sX = rootLayout.x - rootbranchwidth / 2;
for (var k = 0; k < mainnodes.length; k++) {
var mLayout = mainnodes[k].getLayout();
mLayout.x = sX + nodeStyles.main.margin[3] + 5;
sX += mLayout.branchwidth;
}
return mainnodes;
};
var updateLayoutAll = function (node, parent, action) {
var effectSet = [];
var nodeType = node.getType();
var Layout = node.getLayout();
var _root = minder.getRoot();
var rootLayout = _root.getLayout();
if (nodeType === "root") {
Layout.x = getMinderSize().width / 2;
Layout.y = 100;
Layout.align = "center";
effectSet.push(node);
var children = node.getChildren();
for (var i = 0; i < children.length; i++) {
var childLayout = children[i].getLayout();
childLayout.y = Layout.y + node.getRenderContainer().getHeight() + nodeStyles.root.margin[2] + nodeStyles.main.margin[0];
}
effectSet = [_root];
var mains = _root.getChildren();
for (var x = 0; x < mains.length; x++) {
if (mains[x].getLayout().added)
effectSet.push(mains[x]);
}
} else if (nodeType === "main") {
Layout.align = "left";
if (action === "append" || action === "contract") {
Layout.y = rootLayout.y + _root.getRenderContainer().getHeight() + nodeStyles.root.margin[2] + nodeStyles.main.margin[0];
}
effectSet = updateLayoutMain();
} else {
Layout.align = "left";
var parentLayout = parent.getLayout();
if (action === "append") {
if (parent.getType() === "main") {
Layout.x = nodeStyles.sub.margin[3];
} else {
Layout.x = parentLayout.x + nodeStyles.sub.margin[3];
}
}
if (action === "append" || action === "contract") {
Layout.branchheight = node.getRenderContainer().getHeight() + nodeStyles.sub.margin[0] + nodeStyles.sub.margin[2];
}
var prt = parent;
if (action === "change") {
prt = node;
}
//自底向上更新branchheight
while (prt.getType() !== "main") {
var c = prt.getChildren();
var prtLayout = prt.getLayout();
var branchHeight = prt.getRenderContainer().getHeight() + nodeStyles.sub.margin[0] + nodeStyles.sub.margin[2];
for (var i1 = 0; i1 < c.length; i1++) {
if (c[i1].getLayout().added) branchHeight += c[i1].getLayout().branchheight;
}
prtLayout.branchheight = branchHeight;
prt = prt.getParent();
}
//自顶向下更新y
var _buffer = [prt];
while (_buffer.length !== 0) {
var childrenC = _buffer[0].getChildren();
childrenC = (function () {
var result = [];
for (var len = 0; len < childrenC.length; len++) {
var l = childrenC[len].getLayout();
if (l.added) {
result.push(childrenC[len]);
}
}
return result;
})();
_buffer = _buffer.concat(childrenC);
var _buffer0Layout = _buffer[0].getLayout();
var _buffer0Style = nodeStyles[_buffer[0].getType()];
var sY;
if (_buffer[0].getType() === "main") sY = 0;
else sY = _buffer0Layout.y + _buffer[0].getRenderContainer().getHeight() + _buffer0Style.margin[2];
for (var s = 0; s < childrenC.length; s++) {
var childLayoutC = childrenC[s].getLayout();
var childStyleC = nodeStyles[childrenC[s].getType()];
childLayoutC.y = sY + childStyleC.margin[0];
sY += childLayoutC.branchheight;
}
if (_buffer[0] !== _root && _buffer[0].getLayout().added) effectSet.push(_buffer[0]);
_buffer.shift();
}
}
return effectSet;
};
var translateNode = function (node) {
var Layout = node.getLayout();
var nodeShape = node.getRenderContainer();
var align = Layout.align;
var _rectHeight = nodeShape.getHeight();
var _rectWidth = nodeShape.getWidth();
switch (align) {
case "right":
nodeShape.setTranslate(Layout.x - _rectWidth, Layout.y);
break;
case "center":
nodeShape.setTranslate(Layout.x - _rectWidth / 2, Layout.y);
break;
default:
nodeShape.setTranslate(Layout.x, Layout.y);
break;
}
if (node.getType() === "main") {
Layout.subgroup.setTranslate(Layout.x, Layout.y + node.getRenderContainer().getHeight());
}
node.setPoint(Layout.x, Layout.y);
};
var updateConnectAndshIcon = function (node) {
var nodeType = node.getType();
var Layout = node.getLayout();
var nodeStyle = nodeStyles[node.getType()];
var connect;
var _root = minder.getRoot();
var _rootLayout = _root.getLayout();
//更新连线
if (nodeType === "main") {
if (!Layout.connect) {
connect = Layout.connect = new kity.Path();
minder.getRenderContainer().addShape(connect);
}
connect = Layout.connect;
var sX = _rootLayout.x;
var sY = _rootLayout.y + _root.getRenderContainer().getHeight();
var transX = Layout.x + node.getRenderContainer().getWidth() / 2;
var transY = sY + nodeStyles.root.margin[2];
connect.getDrawer().clear()
.moveTo(sX, sY)
.lineTo(sX, transY)
.lineTo(transX, transY)
.lineTo(transX, Layout.y);
connect.stroke(nodeStyles.main.stroke);
} else if (nodeType === "sub") {
var parent = node.getParent();
var parentLayout = parent.getLayout();
if (!Layout.connect) {
connect = Layout.connect = new kity.Path();
parentLayout.subgroup.addShape(connect);
}
connect = Layout.connect;
var ssX, ssY;
if (parent.getType() === "main") {
ssX = 10;
ssY = 0;
} else {
ssX = parentLayout.x + 10;
ssY = parentLayout.y + parent.getRenderContainer().getHeight() + 10;
}
var transsY = Layout.y + node.getRenderContainer().getHeight() / 2;
connect.getDrawer().clear()
.moveTo(ssX, ssY)
.lineTo(ssX, transsY)
.lineTo(Layout.x, transsY);
connect.stroke(nodeStyles.sub.stroke);
}
//更新收放icon
if (nodeType !== "root" && node.getChildren().length !== 0) {
if (!Layout.shicon) {
Layout.shicon = new ShIcon(node);
}
Layout.shicon.update();
}
};
var _style = {
getCurrentLayoutStyle: function () {
return nodeStyles;
},
highlightNode: function (node) {
var highlight = node.isHighlight();
var nodeType = node.getType();
var nodeStyle = nodeStyles[nodeType];
var Layout = node.getLayout();
switch (nodeType) {
case "root":
case "main":
case "sub":
if (highlight) {
Layout.bgRect.fill(nodeStyle.highlight);
} else {
Layout.bgRect.fill(nodeStyle.fill);
}
break;
default:
break;
}
},
updateLayout: function (node) {
node.getContRc().clear();
this._firePharse(new MinderEvent("RenderNodeLeft", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeCenter", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeRight", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeBottom", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeTop", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNode", {
node: node
}, false));
updateShapeByCont(node);
var set = updateLayoutAll(node, node.getParent(), "change");
for (var i = 0; i < set.length; i++) {
translateNode(set [i]);
updateConnectAndshIcon(set [i]);
}
if (node.getType() === "sub") {
var set1 = updateLayoutMain();
for (var j = 0; j < set1.length; j++) {
translateNode(set1[j]);
updateConnectAndshIcon(set1[j]);
}
}
},
initStyle: function () {
var _root = minder.getRoot();
minder.handelNodeInsert(_root);
//设置root的align
_root.getLayout().align = "center";
updateBg(_root);
initLayout(_root);
_root.getContRc().clear();
this._firePharse(new MinderEvent("RenderNodeLeft", {
node: _root
}, false));
this._firePharse(new MinderEvent("RenderNodeCenter", {
node: _root
}, false));
this._firePharse(new MinderEvent("RenderNodeRight", {
node: _root
}, false));
this._firePharse(new MinderEvent("RenderNodeBottom", {
node: _root
}, false));
this._firePharse(new MinderEvent("RenderNodeTop", {
node: _root
}, false));
this._firePharse(new MinderEvent("RenderNode", {
node: _root
}, false));
updateShapeByCont(_root);
updateLayoutAll(_root);
translateNode(_root);
var mains = _root.getChildren();
for (var i = 0; i < mains.length; i++) {
this.appendChildNode(_root, mains[i]);
if (mains[i].isExpanded() && (mains[i].getChildren().length > 0)) {
minder.expandNode(mains[i]);
}
}
},
appendChildNode: function (parent, node, sibling) {
node.clearLayout();
node.getContRc().clear();
var Layout = node.getLayout();
Layout = node.getLayout();
if (!Layout.added) minder.handelNodeInsert(node);
Layout.added = true;
var parentLayout = parent.getLayout();
var children = parent.getChildren();
var exist = (children.indexOf(node) !== -1);
//设置分支类型
if (parent.getType() === "root") {
node.setType("main");
} else {
node.setType("sub");
//将节点加入到main分支的subgroup中
parentLayout.subgroup.addShape(node.getRenderContainer());
node.getLayout().subgroup = parentLayout.subgroup;
}
initLayout(node);
if (sibling) {
if (!exist) parent.insertChild(node, sibling.getIndex() + 1);
} else {
if (!exist) parent.appendChild(node);
}
//计算位置等流程
this._firePharse(new MinderEvent("RenderNodeLeft", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeCenter", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeRight", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeBottom", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeTop", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNode", {
node: node
}, false));
updateBg(node);
updateShapeByCont(node);
var set = updateLayoutAll(node, parent, "append");
for (var i = 0; i < set.length; i++) {
translateNode(set [i]);
updateConnectAndshIcon(set [i]);
}
if (node.getType() === "sub") {
var set1 = updateLayoutMain();
for (var j = 0; j < set1.length; j++) {
translateNode(set1[j]);
updateConnectAndshIcon(set1[j]);
}
}
parent.expand();
var shicon = parent.getLayout().shicon;
if (shicon) shicon.switchState(true);
},
appendSiblingNode: function (sibling, node) {
var parent = sibling.getParent();
this.appendChildNode(parent, node, sibling);
},
removeNode: function (nodes) {
while (nodes.length !== 0) {
var parent = nodes[0].getParent();
if (!parent) {
nodes.splice(0, 1);
return false;
}
var nodeLayout = nodes[0].getLayout();
parent.removeChild(nodes[0]);
if (parent.getType() !== "root" && parent.getChildren().length === 0) {
var prtLayout = parent.getLayout();
prtLayout.shicon.remove();
prtLayout.shicon = null;
}
var set = updateLayoutAll(nodes[0], parent, "remove");
for (var j = 0; j < set.length; j++) {
translateNode(set [j]);
updateConnectAndshIcon(set [j]);
}
var set1 = updateLayoutMain();
for (var k = 0; k < set1.length; k++) {
translateNode(set1[k]);
updateConnectAndshIcon(set1[k]);
}
var _buffer = [nodes[0]];
while (_buffer.length !== 0) {
_buffer = _buffer.concat(_buffer[0].getChildren());
try {
_buffer[0].getRenderContainer().remove();
var Layout = _buffer[0].getLayout();
Layout.connect.remove();
Layout.shicon.remove();
} catch (error) {
console.log("isRemoved");
}
//检测当前节点是否在选中的数组中,如果在的话,从选中数组中去除
var idx = nodes.indexOf(_buffer[0]);
if (idx !== -1) {
nodes.splice(idx, 1);
}
_buffer.shift();
}
}
},
expandNode: function (ico) {
var isExpand, node;
if (ico instanceof MinderNode) {
node = ico;
isExpand = node.getLayout().shicon.switchState();
} else {
isExpand = ico.icon.switchState();
node = ico.icon._node;
}
var _buffer;
if (isExpand) {
node.expand();
//遍历子树展开需要展开的节点
_buffer = [node];
while (_buffer.length !== 0) {
var c = _buffer[0].getChildren();
if (_buffer[0].isExpanded() && c.length !== 0) {
for (var x = 0; x < c.length; x++) {
minder.appendChildNode(_buffer[0], c[x]);
}
_buffer = _buffer.concat(c);
}
_buffer.shift();
}
} else {
node.collapse();
//遍历子树移除需要移除的节点
_buffer = node.getChildren();
while (_buffer.length !== 0) {
var Layout = _buffer[0].getLayout();
if (Layout.added) {
Layout.added = false;
_buffer[0].getRenderContainer().remove();
Layout.connect.remove();
if (Layout.shicon) Layout.shicon.remove();
}
_buffer = _buffer.concat(_buffer[0].getChildren());
_buffer.shift();
}
var set = updateLayoutAll(node, node.getParent(), "contract");
for (var i = 0; i < set.length; i++) {
translateNode(set [i]);
updateConnectAndshIcon(set [i]);
}
}
}
};
this.addLayoutStyle("bottom", _style);
return {};
});
\ No newline at end of file
KityMinder.registerModule("LayoutDefault", function() {
var _target = this.getRenderTarget();
function getMinderSize() {
return {
width: _target.clientWidth,
height: _target.clientHeight
};
}
var minder = this;
//收缩-展开子树的节点
var ShIcon = kity.createClass("DefaultshIcon", (function() {
return {
constructor: function(node) {
this._show = false;
this._node = node;
var iconShape = this.shape = new kity.Group();
iconShape.class = "shicon";
iconShape.icon = this;
var circle = this._circle = new kity.Circle().fill("white").stroke("gray").setRadius(5);
var plus = this._plus = new kity.Path();
plus.getDrawer()
.moveTo(-3, 0)
.lineTo(3, 0)
.moveTo(0, -3)
.lineTo(0, 3);
plus.stroke("gray");
var dec = this._dec = new kity.Path();
dec.getDrawer()
.moveTo(-3, 0)
.lineTo(3, 0);
dec.stroke("gray");
minder.getRenderContainer().addShape(iconShape);
iconShape.addShapes([circle, plus, dec]);
this.update();
},
switchState: function(val) {
if (val === true || val === false)
this._show = !val;
if (!this._show) {
this._plus.setOpacity(0);
this._dec.setOpacity(1);
this._show = true;
} else {
this._plus.setOpacity(1);
this._dec.setOpacity(0);
this._show = false;
}
return this._show;
},
update: function() {
var node = this._node;
var Layout = node.getLayout();
var nodeShape = node.getRenderContainer();
var nodeX, nodeY = (node.getType() === "main" ? Layout.y : (Layout.y + nodeShape.getHeight() / 2 - 5));
if (Layout.appendside === "left") {
nodeX = nodeShape.getRenderBox().closurePoints[1].x - 5;
} else {
nodeX = nodeShape.getRenderBox().closurePoints[0].x + 6;
if (node.getType() === "main") nodeX -= 3;
}
this.shape.setTranslate(nodeX, nodeY);
},
remove: function() {
this.shape.remove();
}
};
})());
//求并集
var uSet = function(a, b) {
for (var i = 0; i < a.length; i++) {
var idx = b.indexOf(a[i]);
if (idx !== -1) {
b.splice(idx, 1);
}
}
return a.concat(b);
};
//样式的配置(包括颜色、字号等)
var nodeStyles = {
"root": {
color: '#430',
fill: '#e9df98',
fontSize: 24,
padding: [15.5, 25.5, 15.5, 25.5],
margin: [0, 0, 0, 0],
radius: 30,
highlight: 'rgb(254, 219, 0)',
spaceLeft: 3,
spaceRight: 0,
spaceTop: 3,
spaceBottom: 10
},
"main": {
stroke: new kity.Pen("white", 2).setLineCap("round").setLineJoin("round"),
fill: '#A4c5c0',
color: "#333",
padding: [6.5, 20, 6.5, 20],
fontSize: 16,
margin: [0, 10, 30, 50],
radius: 10,
highlight: 'rgb(254, 219, 0)',
spaceLeft: 5,
spaceRight: 0,
spaceTop: 2,
spaceBottom: 5
},
"sub": {
stroke: new kity.Pen("white", 2).setLineCap("round").setLineJoin("round"),
color: "white",
fontSize: 12,
margin: [0, 10, 20, 6],
padding: [5, 10, 5.5, 10],
highlight: 'rgb(254, 219, 0)',
spaceLeft: 4,
spaceRight: 0,
spaceTop: 2,
spaceBottom: 5
}
};
//更新背景
var updateBg = function(node) {
var nodeType = node.getType();
var nodeStyle = nodeStyles[nodeType];
var Layout = node.getLayout();
switch (node.getType()) {
case "root":
case "main":
var bg = node.getBgRc().clear();
bg.addShape(Layout.bgShadow = new kity.Rect());
bg.addShape(Layout.bgRect = new kity.Rect());
Layout.bgRect.fill(nodeStyle.fill).setRadius(nodeStyle.radius);
Layout.bgShadow.fill('black').setOpacity(0.2).setRadius(nodeStyle.radius).translate(3, 5);
break;
case "sub":
var underline = Layout.underline = new kity.Path();
var highlightshape = Layout.highlightshape = new kity.Rect().setRadius(4);
node.getBgRc().clear().addShapes([Layout.bgRect = new kity.Rect().setRadius(4), highlightshape, underline]);
break;
default:
break;
}
};
//初始化样式
var initLayout = function(node) {
var Layout = node.getLayout();
var nodeType = node.getType();
var nodeStyle = nodeStyles[nodeType];
//var txtShape = node.getTextShape();
//txtShape.fill( nodeStyle.color ).setSize( nodeStyle.fontSize ).setY( -3 );
if (nodeType === "root") {
Layout.leftList = [];
Layout.rightList = [];
Layout.leftHeight = 0;
Layout.rightHeight = 0;
}
};
//根据内容调整节点尺寸
var updateShapeByCont = function(node) {
var contRc = node.getContRc();
var nodeType = node.getType();
var nodeStyle = nodeStyles[nodeType];
var _contRCWidth = contRc.getWidth();
var _contRCHeight = contRc.getHeight();
var Layout = node.getLayout();
switch (nodeType) {
case "root":
case "main":
var width = _contRCWidth + nodeStyle.padding[1] + nodeStyle.padding[3],
height = _contRCHeight + nodeStyle.padding[0] + nodeStyle.padding[2];
Layout.bgRect.setWidth(width).setHeight(height);
Layout.bgShadow.setWidth(width).setHeight(height);
break;
case "sub":
var _contWidth = contRc.getWidth();
var _contHeight = contRc.getHeight();
width = _contWidth + nodeStyle.padding[1] + nodeStyle.padding[3];
height = _contHeight + nodeStyle.padding[0] + nodeStyle.padding[2];
Layout.underline.getDrawer()
.clear()
.moveTo(0, _contHeight + nodeStyle.padding[2] + nodeStyle.padding[0])
.lineTo(_contWidth + nodeStyle.padding[1] + nodeStyle.padding[3], _contHeight + nodeStyle.padding[2] + nodeStyle.padding[0]);
Layout.underline.stroke(nodeStyle.stroke);
Layout.highlightshape
.setWidth(_contWidth + nodeStyle.padding[1] + nodeStyle.padding[3])
.setHeight(_contHeight + nodeStyle.padding[0] + nodeStyle.padding[2]);
Layout.bgRect.setWidth(width).setHeight(height);
break;
default:
break;
}
var rBox = contRc.getRenderBox();
// contRc.setTranslate(nodeStyle.padding[3], nodeStyle.padding[0] - rBox.top);
// Todo:很坑的改法,不知为何就对了,需要处理
contRc.setTranslate(nodeStyle.padding[3], 0);
contRc.translate(0, nodeStyle.padding[0] - rBox.top);
};
//计算节点在垂直方向的位置
var updateLayoutVertical = function(node, parent, action) {
var root = minder.getRoot();
var effectSet = [node];
if (action === "remove") {
effectSet = [];
}
var Layout = node.getLayout();
var nodeShape = node.getRenderContainer();
var nodeType = node.getType();
var nodeStyle = nodeStyles[nodeType];
var appendside = Layout.appendside;
var countBranchHeight = function(node, side) {
var nodeStyle = nodeStyles[node.getType()];
var selfHeight = node.getRenderContainer().getHeight() + nodeStyle.margin[0] + nodeStyle.margin[2];
var childHeight = (function() {
var sum = 0;
var children;
if (!side) {
children = node.getChildren();
} else {
children = node.getLayout()[side + "List"];
}
for (var i = 0; i < children.length; i++) {
var childLayout = children[i].getLayout();
if (children[i].getRenderContainer().getPaper() && children[i].getRenderContainer().getHeight() !== 0)
sum += childLayout.branchheight;
}
return sum;
})();
if (side) {
return childHeight;
} else {
return (selfHeight > childHeight ? selfHeight : childHeight);
}
};
if (nodeType === "root") {
Layout.y = getMinderSize().height / 2;
effectSet.push(node);
} else {
if (action === "append" || action === "contract") {
var nodeHeight = node.getRenderContainer().getHeight() || (node.getContRc().getHeight() + nodeStyle.padding[0] + nodeStyle.padding[2]);
Layout.branchheight = nodeHeight + nodeStyle.margin[0] + nodeStyle.margin[2];
} else if (action === "change") {
Layout.branchheight = countBranchHeight(node);
}
var parentLayout = parent.getLayout();
var parentShape = parent.getRenderContainer();
var prt = node.getParent() || parent;
//自底向上更新祖先元素的branchheight值
while (prt) {
var prtLayout = prt.getLayout();
if (prt.getType() === "root") {
prtLayout[appendside + "Height"] = countBranchHeight(prt, appendside);
} else {
prtLayout.branchheight = countBranchHeight(prt);
}
prt = prt.getParent();
}
}
//自顶向下更新受影响一侧的y值
var updateSide = function(appendside) {
var _buffer = [root];
while (_buffer.length > 0) {
var _buffer0Layout = _buffer[0].getLayout();
var children = _buffer0Layout[appendside + "List"] || _buffer[0].getChildren();
children = (function() {
var result = [];
for (var len = 0; len < children.length; len++) {
var l = children[len].getLayout();
if (l && l.added) {
result.push(children[len]);
}
}
return result;
})();
_buffer = _buffer.concat(children);
var sY = _buffer0Layout.y - (_buffer0Layout[appendside + "Height"] || _buffer0Layout.branchheight) / 2;
for (var i = 0; i < children.length; i++) {
var childLayout = children[i].getLayout();
childLayout.y = sY + childLayout.branchheight / 2;
sY += childLayout.branchheight;
}
if (_buffer[0] !== root && _buffer[0].getLayout().added) effectSet.push(_buffer[0]);
_buffer.shift();
}
};
var sideList;
if (appendside) {
updateSide(appendside);
} else {
updateSide("left");
updateSide("right");
}
return effectSet;
};
//计算节点在水平方向的位置
var updateLayoutHorizon = function(node) {
var nodeType = node.getType();
var parent = node.getParent();
var effectSet = [node];
var Layout = node.getLayout();
var _buffer = [node];
while (_buffer.length !== 0) {
var prt = _buffer[0].getParent();
var children = _buffer[0].getChildren();
children = (function() {
var result = [];
for (var len = 0; len < children.length; len++) {
var l = children[len].getLayout();
if (l.added) {
result.push(children[len]);
}
}
return result;
})();
_buffer = _buffer.concat(children);
if (!prt) {
Layout.x = getMinderSize().width / 2;
_buffer.shift();
continue;
}
var parentLayout = prt.getLayout();
var parentWidth = prt.getRenderContainer().getWidth();
var parentStyle = nodeStyles[prt.getType()];
var childLayout = _buffer[0].getLayout();
var childStyle = nodeStyles[_buffer[0].getType()];
if (parentLayout.align === "center") {
parentWidth = parentWidth / 2;
}
if (childLayout.appendside === "left") {
childLayout.x = parentLayout.x - parentWidth - parentStyle.margin[1] - childStyle.margin[3];
} else {
childLayout.x = parentLayout.x + parentWidth + parentStyle.margin[1] + childStyle.margin[3];
}
effectSet.push(_buffer[0]);
_buffer.shift();
}
return effectSet;
};
var translateNode = function(node) {
var Layout = node.getLayout();
var nodeShape = node.getRenderContainer();
var align = Layout.align;
var _rectHeight = nodeShape.getHeight();
var _rectWidth = nodeShape.getWidth();
switch (align) {
case "right":
nodeShape.setTranslate(Layout.x - _rectWidth, Layout.y - _rectHeight / 2);
break;
case "center":
nodeShape.setTranslate(Layout.x - _rectWidth / 2, Layout.y - _rectHeight / 2);
break;
default:
nodeShape.setTranslate(Layout.x, Layout.y - _rectHeight / 2);
break;
}
node.setPoint(Layout.x, Layout.y);
};
var updateConnectAndshIcon = function(node) {
var nodeType = node.getType();
var Layout = node.getLayout();
var nodeStyle = nodeStyles[node.getType()];
var connect;
//更新连线
if (nodeType === "main") {
if (!Layout.connect) {
connect = Layout.connect = new kity.Group();
var bezier = Layout.connect.bezier = new kity.Bezier();
var circle = Layout.connect.circle = new kity.Circle();
connect.addShapes([bezier, circle]);
minder.getRenderContainer().addShape(connect);
minder.getRoot().getRenderContainer().bringTop();
}
var parent = minder.getRoot();
var rootX = parent.getLayout().x;
var rootY = parent.getLayout().y;
connect = Layout.connect;
var nodeShape = node.getRenderContainer();
var nodeClosurePoints = nodeShape.getRenderBox().closurePoints;
var sPos;
var endPos;
if (Layout.appendside === "left") {
sPos = new kity.BezierPoint(rootX - 30, nodeClosurePoints[2].y + nodeShape.getHeight() / 2);
endPos = new kity.BezierPoint(nodeClosurePoints[2].x + 3, nodeClosurePoints[2].y + nodeShape.getHeight() / 2);
} else {
sPos = new kity.BezierPoint(rootX + 30, nodeClosurePoints[3].y + nodeShape.getHeight() / 2);
endPos = new kity.BezierPoint(nodeClosurePoints[3].x - 3, nodeClosurePoints[3].y + nodeShape.getHeight() / 2);
}
var sPosV = sPos.getVertex();
var endPosV = endPos.getVertex();
sPos.setVertex(rootX, rootY);
connect.bezier.setPoints([sPos, endPos]).stroke(nodeStyle.stroke);
connect.circle.setCenter(endPosV.x + (Layout.appendside === "left" ? -0.5 : -1.5), endPosV.y).fill("white").setRadius(4);
} else if (nodeType === "sub") {
if (!Layout.connect) {
connect = Layout.connect = new kity.Path();
minder.getRenderContainer().addShape(connect);
}
connect = Layout.connect;
var parent = node.getParent();
var parentShape = parent.getRenderContainer();
var parentBox = parentShape.getRenderBox();
var parentLayout = parent.getLayout();
var parentStyle = nodeStyles[node.getParent().getType()];
var Shape = node.getRenderContainer();
var sX, sY = parentBox.bottom - 5;
if (parent.getType() === 'main') {
sY = (parentBox.top + parentBox.bottom) / 2
}
var nodeX, nodeY = Shape.getRenderBox().closurePoints[1].y;
if (Layout.appendside === "left") {
sX = parentBox.closurePoints[1].x - parentStyle.margin[1];
nodeX = Shape.getRenderBox().closurePoints[0].x;
connect.getDrawer()
.clear()
.moveTo(sX, sY)
.lineTo(sX, nodeY > sY ? (nodeY - nodeStyle.margin[3]) : (nodeY + nodeStyle.margin[3]));
if (nodeY > sY) connect.getDrawer().carcTo(nodeStyle.margin[3], 0, 1, nodeX, nodeY);
else connect.getDrawer().carcTo(nodeStyle.margin[3], 0, 0, nodeX, nodeY);
connect.stroke(nodeStyle.stroke);
} else {
sX = parentBox.closurePoints[0].x + parentStyle.margin[1];
nodeX = Shape.getRenderBox().closurePoints[1].x + 1;
connect.getDrawer()
.clear()
.moveTo(sX, sY)
.lineTo(sX, nodeY > sY ? (nodeY - nodeStyle.margin[3]) : (nodeY + nodeStyle.margin[3]));
if (nodeY > sY) connect.getDrawer().carcTo(nodeStyle.margin[3], 0, 0, nodeX, nodeY);
else connect.getDrawer().carcTo(nodeStyle.margin[3], 0, 1, nodeX, nodeY);
connect.stroke(nodeStyle.stroke);
}
}
//更新收放icon
if (nodeType !== "root" && node.getChildren().length !== 0) {
if (!Layout.shicon) {
Layout.shicon = new ShIcon(node);
}
Layout.shicon.update();
}
};
var _style = {
getCurrentLayoutStyle: function() {
return nodeStyles;
},
initStyle: function() {
//渲染根节点
var _root = minder.getRoot();
var historyPoint = _root.getPoint();
if (historyPoint) historyPoint = JSON.parse(JSON.stringify(historyPoint));
minder.handelNodeInsert(_root);
//设置root的align
_root.getLayout().align = "center";
updateBg(_root);
initLayout(_root);
_root.getContRc().clear();
this._firePharse(new MinderEvent("RenderNodeLeft", {
node: _root
}, false));
this._firePharse(new MinderEvent("RenderNodeCenter", {
node: _root
}, false));
this._firePharse(new MinderEvent("RenderNodeRight", {
node: _root
}, false));
this._firePharse(new MinderEvent("RenderNodeBottom", {
node: _root
}, false));
this._firePharse(new MinderEvent("RenderNodeTop", {
node: _root
}, false));
this._firePharse(new MinderEvent("RenderNode", {
node: _root
}, false));
updateShapeByCont(_root);
updateLayoutHorizon(_root);
updateLayoutVertical(_root);
translateNode(_root);
if (historyPoint) _root.setPoint(historyPoint.x, historyPoint.y);
//渲染首层节点
var mains = _root.getChildren();
for (var i = 0; i < mains.length; i++) {
this.appendChildNode(_root, mains[i]);
if (mains[i].isExpanded() && (mains[i].getChildren().length > 0)) {
minder.expandNode(mains[i]);
}
}
_root.setPoint(_root.getLayout().x, _root.getLayout().y);
},
updateLayout: function(node) {
node.getContRc().clear();
this._firePharse(new MinderEvent("RenderNodeLeft", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeCenter", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeRight", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeBottom", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeTop", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNode", {
node: node
}, false));
updateShapeByCont(node);
var set1 = updateLayoutHorizon(node);
var set2 = updateLayoutVertical(node, node.getParent(), "change");
var set = uSet(set1, set2);
for (var i = 0; i < set.length; i++) {
translateNode(set [i]);
updateConnectAndshIcon(set [i]);
}
if (this.isNodeSelected(node)) {
this.highlightNode(node)
}
},
expandNode: function(ico) {
var isExpand, node;
if (ico instanceof MinderNode) {
node = ico;
isExpand = node.getLayout().shicon.switchState();
} else {
isExpand = ico.icon.switchState();
node = ico.icon._node;
}
var _buffer;
if (isExpand) {
node.expand();
//遍历子树展开需要展开的节点
_buffer = [node];
while (_buffer.length !== 0) {
var c = _buffer[0].getChildren();
if (_buffer[0].isExpanded() && c.length !== 0) {
for (var x = 0; x < c.length; x++) {
minder.appendChildNode(_buffer[0], c[x]);
}
_buffer = _buffer.concat(c);
}
_buffer.shift();
}
} else {
node.collapse();
//遍历子树移除需要移除的节点
_buffer = node.getChildren();
while (_buffer.length !== 0) {
var Layout = _buffer[0].getLayout();
if (Layout.added) {
Layout.added = false;
_buffer[0].getRenderContainer().remove();
Layout.connect.remove();
if (Layout.shicon) Layout.shicon.remove();
}
_buffer = _buffer.concat(_buffer[0].getChildren());
_buffer.shift();
}
var set = updateLayoutVertical(node, node.getParent(), "contract");
for (var i = 0; i < set.length; i++) {
translateNode(set [i]);
updateConnectAndshIcon(set [i]);
}
}
},
appendChildNode: function(parent, node, sibling) {
minder.handelNodeInsert(node);
node.clearLayout();
node.getContRc().clear();
var Layout = node.getLayout();
Layout = node.getLayout();
Layout.added = true;
var parentLayout = parent.getLayout();
var children = parent.getChildren();
var exist = (children.indexOf(node) !== -1);
if (sibling) {
if (!exist) parent.insertChild(node, sibling.getIndex() + 1);
var siblingLayout = sibling.getLayout();
Layout.appendside = siblingLayout.appendside;
Layout.align = siblingLayout.align;
if (parent.getType() === "root") {
minder.handelNodeInsert(node);
var len = children.length;
if (len < 7) {
if (len % 2) {
Layout.appendside = "right";
Layout.align = "left";
} else {
Layout.appendside = "left";
Layout.align = "right";
}
}
var sideList = parentLayout[Layout.appendside + "List"];
var idx = sideList.indexOf(sibling);
sideList.splice(idx + 1, 0, node);
}
} else {
if (parent.getType() !== "root") {
var prtLayout = parent.getLayout();
Layout.appendside = prtLayout.appendside;
Layout.align = prtLayout.align;
if (!exist) parent.appendChild(node);
} else {
var nodeP = node.getPoint();
if (nodeP && nodeP.x && nodeP.y) {
if (nodeP.x > parent.getPoint().x) {
Layout.appendside = "right";
Layout.align = "left";
} else {
Layout.appendside = "left";
Layout.align = "right";
}
} else {
if (parentLayout.rightList.length > 1 && parentLayout.rightList.length > parentLayout.leftList.length) {
Layout.appendside = "left";
Layout.align = "right";
} else {
Layout.appendside = "right";
Layout.align = "left";
}
}
var sideList1 = parentLayout[Layout.appendside + "List"];
sideList1.push(node);
var idx1;
if (Layout.appendside === "right") {
idx1 = sideList1.length;
} else {
idx1 = parent.getChildren().length;
}
if (!exist) parent.insertChild(node, idx1);
}
}
//设置分支类型
if (parent.getType() === "root") {
node.setType("main");
} else {
node.setType("sub");
}
//计算位置等流程
updateBg(node);
initLayout(node);
this._firePharse(new MinderEvent("RenderNodeLeft", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeCenter", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeRight", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeBottom", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNodeTop", {
node: node
}, false));
this._firePharse(new MinderEvent("RenderNode", {
node: node
}, false));
updateShapeByCont(node);
var set1 = updateLayoutVertical(node, parent, "append");
var set2 = updateLayoutHorizon(node);
var set = uSet(set1, set2);
for (var i = 0; i < set.length; i++) {
translateNode(set [i]);
updateConnectAndshIcon(set [i]);
}
parent.expand();
var shicon = parent.getLayout().shicon;
if (shicon) shicon.switchState(true);
},
appendSiblingNode: function(sibling, node) {
var parent = sibling.getParent();
this.appendChildNode(parent, node, sibling);
},
removeNode: function(nodes) {
nodes = utils.isArray(nodes) ? nodes : [nodes];
while (nodes.length !== 0) {
var parent = nodes[0].getParent();
if (!parent) {
nodes.splice(0, 1);
return false;
}
var nodeLayout = nodes[0].getLayout();
if (parent.getType() === "root") {
var sideList = parent.getLayout()[nodeLayout.appendside + "List"];
var index = sideList.indexOf(nodes[0]);
sideList.splice(index, 1);
}
parent.removeChild(nodes[0]);
if (parent.getType() !== "root" && parent.getChildren().length === 0) {
var prtLayout = parent.getLayout();
prtLayout.shicon.remove();
prtLayout.shicon = null;
}
var set = updateLayoutVertical(nodes[0], parent, "remove");
for (var j = 0; j < set.length; j++) {
translateNode(set [j]);
updateConnectAndshIcon(set [j]);
}
var _buffer = [nodes[0]];
while (_buffer.length !== 0) {
_buffer = _buffer.concat(_buffer[0].getChildren());
try {
_buffer[0].getRenderContainer().remove();
var Layout = _buffer[0].getLayout();
Layout.connect.remove();
Layout.shicon.remove();
} catch (error) {
console.log("isRemoved");
}
//检测当前节点是否在选中的数组中,如果在的话,从选中数组中去除
var idx = nodes.indexOf(_buffer[0]);
if (idx !== -1) {
nodes.splice(idx, 1);
}
_buffer.shift();
}
}
},
highlightNode: function(node) {
var highlight = node.isHighlight();
var nodeType = node.getType();
var nodeStyle = nodeStyles[nodeType];
var Layout = node.getLayout();
switch (nodeType) {
case "root":
case "main":
if (highlight) {
Layout.bgRect.fill(nodeStyle.highlight);
} else {
Layout.bgRect.fill(node.getData('backgroundcolor') || nodeStyle.fill);
}
break;
case "sub":
if (highlight) {
Layout.highlightshape.fill(nodeStyle.highlight).setOpacity(1);
node.getTextShape().fill(node.getData('fontcolor') || 'black');
} else {
Layout.highlightshape.setOpacity(0);
node.getTextShape().fill(node.getData('fontcolor') || 'white');
}
break;
default:
break;
}
}
};
this.addLayoutStyle("default", _style);
return {};
});
\ No newline at end of file
KityMinder.registerModule("LayoutModule", function() {
var me = this;
var clearPaper = function() {
me._rc.remove();
me._rc = new kity.Group();
me._paper.addShape(this._rc);
};
kity.extendClass(Minder, {
addLayoutStyle: function(name, style) {
if (!this._layoutStyles) this._layoutStyles = {};
this._layoutStyles[name] = style;
},
getLayoutStyle: function(name) {
return this._layoutStyles[name];
},
getLayoutStyleItems: function() {
var items = [];
for (var key in this._layoutStyles) {
items.push(key);
}
return items;
},
getCurrentStyle: function() {
var _root = this.getRoot();
return _root.getData("currentstyle");
},
setCurrentStyle: function(name) {
var _root = this.getRoot();
_root.setData("currentstyle", name);
return name;
},
getCurrentLayoutStyle: function() {
var curStyle = this.getCurrentStyle();
return this.getLayoutStyle(curStyle).getCurrentLayoutStyle.call(this);
},
highlightNode: function(node) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle(curStyle).highlightNode.call(this, node);
},
initStyle: function() {
var curStyle = this.getCurrentStyle();
this._rc.remove();
var transform = this._rc.transform;
this._rc = new kity.Group();
this._paper.addShape(this._rc);
this._rc.transform = transform;
this._rc._applyTransform();
var _root = this.getRoot();
_root.preTraverse(function(n) {
n.clearLayout();
});
this.getLayoutStyle(curStyle).initStyle.call(this);
this.fire('afterinitstyle');
},
appendChildNode: function(parent, node, index) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle(curStyle).appendChildNode.call(this, parent, node, index);
},
appendSiblingNode: function(sibling, node) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle(curStyle).appendSiblingNode.call(this, sibling, node);
},
removeNode: function(nodes) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle(curStyle).removeNode.call(this, nodes);
},
updateLayout: function(node) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle(curStyle).updateLayout.call(this, node);
},
expandNode: function(ico) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle(curStyle).expandNode.call(this, ico);
}
});
kity.extendClass(MinderNode, {
setLayout: function(k, v) {
if (this._layout === undefined) {
this._layout = {};
}
var _pros = this.getLayout();
Utils.extend(_pros, {
k: v
});
this._layout = _pros;
},
getLayout: function(k) {
if (k === undefined) {
return this._layout;
}
return this._layout[k];
},
clearLayout: function() {
this._layout = {};
}
});
var switchLayout = function(km, style) {
var _root = km.getRoot();
_root.preTraverse(function(n) {
n.setPoint();
n.getBgRc().clear();
});
km.setCurrentStyle(style);
//km.initStyle();
return style;
};
var SwitchLayoutCommand = kity.createClass("SwitchLayoutCommand", (function() {
return {
base: Command,
execute: switchLayout,
queryValue: function(km) {
return km.getCurrentStyle();
}
};
})());
var AppendChildNodeCommand = kity.createClass("AppendChildNodeCommand", (function() {
return {
base: Command,
execute: function(km, node) {
var parent = km.getSelectedNode();
if (!parent) {
return null;
}
if (parent.getType() !== "root" && parent.getChildren().length !== 0 && !parent.isExpanded()) {
km.expandNode(parent);
}
parent.expand();
km.appendChildNode(parent, node);
km.select(node, true);
return node;
},
queryState: function(km) {
var selectedNode = km.getSelectedNode();
if (!selectedNode) {
return -1;
} else {
return 0;
}
}
};
})());
var AppendSiblingNodeCommand = kity.createClass("AppendSiblingNodeCommand", (function() {
return {
base: Command,
execute: function(km, node) {
var selectedNode = km.getSelectedNode();
if (!selectedNode) {
return null;
}
if (selectedNode.isRoot()) {
node.setType("main");
km.appendChildNode(selectedNode, node);
} else {
km.appendSiblingNode(selectedNode, node);
}
km.select(node, true);
return node;
},
queryState: function(km) {
var selectedNodes = km.getSelectedNodes();
//没选中节点和单选root的时候返回不可执行
if (selectedNodes.length === 0 || (selectedNodes.length === 1 && selectedNodes[0] === km.getRoot())) {
return -1;
} else {
return 0;
}
}
};
})());
var RemoveNodeCommand = kity.createClass("RemoveNodeCommand", (function() {
return {
base: Command,
execute: function(km) {
if (km.getRoot().children.length == 0) {
return;
}
var selectedNodes = km.getSelectedNodes();
var _root = km.getRoot();
var _buffer = [];
for (var i = 0; i < selectedNodes.length; i++) {
_buffer.push(selectedNodes[i]);
}
do {
var parent = _buffer[0].getParent();
if (parent && _buffer.indexOf(parent) === -1) _buffer.push(parent);
_buffer.shift();
} while (_buffer.length > 1);
km.removeNode(selectedNodes);
km.select(_buffer[0]);
},
queryState: function(km) {
var selectedNodes = km.getSelectedNodes();
if (selectedNodes.length === 0 || (selectedNodes.length === 1 && selectedNodes[0] === km.getRoot())) {
return -1;
} else {
return 0;
}
}
};
})());
var EditNodeCommand = kity.createClass("EditNodeCommand", (function() {
return {
base: Command,
execute: function(km) {
var selectedNode = km.getSelectedNode();
if (!selectedNode) {
return null;
}
km.select(selectedNode, true);
km.textEditNode(selectedNode);
},
queryState: function(km) {
var selectedNode = km.getSelectedNode();
if (!selectedNode) {
return -1;
} else {
return 0;
}
},
isNeedUndo: function() {
return false;
}
};
})());
return {
"commands": {
"appendchildnode": AppendChildNodeCommand,
"appendsiblingnode": AppendSiblingNodeCommand,
"removenode": RemoveNodeCommand,
"editnode": EditNodeCommand,
"switchlayout": SwitchLayoutCommand
},
"events": {
"ready": function() {
this.setDefaultOptions('layoutstyle', this.getLayoutStyleItems());
switchLayout(this, this.getOptions('defaultlayoutstyle'));
},
"click": function(e) {
var ico = e.kityEvent.targetShape && e.kityEvent.targetShape.container;
if (ico && ico.class === "shicon") {
this.expandNode(ico);
this.fire('contentchange');
}
},
"resize": function(e) {
clearTimeout(this._lastStyleResetTimeout);
this._lastStyleResetTimeout = setTimeout(function() {
this.updateLayout(this.getRoot());
}.bind(this), 100);
},
"import": function(e) {
this.initStyle();
}
},
'contextmenu': [{
label: this.getLang('node.appendsiblingnode'),
exec: function() {
this.execCommand('appendsiblingnode', new MinderNode(this.getLang('topic')))
},
cmdName: 'appendsiblingnode'
}, {
label: this.getLang('node.appendchildnode'),
exec: function() {
this.execCommand('appendchildnode', new MinderNode(this.getLang('topic')))
},
cmdName: 'appendchildnode'
}, {
label: this.getLang('node.editnode'),
exec: function() {
this.execCommand('editnode', null);
},
cmdName: 'editnode'
}, {
label: this.getLang('node.removenode'),
cmdName: 'removenode'
}, {
divider: 1
}, {
label: this.getLang('layout.default'),
exec: function() {
this.execCommand('switchlayout', 'default');
this.initStyle();
},
cmdName: 'switchlayout'
}, {
label: this.getLang('layout.bottom'),
exec: function() {
this.execCommand('switchlayout', 'bottom');
this.initStyle();
},
cmdName: 'switchlayout'
}
],
"defaultOptions": {
"defaultlayoutstyle": "default",
"node": {
'appendsiblingnode': 'appendsiblingnode',
'appendchildnode': 'appendchildnode',
'editnode': 'editnode',
'removenode': 'removenode'
},
'defaultExpand': {
'defaultLayer': 0,
'defaultSubShow': 0
}
}
};
});
\ No newline at end of file
......@@ -57,13 +57,60 @@ var RemoveNodeCommand = kity.createClass('RemoverNodeCommand', {
}
});
var EditNodeCommand = kity.createClass('EditNodeCommand', {
base: Command,
execute: function(km) {
var selectedNode = km.getSelectedNode();
if (!selectedNode) {
return null;
}
km.select(selectedNode, true);
km.textEditNode(selectedNode);
},
queryState: function(km) {
var selectedNode = km.getSelectedNode();
if (!selectedNode) {
return -1;
} else {
return 0;
}
},
isNeedUndo: function() {
return false;
}
});
KityMinder.registerModule('NodeModule', function() {
return {
commands: {
'AppendChildNode': AppendChildCommand,
'AppendSiblingNode': AppendSiblingCommand,
'RemoveNode': RemoveNodeCommand
}
'RemoveNode': RemoveNodeCommand,
'EditNode': EditNodeCommand
},
'contextmenu': [{
label: this.getLang('node.appendsiblingnode'),
exec: function() {
this.execCommand('AppendSiblingNode', this.getLang('topic'));
},
cmdName: 'appendsiblingnode'
}, {
label: this.getLang('node.appendchildnode'),
exec: function() {
this.execCommand('AppendChildNode', this.getLang('topic'));
},
cmdName: 'appendchildnode'
}, {
label: this.getLang('node.editnode'),
exec: function() {
this.execCommand('EditNode');
},
cmdName: 'editnode'
}, {
label: this.getLang('node.removenode'),
cmdName: 'RemoveNode'
}, {
divider: 1
}]
};
});
\ No newline at end of file
KityMinder.registerModule( "NodeText", function () {
return {
events: {
'renderNodeCenter': function ( e ) {
var node = e.node;
var width = node.getContRc().getWidth();
var textShape = new kity.Text( node.getData( 'text' ) || '' );
textShape.setAttr( '_nodeTextShape', true );
node.getContRc().appendShape( textShape );
var style = this.getCurrentLayoutStyle()[ node.getType() ];
textShape.fill( style.color ).setSize( style.fontSize );
textShape.setTranslate( width + style.spaceLeft, 0 );
textShape.setVerticalAlign( 'middle' );
}
}
}
} );
\ No newline at end of file
......@@ -32,7 +32,7 @@ KityMinder.registerModule('PriorityModule', function() {
.setSize(this.width, this.height);
number = new kity.Text()
.setX(this.width / 2 + 0.5).setY(this.height / 2 + 0.5)
.setX(this.width / 2 + 0.5).setY(this.height / 2 - 0.5)
.setTextAnchor('middle')
.setVerticalAlign('middle')
.setFontSize(12)
......@@ -73,6 +73,10 @@ KityMinder.registerModule('PriorityModule', function() {
if (val) break;
}
return val;
},
queryState: function(km) {
return km.getSelectedNodes().length ? 0 : -1;
}
});
return {
......
......@@ -65,6 +65,10 @@ KityMinder.registerModule('ProgressModule', function() {
if (val) break;
}
return val;
},
queryState: function(km) {
return km.getSelectedNodes().length ? 0 : -1;
}
});
......
......@@ -100,7 +100,7 @@ KityMinder.registerModule('View', function() {
enableReadOnly: false
});
var CameraCommand = kity.createClass("CameraCommand", {
var CameraCommand = kity.createClass('CameraCommand', {
base: Command,
execute: function(km, focusNode, noAnimate) {
focusNode = focusNode || km.getRoot();
......@@ -112,7 +112,7 @@ KityMinder.registerModule('View', function() {
if (noAnimate) {
km.getRenderContainer().translate(dx, dy);
} else {
km.getRenderContainer().fxTranslate(dx, dy, 1000, "easeOutQuint");
km.getRenderContainer().fxTranslate(dx, dy, 1000, 'easeOutQuint');
}
this.setContentChanged(false);
},
......
KityMinder.registerModule( 'Zoom', function () {
KityMinder.registerModule('Zoom', function() {
var me = this;
var timeline;
me.setDefaultOptions( 'zoom', [ 50, 80, 100, 120, 150, 200 ] );
me.setDefaultOptions('zoom', [50, 80, 100, 120, 150, 200]);
function zoomMinder( minder, zoom ) {
function zoomMinder(minder, zoom) {
var paper = minder.getPaper();
var viewport = paper.getViewPort();
if ( !zoom ) return;
if (!zoom) return;
var animator = new kity.Animator( {
var animator = new kity.Animator({
beginValue: viewport.zoom,
finishValue: zoom / 100,
setter: function ( target, value ) {
setter: function(target, value) {
viewport.zoom = value;
target.setViewPort( viewport );
target.setViewPort(viewport);
}
} );
});
minder.zoom = zoom;
if ( timeline ) {
if (timeline) {
timeline.pause();
}
timeline = animator.start( paper, 500, 'ease' );
timeline = animator.start(paper, 500, 'ease', function() {
minder.refresh(300);
});
}
var ZoomCommand = kity.createClass( 'Zoom', {
var ZoomCommand = kity.createClass('Zoom', {
base: Command,
execute: zoomMinder,
queryValue: function ( minder ) {
queryValue: function(minder) {
return minder.zoom;
}
} );
});
var ZoomInCommand = kity.createClass( 'ZoomInCommand', {
var ZoomInCommand = kity.createClass('ZoomInCommand', {
base: Command,
execute: function ( minder ) {
zoomMinder( minder, this.nextValue( minder ) );
execute: function(minder) {
zoomMinder(minder, this.nextValue(minder));
},
queryState: function ( minder ) {
return ~this.nextValue( minder );
queryState: function(minder) {
return (~this.nextValue(minder));
},
nextValue: function ( minder ) {
var stack = minder.getOptions( 'zoom' ),
nextValue: function(minder) {
var stack = minder.getOptions('zoom'),
i;
for ( i = 0; i < stack.length; i++ ) {
if ( stack[ i ] > minder.zoom ) return stack[ i ];
for (i = 0; i < stack.length; i++) {
if (stack[i] > minder.zoom) return stack[i];
}
return 0;
},
enableReadOnly: false
} );
});
var ZoomOutCommand = kity.createClass( 'ZoomOutCommand', {
var ZoomOutCommand = kity.createClass('ZoomOutCommand', {
base: Command,
execute: function ( minder ) {
zoomMinder( minder, this.nextValue( minder ) );
execute: function(minder) {
zoomMinder(minder, this.nextValue(minder));
},
queryState: function ( minder ) {
return ~this.nextValue( minder );
queryState: function(minder) {
return (~this.nextValue(minder));
},
nextValue: function ( minder ) {
var stack = minder.getOptions( 'zoom' ),
nextValue: function(minder) {
var stack = minder.getOptions('zoom'),
i;
for ( i = stack.length - 1; i >= 0; i-- ) {
if ( stack[ i ] < minder.zoom ) return stack[ i ];
for (i = stack.length - 1; i >= 0; i--) {
if (stack[i] < minder.zoom) return stack[i];
}
return 0;
},
enableReadOnly: false
} );
});
return {
init: function () {
init: function() {
this.zoom = 100;
},
commands: {
......@@ -82,49 +84,49 @@ KityMinder.registerModule( 'Zoom', function () {
'zoom': ZoomCommand
},
events: {
'normal.keydown': function ( e ) {
'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-in');
}
if ( keymap[ '-' ] == keyCode ) {
me.execCommand( 'zoom-out' );
if (keymap['-'] == keyCode) {
me.execCommand('zoom-out');
}
},
'ready': function () {
'ready': function() {
this._zoomValue = 1;
},
'normal.mousewheel readonly.mousewheel': function ( e ) {
if ( !e.originEvent.ctrlKey ) return;
'normal.mousewheel readonly.mousewheel': function(e) {
if (!e.originEvent.ctrlKey) return;
var delta = e.originEvent.wheelDelta;
var me = this;
if ( !kity.Browser.mac ) {
if (!kity.Browser.mac) {
delta = -delta;
}
// 稀释
if ( Math.abs( delta ) > 100 ) {
clearTimeout( this._wheelZoomTimeout );
if (Math.abs(delta) > 100) {
clearTimeout(this._wheelZoomTimeout);
} else {
return;
}
this._wheelZoomTimeout = setTimeout( function () {
this._wheelZoomTimeout = setTimeout(function() {
var value;
var lastValue = me.getPaper()._zoom || 1;
if ( delta < 0 ) {
me.execCommand( 'zoom-in' );
} else if ( delta > 0 ) {
me.execCommand( 'zoom-out' );
if (delta < 0) {
me.execCommand('zoom-in');
} else if (delta > 0) {
me.execCommand('zoom-out');
}
}, 100 );
}, 100);
e.originEvent.preventDefault();
}
}
};
} );
\ No newline at end of file
});
\ No newline at end of file
KityMinder.registerProtocal("png", function() {
function loadImage(url, callback) {
var image = new Image();
image.onload = callback;
console.log(url);
image.src = url;
}
return {
fileDescription: 'PNG 图片(暂不支持IE)',
fileExtension: '.png',
encode: function(json, km) {
var domContainer = km.getPaper().container,
svgXml,
$svg,
bgDeclare = getComputedStyle(domContainer).backgroundImage,
bgUrl = /url\((.+)\)$/.exec(bgDeclare)[1],
renderContainer = km.getRenderContainer(),
renderBox = renderContainer.getRenderBox(),
transform = renderContainer.getTransform(),
width = renderBox.width,
height = renderBox.height,
padding = 20,
canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d'),
blob, DomURL, url, img, finishCallback;
bgUrl = bgUrl.replace(/"/g, '');
renderContainer.translate(-renderBox.x, -renderBox.y);
svgXml = km.getPaper().container.innerHTML;
renderContainer.translate(renderBox.x, renderBox.y);
$svg = $(svgXml).filter('svg');
$svg.attr({
width: renderBox.width,
height: renderBox.height,
style: 'font-family: Arial, "Microsoft Yahei","Heiti SC";'
});
// 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"
});
DomURL = window.URL || window.webkitURL || window;
url = DomURL.createObjectURL(blob);
canvas.width = width + padding * 2;
canvas.height = height + padding * 2;
function fillBackground(ctx, image, width, height) {
ctx.save();
ctx.fillStyle = ctx.createPattern(image, "repeat");
ctx.fillRect(0, 0, width, height);
ctx.restore();
}
function drawImage(ctx, image, x, y) {
ctx.drawImage(image, x, y);
}
function generateDataUrl(canvas) {
var url = canvas.toDataURL('png');
return url;
}
loadImage(url, function() {
var svgImage = this;
loadImage(bgUrl, function() {
var downloadUrl;
fillBackground(ctx, this, canvas.width, canvas.height);
drawImage(ctx, svgImage, padding, padding);
DomURL.revokeObjectURL(url);
downloadUrl = generateDataUrl(canvas);
if (finishCallback) {
finishCallback(downloadUrl);
}
if (!kity.Browser.ie) {
KityMinder.registerProtocal('png', function() {
function loadImage(url, callback) {
var image = document.createElement('img');
image.onload = callback;
image.src = url;
}
return {
fileDescription: 'PNG 图片',
fileExtension: '.png',
encode: function(json, km) {
var domContainer = km.getPaper().container,
svgXml,
$svg,
bgDeclare = getComputedStyle(domContainer).backgroundImage,
bgUrl = /url\((.+)\)$/.exec(bgDeclare)[1],
renderContainer = km.getRenderContainer(),
renderBox = renderContainer.getRenderBox(),
transform = renderContainer.getTransform(),
width = renderBox.width,
height = renderBox.height,
padding = 20,
canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d'),
blob, DomURL, url, img, finishCallback;
bgUrl = bgUrl.replace(/"/g, '');
renderContainer.translate(-renderBox.x, -renderBox.y);
svgXml = km.getPaper().container.innerHTML;
renderContainer.translate(renderBox.x, renderBox.y);
$svg = $(svgXml).filter('svg');
$svg.attr({
width: renderBox.width,
height: renderBox.height,
style: 'font-family: Arial, "Microsoft Yahei","Heiti SC";'
});
// 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"
});
});
return {
then: function(callback) {
finishCallback = callback;
DomURL = window.URL || window.webkitURL || window;
url = DomURL.createObjectURL(blob);
canvas.width = width + padding * 2;
canvas.height = height + padding * 2;
function fillBackground(ctx, image, width, height) {
ctx.save();
ctx.fillStyle = ctx.createPattern(image, "repeat");
ctx.fillRect(0, 0, width, height);
ctx.restore();
}
function drawImage(ctx, image, x, y) {
ctx.drawImage(image, x, y);
}
function generateDataUrl(canvas) {
var url = canvas.toDataURL('png');
return url;
}
};
},
recognizePriority: -1
};
});
\ No newline at end of file
loadImage(url, function() {
var svgImage = this;
loadImage(bgUrl, function() {
var downloadUrl;
fillBackground(ctx, this, canvas.width, canvas.height);
drawImage(ctx, svgImage, padding, padding);
DomURL.revokeObjectURL(url);
downloadUrl = generateDataUrl(canvas);
if (finishCallback) {
finishCallback(downloadUrl);
}
});
});
return {
then: function(callback) {
finishCallback = callback;
}
};
},
recognizePriority: -1
};
});
}
\ No newline at end of file
KityMinder.registerProtocal("svg", function() {
return {
fileDescription: 'SVG 矢量图(暂不支持IE)',
fileExtension: '.svg',
mineType: 'image/svg+xml',
encode: function(json, km) {
var domContainer = km.getPaper().container,
svgXml,
$svg,
renderContainer = km.getRenderContainer(),
renderBox = renderContainer.getRenderBox(),
transform = renderContainer.getTransform(),
width = renderBox.width,
height = renderBox.height,
padding = 20;
if (!kity.Browser.ie) {
KityMinder.registerProtocal('svg', function() {
return {
fileDescription: 'SVG 矢量图',
fileExtension: '.svg',
mineType: 'image/svg+xml',
encode: function(json, km) {
var domContainer = km.getPaper().container,
svgXml,
$svg,
svgXml = km.getPaper().container.innerHTML;
renderContainer = km.getRenderContainer(),
renderBox = renderContainer.getRenderBox(),
transform = renderContainer.getTransform(),
width = renderBox.width,
height = renderBox.height,
padding = 20;
$svg = $(svgXml).filter('svg');
$svg.attr({
width: width + padding * 2 | 0,
height: height + padding * 2 | 0,
style: 'font-family: Arial, "Microsoft Yahei","Heiti SC";'
});
$svg[0].setAttribute('viewBox', [renderBox.x - padding | 0,
renderBox.y - padding | 0,
width + padding * 2 | 0,
height + padding * 2 | 0
].join(' '));
svgXml = km.getPaper().container.innerHTML;
// need a xml with width and height
svgXml = $('<div></div>').append($svg).html();
$svg = $(svgXml).filter('svg');
$svg.attr({
width: width + padding * 2 | 0,
height: height + padding * 2 | 0,
style: 'font-family: Arial, "Microsoft Yahei", "Heiti SC";'
});
$svg[0].setAttribute('viewBox', [renderBox.x - padding | 0,
renderBox.y - padding | 0,
width + padding * 2 | 0,
height + padding * 2 | 0
].join(' '));
// svg 含有 &nbsp; 符号导出报错 Entity 'nbsp' not defined
svgXml = svgXml.replace(/&nbsp;/g, '&#xa0;');
// need a xml with width and height
svgXml = $('<div></div>').append($svg).html();
// svg 含有 &nbsp; 符号导出报错 Entity 'nbsp' not defined
return svgXml;
},
recognizePriority: -1
};
});
\ No newline at end of file
// svg 含有 &nbsp; 符号导出报错 Entity 'nbsp' not defined
svgXml = svgXml.replace(/&nbsp;/g, '&#xa0;');
// svg 含有 &nbsp; 符号导出报错 Entity 'nbsp' not defined
return svgXml;
},
recognizePriority: -1
};
});
}
\ No newline at end of file
KityMinder.registerTemplate('bottom', {
KityMinder.registerTemplate('structure', {
name: '组织结构图',
getLayout: function(node) {
......@@ -6,9 +8,5 @@ KityMinder.registerTemplate('bottom', {
if (node.isRoot()) return 'bottom';
return 'filetree';
},
getTheme: function(node) {
return node ? (node.isRoot() ? 'bottom' : 'filetree') : 'default';
}
});
\ No newline at end of file
KityMinder.registerTheme('bottom', {
'root-color': '#430',
'root-background': '#e9df98',
'root-stroke': 'none',
'root-font-size': 24,
'root-padding': [15, 25],
'root-margin': 0,
'root-radius': 0,
'root-space': 10,
'main-color': '#333',
'main-background': '#a4c5c0',
'main-stroke': 'none',
'main-font-size': 16,
'main-padding': [6, 20],
'main-margin': [30, 0, 10, 0],
'main-radius': 5,
'main-space': 5,
'sub-color': 'white',
'sub-background': 'none',
'sub-stroke': 'white',
'sub-font-size': 12,
'sub-padding': [5, 10],
'sub-margin': [5, 15, 10, 5],
'sub-radius': 5,
'sub-space': 5,
'connect-color': 'white',
'connect-width': 2,
'connect-radius': 5,
'selected-background': 'rgb(254, 219, 0)'
});
\ No newline at end of file
KityMinder.registerTheme('default', {
'background': 'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoTWFjaW50b3NoKSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDowQzg5QTQ0NDhENzgxMUUzOENGREE4QTg0RDgzRTZDNyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDowQzg5QTQ0NThENzgxMUUzOENGREE4QTg0RDgzRTZDNyI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkMwOEQ1NDRGOEQ3NzExRTM4Q0ZEQThBODREODNFNkM3IiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOkMwOEQ1NDUwOEQ3NzExRTM4Q0ZEQThBODREODNFNkM3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+e9P33AAAACVJREFUeNpisXJ0YUACTAyoAMr/+eM7EGGRZ4FQ7BycEAZAgAEAHbEGtkoQm/wAAAAASUVORK5CYII=) repeat',
'name': '脑图经典',
'root-color': '#430',
'root-background': '#e9df98',
'root-stroke': 'none',
'root-font-size': 24,
'root-padding': [15, 25],
'root-margin': 100,
'root-margin': [30, 100],
'root-radius': 30,
'root-space': 10,
'root-shadow': 'rgba(0, 0, 0, .25)',
......
KityMinder.registerTheme('fresh', {
'name': '文艺小清新',
'background': 'white',
'root-color': '#fff',
......@@ -7,7 +10,7 @@ KityMinder.registerTheme('fresh', {
'root-stroke': 'none',
'root-font-size': 16,
'root-padding': [12, 24],
'root-margin': 100,
'root-margin': [30, 100],
'root-radius': 5,
'root-space': 10,
......
KityMinder.registerTheme('filetree', {
KityMinder.registerTheme('snow', {
'root-color': '#430',
'root-background': '#e9df98',
'root-stroke': 'none',
'root-font-size': 24,
'root-padding': [15, 25],
'root-margin': 100,
'root-radius': 30,
'root-margin': 30,
'root-radius': 5,
'root-space': 10,
'main-color': '#333',
......@@ -13,8 +14,8 @@ KityMinder.registerTheme('filetree', {
'main-stroke': 'none',
'main-font-size': 16,
'main-padding': [6, 20],
'main-margin': [15, 15, 15, 10],
'main-radius': 0,
'main-margin': [20, 40],
'main-radius': 5,
'main-space': 5,
'sub-color': 'black',
......@@ -22,8 +23,8 @@ KityMinder.registerTheme('filetree', {
'sub-stroke': 'none',
'sub-font-size': 12,
'sub-padding': [5, 10],
'sub-margin': [15, 15, 15, 10],
'sub-radius': 0,
'sub-margin': [10, 20],
'sub-radius': 5,
'sub-space': 5,
'connect-color': 'white',
......
......@@ -194,6 +194,19 @@
} );
},
selectItemByValue: function( value ){
var values = this.data('options').value,
me = this,
i;
for (i = 0; i < values.length; i++) {
if (values[i] == value) return me.select(i);
}
return false;
},
getItems: function () {
return this.data( "options" ).items;
......
......@@ -12,6 +12,7 @@ KM.ui.define('menu',{
}:{}))
this.trigger('aftershow');
}
$obj.addClass('active');
},
hide : function(all){
var $parentmenu;
......@@ -26,6 +27,8 @@ KM.ui.define('menu',{
this.root().css('display','none');
this.trigger('afterhide');
}
var $obj = this.data('$mergeObj');
if ($obj) $obj.removeClass('active');
},
attachTo : function($obj){
var me = this;
......
......@@ -42,7 +42,7 @@ KM.ui.define('popup', {
},
hide: function () {
this.root().css('display', 'none');
this.trigger('afterhide')
this.trigger('afterhide');
},
attachTo: function ($obj, posObj) {
var me = this
......
.kmui-modal {
position: fixed;
top: 60px;
top: 90px;
right:10px;
background-color: #ffffff;
background-color: #fafafa;
outline: 0;
border-radius: 5px;
box-shadow: 3px 3px 8px rgba(0,0,0, .5);
......
......@@ -23,18 +23,17 @@ html, body, #kityminder, div.kmui-editor-body {
}
.kmui-container .kmui-toolbar{
background-color: #fafafa;
z-index: 99999;
margin-right: 400px;
z-index: 999;
}
.kmui-toolbar .kmui-btn-toolbar{
padding: 5px;
}
.kmui-toolbar {
position: absolute;
left: 10px;
top: 10px;
border-radius: 4px;
box-shadow: 3px 3px 8px rgba(0,0,0, .5);
left: 0;
right: 0;
top: 30px;
border-bottom: 1px solid #f0f0f0;
}
.kmui-container .kmui-editor-body {
background: rgb(50, 60, 61) url(../images/grid.png) repeat;
......@@ -44,6 +43,25 @@ html, body, #kityminder, div.kmui-editor-body {
svg, body {
font-family: Arial, "Microsoft Yahei", "Heiti SC", sans-serif;
}
#about{position:absolute;bottom:10px;right:10px;height:24px;line-height:24px;color:#888;font-family:Arial;font-size:13px;font-weight:normal;margin:0;text-shadow:0 1px 1px #000}#about a{color:#888}#about a:hover{color:#fff}
#about {
position:absolute;
bottom: 0;
right: 0;
left: 0;
height: 30px;
line-height: 30px;
background: #fafafa;
color: #333;
font-family:Arial;
font-size:13px;
font-weight:normal;
margin:0;
text-align: right;
padding: 0 15px;
border-top: 1px solid #f0f0f0;
}
#about a {
color: #333;
}
#km-version.new-version{position:relative;padding-right:30px}
#km-version.new-version:after{content:'NEW';color:#ff0;position:absolute;top:-10px;right:-5px;display:block;background:#f00;padding:0 5px;border-radius:4px;text-shadow:none;box-shadow:-1px 1px 3px rgba(0,0,0,0.3);-webkit-transform:scale(.6);-moz-transform:scale(.6);-ms-transform:scale(.6);transform:scale(.6)}
themes/default/images/baiducloud.png

1.34 KB | W: | H:

themes/default/images/baiducloud.png

1.62 KB | W: | H:

themes/default/images/baiducloud.png
themes/default/images/baiducloud.png
themes/default/images/baiducloud.png
themes/default/images/baiducloud.png
  • 2-up
  • Swipe
  • Onion skin
themes/default/images/share.png

1.14 KB | W: | H:

themes/default/images/share.png

1.46 KB | W: | H:

themes/default/images/share.png
themes/default/images/share.png
themes/default/images/share.png
themes/default/images/share.png
  • 2-up
  • Swipe
  • Onion skin
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