[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/fckeditor/editor/_source/internals/ -> fck_1.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: fck_1.js
  14   *     This is the first part of the "FCK" object creation. This is the main
  15   *     object that represents an editor instance.
  16   * 
  17   * File Authors:
  18   *         Frederico Caldeira Knabben (fredck@fckeditor.net)
  19   */
  20  
  21  var FCK_StartupValue ;
  22  
  23  FCK.Events    = new FCKEvents( FCK ) ;
  24  FCK.Toolbar    = null ;
  25  FCK.HasFocus = false ;
  26  
  27  FCK.StartEditor = function()
  28  {
  29      FCK.TempBaseTag = FCKConfig.BaseHref.length > 0 ? '<base href="' + FCKConfig.BaseHref + '" _fcktemp="true"></base>' : '' ;
  30  
  31      FCK.EditingArea = new FCKEditingArea( document.getElementById( 'xEditingArea' ) ) ;
  32  
  33      // Set the editor's startup contents
  34      this.SetHTML( FCKTools.GetLinkedFieldValue() ) ;
  35  }
  36  
  37  FCK.Focus = function()
  38  {
  39      FCK.EditingArea.Focus() ;
  40  }
  41  
  42  FCK.SetStatus = function( newStatus )
  43  {
  44      this.Status = newStatus ;
  45  
  46      if ( newStatus == FCK_STATUS_ACTIVE )
  47      {
  48          FCKFocusManager.AddWindow( window, true ) ;
  49          
  50          if ( FCKBrowserInfo.IsIE )
  51              FCKFocusManager.AddWindow( window.frameElement, true ) ;
  52  
  53          // Force the focus in the editor.
  54          if ( FCKConfig.StartupFocus )
  55              FCK.Focus() ;
  56      }
  57  
  58      this.Events.FireEvent( 'OnStatusChange', newStatus ) ;
  59  }
  60  
  61  // GetHTML is Deprecated : returns the same value as GetXHTML.
  62  FCK.GetHTML = FCK.GetXHTML = function( format )
  63  {
  64      // We assume that if the user is in source editing, the editor value must
  65      // represent the exact contents of the source, as the user wanted it to be.
  66      if ( FCK.EditMode == FCK_EDITMODE_SOURCE )
  67              return FCK.EditingArea.Textarea.value ;
  68  
  69      var sXHTML ;
  70      
  71      if ( FCKConfig.FullPage )
  72          sXHTML = FCKXHtml.GetXHTML( this.EditorDocument.getElementsByTagName( 'html' )[0], true, format ) ;
  73      else
  74      {
  75          if ( FCKConfig.IgnoreEmptyParagraphValue && this.EditorDocument.body.innerHTML == '<P>&nbsp;</P>' )
  76              sXHTML = '' ;
  77          else
  78              sXHTML = FCKXHtml.GetXHTML( this.EditorDocument.body, false, format ) ;
  79      }
  80  
  81      if ( FCKBrowserInfo.IsIE )
  82          sXHTML = sXHTML.replace( FCKRegexLib.ToReplace, '$1' ) ;
  83  
  84      if ( FCK.DocTypeDeclaration && FCK.DocTypeDeclaration.length > 0 )
  85          sXHTML = FCK.DocTypeDeclaration + '\n' + sXHTML ;
  86  
  87      if ( FCK.XmlDeclaration && FCK.XmlDeclaration.length > 0 )
  88          sXHTML = FCK.XmlDeclaration + '\n' + sXHTML ;
  89  
  90      return FCKConfig.ProtectedSource.Revert( sXHTML ) ;
  91  }
  92  
  93  FCK.UpdateLinkedField = function()
  94  {
  95      FCK.LinkedField.value = FCK.GetXHTML( FCKConfig.FormatOutput ) ;
  96      FCK.Events.FireEvent( 'OnAfterLinkedFieldUpdate' ) ;
  97  }
  98  
  99  FCK.RegisteredDoubleClickHandlers = new Object() ;
 100  
 101  FCK.OnDoubleClick = function( element )
 102  {
 103      var oHandler = FCK.RegisteredDoubleClickHandlers[ element.tagName ] ;
 104      if ( oHandler )
 105          oHandler( element ) ;
 106  }
 107  
 108  // Register objects that can handle double click operations.
 109  FCK.RegisterDoubleClickHandler = function( handlerFunction, tag )
 110  {
 111      FCK.RegisteredDoubleClickHandlers[ tag.toUpperCase() ] = handlerFunction ;
 112  }
 113  
 114  FCK.OnAfterSetHTML = function()
 115  {
 116      FCKDocumentProcessor.Process( FCK.EditorDocument ) ;
 117      FCK.Events.FireEvent( 'OnAfterSetHTML' ) ;
 118  }
 119  
 120  // Saves URLs on links and images on special attributes, so they don't change when 
 121  // moving around.
 122  FCK.ProtectUrls = function( html )
 123  {
 124      // <A> href
 125      html = html.replace( FCKRegexLib.ProtectUrlsAApo    , '$1$2$3$2 _fcksavedurl=$2$3$2' ) ;
 126      html = html.replace( FCKRegexLib.ProtectUrlsANoApo    , '$1$2 _fcksavedurl="$2"' ) ;
 127  
 128      // <IMG> src
 129      html = html.replace( FCKRegexLib.ProtectUrlsImgApo    , '$1$2$3$2 _fcksavedurl=$2$3$2' ) ;
 130      html = html.replace( FCKRegexLib.ProtectUrlsImgNoApo, '$1$2 _fcksavedurl="$2"' ) ;
 131      
 132      return html ;
 133  }
 134  
 135  FCK.IsDirty = function()
 136  {
 137      return ( FCK_StartupValue != FCK.EditorDocument.body.innerHTML ) ;
 138  }
 139  
 140  FCK.ResetIsDirty = function()
 141  {
 142      if ( FCK.EditorDocument.body )
 143          FCK_StartupValue = FCK.EditorDocument.body.innerHTML ;
 144  }
 145  
 146  FCK.SetHTML = function( html )
 147  {
 148      this.EditingArea.Mode = FCK.EditMode ;
 149  
 150      if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
 151      {
 152          // Firefox can't handle correctly the editing of the STRONG and EM tags. 
 153          // We must replace them with B and I.
 154          if ( FCKBrowserInfo.IsGecko )
 155          {
 156              html = html.replace( FCKRegexLib.StrongOpener, '<b$1' ) ;
 157              html = html.replace( FCKRegexLib.StrongCloser, '<\/b>' ) ;
 158              html = html.replace( FCKRegexLib.EmOpener, '<i$1' ) ;
 159              html = html.replace( FCKRegexLib.EmCloser, '<\/i>' ) ;
 160          }
 161      
 162          html = FCKConfig.ProtectedSource.Protect( html ) ;
 163          html = FCK.ProtectUrls( html ) ;
 164  
 165          var sHtml ;
 166  
 167          if ( FCKConfig.FullPage )
 168          {
 169              var sHtml ;
 170  
 171              if ( FCKBrowserInfo.IsIE )
 172                  sHtml = FCK._GetBehaviorsStyle() ;
 173              else if ( FCKConfig.ShowBorders ) 
 174                  sHtml = '<link href="' + FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
 175  
 176              sHtml += '<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
 177  
 178              sHtml = html.replace( FCKRegexLib.HeadCloser, sHtml + '$&' ) ;
 179  
 180              // Insert the base tag (FCKConfig.BaseHref), if not exists in the source.
 181              if ( FCK.TempBaseTag.length > 0 && !FCKRegexLib.HasBaseTag.test( html ) )
 182                  sHtml = sHtml.replace( FCKRegexLib.HeadOpener, '$&' + FCK.TempBaseTag ) ;
 183          }
 184          else
 185          {
 186              sHtml =
 187                  FCKConfig.DocType +
 188                  '<html dir="' + FCKConfig.ContentLangDirection + '"' ;
 189              
 190              // On IE, if you are use a DOCTYPE differenft of HTML 4 (like
 191              // XHTML), you must force the vertical scroll to show, otherwise
 192              // the horizontal one may appear when the page needs vertical scrolling.
 193              if ( FCKBrowserInfo.IsIE && !FCKRegexLib.Html4DocType.test( FCKConfig.DocType ) )
 194                  sHtml += ' style="overflow-y: scroll"' ;
 195              
 196              sHtml +=
 197                  '><head><title></title>' +
 198                  this._GetEditorAreaStyleTags() +
 199                  '<link href="' + FCKConfig.FullBasePath + 'css/fck_internal.css' + '" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
 200  
 201              if ( FCKBrowserInfo.IsIE )
 202                  sHtml += FCK._GetBehaviorsStyle() ;
 203              else if ( FCKConfig.ShowBorders ) 
 204                  sHtml += '<link href="' + FCKConfig.FullBasePath + 'css/fck_showtableborders_gecko.css" rel="stylesheet" type="text/css" _fcktemp="true" />' ;
 205  
 206              sHtml += FCK.TempBaseTag ;
 207              sHtml += '</head><body>' ;
 208              
 209              if ( FCKBrowserInfo.IsGecko && ( html.length == 0 || FCKRegexLib.EmptyParagraph.test( html ) ) )
 210                  sHtml += GECKO_BOGUS ;
 211              else
 212                  sHtml += html ;
 213              
 214              sHtml += '</body></html>' ;
 215          }
 216  
 217          this.EditingArea.OnLoad = FCK_EditingArea_OnLoad ;
 218          this.EditingArea.Start( sHtml ) ;
 219      }
 220      else
 221      {
 222          this.EditingArea.OnLoad = null ;
 223          this.EditingArea.Start( html ) ;
 224          
 225          // Enables the context menu in the textarea.
 226          this.EditingArea.Textarea._FCKShowContextMenu = true ;
 227      }
 228  }
 229  
 230  function FCK_EditingArea_OnLoad()
 231  {
 232      // Get the editor's window and document (DOM)
 233      FCK.EditorWindow    = FCK.EditingArea.Window ;
 234      FCK.EditorDocument    = FCK.EditingArea.Document ;
 235  
 236      FCK.InitializeBehaviors() ;
 237  
 238      FCK.OnAfterSetHTML() ;
 239  
 240      // Check if it is not a startup call, otherwise complete the startup.
 241      if ( FCK.Status != FCK_STATUS_NOTLOADED )
 242          return ;
 243  
 244      // Save the startup value for the "IsDirty()" check.
 245      FCK.ResetIsDirty() ;
 246  
 247      // Attach the editor to the form onsubmit event
 248      FCKTools.AttachToLinkedFieldFormSubmit( FCK.UpdateLinkedField ) ;
 249  
 250      FCKUndo.SaveUndoStep() ;
 251  
 252      FCK.SetStatus( FCK_STATUS_ACTIVE ) ;
 253  }
 254  
 255  FCK._GetEditorAreaStyleTags = function()
 256  {
 257      var sTags = '' ;
 258      var aCSSs = FCKConfig.EditorAreaCSS ;
 259      
 260      for ( var i = 0 ; i < aCSSs.length ; i++ )
 261          sTags += '<link href="' + aCSSs[i] + '" rel="stylesheet" type="text/css" />' ;
 262      
 263      return sTags ;
 264  }
 265  
 266  // # Focus Manager: Manages the focus in the editor.
 267  var FCKFocusManager = FCK.FocusManager = new Object() ;
 268  FCKFocusManager.IsLocked = false ;
 269  FCK.HasFocus = false ;
 270  
 271  FCKFocusManager.AddWindow = function( win, sendToEditingArea )
 272  {
 273      var oTarget ;
 274      
 275      if ( FCKBrowserInfo.IsIE )
 276          oTarget = win.nodeType == 1 ? win : win.frameElement ? win.frameElement : win.document ;
 277      else
 278          oTarget = win.document ;
 279      
 280      FCKTools.AddEventListener( oTarget, 'blur', FCKFocusManager_Win_OnBlur ) ;
 281      FCKTools.AddEventListener( oTarget, 'focus', sendToEditingArea ? FCKFocusManager_Win_OnFocus_Area : FCKFocusManager_Win_OnFocus ) ;
 282  }
 283  
 284  FCKFocusManager.RemoveWindow = function( win )
 285  {
 286      if ( FCKBrowserInfo.IsIE )
 287          oTarget = win.nodeType == 1 ? win : win.frameElement ? win.frameElement : win.document ;
 288      else
 289          oTarget = win.document ;
 290  
 291      FCKTools.RemoveEventListener( oTarget, 'blur', FCKFocusManager_Win_OnBlur ) ;
 292      FCKTools.RemoveEventListener( oTarget, 'focus', FCKFocusManager_Win_OnFocus_Area ) ;
 293      FCKTools.RemoveEventListener( oTarget, 'focus', FCKFocusManager_Win_OnFocus ) ;
 294  }
 295  
 296  FCKFocusManager.Lock = function()
 297  {
 298      this.IsLocked = true ;
 299  }
 300  
 301  FCKFocusManager.Unlock = function()
 302  {
 303      if ( this._HasPendingBlur )
 304          FCKFocusManager._Timer = window.setTimeout( FCKFocusManager_FireOnBlur, 100 ) ;
 305          
 306      this.IsLocked = false ;
 307  }
 308  
 309  FCKFocusManager._ResetTimer = function()
 310  {
 311      this._HasPendingBlur = false ;
 312  
 313      if ( this._Timer )
 314      {
 315          window.clearTimeout( this._Timer ) ;
 316          delete this._Timer ; 
 317      }
 318  }
 319  
 320  function FCKFocusManager_Win_OnBlur()
 321  {
 322      if ( FCK && FCK.HasFocus )
 323      {
 324          FCKFocusManager._ResetTimer() ;
 325          FCKFocusManager._Timer = window.setTimeout( FCKFocusManager_FireOnBlur, 100 ) ;
 326      }
 327  }
 328  
 329  function FCKFocusManager_FireOnBlur()
 330  {
 331      if ( FCKFocusManager.IsLocked )
 332          FCKFocusManager._HasPendingBlur = true ;
 333      else
 334      {
 335          FCK.HasFocus = false ;
 336          FCK.Events.FireEvent( "OnBlur" ) ;
 337      }
 338  }
 339  
 340  function FCKFocusManager_Win_OnFocus_Area()
 341  {
 342      FCKFocusManager_Win_OnFocus() ;
 343      FCK.Focus() ;
 344  }
 345  
 346  function FCKFocusManager_Win_OnFocus()
 347  {
 348      FCKFocusManager._ResetTimer() ;
 349  
 350      if ( !FCK.HasFocus && !FCKFocusManager.IsLocked )
 351      {
 352          FCK.HasFocus = true ;
 353          FCK.Events.FireEvent( "OnFocus" ) ;
 354      }
 355  }


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