/** * Created by JetBrains PhpStorm. * User: dongyancen * Date: 12-4-12 * Time: 下午4:46 * To change this template use File | Settings | File Templates. */ module( 'ui.toolbar' ); test( 'toolbar显示', function() { var editor = new baidu.editor.ui.Editor(); var toolbar =[ 'link','unlink','|']; baidu.editor.ui['link'] = function (cmd){ return function (editor, title){ var ui = new baidu.editor.ui.Button({ className: 'edui-for-' + cmd, title: title || editor.options.labelMap || editor.getLang('labelMap') || '', onclick: function (){ editor.execCommand(cmd); }, showText: false, editor:editor }); editor.addListener('selectionchange', function (type, causeByUi, uiReady){ var state = editor.queryCommandState(cmd); if (state == -1) { ui.setDisabled(true); ui.setChecked(false); } else { if(!uiReady){ ui.setDisabled(false); ui.setChecked(state); } } }); return ui; }; }('link'); baidu.editor.ui['unlink'] = function (cmd){ return function (editor, title){ var ui = new baidu.editor.ui.Button({ className: 'edui-for-' + cmd, title: title || editor.options.labelMap || editor.getLang('labelMap') || '', onclick: function (){ editor.execCommand(cmd); }, showText: false, editor:editor }); editor.addListener('selectionchange', function (type, causeByUi, uiReady){ var state = editor.queryCommandState(cmd); if (state == -1) { ui.setDisabled(true); ui.setChecked(false); } else { if(!uiReady){ ui.setDisabled(false); ui.setChecked(state); } } }); return ui; }; }('unlink'); var toolbarUi = new baidu.editor.ui.Toolbar({theme:editor.options.theme}); for ( var j = 0; j < toolbar.length; j++ ) { var toolbarItem = toolbar[j].toLowerCase(); var toolbarItemUi = null; if ( typeof toolbarItem == 'string' ) { if ( toolbarItem == '|' ) { toolbarItem = 'Separator'; } if ( baidu.editor.ui[toolbarItem] ) { toolbarItemUi = new baidu.editor.ui[toolbarItem]( editor ); } } else { toolbarItemUi = toolbarItem; } if ( toolbarItemUi ) { toolbarUi.add( toolbarItemUi ); } } var theme = ' edui-'+editor.options.theme; toolbarUi.render(te.dom[0]); toolbarUi.postRender(); var toolbarShow = document.getElementById('editor').firstChild; equal(toolbarShow.className,'edui-toolbar '+theme,'检查toolbar的显示'); equal(toolbarShow.childNodes.length ,toolbar.length,'检查toolbar的显示'); for(var i=0;i