comparison static/js/tiny_mce/tiny_mce_src.js @ 442:6c182ceb7147

Fixing #217; upgrade TinyMCE to 3.4.2 and enable the paste plugin.
author Brian Neal <bgneal@gmail.com>
date Thu, 26 May 2011 00:43:49 +0000
parents 88b2b9cb8c1f
children
comparison
equal deleted inserted replaced
441:33d0c55e57a9 442:6c182ceb7147
1 (function(win) { 1 (function(win) {
2 var whiteSpaceRe = /^\s*|\s*$/g, 2 var whiteSpaceRe = /^\s*|\s*$/g,
3 undefined; 3 undefined, isRegExpBroken = 'B'.replace(/A(.)|B/, '$1') === '$1';
4 4
5 var tinymce = { 5 var tinymce = {
6 majorVersion : '3', 6 majorVersion : '3',
7 7
8 minorVersion : '3.9', 8 minorVersion : '4.2',
9 9
10 releaseDate : '2010-09-08', 10 releaseDate : '2011-04-07',
11 11
12 _init : function() { 12 _init : function() {
13 var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v; 13 var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v;
14 14
15 t.isOpera = win.opera && opera.buildNumber; 15 t.isOpera = win.opera && opera.buildNumber;
101 return true; 101 return true;
102 102
103 return typeof(o) == t; 103 return typeof(o) == t;
104 }, 104 },
105 105
106 makeMap : function(items, delim, map) {
107 var i;
108
109 items = items || [];
110 delim = delim || ',';
111
112 if (typeof(items) == "string")
113 items = items.split(delim);
114
115 map = map || {};
116
117 i = items.length;
118 while (i--)
119 map[items[i]] = {};
120
121 return map;
122 },
123
106 each : function(o, cb, s) { 124 each : function(o, cb, s) {
107 var n, l; 125 var n, l;
108 126
109 if (!o) 127 if (!o)
110 return 0; 128 return 0;
183 201
184 trim : function(s) { 202 trim : function(s) {
185 return (s ? '' + s : '').replace(whiteSpaceRe, ''); 203 return (s ? '' + s : '').replace(whiteSpaceRe, '');
186 }, 204 },
187 205
188 create : function(s, p) { 206 create : function(s, p, root) {
189 var t = this, sp, ns, cn, scn, c, de = 0; 207 var t = this, sp, ns, cn, scn, c, de = 0;
190 208
191 // Parse : <prefix> <class>:<super class> 209 // Parse : <prefix> <class>:<super class>
192 s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s); 210 s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
193 cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name 211 cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
194 212
195 // Create namespace for new class 213 // Create namespace for new class
196 ns = t.createNS(s[3].replace(/\.\w+$/, '')); 214 ns = t.createNS(s[3].replace(/\.\w+$/, ''), root);
197 215
198 // Class already exists 216 // Class already exists
199 if (ns[cn]) 217 if (ns[cn])
200 return; 218 return;
201 219
426 444
427 if (u.indexOf('#') == -1) 445 if (u.indexOf('#') == -1)
428 return u + v; 446 return u + v;
429 447
430 return u.replace('#', v + '#'); 448 return u.replace('#', v + '#');
449 },
450
451 // Fix function for IE 9 where regexps isn't working correctly
452 // Todo: remove me once MS fixes the bug
453 _replace : function(find, replace, str) {
454 // On IE9 we have to fake $x replacement
455 if (isRegExpBroken) {
456 return str.replace(find, function() {
457 var val = replace, args = arguments, i;
458
459 for (i = 0; i < args.length - 2; i++) {
460 if (args[i] === undefined) {
461 val = val.replace(new RegExp('\\$' + i, 'g'), '');
462 } else {
463 val = val.replace(new RegExp('\\$' + i, 'g'), args[i]);
464 }
465 }
466
467 return val;
468 });
469 }
470
471 return str.replace(find, replace);
431 } 472 }
432 473
433 }; 474 };
434 475
435 // Initialize the API 476 // Initialize the API
436 tinymce._init(); 477 tinymce._init();
437 478
438 // Expose tinymce namespace to the global namespace (window) 479 // Expose tinymce namespace to the global namespace (window)
439 win.tinymce = win.tinyMCE = tinymce; 480 win.tinymce = win.tinyMCE = tinymce;
440 })(window); 481
482 // Describe the different namespaces
483
484 })(window);
441 485
442 486
443 tinymce.create('tinymce.util.Dispatcher', { 487 tinymce.create('tinymce.util.Dispatcher', {
444 scope : null, 488 scope : null,
445 listeners : null, 489 listeners : null,
803 this.set(n, '', d, p, d); 847 this.set(n, '', d, p, d);
804 } 848 }
805 }); 849 });
806 })(); 850 })();
807 851
808 tinymce.create('static tinymce.util.JSON', { 852 (function() {
809 serialize : function(o) { 853 function serialize(o, quote) {
810 var i, v, s = tinymce.util.JSON.serialize, t; 854 var i, v, t;
855
856 quote = quote || '"';
811 857
812 if (o == null) 858 if (o == null)
813 return 'null'; 859 return 'null';
814 860
815 t = typeof o; 861 t = typeof o;
816 862
817 if (t == 'string') { 863 if (t == 'string') {
818 v = '\bb\tt\nn\ff\rr\""\'\'\\\\'; 864 v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
819 865
820 return '"' + o.replace(/([\u0080-\uFFFF\x00-\x1f\"])/g, function(a, b) { 866 return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) {
867 // Make sure single quotes never get encoded inside double quotes for JSON compatibility
868 if (quote === '"' && a === "'")
869 return a;
870
821 i = v.indexOf(b); 871 i = v.indexOf(b);
822 872
823 if (i + 1) 873 if (i + 1)
824 return '\\' + v.charAt(i + 1); 874 return '\\' + v.charAt(i + 1);
825 875
826 a = b.charCodeAt().toString(16); 876 a = b.charCodeAt().toString(16);
827 877
828 return '\\u' + '0000'.substring(a.length) + a; 878 return '\\u' + '0000'.substring(a.length) + a;
829 }) + '"'; 879 }) + quote;
830 } 880 }
831 881
832 if (t == 'object') { 882 if (t == 'object') {
833 if (o.hasOwnProperty && o instanceof Array) { 883 if (o.hasOwnProperty && o instanceof Array) {
834 for (i=0, v = '['; i<o.length; i++) 884 for (i=0, v = '['; i<o.length; i++)
835 v += (i > 0 ? ',' : '') + s(o[i]); 885 v += (i > 0 ? ',' : '') + serialize(o[i], quote);
836 886
837 return v + ']'; 887 return v + ']';
838 } 888 }
839 889
840 v = '{'; 890 v = '{';
841 891
842 for (i in o) 892 for (i in o)
843 v += typeof o[i] != 'function' ? (v.length > 1 ? ',"' : '"') + i + '":' + s(o[i]) : ''; 893 v += typeof o[i] != 'function' ? (v.length > 1 ? ',' + quote : quote) + i + quote +':' + serialize(o[i], quote) : '';
844 894
845 return v + '}'; 895 return v + '}';
846 } 896 }
847 897
848 return '' + o; 898 return '' + o;
849 }, 899 };
850 900
851 parse : function(s) { 901 tinymce.util.JSON = {
852 try { 902 serialize: serialize,
853 return eval('(' + s + ')'); 903
854 } catch (ex) { 904 parse: function(s) {
855 // Ignore 905 try {
906 return eval('(' + s + ')');
907 } catch (ex) {
908 // Ignore
909 }
856 } 910 }
857 } 911
858 912 };
859 }); 913 })();
860
861 tinymce.create('static tinymce.util.XHR', { 914 tinymce.create('static tinymce.util.XHR', {
862 send : function(o) { 915 send : function(o) {
863 var x, t, w = window, c = 0; 916 var x, t, w = window, c = 0;
864 917
865 // Default settings 918 // Default settings
946 else 999 else
947 scb.call(o.success_scope || o.scope, c.result); 1000 scb.call(o.success_scope || o.scope, c.result);
948 }; 1001 };
949 1002
950 o.error = function(ty, x) { 1003 o.error = function(ty, x) {
951 ecb.call(o.error_scope || o.scope, ty, x); 1004 if (ecb)
1005 ecb.call(o.error_scope || o.scope, ty, x);
952 }; 1006 };
953 1007
954 o.data = JSON.serialize({ 1008 o.data = JSON.serialize({
955 id : o.id || 'c' + (this.count++), 1009 id : o.id || 'c' + (this.count++),
956 method : o.method, 1010 method : o.method,
968 return new tinymce.util.JSONRequest().send(o); 1022 return new tinymce.util.JSONRequest().send(o);
969 } 1023 }
970 } 1024 }
971 }); 1025 });
972 }()); 1026 }());
1027 (function(tinymce) {
1028 var namedEntities, baseEntities, reverseEntities,
1029 attrsCharsRegExp = /[&\"\u007E-\uD7FF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
1030 textCharsRegExp = /[<>&\u007E-\uD7FF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
1031 rawCharsRegExp = /[<>&\"\']/g,
1032 entityRegExp = /&(#)?([\w]+);/g,
1033 asciiMap = {
1034 128 : "\u20AC", 130 : "\u201A", 131 : "\u0192", 132 : "\u201E", 133 : "\u2026", 134 : "\u2020",
1035 135 : "\u2021", 136 : "\u02C6", 137 : "\u2030", 138 : "\u0160", 139 : "\u2039", 140 : "\u0152",
1036 142 : "\u017D", 145 : "\u2018", 146 : "\u2019", 147 : "\u201C", 148 : "\u201D", 149 : "\u2022",
1037 150 : "\u2013", 151 : "\u2014", 152 : "\u02DC", 153 : "\u2122", 154 : "\u0161", 155 : "\u203A",
1038 156 : "\u0153", 158 : "\u017E", 159 : "\u0178"
1039 };
1040
1041 // Raw entities
1042 baseEntities = {
1043 '"' : '&quot;',
1044 "'" : '&#39;',
1045 '<' : '&lt;',
1046 '>' : '&gt;',
1047 '&' : '&amp;'
1048 };
1049
1050 // Reverse lookup table for raw entities
1051 reverseEntities = {
1052 '&lt;' : '<',
1053 '&gt;' : '>',
1054 '&amp;' : '&',
1055 '&quot;' : '"',
1056 '&apos;' : "'"
1057 };
1058
1059 // Decodes text by using the browser
1060 function nativeDecode(text) {
1061 var elm;
1062
1063 elm = document.createElement("div");
1064 elm.innerHTML = text;
1065
1066 return elm.textContent || elm.innerText || text;
1067 };
1068
1069 // Build a two way lookup table for the entities
1070 function buildEntitiesLookup(items, radix) {
1071 var i, chr, entity, lookup = {};
1072
1073 if (items) {
1074 items = items.split(',');
1075 radix = radix || 10;
1076
1077 // Build entities lookup table
1078 for (i = 0; i < items.length; i += 2) {
1079 chr = String.fromCharCode(parseInt(items[i], radix));
1080
1081 // Only add non base entities
1082 if (!baseEntities[chr]) {
1083 entity = '&' + items[i + 1] + ';';
1084 lookup[chr] = entity;
1085 lookup[entity] = chr;
1086 }
1087 }
1088
1089 return lookup;
1090 }
1091 };
1092
1093 // Unpack entities lookup where the numbers are in radix 32 to reduce the size
1094 namedEntities = buildEntitiesLookup(
1095 '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
1096 '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
1097 '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
1098 '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
1099 '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
1100 '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
1101 '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
1102 '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
1103 '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
1104 '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
1105 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
1106 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
1107 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
1108 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
1109 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
1110 '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
1111 '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
1112 '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
1113 '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
1114 '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
1115 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
1116 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
1117 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
1118 '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
1119 '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro'
1120 , 32);
1121
1122 tinymce.html = tinymce.html || {};
1123
1124 tinymce.html.Entities = {
1125 encodeRaw : function(text, attr) {
1126 return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
1127 return baseEntities[chr] || chr;
1128 });
1129 },
1130
1131 encodeAllRaw : function(text) {
1132 return ('' + text).replace(rawCharsRegExp, function(chr) {
1133 return baseEntities[chr] || chr;
1134 });
1135 },
1136
1137 encodeNumeric : function(text, attr) {
1138 return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
1139 // Multi byte sequence convert it to a single entity
1140 if (chr.length > 1)
1141 return '&#' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';';
1142
1143 return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
1144 });
1145 },
1146
1147 encodeNamed : function(text, attr, entities) {
1148 entities = entities || namedEntities;
1149
1150 return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
1151 return baseEntities[chr] || entities[chr] || chr;
1152 });
1153 },
1154
1155 getEncodeFunc : function(name, entities) {
1156 var Entities = tinymce.html.Entities;
1157
1158 entities = buildEntitiesLookup(entities) || namedEntities;
1159
1160 function encodeNamedAndNumeric(text, attr) {
1161 return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
1162 return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
1163 });
1164 };
1165
1166 function encodeCustomNamed(text, attr) {
1167 return Entities.encodeNamed(text, attr, entities);
1168 };
1169
1170 // Replace + with , to be compatible with previous TinyMCE versions
1171 name = tinymce.makeMap(name.replace(/\+/g, ','));
1172
1173 // Named and numeric encoder
1174 if (name.named && name.numeric)
1175 return encodeNamedAndNumeric;
1176
1177 // Named encoder
1178 if (name.named) {
1179 // Custom names
1180 if (entities)
1181 return encodeCustomNamed;
1182
1183 return Entities.encodeNamed;
1184 }
1185
1186 // Numeric
1187 if (name.numeric)
1188 return Entities.encodeNumeric;
1189
1190 // Raw encoder
1191 return Entities.encodeRaw;
1192 },
1193
1194 decode : function(text) {
1195 return text.replace(entityRegExp, function(all, numeric, value) {
1196 if (numeric) {
1197 value = parseInt(value);
1198
1199 // Support upper UTF
1200 if (value > 0xFFFF) {
1201 value -= 0x10000;
1202
1203 return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF));
1204 } else
1205 return asciiMap[value] || String.fromCharCode(value);
1206 }
1207
1208 return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
1209 });
1210 }
1211 };
1212 })(tinymce);
1213
1214 tinymce.html.Styles = function(settings, schema) {
1215 var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
1216 urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
1217 styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
1218 trimRightRegExp = /\s+$/,
1219 urlColorRegExp = /rgb/,
1220 undef, i, encodingLookup = {}, encodingItems;
1221
1222 settings = settings || {};
1223
1224 encodingItems = '\\" \\\' \\; \\: ; : _'.split(' ');
1225 for (i = 0; i < encodingItems.length; i++) {
1226 encodingLookup[encodingItems[i]] = '_' + i;
1227 encodingLookup['_' + i] = encodingItems[i];
1228 }
1229
1230 function toHex(match, r, g, b) {
1231 function hex(val) {
1232 val = parseInt(val).toString(16);
1233
1234 return val.length > 1 ? val : '0' + val; // 0 -> 00
1235 };
1236
1237 return '#' + hex(r) + hex(g) + hex(b);
1238 };
1239
1240 return {
1241 toHex : function(color) {
1242 return color.replace(rgbRegExp, toHex);
1243 },
1244
1245 parse : function(css) {
1246 var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this;
1247
1248 function compress(prefix, suffix) {
1249 var top, right, bottom, left;
1250
1251 // Get values and check it it needs compressing
1252 top = styles[prefix + '-top' + suffix];
1253 if (!top)
1254 return;
1255
1256 right = styles[prefix + '-right' + suffix];
1257 if (top != right)
1258 return;
1259
1260 bottom = styles[prefix + '-bottom' + suffix];
1261 if (right != bottom)
1262 return;
1263
1264 left = styles[prefix + '-left' + suffix];
1265 if (bottom != left)
1266 return;
1267
1268 // Compress
1269 styles[prefix + suffix] = left;
1270 delete styles[prefix + '-top' + suffix];
1271 delete styles[prefix + '-right' + suffix];
1272 delete styles[prefix + '-bottom' + suffix];
1273 delete styles[prefix + '-left' + suffix];
1274 };
1275
1276 function canCompress(key) {
1277 var value = styles[key], i;
1278
1279 if (!value || value.indexOf(' ') < 0)
1280 return;
1281
1282 value = value.split(' ');
1283 i = value.length;
1284 while (i--) {
1285 if (value[i] !== value[0])
1286 return false;
1287 }
1288
1289 styles[key] = value[0];
1290
1291 return true;
1292 };
1293
1294 function compress2(target, a, b, c) {
1295 if (!canCompress(a))
1296 return;
1297
1298 if (!canCompress(b))
1299 return;
1300
1301 if (!canCompress(c))
1302 return;
1303
1304 // Compress
1305 styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
1306 delete styles[a];
1307 delete styles[b];
1308 delete styles[c];
1309 };
1310
1311 // Encodes the specified string by replacing all \" \' ; : with _<num>
1312 function encode(str) {
1313 isEncoded = true;
1314
1315 return encodingLookup[str];
1316 };
1317
1318 // Decodes the specified string by replacing all _<num> with it's original value \" \' etc
1319 // It will also decode the \" \' if keep_slashes is set to fale or omitted
1320 function decode(str, keep_slashes) {
1321 if (isEncoded) {
1322 str = str.replace(/_[0-9]/g, function(str) {
1323 return encodingLookup[str];
1324 });
1325 }
1326
1327 if (!keep_slashes)
1328 str = str.replace(/\\([\'\";:])/g, "$1");
1329
1330 return str;
1331 }
1332
1333 if (css) {
1334 // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing
1335 css = css.replace(/\\[\"\';:_]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
1336 return str.replace(/[;:]/g, encode);
1337 });
1338
1339 // Parse styles
1340 while (matches = styleRegExp.exec(css)) {
1341 name = matches[1].replace(trimRightRegExp, '').toLowerCase();
1342 value = matches[2].replace(trimRightRegExp, '');
1343
1344 if (name && value.length > 0) {
1345 // Opera will produce 700 instead of bold in their style values
1346 if (name === 'font-weight' && value === '700')
1347 value = 'bold';
1348 else if (name === 'color' || name === 'background-color') // Lowercase colors like RED
1349 value = value.toLowerCase();
1350
1351 // Convert RGB colors to HEX
1352 value = value.replace(rgbRegExp, toHex);
1353
1354 // Convert URLs and force them into url('value') format
1355 value = value.replace(urlOrStrRegExp, function(match, url, url2, url3, str, str2) {
1356 str = str || str2;
1357
1358 if (str) {
1359 str = decode(str);
1360
1361 // Force strings into single quote format
1362 return "'" + str.replace(/\'/g, "\\'") + "'";
1363 }
1364
1365 url = decode(url || url2 || url3);
1366
1367 // Convert the URL to relative/absolute depending on config
1368 if (urlConverter)
1369 url = urlConverter.call(urlConverterScope, url, 'style');
1370
1371 // Output new URL format
1372 return "url('" + url.replace(/\'/g, "\\'") + "')";
1373 });
1374
1375 styles[name] = isEncoded ? decode(value, true) : value;
1376 }
1377
1378 styleRegExp.lastIndex = matches.index + matches[0].length;
1379 }
1380
1381 // Compress the styles to reduce it's size for example IE will expand styles
1382 compress("border", "");
1383 compress("border", "-width");
1384 compress("border", "-color");
1385 compress("border", "-style");
1386 compress("padding", "");
1387 compress("margin", "");
1388 compress2('border', 'border-width', 'border-style', 'border-color');
1389
1390 // Remove pointless border, IE produces these
1391 if (styles.border === 'medium none')
1392 delete styles.border;
1393 }
1394
1395 return styles;
1396 },
1397
1398 serialize : function(styles, element_name) {
1399 var css = '', name, value;
1400
1401 function serializeStyles(name) {
1402 var styleList, i, l, name, value;
1403
1404 styleList = schema.styles[name];
1405 if (styleList) {
1406 for (i = 0, l = styleList.length; i < l; i++) {
1407 name = styleList[i];
1408 value = styles[name];
1409
1410 if (value !== undef && value.length > 0)
1411 css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
1412 }
1413 }
1414 };
1415
1416 // Serialize styles according to schema
1417 if (element_name && schema && schema.styles) {
1418 // Serialize global styles and element specific styles
1419 serializeStyles('*');
1420 serializeStyles(name);
1421 } else {
1422 // Output the styles in the order they are inside the object
1423 for (name in styles) {
1424 value = styles[name];
1425
1426 if (value !== undef && value.length > 0)
1427 css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
1428 }
1429 }
1430
1431 return css;
1432 }
1433 };
1434 };
1435
1436 (function(tinymce) {
1437 var transitional = {}, boolAttrMap, blockElementsMap, shortEndedElementsMap, nonEmptyElementsMap,
1438 whiteSpaceElementsMap, selfClosingElementsMap, makeMap = tinymce.makeMap, each = tinymce.each;
1439
1440 function split(str, delim) {
1441 return str.split(delim || ',');
1442 };
1443
1444 function unpack(lookup, data) {
1445 var key, elements = {};
1446
1447 function replace(value) {
1448 return value.replace(/[A-Z]+/g, function(key) {
1449 return replace(lookup[key]);
1450 });
1451 };
1452
1453 // Unpack lookup
1454 for (key in lookup) {
1455 if (lookup.hasOwnProperty(key))
1456 lookup[key] = replace(lookup[key]);
1457 }
1458
1459 // Unpack and parse data into object map
1460 replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) {
1461 attributes = split(attributes, '|');
1462
1463 elements[name] = {
1464 attributes : makeMap(attributes),
1465 attributesOrder : attributes,
1466 children : makeMap(children, '|', {'#comment' : {}})
1467 }
1468 });
1469
1470 return elements;
1471 };
1472
1473 // Build a lookup table for block elements both lowercase and uppercase
1474 blockElementsMap = 'h1,h2,h3,h4,h5,h6,hr,p,div,address,pre,form,table,tbody,thead,tfoot,' +
1475 'th,tr,td,li,ol,ul,caption,blockquote,center,dl,dt,dd,dir,fieldset,' +
1476 'noscript,menu,isindex,samp,header,footer,article,section,hgroup';
1477 blockElementsMap = makeMap(blockElementsMap, ',', makeMap(blockElementsMap.toUpperCase()));
1478
1479 // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size
1480 transitional = unpack({
1481 Z : 'H|K|N|O|P',
1482 Y : 'X|form|R|Q',
1483 ZG : 'E|span|width|align|char|charoff|valign',
1484 X : 'p|T|div|U|W|isindex|fieldset|table',
1485 ZF : 'E|align|char|charoff|valign',
1486 W : 'pre|hr|blockquote|address|center|noframes',
1487 ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height',
1488 ZD : '[E][S]',
1489 U : 'ul|ol|dl|menu|dir',
1490 ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
1491 T : 'h1|h2|h3|h4|h5|h6',
1492 ZB : 'X|S|Q',
1493 S : 'R|P',
1494 ZA : 'a|G|J|M|O|P',
1495 R : 'a|H|K|N|O',
1496 Q : 'noscript|P',
1497 P : 'ins|del|script',
1498 O : 'input|select|textarea|label|button',
1499 N : 'M|L',
1500 M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
1501 L : 'sub|sup',
1502 K : 'J|I',
1503 J : 'tt|i|b|u|s|strike',
1504 I : 'big|small|font|basefont',
1505 H : 'G|F',
1506 G : 'br|span|bdo',
1507 F : 'object|applet|img|map|iframe',
1508 E : 'A|B|C',
1509 D : 'accesskey|tabindex|onfocus|onblur',
1510 C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
1511 B : 'lang|xml:lang|dir',
1512 A : 'id|class|style|title'
1513 }, 'script[id|charset|type|language|src|defer|xml:space][]' +
1514 'style[B|id|type|media|title|xml:space][]' +
1515 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' +
1516 'param[id|name|value|valuetype|type][]' +
1517 'p[E|align][#|S]' +
1518 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' +
1519 'br[A|clear][]' +
1520 'span[E][#|S]' +
1521 'bdo[A|C|B][#|S]' +
1522 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' +
1523 'h1[E|align][#|S]' +
1524 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' +
1525 'map[B|C|A|name][X|form|Q|area]' +
1526 'h2[E|align][#|S]' +
1527 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' +
1528 'h3[E|align][#|S]' +
1529 'tt[E][#|S]' +
1530 'i[E][#|S]' +
1531 'b[E][#|S]' +
1532 'u[E][#|S]' +
1533 's[E][#|S]' +
1534 'strike[E][#|S]' +
1535 'big[E][#|S]' +
1536 'small[E][#|S]' +
1537 'font[A|B|size|color|face][#|S]' +
1538 'basefont[id|size|color|face][]' +
1539 'em[E][#|S]' +
1540 'strong[E][#|S]' +
1541 'dfn[E][#|S]' +
1542 'code[E][#|S]' +
1543 'q[E|cite][#|S]' +
1544 'samp[E][#|S]' +
1545 'kbd[E][#|S]' +
1546 'var[E][#|S]' +
1547 'cite[E][#|S]' +
1548 'abbr[E][#|S]' +
1549 'acronym[E][#|S]' +
1550 'sub[E][#|S]' +
1551 'sup[E][#|S]' +
1552 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' +
1553 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' +
1554 'optgroup[E|disabled|label][option]' +
1555 'option[E|selected|disabled|label|value][]' +
1556 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' +
1557 'label[E|for|accesskey|onfocus|onblur][#|S]' +
1558 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
1559 'h4[E|align][#|S]' +
1560 'ins[E|cite|datetime][#|Y]' +
1561 'h5[E|align][#|S]' +
1562 'del[E|cite|datetime][#|Y]' +
1563 'h6[E|align][#|S]' +
1564 'div[E|align][#|Y]' +
1565 'ul[E|type|compact][li]' +
1566 'li[E|type|value][#|Y]' +
1567 'ol[E|type|compact|start][li]' +
1568 'dl[E|compact][dt|dd]' +
1569 'dt[E][#|S]' +
1570 'dd[E][#|Y]' +
1571 'menu[E|compact][li]' +
1572 'dir[E|compact][li]' +
1573 'pre[E|width|xml:space][#|ZA]' +
1574 'hr[E|align|noshade|size|width][]' +
1575 'blockquote[E|cite][#|Y]' +
1576 'address[E][#|S|p]' +
1577 'center[E][#|Y]' +
1578 'noframes[E][#|Y]' +
1579 'isindex[A|B|prompt][]' +
1580 'fieldset[E][#|legend|Y]' +
1581 'legend[E|accesskey|align][#|S]' +
1582 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' +
1583 'caption[E|align][#|S]' +
1584 'col[ZG][]' +
1585 'colgroup[ZG][col]' +
1586 'thead[ZF][tr]' +
1587 'tr[ZF|bgcolor][th|td]' +
1588 'th[E|ZE][#|Y]' +
1589 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' +
1590 'noscript[E][#|Y]' +
1591 'td[E|ZE][#|Y]' +
1592 'tfoot[ZF][tr]' +
1593 'tbody[ZF][tr]' +
1594 'area[E|D|shape|coords|href|nohref|alt|target][]' +
1595 'base[id|href|target][]' +
1596 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]'
1597 );
1598
1599 boolAttrMap = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected,preload,autoplay,loop,controls');
1600 shortEndedElementsMap = makeMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,source');
1601 nonEmptyElementsMap = tinymce.extend(makeMap('td,th,iframe,video,object'), shortEndedElementsMap);
1602 whiteSpaceElementsMap = makeMap('pre,script,style');
1603 selfClosingElementsMap = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr');
1604
1605 tinymce.html.Schema = function(settings) {
1606 var self = this, elements = {}, children = {}, patternElements = [], validStyles;
1607
1608 settings = settings || {};
1609
1610 // Allow all elements and attributes if verify_html is set to false
1611 if (settings.verify_html === false)
1612 settings.valid_elements = '*[*]';
1613
1614 // Build styles list
1615 if (settings.valid_styles) {
1616 validStyles = {};
1617
1618 // Convert styles into a rule list
1619 each(settings.valid_styles, function(value, key) {
1620 validStyles[key] = tinymce.explode(value);
1621 });
1622 }
1623
1624 // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
1625 function patternToRegExp(str) {
1626 return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
1627 };
1628
1629 // Parses the specified valid_elements string and adds to the current rules
1630 // This function is a bit hard to read since it's heavily optimized for speed
1631 function addValidElements(valid_elements) {
1632 var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
1633 prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value,
1634 elementRuleRegExp = /^([#+-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/,
1635 attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
1636 hasPatternsRegExp = /[*?+]/;
1637
1638 if (valid_elements) {
1639 // Split valid elements into an array with rules
1640 valid_elements = split(valid_elements);
1641
1642 if (elements['@']) {
1643 globalAttributes = elements['@'].attributes;
1644 globalAttributesOrder = elements['@'].attributesOrder;
1645 }
1646
1647 // Loop all rules
1648 for (ei = 0, el = valid_elements.length; ei < el; ei++) {
1649 // Parse element rule
1650 matches = elementRuleRegExp.exec(valid_elements[ei]);
1651 if (matches) {
1652 // Setup local names for matches
1653 prefix = matches[1];
1654 elementName = matches[2];
1655 outputName = matches[3];
1656 attrData = matches[4];
1657
1658 // Create new attributes and attributesOrder
1659 attributes = {};
1660 attributesOrder = [];
1661
1662 // Create the new element
1663 element = {
1664 attributes : attributes,
1665 attributesOrder : attributesOrder
1666 };
1667
1668 // Padd empty elements prefix
1669 if (prefix === '#')
1670 element.paddEmpty = true;
1671
1672 // Remove empty elements prefix
1673 if (prefix === '-')
1674 element.removeEmpty = true;
1675
1676 // Copy attributes from global rule into current rule
1677 if (globalAttributes) {
1678 for (key in globalAttributes)
1679 attributes[key] = globalAttributes[key];
1680
1681 attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
1682 }
1683
1684 // Attributes defined
1685 if (attrData) {
1686 attrData = split(attrData, '|');
1687 for (ai = 0, al = attrData.length; ai < al; ai++) {
1688 matches = attrRuleRegExp.exec(attrData[ai]);
1689 if (matches) {
1690 attr = {};
1691 attrType = matches[1];
1692 attrName = matches[2].replace(/::/g, ':');
1693 prefix = matches[3];
1694 value = matches[4];
1695
1696 // Required
1697 if (attrType === '!') {
1698 element.attributesRequired = element.attributesRequired || [];
1699 element.attributesRequired.push(attrName);
1700 attr.required = true;
1701 }
1702
1703 // Denied from global
1704 if (attrType === '-') {
1705 delete attributes[attrName];
1706 attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1);
1707 continue;
1708 }
1709
1710 // Default value
1711 if (prefix) {
1712 // Default value
1713 if (prefix === '=') {
1714 element.attributesDefault = element.attributesDefault || [];
1715 element.attributesDefault.push({name: attrName, value: value});
1716 attr.defaultValue = value;
1717 }
1718
1719 // Forced value
1720 if (prefix === ':') {
1721 element.attributesForced = element.attributesForced || [];
1722 element.attributesForced.push({name: attrName, value: value});
1723 attr.forcedValue = value;
1724 }
1725
1726 // Required values
1727 if (prefix === '<')
1728 attr.validValues = makeMap(value, '?');
1729 }
1730
1731 // Check for attribute patterns
1732 if (hasPatternsRegExp.test(attrName)) {
1733 element.attributePatterns = element.attributePatterns || [];
1734 attr.pattern = patternToRegExp(attrName);
1735 element.attributePatterns.push(attr);
1736 } else {
1737 // Add attribute to order list if it doesn't already exist
1738 if (!attributes[attrName])
1739 attributesOrder.push(attrName);
1740
1741 attributes[attrName] = attr;
1742 }
1743 }
1744 }
1745 }
1746
1747 // Global rule, store away these for later usage
1748 if (!globalAttributes && elementName == '@') {
1749 globalAttributes = attributes;
1750 globalAttributesOrder = attributesOrder;
1751 }
1752
1753 // Handle substitute elements such as b/strong
1754 if (outputName) {
1755 element.outputName = elementName;
1756 elements[outputName] = element;
1757 }
1758
1759 // Add pattern or exact element
1760 if (hasPatternsRegExp.test(elementName)) {
1761 element.pattern = patternToRegExp(elementName);
1762 patternElements.push(element);
1763 } else
1764 elements[elementName] = element;
1765 }
1766 }
1767 }
1768 };
1769
1770 function setValidElements(valid_elements) {
1771 elements = {};
1772 patternElements = [];
1773
1774 addValidElements(valid_elements);
1775
1776 each(transitional, function(element, name) {
1777 children[name] = element.children;
1778 });
1779 };
1780
1781 // Adds custom non HTML elements to the schema
1782 function addCustomElements(custom_elements) {
1783 var customElementRegExp = /^(~)?(.+)$/;
1784
1785 if (custom_elements) {
1786 each(split(custom_elements), function(rule) {
1787 var matches = customElementRegExp.exec(rule),
1788 cloneName = matches[1] === '~' ? 'span' : 'div',
1789 name = matches[2];
1790
1791 children[name] = children[cloneName];
1792
1793 // Add custom elements at span/div positions
1794 each(children, function(element, child) {
1795 if (element[cloneName])
1796 element[name] = element[cloneName];
1797 });
1798 });
1799 }
1800 };
1801
1802 // Adds valid children to the schema object
1803 function addValidChildren(valid_children) {
1804 var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
1805
1806 if (valid_children) {
1807 each(split(valid_children), function(rule) {
1808 var matches = childRuleRegExp.exec(rule), parent, prefix;
1809
1810 if (matches) {
1811 prefix = matches[1];
1812
1813 // Add/remove items from default
1814 if (prefix)
1815 parent = children[matches[2]];
1816 else
1817 parent = children[matches[2]] = {'#comment' : {}};
1818
1819 parent = children[matches[2]];
1820
1821 each(split(matches[3], '|'), function(child) {
1822 if (prefix === '-')
1823 delete parent[child];
1824 else
1825 parent[child] = {};
1826 });
1827 }
1828 });
1829 }
1830 }
1831
1832 if (!settings.valid_elements) {
1833 // No valid elements defined then clone the elements from the transitional spec
1834 each(transitional, function(element, name) {
1835 elements[name] = {
1836 attributes : element.attributes,
1837 attributesOrder : element.attributesOrder
1838 };
1839
1840 children[name] = element.children;
1841 });
1842
1843 // Switch these
1844 each(split('strong/b,em/i'), function(item) {
1845 item = split(item, '/');
1846 elements[item[1]].outputName = item[0];
1847 });
1848
1849 // Add default alt attribute for images
1850 elements.img.attributesDefault = [{name: 'alt', value: ''}];
1851
1852 // Remove these if they are empty by default
1853 each(split('ol,ul,li,sub,sup,blockquote,tr,div,span,font,a,table,tbody'), function(name) {
1854 elements[name].removeEmpty = true;
1855 });
1856
1857 // Padd these by default
1858 each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) {
1859 elements[name].paddEmpty = true;
1860 });
1861 } else
1862 setValidElements(settings.valid_elements);
1863
1864 addCustomElements(settings.custom_elements);
1865 addValidChildren(settings.valid_children);
1866 addValidElements(settings.extended_valid_elements);
1867
1868 // Todo: Remove this when we fix list handling to be valid
1869 addValidChildren('+ol[ul|ol],+ul[ul|ol]');
1870
1871 // Delete invalid elements
1872 if (settings.invalid_elements) {
1873 tinymce.each(tinymce.explode(settings.invalid_elements), function(item) {
1874 if (elements[item])
1875 delete elements[item];
1876 });
1877 }
1878
1879 self.children = children;
1880
1881 self.styles = validStyles;
1882
1883 self.getBoolAttrs = function() {
1884 return boolAttrMap;
1885 };
1886
1887 self.getBlockElements = function() {
1888 return blockElementsMap;
1889 };
1890
1891 self.getShortEndedElements = function() {
1892 return shortEndedElementsMap;
1893 };
1894
1895 self.getSelfClosingElements = function() {
1896 return selfClosingElementsMap;
1897 };
1898
1899 self.getNonEmptyElements = function() {
1900 return nonEmptyElementsMap;
1901 };
1902
1903 self.getWhiteSpaceElements = function() {
1904 return whiteSpaceElementsMap;
1905 };
1906
1907 self.isValidChild = function(name, child) {
1908 var parent = children[name];
1909
1910 return !!(parent && parent[child]);
1911 };
1912
1913 self.getElementRule = function(name) {
1914 var element = elements[name], i;
1915
1916 // Exact match found
1917 if (element)
1918 return element;
1919
1920 // No exact match then try the patterns
1921 i = patternElements.length;
1922 while (i--) {
1923 element = patternElements[i];
1924
1925 if (element.pattern.test(name))
1926 return element;
1927 }
1928 };
1929
1930 self.addValidElements = addValidElements;
1931
1932 self.setValidElements = setValidElements;
1933
1934 self.addCustomElements = addCustomElements;
1935
1936 self.addValidChildren = addValidChildren;
1937 };
1938
1939 // Expose boolMap and blockElementMap as static properties for usage in DOMUtils
1940 tinymce.html.Schema.boolAttrMap = boolAttrMap;
1941 tinymce.html.Schema.blockElementsMap = blockElementsMap;
1942 })(tinymce);
1943
1944 (function(tinymce) {
1945 tinymce.html.SaxParser = function(settings, schema) {
1946 var self = this, noop = function() {};
1947
1948 settings = settings || {};
1949 self.schema = schema = schema || new tinymce.html.Schema();
1950
1951 if (settings.fix_self_closing !== false)
1952 settings.fix_self_closing = true;
1953
1954 // Add handler functions from settings and setup default handlers
1955 tinymce.each('comment cdata text start end pi doctype'.split(' '), function(name) {
1956 if (name)
1957 self[name] = settings[name] || noop;
1958 });
1959
1960 self.parse = function(html) {
1961 var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name,
1962 shortEndedElements, fillAttrsMap, isShortEnded, validate, elementRule, isValidElement, attr, attribsValue,
1963 validAttributesMap, validAttributePatterns, attributesRequired, attributesDefault, attributesForced, selfClosing,
1964 tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0, decode = tinymce.html.Entities.decode, fixSelfClosing;
1965
1966 function processEndTag(name) {
1967 var pos, i;
1968
1969 // Find position of parent of the same type
1970 pos = stack.length;
1971 while (pos--) {
1972 if (stack[pos].name === name)
1973 break;
1974 }
1975
1976 // Found parent
1977 if (pos >= 0) {
1978 // Close all the open elements
1979 for (i = stack.length - 1; i >= pos; i--) {
1980 name = stack[i];
1981
1982 if (name.valid)
1983 self.end(name.name);
1984 }
1985
1986 // Remove the open elements from the stack
1987 stack.length = pos;
1988 }
1989 };
1990
1991 // Precompile RegExps and map objects
1992 tokenRegExp = new RegExp('<(?:' +
1993 '(?:!--([\\w\\W]*?)-->)|' + // Comment
1994 '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA
1995 '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE
1996 '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI
1997 '(?:\\/([^>]+)>)|' + // End element
1998 '(?:([^\\s\\/<>]+)\\s*((?:[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*)>)' + // Start element
1999 ')', 'g');
2000
2001 attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:\\.|[^\"])*)\")|(?:\'((?:\\.|[^\'])*)\')|([^>\s]+)))?/g;
2002 specialElements = {
2003 'script' : /<\/script[^>]*>/gi,
2004 'style' : /<\/style[^>]*>/gi,
2005 'noscript' : /<\/noscript[^>]*>/gi
2006 };
2007
2008 // Setup lookup tables for empty elements and boolean attributes
2009 shortEndedElements = schema.getShortEndedElements();
2010 selfClosing = schema.getSelfClosingElements();
2011 fillAttrsMap = schema.getBoolAttrs();
2012 validate = settings.validate;
2013 fixSelfClosing = settings.fix_self_closing;
2014
2015 while (matches = tokenRegExp.exec(html)) {
2016 // Text
2017 if (index < matches.index)
2018 self.text(decode(html.substr(index, matches.index - index)));
2019
2020 if (value = matches[6]) { // End element
2021 processEndTag(value.toLowerCase());
2022 } else if (value = matches[7]) { // Start element
2023 value = value.toLowerCase();
2024 isShortEnded = value in shortEndedElements;
2025
2026 // Is self closing tag for example an <li> after an open <li>
2027 if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value)
2028 processEndTag(value);
2029
2030 // Validate element
2031 if (!validate || (elementRule = schema.getElementRule(value))) {
2032 isValidElement = true;
2033
2034 // Grab attributes map and patters when validation is enabled
2035 if (validate) {
2036 validAttributesMap = elementRule.attributes;
2037 validAttributePatterns = elementRule.attributePatterns;
2038 }
2039
2040 // Parse attributes
2041 if (attribsValue = matches[8]) {
2042 attrList = [];
2043 attrList.map = {};
2044
2045 attribsValue.replace(attrRegExp, function(match, name, value, val2, val3) {
2046 var attrRule, i;
2047
2048 name = name.toLowerCase();
2049 value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute
2050
2051 // Validate name and value
2052 if (validate && name.indexOf('data-') !== 0) {
2053 attrRule = validAttributesMap[name];
2054
2055 // Find rule by pattern matching
2056 if (!attrRule && validAttributePatterns) {
2057 i = validAttributePatterns.length;
2058 while (i--) {
2059 attrRule = validAttributePatterns[i];
2060 if (attrRule.pattern.test(name))
2061 break;
2062 }
2063
2064 // No rule matched
2065 if (i === -1)
2066 attrRule = null;
2067 }
2068
2069 // No attribute rule found
2070 if (!attrRule)
2071 return;
2072
2073 // Validate value
2074 if (attrRule.validValues && !(value in attrRule.validValues))
2075 return;
2076 }
2077
2078 // Add attribute to list and map
2079 attrList.map[name] = value;
2080 attrList.push({
2081 name: name,
2082 value: value
2083 });
2084 });
2085 } else {
2086 attrList = [];
2087 attrList.map = {};
2088 }
2089
2090 // Process attributes if validation is enabled
2091 if (validate) {
2092 attributesRequired = elementRule.attributesRequired;
2093 attributesDefault = elementRule.attributesDefault;
2094 attributesForced = elementRule.attributesForced;
2095
2096 // Handle forced attributes
2097 if (attributesForced) {
2098 i = attributesForced.length;
2099 while (i--) {
2100 attr = attributesForced[i];
2101 name = attr.name;
2102 attrValue = attr.value;
2103
2104 if (attrValue === '{$uid}')
2105 attrValue = 'mce_' + idCount++;
2106
2107 attrList.map[name] = attrValue;
2108 attrList.push({name: name, value: attrValue});
2109 }
2110 }
2111
2112 // Handle default attributes
2113 if (attributesDefault) {
2114 i = attributesDefault.length;
2115 while (i--) {
2116 attr = attributesDefault[i];
2117 name = attr.name;
2118
2119 if (!(name in attrList.map)) {
2120 attrValue = attr.value;
2121
2122 if (attrValue === '{$uid}')
2123 attrValue = 'mce_' + idCount++;
2124
2125 attrList.map[name] = attrValue;
2126 attrList.push({name: name, value: attrValue});
2127 }
2128 }
2129 }
2130
2131 // Handle required attributes
2132 if (attributesRequired) {
2133 i = attributesRequired.length;
2134 while (i--) {
2135 if (attributesRequired[i] in attrList.map)
2136 break;
2137 }
2138
2139 // None of the required attributes where found
2140 if (i === -1)
2141 isValidElement = false;
2142 }
2143
2144 // Invalidate element if it's marked as bogus
2145 if (attrList.map['data-mce-bogus'])
2146 isValidElement = false;
2147 }
2148
2149 if (isValidElement)
2150 self.start(value, attrList, isShortEnded);
2151 } else
2152 isValidElement = false;
2153
2154 // Treat script, noscript and style a bit different since they may include code that looks like elements
2155 if (endRegExp = specialElements[value]) {
2156 endRegExp.lastIndex = index = matches.index + matches[0].length;
2157
2158 if (matches = endRegExp.exec(html)) {
2159 if (isValidElement)
2160 text = html.substr(index, matches.index - index);
2161
2162 index = matches.index + matches[0].length;
2163 } else {
2164 text = html.substr(index);
2165 index = html.length;
2166 }
2167
2168 if (isValidElement && text.length > 0)
2169 self.text(text, true);
2170
2171 if (isValidElement)
2172 self.end(value);
2173
2174 tokenRegExp.lastIndex = index;
2175 continue;
2176 }
2177
2178 // Push value on to stack
2179 if (!isShortEnded) {
2180 if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1)
2181 stack.push({name: value, valid: isValidElement});
2182 else if (isValidElement)
2183 self.end(value);
2184 }
2185 } else if (value = matches[1]) { // Comment
2186 self.comment(value);
2187 } else if (value = matches[2]) { // CDATA
2188 self.cdata(value);
2189 } else if (value = matches[3]) { // DOCTYPE
2190 self.doctype(value);
2191 } else if (value = matches[4]) { // PI
2192 self.pi(value, matches[5]);
2193 }
2194
2195 index = matches.index + matches[0].length;
2196 }
2197
2198 // Text
2199 if (index < html.length)
2200 self.text(decode(html.substr(index)));
2201
2202 // Close any open elements
2203 for (i = stack.length - 1; i >= 0; i--) {
2204 value = stack[i];
2205
2206 if (value.valid)
2207 self.end(value.name);
2208 }
2209 };
2210 }
2211 })(tinymce);
2212
2213 (function(tinymce) {
2214 var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = {
2215 '#text' : 3,
2216 '#comment' : 8,
2217 '#cdata' : 4,
2218 '#pi' : 7,
2219 '#doctype' : 10,
2220 '#document-fragment' : 11
2221 };
2222
2223 // Walks the tree left/right
2224 function walk(node, root_node, prev) {
2225 var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next';
2226
2227 // Walk into nodes if it has a start
2228 if (node[startName])
2229 return node[startName];
2230
2231 // Return the sibling if it has one
2232 if (node !== root_node) {
2233 sibling = node[siblingName];
2234
2235 if (sibling)
2236 return sibling;
2237
2238 // Walk up the parents to look for siblings
2239 for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) {
2240 sibling = parent[siblingName];
2241
2242 if (sibling)
2243 return sibling;
2244 }
2245 }
2246 };
2247
2248 function Node(name, type) {
2249 this.name = name;
2250 this.type = type;
2251
2252 if (type === 1) {
2253 this.attributes = [];
2254 this.attributes.map = {};
2255 }
2256 }
2257
2258 tinymce.extend(Node.prototype, {
2259 replace : function(node) {
2260 var self = this;
2261
2262 if (node.parent)
2263 node.remove();
2264
2265 self.insert(node, self);
2266 self.remove();
2267
2268 return self;
2269 },
2270
2271 attr : function(name, value) {
2272 var self = this, attrs, i, undef;
2273
2274 if (typeof name !== "string") {
2275 for (i in name)
2276 self.attr(i, name[i]);
2277
2278 return self;
2279 }
2280
2281 if (attrs = self.attributes) {
2282 if (value !== undef) {
2283 // Remove attribute
2284 if (value === null) {
2285 if (name in attrs.map) {
2286 delete attrs.map[name];
2287
2288 i = attrs.length;
2289 while (i--) {
2290 if (attrs[i].name === name) {
2291 attrs = attrs.splice(i, 1);
2292 return self;
2293 }
2294 }
2295 }
2296
2297 return self;
2298 }
2299
2300 // Set attribute
2301 if (name in attrs.map) {
2302 // Set attribute
2303 i = attrs.length;
2304 while (i--) {
2305 if (attrs[i].name === name) {
2306 attrs[i].value = value;
2307 break;
2308 }
2309 }
2310 } else
2311 attrs.push({name: name, value: value});
2312
2313 attrs.map[name] = value;
2314
2315 return self;
2316 } else {
2317 return attrs.map[name];
2318 }
2319 }
2320 },
2321
2322 clone : function() {
2323 var self = this, clone = new Node(self.name, self.type), i, l, selfAttrs, selfAttr, cloneAttrs;
2324
2325 // Clone element attributes
2326 if (selfAttrs = self.attributes) {
2327 cloneAttrs = [];
2328 cloneAttrs.map = {};
2329
2330 for (i = 0, l = selfAttrs.length; i < l; i++) {
2331 selfAttr = selfAttrs[i];
2332
2333 // Clone everything except id
2334 if (selfAttr.name !== 'id') {
2335 cloneAttrs[cloneAttrs.length] = {name: selfAttr.name, value: selfAttr.value};
2336 cloneAttrs.map[selfAttr.name] = selfAttr.value;
2337 }
2338 }
2339
2340 clone.attributes = cloneAttrs;
2341 }
2342
2343 clone.value = self.value;
2344 clone.shortEnded = self.shortEnded;
2345
2346 return clone;
2347 },
2348
2349 wrap : function(wrapper) {
2350 var self = this;
2351
2352 self.parent.insert(wrapper, self);
2353 wrapper.append(self);
2354
2355 return self;
2356 },
2357
2358 unwrap : function() {
2359 var self = this, node, next;
2360
2361 for (node = self.firstChild; node; ) {
2362 next = node.next;
2363 self.insert(node, self, true);
2364 node = next;
2365 }
2366
2367 self.remove();
2368 },
2369
2370 remove : function() {
2371 var self = this, parent = self.parent, next = self.next, prev = self.prev;
2372
2373 if (parent) {
2374 if (parent.firstChild === self) {
2375 parent.firstChild = next;
2376
2377 if (next)
2378 next.prev = null;
2379 } else {
2380 prev.next = next;
2381 }
2382
2383 if (parent.lastChild === self) {
2384 parent.lastChild = prev;
2385
2386 if (prev)
2387 prev.next = null;
2388 } else {
2389 next.prev = prev;
2390 }
2391
2392 self.parent = self.next = self.prev = null;
2393 }
2394
2395 return self;
2396 },
2397
2398 append : function(node) {
2399 var self = this, last;
2400
2401 if (node.parent)
2402 node.remove();
2403
2404 last = self.lastChild;
2405 if (last) {
2406 last.next = node;
2407 node.prev = last;
2408 self.lastChild = node;
2409 } else
2410 self.lastChild = self.firstChild = node;
2411
2412 node.parent = self;
2413
2414 return node;
2415 },
2416
2417 insert : function(node, ref_node, before) {
2418 var parent;
2419
2420 if (node.parent)
2421 node.remove();
2422
2423 parent = ref_node.parent || this;
2424
2425 if (before) {
2426 if (ref_node === parent.firstChild)
2427 parent.firstChild = node;
2428 else
2429 ref_node.prev.next = node;
2430
2431 node.prev = ref_node.prev;
2432 node.next = ref_node;
2433 ref_node.prev = node;
2434 } else {
2435 if (ref_node === parent.lastChild)
2436 parent.lastChild = node;
2437 else
2438 ref_node.next.prev = node;
2439
2440 node.next = ref_node.next;
2441 node.prev = ref_node;
2442 ref_node.next = node;
2443 }
2444
2445 node.parent = parent;
2446
2447 return node;
2448 },
2449
2450 getAll : function(name) {
2451 var self = this, node, collection = [];
2452
2453 for (node = self.firstChild; node; node = walk(node, self)) {
2454 if (node.name === name)
2455 collection.push(node);
2456 }
2457
2458 return collection;
2459 },
2460
2461 empty : function() {
2462 var self = this, nodes, i, node;
2463
2464 // Remove all children
2465 if (self.firstChild) {
2466 nodes = [];
2467
2468 // Collect the children
2469 for (node = self.firstChild; node; node = walk(node, self))
2470 nodes.push(node);
2471
2472 // Remove the children
2473 i = nodes.length;
2474 while (i--) {
2475 node = nodes[i];
2476 node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
2477 }
2478 }
2479
2480 self.firstChild = self.lastChild = null;
2481
2482 return self;
2483 },
2484
2485 isEmpty : function(elements) {
2486 var self = this, node = self.firstChild, i, name;
2487
2488 if (node) {
2489 do {
2490 if (node.type === 1) {
2491 // Ignore bogus elements
2492 if (node.attributes.map['data-mce-bogus'])
2493 continue;
2494
2495 // Keep empty elements like <img />
2496 if (elements[node.name])
2497 return false;
2498
2499 // Keep elements with data attributes or name attribute like <a name="1"></a>
2500 i = node.attributes.length;
2501 while (i--) {
2502 name = node.attributes[i].name;
2503 if (name === "name" || name.indexOf('data-') === 0)
2504 return false;
2505 }
2506 }
2507
2508 // Keep non whitespace text nodes
2509 if ((node.type === 3 && !whiteSpaceRegExp.test(node.value)))
2510 return false;
2511 } while (node = walk(node, self));
2512 }
2513
2514 return true;
2515 }
2516 });
2517
2518 tinymce.extend(Node, {
2519 create : function(name, attrs) {
2520 var node, attrName;
2521
2522 // Create node
2523 node = new Node(name, typeLookup[name] || 1);
2524
2525 // Add attributes if needed
2526 if (attrs) {
2527 for (attrName in attrs)
2528 node.attr(attrName, attrs[attrName]);
2529 }
2530
2531 return node;
2532 }
2533 });
2534
2535 tinymce.html.Node = Node;
2536 })(tinymce);
2537
2538 (function(tinymce) {
2539 var Node = tinymce.html.Node;
2540
2541 tinymce.html.DomParser = function(settings, schema) {
2542 var self = this, nodeFilters = {}, attributeFilters = [], matchedNodes = {}, matchedAttributes = {};
2543
2544 settings = settings || {};
2545 settings.validate = "validate" in settings ? settings.validate : true;
2546 settings.root_name = settings.root_name || 'body';
2547 self.schema = schema = schema || new tinymce.html.Schema();
2548
2549 function fixInvalidChildren(nodes) {
2550 var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i,
2551 childClone, nonEmptyElements, nonSplitableElements, sibling, nextNode;
2552
2553 nonSplitableElements = tinymce.makeMap('tr,td,th,tbody,thead,tfoot,table');
2554 nonEmptyElements = schema.getNonEmptyElements();
2555
2556 for (ni = 0; ni < nodes.length; ni++) {
2557 node = nodes[ni];
2558
2559 // Already removed
2560 if (!node.parent)
2561 continue;
2562
2563 // Get list of all parent nodes until we find a valid parent to stick the child into
2564 parents = [node];
2565 for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent)
2566 parents.push(parent);
2567
2568 // Found a suitable parent
2569 if (parent && parents.length > 1) {
2570 // Reverse the array since it makes looping easier
2571 parents.reverse();
2572
2573 // Clone the related parent and insert that after the moved node
2574 newParent = currentNode = self.filterNode(parents[0].clone());
2575
2576 // Start cloning and moving children on the left side of the target node
2577 for (i = 0; i < parents.length - 1; i++) {
2578 if (schema.isValidChild(currentNode.name, parents[i].name)) {
2579 tempNode = self.filterNode(parents[i].clone());
2580 currentNode.append(tempNode);
2581 } else
2582 tempNode = currentNode;
2583
2584 for (childNode = parents[i].firstChild; childNode && childNode != parents[i + 1]; ) {
2585 nextNode = childNode.next;
2586 tempNode.append(childNode);
2587 childNode = nextNode;
2588 }
2589
2590 currentNode = tempNode;
2591 }
2592
2593 if (!newParent.isEmpty(nonEmptyElements)) {
2594 parent.insert(newParent, parents[0], true);
2595 parent.insert(node, newParent);
2596 } else {
2597 parent.insert(node, parents[0], true);
2598 }
2599
2600 // Check if the element is empty by looking through it's contents and special treatment for <p><br /></p>
2601 parent = parents[0];
2602 if (parent.isEmpty(nonEmptyElements) || parent.firstChild === parent.lastChild && parent.firstChild.name === 'br') {
2603 parent.empty().remove();
2604 }
2605 } else if (node.parent) {
2606 // If it's an LI try to find a UL/OL for it or wrap it
2607 if (node.name === 'li') {
2608 sibling = node.prev;
2609 if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
2610 sibling.append(node);
2611 continue;
2612 }
2613
2614 sibling = node.next;
2615 if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
2616 sibling.insert(node, sibling.firstChild, true);
2617 continue;
2618 }
2619
2620 node.wrap(self.filterNode(new Node('ul', 1)));
2621 continue;
2622 }
2623
2624 // Try wrapping the element in a DIV
2625 if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
2626 node.wrap(self.filterNode(new Node('div', 1)));
2627 } else {
2628 // We failed wrapping it, then remove or unwrap it
2629 if (node.name === 'style' || node.name === 'script')
2630 node.empty().remove();
2631 else
2632 node.unwrap();
2633 }
2634 }
2635 }
2636 };
2637
2638 self.filterNode = function(node) {
2639 var i, name, list;
2640
2641 // Run element filters
2642 if (name in nodeFilters) {
2643 list = matchedNodes[name];
2644
2645 if (list)
2646 list.push(node);
2647 else
2648 matchedNodes[name] = [node];
2649 }
2650
2651 // Run attribute filters
2652 i = attributeFilters.length;
2653 while (i--) {
2654 name = attributeFilters[i].name;
2655
2656 if (name in node.attributes.map) {
2657 list = matchedAttributes[name];
2658
2659 if (list)
2660 list.push(node);
2661 else
2662 matchedAttributes[name] = [node];
2663 }
2664 }
2665
2666 return node;
2667 };
2668
2669 self.addNodeFilter = function(name, callback) {
2670 tinymce.each(tinymce.explode(name), function(name) {
2671 var list = nodeFilters[name];
2672
2673 if (!list)
2674 nodeFilters[name] = list = [];
2675
2676 list.push(callback);
2677 });
2678 };
2679
2680 self.addAttributeFilter = function(name, callback) {
2681 tinymce.each(tinymce.explode(name), function(name) {
2682 var i;
2683
2684 for (i = 0; i < attributeFilters.length; i++) {
2685 if (attributeFilters[i].name === name) {
2686 attributeFilters[i].callbacks.push(callback);
2687 return;
2688 }
2689 }
2690
2691 attributeFilters.push({name: name, callbacks: [callback]});
2692 });
2693 };
2694
2695 self.parse = function(html, args) {
2696 var parser, rootNode, node, nodes, i, l, fi, fl, list, name, validate,
2697 blockElements, startWhiteSpaceRegExp, invalidChildren = [],
2698 endWhiteSpaceRegExp, allWhiteSpaceRegExp, whiteSpaceElements, children, nonEmptyElements;
2699
2700 args = args || {};
2701 matchedNodes = {};
2702 matchedAttributes = {};
2703 blockElements = tinymce.extend(tinymce.makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
2704 nonEmptyElements = schema.getNonEmptyElements();
2705 children = schema.children;
2706 validate = settings.validate;
2707
2708 whiteSpaceElements = schema.getWhiteSpaceElements();
2709 startWhiteSpaceRegExp = /^[ \t\r\n]+/;
2710 endWhiteSpaceRegExp = /[ \t\r\n]+$/;
2711 allWhiteSpaceRegExp = /[ \t\r\n]+/g;
2712
2713 function createNode(name, type) {
2714 var node = new Node(name, type), list;
2715
2716 if (name in nodeFilters) {
2717 list = matchedNodes[name];
2718
2719 if (list)
2720 list.push(node);
2721 else
2722 matchedNodes[name] = [node];
2723 }
2724
2725 return node;
2726 };
2727
2728 function removeWhitespaceBefore(node) {
2729 var textNode, textVal, sibling;
2730
2731 for (textNode = node.prev; textNode && textNode.type === 3; ) {
2732 textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
2733
2734 if (textVal.length > 0) {
2735 textNode.value = textVal;
2736 textNode = textNode.prev;
2737 } else {
2738 sibling = textNode.prev;
2739 textNode.remove();
2740 textNode = sibling;
2741 }
2742 }
2743 };
2744
2745 parser = new tinymce.html.SaxParser({
2746 validate : validate,
2747 fix_self_closing : !validate, // Let the DOM parser handle <li> in <li> or <p> in <p> for better results
2748
2749 cdata: function(text) {
2750 node.append(createNode('#cdata', 4)).value = text;
2751 },
2752
2753 text: function(text, raw) {
2754 var textNode;
2755
2756 // Trim all redundant whitespace on non white space elements
2757 if (!whiteSpaceElements[node.name]) {
2758 text = text.replace(allWhiteSpaceRegExp, ' ');
2759
2760 if (node.lastChild && blockElements[node.lastChild.name])
2761 text = text.replace(startWhiteSpaceRegExp, '');
2762 }
2763
2764 // Do we need to create the node
2765 if (text.length !== 0) {
2766 textNode = createNode('#text', 3);
2767 textNode.raw = !!raw;
2768 node.append(textNode).value = text;
2769 }
2770 },
2771
2772 comment: function(text) {
2773 node.append(createNode('#comment', 8)).value = text;
2774 },
2775
2776 pi: function(name, text) {
2777 node.append(createNode(name, 7)).value = text;
2778 removeWhitespaceBefore(node);
2779 },
2780
2781 doctype: function(text) {
2782 var newNode;
2783
2784 newNode = node.append(createNode('#doctype', 10));
2785 newNode.value = text;
2786 removeWhitespaceBefore(node);
2787 },
2788
2789 start: function(name, attrs, empty) {
2790 var newNode, attrFiltersLen, elementRule, textNode, attrName, text, sibling, parent;
2791
2792 elementRule = validate ? schema.getElementRule(name) : {};
2793 if (elementRule) {
2794 newNode = createNode(elementRule.outputName || name, 1);
2795 newNode.attributes = attrs;
2796 newNode.shortEnded = empty;
2797
2798 node.append(newNode);
2799
2800 // Check if node is valid child of the parent node is the child is
2801 // unknown we don't collect it since it's probably a custom element
2802 parent = children[node.name];
2803 if (parent && children[newNode.name] && !parent[newNode.name])
2804 invalidChildren.push(newNode);
2805
2806 attrFiltersLen = attributeFilters.length;
2807 while (attrFiltersLen--) {
2808 attrName = attributeFilters[attrFiltersLen].name;
2809
2810 if (attrName in attrs.map) {
2811 list = matchedAttributes[attrName];
2812
2813 if (list)
2814 list.push(newNode);
2815 else
2816 matchedAttributes[attrName] = [newNode];
2817 }
2818 }
2819
2820 // Trim whitespace before block
2821 if (blockElements[name])
2822 removeWhitespaceBefore(newNode);
2823
2824 // Change current node if the element wasn't empty i.e not <br /> or <img />
2825 if (!empty)
2826 node = newNode;
2827 }
2828 },
2829
2830 end: function(name) {
2831 var textNode, elementRule, text, sibling, tempNode;
2832
2833 elementRule = validate ? schema.getElementRule(name) : {};
2834 if (elementRule) {
2835 if (blockElements[name]) {
2836 if (!whiteSpaceElements[node.name]) {
2837 // Trim whitespace at beginning of block
2838 for (textNode = node.firstChild; textNode && textNode.type === 3; ) {
2839 text = textNode.value.replace(startWhiteSpaceRegExp, '');
2840
2841 if (text.length > 0) {
2842 textNode.value = text;
2843 textNode = textNode.next;
2844 } else {
2845 sibling = textNode.next;
2846 textNode.remove();
2847 textNode = sibling;
2848 }
2849 }
2850
2851 // Trim whitespace at end of block
2852 for (textNode = node.lastChild; textNode && textNode.type === 3; ) {
2853 text = textNode.value.replace(endWhiteSpaceRegExp, '');
2854
2855 if (text.length > 0) {
2856 textNode.value = text;
2857 textNode = textNode.prev;
2858 } else {
2859 sibling = textNode.prev;
2860 textNode.remove();
2861 textNode = sibling;
2862 }
2863 }
2864 }
2865
2866 // Trim start white space
2867 textNode = node.prev;
2868 if (textNode && textNode.type === 3) {
2869 text = textNode.value.replace(startWhiteSpaceRegExp, '');
2870
2871 if (text.length > 0)
2872 textNode.value = text;
2873 else
2874 textNode.remove();
2875 }
2876 }
2877
2878 // Handle empty nodes
2879 if (elementRule.removeEmpty || elementRule.paddEmpty) {
2880 if (node.isEmpty(nonEmptyElements)) {
2881 if (elementRule.paddEmpty)
2882 node.empty().append(new Node('#text', '3')).value = '\u00a0';
2883 else {
2884 // Leave nodes that have a name like <a name="name">
2885 if (!node.attributes.map.name) {
2886 tempNode = node.parent;
2887 node.empty().remove();
2888 node = tempNode;
2889 return;
2890 }
2891 }
2892 }
2893 }
2894
2895 node = node.parent;
2896 }
2897 }
2898 }, schema);
2899
2900 rootNode = node = new Node(settings.root_name, 11);
2901
2902 parser.parse(html);
2903
2904 if (validate)
2905 fixInvalidChildren(invalidChildren);
2906
2907 // Run node filters
2908 for (name in matchedNodes) {
2909 list = nodeFilters[name];
2910 nodes = matchedNodes[name];
2911
2912 // Remove already removed children
2913 fi = nodes.length;
2914 while (fi--) {
2915 if (!nodes[fi].parent)
2916 nodes.splice(fi, 1);
2917 }
2918
2919 for (i = 0, l = list.length; i < l; i++)
2920 list[i](nodes, name, args);
2921 }
2922
2923 // Run attribute filters
2924 for (i = 0, l = attributeFilters.length; i < l; i++) {
2925 list = attributeFilters[i];
2926
2927 if (list.name in matchedAttributes) {
2928 nodes = matchedAttributes[list.name];
2929
2930 // Remove already removed children
2931 fi = nodes.length;
2932 while (fi--) {
2933 if (!nodes[fi].parent)
2934 nodes.splice(fi, 1);
2935 }
2936
2937 for (fi = 0, fl = list.callbacks.length; fi < fl; fi++)
2938 list.callbacks[fi](nodes, list.name, args);
2939 }
2940 }
2941
2942 return rootNode;
2943 };
2944
2945 // Remove <br> at end of block elements Gecko and WebKit injects BR elements to
2946 // make it possible to place the caret inside empty blocks. This logic tries to remove
2947 // these elements and keep br elements that where intended to be there intact
2948 if (settings.remove_trailing_brs) {
2949 self.addNodeFilter('br', function(nodes, name) {
2950 var i, l = nodes.length, node, blockElements = schema.getBlockElements(),
2951 nonEmptyElements = schema.getNonEmptyElements(), parent, prev, prevName;
2952
2953 // Must loop forwards since it will otherwise remove all brs in <p>a<br><br><br></p>
2954 for (i = 0; i < l; i++) {
2955 node = nodes[i];
2956 parent = node.parent;
2957
2958 if (blockElements[node.parent.name] && node === parent.lastChild) {
2959 // Loop all nodes to the right of the current node and check for other BR elements
2960 // excluding bookmarks since they are invisible
2961 prev = node.prev;
2962 while (prev) {
2963 prevName = prev.name;
2964
2965 // Ignore bookmarks
2966 if (prevName !== "span" || prev.attr('data-mce-type') !== 'bookmark') {
2967 // Found a non BR element
2968 if (prevName !== "br")
2969 break;
2970
2971 // Found another br it's a <br><br> structure then don't remove anything
2972 if (prevName === 'br') {
2973 node = null;
2974 break;
2975 }
2976 }
2977
2978 prev = prev.prev;
2979 }
2980
2981 if (node) {
2982 node.remove();
2983
2984 // Is the parent to be considered empty after we removed the BR
2985 if (parent.isEmpty(nonEmptyElements)) {
2986 elementRule = schema.getElementRule(parent.name);
2987
2988 // Remove or padd the element depending on schema rule
2989 if (elementRule.removeEmpty)
2990 parent.remove();
2991 else if (elementRule.paddEmpty)
2992 parent.empty().append(new tinymce.html.Node('#text', 3)).value = '\u00a0';
2993 }
2994 }
2995 }
2996 }
2997 });
2998 }
2999 }
3000 })(tinymce);
3001
3002 tinymce.html.Writer = function(settings) {
3003 var html = [], indent, indentBefore, indentAfter, encode, htmlOutput;
3004
3005 settings = settings || {};
3006 indent = settings.indent;
3007 indentBefore = tinymce.makeMap(settings.indent_before || '');
3008 indentAfter = tinymce.makeMap(settings.indent_after || '');
3009 encode = tinymce.html.Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
3010 htmlOutput = settings.element_format == "html";
3011
3012 return {
3013 start: function(name, attrs, empty) {
3014 var i, l, attr, value;
3015
3016 if (indent && indentBefore[name] && html.length > 0) {
3017 value = html[html.length - 1];
3018
3019 if (value.length > 0 && value !== '\n')
3020 html.push('\n');
3021 }
3022
3023 html.push('<', name);
3024
3025 if (attrs) {
3026 for (i = 0, l = attrs.length; i < l; i++) {
3027 attr = attrs[i];
3028 html.push(' ', attr.name, '="', encode(attr.value, true), '"');
3029 }
3030 }
3031
3032 if (!empty || htmlOutput)
3033 html[html.length] = '>';
3034 else
3035 html[html.length] = ' />';
3036
3037 if (empty && indent && indentAfter[name] && html.length > 0) {
3038 value = html[html.length - 1];
3039
3040 if (value.length > 0 && value !== '\n')
3041 html.push('\n');
3042 }
3043 },
3044
3045 end: function(name) {
3046 var value;
3047
3048 /*if (indent && indentBefore[name] && html.length > 0) {
3049 value = html[html.length - 1];
3050
3051 if (value.length > 0 && value !== '\n')
3052 html.push('\n');
3053 }*/
3054
3055 html.push('</', name, '>');
3056
3057 if (indent && indentAfter[name] && html.length > 0) {
3058 value = html[html.length - 1];
3059
3060 if (value.length > 0 && value !== '\n')
3061 html.push('\n');
3062 }
3063 },
3064
3065 text: function(text, raw) {
3066 if (text.length > 0)
3067 html[html.length] = raw ? text : encode(text);
3068 },
3069
3070 cdata: function(text) {
3071 html.push('<![CDATA[', text, ']]>');
3072 },
3073
3074 comment: function(text) {
3075 html.push('<!--', text, '-->');
3076 },
3077
3078 pi: function(name, text) {
3079 if (text)
3080 html.push('<?', name, ' ', text, '?>');
3081 else
3082 html.push('<?', name, '?>');
3083
3084 if (indent)
3085 html.push('\n');
3086 },
3087
3088 doctype: function(text) {
3089 html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
3090 },
3091
3092 reset: function() {
3093 html.length = 0;
3094 },
3095
3096 getContent: function() {
3097 return html.join('').replace(/\n$/, '');
3098 }
3099 };
3100 };
3101
3102 (function(tinymce) {
3103 tinymce.html.Serializer = function(settings, schema) {
3104 var self = this, writer = new tinymce.html.Writer(settings);
3105
3106 settings = settings || {};
3107 settings.validate = "validate" in settings ? settings.validate : true;
3108
3109 self.schema = schema = schema || new tinymce.html.Schema();
3110 self.writer = writer;
3111
3112 self.serialize = function(node) {
3113 var handlers, validate;
3114
3115 validate = settings.validate;
3116
3117 handlers = {
3118 // #text
3119 3: function(node, raw) {
3120 writer.text(node.value, node.raw);
3121 },
3122
3123 // #comment
3124 8: function(node) {
3125 writer.comment(node.value);
3126 },
3127
3128 // Processing instruction
3129 7: function(node) {
3130 writer.pi(node.name, node.value);
3131 },
3132
3133 // Doctype
3134 10: function(node) {
3135 writer.doctype(node.value);
3136 },
3137
3138 // CDATA
3139 4: function(node) {
3140 writer.cdata(node.value);
3141 },
3142
3143 // Document fragment
3144 11: function(node) {
3145 if ((node = node.firstChild)) {
3146 do {
3147 walk(node);
3148 } while (node = node.next);
3149 }
3150 }
3151 };
3152
3153 writer.reset();
3154
3155 function walk(node) {
3156 var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
3157
3158 if (!handler) {
3159 name = node.name;
3160 isEmpty = node.shortEnded;
3161 attrs = node.attributes;
3162
3163 // Sort attributes
3164 if (validate && attrs && attrs.length > 1) {
3165 sortedAttrs = [];
3166 sortedAttrs.map = {};
3167
3168 elementRule = schema.getElementRule(node.name);
3169 for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
3170 attrName = elementRule.attributesOrder[i];
3171
3172 if (attrName in attrs.map) {
3173 attrValue = attrs.map[attrName];
3174 sortedAttrs.map[attrName] = attrValue;
3175 sortedAttrs.push({name: attrName, value: attrValue});
3176 }
3177 }
3178
3179 for (i = 0, l = attrs.length; i < l; i++) {
3180 attrName = attrs[i].name;
3181
3182 if (!(attrName in sortedAttrs.map)) {
3183 attrValue = attrs.map[attrName];
3184 sortedAttrs.map[attrName] = attrValue;
3185 sortedAttrs.push({name: attrName, value: attrValue});
3186 }
3187 }
3188
3189 attrs = sortedAttrs;
3190 }
3191
3192 writer.start(node.name, attrs, isEmpty);
3193
3194 if (!isEmpty) {
3195 if ((node = node.firstChild)) {
3196 do {
3197 walk(node);
3198 } while (node = node.next);
3199 }
3200
3201 writer.end(name);
3202 }
3203 } else
3204 handler(node);
3205 }
3206
3207 // Serialize element and treat all non elements as fragments
3208 if (node.type == 1 && !settings.inner)
3209 walk(node);
3210 else
3211 handlers[11](node);
3212
3213 return writer.getContent();
3214 };
3215 }
3216 })(tinymce);
3217
973 (function(tinymce) { 3218 (function(tinymce) {
974 // Shorten names 3219 // Shorten names
975 var each = tinymce.each, 3220 var each = tinymce.each,
976 is = tinymce.is, 3221 is = tinymce.is,
977 isWebKit = tinymce.isWebKit, 3222 isWebKit = tinymce.isWebKit,
978 isIE = tinymce.isIE, 3223 isIE = tinymce.isIE,
979 blockRe = /^(H[1-6R]|P|DIV|ADDRESS|PRE|FORM|T(ABLE|BODY|HEAD|FOOT|H|R|D)|LI|OL|UL|CAPTION|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|NOSCRIPT|MENU|ISINDEX|SAMP)$/, 3224 Entities = tinymce.html.Entities,
980 boolAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
981 mceAttribs = makeMap('src,href,style,coords,shape'),
982 encodedChars = {'&' : '&amp;', '"' : '&quot;', '<' : '&lt;', '>' : '&gt;'},
983 encodeCharsRe = /[<>&\"]/g,
984 simpleSelectorRe = /^([a-z0-9],?)+$/i, 3225 simpleSelectorRe = /^([a-z0-9],?)+$/i,
985 tagRegExp = /<(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)(\s*\/?)>/g, 3226 blockElementsMap = tinymce.html.Schema.blockElementsMap,
986 attrRegExp = /(\w+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g; 3227 whiteSpaceRegExp = /^[ \t\r\n]*$/;
987
988 function makeMap(str) {
989 var map = {}, i;
990
991 str = str.split(',');
992 for (i = str.length; i >= 0; i--)
993 map[str[i]] = 1;
994
995 return map;
996 };
997 3228
998 tinymce.create('tinymce.dom.DOMUtils', { 3229 tinymce.create('tinymce.dom.DOMUtils', {
999 doc : null, 3230 doc : null,
1000 root : null, 3231 root : null,
1001 files : null, 3232 files : null,
1021 t.doc = d; 3252 t.doc = d;
1022 t.win = window; 3253 t.win = window;
1023 t.files = {}; 3254 t.files = {};
1024 t.cssFlicker = false; 3255 t.cssFlicker = false;
1025 t.counter = 0; 3256 t.counter = 0;
1026 t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat"; 3257 t.stdMode = !tinymce.isIE || d.documentMode >= 8;
1027 t.stdMode = d.documentMode === 8; 3258 t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode;
3259 t.hasOuterHTML = "outerHTML" in d.createElement("a");
1028 3260
1029 t.settings = s = tinymce.extend({ 3261 t.settings = s = tinymce.extend({
1030 keep_values : false, 3262 keep_values : false,
1031 hex_colors : 1, 3263 hex_colors : 1
1032 process_html : 1
1033 }, s); 3264 }, s);
3265
3266 t.schema = s.schema;
3267 t.styles = new tinymce.html.Styles({
3268 url_converter : s.url_converter,
3269 url_converter_scope : s.url_converter_scope
3270 }, s.schema);
1034 3271
1035 // Fix IE6SP2 flicker and check it failed for pre SP2 3272 // Fix IE6SP2 flicker and check it failed for pre SP2
1036 if (tinymce.isIE6) { 3273 if (tinymce.isIE6) {
1037 try { 3274 try {
1038 d.execCommand('BackgroundImageCache', false, true); 3275 d.execCommand('BackgroundImageCache', false, true);
1039 } catch (e) { 3276 } catch (e) {
1040 t.cssFlicker = true; 3277 t.cssFlicker = true;
1041 } 3278 }
1042 } 3279 }
1043 3280
1044 // Build styles list 3281 if (isIE) {
1045 if (s.valid_styles) { 3282 // Add missing HTML 4/5 elements to IE
1046 t._styles = {}; 3283 ('abbr article aside audio canvas ' +
1047 3284 'details figcaption figure footer ' +
1048 // Convert styles into a rule list 3285 'header hgroup mark menu meter nav ' +
1049 each(s.valid_styles, function(value, key) { 3286 'output progress section summary ' +
1050 t._styles[key] = tinymce.explode(value); 3287 'time video').replace(/\w+/g, function(name) {
3288 d.createElement(name);
1051 }); 3289 });
1052 } 3290 }
1053 3291
1054 tinymce.addUnload(t.destroy, t); 3292 tinymce.addUnload(t.destroy, t);
1055 }, 3293 },
1244 for (k in a) { 3482 for (k in a) {
1245 if (a.hasOwnProperty(k)) 3483 if (a.hasOwnProperty(k))
1246 o += ' ' + k + '="' + t.encode(a[k]) + '"'; 3484 o += ' ' + k + '="' + t.encode(a[k]) + '"';
1247 } 3485 }
1248 3486
1249 if (tinymce.is(h)) 3487 // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
3488 if (typeof(h) != "undefined")
1250 return o + '>' + h + '</' + n + '>'; 3489 return o + '>' + h + '</' + n + '>';
1251 3490
1252 return o + ' />'; 3491 return o + ' />';
1253 }, 3492 },
1254 3493
1255 remove : function(node, keep_children) { 3494 remove : function(node, keep_children) {
1256 return this.run(node, function(node) { 3495 return this.run(node, function(node) {
1257 var parent, child; 3496 var child, parent = node.parentNode;
1258
1259 parent = node.parentNode;
1260 3497
1261 if (!parent) 3498 if (!parent)
1262 return null; 3499 return null;
1263 3500
1264 if (keep_children) { 3501 if (keep_children) {
1314 s[na] = v || ''; 3551 s[na] = v || '';
1315 } 3552 }
1316 3553
1317 // Force update of the style data 3554 // Force update of the style data
1318 if (t.settings.update_styles) 3555 if (t.settings.update_styles)
1319 t.setAttrib(e, '_mce_style'); 3556 t.setAttrib(e, 'data-mce-style');
1320 }); 3557 });
1321 }, 3558 },
1322 3559
1323 getStyle : function(n, na, c) { 3560 getStyle : function(n, na, c) {
1324 n = this.get(n); 3561 n = this.get(n);
1325 3562
1326 if (!n) 3563 if (!n)
1327 return false; 3564 return;
1328 3565
1329 // Gecko 3566 // Gecko
1330 if (this.doc.defaultView && c) { 3567 if (this.doc.defaultView && c) {
1331 // Remove camelcase 3568 // Remove camelcase
1332 na = na.replace(/[A-Z]/g, function(a){ 3569 na = na.replace(/[A-Z]/g, function(a){
1351 3588
1352 // IE & Opera 3589 // IE & Opera
1353 if (n.currentStyle && c) 3590 if (n.currentStyle && c)
1354 return n.currentStyle[na]; 3591 return n.currentStyle[na];
1355 3592
1356 return n.style[na]; 3593 return n.style ? n.style[na] : undefined;
1357 }, 3594 },
1358 3595
1359 setStyles : function(e, o) { 3596 setStyles : function(e, o) {
1360 var t = this, s = t.settings, ol; 3597 var t = this, s = t.settings, ol;
1361 3598
1368 3605
1369 // Update style info 3606 // Update style info
1370 s.update_styles = ol; 3607 s.update_styles = ol;
1371 if (s.update_styles) 3608 if (s.update_styles)
1372 t.setAttrib(e, s.cssText); 3609 t.setAttrib(e, s.cssText);
3610 },
3611
3612 removeAllAttribs: function(e) {
3613 return this.run(e, function(e) {
3614 var i, attrs = e.attributes;
3615 for (i = attrs.length - 1; i >= 0; i--) {
3616 e.removeAttributeNode(attrs.item(i));
3617 }
3618 });
1373 }, 3619 },
1374 3620
1375 setAttrib : function(e, n, v) { 3621 setAttrib : function(e, n, v) {
1376 var t = this; 3622 var t = this;
1377 3623
1397 } 3643 }
1398 3644
1399 // No mce_style for elements with these since they might get resized by the user 3645 // No mce_style for elements with these since they might get resized by the user
1400 if (s.keep_values) { 3646 if (s.keep_values) {
1401 if (v && !t._isRes(v)) 3647 if (v && !t._isRes(v))
1402 e.setAttribute('_mce_style', v, 2); 3648 e.setAttribute('data-mce-style', v, 2);
1403 else 3649 else
1404 e.removeAttribute('_mce_style', 2); 3650 e.removeAttribute('data-mce-style', 2);
1405 } 3651 }
1406 3652
1407 e.style.cssText = v; 3653 e.style.cssText = v;
1408 break; 3654 break;
1409 3655
1415 case "href": 3661 case "href":
1416 if (s.keep_values) { 3662 if (s.keep_values) {
1417 if (s.url_converter) 3663 if (s.url_converter)
1418 v = s.url_converter.call(s.url_converter_scope || t, v, n, e); 3664 v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
1419 3665
1420 t.setAttrib(e, '_mce_' + n, v, 2); 3666 t.setAttrib(e, 'data-mce-' + n, v, 2);
1421 } 3667 }
1422 3668
1423 break; 3669 break;
1424 3670
1425 case "shape": 3671 case "shape":
1426 e.setAttribute('_mce_style', v); 3672 e.setAttribute('data-mce-style', v);
1427 break; 3673 break;
1428 } 3674 }
1429 3675
1430 if (is(v) && v !== null && v.length !== 0) 3676 if (is(v) && v !== null && v.length !== 0)
1431 e.setAttribute(n, '' + v, 2); 3677 e.setAttribute(n, '' + v, 2);
1455 if (!is(dv)) 3701 if (!is(dv))
1456 dv = ''; 3702 dv = '';
1457 3703
1458 // Try the mce variant for these 3704 // Try the mce variant for these
1459 if (/^(src|href|style|coords|shape)$/.test(n)) { 3705 if (/^(src|href|style|coords|shape)$/.test(n)) {
1460 v = e.getAttribute("_mce_" + n); 3706 v = e.getAttribute("data-mce-" + n);
1461 3707
1462 if (v) 3708 if (v)
1463 return v; 3709 return v;
1464 } 3710 }
1465 3711
1488 3734
1489 if (v) { 3735 if (v) {
1490 v = t.serializeStyle(t.parseStyle(v), e.nodeName); 3736 v = t.serializeStyle(t.parseStyle(v), e.nodeName);
1491 3737
1492 if (t.settings.keep_values && !t._isRes(v)) 3738 if (t.settings.keep_values && !t._isRes(v))
1493 e.setAttribute('_mce_style', v); 3739 e.setAttribute('data-mce-style', v);
1494 } 3740 }
1495 } 3741 }
1496 3742
1497 // Remove Apple and WebKit stuff 3743 // Remove Apple and WebKit stuff
1498 if (isWebKit && n === "class" && v) 3744 if (isWebKit && n === "class" && v)
1556 break; 3802 break;
1557 3803
1558 default: 3804 default:
1559 // IE has odd anonymous function for event attributes 3805 // IE has odd anonymous function for event attributes
1560 if (n.indexOf('on') === 0 && v) 3806 if (n.indexOf('on') === 0 && v)
1561 v = ('' + v).replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1'); 3807 v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v);
1562 } 3808 }
1563 } 3809 }
1564 3810
1565 return (v !== undefined && v !== null && v !== '') ? '' + v : dv; 3811 return (v !== undefined && v !== null && v !== '') ? '' + v : dv;
1566 }, 3812 },
1599 3845
1600 return {x : x, y : y}; 3846 return {x : x, y : y};
1601 }, 3847 },
1602 3848
1603 parseStyle : function(st) { 3849 parseStyle : function(st) {
1604 var t = this, s = t.settings, o = {}; 3850 return this.styles.parse(st);
1605
1606 if (!st)
1607 return o;
1608
1609 function compress(p, s, ot) {
1610 var t, r, b, l;
1611
1612 // Get values and check it it needs compressing
1613 t = o[p + '-top' + s];
1614 if (!t)
1615 return;
1616
1617 r = o[p + '-right' + s];
1618 if (t != r)
1619 return;
1620
1621 b = o[p + '-bottom' + s];
1622 if (r != b)
1623 return;
1624
1625 l = o[p + '-left' + s];
1626 if (b != l)
1627 return;
1628
1629 // Compress
1630 o[ot] = l;
1631 delete o[p + '-top' + s];
1632 delete o[p + '-right' + s];
1633 delete o[p + '-bottom' + s];
1634 delete o[p + '-left' + s];
1635 };
1636
1637 function compress2(ta, a, b, c) {
1638 var t;
1639
1640 t = o[a];
1641 if (!t)
1642 return;
1643
1644 t = o[b];
1645 if (!t)
1646 return;
1647
1648 t = o[c];
1649 if (!t)
1650 return;
1651
1652 // Compress
1653 o[ta] = o[a] + ' ' + o[b] + ' ' + o[c];
1654 delete o[a];
1655 delete o[b];
1656 delete o[c];
1657 };
1658
1659 st = st.replace(/&(#?[a-z0-9]+);/g, '&$1_MCE_SEMI_'); // Protect entities
1660
1661 each(st.split(';'), function(v) {
1662 var sv, ur = [];
1663
1664 if (v) {
1665 v = v.replace(/_MCE_SEMI_/g, ';'); // Restore entities
1666 v = v.replace(/url\([^\)]+\)/g, function(v) {ur.push(v);return 'url(' + ur.length + ')';});
1667 v = v.split(':');
1668 sv = tinymce.trim(v[1]);
1669 sv = sv.replace(/url\(([^\)]+)\)/g, function(a, b) {return ur[parseInt(b) - 1];});
1670
1671 sv = sv.replace(/rgb\([^\)]+\)/g, function(v) {
1672 return t.toHex(v);
1673 });
1674
1675 if (s.url_converter) {
1676 sv = sv.replace(/url\([\'\"]?([^\)\'\"]+)[\'\"]?\)/g, function(x, c) {
1677 return 'url(' + s.url_converter.call(s.url_converter_scope || t, t.decode(c), 'style', null) + ')';
1678 });
1679 }
1680
1681 o[tinymce.trim(v[0]).toLowerCase()] = sv;
1682 }
1683 });
1684
1685 compress("border", "", "border");
1686 compress("border", "-width", "border-width");
1687 compress("border", "-color", "border-color");
1688 compress("border", "-style", "border-style");
1689 compress("padding", "", "padding");
1690 compress("margin", "", "margin");
1691 compress2('border', 'border-width', 'border-style', 'border-color');
1692
1693 if (isIE) {
1694 // Remove pointless border
1695 if (o.border == 'medium none')
1696 o.border = '';
1697 }
1698
1699 return o;
1700 }, 3851 },
1701 3852
1702 serializeStyle : function(o, name) { 3853 serializeStyle : function(o, name) {
1703 var t = this, s = ''; 3854 return this.styles.serialize(o, name);
1704
1705 function add(v, k) {
1706 if (k && v) {
1707 // Remove browser specific styles like -moz- or -webkit-
1708 if (k.indexOf('-') === 0)
1709 return;
1710
1711 switch (k) {
1712 case 'font-weight':
1713 // Opera will output bold as 700
1714 if (v == 700)
1715 v = 'bold';
1716
1717 break;
1718
1719 case 'color':
1720 case 'background-color':
1721 v = v.toLowerCase();
1722 break;
1723 }
1724
1725 s += (s ? ' ' : '') + k + ': ' + v + ';';
1726 }
1727 };
1728
1729 // Validate style output
1730 if (name && t._styles) {
1731 each(t._styles['*'], function(name) {
1732 add(o[name], name);
1733 });
1734
1735 each(t._styles[name.toLowerCase()], function(name) {
1736 add(o[name], name);
1737 });
1738 } else
1739 each(o, add);
1740
1741 return s;
1742 }, 3855 },
1743 3856
1744 loadCSS : function(u) { 3857 loadCSS : function(u) {
1745 var t = this, d = t.doc, head; 3858 var t = this, d = t.doc, head;
1746 3859
1759 link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)}); 3872 link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
1760 3873
1761 // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug 3874 // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
1762 // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading 3875 // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
1763 // It's ugly but it seems to work fine. 3876 // It's ugly but it seems to work fine.
1764 if (isIE && d.documentMode) { 3877 if (isIE && d.documentMode && d.recalc) {
1765 link.onload = function() { 3878 link.onload = function() {
1766 d.recalc(); 3879 if (d.recalc)
3880 d.recalc();
3881
1767 link.onload = null; 3882 link.onload = null;
1768 }; 3883 };
1769 } 3884 }
1770 3885
1771 head.appendChild(link); 3886 head.appendChild(link);
1841 3956
1842 uniqueId : function(p) { 3957 uniqueId : function(p) {
1843 return (!p ? 'mce_' : p) + (this.counter++); 3958 return (!p ? 'mce_' : p) + (this.counter++);
1844 }, 3959 },
1845 3960
1846 setHTML : function(e, h) { 3961 setHTML : function(element, html) {
1847 var t = this; 3962 var self = this;
1848 3963
1849 return this.run(e, function(e) { 3964 return self.run(element, function(element) {
1850 var x, i, nl, n, p, x;
1851
1852 h = t.processHTML(h);
1853
1854 if (isIE) { 3965 if (isIE) {
1855 function set() { 3966 // Remove all child nodes, IE keeps empty text nodes in DOM
1856 // Remove all child nodes 3967 while (element.firstChild)
1857 while (e.firstChild) 3968 element.removeChild(element.firstChild);
1858 e.firstChild.removeNode(); 3969
1859 3970 try {
1860 try { 3971 // IE will remove comments from the beginning
1861 // IE will remove comments from the beginning 3972 // unless you padd the contents with something
1862 // unless you padd the contents with something 3973 element.innerHTML = '<br />' + html;
1863 e.innerHTML = '<br />' + h; 3974 element.removeChild(element.firstChild);
1864 e.removeChild(e.firstChild); 3975 } catch (ex) {
1865 } catch (ex) { 3976 // IE sometimes produces an unknown runtime error on innerHTML if it's an block element within a block element for example a div inside a p
1866 // IE sometimes produces an unknown runtime error on innerHTML if it's an block element within a block element for example a div inside a p 3977 // This seems to fix this problem
1867 // This seems to fix this problem 3978
1868 3979 // Create new div with HTML contents and a BR infront to keep comments
1869 // Create new div with HTML contents and a BR infront to keep comments 3980 element = self.create('div');
1870 x = t.create('div'); 3981 element.innerHTML = '<br />' + html;
1871 x.innerHTML = '<br />' + h; 3982
1872 3983 // Add all children from div to target
1873 // Add all children from div to target 3984 each (element.childNodes, function(node, i) {
1874 each (x.childNodes, function(n, i) { 3985 // Skip br element
1875 // Skip br element 3986 if (i)
1876 if (i) 3987 element.appendChild(node);
1877 e.appendChild(n); 3988 });
1878 });
1879 }
1880 };
1881
1882 // IE has a serious bug when it comes to paragraphs it can produce an invalid
1883 // DOM tree if contents like this <p><ul><li>Item 1</li></ul></p> is inserted
1884 // It seems to be that IE doesn't like a root block element placed inside another root block element
1885 if (t.settings.fix_ie_paragraphs)
1886 h = h.replace(/<p><\/p>|<p([^>]+)><\/p>|<p[^\/+]\/>/gi, '<p$1 _mce_keep="true">&nbsp;</p>');
1887
1888 set();
1889
1890 if (t.settings.fix_ie_paragraphs) {
1891 // Check for odd paragraphs this is a sign of a broken DOM
1892 nl = e.getElementsByTagName("p");
1893 for (i = nl.length - 1, x = 0; i >= 0; i--) {
1894 n = nl[i];
1895
1896 if (!n.hasChildNodes()) {
1897 if (!n._mce_keep) {
1898 x = 1; // Is broken
1899 break;
1900 }
1901
1902 n.removeAttribute('_mce_keep');
1903 }
1904 }
1905 }
1906
1907 // Time to fix the madness IE left us
1908 if (x) {
1909 // So if we replace the p elements with divs and mark them and then replace them back to paragraphs
1910 // after we use innerHTML we can fix the DOM tree
1911 h = h.replace(/<p ([^>]+)>|<p>/ig, '<div $1 _mce_tmp="1">');
1912 h = h.replace(/<\/p>/gi, '</div>');
1913
1914 // Set the new HTML with DIVs
1915 set();
1916
1917 // Replace all DIV elements with the _mce_tmp attibute back to paragraphs
1918 // This is needed since IE has a annoying bug see above for details
1919 // This is a slow process but it has to be done. :(
1920 if (t.settings.fix_ie_paragraphs) {
1921 nl = e.getElementsByTagName("DIV");
1922 for (i = nl.length - 1; i >= 0; i--) {
1923 n = nl[i];
1924
1925 // Is it a temp div
1926 if (n._mce_tmp) {
1927 // Create new paragraph
1928 p = t.doc.createElement('p');
1929
1930 // Copy all attributes
1931 n.cloneNode(false).outerHTML.replace(/([a-z0-9\-_]+)=/gi, function(a, b) {
1932 var v;
1933
1934 if (b !== '_mce_tmp') {
1935 v = n.getAttribute(b);
1936
1937 if (!v && b === 'class')
1938 v = n.className;
1939
1940 p.setAttribute(b, v);
1941 }
1942 });
1943
1944 // Append all children to new paragraph
1945 for (x = 0; x<n.childNodes.length; x++)
1946 p.appendChild(n.childNodes[x].cloneNode(true));
1947
1948 // Replace div with new paragraph
1949 n.swapNode(p);
1950 }
1951 }
1952 }
1953 } 3989 }
1954 } else 3990 } else
1955 e.innerHTML = h; 3991 element.innerHTML = html;
1956 3992
1957 return h; 3993 return html;
1958 }); 3994 });
1959 }, 3995 },
1960 3996
1961 processHTML : function(h) { 3997 getOuterHTML : function(elm) {
1962 var t = this, s = t.settings, codeBlocks = []; 3998 var doc, self = this;
1963 3999
1964 if (!s.process_html) 4000 elm = self.get(elm);
1965 return h; 4001
1966 4002 if (!elm)
1967 if (isIE) {
1968 h = h.replace(/&apos;/g, '&#39;'); // IE can't handle apos
1969 h = h.replace(/\s+(disabled|checked|readonly|selected)\s*=\s*[\"\']?(false|0)[\"\']?/gi, ''); // IE doesn't handle default values correct
1970 }
1971
1972 // Fix some issues
1973 h = h.replace(/<a( )([^>]+)\/>|<a\/>/gi, '<a$1$2></a>'); // Force open
1974
1975 // Store away src and href in _mce_src and mce_href since browsers mess them up
1976 if (s.keep_values) {
1977 // Wrap scripts and styles in comments for serialization purposes
1978 if (/<script|noscript|style/i.test(h)) {
1979 function trim(s) {
1980 // Remove prefix and suffix code for element
1981 s = s.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n');
1982 s = s.replace(/^[\r\n]*|[\r\n]*$/g, '');
1983 s = s.replace(/^\s*(\/\/\s*<!--|\/\/\s*<!\[CDATA\[|<!--|<!\[CDATA\[)[\r\n]*/g, '');
1984 s = s.replace(/\s*(\/\/\s*\]\]>|\/\/\s*-->|\]\]>|-->|\]\]-->)\s*$/g, '');
1985
1986 return s;
1987 };
1988
1989 // Wrap the script contents in CDATA and keep them from executing
1990 h = h.replace(/<script([^>]+|)>([\s\S]*?)<\/script>/gi, function(v, attribs, text) {
1991 // Force type attribute
1992 if (!attribs)
1993 attribs = ' type="text/javascript"';
1994
1995 // Convert the src attribute of the scripts
1996 attribs = attribs.replace(/src=\"([^\"]+)\"?/i, function(a, url) {
1997 if (s.url_converter)
1998 url = t.encode(s.url_converter.call(s.url_converter_scope || t, t.decode(url), 'src', 'script'));
1999
2000 return '_mce_src="' + url + '"';
2001 });
2002
2003 // Wrap text contents
2004 if (tinymce.trim(text)) {
2005 codeBlocks.push(trim(text));
2006 text = '<!--\nMCE_SCRIPT:' + (codeBlocks.length - 1) + '\n// -->';
2007 }
2008
2009 return '<mce:script' + attribs + '>' + text + '</mce:script>';
2010 });
2011
2012 // Wrap style elements
2013 h = h.replace(/<style([^>]+|)>([\s\S]*?)<\/style>/gi, function(v, attribs, text) {
2014 // Wrap text contents
2015 if (text) {
2016 codeBlocks.push(trim(text));
2017 text = '<!--\nMCE_SCRIPT:' + (codeBlocks.length - 1) + '\n-->';
2018 }
2019
2020 return '<mce:style' + attribs + '>' + text + '</mce:style><style ' + attribs + ' _mce_bogus="1">' + text + '</style>';
2021 });
2022
2023 // Wrap noscript elements
2024 h = h.replace(/<noscript([^>]+|)>([\s\S]*?)<\/noscript>/g, function(v, attribs, text) {
2025 return '<mce:noscript' + attribs + '><!--' + t.encode(text).replace(/--/g, '&#45;&#45;') + '--></mce:noscript>';
2026 });
2027 }
2028
2029 h = h.replace(/<!\[CDATA\[([\s\S]+)\]\]>/g, '<!--[CDATA[$1]]-->');
2030
2031 // This function processes the attributes in the HTML string to force boolean
2032 // attributes to the attr="attr" format and convert style, src and href to _mce_ versions
2033 function processTags(html) {
2034 return html.replace(tagRegExp, function(match, elm_name, attrs, end) {
2035 return '<' + elm_name + attrs.replace(attrRegExp, function(match, name, value, val2, val3) {
2036 var mceValue;
2037
2038 name = name.toLowerCase();
2039 value = value || val2 || val3 || "";
2040
2041 // Treat boolean attributes
2042 if (boolAttrs[name]) {
2043 // false or 0 is treated as a missing attribute
2044 if (value === 'false' || value === '0')
2045 return;
2046
2047 return name + '="' + name + '"';
2048 }
2049
2050 // Is attribute one that needs special treatment
2051 if (mceAttribs[name] && attrs.indexOf('_mce_' + name) == -1) {
2052 mceValue = t.decode(value);
2053
2054 // Convert URLs to relative/absolute ones
2055 if (s.url_converter && (name == "src" || name == "href"))
2056 mceValue = s.url_converter.call(s.url_converter_scope || t, mceValue, name, elm_name);
2057
2058 // Process styles lowercases them and compresses them
2059 if (name == 'style')
2060 mceValue = t.serializeStyle(t.parseStyle(mceValue), name);
2061
2062 return name + '="' + value + '"' + ' _mce_' + name + '="' + t.encode(mceValue) + '"';
2063 }
2064
2065 return match;
2066 }) + end + '>';
2067 });
2068 };
2069
2070 h = processTags(h);
2071
2072 // Restore script blocks
2073 h = h.replace(/MCE_SCRIPT:([0-9]+)/g, function(val, idx) {
2074 return codeBlocks[idx];
2075 });
2076 }
2077
2078 return h;
2079 },
2080
2081 getOuterHTML : function(e) {
2082 var d;
2083
2084 e = this.get(e);
2085
2086 if (!e)
2087 return null; 4003 return null;
2088 4004
2089 if (e.outerHTML !== undefined) 4005 if (elm.nodeType === 1 && self.hasOuterHTML)
2090 return e.outerHTML; 4006 return elm.outerHTML;
2091 4007
2092 d = (e.ownerDocument || this.doc).createElement("body"); 4008 doc = (elm.ownerDocument || self.doc).createElement("body");
2093 d.appendChild(e.cloneNode(true)); 4009 doc.appendChild(elm.cloneNode(true));
2094 4010
2095 return d.innerHTML; 4011 return doc.innerHTML;
2096 }, 4012 },
2097 4013
2098 setOuterHTML : function(e, h, d) { 4014 setOuterHTML : function(e, h, d) {
2099 var t = this; 4015 var t = this;
2100 4016
2135 setHTML(e, h, d); 4051 setHTML(e, h, d);
2136 } 4052 }
2137 }); 4053 });
2138 }, 4054 },
2139 4055
2140 decode : function(s) { 4056 decode : Entities.decode,
2141 var e, n, v; 4057
2142 4058 encode : Entities.encodeAllRaw,
2143 // Look for entities to decode
2144 if (/&[\w#]+;/.test(s)) {
2145 // Decode the entities using a div element not super efficient but less code
2146 e = this.doc.createElement("div");
2147 e.innerHTML = s;
2148 n = e.firstChild;
2149 v = '';
2150
2151 if (n) {
2152 do {
2153 v += n.nodeValue;
2154 } while (n = n.nextSibling);
2155 }
2156
2157 return v || s;
2158 }
2159
2160 return s;
2161 },
2162
2163 encode : function(str) {
2164 return ('' + str).replace(encodeCharsRe, function(chr) {
2165 return encodedChars[chr];
2166 });
2167 },
2168 4059
2169 insertAfter : function(node, reference_node) { 4060 insertAfter : function(node, reference_node) {
2170 reference_node = this.get(reference_node); 4061 reference_node = this.get(reference_node);
2171 4062
2172 return this.run(node, function(node) { 4063 return this.run(node, function(node) {
2182 4073
2183 return node; 4074 return node;
2184 }); 4075 });
2185 }, 4076 },
2186 4077
2187 isBlock : function(n) { 4078 isBlock : function(node) {
2188 if (n.nodeType && n.nodeType !== 1) 4079 var type = node.nodeType;
2189 return false; 4080
2190 4081 // If it's a node then check the type and use the nodeName
2191 n = n.nodeName || n; 4082 if (type)
2192 4083 return !!(type === 1 && blockElementsMap[node.nodeName]);
2193 return blockRe.test(n); 4084
4085 return !!blockElementsMap[node];
2194 }, 4086 },
2195 4087
2196 replace : function(n, o, k) { 4088 replace : function(n, o, k) {
2197 var t = this; 4089 var t = this;
2198 4090
2293 if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v)) 4185 if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v))
2294 return; 4186 return;
2295 4187
2296 // Remove everything but class name 4188 // Remove everything but class name
2297 ov = v; 4189 ov = v;
2298 v = v.replace(/.*\.([a-z0-9_\-]+).*/i, '$1'); 4190 v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v);
2299 4191
2300 // Filter classes 4192 // Filter classes
2301 if (f && !(v = f(v, ov))) 4193 if (f && !(v = f(v, ov)))
2302 return; 4194 return;
2303 4195
2385 } 4277 }
2386 4278
2387 return n.attributes; 4279 return n.attributes;
2388 }, 4280 },
2389 4281
4282 isEmpty : function(node, elements) {
4283 var self = this, i, attributes, type, walker, name;
4284
4285 node = node.firstChild;
4286 if (node) {
4287 walker = new tinymce.dom.TreeWalker(node);
4288 elements = elements || self.schema ? self.schema.getNonEmptyElements() : null;
4289
4290 do {
4291 type = node.nodeType;
4292
4293 if (type === 1) {
4294 // Ignore bogus elements
4295 if (node.getAttribute('data-mce-bogus'))
4296 continue;
4297
4298 // Keep empty elements like <img />
4299 if (elements && elements[node.nodeName.toLowerCase()])
4300 return false;
4301
4302 // Keep elements with data attributes or name attribute like <a name="1"></a>
4303 attributes = self.getAttribs(node);
4304 i = node.attributes.length;
4305 while (i--) {
4306 name = node.attributes[i].nodeName;
4307 if (name === "name" || name.indexOf('data-') === 0)
4308 return false;
4309 }
4310 }
4311
4312 // Keep non whitespace text nodes
4313 if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue)))
4314 return false;
4315 } while (node = walker.next());
4316 }
4317
4318 return true;
4319 },
4320
2390 destroy : function(s) { 4321 destroy : function(s) {
2391 var t = this; 4322 var t = this;
2392 4323
2393 if (t.events) 4324 if (t.events)
2394 t.events.destroy(); 4325 t.events.destroy();
2405 4336
2406 return d.createRange ? d.createRange() : new tinymce.dom.Range(this); 4337 return d.createRange ? d.createRange() : new tinymce.dom.Range(this);
2407 }, 4338 },
2408 4339
2409 nodeIndex : function(node, normalized) { 4340 nodeIndex : function(node, normalized) {
2410 var idx = 0, lastNodeType, lastNode, nodeType; 4341 var idx = 0, lastNodeType, lastNode, nodeType, nodeValueExists;
2411 4342
2412 if (node) { 4343 if (node) {
2413 for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) { 4344 for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) {
2414 nodeType = node.nodeType; 4345 nodeType = node.nodeType;
2415 4346
2416 // Normalize text nodes 4347 // Normalize text nodes
2417 if (normalized && nodeType == 3) { 4348 if (normalized && nodeType == 3) {
2418 if (nodeType == lastNodeType || !node.nodeValue.length) 4349 // ensure that text nodes that have been removed are handled correctly in Internet Explorer.
4350 // (the nodeValue attribute will not exist, and will error here).
4351 nodeValueExists = false;
4352 try {nodeValueExists = node.nodeValue.length} catch (c) {}
4353 if (nodeType == lastNodeType || !nodeValueExists)
2419 continue; 4354 continue;
2420 } 4355 }
2421
2422 idx++; 4356 idx++;
2423 lastNodeType = nodeType; 4357 lastNodeType = nodeType;
2424 } 4358 }
2425 } 4359 }
2426 4360
2437 // would produce: 4371 // would produce:
2438 // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p> 4372 // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
2439 // this function will then trim of empty edges and produce: 4373 // this function will then trim of empty edges and produce:
2440 // <p>text 1</p><b>CHOP</b><p>text 2</p> 4374 // <p>text 1</p><b>CHOP</b><p>text 2</p>
2441 function trim(node) { 4375 function trim(node) {
2442 var i, children = node.childNodes; 4376 var i, children = node.childNodes, type = node.nodeType;
2443 4377
2444 if (node.nodeType == 1 && node.getAttribute('_mce_type') == 'bookmark') 4378 if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark')
2445 return; 4379 return;
2446 4380
2447 for (i = children.length - 1; i >= 0; i--) 4381 for (i = children.length - 1; i >= 0; i--)
2448 trim(children[i]); 4382 trim(children[i]);
2449 4383
2450 if (node.nodeType != 9) { 4384 if (type != 9) {
2451 // Keep non whitespace text nodes 4385 // Keep non whitespace text nodes
2452 if (node.nodeType == 3 && node.nodeValue.length > 0) 4386 if (type == 3 && node.nodeValue.length > 0) {
2453 return; 4387 // If parent element isn't a block or there isn't any useful contents for example "<p> </p>"
2454 4388 if (!t.isBlock(node.parentNode) || tinymce.trim(node.nodeValue).length > 0)
2455 if (node.nodeType == 1) { 4389 return;
4390 } else if (type == 1) {
2456 // If the only child is a bookmark then move it up 4391 // If the only child is a bookmark then move it up
2457 children = node.childNodes; 4392 children = node.childNodes;
2458 if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('_mce_type') == 'bookmark') 4393 if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('data-mce-type') == 'bookmark')
2459 node.parentNode.insertBefore(children[0], node); 4394 node.parentNode.insertBefore(children[0], node);
2460 4395
2461 // Keep non empty elements or img, hr etc 4396 // Keep non empty elements or img, hr etc
2462 if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName)) 4397 if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName))
2463 return; 4398 return;
2674 setStart(n, 0); 4609 setStart(n, 0);
2675 setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length); 4610 setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
2676 }; 4611 };
2677 4612
2678 function compareBoundaryPoints(h, r) { 4613 function compareBoundaryPoints(h, r) {
2679 var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET]; 4614 var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET],
4615 rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset;
2680 4616
2681 // Check START_TO_START 4617 // Check START_TO_START
2682 if (h === 0) 4618 if (h === 0)
2683 return _compareBoundaryPoints(sc, so, sc, so); 4619 return _compareBoundaryPoints(sc, so, rsc, rso);
2684 4620
2685 // Check START_TO_END 4621 // Check START_TO_END
2686 if (h === 1) 4622 if (h === 1)
2687 return _compareBoundaryPoints(sc, so, ec, eo); 4623 return _compareBoundaryPoints(ec, eo, rsc, rso);
2688 4624
2689 // Check END_TO_END 4625 // Check END_TO_END
2690 if (h === 2) 4626 if (h === 2)
2691 return _compareBoundaryPoints(ec, eo, ec, eo); 4627 return _compareBoundaryPoints(ec, eo, rec, reo);
2692 4628
2693 // Check END_TO_START 4629 // Check END_TO_START
2694 if (h === 3) 4630 if (h === 3)
2695 return _compareBoundaryPoints(ec, eo, sc, so); 4631 return _compareBoundaryPoints(sc, so, rec, reo);
2696 }; 4632 };
2697 4633
2698 function deleteContents() { 4634 function deleteContents() {
2699 _traverse(DELETE); 4635 _traverse(DELETE);
2700 }; 4636 };
2782 return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]); 4718 return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]);
2783 }; 4719 };
2784 4720
2785 function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) { 4721 function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) {
2786 var c, offsetC, n, cmnRoot, childA, childB; 4722 var c, offsetC, n, cmnRoot, childA, childB;
2787 4723
2788 // In the first case the boundary-points have the same container. A is before B 4724 // In the first case the boundary-points have the same container. A is before B
2789 // if its offset is less than the offset of B, A is equal to B if its offset is 4725 // if its offset is less than the offset of B, A is equal to B if its offset is
2790 // equal to the offset of B, and A is after B if its offset is greater than the 4726 // equal to the offset of B, and A is after B if its offset is greater than the
2791 // offset of B. 4727 // offset of B.
2792 if (containerA == containerB) { 4728 if (containerA == containerB) {
3068 n = _traverseLeftBoundary(startAncestor, how); 5004 n = _traverseLeftBoundary(startAncestor, how);
3069 if (frag) 5005 if (frag)
3070 frag.appendChild(n); 5006 frag.appendChild(n);
3071 5007
3072 startIdx = nodeIndex(startAncestor); 5008 startIdx = nodeIndex(startAncestor);
3073 ++startIdx; // Because we already traversed it.... 5009 ++startIdx; // Because we already traversed it
3074 5010
3075 cnt = t[END_OFFSET] - startIdx; 5011 cnt = t[END_OFFSET] - startIdx;
3076 n = startAncestor.nextSibling; 5012 n = startAncestor.nextSibling;
3077 while (cnt > 0) { 5013 while (cnt > 0) {
3078 sibling = n.nextSibling; 5014 sibling = n.nextSibling;
3266 // If selection is outside the current document just return an empty range 5202 // If selection is outside the current document just return an empty range
3267 element = ieRange.item ? ieRange.item(0) : ieRange.parentElement(); 5203 element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
3268 if (element.ownerDocument != dom.doc) 5204 if (element.ownerDocument != dom.doc)
3269 return domRange; 5205 return domRange;
3270 5206
5207 collapsed = selection.isCollapsed();
5208
3271 // Handle control selection or text selection of a image 5209 // Handle control selection or text selection of a image
3272 if (ieRange.item || !element.hasChildNodes()) { 5210 if (ieRange.item || !element.hasChildNodes()) {
3273 domRange.setStart(element.parentNode, dom.nodeIndex(element)); 5211 if (collapsed) {
3274 domRange.setEnd(domRange.startContainer, domRange.startOffset + 1); 5212 domRange.setStart(element, 0);
5213 domRange.setEnd(element, 0);
5214 } else {
5215 domRange.setStart(element.parentNode, dom.nodeIndex(element));
5216 domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
5217 }
3275 5218
3276 return domRange; 5219 return domRange;
3277 } 5220 }
3278
3279 collapsed = selection.isCollapsed();
3280 5221
3281 function findEndPoint(start) { 5222 function findEndPoint(start) {
3282 var marker, container, offset, nodes, startIndex = 0, endIndex, index, parent, checkRng, position; 5223 var marker, container, offset, nodes, startIndex = 0, endIndex, index, parent, checkRng, position;
3283 5224
3284 // Setup temp range and collapse it 5225 // Setup temp range and collapse it
3379 marker = dom.create('a'); 5320 marker = dom.create('a');
3380 container = start ? startContainer : endContainer; 5321 container = start ? startContainer : endContainer;
3381 offset = start ? startOffset : endOffset; 5322 offset = start ? startOffset : endOffset;
3382 tmpRng = ieRng.duplicate(); 5323 tmpRng = ieRng.duplicate();
3383 5324
3384 if (container == doc) { 5325 if (container == doc || container == doc.documentElement) {
3385 container = body; 5326 container = body;
3386 offset = 0; 5327 offset = 0;
3387 } 5328 }
3388 5329
3389 if (container.nodeType == 3) { 5330 if (container.nodeType == 3) {
3431 if (startOffset == endOffset - 1) { 5372 if (startOffset == endOffset - 1) {
3432 try { 5373 try {
3433 ctrlRng = body.createControlRange(); 5374 ctrlRng = body.createControlRange();
3434 ctrlRng.addElement(startContainer.childNodes[startOffset]); 5375 ctrlRng.addElement(startContainer.childNodes[startOffset]);
3435 ctrlRng.select(); 5376 ctrlRng.select();
3436 ctrlRng.scrollIntoView();
3437 return; 5377 return;
3438 } catch (ex) { 5378 } catch (ex) {
3439 // Ignore 5379 // Ignore
3440 } 5380 }
3441 } 5381 }
3445 setEndPoint(true); 5385 setEndPoint(true);
3446 setEndPoint(); 5386 setEndPoint();
3447 5387
3448 // Select the new range and scroll it into view 5388 // Select the new range and scroll it into view
3449 ieRng.select(); 5389 ieRng.select();
3450 ieRng.scrollIntoView();
3451 }; 5390 };
3452 5391
3453 this.getRangeAt = function() { 5392 this.getRangeAt = function() {
3454 // Setup new range if the cache is empty 5393 // Setup new range if the cache is empty
3455 if (!range || !tinymce.dom.RangeUtils.compareRanges(lastIERng, selection.getRng())) { 5394 if (!range || !tinymce.dom.RangeUtils.compareRanges(lastIERng, selection.getRng())) {
3475 5414
3476 this.destroy = function() { 5415 this.destroy = function() {
3477 // Destroy cached range and last IE range to avoid memory leaks 5416 // Destroy cached range and last IE range to avoid memory leaks
3478 lastIERng = range = null; 5417 lastIERng = range = null;
3479 }; 5418 };
3480
3481 // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode
3482 if (selection.dom.boxModel) {
3483 (function() {
3484 var doc = dom.doc, body = doc.body, started, startRng;
3485
3486 // Make HTML element unselectable since we are going to handle selection by hand
3487 doc.documentElement.unselectable = TRUE;
3488
3489 // Return range from point or null if it failed
3490 function rngFromPoint(x, y) {
3491 var rng = body.createTextRange();
3492
3493 try {
3494 rng.moveToPoint(x, y);
3495 } catch (ex) {
3496 // IE sometimes throws and exception, so lets just ignore it
3497 rng = null;
3498 }
3499
3500 return rng;
3501 };
3502
3503 // Fires while the selection is changing
3504 function selectionChange(e) {
3505 var pointRng;
3506
3507 // Check if the button is down or not
3508 if (e.button) {
3509 // Create range from mouse position
3510 pointRng = rngFromPoint(e.x, e.y);
3511
3512 if (pointRng) {
3513 // Check if pointRange is before/after selection then change the endPoint
3514 if (pointRng.compareEndPoints('StartToStart', startRng) > 0)
3515 pointRng.setEndPoint('StartToStart', startRng);
3516 else
3517 pointRng.setEndPoint('EndToEnd', startRng);
3518
3519 pointRng.select();
3520 }
3521 } else
3522 endSelection();
3523 }
3524
3525 // Removes listeners
3526 function endSelection() {
3527 dom.unbind(doc, 'mouseup', endSelection);
3528 dom.unbind(doc, 'mousemove', selectionChange);
3529 started = 0;
3530 };
3531
3532 // Detect when user selects outside BODY
3533 dom.bind(doc, 'mousedown', function(e) {
3534 if (e.target.nodeName === 'HTML') {
3535 if (started)
3536 endSelection();
3537
3538 started = 1;
3539
3540 // Setup start position
3541 startRng = rngFromPoint(e.x, e.y);
3542 if (startRng) {
3543 // Listen for selection change events
3544 dom.bind(doc, 'mouseup', endSelection);
3545 dom.bind(doc, 'mousemove', selectionChange);
3546
3547 startRng.select();
3548 }
3549 }
3550 });
3551 })();
3552 }
3553 }; 5419 };
3554 5420
3555 // Expose the selection object 5421 // Expose the selection object
3556 tinymce.dom.TridentSelection = Selection; 5422 tinymce.dom.TridentSelection = Selection;
3557 })(); 5423 })();
4889 t._pageInit(win); 6755 t._pageInit(win);
4890 }); 6756 });
4891 }, 6757 },
4892 6758
4893 _stoppers : { 6759 _stoppers : {
4894 preventDefault : function() { 6760 preventDefault : function() {
4895 this.returnValue = false; 6761 this.returnValue = false;
4896 }, 6762 },
4897 6763
4898 stopPropagation : function() { 6764 stopPropagation : function() {
4899 this.cancelBubble = true; 6765 this.cancelBubble = true;
5037 t.serializer = serializer; 6903 t.serializer = serializer;
5038 6904
5039 // Add events 6905 // Add events
5040 each([ 6906 each([
5041 'onBeforeSetContent', 6907 'onBeforeSetContent',
6908
5042 'onBeforeGetContent', 6909 'onBeforeGetContent',
6910
5043 'onSetContent', 6911 'onSetContent',
6912
5044 'onGetContent' 6913 'onGetContent'
5045 ], function(e) { 6914 ], function(e) {
5046 t[e] = new tinymce.util.Dispatcher(t); 6915 t[e] = new tinymce.util.Dispatcher(t);
5047 }); 6916 });
5048 6917
5049 // No W3C Range support 6918 // No W3C Range support
5050 if (!t.win.getSelection) 6919 if (!t.win.getSelection)
5051 t.tridentSel = new tinymce.dom.TridentSelection(t); 6920 t.tridentSel = new tinymce.dom.TridentSelection(t);
6921
6922 if (tinymce.isIE && dom.boxModel)
6923 this._fixIESelection();
5052 6924
5053 // Prevent leaks 6925 // Prevent leaks
5054 tinymce.addUnload(t.destroy, t); 6926 tinymce.addUnload(t.destroy, t);
5055 }, 6927 },
5056 6928
5089 t.onGetContent.dispatch(t, s); 6961 t.onGetContent.dispatch(t, s);
5090 6962
5091 return s.content; 6963 return s.content;
5092 }, 6964 },
5093 6965
5094 setContent : function(h, s) { 6966 setContent : function(content, args) {
5095 var t = this, r = t.getRng(), c, d = t.win.document; 6967 var self = this, rng = self.getRng(), caretNode, doc = self.win.document, frag, temp;
5096 6968
5097 s = s || {format : 'html'}; 6969 args = args || {format : 'html'};
5098 s.set = true; 6970 args.set = true;
5099 h = s.content = t.dom.processHTML(h); 6971 content = args.content = content;
5100 6972
5101 // Dispatch before set content event 6973 // Dispatch before set content event
5102 t.onBeforeSetContent.dispatch(t, s); 6974 if (!args.no_events)
5103 h = s.content; 6975 self.onBeforeSetContent.dispatch(self, args);
5104 6976
5105 if (r.insertNode) { 6977 content = args.content;
6978
6979 if (rng.insertNode) {
5106 // Make caret marker since insertNode places the caret in the beginning of text after insert 6980 // Make caret marker since insertNode places the caret in the beginning of text after insert
5107 h += '<span id="__caret">_</span>'; 6981 content += '<span id="__caret">_</span>';
5108 6982
5109 // Delete and insert new node 6983 // Delete and insert new node
5110 6984 if (rng.startContainer == doc && rng.endContainer == doc) {
5111 if (r.startContainer == d && r.endContainer == d) {
5112 // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents 6985 // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents
5113 d.body.innerHTML = h; 6986 doc.body.innerHTML = content;
5114 } else { 6987 } else {
5115 r.deleteContents(); 6988 rng.deleteContents();
5116 if (d.body.childNodes.length == 0) { 6989
5117 d.body.innerHTML = h; 6990 if (doc.body.childNodes.length == 0) {
6991 doc.body.innerHTML = content;
5118 } else { 6992 } else {
5119 r.insertNode(r.createContextualFragment(h)); 6993 // createContextualFragment doesn't exists in IE 9 DOMRanges
6994 if (rng.createContextualFragment) {
6995 rng.insertNode(rng.createContextualFragment(content));
6996 } else {
6997 // Fake createContextualFragment call in IE 9
6998 frag = doc.createDocumentFragment();
6999 temp = doc.createElement('div');
7000
7001 frag.appendChild(temp);
7002 temp.outerHTML = content;
7003
7004 rng.insertNode(frag);
7005 }
5120 } 7006 }
5121 } 7007 }
5122 7008
5123 // Move to caret marker 7009 // Move to caret marker
5124 c = t.dom.get('__caret'); 7010 caretNode = self.dom.get('__caret');
7011
5125 // Make sure we wrap it compleatly, Opera fails with a simple select call 7012 // Make sure we wrap it compleatly, Opera fails with a simple select call
5126 r = d.createRange(); 7013 rng = doc.createRange();
5127 r.setStartBefore(c); 7014 rng.setStartBefore(caretNode);
5128 r.setEndBefore(c); 7015 rng.setEndBefore(caretNode);
5129 t.setRng(r); 7016 self.setRng(rng);
5130 7017
5131 // Remove the caret position 7018 // Remove the caret position
5132 t.dom.remove('__caret'); 7019 self.dom.remove('__caret');
7020 self.setRng(rng);
5133 } else { 7021 } else {
5134 if (r.item) { 7022 if (rng.item) {
5135 // Delete content and get caret text selection 7023 // Delete content and get caret text selection
5136 d.execCommand('Delete', false, null); 7024 doc.execCommand('Delete', false, null);
5137 r = t.getRng(); 7025 rng = self.getRng();
5138 } 7026 }
5139 7027
5140 r.pasteHTML(h); 7028 rng.pasteHTML(content);
5141 } 7029 }
5142 7030
5143 // Dispatch set content event 7031 // Dispatch set content event
5144 t.onSetContent.dispatch(t, s); 7032 if (!args.no_events)
7033 self.onSetContent.dispatch(self, args);
5145 }, 7034 },
5146 7035
5147 getStart : function() { 7036 getStart : function() {
5148 var rng = this.getRng(), startElement, parentElement, checkRng, node; 7037 var rng = this.getRng(), startElement, parentElement, checkRng, node;
5149 7038
5165 startElement = parentElement; 7054 startElement = parentElement;
5166 break; 7055 break;
5167 } 7056 }
5168 } 7057 }
5169 7058
5170 // If start element is body element try to move to the first child if it exists
5171 if (startElement && startElement.nodeName == 'BODY')
5172 return startElement.firstChild || startElement;
5173
5174 return startElement; 7059 return startElement;
5175 } else { 7060 } else {
5176 startElement = rng.startContainer; 7061 startElement = rng.startContainer;
5177 7062
5178 if (startElement.nodeType == 1 && startElement.hasChildNodes()) 7063 if (startElement.nodeType == 1 && startElement.hasChildNodes())
5284 if (rng.duplicate || rng.item) { 7169 if (rng.duplicate || rng.item) {
5285 // Text selection 7170 // Text selection
5286 if (!rng.item) { 7171 if (!rng.item) {
5287 rng2 = rng.duplicate(); 7172 rng2 = rng.duplicate();
5288 7173
5289 // Insert start marker 7174 try {
5290 rng.collapse(); 7175 // Insert start marker
5291 rng.pasteHTML('<span _mce_type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>'); 7176 rng.collapse();
5292 7177 rng.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>');
5293 // Insert end marker 7178
5294 if (!collapsed) { 7179 // Insert end marker
5295 rng2.collapse(false); 7180 if (!collapsed) {
5296 rng2.pasteHTML('<span _mce_type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>'); 7181 rng2.collapse(false);
7182
7183 // Detect the empty space after block elements in IE and move the end back one character <p></p>] becomes <p>]</p>
7184 rng.moveToElementText(rng2.parentElement());
7185 if (rng.compareEndPoints('StartToEnd', rng2) == 0)
7186 rng2.move('character', -1);
7187
7188 rng2.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>');
7189 }
7190 } catch (ex) {
7191 // IE might throw unspecified error so lets ignore it
7192 return null;
5297 } 7193 }
5298 } else { 7194 } else {
5299 // Control selection 7195 // Control selection
5300 element = rng.item(0); 7196 element = rng.item(0);
5301 name = element.nodeName; 7197 name = element.nodeName;
5312 rng2 = rng.cloneRange(); 7208 rng2 = rng.cloneRange();
5313 7209
5314 // Insert end marker 7210 // Insert end marker
5315 if (!collapsed) { 7211 if (!collapsed) {
5316 rng2.collapse(false); 7212 rng2.collapse(false);
5317 rng2.insertNode(dom.create('span', {_mce_type : "bookmark", id : id + '_end', style : styles}, chr)); 7213 rng2.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_end', style : styles}, chr));
5318 } 7214 }
5319 7215
5320 rng.collapse(true); 7216 rng.collapse(true);
5321 rng.insertNode(dom.create('span', {_mce_type : "bookmark", id : id + '_start', style : styles}, chr)); 7217 rng.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_start', style : styles}, chr));
5322 } 7218 }
5323 7219
5324 t.moveToBookmark({id : id, keep : 1}); 7220 t.moveToBookmark({id : id, keep : 1});
5325 7221
5326 return {id : id}; 7222 return {id : id};
5340 7236
5341 function setEndPoint(start) { 7237 function setEndPoint(start) {
5342 var point = bookmark[start ? 'start' : 'end'], i, node, offset, children; 7238 var point = bookmark[start ? 'start' : 'end'], i, node, offset, children;
5343 7239
5344 if (point) { 7240 if (point) {
7241 offset = point[0];
7242
5345 // Find container node 7243 // Find container node
5346 for (node = root, i = point.length - 1; i >= 1; i--) { 7244 for (node = root, i = point.length - 1; i >= 1; i--) {
5347 children = node.childNodes; 7245 children = node.childNodes;
5348 7246
5349 if (children.length) 7247 if (point[i] > children.length - 1)
5350 node = children[point[i]]; 7248 return;
7249
7250 node = children[point[i]];
5351 } 7251 }
7252
7253 // Move text offset to best suitable location
7254 if (node.nodeType === 3)
7255 offset = Math.min(point[0], node.nodeValue.length);
7256
7257 // Move element offset to best suitable location
7258 if (node.nodeType === 1)
7259 offset = Math.min(point[0], node.childNodes.length);
5352 7260
5353 // Set offset within container node 7261 // Set offset within container node
5354 if (start) 7262 if (start)
5355 rng.setStart(node, point[0]); 7263 rng.setStart(node, offset);
5356 else 7264 else
5357 rng.setEnd(node, point[0]); 7265 rng.setEnd(node, offset);
5358 } 7266 }
7267
7268 return true;
5359 }; 7269 };
5360 7270
5361 setEndPoint(true); 7271 if (setEndPoint(true) && setEndPoint()) {
5362 setEndPoint(); 7272 t.setRng(rng);
5363 7273 }
5364 t.setRng(rng);
5365 } else if (bookmark.id) { 7274 } else if (bookmark.id) {
5366 function restoreEndPoint(suffix) { 7275 function restoreEndPoint(suffix) {
5367 var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep; 7276 var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep;
5368 7277
5369 if (marker) { 7278 if (marker) {
5404 // Remove marker but keep children if for example contents where inserted into the marker 7313 // Remove marker but keep children if for example contents where inserted into the marker
5405 // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature 7314 // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature
5406 while (marker = dom.get(bookmark.id + '_' + suffix)) 7315 while (marker = dom.get(bookmark.id + '_' + suffix))
5407 dom.remove(marker, 1); 7316 dom.remove(marker, 1);
5408 7317
5409 // If siblings are text nodes then merge them 7318 // If siblings are text nodes then merge them unless it's Opera since it some how removes the node
5410 if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3) { 7319 // and we are sniffing since adding a lot of detection code for a browser with 3% of the market isn't worth the effort. Sorry, Opera but it's just a fact
7320 if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) {
5411 idx = prev.nodeValue.length; 7321 idx = prev.nodeValue.length;
5412 prev.appendData(next.nodeValue); 7322 prev.appendData(next.nodeValue);
5413 dom.remove(next); 7323 dom.remove(next);
5414 7324
5415 if (suffix == 'start') { 7325 if (suffix == 'start') {
5423 } 7333 }
5424 } 7334 }
5425 }; 7335 };
5426 7336
5427 function addBogus(node) { 7337 function addBogus(node) {
5428 // Adds a bogus BR element for empty block elements 7338 // Adds a bogus BR element for empty block elements or just a space on IE since it renders BR elements incorrectly
5429 // on non IE browsers just to have a place to put the caret 7339 if (dom.isBlock(node) && !node.innerHTML)
5430 if (!isIE && dom.isBlock(node) && !node.innerHTML) 7340 node.innerHTML = !isIE ? '<br data-mce-bogus="1" />' : ' ';
5431 node.innerHTML = '<br _mce_bogus="1" />';
5432 7341
5433 return node; 7342 return node;
5434 }; 7343 };
5435 7344
5436 // Restore start/end points 7345 // Restore start/end points
5451 }, 7360 },
5452 7361
5453 select : function(node, content) { 7362 select : function(node, content) {
5454 var t = this, dom = t.dom, rng = dom.createRng(), idx; 7363 var t = this, dom = t.dom, rng = dom.createRng(), idx;
5455 7364
5456 idx = dom.nodeIndex(node); 7365 if (node) {
5457 rng.setStart(node.parentNode, idx); 7366 idx = dom.nodeIndex(node);
5458 rng.setEnd(node.parentNode, idx + 1); 7367 rng.setStart(node.parentNode, idx);
5459 7368 rng.setEnd(node.parentNode, idx + 1);
5460 // Find first/last text node or BR element 7369
5461 if (content) { 7370 // Find first/last text node or BR element
5462 function setPoint(node, start) { 7371 if (content) {
5463 var walker = new tinymce.dom.TreeWalker(node, node); 7372 function setPoint(node, start) {
5464 7373 var walker = new tinymce.dom.TreeWalker(node, node);
5465 do { 7374
5466 // Text node 7375 do {
5467 if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) { 7376 // Text node
5468 if (start) 7377 if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) {
5469 rng.setStart(node, 0); 7378 if (start)
5470 else 7379 rng.setStart(node, 0);
5471 rng.setEnd(node, node.nodeValue.length); 7380 else
5472 7381 rng.setEnd(node, node.nodeValue.length);
5473 return; 7382
5474 } 7383 return;
5475 7384 }
5476 // BR element 7385
5477 if (node.nodeName == 'BR') { 7386 // BR element
5478 if (start) 7387 if (node.nodeName == 'BR') {
5479 rng.setStartBefore(node); 7388 if (start)
5480 else 7389 rng.setStartBefore(node);
5481 rng.setEndBefore(node); 7390 else
5482 7391 rng.setEndBefore(node);
5483 return; 7392
5484 } 7393 return;
5485 } while (node = (start ? walker.next() : walker.prev())); 7394 }
5486 }; 7395 } while (node = (start ? walker.next() : walker.prev()));
5487 7396 };
5488 setPoint(node, 1); 7397
5489 setPoint(node); 7398 setPoint(node, 1);
5490 } 7399 setPoint(node);
5491 7400 }
5492 t.setRng(rng); 7401
7402 t.setRng(rng);
7403 }
5493 7404
5494 return node; 7405 return node;
5495 }, 7406 },
5496 7407
5497 isCollapsed : function() { 7408 isCollapsed : function() {
5504 return r.compareEndPoints('StartToEnd', r) === 0; 7415 return r.compareEndPoints('StartToEnd', r) === 0;
5505 7416
5506 return !s || r.collapsed; 7417 return !s || r.collapsed;
5507 }, 7418 },
5508 7419
5509 collapse : function(b) { 7420 collapse : function(to_start) {
5510 var t = this, r = t.getRng(), n; 7421 var self = this, rng = self.getRng(), node;
5511 7422
5512 // Control range on IE 7423 // Control range on IE
5513 if (r.item) { 7424 if (rng.item) {
5514 n = r.item(0); 7425 node = rng.item(0);
5515 r = this.win.document.body.createTextRange(); 7426 rng = self.win.document.body.createTextRange();
5516 r.moveToElementText(n); 7427 rng.moveToElementText(node);
5517 } 7428 }
5518 7429
5519 r.collapse(!!b); 7430 rng.collapse(!!to_start);
5520 t.setRng(r); 7431 self.setRng(rng);
5521 }, 7432 },
5522 7433
5523 getSel : function() { 7434 getSel : function() {
5524 var t = this, w = this.win; 7435 var t = this, w = this.win;
5525 7436
5526 return w.getSelection ? w.getSelection() : w.document.selection; 7437 return w.getSelection ? w.getSelection() : w.document.selection;
5527 }, 7438 },
5528 7439
5529 getRng : function(w3c) { 7440 getRng : function(w3c) {
5530 var t = this, s, r; 7441 var t = this, s, r, elm, doc = t.win.document;
5531 7442
5532 // Found tridentSel object then we need to use that one 7443 // Found tridentSel object then we need to use that one
5533 if (w3c && t.tridentSel) 7444 if (w3c && t.tridentSel)
5534 return t.tridentSel.getRangeAt(0); 7445 return t.tridentSel.getRangeAt(0);
5535 7446
5536 try { 7447 try {
5537 if (s = t.getSel()) 7448 if (s = t.getSel())
5538 r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : t.win.document.createRange()); 7449 r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : doc.createRange());
5539 } catch (ex) { 7450 } catch (ex) {
5540 // IE throws unspecified error here if TinyMCE is placed in a frame/iframe 7451 // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
7452 }
7453
7454 // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
7455 if (tinymce.isIE && r && r.setStart && doc.selection.createRange().item) {
7456 elm = doc.selection.createRange().item(0);
7457 r = doc.createRange();
7458 r.setStartBefore(elm);
7459 r.setEndAfter(elm);
5541 } 7460 }
5542 7461
5543 // No range found then create an empty one 7462 // No range found then create an empty one
5544 // This can occur when the editor is placed in a hidden container element on Gecko 7463 // This can occur when the editor is placed in a hidden container element on Gecko
5545 // Or on IE when there was an exception 7464 // Or on IE when there was an exception
5546 if (!r) 7465 if (!r)
5547 r = t.win.document.createRange ? t.win.document.createRange() : t.win.document.body.createTextRange(); 7466 r = doc.createRange ? doc.createRange() : doc.body.createTextRange();
5548 7467
5549 if (t.selectedRange && t.explicitRange) { 7468 if (t.selectedRange && t.explicitRange) {
5550 if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) { 7469 if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) {
5551 // Safari, Opera and Chrome only ever select text which causes the range to change. 7470 // Safari, Opera and Chrome only ever select text which causes the range to change.
5552 // This lets us use the originally set range if the selection hasn't been changed by the user. 7471 // This lets us use the originally set range if the selection hasn't been changed by the user.
5554 } else { 7473 } else {
5555 t.selectedRange = null; 7474 t.selectedRange = null;
5556 t.explicitRange = null; 7475 t.explicitRange = null;
5557 } 7476 }
5558 } 7477 }
7478
5559 return r; 7479 return r;
5560 }, 7480 },
5561 7481
5562 setRng : function(r) { 7482 setRng : function(r) {
5563 var s, t = this; 7483 var s, t = this;
5565 if (!t.tridentSel) { 7485 if (!t.tridentSel) {
5566 s = t.getSel(); 7486 s = t.getSel();
5567 7487
5568 if (s) { 7488 if (s) {
5569 t.explicitRange = r; 7489 t.explicitRange = r;
5570 s.removeAllRanges(); 7490
7491 try {
7492 s.removeAllRanges();
7493 } catch (ex) {
7494 // IE9 might throw errors here don't know why
7495 }
7496
5571 s.addRange(r); 7497 s.addRange(r);
5572 t.selectedRange = s.getRangeAt(0); 7498 t.selectedRange = s.getRangeAt(0);
5573 } 7499 }
5574 } else { 7500 } else {
5575 // Is W3C Range 7501 // Is W3C Range
5594 7520
5595 return n; 7521 return n;
5596 }, 7522 },
5597 7523
5598 getNode : function() { 7524 getNode : function() {
5599 var t = this, rng = t.getRng(), sel = t.getSel(), elm; 7525 var t = this, rng = t.getRng(), sel = t.getSel(), elm, start = rng.startContainer, end = rng.endContainer;
7526
7527 // Range maybe lost after the editor is made visible again
7528 if (!rng)
7529 return t.dom.getRoot();
5600 7530
5601 if (rng.setStart) { 7531 if (rng.setStart) {
5602 // Range maybe lost after the editor is made visible again
5603 if (!rng)
5604 return t.dom.getRoot();
5605
5606 elm = rng.commonAncestorContainer; 7532 elm = rng.commonAncestorContainer;
5607 7533
5608 // Handle selection a image or other control like element such as anchors 7534 // Handle selection a image or other control like element such as anchors
5609 if (!rng.collapsed) { 7535 if (!rng.collapsed) {
5610 if (rng.startContainer == rng.endContainer) { 7536 if (rng.startContainer == rng.endContainer) {
5611 if (rng.startOffset - rng.endOffset < 2) { 7537 if (rng.endOffset - rng.startOffset < 2) {
5612 if (rng.startContainer.hasChildNodes()) 7538 if (rng.startContainer.hasChildNodes())
5613 elm = rng.startContainer.childNodes[rng.startOffset]; 7539 elm = rng.startContainer.childNodes[rng.startOffset];
5614 } 7540 }
5615 } 7541 }
5616 7542
5617 // If the anchor node is a element instead of a text node then return this element 7543 // If the anchor node is a element instead of a text node then return this element
5618 if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1) 7544 //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
5619 return sel.anchorNode.childNodes[sel.anchorOffset]; 7545 // return sel.anchorNode.childNodes[sel.anchorOffset];
7546
7547 // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent.
7548 // This happens when you double click an underlined word in FireFox.
7549 if (start.nodeType === 3 && end.nodeType === 3) {
7550 function skipEmptyTextNodes(n, forwards) {
7551 var orig = n;
7552 while (n && n.nodeType === 3 && n.length === 0) {
7553 n = forwards ? n.nextSibling : n.previousSibling;
7554 }
7555 return n || orig;
7556 }
7557 if (start.length === rng.startOffset) {
7558 start = skipEmptyTextNodes(start.nextSibling, true);
7559 } else {
7560 start = start.parentNode;
7561 }
7562 if (rng.endOffset === 0) {
7563 end = skipEmptyTextNodes(end.previousSibling, false);
7564 } else {
7565 end = end.parentNode;
7566 }
7567
7568 if (start && start === end)
7569 return start;
7570 }
5620 } 7571 }
5621 7572
5622 if (elm && elm.nodeType == 3) 7573 if (elm && elm.nodeType == 3)
5623 return elm.parentNode; 7574 return elm.parentNode;
5624 7575
5661 t.tridentSel.destroy(); 7612 t.tridentSel.destroy();
5662 7613
5663 // Manual destroy then remove unload handler 7614 // Manual destroy then remove unload handler
5664 if (!s) 7615 if (!s)
5665 tinymce.removeUnload(t.destroy); 7616 tinymce.removeUnload(t.destroy);
7617 },
7618
7619 // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode
7620 _fixIESelection : function() {
7621 var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng, htmlElm;
7622
7623 // Make HTML element unselectable since we are going to handle selection by hand
7624 doc.documentElement.unselectable = true;
7625
7626 // Return range from point or null if it failed
7627 function rngFromPoint(x, y) {
7628 var rng = body.createTextRange();
7629
7630 try {
7631 rng.moveToPoint(x, y);
7632 } catch (ex) {
7633 // IE sometimes throws and exception, so lets just ignore it
7634 rng = null;
7635 }
7636
7637 return rng;
7638 };
7639
7640 // Fires while the selection is changing
7641 function selectionChange(e) {
7642 var pointRng;
7643
7644 // Check if the button is down or not
7645 if (e.button) {
7646 // Create range from mouse position
7647 pointRng = rngFromPoint(e.x, e.y);
7648
7649 if (pointRng) {
7650 // Check if pointRange is before/after selection then change the endPoint
7651 if (pointRng.compareEndPoints('StartToStart', startRng) > 0)
7652 pointRng.setEndPoint('StartToStart', startRng);
7653 else
7654 pointRng.setEndPoint('EndToEnd', startRng);
7655
7656 pointRng.select();
7657 }
7658 } else
7659 endSelection();
7660 }
7661
7662 // Removes listeners
7663 function endSelection() {
7664 var rng = doc.selection.createRange();
7665
7666 // If the range is collapsed then use the last start range
7667 if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0)
7668 startRng.select();
7669
7670 dom.unbind(doc, 'mouseup', endSelection);
7671 dom.unbind(doc, 'mousemove', selectionChange);
7672 startRng = started = 0;
7673 };
7674
7675 // Detect when user selects outside BODY
7676 dom.bind(doc, ['mousedown', 'contextmenu'], function(e) {
7677 if (e.target.nodeName === 'HTML') {
7678 if (started)
7679 endSelection();
7680
7681 // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML
7682 htmlElm = doc.documentElement;
7683 if (htmlElm.scrollHeight > htmlElm.clientHeight)
7684 return;
7685
7686 started = 1;
7687 // Setup start position
7688 startRng = rngFromPoint(e.x, e.y);
7689 if (startRng) {
7690 // Listen for selection change events
7691 dom.bind(doc, 'mouseup', endSelection);
7692 dom.bind(doc, 'mousemove', selectionChange);
7693
7694 dom.win.focus();
7695 startRng.select();
7696 }
7697 }
7698 });
5666 } 7699 }
5667 }); 7700 });
5668 })(tinymce); 7701 })(tinymce);
5669 7702
5670 (function(tinymce) { 7703 (function(tinymce) {
5671 tinymce.create('tinymce.dom.XMLWriter', { 7704 tinymce.dom.Serializer = function(settings, dom, schema) {
5672 node : null, 7705 var onPreProcess, onPostProcess, isIE = tinymce.isIE, each = tinymce.each, htmlParser;
5673 7706
5674 XMLWriter : function(s) { 7707 // Support the old apply_source_formatting option
5675 // Get XML document 7708 if (!settings.apply_source_formatting)
5676 function getXML() { 7709 settings.indent = false;
5677 var i = document.implementation; 7710
5678 7711 settings.remove_trailing_brs = true;
5679 if (!i || !i.createDocument) { 7712
5680 // Try IE objects 7713 // Default DOM and Schema if they are undefined
5681 try {return new ActiveXObject('MSXML2.DOMDocument');} catch (ex) {} 7714 dom = dom || tinymce.DOM;
5682 try {return new ActiveXObject('Microsoft.XmlDom');} catch (ex) {} 7715 schema = schema || new tinymce.html.Schema(settings);
5683 } else 7716 settings.entity_encoding = settings.entity_encoding || 'named';
5684 return i.createDocument('', '', null); 7717
7718 onPreProcess = new tinymce.util.Dispatcher(self);
7719
7720 onPostProcess = new tinymce.util.Dispatcher(self);
7721
7722 htmlParser = new tinymce.html.DomParser(settings, schema);
7723
7724 // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed
7725 htmlParser.addAttributeFilter('src,href,style', function(nodes, name) {
7726 var i = nodes.length, node, value, internalName = 'data-mce-' + name, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef;
7727
7728 while (i--) {
7729 node = nodes[i];
7730
7731 value = node.attributes.map[internalName];
7732 if (value !== undef) {
7733 // Set external name to internal value and remove internal
7734 node.attr(name, value.length > 0 ? value : null);
7735 node.attr(internalName, null);
7736 } else {
7737 // No internal attribute found then convert the value we have in the DOM
7738 value = node.attributes.map[name];
7739
7740 if (name === "style")
7741 value = dom.serializeStyle(dom.parseStyle(value), node.name);
7742 else if (urlConverter)
7743 value = urlConverter.call(urlConverterScope, value, name, node.name);
7744
7745 node.attr(name, value.length > 0 ? value : null);
7746 }
7747 }
7748 });
7749
7750 // Remove internal classes mceItem<..>
7751 htmlParser.addAttributeFilter('class', function(nodes, name) {
7752 var i = nodes.length, node, value;
7753
7754 while (i--) {
7755 node = nodes[i];
7756 value = node.attr('class').replace(/\s*mce(Item\w+|Selected)\s*/g, '');
7757 node.attr('class', value.length > 0 ? value : null);
7758 }
7759 });
7760
7761 // Remove bookmark elements
7762 htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) {
7763 var i = nodes.length, node;
7764
7765 while (i--) {
7766 node = nodes[i];
7767
7768 if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup)
7769 node.remove();
7770 }
7771 });
7772
7773 // Force script into CDATA sections and remove the mce- prefix also add comments around styles
7774 htmlParser.addNodeFilter('script,style', function(nodes, name) {
7775 var i = nodes.length, node, value;
7776
7777 function trim(value) {
7778 return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
7779 .replace(/^[\r\n]*|[\r\n]*$/g, '')
7780 .replace(/^\s*(\/\/\s*<!--|\/\/\s*<!\[CDATA\[|<!--|<!\[CDATA\[)[\r\n]*/g, '')
7781 .replace(/\s*(\/\/\s*\]\]>|\/\/\s*-->|\]\]>|-->|\]\]-->)\s*$/g, '');
5685 }; 7782 };
5686 7783
5687 this.doc = getXML(); 7784 while (i--) {
5688 7785 node = nodes[i];
5689 // Since Opera and WebKit doesn't escape > into &gt; we need to do it our self to normalize the output for all browsers 7786 value = node.firstChild ? node.firstChild.value : '';
5690 this.valid = tinymce.isOpera || tinymce.isWebKit; 7787
5691 7788 if (name === "script") {
5692 this.reset(); 7789 // Remove mce- prefix from script elements
5693 }, 7790 node.attr('type', (node.attr('type') || 'text/javascript').replace(/^mce\-/, ''));
5694 7791
5695 reset : function() { 7792 if (value.length > 0)
5696 var t = this, d = t.doc; 7793 node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
5697 7794 } else {
5698 if (d.firstChild) 7795 if (value.length > 0)
5699 d.removeChild(d.firstChild); 7796 node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
5700 7797 }
5701 t.node = d.appendChild(d.createElement("html")); 7798 }
5702 }, 7799 });
5703 7800
5704 writeStartElement : function(n) { 7801 // Convert comments to cdata and handle protected comments
5705 var t = this; 7802 htmlParser.addNodeFilter('#comment', function(nodes, name) {
5706 7803 var i = nodes.length, node;
5707 t.node = t.node.appendChild(t.doc.createElement(n)); 7804
5708 }, 7805 while (i--) {
5709 7806 node = nodes[i];
5710 writeAttribute : function(n, v) { 7807
5711 if (this.valid) 7808 if (node.value.indexOf('[CDATA[') === 0) {
5712 v = v.replace(/>/g, '%MCGT%'); 7809 node.name = '#cdata';
5713 7810 node.type = 4;
5714 this.node.setAttribute(n, v); 7811 node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
5715 }, 7812 } else if (node.value.indexOf('mce:protected ') === 0) {
5716 7813 node.name = "#text";
5717 writeEndElement : function() { 7814 node.type = 3;
5718 this.node = this.node.parentNode; 7815 node.raw = true;
5719 }, 7816 node.value = unescape(node.value).substr(14);
5720 7817 }
5721 writeFullEndElement : function() { 7818 }
5722 var t = this, n = t.node; 7819 });
5723 7820
5724 n.appendChild(t.doc.createTextNode("")); 7821 htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) {
5725 t.node = n.parentNode; 7822 var i = nodes.length, node;
5726 }, 7823
5727 7824 while (i--) {
5728 writeText : function(v) { 7825 node = nodes[i];
5729 if (this.valid) 7826 if (node.type === 7)
5730 v = v.replace(/>/g, '%MCGT%'); 7827 node.remove();
5731 7828 else if (node.type === 1) {
5732 this.node.appendChild(this.doc.createTextNode(v)); 7829 if (name === "input" && !("type" in node.attributes.map))
5733 }, 7830 node.attr('type', 'text');
5734 7831 }
5735 writeCDATA : function(v) { 7832 }
5736 this.node.appendChild(this.doc.createCDATASection(v)); 7833 });
5737 }, 7834
5738 7835 // Fix list elements, TODO: Replace this later
5739 writeComment : function(v) { 7836 if (settings.fix_list_elements) {
5740 // Fix for bug #2035694 7837 htmlParser.addNodeFilter('ul,ol', function(nodes, name) {
5741 if (tinymce.isIE) 7838 var i = nodes.length, node, parentNode;
5742 v = v.replace(/^\-|\-$/g, ' '); 7839
5743 7840 while (i--) {
5744 this.node.appendChild(this.doc.createComment(v.replace(/\-\-/g, ' '))); 7841 node = nodes[i];
5745 }, 7842 parentNode = node.parent;
5746 7843
5747 getContent : function() { 7844 if (parentNode.name === 'ul' || parentNode.name === 'ol') {
5748 var h; 7845 if (node.prev && node.prev.name === 'li') {
5749 7846 node.prev.append(node);
5750 h = this.doc.xml || new XMLSerializer().serializeToString(this.doc);
5751 h = h.replace(/<\?[^?]+\?>|<html>|<\/html>|<html\/>|<!DOCTYPE[^>]+>/g, '');
5752 h = h.replace(/ ?\/>/g, ' />');
5753
5754 if (this.valid)
5755 h = h.replace(/\%MCGT%/g, '&gt;');
5756
5757 return h;
5758 }
5759 });
5760 })(tinymce);
5761
5762 (function(tinymce) {
5763 tinymce.create('tinymce.dom.StringWriter', {
5764 str : null,
5765 tags : null,
5766 count : 0,
5767 settings : null,
5768 indent : null,
5769
5770 StringWriter : function(s) {
5771 this.settings = tinymce.extend({
5772 indent_char : ' ',
5773 indentation : 0
5774 }, s);
5775
5776 this.reset();
5777 },
5778
5779 reset : function() {
5780 this.indent = '';
5781 this.str = "";
5782 this.tags = [];
5783 this.count = 0;
5784 },
5785
5786 writeStartElement : function(n) {
5787 this._writeAttributesEnd();
5788 this.writeRaw('<' + n);
5789 this.tags.push(n);
5790 this.inAttr = true;
5791 this.count++;
5792 this.elementCount = this.count;
5793 },
5794
5795 writeAttribute : function(n, v) {
5796 var t = this;
5797
5798 t.writeRaw(" " + t.encode(n) + '="' + t.encode(v) + '"');
5799 },
5800
5801 writeEndElement : function() {
5802 var n;
5803
5804 if (this.tags.length > 0) {
5805 n = this.tags.pop();
5806
5807 if (this._writeAttributesEnd(1))
5808 this.writeRaw('</' + n + '>');
5809
5810 if (this.settings.indentation > 0)
5811 this.writeRaw('\n');
5812 }
5813 },
5814
5815 writeFullEndElement : function() {
5816 if (this.tags.length > 0) {
5817 this._writeAttributesEnd();
5818 this.writeRaw('</' + this.tags.pop() + '>');
5819
5820 if (this.settings.indentation > 0)
5821 this.writeRaw('\n');
5822 }
5823 },
5824
5825 writeText : function(v) {
5826 this._writeAttributesEnd();
5827 this.writeRaw(this.encode(v));
5828 this.count++;
5829 },
5830
5831 writeCDATA : function(v) {
5832 this._writeAttributesEnd();
5833 this.writeRaw('<![CDATA[' + v + ']]>');
5834 this.count++;
5835 },
5836
5837 writeComment : function(v) {
5838 this._writeAttributesEnd();
5839 this.writeRaw('<!-- ' + v + '-->');
5840 this.count++;
5841 },
5842
5843 writeRaw : function(v) {
5844 this.str += v;
5845 },
5846
5847 encode : function(s) {
5848 return s.replace(/[<>&"]/g, function(v) {
5849 switch (v) {
5850 case '<':
5851 return '&lt;';
5852
5853 case '>':
5854 return '&gt;';
5855
5856 case '&':
5857 return '&amp;';
5858
5859 case '"':
5860 return '&quot;';
5861 }
5862
5863 return v;
5864 });
5865 },
5866
5867 getContent : function() {
5868 return this.str;
5869 },
5870
5871 _writeAttributesEnd : function(s) {
5872 if (!this.inAttr)
5873 return;
5874
5875 this.inAttr = false;
5876
5877 if (s && this.elementCount == this.count) {
5878 this.writeRaw(' />');
5879 return false;
5880 }
5881
5882 this.writeRaw('>');
5883
5884 return true;
5885 }
5886 });
5887 })(tinymce);
5888
5889 (function(tinymce) {
5890 // Shorten names
5891 var extend = tinymce.extend, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, isIE = tinymce.isIE, isGecko = tinymce.isGecko;
5892
5893 function wildcardToRE(s) {
5894 return s.replace(/([?+*])/g, '.$1');
5895 };
5896
5897 tinymce.create('tinymce.dom.Serializer', {
5898 Serializer : function(s) {
5899 var t = this;
5900
5901 t.key = 0;
5902 t.onPreProcess = new Dispatcher(t);
5903 t.onPostProcess = new Dispatcher(t);
5904
5905 try {
5906 t.writer = new tinymce.dom.XMLWriter();
5907 } catch (ex) {
5908 // IE might throw exception if ActiveX is disabled so we then switch to the slightly slower StringWriter
5909 t.writer = new tinymce.dom.StringWriter();
5910 }
5911
5912 // Default settings
5913 t.settings = s = extend({
5914 dom : tinymce.DOM,
5915 valid_nodes : 0,
5916 node_filter : 0,
5917 attr_filter : 0,
5918 invalid_attrs : /^(_mce_|_moz_|sizset|sizcache)/,
5919 closed : /^(br|hr|input|meta|img|link|param|area)$/,
5920 entity_encoding : 'named',
5921 entities : '160,nbsp,161,iexcl,162,cent,163,pound,164,curren,165,yen,166,brvbar,167,sect,168,uml,169,copy,170,ordf,171,laquo,172,not,173,shy,174,reg,175,macr,176,deg,177,plusmn,178,sup2,179,sup3,180,acute,181,micro,182,para,183,middot,184,cedil,185,sup1,186,ordm,187,raquo,188,frac14,189,frac12,190,frac34,191,iquest,192,Agrave,193,Aacute,194,Acirc,195,Atilde,196,Auml,197,Aring,198,AElig,199,Ccedil,200,Egrave,201,Eacute,202,Ecirc,203,Euml,204,Igrave,205,Iacute,206,Icirc,207,Iuml,208,ETH,209,Ntilde,210,Ograve,211,Oacute,212,Ocirc,213,Otilde,214,Ouml,215,times,216,Oslash,217,Ugrave,218,Uacute,219,Ucirc,220,Uuml,221,Yacute,222,THORN,223,szlig,224,agrave,225,aacute,226,acirc,227,atilde,228,auml,229,aring,230,aelig,231,ccedil,232,egrave,233,eacute,234,ecirc,235,euml,236,igrave,237,iacute,238,icirc,239,iuml,240,eth,241,ntilde,242,ograve,243,oacute,244,ocirc,245,otilde,246,ouml,247,divide,248,oslash,249,ugrave,250,uacute,251,ucirc,252,uuml,253,yacute,254,thorn,255,yuml,402,fnof,913,Alpha,914,Beta,915,Gamma,916,Delta,917,Epsilon,918,Zeta,919,Eta,920,Theta,921,Iota,922,Kappa,923,Lambda,924,Mu,925,Nu,926,Xi,927,Omicron,928,Pi,929,Rho,931,Sigma,932,Tau,933,Upsilon,934,Phi,935,Chi,936,Psi,937,Omega,945,alpha,946,beta,947,gamma,948,delta,949,epsilon,950,zeta,951,eta,952,theta,953,iota,954,kappa,955,lambda,956,mu,957,nu,958,xi,959,omicron,960,pi,961,rho,962,sigmaf,963,sigma,964,tau,965,upsilon,966,phi,967,chi,968,psi,969,omega,977,thetasym,978,upsih,982,piv,8226,bull,8230,hellip,8242,prime,8243,Prime,8254,oline,8260,frasl,8472,weierp,8465,image,8476,real,8482,trade,8501,alefsym,8592,larr,8593,uarr,8594,rarr,8595,darr,8596,harr,8629,crarr,8656,lArr,8657,uArr,8658,rArr,8659,dArr,8660,hArr,8704,forall,8706,part,8707,exist,8709,empty,8711,nabla,8712,isin,8713,notin,8715,ni,8719,prod,8721,sum,8722,minus,8727,lowast,8730,radic,8733,prop,8734,infin,8736,ang,8743,and,8744,or,8745,cap,8746,cup,8747,int,8756,there4,8764,sim,8773,cong,8776,asymp,8800,ne,8801,equiv,8804,le,8805,ge,8834,sub,8835,sup,8836,nsub,8838,sube,8839,supe,8853,oplus,8855,otimes,8869,perp,8901,sdot,8968,lceil,8969,rceil,8970,lfloor,8971,rfloor,9001,lang,9002,rang,9674,loz,9824,spades,9827,clubs,9829,hearts,9830,diams,338,OElig,339,oelig,352,Scaron,353,scaron,376,Yuml,710,circ,732,tilde,8194,ensp,8195,emsp,8201,thinsp,8204,zwnj,8205,zwj,8206,lrm,8207,rlm,8211,ndash,8212,mdash,8216,lsquo,8217,rsquo,8218,sbquo,8220,ldquo,8221,rdquo,8222,bdquo,8224,dagger,8225,Dagger,8240,permil,8249,lsaquo,8250,rsaquo,8364,euro',
5922 valid_elements : '*[*]',
5923 extended_valid_elements : 0,
5924 invalid_elements : 0,
5925 fix_table_elements : 1,
5926 fix_list_elements : true,
5927 fix_content_duplication : true,
5928 convert_fonts_to_spans : false,
5929 font_size_classes : 0,
5930 apply_source_formatting : 0,
5931 indent_mode : 'simple',
5932 indent_char : '\t',
5933 indent_levels : 1,
5934 remove_linebreaks : 1,
5935 remove_redundant_brs : 1,
5936 element_format : 'xhtml'
5937 }, s);
5938
5939 t.dom = s.dom;
5940 t.schema = s.schema;
5941
5942 // Use raw entities if no entities are defined
5943 if (s.entity_encoding == 'named' && !s.entities)
5944 s.entity_encoding = 'raw';
5945
5946 if (s.remove_redundant_brs) {
5947 t.onPostProcess.add(function(se, o) {
5948 // Remove single BR at end of block elements since they get rendered
5949 o.content = o.content.replace(/(<br \/>\s*)+<\/(p|h[1-6]|div|li)>/gi, function(a, b, c) {
5950 // Check if it's a single element
5951 if (/^<br \/>\s*<\//.test(a))
5952 return '</' + c + '>';
5953
5954 return a;
5955 });
5956 });
5957 }
5958
5959 // Remove XHTML element endings i.e. produce crap :) XHTML is better
5960 if (s.element_format == 'html') {
5961 t.onPostProcess.add(function(se, o) {
5962 o.content = o.content.replace(/<([^>]+) \/>/g, '<$1>');
5963 });
5964 }
5965
5966 if (s.fix_list_elements) {
5967 t.onPreProcess.add(function(se, o) {
5968 var nl, x, a = ['ol', 'ul'], i, n, p, r = /^(OL|UL)$/, np;
5969
5970 function prevNode(e, n) {
5971 var a = n.split(','), i;
5972
5973 while ((e = e.previousSibling) != null) {
5974 for (i=0; i<a.length; i++) {
5975 if (e.nodeName == a[i])
5976 return e;
5977 }
5978 }
5979
5980 return null;
5981 };
5982
5983 for (x=0; x<a.length; x++) {
5984 nl = t.dom.select(a[x], o.node);
5985
5986 for (i=0; i<nl.length; i++) {
5987 n = nl[i];
5988 p = n.parentNode;
5989
5990 if (r.test(p.nodeName)) {
5991 np = prevNode(n, 'LI');
5992
5993 if (!np) {
5994 np = t.dom.create('li');
5995 np.innerHTML = '&nbsp;';
5996 np.appendChild(n);
5997 p.insertBefore(np, p.firstChild);
5998 } else
5999 np.appendChild(n);
6000 }
6001 } 7847 }
6002 } 7848 }
6003 }); 7849 }
6004 } 7850 });
6005 7851 }
6006 if (s.fix_table_elements) { 7852
6007 t.onPreProcess.add(function(se, o) { 7853 // Remove internal data attributes
6008 // Since Opera will crash if you attach the node to a dynamic document we need to brrowser sniff a specific build 7854 htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style', function(nodes, name) {
6009 // so Opera users with an older version will have to live with less compaible output not much we can do here 7855 var i = nodes.length;
6010 if (!tinymce.isOpera || opera.buildNumber() >= 1767) { 7856
6011 each(t.dom.select('p table', o.node).reverse(), function(n) { 7857 while (i--) {
6012 var parent = t.dom.getParent(n.parentNode, 'table,p'); 7858 nodes[i].attr(name, null);
6013 7859 }
6014 if (parent.nodeName != 'TABLE') { 7860 });
6015 try { 7861
6016 t.dom.split(parent, n); 7862 // Return public methods
6017 } catch (ex) { 7863 return {
6018 // IE can sometimes fire an unknown runtime error so we just ignore it 7864 schema : schema,
6019 } 7865
6020 } 7866 addNodeFilter : htmlParser.addNodeFilter,
6021 }); 7867
6022 } 7868 addAttributeFilter : htmlParser.addAttributeFilter,
6023 }); 7869
6024 } 7870 onPreProcess : onPreProcess,
6025 }, 7871
6026 7872 onPostProcess : onPostProcess,
6027 setEntities : function(s) { 7873
6028 var t = this, a, i, l = {}, v; 7874 serialize : function(node, args) {
6029 7875 var impl, doc, oldDoc, htmlSerializer, content;
6030 // No need to setup more than once 7876
6031 if (t.entityLookup) 7877 // Explorer won't clone contents of script and style and the
6032 return; 7878 // selected index of select elements are cleared on a clone operation.
6033 7879 if (isIE && dom.select('script,style,select').length > 0) {
6034 // Build regex and lookup array 7880 content = node.innerHTML;
6035 a = s.split(','); 7881 node = node.cloneNode(false);
6036 for (i = 0; i < a.length; i += 2) { 7882 dom.setHTML(node, content);
6037 v = a[i]; 7883 } else
6038 7884 node = node.cloneNode(true);
6039 // Don't add default &amp; &quot; etc. 7885
6040 if (v == 34 || v == 38 || v == 60 || v == 62) 7886 // Nodes needs to be attached to something in WebKit/Opera
6041 continue; 7887 // Older builds of Opera crashes if you attach the node to an document created dynamically
6042 7888 // and since we can't feature detect a crash we need to sniff the acutal build number
6043 l[String.fromCharCode(a[i])] = a[i + 1]; 7889 // This fix will make DOM ranges and make Sizzle happy!
6044 7890 impl = node.ownerDocument.implementation;
6045 v = parseInt(a[i]).toString(16); 7891 if (impl.createHTMLDocument) {
6046 } 7892 // Create an empty HTML document
6047 7893 doc = impl.createHTMLDocument("");
6048 t.entityLookup = l; 7894
6049 }, 7895 // Add the element or it's children if it's a body element to the new document
6050 7896 each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) {
6051 setRules : function(s) { 7897 doc.body.appendChild(doc.importNode(node, true));
6052 var t = this;
6053
6054 t._setup();
6055 t.rules = {};
6056 t.wildRules = [];
6057 t.validElements = {};
6058
6059 return t.addRules(s);
6060 },
6061
6062 addRules : function(s) {
6063 var t = this, dr;
6064
6065 if (!s)
6066 return;
6067
6068 t._setup();
6069
6070 each(s.split(','), function(s) {
6071 var p = s.split(/\[|\]/), tn = p[0].split('/'), ra, at, wat, va = [];
6072
6073 // Extend with default rules
6074 if (dr)
6075 at = tinymce.extend([], dr.attribs);
6076
6077 // Parse attributes
6078 if (p.length > 1) {
6079 each(p[1].split('|'), function(s) {
6080 var ar = {}, i;
6081
6082 at = at || [];
6083
6084 // Parse attribute rule
6085 s = s.replace(/::/g, '~');
6086 s = /^([!\-])?([\w*.?~_\-]+|)([=:<])?(.+)?$/.exec(s);
6087 s[2] = s[2].replace(/~/g, ':');
6088
6089 // Add required attributes
6090 if (s[1] == '!') {
6091 ra = ra || [];
6092 ra.push(s[2]);
6093 }
6094
6095 // Remove inherited attributes
6096 if (s[1] == '-') {
6097 for (i = 0; i <at.length; i++) {
6098 if (at[i].name == s[2]) {
6099 at.splice(i, 1);
6100 return;
6101 }
6102 }
6103 }
6104
6105 switch (s[3]) {
6106 // Add default attrib values
6107 case '=':
6108 ar.defaultVal = s[4] || '';
6109 break;
6110
6111 // Add forced attrib values
6112 case ':':
6113 ar.forcedVal = s[4];
6114 break;
6115
6116 // Add validation values
6117 case '<':
6118 ar.validVals = s[4].split('?');
6119 break;
6120 }
6121
6122 if (/[*.?]/.test(s[2])) {
6123 wat = wat || [];
6124 ar.nameRE = new RegExp('^' + wildcardToRE(s[2]) + '$');
6125 wat.push(ar);
6126 } else {
6127 ar.name = s[2];
6128 at.push(ar);
6129 }
6130
6131 va.push(s[2]);
6132 }); 7898 });
6133 } 7899
6134 7900 // Grab first child or body element for serialization
6135 // Handle element names 7901 if (node.nodeName != 'BODY')
6136 each(tn, function(s, i) { 7902 node = doc.body.firstChild;
6137 var pr = s.charAt(0), x = 1, ru = {}; 7903 else
6138 7904 node = doc.body;
6139 // Extend with default rule data 7905
6140 if (dr) { 7906 // set the new document in DOMUtils so createElement etc works
6141 if (dr.noEmpty) 7907 oldDoc = dom.doc;
6142 ru.noEmpty = dr.noEmpty; 7908 dom.doc = doc;
6143 7909 }
6144 if (dr.fullEnd) 7910
6145 ru.fullEnd = dr.fullEnd; 7911 args = args || {};
6146 7912 args.format = args.format || 'html';
6147 if (dr.padd) 7913
6148 ru.padd = dr.padd; 7914 // Pre process
6149 } 7915 if (!args.no_events) {
6150 7916 args.node = node;
6151 // Handle prefixes 7917 onPreProcess.dispatch(self, args);
6152 switch (pr) { 7918 }
6153 case '-': 7919
6154 ru.noEmpty = true; 7920 // Setup serializer
6155 break; 7921 htmlSerializer = new tinymce.html.Serializer(settings, schema);
6156 7922
6157 case '+': 7923 // Parse and serialize HTML
6158 ru.fullEnd = true; 7924 args.content = htmlSerializer.serialize(
6159 break; 7925 htmlParser.parse(args.getInner ? node.innerHTML : tinymce.trim(dom.getOuterHTML(node), args), args)
6160 7926 );
6161 case '#': 7927
6162 ru.padd = true; 7928 // Replace all BOM characters for now until we can find a better solution
6163 break; 7929 if (!args.cleanup)
6164 7930 args.content = args.content.replace(/\uFEFF/g, '');
6165 default: 7931
6166 x = 0; 7932 // Post process
6167 } 7933 if (!args.no_events)
6168 7934 onPostProcess.dispatch(self, args);
6169 tn[i] = s = s.substring(x); 7935
6170 t.validElements[s] = 1; 7936 // Restore the old document if it was changed
6171 7937 if (oldDoc)
6172 // Add element name or element regex 7938 dom.doc = oldDoc;
6173 if (/[*.?]/.test(tn[0])) { 7939
6174 ru.nameRE = new RegExp('^' + wildcardToRE(tn[0]) + '$'); 7940 args.node = null;
6175 t.wildRules = t.wildRules || {}; 7941
6176 t.wildRules.push(ru); 7942 return args.content;
6177 } else { 7943 },
6178 ru.name = tn[0]; 7944
6179 7945 addRules : function(rules) {
6180 // Store away default rule 7946 schema.addValidElements(rules);
6181 if (tn[0] == '@') 7947 },
6182 dr = ru; 7948
6183 7949 setRules : function(rules) {
6184 t.rules[s] = ru; 7950 schema.setValidElements(rules);
6185 } 7951 }
6186 7952 };
6187 ru.attribs = at; 7953 };
6188
6189 if (ra)
6190 ru.requiredAttribs = ra;
6191
6192 if (wat) {
6193 // Build valid attributes regexp
6194 s = '';
6195 each(va, function(v) {
6196 if (s)
6197 s += '|';
6198
6199 s += '(' + wildcardToRE(v) + ')';
6200 });
6201 ru.validAttribsRE = new RegExp('^' + s.toLowerCase() + '$');
6202 ru.wildAttribs = wat;
6203 }
6204 });
6205 });
6206
6207 // Build valid elements regexp
6208 s = '';
6209 each(t.validElements, function(v, k) {
6210 if (s)
6211 s += '|';
6212
6213 if (k != '@')
6214 s += k;
6215 });
6216 t.validElementsRE = new RegExp('^(' + wildcardToRE(s.toLowerCase()) + ')$');
6217
6218 //console.debug(t.validElementsRE.toString());
6219 //console.dir(t.rules);
6220 //console.dir(t.wildRules);
6221 },
6222
6223 findRule : function(n) {
6224 var t = this, rl = t.rules, i, r;
6225
6226 t._setup();
6227
6228 // Exact match
6229 r = rl[n];
6230 if (r)
6231 return r;
6232
6233 // Try wildcards
6234 rl = t.wildRules;
6235 for (i = 0; i < rl.length; i++) {
6236 if (rl[i].nameRE.test(n))
6237 return rl[i];
6238 }
6239
6240 return null;
6241 },
6242
6243 findAttribRule : function(ru, n) {
6244 var i, wa = ru.wildAttribs;
6245
6246 for (i = 0; i < wa.length; i++) {
6247 if (wa[i].nameRE.test(n))
6248 return wa[i];
6249 }
6250
6251 return null;
6252 },
6253
6254 serialize : function(n, o) {
6255 var h, t = this, doc, oldDoc, impl, selected;
6256
6257 t._setup();
6258 o = o || {};
6259 o.format = o.format || 'html';
6260 t.processObj = o;
6261
6262 // IE looses the selected attribute on option elements so we need to store it
6263 // See: http://support.microsoft.com/kb/829907
6264 if (isIE) {
6265 selected = [];
6266 each(n.getElementsByTagName('option'), function(n) {
6267 var v = t.dom.getAttrib(n, 'selected');
6268
6269 selected.push(v ? v : null);
6270 });
6271 }
6272
6273 n = n.cloneNode(true);
6274
6275 // IE looses the selected attribute on option elements so we need to restore it
6276 if (isIE) {
6277 each(n.getElementsByTagName('option'), function(n, i) {
6278 t.dom.setAttrib(n, 'selected', selected[i]);
6279 });
6280 }
6281
6282 // Nodes needs to be attached to something in WebKit/Opera
6283 // Older builds of Opera crashes if you attach the node to an document created dynamically
6284 // and since we can't feature detect a crash we need to sniff the acutal build number
6285 // This fix will make DOM ranges and make Sizzle happy!
6286 impl = n.ownerDocument.implementation;
6287 if (impl.createHTMLDocument && (tinymce.isOpera && opera.buildNumber() >= 1767)) {
6288 // Create an empty HTML document
6289 doc = impl.createHTMLDocument("");
6290
6291 // Add the element or it's children if it's a body element to the new document
6292 each(n.nodeName == 'BODY' ? n.childNodes : [n], function(node) {
6293 doc.body.appendChild(doc.importNode(node, true));
6294 });
6295
6296 // Grab first child or body element for serialization
6297 if (n.nodeName != 'BODY')
6298 n = doc.body.firstChild;
6299 else
6300 n = doc.body;
6301
6302 // set the new document in DOMUtils so createElement etc works
6303 oldDoc = t.dom.doc;
6304 t.dom.doc = doc;
6305 }
6306
6307 t.key = '' + (parseInt(t.key) + 1);
6308
6309 // Pre process
6310 if (!o.no_events) {
6311 o.node = n;
6312 t.onPreProcess.dispatch(t, o);
6313 }
6314
6315 // Serialize HTML DOM into a string
6316 t.writer.reset();
6317 t._info = o;
6318 t._serializeNode(n, o.getInner);
6319
6320 // Post process
6321 o.content = t.writer.getContent();
6322
6323 // Restore the old document if it was changed
6324 if (oldDoc)
6325 t.dom.doc = oldDoc;
6326
6327 if (!o.no_events)
6328 t.onPostProcess.dispatch(t, o);
6329
6330 t._postProcess(o);
6331 o.node = null;
6332
6333 return tinymce.trim(o.content);
6334 },
6335
6336 // Internal functions
6337
6338 _postProcess : function(o) {
6339 var t = this, s = t.settings, h = o.content, sc = [], p;
6340
6341 if (o.format == 'html') {
6342 // Protect some elements
6343 p = t._protect({
6344 content : h,
6345 patterns : [
6346 {pattern : /(<script[^>]*>)(.*?)(<\/script>)/g},
6347 {pattern : /(<noscript[^>]*>)(.*?)(<\/noscript>)/g},
6348 {pattern : /(<style[^>]*>)(.*?)(<\/style>)/g},
6349 {pattern : /(<pre[^>]*>)(.*?)(<\/pre>)/g, encode : 1},
6350 {pattern : /(<!--\[CDATA\[)(.*?)(\]\]-->)/g}
6351 ]
6352 });
6353
6354 h = p.content;
6355
6356 // Entity encode
6357 if (s.entity_encoding !== 'raw')
6358 h = t._encode(h);
6359
6360 // Use BR instead of &nbsp; padded P elements inside editor and use <p>&nbsp;</p> outside editor
6361 /* if (o.set)
6362 h = h.replace(/<p>\s+(&nbsp;|&#160;|\u00a0|<br \/>)\s+<\/p>/g, '<p><br /></p>');
6363 else
6364 h = h.replace(/<p>\s+(&nbsp;|&#160;|\u00a0|<br \/>)\s+<\/p>/g, '<p>$1</p>');*/
6365
6366 // Since Gecko and Safari keeps whitespace in the DOM we need to
6367 // remove it inorder to match other browsers. But I think Gecko and Safari is right.
6368 // This process is only done when getting contents out from the editor.
6369 if (!o.set) {
6370 // We need to replace paragraph whitespace with an nbsp before indentation to keep the \u00a0 char
6371 h = h.replace(/<p>\s+<\/p>|<p([^>]+)>\s+<\/p>/g, s.entity_encoding == 'numeric' ? '<p$1>&#160;</p>' : '<p$1>&nbsp;</p>');
6372
6373 if (s.remove_linebreaks) {
6374 h = h.replace(/\r?\n|\r/g, ' ');
6375 h = h.replace(/(<[^>]+>)\s+/g, '$1 ');
6376 h = h.replace(/\s+(<\/[^>]+>)/g, ' $1');
6377 h = h.replace(/<(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object) ([^>]+)>\s+/g, '<$1 $2>'); // Trim block start
6378 h = h.replace(/<(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object)>\s+/g, '<$1>'); // Trim block start
6379 h = h.replace(/\s+<\/(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object)>/g, '</$1>'); // Trim block end
6380 }
6381
6382 // Simple indentation
6383 if (s.apply_source_formatting && s.indent_mode == 'simple') {
6384 // Add line breaks before and after block elements
6385 h = h.replace(/<(\/?)(ul|hr|table|meta|link|tbody|tr|object|body|head|html|map)(|[^>]+)>\s*/g, '\n<$1$2$3>\n');
6386 h = h.replace(/\s*<(p|h[1-6]|blockquote|div|title|style|pre|script|td|li|area)(|[^>]+)>/g, '\n<$1$2>');
6387 h = h.replace(/<\/(p|h[1-6]|blockquote|div|title|style|pre|script|td|li)>\s*/g, '</$1>\n');
6388 h = h.replace(/\n\n/g, '\n');
6389 }
6390 }
6391
6392 h = t._unprotect(h, p);
6393
6394 // Restore CDATA sections
6395 h = h.replace(/<!--\[CDATA\[([\s\S]+)\]\]-->/g, '<![CDATA[$1]]>');
6396
6397 // Restore the \u00a0 character if raw mode is enabled
6398 if (s.entity_encoding == 'raw')
6399 h = h.replace(/<p>&nbsp;<\/p>|<p([^>]+)>&nbsp;<\/p>/g, '<p$1>\u00a0</p>');
6400
6401 // Restore noscript elements
6402 h = h.replace(/<noscript([^>]+|)>([\s\S]*?)<\/noscript>/g, function(v, attribs, text) {
6403 return '<noscript' + attribs + '>' + t.dom.decode(text.replace(/<!--|-->/g, '')) + '</noscript>';
6404 });
6405 }
6406
6407 o.content = h;
6408 },
6409
6410 _serializeNode : function(n, inner) {
6411 var t = this, s = t.settings, w = t.writer, hc, el, cn, i, l, a, at, no, v, nn, ru, ar, iv, closed, keep, type, scopeName;
6412
6413 if (!s.node_filter || s.node_filter(n)) {
6414 switch (n.nodeType) {
6415 case 1: // Element
6416 if (n.hasAttribute ? n.hasAttribute('_mce_bogus') : n.getAttribute('_mce_bogus'))
6417 return;
6418
6419 iv = keep = false;
6420 hc = n.hasChildNodes();
6421 nn = n.getAttribute('_mce_name') || n.nodeName.toLowerCase();
6422
6423 // Get internal type
6424 type = n.getAttribute('_mce_type');
6425 if (type) {
6426 if (!t._info.cleanup) {
6427 iv = true;
6428 return;
6429 } else
6430 keep = 1;
6431 }
6432
6433 // Add correct prefix on IE
6434 if (isIE) {
6435 scopeName = n.scopeName;
6436 if (scopeName && scopeName !== 'HTML' && scopeName !== 'html')
6437 nn = scopeName + ':' + nn;
6438 }
6439
6440 // Remove mce prefix on IE needed for the abbr element
6441 if (nn.indexOf('mce:') === 0)
6442 nn = nn.substring(4);
6443
6444 // Check if valid
6445 if (!keep) {
6446 if (!t.validElementsRE || !t.validElementsRE.test(nn) || (t.invalidElementsRE && t.invalidElementsRE.test(nn)) || inner) {
6447 iv = true;
6448 break;
6449 }
6450 }
6451
6452 if (isIE) {
6453 // Fix IE content duplication (DOM can have multiple copies of the same node)
6454 if (s.fix_content_duplication) {
6455 if (n._mce_serialized == t.key)
6456 return;
6457
6458 n._mce_serialized = t.key;
6459 }
6460
6461 // IE sometimes adds a / infront of the node name
6462 if (nn.charAt(0) == '/')
6463 nn = nn.substring(1);
6464 } else if (isGecko) {
6465 // Ignore br elements
6466 if (n.nodeName === 'BR' && n.getAttribute('type') == '_moz')
6467 return;
6468 }
6469
6470 // Check if valid child
6471 if (s.validate_children) {
6472 if (t.elementName && !t.schema.isValid(t.elementName, nn)) {
6473 iv = true;
6474 break;
6475 }
6476
6477 t.elementName = nn;
6478 }
6479
6480 ru = t.findRule(nn);
6481
6482 // No valid rule for this element could be found then skip it
6483 if (!ru) {
6484 iv = true;
6485 break;
6486 }
6487
6488 nn = ru.name || nn;
6489 closed = s.closed.test(nn);
6490
6491 // Skip empty nodes or empty node name in IE
6492 if ((!hc && ru.noEmpty) || (isIE && !nn)) {
6493 iv = true;
6494 break;
6495 }
6496
6497 // Check required
6498 if (ru.requiredAttribs) {
6499 a = ru.requiredAttribs;
6500
6501 for (i = a.length - 1; i >= 0; i--) {
6502 if (this.dom.getAttrib(n, a[i]) !== '')
6503 break;
6504 }
6505
6506 // None of the required was there
6507 if (i == -1) {
6508 iv = true;
6509 break;
6510 }
6511 }
6512
6513 w.writeStartElement(nn);
6514
6515 // Add ordered attributes
6516 if (ru.attribs) {
6517 for (i=0, at = ru.attribs, l = at.length; i<l; i++) {
6518 a = at[i];
6519 v = t._getAttrib(n, a);
6520
6521 if (v !== null)
6522 w.writeAttribute(a.name, v);
6523 }
6524 }
6525
6526 // Add wild attributes
6527 if (ru.validAttribsRE) {
6528 at = t.dom.getAttribs(n);
6529 for (i=at.length-1; i>-1; i--) {
6530 no = at[i];
6531
6532 if (no.specified) {
6533 a = no.nodeName.toLowerCase();
6534
6535 if (s.invalid_attrs.test(a) || !ru.validAttribsRE.test(a))
6536 continue;
6537
6538 ar = t.findAttribRule(ru, a);
6539 v = t._getAttrib(n, ar, a);
6540
6541 if (v !== null)
6542 w.writeAttribute(a, v);
6543 }
6544 }
6545 }
6546
6547 // Keep type attribute
6548 if (type && keep)
6549 w.writeAttribute('_mce_type', type);
6550
6551 // Write text from script
6552 if (nn === 'script' && tinymce.trim(n.innerHTML)) {
6553 w.writeText('// '); // Padd it with a comment so it will parse on older browsers
6554 w.writeCDATA(n.innerHTML.replace(/<!--|-->|<\[CDATA\[|\]\]>/g, '')); // Remove comments and cdata stuctures
6555 hc = false;
6556 break;
6557 }
6558
6559 // Padd empty nodes with a &nbsp;
6560 if (ru.padd) {
6561 // If it has only one bogus child, padd it anyway workaround for <td><br /></td> bug
6562 if (hc && (cn = n.firstChild) && cn.nodeType === 1 && n.childNodes.length === 1) {
6563 if (cn.hasAttribute ? cn.hasAttribute('_mce_bogus') : cn.getAttribute('_mce_bogus'))
6564 w.writeText('\u00a0');
6565 } else if (!hc)
6566 w.writeText('\u00a0'); // No children then padd it
6567 }
6568
6569 break;
6570
6571 case 3: // Text
6572 // Check if valid child
6573 if (s.validate_children && t.elementName && !t.schema.isValid(t.elementName, '#text'))
6574 return;
6575
6576 return w.writeText(n.nodeValue);
6577
6578 case 4: // CDATA
6579 return w.writeCDATA(n.nodeValue);
6580
6581 case 8: // Comment
6582 return w.writeComment(n.nodeValue);
6583 }
6584 } else if (n.nodeType == 1)
6585 hc = n.hasChildNodes();
6586
6587 if (hc && !closed) {
6588 cn = n.firstChild;
6589
6590 while (cn) {
6591 t._serializeNode(cn);
6592 t.elementName = nn;
6593 cn = cn.nextSibling;
6594 }
6595 }
6596
6597 // Write element end
6598 if (!iv) {
6599 if (!closed)
6600 w.writeFullEndElement();
6601 else
6602 w.writeEndElement();
6603 }
6604 },
6605
6606 _protect : function(o) {
6607 var t = this;
6608
6609 o.items = o.items || [];
6610
6611 function enc(s) {
6612 return s.replace(/[\r\n\\]/g, function(c) {
6613 if (c === '\n')
6614 return '\\n';
6615 else if (c === '\\')
6616 return '\\\\';
6617
6618 return '\\r';
6619 });
6620 };
6621
6622 function dec(s) {
6623 return s.replace(/\\[\\rn]/g, function(c) {
6624 if (c === '\\n')
6625 return '\n';
6626 else if (c === '\\\\')
6627 return '\\';
6628
6629 return '\r';
6630 });
6631 };
6632
6633 each(o.patterns, function(p) {
6634 o.content = dec(enc(o.content).replace(p.pattern, function(x, a, b, c) {
6635 b = dec(b);
6636
6637 if (p.encode)
6638 b = t._encode(b);
6639
6640 o.items.push(b);
6641 return a + '<!--mce:' + (o.items.length - 1) + '-->' + c;
6642 }));
6643 });
6644
6645 return o;
6646 },
6647
6648 _unprotect : function(h, o) {
6649 h = h.replace(/\<!--mce:([0-9]+)--\>/g, function(a, b) {
6650 return o.items[parseInt(b)];
6651 });
6652
6653 o.items = [];
6654
6655 return h;
6656 },
6657
6658 _encode : function(h) {
6659 var t = this, s = t.settings, l;
6660
6661 // Entity encode
6662 if (s.entity_encoding !== 'raw') {
6663 if (s.entity_encoding.indexOf('named') != -1) {
6664 t.setEntities(s.entities);
6665 l = t.entityLookup;
6666
6667 h = h.replace(/[\u007E-\uFFFF]/g, function(a) {
6668 var v;
6669
6670 if (v = l[a])
6671 a = '&' + v + ';';
6672
6673 return a;
6674 });
6675 }
6676
6677 if (s.entity_encoding.indexOf('numeric') != -1) {
6678 h = h.replace(/[\u007E-\uFFFF]/g, function(a) {
6679 return '&#' + a.charCodeAt(0) + ';';
6680 });
6681 }
6682 }
6683
6684 return h;
6685 },
6686
6687 _setup : function() {
6688 var t = this, s = this.settings;
6689
6690 if (t.done)
6691 return;
6692
6693 t.done = 1;
6694
6695 t.setRules(s.valid_elements);
6696 t.addRules(s.extended_valid_elements);
6697
6698 if (s.invalid_elements)
6699 t.invalidElementsRE = new RegExp('^(' + wildcardToRE(s.invalid_elements.replace(/,/g, '|').toLowerCase()) + ')$');
6700
6701 if (s.attrib_value_filter)
6702 t.attribValueFilter = s.attribValueFilter;
6703 },
6704
6705 _getAttrib : function(n, a, na) {
6706 var i, v;
6707
6708 na = na || a.name;
6709
6710 if (a.forcedVal && (v = a.forcedVal)) {
6711 if (v === '{$uid}')
6712 return this.dom.uniqueId();
6713
6714 return v;
6715 }
6716
6717 v = this.dom.getAttrib(n, na);
6718
6719 switch (na) {
6720 case 'rowspan':
6721 case 'colspan':
6722 // Whats the point? Remove usless attribute value
6723 if (v == '1')
6724 v = '';
6725
6726 break;
6727 }
6728
6729 if (this.attribValueFilter)
6730 v = this.attribValueFilter(na, v, n);
6731
6732 if (a.validVals) {
6733 for (i = a.validVals.length - 1; i >= 0; i--) {
6734 if (v == a.validVals[i])
6735 break;
6736 }
6737
6738 if (i == -1)
6739 return null;
6740 }
6741
6742 if (v === '' && typeof(a.defaultVal) != 'undefined') {
6743 v = a.defaultVal;
6744
6745 if (v === '{$uid}')
6746 return this.dom.uniqueId();
6747
6748 return v;
6749 } else {
6750 // Remove internal mceItemXX classes when content is extracted from editor
6751 if (na == 'class' && this.processObj.get)
6752 v = v.replace(/\s?mceItem\w+\s?/g, '');
6753 }
6754
6755 if (v === '')
6756 return null;
6757
6758
6759 return v;
6760 }
6761 });
6762 })(tinymce); 7954 })(tinymce);
6763
6764 (function(tinymce) { 7955 (function(tinymce) {
6765 tinymce.dom.ScriptLoader = function(settings) { 7956 tinymce.dom.ScriptLoader = function(settings) {
6766 var QUEUED = 0, 7957 var QUEUED = 0,
6767 LOADING = 1, 7958 LOADING = 1,
6768 LOADED = 2, 7959 LOADED = 2,
6783 if (elm) 7974 if (elm)
6784 elm.onreadystatechange = elm.onload = elm = null; 7975 elm.onreadystatechange = elm.onload = elm = null;
6785 7976
6786 callback(); 7977 callback();
6787 }; 7978 };
7979
7980 function error() {
7981 // Report the error so it's easier for people to spot loading errors
7982 if (typeof(console) !== "undefined" && console.log)
7983 console.log("Failed to load: " + url);
7984
7985 // We can't mark it as done if there is a load error since
7986 // A) We don't want to produce 404 errors on the server and
7987 // B) the onerror event won't fire on all browsers.
7988 // done();
7989 };
6788 7990
6789 id = dom.uniqueId(); 7991 id = dom.uniqueId();
6790 7992
6791 if (tinymce.isIE6) { 7993 if (tinymce.isIE6) {
6792 uri = new tinymce.util.URI(url); 7994 uri = new tinymce.util.URI(url);
6793 loc = location; 7995 loc = location;
6794 7996
6795 // If script is from same domain and we 7997 // If script is from same domain and we
6796 // use IE 6 then use XHR since it's more reliable 7998 // use IE 6 then use XHR since it's more reliable
6797 if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol) { 7999 if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol && uri.protocol.toLowerCase() != 'file') {
6798 tinymce.util.XHR.send({ 8000 tinymce.util.XHR.send({
6799 url : tinymce._addVer(uri.getURI()), 8001 url : tinymce._addVer(uri.getURI()),
6800 success : function(content) { 8002 success : function(content) {
6801 // Create new temp script element 8003 // Create new temp script element
6802 var script = dom.create('script', { 8004 var script = dom.create('script', {
6807 script.text = content; 8009 script.text = content;
6808 document.getElementsByTagName('head')[0].appendChild(script); 8010 document.getElementsByTagName('head')[0].appendChild(script);
6809 dom.remove(script); 8011 dom.remove(script);
6810 8012
6811 done(); 8013 done();
6812 } 8014 },
8015
8016 error : error
6813 }); 8017 });
6814 8018
6815 return; 8019 return;
6816 } 8020 }
6817 } 8021 }
6821 id : id, 8025 id : id,
6822 type : 'text/javascript', 8026 type : 'text/javascript',
6823 src : tinymce._addVer(url) 8027 src : tinymce._addVer(url)
6824 }); 8028 });
6825 8029
6826 // Add onload and readystate listeners 8030 // Add onload listener for non IE browsers since IE9
6827 elm.onload = done; 8031 // fires onload event before the script is parsed and executed
6828 elm.onreadystatechange = function() { 8032 if (!tinymce.isIE)
6829 var state = elm.readyState; 8033 elm.onload = done;
6830 8034
6831 // Loaded state is passed on IE 6 however there 8035 // Add onerror event will get fired on some browsers but not all of them
6832 // are known issues with this method but we can't use 8036 elm.onerror = error;
6833 // XHR in a cross domain loading 8037
6834 if (state == 'complete' || state == 'loaded') 8038 // Opera 9.60 doesn't seem to fire the onreadystate event at correctly
6835 done(); 8039 if (!tinymce.isOpera) {
6836 }; 8040 elm.onreadystatechange = function() {
8041 var state = elm.readyState;
8042
8043 // Loaded state is passed on IE 6 however there
8044 // are known issues with this method but we can't use
8045 // XHR in a cross domain loading
8046 if (state == 'complete' || state == 'loaded')
8047 done();
8048 };
8049 }
6837 8050
6838 // Most browsers support this feature so we report errors 8051 // Most browsers support this feature so we report errors
6839 // for those at least to help users track their missing plugins etc 8052 // for those at least to help users track their missing plugins etc
6840 // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option 8053 // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option
6841 /*elm.onerror = function() { 8054 /*elm.onerror = function() {
6979 this.next = function(shallow) { 8192 this.next = function(shallow) {
6980 return (node = findSibling(node, 'firstChild', 'nextSibling', shallow)); 8193 return (node = findSibling(node, 'firstChild', 'nextSibling', shallow));
6981 }; 8194 };
6982 8195
6983 this.prev = function(shallow) { 8196 this.prev = function(shallow) {
6984 return (node = findSibling(node, 'lastChild', 'lastSibling', shallow)); 8197 return (node = findSibling(node, 'lastChild', 'previousSibling', shallow));
6985 }; 8198 };
6986 }; 8199 };
6987 8200
6988 (function() {
6989 var transitional = {};
6990
6991 function unpack(lookup, data) {
6992 var key;
6993
6994 function replace(value) {
6995 return value.replace(/[A-Z]+/g, function(key) {
6996 return replace(lookup[key]);
6997 });
6998 };
6999
7000 // Unpack lookup
7001 for (key in lookup) {
7002 if (lookup.hasOwnProperty(key))
7003 lookup[key] = replace(lookup[key]);
7004 }
7005
7006 // Unpack and parse data into object map
7007 replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]/g, function(str, name, children) {
7008 var i, map = {};
7009
7010 children = children.split(/\|/);
7011
7012 for (i = children.length - 1; i >= 0; i--)
7013 map[children[i]] = 1;
7014
7015 transitional[name] = map;
7016 });
7017 };
7018
7019 // This is the XHTML 1.0 transitional elements with it's children packed to reduce it's size
7020 // we will later include the attributes here and use it as a default for valid elements but it
7021 // requires us to rewrite the serializer engine
7022 unpack({
7023 Z : '#|H|K|N|O|P',
7024 Y : '#|X|form|R|Q',
7025 X : 'p|T|div|U|W|isindex|fieldset|table',
7026 W : 'pre|hr|blockquote|address|center|noframes',
7027 U : 'ul|ol|dl|menu|dir',
7028 ZC : '#|p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
7029 T : 'h1|h2|h3|h4|h5|h6',
7030 ZB : '#|X|S|Q',
7031 S : 'R|P',
7032 ZA : '#|a|G|J|M|O|P',
7033 R : '#|a|H|K|N|O',
7034 Q : 'noscript|P',
7035 P : 'ins|del|script',
7036 O : 'input|select|textarea|label|button',
7037 N : 'M|L',
7038 M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
7039 L : 'sub|sup',
7040 K : 'J|I',
7041 J : 'tt|i|b|u|s|strike',
7042 I : 'big|small|font|basefont',
7043 H : 'G|F',
7044 G : 'br|span|bdo',
7045 F : 'object|applet|img|map|iframe'
7046 }, 'script[]' +
7047 'style[]' +
7048 'object[#|param|X|form|a|H|K|N|O|Q]' +
7049 'param[]' +
7050 'p[S]' +
7051 'a[Z]' +
7052 'br[]' +
7053 'span[S]' +
7054 'bdo[S]' +
7055 'applet[#|param|X|form|a|H|K|N|O|Q]' +
7056 'h1[S]' +
7057 'img[]' +
7058 'map[X|form|Q|area]' +
7059 'h2[S]' +
7060 'iframe[#|X|form|a|H|K|N|O|Q]' +
7061 'h3[S]' +
7062 'tt[S]' +
7063 'i[S]' +
7064 'b[S]' +
7065 'u[S]' +
7066 's[S]' +
7067 'strike[S]' +
7068 'big[S]' +
7069 'small[S]' +
7070 'font[S]' +
7071 'basefont[]' +
7072 'em[S]' +
7073 'strong[S]' +
7074 'dfn[S]' +
7075 'code[S]' +
7076 'q[S]' +
7077 'samp[S]' +
7078 'kbd[S]' +
7079 'var[S]' +
7080 'cite[S]' +
7081 'abbr[S]' +
7082 'acronym[S]' +
7083 'sub[S]' +
7084 'sup[S]' +
7085 'input[]' +
7086 'select[optgroup|option]' +
7087 'optgroup[option]' +
7088 'option[]' +
7089 'textarea[]' +
7090 'label[S]' +
7091 'button[#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
7092 'h4[S]' +
7093 'ins[#|X|form|a|H|K|N|O|Q]' +
7094 'h5[S]' +
7095 'del[#|X|form|a|H|K|N|O|Q]' +
7096 'h6[S]' +
7097 'div[#|X|form|a|H|K|N|O|Q]' +
7098 'ul[li]' +
7099 'li[#|X|form|a|H|K|N|O|Q]' +
7100 'ol[li]' +
7101 'dl[dt|dd]' +
7102 'dt[S]' +
7103 'dd[#|X|form|a|H|K|N|O|Q]' +
7104 'menu[li]' +
7105 'dir[li]' +
7106 'pre[ZA]' +
7107 'hr[]' +
7108 'blockquote[#|X|form|a|H|K|N|O|Q]' +
7109 'address[S|p]' +
7110 'center[#|X|form|a|H|K|N|O|Q]' +
7111 'noframes[#|X|form|a|H|K|N|O|Q]' +
7112 'isindex[]' +
7113 'fieldset[#|legend|X|form|a|H|K|N|O|Q]' +
7114 'legend[S]' +
7115 'table[caption|col|colgroup|thead|tfoot|tbody|tr]' +
7116 'caption[S]' +
7117 'col[]' +
7118 'colgroup[col]' +
7119 'thead[tr]' +
7120 'tr[th|td]' +
7121 'th[#|X|form|a|H|K|N|O|Q]' +
7122 'form[#|X|a|H|K|N|O|Q]' +
7123 'noscript[#|X|form|a|H|K|N|O|Q]' +
7124 'td[#|X|form|a|H|K|N|O|Q]' +
7125 'tfoot[tr]' +
7126 'tbody[tr]' +
7127 'area[]' +
7128 'base[]' +
7129 'body[#|X|form|a|H|K|N|O|Q]'
7130 );
7131
7132 tinymce.dom.Schema = function() {
7133 var t = this, elements = transitional;
7134
7135 t.isValid = function(name, child_name) {
7136 var element = elements[name];
7137
7138 return !!(element && (!child_name || element[child_name]));
7139 };
7140 };
7141 })();
7142 (function(tinymce) { 8201 (function(tinymce) {
7143 tinymce.dom.RangeUtils = function(dom) { 8202 tinymce.dom.RangeUtils = function(dom) {
7144 var INVISIBLE_CHAR = '\uFEFF'; 8203 var INVISIBLE_CHAR = '\uFEFF';
7145 8204
7146 this.walk = function(rng, callback) { 8205 this.walk = function(rng, callback) {
7200 if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) 8259 if (startContainer.nodeType == 1 && startContainer.hasChildNodes())
7201 startContainer = startContainer.childNodes[startOffset]; 8260 startContainer = startContainer.childNodes[startOffset];
7202 8261
7203 // If index based end position then resolve it 8262 // If index based end position then resolve it
7204 if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) 8263 if (endContainer.nodeType == 1 && endContainer.hasChildNodes())
7205 endContainer = endContainer.childNodes[Math.min(startOffset == endOffset ? endOffset : endOffset - 1, endContainer.childNodes.length - 1)]; 8264 endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)];
7206 8265
7207 // Find common ancestor and end points 8266 // Find common ancestor and end points
7208 ancestor = dom.findCommonAncestor(startContainer, endContainer); 8267 ancestor = dom.findCommonAncestor(startContainer, endContainer);
7209 8268
7210 // Same container 8269 // Same container
7321 return false; 8380 return false;
7322 }; 8381 };
7323 })(tinymce); 8382 })(tinymce);
7324 8383
7325 (function(tinymce) { 8384 (function(tinymce) {
8385 var Event = tinymce.dom.Event, each = tinymce.each;
8386
8387 tinymce.create('tinymce.ui.KeyboardNavigation', {
8388 KeyboardNavigation: function(settings, dom) {
8389 var t = this, root = settings.root, items = settings.items,
8390 enableUpDown = settings.enableUpDown, enableLeftRight = settings.enableLeftRight || !settings.enableUpDown,
8391 excludeFromTabOrder = settings.excludeFromTabOrder,
8392 itemFocussed, itemBlurred, rootKeydown, rootFocussed, focussedId;
8393
8394 dom = dom || tinymce.DOM;
8395
8396 itemFocussed = function(evt) {
8397 focussedId = evt.target.id;
8398 };
8399
8400 itemBlurred = function(evt) {
8401 dom.setAttrib(evt.target.id, 'tabindex', '-1');
8402 };
8403
8404 rootFocussed = function(evt) {
8405 var item = dom.get(focussedId);
8406 dom.setAttrib(item, 'tabindex', '0');
8407 item.focus();
8408 };
8409
8410 t.focus = function() {
8411 dom.get(focussedId).focus();
8412 };
8413
8414 t.destroy = function() {
8415 each(items, function(item) {
8416 dom.unbind(dom.get(item.id), 'focus', itemFocussed);
8417 dom.unbind(dom.get(item.id), 'blur', itemBlurred);
8418 });
8419
8420 dom.unbind(dom.get(root), 'focus', rootFocussed);
8421 dom.unbind(dom.get(root), 'keydown', rootKeydown);
8422
8423 items = dom = root = t.focus = itemFocussed = itemBlurred = rootKeydown = rootFocussed = null;
8424 t.destroy = function() {};
8425 };
8426
8427 t.moveFocus = function(dir, evt) {
8428 var idx = -1, controls = t.controls, newFocus;
8429
8430 if (!focussedId)
8431 return;
8432
8433 each(items, function(item, index) {
8434 if (item.id === focussedId) {
8435 idx = index;
8436 return false;
8437 }
8438 });
8439
8440 idx += dir;
8441 if (idx < 0) {
8442 idx = items.length - 1;
8443 } else if (idx >= items.length) {
8444 idx = 0;
8445 }
8446
8447 newFocus = items[idx];
8448 dom.setAttrib(focussedId, 'tabindex', '-1');
8449 dom.setAttrib(newFocus.id, 'tabindex', '0');
8450 dom.get(newFocus.id).focus();
8451
8452 if (settings.actOnFocus) {
8453 settings.onAction(newFocus.id);
8454 }
8455
8456 if (evt)
8457 Event.cancel(evt);
8458 };
8459
8460 rootKeydown = function(evt) {
8461 var DOM_VK_LEFT = 37, DOM_VK_RIGHT = 39, DOM_VK_UP = 38, DOM_VK_DOWN = 40, DOM_VK_ESCAPE = 27, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_SPACE = 32;
8462
8463 switch (evt.keyCode) {
8464 case DOM_VK_LEFT:
8465 if (enableLeftRight) t.moveFocus(-1);
8466 break;
8467
8468 case DOM_VK_RIGHT:
8469 if (enableLeftRight) t.moveFocus(1);
8470 break;
8471
8472 case DOM_VK_UP:
8473 if (enableUpDown) t.moveFocus(-1);
8474 break;
8475
8476 case DOM_VK_DOWN:
8477 if (enableUpDown) t.moveFocus(1);
8478 break;
8479
8480 case DOM_VK_ESCAPE:
8481 if (settings.onCancel) {
8482 settings.onCancel();
8483 Event.cancel(evt);
8484 }
8485 break;
8486
8487 case DOM_VK_ENTER:
8488 case DOM_VK_RETURN:
8489 case DOM_VK_SPACE:
8490 if (settings.onAction) {
8491 settings.onAction(focussedId);
8492 Event.cancel(evt);
8493 }
8494 break;
8495 }
8496 };
8497
8498 // Set up state and listeners for each item.
8499 each(items, function(item, idx) {
8500 var tabindex;
8501
8502 if (!item.id) {
8503 item.id = dom.uniqueId('_mce_item_');
8504 }
8505
8506 if (excludeFromTabOrder) {
8507 dom.bind(item.id, 'blur', itemBlurred);
8508 tabindex = '-1';
8509 } else {
8510 tabindex = (idx === 0 ? '0' : '-1');
8511 }
8512
8513 dom.setAttrib(item.id, 'tabindex', tabindex);
8514 dom.bind(dom.get(item.id), 'focus', itemFocussed);
8515 });
8516
8517 // Setup initial state for root element.
8518 if (items[0]){
8519 focussedId = items[0].id;
8520 }
8521
8522 dom.setAttrib(root, 'tabindex', '-1');
8523
8524 // Setup listeners for root element.
8525 dom.bind(dom.get(root), 'focus', rootFocussed);
8526 dom.bind(dom.get(root), 'keydown', rootKeydown);
8527 }
8528 });
8529 })(tinymce);
8530 (function(tinymce) {
7326 // Shorten class names 8531 // Shorten class names
7327 var DOM = tinymce.DOM, is = tinymce.is; 8532 var DOM = tinymce.DOM, is = tinymce.is;
7328 8533
7329 tinymce.create('tinymce.ui.Control', { 8534 tinymce.create('tinymce.ui.Control', {
7330 Control : function(id, s) { 8535 Control : function(id, s, editor) {
7331 this.id = id; 8536 this.id = id;
7332 this.settings = s = s || {}; 8537 this.settings = s = s || {};
7333 this.rendered = false; 8538 this.rendered = false;
7334 this.onRender = new tinymce.util.Dispatcher(this); 8539 this.onRender = new tinymce.util.Dispatcher(this);
7335 this.classPrefix = ''; 8540 this.classPrefix = '';
7336 this.scope = s.scope || this; 8541 this.scope = s.scope || this;
7337 this.disabled = 0; 8542 this.disabled = 0;
7338 this.active = 0; 8543 this.active = 0;
8544 this.editor = editor;
8545 },
8546
8547 setAriaProperty : function(property, value) {
8548 var element = DOM.get(this.id + '_aria') || DOM.get(this.id);
8549 if (element) {
8550 DOM.setAttrib(element, 'aria-' + property, !!value);
8551 }
8552 },
8553
8554 focus : function() {
8555 DOM.get(this.id).focus();
7339 }, 8556 },
7340 8557
7341 setDisabled : function(s) { 8558 setDisabled : function(s) {
7342 var e;
7343
7344 if (s != this.disabled) { 8559 if (s != this.disabled) {
7345 e = DOM.get(this.id); 8560 this.setAriaProperty('disabled', s);
7346
7347 // Add accessibility title for unavailable actions
7348 if (e && this.settings.unavailable_prefix) {
7349 if (s) {
7350 this.prevTitle = e.title;
7351 e.title = this.settings.unavailable_prefix + ": " + e.title;
7352 } else
7353 e.title = this.prevTitle;
7354 }
7355 8561
7356 this.setState('Disabled', s); 8562 this.setState('Disabled', s);
7357 this.setState('Enabled', !s); 8563 this.setState('Enabled', !s);
7358 this.disabled = s; 8564 this.disabled = s;
7359 } 8565 }
7365 8571
7366 setActive : function(s) { 8572 setActive : function(s) {
7367 if (s != this.active) { 8573 if (s != this.active) {
7368 this.setState('Active', s); 8574 this.setState('Active', s);
7369 this.active = s; 8575 this.active = s;
8576 this.setAriaProperty('pressed', s);
7370 } 8577 }
7371 }, 8578 },
7372 8579
7373 isActive : function() { 8580 isActive : function() {
7374 return this.active; 8581 return this.active;
7422 tinymce.dom.Event.clear(this.id); 8629 tinymce.dom.Event.clear(this.id);
7423 } 8630 }
7424 }); 8631 });
7425 })(tinymce); 8632 })(tinymce);
7426 tinymce.create('tinymce.ui.Container:tinymce.ui.Control', { 8633 tinymce.create('tinymce.ui.Container:tinymce.ui.Control', {
7427 Container : function(id, s) { 8634 Container : function(id, s, editor) {
7428 this.parent(id, s); 8635 this.parent(id, s, editor);
7429 8636
7430 this.controls = []; 8637 this.controls = [];
7431 8638
7432 this.lookup = {}; 8639 this.lookup = {};
7433 }, 8640 },
7447 8654
7448 tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { 8655 tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', {
7449 Separator : function(id, s) { 8656 Separator : function(id, s) {
7450 this.parent(id, s); 8657 this.parent(id, s);
7451 this.classPrefix = 'mceSeparator'; 8658 this.classPrefix = 'mceSeparator';
8659 this.setDisabled(true);
7452 }, 8660 },
7453 8661
7454 renderHTML : function() { 8662 renderHTML : function() {
7455 return tinymce.DOM.createHTML('span', {'class' : this.classPrefix}); 8663 return tinymce.DOM.createHTML('span', {'class' : this.classPrefix, role : 'separator', 'aria-orientation' : 'vertical', tabindex : '-1'});
7456 } 8664 }
7457 }); 8665 });
7458 8666
7459 (function(tinymce) { 8667 (function(tinymce) {
7460 var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk; 8668 var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk;
7465 this.classPrefix = 'mceMenuItem'; 8673 this.classPrefix = 'mceMenuItem';
7466 }, 8674 },
7467 8675
7468 setSelected : function(s) { 8676 setSelected : function(s) {
7469 this.setState('Selected', s); 8677 this.setState('Selected', s);
8678 this.setAriaProperty('checked', !!s);
7470 this.selected = s; 8679 this.selected = s;
7471 }, 8680 },
7472 8681
7473 isSelected : function() { 8682 isSelected : function() {
7474 return this.selected; 8683 return this.selected;
7612 s.parent = t; 8821 s.parent = t;
7613 s.constrain = s.constrain || cs.constrain; 8822 s.constrain = s.constrain || cs.constrain;
7614 s['class'] = s['class'] || cs['class']; 8823 s['class'] = s['class'] || cs['class'];
7615 s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x; 8824 s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x;
7616 s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y; 8825 s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y;
8826 s.keyboard_focus = cs.keyboard_focus;
7617 m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s); 8827 m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s);
7618 8828
7619 m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem); 8829 m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem);
7620 8830
7621 return m; 8831 return m;
8832 },
8833
8834 focus : function() {
8835 var t = this;
8836 if (t.keyboardNav) {
8837 t.keyboardNav.focus();
8838 }
7622 }, 8839 },
7623 8840
7624 update : function() { 8841 update : function() {
7625 var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th; 8842 var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th;
7626 8843
7741 DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive'); 8958 DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive');
7742 } 8959 }
7743 } 8960 }
7744 }); 8961 });
7745 } 8962 }
8963
8964 Event.add(co, 'keydown', t._keyHandler, t);
7746 8965
7747 t.onShowMenu.dispatch(t); 8966 t.onShowMenu.dispatch(t);
7748 8967
7749 if (s.keyboard_focus) { 8968 if (s.keyboard_focus) {
7750 Event.add(co, 'keydown', t._keyHandler, t); 8969 t._setupKeyboardNav();
7751 DOM.select('a', 'menu_' + t.id)[0].focus(); // Select first link
7752 t._focusIdx = 0;
7753 } 8970 }
7754 }, 8971 },
7755 8972
7756 hideMenu : function(c) { 8973 hideMenu : function(c) {
7757 var t = this, co = DOM.get('menu_' + t.id), e; 8974 var t = this, co = DOM.get('menu_' + t.id), e;
7758 8975
7759 if (!t.isMenuVisible) 8976 if (!t.isMenuVisible)
7760 return; 8977 return;
7761 8978
8979 if (t.keyboardNav) t.keyboardNav.destroy();
7762 Event.remove(co, 'mouseover', t.mouseOverFunc); 8980 Event.remove(co, 'mouseover', t.mouseOverFunc);
7763 Event.remove(co, 'click', t.mouseClickFunc); 8981 Event.remove(co, 'click', t.mouseClickFunc);
7764 Event.remove(co, 'keydown', t._keyHandler); 8982 Event.remove(co, 'keydown', t._keyHandler);
7765 DOM.hide(co); 8983 DOM.hide(co);
7766 t.isMenuVisible = 0; 8984 t.isMenuVisible = 0;
7801 }, 9019 },
7802 9020
7803 destroy : function() { 9021 destroy : function() {
7804 var t = this, co = DOM.get('menu_' + t.id); 9022 var t = this, co = DOM.get('menu_' + t.id);
7805 9023
9024 if (t.keyboardNav) t.keyboardNav.destroy();
7806 Event.remove(co, 'mouseover', t.mouseOverFunc); 9025 Event.remove(co, 'mouseover', t.mouseOverFunc);
9026 Event.remove(DOM.select('a', co), 'focus', t.mouseOverFunc);
7807 Event.remove(co, 'click', t.mouseClickFunc); 9027 Event.remove(co, 'click', t.mouseClickFunc);
9028 Event.remove(co, 'keydown', t._keyHandler);
7808 9029
7809 if (t.element) 9030 if (t.element)
7810 t.element.remove(); 9031 t.element.remove();
7811 9032
7812 DOM.remove(co); 9033 DOM.remove(co);
7813 }, 9034 },
7814 9035
7815 renderNode : function() { 9036 renderNode : function() {
7816 var t = this, s = t.settings, n, tb, co, w; 9037 var t = this, s = t.settings, n, tb, co, w;
7817 9038
7818 w = DOM.create('div', {id : 'menu_' + t.id, 'class' : s['class'], 'style' : 'position:absolute;left:0;top:0;z-index:200000'}); 9039 w = DOM.create('div', {role: 'listbox', id : 'menu_' + t.id, 'class' : s['class'], 'style' : 'position:absolute;left:0;top:0;z-index:200000;outline:0'});
7819 co = DOM.add(w, 'div', {id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')}); 9040 if (t.settings.parent) {
9041 DOM.setAttrib(w, 'aria-parent', 'menu_' + t.settings.parent.id);
9042 }
9043 co = DOM.add(w, 'div', {role: 'presentation', id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')});
7820 t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container}); 9044 t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container});
7821 9045
7822 if (s.menu_line) 9046 if (s.menu_line)
7823 DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'}); 9047 DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'});
7824 9048
7825 // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'}); 9049 // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'});
7826 n = DOM.add(co, 'table', {id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0}); 9050 n = DOM.add(co, 'table', {role: 'presentation', id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0});
7827 tb = DOM.add(n, 'tbody'); 9051 tb = DOM.add(n, 'tbody');
7828 9052
7829 each(t.items, function(o) { 9053 each(t.items, function(o) {
7830 t._add(tb, o); 9054 t._add(tb, o);
7831 }); 9055 });
7834 9058
7835 return w; 9059 return w;
7836 }, 9060 },
7837 9061
7838 // Internal functions 9062 // Internal functions
7839 9063 _setupKeyboardNav : function(){
7840 _keyHandler : function(e) { 9064 var contextMenu, menuItems, t=this;
7841 var t = this, kc = e.keyCode; 9065 contextMenu = DOM.select('#menu_' + t.id)[0];
7842 9066 menuItems = DOM.select('a[role=option]', 'menu_' + t.id);
7843 function focus(d) { 9067 menuItems.splice(0,0,contextMenu);
7844 var i = t._focusIdx + d, e = DOM.select('a', 'menu_' + t.id)[i]; 9068 t.keyboardNav = new tinymce.ui.KeyboardNavigation({
7845 9069 root: 'menu_' + t.id,
7846 if (e) { 9070 items: menuItems,
7847 t._focusIdx = i; 9071 onCancel: function() {
7848 e.focus(); 9072 t.hideMenu();
7849 } 9073 },
7850 }; 9074 enableUpDown: true
7851 9075 });
7852 switch (kc) { 9076 contextMenu.focus();
7853 case 38: 9077 },
7854 focus(-1); // Select first link 9078
7855 return; 9079 _keyHandler : function(evt) {
7856 9080 var t = this, e;
7857 case 40: 9081 switch (evt.keyCode) {
7858 focus(1); 9082 case 37: // Left
7859 return; 9083 if (t.settings.parent) {
7860 9084 t.hideMenu();
7861 case 13: 9085 t.settings.parent.focus();
7862 return; 9086 Event.cancel(evt);
7863 9087 }
7864 case 27: 9088 break;
7865 return this.hideMenu(); 9089 case 39: // Right
9090 if (t.mouseOverFunc)
9091 t.mouseOverFunc(evt);
9092 break;
7866 } 9093 }
7867 }, 9094 },
7868 9095
7869 _add : function(tb, o) { 9096 _add : function(tb, o) {
7870 var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic; 9097 var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic;
7878 9105
7879 return; 9106 return;
7880 } 9107 }
7881 9108
7882 n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'}); 9109 n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'});
7883 n = it = DOM.add(n, 'td'); 9110 n = it = DOM.add(n, s.titleItem ? 'th' : 'td');
7884 n = a = DOM.add(n, 'a', {href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'}); 9111 n = a = DOM.add(n, 'a', {id: o.id + '_aria', role: s.titleItem ? 'presentation' : 'option', href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'});
9112
9113 if (s.parent) {
9114 DOM.setAttrib(a, 'aria-haspopup', 'true');
9115 DOM.setAttrib(a, 'aria-owns', 'menu_' + o.id);
9116 }
7885 9117
7886 DOM.addClass(it, s['class']); 9118 DOM.addClass(it, s['class']);
7887 // n = DOM.add(n, 'span', {'class' : 'item'}); 9119 // n = DOM.add(n, 'span', {'class' : 'item'});
7888 9120
7889 ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')}); 9121 ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')});
7914 })(tinymce); 9146 })(tinymce);
7915 (function(tinymce) { 9147 (function(tinymce) {
7916 var DOM = tinymce.DOM; 9148 var DOM = tinymce.DOM;
7917 9149
7918 tinymce.create('tinymce.ui.Button:tinymce.ui.Control', { 9150 tinymce.create('tinymce.ui.Button:tinymce.ui.Control', {
7919 Button : function(id, s) { 9151 Button : function(id, s, ed) {
7920 this.parent(id, s); 9152 this.parent(id, s, ed);
7921 this.classPrefix = 'mceButton'; 9153 this.classPrefix = 'mceButton';
7922 }, 9154 },
7923 9155
7924 renderHTML : function() { 9156 renderHTML : function() {
7925 var cp = this.classPrefix, s = this.settings, h, l; 9157 var cp = this.classPrefix, s = this.settings, h, l;
7926 9158
7927 l = DOM.encode(s.label || ''); 9159 l = DOM.encode(s.label || '');
7928 h = '<a id="' + this.id + '" href="javascript:;" class="' + cp + ' ' + cp + 'Enabled ' + s['class'] + (l ? ' ' + cp + 'Labeled' : '') +'" onmousedown="return false;" onclick="return false;" title="' + DOM.encode(s.title) + '">'; 9160 h = '<a role="button" id="' + this.id + '" href="javascript:;" class="' + cp + ' ' + cp + 'Enabled ' + s['class'] + (l ? ' ' + cp + 'Labeled' : '') +'" onmousedown="return false;" onclick="return false;" aria-labelledby="' + this.id + '_voice" title="' + DOM.encode(s.title) + '">';
7929 9161
7930 if (s.image) 9162 if (s.image)
7931 h += '<img class="mceIcon" src="' + s.image + '" />' + l + '</a>'; 9163 h += '<img class="mceIcon" src="' + s.image + '" alt="' + DOM.encode(s.title) + '" />' + l;
7932 else 9164 else
7933 h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '') + '</a>'; 9165 h += '<span class="mceIcon ' + s['class'] + '"></span>' + (l ? '<span class="' + cp + 'Label">' + l + '</span>' : '');
7934 9166
9167 h += '<span class="mceVoiceLabel mceIconOnly" style="display: none;" id="' + this.id + '_voice">' + s.title + '</span>';
9168 h += '</a>';
7935 return h; 9169 return h;
7936 }, 9170 },
7937 9171
7938 postRender : function() { 9172 postRender : function() {
7939 var t = this, s = t.settings; 9173 var t = this, s = t.settings;
7948 9182
7949 (function(tinymce) { 9183 (function(tinymce) {
7950 var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher; 9184 var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher;
7951 9185
7952 tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', { 9186 tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', {
7953 ListBox : function(id, s) { 9187 ListBox : function(id, s, ed) {
7954 var t = this; 9188 var t = this;
7955 9189
7956 t.parent(id, s); 9190 t.parent(id, s, ed);
7957 9191
7958 t.items = []; 9192 t.items = [];
7959 9193
7960 t.onChange = new Dispatcher(t); 9194 t.onChange = new Dispatcher(t);
7961 9195
8009 if (o) { 9243 if (o) {
8010 t.selectedValue = o.value; 9244 t.selectedValue = o.value;
8011 t.selectedIndex = idx; 9245 t.selectedIndex = idx;
8012 DOM.setHTML(e, DOM.encode(o.title)); 9246 DOM.setHTML(e, DOM.encode(o.title));
8013 DOM.removeClass(e, 'mceTitle'); 9247 DOM.removeClass(e, 'mceTitle');
9248 DOM.setAttrib(t.id, 'aria-valuenow', o.title);
8014 } else { 9249 } else {
8015 DOM.setHTML(e, DOM.encode(t.settings.title)); 9250 DOM.setHTML(e, DOM.encode(t.settings.title));
8016 DOM.addClass(e, 'mceTitle'); 9251 DOM.addClass(e, 'mceTitle');
8017 t.selectedValue = t.selectedIndex = null; 9252 t.selectedValue = t.selectedIndex = null;
8018 } 9253 DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title);
8019 9254 }
8020 e = 0; 9255 e = 0;
8021 } 9256 }
8022 }, 9257 },
8023 9258
8024 add : function(n, v, o) { 9259 add : function(n, v, o) {
8039 }, 9274 },
8040 9275
8041 renderHTML : function() { 9276 renderHTML : function() {
8042 var h = '', t = this, s = t.settings, cp = t.classPrefix; 9277 var h = '', t = this, s = t.settings, cp = t.classPrefix;
8043 9278
8044 h = '<table id="' + t.id + '" cellpadding="0" cellspacing="0" class="' + cp + ' ' + cp + 'Enabled' + (s['class'] ? (' ' + s['class']) : '') + '"><tbody><tr>'; 9279 h = '<span role="button" aria-haspopup="true" aria-labelledby="' + t.id +'_text" aria-describedby="' + t.id + '_voiceDesc"><table role="presentation" tabindex="0" id="' + t.id + '" cellpadding="0" cellspacing="0" class="' + cp + ' ' + cp + 'Enabled' + (s['class'] ? (' ' + s['class']) : '') + '"><tbody><tr>';
8045 h += '<td>' + DOM.createHTML('a', {id : t.id + '_text', href : 'javascript:;', 'class' : 'mceText', onclick : "return false;", onmousedown : 'return false;'}, DOM.encode(t.settings.title)) + '</td>'; 9280 h += '<td>' + DOM.createHTML('span', {id: t.id + '_voiceDesc', 'class': 'voiceLabel', style:'display:none;'}, t.settings.title);
8046 h += '<td>' + DOM.createHTML('a', {id : t.id + '_open', tabindex : -1, href : 'javascript:;', 'class' : 'mceOpen', onclick : "return false;", onmousedown : 'return false;'}, '<span></span>') + '</td>'; 9281 h += DOM.createHTML('a', {id : t.id + '_text', tabindex : -1, href : 'javascript:;', 'class' : 'mceText', onclick : "return false;", onmousedown : 'return false;'}, DOM.encode(t.settings.title)) + '</td>';
8047 h += '</tr></tbody></table>'; 9282 h += '<td>' + DOM.createHTML('a', {id : t.id + '_open', tabindex : -1, href : 'javascript:;', 'class' : 'mceOpen', onclick : "return false;", onmousedown : 'return false;'}, '<span><span style="display:none;" class="mceIconOnly" aria-hidden="true">\u25BC</span></span>') + '</td>';
9283 h += '</tr></tbody></table></span>';
8048 9284
8049 return h; 9285 return h;
8050 }, 9286 },
8051 9287
8052 showMenu : function() { 9288 showMenu : function() {
8092 9328
8093 hideMenu : function(e) { 9329 hideMenu : function(e) {
8094 var t = this; 9330 var t = this;
8095 9331
8096 if (t.menu && t.menu.isMenuVisible) { 9332 if (t.menu && t.menu.isMenuVisible) {
9333 DOM.removeClass(t.id, t.classPrefix + 'Selected');
9334
8097 // Prevent double toogles by canceling the mouse click event to the button 9335 // Prevent double toogles by canceling the mouse click event to the button
8098 if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open')) 9336 if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open'))
8099 return; 9337 return;
8100 9338
8101 if (!e || !DOM.getParent(e.target, '.mceMenu')) { 9339 if (!e || !DOM.getParent(e.target, '.mceMenu')) {
8114 'class' : t.classPrefix + 'Menu mceNoIcons', 9352 'class' : t.classPrefix + 'Menu mceNoIcons',
8115 max_width : 150, 9353 max_width : 150,
8116 max_height : 150 9354 max_height : 150
8117 }); 9355 });
8118 9356
8119 m.onHideMenu.add(t.hideMenu, t); 9357 m.onHideMenu.add(function() {
9358 t.hideMenu();
9359 t.focus();
9360 });
8120 9361
8121 m.add({ 9362 m.add({
8122 title : t.settings.title, 9363 title : t.settings.title,
8123 'class' : 'mceMenuItemTitle', 9364 'class' : 'mceMenuItemTitle',
8124 onclick : function() { 9365 onclick : function() {
8155 9396
8156 postRender : function() { 9397 postRender : function() {
8157 var t = this, cp = t.classPrefix; 9398 var t = this, cp = t.classPrefix;
8158 9399
8159 Event.add(t.id, 'click', t.showMenu, t); 9400 Event.add(t.id, 'click', t.showMenu, t);
8160 Event.add(t.id + '_text', 'focus', function() { 9401 Event.add(t.id, 'keydown', function(evt) {
9402 if (evt.keyCode == 32) { // Space
9403 t.showMenu(evt);
9404 Event.cancel(evt);
9405 }
9406 });
9407 Event.add(t.id, 'focus', function() {
8161 if (!t._focused) { 9408 if (!t._focused) {
8162 t.keyDownHandler = Event.add(t.id + '_text', 'keydown', function(e) { 9409 t.keyDownHandler = Event.add(t.id, 'keydown', function(e) {
8163 var idx = -1, v, kc = e.keyCode; 9410 if (e.keyCode == 40) {
8164 9411 t.showMenu();
8165 // Find current index 9412 Event.cancel(e);
8166 each(t.items, function(v, i) { 9413 }
8167 if (t.selectedValue == v.value) 9414 });
8168 idx = i; 9415 t.keyPressHandler = Event.add(t.id, 'keypress', function(e) {
8169 }); 9416 var v;
8170 9417 if (e.keyCode == 13) {
8171 // Move up/down
8172 if (kc == 38)
8173 v = t.items[idx - 1];
8174 else if (kc == 40)
8175 v = t.items[idx + 1];
8176 else if (kc == 13) {
8177 // Fake select on enter 9418 // Fake select on enter
8178 v = t.selectedValue; 9419 v = t.selectedValue;
8179 t.selectedValue = null; // Needs to be null to fake change 9420 t.selectedValue = null; // Needs to be null to fake change
9421 Event.cancel(e);
8180 t.settings.onselect(v); 9422 t.settings.onselect(v);
8181 return Event.cancel(e);
8182 }
8183
8184 if (v) {
8185 t.hideMenu();
8186 t.select(v.value);
8187 } 9423 }
8188 }); 9424 });
8189 } 9425 }
8190 9426
8191 t._focused = 1; 9427 t._focused = 1;
8192 }); 9428 });
8193 Event.add(t.id + '_text', 'blur', function() {Event.remove(t.id + '_text', 'keydown', t.keyDownHandler); t._focused = 0;}); 9429 Event.add(t.id, 'blur', function() {
9430 Event.remove(t.id, 'keydown', t.keyDownHandler);
9431 Event.remove(t.id, 'keypress', t.keyPressHandler);
9432 t._focused = 0;
9433 });
8194 9434
8195 // Old IE doesn't have hover on all elements 9435 // Old IE doesn't have hover on all elements
8196 if (tinymce.isIE6 || !DOM.boxModel) { 9436 if (tinymce.isIE6 || !DOM.boxModel) {
8197 Event.add(t.id, 'mouseover', function() { 9437 Event.add(t.id, 'mouseover', function() {
8198 if (!DOM.hasClass(t.id, cp + 'Disabled')) 9438 if (!DOM.hasClass(t.id, cp + 'Disabled'))
8225 this.classPrefix = 'mceNativeListBox'; 9465 this.classPrefix = 'mceNativeListBox';
8226 }, 9466 },
8227 9467
8228 setDisabled : function(s) { 9468 setDisabled : function(s) {
8229 DOM.get(this.id).disabled = s; 9469 DOM.get(this.id).disabled = s;
9470 this.setAriaProperty('disabled', s);
8230 }, 9471 },
8231 9472
8232 isDisabled : function() { 9473 isDisabled : function() {
8233 return DOM.get(this.id).disabled; 9474 return DOM.get(this.id).disabled;
8234 }, 9475 },
8299 9540
8300 each(t.items, function(it) { 9541 each(t.items, function(it) {
8301 h += DOM.createHTML('option', {value : it.value}, it.title); 9542 h += DOM.createHTML('option', {value : it.value}, it.title);
8302 }); 9543 });
8303 9544
8304 h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox'}, h); 9545 h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox', 'aria-labelledby': t.id + '_aria'}, h);
8305 9546 h += DOM.createHTML('span', {id : t.id + '_aria', 'style': 'display: none'}, t.settings.title);
8306 return h; 9547 return h;
8307 }, 9548 },
8308 9549
8309 postRender : function() { 9550 postRender : function() {
8310 var t = this, ch; 9551 var t = this, ch, changeListenerAdded = true;
8311 9552
8312 t.rendered = true; 9553 t.rendered = true;
8313 9554
8314 function onChange(e) { 9555 function onChange(e) {
8315 var v = t.items[e.target.selectedIndex - 1]; 9556 var v = t.items[e.target.selectedIndex - 1];
8327 // Accessibility keyhandler 9568 // Accessibility keyhandler
8328 Event.add(t.id, 'keydown', function(e) { 9569 Event.add(t.id, 'keydown', function(e) {
8329 var bf; 9570 var bf;
8330 9571
8331 Event.remove(t.id, 'change', ch); 9572 Event.remove(t.id, 'change', ch);
9573 changeListenerAdded = false;
8332 9574
8333 bf = Event.add(t.id, 'blur', function() { 9575 bf = Event.add(t.id, 'blur', function() {
9576 if (changeListenerAdded) return;
9577 changeListenerAdded = true;
8334 Event.add(t.id, 'change', onChange); 9578 Event.add(t.id, 'change', onChange);
8335 Event.remove(t.id, 'blur', bf); 9579 Event.remove(t.id, 'blur', bf);
8336 }); 9580 });
8337 9581
8338 if (e.keyCode == 13 || e.keyCode == 32) { 9582 if (e.keyCode == 13 || e.keyCode == 32) {
8347 })(tinymce); 9591 })(tinymce);
8348 (function(tinymce) { 9592 (function(tinymce) {
8349 var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each; 9593 var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
8350 9594
8351 tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', { 9595 tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', {
8352 MenuButton : function(id, s) { 9596 MenuButton : function(id, s, ed) {
8353 this.parent(id, s); 9597 this.parent(id, s, ed);
8354 9598
8355 this.onRenderMenu = new tinymce.util.Dispatcher(this); 9599 this.onRenderMenu = new tinymce.util.Dispatcher(this);
8356 9600
8357 s.menu_container = s.menu_container || DOM.doc.body; 9601 s.menu_container = s.menu_container || DOM.doc.body;
8358 }, 9602 },
8395 menu_line : 1, 9639 menu_line : 1,
8396 'class' : this.classPrefix + 'Menu', 9640 'class' : this.classPrefix + 'Menu',
8397 icons : t.settings.icons 9641 icons : t.settings.icons
8398 }); 9642 });
8399 9643
8400 m.onHideMenu.add(t.hideMenu, t); 9644 m.onHideMenu.add(function() {
9645 t.hideMenu();
9646 t.focus();
9647 });
8401 9648
8402 t.onRenderMenu.dispatch(t, m); 9649 t.onRenderMenu.dispatch(t, m);
8403 t.menu = m; 9650 t.menu = m;
8404 }, 9651 },
8405 9652
8437 9684
8438 (function(tinymce) { 9685 (function(tinymce) {
8439 var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each; 9686 var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each;
8440 9687
8441 tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', { 9688 tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', {
8442 SplitButton : function(id, s) { 9689 SplitButton : function(id, s, ed) {
8443 this.parent(id, s); 9690 this.parent(id, s, ed);
8444 this.classPrefix = 'mceSplitButton'; 9691 this.classPrefix = 'mceSplitButton';
8445 }, 9692 },
8446 9693
8447 renderHTML : function() { 9694 renderHTML : function() {
8448 var h, t = this, s = t.settings, h1; 9695 var h, t = this, s = t.settings, h1;
8449 9696
8450 h = '<tbody><tr>'; 9697 h = '<tbody><tr>';
8451 9698
8452 if (s.image) 9699 if (s.image)
8453 h1 = DOM.createHTML('img ', {src : s.image, 'class' : 'mceAction ' + s['class']}); 9700 h1 = DOM.createHTML('img ', {src : s.image, role: 'presentation', 'class' : 'mceAction ' + s['class']});
8454 else 9701 else
8455 h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, ''); 9702 h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, '');
8456 9703
8457 h += '<td>' + DOM.createHTML('a', {id : t.id + '_action', href : 'javascript:;', 'class' : 'mceAction ' + s['class'], onclick : "return false;", onmousedown : 'return false;', title : s.title}, h1) + '</td>'; 9704 h1 += DOM.createHTML('span', {'class': 'mceVoiceLabel mceIconOnly', id: t.id + '_voice', style: 'display:none;'}, s.title);
9705 h += '<td >' + DOM.createHTML('a', {role: 'button', id : t.id + '_action', tabindex: '-1', href : 'javascript:;', 'class' : 'mceAction ' + s['class'], onclick : "return false;", onmousedown : 'return false;', title : s.title}, h1) + '</td>';
8458 9706
8459 h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}); 9707 h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}, '<span style="display:none;" class="mceIconOnly" aria-hidden="true">\u25BC</span>');
8460 h += '<td>' + DOM.createHTML('a', {id : t.id + '_open', href : 'javascript:;', 'class' : 'mceOpen ' + s['class'], onclick : "return false;", onmousedown : 'return false;', title : s.title}, h1) + '</td>'; 9708 h += '<td >' + DOM.createHTML('a', {role: 'button', id : t.id + '_open', tabindex: '-1', href : 'javascript:;', 'class' : 'mceOpen ' + s['class'], onclick : "return false;", onmousedown : 'return false;', title : s.title}, h1) + '</td>';
8461 9709
8462 h += '</tr></tbody>'; 9710 h += '</tr></tbody>';
8463 9711 h = DOM.createHTML('table', {id : t.id, role: 'presentation', tabindex: '0', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h);
8464 return DOM.createHTML('table', {id : t.id, 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', onmousedown : 'return false;', title : s.title}, h); 9712 return DOM.createHTML('span', {role: 'button', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h);
8465 }, 9713 },
8466 9714
8467 postRender : function() { 9715 postRender : function() {
8468 var t = this, s = t.settings; 9716 var t = this, s = t.settings, activate;
8469 9717
8470 if (s.onclick) { 9718 if (s.onclick) {
8471 Event.add(t.id + '_action', 'click', function() { 9719 activate = function(evt) {
8472 if (!t.isDisabled()) 9720 if (!t.isDisabled()) {
8473 s.onclick(t.value); 9721 s.onclick(t.value);
9722 Event.cancel(evt);
9723 }
9724 };
9725 Event.add(t.id + '_action', 'click', activate);
9726 Event.add(t.id, ['click', 'keydown'], function(evt) {
9727 var DOM_VK_SPACE = 32, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_UP = 38, DOM_VK_DOWN = 40;
9728 if ((evt.keyCode === 32 || evt.keyCode === 13 || evt.keyCode === 14) && !evt.altKey && !evt.ctrlKey && !evt.metaKey) {
9729 activate();
9730 Event.cancel(evt);
9731 } else if (evt.type === 'click' || evt.keyCode === DOM_VK_DOWN) {
9732 t.showMenu();
9733 Event.cancel(evt);
9734 }
8474 }); 9735 });
8475 } 9736 }
8476 9737
8477 Event.add(t.id + '_open', 'click', t.showMenu, t); 9738 Event.add(t.id + '_open', 'click', function (evt) {
8478 Event.add(t.id + '_open', 'focus', function() {t._focused = 1;}); 9739 t.showMenu();
8479 Event.add(t.id + '_open', 'blur', function() {t._focused = 0;}); 9740 Event.cancel(evt);
9741 });
9742 Event.add([t.id, t.id + '_open'], 'focus', function() {t._focused = 1;});
9743 Event.add([t.id, t.id + '_open'], 'blur', function() {t._focused = 0;});
8480 9744
8481 // Old IE doesn't have hover on all elements 9745 // Old IE doesn't have hover on all elements
8482 if (tinymce.isIE6 || !DOM.boxModel) { 9746 if (tinymce.isIE6 || !DOM.boxModel) {
8483 Event.add(t.id, 'mouseover', function() { 9747 Event.add(t.id, 'mouseover', function() {
8484 if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled')) 9748 if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled'))
8495 destroy : function() { 9759 destroy : function() {
8496 this.parent(); 9760 this.parent();
8497 9761
8498 Event.clear(this.id + '_action'); 9762 Event.clear(this.id + '_action');
8499 Event.clear(this.id + '_open'); 9763 Event.clear(this.id + '_open');
9764 Event.clear(this.id);
8500 } 9765 }
8501 }); 9766 });
8502 })(tinymce); 9767 })(tinymce);
8503 9768
8504 (function(tinymce) { 9769 (function(tinymce) {
8505 var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each; 9770 var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each;
8506 9771
8507 tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', { 9772 tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', {
8508 ColorSplitButton : function(id, s) { 9773 ColorSplitButton : function(id, s, ed) {
8509 var t = this; 9774 var t = this;
8510 9775
8511 t.parent(id, s); 9776 t.parent(id, s, ed);
8512 9777
8513 t.settings = s = tinymce.extend({ 9778 t.settings = s = tinymce.extend({
8514 colors : '000000,993300,333300,003300,003366,000080,333399,333333,800000,FF6600,808000,008000,008080,0000FF,666699,808080,FF0000,FF9900,99CC00,339966,33CCCC,3366FF,800080,999999,FF00FF,FFCC00,FFFF00,00FF00,00FFFF,00CCFF,993366,C0C0C0,FF99CC,FFCC99,FFFF99,CCFFCC,CCFFFF,99CCFF,CC99FF,FFFFFF', 9779 colors : '000000,993300,333300,003300,003366,000080,333399,333333,800000,FF6600,808000,008000,008080,0000FF,666699,808080,FF0000,FF9900,99CC00,339966,33CCCC,3366FF,800080,999999,FF00FF,FFCC00,FFFF00,00FF00,00FFFF,00CCFF,993366,C0C0C0,FF99CC,FFCC99,FFFF99,CCFFCC,CCFFFF,99CCFF,CC99FF,FFFFFF',
8515 grid_width : 8, 9780 grid_width : 8,
8516 default_color : '#888888' 9781 default_color : '#888888'
8564 }, 9829 },
8565 9830
8566 hideMenu : function(e) { 9831 hideMenu : function(e) {
8567 var t = this; 9832 var t = this;
8568 9833
8569 // Prevent double toogles by canceling the mouse click event to the button 9834 if (t.isMenuVisible) {
8570 if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';})) 9835 // Prevent double toogles by canceling the mouse click event to the button
8571 return; 9836 if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';}))
8572 9837 return;
8573 if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) { 9838
8574 DOM.removeClass(t.id, 'mceSplitButtonSelected'); 9839 if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) {
8575 Event.remove(DOM.doc, 'mousedown', t.hideMenu, t); 9840 DOM.removeClass(t.id, 'mceSplitButtonSelected');
8576 Event.remove(t.id + '_menu', 'keydown', t._keyHandler); 9841 Event.remove(DOM.doc, 'mousedown', t.hideMenu, t);
8577 DOM.hide(t.id + '_menu'); 9842 Event.remove(t.id + '_menu', 'keydown', t._keyHandler);
8578 } 9843 DOM.hide(t.id + '_menu');
8579 9844 }
8580 t.onHideMenu.dispatch(t); 9845
8581 9846 t.isMenuVisible = 0;
8582 t.isMenuVisible = 0; 9847 }
8583 }, 9848 },
8584 9849
8585 renderMenu : function() { 9850 renderMenu : function() {
8586 var t = this, m, i = 0, s = t.settings, n, tb, tr, w; 9851 var t = this, m, i = 0, s = t.settings, n, tb, tr, w, context;
8587 9852
8588 w = DOM.add(s.menu_container, 'div', {id : t.id + '_menu', 'class' : s['menu_class'] + ' ' + s['class'], style : 'position:absolute;left:0;top:-1000px;'}); 9853 w = DOM.add(s.menu_container, 'div', {role: 'listbox', id : t.id + '_menu', 'class' : s['menu_class'] + ' ' + s['class'], style : 'position:absolute;left:0;top:-1000px;'});
8589 m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'}); 9854 m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'});
8590 DOM.add(m, 'span', {'class' : 'mceMenuLine'}); 9855 DOM.add(m, 'span', {'class' : 'mceMenuLine'});
8591 9856
8592 n = DOM.add(m, 'table', {'class' : 'mceColorSplitMenu'}); 9857 n = DOM.add(m, 'table', {role: 'presentation', 'class' : 'mceColorSplitMenu'});
8593 tb = DOM.add(n, 'tbody'); 9858 tb = DOM.add(n, 'tbody');
8594 9859
8595 // Generate color grid 9860 // Generate color grid
8596 i = 0; 9861 i = 0;
8597 each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) { 9862 each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) {
8601 tr = DOM.add(tb, 'tr'); 9866 tr = DOM.add(tb, 'tr');
8602 i = s.grid_width - 1; 9867 i = s.grid_width - 1;
8603 } 9868 }
8604 9869
8605 n = DOM.add(tr, 'td'); 9870 n = DOM.add(tr, 'td');
8606
8607 n = DOM.add(n, 'a', { 9871 n = DOM.add(n, 'a', {
9872 role : 'option',
8608 href : 'javascript:;', 9873 href : 'javascript:;',
8609 style : { 9874 style : {
8610 backgroundColor : '#' + c 9875 backgroundColor : '#' + c
8611 }, 9876 },
8612 _mce_color : '#' + c 9877 'title': t.editor.getLang('colors.' + c, c),
9878 'data-mce-color' : '#' + c
8613 }); 9879 });
9880
9881 if (t.editor.forcedHighContrastMode) {
9882 n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' });
9883 if (n.getContext && (context = n.getContext("2d"))) {
9884 context.fillStyle = '#' + c;
9885 context.fillRect(0, 0, 16, 16);
9886 } else {
9887 // No point leaving a canvas element around if it's not supported for drawing on anyway.
9888 DOM.remove(n);
9889 }
9890 }
8614 }); 9891 });
8615 9892
8616 if (s.more_colors_func) { 9893 if (s.more_colors_func) {
8617 n = DOM.add(tb, 'tr'); 9894 n = DOM.add(tb, 'tr');
8618 n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'}); 9895 n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'});
8619 n = DOM.add(n, 'a', {id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title); 9896 n = DOM.add(n, 'a', {role: 'option', id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title);
8620 9897
8621 Event.add(n, 'click', function(e) { 9898 Event.add(n, 'click', function(e) {
8622 s.more_colors_func.call(s.more_colors_scope || this); 9899 s.more_colors_func.call(s.more_colors_scope || this);
8623 return Event.cancel(e); // Cancel to fix onbeforeunload problem 9900 return Event.cancel(e); // Cancel to fix onbeforeunload problem
8624 }); 9901 });
8625 } 9902 }
8626 9903
8627 DOM.addClass(m, 'mceColorSplitMenu'); 9904 DOM.addClass(m, 'mceColorSplitMenu');
9905
9906 new tinymce.ui.KeyboardNavigation({
9907 root: t.id + '_menu',
9908 items: DOM.select('a', t.id + '_menu'),
9909 onCancel: function() {
9910 t.hideMenu();
9911 t.focus();
9912 }
9913 });
9914
9915 // Prevent IE from scrolling and hindering click to occur #4019
9916 Event.add(t.id + '_menu', 'mousedown', function(e) {return Event.cancel(e);});
8628 9917
8629 Event.add(t.id + '_menu', 'click', function(e) { 9918 Event.add(t.id + '_menu', 'click', function(e) {
8630 var c; 9919 var c;
8631 9920
8632 e = e.target; 9921 e = DOM.getParent(e.target, 'a', tb);
8633 9922
8634 if (e.nodeName == 'A' && (c = e.getAttribute('_mce_color'))) 9923 if (e && e.nodeName.toLowerCase() == 'a' && (c = e.getAttribute('data-mce-color')))
8635 t.setColor(c); 9924 t.setColor(c);
8636 9925
8637 return Event.cancel(e); // Prevent IE auto save warning 9926 return Event.cancel(e); // Prevent IE auto save warning
8638 }); 9927 });
8639 9928
8640 return w; 9929 return w;
8641 }, 9930 },
8642 9931
8643 setColor : function(c) { 9932 setColor : function(c) {
9933 this.displayColor(c);
9934 this.hideMenu();
9935 this.settings.onselect(c);
9936 },
9937
9938 displayColor : function(c) {
8644 var t = this; 9939 var t = this;
8645 9940
8646 DOM.setStyle(t.id + '_preview', 'backgroundColor', c); 9941 DOM.setStyle(t.id + '_preview', 'backgroundColor', c);
8647 9942
8648 t.value = c; 9943 t.value = c;
8649 t.hideMenu();
8650 t.settings.onselect(c);
8651 }, 9944 },
8652 9945
8653 postRender : function() { 9946 postRender : function() {
8654 var t = this, id = t.id; 9947 var t = this, id = t.id;
8655 9948
8666 DOM.remove(this.id + '_menu'); 9959 DOM.remove(this.id + '_menu');
8667 } 9960 }
8668 }); 9961 });
8669 })(tinymce); 9962 })(tinymce);
8670 9963
9964 (function(tinymce) {
9965 // Shorten class names
9966 var dom = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event;
9967 tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', {
9968 renderHTML : function() {
9969 var t = this, h = [], controls = t.controls, each = tinymce.each, settings = t.settings;
9970
9971 h.push('<div id="' + t.id + '" role="group" aria-labelledby="' + t.id + '_voice">');
9972 //TODO: ACC test this out - adding a role = application for getting the landmarks working well.
9973 h.push("<span role='application'>");
9974 h.push('<span id="' + t.id + '_voice" class="mceVoiceLabel" style="display:none;">' + dom.encode(settings.name) + '</span>');
9975 each(controls, function(toolbar) {
9976 h.push(toolbar.renderHTML());
9977 });
9978 h.push("</span>");
9979 h.push('</div>');
9980
9981 return h.join('');
9982 },
9983
9984 focus : function() {
9985 this.keyNav.focus();
9986 },
9987
9988 postRender : function() {
9989 var t = this, items = [];
9990
9991 each(t.controls, function(toolbar) {
9992 each (toolbar.controls, function(control) {
9993 if (control.id) {
9994 items.push(control);
9995 }
9996 });
9997 });
9998
9999 t.keyNav = new tinymce.ui.KeyboardNavigation({
10000 root: t.id,
10001 items: items,
10002 onCancel: function() {
10003 t.editor.focus();
10004 },
10005 excludeFromTabOrder: !t.settings.tab_focus_toolbar
10006 });
10007 },
10008
10009 destroy : function() {
10010 var self = this;
10011
10012 self.parent();
10013 self.keyNav.destroy();
10014 Event.clear(self.id);
10015 }
10016 });
10017 })(tinymce);
10018
10019 (function(tinymce) {
10020 // Shorten class names
10021 var dom = tinymce.DOM, each = tinymce.each;
8671 tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { 10022 tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', {
8672 renderHTML : function() { 10023 renderHTML : function() {
8673 var t = this, h = '', c, co, dom = tinymce.DOM, s = t.settings, i, pr, nx, cl; 10024 var t = this, h = '', c, co, s = t.settings, i, pr, nx, cl;
8674 10025
8675 cl = t.controls; 10026 cl = t.controls;
8676 for (i=0; i<cl.length; i++) { 10027 for (i=0; i<cl.length; i++) {
8677 // Get current control, prev control, next control and if the control is a list box or not 10028 // Get current control, prev control, next control and if the control is a list box or not
8678 co = cl[i]; 10029 co = cl[i];
8725 else if (co.ListBox) 10076 else if (co.ListBox)
8726 c += ' mceToolbarEndListBox'; 10077 c += ' mceToolbarEndListBox';
8727 10078
8728 h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->')); 10079 h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '<!-- IE -->'));
8729 10080
8730 return dom.createHTML('table', {id : t.id, 'class' : 'mceToolbar' + (s['class'] ? ' ' + s['class'] : ''), cellpadding : '0', cellspacing : '0', align : t.settings.align || ''}, '<tbody><tr>' + h + '</tr></tbody>'); 10081 return dom.createHTML('table', {id : t.id, 'class' : 'mceToolbar' + (s['class'] ? ' ' + s['class'] : ''), cellpadding : '0', cellspacing : '0', align : t.settings.align || '', role: 'presentation', tabindex: '-1'}, '<tbody><tr>' + h + '</tr></tbody>');
8731 } 10082 }
8732 }); 10083 });
10084 })(tinymce);
8733 10085
8734 (function(tinymce) { 10086 (function(tinymce) {
8735 var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each; 10087 var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each;
8736 10088
8737 tinymce.create('tinymce.AddOnManager', { 10089 tinymce.create('tinymce.AddOnManager', {
8749 }, 10101 },
8750 10102
8751 requireLangPack : function(n) { 10103 requireLangPack : function(n) {
8752 var s = tinymce.settings; 10104 var s = tinymce.settings;
8753 10105
8754 if (s && s.language) 10106 if (s && s.language && s.language_load !== false)
8755 tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js'); 10107 tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js');
8756 }, 10108 },
8757 10109
8758 add : function(id, o) { 10110 add : function(id, o) {
8759 this.items.push(o); 10111 this.items.push(o);
8768 10120
8769 if (t.urls[n]) 10121 if (t.urls[n])
8770 return; 10122 return;
8771 10123
8772 if (u.indexOf('/') != 0 && u.indexOf('://') == -1) 10124 if (u.indexOf('/') != 0 && u.indexOf('://') == -1)
8773 u = tinymce.baseURL + '/' + u; 10125 u = tinymce.baseURL + '/' + u;
8774 10126
8775 t.urls[n] = u.substring(0, u.lastIndexOf('/')); 10127 t.urls[n] = u.substring(0, u.lastIndexOf('/'));
8776 10128
8777 if (!t.lookup[n]) 10129 if (!t.lookup[n])
8778 tinymce.ScriptLoader.add(u, cb, s); 10130 tinymce.ScriptLoader.add(u, cb, s);
9230 visual : 1, 10582 visual : 1,
9231 font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large', 10583 font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large',
9232 apply_source_formatting : 1, 10584 apply_source_formatting : 1,
9233 directionality : 'ltr', 10585 directionality : 'ltr',
9234 forced_root_block : 'p', 10586 forced_root_block : 'p',
9235 valid_elements : '@[id|class|style|title|dir<ltr?rtl|lang|xml::lang|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],a[rel|rev|charset|hreflang|tabindex|accesskey|type|name|href|target|title|class|onfocus|onblur],strong/b,em/i,strike,u,#p,-ol[type|compact],-ul[type|compact],-li,br,img[longdesc|usemap|src|border|alt=|title|hspace|vspace|width|height|align],-sub,-sup,-blockquote[cite],-table[border|cellspacing|cellpadding|width|frame|rules|height|align|summary|bgcolor|background|bordercolor],-tr[rowspan|width|height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,#td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor|scope],#th[colspan|rowspan|width|height|align|valign|scope],caption,-div,-span,-code,-pre,address,-h1,-h2,-h3,-h4,-h5,-h6,hr[size|noshade],-font[face|size|color],dd,dl,dt,cite,abbr,acronym,del[datetime|cite],ins[datetime|cite],object[classid|width|height|codebase|*],param[name|value],embed[type|width|height|src|*],script[src|type],map[name],area[shape|coords|href|alt|target],bdo,button,col[align|char|charoff|span|valign|width],colgroup[align|char|charoff|span|valign|width],dfn,fieldset,form[action|accept|accept-charset|enctype|method],input[accept|alt|checked|disabled|maxlength|name|readonly|size|src|type|value|tabindex|accesskey],kbd,label[for],legend,noscript,optgroup[label|disabled],option[disabled|label|selected|value],q[cite],samp,select[disabled|multiple|name|size],small,textarea[cols|rows|disabled|name|readonly],tt,var,big',
9236 hidden_input : 1, 10587 hidden_input : 1,
9237 padd_empty_editor : 1, 10588 padd_empty_editor : 1,
9238 render_ui : 1, 10589 render_ui : 1,
9239 init_theme : 1, 10590 init_theme : 1,
9240 force_p_newlines : 1, 10591 force_p_newlines : 1,
9241 indentation : '30px', 10592 indentation : '30px',
9242 keep_styles : 1, 10593 keep_styles : 1,
9243 fix_table_elements : 1, 10594 fix_table_elements : 1,
9244 inline_styles : 1, 10595 inline_styles : 1,
9245 convert_fonts_to_spans : true 10596 convert_fonts_to_spans : true,
10597 indent : 'simple',
10598 indent_before : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr',
10599 indent_after : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr',
10600 validate : true,
10601 entity_encoding : 'named',
10602 url_converter : t.convertURL,
10603 url_converter_scope : t,
10604 ie7_compat : true
9246 }, s); 10605 }, s);
9247 10606
9248 t.documentBaseURI = new tinymce.util.URI(s.document_base_url || tinymce.documentBaseURL, { 10607 t.documentBaseURI = new tinymce.util.URI(s.document_base_url || tinymce.documentBaseURL, {
9249 base_uri : tinyMCE.baseURI 10608 base_uri : tinyMCE.baseURI
9250 }); 10609 });
9251 10610
9252 t.baseURI = tinymce.baseURI; 10611 t.baseURI = tinymce.baseURI;
10612
10613 t.contentCSS = [];
9253 10614
9254 // Call setup 10615 // Call setup
9255 t.execCallback('setup', t); 10616 t.execCallback('setup', t);
9256 }, 10617 },
9257 10618
9338 }); 10699 });
9339 } 10700 }
9340 10701
9341 // Load scripts 10702 // Load scripts
9342 function loadScripts() { 10703 function loadScripts() {
9343 if (s.language) 10704 if (s.language && s.language_load !== false)
9344 sl.add(tinymce.baseURL + '/langs/' + s.language + '.js'); 10705 sl.add(tinymce.baseURL + '/langs/' + s.language + '.js');
9345 10706
9346 if (s.theme && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme]) 10707 if (s.theme && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme])
9347 ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js'); 10708 ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js');
9348 10709
9365 10726
9366 loadScripts(); 10727 loadScripts();
9367 }, 10728 },
9368 10729
9369 init : function() { 10730 init : function() {
9370 var n, t = this, s = t.settings, w, h, e = t.getElement(), o, ti, u, bi, bc, re; 10731 var n, t = this, s = t.settings, w, h, e = t.getElement(), o, ti, u, bi, bc, re, i;
9371 10732
9372 tinymce.add(t); 10733 tinymce.add(t);
10734
10735 s.aria_label = s.aria_label || DOM.getAttrib(e, 'aria-label', t.getLang('aria.rich_text_area'));
9373 10736
9374 if (s.theme) { 10737 if (s.theme) {
9375 s.theme = s.theme.replace(/-/, ''); 10738 s.theme = s.theme.replace(/-/, '');
9376 o = ThemeManager.get(s.theme); 10739 o = ThemeManager.get(s.theme);
9377 t.theme = new o(); 10740 t.theme = new o();
9406 s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add); 10769 s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add);
9407 10770
9408 t.controlManager = new tinymce.ControlManager(t); 10771 t.controlManager = new tinymce.ControlManager(t);
9409 10772
9410 if (s.custom_undo_redo) { 10773 if (s.custom_undo_redo) {
9411 // Add initial undo level
9412 t.onBeforeExecCommand.add(function(ed, cmd, ui, val, a) { 10774 t.onBeforeExecCommand.add(function(ed, cmd, ui, val, a) {
9413 if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo)) { 10775 if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
9414 if (!t.undoManager.hasUndo()) 10776 t.undoManager.beforeChange();
9415 t.undoManager.add();
9416 }
9417 }); 10777 });
9418 10778
9419 t.onExecCommand.add(function(ed, cmd, ui, val, a) { 10779 t.onExecCommand.add(function(ed, cmd, ui, val, a) {
9420 if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo)) 10780 if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo))
9421 t.undoManager.add(); 10781 t.undoManager.add();
9477 DOM.setStyles(o.sizeContainer || o.editorContainer, { 10837 DOM.setStyles(o.sizeContainer || o.editorContainer, {
9478 width : w, 10838 width : w,
9479 height : h 10839 height : h
9480 }); 10840 });
9481 10841
10842 // Load specified content CSS last
10843 if (s.content_css) {
10844 tinymce.each(explode(s.content_css), function(u) {
10845 t.contentCSS.push(t.documentBaseURI.toAbsolute(u));
10846 });
10847 }
10848
9482 h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : ''); 10849 h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : '');
9483 if (h < 100) 10850 if (h < 100)
9484 h = 100; 10851 h = 100;
9485 10852
9486 t.iframeHTML = s.doctype + '<html><head xmlns="http://www.w3.org/1999/xhtml">'; 10853 t.iframeHTML = s.doctype + '<html><head xmlns="http://www.w3.org/1999/xhtml">';
9488 // We only need to override paths if we have to 10855 // We only need to override paths if we have to
9489 // IE has a bug where it remove site absolute urls to relative ones if this is specified 10856 // IE has a bug where it remove site absolute urls to relative ones if this is specified
9490 if (s.document_base_url != tinymce.documentBaseURL) 10857 if (s.document_base_url != tinymce.documentBaseURL)
9491 t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />'; 10858 t.iframeHTML += '<base href="' + t.documentBaseURI.getURI() + '" />';
9492 10859
9493 t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'; 10860 // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode.
9494 10861 if (s.ie7_compat)
9495 if (tinymce.relaxedDomain) 10862 t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" />';
9496 t.iframeHTML += '<script type="text/javascript">document.domain = "' + tinymce.relaxedDomain + '";</script>'; 10863 else
10864 t.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=edge" />';
10865
10866 t.iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
10867
10868 // Firefox 2 doesn't load stylesheets correctly this way
10869 if (!isGecko || !/Firefox\/2/.test(navigator.userAgent)) {
10870 for (i = 0; i < t.contentCSS.length; i++)
10871 t.iframeHTML += '<link type="text/css" rel="stylesheet" href="' + t.contentCSS[i] + '" />';
10872
10873 t.contentCSS = [];
10874 }
9497 10875
9498 bi = s.body_id || 'tinymce'; 10876 bi = s.body_id || 'tinymce';
9499 if (bi.indexOf('=') != -1) { 10877 if (bi.indexOf('=') != -1) {
9500 bi = t.getParam('body_id', '', 'hash'); 10878 bi = t.getParam('body_id', '', 'hash');
9501 bi = bi[t.id] || bi; 10879 bi = bi[t.id] || bi;
9508 } 10886 }
9509 10887
9510 t.iframeHTML += '</head><body id="' + bi + '" class="mceContentBody ' + bc + '"></body></html>'; 10888 t.iframeHTML += '</head><body id="' + bi + '" class="mceContentBody ' + bc + '"></body></html>';
9511 10889
9512 // Domain relaxing enabled, then set document domain 10890 // Domain relaxing enabled, then set document domain
9513 if (tinymce.relaxedDomain) { 10891 if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) {
9514 // We need to write the contents here in IE since multiple writes messes up refresh button and back button 10892 // We need to write the contents here in IE since multiple writes messes up refresh button and back button
9515 if (isIE || (tinymce.isOpera && parseFloat(opera.version()) >= 9.5)) 10893 u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";var ed = window.parent.tinyMCE.get("' + t.id + '");document.write(ed.iframeHTML);document.close();ed.setupIframe();})()';
9516 u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";var ed = window.parent.tinyMCE.get("' + t.id + '");document.write(ed.iframeHTML);document.close();ed.setupIframe();})()';
9517 else if (tinymce.isOpera)
9518 u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";document.close();ed.setupIframe();})()';
9519 } 10894 }
9520 10895
9521 // Create iframe 10896 // Create iframe
9522 n = DOM.add(o.iframeContainer, 'iframe', { 10897 // TODO: ACC add the appropriate description on this.
10898 n = DOM.add(o.iframeContainer, 'iframe', {
9523 id : t.id + "_ifr", 10899 id : t.id + "_ifr",
9524 src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7 10900 src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7
9525 frameBorder : '0', 10901 frameBorder : '0',
10902 title : s.aria_label,
9526 style : { 10903 style : {
9527 width : '100%', 10904 width : '100%',
9528 height : h 10905 height : h
9529 } 10906 }
9530 }); 10907 });
9531 10908
9532 t.contentAreaContainer = o.iframeContainer; 10909 t.contentAreaContainer = o.iframeContainer;
9533 DOM.get(o.editorContainer).style.display = t.orgDisplay; 10910 DOM.get(o.editorContainer).style.display = t.orgDisplay;
9534 DOM.get(t.id).style.display = 'none'; 10911 DOM.get(t.id).style.display = 'none';
9535 10912 DOM.setAttrib(t.id, 'aria-hidden', true);
9536 if (!isIE || !tinymce.relaxedDomain) 10913
10914 if (!tinymce.relaxedDomain || !u)
9537 t.setupIframe(); 10915 t.setupIframe();
9538 10916
9539 e = n = o = null; // Cleanup 10917 e = n = o = null; // Cleanup
9540 }, 10918 },
9541 10919
9545 // Setup iframe body 10923 // Setup iframe body
9546 if (!isIE || !tinymce.relaxedDomain) { 10924 if (!isIE || !tinymce.relaxedDomain) {
9547 d.open(); 10925 d.open();
9548 d.write(t.iframeHTML); 10926 d.write(t.iframeHTML);
9549 d.close(); 10927 d.close();
10928
10929 if (tinymce.relaxedDomain)
10930 d.domain = tinymce.relaxedDomain;
9550 } 10931 }
9551 10932
9552 // Design mode needs to be added here Ctrl+A will fail otherwise 10933 // Design mode needs to be added here Ctrl+A will fail otherwise
9553 if (!isIE) { 10934 if (!isIE) {
9554 try { 10935 try {
9570 b.contentEditable = true; 10951 b.contentEditable = true;
9571 10952
9572 DOM.show(b); 10953 DOM.show(b);
9573 } 10954 }
9574 10955
10956 t.schema = new tinymce.html.Schema(s);
10957
9575 t.dom = new tinymce.dom.DOMUtils(t.getDoc(), { 10958 t.dom = new tinymce.dom.DOMUtils(t.getDoc(), {
9576 keep_values : true, 10959 keep_values : true,
9577 url_converter : t.convertURL, 10960 url_converter : t.convertURL,
9578 url_converter_scope : t, 10961 url_converter_scope : t,
9579 hex_colors : s.force_hex_style_colors, 10962 hex_colors : s.force_hex_style_colors,
9580 class_filter : s.class_filter, 10963 class_filter : s.class_filter,
9581 update_styles : 1, 10964 update_styles : 1,
9582 fix_ie_paragraphs : 1, 10965 fix_ie_paragraphs : 1,
9583 valid_styles : s.valid_styles 10966 schema : t.schema
9584 }); 10967 });
9585 10968
9586 t.schema = new tinymce.dom.Schema(); 10969 t.parser = new tinymce.html.DomParser(s, t.schema);
9587 10970
9588 t.serializer = new tinymce.dom.Serializer(extend(s, { 10971 // Force anchor names closed
9589 valid_elements : s.verify_html === false ? '*[*]' : s.valid_elements, 10972 t.parser.addAttributeFilter('name', function(nodes, name) {
9590 dom : t.dom, 10973 var i = nodes.length, sibling, prevSibling, parent, node;
9591 schema : t.schema 10974
9592 })); 10975 while (i--) {
10976 node = nodes[i];
10977 if (node.name === 'a' && node.firstChild) {
10978 parent = node.parent;
10979
10980 // Move children after current node
10981 sibling = node.lastChild;
10982 do {
10983 prevSibling = sibling.prev;
10984 parent.insert(sibling, node);
10985 sibling = prevSibling;
10986 } while (sibling);
10987 }
10988 }
10989 });
10990
10991 // Convert src and href into data-mce-src, data-mce-href and data-mce-style
10992 t.parser.addAttributeFilter('src,href,style', function(nodes, name) {
10993 var i = nodes.length, node, dom = t.dom, value;
10994
10995 while (i--) {
10996 node = nodes[i];
10997 value = node.attr(name);
10998
10999 if (name === "style")
11000 node.attr('data-mce-style', dom.serializeStyle(dom.parseStyle(value), node.name));
11001 else
11002 node.attr('data-mce-' + name, t.convertURL(value, name, node.name));
11003 }
11004 });
11005
11006 // Keep scripts from executing
11007 t.parser.addNodeFilter('script', function(nodes, name) {
11008 var i = nodes.length;
11009
11010 while (i--)
11011 nodes[i].attr('type', 'mce-text/javascript');
11012 });
11013
11014 t.parser.addNodeFilter('#cdata', function(nodes, name) {
11015 var i = nodes.length, node;
11016
11017 while (i--) {
11018 node = nodes[i];
11019 node.type = 8;
11020 node.name = '#comment';
11021 node.value = '[CDATA[' + node.value + ']]';
11022 }
11023 });
11024
11025 t.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes, name) {
11026 var i = nodes.length, node, nonEmptyElements = t.schema.getNonEmptyElements();
11027
11028 while (i--) {
11029 node = nodes[i];
11030
11031 if (node.isEmpty(nonEmptyElements))
11032 node.empty().append(new tinymce.html.Node('br', 1)).shortEnded = true;
11033 }
11034 });
11035
11036 t.serializer = new tinymce.dom.Serializer(s, t.dom, t.schema);
9593 11037
9594 t.selection = new tinymce.dom.Selection(t.dom, t.getWin(), t.serializer); 11038 t.selection = new tinymce.dom.Selection(t.dom, t.getWin(), t.serializer);
9595 11039
9596 t.formatter = new tinymce.Formatter(this); 11040 t.formatter = new tinymce.Formatter(this);
9597 11041
9598 // Register default formats 11042 // Register default formats
9599 t.formatter.register({ 11043 t.formatter.register({
9600 alignleft : [ 11044 alignleft : [
9601 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}}, 11045 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}},
9602 {selector : 'img,table', styles : {'float' : 'left'}} 11046 {selector : 'img,table', collapsed : false, styles : {'float' : 'left'}}
9603 ], 11047 ],
9604 11048
9605 aligncenter : [ 11049 aligncenter : [
9606 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}}, 11050 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}},
9607 {selector : 'img', styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}}, 11051 {selector : 'img', collapsed : false, styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}},
9608 {selector : 'table', styles : {marginLeft : 'auto', marginRight : 'auto'}} 11052 {selector : 'table', collapsed : false, styles : {marginLeft : 'auto', marginRight : 'auto'}}
9609 ], 11053 ],
9610 11054
9611 alignright : [ 11055 alignright : [
9612 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}}, 11056 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}},
9613 {selector : 'img,table', styles : {'float' : 'right'}} 11057 {selector : 'img,table', collapsed : false, styles : {'float' : 'right'}}
9614 ], 11058 ],
9615 11059
9616 alignfull : [ 11060 alignfull : [
9617 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}} 11061 {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}}
9618 ], 11062 ],
9619 11063
9620 bold : [ 11064 bold : [
9621 {inline : 'strong'}, 11065 {inline : 'strong', remove : 'all'},
9622 {inline : 'span', styles : {fontWeight : 'bold'}}, 11066 {inline : 'span', styles : {fontWeight : 'bold'}},
9623 {inline : 'b'} 11067 {inline : 'b', remove : 'all'}
9624 ], 11068 ],
9625 11069
9626 italic : [ 11070 italic : [
9627 {inline : 'em'}, 11071 {inline : 'em', remove : 'all'},
9628 {inline : 'span', styles : {fontStyle : 'italic'}}, 11072 {inline : 'span', styles : {fontStyle : 'italic'}},
9629 {inline : 'i'} 11073 {inline : 'i', remove : 'all'}
9630 ], 11074 ],
9631 11075
9632 underline : [ 11076 underline : [
9633 {inline : 'span', styles : {textDecoration : 'underline'}, exact : true}, 11077 {inline : 'span', styles : {textDecoration : 'underline'}, exact : true},
9634 {inline : 'u'} 11078 {inline : 'u', remove : 'all'}
9635 ], 11079 ],
9636 11080
9637 strikethrough : [ 11081 strikethrough : [
9638 {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true}, 11082 {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true},
9639 {inline : 'u'} 11083 {inline : 'strike', remove : 'all'}
9640 ], 11084 ],
9641 11085
9642 forecolor : {inline : 'span', styles : {color : '%value'}}, 11086 forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false},
9643 hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}}, 11087 hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false},
9644 fontname : {inline : 'span', styles : {fontFamily : '%value'}}, 11088 fontname : {inline : 'span', styles : {fontFamily : '%value'}},
9645 fontsize : {inline : 'span', styles : {fontSize : '%value'}}, 11089 fontsize : {inline : 'span', styles : {fontSize : '%value'}},
9646 fontsize_class : {inline : 'span', attributes : {'class' : '%value'}}, 11090 fontsize_class : {inline : 'span', attributes : {'class' : '%value'}},
9647 blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'}, 11091 blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'},
11092 subscript : {inline : 'sub'},
11093 superscript : {inline : 'sup'},
9648 11094
9649 removeformat : [ 11095 removeformat : [
9650 {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true}, 11096 {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true},
9651 {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true}, 11097 {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true},
9652 {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true} 11098 {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true}
9663 11109
9664 t.undoManager = new tinymce.UndoManager(t); 11110 t.undoManager = new tinymce.UndoManager(t);
9665 11111
9666 // Pass through 11112 // Pass through
9667 t.undoManager.onAdd.add(function(um, l) { 11113 t.undoManager.onAdd.add(function(um, l) {
9668 if (!l.initial) 11114 if (um.hasUndo())
9669 return t.onChange.dispatch(t, l, um); 11115 return t.onChange.dispatch(t, l, um);
9670 }); 11116 });
9671 11117
9672 t.undoManager.onUndo.add(function(um, l) { 11118 t.undoManager.onUndo.add(function(um, l) {
9673 return t.onUndo.dispatch(t, l, um); 11119 return t.onUndo.dispatch(t, l, um);
9707 t.getBody().dir = s.directionality; 11153 t.getBody().dir = s.directionality;
9708 11154
9709 if (s.nowrap) 11155 if (s.nowrap)
9710 t.getBody().style.whiteSpace = "nowrap"; 11156 t.getBody().style.whiteSpace = "nowrap";
9711 11157
9712 if (s.custom_elements) {
9713 function handleCustom(ed, o) {
9714 each(explode(s.custom_elements), function(v) {
9715 var n;
9716
9717 if (v.indexOf('~') === 0) {
9718 v = v.substring(1);
9719 n = 'span';
9720 } else
9721 n = 'div';
9722
9723 o.content = o.content.replace(new RegExp('<(' + v + ')([^>]*)>', 'g'), '<' + n + ' _mce_name="$1"$2>');
9724 o.content = o.content.replace(new RegExp('</(' + v + ')>', 'g'), '</' + n + '>');
9725 });
9726 };
9727
9728 t.onBeforeSetContent.add(handleCustom);
9729 t.onPostProcess.add(function(ed, o) {
9730 if (o.set)
9731 handleCustom(ed, o);
9732 });
9733 }
9734
9735 if (s.handle_node_change_callback) { 11158 if (s.handle_node_change_callback) {
9736 t.onNodeChange.add(function(ed, cm, n) { 11159 t.onNodeChange.add(function(ed, cm, n) {
9737 t.execCallback('handle_node_change_callback', t.id, n, -1, -1, true, t.selection.isCollapsed()); 11160 t.execCallback('handle_node_change_callback', t.id, n, -1, -1, true, t.selection.isCollapsed());
9738 }); 11161 });
9739 } 11162 }
9751 t.onChange.add(function(ed, l) { 11174 t.onChange.add(function(ed, l) {
9752 t.execCallback('onchange_callback', t, l); 11175 t.execCallback('onchange_callback', t, l);
9753 }); 11176 });
9754 } 11177 }
9755 11178
11179 if (s.protect) {
11180 t.onBeforeSetContent.add(function(ed, o) {
11181 if (s.protect) {
11182 each(s.protect, function(pattern) {
11183 o.content = o.content.replace(pattern, function(str) {
11184 return '<!--mce:protected ' + escape(str) + '-->';
11185 });
11186 });
11187 }
11188 });
11189 }
11190
9756 if (s.convert_newlines_to_brs) { 11191 if (s.convert_newlines_to_brs) {
9757 t.onBeforeSetContent.add(function(ed, o) { 11192 t.onBeforeSetContent.add(function(ed, o) {
9758 if (o.initial) 11193 if (o.initial)
9759 o.content = o.content.replace(/\r?\n/g, '<br />'); 11194 o.content = o.content.replace(/\r?\n/g, '<br />');
9760 });
9761 }
9762
9763 if (s.fix_nesting && isIE) {
9764 t.onBeforeSetContent.add(function(ed, o) {
9765 o.content = t._fixNesting(o.content);
9766 }); 11195 });
9767 } 11196 }
9768 11197
9769 if (s.preformatted) { 11198 if (s.preformatted) {
9770 t.onPostProcess.add(function(ed, o) { 11199 t.onPostProcess.add(function(ed, o) {
9857 function fixLinks(ed, o) { 11286 function fixLinks(ed, o) {
9858 each(ed.dom.select('a'), function(n) { 11287 each(ed.dom.select('a'), function(n) {
9859 var pn = n.parentNode; 11288 var pn = n.parentNode;
9860 11289
9861 if (ed.dom.isBlock(pn) && pn.lastChild === n) 11290 if (ed.dom.isBlock(pn) && pn.lastChild === n)
9862 ed.dom.add(pn, 'br', {'_mce_bogus' : 1}); 11291 ed.dom.add(pn, 'br', {'data-mce-bogus' : 1});
9863 }); 11292 });
9864 }; 11293 };
9865 11294
9866 t.onExecCommand.add(function(ed, cmd) { 11295 t.onExecCommand.add(function(ed, cmd) {
9867 if (cmd === 'CreateLink') 11296 if (cmd === 'CreateLink')
9886 // A small timeout was needed since firefox will remove. Bug: #1838304 11315 // A small timeout was needed since firefox will remove. Bug: #1838304
9887 setTimeout(function () { 11316 setTimeout(function () {
9888 if (t.removed) 11317 if (t.removed)
9889 return; 11318 return;
9890 11319
9891 t.load({initial : true, format : (s.cleanup_on_startup ? 'html' : 'raw')}); 11320 t.load({initial : true, format : 'html'});
9892 t.startContent = t.getContent({format : 'raw'}); 11321 t.startContent = t.getContent({format : 'raw'});
11322 t.undoManager.add();
9893 t.initialized = true; 11323 t.initialized = true;
9894 11324
9895 t.onInit.dispatch(t); 11325 t.onInit.dispatch(t);
9896 t.execCallback('setupcontent_callback', t.id, t.getBody(), t.getDoc()); 11326 t.execCallback('setupcontent_callback', t.id, t.getBody(), t.getDoc());
9897 t.execCallback('init_instance_callback', t); 11327 t.execCallback('init_instance_callback', t);
9898 t.focus(true); 11328 t.focus(true);
9899 t.nodeChanged({initial : 1}); 11329 t.nodeChanged({initial : 1});
9900 11330
9901 // Load specified content CSS last 11331 // Load specified content CSS last
9902 if (s.content_css) { 11332 each(t.contentCSS, function(u) {
9903 tinymce.each(explode(s.content_css), function(u) { 11333 t.dom.loadCSS(u);
9904 t.dom.loadCSS(t.documentBaseURI.toAbsolute(u)); 11334 });
9905 });
9906 }
9907 11335
9908 // Handle auto focus 11336 // Handle auto focus
9909 if (s.auto_focus) { 11337 if (s.auto_focus) {
9910 setTimeout(function () { 11338 setTimeout(function () {
9911 var ed = tinymce.get(s.auto_focus); 11339 var ed = tinymce.get(s.auto_focus);
10017 11445
10018 return v; 11446 return v;
10019 }, 11447 },
10020 11448
10021 nodeChanged : function(o) { 11449 nodeChanged : function(o) {
10022 var t = this, s = t.selection, n = (isIE ? s.getNode() : s.getStart()) || t.getBody(); 11450 var t = this, s = t.selection, n = s.getStart() || t.getBody();
10023 11451
10024 // Fix for bug #1896577 it seems that this can not be fired while the editor is loading 11452 // Fix for bug #1896577 it seems that this can not be fired while the editor is loading
10025 if (t.initialized) { 11453 if (t.initialized) {
10026 o = o || {}; 11454 o = o || {};
10027 n = isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n; // Fix for IE initial state 11455 n = isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n; // Fix for IE initial state
10050 11478
10051 t.buttons = t.buttons || {}; 11479 t.buttons = t.buttons || {};
10052 t.buttons[n] = s; 11480 t.buttons[n] = s;
10053 }, 11481 },
10054 11482
10055 addCommand : function(n, f, s) { 11483 addCommand : function(name, callback, scope) {
10056 this.execCommands[n] = {func : f, scope : s || this}; 11484 this.execCommands[name] = {func : callback, scope : scope || this};
10057 }, 11485 },
10058 11486
10059 addQueryStateHandler : function(n, f, s) { 11487 addQueryStateHandler : function(name, callback, scope) {
10060 this.queryStateCommands[n] = {func : f, scope : s || this}; 11488 this.queryStateCommands[name] = {func : callback, scope : scope || this};
10061 }, 11489 },
10062 11490
10063 addQueryValueHandler : function(n, f, s) { 11491 addQueryValueHandler : function(name, callback, scope) {
10064 this.queryValueCommands[n] = {func : f, scope : s || this}; 11492 this.queryValueCommands[name] = {func : callback, scope : scope || this};
10065 }, 11493 },
10066 11494
10067 addShortcut : function(pa, desc, cmd_func, sc) { 11495 addShortcut : function(pa, desc, cmd_func, sc) {
10068 var t = this, c; 11496 var t = this, c;
10069 11497
10162 if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) { 11590 if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) {
10163 t.onExecCommand.dispatch(t, cmd, ui, val, a); 11591 t.onExecCommand.dispatch(t, cmd, ui, val, a);
10164 return true; 11592 return true;
10165 } 11593 }
10166 11594
10167 // Execute global commands
10168 if (tinymce.GlobalCommands.execCommand(t, cmd, ui, val)) {
10169 t.onExecCommand.dispatch(t, cmd, ui, val, a);
10170 return true;
10171 }
10172
10173 // Editor commands 11595 // Editor commands
10174 if (t.editorCommands.execCommand(cmd, ui, val)) { 11596 if (t.editorCommands.execCommand(cmd, ui, val)) {
10175 t.onExecCommand.dispatch(t, cmd, ui, val, a); 11597 t.onExecCommand.dispatch(t, cmd, ui, val, a);
10176 return true; 11598 return true;
10177 } 11599 }
10299 o = o || {}; 11721 o = o || {};
10300 o.save = true; 11722 o.save = true;
10301 11723
10302 // Add undo level will trigger onchange event 11724 // Add undo level will trigger onchange event
10303 if (!o.no_events) { 11725 if (!o.no_events) {
10304 t.undoManager.typing = 0; 11726 t.undoManager.typing = false;
10305 t.undoManager.add(); 11727 t.undoManager.add();
10306 } 11728 }
10307 11729
10308 o.element = e; 11730 o.element = e;
10309 h = o.content = t.getContent(o); 11731 h = o.content = t.getContent(o);
10331 o.element = e = null; 11753 o.element = e = null;
10332 11754
10333 return h; 11755 return h;
10334 }, 11756 },
10335 11757
10336 setContent : function(h, o) { 11758 setContent : function(content, args) {
10337 var t = this; 11759 var self = this, rootNode, body = self.getBody();
10338 11760
10339 o = o || {}; 11761 // Setup args object
10340 o.format = o.format || 'html'; 11762 args = args || {};
10341 o.set = true; 11763 args.format = args.format || 'html';
10342 o.content = h; 11764 args.set = true;
10343 11765 args.content = content;
10344 if (!o.no_events) 11766
10345 t.onBeforeSetContent.dispatch(t, o); 11767 // Do preprocessing
11768 if (!args.no_events)
11769 self.onBeforeSetContent.dispatch(self, args);
11770
11771 content = args.content;
10346 11772
10347 // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content 11773 // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
10348 // It will also be impossible to place the caret in the editor unless there is a BR element present 11774 // It will also be impossible to place the caret in the editor unless there is a BR element present
10349 if (!tinymce.isIE && (h.length === 0 || /^\s+$/.test(h))) { 11775 if (!tinymce.isIE && (content.length === 0 || /^\s+$/.test(content))) {
10350 o.content = t.dom.setHTML(t.getBody(), '<br _mce_bogus="1" />'); 11776 body.innerHTML = '<br data-mce-bogus="1" />';
10351 o.format = 'raw'; 11777 return;
10352 } 11778 }
10353 11779
10354 o.content = t.dom.setHTML(t.getBody(), tinymce.trim(o.content)); 11780 // Parse and serialize the html
10355 11781 if (args.format !== 'raw') {
10356 if (o.format != 'raw' && t.settings.cleanup) { 11782 content = new tinymce.html.Serializer({}, self.schema).serialize(
10357 o.getInner = true; 11783 self.parser.parse(content)
10358 o.content = t.dom.setHTML(t.getBody(), t.serializer.serialize(t.getBody(), o)); 11784 );
10359 } 11785 }
10360 11786
10361 if (!o.no_events) 11787 // Set the new cleaned contents to the editor
10362 t.onSetContent.dispatch(t, o); 11788 args.content = tinymce.trim(content);
10363 11789 self.dom.setHTML(body, args.content);
10364 return o.content; 11790
10365 }, 11791 // Do post processing
10366 11792 if (!args.no_events)
10367 getContent : function(o) { 11793 self.onSetContent.dispatch(self, args);
10368 var t = this, h; 11794
10369 11795 return args.content;
10370 o = o || {}; 11796 },
10371 o.format = o.format || 'html'; 11797
10372 o.get = true; 11798 getContent : function(args) {
10373 11799 var self = this, content;
10374 if (!o.no_events) 11800
10375 t.onBeforeGetContent.dispatch(t, o); 11801 // Setup args object
10376 11802 args = args || {};
10377 if (o.format != 'raw' && t.settings.cleanup) { 11803 args.format = args.format || 'html';
10378 o.getInner = true; 11804 args.get = true;
10379 h = t.serializer.serialize(t.getBody(), o); 11805
10380 } else 11806 // Do preprocessing
10381 h = t.getBody().innerHTML; 11807 if (!args.no_events)
10382 11808 self.onBeforeGetContent.dispatch(self, args);
10383 h = h.replace(/^\s*|\s*$/g, ''); 11809
10384 o.content = h; 11810 // Get raw contents or by default the cleaned contents
10385 11811 if (args.format == 'raw')
10386 if (!o.no_events) 11812 content = self.getBody().innerHTML;
10387 t.onGetContent.dispatch(t, o); 11813 else
10388 11814 content = self.serializer.serialize(self.getBody(), args);
10389 return o.content; 11815
11816 args.content = tinymce.trim(content);
11817
11818 // Do post processing
11819 if (!args.no_events)
11820 self.onGetContent.dispatch(self, args);
11821
11822 return args.content;
10390 }, 11823 },
10391 11824
10392 isDirty : function() { 11825 isDirty : function() {
10393 var t = this; 11826 var self = this;
10394 11827
10395 return tinymce.trim(t.startContent) != tinymce.trim(t.getContent({format : 'raw', no_events : 1})) && !t.isNotDirty; 11828 return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty;
10396 }, 11829 },
10397 11830
10398 getContainer : function() { 11831 getContainer : function() {
10399 var t = this; 11832 var t = this;
10400 11833
10568 12001
10569 // Internal functions 12002 // Internal functions
10570 12003
10571 _addEvents : function() { 12004 _addEvents : function() {
10572 // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset 12005 // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset
10573 var t = this, i, s = t.settings, lo = { 12006 var t = this, i, s = t.settings, dom = t.dom, lo = {
10574 mouseup : 'onMouseUp', 12007 mouseup : 'onMouseUp',
10575 mousedown : 'onMouseDown', 12008 mousedown : 'onMouseDown',
10576 click : 'onClick', 12009 click : 'onClick',
10577 keyup : 'onKeyUp', 12010 keyup : 'onKeyUp',
10578 keydown : 'onKeyDown', 12011 keydown : 'onKeyDown',
10600 12033
10601 // Add DOM events 12034 // Add DOM events
10602 each(lo, function(v, k) { 12035 each(lo, function(v, k) {
10603 switch (k) { 12036 switch (k) {
10604 case 'contextmenu': 12037 case 'contextmenu':
10605 if (tinymce.isOpera) { 12038 dom.bind(t.getDoc(), k, eventHandler);
10606 // Fake contextmenu on Opera
10607 t.dom.bind(t.getBody(), 'mousedown', function(e) {
10608 if (e.ctrlKey) {
10609 e.fakeType = 'contextmenu';
10610 eventHandler(e);
10611 }
10612 });
10613 } else
10614 t.dom.bind(t.getBody(), k, eventHandler);
10615 break; 12039 break;
10616 12040
10617 case 'paste': 12041 case 'paste':
10618 t.dom.bind(t.getBody(), k, function(e) { 12042 dom.bind(t.getBody(), k, function(e) {
10619 eventHandler(e); 12043 eventHandler(e);
10620 }); 12044 });
10621 break; 12045 break;
10622 12046
10623 case 'submit': 12047 case 'submit':
10624 case 'reset': 12048 case 'reset':
10625 t.dom.bind(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler); 12049 dom.bind(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler);
10626 break; 12050 break;
10627 12051
10628 default: 12052 default:
10629 t.dom.bind(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler); 12053 dom.bind(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler);
10630 } 12054 }
10631 }); 12055 });
10632 12056
10633 t.dom.bind(s.content_editable ? t.getBody() : (isGecko ? t.getDoc() : t.getWin()), 'focus', function(e) { 12057 dom.bind(s.content_editable ? t.getBody() : (isGecko ? t.getDoc() : t.getWin()), 'focus', function(e) {
10634 t.focus(true); 12058 t.focus(true);
10635 }); 12059 });
10636 12060
10637 12061
10638 // Fixes bug where a specified document_base_uri could result in broken images 12062 // Fixes bug where a specified document_base_uri could result in broken images
10639 // This will also fix drag drop of images in Gecko 12063 // This will also fix drag drop of images in Gecko
10640 if (tinymce.isGecko) { 12064 if (tinymce.isGecko) {
10641 // Convert all images to absolute URLs 12065 dom.bind(t.getDoc(), 'DOMNodeInserted', function(e) {
10642 /* t.onSetContent.add(function(ed, o) {
10643 each(ed.dom.select('img'), function(e) {
10644 var v;
10645
10646 if (v = e.getAttribute('_mce_src'))
10647 e.src = t.documentBaseURI.toAbsolute(v);
10648 })
10649 });*/
10650
10651 t.dom.bind(t.getDoc(), 'DOMNodeInserted', function(e) {
10652 var v; 12066 var v;
10653 12067
10654 e = e.target; 12068 e = e.target;
10655 12069
10656 if (e.nodeType === 1 && e.nodeName === 'IMG' && (v = e.getAttribute('_mce_src'))) 12070 if (e.nodeType === 1 && e.nodeName === 'IMG' && (v = e.getAttribute('data-mce-src')))
10657 e.src = t.documentBaseURI.toAbsolute(v); 12071 e.src = t.documentBaseURI.toAbsolute(v);
10658 }); 12072 });
10659 } 12073 }
10660 12074
10661 // Set various midas options in Gecko 12075 // Set various midas options in Gecko
10700 if (tinymce.isWebKit) { 12114 if (tinymce.isWebKit) {
10701 t.onClick.add(function(ed, e) { 12115 t.onClick.add(function(ed, e) {
10702 e = e.target; 12116 e = e.target;
10703 12117
10704 // Needs tobe the setBaseAndExtend or it will fail to select floated images 12118 // Needs tobe the setBaseAndExtend or it will fail to select floated images
10705 if (e.nodeName == 'IMG' || (e.nodeName == 'A' && t.dom.hasClass(e, 'mceItemAnchor'))) 12119 if (e.nodeName == 'IMG' || (e.nodeName == 'A' && dom.hasClass(e, 'mceItemAnchor'))) {
10706 t.selection.getSel().setBaseAndExtent(e, 0, e, 1); 12120 t.selection.getSel().setBaseAndExtent(e, 0, e, 1);
12121 t.nodeChanged();
12122 }
10707 }); 12123 });
10708 } 12124 }
10709 12125
10710 // Add node change handlers 12126 // Add node change handlers
10711 t.onMouseUp.add(t.nodeChanged); 12127 t.onMouseUp.add(t.nodeChanged);
10794 } 12210 }
10795 12211
10796 if (tinymce.isIE) { 12212 if (tinymce.isIE) {
10797 // Fix so resize will only update the width and height attributes not the styles of an image 12213 // Fix so resize will only update the width and height attributes not the styles of an image
10798 // It will also block mceItemNoResize items 12214 // It will also block mceItemNoResize items
10799 t.dom.bind(t.getDoc(), 'controlselect', function(e) { 12215 dom.bind(t.getDoc(), 'controlselect', function(e) {
10800 var re = t.resizeInfo, cb; 12216 var re = t.resizeInfo, cb;
10801 12217
10802 e = e.target; 12218 e = e.target;
10803 12219
10804 // Don't do this action for non image elements 12220 // Don't do this action for non image elements
10805 if (e.nodeName !== 'IMG') 12221 if (e.nodeName !== 'IMG')
10806 return; 12222 return;
10807 12223
10808 if (re) 12224 if (re)
10809 t.dom.unbind(re.node, re.ev, re.cb); 12225 dom.unbind(re.node, re.ev, re.cb);
10810 12226
10811 if (!t.dom.hasClass(e, 'mceItemNoResize')) { 12227 if (!dom.hasClass(e, 'mceItemNoResize')) {
10812 ev = 'resizeend'; 12228 ev = 'resizeend';
10813 cb = t.dom.bind(e, ev, function(e) { 12229 cb = dom.bind(e, ev, function(e) {
10814 var v; 12230 var v;
10815 12231
10816 e = e.target; 12232 e = e.target;
10817 12233
10818 if (v = t.dom.getStyle(e, 'width')) { 12234 if (v = dom.getStyle(e, 'width')) {
10819 t.dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, '')); 12235 dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, ''));
10820 t.dom.setStyle(e, 'width', ''); 12236 dom.setStyle(e, 'width', '');
10821 } 12237 }
10822 12238
10823 if (v = t.dom.getStyle(e, 'height')) { 12239 if (v = dom.getStyle(e, 'height')) {
10824 t.dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, '')); 12240 dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, ''));
10825 t.dom.setStyle(e, 'height', ''); 12241 dom.setStyle(e, 'height', '');
10826 } 12242 }
10827 }); 12243 });
10828 } else { 12244 } else {
10829 ev = 'resizestart'; 12245 ev = 'resizestart';
10830 cb = t.dom.bind(e, 'resizestart', Event.cancel, Event); 12246 cb = dom.bind(e, 'resizestart', Event.cancel, Event);
10831 } 12247 }
10832 12248
10833 re = t.resizeInfo = { 12249 re = t.resizeInfo = {
10834 node : e, 12250 node : e,
10835 ev : ev, 12251 ev : ev,
10836 cb : cb 12252 cb : cb
10837 }; 12253 };
10838 }); 12254 });
10839 12255
10840 t.onKeyDown.add(function(ed, e) { 12256 t.onKeyDown.add(function(ed, e) {
12257 var sel;
12258
10841 switch (e.keyCode) { 12259 switch (e.keyCode) {
10842 case 8: 12260 case 8:
12261 sel = t.getDoc().selection;
12262
10843 // Fix IE control + backspace browser bug 12263 // Fix IE control + backspace browser bug
10844 if (t.selection.getRng().item) { 12264 if (sel.createRange && sel.createRange().item) {
10845 ed.dom.remove(t.selection.getRng().item(0)); 12265 ed.dom.remove(sel.createRange().item(0));
10846 return Event.cancel(e); 12266 return Event.cancel(e);
10847 } 12267 }
10848 } 12268 }
10849 }); 12269 });
10850
10851 /*if (t.dom.boxModel) {
10852 t.getBody().style.height = '100%';
10853
10854 Event.add(t.getWin(), 'resize', function(e) {
10855 var docElm = t.getDoc().documentElement;
10856
10857 docElm.style.height = (docElm.offsetHeight - 10) + 'px';
10858 });
10859 }*/
10860 } 12270 }
10861 12271
10862 if (tinymce.isOpera) { 12272 if (tinymce.isOpera) {
10863 t.onClick.add(function(ed, e) { 12273 t.onClick.add(function(ed, e) {
10864 Event.prevent(e); 12274 Event.prevent(e);
10866 } 12276 }
10867 12277
10868 // Add custom undo/redo handlers 12278 // Add custom undo/redo handlers
10869 if (s.custom_undo_redo) { 12279 if (s.custom_undo_redo) {
10870 function addUndo() { 12280 function addUndo() {
10871 t.undoManager.typing = 0; 12281 t.undoManager.typing = false;
10872 t.undoManager.add(); 12282 t.undoManager.add();
10873 }; 12283 };
10874 12284
10875 t.dom.bind(t.getDoc(), 'focusout', function(e) { 12285 dom.bind(t.getDoc(), 'focusout', function(e) {
10876 if (!t.removed && t.undoManager.typing) 12286 if (!t.removed && t.undoManager.typing)
10877 addUndo(); 12287 addUndo();
10878 }); 12288 });
10879 12289
12290 // Add undo level when contents is drag/dropped within the editor
12291 t.dom.bind(t.dom.getRoot(), 'dragend', function(e) {
12292 addUndo();
12293 });
12294
10880 t.onKeyUp.add(function(ed, e) { 12295 t.onKeyUp.add(function(ed, e) {
12296 var rng, parent, bookmark;
12297
12298 // Fix for bug #3168, to remove odd ".." nodes from the DOM we need to get/set the HTML of the parent node.
12299 if (isIE && e.keyCode == 8) {
12300 rng = t.selection.getRng();
12301 if (rng.parentElement) {
12302 parent = rng.parentElement();
12303 bookmark = t.selection.getBookmark();
12304 parent.innerHTML = parent.innerHTML;
12305 t.selection.moveToBookmark(bookmark);
12306 }
12307 }
12308
10881 if ((e.keyCode >= 33 && e.keyCode <= 36) || (e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 || e.keyCode == 45 || e.ctrlKey) 12309 if ((e.keyCode >= 33 && e.keyCode <= 36) || (e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 || e.keyCode == 45 || e.ctrlKey)
10882 addUndo(); 12310 addUndo();
10883 }); 12311 });
10884 12312
10885 t.onKeyDown.add(function(ed, e) { 12313 t.onKeyDown.add(function(ed, e) {
10886 var rng, parent, bookmark; 12314 var rng, parent, bookmark, keyCode = e.keyCode;
10887 12315
10888 // IE has a really odd bug where the DOM might include an node that doesn't have 12316 // IE has a really odd bug where the DOM might include an node that doesn't have
10889 // a proper structure. If you try to access nodeValue it would throw an illegal value exception. 12317 // a proper structure. If you try to access nodeValue it would throw an illegal value exception.
10890 // This seems to only happen when you delete contents and it seems to be avoidable if you refresh the element 12318 // This seems to only happen when you delete contents and it seems to be avoidable if you refresh the element
10891 // after you delete contents from it. See: #3008923 12319 // after you delete contents from it. See: #3008923
10892 if (isIE && e.keyCode == 46) { 12320 if (isIE && keyCode == 46) {
10893 rng = t.selection.getRng(); 12321 rng = t.selection.getRng();
10894 12322
10895 if (rng.parentElement) { 12323 if (rng.parentElement) {
10896 parent = rng.parentElement(); 12324 parent = rng.parentElement();
12325
12326 if (!t.undoManager.typing) {
12327 t.undoManager.beforeChange();
12328 t.undoManager.typing = true;
12329 t.undoManager.add();
12330 }
10897 12331
10898 // Select next word when ctrl key is used in combo with delete 12332 // Select next word when ctrl key is used in combo with delete
10899 if (e.ctrlKey) { 12333 if (e.ctrlKey) {
10900 rng.moveEnd('word', 1); 12334 rng.moveEnd('word', 1);
10901 rng.select(); 12335 rng.select();
10923 e.preventDefault(); 12357 e.preventDefault();
10924 return; 12358 return;
10925 } 12359 }
10926 } 12360 }
10927 12361
10928 // Is caracter positon keys 12362 // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter
10929 if ((e.keyCode >= 33 && e.keyCode <= 36) || (e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 || e.keyCode == 45) { 12363 if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45) {
12364 // Add position before enter key is pressed, used by IE since it still uses the default browser behavior
12365 // Todo: Remove this once we normalize enter behavior on IE
12366 if (tinymce.isIE && keyCode == 13)
12367 t.undoManager.beforeChange();
12368
10930 if (t.undoManager.typing) 12369 if (t.undoManager.typing)
10931 addUndo(); 12370 addUndo();
10932 12371
10933 return; 12372 return;
10934 } 12373 }
10935 12374
10936 if (!t.undoManager.typing) { 12375 // If key isn't shift,ctrl,alt,capslock,metakey
12376 if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !t.undoManager.typing) {
12377 t.undoManager.beforeChange();
10937 t.undoManager.add(); 12378 t.undoManager.add();
10938 t.undoManager.typing = 1; 12379 t.undoManager.typing = true;
10939 } 12380 }
10940 }); 12381 });
10941 12382
10942 t.onMouseDown.add(function() { 12383 t.onMouseDown.add(function() {
10943 if (t.undoManager.typing) 12384 if (t.undoManager.typing)
10944 addUndo(); 12385 addUndo();
10945 }); 12386 });
10946 } 12387 }
12388
12389 // Bug fix for FireFox keeping styles from end of selection instead of start.
12390 if (tinymce.isGecko) {
12391 function getAttributeApplyFunction() {
12392 var template = t.dom.getAttribs(t.selection.getStart().cloneNode(false));
12393
12394 return function() {
12395 var target = t.selection.getStart();
12396 t.dom.removeAllAttribs(target);
12397 each(template, function(attr) {
12398 target.setAttributeNode(attr.cloneNode(true));
12399 });
12400 };
12401 }
12402
12403 function isSelectionAcrossElements() {
12404 var s = t.selection;
12405
12406 return !s.isCollapsed() && s.getStart() != s.getEnd();
12407 }
12408
12409 t.onKeyPress.add(function(ed, e) {
12410 var applyAttributes;
12411
12412 if ((e.keyCode == 8 || e.keyCode == 46) && isSelectionAcrossElements()) {
12413 applyAttributes = getAttributeApplyFunction();
12414 t.getDoc().execCommand('delete', false, null);
12415 applyAttributes();
12416
12417 return Event.cancel(e);
12418 }
12419 });
12420
12421 t.dom.bind(t.getDoc(), 'cut', function(e) {
12422 var applyAttributes;
12423
12424 if (isSelectionAcrossElements()) {
12425 applyAttributes = getAttributeApplyFunction();
12426 t.onKeyUp.addToTop(Event.cancel, Event);
12427
12428 setTimeout(function() {
12429 applyAttributes();
12430 t.onKeyUp.remove(Event.cancel, Event);
12431 }, 0);
12432 }
12433 });
12434 }
10947 }, 12435 },
10948 12436
10949 _isHidden : function() { 12437 _isHidden : function() {
10950 var s; 12438 var s;
10951 12439
10953 return 0; 12441 return 0;
10954 12442
10955 // Weird, wheres that cursor selection? 12443 // Weird, wheres that cursor selection?
10956 s = this.selection.getSel(); 12444 s = this.selection.getSel();
10957 return (!s || !s.rangeCount || s.rangeCount == 0); 12445 return (!s || !s.rangeCount || s.rangeCount == 0);
10958 },
10959
10960 // Fix for bug #1867292
10961 _fixNesting : function(s) {
10962 var d = [], i;
10963
10964 s = s.replace(/<(\/)?([^\s>]+)[^>]*?>/g, function(a, b, c) {
10965 var e;
10966
10967 // Handle end element
10968 if (b === '/') {
10969 if (!d.length)
10970 return '';
10971
10972 if (c !== d[d.length - 1].tag) {
10973 for (i=d.length - 1; i>=0; i--) {
10974 if (d[i].tag === c) {
10975 d[i].close = 1;
10976 break;
10977 }
10978 }
10979
10980 return '';
10981 } else {
10982 d.pop();
10983
10984 if (d.length && d[d.length - 1].close) {
10985 a = a + '</' + d[d.length - 1].tag + '>';
10986 d.pop();
10987 }
10988 }
10989 } else {
10990 // Ignore these
10991 if (/^(br|hr|input|meta|img|link|param)$/i.test(c))
10992 return a;
10993
10994 // Ignore closed ones
10995 if (/\/>$/.test(a))
10996 return a;
10997
10998 d.push({tag : c}); // Push start element
10999 }
11000
11001 return a;
11002 });
11003
11004 // End all open tags
11005 for (i=d.length - 1; i>=0; i--)
11006 s += '</' + d[i].tag + '>';
11007
11008 return s;
11009 } 12446 }
11010 }); 12447 });
11011 })(tinymce); 12448 })(tinymce);
11012 12449
11013 (function(tinymce) { 12450 (function(tinymce) {
11150 if (align != name) 12587 if (align != name)
11151 editor.formatter.remove('align' + name); 12588 editor.formatter.remove('align' + name);
11152 }); 12589 });
11153 12590
11154 toggleFormat('align' + align); 12591 toggleFormat('align' + align);
12592 execCommand('mceRepaint');
11155 }, 12593 },
11156 12594
11157 // Override list commands to fix WebKit bug 12595 // Override list commands to fix WebKit bug
11158 'InsertUnorderedList,InsertOrderedList' : function(command) { 12596 'InsertUnorderedList,InsertOrderedList' : function(command) {
11159 var listElm, listParent; 12597 var listElm, listParent;
11175 } 12613 }
11176 } 12614 }
11177 }, 12615 },
11178 12616
11179 // Override commands to use the text formatter engine 12617 // Override commands to use the text formatter engine
11180 'Bold,Italic,Underline,Strikethrough' : function(command) { 12618 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
11181 toggleFormat(command); 12619 toggleFormat(command);
11182 }, 12620 },
11183 12621
11184 // Override commands to use the text formatter engine 12622 // Override commands to use the text formatter engine
11185 'ForeColor,HiliteColor,FontName' : function(command, ui, value) { 12623 'ForeColor,HiliteColor,FontName' : function(command, ui, value) {
11248 mceSelectNode : function(command, ui, value) { 12686 mceSelectNode : function(command, ui, value) {
11249 selection.select(value); 12687 selection.select(value);
11250 }, 12688 },
11251 12689
11252 mceInsertContent : function(command, ui, value) { 12690 mceInsertContent : function(command, ui, value) {
11253 selection.setContent(value); 12691 var caretNode, rng, rootNode, parent, node, rng, nodeRect, viewPortRect, args;
12692
12693 function findSuitableCaretNode(node, root_node, next) {
12694 var walker = new tinymce.dom.TreeWalker(next ? node.nextSibling : node.previousSibling, root_node);
12695
12696 while ((node = walker.current())) {
12697 if ((node.nodeType == 3 && tinymce.trim(node.nodeValue).length) || node.nodeName == 'BR' || node.nodeName == 'IMG')
12698 return node;
12699
12700 if (next)
12701 walker.next();
12702 else
12703 walker.prev();
12704 }
12705 };
12706
12707 args = {content: value, format: 'html'};
12708 selection.onBeforeSetContent.dispatch(selection, args);
12709 value = args.content;
12710
12711 // Add caret at end of contents if it's missing
12712 if (value.indexOf('{$caret}') == -1)
12713 value += '{$caret}';
12714
12715 // Set the content at selection to a span and replace it's contents with the value
12716 selection.setContent('<span id="__mce">\uFEFF</span>', {no_events : false});
12717 dom.setOuterHTML('__mce', value.replace(/\{\$caret\}/, '<span data-mce-type="bookmark" id="__mce">\uFEFF</span>'));
12718
12719 caretNode = dom.select('#__mce')[0];
12720 rootNode = dom.getRoot();
12721
12722 // Move the caret into the last suitable location within the previous sibling if it's a block since the block might be split
12723 if (caretNode.previousSibling && dom.isBlock(caretNode.previousSibling) || caretNode.parentNode == rootNode) {
12724 node = findSuitableCaretNode(caretNode, rootNode);
12725 if (node) {
12726 if (node.nodeName == 'BR')
12727 node.parentNode.insertBefore(caretNode, node);
12728 else
12729 dom.insertAfter(caretNode, node);
12730 }
12731 }
12732
12733 // Find caret root parent and clean it up using the serializer to avoid nesting
12734 while (caretNode) {
12735 if (caretNode === rootNode) {
12736 // Clean up the parent element by parsing and serializing it
12737 // This will remove invalid elements/attributes and fix nesting issues
12738 dom.setOuterHTML(parent,
12739 new tinymce.html.Serializer({}, editor.schema).serialize(
12740 editor.parser.parse(dom.getOuterHTML(parent))
12741 )
12742 );
12743
12744 break;
12745 }
12746
12747 parent = caretNode;
12748 caretNode = caretNode.parentNode;
12749 }
12750
12751 // Find caret after cleanup and move selection to that location
12752 caretNode = dom.select('#__mce')[0];
12753 if (caretNode) {
12754 node = findSuitableCaretNode(caretNode, rootNode) || findSuitableCaretNode(caretNode, rootNode, true);
12755 dom.remove(caretNode);
12756
12757 if (node) {
12758 rng = dom.createRng();
12759
12760 if (node.nodeType == 3) {
12761 rng.setStart(node, node.length);
12762 rng.setEnd(node, node.length);
12763 } else {
12764 if (node.nodeName == 'BR') {
12765 rng.setStartBefore(node);
12766 rng.setEndBefore(node);
12767 } else {
12768 rng.setStartAfter(node);
12769 rng.setEndAfter(node);
12770 }
12771 }
12772
12773 selection.setRng(rng);
12774
12775 // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well
12776 if (!tinymce.isIE) {
12777 node = dom.create('span', null, '\u00a0');
12778 rng.insertNode(node);
12779 nodeRect = dom.getRect(node);
12780 viewPortRect = dom.getViewPort(editor.getWin());
12781
12782 // Check if node is out side the viewport if it is then scroll to it
12783 if ((nodeRect.y > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) ||
12784 (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) {
12785 editor.getBody().scrollLeft = nodeRect.x;
12786 editor.getBody().scrollTop = nodeRect.y;
12787 }
12788
12789 dom.remove(node);
12790 }
12791
12792 // Make sure that the selection is collapsed after we removed the node fixes a WebKit bug
12793 // where WebKit would place the endContainer/endOffset at a different location than the startContainer/startOffset
12794 selection.collapse(true);
12795 }
12796 }
12797
12798 selection.onSetContent.dispatch(selection, args);
12799 editor.addVisual();
11254 }, 12800 },
11255 12801
11256 mceInsertRawHTML : function(command, ui, value) { 12802 mceInsertRawHTML : function(command, ui, value) {
11257 selection.setContent('tiny_mce_marker'); 12803 selection.setContent('tiny_mce_marker');
11258 editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value })); 12804 editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value }));
11303 mceToggleFormat : function(command, ui, value) { 12849 mceToggleFormat : function(command, ui, value) {
11304 editor.formatter.toggle(value); 12850 editor.formatter.toggle(value);
11305 }, 12851 },
11306 12852
11307 InsertHorizontalRule : function() { 12853 InsertHorizontalRule : function() {
11308 selection.setContent('<hr />'); 12854 editor.execCommand('mceInsertContent', false, '<hr />');
11309 }, 12855 },
11310 12856
11311 mceToggleVisualAid : function() { 12857 mceToggleVisualAid : function() {
11312 editor.hasVisual = !editor.hasVisual; 12858 editor.hasVisual = !editor.hasVisual;
11313 editor.addVisual(); 12859 editor.addVisual();
11314 }, 12860 },
11315 12861
11316 mceReplaceContent : function(command, ui, value) { 12862 mceReplaceContent : function(command, ui, value) {
11317 selection.setContent(value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'}))); 12863 editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'})));
11318 }, 12864 },
11319 12865
11320 mceInsertLink : function(command, ui, value) { 12866 mceInsertLink : function(command, ui, value) {
11321 var link = dom.getParent(selection.getNode(), 'a'); 12867 var link = dom.getParent(selection.getNode(), 'a'), img, floatVal;
11322 12868
11323 if (tinymce.is(value, 'string')) 12869 if (tinymce.is(value, 'string'))
11324 value = {href : value}; 12870 value = {href : value};
11325 12871
12872 // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here.
12873 value.href = value.href.replace(' ', '%20');
12874
11326 if (!link) { 12875 if (!link) {
12876 // WebKit can't create links on float images for some odd reason so just remove it and restore it later
12877 if (tinymce.isWebKit) {
12878 img = dom.getParent(selection.getNode(), 'img');
12879
12880 if (img) {
12881 floatVal = img.style.cssFloat;
12882 img.style.cssFloat = null;
12883 }
12884 }
12885
11327 execNativeCommand('CreateLink', FALSE, 'javascript:mctmp(0);'); 12886 execNativeCommand('CreateLink', FALSE, 'javascript:mctmp(0);');
11328 each(dom.select('a[href=javascript:mctmp(0);]'), function(link) { 12887
12888 // Restore float value
12889 if (floatVal)
12890 img.style.cssFloat = floatVal;
12891
12892 each(dom.select("a[href='javascript:mctmp(0);']"), function(link) {
11329 dom.setAttribs(link, value); 12893 dom.setAttribs(link, value);
11330 }); 12894 });
11331 } else { 12895 } else {
11332 if (value.href) 12896 if (value.href)
11333 dom.setAttribs(link, value); 12897 dom.setAttribs(link, value);
11351 // Override justify commands 12915 // Override justify commands
11352 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) { 12916 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) {
11353 return isFormatMatch('align' + command.substring(7)); 12917 return isFormatMatch('align' + command.substring(7));
11354 }, 12918 },
11355 12919
11356 'Bold,Italic,Underline,Strikethrough' : function(command) { 12920 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) {
11357 return isFormatMatch(command); 12921 return isFormatMatch(command);
11358 }, 12922 },
11359 12923
11360 mceBlockQuote : function() { 12924 mceBlockQuote : function() {
11361 return isFormatMatch('blockquote'); 12925 return isFormatMatch('blockquote');
11408 } 12972 }
11409 }); 12973 });
11410 } 12974 }
11411 }; 12975 };
11412 })(tinymce); 12976 })(tinymce);
12977
11413 (function(tinymce) { 12978 (function(tinymce) {
11414 var Dispatcher = tinymce.util.Dispatcher; 12979 var Dispatcher = tinymce.util.Dispatcher;
11415 12980
11416 tinymce.UndoManager = function(editor) { 12981 tinymce.UndoManager = function(editor) {
11417 var self, index = 0, data = []; 12982 var self, index = 0, data = [];
11419 function getContent() { 12984 function getContent() {
11420 return tinymce.trim(editor.getContent({format : 'raw', no_events : 1})); 12985 return tinymce.trim(editor.getContent({format : 'raw', no_events : 1}));
11421 }; 12986 };
11422 12987
11423 return self = { 12988 return self = {
11424 typing : 0, 12989 typing : false,
11425 12990
11426 onAdd : new Dispatcher(self), 12991 onAdd : new Dispatcher(self),
12992
11427 onUndo : new Dispatcher(self), 12993 onUndo : new Dispatcher(self),
12994
11428 onRedo : new Dispatcher(self), 12995 onRedo : new Dispatcher(self),
12996
12997 beforeChange : function() {
12998 // Set before bookmark on previous level
12999 if (data[index])
13000 data[index].beforeBookmark = editor.selection.getBookmark(2, true);
13001 },
11429 13002
11430 add : function(level) { 13003 add : function(level) {
11431 var i, settings = editor.settings, lastLevel; 13004 var i, settings = editor.settings, lastLevel;
11432 13005
11433 level = level || {}; 13006 level = level || {};
11434 level.content = getContent(); 13007 level.content = getContent();
11435 13008
11436 // Add undo level if needed 13009 // Add undo level if needed
11437 lastLevel = data[index]; 13010 lastLevel = data[index];
11438 if (lastLevel && lastLevel.content == level.content) { 13011 if (lastLevel && lastLevel.content == level.content)
11439 if (index > 0 || data.length == 1) 13012 return null;
11440 return null;
11441 }
11442 13013
11443 // Time to compress 13014 // Time to compress
11444 if (settings.custom_undo_redo_levels) { 13015 if (settings.custom_undo_redo_levels) {
11445 if (data.length > settings.custom_undo_redo_levels) { 13016 if (data.length > settings.custom_undo_redo_levels) {
11446 for (i = 0; i < data.length - 1; i++) 13017 for (i = 0; i < data.length - 1; i++)
11453 13024
11454 // Get a non intrusive normalized bookmark 13025 // Get a non intrusive normalized bookmark
11455 level.bookmark = editor.selection.getBookmark(2, true); 13026 level.bookmark = editor.selection.getBookmark(2, true);
11456 13027
11457 // Crop array if needed 13028 // Crop array if needed
11458 if (index < data.length - 1) { 13029 if (index < data.length - 1)
11459 // Treat first level as initial 13030 data.length = index + 1;
11460 if (index == 0)
11461 data = [];
11462 else
11463 data.length = index + 1;
11464 }
11465 13031
11466 data.push(level); 13032 data.push(level);
11467 index = data.length - 1; 13033 index = data.length - 1;
11468 13034
11469 self.onAdd.dispatch(self, level); 13035 self.onAdd.dispatch(self, level);
11475 undo : function() { 13041 undo : function() {
11476 var level, i; 13042 var level, i;
11477 13043
11478 if (self.typing) { 13044 if (self.typing) {
11479 self.add(); 13045 self.add();
11480 self.typing = 0; 13046 self.typing = false;
11481 } 13047 }
11482 13048
11483 if (index > 0) { 13049 if (index > 0) {
11484 level = data[--index]; 13050 level = data[--index];
11485 13051
11486 editor.setContent(level.content, {format : 'raw'}); 13052 editor.setContent(level.content, {format : 'raw'});
11487 editor.selection.moveToBookmark(level.bookmark); 13053 editor.selection.moveToBookmark(level.beforeBookmark);
11488 13054
11489 self.onUndo.dispatch(self, level); 13055 self.onUndo.dispatch(self, level);
11490 } 13056 }
11491 13057
11492 return level; 13058 return level;
11507 return level; 13073 return level;
11508 }, 13074 },
11509 13075
11510 clear : function() { 13076 clear : function() {
11511 data = []; 13077 data = [];
11512 index = self.typing = 0; 13078 index = 0;
13079 self.typing = false;
11513 }, 13080 },
11514 13081
11515 hasUndo : function() { 13082 hasUndo : function() {
11516 return index > 0 || self.typing; 13083 return index > 0 || this.typing;
11517 }, 13084 },
11518 13085
11519 hasRedo : function() { 13086 hasRedo : function() {
11520 return index < data.length - 1; 13087 return index < data.length - 1 && !this.typing;
11521 } 13088 }
11522 }; 13089 };
11523 }; 13090 };
11524 })(tinymce); 13091 })(tinymce);
11525 13092
11564 13131
11565 // Get number of characters to the right of the cursor if it's zero then we are at the end and need to merge the next block element 13132 // Get number of characters to the right of the cursor if it's zero then we are at the end and need to merge the next block element
11566 return rng2.cloneContents().textContent.length == 0; 13133 return rng2.cloneContents().textContent.length == 0;
11567 }; 13134 };
11568 13135
11569 function isEmpty(n) {
11570 n = n.innerHTML;
11571
11572 n = n.replace(/<(img|hr|table|input|select|textarea)[ \>]/gi, '-'); // Keep these convert them to - chars
11573 n = n.replace(/<[^>]+>/g, ''); // Remove all tags
11574
11575 return n.replace(/[ \u00a0\t\r\n]+/g, '') == '';
11576 };
11577
11578 function splitList(selection, dom, li) { 13136 function splitList(selection, dom, li) {
11579 var listBlock, block; 13137 var listBlock, block;
11580 13138
11581 if (isEmpty(li)) { 13139 if (dom.isEmpty(li)) {
11582 listBlock = dom.getParent(li, 'ul,ol'); 13140 listBlock = dom.getParent(li, 'ul,ol');
11583 13141
11584 if (!dom.getParent(listBlock.parentNode, 'ul,ol')) { 13142 if (!dom.getParent(listBlock.parentNode, 'ul,ol')) {
11585 dom.split(listBlock, li); 13143 dom.split(listBlock, li);
11586 block = dom.create('p', 0, '<br _mce_bogus="1" />'); 13144 block = dom.create('p', 0, '<br data-mce-bogus="1" />');
11587 dom.replace(block, li); 13145 dom.replace(block, li);
11588 selection.select(block, 1); 13146 selection.select(block, 1);
11589 } 13147 }
11590 13148
11591 return FALSE; 13149 return FALSE;
11603 elm = (s.forced_root_block || 'p').toLowerCase(); 13161 elm = (s.forced_root_block || 'p').toLowerCase();
11604 s.element = elm.toUpperCase(); 13162 s.element = elm.toUpperCase();
11605 13163
11606 ed.onPreInit.add(t.setup, t); 13164 ed.onPreInit.add(t.setup, t);
11607 13165
11608 t.reOpera = new RegExp('(\\u00a0|&#160;|&nbsp;)<\/' + elm + '>', 'gi');
11609 t.rePadd = new RegExp('<p( )([^>]+)><\\\/p>|<p( )([^>]+)\\\/>|<p( )([^>]+)>\\s+<\\\/p>|<p><\\\/p>|<p\\\/>|<p>\\s+<\\\/p>'.replace(/p/g, elm), 'gi');
11610 t.reNbsp2BR1 = new RegExp('<p( )([^>]+)>[\\s\\u00a0]+<\\\/p>|<p>[\\s\\u00a0]+<\\\/p>'.replace(/p/g, elm), 'gi');
11611 t.reNbsp2BR2 = new RegExp('<%p()([^>]+)>(&nbsp;|&#160;)<\\\/%p>|<%p>(&nbsp;|&#160;)<\\\/%p>'.replace(/%p/g, elm), 'gi');
11612 t.reBR2Nbsp = new RegExp('<p( )([^>]+)>\\s*<br \\\/>\\s*<\\\/p>|<p>\\s*<br \\\/>\\s*<\\\/p>'.replace(/p/g, elm), 'gi');
11613
11614 function padd(ed, o) {
11615 if (isOpera)
11616 o.content = o.content.replace(t.reOpera, '</' + elm + '>');
11617
11618 o.content = o.content.replace(t.rePadd, '<' + elm + '$1$2$3$4$5$6>\u00a0</' + elm + '>');
11619
11620 if (!isIE && !isOpera && o.set) {
11621 // Use &nbsp; instead of BR in padded paragraphs
11622 o.content = o.content.replace(t.reNbsp2BR1, '<' + elm + '$1$2><br /></' + elm + '>');
11623 o.content = o.content.replace(t.reNbsp2BR2, '<' + elm + '$1$2><br /></' + elm + '>');
11624 } else
11625 o.content = o.content.replace(t.reBR2Nbsp, '<' + elm + '$1$2>\u00a0</' + elm + '>');
11626 };
11627
11628 ed.onBeforeSetContent.add(padd);
11629 ed.onPostProcess.add(padd);
11630
11631 if (s.forced_root_block) { 13166 if (s.forced_root_block) {
11632 ed.onInit.add(t.forceRoots, t); 13167 ed.onInit.add(t.forceRoots, t);
11633 ed.onSetContent.add(t.forceRoots, t); 13168 ed.onSetContent.add(t.forceRoots, t);
11634 ed.onBeforeGetContent.add(t.forceRoots, t); 13169 ed.onBeforeGetContent.add(t.forceRoots, t);
13170 ed.onExecCommand.add(function(ed, cmd) {
13171 if (cmd == 'mceInsertContent') {
13172 t.forceRoots();
13173 ed.nodeChanged();
13174 }
13175 });
11635 } 13176 }
11636 }, 13177 },
11637 13178
11638 setup : function() { 13179 setup : function() {
11639 var t = this, ed = t.editor, s = ed.settings, dom = ed.dom, selection = ed.selection; 13180 var t = this, ed = t.editor, s = ed.settings, dom = ed.dom, selection = ed.selection;
11703 fmt.inner.innerHTML = '\uFEFF'; 13244 fmt.inner.innerHTML = '\uFEFF';
11704 } else 13245 } else
11705 parent.innerHTML = '\uFEFF'; 13246 parent.innerHTML = '\uFEFF';
11706 13247
11707 selection.select(parent, 1); 13248 selection.select(parent, 1);
13249 selection.collapse(true);
11708 ed.getDoc().execCommand('Delete', false, null); 13250 ed.getDoc().execCommand('Delete', false, null);
11709 t._previousFormats = 0; 13251 t._previousFormats = 0;
11710 } 13252 }
11711 } 13253 }
11712 } 13254 }
11756 insertBr(ed); 13298 insertBr(ed);
11757 Event.cancel(e); 13299 Event.cancel(e);
11758 } 13300 }
11759 }); 13301 });
11760 } 13302 }
11761
11762 // Padd empty inline elements within block elements
11763 // For example: <p><strong><em></em></strong></p> becomes <p><strong><em>&nbsp;</em></strong></p>
11764 ed.onPreProcess.add(function(ed, o) {
11765 each(dom.select('p,h1,h2,h3,h4,h5,h6,div', o.node), function(p) {
11766 if (isEmpty(p)) {
11767 each(dom.select('span,em,strong,b,i', o.node), function(n) {
11768 if (!n.hasChildNodes()) {
11769 n.appendChild(ed.getDoc().createTextNode('\u00a0'));
11770 return FALSE; // Break the loop one padding is enough
11771 }
11772 });
11773 }
11774 });
11775 });
11776 13303
11777 // IE specific fixes 13304 // IE specific fixes
11778 if (isIE) { 13305 if (isIE) {
11779 // Replaces IE:s auto generated paragraphs with the specified element name 13306 // Replaces IE:s auto generated paragraphs with the specified element name
11780 if (s.element != 'P') { 13307 if (s.element != 'P') {
11832 // Wrap non blocks into blocks 13359 // Wrap non blocks into blocks
11833 for (i = nl.length - 1; i >= 0; i--) { 13360 for (i = nl.length - 1; i >= 0; i--) {
11834 nx = nl[i]; 13361 nx = nl[i];
11835 13362
11836 // Ignore internal elements 13363 // Ignore internal elements
11837 if (nx.nodeType === 1 && nx.getAttribute('_mce_type')) { 13364 if (nx.nodeType === 1 && nx.getAttribute('data-mce-type')) {
11838 bl = null; 13365 bl = null;
11839 continue; 13366 continue;
11840 } 13367 }
11841 13368
11842 // Is text or non block element 13369 // Is text or non block element
11844 if (!bl) { 13371 if (!bl) {
11845 // Create new block but ignore whitespace 13372 // Create new block but ignore whitespace
11846 if (nx.nodeType != 3 || /[^\s]/g.test(nx.nodeValue)) { 13373 if (nx.nodeType != 3 || /[^\s]/g.test(nx.nodeValue)) {
11847 // Store selection 13374 // Store selection
11848 if (si == -2 && r) { 13375 if (si == -2 && r) {
11849 if (!isIE) { 13376 if (!isIE || r.setStart) {
11850 // If selection is element then mark it 13377 // If selection is element then mark it
11851 if (r.startContainer.nodeType == 1 && (n = r.startContainer.childNodes[r.startOffset]) && n.nodeType == 1) { 13378 if (r.startContainer.nodeType == 1 && (n = r.startContainer.childNodes[r.startOffset]) && n.nodeType == 1) {
11852 // Save the id of the selected element 13379 // Save the id of the selected element
11853 eid = n.getAttribute("id"); 13380 eid = n.getAttribute("id");
11854 n.setAttribute("id", "__mce"); 13381 n.setAttribute("id", "__mce");
11903 bl = null; // Time to create new block 13430 bl = null; // Time to create new block
11904 } 13431 }
11905 13432
11906 // Restore selection 13433 // Restore selection
11907 if (si != -2) { 13434 if (si != -2) {
11908 if (!isIE) { 13435 if (!isIE || r.setStart) {
11909 bl = b.getElementsByTagName(ed.settings.element)[0]; 13436 bl = b.getElementsByTagName(ed.settings.element)[0];
11910 r = d.createRange(); 13437 r = d.createRange();
11911 13438
11912 // Select last location or generated block 13439 // Select last location or generated block
11913 if (si != -1) 13440 if (si != -1)
11935 r.select(); 13462 r.select();
11936 } catch (ex) { 13463 } catch (ex) {
11937 // Ignore 13464 // Ignore
11938 } 13465 }
11939 } 13466 }
11940 } else if (!isIE && (n = ed.dom.get('__mce'))) { 13467 } else if ((!isIE || r.setStart) && (n = ed.dom.get('__mce'))) {
11941 // Restore the id of the selected element 13468 // Restore the id of the selected element
11942 if (eid) 13469 if (eid)
11943 n.setAttribute('id', eid); 13470 n.setAttribute('id', eid);
11944 else 13471 else
11945 n.removeAttribute('id'); 13472 n.removeAttribute('id');
11959 }, 13486 },
11960 13487
11961 insertPara : function(e) { 13488 insertPara : function(e) {
11962 var t = this, ed = t.editor, dom = ed.dom, d = ed.getDoc(), se = ed.settings, s = ed.selection.getSel(), r = s.getRangeAt(0), b = d.body; 13489 var t = this, ed = t.editor, dom = ed.dom, d = ed.getDoc(), se = ed.settings, s = ed.selection.getSel(), r = s.getRangeAt(0), b = d.body;
11963 var rb, ra, dir, sn, so, en, eo, sb, eb, bn, bef, aft, sc, ec, n, vp = dom.getViewPort(ed.getWin()), y, ch, car; 13490 var rb, ra, dir, sn, so, en, eo, sb, eb, bn, bef, aft, sc, ec, n, vp = dom.getViewPort(ed.getWin()), y, ch, car;
13491
13492 ed.undoManager.beforeChange();
11964 13493
11965 // If root blocks are forced then use Operas default behavior since it's really good 13494 // If root blocks are forced then use Operas default behavior since it's really good
11966 // Removed due to bug: #1853816 13495 // Removed due to bug: #1853816
11967 // if (se.forced_root_block && isOpera) 13496 // if (se.forced_root_block && isOpera)
11968 // return TRUE; 13497 // return TRUE;
12136 13665
12137 if (aft.firstChild && aft.firstChild.nodeName == bn) 13666 if (aft.firstChild && aft.firstChild.nodeName == bn)
12138 aft.innerHTML = aft.firstChild.innerHTML; 13667 aft.innerHTML = aft.firstChild.innerHTML;
12139 13668
12140 // Padd empty blocks 13669 // Padd empty blocks
12141 if (isEmpty(bef)) 13670 if (dom.isEmpty(bef))
12142 bef.innerHTML = '<br />'; 13671 bef.innerHTML = '<br />';
12143 13672
12144 function appendStyles(e, en) { 13673 function appendStyles(e, en) {
12145 var nl = [], nn, n, i; 13674 var nl = [], nn, n, i;
12146 13675
12163 if (nl.length > 0) { 13692 if (nl.length > 0) {
12164 for (i = nl.length - 1, nn = e; i >= 0; i--) 13693 for (i = nl.length - 1, nn = e; i >= 0; i--)
12165 nn = nn.appendChild(nl[i]); 13694 nn = nn.appendChild(nl[i]);
12166 13695
12167 // Padd most inner style element 13696 // Padd most inner style element
12168 nl[0].innerHTML = isOpera ? '&nbsp;' : '<br />'; // Extra space for Opera so that the caret can move there 13697 nl[0].innerHTML = isOpera ? '\u00a0' : '<br />'; // Extra space for Opera so that the caret can move there
12169 return nl[0]; // Move caret to most inner element 13698 return nl[0]; // Move caret to most inner element
12170 } else 13699 } else
12171 e.innerHTML = isOpera ? '&nbsp;' : '<br />'; // Extra space for Opera so that the caret can move there 13700 e.innerHTML = isOpera ? '\u00a0' : '<br />'; // Extra space for Opera so that the caret can move there
12172 }; 13701 };
12173 13702
12174 // Fill empty afterblook with current style 13703 // Fill empty afterblook with current style
12175 if (isEmpty(aft)) 13704 if (dom.isEmpty(aft))
12176 car = appendStyles(aft, en); 13705 car = appendStyles(aft, en);
12177 13706
12178 // Opera needs this one backwards for older versions 13707 // Opera needs this one backwards for older versions
12179 if (isOpera && parseFloat(opera.version()) < 9.5) { 13708 if (isOpera && parseFloat(opera.version()) < 9.5) {
12180 r.insertNode(bef); 13709 r.insertNode(bef);
12199 s.removeAllRanges(); 13728 s.removeAllRanges();
12200 s.addRange(r); 13729 s.addRange(r);
12201 13730
12202 // scrollIntoView seems to scroll the parent window in most browsers now including FF 3.0b4 so it's time to stop using it and do it our selfs 13731 // scrollIntoView seems to scroll the parent window in most browsers now including FF 3.0b4 so it's time to stop using it and do it our selfs
12203 y = ed.dom.getPos(aft).y; 13732 y = ed.dom.getPos(aft).y;
12204 ch = aft.clientHeight; 13733 //ch = aft.clientHeight;
12205 13734
12206 // Is element within viewport 13735 // Is element within viewport
12207 if (y < vp.y || y + ch > vp.y + vp.h) { 13736 if (y < vp.y || y + 25 > vp.y + vp.h) {
12208 ed.getWin().scrollTo(0, y < vp.y ? y : y - vp.h + 25); // Needs to be hardcoded to roughly one line of text if a huge text block is broken into two blocks 13737 ed.getWin().scrollTo(0, y < vp.y ? y : y - vp.h + 25); // Needs to be hardcoded to roughly one line of text if a huge text block is broken into two blocks
12209 //console.debug('SCROLL!', 'vp.y: ' + vp.y, 'y' + y, 'vp.h' + vp.h, 'clientHeight' + aft.clientHeight, 'yyy: ' + (y < vp.y ? y : y - vp.h + aft.clientHeight)); 13738
12210 } 13739 /*console.debug(
13740 'Element: y=' + y + ', h=' + ch + ', ' +
13741 'Viewport: y=' + vp.y + ", h=" + vp.h + ', bottom=' + (vp.y + vp.h)
13742 );*/
13743 }
13744
13745 ed.undoManager.add();
12211 13746
12212 return FALSE; 13747 return FALSE;
12213 }, 13748 },
12214 13749
12215 backspaceDelete : function(e, bs) { 13750 backspaceDelete : function(e, bs) {
12421 13956
12422 if (ed.settings.use_native_selects) 13957 if (ed.settings.use_native_selects)
12423 c = new tinymce.ui.NativeListBox(id, s); 13958 c = new tinymce.ui.NativeListBox(id, s);
12424 else { 13959 else {
12425 cls = cc || t._cls.listbox || tinymce.ui.ListBox; 13960 cls = cc || t._cls.listbox || tinymce.ui.ListBox;
12426 c = new cls(id, s); 13961 c = new cls(id, s, ed);
12427 } 13962 }
12428 13963
12429 t.controls[id] = c; 13964 t.controls[id] = c;
12430 13965
12431 // Fix focus problem in Safari 13966 // Fix focus problem in Safari
12476 14011
12477 id = t.prefix + id; 14012 id = t.prefix + id;
12478 14013
12479 if (s.menu_button) { 14014 if (s.menu_button) {
12480 cls = cc || t._cls.menubutton || tinymce.ui.MenuButton; 14015 cls = cc || t._cls.menubutton || tinymce.ui.MenuButton;
12481 c = new cls(id, s); 14016 c = new cls(id, s, ed);
12482 ed.onMouseDown.add(c.hideMenu, c); 14017 ed.onMouseDown.add(c.hideMenu, c);
12483 } else { 14018 } else {
12484 cls = t._cls.button || tinymce.ui.Button; 14019 cls = t._cls.button || tinymce.ui.Button;
12485 c = new cls(id, s); 14020 c = new cls(id, s);
12486 } 14021 }
12523 control_manager : t 14058 control_manager : t
12524 }, s); 14059 }, s);
12525 14060
12526 id = t.prefix + id; 14061 id = t.prefix + id;
12527 cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton; 14062 cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton;
12528 c = t.add(new cls(id, s)); 14063 c = t.add(new cls(id, s, ed));
12529 ed.onMouseDown.add(c.hideMenu, c); 14064 ed.onMouseDown.add(c.hideMenu, c);
12530 14065
12531 return c; 14066 return c;
12532 }, 14067 },
12533 14068
12563 more_colors_title : ed.getLang('more_colors') 14098 more_colors_title : ed.getLang('more_colors')
12564 }, s); 14099 }, s);
12565 14100
12566 id = t.prefix + id; 14101 id = t.prefix + id;
12567 cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton; 14102 cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton;
12568 c = new cls(id, s); 14103 c = new cls(id, s, ed);
12569 ed.onMouseDown.add(c.hideMenu, c); 14104 ed.onMouseDown.add(c.hideMenu, c);
12570 14105
12571 // Remove the menu element when the editor is removed 14106 // Remove the menu element when the editor is removed
12572 ed.onRemove.add(function() { 14107 ed.onRemove.add(function() {
12573 c.destroy(); 14108 c.destroy();
12595 createToolbar : function(id, s, cc) { 14130 createToolbar : function(id, s, cc) {
12596 var c, t = this, cls; 14131 var c, t = this, cls;
12597 14132
12598 id = t.prefix + id; 14133 id = t.prefix + id;
12599 cls = cc || t._cls.toolbar || tinymce.ui.Toolbar; 14134 cls = cc || t._cls.toolbar || tinymce.ui.Toolbar;
12600 c = new cls(id, s); 14135 c = new cls(id, s, t.editor);
12601 14136
12602 if (t.get(id)) 14137 if (t.get(id))
12603 return null; 14138 return null;
12604 14139
14140 return t.add(c);
14141 },
14142
14143 createToolbarGroup : function(id, s, cc) {
14144 var c, t = this, cls;
14145 id = t.prefix + id;
14146 cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup;
14147 c = new cls(id, s, t.editor);
14148
14149 if (t.get(id))
14150 return null;
14151
12605 return t.add(c); 14152 return t.add(c);
12606 }, 14153 },
12607 14154
12608 createSeparator : function(cc) { 14155 createSeparator : function(cc) {
12609 var cls = cc || this._cls.separator || tinymce.ui.Separator; 14156 var cls = cc || this._cls.separator || tinymce.ui.Separator;
12739 return tinymce.DOM.decode(s).replace(/\\n/g, '\n'); 14286 return tinymce.DOM.decode(s).replace(/\\n/g, '\n');
12740 } 14287 }
12741 }); 14288 });
12742 }(tinymce)); 14289 }(tinymce));
12743 (function(tinymce) { 14290 (function(tinymce) {
12744 function CommandManager() {
12745 var execCommands = {}, queryStateCommands = {}, queryValueCommands = {};
12746
12747 function add(collection, cmd, func, scope) {
12748 if (typeof(cmd) == 'string')
12749 cmd = [cmd];
12750
12751 tinymce.each(cmd, function(cmd) {
12752 collection[cmd.toLowerCase()] = {func : func, scope : scope};
12753 });
12754 };
12755
12756 tinymce.extend(this, {
12757 add : function(cmd, func, scope) {
12758 add(execCommands, cmd, func, scope);
12759 },
12760
12761 addQueryStateHandler : function(cmd, func, scope) {
12762 add(queryStateCommands, cmd, func, scope);
12763 },
12764
12765 addQueryValueHandler : function(cmd, func, scope) {
12766 add(queryValueCommands, cmd, func, scope);
12767 },
12768
12769 execCommand : function(scope, cmd, ui, value, args) {
12770 if (cmd = execCommands[cmd.toLowerCase()]) {
12771 if (cmd.func.call(scope || cmd.scope, ui, value, args) !== false)
12772 return true;
12773 }
12774 },
12775
12776 queryCommandValue : function() {
12777 if (cmd = queryValueCommands[cmd.toLowerCase()])
12778 return cmd.func.call(scope || cmd.scope, ui, value, args);
12779 },
12780
12781 queryCommandState : function() {
12782 if (cmd = queryStateCommands[cmd.toLowerCase()])
12783 return cmd.func.call(scope || cmd.scope, ui, value, args);
12784 }
12785 });
12786 };
12787
12788 tinymce.GlobalCommands = new CommandManager();
12789 })(tinymce);
12790 (function(tinymce) {
12791 tinymce.Formatter = function(ed) { 14291 tinymce.Formatter = function(ed) {
12792 var formats = {}, 14292 var formats = {},
12793 each = tinymce.each, 14293 each = tinymce.each,
12794 dom = ed.dom, 14294 dom = ed.dom,
12795 selection = ed.selection, 14295 selection = ed.selection,
12796 TreeWalker = tinymce.dom.TreeWalker, 14296 TreeWalker = tinymce.dom.TreeWalker,
12797 rangeUtils = new tinymce.dom.RangeUtils(dom), 14297 rangeUtils = new tinymce.dom.RangeUtils(dom),
12798 isValid = ed.schema.isValid, 14298 isValid = ed.schema.isValidChild,
12799 isBlock = dom.isBlock, 14299 isBlock = dom.isBlock,
12800 forcedRootBlock = ed.settings.forced_root_block, 14300 forcedRootBlock = ed.settings.forced_root_block,
12801 nodeIndex = dom.nodeIndex, 14301 nodeIndex = dom.nodeIndex,
12802 INVISIBLE_CHAR = '\uFEFF', 14302 INVISIBLE_CHAR = '\uFEFF',
12803 MCE_ATTR_RE = /^(src|href|style)$/, 14303 MCE_ATTR_RE = /^(src|href|style)$/,
12862 formats[name] = format; 14362 formats[name] = format;
12863 } 14363 }
12864 } 14364 }
12865 }; 14365 };
12866 14366
14367 var getTextDecoration = function(node) {
14368 var decoration;
14369
14370 ed.dom.getParent(node, function(n) {
14371 decoration = ed.dom.getStyle(n, 'text-decoration');
14372 return decoration && decoration !== 'none';
14373 });
14374
14375 return decoration;
14376 };
14377
14378 var processUnderlineAndColor = function(node) {
14379 var textDecoration;
14380 if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
14381 textDecoration = getTextDecoration(node.parentNode);
14382 if (ed.dom.getStyle(node, 'color') && textDecoration) {
14383 ed.dom.setStyle(node, 'text-decoration', textDecoration);
14384 } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) {
14385 ed.dom.setStyle(node, 'text-decoration', null);
14386 }
14387 }
14388 };
14389
12867 function apply(name, vars, node) { 14390 function apply(name, vars, node) {
12868 var formatList = get(name), format = formatList[0], bookmark, rng, i; 14391 var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed();
12869 14392
12870 function moveStart(rng) { 14393 function moveStart(rng) {
12871 var container = rng.startContainer, 14394 var container = rng.startContainer,
12872 offset = rng.startOffset, 14395 offset = rng.startOffset,
12873 walker, node; 14396 walker, node;
12954 14477
12955 // Handle selector patterns 14478 // Handle selector patterns
12956 if (format.selector) { 14479 if (format.selector) {
12957 // Look for matching formats 14480 // Look for matching formats
12958 each(formatList, function(format) { 14481 each(formatList, function(format) {
14482 // Check collapsed state if it exists
14483 if ('collapsed' in format && format.collapsed !== isCollapsed) {
14484 return;
14485 }
14486
12959 if (dom.is(node, format.selector) && !isCaretNode(node)) { 14487 if (dom.is(node, format.selector) && !isCaretNode(node)) {
12960 setElementFormat(node, format); 14488 setElementFormat(node, format);
12961 found = true; 14489 found = true;
12962 } 14490 }
12963 }); 14491 });
12968 return; 14496 return;
12969 } 14497 }
12970 } 14498 }
12971 14499
12972 // Is it valid to wrap this item 14500 // Is it valid to wrap this item
12973 if (isValid(wrapName, nodeName) && isValid(parentName, wrapName)) { 14501 if (isValid(wrapName, nodeName) && isValid(parentName, wrapName) &&
14502 !(node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279)) {
12974 // Start wrapping 14503 // Start wrapping
12975 if (!currentWrapElm) { 14504 if (!currentWrapElm) {
12976 // Wrap the node 14505 // Wrap the node
12977 currentWrapElm = wrapElm.cloneNode(FALSE); 14506 currentWrapElm = wrapElm.cloneNode(FALSE);
12978 node.parentNode.insertBefore(currentWrapElm, node); 14507 node.parentNode.insertBefore(currentWrapElm, node);
12993 14522
12994 // Process siblings from range 14523 // Process siblings from range
12995 each(nodes, process); 14524 each(nodes, process);
12996 }); 14525 });
12997 14526
14527 // Wrap links inside as well, for example color inside a link when the wrapper is around the link
14528 if (format.wrap_links === false) {
14529 each(newWrappers, function(node) {
14530 function process(node) {
14531 var i, currentWrapElm, children;
14532
14533 if (node.nodeName === 'A') {
14534 currentWrapElm = wrapElm.cloneNode(FALSE);
14535 newWrappers.push(currentWrapElm);
14536
14537 children = tinymce.grep(node.childNodes);
14538 for (i = 0; i < children.length; i++)
14539 currentWrapElm.appendChild(children[i]);
14540
14541 node.appendChild(currentWrapElm);
14542 }
14543
14544 each(tinymce.grep(node.childNodes), process);
14545 };
14546
14547 process(node);
14548 });
14549 }
14550
12998 // Cleanup 14551 // Cleanup
12999 each(newWrappers, function(node) { 14552 each(newWrappers, function(node) {
13000 var childCount; 14553 var childCount;
13001 14554
13002 function getChildCount(node) { 14555 function getChildCount(node) {
13032 return clone || node; 14585 return clone || node;
13033 }; 14586 };
13034 14587
13035 childCount = getChildCount(node); 14588 childCount = getChildCount(node);
13036 14589
13037 // Remove empty nodes 14590 // Remove empty nodes but only if there is multiple wrappers and they are not block
13038 if (childCount === 0) { 14591 // elements so never remove single <h1></h1> since that would remove the currrent empty block element where the caret is at
14592 if ((newWrappers.length > 1 || !isBlock(node)) && childCount === 0) {
13039 dom.remove(node, 1); 14593 dom.remove(node, 1);
13040 return; 14594 return;
13041 } 14595 }
13042 14596
13043 if (format.inline || format.wrapper) { 14597 if (format.inline || format.wrapper) {
13049 each(formatList, function(format) { 14603 each(formatList, function(format) {
13050 // Merge all children of similar type will move styles from child to parent 14604 // Merge all children of similar type will move styles from child to parent
13051 // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span> 14605 // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span>
13052 // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span> 14606 // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span>
13053 each(dom.select(format.inline, node), function(child) { 14607 each(dom.select(format.inline, node), function(child) {
14608 var parent;
14609
14610 // When wrap_links is set to false we don't want
14611 // to remove the format on children within links
14612 if (format.wrap_links === false) {
14613 parent = child.parentNode;
14614
14615 do {
14616 if (parent.nodeName === 'A')
14617 return;
14618 } while (parent = parent.parentNode);
14619 }
14620
13054 removeFormat(format, vars, child, format.exact ? child : null); 14621 removeFormat(format, vars, child, format.exact ? child : null);
13055 }); 14622 });
13056 }); 14623 });
13057 14624
13058 // Remove child if direct parent is of same type 14625 // Remove child if direct parent is of same type
13089 rng.setStartBefore(node); 14656 rng.setStartBefore(node);
13090 rng.setEndAfter(node); 14657 rng.setEndAfter(node);
13091 14658
13092 applyRngStyle(expandRng(rng, formatList)); 14659 applyRngStyle(expandRng(rng, formatList));
13093 } else { 14660 } else {
13094 if (!selection.isCollapsed() || !format.inline) { 14661 if (!isCollapsed || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
14662 // Obtain selection node before selection is unselected by applyRngStyle()
14663 var curSelNode = ed.selection.getNode();
14664
13095 // Apply formatting to selection 14665 // Apply formatting to selection
13096 bookmark = selection.getBookmark(); 14666 bookmark = selection.getBookmark();
13097 applyRngStyle(expandRng(selection.getRng(TRUE), formatList)); 14667 applyRngStyle(expandRng(selection.getRng(TRUE), formatList));
14668
14669 // Colored nodes should be underlined so that the color of the underline matches the text color.
14670 if (format.styles && (format.styles.color || format.styles.textDecoration)) {
14671 tinymce.walk(curSelNode, processUnderlineAndColor, 'childNodes');
14672 processUnderlineAndColor(curSelNode);
14673 }
13098 14674
13099 selection.moveToBookmark(bookmark); 14675 selection.moveToBookmark(bookmark);
13100 selection.setRng(moveStart(selection.getRng(TRUE))); 14676 selection.setRng(moveStart(selection.getRng(TRUE)));
13101 ed.nodeChanged(); 14677 ed.nodeChanged();
13102 } else 14678 } else
13257 startContainer = getContainer(rng, TRUE); 14833 startContainer = getContainer(rng, TRUE);
13258 endContainer = getContainer(rng); 14834 endContainer = getContainer(rng);
13259 14835
13260 if (startContainer != endContainer) { 14836 if (startContainer != endContainer) {
13261 // Wrap start/end nodes in span element since these might be cloned/moved 14837 // Wrap start/end nodes in span element since these might be cloned/moved
13262 startContainer = wrap(startContainer, 'span', {id : '_start', _mce_type : 'bookmark'}); 14838 startContainer = wrap(startContainer, 'span', {id : '_start', 'data-mce-type' : 'bookmark'});
13263 endContainer = wrap(endContainer, 'span', {id : '_end', _mce_type : 'bookmark'}); 14839 endContainer = wrap(endContainer, 'span', {id : '_end', 'data-mce-type' : 'bookmark'});
13264 14840
13265 // Split start/end 14841 // Split start/end
13266 splitToFormatRoot(startContainer); 14842 splitToFormatRoot(startContainer);
13267 splitToFormatRoot(endContainer); 14843 splitToFormatRoot(endContainer);
13268 14844
13281 14857
13282 // Remove items between start/end 14858 // Remove items between start/end
13283 rangeUtils.walk(rng, function(nodes) { 14859 rangeUtils.walk(rng, function(nodes) {
13284 each(nodes, function(node) { 14860 each(nodes, function(node) {
13285 process(node); 14861 process(node);
14862
14863 // Remove parent span if it only contains text-decoration: underline, yet a parent node is also underlined.
14864 if (node.nodeType === 1 && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && getTextDecoration(node.parentNode) === 'underline') {
14865 removeFormat({'deep': false, 'exact': true, 'inline': 'span', 'styles': {'textDecoration' : 'underline'}}, null, node);
14866 }
13286 }); 14867 });
13287 }); 14868 });
13288 }; 14869 };
13289 14870
13290 // Handle node 14871 // Handle node
13294 rng.setEndAfter(node); 14875 rng.setEndAfter(node);
13295 removeRngStyle(rng); 14876 removeRngStyle(rng);
13296 return; 14877 return;
13297 } 14878 }
13298 14879
13299 if (!selection.isCollapsed() || !format.inline) { 14880 if (!selection.isCollapsed() || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) {
13300 bookmark = selection.getBookmark(); 14881 bookmark = selection.getBookmark();
13301 removeRngStyle(selection.getRng(TRUE)); 14882 removeRngStyle(selection.getRng(TRUE));
13302 selection.moveToBookmark(bookmark); 14883 selection.moveToBookmark(bookmark);
13303 14884
13304 // Check if start element still has formatting then we are at: "<b>text|</b>text" and need to move the start into the next text node 14885 // Check if start element still has formatting then we are at: "<b>text|</b>text" and need to move the start into the next text node
13310 } else 14891 } else
13311 performCaretAction('remove', name, vars); 14892 performCaretAction('remove', name, vars);
13312 }; 14893 };
13313 14894
13314 function toggle(name, vars, node) { 14895 function toggle(name, vars, node) {
13315 if (match(name, vars, node)) 14896 var fmt = get(name);
14897
14898 if (match(name, vars, node) && (!('toggle' in fmt[0]) || fmt[0]['toggle']))
13316 remove(name, vars, node); 14899 remove(name, vars, node);
13317 else 14900 else
13318 apply(name, vars, node); 14901 apply(name, vars, node);
13319 }; 14902 };
13320 14903
13574 15157
13575 function expandRng(rng, format, remove) { 15158 function expandRng(rng, format, remove) {
13576 var startContainer = rng.startContainer, 15159 var startContainer = rng.startContainer,
13577 startOffset = rng.startOffset, 15160 startOffset = rng.startOffset,
13578 endContainer = rng.endContainer, 15161 endContainer = rng.endContainer,
13579 endOffset = rng.endOffset, sibling, lastIdx; 15162 endOffset = rng.endOffset, sibling, lastIdx, leaf;
13580 15163
13581 // This function walks up the tree if there is no siblings before/after the node 15164 // This function walks up the tree if there is no siblings before/after the node
13582 function findParentContainer(container, child_name, sibling_name, root) { 15165 function findParentContainer(container, child_name, sibling_name, root) {
13583 var parent, child; 15166 var parent, child;
13584 15167
13603 container = container.parentNode; 15186 container = container.parentNode;
13604 } 15187 }
13605 15188
13606 return container; 15189 return container;
13607 }; 15190 };
15191
15192 // This function walks down the tree to find the leaf at the selection.
15193 // The offset is also returned as if node initially a leaf, the offset may be in the middle of the text node.
15194 function findLeaf(node, offset) {
15195 if (offset === undefined)
15196 offset = node.nodeType === 3 ? node.length : node.childNodes.length;
15197 while (node && node.hasChildNodes()) {
15198 node = node.childNodes[offset];
15199 if (node)
15200 offset = node.nodeType === 3 ? node.length : node.childNodes.length;
15201 }
15202 return { node: node, offset: offset };
15203 }
13608 15204
13609 // If index based start position then resolve it 15205 // If index based start position then resolve it
13610 if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) { 15206 if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
13611 lastIdx = startContainer.childNodes.length - 1; 15207 lastIdx = startContainer.childNodes.length - 1;
13612 startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset]; 15208 startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
13629 startContainer = startContainer.parentNode; 15225 startContainer = startContainer.parentNode;
13630 15226
13631 if (isBookmarkNode(startContainer)) 15227 if (isBookmarkNode(startContainer))
13632 startContainer = startContainer.nextSibling || startContainer; 15228 startContainer = startContainer.nextSibling || startContainer;
13633 15229
13634 if (isBookmarkNode(endContainer.parentNode)) 15230 if (isBookmarkNode(endContainer.parentNode)) {
15231 endOffset = dom.nodeIndex(endContainer);
13635 endContainer = endContainer.parentNode; 15232 endContainer = endContainer.parentNode;
13636 15233 }
13637 if (isBookmarkNode(endContainer)) 15234
13638 endContainer = endContainer.previousSibling || endContainer; 15235 if (isBookmarkNode(endContainer) && endContainer.previousSibling) {
13639 15236 endContainer = endContainer.previousSibling;
15237 endOffset = endContainer.length;
15238 }
15239
15240 if (format[0].inline) {
15241 // Avoid applying formatting to a trailing space.
15242 leaf = findLeaf(endContainer, endOffset);
15243 if (leaf.node) {
15244 while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling)
15245 leaf = findLeaf(leaf.node.previousSibling);
15246
15247 if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 &&
15248 leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
15249
15250 if (leaf.offset > 1) {
15251 endContainer = leaf.node;
15252 endContainer.splitText(leaf.offset - 1);
15253 } else if (leaf.node.previousSibling) {
15254 endContainer = leaf.node.previousSibling;
15255 }
15256 }
15257 }
15258 }
15259
13640 // Move start/end point up the tree if the leaves are sharp and if we are in different containers 15260 // Move start/end point up the tree if the leaves are sharp and if we are in different containers
13641 // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>! 15261 // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>!
13642 // This will reduce the number of wrapper elements that needs to be created 15262 // This will reduce the number of wrapper elements that needs to be created
13643 // Move start point up the tree 15263 // Move start point up the tree
13644 if (format[0].inline || format[0].block_expand) { 15264 if (format[0].inline || format[0].block_expand) {
13647 } 15267 }
13648 15268
13649 // Expand start/end container to matching selector 15269 // Expand start/end container to matching selector
13650 if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) { 15270 if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) {
13651 function findSelectorEndPoint(container, sibling_name) { 15271 function findSelectorEndPoint(container, sibling_name) {
13652 var parents, i, y; 15272 var parents, i, y, curFormat;
13653 15273
13654 if (container.nodeType == 3 && container.nodeValue.length == 0 && container[sibling_name]) 15274 if (container.nodeType == 3 && container.nodeValue.length == 0 && container[sibling_name])
13655 container = container[sibling_name]; 15275 container = container[sibling_name];
13656 15276
13657 parents = getParents(container); 15277 parents = getParents(container);
13658 for (i = 0; i < parents.length; i++) { 15278 for (i = 0; i < parents.length; i++) {
13659 for (y = 0; y < format.length; y++) { 15279 for (y = 0; y < format.length; y++) {
13660 if (dom.is(parents[i], format[y].selector)) 15280 curFormat = format[y];
15281
15282 // If collapsed state is set then skip formats that doesn't match that
15283 if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed)
15284 continue;
15285
15286 if (dom.is(parents[i], curFormat.selector))
13661 return parents[i]; 15287 return parents[i];
13662 } 15288 }
13663 } 15289 }
13664 15290
13665 return container; 15291 return container;
13765 }); 15391 });
13766 15392
13767 // Remove style attribute if it's empty 15393 // Remove style attribute if it's empty
13768 if (stylesModified && dom.getAttrib(node, 'style') == '') { 15394 if (stylesModified && dom.getAttrib(node, 'style') == '') {
13769 node.removeAttribute('style'); 15395 node.removeAttribute('style');
13770 node.removeAttribute('_mce_style'); 15396 node.removeAttribute('data-mce-style');
13771 } 15397 }
13772 15398
13773 // Remove attributes 15399 // Remove attributes
13774 each(format.attributes, function(value, name) { 15400 each(format.attributes, function(value, name) {
13775 var valueOut; 15401 var valueOut;
13806 if (name == "class") 15432 if (name == "class")
13807 node.removeAttribute('className'); 15433 node.removeAttribute('className');
13808 15434
13809 // Remove mce prefixed attributes 15435 // Remove mce prefixed attributes
13810 if (MCE_ATTR_RE.test(name)) 15436 if (MCE_ATTR_RE.test(name))
13811 node.removeAttribute('_mce_' + name); 15437 node.removeAttribute('data-mce-' + name);
13812 15438
13813 node.removeAttribute(name); 15439 node.removeAttribute(name);
13814 } 15440 }
13815 }); 15441 });
13816 15442
13891 } 15517 }
13892 } 15518 }
13893 }; 15519 };
13894 15520
13895 function isBookmarkNode(node) { 15521 function isBookmarkNode(node) {
13896 return node && node.nodeType == 1 && node.getAttribute('_mce_type') == 'bookmark'; 15522 return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark';
13897 }; 15523 };
13898 15524
13899 function mergeSiblings(prev, next) { 15525 function mergeSiblings(prev, next) {
13900 var marker, sibling, tmpSibling; 15526 var marker, sibling, tmpSibling;
13901 15527
13962 15588
13963 // Check if next/prev exists and that they are elements 15589 // Check if next/prev exists and that they are elements
13964 if (prev && next) { 15590 if (prev && next) {
13965 function findElementSibling(node, sibling_name) { 15591 function findElementSibling(node, sibling_name) {
13966 for (sibling = node; sibling; sibling = sibling[sibling_name]) { 15592 for (sibling = node; sibling; sibling = sibling[sibling_name]) {
13967 if (sibling.nodeType == 3 && !isWhiteSpaceNode(sibling)) 15593 if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0)
13968 return node; 15594 return node;
13969 15595
13970 if (sibling.nodeType == 1 && !isBookmarkNode(sibling)) 15596 if (sibling.nodeType == 1 && !isBookmarkNode(sibling))
13971 return sibling; 15597 return sibling;
13972 } 15598 }
14039 15665
14040 function perform(caret_node) { 15666 function perform(caret_node) {
14041 // Apply pending formats 15667 // Apply pending formats
14042 each(pendingFormats.apply.reverse(), function(item) { 15668 each(pendingFormats.apply.reverse(), function(item) {
14043 apply(item.name, item.vars, caret_node); 15669 apply(item.name, item.vars, caret_node);
15670
15671 // Colored nodes should be underlined so that the color of the underline matches the text color.
15672 if (item.name === 'forecolor' && item.vars.value)
15673 processUnderlineAndColor(caret_node.parentNode);
14044 }); 15674 });
14045 15675
14046 // Remove pending formats 15676 // Remove pending formats
14047 each(pendingFormats.remove.reverse(), function(item) { 15677 each(pendingFormats.remove.reverse(), function(item) {
14048 remove(item.name, item.vars, caret_node); 15678 remove(item.name, item.vars, caret_node);
14170 }); 15800 });
14171 } 15801 }
14172 }; 15802 };
14173 15803
14174 ed.onPreProcess.add(convert); 15804 ed.onPreProcess.add(convert);
15805 ed.onSetContent.add(convert);
14175 15806
14176 ed.onInit.add(function() { 15807 ed.onInit.add(function() {
14177 ed.selection.onSetContent.add(convert); 15808 ed.selection.onSetContent.add(convert);
14178 }); 15809 });
14179 } 15810 }