Nation Notes module contributed by Z&H Healthcare.
[openemr.git] / library / custom_template / ckeditor / _source / plugins / entities / plugin.js
blob8beb09eb45e1252e68dcc3bc4366acfbe0a484ff
1 /*
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
6 (function()
8         // Base HTML entities.
9         var htmlbase = 'nbsp,gt,lt';
11         var entities =
12                 // Latin-1 Entities
13                 'quot,iexcl,cent,pound,curren,yen,brvbar,sect,uml,copy,ordf,laquo,' +
14                 'not,shy,reg,macr,deg,plusmn,sup2,sup3,acute,micro,para,middot,' +
15                 'cedil,sup1,ordm,raquo,frac14,frac12,frac34,iquest,times,divide,' +
17                 // Symbols
18                 'fnof,bull,hellip,prime,Prime,oline,frasl,weierp,image,real,trade,' +
19                 'alefsym,larr,uarr,rarr,darr,harr,crarr,lArr,uArr,rArr,dArr,hArr,' +
20                 'forall,part,exist,empty,nabla,isin,notin,ni,prod,sum,minus,lowast,' +
21                 'radic,prop,infin,ang,and,or,cap,cup,int,there4,sim,cong,asymp,ne,' +
22                 'equiv,le,ge,sub,sup,nsub,sube,supe,oplus,otimes,perp,sdot,lceil,' +
23                 'rceil,lfloor,rfloor,lang,rang,loz,spades,clubs,hearts,diams,' +
25                 // Other Special Characters
26                 'circ,tilde,ensp,emsp,thinsp,zwnj,zwj,lrm,rlm,ndash,mdash,lsquo,' +
27                 'rsquo,sbquo,ldquo,rdquo,bdquo,dagger,Dagger,permil,lsaquo,rsaquo,' +
28                 'euro';
30         // Latin Letters Entities
31         var latin =
32                 'Agrave,Aacute,Acirc,Atilde,Auml,Aring,AElig,Ccedil,Egrave,Eacute,' +
33                 'Ecirc,Euml,Igrave,Iacute,Icirc,Iuml,ETH,Ntilde,Ograve,Oacute,Ocirc,' +
34                 'Otilde,Ouml,Oslash,Ugrave,Uacute,Ucirc,Uuml,Yacute,THORN,szlig,' +
35                 'agrave,aacute,acirc,atilde,auml,aring,aelig,ccedil,egrave,eacute,' +
36                 'ecirc,euml,igrave,iacute,icirc,iuml,eth,ntilde,ograve,oacute,ocirc,' +
37                 'otilde,ouml,oslash,ugrave,uacute,ucirc,uuml,yacute,thorn,yuml,' +
38                 'OElig,oelig,Scaron,scaron,Yuml';
40         // Greek Letters Entities.
41         var greek =
42                 'Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,Mu,' +
43                 'Nu,Xi,Omicron,Pi,Rho,Sigma,Tau,Upsilon,Phi,Chi,Psi,Omega,alpha,' +
44                 'beta,gamma,delta,epsilon,zeta,eta,theta,iota,kappa,lambda,mu,nu,xi,' +
45                 'omicron,pi,rho,sigmaf,sigma,tau,upsilon,phi,chi,psi,omega,thetasym,' +
46                 'upsih,piv';
48         /**
49          * Create a mapping table between one character and it's entity form from a list of entity names.
50          * @param reverse {Boolean} Whether create a reverse map from the entity string form to actual character.
51          */
52         function buildTable( entities, reverse )
53         {
54                 var table = {},
55                         regex = [];
57                 // Entities that the browsers DOM don't transform to the final char
58                 // automatically.
59                 var specialTable =
60                         {
61                                 nbsp    : '\u00A0',             // IE | FF
62                                 shy             : '\u00AD',             // IE
63                                 gt              : '\u003E',             // IE | FF |   --   | Opera
64                                 lt              : '\u003C'              // IE | FF | Safari | Opera
65                         };
67                 entities = entities.replace( /\b(nbsp|shy|gt|lt|amp)(?:,|$)/g, function( match, entity )
68                         {
69                                 var org = reverse ? '&' + entity + ';' : specialTable[ entity ],
70                                         result = reverse ? specialTable[ entity ] : '&' + entity + ';';
72                                 table[ org ] = result;
73                                 regex.push( org );
74                                 return '';
75                         });
77                 if ( !reverse && entities )
78                 {
79                         // Transforms the entities string into an array.
80                         entities = entities.split( ',' );
82                         // Put all entities inside a DOM element, transforming them to their
83                         // final chars.
84                         var div = document.createElement( 'div' ),
85                                 chars;
86                         div.innerHTML = '&' + entities.join( ';&' ) + ';';
87                         chars = div.innerHTML;
88                         div = null;
90                         // Add all chars to the table.
91                         for ( var i = 0 ; i < chars.length ; i++ )
92                         {
93                                 var charAt = chars.charAt( i );
94                                 table[ charAt ] = '&' + entities[ i ] + ';';
95                                 regex.push( charAt );
96                         }
97                 }
99                 table.regex = regex.join( reverse ? '|' : '' );
101                 return table;
102         }
104         CKEDITOR.plugins.add( 'entities',
105         {
106                 afterInit : function( editor )
107                 {
108                         var config = editor.config;
110                         var dataProcessor = editor.dataProcessor,
111                                 htmlFilter = dataProcessor && dataProcessor.htmlFilter;
113                         if ( htmlFilter )
114                         {
115                                 // Mandatory HTML base entities.
116                                 var selectedEntities = htmlbase;
118                                 if ( config.entities )
119                                 {
120                                         selectedEntities += ',' + entities;
121                                         if ( config.entities_latin )
122                                                 selectedEntities += ',' + latin;
124                                         if ( config.entities_greek )
125                                                 selectedEntities += ',' + greek;
127                                         if ( config.entities_additional )
128                                                 selectedEntities += ',' + config.entities_additional;
129                                 }
131                                 var entitiesTable = buildTable( selectedEntities );
133                                 // Create the Regex used to find entities in the text.
134                                 var entitiesRegex = '[' + entitiesTable.regex + ']';
135                                 delete entitiesTable.regex;
137                                 if ( config.entities && config.entities_processNumerical )
138                                         entitiesRegex = '[^ -~]|' + entitiesRegex ;
140                                 entitiesRegex = new RegExp( entitiesRegex, 'g' );
142                                 function getEntity( character )
143                                 {
144                                         return config.entities_processNumerical == 'force' || !entitiesTable[ character ] ?
145                                                    '&#' + character.charCodeAt(0) + ';'
146                                                         : entitiesTable[ character ];
147                                 }
149                                 // Decode entities that the browsers has transformed
150                                 // at first place.
151                                 var baseEntitiesTable = buildTable( [ htmlbase, 'shy' ].join( ',' ) , true ),
152                                         baseEntitiesRegex = new RegExp( baseEntitiesTable.regex, 'g' );
154                                 function getChar( character )
155                                 {
156                                         return baseEntitiesTable[ character ];
157                                 }
159                                 htmlFilter.addRules(
160                                         {
161                                                 text : function( text )
162                                                 {
163                                                         return text.replace( baseEntitiesRegex, getChar )
164                                                                         .replace( entitiesRegex, getEntity );
165                                                 }
166                                         });
167                         }
168                 }
169         });
170 })();
173  * Whether to use HTML entities in the output.
174  * @type Boolean
175  * @default true
176  * @example
177  * config.entities = false;
178  */
179 CKEDITOR.config.entities = true;
182  * Whether to convert some Latin characters (Latin alphabet No&#46; 1, ISO 8859-1)
183  * to HTML entities. The list of entities can be found at the
184  * <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>.
185  * @type Boolean
186  * @default true
187  * @example
188  * config.entities_latin = false;
189  */
190 CKEDITOR.config.entities_latin = true;
193  * Whether to convert some symbols, mathematical symbols, and Greek letters to
194  * HTML entities. This may be more relevant for users typing text written in Greek.
195  * The list of entities can be found at the
196  * <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>.
197  * @type Boolean
198  * @default true
199  * @example
200  * config.entities_greek = false;
201  */
202 CKEDITOR.config.entities_greek = true;
205  * Whether to convert all remaining characters, not comprised in the ASCII
206  * character table, to their relative decimal numeric representation of HTML entity.
207  * When specified as the value 'force', it will simply convert all entities into the above form.
208  * For example, the phrase "This is Chinese: &#27721;&#35821;." is outputted
209  * as "This is Chinese: &amp;#27721;&amp;#35821;."
210  * @type Boolean
211  * @type Boolean|String
212  * @default false
213  * @example
214  * config.entities_processNumerical = true;
215  * config.entities_processNumerical = 'force';          //Convert from "&nbsp;" into "&#160;";
216  */
219  * An additional list of entities to be used. It's a string containing each
220  * entry separated by a comma. Entities names or number must be used, exclusing
221  * the "&amp;" preffix and the ";" termination.
222  * @default '#39'  // The single quote (') character.
223  * @type String
224  * @example
225  */
226 CKEDITOR.config.entities_additional = '#39';