[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

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

   1  /*
   2   * FCKeditor - The text editor for internet
   3   * Copyright (C) 2003-2005 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        || '370' ;
  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.Create = function()
  46  {
  47      // Check for errors
  48      if ( !this.InstanceName || this.InstanceName.length == 0 )
  49      {
  50          this._ThrowError( 701, 'You must specify an instance name.' ) ;
  51          return ;
  52      }
  53  
  54      document.write( '<div>' ) ;
  55  
  56      if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
  57      {
  58          document.write( '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" style="display:none" />' ) ;
  59          document.write( this._GetConfigHtml() ) ;
  60          document.write( this._GetIFrameHtml() ) ;
  61      }
  62      else
  63      {
  64          var sWidth  = this.Width.toString().indexOf('%')  > 0 ? this.Width  : this.Width  + 'px' ;
  65          var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
  66          document.write('<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="WIDTH: ' + sWidth + '; HEIGHT: ' + sHeight + '">' + this._HTMLEncode( this.Value ) + '<\/textarea>') ;
  67      }
  68  
  69      document.write( '</div>' ) ;
  70  }
  71  
  72  FCKeditor.prototype.ReplaceTextarea = function()
  73  {
  74      if(document.getElementById('description___Config') != null)    
  75      {
  76          var oConfig = document.getElementsByName('description___Config');
  77          var oFrame = document.getElementsByName('description___Frame');
  78          for(vi=0;vi < oConfig.length;vi++)
  79          {
  80              oConfig[vi].style.display = 'none';
  81              oFrame[vi].style.display = 'none';
  82          }
  83      }
  84      if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
  85      {
  86          // We must check the elements firstly using the Id and then the name.
  87          var oTextarea = document.getElementById( this.InstanceName ) ;
  88          var colElementsByName = document.getElementsByName( this.InstanceName ) ;
  89          var i = 0;
  90          while ( oTextarea || i == 0 )
  91          {
  92              if ( oTextarea && oTextarea.tagName == 'TEXTAREA' )
  93                  break ;
  94              oTextarea = colElementsByName[i++] ;
  95          }
  96          
  97          if ( !oTextarea )
  98          {
  99              alert( 'Error: The TEXTAREA with id or name set to "' + this.InstanceName + '" was not found' ) ;
 100              return ;
 101          }
 102  
 103          oTextarea.style.display = 'none' ;
 104          this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
 105          this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
 106      }
 107  }
 108  
 109  FCKeditor.prototype._InsertHtmlBefore = function( html, element )
 110  {
 111      if ( element.insertAdjacentHTML )    // IE
 112          element.insertAdjacentHTML( 'beforeBegin', html ) ;
 113      else                                // Gecko
 114      {
 115          var oRange = document.createRange() ;
 116          oRange.setStartBefore( element ) ;
 117          var oFragment = oRange.createContextualFragment( html );
 118          element.parentNode.insertBefore( oFragment, element ) ;
 119      }
 120  }
 121  
 122  FCKeditor.prototype._GetConfigHtml = function()
 123  {
 124      var sConfig = '' ;
 125      for ( var o in this.Config )
 126      {
 127          if ( sConfig.length > 0 ) sConfig += '&amp;' ;
 128          sConfig += escape(o) + '=' + escape( this.Config[o] ) ;
 129      }
 130  
 131      return '<input type="hidden" id="' + this.InstanceName + '___Config" name="' + this.InstanceName + '___Config" value="' + sConfig + '" style="display:none" />' ;
 132  }
 133  
 134  FCKeditor.prototype._GetIFrameHtml = function()
 135  {
 136      var sFile = (/fcksource=true/i).test( window.top.location.search ) ? 'fckeditor.original.html' : 'fckeditor.html' ;
 137  
 138      var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + this.InstanceName ;
 139      if (this.ToolbarSet) sLink += '&Toolbar=' + this.ToolbarSet ;
 140  
 141      return '<iframe id="' + this.InstanceName + '___Frame" name="' + this.InstanceName + '___Frame" name="" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height + '" frameborder="no" scrolling="no"></iframe>' ;
 142  }
 143  
 144  FCKeditor.prototype._IsCompatibleBrowser = function()
 145  {
 146      var sAgent = navigator.userAgent.toLowerCase() ;
 147      
 148      // Internet Explorer
 149      if ( sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1 )
 150      {
 151          var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
 152          return ( sBrowserVersion >= 5.5 ) ;
 153      }
 154      
 155      // Gecko
 156      if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 )
 157          return true ;
 158      
 159      // Opera
 160      if ( this.EnableOpera )
 161      {
 162          var aMatch = sAgent.match( /^opera\/(\d+\.\d+)/ ) ;
 163          if ( aMatch && aMatch[1] >= 9.0 )
 164              return true ;
 165      }
 166      
 167      // Safari
 168      if ( this.EnableSafari && sAgent.indexOf( 'safari' ) != -1 )
 169          return ( sAgent.match( /safari\/(\d+)/ )[1] >= 312 ) ;    // Build must be at least 312 (1.3)
 170      
 171      return false ;
 172  }
 173  
 174  FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
 175  {
 176      this.ErrorNumber        = errorNumber ;
 177      this.ErrorDescription    = errorDescription ;
 178  
 179      if ( this.DisplayErrors )
 180      {
 181          document.write( '<div style="COLOR: #ff0000">' ) ;
 182          document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
 183          document.write( '</div>' ) ;
 184      }
 185  
 186      if ( typeof( this.OnError ) == 'function' )
 187          this.OnError( this, errorNumber, errorDescription ) ;
 188  }
 189  
 190  FCKeditor.prototype._HTMLEncode = function( text )
 191  {
 192      if ( typeof( text ) != "string" )
 193          text = text.toString() ;
 194  
 195      text = text.replace(/&/g, "&amp;") ;
 196      text = text.replace(/"/g, "&quot;") ;
 197      text = text.replace(/</g, "&lt;") ;
 198      text = text.replace(/>/g, "&gt;") ;
 199      text = text.replace(/'/g, "&#39;") ;
 200  
 201      return text ;
 202  }


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7