2 Copyright (c) 2003-2011, 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 ] = CKEDITOR
.env
.ie
? 'mouseup' : 'click'; // SPACE
40 CKEDITOR
.env
.ie
&& ( keys
[ 13 ] = 'mouseup' ); // Manage ENTER, since onclick is blocked in IE (#8041).
42 this._
.pendingHtml
= [];
53 this._
.pendingHtml
.push( '</ul>' );
54 delete this._
.started
;
62 this._
.click
= CKEDITOR
.tools
.addFunction( function( value
)
66 if ( this.multiSelect
)
67 marked
= this.toggle( value
);
72 this.onClick( value
, marked
);
82 add : function( value
, html
, title
)
84 var pendingHtml
= this._
.pendingHtml
,
85 id
= CKEDITOR
.tools
.getNextId();
87 if ( !this._
.started
)
89 pendingHtml
.push( '<ul role="presentation" class=cke_panel_list>' );
91 this._
.size
= this._
.size
|| 0;
94 this._
.items
[ value
] = id
;
97 '<li id=', id
, ' class=cke_panel_listItem role=presentation>' +
98 '<a id="', id
, '_option" _cke_focus=1 hidefocus=true' +
99 ' title="', title
|| value
, '"' +
100 ' href="javascript:void(\'', value
, '\')" ' +
101 ( CKEDITOR
.env
.ie
? 'onclick="return false;" onmouseup' : 'onclick' ) + // #188
102 '="CKEDITOR.tools.callFunction(', this._
.getClick(), ',\'', value
, '\'); return false;"',
104 ' aria-posinset="' + ++this._
.size
+ '">',
110 startGroup : function( title
)
114 var id
= CKEDITOR
.tools
.getNextId();
116 this._
.groups
[ title
] = id
;
118 this._
.pendingHtml
.push( '<h1 role="presentation" id=', id
, ' class=cke_panel_grouptitle>', title
, '</h1>' );
124 this.element
.appendHtml( this._
.pendingHtml
.join( '' ) );
126 var items
= this._
.items
,
127 doc
= this.element
.getDocument();
128 for ( var value
in items
)
129 doc
.getById( items
[ value
] + '_option' ).setAttribute( 'aria-setsize', this._
.size
);
132 this._
.pendingHtml
= [];
135 toggle : function( value
)
137 var isMarked
= this.isMarked( value
);
140 this.unmark( value
);
147 hideGroup : function( groupTitle
)
149 var group
= this.element
.getDocument().getById( this._
.groups
[ groupTitle
] ),
150 list
= group
&& group
.getNext();
154 group
.setStyle( 'display', 'none' );
156 if ( list
&& list
.getName() == 'ul' )
157 list
.setStyle( 'display', 'none' );
161 hideItem : function( value
)
163 this.element
.getDocument().getById( this._
.items
[ value
] ).setStyle( 'display', 'none' );
168 var items
= this._
.items
,
169 groups
= this._
.groups
,
170 doc
= this.element
.getDocument();
172 for ( var value
in items
)
174 doc
.getById( items
[ value
] ).setStyle( 'display', '' );
177 for ( var title
in groups
)
179 var group
= doc
.getById( groups
[ title
] ),
180 list
= group
.getNext();
182 group
.setStyle( 'display', '' );
184 if ( list
&& list
.getName() == 'ul' )
185 list
.setStyle( 'display', '' );
189 mark : function( value
)
191 if ( !this.multiSelect
)
194 var itemId
= this._
.items
[ value
],
195 item
= this.element
.getDocument().getById( itemId
);
196 item
.addClass( 'cke_selected' );
198 this.element
.getDocument().getById( itemId
+ '_option' ).setAttribute( 'aria-selected', true );
199 this.element
.setAttribute( 'aria-activedescendant', itemId
+ '_option' );
201 this.onMark
&& this.onMark( item
);
204 unmark : function( value
)
206 var doc
= this.element
.getDocument(),
207 itemId
= this._
.items
[ value
],
208 item
= doc
.getById( itemId
);
210 item
.removeClass( 'cke_selected' );
211 doc
.getById( itemId
+ '_option' ).removeAttribute( 'aria-selected' );
213 this.onUnmark
&& this.onUnmark( item
);
216 unmarkAll : function()
218 var items
= this._
.items
,
219 doc
= this.element
.getDocument();
221 for ( var value
in items
)
223 var itemId
= items
[ value
];
225 doc
.getById( itemId
).removeClass( 'cke_selected' );
226 doc
.getById( itemId
+ '_option' ).removeAttribute( 'aria-selected' );
229 this.onUnmark
&& this.onUnmark();
232 isMarked : function( value
)
234 return this.element
.getDocument().getById( this._
.items
[ value
] ).hasClass( 'cke_selected' );
237 focus : function( value
)
239 this._
.focusIndex
= -1;
243 var selected
= this.element
.getDocument().getById( this._
.items
[ value
] ).getFirst();
245 var links
= this.element
.getElementsByTag( 'a' ),
249 while ( ( link
= links
.getItem( ++i
) ) )
251 if ( link
.equals( selected
) )
253 this._
.focusIndex
= i
;
258 setTimeout( function()