Commit ab951fb2 authored by techird's avatar techird

add background change command

parent ed1befc0
/** /**
* 开发版本的文件导入 * 开发版本的文件导入
*/ */
(function (){ (function () {
var paths = new Array( var paths = [
'core/kityminder.js' 'core/kityminder.js',
,'core/utils.js' 'core/utils.js',
,'core/command.js' 'core/command.js',
,'core/node.js' 'core/node.js',
,'core/module.js' 'core/module.js',
,'core/event.js' 'core/event.js',
,'core/minder.js' 'core/minder.js',
,'core/minder.data.js' 'core/minder.data.js',
,'core/minder.event.js' 'core/minder.event.js',
,'core/minder.module.js' 'core/minder.module.js',
,'core/minder.command.js' 'core/minder.command.js',
,'core/minder.node.js' 'core/minder.node.js',
,'core/keymap.js' 'core/keymap.js',
,'core/minder.lang.js' 'core/minder.lang.js',
,'core/minder.defaultoptions.js' 'core/minder.defaultoptions.js',
,'core/minder.preference.js' 'core/minder.preference.js',
,'core/browser.js' 'core/browser.js',
,'module/geometry.js' 'module/geometry.js',
,'module/history.js' 'module/history.js',
,'module/icon.js' 'module/icon.js',
,'module/image.js' 'module/image.js',
,'module/resource.js' 'module/resource.js',
,'module/layout.js' 'module/layout.js',
,'module/layout.default.js' 'module/layout.default.js',
,'module/layout.bottom.js' 'module/layout.bottom.js',
,'core/minder.select.js' 'core/minder.select.js',
,'module/view.js' 'module/view.js',
,'module/dragtree.js' 'module/dragtree.js',
,'module/dropfile.js' 'module/dropfile.js',
,'module/keyboard.js' 'module/keyboard.js',
,'module/select.js' 'module/select.js',
,'module/history.js' 'module/history.js',
,'module/editor.js' 'module/editor.js',
,'module/editor.range.js' 'module/editor.range.js',
,'module/editor.receiver.js' 'module/editor.receiver.js',
,'module/editor.selection.js' 'module/editor.selection.js',
,'module/basestyle.js' 'module/basestyle.js',
,'module/font.js' 'module/font.js',
,'module/zoom.js' 'module/zoom.js',
,'module/nodetext.js' 'module/nodetext.js',
,'module/hyperlink.js' 'module/hyperlink.js',
,'module/expand.js' 'module/expand.js',
,'ui/jquery-ui-1.10.4.custom.min.js' 'ui/jquery-ui-1.10.4.custom.min.js',
,'ui/widget.js' 'ui/widget.js',
,'ui/button.js' 'ui/button.js',
,'ui/toolbar.js' 'ui/toolbar.js',
,'ui/menu.js' 'ui/menu.js',
,'ui/dropmenu.js' 'ui/dropmenu.js',
,'ui/splitbutton.js' 'ui/splitbutton.js',
,'ui/colorsplitbutton.js' 'ui/colorsplitbutton.js',
,'ui/popup.js' 'ui/popup.js',
,'ui/scale.js' 'ui/scale.js',
,'ui/colorpicker.js' 'ui/colorpicker.js',
,'ui/combobox.js' 'ui/combobox.js',
,'ui/buttoncombobox.js' 'ui/buttoncombobox.js',
,'ui/modal.js' 'ui/modal.js',
,'ui/tooltip.js' 'ui/tooltip.js',
,'ui/tab.js' 'ui/tab.js',
,'ui/separator.js' 'ui/separator.js',
,'ui/scale.js' 'ui/scale.js',
,'adapter/utils.js' 'adapter/utils.js',
,'adapter/adapter.js' 'adapter/adapter.js',
,'adapter/button.js' 'adapter/button.js',
,'adapter/combobox.js' 'adapter/combobox.js',
,'adapter/saveto.js' 'adapter/color.js',
,'adapter/tooltips.js' 'adapter/saveto.js',
,'adapter/layout.js' 'adapter/tooltips.js',
,'adapter/node.js' 'adapter/layout.js',
,'adapter/contextmenu.js' 'adapter/node.js',
,'adapter/dialog.js' 'adapter/contextmenu.js',
,'adapter/hyperlink.js' 'adapter/dialog.js',
,'adapter/image.js' 'adapter/hyperlink.js',
,'adapter/zoom.js' 'adapter/image.js',
,'protocal/xmind.js' 'adapter/zoom.js',
,'protocal/freemind.js' 'protocal/xmind.js',
,'protocal/mindmanager.js' 'protocal/freemind.js',
,'protocal/plain.js' 'protocal/mindmanager.js',
,'protocal/json.js' 'protocal/plain.js',
,'protocal/png.js' 'protocal/json.js',
,'protocal/svg.js' 'protocal/png.js',
'protocal/svg.js'
), ],
baseURL = 'src/'; baseURL = 'src/', doc = document;
for (var i=0,pi;pi = paths[i++];) { while (paths.length) {
document.write('<script type="text/javascript" src="'+ baseURL + pi +'"></script>'); doc.write('<script type="text/javascript" src="' + baseURL + paths.shift() + '"></script>');
} }
})(); })();
\ No newline at end of file
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.registerToolbarUI( 'fontfamily fontsize', function ( name ) { KM.registerToolbarUI('fontfamily fontsize', 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,
comboboxName: name, comboboxName: name,
items: me.getOptions( name ) || [], items: me.getOptions(name) || [],
itemStyles: [], itemStyles: [],
value: [], value: [],
autowidthitem: [] autowidthitem: []
...@@ -14,65 +14,65 @@ KM.registerToolbarUI( 'fontfamily fontsize', function ( name ) { ...@@ -14,65 +14,65 @@ KM.registerToolbarUI( 'fontfamily fontsize', function ( name ) {
$combox = null, $combox = null,
comboboxWidget = null; comboboxWidget = null;
if ( options.items.length == 0 ) { if (options.items.length == 0) {
return null; return null;
} }
switch ( name ) { switch (name) {
case 'fontfamily': case 'fontfamily':
options = transForFontfamily( options ); options = transForFontfamily(options);
break; break;
case 'fontsize': case 'fontsize':
options = transForFontsize( options ); options = transForFontsize(options);
break; break;
} }
//实例化 //实例化
$combox = $.kmuibuttoncombobox( options ).css( 'zIndex', me.getOptions( 'zIndex' ) + 1 ); $combox = $.kmuibuttoncombobox(options).css('zIndex', me.getOptions('zIndex') + 1);
comboboxWidget = $combox.kmui(); 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 () { }).on("beforeshow", function () {
if ( $combox.parent().length === 0 ) { if ($combox.parent().length === 0) {
$combox.appendTo( me.$container.find( '.kmui-dialog-container' ) ); $combox.appendTo(me.$container.find('.kmui-dialog-container'));
} }
} ); });
//状态反射 //状态反射
this.on( 'interactchange', function () { this.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);
} }
} ); });
return comboboxWidget.button().addClass( 'kmui-combobox' ); return comboboxWidget.button().addClass('kmui-combobox');
//字体参数转换 //字体参数转换
function transForFontfamily( options ) { function transForFontfamily(options) {
var temp = null, var temp = null,
tempItems = []; tempItems = [];
for ( var i = 0, len = options.items.length; i < len; i++ ) { for (var i = 0, len = options.items.length; i < len; i++) {
temp = options.items[ i ].val; temp = options.items[i].val;
tempItems.push( temp.split( /\s*,\s*/ )[ 0 ] ); tempItems.push(temp.split(/\s*,\s*/)[0]);
options.itemStyles.push( 'font-family: ' + temp ); options.itemStyles.push('font-family: ' + temp);
options.value.push( temp ); options.value.push(temp);
options.autowidthitem.push( $.wordCountAdaptive( tempItems[ i ] ) ); options.autowidthitem.push($.wordCountAdaptive(tempItems[i]));
} }
...@@ -83,7 +83,7 @@ KM.registerToolbarUI( 'fontfamily fontsize', function ( name ) { ...@@ -83,7 +83,7 @@ KM.registerToolbarUI( 'fontfamily fontsize', function ( name ) {
} }
//字体大小参数转换 //字体大小参数转换
function transForFontsize( options ) { function transForFontsize(options) {
var temp = null, var temp = null,
tempItems = []; tempItems = [];
...@@ -91,11 +91,11 @@ KM.registerToolbarUI( 'fontfamily fontsize', function ( name ) { ...@@ -91,11 +91,11 @@ KM.registerToolbarUI( 'fontfamily fontsize', function ( name ) {
options.itemStyles = []; options.itemStyles = [];
options.value = []; options.value = [];
for ( var i = 0, len = options.items.length; i < len; i++ ) { for (var i = 0, len = options.items.length; i < len; i++) {
temp = options.items[ i ]; temp = options.items[i];
tempItems.push( temp ); tempItems.push(temp);
options.itemStyles.push( 'font-size: ' + temp + 'px; height:' + (temp+2) + 'px; line-height: ' + (temp + 2) + 'px' ); options.itemStyles.push('font-size: ' + temp + 'px; height:' + (temp + 2) + 'px; line-height: ' + (temp + 2) + 'px');
} }
options.value = options.items; options.value = options.items;
...@@ -106,68 +106,4 @@ KM.registerToolbarUI( 'fontfamily fontsize', function ( name ) { ...@@ -106,68 +106,4 @@ KM.registerToolbarUI( 'fontfamily fontsize', function ( name ) {
} }
} ); });
\ No newline at end of file
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
...@@ -54,6 +54,33 @@ KityMinder.registerModule( "fontmodule", function () { ...@@ -54,6 +54,33 @@ KityMinder.registerModule( "fontmodule", function () {
}, },
queryState:function(km){ queryState:function(km){
return km.getSelectedNodes().length == 0 ? -1 : 0 return km.getSelectedNodes().length == 0 ? -1 : 0
},
queryValue: function(km) {
if (km.getSelectedNodes().length == 1) {
return km.getSelectedNodes()[0].getData('fontcolor');
}
return 'mixed';
}
} ),
"backgroundcolor": kity.createClass( "backgroudcolorCommand", {
base: Command,
execute: function ( km, color ) {
var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) {
n.setData( 'backgroundcolor', color );
n.getLayout().bgRect.fill( color );
} );
},
queryState:function(km){
return km.getSelectedNodes().length == 0 ? -1 : 0
},
queryValue: function (km) {
if (km.getSelectedNodes().length == 1) {
return km.getSelectedNodes()[0].getData('backgroundcolor');
}
return 'mixed';
} }
} ), } ),
...@@ -98,6 +125,9 @@ KityMinder.registerModule( "fontmodule", function () { ...@@ -98,6 +125,9 @@ KityMinder.registerModule( "fontmodule", function () {
if ( val = e.node.getData( 'fontcolor' ) ) { if ( val = e.node.getData( 'fontcolor' ) ) {
e.node.getTextShape().fill( val ); e.node.getTextShape().fill( val );
} }
if ( val = e.node.getData( 'backgroundcolor' ) ) {
e.node.getLayout().bgRect.fill( val );
}
if ( val = e.node.getData( 'fontsize' ) ) { if ( val = e.node.getData( 'fontsize' ) ) {
e.node.getTextShape().setSize( val ); e.node.getTextShape().setSize( val );
} }
......
...@@ -731,7 +731,7 @@ KityMinder.registerModule("LayoutDefault", function () { ...@@ -731,7 +731,7 @@ KityMinder.registerModule("LayoutDefault", function () {
if (highlight) { if (highlight) {
Layout.bgRect.fill(nodeStyle.highlight); Layout.bgRect.fill(nodeStyle.highlight);
} else { } else {
Layout.bgRect.fill(nodeStyle.fill); Layout.bgRect.fill(node.getData('backgroundcolor') || nodeStyle.fill);
} }
break; break;
case "sub": case "sub":
......
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