HTMLArea.TYPO3Color=HTMLArea.Plugin.extend({constructor:function(editor,pluginName){this.base(editor,pluginName);},configurePlugin:function(editor){this.buttonsConfiguration=this.editorConfiguration.buttons;this.colorsConfiguration=this.editorConfiguration.colors;this.disableColorPicker=this.editorConfiguration.disableColorPicker;if(this.editor.plugins.TextStyle&&this.editor.plugins.TextStyle.instance){this.editor.plugins.TextStyle.instance.addAllowedAttribute('style');this.allowedAttributes=this.editor.plugins.TextStyle.instance.allowedAttributes;}
if(this.editor.plugins.InlineElements&&this.editor.plugins.InlineElements.instance){this.editor.plugins.InlineElements.instance.addAllowedAttribute('style');if(!this.allowedAllowedAttributes){this.allowedAttributes=this.editor.plugins.InlineElements.instance.allowedAttributes;}}
if(this.editor.plugins.BlockElements&&this.editor.plugins.BlockElements.instance){this.editor.plugins.BlockElements.instance.addAllowedAttribute('style');}
if(!this.allowedAttributes){this.allowedAttributes=new Array('id','title','lang','xml:lang','dir','class','style');if(Ext.isIE){this.allowedAttributes.push('className');}}
var pluginInformation={version:'4.1',developer:'Stanislas Rolland',developerUrl:'http://www.sjbr.ca/',copyrightOwner:'Stanislas Rolland',sponsor:'SJBR',sponsorUrl:'http://www.sjbr.ca/',license:'GPL'};this.registerPluginInformation(pluginInformation);var buttonList=this.buttonList,buttonId;for(var i=0;i {0}'),allowReselect:true,listeners:{select:{fn:this.onSelect,scope:this}}}});}
itemsConfig.push({xtype:'container',layout:'hbox',items:paletteItems});itemsConfig.push({xtype:'displayfield',itemId:'show-color',cls:'show-color',width:60,height:22,helpTitle:this.localize(buttonId)});itemsConfig.push({itemId:'color',cls:'color',width:60,minValue:0,value:(element&&element.style[this.styleProperty[buttonId]])?HTMLArea.util.Color.colorToHex(element.style[this.styleProperty[buttonId]]).substr(1,6):'',enableKeyEvents:true,fieldLabel:this.localize(buttonId),helpTitle:this.localize(buttonId),listeners:{change:{fn:this.onChange,scope:this},afterrender:{fn:this.onAfterRender,scope:this}}});return{xtype:'fieldset',title:this.localize('color_title'),defaultType:'textfield',labelWidth:175,defaults:{helpIcon:false},items:itemsConfig};},onSelect:function(palette,color){this.dialog.find('itemId','color')[0].setValue(color);this.showColor(color);if(palette.getItemId()=='color-palette'){var customPalette=this.dialog.find('itemId','custom-colors')[0];if(customPalette){customPalette.deSelect();}}else{var standardPalette=this.dialog.find('itemId','color-palette')[0];if(standardPalette){standardPalette.deSelect();}}},showColor:function(color){if(color){var newColor=color;if(newColor.indexOf('#')==0){newColor=newColor.substr(1);}
this.dialog.find('itemId','show-color')[0].el.setStyle('backgroundColor',HTMLArea.util.Color.colorToHex(parseInt(newColor,16)));}},onChange:function(field,value){if(value){var color=value.toUpperCase();this.showColor(color);var standardPalette=this.dialog.find('itemId','color-palette')[0];if(standardPalette){standardPalette.select(color);}
var customPalette=this.dialog.find('itemId','custom-colors')[0];if(customPalette){customPalette.select(color);}}},onAfterRender:function(field){if(!Ext.isEmpty(field.getValue())){this.showColor(field.getValue());}},openDialogue:function(title,arguments,dimensions,items,handler){if(this.dialog){this.dialog.close();}
this.dialog=new Ext.Window({title:this.localize(title),arguments:arguments,cls:'htmlarea-window',border:false,width:dimensions.width,height:dimensions.height,autoScroll:true,resizable:!Ext.isIE,iconCls:this.getButton(arguments.buttonId).iconCls,listeners:{close:{fn:this.onClose,scope:this}},items:{xtype:'container',layout:'form',style:{width:'95%'},defaults:{labelWidth:150},items:items},buttons:[this.buildButtonConfig('OK',handler),this.buildButtonConfig('Cancel',this.onCancel)]});this.show();},setColor:function(button,event){this.restoreSelection();var buttonId=this.dialog.arguments.buttonId;var color=this.dialog.find('itemId','color')[0].getValue();if(color){if(color.indexOf('#')==0){color=color.substr(1);}
color=HTMLArea.util.Color.colorToHex(parseInt(color,16));}
this.editor.focus();var element,fullNodeSelected=false;var selection=this.editor._getSelection();var range=this.editor._createRange(selection);var parent=this.editor.getParentElement(selection,range);var selectionEmpty=this.editor._selectionEmpty(selection);var statusBarSelection=this.editor.statusBar?this.editor.statusBar.getSelection():null;if(!selectionEmpty){var ancestors=this.editor.getAllAncestors();var fullySelectedNode=this.editor.getFullySelectedNode(selection,range,ancestors);if(fullySelectedNode){fullNodeSelected=true;parent=fullySelectedNode;}}
if(selectionEmpty||fullNodeSelected){element=parent;element.style[this.styleProperty[buttonId]]=color;if((element.nodeName.toLowerCase()==='span')&&!HTMLArea.hasAllowedAttributes(element,this.allowedAttributes)){this.editor.removeMarkup(element);}}else if(statusBarSelection){var element=statusBarSelection;element.style[this.styleProperty[buttonId]]=color;if((element.nodeName.toLowerCase()==='span')&&!HTMLArea.hasAllowedAttributes(element,this.allowedAttributes)){this.editor.removeMarkup(element);}}else if(color&&this.editor.endPointsInSameBlock()){var element=this.editor._doc.createElement('span');element.style[this.styleProperty[buttonId]]=color;this.editor.wrapWithInlineElement(element,selection,range);}
this.close();event.stopEvent();},onUpdateToolbar:function(button,mode,selectionEmpty,ancestors,endPointsInSameBlock){if(mode==='wysiwyg'&&this.editor.isEditable()){var statusBarSelection=this.editor.statusBar?this.editor.statusBar.getSelection():null,parentElement=statusBarSelection?statusBarSelection:this.editor.getParentElement(),disabled=!endPointsInSameBlock||(selectionEmpty&&/^body$/i.test(parentElement.nodeName));button.setInactive(!parentElement.style[this.styleProperty[button.itemId]]);button.setDisabled(disabled);}}});