[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/fckeditor/ -> fckeditor.js (source)

   1  /*
   2   * FCKeditor - The text editor for internet
   3   * Copyright (C) 2003-2006 Frederico Caldeira Knabben
   4   * 
   5   * Licensed under the terms of the GNU Lesser General Public License:
   6   *         http://www.opensource.org/licenses/lgpl-license.php
   7   * 
   8   * For further information visit:
   9   *         http://www.fckeditor.net/
  10   * 
  11   * "Support Open Source software. What about a donation today?"
  12   * 
  13   * File Name: fckeditor.js
  14   *     This is the integration file for JavaScript.
  15   * 
  16   *     It defines the FCKeditor class that can be used to create editor
  17   *     instances in a HTML page in the client side. For server side
  18   *     operations, use the specific integration system.
  19   * 
  20   * File Authors:
  21   *         Frederico Caldeira Knabben (fredck@fckeditor.net)
  22   */
  23  
  24  // FCKeditor Class
  25  var FCKeditor = function( instanceName, width, height, toolbarSet, value )
  26  {
  27      // Properties
  28      this.InstanceName    = instanceName ;
  29      this.Width            = width            || '100%' ;
  30      this.Height            = height        || '200' ;
  31      this.ToolbarSet        = toolbarSet    || 'Default' ;
  32      this.Value            = value            || '' ;
  33      this.BasePath        = '/fckeditor/' ;
  34      this.CheckBrowser    = true ;
  35      this.DisplayErrors    = true ;
  36      this.EnableSafari    = false ;        // This is a temporary property, while Safari support is under development.
  37      this.EnableOpera    = false ;        // This is a temporary property, while Opera support is under development.
  38  
  39      this.Config            = new Object() ;
  40  
  41      // Events
  42      this.OnError        = null ;    // function( source, errorNumber, errorDescription )
  43  }
  44  
  45  FCKeditor.prototype.Version            = '2.3.1' ;
  46  FCKeditor.prototype.VersionBuild    = '1062' ;
  47  
  48  FCKeditor.prototype.Create = function()
  49  {
  50      // Check for errors
  51      if ( !this.InstanceName || this.InstanceName.length == 0 )
  52      {
  53          this._ThrowError( 701, 'You must specify an instance name.' ) ;
  54          return ;
  55      }
  56  
  57      document.write( '<div>' ) ;
  58  
  59      if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
  60      {
  61          document.write( '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" style="display:none" />' ) ;
  62          document.write( this._GetConfigHtml() ) ;
  63          document.write( this._GetIFrameHtml() ) ;
  64      }
  65      else
  66      {
  67          var sWidth  = this.Width.toString().indexOf('%')  > 0 ? this.Width  : this.Width  + 'px' ;
  68          var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
  69          document.write('<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="WIDTH: ' + sWidth + '; HEIGHT: ' + sHeight + '">' + this._HTMLEncode( this.Value ) + '<\/textarea>') ;
  70      }
  71  
  72      document.write( '</div>' ) ;
  73  }
  74  
  75  FCKeditor.prototype.ReplaceTextarea = function()
  76  {
  77      if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
  78      {
  79          // We must check the elements firstly using the Id and then the name.
  80          var oTextarea = document.getElementById( this.InstanceName ) ;
  81          var colElementsByName = document.getElementsByName( this.InstanceName ) ;
  82          var i = 0;
  83          while ( oTextarea || i == 0 )
  84          {
  85              if ( oTextarea && oTextarea.tagName == 'TEXTAREA' )
  86                  break ;
  87              oTextarea = colElementsByName[i++] ;
  88          }
  89          
  90          if ( !oTextarea )
  91          {
  92              alert( 'Error: The TEXTAREA with id or name set to "' + this.InstanceName + '" was not found' ) ;
  93              return ;
  94          }
  95  
  96          oTextarea.style.display = 'none' ;
  97          this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
  98          this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
  99      }
 100  }
 101  
 102  FCKeditor.prototype._InsertHtmlBefore = function( html, element )
 103  {
 104      if ( element.insertAdjacentHTML )    // IE
 105          element.insertAdjacentHTML( 'beforeBegin', html ) ;
 106      else                                // Gecko
 107      {
 108          var oRange = document.createRange() ;
 109          oRange.setStartBefore( element ) ;
 110          var oFragment = oRange.createContextualFragment( html );
 111          element.parentNode.insertBefore( oFragment, element ) ;
 112      }
 113  }
 114  
 115  FCKeditor.prototype._GetConfigHtml = function()
 116  {
 117      var sConfig = '' ;
 118      for ( var o in this.Config )
 119      {
 120          if ( sConfig.length > 0 ) sConfig += '&amp;' ;
 121          sConfig += escape(o) + '=' + escape( this.Config[o] ) ;
 122      }
 123  
 124      return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" style="display:none" />' ;
 125  }
 126  
 127  FCKeditor.prototype._GetIFrameHtml = function()
 128  {
 129      var sFile = (/fcksource=true/i).test( window.top.location.search ) ? 'fckeditor.original.html' : 'fckeditor.html' ;
 130  
 131      var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + this.InstanceName ;
 132      if (this.ToolbarSet) sLink += '&Toolbar=' + this.ToolbarSet ;
 133  
 134      return '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height + '" frameborder="0" scrolling="no"></iframe>' ;
 135  }
 136  
 137  FCKeditor.prototype._IsCompatibleBrowser = function()
 138  {
 139      var sAgent = navigator.userAgent.toLowerCase() ;
 140      
 141      // Internet Explorer
 142      if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )
 143      {
 144          var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
 145          return ( sBrowserVersion >= 5.5 ) ;
 146      }
 147  
 148      // Gecko (Opera 9 tries to behave like Gecko at this point).
 149      if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 && !( typeof(opera) == 'object' && opera.postError ) )
 150          return true ;
 151  
 152      // Opera
 153      if ( this.EnableOpera && navigator.appName == 'Opera' && parseInt( navigator.appVersion ) >= 9 )
 154              return true ;
 155  
 156      // Safari
 157      if ( this.EnableSafari && sAgent.indexOf( 'safari' ) != -1 )
 158          return ( sAgent.match( /safari\/(\d+)/ )[1] >= 312 ) ;    // Build must be at least 312 (1.3)
 159      
 160      return false ;
 161  }
 162  
 163  FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
 164  {
 165      this.ErrorNumber        = errorNumber ;
 166      this.ErrorDescription    = errorDescription ;
 167  
 168      if ( this.DisplayErrors )
 169      {
 170          document.write( '<div style="COLOR: #ff0000">' ) ;
 171          document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
 172          document.write( '</div>' ) ;
 173      }
 174  
 175      if ( typeof( this.OnError ) == 'function' )
 176          this.OnError( this, errorNumber, errorDescription ) ;
 177  }
 178  
 179  FCKeditor.prototype._HTMLEncode = function( text )
 180  {
 181      if ( typeof( text ) != "string" )
 182          text = text.toString() ;
 183  
 184      text = text.replace(/&/g, "&amp;") ;
 185      text = text.replace(/"/g, "&quot;") ;
 186      text = text.replace(/</g, "&lt;") ;
 187      text = text.replace(/>/g, "&gt;") ;
 188      text = text.replace(/'/g, "&#39;") ;
 189  
 190      return text ;
 191  }


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics