X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=webcit%2Ftiny_mce%2Ftiny_mce_src.js;h=8c665b09535c46d2bdac3012c7b881f0948b6e2c;hp=2b3453ba9b4b9f68a3bdd71bc9713030e072b14d;hb=b05f4eef4014db3885787ef15107cba93c932ac9;hpb=b347fec899815ec89b2738a0877880ee81e74b59
diff --git a/webcit/tiny_mce/tiny_mce_src.js b/webcit/tiny_mce/tiny_mce_src.js
index 2b3453ba9..8c665b095 100644
--- a/webcit/tiny_mce/tiny_mce_src.js
+++ b/webcit/tiny_mce/tiny_mce_src.js
@@ -5,9 +5,9 @@
var tinymce = {
majorVersion : '3',
- minorVersion : '3.9.2',
+ minorVersion : '4.5',
- releaseDate : '2010-09-29',
+ releaseDate : '2011-09-06',
_init : function() {
var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v;
@@ -20,6 +20,12 @@
t.isIE6 = t.isIE && /MSIE [56]/.test(ua);
+ t.isIE7 = t.isIE && /MSIE [7]/.test(ua);
+
+ t.isIE8 = t.isIE && /MSIE [8]/.test(ua);
+
+ t.isIE9 = t.isIE && /MSIE [9]/.test(ua);
+
t.isGecko = !t.isWebKit && /Gecko/.test(ua);
t.isMac = ua.indexOf('Mac') != -1;
@@ -27,6 +33,8 @@
t.isAir = /adobeair/i.test(ua);
t.isIDevice = /(iPad|iPhone)/.test(ua);
+
+ t.isIOS5 = t.isIDevice && ua.match(/AppleWebKit\/(\d*)/)[1]>=534;
// TinyMCE .NET webcontrol might be setting the values for TinyMCE
if (win.tinyMCEPreInit) {
@@ -103,6 +111,24 @@
return typeof(o) == t;
},
+ makeMap : function(items, delim, map) {
+ var i;
+
+ items = items || [];
+ delim = delim || ',';
+
+ if (typeof(items) == "string")
+ items = items.split(delim);
+
+ map = map || {};
+
+ i = items.length;
+ while (i--)
+ map[items[i]] = {};
+
+ return map;
+ },
+
each : function(o, cb, s) {
var n, l;
@@ -185,7 +211,7 @@
return (s ? '' + s : '').replace(whiteSpaceRe, '');
},
- create : function(s, p) {
+ create : function(s, p, root) {
var t = this, sp, ns, cn, scn, c, de = 0;
// Parse : :
@@ -193,7 +219,7 @@
cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
// Create namespace for new class
- ns = t.createNS(s[3].replace(/\.\w+$/, ''));
+ ns = t.createNS(s[3].replace(/\.\w+$/, ''), root);
// Class already exists
if (ns[cn])
@@ -460,7 +486,11 @@
// Expose tinymce namespace to the global namespace (window)
win.tinymce = win.tinyMCE = tinymce;
-})(window);
+
+ // Describe the different namespaces
+
+ })(window);
+
tinymce.create('tinymce.util.Dispatcher', {
@@ -521,7 +551,7 @@ tinymce.create('tinymce.util.Dispatcher', {
tinymce.create('tinymce.util.URI', {
URI : function(u, s) {
- var t = this, o, a, b;
+ var t = this, o, a, b, base_url;
// Trim whitespace
u = tinymce.trim(u);
@@ -529,8 +559,9 @@ tinymce.create('tinymce.util.Dispatcher', {
// Default settings
s = t.settings = s || {};
- // Strange app protocol or local anchor
- if (/^(mailto|tel|news|javascript|about|data):/i.test(u) || /^\s*#/.test(u)) {
+ // Strange app protocol that isn't http/https or local anchor
+ // For example: mailto,skype,tel etc.
+ if (/^([\w\-]+):([^\/]{2})/i.test(u) || /^\s*#/.test(u)) {
t.source = u;
return;
}
@@ -540,8 +571,10 @@ tinymce.create('tinymce.util.Dispatcher', {
u = (s.base_uri ? s.base_uri.protocol || 'http' : 'http') + '://mce_host' + u;
// Relative path http:// or protocol relative //path
- if (!/^\w*:?\/\//.test(u))
- u = (s.base_uri.protocol || 'http') + '://mce_host' + t.toAbsPath(s.base_uri.path, u);
+ if (!/^[\w-]*:?\/\//.test(u)) {
+ base_url = s.base_uri ? s.base_uri.path : new tinymce.util.URI(location.href).directory;
+ u = ((s.base_uri && s.base_uri.protocol) || 'http') + '://mce_host' + t.toAbsPath(base_url, u);
+ }
// Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
u = u.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
@@ -828,9 +861,11 @@ tinymce.create('tinymce.util.Dispatcher', {
});
})();
-tinymce.create('static tinymce.util.JSON', {
- serialize : function(o) {
- var i, v, s = tinymce.util.JSON.serialize, t;
+(function() {
+ function serialize(o, quote) {
+ var i, v, t;
+
+ quote = quote || '"';
if (o == null)
return 'null';
@@ -840,7 +875,11 @@ tinymce.create('static tinymce.util.JSON', {
if (t == 'string') {
v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
- return '"' + o.replace(/([\u0080-\uFFFF\x00-\x1f\"])/g, function(a, b) {
+ return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) {
+ // Make sure single quotes never get encoded inside double quotes for JSON compatibility
+ if (quote === '"' && a === "'")
+ return a;
+
i = v.indexOf(b);
if (i + 1)
@@ -849,13 +888,13 @@ tinymce.create('static tinymce.util.JSON', {
a = b.charCodeAt().toString(16);
return '\\u' + '0000'.substring(a.length) + a;
- }) + '"';
+ }) + quote;
}
if (t == 'object') {
if (o.hasOwnProperty && o instanceof Array) {
for (i=0, v = '['; i 0 ? ',' : '') + s(o[i]);
+ v += (i > 0 ? ',' : '') + serialize(o[i], quote);
return v + ']';
}
@@ -863,24 +902,27 @@ tinymce.create('static tinymce.util.JSON', {
v = '{';
for (i in o)
- v += typeof o[i] != 'function' ? (v.length > 1 ? ',"' : '"') + i + '":' + s(o[i]) : '';
+ v += typeof o[i] != 'function' ? (v.length > 1 ? ',' + quote : quote) + i + quote +':' + serialize(o[i], quote) : '';
return v + '}';
}
return '' + o;
- },
+ };
- parse : function(s) {
- try {
- return eval('(' + s + ')');
- } catch (ex) {
- // Ignore
- }
- }
+ tinymce.util.JSON = {
+ serialize: serialize,
- });
+ parse: function(s) {
+ try {
+ return eval('(' + s + ')');
+ } catch (ex) {
+ // Ignore
+ }
+ }
+ };
+})();
tinymce.create('static tinymce.util.XHR', {
send : function(o) {
var x, t, w = window, c = 0;
@@ -971,7 +1013,8 @@ tinymce.create('static tinymce.util.XHR', {
};
o.error = function(ty, x) {
- ecb.call(o.error_scope || o.scope, ty, x);
+ if (ecb)
+ ecb.call(o.error_scope || o.scope, ty, x);
};
o.data = JSON.serialize({
@@ -993,5820 +1036,7420 @@ tinymce.create('static tinymce.util.XHR', {
}
});
}());
-(function(tinymce) {
- // Shorten names
- var each = tinymce.each,
- is = tinymce.is,
- isWebKit = tinymce.isWebKit,
- isIE = tinymce.isIE,
- 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)$/,
- boolAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'),
- mceAttribs = makeMap('src,href,style,coords,shape'),
- encodedChars = {'&' : '&', '"' : '"', '<' : '<', '>' : '>'},
- encodeCharsRe = /[<>&\"]/g,
- simpleSelectorRe = /^([a-z0-9],?)+$/i,
- tagRegExp = /<(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)(\s*\/?)>/g,
- attrRegExp = /(\w+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;
+(function(tinymce){
+ tinymce.VK = {
+ DELETE:46,
+ BACKSPACE:8
+
+ }
- function makeMap(str) {
- var map = {}, i;
+})(tinymce);
- str = str.split(',');
- for (i = str.length; i >= 0; i--)
- map[str[i]] = 1;
+(function(tinymce) {
+ var VK = tinymce.VK, BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE;
- return map;
- };
+ function cleanupStylesWhenDeleting(ed) {
+ var dom = ed.dom, selection = ed.selection;
- tinymce.create('tinymce.dom.DOMUtils', {
- doc : null,
- root : null,
- files : null,
- pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/,
- props : {
- "for" : "htmlFor",
- "class" : "className",
- className : "className",
- checked : "checked",
- disabled : "disabled",
- maxlength : "maxLength",
- readonly : "readOnly",
- selected : "selected",
- value : "value",
- id : "id",
- name : "name",
- type : "type"
- },
+ ed.onKeyDown.add(function(ed, e) {
+ var rng, blockElm, node, clonedSpan, isDelete;
- DOMUtils : function(d, s) {
- var t = this, globalStyle;
+ isDelete = e.keyCode == DELETE;
+ if (isDelete || e.keyCode == BACKSPACE) {
+ e.preventDefault();
+ rng = selection.getRng();
- t.doc = d;
- t.win = window;
- t.files = {};
- t.cssFlicker = false;
- t.counter = 0;
- t.stdMode = d.documentMode >= 8;
- t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode;
+ // Find root block
+ blockElm = dom.getParent(rng.startContainer, dom.isBlock);
- t.settings = s = tinymce.extend({
- keep_values : false,
- hex_colors : 1,
- process_html : 1
- }, s);
+ // On delete clone the root span of the next block element
+ if (isDelete)
+ blockElm = dom.getNext(blockElm, dom.isBlock);
- // Fix IE6SP2 flicker and check it failed for pre SP2
- if (tinymce.isIE6) {
- try {
- d.execCommand('BackgroundImageCache', false, true);
- } catch (e) {
- t.cssFlicker = true;
+ // Locate root span element and clone it since it would otherwise get merged by the "apple-style-span" on delete/backspace
+ if (blockElm) {
+ node = blockElm.firstChild;
+
+ if (node && node.nodeName === 'SPAN') {
+ clonedSpan = node.cloneNode(false);
+ }
}
- }
- // Build styles list
- if (s.valid_styles) {
- t._styles = {};
+ // Do the backspace/delete actiopn
+ ed.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
+
+ // Find all odd apple-style-spans
+ blockElm = dom.getParent(rng.startContainer, dom.isBlock);
+ tinymce.each(dom.select('span.Apple-style-span,font.Apple-style-span', blockElm), function(span) {
+ var rng = dom.createRng();
+
+ // Set range selection before the span we are about to remove
+ rng.setStartBefore(span);
+ rng.setEndBefore(span);
+
+ if (clonedSpan) {
+ dom.replace(clonedSpan.cloneNode(false), span, true);
+ } else {
+ dom.remove(span, true);
+ }
- // Convert styles into a rule list
- each(s.valid_styles, function(value, key) {
- t._styles[key] = tinymce.explode(value);
+ // Restore the selection
+ selection.setRng(rng);
});
}
+ });
+ };
- tinymce.addUnload(t.destroy, t);
- },
+ function emptyEditorWhenDeleting(ed) {
+ ed.onKeyUp.add(function(ed, e) {
+ var keyCode = e.keyCode;
- getRoot : function() {
- var t = this, s = t.settings;
+ if (keyCode == DELETE || keyCode == BACKSPACE) {
+ if (ed.dom.isEmpty(ed.getBody())) {
+ ed.setContent('', {format : 'raw'});
+ ed.nodeChanged();
+ return;
+ }
+ }
+ });
+ };
+
+ tinymce.create('tinymce.util.Quirks', {
+ Quirks: function(ed) {
+ // Load WebKit specific fixed
+ if (tinymce.isWebKit) {
+ cleanupStylesWhenDeleting(ed);
+ emptyEditorWhenDeleting(ed);
+ }
- return (s && t.get(s.root_element)) || t.doc.body;
- },
+ // Load IE specific fixes
+ if (tinymce.isIE) {
+ emptyEditorWhenDeleting(ed);
+ }
+ }
+ });
+})(tinymce);
+(function(tinymce) {
+ var namedEntities, baseEntities, reverseEntities,
+ attrsCharsRegExp = /[&<>\"\u007E-\uD7FF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
+ textCharsRegExp = /[<>&\u007E-\uD7FF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
+ rawCharsRegExp = /[<>&\"\']/g,
+ entityRegExp = /&(#x|#)?([\w]+);/g,
+ asciiMap = {
+ 128 : "\u20AC", 130 : "\u201A", 131 : "\u0192", 132 : "\u201E", 133 : "\u2026", 134 : "\u2020",
+ 135 : "\u2021", 136 : "\u02C6", 137 : "\u2030", 138 : "\u0160", 139 : "\u2039", 140 : "\u0152",
+ 142 : "\u017D", 145 : "\u2018", 146 : "\u2019", 147 : "\u201C", 148 : "\u201D", 149 : "\u2022",
+ 150 : "\u2013", 151 : "\u2014", 152 : "\u02DC", 153 : "\u2122", 154 : "\u0161", 155 : "\u203A",
+ 156 : "\u0153", 158 : "\u017E", 159 : "\u0178"
+ };
- getViewPort : function(w) {
- var d, b;
+ // Raw entities
+ baseEntities = {
+ '\"' : '"', // Needs to be escaped since the YUI compressor would otherwise break the code
+ "'" : ''',
+ '<' : '<',
+ '>' : '>',
+ '&' : '&'
+ };
- w = !w ? this.win : w;
- d = w.document;
- b = this.boxModel ? d.documentElement : d.body;
+ // Reverse lookup table for raw entities
+ reverseEntities = {
+ '<' : '<',
+ '>' : '>',
+ '&' : '&',
+ '"' : '"',
+ ''' : "'"
+ };
- // Returns viewport size excluding scrollbars
- return {
- x : w.pageXOffset || b.scrollLeft,
- y : w.pageYOffset || b.scrollTop,
- w : w.innerWidth || b.clientWidth,
- h : w.innerHeight || b.clientHeight
- };
- },
+ // Decodes text by using the browser
+ function nativeDecode(text) {
+ var elm;
- getRect : function(e) {
- var p, t = this, sr;
+ elm = document.createElement("div");
+ elm.innerHTML = text;
- e = t.get(e);
- p = t.getPos(e);
- sr = t.getSize(e);
+ return elm.textContent || elm.innerText || text;
+ };
- return {
- x : p.x,
- y : p.y,
- w : sr.w,
- h : sr.h
- };
- },
+ // Build a two way lookup table for the entities
+ function buildEntitiesLookup(items, radix) {
+ var i, chr, entity, lookup = {};
- getSize : function(e) {
- var t = this, w, h;
+ if (items) {
+ items = items.split(',');
+ radix = radix || 10;
- e = t.get(e);
- w = t.getStyle(e, 'width');
- h = t.getStyle(e, 'height');
+ // Build entities lookup table
+ for (i = 0; i < items.length; i += 2) {
+ chr = String.fromCharCode(parseInt(items[i], radix));
- // Non pixel value, then force offset/clientWidth
- if (w.indexOf('px') === -1)
- w = 0;
+ // Only add non base entities
+ if (!baseEntities[chr]) {
+ entity = '&' + items[i + 1] + ';';
+ lookup[chr] = entity;
+ lookup[entity] = chr;
+ }
+ }
- // Non pixel value, then force offset/clientWidth
- if (h.indexOf('px') === -1)
- h = 0;
+ return lookup;
+ }
+ };
- return {
- w : parseInt(w) || e.offsetWidth || e.clientWidth,
- h : parseInt(h) || e.offsetHeight || e.clientHeight
- };
+ // Unpack entities lookup where the numbers are in radix 32 to reduce the size
+ namedEntities = buildEntitiesLookup(
+ '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
+ '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
+ '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
+ '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
+ '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
+ '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
+ '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
+ '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
+ '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
+ '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
+ 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
+ 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
+ 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
+ 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
+ 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
+ '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
+ '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
+ '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
+ '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
+ '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
+ 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
+ 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
+ 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
+ '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
+ '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro'
+ , 32);
+
+ tinymce.html = tinymce.html || {};
+
+ tinymce.html.Entities = {
+ encodeRaw : function(text, attr) {
+ return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
+ return baseEntities[chr] || chr;
+ });
},
- getParent : function(n, f, r) {
- return this.getParents(n, f, r, false);
+ encodeAllRaw : function(text) {
+ return ('' + text).replace(rawCharsRegExp, function(chr) {
+ return baseEntities[chr] || chr;
+ });
},
- getParents : function(n, f, r, c) {
- var t = this, na, se = t.settings, o = [];
+ encodeNumeric : function(text, attr) {
+ return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
+ // Multi byte sequence convert it to a single entity
+ if (chr.length > 1)
+ return '' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';';
- n = t.get(n);
- c = c === undefined;
+ return baseEntities[chr] || '' + chr.charCodeAt(0) + ';';
+ });
+ },
- if (se.strict_root)
- r = r || t.getRoot();
+ encodeNamed : function(text, attr, entities) {
+ entities = entities || namedEntities;
- // Wrap node name as func
- if (is(f, 'string')) {
- na = f;
+ return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
+ return baseEntities[chr] || entities[chr] || chr;
+ });
+ },
- if (f === '*') {
- f = function(n) {return n.nodeType == 1;};
- } else {
- f = function(n) {
- return t.is(n, na);
- };
- }
- }
+ getEncodeFunc : function(name, entities) {
+ var Entities = tinymce.html.Entities;
- while (n) {
- if (n == r || !n.nodeType || n.nodeType === 9)
- break;
+ entities = buildEntitiesLookup(entities) || namedEntities;
- if (!f || f(n)) {
- if (c)
- o.push(n);
- else
- return n;
- }
+ function encodeNamedAndNumeric(text, attr) {
+ return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
+ return baseEntities[chr] || entities[chr] || '' + chr.charCodeAt(0) + ';' || chr;
+ });
+ };
- n = n.parentNode;
- }
+ function encodeCustomNamed(text, attr) {
+ return Entities.encodeNamed(text, attr, entities);
+ };
- return c ? o : null;
- },
+ // Replace + with , to be compatible with previous TinyMCE versions
+ name = tinymce.makeMap(name.replace(/\+/g, ','));
- get : function(e) {
- var n;
+ // Named and numeric encoder
+ if (name.named && name.numeric)
+ return encodeNamedAndNumeric;
- if (e && this.doc && typeof(e) == 'string') {
- n = e;
- e = this.doc.getElementById(e);
+ // Named encoder
+ if (name.named) {
+ // Custom names
+ if (entities)
+ return encodeCustomNamed;
- // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
- if (e && e.id !== n)
- return this.doc.getElementsByName(n)[1];
+ return Entities.encodeNamed;
}
- return e;
- },
+ // Numeric
+ if (name.numeric)
+ return Entities.encodeNumeric;
- getNext : function(node, selector) {
- return this._findSib(node, selector, 'nextSibling');
+ // Raw encoder
+ return Entities.encodeRaw;
},
- getPrev : function(node, selector) {
- return this._findSib(node, selector, 'previousSibling');
- },
+ decode : function(text) {
+ return text.replace(entityRegExp, function(all, numeric, value) {
+ if (numeric) {
+ value = parseInt(value, numeric.length === 2 ? 16 : 10);
+ // Support upper UTF
+ if (value > 0xFFFF) {
+ value -= 0x10000;
- select : function(pa, s) {
- var t = this;
+ return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF));
+ } else
+ return asciiMap[value] || String.fromCharCode(value);
+ }
- return tinymce.dom.Sizzle(pa, t.get(s) || t.get(t.settings.root_element) || t.doc, []);
- },
+ return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
+ });
+ }
+ };
+})(tinymce);
- is : function(n, selector) {
- var i;
+tinymce.html.Styles = function(settings, schema) {
+ var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
+ urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
+ styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
+ trimRightRegExp = /\s+$/,
+ urlColorRegExp = /rgb/,
+ undef, i, encodingLookup = {}, encodingItems;
- // If it isn't an array then try to do some simple selectors instead of Sizzle for to boost performance
- if (n.length === undefined) {
- // Simple all selector
- if (selector === '*')
- return n.nodeType == 1;
+ settings = settings || {};
- // Simple selector just elements
- if (simpleSelectorRe.test(selector)) {
- selector = selector.toLowerCase().split(/,/);
- n = n.nodeName.toLowerCase();
+ encodingItems = '\\" \\\' \\; \\: ; : \uFEFF'.split(' ');
+ for (i = 0; i < encodingItems.length; i++) {
+ encodingLookup[encodingItems[i]] = '\uFEFF' + i;
+ encodingLookup['\uFEFF' + i] = encodingItems[i];
+ }
- for (i = selector.length - 1; i >= 0; i--) {
- if (selector[i] == n)
- return true;
- }
+ function toHex(match, r, g, b) {
+ function hex(val) {
+ val = parseInt(val).toString(16);
- return false;
- }
- }
+ return val.length > 1 ? val : '0' + val; // 0 -> 00
+ };
- return tinymce.dom.Sizzle.matches(selector, n.nodeType ? [n] : n).length > 0;
+ return '#' + hex(r) + hex(g) + hex(b);
+ };
+
+ return {
+ toHex : function(color) {
+ return color.replace(rgbRegExp, toHex);
},
+ parse : function(css) {
+ var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this;
- add : function(p, n, a, h, c) {
- var t = this;
+ function compress(prefix, suffix) {
+ var top, right, bottom, left;
- return this.run(p, function(p) {
- var e, k;
+ // Get values and check it it needs compressing
+ top = styles[prefix + '-top' + suffix];
+ if (!top)
+ return;
- e = is(n, 'string') ? t.doc.createElement(n) : n;
- t.setAttribs(e, a);
+ right = styles[prefix + '-right' + suffix];
+ if (top != right)
+ return;
- if (h) {
- if (h.nodeType)
- e.appendChild(h);
- else
- t.setHTML(e, h);
- }
+ bottom = styles[prefix + '-bottom' + suffix];
+ if (right != bottom)
+ return;
- return !c ? p.appendChild(e) : e;
- });
- },
+ left = styles[prefix + '-left' + suffix];
+ if (bottom != left)
+ return;
- create : function(n, a, h) {
- return this.add(this.doc.createElement(n), n, a, h, 1);
- },
+ // Compress
+ styles[prefix + suffix] = left;
+ delete styles[prefix + '-top' + suffix];
+ delete styles[prefix + '-right' + suffix];
+ delete styles[prefix + '-bottom' + suffix];
+ delete styles[prefix + '-left' + suffix];
+ };
- createHTML : function(n, a, h) {
- var o = '', t = this, k;
+ function canCompress(key) {
+ var value = styles[key], i;
- o += '<' + n;
+ if (!value || value.indexOf(' ') < 0)
+ return;
- for (k in a) {
- if (a.hasOwnProperty(k))
- o += ' ' + k + '="' + t.encode(a[k]) + '"';
- }
+ value = value.split(' ');
+ i = value.length;
+ while (i--) {
+ if (value[i] !== value[0])
+ return false;
+ }
- // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
- if (typeof(h) != "undefined")
- return o + '>' + h + '' + n + '>';
+ styles[key] = value[0];
- return o + ' />';
- },
+ return true;
+ };
- remove : function(node, keep_children) {
- return this.run(node, function(node) {
- var parent, child;
+ function compress2(target, a, b, c) {
+ if (!canCompress(a))
+ return;
- parent = node.parentNode;
+ if (!canCompress(b))
+ return;
- if (!parent)
- return null;
+ if (!canCompress(c))
+ return;
- if (keep_children) {
- while (child = node.firstChild) {
- // IE 8 will crash if you don't remove completely empty text nodes
- if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue)
- parent.insertBefore(child, node);
- else
- node.removeChild(child);
- }
- }
+ // Compress
+ styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
+ delete styles[a];
+ delete styles[b];
+ delete styles[c];
+ };
- return parent.removeChild(node);
- });
- },
+ // Encodes the specified string by replacing all \" \' ; : with _
+ function encode(str) {
+ isEncoded = true;
- setStyle : function(n, na, v) {
- var t = this;
+ return encodingLookup[str];
+ };
- return t.run(n, function(e) {
- var s, i;
+ // Decodes the specified string by replacing all _ with it's original value \" \' etc
+ // It will also decode the \" \' if keep_slashes is set to fale or omitted
+ function decode(str, keep_slashes) {
+ if (isEncoded) {
+ str = str.replace(/\uFEFF[0-9]/g, function(str) {
+ return encodingLookup[str];
+ });
+ }
- s = e.style;
+ if (!keep_slashes)
+ str = str.replace(/\\([\'\";:])/g, "$1");
- // Camelcase it, if needed
- na = na.replace(/-(\D)/g, function(a, b){
- return b.toUpperCase();
+ return str;
+ }
+
+ if (css) {
+ // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing
+ css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
+ return str.replace(/[;:]/g, encode);
});
- // Default px suffix on these
- if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
- v += 'px';
+ // Parse styles
+ while (matches = styleRegExp.exec(css)) {
+ name = matches[1].replace(trimRightRegExp, '').toLowerCase();
+ value = matches[2].replace(trimRightRegExp, '');
- switch (na) {
- case 'opacity':
- // IE specific opacity
- if (isIE) {
- s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
+ if (name && value.length > 0) {
+ // Opera will produce 700 instead of bold in their style values
+ if (name === 'font-weight' && value === '700')
+ value = 'bold';
+ else if (name === 'color' || name === 'background-color') // Lowercase colors like RED
+ value = value.toLowerCase();
- if (!n.currentStyle || !n.currentStyle.hasLayout)
- s.display = 'inline-block';
- }
+ // Convert RGB colors to HEX
+ value = value.replace(rgbRegExp, toHex);
- // Fix for older browsers
- s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
- break;
+ // Convert URLs and force them into url('value') format
+ value = value.replace(urlOrStrRegExp, function(match, url, url2, url3, str, str2) {
+ str = str || str2;
- case 'float':
- isIE ? s.styleFloat = v : s.cssFloat = v;
- break;
-
- default:
- s[na] = v || '';
- }
+ if (str) {
+ str = decode(str);
- // Force update of the style data
- if (t.settings.update_styles)
- t.setAttrib(e, '_mce_style');
- });
- },
+ // Force strings into single quote format
+ return "'" + str.replace(/\'/g, "\\'") + "'";
+ }
- getStyle : function(n, na, c) {
- n = this.get(n);
+ url = decode(url || url2 || url3);
- if (!n)
- return false;
+ // Convert the URL to relative/absolute depending on config
+ if (urlConverter)
+ url = urlConverter.call(urlConverterScope, url, 'style');
- // Gecko
- if (this.doc.defaultView && c) {
- // Remove camelcase
- na = na.replace(/[A-Z]/g, function(a){
- return '-' + a;
- });
+ // Output new URL format
+ return "url('" + url.replace(/\'/g, "\\'") + "')";
+ });
- try {
- return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
- } catch (ex) {
- // Old safari might fail
- return null;
+ styles[name] = isEncoded ? decode(value, true) : value;
+ }
+
+ styleRegExp.lastIndex = matches.index + matches[0].length;
}
+
+ // Compress the styles to reduce it's size for example IE will expand styles
+ compress("border", "");
+ compress("border", "-width");
+ compress("border", "-color");
+ compress("border", "-style");
+ compress("padding", "");
+ compress("margin", "");
+ compress2('border', 'border-width', 'border-style', 'border-color');
+
+ // Remove pointless border, IE produces these
+ if (styles.border === 'medium none')
+ delete styles.border;
}
- // Camelcase it, if needed
- na = na.replace(/-(\D)/g, function(a, b){
- return b.toUpperCase();
- });
+ return styles;
+ },
- if (na == 'float')
- na = isIE ? 'styleFloat' : 'cssFloat';
+ serialize : function(styles, element_name) {
+ var css = '', name, value;
- // IE & Opera
- if (n.currentStyle && c)
- return n.currentStyle[na];
+ function serializeStyles(name) {
+ var styleList, i, l, value;
- return n.style[na];
- },
+ styleList = schema.styles[name];
+ if (styleList) {
+ for (i = 0, l = styleList.length; i < l; i++) {
+ name = styleList[i];
+ value = styles[name];
- setStyles : function(e, o) {
- var t = this, s = t.settings, ol;
+ if (value !== undef && value.length > 0)
+ css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
+ }
+ }
+ };
- ol = s.update_styles;
- s.update_styles = 0;
+ // Serialize styles according to schema
+ if (element_name && schema && schema.styles) {
+ // Serialize global styles and element specific styles
+ serializeStyles('*');
+ serializeStyles(element_name);
+ } else {
+ // Output the styles in the order they are inside the object
+ for (name in styles) {
+ value = styles[name];
- each(o, function(v, n) {
- t.setStyle(e, n, v);
- });
+ if (value !== undef && value.length > 0)
+ css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
+ }
+ }
- // Update style info
- s.update_styles = ol;
- if (s.update_styles)
- t.setAttrib(e, s.cssText);
- },
+ return css;
+ }
+ };
+};
- setAttrib : function(e, n, v) {
- var t = this;
+(function(tinymce) {
+ var transitional = {}, boolAttrMap, blockElementsMap, shortEndedElementsMap, nonEmptyElementsMap, customElementsMap = {},
+ defaultWhiteSpaceElementsMap, selfClosingElementsMap, makeMap = tinymce.makeMap, each = tinymce.each;
- // Whats the point
- if (!e || !n)
- return;
+ function split(str, delim) {
+ return str.split(delim || ',');
+ };
- // Strict XML mode
- if (t.settings.strict)
- n = n.toLowerCase();
+ function unpack(lookup, data) {
+ var key, elements = {};
- return this.run(e, function(e) {
- var s = t.settings;
+ function replace(value) {
+ return value.replace(/[A-Z]+/g, function(key) {
+ return replace(lookup[key]);
+ });
+ };
- switch (n) {
- case "style":
- if (!is(v, 'string')) {
- each(v, function(v, n) {
- t.setStyle(e, n, v);
- });
+ // Unpack lookup
+ for (key in lookup) {
+ if (lookup.hasOwnProperty(key))
+ lookup[key] = replace(lookup[key]);
+ }
- return;
- }
+ // Unpack and parse data into object map
+ replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) {
+ attributes = split(attributes, '|');
- // No mce_style for elements with these since they might get resized by the user
- if (s.keep_values) {
- if (v && !t._isRes(v))
- e.setAttribute('_mce_style', v, 2);
- else
- e.removeAttribute('_mce_style', 2);
- }
+ elements[name] = {
+ attributes : makeMap(attributes),
+ attributesOrder : attributes,
+ children : makeMap(children, '|', {'#comment' : {}})
+ }
+ });
- e.style.cssText = v;
- break;
+ return elements;
+ };
- case "class":
- e.className = v || ''; // Fix IE null bug
- break;
+ // Build a lookup table for block elements both lowercase and uppercase
+ blockElementsMap = 'h1,h2,h3,h4,h5,h6,hr,p,div,address,pre,form,table,tbody,thead,tfoot,' +
+ 'th,tr,td,li,ol,ul,caption,blockquote,center,dl,dt,dd,dir,fieldset,' +
+ 'noscript,menu,isindex,samp,header,footer,article,section,hgroup';
+ blockElementsMap = makeMap(blockElementsMap, ',', makeMap(blockElementsMap.toUpperCase()));
+
+ // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size
+ transitional = unpack({
+ Z : 'H|K|N|O|P',
+ Y : 'X|form|R|Q',
+ ZG : 'E|span|width|align|char|charoff|valign',
+ X : 'p|T|div|U|W|isindex|fieldset|table',
+ ZF : 'E|align|char|charoff|valign',
+ W : 'pre|hr|blockquote|address|center|noframes',
+ ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height',
+ ZD : '[E][S]',
+ U : 'ul|ol|dl|menu|dir',
+ ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q',
+ T : 'h1|h2|h3|h4|h5|h6',
+ ZB : 'X|S|Q',
+ S : 'R|P',
+ ZA : 'a|G|J|M|O|P',
+ R : 'a|H|K|N|O',
+ Q : 'noscript|P',
+ P : 'ins|del|script',
+ O : 'input|select|textarea|label|button',
+ N : 'M|L',
+ M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym',
+ L : 'sub|sup',
+ K : 'J|I',
+ J : 'tt|i|b|u|s|strike',
+ I : 'big|small|font|basefont',
+ H : 'G|F',
+ G : 'br|span|bdo',
+ F : 'object|applet|img|map|iframe',
+ E : 'A|B|C',
+ D : 'accesskey|tabindex|onfocus|onblur',
+ C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup',
+ B : 'lang|xml:lang|dir',
+ A : 'id|class|style|title'
+ }, 'script[id|charset|type|language|src|defer|xml:space][]' +
+ 'style[B|id|type|media|title|xml:space][]' +
+ 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' +
+ 'param[id|name|value|valuetype|type][]' +
+ 'p[E|align][#|S]' +
+ 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' +
+ 'br[A|clear][]' +
+ 'span[E][#|S]' +
+ 'bdo[A|C|B][#|S]' +
+ 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' +
+ 'h1[E|align][#|S]' +
+ 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' +
+ 'map[B|C|A|name][X|form|Q|area]' +
+ 'h2[E|align][#|S]' +
+ 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' +
+ 'h3[E|align][#|S]' +
+ 'tt[E][#|S]' +
+ 'i[E][#|S]' +
+ 'b[E][#|S]' +
+ 'u[E][#|S]' +
+ 's[E][#|S]' +
+ 'strike[E][#|S]' +
+ 'big[E][#|S]' +
+ 'small[E][#|S]' +
+ 'font[A|B|size|color|face][#|S]' +
+ 'basefont[id|size|color|face][]' +
+ 'em[E][#|S]' +
+ 'strong[E][#|S]' +
+ 'dfn[E][#|S]' +
+ 'code[E][#|S]' +
+ 'q[E|cite][#|S]' +
+ 'samp[E][#|S]' +
+ 'kbd[E][#|S]' +
+ 'var[E][#|S]' +
+ 'cite[E][#|S]' +
+ 'abbr[E][#|S]' +
+ 'acronym[E][#|S]' +
+ 'sub[E][#|S]' +
+ 'sup[E][#|S]' +
+ 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' +
+ 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' +
+ 'optgroup[E|disabled|label][option]' +
+ 'option[E|selected|disabled|label|value][]' +
+ 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' +
+ 'label[E|for|accesskey|onfocus|onblur][#|S]' +
+ 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' +
+ 'h4[E|align][#|S]' +
+ 'ins[E|cite|datetime][#|Y]' +
+ 'h5[E|align][#|S]' +
+ 'del[E|cite|datetime][#|Y]' +
+ 'h6[E|align][#|S]' +
+ 'div[E|align][#|Y]' +
+ 'ul[E|type|compact][li]' +
+ 'li[E|type|value][#|Y]' +
+ 'ol[E|type|compact|start][li]' +
+ 'dl[E|compact][dt|dd]' +
+ 'dt[E][#|S]' +
+ 'dd[E][#|Y]' +
+ 'menu[E|compact][li]' +
+ 'dir[E|compact][li]' +
+ 'pre[E|width|xml:space][#|ZA]' +
+ 'hr[E|align|noshade|size|width][]' +
+ 'blockquote[E|cite][#|Y]' +
+ 'address[E][#|S|p]' +
+ 'center[E][#|Y]' +
+ 'noframes[E][#|Y]' +
+ 'isindex[A|B|prompt][]' +
+ 'fieldset[E][#|legend|Y]' +
+ 'legend[E|accesskey|align][#|S]' +
+ 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' +
+ 'caption[E|align][#|S]' +
+ 'col[ZG][]' +
+ 'colgroup[ZG][col]' +
+ 'thead[ZF][tr]' +
+ 'tr[ZF|bgcolor][th|td]' +
+ 'th[E|ZE][#|Y]' +
+ 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' +
+ 'noscript[E][#|Y]' +
+ 'td[E|ZE][#|Y]' +
+ 'tfoot[ZF][tr]' +
+ 'tbody[ZF][tr]' +
+ 'area[E|D|shape|coords|href|nohref|alt|target][]' +
+ 'base[id|href|target][]' +
+ 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]'
+ );
- case "src":
- case "href":
- if (s.keep_values) {
- if (s.url_converter)
- v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
+ boolAttrMap = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected,autoplay,loop,controls');
+ shortEndedElementsMap = makeMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,source');
+ nonEmptyElementsMap = tinymce.extend(makeMap('td,th,iframe,video,audio,object'), shortEndedElementsMap);
+ defaultWhiteSpaceElementsMap = makeMap('pre,script,style,textarea');
+ selfClosingElementsMap = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr');
- t.setAttrib(e, '_mce_' + n, v, 2);
- }
+ tinymce.html.Schema = function(settings) {
+ var self = this, elements = {}, children = {}, patternElements = [], validStyles, whiteSpaceElementsMap;
- break;
-
- case "shape":
- e.setAttribute('_mce_style', v);
- break;
- }
+ settings = settings || {};
- if (is(v) && v !== null && v.length !== 0)
- e.setAttribute(n, '' + v, 2);
- else
- e.removeAttribute(n, 2);
- });
- },
+ // Allow all elements and attributes if verify_html is set to false
+ if (settings.verify_html === false)
+ settings.valid_elements = '*[*]';
- setAttribs : function(e, o) {
- var t = this;
+ // Build styles list
+ if (settings.valid_styles) {
+ validStyles = {};
- return this.run(e, function(e) {
- each(o, function(v, n) {
- t.setAttrib(e, n, v);
- });
+ // Convert styles into a rule list
+ each(settings.valid_styles, function(value, key) {
+ validStyles[key] = tinymce.explode(value);
});
- },
+ }
- getAttrib : function(e, n, dv) {
- var v, t = this;
+ whiteSpaceElementsMap = settings.whitespace_elements ? makeMap(settings.whitespace_elements) : defaultWhiteSpaceElementsMap;
- e = t.get(e);
+ // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
+ function patternToRegExp(str) {
+ return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
+ };
- if (!e || e.nodeType !== 1)
- return false;
+ // Parses the specified valid_elements string and adds to the current rules
+ // This function is a bit hard to read since it's heavily optimized for speed
+ function addValidElements(valid_elements) {
+ var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
+ prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value,
+ elementRuleRegExp = /^([#+-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/,
+ attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
+ hasPatternsRegExp = /[*?+]/;
+
+ if (valid_elements) {
+ // Split valid elements into an array with rules
+ valid_elements = split(valid_elements);
+
+ if (elements['@']) {
+ globalAttributes = elements['@'].attributes;
+ globalAttributesOrder = elements['@'].attributesOrder;
+ }
- if (!is(dv))
- dv = '';
+ // Loop all rules
+ for (ei = 0, el = valid_elements.length; ei < el; ei++) {
+ // Parse element rule
+ matches = elementRuleRegExp.exec(valid_elements[ei]);
+ if (matches) {
+ // Setup local names for matches
+ prefix = matches[1];
+ elementName = matches[2];
+ outputName = matches[3];
+ attrData = matches[4];
+
+ // Create new attributes and attributesOrder
+ attributes = {};
+ attributesOrder = [];
+
+ // Create the new element
+ element = {
+ attributes : attributes,
+ attributesOrder : attributesOrder
+ };
- // Try the mce variant for these
- if (/^(src|href|style|coords|shape)$/.test(n)) {
- v = e.getAttribute("_mce_" + n);
+ // Padd empty elements prefix
+ if (prefix === '#')
+ element.paddEmpty = true;
- if (v)
- return v;
- }
+ // Remove empty elements prefix
+ if (prefix === '-')
+ element.removeEmpty = true;
- if (isIE && t.props[n]) {
- v = e[t.props[n]];
- v = v && v.nodeValue ? v.nodeValue : v;
- }
+ // Copy attributes from global rule into current rule
+ if (globalAttributes) {
+ for (key in globalAttributes)
+ attributes[key] = globalAttributes[key];
- if (!v)
- v = e.getAttribute(n, 2);
+ attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
+ }
- // Check boolean attribs
- if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) {
- if (e[t.props[n]] === true && v === '')
- return n;
+ // Attributes defined
+ if (attrData) {
+ attrData = split(attrData, '|');
+ for (ai = 0, al = attrData.length; ai < al; ai++) {
+ matches = attrRuleRegExp.exec(attrData[ai]);
+ if (matches) {
+ attr = {};
+ attrType = matches[1];
+ attrName = matches[2].replace(/::/g, ':');
+ prefix = matches[3];
+ value = matches[4];
+
+ // Required
+ if (attrType === '!') {
+ element.attributesRequired = element.attributesRequired || [];
+ element.attributesRequired.push(attrName);
+ attr.required = true;
+ }
- return v ? n : '';
- }
+ // Denied from global
+ if (attrType === '-') {
+ delete attributes[attrName];
+ attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1);
+ continue;
+ }
- // Inner input elements will override attributes on form elements
- if (e.nodeName === "FORM" && e.getAttributeNode(n))
- return e.getAttributeNode(n).nodeValue;
+ // Default value
+ if (prefix) {
+ // Default value
+ if (prefix === '=') {
+ element.attributesDefault = element.attributesDefault || [];
+ element.attributesDefault.push({name: attrName, value: value});
+ attr.defaultValue = value;
+ }
- if (n === 'style') {
- v = v || e.style.cssText;
+ // Forced value
+ if (prefix === ':') {
+ element.attributesForced = element.attributesForced || [];
+ element.attributesForced.push({name: attrName, value: value});
+ attr.forcedValue = value;
+ }
- if (v) {
- v = t.serializeStyle(t.parseStyle(v), e.nodeName);
+ // Required values
+ if (prefix === '<')
+ attr.validValues = makeMap(value, '?');
+ }
- if (t.settings.keep_values && !t._isRes(v))
- e.setAttribute('_mce_style', v);
+ // Check for attribute patterns
+ if (hasPatternsRegExp.test(attrName)) {
+ element.attributePatterns = element.attributePatterns || [];
+ attr.pattern = patternToRegExp(attrName);
+ element.attributePatterns.push(attr);
+ } else {
+ // Add attribute to order list if it doesn't already exist
+ if (!attributes[attrName])
+ attributesOrder.push(attrName);
+
+ attributes[attrName] = attr;
+ }
+ }
+ }
+ }
+
+ // Global rule, store away these for later usage
+ if (!globalAttributes && elementName == '@') {
+ globalAttributes = attributes;
+ globalAttributesOrder = attributesOrder;
+ }
+
+ // Handle substitute elements such as b/strong
+ if (outputName) {
+ element.outputName = elementName;
+ elements[outputName] = element;
+ }
+
+ // Add pattern or exact element
+ if (hasPatternsRegExp.test(elementName)) {
+ element.pattern = patternToRegExp(elementName);
+ patternElements.push(element);
+ } else
+ elements[elementName] = element;
+ }
}
}
+ };
- // Remove Apple and WebKit stuff
- if (isWebKit && n === "class" && v)
- v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
+ function setValidElements(valid_elements) {
+ elements = {};
+ patternElements = [];
- // Handle IE issues
- if (isIE) {
- switch (n) {
- case 'rowspan':
- case 'colspan':
- // IE returns 1 as default value
- if (v === 1)
- v = '';
+ addValidElements(valid_elements);
- break;
+ each(transitional, function(element, name) {
+ children[name] = element.children;
+ });
+ };
- case 'size':
- // IE returns +0 as default value for size
- if (v === '+0' || v === 20 || v === 0)
- v = '';
+ // Adds custom non HTML elements to the schema
+ function addCustomElements(custom_elements) {
+ var customElementRegExp = /^(~)?(.+)$/;
- break;
+ if (custom_elements) {
+ each(split(custom_elements), function(rule) {
+ var matches = customElementRegExp.exec(rule),
+ inline = matches[1] === '~',
+ cloneName = inline ? 'span' : 'div',
+ name = matches[2];
- case 'width':
- case 'height':
- case 'vspace':
- case 'checked':
- case 'disabled':
- case 'readonly':
- if (v === 0)
- v = '';
+ children[name] = children[cloneName];
+ customElementsMap[name] = cloneName;
- break;
+ // If it's not marked as inline then add it to valid block elements
+ if (!inline)
+ blockElementsMap[name] = {};
- case 'hspace':
- // IE returns -1 as default value
- if (v === -1)
- v = '';
+ // Add custom elements at span/div positions
+ each(children, function(element, child) {
+ if (element[cloneName])
+ element[name] = element[cloneName];
+ });
+ });
+ }
+ };
- break;
+ // Adds valid children to the schema object
+ function addValidChildren(valid_children) {
+ var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
- case 'maxlength':
- case 'tabindex':
- // IE returns default value
- if (v === 32768 || v === 2147483647 || v === '32768')
- v = '';
+ if (valid_children) {
+ each(split(valid_children), function(rule) {
+ var matches = childRuleRegExp.exec(rule), parent, prefix;
- break;
+ if (matches) {
+ prefix = matches[1];
- case 'multiple':
- case 'compact':
- case 'noshade':
- case 'nowrap':
- if (v === 65535)
- return n;
+ // Add/remove items from default
+ if (prefix)
+ parent = children[matches[2]];
+ else
+ parent = children[matches[2]] = {'#comment' : {}};
- return dv;
+ parent = children[matches[2]];
- case 'shape':
- v = v.toLowerCase();
- break;
+ each(split(matches[3], '|'), function(child) {
+ if (prefix === '-')
+ delete parent[child];
+ else
+ parent[child] = {};
+ });
+ }
+ });
+ }
+ };
- default:
- // IE has odd anonymous function for event attributes
- if (n.indexOf('on') === 0 && v)
- v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v);
- }
+ function getElementRule(name) {
+ var element = elements[name], i;
+
+ // Exact match found
+ if (element)
+ return element;
+
+ // No exact match then try the patterns
+ i = patternElements.length;
+ while (i--) {
+ element = patternElements[i];
+
+ if (element.pattern.test(name))
+ return element;
}
+ };
- return (v !== undefined && v !== null && v !== '') ? '' + v : dv;
- },
+ if (!settings.valid_elements) {
+ // No valid elements defined then clone the elements from the transitional spec
+ each(transitional, function(element, name) {
+ elements[name] = {
+ attributes : element.attributes,
+ attributesOrder : element.attributesOrder
+ };
- getPos : function(n, ro) {
- var t = this, x = 0, y = 0, e, d = t.doc, r;
+ children[name] = element.children;
+ });
- n = t.get(n);
- ro = ro || d.body;
+ // Switch these
+ each(split('strong/b,em/i'), function(item) {
+ item = split(item, '/');
+ elements[item[1]].outputName = item[0];
+ });
- if (n) {
- // Use getBoundingClientRect on IE, Opera has it but it's not perfect
- if (isIE && !t.stdMode) {
- n = n.getBoundingClientRect();
- e = t.boxModel ? d.documentElement : d.body;
- x = t.getStyle(t.select('html')[0], 'borderWidth'); // Remove border
- x = (x == 'medium' || t.boxModel && !t.isIE6) && 2 || x;
+ // Add default alt attribute for images
+ elements.img.attributesDefault = [{name: 'alt', value: ''}];
- return {x : n.left + e.scrollLeft - x, y : n.top + e.scrollTop - x};
- }
+ // Remove these if they are empty by default
+ each(split('ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr'), function(name) {
+ elements[name].removeEmpty = true;
+ });
- r = n;
- while (r && r != ro && r.nodeType) {
- x += r.offsetLeft || 0;
- y += r.offsetTop || 0;
- r = r.offsetParent;
- }
+ // Padd these by default
+ each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) {
+ elements[name].paddEmpty = true;
+ });
+ } else
+ setValidElements(settings.valid_elements);
- r = n.parentNode;
- while (r && r != ro && r.nodeType) {
- x -= r.scrollLeft || 0;
- y -= r.scrollTop || 0;
- r = r.parentNode;
- }
- }
+ addCustomElements(settings.custom_elements);
+ addValidChildren(settings.valid_children);
+ addValidElements(settings.extended_valid_elements);
- return {x : x, y : y};
- },
+ // Todo: Remove this when we fix list handling to be valid
+ addValidChildren('+ol[ul|ol],+ul[ul|ol]');
- parseStyle : function(st) {
- var t = this, s = t.settings, o = {};
+ // If the user didn't allow span only allow internal spans
+ if (!getElementRule('span'))
+ addValidElements('span[!data-mce-type|*]');
- if (!st)
- return o;
+ // Delete invalid elements
+ if (settings.invalid_elements) {
+ tinymce.each(tinymce.explode(settings.invalid_elements), function(item) {
+ if (elements[item])
+ delete elements[item];
+ });
+ }
- function compress(p, s, ot) {
- var t, r, b, l;
+ self.children = children;
- // Get values and check it it needs compressing
- t = o[p + '-top' + s];
- if (!t)
- return;
+ self.styles = validStyles;
- r = o[p + '-right' + s];
- if (t != r)
- return;
+ self.getBoolAttrs = function() {
+ return boolAttrMap;
+ };
- b = o[p + '-bottom' + s];
- if (r != b)
- return;
+ self.getBlockElements = function() {
+ return blockElementsMap;
+ };
- l = o[p + '-left' + s];
- if (b != l)
- return;
+ self.getShortEndedElements = function() {
+ return shortEndedElementsMap;
+ };
- // Compress
- o[ot] = l;
- delete o[p + '-top' + s];
- delete o[p + '-right' + s];
- delete o[p + '-bottom' + s];
- delete o[p + '-left' + s];
- };
+ self.getSelfClosingElements = function() {
+ return selfClosingElementsMap;
+ };
- function compress2(ta, a, b, c) {
- var t;
+ self.getNonEmptyElements = function() {
+ return nonEmptyElementsMap;
+ };
- t = o[a];
- if (!t)
- return;
+ self.getWhiteSpaceElements = function() {
+ return whiteSpaceElementsMap;
+ };
- t = o[b];
- if (!t)
- return;
+ self.isValidChild = function(name, child) {
+ var parent = children[name];
- t = o[c];
- if (!t)
- return;
+ return !!(parent && parent[child]);
+ };
- // Compress
- o[ta] = o[a] + ' ' + o[b] + ' ' + o[c];
- delete o[a];
- delete o[b];
- delete o[c];
- };
+ self.getElementRule = getElementRule;
- st = st.replace(/&(#?[a-z0-9]+);/g, '&$1_MCE_SEMI_'); // Protect entities
+ self.getCustomElements = function() {
+ return customElementsMap;
+ };
- each(st.split(';'), function(v) {
- var sv, ur = [];
+ self.addValidElements = addValidElements;
- if (v) {
- v = v.replace(/_MCE_SEMI_/g, ';'); // Restore entities
- v = v.replace(/url\([^\)]+\)/g, function(v) {ur.push(v);return 'url(' + ur.length + ')';});
- v = v.split(':');
- sv = tinymce.trim(v[1]);
- sv = sv.replace(/url\(([^\)]+)\)/g, function(a, b) {return ur[parseInt(b) - 1];});
-
- sv = sv.replace(/rgb\([^\)]+\)/g, function(v) {
- return t.toHex(v);
- });
+ self.setValidElements = setValidElements;
- if (s.url_converter) {
- sv = sv.replace(/url\([\'\"]?([^\)\'\"]+)[\'\"]?\)/g, function(x, c) {
- return 'url(' + s.url_converter.call(s.url_converter_scope || t, t.decode(c), 'style', null) + ')';
- });
- }
+ self.addCustomElements = addCustomElements;
- o[tinymce.trim(v[0]).toLowerCase()] = sv;
- }
- });
+ self.addValidChildren = addValidChildren;
+ };
- compress("border", "", "border");
- compress("border", "-width", "border-width");
- compress("border", "-color", "border-color");
- compress("border", "-style", "border-style");
- compress("padding", "", "padding");
- compress("margin", "", "margin");
- compress2('border', 'border-width', 'border-style', 'border-color');
+ // Expose boolMap and blockElementMap as static properties for usage in DOMUtils
+ tinymce.html.Schema.boolAttrMap = boolAttrMap;
+ tinymce.html.Schema.blockElementsMap = blockElementsMap;
+})(tinymce);
- if (isIE) {
- // Remove pointless border
- if (o.border == 'medium none')
- o.border = '';
- }
+(function(tinymce) {
+ tinymce.html.SaxParser = function(settings, schema) {
+ var self = this, noop = function() {};
- return o;
- },
+ settings = settings || {};
+ self.schema = schema = schema || new tinymce.html.Schema();
- serializeStyle : function(o, name) {
- var t = this, s = '';
+ if (settings.fix_self_closing !== false)
+ settings.fix_self_closing = true;
- function add(v, k) {
- if (k && v) {
- // Remove browser specific styles like -moz- or -webkit-
- if (k.indexOf('-') === 0)
- return;
+ // Add handler functions from settings and setup default handlers
+ tinymce.each('comment cdata text start end pi doctype'.split(' '), function(name) {
+ if (name)
+ self[name] = settings[name] || noop;
+ });
- switch (k) {
- case 'font-weight':
- // Opera will output bold as 700
- if (v == 700)
- v = 'bold';
+ self.parse = function(html) {
+ var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name, isInternalElement, removeInternalElements,
+ shortEndedElements, fillAttrsMap, isShortEnded, validate, elementRule, isValidElement, attr, attribsValue, invalidPrefixRegExp,
+ validAttributesMap, validAttributePatterns, attributesRequired, attributesDefault, attributesForced, selfClosing,
+ tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0, decode = tinymce.html.Entities.decode, fixSelfClosing, isIE;
- break;
+ function processEndTag(name) {
+ var pos, i;
- case 'color':
- case 'background-color':
- v = v.toLowerCase();
- break;
+ // Find position of parent of the same type
+ pos = stack.length;
+ while (pos--) {
+ if (stack[pos].name === name)
+ break;
+ }
+
+ // Found parent
+ if (pos >= 0) {
+ // Close all the open elements
+ for (i = stack.length - 1; i >= pos; i--) {
+ name = stack[i];
+
+ if (name.valid)
+ self.end(name.name);
}
- s += (s ? ' ' : '') + k + ': ' + v + ';';
+ // Remove the open elements from the stack
+ stack.length = pos;
}
};
- // Validate style output
- if (name && t._styles) {
- each(t._styles['*'], function(name) {
- add(o[name], name);
- });
+ // Precompile RegExps and map objects
+ tokenRegExp = new RegExp('<(?:' +
+ '(?:!--([\\w\\W]*?)-->)|' + // Comment
+ '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA
+ '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE
+ '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI
+ '(?:\\/([^>]+)>)|' + // End element
+ '(?:([^\\s\\/<>]+)\\s*((?:[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*)>)' + // Start element
+ ')', 'g');
+
+ attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:\\.|[^\"])*)\")|(?:\'((?:\\.|[^\'])*)\')|([^>\s]+)))?/g;
+ specialElements = {
+ 'script' : /<\/script[^>]*>/gi,
+ 'style' : /<\/style[^>]*>/gi,
+ 'noscript' : /<\/noscript[^>]*>/gi
+ };
- each(t._styles[name.toLowerCase()], function(name) {
- add(o[name], name);
- });
- } else
- each(o, add);
+ // Setup lookup tables for empty elements and boolean attributes
+ shortEndedElements = schema.getShortEndedElements();
+ selfClosing = schema.getSelfClosingElements();
+ fillAttrsMap = schema.getBoolAttrs();
+ validate = settings.validate;
+ removeInternalElements = settings.remove_internals;
+ fixSelfClosing = settings.fix_self_closing;
+ isIE = tinymce.isIE;
+ invalidPrefixRegExp = /^:/;
+
+ while (matches = tokenRegExp.exec(html)) {
+ // Text
+ if (index < matches.index)
+ self.text(decode(html.substr(index, matches.index - index)));
+
+ if (value = matches[6]) { // End element
+ value = value.toLowerCase();
+
+ // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
+ if (isIE && invalidPrefixRegExp.test(value))
+ value = value.substr(1);
+
+ processEndTag(value);
+ } else if (value = matches[7]) { // Start element
+ value = value.toLowerCase();
+
+ // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
+ if (isIE && invalidPrefixRegExp.test(value))
+ value = value.substr(1);
+
+ isShortEnded = value in shortEndedElements;
+
+ // Is self closing tag for example an after an open
+ if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value)
+ processEndTag(value);
+
+ // Validate element
+ if (!validate || (elementRule = schema.getElementRule(value))) {
+ isValidElement = true;
+
+ // Grab attributes map and patters when validation is enabled
+ if (validate) {
+ validAttributesMap = elementRule.attributes;
+ validAttributePatterns = elementRule.attributePatterns;
+ }
- return s;
- },
+ // Parse attributes
+ if (attribsValue = matches[8]) {
+ isInternalElement = attribsValue.indexOf('data-mce-type') !== -1; // Check if the element is an internal element
- loadCSS : function(u) {
- var t = this, d = t.doc, head;
+ // If the element has internal attributes then remove it if we are told to do so
+ if (isInternalElement && removeInternalElements)
+ isValidElement = false;
- if (!u)
- u = '';
+ attrList = [];
+ attrList.map = {};
- head = t.select('head')[0];
+ attribsValue.replace(attrRegExp, function(match, name, value, val2, val3) {
+ var attrRule, i;
- each(u.split(','), function(u) {
- var link;
+ name = name.toLowerCase();
+ value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute
- if (t.files[u])
- return;
+ // Validate name and value
+ if (validate && !isInternalElement && name.indexOf('data-') !== 0) {
+ attrRule = validAttributesMap[name];
- t.files[u] = true;
- link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)});
+ // Find rule by pattern matching
+ if (!attrRule && validAttributePatterns) {
+ i = validAttributePatterns.length;
+ while (i--) {
+ attrRule = validAttributePatterns[i];
+ if (attrRule.pattern.test(name))
+ break;
+ }
- // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
- // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading
- // It's ugly but it seems to work fine.
- if (isIE && d.documentMode && d.recalc) {
- link.onload = function() {
- d.recalc();
- link.onload = null;
- };
- }
+ // No rule matched
+ if (i === -1)
+ attrRule = null;
+ }
- head.appendChild(link);
- });
- },
+ // No attribute rule found
+ if (!attrRule)
+ return;
- addClass : function(e, c) {
- return this.run(e, function(e) {
- var o;
+ // Validate value
+ if (attrRule.validValues && !(value in attrRule.validValues))
+ return;
+ }
- if (!c)
- return 0;
+ // Add attribute to list and map
+ attrList.map[name] = value;
+ attrList.push({
+ name: name,
+ value: value
+ });
+ });
+ } else {
+ attrList = [];
+ attrList.map = {};
+ }
- if (this.hasClass(e, c))
- return e.className;
+ // Process attributes if validation is enabled
+ if (validate && !isInternalElement) {
+ attributesRequired = elementRule.attributesRequired;
+ attributesDefault = elementRule.attributesDefault;
+ attributesForced = elementRule.attributesForced;
+
+ // Handle forced attributes
+ if (attributesForced) {
+ i = attributesForced.length;
+ while (i--) {
+ attr = attributesForced[i];
+ name = attr.name;
+ attrValue = attr.value;
+
+ if (attrValue === '{$uid}')
+ attrValue = 'mce_' + idCount++;
+
+ attrList.map[name] = attrValue;
+ attrList.push({name: name, value: attrValue});
+ }
+ }
- o = this.removeClass(e, c);
+ // Handle default attributes
+ if (attributesDefault) {
+ i = attributesDefault.length;
+ while (i--) {
+ attr = attributesDefault[i];
+ name = attr.name;
- return e.className = (o != '' ? (o + ' ') : '') + c;
- });
- },
+ if (!(name in attrList.map)) {
+ attrValue = attr.value;
- removeClass : function(e, c) {
- var t = this, re;
+ if (attrValue === '{$uid}')
+ attrValue = 'mce_' + idCount++;
- return t.run(e, function(e) {
- var v;
+ attrList.map[name] = attrValue;
+ attrList.push({name: name, value: attrValue});
+ }
+ }
+ }
- if (t.hasClass(e, c)) {
- if (!re)
- re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g");
+ // Handle required attributes
+ if (attributesRequired) {
+ i = attributesRequired.length;
+ while (i--) {
+ if (attributesRequired[i] in attrList.map)
+ break;
+ }
- v = e.className.replace(re, ' ');
- v = tinymce.trim(v != ' ' ? v : '');
+ // None of the required attributes where found
+ if (i === -1)
+ isValidElement = false;
+ }
- e.className = v;
+ // Invalidate element if it's marked as bogus
+ if (attrList.map['data-mce-bogus'])
+ isValidElement = false;
+ }
- // Empty class attr
- if (!v) {
- e.removeAttribute('class');
- e.removeAttribute('className');
- }
+ if (isValidElement)
+ self.start(value, attrList, isShortEnded);
+ } else
+ isValidElement = false;
- return v;
- }
+ // Treat script, noscript and style a bit different since they may include code that looks like elements
+ if (endRegExp = specialElements[value]) {
+ endRegExp.lastIndex = index = matches.index + matches[0].length;
- return e.className;
- });
- },
+ if (matches = endRegExp.exec(html)) {
+ if (isValidElement)
+ text = html.substr(index, matches.index - index);
- hasClass : function(n, c) {
- n = this.get(n);
-
- if (!n || !c)
- return false;
+ index = matches.index + matches[0].length;
+ } else {
+ text = html.substr(index);
+ index = html.length;
+ }
- return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1;
- },
+ if (isValidElement && text.length > 0)
+ self.text(text, true);
- show : function(e) {
- return this.setStyle(e, 'display', 'block');
- },
+ if (isValidElement)
+ self.end(value);
- hide : function(e) {
- return this.setStyle(e, 'display', 'none');
- },
+ tokenRegExp.lastIndex = index;
+ continue;
+ }
- isHidden : function(e) {
- e = this.get(e);
+ // Push value on to stack
+ if (!isShortEnded) {
+ if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1)
+ stack.push({name: value, valid: isValidElement});
+ else if (isValidElement)
+ self.end(value);
+ }
+ } else if (value = matches[1]) { // Comment
+ self.comment(value);
+ } else if (value = matches[2]) { // CDATA
+ self.cdata(value);
+ } else if (value = matches[3]) { // DOCTYPE
+ self.doctype(value);
+ } else if (value = matches[4]) { // PI
+ self.pi(value, matches[5]);
+ }
- return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none';
- },
+ index = matches.index + matches[0].length;
+ }
- uniqueId : function(p) {
- return (!p ? 'mce_' : p) + (this.counter++);
- },
+ // Text
+ if (index < html.length)
+ self.text(decode(html.substr(index)));
- setHTML : function(e, h) {
- var t = this;
+ // Close any open elements
+ for (i = stack.length - 1; i >= 0; i--) {
+ value = stack[i];
- return this.run(e, function(e) {
- var x, i, nl, n, p, x;
+ if (value.valid)
+ self.end(value.name);
+ }
+ };
+ }
+})(tinymce);
- h = t.processHTML(h);
+(function(tinymce) {
+ var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = {
+ '#text' : 3,
+ '#comment' : 8,
+ '#cdata' : 4,
+ '#pi' : 7,
+ '#doctype' : 10,
+ '#document-fragment' : 11
+ };
- if (isIE) {
- function set() {
- // Remove all child nodes
- while (e.firstChild)
- e.firstChild.removeNode();
+ // Walks the tree left/right
+ function walk(node, root_node, prev) {
+ var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next';
- try {
- // IE will remove comments from the beginning
- // unless you padd the contents with something
- e.innerHTML = '
' + h;
- e.removeChild(e.firstChild);
- } catch (ex) {
- // 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
- // This seems to fix this problem
-
- // Create new div with HTML contents and a BR infront to keep comments
- x = t.create('div');
- x.innerHTML = '
' + h;
-
- // Add all children from div to target
- each (x.childNodes, function(n, i) {
- // Skip br element
- if (i)
- e.appendChild(n);
- });
- }
- };
+ // Walk into nodes if it has a start
+ if (node[startName])
+ return node[startName];
- // IE has a serious bug when it comes to paragraphs it can produce an invalid
- // DOM tree if contents like this
is inserted
- // It seems to be that IE doesn't like a root block element placed inside another root block element
- if (t.settings.fix_ie_paragraphs)
- h = h.replace(/<\/p>|
]+)><\/p>|
/gi, '
');
+ // Return the sibling if it has one
+ if (node !== root_node) {
+ sibling = node[siblingName];
- set();
+ if (sibling)
+ return sibling;
- if (t.settings.fix_ie_paragraphs) {
- // Check for odd paragraphs this is a sign of a broken DOM
- nl = e.getElementsByTagName("p");
- for (i = nl.length - 1, x = 0; i >= 0; i--) {
- n = nl[i];
+ // Walk up the parents to look for siblings
+ for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) {
+ sibling = parent[siblingName];
- if (!n.hasChildNodes()) {
- if (!n._mce_keep) {
- x = 1; // Is broken
- break;
- }
+ if (sibling)
+ return sibling;
+ }
+ }
+ };
- n.removeAttribute('_mce_keep');
- }
- }
- }
+ function Node(name, type) {
+ this.name = name;
+ this.type = type;
- // Time to fix the madness IE left us
- if (x) {
- // So if we replace the p elements with divs and mark them and then replace them back to paragraphs
- // after we use innerHTML we can fix the DOM tree
- h = h.replace(/]+)>|
/ig, '
');
- h = h.replace(/<\/p>/gi, '
');
+ if (type === 1) {
+ this.attributes = [];
+ this.attributes.map = {};
+ }
+ }
- // Set the new HTML with DIVs
- set();
+ tinymce.extend(Node.prototype, {
+ replace : function(node) {
+ var self = this;
- // Replace all DIV elements with the _mce_tmp attibute back to paragraphs
- // This is needed since IE has a annoying bug see above for details
- // This is a slow process but it has to be done. :(
- if (t.settings.fix_ie_paragraphs) {
- nl = e.getElementsByTagName("DIV");
- for (i = nl.length - 1; i >= 0; i--) {
- n = nl[i];
+ if (node.parent)
+ node.remove();
- // Is it a temp div
- if (n._mce_tmp) {
- // Create new paragraph
- p = t.doc.createElement('p');
+ self.insert(node, self);
+ self.remove();
- // Copy all attributes
- n.cloneNode(false).outerHTML.replace(/([a-z0-9\-_]+)=/gi, function(a, b) {
- var v;
+ return self;
+ },
- if (b !== '_mce_tmp') {
- v = n.getAttribute(b);
+ attr : function(name, value) {
+ var self = this, attrs, i, undef;
- if (!v && b === 'class')
- v = n.className;
+ if (typeof name !== "string") {
+ for (i in name)
+ self.attr(i, name[i]);
- p.setAttribute(b, v);
- }
- });
+ return self;
+ }
- // Append all children to new paragraph
- for (x = 0; x]+)\/>|/gi, '', h); // Force open
-
- // Store away src and href in _mce_src and mce_href since browsers mess them up
- if (s.keep_values) {
- // Wrap scripts and styles in comments for serialization purposes
- if (/';
+ t.iframeHTML += '';
bi = s.body_id || 'tinymce';
if (bi.indexOf('=') != -1) {
@@ -9556,33 +11442,35 @@ tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', {
bc = bc[t.id] || '';
}
- t.iframeHTML += '