FCKeditor 2.6.6
[freeside.git] / httemplate / elements / fckeditor / fckeditor.js
index 63ec41f..8e0126b 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
- * Copyright (C) 2003-2007 Frederico Caldeira Knabben\r
+ * Copyright (C) 2003-2010 Frederico Caldeira Knabben\r
  *\r
  * == BEGIN LICENSE ==\r
  *\r
@@ -34,11 +34,9 @@ var FCKeditor = function( instanceName, width, height, toolbarSet, value )
        this.Height                     = height                || '200' ;\r
        this.ToolbarSet         = toolbarSet    || 'Default' ;\r
        this.Value                      = value                 || '' ;\r
-       this.BasePath           = '/fckeditor/' ;\r
+       this.BasePath           = FCKeditor.BasePath ;\r
        this.CheckBrowser       = true ;\r
        this.DisplayErrors      = true ;\r
-       this.EnableSafari       = false ;               // This is a temporary property, while Safari support is under development.\r
-       this.EnableOpera        = false ;               // This is a temporary property, while Opera support is under development.\r
 \r
        this.Config                     = new Object() ;\r
 \r
@@ -46,8 +44,23 @@ var FCKeditor = function( instanceName, width, height, toolbarSet, value )
        this.OnError            = null ;        // function( source, errorNumber, errorDescription )\r
 }\r
 \r
-FCKeditor.prototype.Version                    = '2.4.3' ;\r
-FCKeditor.prototype.VersionBuild       = '15657' ;\r
+/**\r
+ * This is the default BasePath used by all editor instances.\r
+ */\r
+FCKeditor.BasePath = '/fckeditor/' ;\r
+\r
+/**\r
+ * The minimum height used when replacing textareas.\r
+ */\r
+FCKeditor.MinHeight = 200 ;\r
+\r
+/**\r
+ * The minimum width used when replacing textareas.\r
+ */\r
+FCKeditor.MinWidth = 750 ;\r
+\r
+FCKeditor.prototype.Version                    = '2.6.6' ;\r
+FCKeditor.prototype.VersionBuild       = '25427' ;\r
 \r
 FCKeditor.prototype.Create = function()\r
 {\r
@@ -63,7 +76,7 @@ FCKeditor.prototype.CreateHtml = function()
                return '' ;\r
        }\r
 \r
-       var sHtml = '<div>' ;\r
+       var sHtml = '' ;\r
 \r
        if ( !this.CheckBrowser || this._IsCompatibleBrowser() )\r
        {\r
@@ -75,16 +88,26 @@ FCKeditor.prototype.CreateHtml = function()
        {\r
                var sWidth  = this.Width.toString().indexOf('%')  > 0 ? this.Width  : this.Width  + 'px' ;\r
                var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;\r
-               sHtml += '<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="width:' + sWidth + ';height:' + sHeight + '">' + this._HTMLEncode( this.Value ) + '<\/textarea>' ;\r
-       }\r
 \r
-       sHtml += '</div>' ;\r
+               sHtml += '<textarea name="' + this.InstanceName +\r
+                       '" rows="4" cols="40" style="width:' + sWidth +\r
+                       ';height:' + sHeight ;\r
+\r
+               if ( this.TabIndex )\r
+                       sHtml += '" tabindex="' + this.TabIndex ;\r
+\r
+               sHtml += '">' +\r
+                       this._HTMLEncode( this.Value ) +\r
+                       '<\/textarea>' ;\r
+       }\r
 \r
        return sHtml ;\r
 }\r
 \r
 FCKeditor.prototype.ReplaceTextarea = function()\r
 {\r
+       if ( document.getElementById( this.InstanceName + '___Frame' ) )\r
+               return ;\r
        if ( !this.CheckBrowser || this._IsCompatibleBrowser() )\r
        {\r
                // We must check the elements firstly using the Id and then the name.\r
@@ -105,6 +128,10 @@ FCKeditor.prototype.ReplaceTextarea = function()
                }\r
 \r
                oTextarea.style.display = 'none' ;\r
+\r
+               if ( oTextarea.tabIndex )\r
+                       this.TabIndex = oTextarea.tabIndex ;\r
+\r
                this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;\r
                this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;\r
        }\r
@@ -147,14 +174,25 @@ FCKeditor.prototype._GetIFrameHtml = function()
        catch (e) { /* Ignore it. Much probably we are inside a FRAME where the "top" is in another domain (security error). */ }\r
 \r
        var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.InstanceName ) ;\r
-       if (this.ToolbarSet) sLink += '&amp;Toolbar=' + this.ToolbarSet ;\r
+       if (this.ToolbarSet)\r
+               sLink += '&amp;Toolbar=' + this.ToolbarSet ;\r
+\r
+       var html = '<iframe id="' + this.InstanceName +\r
+               '___Frame" src="' + sLink +\r
+               '" width="' + this.Width +\r
+               '" height="' + this.Height ;\r
+\r
+       if ( this.TabIndex )\r
+               html += '" tabindex="' + this.TabIndex ;\r
+\r
+       html += '" frameborder="0" scrolling="no"></iframe>' ;\r
 \r
-       return '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height + '" frameborder="0" scrolling="no"></iframe>' ;\r
+       return html ;\r
 }\r
 \r
 FCKeditor.prototype._IsCompatibleBrowser = function()\r
 {\r
-       return FCKeditor_IsCompatibleBrowser( this.EnableSafari, this.EnableOpera ) ;\r
+       return FCKeditor_IsCompatibleBrowser() ;\r
 }\r
 \r
 FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )\r
