[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/libraries/ckeditor/_source/plugins/flash/ -> 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  (function()
   7  {
   8      var flashFilenameRegex = /\.swf(?:$|\?)/i,
   9          numberRegex = /^\d+(?:\.\d+)?$/;
  10  
  11  	function cssifyLength( length )
  12      {
  13          if ( numberRegex.test( length ) )
  14              return length + 'px';
  15          return length;
  16      }
  17  
  18  	function isFlashEmbed( element )
  19      {
  20          var attributes = element.attributes;
  21  
  22          return ( attributes.type == 'application/x-shockwave-flash' || flashFilenameRegex.test( attributes.src || '' ) );
  23      }
  24  
  25  	function createFakeElement( editor, realElement )
  26      {
  27          var fakeElement = editor.createFakeParserElement( realElement, 'cke_flash', 'flash', true ),
  28              fakeStyle = fakeElement.attributes.style || '';
  29  
  30          var width = realElement.attributes.width,
  31              height = realElement.attributes.height;
  32  
  33          if ( typeof width != 'undefined' )
  34              fakeStyle = fakeElement.attributes.style = fakeStyle + 'width:' + cssifyLength( width ) + ';';
  35  
  36          if ( typeof height != 'undefined' )
  37              fakeStyle = fakeElement.attributes.style = fakeStyle + 'height:' + cssifyLength( height ) + ';';
  38  
  39          return fakeElement;
  40      }
  41  
  42      CKEDITOR.plugins.add( 'flash',
  43      {
  44          init : function( editor )
  45          {
  46              editor.addCommand( 'flash', new CKEDITOR.dialogCommand( 'flash' ) );
  47              editor.ui.addButton( 'Flash',
  48                  {
  49                      label : editor.lang.common.flash,
  50                      command : 'flash'
  51                  });
  52              CKEDITOR.dialog.add( 'flash', this.path + 'dialogs/flash.js' );
  53  
  54              editor.addCss(
  55                  'img.cke_flash' +
  56                  '{' +
  57                      'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/placeholder.png' ) + ');' +
  58                      'background-position: center center;' +
  59                      'background-repeat: no-repeat;' +
  60                      'border: 1px solid #a9a9a9;' +
  61                      'width: 80px;' +
  62                      'height: 80px;' +
  63                  '}'
  64                  );
  65  
  66              // If the "menu" plugin is loaded, register the menu items.

  67              if ( editor.addMenuItems )
  68              {
  69                  editor.addMenuItems(
  70                      {
  71                          flash :
  72                          {
  73                              label : editor.lang.flash.properties,
  74                              command : 'flash',
  75                              group : 'flash'
  76                          }
  77                      });
  78              }
  79  
  80              editor.on( 'doubleclick', function( evt )
  81                  {
  82                      var element = evt.data.element;
  83  
  84                      if ( element.is( 'img' ) && element.getAttribute( '_cke_real_element_type' ) == 'flash' )
  85                          evt.data.dialog = 'flash';
  86                  });
  87  
  88              // If the "contextmenu" plugin is loaded, register the listeners.

  89              if ( editor.contextMenu )
  90              {
  91                  editor.contextMenu.addListener( function( element, selection )
  92                      {
  93                          if ( element && element.is( 'img' ) && !element.isReadOnly()
  94                                  && element.getAttribute( '_cke_real_element_type' ) == 'flash' )
  95                              return { flash : CKEDITOR.TRISTATE_OFF };
  96                      });
  97              }
  98          },
  99  
 100          afterInit : function( editor )
 101          {
 102              var dataProcessor = editor.dataProcessor,
 103                  dataFilter = dataProcessor && dataProcessor.dataFilter;
 104  
 105              if ( dataFilter )
 106              {
 107                  dataFilter.addRules(
 108                      {
 109                          elements :
 110                          {
 111                              'cke:object' : function( element )
 112                              {
 113                                  var attributes = element.attributes,
 114                                      classId = attributes.classid && String( attributes.classid ).toLowerCase();
 115  
 116                                  if ( !classId )
 117                                  {
 118                                      // Look for the inner <embed>

 119                                      for ( var i = 0 ; i < element.children.length ; i++ )
 120                                      {
 121                                          if ( element.children[ i ].name == 'cke:embed' )
 122                                          {
 123                                              if ( !isFlashEmbed( element.children[ i ] ) )
 124                                                  return null;
 125  
 126                                              return createFakeElement( editor, element );
 127                                          }
 128                                      }
 129                                      return null;
 130                                  }
 131  
 132                                  return createFakeElement( editor, element );
 133                              },
 134  
 135                              'cke:embed' : function( element )
 136                              {
 137                                  if ( !isFlashEmbed( element ) )
 138                                      return null;
 139  
 140                                  return createFakeElement( editor, element );
 141                              }
 142                          }
 143                      },
 144                      5);
 145              }
 146          },
 147  
 148          requires : [ 'fakeobjects' ]
 149      });
 150  })();
 151  
 152  CKEDITOR.tools.extend( CKEDITOR.config,
 153  {
 154      /**

 155       * Save as EMBED tag only. This tag is unrecommended.

 156       * @type Boolean

 157       * @default false

 158       */
 159      flashEmbedTagOnly : false,
 160  
 161      /**

 162       * Add EMBED tag as alternative: &lt;object&gt&lt;embed&gt&lt;/embed&gt&lt;/object&gt

 163       * @type Boolean

 164       * @default false

 165       */
 166      flashAddEmbedTag : true,
 167  
 168      /**

 169       * Use embedTagOnly and addEmbedTag values on edit.

 170       * @type Boolean

 171       * @default false

 172       */
 173      flashConvertOnEdit : false
 174  } );


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