Commit ab951fb2 authored by techird's avatar techird

add background change command

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