+++ /dev/null
-/*\r
- * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
- * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
- *\r
- * == BEGIN LICENSE ==\r
- *\r
- * Licensed under the terms of any of the following licenses at your\r
- * choice:\r
- *\r
- * - GNU General Public License Version 2 or later (the "GPL")\r
- * http://www.gnu.org/licenses/gpl.html\r
- *\r
- * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
- * http://www.gnu.org/licenses/lgpl.html\r
- *\r
- * - Mozilla Public License Version 1.1 or later (the "MPL")\r
- * http://www.mozilla.org/MPL/MPL-1.1.html\r
- *\r
- * == END LICENSE ==\r
- *\r
- * FCKEditingArea Class: renders an editable area.\r
- */\r
-\r
-/**\r
- * @constructor\r
- * @param {String} targetElement The element that will hold the editing area. Any child element present in the target will be deleted.\r
- */\r
-var FCKEditingArea = function( targetElement )\r
-{\r
- this.TargetElement = targetElement ;\r
- this.Mode = FCK_EDITMODE_WYSIWYG ;\r
-\r
- if ( FCK.IECleanup )\r
- FCK.IECleanup.AddItem( this, FCKEditingArea_Cleanup ) ;\r
-}\r
-\r
-\r
-/**\r
- * @param {String} html The complete HTML for the page, including DOCTYPE and the <html> tag.\r
- */\r
-FCKEditingArea.prototype.Start = function( html, secondCall )\r
-{\r
- var eTargetElement = this.TargetElement ;\r
- var oTargetDocument = FCKTools.GetElementDocument( eTargetElement ) ;\r
-\r
- // Remove all child nodes from the target.\r
- while( eTargetElement.firstChild )\r
- eTargetElement.removeChild( eTargetElement.firstChild ) ;\r
-\r
- if ( this.Mode == FCK_EDITMODE_WYSIWYG )\r
- {\r
- // For FF, document.domain must be set only when different, otherwhise\r
- // we'll strangely have "Permission denied" issues.\r
- if ( FCK_IS_CUSTOM_DOMAIN )\r
- html = '<script>document.domain="' + FCK_RUNTIME_DOMAIN + '";</script>' + html ;\r
-\r
- // IE has a bug with the <base> tag... it must have a </base> closer,\r
- // otherwise the all successive tags will be set as children nodes of the <base>.\r
- if ( FCKBrowserInfo.IsIE )\r
- html = html.replace( /(<base[^>]*?)\s*\/?>(?!\s*<\/base>)/gi, '$1></base>' ) ;\r
- else if ( !secondCall )\r
- {\r
- // Gecko moves some tags out of the body to the head, so we must use\r
- // innerHTML to set the body contents (SF BUG 1526154).\r
-\r
- // Extract the BODY contents from the html.\r
- var oMatchBefore = html.match( FCKRegexLib.BeforeBody ) ;\r
- var oMatchAfter = html.match( FCKRegexLib.AfterBody ) ;\r
-\r
- if ( oMatchBefore && oMatchAfter )\r
- {\r
- var sBody = html.substr( oMatchBefore[1].length,\r
- html.length - oMatchBefore[1].length - oMatchAfter[1].length ) ; // This is the BODY tag contents.\r
-\r
- html =\r
- oMatchBefore[1] + // This is the HTML until the <body...> tag, inclusive.\r
- ' ' +\r
- oMatchAfter[1] ; // This is the HTML from the </body> tag, inclusive.\r
-\r
- // If nothing in the body, place a BOGUS tag so the cursor will appear.\r
- if ( FCKBrowserInfo.IsGecko && ( sBody.length == 0 || FCKRegexLib.EmptyParagraph.test( sBody ) ) )\r
- sBody = '<br type="_moz">' ;\r
-\r
- this._BodyHTML = sBody ;\r
-\r
- }\r
- else\r
- this._BodyHTML = html ; // Invalid HTML input.\r
- }\r
-\r
- // Create the editing area IFRAME.\r
- var oIFrame = this.IFrame = oTargetDocument.createElement( 'iframe' ) ;\r
-\r
- // IE: Avoid JavaScript errors thrown by the editing are source (like tags events).\r
- // See #1055.\r
- var sOverrideError = '<script type="text/javascript" _fcktemp="true">window.onerror=function(){return true;};</script>' ;\r
-\r
- oIFrame.frameBorder = 0 ;\r
- oIFrame.style.width = oIFrame.style.height = '100%' ;\r
-\r
- if ( FCK_IS_CUSTOM_DOMAIN && FCKBrowserInfo.IsIE )\r
- {\r
- window._FCKHtmlToLoad = html.replace( /<head>/i, '<head>' + sOverrideError ) ;\r
- oIFrame.src = 'javascript:void( (function(){' +\r
- 'document.open() ;' +\r
- 'document.domain="' + document.domain + '" ;' +\r
- 'document.write( window.parent._FCKHtmlToLoad );' +\r
- 'document.close() ;' +\r
- 'window.parent._FCKHtmlToLoad = null ;' +\r
- '})() )' ;\r
- }\r
- else if ( !FCKBrowserInfo.IsGecko )\r
- {\r
- // Firefox will render the tables inside the body in Quirks mode if the\r
- // source of the iframe is set to javascript. see #515\r
- oIFrame.src = 'javascript:void(0)' ;\r
- }\r
-\r
- // Append the new IFRAME to the target. For IE, it must be done after\r
- // setting the "src", to avoid the "secure/unsecure" message under HTTPS.\r
- eTargetElement.appendChild( oIFrame ) ;\r
-\r
- // Get the window and document objects used to interact with the newly created IFRAME.\r
- this.Window = oIFrame.contentWindow ;\r
-\r
- // IE: Avoid JavaScript errors thrown by the editing are source (like tags events).\r
- // TODO: This error handler is not being fired.\r
- // this.Window.onerror = function() { alert( 'Error!' ) ; return true ; }\r
-\r
- if ( !FCK_IS_CUSTOM_DOMAIN || !FCKBrowserInfo.IsIE )\r
- {\r
- var oDoc = this.Window.document ;\r
-\r
- oDoc.open() ;\r
- oDoc.write( html.replace( /<head>/i, '<head>' + sOverrideError ) ) ;\r
- oDoc.close() ;\r
- }\r
-\r
- if ( FCKBrowserInfo.IsAIR )\r
- FCKAdobeAIR.EditingArea_Start( oDoc, html ) ;\r
-\r
- // Firefox 1.0.x is buggy... ohh yes... so let's do it two times and it\r
- // will magically work.\r
- if ( FCKBrowserInfo.IsGecko10 && !secondCall )\r
- {\r
- this.Start( html, true ) ;\r
- return ;\r
- }\r
-\r
- if ( oIFrame.readyState && oIFrame.readyState != 'completed' )\r
- {\r
- var editArea = this ;\r
-\r
- // Using a IE alternative for DOMContentLoaded, similar to the\r
- // solution proposed at http://javascript.nwbox.com/IEContentLoaded/\r
- setTimeout( function()\r
- {\r
- try\r
- {\r
- editArea.Window.document.documentElement.doScroll("left") ;\r
- }\r
- catch(e)\r
- {\r
- setTimeout( arguments.callee, 0 ) ;\r
- return ;\r
- }\r
- editArea.Window._FCKEditingArea = editArea ;\r
- FCKEditingArea_CompleteStart.call( editArea.Window ) ;\r
- }, 0 ) ;\r
- }\r
- else\r
- {\r
- this.Window._FCKEditingArea = this ;\r
-\r
- // FF 1.0.x is buggy... we must wait a lot to enable editing because\r
- // sometimes the content simply disappears, for example when pasting\r
- // "bla1!<img src='some_url'>!bla2" in the source and then switching\r
- // back to design.\r
- if ( FCKBrowserInfo.IsGecko10 )\r
- this.Window.setTimeout( FCKEditingArea_CompleteStart, 500 ) ;\r
- else\r
- FCKEditingArea_CompleteStart.call( this.Window ) ;\r
- }\r
- }\r
- else\r
- {\r
- var eTextarea = this.Textarea = oTargetDocument.createElement( 'textarea' ) ;\r
- eTextarea.className = 'SourceField' ;\r
- eTextarea.dir = 'ltr' ;\r
- FCKDomTools.SetElementStyles( eTextarea,\r
- {\r
- width : '100%',\r
- height : '100%',\r
- border : 'none',\r
- resize : 'none',\r
- outline : 'none'\r
- } ) ;\r
- eTargetElement.appendChild( eTextarea ) ;\r
-\r
- eTextarea.value = html ;\r
-\r
- // Fire the "OnLoad" event.\r
- FCKTools.RunFunction( this.OnLoad ) ;\r
- }\r
-}\r
-\r
-// "this" here is FCKEditingArea.Window\r
-function FCKEditingArea_CompleteStart()\r
-{\r
- // On Firefox, the DOM takes a little to become available. So we must wait for it in a loop.\r
- if ( !this.document.body )\r
- {\r
- this.setTimeout( FCKEditingArea_CompleteStart, 50 ) ;\r
- return ;\r
- }\r
-\r
- var oEditorArea = this._FCKEditingArea ;\r
-\r
- // Save this reference to be re-used later.\r
- oEditorArea.Document = oEditorArea.Window.document ;\r
-\r
- oEditorArea.MakeEditable() ;\r
-\r
- // Fire the "OnLoad" event.\r
- FCKTools.RunFunction( oEditorArea.OnLoad ) ;\r
-}\r
-\r
-FCKEditingArea.prototype.MakeEditable = function()\r
-{\r
- var oDoc = this.Document ;\r
-\r
- if ( FCKBrowserInfo.IsIE )\r
- {\r
- // Kludge for #141 and #523\r
- oDoc.body.disabled = true ;\r
- oDoc.body.contentEditable = true ;\r
- oDoc.body.removeAttribute( "disabled" ) ;\r
-\r
- /* The following commands don't throw errors, but have no effect.\r
- oDoc.execCommand( 'AutoDetect', false, false ) ;\r
- oDoc.execCommand( 'KeepSelection', false, true ) ;\r
- */\r
- }\r
- else\r
- {\r
- try\r
- {\r
- // Disable Firefox 2 Spell Checker.\r
- oDoc.body.spellcheck = ( this.FFSpellChecker !== false ) ;\r
-\r
- if ( this._BodyHTML )\r
- {\r
- oDoc.body.innerHTML = this._BodyHTML ;\r
- oDoc.body.offsetLeft ; // Don't remove, this is a hack to fix Opera 9.50, see #2264.\r
- this._BodyHTML = null ;\r
- }\r
-\r
- oDoc.designMode = 'on' ;\r
-\r
- // Tell Gecko (Firefox 1.5+) to enable or not live resizing of objects (by Alfonso Martinez)\r
- oDoc.execCommand( 'enableObjectResizing', false, !FCKConfig.DisableObjectResizing ) ;\r
-\r
- // Disable the standard table editing features of Firefox.\r
- oDoc.execCommand( 'enableInlineTableEditing', false, !FCKConfig.DisableFFTableHandles ) ;\r
- }\r
- catch (e)\r
- {\r
- // In Firefox if the iframe is initially hidden it can't be set to designMode and it raises an exception\r
- // So we set up a DOM Mutation event Listener on the HTML, as it will raise several events when the document is visible again\r
- FCKTools.AddEventListener( this.Window.frameElement, 'DOMAttrModified', FCKEditingArea_Document_AttributeNodeModified ) ;\r
- }\r
-\r
- }\r
-}\r
-\r
-// This function processes the notifications of the DOM Mutation event on the document\r
-// We use it to know that the document will be ready to be editable again (or we hope so)\r
-function FCKEditingArea_Document_AttributeNodeModified( evt )\r
-{\r
- var editingArea = evt.currentTarget.contentWindow._FCKEditingArea ;\r
-\r
- // We want to run our function after the events no longer fire, so we can know that it's a stable situation\r
- if ( editingArea._timer )\r
- window.clearTimeout( editingArea._timer ) ;\r
-\r
- editingArea._timer = FCKTools.SetTimeout( FCKEditingArea_MakeEditableByMutation, 1000, editingArea ) ;\r
-}\r
-\r
-// This function ideally should be called after the document is visible, it does clean up of the\r
-// mutation tracking and tries again to make the area editable.\r
-function FCKEditingArea_MakeEditableByMutation()\r
-{\r
- // Clean up\r
- delete this._timer ;\r
- // Now we don't want to keep on getting this event\r
- FCKTools.RemoveEventListener( this.Window.frameElement, 'DOMAttrModified', FCKEditingArea_Document_AttributeNodeModified ) ;\r
- // Let's try now to set the editing area editable\r
- // If it fails it will set up the Mutation Listener again automatically\r
- this.MakeEditable() ;\r
-}\r
-\r
-FCKEditingArea.prototype.Focus = function()\r
-{\r
- try\r
- {\r
- if ( this.Mode == FCK_EDITMODE_WYSIWYG )\r
- {\r
- if ( FCKBrowserInfo.IsIE )\r
- this._FocusIE() ;\r
- else\r
- this.Window.focus() ;\r
- }\r
- else\r
- {\r
- var oDoc = FCKTools.GetElementDocument( this.Textarea ) ;\r
- if ( (!oDoc.hasFocus || oDoc.hasFocus() ) && oDoc.activeElement == this.Textarea )\r
- return ;\r
-\r
- this.Textarea.focus() ;\r
- }\r
- }\r
- catch(e) {}\r
-}\r
-\r
-FCKEditingArea.prototype._FocusIE = function()\r
-{\r
- // In IE it can happen that the document is in theory focused but the\r
- // active element is outside of it.\r
- this.Document.body.setActive() ;\r
-\r
- this.Window.focus() ;\r
-\r
- // Kludge for #141... yet more code to workaround IE bugs\r
- var range = this.Document.selection.createRange() ;\r
-\r
- var parentNode = range.parentElement() ;\r
- var parentTag = parentNode.nodeName.toLowerCase() ;\r
-\r
- // Only apply the fix when in a block, and the block is empty.\r
- if ( parentNode.childNodes.length > 0 ||\r
- !( FCKListsLib.BlockElements[parentTag] ||\r
- FCKListsLib.NonEmptyBlockElements[parentTag] ) )\r
- {\r
- return ;\r
- }\r
-\r
- // Force the selection to happen, in this way we guarantee the focus will\r
- // be there.\r
- range = new FCKDomRange( this.Window ) ;\r
- range.MoveToElementEditStart( parentNode ) ;\r
- range.Select() ;\r
-}\r
-\r
-function FCKEditingArea_Cleanup()\r
-{\r
- if ( this.Document )\r
- this.Document.body.innerHTML = "" ;\r
- this.TargetElement = null ;\r
- this.IFrame = null ;\r
- this.Document = null ;\r
- this.Textarea = null ;\r
-\r
- if ( this.Window )\r
- {\r
- this.Window._FCKEditingArea = null ;\r
- this.Window = null ;\r
- }\r
-}\r