[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/libraries/ckeditor/_source/plugins/pastefromword/ -> 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  (function()
   6  {
   7      CKEDITOR.plugins.add( 'pastefromword',
   8      {
   9          init : function( editor )
  10          {
  11  
  12              // Flag indicate this command is actually been asked instead of a generic

  13              // pasting.

  14              var forceFromWord = 0;
  15              var resetFromWord = function()
  16                  {
  17                      setTimeout( function() { forceFromWord = 0; }, 0 );
  18                  };
  19  
  20              // Features bring by this command beside the normal process:

  21              // 1. No more bothering of user about the clean-up.

  22              // 2. Perform the clean-up even if content is not from MS-Word.

  23              // (e.g. from a MS-Word similar application.)

  24              editor.addCommand( 'pastefromword',
  25              {
  26                  canUndo : false,
  27                  exec : function()
  28                  {
  29                      forceFromWord = 1;
  30                      if ( editor.execCommand( 'paste' ) === false )
  31                      {
  32                          editor.on( 'dialogHide', function ( evt )
  33                              {
  34                                  evt.removeListener();
  35                                  resetFromWord();
  36                              });
  37                      }
  38                      else
  39                          resetFromWord();
  40                  }
  41              });
  42  
  43              // Register the toolbar button.

  44              editor.ui.addButton( 'PasteFromWord',
  45                  {
  46                      label : editor.lang.pastefromword.toolbar,
  47                      command : 'pastefromword'
  48                  });
  49  
  50              editor.on( 'paste', function( evt )
  51              {
  52                  var data = evt.data,
  53                      mswordHtml;
  54  
  55                  // MS-WORD format sniffing.

  56                  if ( ( mswordHtml = data[ 'html' ] )
  57                       && ( forceFromWord || ( /(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/ ).test( mswordHtml ) ) )
  58                  {
  59                      var isLazyLoad = this.loadFilterRules( function()
  60                          {
  61                              // Event continuation with the original data.

  62                              if ( isLazyLoad )
  63                                  editor.fire( 'paste', data );
  64                              else if ( !editor.config.pasteFromWordPromptCleanup
  65                                || ( forceFromWord || confirm( editor.lang.pastefromword.confirmCleanup ) ) )
  66                               {
  67                                  data[ 'html' ] = CKEDITOR.cleanWord( mswordHtml, editor );
  68                              }
  69                          });
  70  
  71                      // The cleanup rules are to be loaded, we should just cancel

  72                      // this event.

  73                      isLazyLoad && evt.cancel();
  74                  }
  75              }, this );
  76          },
  77  
  78          loadFilterRules : function( callback )
  79          {
  80  
  81              var isLoaded = CKEDITOR.cleanWord;
  82  
  83              if ( isLoaded )
  84                  callback();
  85              else
  86              {
  87                  var filterFilePath = CKEDITOR.getUrl(
  88                          CKEDITOR.config.pasteFromWordCleanupFile
  89                          || ( this.path + 'filter/default.js' ) );
  90  
  91                  // Load with busy indicator.

  92                  CKEDITOR.scriptLoader.load( filterFilePath, callback, null, false, true );
  93              }
  94  
  95              return !isLoaded;
  96          }
  97      });
  98  })();
  99  
 100  /**

 101   * Whether to prompt the user about the clean up of content being pasted from

 102   * MS Word.

 103   * @name CKEDITOR.config.pasteFromWordPromptCleanup

 104   * @since 3.1

 105   * @type Boolean

 106   * @default undefined

 107   * @example

 108   * config.pasteFromWordPromptCleanup = true;

 109   */
 110  
 111  /**

 112   * The file that provides the MS Word cleanup function for pasting operations.

 113   * Note: This is a global configuration shared by all editor instances present

 114   * in the page.

 115   * @name CKEDITOR.config.pasteFromWordCleanupFile

 116   * @since 3.1

 117   * @type String

 118   * @default 'default'

 119   * @example

 120   * // Load from 'pastefromword' plugin 'filter' sub folder (custom.js file).

 121   * CKEDITOR.config.pasteFromWordCleanupFile = 'custom';

 122   */


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