Commit 69cb9cc4 authored by campaign's avatar campaign

by zhanyi

parent cbfcc958
window.KITYMINDER_CONFIG = {
//定义工具栏
toolbars:[
'undo redo | bold italic | forecolor'
'undo redo | bold italic | forecolor | layoutstyle | fontfamily fontsize'
]
//设置主题
//layoutstyle : 'default'
//,defaultlayoutstyle : 'default' //设置默认的主题
//,layoutstyle : [] //添加有那些主图
//回退相关选项
//maxUndoCount:20 //最大可回退的次数,默认20
//,maxUndoCount:20 //最大可回退的次数,默认20
//语言默认是zh-cn
//,lang:'zh-cn'
//设置km整体的z-index大小
//zIndex : 1000
//,zIndex : 1000
};
\ No newline at end of file
......@@ -19,10 +19,6 @@
</head>
<body >
<div id="kityminder" style="height:1000px;width:100%" onselectstart="return false">
<select id="StyleChange">
<option value="default">Default</option>
<option value="green" selected>Green</option>
</select>
</div>
</body>
<script>
......
KityMinder.LANG['zh-cn'] = {
'tooltips':{
'undo':'撤销', 'redo':'重做', 'bold':'加粗', 'italic':'斜体','forecolor':'字体颜色'
'undo':'撤销', 'redo':'重做',
'bold':'加粗', 'italic':'斜体',
'forecolor':'字体颜色', 'fontfamily':'字体', 'fontsize':'字号',
'layoutstyle':'选择主题'
},
'popupcolor':{
'clearColor':'清空颜色',
......
......@@ -33,8 +33,11 @@ utils.extend(KityMinder,function(){
if(name == '|'){
$.kmuiseparator && btns.push($.kmuiseparator());
}else{
var ui = _kityminderUI[name].call(km,name);
ui && btns.push(ui);
if(_kityminderUI[name]){
var ui = _kityminderUI[name].call(km,name);
ui && btns.push(ui);
}
}
});
......
KM.registerUI('layoutstyle 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 'layoutstyle':
options = transForLayoutstyle( options );
break;
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');
/**
* 宽度自适应工具函数
* @param word 单词内容
* @param hasSuffix 是否含有后缀
*/
function wordCountAdaptive ( 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 );
}
}
function transForLayoutstyle ( options ) {
var tempItems = [];
utils.each(options.items,function(k,v){
options.value.push(k);
tempItems.push(k);
options.autowidthitem.push( wordCountAdaptive( tempItems[ tempItems.length - 1 ] ) );
});
options.items = tempItems;
return options;
}
//字体参数转换
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');
}
options.value = options.items;
options.items = tempItems;
options.autoRecord = false;
return options;
}
});
KM.registerUI('forecolor', function( name ) {
function getCurrentColor() {
return $colorLabel.css('background-color');
......
KityMinder.registerModule( "fontmodule", function () {
return {
defaultOptions:{
'fontfamily': [
{ name: 'songti', val: '宋体,SimSun'},
{ name: 'yahei', val: '微软雅黑,Microsoft YaHei'},
{ name: 'kaiti', val: '楷体,楷体_GB2312, SimKai'},
{ name: 'heiti', val: '黑体, SimHei'},
{ name: 'lishu', val: '隶书, SimLi'},
{ name: 'andaleMono', val: 'andale mono'},
{ name: 'arial', val: 'arial, helvetica,sans-serif'},
{ name: 'arialBlack', val: 'arial black,avant garde'},
{ name: 'comicSansMs', val: 'comic sans ms'},
{ name: 'impact', val: 'impact,chicago'},
{ name: 'timesNewRoman', val: 'times new roman'},
{ name: 'sans-serif',val:'sans-serif'}
],
'fontsize': [10, 12, 16, 18,24, 32,48]
},
"commands": {
"forecolor": kity.createClass( "fontcolorCommand", {
base: Command,
......@@ -25,6 +41,17 @@ KityMinder.registerModule( "fontmodule", function () {
n.getTextShape().setAttr( 'font-family', family );
} )
}
} ),
"fontsize": kity.createClass( "fontsizeCommand", {
base: Command,
execute: function ( km, size ) {
var nodes = km.getSelectedNodes();
utils.each( nodes, function ( i, n ) {
n.setData( 'fontsize', size );
n.getTextShape().setSize(size);
} )
}
} )
},
......
......@@ -7,6 +7,9 @@ KityMinder.registerModule( "LayoutModule", function () {
getLayoutStyle: function ( name ) {
return this._layoutStyles[ name ];
},
getLayoutStyleItems : function(){
return this._layoutStyles
},
getCurrentStyle: function () {
var _root = this.getRoot();
return _root.getData( "currentstyle" );
......@@ -148,11 +151,12 @@ KityMinder.registerModule( "LayoutModule", function () {
},
"events": {
"ready": function () {
switchLayout( this, this.getOptions( 'layoutstyle' ) );
this.setDefaultOptions('layoutstyle',this.getLayoutStyleItems());
switchLayout( this, this.getOptions( 'defaultlayoutstyle' ) );
}
},
"defaultOptions": {
"layoutstyle": "default"
"defaultlayoutstyle": "default"
}
};
} );
\ No newline at end of file
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