[ Index ]
 

Code source de FCKeditor 2.4

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

title

Body

[fermer]

/editor/_source/internals/ -> fck_ie.js (source)

   1  /*
   2   * FCKeditor - The text editor for Internet - http://www.fckeditor.net
   3   * Copyright (C) 2003-2007 Frederico Caldeira Knabben
   4   * 
   5   * == BEGIN LICENSE ==
   6   * 
   7   * Licensed under the terms of any of the following licenses at your
   8   * choice:
   9   * 
  10   *  - GNU General Public License Version 2 or later (the "GPL")
  11   *    http://www.gnu.org/licenses/gpl.html
  12   * 
  13   *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
  14   *    http://www.gnu.org/licenses/lgpl.html
  15   * 
  16   *  - Mozilla Public License Version 1.1 or later (the "MPL")
  17   *    http://www.mozilla.org/MPL/MPL-1.1.html
  18   * 
  19   * == END LICENSE ==
  20   * 
  21   * File Name: fck_ie.js
  22   *     Creation and initialization of the "FCK" object. This is the main
  23   *     object that represents an editor instance.
  24   *     (IE specific implementations)
  25   * 
  26   * File Authors:
  27   *         Frederico Caldeira Knabben (www.fckeditor.net)
  28   */
  29  
  30  FCK.Description = "FCKeditor for Internet Explorer 5.5+" ;
  31  
  32  FCK._GetBehaviorsStyle = function()
  33  {
  34      if ( !FCK._BehaviorsStyle )
  35      {
  36          var sBasePath = FCKConfig.FullBasePath ;
  37          var sTableBehavior = '' ;
  38          var sStyle ;
  39          
  40          // The behaviors should be pointed using the FullBasePath to avoid security
  41          // errors when using a differente BaseHref.
  42          sStyle =
  43              '<style type="text/css" _fcktemp="true">' +
  44              'INPUT { behavior: url(' + sBasePath + 'css/behaviors/hiddenfield.htc) ; }' ;
  45  
  46          if ( FCKConfig.ShowBorders )
  47              sTableBehavior = 'url(' + sBasePath + 'css/behaviors/showtableborders.htc)' ;
  48  
  49          // Disable resize handlers.
  50          sStyle += 'INPUT,TEXTAREA,SELECT,.FCK__Anchor,.FCK__PageBreak' ;
  51  
  52          if ( FCKConfig.DisableObjectResizing )
  53          {
  54              sStyle += ',IMG' ;
  55              sTableBehavior += ' url(' + sBasePath + 'css/behaviors/disablehandles.htc)' ;
  56          }
  57          
  58          sStyle += ' { behavior: url(' + sBasePath + 'css/behaviors/disablehandles.htc) ; }' ;
  59  
  60          if ( sTableBehavior.length > 0 )
  61              sStyle += 'TABLE { behavior: ' + sTableBehavior + ' ; }' ;
  62  
  63          sStyle += '</style>' ;
  64          FCK._BehaviorsStyle = sStyle ;
  65      }
  66      
  67      return FCK._BehaviorsStyle ;
  68  }
  69  
  70  function Doc_OnMouseUp()
  71  {
  72      if ( FCK.EditorWindow.event.srcElement.tagName == 'HTML' )
  73      {
  74          FCK.Focus() ;
  75          FCK.EditorWindow.event.cancelBubble    = true ;
  76          FCK.EditorWindow.event.returnValue    = false ;
  77      }
  78  }
  79  
  80  function Doc_OnPaste()
  81  {
  82      return ( FCK.Status == FCK_STATUS_COMPLETE && FCK.Events.FireEvent( "OnPaste" ) ) ;
  83  }
  84  
  85  function Doc_OnKeyDown()
  86  {
  87      if ( FCK.EditorWindow )
  88      {
  89          var e = FCK.EditorWindow.event ;
  90          
  91          if ( !( e.keyCode >=16 && e.keyCode <= 18 ) )
  92              Doc_OnKeyDownUndo() ;
  93      }
  94      return true ;
  95  }
  96  
  97  function Doc_OnKeyDownUndo()
  98  {
  99      if ( !FCKUndo.Typing )
 100      {
 101          FCKUndo.SaveUndoStep() ;
 102          FCKUndo.Typing = true ;
 103          FCK.Events.FireEvent( "OnSelectionChange" ) ;
 104      }
 105      
 106      FCKUndo.TypesCount++ ;
 107  
 108      if ( FCKUndo.TypesCount > FCKUndo.MaxTypes )
 109      {
 110          FCKUndo.TypesCount = 0 ;
 111          FCKUndo.SaveUndoStep() ;
 112      }
 113  }
 114  
 115  function Doc_OnDblClick()
 116  {
 117      FCK.OnDoubleClick( FCK.EditorWindow.event.srcElement ) ;
 118      FCK.EditorWindow.event.cancelBubble = true ;
 119  }
 120  
 121  function Doc_OnSelectionChange()
 122  {
 123      FCK.Events.FireEvent( "OnSelectionChange" ) ;
 124  }
 125  
 126  FCK.InitializeBehaviors = function( dontReturn )
 127  {
 128      // Set the focus to the editable area when clicking in the document area.
 129      // TODO: The cursor must be positioned at the end.
 130      this.EditorDocument.attachEvent( 'onmouseup', Doc_OnMouseUp ) ;
 131  
 132      // Intercept pasting operations
 133      this.EditorDocument.body.attachEvent( 'onpaste', Doc_OnPaste ) ;
 134  
 135      // Reset the context menu.
 136      FCK.ContextMenu._InnerContextMenu.AttachToElement( FCK.EditorDocument.body ) ;
 137  
 138      // Build the "TAB" key replacement (if necessary).
 139      if ( FCKConfig.TabSpaces > 0 )
 140      {
 141          window.FCKTabHTML = '' ;
 142          for ( i = 0 ; i < FCKConfig.TabSpaces ; i++ )
 143              window.FCKTabHTML += "&nbsp;" ;
 144      }
 145      this.EditorDocument.attachEvent("onkeydown", Doc_OnKeyDown ) ;
 146  
 147      this.EditorDocument.attachEvent("ondblclick", Doc_OnDblClick ) ;
 148  
 149      // Catch cursor selection changes.
 150      this.EditorDocument.attachEvent("onselectionchange", Doc_OnSelectionChange ) ;
 151  }
 152  
 153  FCK.InsertHtml = function( html )
 154  {
 155      html = FCKConfig.ProtectedSource.Protect( html ) ;
 156      html = FCK.ProtectUrls( html ) ;
 157  
 158  //    FCK.Focus() ;
 159      FCK.EditorWindow.focus() ;
 160  
 161      FCKUndo.SaveUndoStep() ;
 162  
 163      // Gets the actual selection.
 164      var oSel = FCK.EditorDocument.selection ;
 165  
 166      // Deletes the actual selection contents.
 167      if ( oSel.type.toLowerCase() == 'control' )
 168          oSel.clear() ;
 169  
 170      // Insert the HTML.
 171      oSel.createRange().pasteHTML( html ) ;
 172      
 173      FCKDocumentProcessor.Process( FCK.EditorDocument ) ;
 174  }
 175  
 176  FCK.SetInnerHtml = function( html )        // IE Only
 177  {
 178      var oDoc = FCK.EditorDocument ;
 179      // Using the following trick, any comment in the begining of the HTML will
 180      // be preserved.
 181      oDoc.body.innerHTML = '<div id="__fakeFCKRemove__">&nbsp;</div>' + html ;
 182      oDoc.getElementById('__fakeFCKRemove__').removeNode( true ) ;
 183  }
 184  
 185  function FCK_PreloadImages()
 186  {
 187      var oPreloader = new FCKImagePreloader() ;
 188      
 189      // Add the configured images.
 190      oPreloader.AddImages( FCKConfig.PreloadImages ) ;
 191  
 192      // Add the skin icons strip.
 193      oPreloader.AddImages( FCKConfig.SkinPath + 'fck_strip.gif' ) ;
 194  
 195      oPreloader.OnComplete = LoadToolbarSetup ;
 196      oPreloader.Start() ;
 197  }
 198  
 199  // Disable the context menu in the editor (outside the editing area).
 200  function Document_OnContextMenu()
 201  {
 202      return ( event.srcElement._FCKShowContextMenu == true ) ;
 203  }
 204  document.oncontextmenu = Document_OnContextMenu ;
 205  
 206  function FCK_Cleanup()
 207  {
 208      this.EditorWindow = null ;
 209      this.EditorDocument = null ;
 210  }
 211  
 212  FCK.Paste = function()
 213  {
 214      // As we call ExecuteNamedCommand('Paste'), it would enter in a loop. So, let's use a semaphore.
 215      if ( FCK._PasteIsRunning )
 216          return true ;
 217  
 218      if ( FCKConfig.ForcePasteAsPlainText )
 219      {
 220          FCK.PasteAsPlainText() ;    
 221          return false ;
 222      }
 223  
 224      var sHTML = FCK.GetClipboardHTML() ;
 225  
 226      if ( FCKConfig.AutoDetectPasteFromWord && sHTML.length > 0 )
 227      {
 228          var re = /<\w[^>]*(( class="?MsoNormal"?)|(="mso-))/gi ;
 229          if ( re.test( sHTML ) )
 230          {
 231              if ( confirm( FCKLang.PasteWordConfirm ) )
 232              {
 233                  FCK.PasteFromWord() ;
 234                  return false ;
 235              }
 236          }
 237      }
 238  
 239      // Instead of inserting the retrieved HTML, let's leave the OS work for us
 240      // and paste the content (return true); It could give better results.
 241      // Also, let's always make a custom implementation (return false), otherwise 
 242      // the new Keyboard Handler may conflict with this code, and the CTRL+V code
 243      // could result in a simple "V" being pasted.
 244  
 245      // Enable the semaphore to avoid a loop.
 246      FCK._PasteIsRunning = true ;
 247      
 248      FCK.ExecuteNamedCommand( 'Paste' ) ;
 249      
 250      // Removes the semaphore.
 251      delete FCK._PasteIsRunning  ;
 252  
 253      // "false" means that we have a custom implementation.
 254      return false ;
 255  }
 256  
 257  FCK.PasteAsPlainText = function()
 258  {
 259      // Get the data available in the clipboard and encodes it in HTML.
 260      var sText = clipboardData.getData("Text") ;
 261  
 262      if ( sText && sText.length > 0 )
 263      {
 264          // Replace the carriage returns with <BR>
 265          sText = FCKTools.HTMLEncode( sText ).replace( /\n/g, '<BR>' ) ;
 266          
 267          // Insert the resulting data in the editor.
 268          this.InsertHtml( sText ) ;
 269      }
 270  }
 271  
 272  FCK.InsertElement = function( element )
 273  {
 274      FCK.InsertHtml( element.outerHTML ) ;
 275  }
 276  
 277  FCK.GetClipboardHTML = function()
 278  {
 279      var oDiv = document.getElementById( '___FCKHiddenDiv' ) ;
 280      
 281      if ( !oDiv )
 282      {
 283          oDiv = document.createElement( 'DIV' ) ;
 284          oDiv.id = '___FCKHiddenDiv' ;
 285          
 286          var oDivStyle = oDiv.style ;
 287          oDivStyle.position        = 'absolute' ;
 288          oDivStyle.visibility    = oDivStyle.overflow    = 'hidden' ;
 289          oDivStyle.width            = oDivStyle.height        = 1 ;
 290      
 291          document.body.appendChild( oDiv ) ;
 292      }
 293      
 294      oDiv.innerHTML = '' ;
 295      
 296      var oTextRange = document.body.createTextRange() ;
 297      oTextRange.moveToElementText( oDiv ) ;
 298      oTextRange.execCommand( 'Paste' ) ;
 299      
 300      var sData = oDiv.innerHTML ;
 301      oDiv.innerHTML = '' ;
 302      
 303      return sData ;
 304  }
 305  
 306  FCK.AttachToOnSelectionChange = function( functionPointer )
 307  {
 308      this.Events.AttachEvent( 'OnSelectionChange', functionPointer ) ;
 309  }
 310  
 311  FCK.CreateLink = function( url )
 312  {
 313      // Remove any existing link in the selection.
 314      FCK.ExecuteNamedCommand( 'Unlink' ) ;
 315  
 316      if ( url.length > 0 )
 317      {
 318          // Generate a temporary name for the link.
 319          var sTempUrl = 'javascript:void(0);/*' + ( new Date().getTime() ) + '*/' ;
 320          
 321          // Use the internal "CreateLink" command to create the link.
 322          FCK.ExecuteNamedCommand( 'CreateLink', sTempUrl ) ;
 323  
 324          // Look for the just create link.
 325          var oLinks = this.EditorDocument.links ;
 326  
 327          for ( i = 0 ; i < oLinks.length ; i++ )
 328          {
 329              var oLink = oLinks[i] ;
 330              
 331              if ( oLink.href == sTempUrl )
 332              {
 333                  var sInnerHtml = oLink.innerHTML ;    // Save the innerHTML (IE changes it if it is like an URL).
 334                  oLink.href = url ;
 335                  oLink.innerHTML = sInnerHtml ;        // Restore the innerHTML.
 336                  return oLink ;
 337              }
 338          }
 339      }
 340  
 341      return null ;
 342  }


Généré le : Sun Feb 25 15:28:05 2007 par Balluche grâce à PHPXref 0.7