CKEDITOR.plugins.add('listblock',{requires:['panel'],onLoad:function(){CKEDITOR.ui.panel.prototype.addListBlock=function(a,b){return this.addBlock(a,new CKEDITOR.ui.listBlock(this.getHolderElement(),b));};CKEDITOR.ui.listBlock=CKEDITOR.tools.createClass({base:CKEDITOR.ui.panel.block,$:function(a,b){var e=this;b=b||{};var c=b.attributes||(b.attributes={});(e.multiSelect=!!b.multiSelect)&&(c['aria-multiselectable']=true);!c.role&&(c.role='listbox');e.base.apply(e,arguments);var d=e.keys;d[40]='next';d[9]='next';d[38]='prev';d[CKEDITOR.SHIFT+9]='prev';d[32]='click';e._.pendingHtml=[];e._.items={};e._.groups={};},_:{close:function(){if(this._.started){this._.pendingHtml.push('</ul>');delete this._.started;}},getClick:function(){if(!this._.click)this._.click=CKEDITOR.tools.addFunction(function(a){var c=this;var b=true;if(c.multiSelect)b=c.toggle(a);else c.mark(a);if(c.onClick)c.onClick(a,b);},this);return this._.click;}},proto:{add:function(a,b,c){var f=this;var d=f._.pendingHtml,e='cke_'+CKEDITOR.tools.getNextNumber();if(!f._.started){d.push('<ul role="presentation" class=cke_panel_list>');f._.started=1;f._.size=f._.size||0;}f._.items[a]=e;d.push('<li id=',e,' class=cke_panel_listItem><a id="',e,'_option" _cke_focus=1 hidefocus=true title="',c||a,'" href="javascript:void(\'',a,'\')" onclick="CKEDITOR.tools.callFunction(',f._.getClick(),",'",a,"'); return false;\"",' role="option" aria-posinset="'+ ++f._.size+'">',b||a,'</a></li>');},startGroup:function(a){this._.close();var b='cke_'+CKEDITOR.tools.getNextNumber();this._.groups[a]=b;this._.pendingHtml.push('<h1 role="presentation" id=',b,' class=cke_panel_grouptitle>',a,'</h1>');},commit:function(){var d=this;d._.close();d.element.appendHtml(d._.pendingHtml.join(''));var a=d._.items,b=d.element.getDocument();for(var c in a)b.getById(a[c]+'_option').setAttribute('aria-setsize',d._.size);delete d._.size;d._.pendingHtml=[];},toggle:function(a){var b=this.isMarked(a);if(b)this.unmark(a);else this.mark(a);return!b;},hideGroup:function(a){var b=this.element.getDocument().getById(this._.groups[a]),c=b&&b.getNext();if(b){b.setStyle('display','none');if(c&&c.getName()=='ul')c.setStyle('display','none');}},hideItem:function(a){this.element.getDocument().getById(this._.items[a]).setStyle('display','none');},showAll:function(){var a=this._.items,b=this._.groups,c=this.element.getDocument();for(var d in a)c.getById(a[d]).setStyle('display','');for(var e in b){var f=c.getById(b[e]),g=f.getNext();f.setStyle('display','');if(g&&g.getName()=='ul')g.setStyle('display','');
}},mark:function(a){var d=this;if(!d.multiSelect)d.unmarkAll();var b=d._.items[a],c=d.element.getDocument().getById(b);c.addClass('cke_selected');d.element.getDocument().getById(b+'_option').setAttribute('aria-selected',true);d.element.setAttribute('aria-activedescendant',b+'_option');d.onMark&&d.onMark(c);},unmark:function(a){var b=this;b.element.getDocument().getById(b._.items[a]).removeClass('cke_selected');b.onUnmark&&b.onUnmark(b._.items[a]);},unmarkAll:function(){var d=this;var a=d._.items,b=d.element.getDocument();for(var c in a)b.getById(a[c]).removeClass('cke_selected');d.onUnmark&&d.onUnmark();},isMarked:function(a){return this.element.getDocument().getById(this._.items[a]).hasClass('cke_selected');},focus:function(a){this._.focusIndex=-1;if(a){var b=this.element.getDocument().getById(this._.items[a]).getFirst(),c=this.element.getElementsByTag('a'),d,e=-1;while(d=c.getItem(++e)){if(d.equals(b)){this._.focusIndex=e;break;}}setTimeout(function(){b.focus();},0);}}}});}});
