fck paste











var oEditor = window.parent.InnerDialogLoaded() ;
var FCK = oEditor.FCK;
var FCKTools = oEditor.FCKTools ;
var FCKConfig = oEditor.FCKConfig ;

window.onload = function ()
{
// First of all, translate the dialog box texts
oEditor.FCKLanguageManager.TranslatePage(document) ;

var sPastingType = window.parent.dialogArguments.CustomValue ;

if ( sPastingType == 'Word' || sPastingType == 'Security' )
{
if ( sPastingType == 'Security' )
document.getElementById( 'xSecurityMsg' ).style.display = '' ;

var oFrame = document.getElementById('frmData') ;
oFrame.style.display = '' ;

// Avoid errors if the pasted content has any script that fails: #389
var oDoc = oFrame.contentWindow.document ;
oDoc.open() ;
oDoc.write('window.onerror = function() { return true ; };') ;
oDoc.close() ;

if ( oFrame.contentDocument )
oFrame.contentDocument.designMode = 'on' ;
else
oFrame.contentWindow.document.body.contentEditable = true ;

// Set the focus on the pasting area
oFrame.contentWindow.focus();
}
else
{
document.getElementById('txtData').style.display = '' ;
}

if ( sPastingType != 'Word' )
document.getElementById('oWordCommands').style.display = 'none' ;

window.parent.SetOkButton( true ) ;
window.parent.SetAutoSize( true ) ;
}

function Ok()
{
// Before doing anything, save undo snapshot.
oEditor.FCKUndo.SaveUndoStep() ;

var sHtml ;

var sPastingType = window.parent.dialogArguments.CustomValue ;

if ( sPastingType == 'Word' || sPastingType == 'Security' )
{
var oFrame = document.getElementById('frmData') ;
var oBody ;

if ( oFrame.contentDocument )
oBody = oFrame.contentDocument.body ;
else
oBody = oFrame.contentWindow.document.body ;

if ( sPastingType == 'Word' )
{
// If a plugin creates a FCK.CustomCleanWord function it will be called instead of the default one
if ( typeof( FCK.CustomCleanWord ) == 'function' )
sHtml = FCK.CustomCleanWord( oBody, document.getElementById('chkRemoveFont').checked, document.getElementById('chkRemoveStyles').checked ) ;
else
sHtml = CleanWord( oBody, document.getElementById('chkRemoveFont').checked, document.getElementById('chkRemoveStyles').checked ) ;
}
else
sHtml = oBody.innerHTML ;

// Fix relative anchor URLs (IE automatically adds the current page URL).
var re = new RegExp( window.location + "#", "g" ) ;
sHtml = sHtml.replace( re, '#') ;
}
else
{
sHtml = oEditor.FCKTools.HTMLEncode( document.getElementById('txtData').value ) ;
sHtml = FCKTools.ProcessLineBreaks( oEditor, FCKConfig, sHtml ) ;

// FCK.InsertHtml() does not work for us, since document fragments cannot contain node fragments. :(
// Use the marker method instead. It's primitive, but it works.
var range = new oEditor.FCKDomRange( oEditor.FCK.EditorWindow ) ;
var oDoc = oEditor.FCK.EditorDocument ;
range.MoveToSelection() ;
range.DeleteContents() ;
var marker = [] ;
for ( var i = 0 ; i < 5 ; i++ )
marker.push( parseInt(Math.random() * 100000, 10 ) ) ;
marker = marker.join( "" ) ;
range.InsertNode ( oDoc.createTextNode( marker ) ) ;
var bookmark = range.CreateBookmark() ;

// Now we've got a marker indicating the paste position in the editor document.
// Find its position in the HTML code.
var htmlString = oDoc.body.innerHTML ;
var index = htmlString.indexOf( marker ) ;

// Split it the HTML code up, add the code we generated, and put them back together.
var htmlList = [] ;
htmlList.push( htmlString.substr( 0, index ) ) ;
htmlList.push( sHtml ) ;
htmlList.push( htmlString.substr( index + marker.length ) ) ;
htmlString = htmlList.join( "" ) ;

if ( oEditor.FCKBrowserInfo.IsIE )
oEditor.FCK.SetInnerHtml( htmlString ) ;
else
oDoc.body.innerHTML = htmlString ;

range.MoveToBookmark( bookmark ) ;
range.Collapse( false ) ;
range.Select() ;
range.Release() ;
return true ;
}

oEditor.FCK.InsertHtml( sHtml ) ;

return true ;
}

function CleanUpBox()
{
var oFrame = document.getElementById('frmData') ;

if ( oFrame.contentDocument )
oFrame.contentDocument.body.innerHTML = '' ;
else
oFrame.contentWindow.document.body.innerHTML = '' ;
}


// This function will be called from the PasteFromWord dialog (fck_paste.html)
// Input: oNode a DOM node that contains the raw paste from the clipboard
// bIgnoreFont, bRemoveStyles booleans according to the values set in the dialog
// Output: the cleaned string
function CleanWord( oNode, bIgnoreFont, bRemoveStyles )
{
var html = oNode.innerHTML ;

html = html.replace(/\s*/g, '') ;
html = html.replace(/.*?/g, ' ') ;

// Remove mso-xxx styles.
html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, '' ) ;

// Remove margin styles.
html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, '' ) ;
html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;

html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, '' ) ;
html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;

html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;

html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;

html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;

html = html.replace( /\s*tab-stops:[^;"]*;?/gi, '' ) ;
html = html.replace( /\s*tab-stops:[^"]*/gi, '' ) ;

// Remove FONT face attributes.
if ( bIgnoreFont )
{
html = html.replace( /\s*face="[^"]*"/gi, '' ) ;
html = html.replace( /\s*face=[^ >]*/gi, '' ) ;

html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, '' ) ;
}

// Remove Class attributes
html = html.replace(/]*) class=([^ |>]*)([^>]*)/gi, "]*)/gi, "]*)/gi, "]*)/gi, "

Wyszukiwarka

Podobne podstrony:
fck paste
fck paste
fck anchor
fck template
fck radiobutton
fck anchor

więcej podobnych podstron