Commit 104a05e7 authored by campaign's avatar campaign

Merge branch 'dev' of https://github.com/fex-team/kityminder into dev

parents 41ecad4f f44593c4
dialogs/markers/images/iconpriority.png

3.74 KB | W: | H:

dialogs/markers/images/iconpriority.png

4.44 KB | W: | H:

dialogs/markers/images/iconpriority.png
dialogs/markers/images/iconpriority.png
dialogs/markers/images/iconpriority.png
dialogs/markers/images/iconpriority.png
  • 2-up
  • Swipe
  • Onion skin
dialogs/markers/images/iconprogress.png

3.74 KB | W: | H:

dialogs/markers/images/iconprogress.png

5.06 KB | W: | H:

dialogs/markers/images/iconprogress.png
dialogs/markers/images/iconprogress.png
dialogs/markers/images/iconprogress.png
dialogs/markers/images/iconprogress.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -7,20 +7,39 @@ ...@@ -7,20 +7,39 @@
".kmui-dialog-<%= container %> .icon.p3{background-position: -40px 0}" + ".kmui-dialog-<%= container %> .icon.p3{background-position: -40px 0}" +
".kmui-dialog-<%= container %> .icon.p4{background-position: -60px 0}" + ".kmui-dialog-<%= container %> .icon.p4{background-position: -60px 0}" +
".kmui-dialog-<%= container %> .icon.p5{background-position: -80px 0}" + ".kmui-dialog-<%= container %> .icon.p5{background-position: -80px 0}" +
".kmui-dialog-<%= container %> .icon.p6{background-position: -100px 0}" +
".kmui-dialog-<%= container %> .icon.p7{background-position: -120px 0}" +
".kmui-dialog-<%= container %> .icon.p8{background-position: -140px 0}" +
".kmui-dialog-<%= container %> .icon.p9{background-position: -160px 0}" +
".kmui-dialog-<%= container %> .icon.p0{background-position: -180px 0}" +
".kmui-dialog-<%= container %> ul li{width:40%;display:inline-block}" +
".kmui-dialog-<%= container %> h4{padding:5px 10px; margin:0; background:#eee}" +
"</style>" + "</style>" +
"<h4><%= priority %></h3>" +
"<ul class='icon-list priority'>" + "<ul class='icon-list priority'>" +
"<li value='1' type='priority'><span class='icon p1'></span><span><%= priority %>1</span></li>" + "<li value='1' type='priority'><span class='icon p1'></span><span><%= priority %>1</span></li>" +
"<li value='2' type='priority'><span class='icon p2'></span><span><%= priority %>2</span></li>" + "<li value='2' type='priority'><span class='icon p2'></span><span><%= priority %>2</span></li>" +
"<li value='3' type='priority'><span class='icon p3'></span><span><%= priority %>3</span></li>" + "<li value='3' type='priority'><span class='icon p3'></span><span><%= priority %>3</span></li>" +
"<li value='4' type='priority'><span class='icon p4'></span><span><%= priority %>4</span></li>" + "<li value='4' type='priority'><span class='icon p4'></span><span><%= priority %>4</span></li>" +
"<li value='5' type='priority'><span class='icon p5'></span><span><%= priority %>5</span></li>" + "<li value='5' type='priority'><span class='icon p5'></span><span><%= priority %>5</span></li>" +
"<li value='6' type='priority'><span class='icon p6'></span><span><%= priority %>6</span></li>" +
"<li value='7' type='priority'><span class='icon p7'></span><span><%= priority %>7</span></li>" +
"<li value='8' type='priority'><span class='icon p8'></span><span><%= priority %>8</span></li>" +
"<li value='9' type='priority'><span class='icon p9'></span><span><%= priority %>9</span></li>" +
"<li value='0' type='priority'><span class='icon p0'></span><span><%= none %></span></li>" +
"</ul>" + "</ul>" +
"<h4><%= progress.title %></h4>" +
"<ul class='icon-list progress'>" + "<ul class='icon-list progress'>" +
"<li value='1' type='progress'><span class='icon p1'></span><span><%= progress.notdone %></span></li>" + "<li value='1' type='progress'><span class='icon p1'></span><span><%= progress.notdone %></span></li>" +
"<li value='2' type='progress'><span class='icon p2'></span><span><%= progress.quarterdone %></span></li>" + "<li value='2' type='progress'><span class='icon p2'></span><span><%= progress.done1 %></span></li>" +
"<li value='3' type='progress'><span class='icon p3'></span><span><%= progress.halfdone %></span></li>" + "<li value='3' type='progress'><span class='icon p3'></span><span><%= progress.done2 %></span></li>" +
"<li value='4' type='progress'><span class='icon p4'></span><span><%= progress.threequartersdone %></span></li>" + "<li value='4' type='progress'><span class='icon p4'></span><span><%= progress.done3 %></span></li>" +
"<li value='5' type='progress'><span class='icon p5'></span><span><%= progress.done %></span></li>" + "<li value='5' type='progress'><span class='icon p5'></span><span><%= progress.done4 %></span></li>" +
"<li value='6' type='progress'><span class='icon p6'></span><span><%= progress.done5 %></span></li>" +
"<li value='7' type='progress'><span class='icon p7'></span><span><%= progress.done6 %></span></li>" +
"<li value='8' type='progress'><span class='icon p8'></span><span><%= progress.done7 %></span></li>" +
"<li value='9' type='progress'><span class='icon p9'></span><span><%= progress.done %></span></li>" +
"<li value='0' type='progress'><span class='icon p0'></span><span><%= none %></span></li>" +
"</ul>", "</ul>",
initContent: function (km, $w) { initContent: function (km, $w) {
var lang = km.getLang('dialogs.markers'); var lang = km.getLang('dialogs.markers');
...@@ -30,8 +49,8 @@ ...@@ -30,8 +49,8 @@
}, lang)); }, lang));
} }
this.root().html(html); this.root().html(html);
var valPri = km.queryCommandValue("priority"); var valPri = km.queryCommandValue("priority") || 0;
var valPro = km.queryCommandValue("progress"); var valPro = km.queryCommandValue("progress") || 0;
$w.find("li[type='priority']").removeClass("active"); $w.find("li[type='priority']").removeClass("active");
$w.find("li[type='priority'][value='" + valPri + "']").addClass("active"); $w.find("li[type='priority'][value='" + valPri + "']").addClass("active");
$w.find("li[type='progress']").removeClass("active"); $w.find("li[type='progress']").removeClass("active");
...@@ -41,11 +60,7 @@ ...@@ -41,11 +60,7 @@
$w.on("click", "li", function () { $w.on("click", "li", function () {
var $this = $(this); var $this = $(this);
$this.siblings().removeClass("active"); $this.siblings().removeClass("active");
$this.toggleClass("active");
var val = $this.val(); var val = $this.val();
if (!$this.hasClass("active")) {
val = null;
}
var type = $this.attr("type"); var type = $this.attr("type");
km.execCommand(type, val); km.execCommand(type, val);
}); });
......
( function () { (function () {
function getKMBasePath( docUrl, confUrl ) { function getKMBasePath(docUrl, confUrl) {
return getBasePath( docUrl || self.document.URL || self.location.href, confUrl || getConfigFilePath() ); return getBasePath(docUrl || self.document.URL || self.location.href, confUrl || getConfigFilePath());
} }
function getConfigFilePath() { function getConfigFilePath() {
var configPath = document.getElementsByTagName( 'script' ); var configPath = document.getElementsByTagName('script');
return configPath[ configPath.length - 1 ].src; return configPath[configPath.length - 1].src;
} }
function getBasePath( docUrl, confUrl ) { function getBasePath(docUrl, confUrl) {
var basePath = confUrl; var basePath = confUrl;
if ( /^(\/|\\\\)/.test( confUrl ) ) { if (/^(\/|\\\\)/.test(confUrl)) {
basePath = /^.+?\w(\/|\\\\)/.exec( docUrl )[ 0 ] + confUrl.replace( /^(\/|\\\\)/, '' ); basePath = /^.+?\w(\/|\\\\)/.exec(docUrl)[0] + confUrl.replace(/^(\/|\\\\)/, '');
} else if ( !/^[a-z]+:/i.test( confUrl ) ) { } else if (!/^[a-z]+:/i.test(confUrl)) {
docUrl = docUrl.split( "#" )[ 0 ].split( "?" )[ 0 ].replace( /[^\\\/]+$/, '' ); docUrl = docUrl.split("#")[0].split("?")[0].replace(/[^\\\/]+$/, '');
basePath = docUrl + "" + confUrl; basePath = docUrl + "" + confUrl;
} }
return optimizationPath( basePath ); return optimizationPath(basePath);
} }
function optimizationPath( path ) { function optimizationPath(path) {
var protocol = /^[a-z]+:\/\//.exec( path )[ 0 ], var protocol = /^[a-z]+:\/\//.exec(path)[0],
tmp = null, tmp = null,
res = []; res = [];
path = path.replace( protocol, "" ).split( "?" )[ 0 ].split( "#" )[ 0 ]; path = path.replace(protocol, "").split("?")[0].split("#")[0];
path = path.replace( /\\/g, '/' ).split( /\// ); path = path.replace(/\\/g, '/').split(/\//);
path[ path.length - 1 ] = ""; path[path.length - 1] = "";
while ( path.length ) { while (path.length) {
if ( ( tmp = path.shift() ) === ".." ) { if ((tmp = path.shift()) === "..") {
res.pop(); res.pop();
} else if ( tmp !== "." ) { } else if (tmp !== ".") {
res.push( tmp ); res.push(tmp);
} }
} }
return protocol + res.join( "/" ); return protocol + res.join("/");
} }
window.KITYMINDER_CONFIG = { window.KITYMINDER_CONFIG = {
'KITYMINDER_HOME_URL': getKMBasePath(), 'KITYMINDER_HOME_URL': getKMBasePath(),
//定义工具栏 //定义工具栏
toolbars: [ 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 | collapsenode expandnode | undo redo | bold italic | fontfamily fontsize forecolor | saveto | switchlayout | hyperlink unhyperlink image removeimage | markers resource | node | help'
] ]
//只读模式,默认是false //只读模式,默认是false
//readOnly: true //readOnly: true
...@@ -95,4 +95,4 @@ ...@@ -95,4 +95,4 @@
//,maxImageHeight: 200 //,maxImageHeight: 200
// //
}; };
} )(); })();
\ No newline at end of file \ No newline at end of file
KityMinder.LANG[ 'zh-cn' ] = { KityMinder.LANG['zh-cn'] = {
'maintopic': '中心主题', 'maintopic': '中心主题',
'topic': '分支主题', 'topic': '分支主题',
'tooltips': { 'tooltips': {
...@@ -39,11 +39,17 @@ KityMinder.LANG[ 'zh-cn' ] = { ...@@ -39,11 +39,17 @@ KityMinder.LANG[ 'zh-cn' ] = {
'lang_input_target': '是否在新窗口打开:' 'lang_input_target': '是否在新窗口打开:'
}, },
'priority': '优先级', 'priority': '优先级',
'none': '无',
'progress': { 'progress': {
'title': '进度',
'notdone': "未完成", 'notdone': "未完成",
'quarterdone': '完成1/4', 'done1': '完成1/8',
'halfdone': '完成1/2', 'done2': '完成1/4',
'threequartersdone': '完成3/4', 'done3': '完成3/8',
'done4': '完成1/2',
'done5': '完成5/8',
'done6': '完成3/4',
'done7': '完成7/8',
'done': '已完成' 'done': '已完成'
} }
}, },
...@@ -52,8 +58,7 @@ KityMinder.LANG[ 'zh-cn' ] = { ...@@ -52,8 +58,7 @@ KityMinder.LANG[ 'zh-cn' ] = {
}, },
'hyperlink': {}, 'hyperlink': {},
'image': {}, 'image': {},
'resource': { 'resource': {}
}
}, },
'node': { 'node': {
'appendsiblingnode': '插入同级节点', 'appendsiblingnode': '插入同级节点',
...@@ -65,11 +70,11 @@ KityMinder.LANG[ 'zh-cn' ] = { ...@@ -65,11 +70,11 @@ KityMinder.LANG[ 'zh-cn' ] = {
'default': '左右展开', 'default': '左右展开',
'bottom': '向下展开' 'bottom': '向下展开'
}, },
'hyperlink':{ 'hyperlink': {
'hyperlink':'插入超链接', 'hyperlink': '插入超链接',
'unhyperlink':"取消超链接" 'unhyperlink': "取消超链接"
}, },
'image':{ 'image': {
'image': '插入图片', 'image': '插入图片',
'removeimage': '删除图片' 'removeimage': '删除图片'
} }
......
KM.registerToolbarUI( 'switchlayout', function ( name ) { KM.registerToolbarUI('switchlayout', function (name) {
var me = this, var me = this,
label = me.getLang( 'tooltips.' + name ), label = me.getLang('tooltips.' + name),
options = { options = {
label: label, label: label,
title: label, title: label,
...@@ -13,54 +12,55 @@ KM.registerToolbarUI( 'switchlayout', function ( name ) { ...@@ -13,54 +12,55 @@ KM.registerToolbarUI( 'switchlayout', function ( name ) {
enabledRecord: false enabledRecord: false
}, },
$combox = null; $combox = null;
if ( options.items.length == 0 ) { if (options.items.length == 0) {
return null; return null;
} }
utils.each( options.items, function ( i, item ) { utils.each(options.items, function (i, item) {
options.items[ i ] = me.getLang( 'layout' )[ item ]; options.items[i] = me.getLang('layout')[item];
} ); });
//实例化 //实例化
$combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 ); $combox = $.kmuibuttoncombobox(options).css('zIndex', me.getOptions('zIndex') + 1);
var comboboxWidget = $combox.kmui(); var comboboxWidget = $combox.kmui();
comboboxWidget.on( 'comboboxselect', function ( evt, res ) { comboboxWidget.on('comboboxselect', function (evt, res) {
me.execCommand( name, res.value ); me.execCommand(name, res.value);
} ).on( "beforeshow", function () { me.initStyle();
if ( $combox.parent().length === 0 ) { }).on("beforeshow", function () {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) ); if ($combox.parent().length === 0) {
$combox.appendTo(me.$container.find('.kmui-dialog-container'));
} }
} ); });
//状态反射 //状态反射
me.on( 'interactchange', function () { me.on('interactchange', function () {
var state = this.queryCommandState( name ), var state = this.queryCommandState(name),
value = this.queryCommandValue( name ); value = this.queryCommandValue(name);
//设置按钮状态 //设置按钮状态
comboboxWidget.button().kmui().disabled( state == -1 ).active( state == 1 ); comboboxWidget.button().kmui().disabled(state == -1).active(state == 1);
if ( value ) { if (value) {
//设置label //设置label
value = value.replace( /['"]/g, '' ).toLowerCase().split( /['|"]?\s*,\s*[\1]?/ ); value = value.replace(/['"]/g, '').toLowerCase().split(/['|"]?\s*,\s*[\1]?/);
comboboxWidget.selectItemByLabel( value ); comboboxWidget.selectItemByLabel(value);
} }
} ); });
var data = []; var data = [];
utils.each( me.getLayoutStyleItems(), function ( i, v ) { utils.each(me.getLayoutStyleItems(), function (i, v) {
data.push( { data.push({
label: me.getLang( 'tooltips.' + name ) + ' ' + v, label: me.getLang('tooltips.' + name) + ' ' + v,
cmdName: 'switchlayout', cmdName: 'switchlayout',
exec: function () { exec: function () {
me.execCommand( 'switchlayout', v ); me.execCommand('switchlayout', v);
} }
} ) })
} ); });
data.push( { data.push({
divider: 1 divider: 1
} ); });
me.addContextmenu( data ); me.addContextmenu(data);
return comboboxWidget.button().addClass( 'kmui-combobox' ); return comboboxWidget.button().addClass('kmui-combobox');
} ); });
\ No newline at end of file \ No newline at end of file
KityMinder.registerModule( "IconModule", function () { KityMinder.registerModule("IconModule", function () {
var minder = this; var minder = this;
var renderPriorityIcon = function ( node, val ) { var renderPriorityIcon = function (node, val) {
var colors = [ "", "#A92E24", "#29A6BD", "#1E8D54", "#eb6100", "#876DDA" ]; var colors = ["", "#A92E24", "#29A6BD", "#1E8D54", "#eb6100", "#876DDA", "#828282", "#828282", "#828282", "#828282"];
var _bg = new kity.Rect().fill( colors[ val ] ).setRadius( 3 ).setWidth( 20 ).setHeight( 20 ); var bgcolor = colors[val];
var _number = new kity.Text().setContent( val ).fill( "white" ).setSize( 12 ); var _bg = new kity.Rect().fill(colors[val]).setRadius(3).setWidth(20).setHeight(20);
var _number = new kity.Text().setContent(val).fill("white").setSize(12);
var _rc = new kity.Group(); var _rc = new kity.Group();
_rc.addShapes( [ _bg, _number ] ); _rc.addShapes([_bg, _number]);
node.getContRc().addShape( _rc ); node.getContRc().addShape(_rc);
_number.setTranslate( 6, 15 ); _number.setTranslate(6, 15);
var rcHeight = _rc.getHeight(); var rcHeight = _rc.getHeight();
_rc.setTranslate( 0, -rcHeight / 2 ); _rc.setTranslate(0, -rcHeight / 2);
}; };
var renderProgressIcon = function ( node, val ) { var renderProgressIcon = function (node, val) {
var _rc = new kity.Group(); var _rc = new kity.Group();
var _contRc = node.getContRc(); var _contRc = node.getContRc();
var _bg = new kity.Circle().setRadius( 8 ).fill( "white" ).stroke( new kity.Pen( "#29A6BD", 2 ) ); var _bg = new kity.Circle().setRadius(8).fill("white").stroke(new kity.Pen("#29A6BD", 2));
var _percent, d; var _percent, d;
if ( val < 5 ) { if (val < 9) {
_percent = new kity.Path(); _percent = new kity.Path();
d = _percent.getDrawer(); d = _percent.getDrawer();
d.moveTo( 0, 0 ).lineTo( 6, 0 ); d.moveTo(0, 0).lineTo(0, -6);
} else _percent = new kity.Group(); } else _percent = new kity.Group();
_rc.addShapes( [ _bg, _percent ] ); _rc.addShapes([_bg, _percent]);
_contRc.addShape( _rc ); _contRc.addShape(_rc);
switch ( val ) { //r, laf, sf, x, y
//large-arc-flag 为1 表示大角度弧线,0 代表小角度弧线。
//sweep-flag 为1代表从起点到终点弧线绕中心顺时针方向,0 代表逆时针方向。
switch (val) {
case 1: case 1:
break; break;
case 2: case 2:
d.carcTo( 6, 0, 0, 0, -6 ); d.carcTo(6, 0, 1, 6 * Math.cos(2 * Math.PI / 8), -6 * Math.sin(2 * Math.PI / 8));
break; break;
case 3: case 3:
d.carcTo( 6, 0, 0, -6, 0 ); d.carcTo(6, 0, 1, 6, 0);
break; break;
case 4: case 4:
d.carcTo( 6, 1, 0, 0, 6 ); d.carcTo(6, 0, 1, 6 * Math.cos(2 * Math.PI / 8), 6 * Math.sin(2 * Math.PI / 8));
break; break;
case 5: case 5:
d.carcTo(6, 0, 1, 0, 6);
break;
case 6:
d.carcTo(6, 1, 1, -6 * Math.cos(2 * Math.PI / 8), 6 * Math.sin(2 * Math.PI / 8));
break;
case 7:
d.carcTo(6, 1, 1, -6, 0);
break;
case 8:
d.carcTo(6, 1, 1, -6 * Math.cos(2 * Math.PI / 8), -6 * Math.sin(2 * Math.PI / 8));
break;
case 9:
var check = new kity.Path(); var check = new kity.Path();
_percent.addShapes( [ new kity.Circle().setRadius( 6 ).fill( "#29A6BD" ), check ] ); _percent.addShapes([new kity.Circle().setRadius(6).fill("#29A6BD"), check]);
check.getDrawer().moveTo( -3, 0 ).lineTo( -1, 3 ).lineTo( 3, -2 ); check.getDrawer().moveTo(-3, 0).lineTo(-1, 3).lineTo(3, -2);
check.stroke( new kity.Pen( "white", 2 ).setLineCap( "round" ) ); check.stroke(new kity.Pen("white", 2).setLineCap("round"));
break; break;
} }
if ( val < 5 ) d.close(); if (val && val < 8) d.close();
_percent.fill( "#29A6BD" ); _percent.fill("#29A6BD");
var pre = node.getData( "PriorityIcon" ); var pre = node.getData("PriorityIcon");
var style = minder.getCurrentLayoutStyle()[ node.getType() ]; var style = minder.getCurrentLayoutStyle()[node.getType()];
if ( !pre ) _rc.setTranslate( _rc.getWidth() / 2, 0 ); if (!pre) _rc.setTranslate(_rc.getWidth() / 2, 0);
else _rc.setTranslate( _contRc.getWidth() + style.spaceLeft, 0 ); else _rc.setTranslate(_contRc.getWidth() + style.spaceLeft, 0);
}; };
var setPriorityCommand = kity.createClass( "SetPriorityCommand", ( function () { var setPriorityCommand = kity.createClass("SetPriorityCommand", (function () {
return { return {
base: Command, base: Command,
execute: function ( km, value ) { execute: function (km, value) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
for ( var i = 0; i < nodes.length; i++ ) { for (var i = 0; i < nodes.length; i++) {
nodes[ i ].setData( "PriorityIcon", value ); nodes[i].setData("PriorityIcon", value);
km.updateLayout( nodes[ i ] ); km.updateLayout(nodes[i]);
} }
}, },
queryValue: function ( km ) { queryValue: function (km) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
var val; var val;
for ( var i = 0; i < nodes.length; i++ ) { for (var i = 0; i < nodes.length; i++) {
val = nodes[ i ].getData( "PriorityIcon" ); val = nodes[i].getData("PriorityIcon");
if ( val ) break; if (val) break;
} }
return val; return val;
} }
}; };
} )() ); })());
var setProgressCommand = kity.createClass( "SetProgressCommand", ( function () { var setProgressCommand = kity.createClass("SetProgressCommand", (function () {
return { return {
base: Command, base: Command,
execute: function ( km, value ) { execute: function (km, value) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
for ( var i = 0; i < nodes.length; i++ ) { for (var i = 0; i < nodes.length; i++) {
nodes[ i ].setData( "ProgressIcon", value ); nodes[i].setData("ProgressIcon", value);
km.updateLayout( nodes[ i ] ); km.updateLayout(nodes[i]);
} }
}, },
queryValue: function ( km ) { queryValue: function (km) {
var nodes = km.getSelectedNodes(); var nodes = km.getSelectedNodes();
var val; var val;
for ( var i = 0; i < nodes.length; i++ ) { for (var i = 0; i < nodes.length; i++) {
val = nodes[ i ].getData( "ProgressIcon" ); val = nodes[i].getData("ProgressIcon");
if ( val ) break; if (val) break;
} }
return val; return val;
} }
}; };
} )() ); })());
return { return {
"commands": { "commands": {
"priority": setPriorityCommand, "priority": setPriorityCommand,
"progress": setProgressCommand "progress": setProgressCommand
}, },
"events": { "events": {
"RenderNodeLeft": function ( e ) { "RenderNodeLeft": function (e) {
var node = e.node; var node = e.node;
var PriorityIconVal = node.getData( "PriorityIcon" ); var PriorityIconVal = node.getData("PriorityIcon");
var ProgressIconVal = node.getData( "ProgressIcon" ); var ProgressIconVal = node.getData("ProgressIcon");
var contRc = node.getContRc(); var contRc = node.getContRc();
if ( PriorityIconVal ) { if (PriorityIconVal) {
renderPriorityIcon( node, PriorityIconVal ); renderPriorityIcon(node, PriorityIconVal);
} }
if ( ProgressIconVal ) { if (ProgressIconVal) {
renderProgressIcon( node, ProgressIconVal ); renderProgressIcon(node, ProgressIconVal);
} }
} }
} }
}; };
} ); });
\ No newline at end of file \ No newline at end of file
KityMinder.registerModule( "KeyboardModule", function () { KityMinder.registerModule("KeyboardModule", function () {
var min = Math.min, var min = Math.min,
max = Math.max, max = Math.max,
abs = Math.abs, abs = Math.abs,
sqrt = Math.sqrt, sqrt = Math.sqrt,
exp = Math.exp; exp = Math.exp;
function buildPositionNetwork( root ) { function buildPositionNetwork(root) {
var pointIndexes = [], var pointIndexes = [],
p; p;
root.traverse( function ( node ) { root.traverse(function (node) {
p = node.getRenderContainer().getRenderBox( 'top' ); p = node.getRenderContainer().getRenderBox('top');
// bugfix: 不应导航到收起的节点(判断其尺寸是否存在) // bugfix: 不应导航到收起的节点(判断其尺寸是否存在)
if ( p.width && p.height ) { if (p.width && p.height) {
pointIndexes.push( { pointIndexes.push({
left: p.x, left: p.x,
top: p.y, top: p.y,
right: p.x + p.width, right: p.x + p.width,
...@@ -22,30 +22,30 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -22,30 +22,30 @@ KityMinder.registerModule( "KeyboardModule", function () {
height: p.height, height: p.height,
node: node, node: node,
text: node.getText() text: node.getText()
} ); });
} }
} ); });
for ( var i = 0; i < pointIndexes.length; i++ ) { for (var i = 0; i < pointIndexes.length; i++) {
findClosestPointsFor( pointIndexes, i ); findClosestPointsFor(pointIndexes, i);
} }
} }
// 这是金泉的点子,赞! // 这是金泉的点子,赞!
// 求两个不相交矩形的最近距离 // 求两个不相交矩形的最近距离
function getCoefedDistance( box1, box2 ) { function getCoefedDistance(box1, box2) {
var xMin, xMax, yMin, yMax, xDist, yDist, dist, cx, cy; var xMin, xMax, yMin, yMax, xDist, yDist, dist, cx, cy;
xMin = min( box1.left, box2.left ); xMin = min(box1.left, box2.left);
xMax = max( box1.right, box2.right ); xMax = max(box1.right, box2.right);
yMin = min( box1.top, box2.top ); yMin = min(box1.top, box2.top);
yMax = max( box1.bottom, box2.bottom ); yMax = max(box1.bottom, box2.bottom);
xDist = xMax - xMin - box1.width - box2.width; xDist = xMax - xMin - box1.width - box2.width;
yDist = yMax - yMin - box1.height - box2.height; yDist = yMax - yMin - box1.height - box2.height;
if ( xDist < 0 ) dist = yDist; if (xDist < 0) dist = yDist;
else if ( yDist < 0 ) dist = xDist; else if (yDist < 0) dist = xDist;
else dist = sqrt( xDist * xDist + yDist * yDist ); else dist = sqrt(xDist * xDist + yDist * yDist);
return { return {
cx: dist, cx: dist,
...@@ -53,21 +53,22 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -53,21 +53,22 @@ KityMinder.registerModule( "KeyboardModule", function () {
}; };
} }
function findClosestPointsFor( pointIndexes, iFind ) { function findClosestPointsFor(pointIndexes, iFind) {
var find = pointIndexes[ iFind ]; var find = pointIndexes[iFind];
var most = {}, quad; var most = {},
quad;
var current, dist; var current, dist;
for ( var i = 0; i < pointIndexes.length; i++ ) { for (var i = 0; i < pointIndexes.length; i++) {
if ( i == iFind ) continue; if (i == iFind) continue;
current = pointIndexes[ i ]; current = pointIndexes[i];
dist = getCoefedDistance( current, find ); dist = getCoefedDistance(current, find);
// left check // left check
if ( current.right < find.left ) { if (current.right < find.left) {
if ( !most.left || dist.cx < most.left.dist ) { if (!most.left || dist.cx < most.left.dist) {
most.left = { most.left = {
dist: dist.cx, dist: dist.cx,
node: current.node node: current.node
...@@ -76,8 +77,8 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -76,8 +77,8 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
// right check // right check
if ( current.left > find.right ) { if (current.left > find.right) {
if ( !most.right || dist.cx < most.right.dist ) { if (!most.right || dist.cx < most.right.dist) {
most.right = { most.right = {
dist: dist.cx, dist: dist.cx,
node: current.node node: current.node
...@@ -86,8 +87,8 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -86,8 +87,8 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
// top check // top check
if ( current.bottom < find.top ) { if (current.bottom < find.top) {
if ( !most.top || dist.cy < most.top.dist ) { if (!most.top || dist.cy < most.top.dist) {
most.top = { most.top = {
dist: dist.cy, dist: dist.cy,
node: current.node node: current.node
...@@ -96,8 +97,8 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -96,8 +97,8 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
// bottom check // bottom check
if ( current.top > find.bottom ) { if (current.top > find.bottom) {
if ( !most.down || dist.cy < most.down.dist ) { if (!most.down || dist.cy < most.down.dist) {
most.down = { most.down = {
dist: dist.cy, dist: dist.cy,
node: current.node node: current.node
...@@ -114,63 +115,63 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -114,63 +115,63 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
function navigateTo( km, direction ) { function navigateTo(km, direction) {
var referNode = km.getSelectedNode(); var referNode = km.getSelectedNode();
if ( !referNode ) { if (!referNode) {
km.select( km.getRoot() ); km.select(km.getRoot());
buildPositionNetwork( km.getRoot() ); buildPositionNetwork(km.getRoot());
return; return;
} }
var nextNode = referNode._nearestNodes[ direction ]; var nextNode = referNode._nearestNodes[direction];
if ( nextNode ) { if (nextNode) {
km.select( nextNode, true ); km.select(nextNode, true);
} }
} }
return { return {
"events": { "events": {
contentchange: function () { contentchange: function () {
buildPositionNetwork( this.getRoot() ); buildPositionNetwork(this.getRoot());
}, },
"normal.keydown": function ( e ) { "normal.keydown": function (e) {
var keys = KityMinder.keymap; var keys = KityMinder.keymap;
var node = e.getTargetNode(); var node = e.getTargetNode();
this.receiver.keydownNode = node; this.receiver.keydownNode = node;
switch ( e.originEvent.keyCode ) { switch (e.originEvent.keyCode) {
case keys.Enter: case keys.Enter:
this.execCommand( 'appendSiblingNode', new MinderNode( this.getLang().topic ), true ); this.execCommand('appendSiblingNode', new MinderNode(this.getLang().topic));
e.preventDefault(); e.preventDefault();
break; break;
case keys.Tab: case keys.Tab:
this.execCommand( 'appendChildNode', new MinderNode( this.getLang().topic ), true ); this.execCommand('appendChildNode', new MinderNode(this.getLang().topic));
e.preventDefault(); e.preventDefault();
break; break;
case keys.Backspace: case keys.Backspace:
case keys.Del: case keys.Del:
e.preventDefault(); e.preventDefault();
this.execCommand( 'removenode' ); this.execCommand('removenode');
break; break;
case keys.F2: case keys.F2:
e.preventDefault(); e.preventDefault();
this.execCommand( 'editnode' ); this.execCommand('editnode');
break; break;
case keys.Left: case keys.Left:
navigateTo( this, 'left' ); navigateTo(this, 'left');
e.preventDefault(); e.preventDefault();
break; break;
case keys.Up: case keys.Up:
navigateTo( this, 'top' ); navigateTo(this, 'top');
e.preventDefault(); e.preventDefault();
break; break;
case keys.Right: case keys.Right:
navigateTo( this, 'right' ); navigateTo(this, 'right');
e.preventDefault(); e.preventDefault();
break; break;
case keys.Down: case keys.Down:
navigateTo( this, 'down' ); navigateTo(this, 'down');
e.preventDefault(); e.preventDefault();
break; break;
} }
...@@ -178,4 +179,4 @@ KityMinder.registerModule( "KeyboardModule", function () { ...@@ -178,4 +179,4 @@ KityMinder.registerModule( "KeyboardModule", function () {
} }
} }
}; };
} ); });
\ No newline at end of file \ No newline at end of file
This diff is collapsed.
...@@ -396,12 +396,16 @@ KityMinder.registerModule("LayoutDefault", function () { ...@@ -396,12 +396,16 @@ KityMinder.registerModule("LayoutDefault", function () {
minder.getRenderContainer().addShape(connect); minder.getRenderContainer().addShape(connect);
} }
connect = Layout.connect; connect = Layout.connect;
var parentShape = node.getParent().getRenderContainer(); var parent = node.getParent();
var parentShape = parent.getRenderContainer();
var parentBox = parentShape.getRenderBox(); var parentBox = parentShape.getRenderBox();
var parentLayout = node.getParent().getLayout(); var parentLayout = parent.getLayout();
var parentStyle = nodeStyles[node.getParent().getType()]; var parentStyle = nodeStyles[node.getParent().getType()];
var Shape = node.getRenderContainer(); var Shape = node.getRenderContainer();
var sX, sY = parentLayout.y; var sX, sY = parentBox.bottom - 5;
if (parent.getType() === 'main') {
sY = (parentBox.top + parentBox.bottom) / 2
}
var nodeX, nodeY = Shape.getRenderBox().closurePoints[1].y; var nodeX, nodeY = Shape.getRenderBox().closurePoints[1].y;
if (Layout.appendside === "left") { if (Layout.appendside === "left") {
sX = parentBox.closurePoints[1].x - parentStyle.margin[1]; sX = parentBox.closurePoints[1].x - parentStyle.margin[1];
...@@ -587,11 +591,11 @@ KityMinder.registerModule("LayoutDefault", function () { ...@@ -587,11 +591,11 @@ KityMinder.registerModule("LayoutDefault", function () {
} }
} }
}, },
appendChildNode: function (parent, node, focus, sibling) { appendChildNode: function (parent, node, sibling) {
minder.handelNodeInsert(node); minder.handelNodeInsert(node);
var Layout = node.getLayout();
node.clearLayout(); node.clearLayout();
node.getContRc().clear(); node.getContRc().clear();
var Layout = node.getLayout();
Layout = node.getLayout(); Layout = node.getLayout();
Layout.added = true; Layout.added = true;
var parentLayout = parent.getLayout(); var parentLayout = parent.getLayout();
...@@ -690,16 +694,13 @@ KityMinder.registerModule("LayoutDefault", function () { ...@@ -690,16 +694,13 @@ KityMinder.registerModule("LayoutDefault", function () {
updateConnectAndshIcon(set [i]); updateConnectAndshIcon(set [i]);
} }
// if ( focus ) {
// showNodeInView( node );
// }
parent.expand(); parent.expand();
var shicon = parent.getLayout().shicon; var shicon = parent.getLayout().shicon;
if (shicon) shicon.switchState(true); if (shicon) shicon.switchState(true);
}, },
appendSiblingNode: function (sibling, node, focus) { appendSiblingNode: function (sibling, node) {
var parent = sibling.getParent(); var parent = sibling.getParent();
this.appendChildNode(parent, node, focus, sibling); this.appendChildNode(parent, node, sibling);
}, },
removeNode: function (nodes) { removeNode: function (nodes) {
nodes = utils.isArray(nodes) ? nodes : [nodes]; nodes = utils.isArray(nodes) ? nodes : [nodes];
......
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