[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/libraries/ckeditor/_source/plugins/editingblock/ -> plugin.js (source)

   1  /*

   2  Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.

   3  For licensing, see LICENSE.html or http://ckeditor.com/license

   4  */
   5  
   6  /**

   7   * @fileOverview The default editing block plugin, which holds the editing area

   8   *        and source view.

   9   */
  10  
  11  (function()
  12  {
  13      var getMode = function( editor, mode )
  14      {
  15          return editor._.modes && editor._.modes[ mode || editor.mode ];
  16      };
  17  
  18      // This is a semaphore used to avoid recursive calls between

  19      // the following data handling functions.

  20      var isHandlingData;
  21  
  22      CKEDITOR.plugins.add( 'editingblock',
  23      {
  24          init : function( editor )
  25          {
  26              if ( !editor.config.editingBlock )
  27                  return;
  28  
  29              editor.on( 'themeSpace', function( event )
  30                  {
  31                      if ( event.data.space == 'contents' )
  32                          event.data.html += '<br>';
  33                  });
  34  
  35              editor.on( 'themeLoaded', function()
  36                  {
  37                      editor.fireOnce( 'editingBlockReady' );
  38                  });
  39  
  40              editor.on( 'uiReady', function()
  41                  {
  42                      editor.setMode( editor.config.startupMode );
  43                  });
  44  
  45              editor.on( 'afterSetData', function()
  46                  {
  47                      if ( !isHandlingData )
  48                      {
  49  						function setData()
  50                          {
  51                              isHandlingData = true;
  52                              getMode( editor ).loadData( editor.getData() );
  53                              isHandlingData = false;
  54                          }
  55  
  56                          if ( editor.mode )
  57                              setData();
  58                          else
  59                          {
  60                              editor.on( 'mode', function()
  61                                  {
  62                                      setData();
  63                                      editor.removeListener( 'mode', arguments.callee );
  64                                  });
  65                          }
  66                      }
  67                  });
  68  
  69              editor.on( 'beforeGetData', function()
  70                  {
  71                      if ( !isHandlingData && editor.mode )
  72                      {
  73                          isHandlingData = true;
  74                          editor.setData( getMode( editor ).getData() );
  75                          isHandlingData = false;
  76                      }
  77                  });
  78  
  79              editor.on( 'getSnapshot', function( event )
  80                  {
  81                      if ( editor.mode )
  82                          event.data = getMode( editor ).getSnapshotData();
  83                  });
  84  
  85              editor.on( 'loadSnapshot', function( event )
  86                  {
  87                      if ( editor.mode )
  88                          getMode( editor ).loadSnapshotData( event.data );
  89                  });
  90  
  91              // For the first "mode" call, we'll also fire the "instanceReady"

  92              // event.

  93              editor.on( 'mode', function( event )
  94                  {
  95                      // Do that once only.

  96                      event.removeListener();
  97  
  98                      // Redirect the focus into editor for webkit. (#5713)

  99                      CKEDITOR.env.webkit && editor.container.on( 'focus', function()
 100                          {
 101                              editor.focus();
 102                          });
 103  
 104                      if ( editor.config.startupFocus )
 105                          editor.focus();
 106  
 107                      // Fire instanceReady for both the editor and CKEDITOR, but

 108                      // defer this until the whole execution has completed

 109                      // to guarantee the editor is fully responsible.

 110                      setTimeout( function(){
 111                          editor.fireOnce( 'instanceReady' );
 112                          CKEDITOR.fire( 'instanceReady', null, editor );
 113                      } );
 114                  });
 115          }
 116      });
 117  
 118      /**

 119       * The current editing mode. An editing mode is basically a viewport for

 120       * editing or content viewing. By default the possible values for this

 121       * property are "wysiwyg" and "source".

 122       * @type String

 123       * @example

 124       * alert( CKEDITOR.instances.editor1.mode );  // "wysiwyg" (e.g.)

 125       */
 126      CKEDITOR.editor.prototype.mode = '';
 127  
 128      /**

 129       * Registers an editing mode. This function is to be used mainly by plugins.

 130       * @param {String} mode The mode name.

 131       * @param {Object} modeEditor The mode editor definition.

 132       * @example

 133       */
 134      CKEDITOR.editor.prototype.addMode = function( mode, modeEditor )
 135      {
 136          modeEditor.name = mode;
 137          ( this._.modes || ( this._.modes = {} ) )[ mode ] = modeEditor;
 138      };
 139  
 140      /**

 141       * Sets the current editing mode in this editor instance.

 142       * @param {String} mode A registered mode name.

 143       * @example

 144       * // Switch to "source" view.

 145       * CKEDITOR.instances.editor1.setMode( 'source' );

 146       */
 147      CKEDITOR.editor.prototype.setMode = function( mode )
 148      {
 149          var data,
 150              holderElement = this.getThemeSpace( 'contents' ),
 151              isDirty = this.checkDirty();
 152  
 153          // Unload the previous mode.

 154          if ( this.mode )
 155          {
 156              if ( mode == this.mode )
 157                  return;
 158  
 159              this.fire( 'beforeModeUnload' );
 160  
 161              var currentMode = getMode( this );
 162              data = currentMode.getData();
 163              currentMode.unload( holderElement );
 164              this.mode = '';
 165          }
 166  
 167          holderElement.setHtml( '' );
 168  
 169          // Load required mode.

 170          var modeEditor = getMode( this, mode );
 171          if ( !modeEditor )
 172              throw '[CKEDITOR.editor.setMode] Unknown mode "' + mode + '".';
 173  
 174          if ( !isDirty )
 175          {
 176              this.on( 'mode', function()
 177                  {
 178                      this.resetDirty();
 179                      this.removeListener( 'mode', arguments.callee );
 180                  });
 181          }
 182  
 183          modeEditor.load( holderElement, ( typeof data ) != 'string'  ? this.getData() : data);
 184      };
 185  
 186      /**

 187       * Moves the selection focus to the editing are space in the editor.

 188       */
 189      CKEDITOR.editor.prototype.focus = function()
 190      {
 191          var mode = getMode( this );
 192          if ( mode )
 193              mode.focus();
 194      };
 195  })();
 196  
 197  /**

 198   * The mode to load at the editor startup. It depends on the plugins

 199   * loaded. By default, the "wysiwyg" and "source" modes are available.

 200   * @type String

 201   * @default 'wysiwyg'

 202   * @example

 203   * config.startupMode = 'source';

 204   */
 205  CKEDITOR.config.startupMode = 'wysiwyg';
 206  
 207  /**

 208   * Sets whether the editor should have the focus when the page loads.

 209   * @type Boolean

 210   * @default false

 211   * @example

 212   * config.startupFocus = true;

 213   */
 214  CKEDITOR.config.startupFocus = false;
 215  
 216  /**

 217   * Whether to render or not the editing block area in the editor interface.

 218   * @type Boolean

 219   * @default true

 220   * @example

 221   * config.editingBlock = false;

 222   */
 223  CKEDITOR.config.editingBlock = true;
 224  
 225  /**

 226   * Fired when a CKEDITOR instance is created, fully initialized and ready for interaction.

 227   * @name CKEDITOR#instanceReady

 228   * @event

 229   * @param {CKEDITOR.editor} editor The editor instance that has been created.

 230   */


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7