/* Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ CKEDITOR.plugins.add('button',{beforeInit:function(a){a.ui.addHandler(CKEDITOR.UI_BUTTON,CKEDITOR.ui.button.handler);}});CKEDITOR.UI_BUTTON=1;CKEDITOR.ui.button=function(a){CKEDITOR.tools.extend(this,a,{title:a.label,className:a.className||a.command&&'cke_button_'+a.command||'',click:a.click||(function(b){b.execCommand(a.command);})});this._={};};CKEDITOR.ui.button.handler={create:function(a){return new CKEDITOR.ui.button(a);}};CKEDITOR.ui.button.prototype={canGroup:true,render:function(a,b){var c=CKEDITOR.env,d=this._.id='cke_'+CKEDITOR.tools.getNextNumber();this._.editor=a;var e={id:d,button:this,editor:a,focus:function(){var k=CKEDITOR.document.getById(d);k.focus();},execute:function(){this.button.click(a);}},f=CKEDITOR.tools.addFunction(e.execute,e),g=CKEDITOR.ui.button._.instances.push(e)-1,h='',i=this.command;if(this.modes)a.on('mode',function(){this.setState(this.modes[a.mode]?CKEDITOR.TRISTATE_OFF:CKEDITOR.TRISTATE_DISABLED);},this);else if(i){i=a.getCommand(i);if(i){i.on('state',function(){this.setState(i.state);},this);h+='cke_'+(i.state==CKEDITOR.TRISTATE_ON?'on':i.state==CKEDITOR.TRISTATE_DISABLED?'disabled':'off');}}if(!i)h+='cke_off';if(this.className)h+=' '+this.className;b.push('','',this.label,'');if(this.hasArrow)b.push('');b.push('','');if(this.onRender)this.onRender();return e;},setState:function(a){var f=this;if(f._.state==a)return;var b=CKEDITOR.document.getById(f._.id);if(b){b.setState(a);var c=f.title,d=f._.editor.lang.common.unavailable,e=b.getChild(1);if(a==CKEDITOR.TRISTATE_DISABLED)c=d.replace('%1',f.title);e.setHtml(c);}f._.state=a;}};CKEDITOR.ui.button._={instances:[],keydown:function(a,b){var c=CKEDITOR.ui.button._.instances[a];if(c.onkey){b=new CKEDITOR.dom.event(b); return c.onkey(c,b.getKeystroke())!==false;}},focus:function(a,b){var c=CKEDITOR.ui.button._.instances[a],d;if(c.onfocus)d=c.onfocus(c,new CKEDITOR.dom.event(b))!==false;if(CKEDITOR.env.gecko&&CKEDITOR.env.version<10900)b.preventBubble();return d;}};CKEDITOR.ui.prototype.addButton=function(a,b){this.add(a,CKEDITOR.UI_BUTTON,b);};