@@ -187,12 +225,84 @@ FCKeditor.prototype._HTMLEncode = function( text )
        return text ;\r
 }\r
 \r
-function FCKeditor_IsCompatibleBrowser( enableSafari, enableOpera )\r
+;(function()\r
+{\r
+       var textareaToEditor = function( textarea )\r
+       {\r
+               var editor = new FCKeditor( textarea.name ) ;\r
+\r
+               editor.Width = Math.max( textarea.offsetWidth, FCKeditor.MinWidth ) ;\r
+               editor.Height = Math.max( textarea.offsetHeight, FCKeditor.MinHeight ) ;\r
+\r
+               return editor ;\r
+       }\r
+\r
+       /**\r
+        * Replace all <textarea> elements available in the document with FCKeditor\r
+        * instances.\r
+        *\r
+        *      // Replace all <textarea> elements in the page.\r
+        *      FCKeditor.ReplaceAllTextareas() ;\r
+        *\r
+        *      // Replace all <textarea class="myClassName"> elements in the page.\r
+        *      FCKeditor.ReplaceAllTextareas( 'myClassName' ) ;\r
+        *\r
+        *      // Selectively replace <textarea> elements, based on custom assertions.\r
+        *      FCKeditor.ReplaceAllTextareas( function( textarea, editor )\r
+        *              {\r
+        *                      // Custom code to evaluate the replace, returning false if it\r
+        *                      // must not be done.\r
+        *                      // It also passes the "editor" parameter, so the developer can\r
+        *                      // customize the instance.\r
+        *              } ) ;\r
+        */\r
+       FCKeditor.ReplaceAllTextareas = function()\r
+       {\r
+               var textareas = document.getElementsByTagName( 'textarea' ) ;\r
+\r
+               for ( var i = 0 ; i < textareas.length ; i++ )\r
+               {\r
+                       var editor = null ;\r
+                       var textarea = textareas[i] ;\r
+                       var name = textarea.name ;\r
+\r
+                       // The "name" attribute must exist.\r
+                       if ( !name || name.length == 0 )\r
+                               continue ;\r
+\r
+                       if ( typeof arguments[0] == 'string' )\r
+                       {\r
+                               // The textarea class name could be passed as the function\r
+                               // parameter.\r
+\r
+                               var classRegex = new RegExp( '(?:^| )' + arguments[0] + '(?:$| )' ) ;\r
+\r
+                               if ( !classRegex.test( textarea.className ) )\r
+                                       continue ;\r
+                       }\r
+                       else if ( typeof arguments[0] == 'function' )\r
+                       {\r
+                               // An assertion function could be passed as the function parameter.\r
+                               // It must explicitly return "false" to ignore a specific <textarea>.\r
+                               editor = textareaToEditor( textarea ) ;\r
+                               if ( arguments[0]( textarea, editor ) === false )\r
+                                       continue ;\r
+                       }\r
+\r
+                       if ( !editor )\r
+                               editor = textareaToEditor( textarea ) ;\r
+\r
+                       editor.ReplaceTextarea() ;\r
+               }\r
+       }\r
+})() ;\r
+\r
+function FCKeditor_IsCompatibleBrowser()\r
 {\r
        var sAgent = navigator.userAgent.toLowerCase() ;\r
 \r
-       // Internet Explorer\r
-       if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )\r
+       // Internet Explorer 5.5+\r
+       if ( /*@cc_on!@*/false && sAgent.indexOf("mac") == -1 )\r
        {\r
                var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;\r
                return ( sBrowserVersion >= 5.5 ) ;\r
@@ -202,13 +312,19 @@ function FCKeditor_IsCompatibleBrowser( enableSafari, enableOpera )
        if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 && !( typeof(opera) == 'object' && opera.postError ) )\r
                return true ;\r
 \r
-       // Opera\r
-       if ( enableOpera && sAgent.indexOf( 'opera' ) == 0 && parseInt( navigator.appVersion, 10 ) >= 9 )\r
-                       return true ;\r
+       // Opera 9.50+\r
+       if ( window.opera && window.opera.version && parseFloat( window.opera.version() ) >= 9.5 )\r
+               return true ;\r
+\r
+       // Adobe AIR\r
+       // Checked before Safari because AIR have the WebKit rich text editor\r
+       // features from Safari 3.0.4, but the version reported is 420.\r
+       if ( sAgent.indexOf( ' adobeair/' ) != -1 )\r
+               return ( sAgent.match( / adobeair\/(\d+)/ )[1] >= 1 ) ; // Build must be at least v1\r
 \r
-       // Safari\r
-       if ( enableSafari && sAgent.indexOf( 'safari' ) != -1 )\r
-               return ( sAgent.match( /safari\/(\d+)/ )[1] >= 312 ) ;  // Build must be at least 312 (1.3)\r
+       // Safari 3+\r
+       if ( sAgent.indexOf( ' applewebkit/' ) != -1 )\r
+               return ( sAgent.match( / applewebkit\/(\d+)/ )[1] >= 522 ) ;    // Build must be at least 522 (v3)\r
 \r
        return false ;\r
-}
\ No newline at end of file
+}\r