HTMLArea.CopyPaste=HTMLArea.Plugin.extend({constructor:function(editor,pluginName){this.base(editor,pluginName);},configurePlugin:function(editor){this.buttonsConfiguration=this.editorConfiguration.buttons;var pluginInformation={version:'2.2',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);Ext.iterate(this.buttonList,function(buttonId,button){var buttonConfiguration={id:buttonId,tooltip:this.localize(buttonId.toLowerCase()),iconCls:'htmlarea-action-'+button[2],action:'onButtonPress',context:button[0],selection:button[3],hotKey:button[1]};this.registerButton(buttonConfiguration);},this);return true;},buttonList:{Copy:[null,'c','copy',true],Cut:[null,'x','cut',true],Paste:[null,'v','paste',false]},onGenerate:function(){this.editor.iframe.mon(Ext.get(Ext.isIE?this.editor.document.body:this.editor.document.documentElement),'cut',this.cutHandler,this);Ext.iterate(this.buttonList,function(buttonId,button){if(!Ext.isGecko&&!this.editor.document.queryCommandSupported(buttonId)){this.editor.toolbar.remove(buttonId);}
if(!this.getButton(buttonId)){this.editor.iframe.hotKeyMap.addBinding({key:button[1].toUpperCase(),ctrl:true,shift:false,alt:false,handler:this.onHotKey,scope:this});this.editorConfiguration.hotKeyList[button[1]]={id:button[1],cmd:buttonId};}},this);},onButtonPress:function(editor,id){var buttonId=this.translateHotKey(id);buttonId=buttonId?buttonId:id;this.editor.focus();if(!this.applyToTable(buttonId)){switch(buttonId){case'Copy':if(buttonId==id){this.applyBrowserCommand(buttonId);}
break;case'Cut':if(buttonId==id){this.applyBrowserCommand(buttonId);}
if(Ext.isOpera){this.cutHandler();}
break;case'Paste':if(buttonId==id){this.applyBrowserCommand(buttonId);}
if(Ext.isOpera||Ext.isGecko2){var cleaner=this.getButton('CleanWord');if(cleaner){cleaner.fireEvent.defer(250,cleaner,['click',cleaner]);}}
break;default:break;}
return(buttonId!=id);}else{if(Ext.isOpera){this.editor.inhibitKeyboardInput=true;var bookmark=this.editor.getBookmark(this.editor._createRange(this.editor._getSelection()));var html=this.editor.getInnerHTML();this.revertPaste.defer(200,this,[html,bookmark]);}
return false;}},revertPaste:function(html,bookmark){this.editor.setHTML(html);this.editor.selectRange(this.editor.moveToBookmark(bookmark));this.editor.inhibitKeyboardInput=false;},applyBrowserCommand:function(buttonId){try{this.editor.document.execCommand(buttonId,false,null);}catch(e){if(Ext.isGecko){this.mozillaClipboardAccessException();}}},onHotKey:function(key,event){var hotKey=String.fromCharCode(key).toLowerCase();if(!this.onButtonPress(this,hotKey)){event.stopEvent();}},cutHandler:function(event){this.removeEmptyLink.defer(50,this);},removeEmptyLink:function(){var selection=this.editor._getSelection();var range=this.editor._createRange(selection);var parent=this.editor.getParentElement(selection,range);if(parent.firstChild&&/^(a)$/i.test(parent.firstChild.nodeName)){parent=parent.firstChild;}
if(/^(a)$/i.test(parent.nodeName)){parent.normalize();if(!parent.innerHTML||(parent.childNodes.length==1&&/^(br)$/i.test(parent.firstChild.nodeName))){if(!Ext.isIE){var container=parent.parentNode;this.editor.removeMarkup(parent);if(Ext.isOpera&&/^(li)$/i.test(container.nodeName)&&!container.firstChild){container.innerHTML='
';this.editor.selectNodeContents(container,true);}}else{HTMLArea.removeFromParent(parent);}}}
if(Ext.isWebKit){this.editor.cleanAppleStyleSpans(this.editor.document.body);var bookmark=this.editor.getBookmark(this.editor._createRange(this.editor._getSelection()));this.editor.selectRange(this.editor.moveToBookmark(bookmark));}
this.editor.updateToolbar();},applyToTable:function(buttonId){var selection=this.editor._getSelection();var range=this.editor._createRange(selection);var parent=this.editor.getParentElement(selection,range);var endBlocks=this.editor.getEndBlocks(selection);switch(buttonId){case'Copy':case'Cut':HTMLArea.copiedCells=null;var endBlocks=this.editor.getEndBlocks(selection);if((/^(tr)$/i.test(parent.nodeName)&&!Ext.isIE)||(/^(td|th)$/i.test(endBlocks.start.nodeName)&&/^(td|th)$/i.test(endBlocks.end.nodeName)&&!Ext.isGecko&&endBlocks.start!=endBlocks.end)){HTMLArea.copiedCells=this.collectCells(buttonId,selection,endBlocks);}
break;case'Paste':if(/^(tr|td|th)$/i.test(parent.nodeName)&&HTMLArea.copiedCells){return this.pasteCells(selection,endBlocks);}
break;default:break;}
return false;},pasteCells:function(selection,endBlocks){var cell=null;if(Ext.isGecko){range=selection.getRangeAt(0);cell=range.startContainer.childNodes[range.startOffset];while(cell&&!HTMLArea.isBlockElement(cell)){cell=cell.parentNode;}}
if(!cell&&/^(td|th)$/i.test(endBlocks.start.nodeName)){cell=endBlocks.start;}
if(!cell){return false;}
var tableParts=['thead','tbody','tfoot'];var tablePartsIndex={thead:0,tbody:1,tfoot:2};var tablePart=cell.parentNode.parentNode;var tablePartIndex=tablePartsIndex[tablePart.nodeName.toLowerCase()]
var rows=HTMLArea.copiedCells[tablePartIndex];if(rows&&rows[0]){for(var i=0,rowIndex=cell.parentNode.sectionRowIndex-1;i=0;){rows[k]=[];}
var row=null;var cutRows=[];if(Ext.isGecko){if(selection.rangeCount==1){cells=[];for(var i=0,n=endBlocks.start.cells.length;i';}
if(operation==='Cut'){cutRows.push(endBlocks.start);}}
rows[tablePartsIndex[endBlocks.start.parentNode.nodeName.toLowerCase()]].push(cells);}else{try{var firstCellOfRow=false;var lastCellOfRow=false;while(range=selection.getRangeAt(i++)){cell=range.startContainer.childNodes[range.startOffset];if(cell.parentNode!=row){(cells)&&rows[tablePartsIndex[row.parentNode.nodeName.toLowerCase()]].push(cells);if(operation==='Cut'&&firstCellOfRow&&lastCellOfRow)cutRows.push(row);row=cell.parentNode;cells=[];firstCellOfRow=false;lastCellOfRow=false;}
cells.push(cell.innerHTML);if(operation==='Cut'){cell.innerHTML='
';}
if(!cell.previousSibling)firstCellOfRow=true;if(!cell.nextSibling)lastCellOfRow=true;}}catch(e){}
try{rows[tablePartsIndex[row.parentNode.nodeName.toLowerCase()]].push(cells);}catch(e){}
if(row&&operation==='Cut'&&firstCellOfRow&&lastCellOfRow){cutRows.push(row);}}}else{var firstRow=endBlocks.start.parentNode;var lastRow=endBlocks.end.parentNode;cells=[];var firstCellOfRow=false;var lastCellOfRow=false;if(firstRow==lastRow){cell=endBlocks.start;while(cell){cells.push(cell.innerHTML);if(operation==='Cut'){cell.innerHTML='';}
if(!cell.previousSibling)firstCellOfRow=true;if(!cell.nextSibling)lastCellOfRow=true;if(cell==endBlocks.end)break;cell=cell.nextSibling;}
rows[tablePartsIndex[firstRow.parentNode.nodeName.toLowerCase()]].push(cells);if(operation==='Cut'&&firstCellOfRow&&lastCellOfRow)cutRows.push(firstRow);}else{row=firstRow;while(row){cells=[];for(var i=0,n=row.cells.length;i