2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
6 CKEDITOR
.plugins
.add( 'listblock',
8 requires
: [ 'panel' ],
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
);
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
= [];
52 this._
.pendingHtml
.push( '</ul>' );
53 delete this._
.started
;
61 this._
.click
= CKEDITOR
.tools
.addFunction( function( value
)
65 if ( this.multiSelect
)
66 marked
= this.toggle( value
);
71 this.onClick( value
, marked
);
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>' );
90 this._
.size
= this._
.size
|| 0;
93 this._
.items
[ value
] = id
;
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;"',
102 ' aria-posinset="' + ++this._
.size
+ '">',
108 startGroup : function( title
)
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>' );
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
);
130 this._
.pendingHtml
= [];
133 toggle : function( value
)
135 var isMarked
= this.isMarked( value
);
138 this.unmark( value
);
145 hideGroup : function( groupTitle
)
147 var group
= this.element
.getDocument().getById( this._
.groups
[ groupTitle
] ),
148 list
= group
&& group
.getNext();
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' );
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
)
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;
232 var selected
= this.element
.getDocument().getById( this._
.items
[ value
] ).getFirst();
234 var links
= this.element
.getElementsByTag( 'a' ),
238 while ( ( link
= links
.getItem( ++i
) ) )
240 if ( link
.equals( selected
) )
242 this._
.focusIndex
= i
;
247 setTimeout( function()