HTMLArea.BlockStyle=HTMLArea.Plugin.extend({constructor:function(editor,pluginName){this.base(editor,pluginName);},configurePlugin:function(editor){this.cssArray={};this.classesUrl=this.editorConfiguration.classesUrl;this.pageTSconfiguration=this.editorConfiguration.buttons.blockstyle;this.tags=(this.pageTSconfiguration&&this.pageTSconfiguration.tags)?this.pageTSconfiguration.tags:{};if(typeof(this.editorConfiguration.classesTag)!=="undefined"){if(this.editorConfiguration.classesTag.div){if(!this.tags.div){this.tags.div=new Object();}
if(!this.tags.div.allowedClasses){this.tags.div.allowedClasses=this.editorConfiguration.classesTag.div;}}
if(this.editorConfiguration.classesTag.td){if(!this.tags.td){this.tags.td=new Object();}
if(!this.tags.td.allowedClasses){this.tags.td.allowedClasses=this.editorConfiguration.classesTag.td;}}
if(this.editorConfiguration.classesTag.table){if(!this.tags.table){this.tags.table=new Object();}
if(!this.tags.table.allowedClasses){this.tags.table.allowedClasses=this.editorConfiguration.classesTag.table;}}}
var allowedClasses;for(var tagName in this.tags){if(this.tags.hasOwnProperty(tagName)){if(this.tags[tagName].allowedClasses){allowedClasses=this.tags[tagName].allowedClasses.trim().split(",");for(var cssClass in allowedClasses){if(allowedClasses.hasOwnProperty(cssClass)){allowedClasses[cssClass]=allowedClasses[cssClass].trim().replace(/\*/g,".*");}}
this.tags[tagName].allowedClasses=new RegExp("^("+allowedClasses.join("|")+")$","i");}}}
this.showTagFreeClasses=(this.pageTSconfiguration?this.pageTSconfiguration.showTagFreeClasses:false)||this.editorConfiguration.showTagFreeClasses;this.prefixLabelWithClassName=this.pageTSconfiguration?this.pageTSconfiguration.prefixLabelWithClassName:false;this.postfixLabelWithClassName=this.pageTSconfiguration?this.pageTSconfiguration.postfixLabelWithClassName:false;var pluginInformation={version:'2.0',developer:'Stanislas Rolland',developerUrl:'http://www.sjbr.ca/',copyrightOwner:'Stanislas Rolland',sponsor:this.localize('Technische Universitat Ilmenau'),sponsorUrl:'http://www.tu-ilmenau.de/',license:'GPL'};this.registerPluginInformation(pluginInformation);var dropDownId='BlockStyle';var fieldLabel=this.pageTSconfiguration?this.pageTSconfiguration.fieldLabel:'';if(Ext.isEmpty(fieldLabel)&&this.isButtonInToolbar('I[Block style label]')){fieldLabel=this.localize('Block style label');}
var dropDownConfiguration={id:dropDownId,tooltip:this.localize(dropDownId+'-Tooltip'),fieldLabel:fieldLabel,options:[[this.localize('No style'),'none']],action:'onChange',storeFields:[{name:'text'},{name:'value'},{name:'style'}],tpl:'{text}
'};if(this.pageTSconfiguration){if(this.pageTSconfiguration.width){dropDownConfiguration.width=parseInt(this.pageTSconfiguration.width,10);}
if(this.pageTSconfiguration.listWidth){dropDownConfiguration.listWidth=parseInt(this.pageTSconfiguration.listWidth,10);}
if(this.pageTSconfiguration.maxHeight){dropDownConfiguration.maxHeight=parseInt(this.pageTSconfiguration.maxHeight,10);}}
this.registerDropDown(dropDownConfiguration);return true;},onChange:function(editor,combo,record,index){var className=combo.getValue();this.editor.focus();var blocks=this.getSelectedBlocks();for(var k=0;k=0;){if(!HTMLArea.reservedClassNames.test(classNames[i])){HTMLArea.DOM.removeClass(node,classNames[i]);if(node.nodeName.toLowerCase()==="table"&&this.getPluginInstance('TableOperations')){this.getPluginInstance('TableOperations').removeAlternatingClasses(node,classNames[i]);this.getPluginInstance('TableOperations').removeCountingClasses(node,classNames[i]);}
break;}}}else{var nodeName=node.nodeName.toLowerCase();if(this.tags&&this.tags[nodeName]&&this.tags[nodeName].allowedClasses){if(this.tags[nodeName].allowedClasses.test(className)){HTMLArea.DOM.addClass(node,className);}}else if(this.tags&&this.tags.all&&this.tags.all.allowedClasses){if(this.tags.all.allowedClasses.test(className)){HTMLArea.DOM.addClass(node,className);}}else{HTMLArea.DOM.addClass(node,className);}
if(nodeName==="table"&&this.getPluginInstance('TableOperations')){this.getPluginInstance('TableOperations').reStyleTable(node);}}},getSelectedBlocks:function(){var block,range,i=0,blocks=[];var statusBarSelection=this.editor.statusBar?this.editor.statusBar.getSelection():null;if(Ext.isGecko){var selection=this.editor._getSelection();try{while((range=selection.getRangeAt(i++))){block=this.editor.getParentElement(selection,range);blocks.push(statusBarSelection?statusBarSelection:block);}}catch(e){}}else{blocks.push(statusBarSelection?statusBarSelection:this.editor.getParentElement());}
return blocks;},onGenerate:function(){this.editor.iframe.mon(this.editor,'HTMLAreaEventModeChange',this.onModeChange,this);this.blockStyles=new HTMLArea.CSS.Parser({prefixLabelWithClassName:this.prefixLabelWithClassName,postfixLabelWithClassName:this.postfixLabelWithClassName,showTagFreeClasses:this.showTagFreeClasses,tags:this.tags,editor:this.editor});this.editor.iframe.mon(this.blockStyles,'HTMLAreaEventCssParsingComplete',this.onCssParsingComplete,this);this.blockStyles.initiateParsing();},onCssParsingComplete:function(){if(this.blockStyles.isReady){this.cssArray=this.blockStyles.getClasses();}
if(this.getEditorMode()==='wysiwyg'&&this.editor.isEditable()){this.updateValue('BlockStyle');}},onUpdateToolbar:function(button,mode,selectionEmpty,ancestors){if(mode==='wysiwyg'&&this.editor.isEditable()){this.updateValue(button.itemId);}},onModeChange:function(mode){if(mode==='wysiwyg'&&this.editor.isEditable()){this.updateValue('BlockStyle');}},updateValue:function(dropDownId){var dropDown=this.getButton(dropDownId);if(dropDown){var classNames=new Array();var tagName=null;var statusBarSelection=this.editor.statusBar?this.editor.statusBar.getSelection():null;var parent=statusBarSelection?statusBarSelection:this.editor.getParentElement();while(parent&&!HTMLArea.isBlockElement(parent)&&parent.nodeName.toLowerCase()!="img"){parent=parent.parentNode;}
if(parent){tagName=parent.nodeName.toLowerCase();classNames=HTMLArea.DOM.getClassNames(parent);}
if(tagName&&tagName!=="body"){this.buildDropDownOptions(dropDown,tagName);this.setSelectedOption(dropDown,classNames);}else{this.initializeDropDown(dropDown);dropDown.setDisabled(true);}}},initializeDropDown:function(dropDown){var store=dropDown.getStore();store.removeAll(false);store.insert(0,new store.recordType({text:this.localize('No style'),value:'none'}));dropDown.setValue('none');},buildDropDownOptions:function(dropDown,nodeName){var store=dropDown.getStore();this.initializeDropDown(dropDown);if(this.blockStyles.isReady){var allowedClasses={};if(Ext.isDefined(this.cssArray[nodeName])){allowedClasses=this.cssArray[nodeName];}else if(this.showTagFreeClasses&&Ext.isDefined(this.cssArray['all'])){allowedClasses=this.cssArray['all'];}
Ext.iterate(allowedClasses,function(cssClass,value){var style=null;if(!this.editor.config.disablePCexamples){if(HTMLArea.classesValues[cssClass]&&!HTMLArea.classesNoShow[cssClass]){style=HTMLArea.classesValues[cssClass];}else if(/-[0-9]+$/.test(cssClass)&&HTMLArea.classesValues[RegExp.leftContext+'-']){style=HTMLArea.classesValues[RegExp.leftContext+'-'];}}
store.add(new store.recordType({text:value,value:cssClass,style:style}));},this);}},setSelectedOption:function(dropDown,classNames,noUnknown,defaultClass){var store=dropDown.getStore();dropDown.setValue('none');if(classNames.length){var index=store.findExact('value',classNames[classNames.length-1]);if(index!=-1){dropDown.setValue(classNames[classNames.length-1]);if(!defaultClass){store.getAt(0).set('text',this.localize('Remove style'));}}
if(index==-1&&!noUnknown){store.add(new store.recordType({text:this.localize('Unknown style'),value:classNames[classNames.length-1]}));index=store.getCount()-1;dropDown.setValue(classNames[classNames.length-1]);if(!defaultClass){store.getAt(0).set('text',this.localize('Remove style'));}}
var classNamesString=','+classNames.join(',')+',';store.each(function(option){if(classNamesString.indexOf(','+option.get('value')+',')!=-1){store.removeAt(store.indexOf(option));}
return true;});}
dropDown.setDisabled(!store.getCount()||(store.getCount()==1&&dropDown.getValue()=='none'));}});