[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/libraries/ckeditor/_source/plugins/format/ -> 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  CKEDITOR.plugins.add( 'format',
   7  {
   8      requires : [ 'richcombo', 'styles' ],
   9  
  10      init : function( editor )
  11      {
  12          var config = editor.config,
  13              lang = editor.lang.format;
  14  
  15          // Gets the list of tags from the settings.

  16          var tags = config.format_tags.split( ';' );
  17  
  18          // Create style objects for all defined styles.

  19          var styles = {};
  20          for ( var i = 0 ; i < tags.length ; i++ )
  21          {
  22              var tag = tags[ i ];
  23              styles[ tag ] = new CKEDITOR.style( config[ 'format_' + tag ] );
  24              styles[ tag ]._.enterMode = editor.config.enterMode;
  25          }
  26  
  27          editor.ui.addRichCombo( 'Format',
  28              {
  29                  label : lang.label,
  30                  title : lang.panelTitle,
  31                  className : 'cke_format',
  32                  panel :
  33                  {
  34                      css : editor.skin.editor.css.concat( config.contentsCss ),
  35                      multiSelect : false,
  36                      attributes : { 'aria-label' : lang.panelTitle }
  37                  },
  38  
  39                  init : function()
  40                  {
  41                      this.startGroup( lang.panelTitle );
  42  
  43                      for ( var tag in styles )
  44                      {
  45                          var label = lang[ 'tag_' + tag ];
  46  
  47                          // Add the tag entry to the panel list.

  48                          this.add( tag, '<' + tag + '>' + label + '</' + tag + '>', label );
  49                      }
  50                  },
  51  
  52                  onClick : function( value )
  53                  {
  54                      editor.focus();
  55                      editor.fire( 'saveSnapshot' );
  56  
  57                      styles[ value ].apply( editor.document );
  58  
  59                      // Save the undo snapshot after all changes are affected. (#4899)

  60                      setTimeout( function()
  61                      {
  62                          editor.fire( 'saveSnapshot' );
  63                      }, 0 );
  64                  },
  65  
  66                  onRender : function()
  67                  {
  68                      editor.on( 'selectionChange', function( ev )
  69                          {
  70                              var currentTag = this.getValue();
  71  
  72                              var elementPath = ev.data.path;
  73  
  74                              for ( var tag in styles )
  75                              {
  76                                  if ( styles[ tag ].checkActive( elementPath ) )
  77                                  {
  78                                      if ( tag != currentTag )
  79                                          this.setValue( tag, editor.lang.format[ 'tag_' + tag ] );
  80                                      return;
  81                                  }
  82                              }
  83  
  84                              // If no styles match, just empty it.

  85                              this.setValue( '' );
  86                          },
  87                          this);
  88                  }
  89              });
  90      }
  91  });
  92  
  93  /**

  94   * A list of semi colon separated style names (by default tags) representing

  95   * the style definition for each entry to be displayed in the Format combo in

  96   * the toolbar. Each entry must have its relative definition configuration in a

  97   * setting named "format_(tagName)". For example, the "p" entry has its

  98   * definition taken from config.format_p.

  99   * @type String

 100   * @default 'p;h1;h2;h3;h4;h5;h6;pre;address;div'

 101   * @example

 102   * config.format_tags = 'p;h2;h3;pre'

 103   */
 104  CKEDITOR.config.format_tags = 'p;h1;h2;h3;h4;h5;h6;pre;address;div';
 105  
 106  /**

 107   * The style definition to be used to apply the "Normal" format.

 108   * @type Object

 109   * @default { element : 'p' }

 110   * @example

 111   * config.format_p = { element : 'p', attributes : { class : 'normalPara' } };

 112   */
 113  CKEDITOR.config.format_p = { element : 'p' };
 114  
 115  /**

 116   * The style definition to be used to apply the "Normal (DIV)" format.

 117   * @type Object

 118   * @default { element : 'div' }

 119   * @example

 120   * config.format_div = { element : 'div', attributes : { class : 'normalDiv' } };

 121   */
 122  CKEDITOR.config.format_div = { element : 'div' };
 123  
 124  /**

 125   * The style definition to be used to apply the "Formatted" format.

 126   * @type Object

 127   * @default { element : 'pre' }

 128   * @example

 129   * config.format_pre = { element : 'pre', attributes : { class : 'code' } };

 130   */
 131  CKEDITOR.config.format_pre = { element : 'pre' };
 132  
 133  /**

 134   * The style definition to be used to apply the "Address" format.

 135   * @type Object

 136   * @default { element : 'address' }

 137   * @example

 138   * config.format_address = { element : 'address', attributes : { class : 'styledAddress' } };

 139   */
 140  CKEDITOR.config.format_address = { element : 'address' };
 141  
 142  /**

 143   * The style definition to be used to apply the "Heading 1" format.

 144   * @type Object

 145   * @default { element : 'h1' }

 146   * @example

 147   * config.format_h1 = { element : 'h1', attributes : { class : 'contentTitle1' } };

 148   */
 149  CKEDITOR.config.format_h1 = { element : 'h1' };
 150  
 151  /**

 152   * The style definition to be used to apply the "Heading 1" format.

 153   * @type Object

 154   * @default { element : 'h2' }

 155   * @example

 156   * config.format_h2 = { element : 'h2', attributes : { class : 'contentTitle2' } };

 157   */
 158  CKEDITOR.config.format_h2 = { element : 'h2' };
 159  
 160  /**

 161   * The style definition to be used to apply the "Heading 1" format.

 162   * @type Object

 163   * @default { element : 'h3' }

 164   * @example

 165   * config.format_h3 = { element : 'h3', attributes : { class : 'contentTitle3' } };

 166   */
 167  CKEDITOR.config.format_h3 = { element : 'h3' };
 168  
 169  /**

 170   * The style definition to be used to apply the "Heading 1" format.

 171   * @type Object

 172   * @default { element : 'h4' }

 173   * @example

 174   * config.format_h4 = { element : 'h4', attributes : { class : 'contentTitle4' } };

 175   */
 176  CKEDITOR.config.format_h4 = { element : 'h4' };
 177  
 178  /**

 179   * The style definition to be used to apply the "Heading 1" format.

 180   * @type Object

 181   * @default { element : 'h5' }

 182   * @example

 183   * config.format_h5 = { element : 'h5', attributes : { class : 'contentTitle5' } };

 184   */
 185  CKEDITOR.config.format_h5 = { element : 'h5' };
 186  
 187  /**

 188   * The style definition to be used to apply the "Heading 1" format.

 189   * @type Object

 190   * @default { element : 'h6' }

 191   * @example

 192   * config.format_h6 = { element : 'h6', attributes : { class : 'contentTitle6' } };

 193   */
 194  CKEDITOR.config.format_h6 = { element : 'h6' };


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