123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787 |
-
- ( function() {
- var toolbox = function() {
- this.toolbars = [];
- this.focusCommandExecuted = false;
- };
- toolbox.prototype.focus = function() {
- for ( var t = 0, toolbar; toolbar = this.toolbars[ t++ ]; ) {
- for ( var i = 0, item; item = toolbar.items[ i++ ]; ) {
- if ( item.focus ) {
- item.focus();
- return;
- }
- }
- }
- };
- var commands = {
- toolbarFocus: {
- modes: { wysiwyg: 1, source: 1 },
- readOnly: 1,
- exec: function( editor ) {
- if ( editor.toolbox ) {
- editor.toolbox.focusCommandExecuted = true;
-
-
- if ( CKEDITOR.env.ie || CKEDITOR.env.air )
- setTimeout( function() {
- editor.toolbox.focus();
- }, 100 );
- else
- editor.toolbox.focus();
- }
- }
- }
- };
- CKEDITOR.plugins.add( 'toolbar', {
- requires: 'button',
- lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en,en-au,en-ca,en-gb,eo,es,et,eu,fa,fi,fo,fr,fr-ca,gl,gu,he,hi,hr,hu,id,is,it,ja,ka,km,ko,ku,lt,lv,mk,mn,ms,nb,nl,no,pl,pt,pt-br,ro,ru,si,sk,sl,sq,sr,sr-latn,sv,th,tr,tt,ug,uk,vi,zh,zh-cn',
- init: function( editor ) {
- var endFlag;
- var itemKeystroke = function( item, keystroke ) {
- var next, toolbar;
- var rtl = editor.lang.dir == 'rtl',
- toolbarGroupCycling = editor.config.toolbarGroupCycling,
-
- rightKeyCode = rtl ? 37 : 39,
- leftKeyCode = rtl ? 39 : 37;
- toolbarGroupCycling = toolbarGroupCycling === undefined || toolbarGroupCycling;
- switch ( keystroke ) {
- case 9:
- case CKEDITOR.SHIFT + 9:
-
-
- while ( !toolbar || !toolbar.items.length ) {
- toolbar = keystroke == 9 ? ( ( toolbar ? toolbar.next : item.toolbar.next ) || editor.toolbox.toolbars[ 0 ] ) : ( ( toolbar ? toolbar.previous : item.toolbar.previous ) || editor.toolbox.toolbars[ editor.toolbox.toolbars.length - 1 ] );
-
- if ( toolbar.items.length ) {
- item = toolbar.items[ endFlag ? ( toolbar.items.length - 1 ) : 0 ];
- while ( item && !item.focus ) {
- item = endFlag ? item.previous : item.next;
- if ( !item )
- toolbar = 0;
- }
- }
- }
- if ( item )
- item.focus();
- return false;
- case rightKeyCode:
- next = item;
- do {
-
- next = next.next;
-
- if ( !next && toolbarGroupCycling ) next = item.toolbar.items[ 0 ];
- }
- while ( next && !next.focus );
-
-
- if ( next )
- next.focus();
- else
-
- itemKeystroke( item, 9 );
- return false;
- case 40:
- if ( item.button && item.button.hasArrow ) {
-
- editor.once( 'panelShow', function( evt ) {
- evt.data._.panel._.currentBlock.onKeyDown( 40 );
- } );
- item.execute();
- } else {
-
- itemKeystroke( item, keystroke == 40 ? rightKeyCode : leftKeyCode );
- }
- return false;
- case leftKeyCode:
- case 38:
- next = item;
- do {
-
- next = next.previous;
-
- if ( !next && toolbarGroupCycling ) next = item.toolbar.items[ item.toolbar.items.length - 1 ];
- }
- while ( next && !next.focus );
-
-
- if ( next )
- next.focus();
- else {
- endFlag = 1;
-
- itemKeystroke( item, CKEDITOR.SHIFT + 9 );
- endFlag = 0;
- }
- return false;
- case 27:
- editor.focus();
- return false;
- case 13:
- case 32:
- item.execute();
- return false;
- }
- return true;
- };
- editor.on( 'uiSpace', function( event ) {
- if ( event.data.space != editor.config.toolbarLocation )
- return;
-
- event.removeListener();
- editor.toolbox = new toolbox();
- var labelId = CKEDITOR.tools.getNextId();
- var output = [
- '<span id="', labelId, '" class="cke_voice_label">', editor.lang.toolbar.toolbars, '</span>',
- '<span id="' + editor.ui.spaceId( 'toolbox' ) + '" class="cke_toolbox" role="group" aria-labelledby="', labelId, '" onmousedown="return false;">' ];
- var expanded = editor.config.toolbarStartupExpanded !== false,
- groupStarted, pendingSeparator;
-
-
- if ( editor.config.toolbarCanCollapse && editor.elementMode != CKEDITOR.ELEMENT_MODE_INLINE )
- output.push( '<span class="cke_toolbox_main"' + ( expanded ? '>' : ' style="display:none">' ) );
- var toolbars = editor.toolbox.toolbars,
- toolbar = getToolbarConfig( editor );
- for ( var r = 0; r < toolbar.length; r++ ) {
- var toolbarId,
- toolbarObj = 0,
- toolbarName,
- row = toolbar[ r ],
- items;
-
-
-
-
-
- if ( !row )
- continue;
- if ( groupStarted ) {
- output.push( '</span>' );
- groupStarted = 0;
- pendingSeparator = 0;
- }
- if ( row === '/' ) {
- output.push( '<span class="cke_toolbar_break"></span>' );
- continue;
- }
- items = row.items || row;
-
- for ( var i = 0; i < items.length; i++ ) {
- var item = items[ i ],
- canGroup;
- if ( item ) {
- if ( item.type == CKEDITOR.UI_SEPARATOR ) {
-
-
-
- pendingSeparator = groupStarted && item;
- continue;
- }
- canGroup = item.canGroup !== false;
-
- if ( !toolbarObj ) {
-
- toolbarId = CKEDITOR.tools.getNextId();
- toolbarObj = { id: toolbarId, items: [] };
- toolbarName = row.name && ( editor.lang.toolbar.toolbarGroups[ row.name ] || row.name );
-
- output.push( '<span id="', toolbarId, '" class="cke_toolbar"', ( toolbarName ? ' aria-labelledby="' + toolbarId + '_label"' : '' ), ' role="toolbar">' );
-
- toolbarName && output.push( '<span id="', toolbarId, '_label" class="cke_voice_label">', toolbarName, '</span>' );
- output.push( '<span class="cke_toolbar_start"></span>' );
-
-
- var index = toolbars.push( toolbarObj ) - 1;
-
- if ( index > 0 ) {
- toolbarObj.previous = toolbars[ index - 1 ];
- toolbarObj.previous.next = toolbarObj;
- }
- }
- if ( canGroup ) {
- if ( !groupStarted ) {
- output.push( '<span class="cke_toolgroup" role="presentation">' );
- groupStarted = 1;
- }
- } else if ( groupStarted ) {
- output.push( '</span>' );
- groupStarted = 0;
- }
- function addItem( item ) {
- var itemObj = item.render( editor, output );
- index = toolbarObj.items.push( itemObj ) - 1;
- if ( index > 0 ) {
- itemObj.previous = toolbarObj.items[ index - 1 ];
- itemObj.previous.next = itemObj;
- }
- itemObj.toolbar = toolbarObj;
- itemObj.onkey = itemKeystroke;
-
-
- itemObj.onfocus = function() {
- if ( !editor.toolbox.focusCommandExecuted )
- editor.focus();
- };
- }
- if ( pendingSeparator ) {
- addItem( pendingSeparator );
- pendingSeparator = 0;
- }
- addItem( item );
- }
- }
- if ( groupStarted ) {
- output.push( '</span>' );
- groupStarted = 0;
- pendingSeparator = 0;
- }
- if ( toolbarObj )
- output.push( '<span class="cke_toolbar_end"></span></span>' );
- }
- if ( editor.config.toolbarCanCollapse )
- output.push( '</span>' );
-
- if ( editor.config.toolbarCanCollapse && editor.elementMode != CKEDITOR.ELEMENT_MODE_INLINE ) {
- var collapserFn = CKEDITOR.tools.addFunction( function() {
- editor.execCommand( 'toolbarCollapse' );
- } );
- editor.on( 'destroy', function() {
- CKEDITOR.tools.removeFunction( collapserFn );
- } );
- editor.addCommand( 'toolbarCollapse', {
- readOnly: 1,
- exec: function( editor ) {
- var collapser = editor.ui.space( 'toolbar_collapser' ),
- toolbox = collapser.getPrevious(),
- contents = editor.ui.space( 'contents' ),
- toolboxContainer = toolbox.getParent(),
- contentHeight = parseInt( contents.$.style.height, 10 ),
- previousHeight = toolboxContainer.$.offsetHeight,
- minClass = 'cke_toolbox_collapser_min',
- collapsed = collapser.hasClass( minClass );
- if ( !collapsed ) {
- toolbox.hide();
- collapser.addClass( minClass );
- collapser.setAttribute( 'title', editor.lang.toolbar.toolbarExpand );
- } else {
- toolbox.show();
- collapser.removeClass( minClass );
- collapser.setAttribute( 'title', editor.lang.toolbar.toolbarCollapse );
- }
-
- collapser.getFirst().setText( collapsed ? '\u25B2' :
- '\u25C0' );
- var dy = toolboxContainer.$.offsetHeight - previousHeight;
- contents.setStyle( 'height', ( contentHeight - dy ) + 'px' );
- editor.fire( 'resize' );
- },
- modes: { wysiwyg: 1, source: 1 }
- } );
- editor.setKeystroke( CKEDITOR.ALT + ( CKEDITOR.env.ie || CKEDITOR.env.webkit ? 189 : 109 ) , 'toolbarCollapse' );
- output.push( '<a title="' + ( expanded ? editor.lang.toolbar.toolbarCollapse : editor.lang.toolbar.toolbarExpand )
- + '" id="' + editor.ui.spaceId( 'toolbar_collapser' )
- + '" tabIndex="-1" class="cke_toolbox_collapser' );
- if ( !expanded )
- output.push( ' cke_toolbox_collapser_min' );
- output.push( '" onclick="CKEDITOR.tools.callFunction(' + collapserFn + ')">', '<span class="cke_arrow">▲</span>',
- '</a>' );
- }
- output.push( '</span>' );
- event.data.html += output.join( '' );
- } );
- editor.on( 'destroy', function() {
- if ( this.toolbox )
- {
- var toolbars,
- index = 0,
- i, items, instance;
- toolbars = this.toolbox.toolbars;
- for ( ; index < toolbars.length; index++ ) {
- items = toolbars[ index ].items;
- for ( i = 0; i < items.length; i++ ) {
- instance = items[ i ];
- if ( instance.clickFn )
- CKEDITOR.tools.removeFunction( instance.clickFn );
- if ( instance.keyDownFn )
- CKEDITOR.tools.removeFunction( instance.keyDownFn );
- }
- }
- }
- } );
-
- editor.on( 'uiReady', function() {
- var toolbox = editor.ui.space( 'toolbox' );
- toolbox && editor.focusManager.add( toolbox, 1 );
- } );
- editor.addCommand( 'toolbarFocus', commands.toolbarFocus );
- editor.setKeystroke( CKEDITOR.ALT + 121 , 'toolbarFocus' );
- editor.ui.add( '-', CKEDITOR.UI_SEPARATOR, {} );
- editor.ui.addHandler( CKEDITOR.UI_SEPARATOR, {
- create: function() {
- return {
- render: function( editor, output ) {
- output.push( '<span class="cke_toolbar_separator" role="separator"></span>' );
- return {};
- }
- };
- }
- } );
- }
- } );
- function getToolbarConfig( editor ) {
- var removeButtons = editor.config.removeButtons;
- removeButtons = removeButtons && removeButtons.split( ',' );
- function buildToolbarConfig() {
-
- var lookup = getItemDefinedGroups();
-
-
- var toolbar = CKEDITOR.tools.clone( editor.config.toolbarGroups ) || getPrivateToolbarGroups( editor );
-
- for ( var i = 0; i < toolbar.length; i++ ) {
- var toolbarGroup = toolbar[ i ];
-
- if ( toolbarGroup == '/' )
- continue;
-
- else if ( typeof toolbarGroup == 'string' )
- toolbarGroup = toolbar[ i ] = { name: toolbarGroup };
- var items, subGroups = toolbarGroup.groups;
-
- if ( subGroups ) {
- for ( var j = 0, sub; j < subGroups.length; j++ ) {
- sub = subGroups[ j ];
-
- items = lookup[ sub ];
- items && fillGroup( toolbarGroup, items );
- }
- }
-
- items = lookup[ toolbarGroup.name ];
- items && fillGroup( toolbarGroup, items );
- }
- return toolbar;
- }
-
- function getItemDefinedGroups() {
- var groups = {},
- itemName, item, itemToolbar, group, order;
- for ( itemName in editor.ui.items ) {
- item = editor.ui.items[ itemName ];
- itemToolbar = item.toolbar || 'others';
- if ( itemToolbar ) {
-
- itemToolbar = itemToolbar.split( ',' );
- group = itemToolbar[ 0 ];
- order = parseInt( itemToolbar[ 1 ] || -1, 10 );
-
- groups[ group ] || ( groups[ group ] = [] );
-
- groups[ group ].push( { name: itemName, order: order } );
- }
- }
-
- for ( group in groups ) {
- groups[ group ] = groups[ group ].sort( function( a, b ) {
- return a.order == b.order ? 0 :
- b.order < 0 ? -1 :
- a.order < 0 ? 1 :
- a.order < b.order ? -1 :
- 1;
- } );
- }
- return groups;
- }
- function fillGroup( toolbarGroup, uiItems ) {
- if ( uiItems.length ) {
- if ( toolbarGroup.items )
- toolbarGroup.items.push( editor.ui.create( '-' ) );
- else
- toolbarGroup.items = [];
- var item, name;
- while ( ( item = uiItems.shift() ) ) {
- name = typeof item == 'string' ? item : item.name;
-
- if ( !removeButtons || CKEDITOR.tools.indexOf( removeButtons, name ) == -1 ) {
- item = editor.ui.create( name );
- if ( !item )
- continue;
- if ( !editor.addFeature( item ) )
- continue;
- toolbarGroup.items.push( item );
- }
- }
- }
- }
- function populateToolbarConfig( config ) {
- var toolbar = [],
- i, group, newGroup;
- for ( i = 0; i < config.length; ++i ) {
- group = config[ i ];
- newGroup = {};
- if ( group == '/' )
- toolbar.push( group );
- else if ( CKEDITOR.tools.isArray( group ) ) {
- fillGroup( newGroup, CKEDITOR.tools.clone( group ) );
- toolbar.push( newGroup );
- }
- else if ( group.items ) {
- fillGroup( newGroup, CKEDITOR.tools.clone( group.items ) );
- newGroup.name = group.name;
- toolbar.push( newGroup );
- }
- }
- return toolbar;
- }
- var toolbar = editor.config.toolbar;
-
- if ( typeof toolbar == 'string' )
- toolbar = editor.config[ 'toolbar_' + toolbar ];
- return ( editor.toolbar = toolbar ? populateToolbarConfig( toolbar ) : buildToolbarConfig() );
- }
-
- CKEDITOR.ui.prototype.addToolbarGroup = function( name, previous, subgroupOf ) {
-
- var toolbarGroups = getPrivateToolbarGroups( this.editor ),
- atStart = previous === 0,
- newGroup = { name: name };
- if ( subgroupOf ) {
-
- subgroupOf = CKEDITOR.tools.search( toolbarGroups, function( group ) {
- return group.name == subgroupOf;
- } );
- if ( subgroupOf ) {
- !subgroupOf.groups && ( subgroupOf.groups = [] ) ;
- if ( previous ) {
-
- previous = CKEDITOR.tools.indexOf( subgroupOf.groups, previous );
- if ( previous >= 0 ) {
- subgroupOf.groups.splice( previous + 1, 0, name );
- return;
- }
- }
-
- if ( atStart )
- subgroupOf.groups.splice( 0, 0, name );
- else
- subgroupOf.groups.push( name );
- return;
- } else {
-
- previous = null;
- }
- }
- if ( previous ) {
-
- previous = CKEDITOR.tools.indexOf( toolbarGroups, function( group ) {
- return group.name == previous;
- } );
- }
- if ( atStart )
- toolbarGroups.splice( 0, 0, name );
- else if ( typeof previous == 'number' )
- toolbarGroups.splice( previous + 1, 0, newGroup );
- else
- toolbarGroups.push( name );
- };
- function getPrivateToolbarGroups( editor ) {
- return editor._.toolbarGroups || ( editor._.toolbarGroups = [
- { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
- { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
- { name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ] },
- { name: 'forms' },
- '/',
- { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
- { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
- { name: 'links' },
- { name: 'insert' },
- '/',
- { name: 'styles' },
- { name: 'colors' },
- { name: 'tools' },
- { name: 'others' },
- { name: 'about' }
- ] );
- }
- } )();
- CKEDITOR.UI_SEPARATOR = 'separator';
- CKEDITOR.config.toolbarLocation = 'top';
|