[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/libraries/ckeditor/_source/plugins/entities/ -> 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 entities =
   9  
  10          // Base HTML entities.

  11          'nbsp,gt,lt,quot,' +
  12  
  13          // Latin-1 Entities

  14          'iexcl,cent,pound,curren,yen,brvbar,sect,uml,copy,ordf,laquo,' +
  15          'not,shy,reg,macr,deg,plusmn,sup2,sup3,acute,micro,para,middot,' +
  16          'cedil,sup1,ordm,raquo,frac14,frac12,frac34,iquest,times,divide,' +
  17  
  18          // Symbols

  19          'fnof,bull,hellip,prime,Prime,oline,frasl,weierp,image,real,trade,' +
  20          'alefsym,larr,uarr,rarr,darr,harr,crarr,lArr,uArr,rArr,dArr,hArr,' +
  21          'forall,part,exist,empty,nabla,isin,notin,ni,prod,sum,minus,lowast,' +
  22          'radic,prop,infin,ang,and,or,cap,cup,int,there4,sim,cong,asymp,ne,' +
  23          'equiv,le,ge,sub,sup,nsub,sube,supe,oplus,otimes,perp,sdot,lceil,' +
  24          'rceil,lfloor,rfloor,lang,rang,loz,spades,clubs,hearts,diams,' +
  25  
  26          // Other Special Characters

  27          'circ,tilde,ensp,emsp,thinsp,zwnj,zwj,lrm,rlm,ndash,mdash,lsquo,' +
  28          'rsquo,sbquo,ldquo,rdquo,bdquo,dagger,Dagger,permil,lsaquo,rsaquo,' +
  29          'euro';
  30  
  31      // Latin Letters Entities

  32      var latin =
  33          'Agrave,Aacute,Acirc,Atilde,Auml,Aring,AElig,Ccedil,Egrave,Eacute,' +
  34          'Ecirc,Euml,Igrave,Iacute,Icirc,Iuml,ETH,Ntilde,Ograve,Oacute,Ocirc,' +
  35          'Otilde,Ouml,Oslash,Ugrave,Uacute,Ucirc,Uuml,Yacute,THORN,szlig,' +
  36          'agrave,aacute,acirc,atilde,auml,aring,aelig,ccedil,egrave,eacute,' +
  37          'ecirc,euml,igrave,iacute,icirc,iuml,eth,ntilde,ograve,oacute,ocirc,' +
  38          'otilde,ouml,oslash,ugrave,uacute,ucirc,uuml,yacute,thorn,yuml,' +
  39          'OElig,oelig,Scaron,scaron,Yuml';
  40  
  41      // Greek Letters Entities.

  42      var greek =
  43          'Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,Mu,' +
  44          'Nu,Xi,Omicron,Pi,Rho,Sigma,Tau,Upsilon,Phi,Chi,Psi,Omega,alpha,' +
  45          'beta,gamma,delta,epsilon,zeta,eta,theta,iota,kappa,lambda,mu,nu,xi,' +
  46          'omicron,pi,rho,sigmaf,sigma,tau,upsilon,phi,chi,psi,omega,thetasym,' +
  47          'upsih,piv';
  48  
  49  	function buildTable( entities )
  50      {
  51          var table = {},
  52              regex = [];
  53  
  54          // Entities that the browsers DOM don't transform to the final char

  55          // automatically.

  56          var specialTable =
  57              {
  58                  nbsp    : '\u00A0',        // IE | FF
  59                  shy        : '\u00AD',        // IE
  60                  gt        : '\u003E',        // IE | FF |   --   | Opera
  61                  lt        : '\u003C'        // IE | FF | Safari | Opera
  62              };
  63  
  64          entities = entities.replace( /\b(nbsp|shy|gt|lt|amp)(?:,|$)/g, function( match, entity )
  65              {
  66                  table[ specialTable[ entity ] ] = '&' + entity + ';';
  67                  regex.push( specialTable[ entity ] );
  68                  return '';
  69              });
  70  
  71          // Transforms the entities string into an array.

  72          entities = entities.split( ',' );
  73  
  74          // Put all entities inside a DOM element, transforming them to their

  75          // final chars.

  76          var div = document.createElement( 'div' ),
  77              chars;
  78          div.innerHTML = '&' + entities.join( ';&' ) + ';';
  79          chars = div.innerHTML;
  80          div = null;
  81  
  82          // Add all chars to the table.

  83          for ( var i = 0 ; i < chars.length ; i++ )
  84          {
  85              var charAt = chars.charAt( i );
  86              table[ charAt ] = '&' + entities[ i ] + ';';
  87              regex.push( charAt );
  88          }
  89  
  90          table.regex = regex.join( '' );
  91  
  92          return table;
  93      }
  94  
  95      CKEDITOR.plugins.add( 'entities',
  96      {
  97          afterInit : function( editor )
  98          {
  99              var config = editor.config;
 100  
 101              if ( !config.entities )
 102                  return;
 103  
 104              var dataProcessor = editor.dataProcessor,
 105                  htmlFilter = dataProcessor && dataProcessor.htmlFilter;
 106  
 107              if ( htmlFilter )
 108              {
 109                  var selectedEntities = entities;
 110  
 111                  if ( config.entities_latin )
 112                      selectedEntities += ',' + latin;
 113  
 114                  if ( config.entities_greek )
 115                      selectedEntities += ',' + greek;
 116  
 117                  if ( config.entities_additional )
 118                      selectedEntities += ',' + config.entities_additional;
 119  
 120                  var entitiesTable = buildTable( selectedEntities );
 121  
 122                  // Create the Regex used to find entities in the text.

 123                  var entitiesRegex = '[' + entitiesTable.regex + ']';
 124                  delete entitiesTable.regex;
 125  
 126                  if ( config.entities_processNumerical )
 127                      entitiesRegex = '[^ -~]|' + entitiesRegex ;
 128  
 129                  entitiesRegex = new RegExp( entitiesRegex, 'g' );
 130  
 131  				function getChar( character )
 132                  {
 133                      return entitiesTable[ character ] || ( '&#' + character.charCodeAt(0) + ';' );
 134                  }
 135  
 136                  htmlFilter.addRules(
 137                      {
 138                          text : function( text )
 139                          {
 140                              return text.replace( entitiesRegex, getChar );
 141                          }
 142                      });
 143              }
 144          }
 145      });
 146  })();
 147  
 148  /**

 149   * Whether to use HTML entities in the output.

 150   * @type Boolean

 151   * @default true

 152   * @example

 153   * config.entities = false;

 154   */
 155  CKEDITOR.config.entities = true;
 156  
 157  /**

 158   * Whether to convert some Latin characters (Latin alphabet No&#46; 1, ISO 8859-1)

 159   * to HTML entities. The list of entities can be found at the

 160   * <a href="http://www.w3.org/TR/html4/sgml/entities.html#h-24.2.1">W3C HTML 4.01 Specification, section 24.2.1</a>.

 161   * @type Boolean

 162   * @default true

 163   * @example

 164   * config.entities_latin = false;

 165   */
 166  CKEDITOR.config.entities_latin = true;
 167  
 168  /**

 169   * Whether to convert some symbols, mathematical symbols, and Greek letters to

 170   * HTML entities. This may be more relevant for users typing text written in Greek.

 171   * The list of entities can be found at the

 172   * <a href="http://www.w3.org/TR/html4/sgml/entities.html#h-24.3.1">W3C HTML 4.01 Specification, section 24.3.1</a>.

 173   * @type Boolean

 174   * @default true

 175   * @example

 176   * config.entities_greek = false;

 177   */
 178  CKEDITOR.config.entities_greek = true;
 179  
 180  /**

 181   * Whether to convert all remaining characters, not comprised in the ASCII

 182   * character table, to their relative numeric representation of HTML entity.

 183   * For example, the phrase "This is Chinese: &#27721;&#35821;." is outputted

 184   * as "This is Chinese: &amp;#27721;&amp;#35821;."

 185   * @type Boolean

 186   * @default false

 187   * @example

 188   * config.entities_processNumerical = true;

 189   */
 190  CKEDITOR.config.entities_processNumerical = false;
 191  
 192  /**

 193   * An additional list of entities to be used. It's a string containing each

 194   * entry separated by a comma. Entities names or number must be used, exclusing

 195   * the "&amp;" preffix and the ";" termination.

 196   * @default '#39'  // The single quote (') character.

 197   * @type String

 198   * @example

 199   */
 200  CKEDITOR.config.entities_additional = '#39';


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