Commit a905f19b authored by campaign's avatar campaign

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

parents 204a3282 87f6d905
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
"white": false, "white": false,
"quotmark": false, "quotmark": false,
"predef" : [ "predef" : [
"module",
"require", "require",
"console", "console",
"kity", "kity",
......
Subproject commit ebccc80ba41995fa718b1fb0b8f7d79938501ed1 Subproject commit a9630e638b29633f62cdc2df239bc702118b231a
...@@ -42,8 +42,8 @@ KityMinder.LANG[ 'zh-cn' ] = { ...@@ -42,8 +42,8 @@ KityMinder.LANG[ 'zh-cn' ] = {
} }
}, },
'node': { 'node': {
'appendsiblingnode': '插入兄弟节点', 'appendsiblingnode': '插入同级节点',
'appendchildnode': '插入子节点', 'appendchildnode': '插入子节点',
'removenode': '删除节点' 'removenode': '删除节点'
} }
......
This diff is collapsed.
( function () {
function getKMBasePath( docUrl, confUrl ) {
return getBasePath( docUrl || self.document.URL || self.location.href, confUrl || getConfigFilePath() );
}
function getConfigFilePath() {
var configPath = document.getElementsByTagName( 'script' );
return configPath[ configPath.length - 1 ].src;
}
function getBasePath( docUrl, confUrl ) {
var basePath = confUrl;
if ( /^(\/|\\\\)/.test( confUrl ) ) {
basePath = /^.+?\w(\/|\\\\)/.exec( docUrl )[ 0 ] + confUrl.replace( /^(\/|\\\\)/, '' );
} else if ( !/^[a-z]+:/i.test( confUrl ) ) {
docUrl = docUrl.split( "#" )[ 0 ].split( "?" )[ 0 ].replace( /[^\\\/]+$/, '' );
basePath = docUrl + "" + confUrl;
}
return optimizationPath( basePath );
}
function optimizationPath( path ) {
var protocol = /^[a-z]+:\/\//.exec( path )[ 0 ],
tmp = null,
res = [];
path = path.replace( protocol, "" ).split( "?" )[ 0 ].split( "#" )[ 0 ];
path = path.replace( /\\/g, '/' ).split( /\// );
path[ path.length - 1 ] = "";
while ( path.length ) {
if ( ( tmp = path.shift() ) === ".." ) {
res.pop();
} else if ( tmp !== "." ) {
res.push( tmp );
}
}
return protocol + res.join( "/" );
}
window.KITYMINDER_CONFIG = {
'KITYMINDER_HOME_URL': getKMBasePath(),
//定义工具栏
toolbars: [
'hand zoom-in zoom-out | undo redo | bold italic | fontfamily fontsize forecolor | saveto | markers | node | switchlayout'
]
//设置主题
//,defaultlayoutstyle : 'default' //设置默认的主题
//,layoutstyle : [] //添加有那些主图
//回退相关选项
//,maxUndoCount:20 //最大可回退的次数,默认20
//语言默认是zh-cn
//,lang:'zh-cn'
//设置km整体的z-index大小
//,zIndex : 1000
};
} )()
\ No newline at end of file
This diff is collapsed.
.kmui-modal-header .kmui-title{
font-size: 14px;
}
.kmui-dialog-markers-body {
padding-bottom: 5px
}
.icon-list{
margin: 0;
padding: 0
}
.icon-list li{
padding: 5px 10px;
margin: 0;
list-style: none;
cursor: pointer;
color: #333
}
.icon-list li:hover,.icon-list li.active{
background: #cfe0f7
}
.icon-list li span.icon{
display: inline-block;
width: 20px;
height: 20px;
vertical-align: middle;
margin-right: 10px;
}
\ No newline at end of file
( function () {
var utils = KM.utils;
KM.registerWidget( 'markers', {
tpl: "<ul class='icon-list'>" +
"<li value='1' type='priority'><span class='icon' style='background:url(../dialogs/icons/iconpriority.png) 0 0'></span><span><%= priority %>1</span></li>" +
"<li value='2' type='priority'><span class='icon' style='background:url(../dialogs/icons/iconpriority.png) -20px 0'></span><span><%= priority %>2</span></li>" +
"<li value='3' type='priority'><span class='icon' style='background:url(../dialogs/icons/iconpriority.png) -40px 0'></span><span><%= priority %>3</span></li>" +
"<li value='4' type='priority'><span class='icon' style='background:url(../dialogs/icons/iconpriority.png) -60px 0'></span><span><%= priority %>4</span></li>" +
"<li value='5' type='priority'><span class='icon' style='background:url(../dialogs/icons/iconpriority.png) -80px 0'></span><span><%= priority %>5</span></li>" +
"</ul>" +
"<ul class='icon-list'>" +
"<li value='1' type='progress'><span class='icon' style='background:url(../dialogs/icons/iconprogress.png) 0 0'></span><span><%= progress.notdone %></span></li>" +
"<li value='2' type='progress'><span class='icon' style='background:url(../dialogs/icons/iconprogress.png) -20px 0'></span><span><%= progress.quarterdone %></span></li>" +
"<li value='3' type='progress'><span class='icon' style='background:url(../dialogs/icons/iconprogress.png) -40px 0'></span><span><%= progress.halfdone %></span></li>" +
"<li value='4' type='progress'><span class='icon' style='background:url(../dialogs/icons/iconprogress.png) -60px 0'></span><span><%= progress.threequartersdone %></span></li>" +
"<li value='5' type='progress'><span class='icon' style='background:url(../dialogs/icons/iconprogress.png) -80px 0'></span><span><%= progress.done %></span></li>" +
"</ul>",
initContent: function ( km ) {
var lang = km.getLang( 'dialogs.markers' );
if ( lang ) {
var html = $.parseTmpl( this.tpl, lang );
}
this.root().html( html );
},
initEvent: function ( km, $w ) {
$w.on( "click", "li", function () {
var $this = $( this );
$this.siblings().removeClass( "active" );
$this.toggleClass( "active" );
var val = $this.val();
if ( !$this.hasClass( "active" ) ) {
val = null;
}
var type = $this.attr( "type" );
km.execCommand( type, val );
} );
km.on( 'interactchange', function ( e ) {
var valPri = this.queryCommandValue( "priority" );
var valPro = this.queryCommandValue( "progress" );
$w.find( "li[type='priority']" ).removeClass( "active" );
$w.find( "li[type='priority'][value='" + valPri + "']" ).addClass( "active" );
$w.find( "li[type='progress']" ).removeClass( "active" );
$w.find( "li[type='progress'][value='" + valPro + "']" ).addClass( "active" );
} );
},
buttons: {
'ok': {
exec: function ( km, $w ) {
var href = $( '#kmui-link-Jhref' ).val().replace( /^\s+|\s+$/g, '' );
if ( href ) {
km.execCommand( 'link', {
'href': href,
'target': $( "#kmui-link-Jtarget:checked" ).length ? "_blank" : '_self',
'title': $( "#kmui-link-Jtitle" ).val().replace( /^\s+|\s+$/g, '' ),
'_href': href
} );
}
}
},
'cancel': {}
},
width: 200,
} )
} )();
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="jquery-2.1.0.min.js" charset="utf-8"></script>
<script src="baidu-frontia-js-full-1.0.0.js" charset="utf-8"></script>
<script src="social.js" charset="utf-8"></script>
<script src="kitygraph.all.min.js" charset="utf-8"></script>
<script src="configure.js" charset="utf-8"></script>
<script src="dev.js" charset="utf-8"></script>
<script src="lang/zh-cn/zh-cn.js" charset="utf-8"></script>
<link href="themes/default/css/import.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" href="social.css">
<style>
.km_receiver{
width:0;
height:0;
}
.km-minderNode{
cursor:default;
}
.kmui-container {
height: 100%;
}
html, body, div {
margin: 0;
padding: 0;
}
html, body, div.kmui-editor-body {
height: 100%;
-moz-user-select: none;
}
</style>
</head>
<body >
<div id="kityminder" style="height:100%;width:100%" onselectstart="return false">
</div>
<div id="social"></div>
</body>
<script>
window.km = KM.getKityMinder('kityminder');
</script>
</html>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
KityMinder.LANG[ 'zh-cn' ] = {
'maintopic': '中心主题',
'topic': '分支主题',
'tooltips': {
'undo': '撤销',
'redo': '重做',
'bold': '加粗',
'italic': '斜体',
'forecolor': '字体颜色',
'fontfamily': '字体',
'fontsize': '字号',
'layoutstyle': '主题',
'node': '节点操作',
'saveto': '导出',
'hand': '允许拖拽',
'zoom-in': '放大',
'zoom-out': '缩小',
'markers': '添加标签',
'switchlayout': '切换主题'
},
'popupcolor': {
'clearColor': '清空颜色',
'standardColor': '标准颜色',
'themeColor': '主题颜色'
},
'dialogs': {
'markers': {
'static': {
'lang_input_text': '文本内容:',
'lang_input_url': '链接地址:',
'lang_input_title': '标题:',
'lang_input_target': '是否在新窗口打开:'
},
'priority': '优先级',
'progress': {
'notdone': "未完成",
'quarterdone': '完成1/4',
'halfdone': '完成1/2',
'threequartersdone': '完成3/4',
'done': '已完成'
}
}
},
'node': {
'appendsiblingnode': '插入兄弟节点',
'appendchildnode': '插入孩子节点',
'removenode': '删除节点'
}
};
\ No newline at end of file
{
"main": "index.html",
"name": "kityminder",
"description": "kityminder",
"version": "1.0.0.0 ",
"keywords": [ "kity", "kityminder", "minder" ],
"window": {
"icon": "minder.png",
"toolbar": false,
"width": 800,
"height": 600,
"frame": true
}
}
\ No newline at end of file
#social {
position: absolute;
right: 10px;
top: 10px;
line-height: 20px;
text-align: right;
overflow: hidden;
}
#social button {
font-family: Arial, "Heiti SC", "Microsoft Yahei";
outline: none;
display: inline-block;
padding: 0 15px;
height: 35px;
font-size: 13px;
line-height: 35px;
text-align: center;
border-radius: 5px;
color: #ffffff;
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 */
}
#social button:hover {
background: #009fff;
}
#social button[disabled] {
background: #AAA;
}
#social button.baidu-cloud {
padding-left: 35px;
position: relative;
}
#social 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 button.share {
padding-left: 35px;
position: relative;
}
#social 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;
}
#social button img {
position: relative;
top: 3px;
border-radius: 2px;
margin-right: 7px;
}
#social button.user-file {
padding-right: 28px;
position: relative;
}
#social 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: #FFFFFF transparent transparent transparent;
}
.user-file-menu {
margin-top: 20px;
margin-left: 1px;
}
This diff is collapsed.
#social {
position: absolute;
right: 10px;
top: 10px;
line-height: 20px;
text-align: right;
overflow: hidden;
button {
font-family: Arial, "Heiti SC", "Microsoft Yahei";
outline: none;
display: inline-block;
padding: 0 15px;
height: 35px;
font-size: 13px;
line-height: 35px;
text-align: center;
border-radius: 5px;
color: #ffffff;
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 */
&:hover {
background: #009fff;
}
&[disabled] {
background: #AAA;
}
&.baidu-cloud {
padding-left: 35px;
position: relative;
&:before {
content: ' ';
display: block;
width: 24px;
height: 24px;
background: url(../themes/default/images/baiducloud.png);
position: absolute;
left: 7px;
top: 5px;
}
}
&.share {
padding-left: 35px;
position: relative;
&:before {
content: ' ';
display: block;
width: 24px;
height: 24px;
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;
}
&.user-file {
padding-right: 28px;
position: relative;
&:after {
content: ' ';
display: block;
position: absolute;
right: 10px;
top: 15px;
width: 0;
height: 0;
border: solid;
border-width: 4px 5px;
border-color: #FFFFFF transparent transparent transparent;
}
}
}
}
.user-file-menu {
margin-top: 20px;
margin-left: 1px;
}
\ No newline at end of file
utils.extend( KityMinder, function () {
var _kityminderUI = {},
_kityminderToolbarUI = {},
_activeWidget = null,
_widgetData = {},
_widgetCallBack = {};
return {
registerUI: function ( uiname, fn ) {
utils.each( uiname.split( /\s+/ ), function ( i, name ) {
_kityminderUI[ name ] = fn;
} )
},
registerToolbarUI: function ( uiname, fn ) {
utils.each( uiname.split( /\s+/ ), function ( i, name ) {
_kityminderToolbarUI[ name ] = fn;
} )
},
loadUI: function ( km ) {
utils.each( _kityminderUI, function ( i, fn ) {
fn.call( km )
} )
},
_createUI: function ( id ) {
var $cont = $( '<div class="kmui-container"></div>' ),
$toolbar = $.kmuitoolbar(),
$kmbody = $( '<div class="kmui-editor-body"></div>' ),
$statusbar = $( '<div class="kmui-statusbar"></div>' );
$cont.append( $toolbar ).append( $kmbody ).append( $statusbar );
$( utils.isString( id ) ? '#' + id : id ).append( $cont );
return {
'$container': $cont,
'$toolbar': $toolbar,
'$body': $kmbody,
'$statusbar': $statusbar
};
},
_createToolbar: function ( $toolbar, km ) {
var toolbars = km.getOptions( 'toolbars' );
if ( toolbars && toolbars.length ) {
var btns = [];
$.each( toolbars, function ( i, uiNames ) {
$.each( uiNames.split( /\s+/ ), function ( index, name ) {
if ( name == '|' ) {
$.kmuiseparator && btns.push( $.kmuiseparator() );
} else {
if ( _kityminderToolbarUI[ name ] ) {
var ui = _kityminderToolbarUI[ name ].call( km, name );
ui && btns.push( ui );
}
}
} );
btns.length && $toolbar.kmui().appendToBtnmenu( btns );
} );
}
$toolbar.append( $( '<div class="kmui-dialog-container"></div>' ) );
},
_createStatusbar: function ( $statusbar, km ) {
},
getKityMinder: function ( id, options ) {
var containers = this._createUI( id );
var km = this.getMinder( containers.$body.get( 0 ), options );
this._createToolbar( containers.$toolbar, km );
this._createStatusbar( containers.$statusbar, km );
km.$container = containers.$container;
this.loadUI( km );
return km.fire( 'interactchange' );
},
registerWidget: function ( name, pro, cb ) {
_widgetData[ name ] = $.extend2( pro, {
$root: '',
_preventDefault: false,
root: function ( $el ) {
return this.$root || ( this.$root = $el );
},
preventDefault: function () {
this._preventDefault = true;
},
clear: false
} );
if ( cb ) {
_widgetCallBack[ name ] = cb;
}
},
getWidgetData: function ( name ) {
return _widgetData[ name ]
},
setWidgetBody: function ( name, $widget, km ) {
if ( !km._widgetData ) {
utils.extend( km, {
_widgetData: {},
getWidgetData: function ( name ) {
return this._widgetData[ name ];
},
getWidgetCallback: function ( widgetName ) {
var me = this;
return function () {
return _widgetCallBack[ widgetName ].apply( me, [ me, $widget ].concat( utils.argsToArray( arguments, 0 ) ) )
}
}
} )
}
var pro = _widgetData[ name ];
if ( !pro ) {
return null;
}
pro = km._widgetData[ name ];
if ( !pro ) {
pro = _widgetData[ name ];
pro = km._widgetData[ name ] = $.type( pro ) == 'function' ? pro : utils.clone( pro );
}
pro.root( $widget.kmui().getBodyContainer() );
pro.initContent( km, $widget );
if ( !pro._preventDefault ) {
pro.initEvent( km, $widget );
}
pro.width && $widget.width( pro.width );
},
setActiveWidget: function ( $widget ) {
_activeWidget = $widget;
}
}
}() );
\ No newline at end of file
KM.registerToolbarUI( 'bold italic redo undo',
function ( name ) {
var me = this;
var $btn = $.kmuibutton( {
icon: name,
click: function () {
me.execCommand( name );
},
title: this.getLang( 'tooltips' )[ name ] || ''
} );
this.on( 'interactchange', function () {
var state = this.queryCommandState( name );
$btn.kmui().disabled( state == -1 ).active( state == 1 );
} );
return $btn;
}
);
\ No newline at end of file
KM.registerToolbarUI( 'fontfamily fontsize', function ( name ) {
var me = this,
label = me.getLang( 'tooltips.' + name ),
options = {
label: label,
title: label,
comboboxName: name,
items: me.getOptions( name ) || [],
itemStyles: [],
value: [],
autowidthitem: []
},
$combox = null,
comboboxWidget = null;
if ( options.items.length == 0 ) {
return null;
}
switch ( name ) {
case 'fontfamily':
options = transForFontfamily( options );
break;
case 'fontsize':
options = transForFontsize( options );
break;
}
//实例化
$combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( name, res.value );
} ).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
}
} );
//状态反射
this.on( 'interactchange', function () {
var state = this.queryCommandState( name ),
value = this.queryCommandValue( name );
//设置按钮状态
comboboxWidget.button().kmui().disabled( state == -1 ).active( state == 1 );
if ( value ) {
//设置label
value = value.replace( /['"]/g, '' ).toLowerCase().split( /['|"]?\s*,\s*[\1]?/ );
comboboxWidget.selectItemByLabel( value );
}
} );
return comboboxWidget.button().addClass( 'kmui-combobox' );
//字体参数转换
function transForFontfamily( options ) {
var temp = null,
tempItems = [];
for ( var i = 0, len = options.items.length; i < len; i++ ) {
temp = options.items[ i ].val;
tempItems.push( temp.split( /\s*,\s*/ )[ 0 ] );
options.itemStyles.push( 'font-family: ' + temp );
options.value.push( temp );
options.autowidthitem.push( $.wordCountAdaptive( tempItems[ i ] ) );
}
options.items = tempItems;
return options;
}
//字体大小参数转换
function transForFontsize( options ) {
var temp = null,
tempItems = [];
options.itemStyles = [];
options.value = [];
for ( var i = 0, len = options.items.length; i < len; i++ ) {
temp = options.items[ i ];
tempItems.push( temp );
options.itemStyles.push( 'font-size: ' + temp + 'px; height:' + (temp+2) + 'px; line-height: ' + (temp + 2) + 'px' );
}
options.value = options.items;
options.items = tempItems;
options.autoRecord = false;
return options;
}
} );
KM.registerToolbarUI( 'forecolor', function ( name ) {
function getCurrentColor() {
return $colorLabel.css( 'background-color' );
}
var me = this,
$colorPickerWidget = null,
$colorLabel = null,
$btn = null;
this.on( 'interactchange', function () {
var state = this.queryCommandState( name );
$btn.kmui().disabled( state == -1 ).active( state == 1 );
} );
$btn = $.kmuicolorsplitbutton( {
icon: name,
caret: true,
name: name,
title: this.getLang( 'tooltips' )[ name ] || '',
click: function () {
var color = kity.Color.parse(getCurrentColor()).toHEX();
if(!color == '#000000'){
me.execCommand( name, color );
}
}
} );
$colorLabel = $btn.kmui().colorLabel();
$colorPickerWidget = $.kmuicolorpicker( {
name: name,
lang_clearColor: me.getLang( 'popupcolor' )[ 'clearColor' ] || '',
lang_themeColor: me.getLang( 'popupcolor' )[ 'themeColor' ] || '',
lang_standardColor: me.getLang( 'popupcolor' )[ 'standardColor' ] || ''
} ).on( 'pickcolor', function ( evt, color ) {
window.setTimeout( function () {
$colorLabel.css( "backgroundColor", color );
me.execCommand( name, color );
}, 0 );
} ).on( 'show', function () {
KM.setActiveWidget( $colorPickerWidget.kmui().root() );
} ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
$btn.kmui().on( 'arrowclick', function () {
if ( !$colorPickerWidget.parent().length ) {
me.$container.find( '.kmui-dialog-container' ).append( $colorPickerWidget );
}
$colorPickerWidget.kmui().show( $btn, {
caretDir: "down",
offsetTop: -5,
offsetLeft: 8,
caretLeft: 11,
caretTop: -8
} );
} ).register( 'click', $btn, function () {
$colorPickerWidget.kmui().hide()
} );
return $btn;
} );
\ No newline at end of file
KM.registerUI( 'contextmenu', function () {
var me = this;
function getItemByLabel(label){
var result;
utils.each(me.getContextmenu(),function(i,item){
if(item.label == label){
result = item;
return false;
}
});
return result;
}
var $menu = $.kmuidropmenu({
click:function(e,v,l){
var item = getItemByLabel(l);
if(item.exec){
item.exec.apply(km)
}else{
me.execCommand(item.cmdName);
}
this.hide();
}
});
me.$container.append($menu);
me.on('contextmenu',function(e){
var items = me.getContextmenu();
var data = [];
utils.each(items,function(i,item){
if(item.divider){
data.push(item)
return;
}
if(me.queryCommandState(item.cmdName)!=-1){
data.push({
label:item.label,
value:item.cmdName
})
}
});
if(data.length){
var item = data[data.length-1];
if(item.divider){
data.pop();
}
$menu.kmui().setData({
data:data
}).position(e.getPosition()).show();
e.preventDefault()
}
});
me.on('click',function(){
$menu.kmui().hide();
});
me.on('beforemousedown',function(e){
var isRightMB;
if ("which" in e.originEvent) // Gecko (Firefox), WebKit (Safari/Chrome) & Opera
isRightMB = e.originEvent.which == 3;
else if ("button" in e.originEvent) // IE, Opera
isRightMB = e.originEvent.button == 2;
if(isRightMB){
e.stopPropagationImmediately();
}
})
} );
KM.registerToolbarUI( 'markers', function ( name ) {
var me = this,
currentRange, $dialog,
opt = {
width: 200,
title: this.getLang( 'tooltips' )[ name ] || '',
url: me.getOptions( 'KITYMINDER_HOME_URL' ) + 'dialogs/' + name + '/' + name + '.js',
};
var $btn = $.kmuibutton( {
icon: name,
title: this.getLang( 'tooltips' )[ name ] || ''
} );
//加载模版数据
utils.loadFile( document, {
src: opt.url,
tag: "script",
type: "text/javascript",
defer: "defer"
}, function () {
$dialog = $.kmuimodal( opt );
$dialog.attr( 'id', 'kmui-dialog-' + name ).addClass( 'kmui-dialog-' + name )
.find( '.kmui-modal-body' ).addClass( 'kmui-dialog-' + name + '-body' );
$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 );
}
KM.setWidgetBody( name, $dialog, me );
} ).attachTo( $btn )
} );
me.on( 'interactchange', function () {
var state = this.queryCommandState( name );
$btn.kmui().disabled( state == -1 ).active( state == 1 )
} );
return $btn;
} );
\ 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;
}
//实例化
$combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( name, res.value );
} ).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
}
} );
//状态反射
me.on( 'interactchange', function () {
var state = this.queryCommandState( name ),
value = this.queryCommandValue( name );
//设置按钮状态
comboboxWidget.button().kmui().disabled( state == -1 ).active( state == 1 );
if ( value ) {
//设置label
value = value.replace( /['"]/g, '' ).toLowerCase().split( /['|"]?\s*,\s*[\1]?/ );
comboboxWidget.selectItemByLabel( value );
}
} );
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( 'node', function ( name ) {
var shortcutKeys = {
"appendsiblingnode": "enter",
"appendchildnode": "tab",
"removenode": "del|backspace"
};
var me = this,
msg = me.getLang( 'node' ),
label = me.getLang( 'tooltips.' + name ),
options = {
label: label,
title: label,
comboboxName: name,
items: me.getOptions( name ) || [],
itemStyles: [],
value: [],
autowidthitem: [],
enabledRecord: false
},
$combox = null;
if ( options.items.length == 0 ) {
return null;
}
//实例化
$combox = $.kmuibuttoncombobox( transForInserttopic( options ) ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
me.execCommand( res.value, new MinderNode( me.getLang().topic ) );
} ).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
}
var combox = $combox.kmui();
combox.traverseItems( function ( label, value ) {
if ( me.queryCommandState( value ) == -1 ) {
combox.disableItemByLabel( label )
} else {
combox.enableItemByLabel( label )
}
} )
} );
return comboboxWidget.button().addClass( 'kmui-combobox' );
function transForInserttopic( options ) {
var tempItems = [];
utils.each( options.items, function ( k, v ) {
options.value.push( v );
tempItems.push( ( msg[ k ] || k ) + '(' + shortcutKeys[ v ].toUpperCase() + ')' );
options.autowidthitem.push( $.wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) );
} );
options.items = tempItems;
return options;
}
} );
\ No newline at end of file
KM.registerToolbarUI( 'saveto', function ( name ) {
var me = this,
label = me.getLang( 'tooltips.' + name ),
options = {
label: label,
title: label,
comboboxName: name,
items: [],
itemStyles: [],
value: [],
autowidthitem: [],
enabledRecord: false
},
$combox = null,
comboboxWidget = null;
var downloadLink = document.createElement( 'a' );
utils.each( KityMinder.getAllRegisteredProtocals(), function ( k ) {
var p = KityMinder.findProtocal( k );
var text = p.fileDescription + '(' + p.fileExtension + ')';
options.value.push( k );
options.items.push( text );
options.autowidthitem.push( $.wordCountAdaptive( text ), true );
} );
//实例化
$combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 );
comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) {
if ( res.value === "png" ) {
var svghtml = $( "#kityminder .kmui-editor-body" ).html();
var bgImg = $( "#kityminder .kmui-editor-body" ).css( "backgroundImage" ).replace( /"/g, "" ).replace( /url\(|\)$/ig, "" );
var renderBox = me.getRenderContainer().getRenderBox( "top" );
var renderContainer = me.getRenderContainer();
var transform = renderContainer.getTransform();
renderContainer.resetTransform();
var svg = $( svghtml ).attr( {
width: renderBox.width,
height: renderBox.height,
viewBox: null
} );
var div = $( "<div></div>" ).append( svg );
svghtml = div.html();
var canvas = $( '<canvas width="' + ( parseInt( renderBox.width ) + 40 ) + '" height="' + ( parseInt( renderBox.height ) + 40 ) + '"></canvas>' );
var ctx = canvas[ 0 ].getContext( "2d" );
var DOMURL = self.URL || self.webkitURL || self;
var img = new Image();
var svg = new Blob( [ svghtml ], {
type: "image/svg+xml;charset=utf-8"
} );
var url = DOMURL.createObjectURL( svg );
img.onload = function () {
var bgTexture = document.createElement( 'img' );
bgTexture.src = bgImg;
bgTexture.onload = function () {
var bgfill = ctx.createPattern( bgTexture, "repeat" );
ctx.fillStyle = bgfill;
ctx.fillRect( 0, 0, renderBox.width + 40, renderBox.height + 40 );
ctx.drawImage( img, -renderBox.x + 20, -renderBox.y + 20 );
DOMURL.revokeObjectURL( url );
var type = 'png';
var imgData = canvas[ 0 ].toDataURL( type );
var _fixType = function ( type ) {
type = type.toLowerCase().replace( /jpg/i, 'jpeg' );
var r = type.match( /png|jpeg|bmp|gif/ )[ 0 ];
return 'image/' + r;
};
imgData = imgData.replace( _fixType( type ), 'image/octet-stream' );
var saveFile = function ( data, filename ) {
var save_link = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'a' );
save_link.href = data;
save_link.download = filename;
var event = document.createEvent( 'MouseEvents' );
event.initMouseEvent( 'click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null );
save_link.dispatchEvent( event );
};
// 下载后的文件名
var filename = 'kityminder_' + ( new Date() ).getTime() + '.' + type;
// download
saveFile( imgData, filename );
renderContainer.setTransform( transform );
};
};
img.src = url;
return "png";
} else if ( res.value === "svg" ) {
var svghtml = $( "#kityminder .kmui-editor-body" ).html();
var saveFile = function ( data, filename ) {
var save_link = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'a' );
save_link.href = 'data:image/svg+xml; utf-8,' + encodeURI( svghtml );
save_link.download = filename;
var event = document.createEvent( 'MouseEvents' );
event.initMouseEvent( 'click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null );
save_link.dispatchEvent( event );
};
var filename = 'kityminder_' + ( new Date() ).getTime() + '.svg';
saveFile( svg, filename );
return "svg";
}
var data = me.exportData( res.value );
var p = KityMinder.findProtocal( res.value );
var a = downloadLink;
a.setAttribute( 'download', 'MyMind' + p.fileExtension );
a.setAttribute( 'href', 'data:text/plain; utf-8,' + encodeURI( data ) );
a.dispatchEvent( new MouseEvent( 'click' ) );
} ).on( "beforeshow", function () {
if ( $combox.parent().length === 0 ) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) );
}
} ).on( 'aftercomboboxselect', function () {
this.setLabelWithDefaultValue();
} );
return comboboxWidget.button().addClass( 'kmui-combobox' );
} );
\ No newline at end of file
KM.registerUI( 'tooltips',
function ( name ) {
var km = this;
//添加tooltip;
if($.kmuitooltip){
$("[data-original-title]",km.$container).each(function(i,n){
var tooltips = km.getLang('tooltips');
var tooltip = $(n).data('original-title');
utils.each(tooltips,function(v,k){
if(k == tooltip && km.getShortcutKey(v)){
$(n).attr('data-original-title',tooltip + ' (' + km.getShortcutKey(v).toUpperCase() + ')');
}
})
});
$.kmuitooltip('attachTo', $("[data-original-title]",km.$container)).css('z-index',km.getOptions('zIndex')+1);
}
km.$container.find('a').click(function(evt){
evt.preventDefault()
});
}
);
\ No newline at end of file
/**
* 宽度自适应工具函数
* @param word 单词内容
* @param hasSuffix 是否含有后缀
*/
$.wordCountAdaptive = function( word, hasSuffix ) {
var $tmpNode = $('<span>' ).html( word ).css( {
display: 'inline',
position: 'absolute',
top: -10000000,
left: -100000
} ).appendTo( document.body),
width = $tmpNode.width();
$tmpNode.remove();
$tmpNode = null;
if( width < 50 ) {
return word;
} else {
word = word.slice( 0, hasSuffix ? -4 : -1 );
if( !word.length ) {
return '...';
}
return $.wordCountAdaptive( word + '...', true );
}
};
\ No newline at end of file
KM.registerToolbarUI( 'hand zoom-in zoom-out',
function ( name ) {
var me = this;
var $btn = $.kmuibutton( {
icon: name,
click: function () {
me.execCommand( name );
},
title: this.getLang( 'tooltips.' )[ name ] || ''
} );
me.on('interactchange', function() {
var state = me.queryCommandState( name );
$btn.kmui().disabled( state == -1 ).active( state == 1 );
});
return $btn;
}
);
\ No newline at end of file
var Command = kity.createClass( "Command", {
constructor: function () {
this._isContentChange = true;
this._isSelectionChange = false;
},
execute: function ( minder, args ) {
},
setContentChanged: function ( val ) {
this._isContentChange = !! val;
},
isContentChanged: function () {
return this._isContentChange;
},
setSelectionChanged: function ( val ) {
this._isSelectionChange = !! val;
},
isSelectionChanged: function () {
return this._isContentChange;
},
queryState: function ( km ) {
return 0;
},
queryValue: function ( km ) {
return 0;
},
isNeedUndo: function () {
return true;
}
} );
\ No newline at end of file
var MinderEvent = kity.createClass( 'MindEvent', {
constructor: function ( type, params, canstop ) {
params = params || {};
if ( params.getType && params.getType() == 'ShapeEvent' ) {
this.kityEvent = params;
this.originEvent = params.originEvent;
this.getPosition = params.getPosition.bind( params );
} else if ( params.target && params.preventDefault ) {
this.originEvent = params;
} else {
kity.Utils.extend( this, params );
}
this.type = type;
this._canstop = canstop || false;
},
getTargetNode: function () {
var findShape = this.kityEvent && this.kityEvent.targetShape;
if ( !findShape ) return null;
while ( !findShape.minderNode && findShape.container ) {
findShape = findShape.container;
}
return findShape.minderNode || null;
},
stopPropagation: function () {
this._stoped = true;
},
stopPropagationImmediately: function () {
this._immediatelyStoped = true;
this._stoped = true;
},
shouldStopPropagation: function () {
return this._canstop && this._stoped;
},
shouldStopPropagationImmediately: function () {
return this._canstop && this._immediatelyStoped;
},
preventDefault:function(){
this.originEvent.preventDefault();
}
} );
\ No newline at end of file
var keymap = KityMinder.keymap = {
'Backspace' : 8,
'Tab' : 9,
'Enter' : 13,
'Shift':16,
'Control':17,
'Alt':18,
'CapsLock':20,
'Esc':27,
'Spacebar':32,
'PageUp':33,
'PageDown':34,
'End':35,
'Home':36,
'Left':37,
'Up':38,
'Right':39,
'Down':40,
'Insert':45,
'Del':46,
'NumLock':144,
'Cmd':91,
'=':187,
'-':189,
"b":66,
'i':73,
'z':90,
'y':89
};
\ No newline at end of file
var KityMinder = window.KM = window.KityMinder = function () {
var instanceMap = {}, instanceId = 0;
return {
version: '1.0.0',
createMinder: function ( renderTarget, options ) {
options = options || {};
options.renderTo = Utils.isString( renderTarget ) ? document.getElementById( renderTarget ) : renderTarget;
var minder = new Minder( options );
this.addMinder( options.renderTo, minder );
return minder;
},
addMinder: function ( target, minder ) {
var id;
if ( typeof ( target ) === 'string' ) {
id = target;
} else {
id = target.id || ( "KM_INSTANCE_" + instanceId++ );
}
instanceMap[ id ] = minder;
},
getMinder: function ( target, options ) {
var id;
if ( typeof ( target ) === 'string' ) {
id = target;
} else {
id = target.id || ( "KM_INSTANCE_" + instanceId++ );
}
return instanceMap[ id ] || this.createMinder( target, options );
},
//挂接多语言
LANG: {}
};
}();
\ No newline at end of file
kity.extendClass( Minder, {
_getCommand: function ( name ) {
return this._commands[ name.toLowerCase() ];
},
_queryCommand: function ( name, type, args ) {
var cmd = this._getCommand( name );
if ( cmd ) {
var queryCmd = cmd[ 'query' + type ];
if ( queryCmd )
return queryCmd.apply( cmd, [ this ].concat( args ) );
}
return 0;
},
queryCommandState: function ( name ) {
return this._queryCommand( name, "State", Utils.argsToArray( 1 ) );
},
queryCommandValue: function ( name ) {
return this._queryCommand( name, "Value", Utils.argsToArray( 1 ) );
},
execCommand: function ( name ) {
name = name.toLowerCase();
var cmdArgs = Utils.argsToArray( arguments, 1 ),
cmd, stoped, result, eventParams;
var me = this;
cmd = this._getCommand( name );
eventParams = {
command: cmd,
commandName: name.toLowerCase(),
commandArgs: cmdArgs
};
if ( !cmd ) {
return false;
}
if ( !this._hasEnterExecCommand && cmd.isNeedUndo() ) {
this._hasEnterExecCommand = true;
stoped = this._fire( new MinderEvent( 'beforeExecCommand', eventParams, true ) );
if ( !stoped ) {
//保存场景
this._fire( new MinderEvent( 'saveScene' ) );
this._fire( new MinderEvent( "preExecCommand", eventParams, false ) );
result = cmd.execute.apply( cmd, [ me ].concat( cmdArgs ) );
this._fire( new MinderEvent( 'execCommand', eventParams, false ) );
//保存场景
this._fire( new MinderEvent( 'saveScene' ) );
if ( cmd.isContentChanged() ) {
this._firePharse( new MinderEvent( 'contentchange' ) );
}
if ( cmd.isSelectionChanged() ) {
this._firePharse( new MinderEvent( 'selectionchange' ) );
}
this._firePharse( new MinderEvent( 'interactchange' ) );
}
this._hasEnterExecCommand = false;
} else {
result = cmd.execute.apply( cmd, [ me ].concat( cmdArgs ) );
}
return result === undefined ? null : result;
}
} );
\ No newline at end of file
Utils.extend( KityMinder, {
_protocals: {},
registerProtocal: function ( name, protocalDeal ) {
KityMinder._protocals[ name ] = protocalDeal();
},
findProtocal: function ( name ) {
return KityMinder._protocals[ name ] || null;
},
getSupportedProtocals: function () {
return Utils.keys( KityMinder._protocals ).sort(function(a, b) {
return KityMinder._protocals[b].recognizePriority - KityMinder._protocals[a].recognizePriority;
});
},
getAllRegisteredProtocals: function () {
return KityMinder._protocals;
}
} );
// 这里的 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;
}
function importNode( node, json ) {
var data = json.data;
for ( var field in data ) {
node.setData( field, data[ field ] );
}
node.setText( data.text );
var childrenTreeData = json.children;
if ( !childrenTreeData ) return;
for ( var i = 0; i < childrenTreeData.length; i++ ) {
var childNode = new MinderNode();
importNode( childNode, childrenTreeData[ i ] );
node.appendChild( childNode );
}
return node;
}
// 导入导出
kity.extendClass( Minder, {
exportData: function ( protocalName ) {
var json, protocal;
json = exportNode( this.getRoot() );
protocal = KityMinder.findProtocal( protocalName );
if ( protocal ) {
return protocal.encode( json );
} else {
return json;
}
},
importData: function ( local, protocalName ) {
var json, protocal;
if ( protocalName ) {
protocal = KityMinder.findProtocal( protocalName );
} else {
KityMinder.getSupportedProtocals().every( function ( name ) {
var test = KityMinder.findProtocal( name );
if ( test.recognize && test.recognize( local ) ) {
protocal = test;
}
return !protocal;
} );
}
if ( !protocal ) {
throw new Error( "Unsupported protocal: " + protocalName );
}
var params = {
local: local,
protocalName: protocalName,
protocal: protocal
};
// 是否需要阻止导入
var stoped = this._fire( new MinderEvent( 'beforeimport', params, true ) );
if ( stoped ) return this;
json = params.json || ( params.json = protocal.decode( local ) );
this._fire( new MinderEvent( 'preimport', params, false ) );
// 删除当前所有节点
while ( this._root.getChildren().length ) {
this._root.removeChild( 0 );
}
importNode( this._root, json );
this._fire( new MinderEvent( 'import', params, false ) );
this._firePharse( {
type: 'contentchange'
} );
this._firePharse( {
type: 'interactchange'
} );
return this;
}
} );
\ No newline at end of file
//这里只放不是由模块产生的默认参数
KM.defaultOptions = {
zIndex : 1000,
lang:'zh-cn'
};
\ No newline at end of file
// 事件机制
kity.extendClass( Minder, {
_initEvents: function () {
this._eventCallbacks = {};
},
_bindEvents: function () {
this._bindPaperEvents();
this._bindKeyboardEvents();
},
_resetEvents: function () {
this._initEvents();
this._bindEvents();
},
// TODO: mousemove lazy bind
_bindPaperEvents: function () {
this._paper.on( 'click dblclick mousedown contextmenu mouseup mousemove mousewheel touchstart touchmove touchend', this._firePharse.bind( this ) );
if ( window ) {
window.addEventListener( 'resize', this._firePharse.bind( this ) );
}
},
_bindKeyboardEvents: function () {
if ( ( navigator.userAgent.indexOf( 'iPhone' ) == -1 ) && ( navigator.userAgent.indexOf( 'iPod' ) == -1 ) && ( navigator.userAgent.indexOf( 'iPad' ) == -1 ) ) {
//只能在这里做,要不无法触发
Utils.listen( document.body, 'keydown keyup keypress', this._firePharse.bind( this ) );
}
},
_firePharse: function ( e ) {
var beforeEvent, preEvent, executeEvent;
beforeEvent = new MinderEvent( 'before' + e.type, e, true );
if ( this._fire( beforeEvent ) ) {
return;
}
preEvent = new MinderEvent( 'pre' + e.type, e, false );
executeEvent = new MinderEvent( e.type, e, false );
this._fire( preEvent );
this._fire( executeEvent );
this._fire( new MinderEvent( 'after' + e.type, e, false ) );
if ( ~'mousedown mouseup keydown keyup'.indexOf( e.type ) ) {
this._interactChange( e );
}
},
_interactChange: function ( e ) {
var minder = this;
clearTimeout( this._interactTimeout );
this._interactTimeout = setTimeout( function () {
var stoped = minder._fire( new MinderEvent( 'beforeinteractchange' ) );
if ( stoped ) {
return;
}
minder._fire( new MinderEvent( 'preinteractchange' ) );
minder._fire( new MinderEvent( 'interactchange' ) );
}, 300 );
},
_listen: function ( type, callback ) {
var callbacks = this._eventCallbacks[ type ] || ( this._eventCallbacks[ type ] = [] );
callbacks.push( callback );
},
_fire: function ( e ) {
var callbacks = this._eventCallbacks[ e.type.toLowerCase() ];
if ( !callbacks ) {
return false;
}
for ( var i = 0; i < callbacks.length; i++ ) {
callbacks[ i ].call( this, e );
if ( e.shouldStopPropagationImmediately() ) {
break;
}
}
return e.shouldStopPropagation();
},
on: function ( name, callback ) {
var types = name.split( ' ' );
for ( var i = 0; i < types.length; i++ ) {
this._listen( types[ i ].toLowerCase(), callback );
}
return this;
},
off: function ( name, callback ) {
var types = name.split( ' ' );
var i, j, callbacks, removeIndex;
for ( i = 0; i < types.length; i++ ) {
callbacks = this._eventCallbacks[ types[ i ].toLowerCase() ];
if ( callbacks ) {
removeIndex = null;
for ( j = 0; j < callbacks.length; j++ ) {
if ( callbacks[ j ] == callback ) {
removeIndex = j;
}
}
if ( removeIndex !== null ) {
callbacks.splice( removeIndex, 1 );
}
}
}
},
fire: function ( type, params ) {
var e = new MinderEvent( type, params );
this._fire( e );
return this;
}
} );
\ No newline at end of file
var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
constructor: function ( options ) {
this._options = Utils.extend( window.KITYMINDER_CONFIG || {}, options );
this.setDefaultOptions( KM.defaultOptions );
this._initEvents();
this._initMinder();
this._initSelection();
this._initShortcutKey();
this._initContextmenu();
this._initModules();
this.fire( 'ready' );
},
getOptions: function ( key ) {
return this._options[ key ];
},
setDefaultOptions: function ( key, val ) {
var obj = {};
if ( Utils.isString( key ) ) {
obj[ key ] = val;
} else {
obj = key;
}
utils.extend( this._options, obj, true );
},
_initMinder: function () {
this._paper = new kity.Paper();
this._paper.getNode().setAttribute( 'contenteditable', true );
this._paper.getNode().ondragstart = function(e) {
e.preventDefault();
};
this._addRenderContainer();
this._root = new MinderNode( this.getLang().maintopic );
this._root.setType( "root" );
if ( this._options.renderTo ) {
this.renderTo( this._options.renderTo );
}
},
_addRenderContainer: function () {
this._rc = new kity.Group();
this._paper.addShape( this._rc );
},
renderTo: function ( target ) {
this._paper.renderTo( this._renderTarget = target );
this._bindEvents();
},
getRenderContainer: function () {
return this._rc;
},
getPaper: function () {
return this._paper;
},
getRenderTarget: function () {
return this._renderTarget;
},
_initShortcutKey: function () {
this._shortcutkeys = {};
this._bindshortcutKeys();
},
isTextEditStatus:function(){
return false;
},
addShortcutKeys: function ( cmd, keys ) {
var obj = {},km = this;
if ( keys ) {
obj[ cmd ] = keys
} else {
obj = cmd;
}
utils.each(obj,function(k,v){
km._shortcutkeys[k.toLowerCase()] = v;
});
},
getShortcutKey : function(cmdName){
return this._shortcutkeys[cmdName]
},
_bindshortcutKeys: function () {
var me = this,
shortcutkeys = this._shortcutkeys;
function checkkey(key,keyCode,e){
switch(key){
case 'ctrl':
case 'cmd':
if(e.ctrlKey || e.metaKey){
return true;
}
break;
case 'alt':
if(e.altKey){
return true
}
break;
case 'shift':
if(e.shiftKey){
return true;
}
}
if(keyCode == keymap[key]){
return true;
}
return false
}
me.on( 'keydown', function ( e ) {
var originEvent = e.originEvent;
var keyCode = originEvent.keyCode || originEvent.which;
for ( var i in shortcutkeys ) {
var keys = shortcutkeys[ i ].toLowerCase().split('+');
var current = 0;
utils.each(keys,function(i,k){
if(checkkey(k,keyCode,originEvent)){
current++;
}
});
//todo 暂时通过receiver判断
if(me.isTextEditStatus()){
return;
}
if(current == keys.length){
if ( me.queryCommandState( i ) != -1 )
me.execCommand( i );
originEvent.preventDefault();
break;
}
}
} );
},
_initContextmenu:function(){
this.contextmenus = [];
},
addContextmenu:function(item){
if(utils.isArray(item)){
this.contextmenus = this.contextmenus.concat(item);
}else{
this.contextmenus.push(item);
}
return this;
},
getContextmenu:function(){
return this.contextmenus;
}
} );
/**
* @include <minder.data.js>
* @include <minder.event.js>
* @include <minder.module.js>
* @include <minder.node.js>
* @include <minder.select.js>
*/
\ No newline at end of file
//添加多语言模块
kity.extendClass( Minder, {
getLang: function ( path ) {
var lang = KM.LANG[ this.getOptions( 'lang' ) ];
if ( !lang ) {
throw Error( "not import language file" );
}
path = ( path || "" ).split( "." );
for ( var i = 0, ci; ci = path[ i++ ]; ) {
lang = lang[ ci ];
if ( !lang ) break;
}
return lang;
}
} );
\ No newline at end of file
// 模块声明周期维护
kity.extendClass( Minder, {
_initModules: function () {
var modulesPool = KityMinder.getModules();
var modulesToLoad = this._options.modules || Utils.keys( modulesPool );
this._commands = {};
this._query = {};
this._modules = {};
var i, name, module, moduleDeals, dealCommands, dealEvents;
var me = this;
for ( i = 0; i < modulesToLoad.length; i++ ) {
name = modulesToLoad[ i ];
if ( !modulesPool[ name ] ) continue;
//执行模块初始化,抛出后续处理对象
moduleDeals = modulesPool[ name ].call( me );
this._modules[ name ] = moduleDeals;
if ( moduleDeals.init ) {
moduleDeals.init.call( me, this._options );
}
//command加入命令池子
dealCommands = moduleDeals.commands;
for ( var name in dealCommands ) {
this._commands[ name.toLowerCase() ] = new dealCommands[ name ];
}
//绑定事件
dealEvents = moduleDeals.events;
if ( dealEvents ) {
for ( var type in dealEvents ) {
me.on( type, dealEvents[ type ] );
}
}
if ( moduleDeals.defaultOptions ) {
this.setDefaultOptions( moduleDeals.defaultOptions );
}
//添加模块的快捷键
if ( moduleDeals.addShortcutKeys ) {
this.addShortcutKeys( moduleDeals.addShortcutKeys )
}
//添加邮件菜单
if(moduleDeals.contextmenu){
this.addContextmenu(moduleDeals.contextmenu)
}
}
},
_garbage: function () {
this.clearSelect();
while ( this._root.getChildren().length ) {
this._root.removeChild( 0 );
}
},
destroy: function () {
var modules = this._modules;
this._resetEvents();
this._garbage();
for ( var key in modules ) {
if ( !modules[ key ].destroy ) continue;
modules[ key ].destroy.call( this );
}
},
reset: function () {
var modules = this._modules;
this._garbage();
for ( var key in modules ) {
if ( !modules[ key ].reset ) continue;
modules[ key ].reset.call( this );
}
}
} );
\ No newline at end of file
kity.extendClass( Minder, {
getRoot: function () {
return this._root;
},
setRoot: function ( root ) {
this._root = root;
},
handelNodeInsert: function ( node ) {
var rc = this._rc;
node.traverse( function ( current ) {
rc.addShape( current.getRenderContainer() );
} );
},
handelNodeRemove: function ( node ) {
var rc = this._rc;
node.traverse( function ( current ) {
rc.removeShape( current.getRenderContainer() );
} );
},
renderNodes: function ( nodes ) {
var km = this;
if ( nodes instanceof Array ) {
if ( nodes.length === 0 ) return false;
for ( var i = 0; i < nodes.length; i++ ) {
km.renderNode( nodes[ i ] );
}
} else {
km.renderNode( nodes );
}
},
getMinderTitle: function() {
return this.getRoot().getText();
}
} );
\ No newline at end of file
// 选区管理
kity.extendClass( Minder, function () {
function highlightNode( km, node ) {
node.setTmpData( "highlight", true );
km.highlightNode( node );
}
function unhighlightNode( km, node ) {
node.setTmpData( "highlight", false );
km.highlightNode( node );
}
return {
_initSelection: function () {
this._selectedNodes = [];
},
getSelectedNodes: function () {
//不能克隆返回,会对当前选区操作,从而影响querycommand
return this._selectedNodes;
},
getSelectedNode: function () {
return this.getSelectedNodes()[ 0 ] || null;
},
removeAllSelectedNodes: function () {
var me = this;
Utils.each( this.getSelectedNodes(), function ( i, n ) {
unhighlightNode( me, n );
} );
this._selectedNodes = [];
return this.fire( 'selectionclear' );
},
removeSelectedNodes: function ( nodes ) {
var me = this;
Utils.each( Utils.isArray( nodes ) ? nodes : [ nodes ], function ( i, n ) {
var index;
if ( ( index = me._selectedNodes.indexOf( n ) ) === -1 ) return;
me._selectedNodes.splice( index, 1 );
unhighlightNode( me, n );
} );
return this;
},
select: function ( nodes, isToggleSelect ) {
if ( isToggleSelect ) {
this.removeAllSelectedNodes();
}
var me = this;
Utils.each( Utils.isArray( nodes ) ? nodes : [ nodes ], function ( i, n ) {
if ( me._selectedNodes.indexOf( n ) !== -1 ) return;
me._selectedNodes.push( n );
highlightNode( me, n );
} );
return this;
},
isNodeSelected: function ( node ) {
return node.getTmpData( 'highlight' ) === true;
},
//当前选区中的节点在给定的节点范围内的保留选中状态,
//没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果
toggleSelect: function ( node ) {
if ( Utils.isArray( node ) ) {
node.forEach( this.toggleSelect.bind( this ) );
} else {
if ( node.isSelected() ) this.removeSelectedNodes( node );
else this.select( node );
}
return this;
},
isSingleSelect: function () {
return this._selectedNodes.length == 1;
},
getSelectedAncestors: function() {
var nodes = this.getSelectedNodes().slice( 0 ),
ancestors = [],
judge;
// 根节点不参与计算
var rootIndex = nodes.indexOf( this.getRoot() );
if ( ~rootIndex ) {
nodes.splice( rootIndex, 1 );
}
// 判断 nodes 列表中是否存在 judge 的祖先
function hasAncestor( nodes, judge ) {
for ( var i = nodes.length - 1; i >= 0; --i ) {
if ( nodes[ i ].isAncestorOf( judge ) ) return true;
}
return false;
}
// 按照拓扑排序
nodes.sort( function ( node1, node2 ) {
return node1.getLevel() - node2.getLevel();
} );
// 因为是拓扑有序的,所以只需往上查找
while ( ( judge = nodes.pop() ) ) {
if ( !hasAncestor( nodes, judge ) ) {
ancestors.push( judge );
}
}
return ancestors;
}
};
}() );
\ No newline at end of file
//模块注册&暴露模块接口
( function () {
var _modules;
KityMinder.registerModule = function ( name, module ) {
//初始化模块列表
if ( !_modules ) {
_modules = {};
}
_modules[ name ] = module;
};
KityMinder.getModules = function () {
return _modules;
};
} )();
\ No newline at end of file
var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
constructor: function ( options ) {
this.parent = null;
this.children = [];
this.data = {};
this.tmpData = {};
if ( Utils.isString( options ) ) {
this.setData( 'text', options );
} else {
this.setData( options );
}
this._createShapeDom();
this.setData( "layout", {} );
},
_createShapeDom: function () {
this.rc = new kity.Group();
this.rc.addClass( 'km-minderNode' );
this.rc.minderNode = this;
this._createBgGroup();
this._createContGroup();
this._createIconShape();
this._createTextShape();
},
_createGroup: function ( type ) {
var g = new kity.Group();
g.setData( 'rctype', type );
this.rc.appendShape( g );
},
_createBgGroup: function () {
this._createGroup( 'bgrc' );
},
_createContGroup: function () {
this._createGroup( 'contrc' );
},
_createTextShape: function () {
var textShape = new kity.Text( this.getData( 'text' ) || '' );
textShape.setAttr( '_nodeTextShape', true );
this.getContRc().appendShape( textShape );
},
_createIconShape: function () {
var g = new kity.Group();
this.getContRc().appendShape( g );
this._iconRc = g;
},
getContRc: function () {
var groups = this.rc.getShapesByType( 'group' ),
result;
Utils.each( groups, function ( i, p ) {
if ( p.getData( 'rctype' ) == 'contrc' ) {
result = p;
return false;
}
} );
return result;
},
getBgRc: function () {
var groups = this.rc.getShapesByType( 'group' ),
result;
Utils.each( groups, function ( i, p ) {
if ( p.getData( 'rctype' ) == 'bgrc' ) {
result = p;
return false;
}
} );
return result;
},
getIconRc: function () {
return this._iconRc;
},
setPoint: function ( x, y ) {
if ( arguments.length < 2 ) {
this.setData( "point", x );
} else {
this.setData( 'point', {
x: x,
y: y
} );
}
},
getPoint: function () {
return this.getData( 'point' );
},
setType: function ( type ) {
this.setData( 'type', type );
},
getLevel: function () {
var level = 0,
parent = this.parent;
while ( parent ) {
level++;
parent = parent.parent;
}
return level;
},
getType: function ( type ) {
var cached = this.getData( 'type' );
if ( cached ) {
return cached;
}
var level = Math.min( this.getLevel(), 2 );
cached = [ 'root', 'main', 'sub' ][ level ];
this.setData( 'type', cached );
return cached;
},
setText: function ( text ) {
this.setData( 'text', text );
this.getTextShape().setContent( text );
},
getText: function () {
return this.getData( 'text' );
},
isRoot: function () {
return this.getParent() === null ? true : false;
},
getParent: function () {
return this.parent;
},
getDepth: function () {
var depth = 0,
p = this.parent;
while ( p ) {
p = p.parent;
depth++;
}
return depth;
},
getRoot: function () {
var root = this;
while ( root.parent ) {
root = root.parent;
}
return root;
},
isAncestorOf: function ( test ) {
var p = test.parent;
while ( p ) {
if ( p == this ) return true;
p = p.parent;
}
return false;
},
preTraverse: function ( fn ) {
var children = this.getChildren();
fn( this );
for ( var i = 0; i < children.length; i++ ) {
children[ i ].preTraverse( fn );
}
},
postTraverse: function ( fn ) {
var children = this.getChildren();
for ( var i = 0; i < children.length; i++ ) {
children[ i ].postTraverse( fn );
}
fn( this );
},
traverse: function ( fn ) {
return this.postTraverse( fn );
},
getChildren: function () {
return this.children;
},
getIndex: function () {
return this.parent ? this.parent.children.indexOf( this ) : -1;
},
insertChild: function ( node, index ) {
if ( index === undefined ) {
index = this.children.length;
}
if ( node.parent ) {
node.parent.removeChild( node );
}
node.parent = this;
node.root = parent.root;
this.children.splice( index, 0, node );
},
appendChild: function ( node ) {
return this.insertChild( node );
},
prependChild: function ( node ) {
return this.insertChild( node, 0 );
},
removeChild: function ( elem ) {
var index = elem,
removed;
if ( elem instanceof MinderNode ) {
index = this.children.indexOf( elem );
}
if ( index >= 0 ) {
removed = this.children.splice( index, 1 )[ 0 ];
removed.parent = null;
// this.handelRemove( removed );
}
},
// handelRemove: function ( node ) {
// var root = this.getRoot();
// if ( root.tnh ) {
// root.tnh.handelNodeRemove.call( root.tnh, node );
// }
// },
getChild: function ( index ) {
return this.children[ index ];
},
getFirstChild: function () {
return this.children[ 0 ];
},
getLastChild: function () {
return this.children[ this.children.length - 1 ];
},
getData: function ( name ) {
if ( name === undefined ) {
return this.data;
}
return this.data[ name ];
},
setData: function ( name, value ) {
if ( name === undefined ) {
this.data = {};
} else if ( utils.isObject( name ) ) {
Utils.extend( this.data, name );
} else {
if ( value === undefined ) {
this.data[ name ] = null;
delete this.data[ name ];
} else {
this.data[ name ] = value;
}
}
},
getRenderContainer: function () {
return this.rc;
},
getCommonAncestor: function ( node ) {
return Utils.getNodeCommonAncestor( this, node );
},
contains: function ( node ) {
if ( this === node ) {
return true;
}
if ( this === node.parent ) {
return true;
}
var isContain = false;
Utils.each( this.getChildren(), function ( i, n ) {
isContain = n.contains( node );
if ( isContain === true ) {
return false;
}
} );
return isContain;
},
clone: function () {
function cloneNode( parent, isClonedNode ) {
var _tmp = new KM.MinderNode( isClonedNode.getText() );
_tmp.data = Utils.clonePlainObject( isClonedNode.getData() );
_tmp.tmpData = Utils.clonePlainObject( isClonedNode.getTmpData() )
_tmp.parent = parent;
if ( parent ) {
parent.children.push( _tmp );
}
for ( var i = 0, ci;
( ci = isClonedNode.children[ i++ ] ); ) {
cloneNode( _tmp, ci );
}
return _tmp;
}
return function () {
return cloneNode( null, this );
};
}(),
equals: function ( node ) {
if ( node.children.length != this.children.length ) {
return false;
}
if ( utils.compareObject( node.getData(), this.getData() ) === false ) {
return false;
}
if ( utils.compareObject( node.getTmpData(), this.getTmpData() ) === false ) {
return false;
}
for ( var i = 0, ci;
( ci = this.children[ i ] ); i++ ) {
if ( ci.equals( node.children[ i ] ) === false ) {
return false;
}
}
return true;
},
getTextShape: function () {
var textShape;
utils.each( this.getContRc().getShapesByType( 'text' ), function ( i, t ) {
if ( t.getAttr( '_nodeTextShape' ) ) {
textShape = t;
return false;
}
} );
return textShape;
},
isSelected: function () {
return this.getTmpData( 'highlight' ) === true;
},
clearChildren: function () {
this.children = [];
},
isHighlight: function () {
return this.getTmpData( 'highlight' )
},
setTmpData: function ( a, v ) {
var me = this;
if ( utils.isObject( a ) ) {
utils.each( a, function ( val, key ) {
me.setTmpData( key, val )
} )
}
if ( v === undefined || v === null || v === '' ) {
delete this.tmpData[ a ];
} else {
this.tmpData[ a ] = v;
}
},
getTmpData: function ( a ) {
if ( a === undefined ) {
return this.tmpData;
}
return this.tmpData[ a ]
}
} );
\ No newline at end of file
var utils = Utils = KityMinder.Utils = {
extend: kity.Utils.extend.bind( kity.Utils ),
listen: function ( element, type, handler ) {
var types = utils.isArray( type ) ? type : utils.trim( type ).split( /\s+/ ),
k = types.length;
if ( k )
while ( k-- ) {
type = types[ k ];
if ( element.addEventListener ) {
element.addEventListener( type, handler, false );
} else {
if ( !handler._d ) {
handler._d = {
els: []
};
}
var key = type + handler.toString(),
index = utils.indexOf( handler._d.els, element );
if ( !handler._d[ key ] || index == -1 ) {
if ( index == -1 ) {
handler._d.els.push( element );
}
if ( !handler._d[ key ] ) {
handler._d[ key ] = function ( evt ) {
return handler.call( evt.srcElement, evt || window.event );
};
}
element.attachEvent( 'on' + type, handler._d[ key ] );
}
}
}
element = null;
},
trim: function ( str ) {
return str.replace( /(^[ \t\n\r]+)|([ \t\n\r]+$)/g, '' );
},
each: function ( obj, iterator, context ) {
if ( obj == null ) return;
if ( obj.length === +obj.length ) {
for ( var i = 0, l = obj.length; i < l; i++ ) {
if ( iterator.call( context, i, obj[ i ], obj ) === false )
return false;
}
} else {
for ( var key in obj ) {
if ( obj.hasOwnProperty( key ) ) {
if ( iterator.call( context, key, obj[ key ], obj ) === false )
return false;
}
}
}
},
addCssRule: function ( key, style, doc ) {
var head, node;
if ( style === undefined || style && style.nodeType && style.nodeType == 9 ) {
//获取样式
doc = style && style.nodeType && style.nodeType == 9 ? style : ( doc || document );
node = doc.getElementById( key );
return node ? node.innerHTML : undefined;
}
doc = doc || document;
node = doc.getElementById( key );
//清除样式
if ( style === '' ) {
if ( node ) {
node.parentNode.removeChild( node );
return true
}
return false;
}
//添加样式
if ( node ) {
node.innerHTML = style;
} else {
node = doc.createElement( 'style' );
node.id = key;
node.innerHTML = style;
doc.getElementsByTagName( 'head' )[ 0 ].appendChild( node );
}
},
keys: function ( plain ) {
var keys = [];
for ( var key in plain ) {
if ( plain.hasOwnProperty( key ) ) {
keys.push( key );
}
}
return keys;
},
proxy: function ( fn, context ) {
return function () {
return fn.apply( context, arguments );
};
},
indexOf: function ( array, item, start ) {
var index = -1;
start = this.isNumber( start ) ? start : 0;
this.each( array, function ( v, i ) {
if ( i >= start && v === item ) {
index = i;
return false;
}
} );
return index;
},
argsToArray: function ( args,index ) {
return Array.prototype.slice.call( args, index || 0 );
},
clonePlainObject:function (source, target) {
var tmp;
target = target || {};
for (var i in source) {
if (source.hasOwnProperty(i)) {
tmp = source[i];
if (utils.isObject(tmp) || utils.isArray(tmp)) {
target[i] = utils.isArray(tmp) ? [] : {};
utils.clonePlainObject(source[i], target[i])
} else {
target[i] = tmp;
}
}
}
return target;
},
compareObject:function(source,target){
var tmp;
if(this.isEmptyObject(source) !== this.isEmptyObject(target)){
return false
}
if(this.getObjectLength(source) != this.getObjectLength(target)){
return false;
}
for(var p in source){
if(source.hasOwnProperty(p)){
tmp = source[p];
if(target[p] === undefined){
return false;
}
if (this.isObject(tmp) || this.isArray(tmp)) {
if(this.isObject(target[p]) !== this.isObject(tmp)){
return false;
}
if(this.isArray(tmp) !== this.isArray(target[p])){
return false;
}
if(this.compareObject(tmp, target[p]) === false){
return false
}
} else {
if(tmp != target[p]){
return false
}
}
}
}
return true;
},
getObjectLength:function(obj){
if (this.isArray(obj) || this.isString(obj)) return obj.length;
var count = 0;
for (var key in obj) if (obj.hasOwnProperty(key)) count++;
return count;
},
isEmptyObject:function (obj) {
if (obj == null) return true;
if (this.isArray(obj) || this.isString(obj)) return obj.length === 0;
for (var key in obj) if (obj.hasOwnProperty(key)) return false;
return true;
},
getNodeCommonAncestor : function(nodeA,nodeB){
if ( nodeA === nodeB ) {
return nodeA.parent
}
if ( nodeA.contains( nodeB ) ) {
return this
}
if ( nodeB.contains( nodeA ) ) {
return nodeB
}
var parent = nodeA.parent;
while ( !parent.contains( nodeB ) ) {
parent = parent.parent;
}
return parent;
},
loadFile:function () {
var tmpList = [];
function getItem(doc, obj) {
try {
for (var i = 0, ci; ci = tmpList[i++];) {
if (ci.doc === doc && ci.url == (obj.src || obj.href)) {
return ci;
}
}
} catch (e) {
return null;
}
}
return function (doc, obj, fn) {
var item = getItem(doc, obj);
if (item) {
if (item.ready) {
fn && fn();
} else {
item.funs.push(fn)
}
return;
}
tmpList.push({
doc:doc,
url:obj.src || obj.href,
funs:[fn]
});
if (!doc.body) {
var html = [];
for (var p in obj) {
if (p == 'tag')continue;
html.push(p + '="' + obj[p] + '"')
}
doc.write('<' + obj.tag + ' ' + html.join(' ') + ' ></' + obj.tag + '>');
return;
}
if (obj.id && doc.getElementById(obj.id)) {
return;
}
var element = doc.createElement(obj.tag);
delete obj.tag;
for (var p in obj) {
element.setAttribute(p, obj[p]);
}
element.onload = element.onreadystatechange = function () {
if (!this.readyState || /loaded|complete/.test(this.readyState)) {
item = getItem(doc, obj);
if (item.funs.length > 0) {
item.ready = 1;
for (var fi; fi = item.funs.pop();) {
fi();
}
}
element.onload = element.onreadystatechange = null;
}
};
element.onerror = function () {
throw Error('The load ' + (obj.href || obj.src) + ' fails,check the url settings of file umeditor.config.js ')
};
doc.getElementsByTagName("head")[0].appendChild(element);
}
}(),
clone:function (source, target) {
var tmp;
target = target || {};
for (var i in source) {
if (source.hasOwnProperty(i)) {
tmp = source[i];
if (typeof tmp == 'object') {
target[i] = utils.isArray(tmp) ? [] : {};
utils.clone(source[i], target[i])
} else {
target[i] = tmp;
}
}
}
return target;
},
};
Utils.each( [ 'String', 'Function', 'Array', 'Number', 'RegExp', 'Object' ], function ( i, v ) {
KityMinder.Utils[ 'is' + v ] = function ( obj ) {
return Object.prototype.toString.apply( obj ) == '[object ' + v + ']';
}
} );
\ No newline at end of file
KityMinder.registerModule( "basestylemodule", function () {
var km = this;
return {
"commands": {
"bold": kity.createClass( "boldCommand", {
base: Command,
execute: function ( ) {
var nodes = km.getSelectedNodes();
if(this.queryState('bold') == 1){
utils.each(nodes,function(i,n){
n.setData('bold');
n.getTextShape().setAttr('font-weight');
km.updateLayout(n)
})
}else{
utils.each(nodes,function(i,n){
n.setData('bold',true);
n.getTextShape().setAttr('font-weight','bold');
km.updateLayout(n)
})
}
},
queryState: function ( ) {
var nodes = km.getSelectedNodes(),
result = 0;
if(nodes.length == 0){
return -1;
}
utils.each(nodes,function(i,n){
if(n.getData('bold')){
result = 1;
return false;
}
});
return result;
}
} ),
"italic": kity.createClass( "italicCommand", {
base: Command,
execute: function ( ) {
var nodes = km.getSelectedNodes();
if(this.queryState('italic') == 1){
utils.each(nodes,function(i,n){
n.setData('italic');
n.getTextShape().setAttr('font-style');
km.updateLayout(n)
})
}else{
utils.each(nodes,function(i,n){
n.setData('italic',true);
n.getTextShape().setAttr('font-style','italic');
km.updateLayout(n)
})
}
},
queryState: function ( ) {
var nodes = km.getSelectedNodes(),
result = 0;
if(nodes.length == 0){
return -1;
}
utils.each(nodes,function(i,n){
if(n.getData('italic')){
result = 1;
return false;
}
});
return result;
}
} )
},
addShortcutKeys: {
"bold": "ctrl+b", //bold
"italic": "ctrl+i" //italic
},
"events": {
"beforeRenderNode": function ( e ) {
//加粗
if(e.node.getData('bold')){
e.node.getTextShape().setAttr('font-weight','bold');
}
if(e.node.getData('italic')){
e.node.getTextShape().setAttr('font-style','italic');
}
}
}
};
} );
\ No newline at end of file
This diff is collapsed.
KityMinder.registerModule( "DropFile", function () {
function init() {
var container = this.getPaper().getContainer();
container.addEventListener( 'dragover', onDragOver );
container.addEventListener( 'drop', onDrop.bind( this ) );
}
function onDragOver( e ) {
e.preventDefault();
e.stopPropagation();
e.dataTransfer.dropEffect = 'copy';
}
function onDrop( e ) {
e.preventDefault();
e.stopPropagation();
var minder = this;
if ( e.dataTransfer.files ) {
var reader = new FileReader();
reader.onload = function ( e ) {
minder.importData( e.target.result );
};
reader.readAsText( e.dataTransfer.files[ 0 ] );
}
}
return {
events: {
ready: init
}
};
} );
\ No newline at end of file
This diff is collapsed.
Minder.Range = kity.createClass('Range',{
constructor : function(){
this.nativeRange = document.createRange();
this.nativeSel = window.getSelection();
},
select:function(){
var start = this.nativeRange.startContainer;
if(start.nodeType == 1 && start.childNodes.length == 0){
var char = document.createTextNode('\u200b');
start.appendChild(char);
this.nativeRange.setStart(char,1);
this.nativeRange.collapse(true);
}
this.nativeSel.removeAllRanges();
this.nativeSel.addRange(this.nativeRange);
return this;
},
setStart:function(node,index){
try{
this.nativeRange.setStart(node,index);
}catch(e){
console.log(e)
}
return this;
},
setEnd:function(node,index){
this.nativeRange.setEnd(node,index);
return this;
},
getStart:function(){
var range = this.nativeSel.getRangeAt(0);
return {
startContainer:range.startContainer,
startOffset:range.startOffset
}
},
collapse:function(toStart){
this.nativeRange.collapse(toStart === true);
return this;
},
insertNode:function(node){
this.nativeRange.insertNode(node);
return this;
}
});
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
KityMinder.registerModule( "pasteModule", function () {
var km = this;
//getSelectedTopNodes
return {
};
} );
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
KityMinder.registerProtocal( 'json', function () {
function filter( key, value ) {
if ( key == 'layout' || key == 'shicon' ) {
return undefined;
}
return value;
}
return {
fileDescription: 'KityMinder',
fileExtension: '.km',
encode: function ( json ) {
return JSON.stringify( json, filter );
},
decode: function ( local ) {
return JSON.parse( local );
},
recognize: function ( local ) {
return Utils.isString( local ) && local.charAt( 0 ) == '{' && local.charAt( local.length - 1 ) == '}';
},
recognizePriority: 0
};
} );
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
http://www.xmind.net/developer/
Parsing XMind file
XMind files are generated in XMind Workbook (.xmind) format, an open format that is based on the principles of OpenDocument. It consists of a ZIP compressed archive containing separate XML documents for content and styles, a .jpg image file for thumbnails, and directories for related attachments.
*/
KityMinder.registerProtocal( 'xmind', {
fileExtension: '.xmind',
} );
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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