Update ckeditor to version 3.2.1
[gopost.git] / ckeditor / _source / plugins / listblock / plugin.js
blob63f85c72bafa1696683324a088fb606c3d433f21
1 /*
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
6 CKEDITOR.plugins.add( 'listblock',
8 requires : [ 'panel' ],
10 onLoad : function()
12 CKEDITOR.ui.panel.prototype.addListBlock = function( name, definition )
14 return this.addBlock( name, new CKEDITOR.ui.listBlock( this.getHolderElement(), definition ) );
17 CKEDITOR.ui.listBlock = CKEDITOR.tools.createClass(
19 base : CKEDITOR.ui.panel.block,
21 $ : function( blockHolder, blockDefinition )
23 blockDefinition = blockDefinition || {};
25 var attribs = blockDefinition.attributes || ( blockDefinition.attributes = {} );
26 ( this.multiSelect = !!blockDefinition.multiSelect ) &&
27 ( attribs[ 'aria-multiselectable' ] = true );
28 // Provide default role of 'listbox'.
29 !attribs.role && ( attribs.role = 'listbox' );
31 // Call the base contructor.
32 this.base.apply( this, arguments );
34 var keys = this.keys;
35 keys[ 40 ] = 'next'; // ARROW-DOWN
36 keys[ 9 ] = 'next'; // TAB
37 keys[ 38 ] = 'prev'; // ARROW-UP
38 keys[ CKEDITOR.SHIFT + 9 ] = 'prev'; // SHIFT + TAB
39 keys[ 32 ] = 'click'; // SPACE
41 this._.pendingHtml = [];
42 this._.items = {};
43 this._.groups = {};
46 _ :
48 close : function()
50 if ( this._.started )
52 this._.pendingHtml.push( '</ul>' );
53 delete this._.started;
57 getClick : function()
59 if ( !this._.click )
61 this._.click = CKEDITOR.tools.addFunction( function( value )
63 var marked = true;
65 if ( this.multiSelect )
66 marked = this.toggle( value );
67 else
68 this.mark( value );
70 if ( this.onClick )
71 this.onClick( value, marked );
73 this );
75 return this._.click;
79 proto :
81 add : function( value, html, title )
83 var pendingHtml = this._.pendingHtml,
84 id = 'cke_' + CKEDITOR.tools.getNextNumber();
86 if ( !this._.started )
88 pendingHtml.push( '<ul role="presentation" class=cke_panel_list>' );
89 this._.started = 1;
90 this._.size = this._.size || 0;
93 this._.items[ value ] = id;
95 pendingHtml.push(
96 '<li id=', id, ' class=cke_panel_listItem>' +
97 '<a id="', id, '_option" _cke_focus=1 hidefocus=true' +
98 ' title="', title || value, '"' +
99 ' href="javascript:void(\'', value, '\')"' +
100 ' onclick="CKEDITOR.tools.callFunction(', this._.getClick(), ',\'', value, '\'); return false;"',
101 ' role="option"' +
102 ' aria-posinset="' + ++this._.size + '">',
103 html || value,
104 '</a>' +
105 '</li>' );
108 startGroup : function( title )
110 this._.close();
112 var id = 'cke_' + CKEDITOR.tools.getNextNumber();
114 this._.groups[ title ] = id;
116 this._.pendingHtml.push( '<h1 role="presentation" id=', id, ' class=cke_panel_grouptitle>', title, '</h1>' );
119 commit : function()
121 this._.close();
122 this.element.appendHtml( this._.pendingHtml.join( '' ) );
124 var items = this._.items,
125 doc = this.element.getDocument();
126 for ( var value in items )
127 doc.getById( items[ value ] + '_option' ).setAttribute( 'aria-setsize', this._.size );
128 delete this._.size;
130 this._.pendingHtml = [];
133 toggle : function( value )
135 var isMarked = this.isMarked( value );
137 if ( isMarked )
138 this.unmark( value );
139 else
140 this.mark( value );
142 return !isMarked;
145 hideGroup : function( groupTitle )
147 var group = this.element.getDocument().getById( this._.groups[ groupTitle ] ),
148 list = group && group.getNext();
150 if ( group )
152 group.setStyle( 'display', 'none' );
154 if ( list && list.getName() == 'ul' )
155 list.setStyle( 'display', 'none' );
159 hideItem : function( value )
161 this.element.getDocument().getById( this._.items[ value ] ).setStyle( 'display', 'none' );
164 showAll : function()
166 var items = this._.items,
167 groups = this._.groups,
168 doc = this.element.getDocument();
170 for ( var value in items )
172 doc.getById( items[ value ] ).setStyle( 'display', '' );
175 for ( var title in groups )
177 var group = doc.getById( groups[ title ] ),
178 list = group.getNext();
180 group.setStyle( 'display', '' );
182 if ( list && list.getName() == 'ul' )
183 list.setStyle( 'display', '' );
187 mark : function( value )
189 if ( !this.multiSelect )
190 this.unmarkAll();
192 var itemId = this._.items[ value ],
193 item = this.element.getDocument().getById( itemId );
194 item.addClass( 'cke_selected' );
196 this.element.getDocument().getById( itemId + '_option' ).setAttribute( 'aria-selected', true );
197 this.element.setAttribute( 'aria-activedescendant', itemId + '_option' );
199 this.onMark && this.onMark( item );
202 unmark : function( value )
204 this.element.getDocument().getById( this._.items[ value ] ).removeClass( 'cke_selected' );
205 this.onUnmark && this.onUnmark( this._.items[ value ] );
208 unmarkAll : function()
210 var items = this._.items,
211 doc = this.element.getDocument();
213 for ( var value in items )
215 doc.getById( items[ value ] ).removeClass( 'cke_selected' );
218 this.onUnmark && this.onUnmark();
221 isMarked : function( value )
223 return this.element.getDocument().getById( this._.items[ value ] ).hasClass( 'cke_selected' );
226 focus : function( value )
228 this._.focusIndex = -1;
230 if ( value )
232 var selected = this.element.getDocument().getById( this._.items[ value ] ).getFirst();
234 var links = this.element.getElementsByTag( 'a' ),
235 link,
236 i = -1;
238 while ( ( link = links.getItem( ++i ) ) )
240 if ( link.equals( selected ) )
242 this._.focusIndex = i;
243 break;
247 setTimeout( function()
249 selected.focus();
251 0 );