bgneal@312: (function(win) { bgneal@312: var whiteSpaceRe = /^\s*|\s*$/g, bgneal@442: undefined, isRegExpBroken = 'B'.replace(/A(.)|B/, '$1') === '$1'; bgneal@312: bgneal@312: var tinymce = { bgneal@312: majorVersion : '3', bgneal@312: bgneal@442: minorVersion : '4.2', bgneal@442: bgneal@442: releaseDate : '2011-04-07', bgneal@312: bgneal@312: _init : function() { bgneal@312: var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v; bgneal@312: bgneal@312: t.isOpera = win.opera && opera.buildNumber; bgneal@312: bgneal@312: t.isWebKit = /WebKit/.test(ua); bgneal@312: bgneal@312: t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName); bgneal@312: bgneal@312: t.isIE6 = t.isIE && /MSIE [56]/.test(ua); bgneal@312: bgneal@312: t.isGecko = !t.isWebKit && /Gecko/.test(ua); bgneal@312: bgneal@312: t.isMac = ua.indexOf('Mac') != -1; bgneal@312: bgneal@312: t.isAir = /adobeair/i.test(ua); bgneal@312: bgneal@312: t.isIDevice = /(iPad|iPhone)/.test(ua); bgneal@312: bgneal@312: // TinyMCE .NET webcontrol might be setting the values for TinyMCE bgneal@312: if (win.tinyMCEPreInit) { bgneal@312: t.suffix = tinyMCEPreInit.suffix; bgneal@312: t.baseURL = tinyMCEPreInit.base; bgneal@312: t.query = tinyMCEPreInit.query; bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Get suffix and base bgneal@312: t.suffix = ''; bgneal@312: bgneal@312: // If base element found, add that infront of baseURL bgneal@312: nl = d.getElementsByTagName('base'); bgneal@312: for (i=0; i : bgneal@312: s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s); bgneal@312: cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name bgneal@312: bgneal@312: // Create namespace for new class bgneal@442: ns = t.createNS(s[3].replace(/\.\w+$/, ''), root); bgneal@312: bgneal@312: // Class already exists bgneal@312: if (ns[cn]) bgneal@312: return; bgneal@312: bgneal@312: // Make pure static class bgneal@312: if (s[2] == 'static') { bgneal@312: ns[cn] = p; bgneal@312: bgneal@312: if (this.onCreate) bgneal@312: this.onCreate(s[2], s[3], ns[cn]); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Create default constructor bgneal@312: if (!p[cn]) { bgneal@312: p[cn] = function() {}; bgneal@312: de = 1; bgneal@312: } bgneal@312: bgneal@312: // Add constructor and methods bgneal@312: ns[cn] = p[cn]; bgneal@312: t.extend(ns[cn].prototype, p); bgneal@312: bgneal@312: // Extend bgneal@312: if (s[5]) { bgneal@312: sp = t.resolve(s[5]).prototype; bgneal@312: scn = s[5].match(/\.(\w+)$/i)[1]; // Class name bgneal@312: bgneal@312: // Extend constructor bgneal@312: c = ns[cn]; bgneal@312: if (de) { bgneal@312: // Add passthrough constructor bgneal@312: ns[cn] = function() { bgneal@312: return sp[scn].apply(this, arguments); bgneal@312: }; bgneal@312: } else { bgneal@312: // Add inherit constructor bgneal@312: ns[cn] = function() { bgneal@312: this.parent = sp[scn]; bgneal@312: return c.apply(this, arguments); bgneal@312: }; bgneal@312: } bgneal@312: ns[cn].prototype[cn] = ns[cn]; bgneal@312: bgneal@312: // Add super methods bgneal@312: t.each(sp, function(f, n) { bgneal@312: ns[cn].prototype[n] = sp[n]; bgneal@312: }); bgneal@312: bgneal@312: // Add overridden methods bgneal@312: t.each(p, function(f, n) { bgneal@312: // Extend methods if needed bgneal@312: if (sp[n]) { bgneal@312: ns[cn].prototype[n] = function() { bgneal@312: this.parent = sp[n]; bgneal@312: return f.apply(this, arguments); bgneal@312: }; bgneal@312: } else { bgneal@312: if (n != cn) bgneal@312: ns[cn].prototype[n] = f; bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: // Add static methods bgneal@312: t.each(p['static'], function(f, n) { bgneal@312: ns[cn][n] = f; bgneal@312: }); bgneal@312: bgneal@312: if (this.onCreate) bgneal@312: this.onCreate(s[2], s[3], ns[cn].prototype); bgneal@312: }, bgneal@312: bgneal@312: walk : function(o, f, n, s) { bgneal@312: s = s || this; bgneal@312: bgneal@312: if (o) { bgneal@312: if (n) bgneal@312: o = o[n]; bgneal@312: bgneal@312: tinymce.each(o, function(o, i) { bgneal@312: if (f.call(s, o, i, n) === false) bgneal@312: return false; bgneal@312: bgneal@312: tinymce.walk(o, f, n, s); bgneal@312: }); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: createNS : function(n, o) { bgneal@312: var i, v; bgneal@312: bgneal@312: o = o || win; bgneal@312: bgneal@312: n = n.split('.'); bgneal@312: for (i=0; i= items.length) { bgneal@312: for (i = 0, l = base.length; i < l; i++) { bgneal@312: if (i >= items.length || base[i] != items[i]) { bgneal@312: bp = i + 1; bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if (base.length < items.length) { bgneal@312: for (i = 0, l = items.length; i < l; i++) { bgneal@312: if (i >= base.length || base[i] != items[i]) { bgneal@312: bp = i + 1; bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if (bp == 1) bgneal@312: return path; bgneal@312: bgneal@312: for (i = 0, l = base.length - (bp - 1); i < l; i++) bgneal@312: out += "../"; bgneal@312: bgneal@312: for (i = bp - 1, l = items.length; i < l; i++) { bgneal@312: if (i != bp - 1) bgneal@312: out += "/" + items[i]; bgneal@312: else bgneal@312: out += items[i]; bgneal@312: } bgneal@312: bgneal@312: return out; bgneal@312: }, bgneal@312: bgneal@312: toAbsPath : function(base, path) { bgneal@312: var i, nb = 0, o = [], tr, outPath; bgneal@312: bgneal@312: // Split paths bgneal@312: tr = /\/$/.test(path) ? '/' : ''; bgneal@312: base = base.split('/'); bgneal@312: path = path.split('/'); bgneal@312: bgneal@312: // Remove empty chunks bgneal@312: each(base, function(k) { bgneal@312: if (k) bgneal@312: o.push(k); bgneal@312: }); bgneal@312: bgneal@312: base = o; bgneal@312: bgneal@312: // Merge relURLParts chunks bgneal@312: for (i = path.length - 1, o = []; i >= 0; i--) { bgneal@312: // Ignore empty or . bgneal@312: if (path[i].length == 0 || path[i] == ".") bgneal@312: continue; bgneal@312: bgneal@312: // Is parent bgneal@312: if (path[i] == '..') { bgneal@312: nb++; bgneal@312: continue; bgneal@312: } bgneal@312: bgneal@312: // Move up bgneal@312: if (nb > 0) { bgneal@312: nb--; bgneal@312: continue; bgneal@312: } bgneal@312: bgneal@312: o.push(path[i]); bgneal@312: } bgneal@312: bgneal@312: i = base.length - nb; bgneal@312: bgneal@312: // If /a/b/c or / bgneal@312: if (i <= 0) bgneal@312: outPath = o.reverse().join('/'); bgneal@312: else bgneal@312: outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/'); bgneal@312: bgneal@312: // Add front / if it's needed bgneal@312: if (outPath.indexOf('/') !== 0) bgneal@312: outPath = '/' + outPath; bgneal@312: bgneal@312: // Add traling / if it's needed bgneal@312: if (tr && outPath.lastIndexOf('/') !== outPath.length - 1) bgneal@312: outPath += tr; bgneal@312: bgneal@312: return outPath; bgneal@312: }, bgneal@312: bgneal@312: getURI : function(nh) { bgneal@312: var s, t = this; bgneal@312: bgneal@312: // Rebuild source bgneal@312: if (!t.source || nh) { bgneal@312: s = ''; bgneal@312: bgneal@312: if (!nh) { bgneal@312: if (t.protocol) bgneal@312: s += t.protocol + '://'; bgneal@312: bgneal@312: if (t.userInfo) bgneal@312: s += t.userInfo + '@'; bgneal@312: bgneal@312: if (t.host) bgneal@312: s += t.host; bgneal@312: bgneal@312: if (t.port) bgneal@312: s += ':' + t.port; bgneal@312: } bgneal@312: bgneal@312: if (t.path) bgneal@312: s += t.path; bgneal@312: bgneal@312: if (t.query) bgneal@312: s += '?' + t.query; bgneal@312: bgneal@312: if (t.anchor) bgneal@312: s += '#' + t.anchor; bgneal@312: bgneal@312: t.source = s; bgneal@312: } bgneal@312: bgneal@312: return t.source; bgneal@312: } bgneal@312: }); bgneal@312: })(); bgneal@312: bgneal@312: (function() { bgneal@312: var each = tinymce.each; bgneal@312: bgneal@312: tinymce.create('static tinymce.util.Cookie', { bgneal@312: getHash : function(n) { bgneal@312: var v = this.get(n), h; bgneal@312: bgneal@312: if (v) { bgneal@312: each(v.split('&'), function(v) { bgneal@312: v = v.split('='); bgneal@312: h = h || {}; bgneal@312: h[unescape(v[0])] = unescape(v[1]); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: return h; bgneal@312: }, bgneal@312: bgneal@312: setHash : function(n, v, e, p, d, s) { bgneal@312: var o = ''; bgneal@312: bgneal@312: each(v, function(v, k) { bgneal@312: o += (!o ? '' : '&') + escape(k) + '=' + escape(v); bgneal@312: }); bgneal@312: bgneal@312: this.set(n, o, e, p, d, s); bgneal@312: }, bgneal@312: bgneal@312: get : function(n) { bgneal@312: var c = document.cookie, e, p = n + "=", b; bgneal@312: bgneal@312: // Strict mode bgneal@312: if (!c) bgneal@312: return; bgneal@312: bgneal@312: b = c.indexOf("; " + p); bgneal@312: bgneal@312: if (b == -1) { bgneal@312: b = c.indexOf(p); bgneal@312: bgneal@312: if (b != 0) bgneal@312: return null; bgneal@312: } else bgneal@312: b += 2; bgneal@312: bgneal@312: e = c.indexOf(";", b); bgneal@312: bgneal@312: if (e == -1) bgneal@312: e = c.length; bgneal@312: bgneal@312: return unescape(c.substring(b + p.length, e)); bgneal@312: }, bgneal@312: bgneal@312: set : function(n, v, e, p, d, s) { bgneal@312: document.cookie = n + "=" + escape(v) + bgneal@312: ((e) ? "; expires=" + e.toGMTString() : "") + bgneal@312: ((p) ? "; path=" + escape(p) : "") + bgneal@312: ((d) ? "; domain=" + d : "") + bgneal@312: ((s) ? "; secure" : ""); bgneal@312: }, bgneal@312: bgneal@312: remove : function(n, p) { bgneal@312: var d = new Date(); bgneal@312: bgneal@312: d.setTime(d.getTime() - 1000); bgneal@312: bgneal@312: this.set(n, '', d, p, d); bgneal@312: } bgneal@312: }); bgneal@312: })(); bgneal@312: bgneal@442: (function() { bgneal@442: function serialize(o, quote) { bgneal@442: var i, v, t; bgneal@442: bgneal@442: quote = quote || '"'; bgneal@312: bgneal@312: if (o == null) bgneal@312: return 'null'; bgneal@312: bgneal@312: t = typeof o; bgneal@312: bgneal@312: if (t == 'string') { bgneal@312: v = '\bb\tt\nn\ff\rr\""\'\'\\\\'; bgneal@312: bgneal@442: return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) { bgneal@442: // Make sure single quotes never get encoded inside double quotes for JSON compatibility bgneal@442: if (quote === '"' && a === "'") bgneal@442: return a; bgneal@442: bgneal@312: i = v.indexOf(b); bgneal@312: bgneal@312: if (i + 1) bgneal@312: return '\\' + v.charAt(i + 1); bgneal@312: bgneal@312: a = b.charCodeAt().toString(16); bgneal@312: bgneal@312: return '\\u' + '0000'.substring(a.length) + a; bgneal@442: }) + quote; bgneal@312: } bgneal@312: bgneal@312: if (t == 'object') { bgneal@312: if (o.hasOwnProperty && o instanceof Array) { bgneal@312: for (i=0, v = '['; i 0 ? ',' : '') + serialize(o[i], quote); bgneal@312: bgneal@312: return v + ']'; bgneal@312: } bgneal@312: bgneal@312: v = '{'; bgneal@312: bgneal@312: for (i in o) bgneal@442: v += typeof o[i] != 'function' ? (v.length > 1 ? ',' + quote : quote) + i + quote +':' + serialize(o[i], quote) : ''; bgneal@312: bgneal@312: return v + '}'; bgneal@312: } bgneal@312: bgneal@312: return '' + o; bgneal@442: }; bgneal@442: bgneal@442: tinymce.util.JSON = { bgneal@442: serialize: serialize, bgneal@442: bgneal@442: parse: function(s) { bgneal@442: try { bgneal@442: return eval('(' + s + ')'); bgneal@442: } catch (ex) { bgneal@442: // Ignore bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: }; bgneal@442: })(); bgneal@312: tinymce.create('static tinymce.util.XHR', { bgneal@312: send : function(o) { bgneal@312: var x, t, w = window, c = 0; bgneal@312: bgneal@312: // Default settings bgneal@312: o.scope = o.scope || this; bgneal@312: o.success_scope = o.success_scope || o.scope; bgneal@312: o.error_scope = o.error_scope || o.scope; bgneal@312: o.async = o.async === false ? false : true; bgneal@312: o.data = o.data || ''; bgneal@312: bgneal@312: function get(s) { bgneal@312: x = 0; bgneal@312: bgneal@312: try { bgneal@312: x = new ActiveXObject(s); bgneal@312: } catch (ex) { bgneal@312: } bgneal@312: bgneal@312: return x; bgneal@312: }; bgneal@312: bgneal@312: x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Microsoft.XMLHTTP') || get('Msxml2.XMLHTTP'); bgneal@312: bgneal@312: if (x) { bgneal@312: if (x.overrideMimeType) bgneal@312: x.overrideMimeType(o.content_type); bgneal@312: bgneal@312: x.open(o.type || (o.data ? 'POST' : 'GET'), o.url, o.async); bgneal@312: bgneal@312: if (o.content_type) bgneal@312: x.setRequestHeader('Content-Type', o.content_type); bgneal@312: bgneal@312: x.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); bgneal@312: bgneal@312: x.send(o.data); bgneal@312: bgneal@312: function ready() { bgneal@312: if (!o.async || x.readyState == 4 || c++ > 10000) { bgneal@312: if (o.success && c < 10000 && x.status == 200) bgneal@312: o.success.call(o.success_scope, '' + x.responseText, x, o); bgneal@312: else if (o.error) bgneal@312: o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o); bgneal@312: bgneal@312: x = null; bgneal@312: } else bgneal@312: w.setTimeout(ready, 10); bgneal@312: }; bgneal@312: bgneal@312: // Syncronous request bgneal@312: if (!o.async) bgneal@312: return ready(); bgneal@312: bgneal@312: // Wait for response, onReadyStateChange can not be used since it leaks memory in IE bgneal@312: t = w.setTimeout(ready, 10); bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: (function() { bgneal@312: var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR; bgneal@312: bgneal@312: tinymce.create('tinymce.util.JSONRequest', { bgneal@312: JSONRequest : function(s) { bgneal@312: this.settings = extend({ bgneal@312: }, s); bgneal@312: this.count = 0; bgneal@312: }, bgneal@312: bgneal@312: send : function(o) { bgneal@312: var ecb = o.error, scb = o.success; bgneal@312: bgneal@312: o = extend(this.settings, o); bgneal@312: bgneal@312: o.success = function(c, x) { bgneal@312: c = JSON.parse(c); bgneal@312: bgneal@312: if (typeof(c) == 'undefined') { bgneal@312: c = { bgneal@312: error : 'JSON Parse error.' bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: if (c.error) bgneal@312: ecb.call(o.error_scope || o.scope, c.error, x); bgneal@312: else bgneal@312: scb.call(o.success_scope || o.scope, c.result); bgneal@312: }; bgneal@312: bgneal@312: o.error = function(ty, x) { bgneal@442: if (ecb) bgneal@442: ecb.call(o.error_scope || o.scope, ty, x); bgneal@312: }; bgneal@312: bgneal@312: o.data = JSON.serialize({ bgneal@312: id : o.id || 'c' + (this.count++), bgneal@312: method : o.method, bgneal@312: params : o.params bgneal@312: }); bgneal@312: bgneal@312: // JSON content type for Ruby on rails. Bug: #1883287 bgneal@312: o.content_type = 'application/json'; bgneal@312: bgneal@312: XHR.send(o); bgneal@312: }, bgneal@312: bgneal@312: 'static' : { bgneal@312: sendRPC : function(o) { bgneal@312: return new tinymce.util.JSONRequest().send(o); bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: }()); bgneal@312: (function(tinymce) { bgneal@442: var namedEntities, baseEntities, reverseEntities, bgneal@442: attrsCharsRegExp = /[&\"\u007E-\uD7FF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, bgneal@442: textCharsRegExp = /[<>&\u007E-\uD7FF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, bgneal@442: rawCharsRegExp = /[<>&\"\']/g, bgneal@442: entityRegExp = /&(#)?([\w]+);/g, bgneal@442: asciiMap = { bgneal@442: 128 : "\u20AC", 130 : "\u201A", 131 : "\u0192", 132 : "\u201E", 133 : "\u2026", 134 : "\u2020", bgneal@442: 135 : "\u2021", 136 : "\u02C6", 137 : "\u2030", 138 : "\u0160", 139 : "\u2039", 140 : "\u0152", bgneal@442: 142 : "\u017D", 145 : "\u2018", 146 : "\u2019", 147 : "\u201C", 148 : "\u201D", 149 : "\u2022", bgneal@442: 150 : "\u2013", 151 : "\u2014", 152 : "\u02DC", 153 : "\u2122", 154 : "\u0161", 155 : "\u203A", bgneal@442: 156 : "\u0153", 158 : "\u017E", 159 : "\u0178" bgneal@442: }; bgneal@442: bgneal@442: // Raw entities bgneal@442: baseEntities = { bgneal@442: '"' : '"', bgneal@442: "'" : ''', bgneal@442: '<' : '<', bgneal@442: '>' : '>', bgneal@442: '&' : '&' bgneal@442: }; bgneal@442: bgneal@442: // Reverse lookup table for raw entities bgneal@442: reverseEntities = { bgneal@442: '<' : '<', bgneal@442: '>' : '>', bgneal@442: '&' : '&', bgneal@442: '"' : '"', bgneal@442: ''' : "'" bgneal@442: }; bgneal@442: bgneal@442: // Decodes text by using the browser bgneal@442: function nativeDecode(text) { bgneal@442: var elm; bgneal@442: bgneal@442: elm = document.createElement("div"); bgneal@442: elm.innerHTML = text; bgneal@442: bgneal@442: return elm.textContent || elm.innerText || text; bgneal@442: }; bgneal@442: bgneal@442: // Build a two way lookup table for the entities bgneal@442: function buildEntitiesLookup(items, radix) { bgneal@442: var i, chr, entity, lookup = {}; bgneal@442: bgneal@442: if (items) { bgneal@442: items = items.split(','); bgneal@442: radix = radix || 10; bgneal@442: bgneal@442: // Build entities lookup table bgneal@442: for (i = 0; i < items.length; i += 2) { bgneal@442: chr = String.fromCharCode(parseInt(items[i], radix)); bgneal@442: bgneal@442: // Only add non base entities bgneal@442: if (!baseEntities[chr]) { bgneal@442: entity = '&' + items[i + 1] + ';'; bgneal@442: lookup[chr] = entity; bgneal@442: lookup[entity] = chr; bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: return lookup; bgneal@442: } bgneal@442: }; bgneal@442: bgneal@442: // Unpack entities lookup where the numbers are in radix 32 to reduce the size bgneal@442: namedEntities = buildEntitiesLookup( bgneal@442: '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' + bgneal@442: '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' + bgneal@442: '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' + bgneal@442: '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' + bgneal@442: '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' + bgneal@442: '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' + bgneal@442: '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' + bgneal@442: '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' + bgneal@442: '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' + bgneal@442: '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' + bgneal@442: 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' + bgneal@442: 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' + bgneal@442: 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' + bgneal@442: 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' + bgneal@442: 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' + bgneal@442: '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' + bgneal@442: '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' + bgneal@442: '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' + bgneal@442: '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' + bgneal@442: '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' + bgneal@442: 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' + bgneal@442: 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' + bgneal@442: 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' + bgneal@442: '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' + bgneal@442: '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro' bgneal@442: , 32); bgneal@442: bgneal@442: tinymce.html = tinymce.html || {}; bgneal@442: bgneal@442: tinymce.html.Entities = { bgneal@442: encodeRaw : function(text, attr) { bgneal@442: return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) { bgneal@442: return baseEntities[chr] || chr; bgneal@442: }); bgneal@442: }, bgneal@442: bgneal@442: encodeAllRaw : function(text) { bgneal@442: return ('' + text).replace(rawCharsRegExp, function(chr) { bgneal@442: return baseEntities[chr] || chr; bgneal@442: }); bgneal@442: }, bgneal@442: bgneal@442: encodeNumeric : function(text, attr) { bgneal@442: return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) { bgneal@442: // Multi byte sequence convert it to a single entity bgneal@442: if (chr.length > 1) bgneal@442: return '&#' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';'; bgneal@442: bgneal@442: return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';'; bgneal@442: }); bgneal@442: }, bgneal@442: bgneal@442: encodeNamed : function(text, attr, entities) { bgneal@442: entities = entities || namedEntities; bgneal@442: bgneal@442: return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) { bgneal@442: return baseEntities[chr] || entities[chr] || chr; bgneal@442: }); bgneal@442: }, bgneal@442: bgneal@442: getEncodeFunc : function(name, entities) { bgneal@442: var Entities = tinymce.html.Entities; bgneal@442: bgneal@442: entities = buildEntitiesLookup(entities) || namedEntities; bgneal@442: bgneal@442: function encodeNamedAndNumeric(text, attr) { bgneal@442: return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) { bgneal@442: return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr; bgneal@442: }); bgneal@442: }; bgneal@442: bgneal@442: function encodeCustomNamed(text, attr) { bgneal@442: return Entities.encodeNamed(text, attr, entities); bgneal@442: }; bgneal@442: bgneal@442: // Replace + with , to be compatible with previous TinyMCE versions bgneal@442: name = tinymce.makeMap(name.replace(/\+/g, ',')); bgneal@442: bgneal@442: // Named and numeric encoder bgneal@442: if (name.named && name.numeric) bgneal@442: return encodeNamedAndNumeric; bgneal@442: bgneal@442: // Named encoder bgneal@442: if (name.named) { bgneal@442: // Custom names bgneal@442: if (entities) bgneal@442: return encodeCustomNamed; bgneal@442: bgneal@442: return Entities.encodeNamed; bgneal@442: } bgneal@442: bgneal@442: // Numeric bgneal@442: if (name.numeric) bgneal@442: return Entities.encodeNumeric; bgneal@442: bgneal@442: // Raw encoder bgneal@442: return Entities.encodeRaw; bgneal@442: }, bgneal@442: bgneal@442: decode : function(text) { bgneal@442: return text.replace(entityRegExp, function(all, numeric, value) { bgneal@442: if (numeric) { bgneal@442: value = parseInt(value); bgneal@442: bgneal@442: // Support upper UTF bgneal@442: if (value > 0xFFFF) { bgneal@442: value -= 0x10000; bgneal@442: bgneal@442: return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF)); bgneal@442: } else bgneal@442: return asciiMap[value] || String.fromCharCode(value); bgneal@442: } bgneal@442: bgneal@442: return reverseEntities[all] || namedEntities[all] || nativeDecode(all); bgneal@442: }); bgneal@442: } bgneal@442: }; bgneal@442: })(tinymce); bgneal@442: bgneal@442: tinymce.html.Styles = function(settings, schema) { bgneal@442: var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi, bgneal@442: urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi, bgneal@442: styleRegExp = /\s*([^:]+):\s*([^;]+);?/g, bgneal@442: trimRightRegExp = /\s+$/, bgneal@442: urlColorRegExp = /rgb/, bgneal@442: undef, i, encodingLookup = {}, encodingItems; bgneal@442: bgneal@442: settings = settings || {}; bgneal@442: bgneal@442: encodingItems = '\\" \\\' \\; \\: ; : _'.split(' '); bgneal@442: for (i = 0; i < encodingItems.length; i++) { bgneal@442: encodingLookup[encodingItems[i]] = '_' + i; bgneal@442: encodingLookup['_' + i] = encodingItems[i]; bgneal@442: } bgneal@442: bgneal@442: function toHex(match, r, g, b) { bgneal@442: function hex(val) { bgneal@442: val = parseInt(val).toString(16); bgneal@442: bgneal@442: return val.length > 1 ? val : '0' + val; // 0 -> 00 bgneal@442: }; bgneal@442: bgneal@442: return '#' + hex(r) + hex(g) + hex(b); bgneal@442: }; bgneal@442: bgneal@442: return { bgneal@442: toHex : function(color) { bgneal@442: return color.replace(rgbRegExp, toHex); bgneal@442: }, bgneal@442: bgneal@442: parse : function(css) { bgneal@442: var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this; bgneal@442: bgneal@442: function compress(prefix, suffix) { bgneal@442: var top, right, bottom, left; bgneal@442: bgneal@442: // Get values and check it it needs compressing bgneal@442: top = styles[prefix + '-top' + suffix]; bgneal@442: if (!top) bgneal@442: return; bgneal@442: bgneal@442: right = styles[prefix + '-right' + suffix]; bgneal@442: if (top != right) bgneal@442: return; bgneal@442: bgneal@442: bottom = styles[prefix + '-bottom' + suffix]; bgneal@442: if (right != bottom) bgneal@442: return; bgneal@442: bgneal@442: left = styles[prefix + '-left' + suffix]; bgneal@442: if (bottom != left) bgneal@442: return; bgneal@442: bgneal@442: // Compress bgneal@442: styles[prefix + suffix] = left; bgneal@442: delete styles[prefix + '-top' + suffix]; bgneal@442: delete styles[prefix + '-right' + suffix]; bgneal@442: delete styles[prefix + '-bottom' + suffix]; bgneal@442: delete styles[prefix + '-left' + suffix]; bgneal@442: }; bgneal@442: bgneal@442: function canCompress(key) { bgneal@442: var value = styles[key], i; bgneal@442: bgneal@442: if (!value || value.indexOf(' ') < 0) bgneal@442: return; bgneal@442: bgneal@442: value = value.split(' '); bgneal@442: i = value.length; bgneal@442: while (i--) { bgneal@442: if (value[i] !== value[0]) bgneal@442: return false; bgneal@442: } bgneal@442: bgneal@442: styles[key] = value[0]; bgneal@442: bgneal@442: return true; bgneal@442: }; bgneal@442: bgneal@442: function compress2(target, a, b, c) { bgneal@442: if (!canCompress(a)) bgneal@442: return; bgneal@442: bgneal@442: if (!canCompress(b)) bgneal@442: return; bgneal@442: bgneal@442: if (!canCompress(c)) bgneal@442: return; bgneal@442: bgneal@442: // Compress bgneal@442: styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c]; bgneal@442: delete styles[a]; bgneal@442: delete styles[b]; bgneal@442: delete styles[c]; bgneal@442: }; bgneal@442: bgneal@442: // Encodes the specified string by replacing all \" \' ; : with _ bgneal@442: function encode(str) { bgneal@442: isEncoded = true; bgneal@442: bgneal@442: return encodingLookup[str]; bgneal@442: }; bgneal@442: bgneal@442: // Decodes the specified string by replacing all _ with it's original value \" \' etc bgneal@442: // It will also decode the \" \' if keep_slashes is set to fale or omitted bgneal@442: function decode(str, keep_slashes) { bgneal@442: if (isEncoded) { bgneal@442: str = str.replace(/_[0-9]/g, function(str) { bgneal@442: return encodingLookup[str]; bgneal@442: }); bgneal@442: } bgneal@442: bgneal@442: if (!keep_slashes) bgneal@442: str = str.replace(/\\([\'\";:])/g, "$1"); bgneal@442: bgneal@442: return str; bgneal@442: } bgneal@442: bgneal@442: if (css) { bgneal@442: // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing bgneal@442: css = css.replace(/\\[\"\';:_]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) { bgneal@442: return str.replace(/[;:]/g, encode); bgneal@442: }); bgneal@442: bgneal@442: // Parse styles bgneal@442: while (matches = styleRegExp.exec(css)) { bgneal@442: name = matches[1].replace(trimRightRegExp, '').toLowerCase(); bgneal@442: value = matches[2].replace(trimRightRegExp, ''); bgneal@442: bgneal@442: if (name && value.length > 0) { bgneal@442: // Opera will produce 700 instead of bold in their style values bgneal@442: if (name === 'font-weight' && value === '700') bgneal@442: value = 'bold'; bgneal@442: else if (name === 'color' || name === 'background-color') // Lowercase colors like RED bgneal@442: value = value.toLowerCase(); bgneal@442: bgneal@442: // Convert RGB colors to HEX bgneal@442: value = value.replace(rgbRegExp, toHex); bgneal@442: bgneal@442: // Convert URLs and force them into url('value') format bgneal@442: value = value.replace(urlOrStrRegExp, function(match, url, url2, url3, str, str2) { bgneal@442: str = str || str2; bgneal@442: bgneal@442: if (str) { bgneal@442: str = decode(str); bgneal@442: bgneal@442: // Force strings into single quote format bgneal@442: return "'" + str.replace(/\'/g, "\\'") + "'"; bgneal@442: } bgneal@442: bgneal@442: url = decode(url || url2 || url3); bgneal@442: bgneal@442: // Convert the URL to relative/absolute depending on config bgneal@442: if (urlConverter) bgneal@442: url = urlConverter.call(urlConverterScope, url, 'style'); bgneal@442: bgneal@442: // Output new URL format bgneal@442: return "url('" + url.replace(/\'/g, "\\'") + "')"; bgneal@442: }); bgneal@442: bgneal@442: styles[name] = isEncoded ? decode(value, true) : value; bgneal@442: } bgneal@442: bgneal@442: styleRegExp.lastIndex = matches.index + matches[0].length; bgneal@442: } bgneal@442: bgneal@442: // Compress the styles to reduce it's size for example IE will expand styles bgneal@442: compress("border", ""); bgneal@442: compress("border", "-width"); bgneal@442: compress("border", "-color"); bgneal@442: compress("border", "-style"); bgneal@442: compress("padding", ""); bgneal@442: compress("margin", ""); bgneal@442: compress2('border', 'border-width', 'border-style', 'border-color'); bgneal@442: bgneal@442: // Remove pointless border, IE produces these bgneal@442: if (styles.border === 'medium none') bgneal@442: delete styles.border; bgneal@442: } bgneal@442: bgneal@442: return styles; bgneal@442: }, bgneal@442: bgneal@442: serialize : function(styles, element_name) { bgneal@442: var css = '', name, value; bgneal@442: bgneal@442: function serializeStyles(name) { bgneal@442: var styleList, i, l, name, value; bgneal@442: bgneal@442: styleList = schema.styles[name]; bgneal@442: if (styleList) { bgneal@442: for (i = 0, l = styleList.length; i < l; i++) { bgneal@442: name = styleList[i]; bgneal@442: value = styles[name]; bgneal@442: bgneal@442: if (value !== undef && value.length > 0) bgneal@442: css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';'; bgneal@442: } bgneal@442: } bgneal@442: }; bgneal@442: bgneal@442: // Serialize styles according to schema bgneal@442: if (element_name && schema && schema.styles) { bgneal@442: // Serialize global styles and element specific styles bgneal@442: serializeStyles('*'); bgneal@442: serializeStyles(name); bgneal@442: } else { bgneal@442: // Output the styles in the order they are inside the object bgneal@442: for (name in styles) { bgneal@442: value = styles[name]; bgneal@442: bgneal@442: if (value !== undef && value.length > 0) bgneal@442: css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';'; bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: return css; bgneal@442: } bgneal@442: }; bgneal@442: }; bgneal@442: bgneal@442: (function(tinymce) { bgneal@442: var transitional = {}, boolAttrMap, blockElementsMap, shortEndedElementsMap, nonEmptyElementsMap, bgneal@442: whiteSpaceElementsMap, selfClosingElementsMap, makeMap = tinymce.makeMap, each = tinymce.each; bgneal@442: bgneal@442: function split(str, delim) { bgneal@442: return str.split(delim || ','); bgneal@442: }; bgneal@442: bgneal@442: function unpack(lookup, data) { bgneal@442: var key, elements = {}; bgneal@442: bgneal@442: function replace(value) { bgneal@442: return value.replace(/[A-Z]+/g, function(key) { bgneal@442: return replace(lookup[key]); bgneal@442: }); bgneal@442: }; bgneal@442: bgneal@442: // Unpack lookup bgneal@442: for (key in lookup) { bgneal@442: if (lookup.hasOwnProperty(key)) bgneal@442: lookup[key] = replace(lookup[key]); bgneal@442: } bgneal@442: bgneal@442: // Unpack and parse data into object map bgneal@442: replace(data).replace(/#/g, '#text').replace(/(\w+)\[([^\]]+)\]\[([^\]]*)\]/g, function(str, name, attributes, children) { bgneal@442: attributes = split(attributes, '|'); bgneal@442: bgneal@442: elements[name] = { bgneal@442: attributes : makeMap(attributes), bgneal@442: attributesOrder : attributes, bgneal@442: children : makeMap(children, '|', {'#comment' : {}}) bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: return elements; bgneal@442: }; bgneal@442: bgneal@442: // Build a lookup table for block elements both lowercase and uppercase bgneal@442: blockElementsMap = 'h1,h2,h3,h4,h5,h6,hr,p,div,address,pre,form,table,tbody,thead,tfoot,' + bgneal@442: 'th,tr,td,li,ol,ul,caption,blockquote,center,dl,dt,dd,dir,fieldset,' + bgneal@442: 'noscript,menu,isindex,samp,header,footer,article,section,hgroup'; bgneal@442: blockElementsMap = makeMap(blockElementsMap, ',', makeMap(blockElementsMap.toUpperCase())); bgneal@442: bgneal@442: // This is the XHTML 1.0 transitional elements with it's attributes and children packed to reduce it's size bgneal@442: transitional = unpack({ bgneal@442: Z : 'H|K|N|O|P', bgneal@442: Y : 'X|form|R|Q', bgneal@442: ZG : 'E|span|width|align|char|charoff|valign', bgneal@442: X : 'p|T|div|U|W|isindex|fieldset|table', bgneal@442: ZF : 'E|align|char|charoff|valign', bgneal@442: W : 'pre|hr|blockquote|address|center|noframes', bgneal@442: ZE : 'abbr|axis|headers|scope|rowspan|colspan|align|char|charoff|valign|nowrap|bgcolor|width|height', bgneal@442: ZD : '[E][S]', bgneal@442: U : 'ul|ol|dl|menu|dir', bgneal@442: ZC : 'p|Y|div|U|W|table|br|span|bdo|object|applet|img|map|K|N|Q', bgneal@442: T : 'h1|h2|h3|h4|h5|h6', bgneal@442: ZB : 'X|S|Q', bgneal@442: S : 'R|P', bgneal@442: ZA : 'a|G|J|M|O|P', bgneal@442: R : 'a|H|K|N|O', bgneal@442: Q : 'noscript|P', bgneal@442: P : 'ins|del|script', bgneal@442: O : 'input|select|textarea|label|button', bgneal@442: N : 'M|L', bgneal@442: M : 'em|strong|dfn|code|q|samp|kbd|var|cite|abbr|acronym', bgneal@442: L : 'sub|sup', bgneal@442: K : 'J|I', bgneal@442: J : 'tt|i|b|u|s|strike', bgneal@442: I : 'big|small|font|basefont', bgneal@442: H : 'G|F', bgneal@442: G : 'br|span|bdo', bgneal@442: F : 'object|applet|img|map|iframe', bgneal@442: E : 'A|B|C', bgneal@442: D : 'accesskey|tabindex|onfocus|onblur', bgneal@442: C : 'onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup', bgneal@442: B : 'lang|xml:lang|dir', bgneal@442: A : 'id|class|style|title' bgneal@442: }, 'script[id|charset|type|language|src|defer|xml:space][]' + bgneal@442: 'style[B|id|type|media|title|xml:space][]' + bgneal@442: 'object[E|declare|classid|codebase|data|type|codetype|archive|standby|width|height|usemap|name|tabindex|align|border|hspace|vspace][#|param|Y]' + bgneal@442: 'param[id|name|value|valuetype|type][]' + bgneal@442: 'p[E|align][#|S]' + bgneal@442: 'a[E|D|charset|type|name|href|hreflang|rel|rev|shape|coords|target][#|Z]' + bgneal@442: 'br[A|clear][]' + bgneal@442: 'span[E][#|S]' + bgneal@442: 'bdo[A|C|B][#|S]' + bgneal@442: 'applet[A|codebase|archive|code|object|alt|name|width|height|align|hspace|vspace][#|param|Y]' + bgneal@442: 'h1[E|align][#|S]' + bgneal@442: 'img[E|src|alt|name|longdesc|width|height|usemap|ismap|align|border|hspace|vspace][]' + bgneal@442: 'map[B|C|A|name][X|form|Q|area]' + bgneal@442: 'h2[E|align][#|S]' + bgneal@442: 'iframe[A|longdesc|name|src|frameborder|marginwidth|marginheight|scrolling|align|width|height][#|Y]' + bgneal@442: 'h3[E|align][#|S]' + bgneal@442: 'tt[E][#|S]' + bgneal@442: 'i[E][#|S]' + bgneal@442: 'b[E][#|S]' + bgneal@442: 'u[E][#|S]' + bgneal@442: 's[E][#|S]' + bgneal@442: 'strike[E][#|S]' + bgneal@442: 'big[E][#|S]' + bgneal@442: 'small[E][#|S]' + bgneal@442: 'font[A|B|size|color|face][#|S]' + bgneal@442: 'basefont[id|size|color|face][]' + bgneal@442: 'em[E][#|S]' + bgneal@442: 'strong[E][#|S]' + bgneal@442: 'dfn[E][#|S]' + bgneal@442: 'code[E][#|S]' + bgneal@442: 'q[E|cite][#|S]' + bgneal@442: 'samp[E][#|S]' + bgneal@442: 'kbd[E][#|S]' + bgneal@442: 'var[E][#|S]' + bgneal@442: 'cite[E][#|S]' + bgneal@442: 'abbr[E][#|S]' + bgneal@442: 'acronym[E][#|S]' + bgneal@442: 'sub[E][#|S]' + bgneal@442: 'sup[E][#|S]' + bgneal@442: 'input[E|D|type|name|value|checked|disabled|readonly|size|maxlength|src|alt|usemap|onselect|onchange|accept|align][]' + bgneal@442: 'select[E|name|size|multiple|disabled|tabindex|onfocus|onblur|onchange][optgroup|option]' + bgneal@442: 'optgroup[E|disabled|label][option]' + bgneal@442: 'option[E|selected|disabled|label|value][]' + bgneal@442: 'textarea[E|D|name|rows|cols|disabled|readonly|onselect|onchange][]' + bgneal@442: 'label[E|for|accesskey|onfocus|onblur][#|S]' + bgneal@442: 'button[E|D|name|value|type|disabled][#|p|T|div|U|W|table|G|object|applet|img|map|K|N|Q]' + bgneal@442: 'h4[E|align][#|S]' + bgneal@442: 'ins[E|cite|datetime][#|Y]' + bgneal@442: 'h5[E|align][#|S]' + bgneal@442: 'del[E|cite|datetime][#|Y]' + bgneal@442: 'h6[E|align][#|S]' + bgneal@442: 'div[E|align][#|Y]' + bgneal@442: 'ul[E|type|compact][li]' + bgneal@442: 'li[E|type|value][#|Y]' + bgneal@442: 'ol[E|type|compact|start][li]' + bgneal@442: 'dl[E|compact][dt|dd]' + bgneal@442: 'dt[E][#|S]' + bgneal@442: 'dd[E][#|Y]' + bgneal@442: 'menu[E|compact][li]' + bgneal@442: 'dir[E|compact][li]' + bgneal@442: 'pre[E|width|xml:space][#|ZA]' + bgneal@442: 'hr[E|align|noshade|size|width][]' + bgneal@442: 'blockquote[E|cite][#|Y]' + bgneal@442: 'address[E][#|S|p]' + bgneal@442: 'center[E][#|Y]' + bgneal@442: 'noframes[E][#|Y]' + bgneal@442: 'isindex[A|B|prompt][]' + bgneal@442: 'fieldset[E][#|legend|Y]' + bgneal@442: 'legend[E|accesskey|align][#|S]' + bgneal@442: 'table[E|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor][caption|col|colgroup|thead|tfoot|tbody|tr]' + bgneal@442: 'caption[E|align][#|S]' + bgneal@442: 'col[ZG][]' + bgneal@442: 'colgroup[ZG][col]' + bgneal@442: 'thead[ZF][tr]' + bgneal@442: 'tr[ZF|bgcolor][th|td]' + bgneal@442: 'th[E|ZE][#|Y]' + bgneal@442: 'form[E|action|method|name|enctype|onsubmit|onreset|accept|accept-charset|target][#|X|R|Q]' + bgneal@442: 'noscript[E][#|Y]' + bgneal@442: 'td[E|ZE][#|Y]' + bgneal@442: 'tfoot[ZF][tr]' + bgneal@442: 'tbody[ZF][tr]' + bgneal@442: 'area[E|D|shape|coords|href|nohref|alt|target][]' + bgneal@442: 'base[id|href|target][]' + bgneal@442: 'body[E|onload|onunload|background|bgcolor|text|link|vlink|alink][#|Y]' bgneal@442: ); bgneal@442: bgneal@442: boolAttrMap = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected,preload,autoplay,loop,controls'); bgneal@442: shortEndedElementsMap = makeMap('area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed,source'); bgneal@442: nonEmptyElementsMap = tinymce.extend(makeMap('td,th,iframe,video,object'), shortEndedElementsMap); bgneal@442: whiteSpaceElementsMap = makeMap('pre,script,style'); bgneal@442: selfClosingElementsMap = makeMap('colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr'); bgneal@442: bgneal@442: tinymce.html.Schema = function(settings) { bgneal@442: var self = this, elements = {}, children = {}, patternElements = [], validStyles; bgneal@442: bgneal@442: settings = settings || {}; bgneal@442: bgneal@442: // Allow all elements and attributes if verify_html is set to false bgneal@442: if (settings.verify_html === false) bgneal@442: settings.valid_elements = '*[*]'; bgneal@442: bgneal@442: // Build styles list bgneal@442: if (settings.valid_styles) { bgneal@442: validStyles = {}; bgneal@442: bgneal@442: // Convert styles into a rule list bgneal@442: each(settings.valid_styles, function(value, key) { bgneal@442: validStyles[key] = tinymce.explode(value); bgneal@442: }); bgneal@442: } bgneal@442: bgneal@442: // Converts a wildcard expression string to a regexp for example *a will become /.*a/. bgneal@442: function patternToRegExp(str) { bgneal@442: return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$'); bgneal@442: }; bgneal@442: bgneal@442: // Parses the specified valid_elements string and adds to the current rules bgneal@442: // This function is a bit hard to read since it's heavily optimized for speed bgneal@442: function addValidElements(valid_elements) { bgneal@442: var ei, el, ai, al, yl, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder, bgneal@442: prefix, outputName, globalAttributes, globalAttributesOrder, transElement, key, childKey, value, bgneal@442: elementRuleRegExp = /^([#+-])?([^\[\/]+)(?:\/([^\[]+))?(?:\[([^\]]+)\])?$/, bgneal@442: attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/, bgneal@442: hasPatternsRegExp = /[*?+]/; bgneal@442: bgneal@442: if (valid_elements) { bgneal@442: // Split valid elements into an array with rules bgneal@442: valid_elements = split(valid_elements); bgneal@442: bgneal@442: if (elements['@']) { bgneal@442: globalAttributes = elements['@'].attributes; bgneal@442: globalAttributesOrder = elements['@'].attributesOrder; bgneal@442: } bgneal@442: bgneal@442: // Loop all rules bgneal@442: for (ei = 0, el = valid_elements.length; ei < el; ei++) { bgneal@442: // Parse element rule bgneal@442: matches = elementRuleRegExp.exec(valid_elements[ei]); bgneal@442: if (matches) { bgneal@442: // Setup local names for matches bgneal@442: prefix = matches[1]; bgneal@442: elementName = matches[2]; bgneal@442: outputName = matches[3]; bgneal@442: attrData = matches[4]; bgneal@442: bgneal@442: // Create new attributes and attributesOrder bgneal@442: attributes = {}; bgneal@442: attributesOrder = []; bgneal@442: bgneal@442: // Create the new element bgneal@442: element = { bgneal@442: attributes : attributes, bgneal@442: attributesOrder : attributesOrder bgneal@442: }; bgneal@442: bgneal@442: // Padd empty elements prefix bgneal@442: if (prefix === '#') bgneal@442: element.paddEmpty = true; bgneal@442: bgneal@442: // Remove empty elements prefix bgneal@442: if (prefix === '-') bgneal@442: element.removeEmpty = true; bgneal@442: bgneal@442: // Copy attributes from global rule into current rule bgneal@442: if (globalAttributes) { bgneal@442: for (key in globalAttributes) bgneal@442: attributes[key] = globalAttributes[key]; bgneal@442: bgneal@442: attributesOrder.push.apply(attributesOrder, globalAttributesOrder); bgneal@442: } bgneal@442: bgneal@442: // Attributes defined bgneal@442: if (attrData) { bgneal@442: attrData = split(attrData, '|'); bgneal@442: for (ai = 0, al = attrData.length; ai < al; ai++) { bgneal@442: matches = attrRuleRegExp.exec(attrData[ai]); bgneal@442: if (matches) { bgneal@442: attr = {}; bgneal@442: attrType = matches[1]; bgneal@442: attrName = matches[2].replace(/::/g, ':'); bgneal@442: prefix = matches[3]; bgneal@442: value = matches[4]; bgneal@442: bgneal@442: // Required bgneal@442: if (attrType === '!') { bgneal@442: element.attributesRequired = element.attributesRequired || []; bgneal@442: element.attributesRequired.push(attrName); bgneal@442: attr.required = true; bgneal@442: } bgneal@442: bgneal@442: // Denied from global bgneal@442: if (attrType === '-') { bgneal@442: delete attributes[attrName]; bgneal@442: attributesOrder.splice(tinymce.inArray(attributesOrder, attrName), 1); bgneal@442: continue; bgneal@442: } bgneal@442: bgneal@442: // Default value bgneal@442: if (prefix) { bgneal@442: // Default value bgneal@442: if (prefix === '=') { bgneal@442: element.attributesDefault = element.attributesDefault || []; bgneal@442: element.attributesDefault.push({name: attrName, value: value}); bgneal@442: attr.defaultValue = value; bgneal@442: } bgneal@442: bgneal@442: // Forced value bgneal@442: if (prefix === ':') { bgneal@442: element.attributesForced = element.attributesForced || []; bgneal@442: element.attributesForced.push({name: attrName, value: value}); bgneal@442: attr.forcedValue = value; bgneal@442: } bgneal@442: bgneal@442: // Required values bgneal@442: if (prefix === '<') bgneal@442: attr.validValues = makeMap(value, '?'); bgneal@442: } bgneal@442: bgneal@442: // Check for attribute patterns bgneal@442: if (hasPatternsRegExp.test(attrName)) { bgneal@442: element.attributePatterns = element.attributePatterns || []; bgneal@442: attr.pattern = patternToRegExp(attrName); bgneal@442: element.attributePatterns.push(attr); bgneal@442: } else { bgneal@442: // Add attribute to order list if it doesn't already exist bgneal@442: if (!attributes[attrName]) bgneal@442: attributesOrder.push(attrName); bgneal@442: bgneal@442: attributes[attrName] = attr; bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: // Global rule, store away these for later usage bgneal@442: if (!globalAttributes && elementName == '@') { bgneal@442: globalAttributes = attributes; bgneal@442: globalAttributesOrder = attributesOrder; bgneal@442: } bgneal@442: bgneal@442: // Handle substitute elements such as b/strong bgneal@442: if (outputName) { bgneal@442: element.outputName = elementName; bgneal@442: elements[outputName] = element; bgneal@442: } bgneal@442: bgneal@442: // Add pattern or exact element bgneal@442: if (hasPatternsRegExp.test(elementName)) { bgneal@442: element.pattern = patternToRegExp(elementName); bgneal@442: patternElements.push(element); bgneal@442: } else bgneal@442: elements[elementName] = element; bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: }; bgneal@442: bgneal@442: function setValidElements(valid_elements) { bgneal@442: elements = {}; bgneal@442: patternElements = []; bgneal@442: bgneal@442: addValidElements(valid_elements); bgneal@442: bgneal@442: each(transitional, function(element, name) { bgneal@442: children[name] = element.children; bgneal@442: }); bgneal@442: }; bgneal@442: bgneal@442: // Adds custom non HTML elements to the schema bgneal@442: function addCustomElements(custom_elements) { bgneal@442: var customElementRegExp = /^(~)?(.+)$/; bgneal@442: bgneal@442: if (custom_elements) { bgneal@442: each(split(custom_elements), function(rule) { bgneal@442: var matches = customElementRegExp.exec(rule), bgneal@442: cloneName = matches[1] === '~' ? 'span' : 'div', bgneal@442: name = matches[2]; bgneal@442: bgneal@442: children[name] = children[cloneName]; bgneal@442: bgneal@442: // Add custom elements at span/div positions bgneal@442: each(children, function(element, child) { bgneal@442: if (element[cloneName]) bgneal@442: element[name] = element[cloneName]; bgneal@442: }); bgneal@442: }); bgneal@442: } bgneal@442: }; bgneal@442: bgneal@442: // Adds valid children to the schema object bgneal@442: function addValidChildren(valid_children) { bgneal@442: var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/; bgneal@442: bgneal@442: if (valid_children) { bgneal@442: each(split(valid_children), function(rule) { bgneal@442: var matches = childRuleRegExp.exec(rule), parent, prefix; bgneal@442: bgneal@442: if (matches) { bgneal@442: prefix = matches[1]; bgneal@442: bgneal@442: // Add/remove items from default bgneal@442: if (prefix) bgneal@442: parent = children[matches[2]]; bgneal@442: else bgneal@442: parent = children[matches[2]] = {'#comment' : {}}; bgneal@442: bgneal@442: parent = children[matches[2]]; bgneal@442: bgneal@442: each(split(matches[3], '|'), function(child) { bgneal@442: if (prefix === '-') bgneal@442: delete parent[child]; bgneal@442: else bgneal@442: parent[child] = {}; bgneal@442: }); bgneal@442: } bgneal@442: }); bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: if (!settings.valid_elements) { bgneal@442: // No valid elements defined then clone the elements from the transitional spec bgneal@442: each(transitional, function(element, name) { bgneal@442: elements[name] = { bgneal@442: attributes : element.attributes, bgneal@442: attributesOrder : element.attributesOrder bgneal@442: }; bgneal@442: bgneal@442: children[name] = element.children; bgneal@442: }); bgneal@442: bgneal@442: // Switch these bgneal@442: each(split('strong/b,em/i'), function(item) { bgneal@442: item = split(item, '/'); bgneal@442: elements[item[1]].outputName = item[0]; bgneal@442: }); bgneal@442: bgneal@442: // Add default alt attribute for images bgneal@442: elements.img.attributesDefault = [{name: 'alt', value: ''}]; bgneal@442: bgneal@442: // Remove these if they are empty by default bgneal@442: each(split('ol,ul,li,sub,sup,blockquote,tr,div,span,font,a,table,tbody'), function(name) { bgneal@442: elements[name].removeEmpty = true; bgneal@442: }); bgneal@442: bgneal@442: // Padd these by default bgneal@442: each(split('p,h1,h2,h3,h4,h5,h6,th,td,pre,div,address,caption'), function(name) { bgneal@442: elements[name].paddEmpty = true; bgneal@442: }); bgneal@442: } else bgneal@442: setValidElements(settings.valid_elements); bgneal@442: bgneal@442: addCustomElements(settings.custom_elements); bgneal@442: addValidChildren(settings.valid_children); bgneal@442: addValidElements(settings.extended_valid_elements); bgneal@442: bgneal@442: // Todo: Remove this when we fix list handling to be valid bgneal@442: addValidChildren('+ol[ul|ol],+ul[ul|ol]'); bgneal@442: bgneal@442: // Delete invalid elements bgneal@442: if (settings.invalid_elements) { bgneal@442: tinymce.each(tinymce.explode(settings.invalid_elements), function(item) { bgneal@442: if (elements[item]) bgneal@442: delete elements[item]; bgneal@442: }); bgneal@442: } bgneal@442: bgneal@442: self.children = children; bgneal@442: bgneal@442: self.styles = validStyles; bgneal@442: bgneal@442: self.getBoolAttrs = function() { bgneal@442: return boolAttrMap; bgneal@442: }; bgneal@442: bgneal@442: self.getBlockElements = function() { bgneal@442: return blockElementsMap; bgneal@442: }; bgneal@442: bgneal@442: self.getShortEndedElements = function() { bgneal@442: return shortEndedElementsMap; bgneal@442: }; bgneal@442: bgneal@442: self.getSelfClosingElements = function() { bgneal@442: return selfClosingElementsMap; bgneal@442: }; bgneal@442: bgneal@442: self.getNonEmptyElements = function() { bgneal@442: return nonEmptyElementsMap; bgneal@442: }; bgneal@442: bgneal@442: self.getWhiteSpaceElements = function() { bgneal@442: return whiteSpaceElementsMap; bgneal@442: }; bgneal@442: bgneal@442: self.isValidChild = function(name, child) { bgneal@442: var parent = children[name]; bgneal@442: bgneal@442: return !!(parent && parent[child]); bgneal@442: }; bgneal@442: bgneal@442: self.getElementRule = function(name) { bgneal@442: var element = elements[name], i; bgneal@442: bgneal@442: // Exact match found bgneal@442: if (element) bgneal@442: return element; bgneal@442: bgneal@442: // No exact match then try the patterns bgneal@442: i = patternElements.length; bgneal@442: while (i--) { bgneal@442: element = patternElements[i]; bgneal@442: bgneal@442: if (element.pattern.test(name)) bgneal@442: return element; bgneal@442: } bgneal@442: }; bgneal@442: bgneal@442: self.addValidElements = addValidElements; bgneal@442: bgneal@442: self.setValidElements = setValidElements; bgneal@442: bgneal@442: self.addCustomElements = addCustomElements; bgneal@442: bgneal@442: self.addValidChildren = addValidChildren; bgneal@442: }; bgneal@442: bgneal@442: // Expose boolMap and blockElementMap as static properties for usage in DOMUtils bgneal@442: tinymce.html.Schema.boolAttrMap = boolAttrMap; bgneal@442: tinymce.html.Schema.blockElementsMap = blockElementsMap; bgneal@442: })(tinymce); bgneal@442: bgneal@442: (function(tinymce) { bgneal@442: tinymce.html.SaxParser = function(settings, schema) { bgneal@442: var self = this, noop = function() {}; bgneal@442: bgneal@442: settings = settings || {}; bgneal@442: self.schema = schema = schema || new tinymce.html.Schema(); bgneal@442: bgneal@442: if (settings.fix_self_closing !== false) bgneal@442: settings.fix_self_closing = true; bgneal@442: bgneal@442: // Add handler functions from settings and setup default handlers bgneal@442: tinymce.each('comment cdata text start end pi doctype'.split(' '), function(name) { bgneal@442: if (name) bgneal@442: self[name] = settings[name] || noop; bgneal@442: }); bgneal@442: bgneal@442: self.parse = function(html) { bgneal@442: var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name, bgneal@442: shortEndedElements, fillAttrsMap, isShortEnded, validate, elementRule, isValidElement, attr, attribsValue, bgneal@442: validAttributesMap, validAttributePatterns, attributesRequired, attributesDefault, attributesForced, selfClosing, bgneal@442: tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0, decode = tinymce.html.Entities.decode, fixSelfClosing; bgneal@442: bgneal@442: function processEndTag(name) { bgneal@442: var pos, i; bgneal@442: bgneal@442: // Find position of parent of the same type bgneal@442: pos = stack.length; bgneal@442: while (pos--) { bgneal@442: if (stack[pos].name === name) bgneal@442: break; bgneal@442: } bgneal@442: bgneal@442: // Found parent bgneal@442: if (pos >= 0) { bgneal@442: // Close all the open elements bgneal@442: for (i = stack.length - 1; i >= pos; i--) { bgneal@442: name = stack[i]; bgneal@442: bgneal@442: if (name.valid) bgneal@442: self.end(name.name); bgneal@442: } bgneal@442: bgneal@442: // Remove the open elements from the stack bgneal@442: stack.length = pos; bgneal@442: } bgneal@442: }; bgneal@442: bgneal@442: // Precompile RegExps and map objects bgneal@442: tokenRegExp = new RegExp('<(?:' + bgneal@442: '(?:!--([\\w\\W]*?)-->)|' + // Comment bgneal@442: '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA bgneal@442: '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE bgneal@442: '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI bgneal@442: '(?:\\/([^>]+)>)|' + // End element bgneal@442: '(?:([^\\s\\/<>]+)\\s*((?:[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*)>)' + // Start element bgneal@442: ')', 'g'); bgneal@442: bgneal@442: attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:\\.|[^\"])*)\")|(?:\'((?:\\.|[^\'])*)\')|([^>\s]+)))?/g; bgneal@442: specialElements = { bgneal@442: 'script' : /<\/script[^>]*>/gi, bgneal@442: 'style' : /<\/style[^>]*>/gi, bgneal@442: 'noscript' : /<\/noscript[^>]*>/gi bgneal@442: }; bgneal@442: bgneal@442: // Setup lookup tables for empty elements and boolean attributes bgneal@442: shortEndedElements = schema.getShortEndedElements(); bgneal@442: selfClosing = schema.getSelfClosingElements(); bgneal@442: fillAttrsMap = schema.getBoolAttrs(); bgneal@442: validate = settings.validate; bgneal@442: fixSelfClosing = settings.fix_self_closing; bgneal@442: bgneal@442: while (matches = tokenRegExp.exec(html)) { bgneal@442: // Text bgneal@442: if (index < matches.index) bgneal@442: self.text(decode(html.substr(index, matches.index - index))); bgneal@442: bgneal@442: if (value = matches[6]) { // End element bgneal@442: processEndTag(value.toLowerCase()); bgneal@442: } else if (value = matches[7]) { // Start element bgneal@442: value = value.toLowerCase(); bgneal@442: isShortEnded = value in shortEndedElements; bgneal@442: bgneal@442: // Is self closing tag for example an
  • after an open
  • bgneal@442: if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value) bgneal@442: processEndTag(value); bgneal@442: bgneal@442: // Validate element bgneal@442: if (!validate || (elementRule = schema.getElementRule(value))) { bgneal@442: isValidElement = true; bgneal@442: bgneal@442: // Grab attributes map and patters when validation is enabled bgneal@442: if (validate) { bgneal@442: validAttributesMap = elementRule.attributes; bgneal@442: validAttributePatterns = elementRule.attributePatterns; bgneal@442: } bgneal@442: bgneal@442: // Parse attributes bgneal@442: if (attribsValue = matches[8]) { bgneal@442: attrList = []; bgneal@442: attrList.map = {}; bgneal@442: bgneal@442: attribsValue.replace(attrRegExp, function(match, name, value, val2, val3) { bgneal@442: var attrRule, i; bgneal@442: bgneal@442: name = name.toLowerCase(); bgneal@442: value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute bgneal@442: bgneal@442: // Validate name and value bgneal@442: if (validate && name.indexOf('data-') !== 0) { bgneal@442: attrRule = validAttributesMap[name]; bgneal@442: bgneal@442: // Find rule by pattern matching bgneal@442: if (!attrRule && validAttributePatterns) { bgneal@442: i = validAttributePatterns.length; bgneal@442: while (i--) { bgneal@442: attrRule = validAttributePatterns[i]; bgneal@442: if (attrRule.pattern.test(name)) bgneal@442: break; bgneal@442: } bgneal@442: bgneal@442: // No rule matched bgneal@442: if (i === -1) bgneal@442: attrRule = null; bgneal@442: } bgneal@442: bgneal@442: // No attribute rule found bgneal@442: if (!attrRule) bgneal@442: return; bgneal@442: bgneal@442: // Validate value bgneal@442: if (attrRule.validValues && !(value in attrRule.validValues)) bgneal@442: return; bgneal@442: } bgneal@442: bgneal@442: // Add attribute to list and map bgneal@442: attrList.map[name] = value; bgneal@442: attrList.push({ bgneal@442: name: name, bgneal@442: value: value bgneal@442: }); bgneal@442: }); bgneal@442: } else { bgneal@442: attrList = []; bgneal@442: attrList.map = {}; bgneal@442: } bgneal@442: bgneal@442: // Process attributes if validation is enabled bgneal@442: if (validate) { bgneal@442: attributesRequired = elementRule.attributesRequired; bgneal@442: attributesDefault = elementRule.attributesDefault; bgneal@442: attributesForced = elementRule.attributesForced; bgneal@442: bgneal@442: // Handle forced attributes bgneal@442: if (attributesForced) { bgneal@442: i = attributesForced.length; bgneal@442: while (i--) { bgneal@442: attr = attributesForced[i]; bgneal@442: name = attr.name; bgneal@442: attrValue = attr.value; bgneal@442: bgneal@442: if (attrValue === '{$uid}') bgneal@442: attrValue = 'mce_' + idCount++; bgneal@442: bgneal@442: attrList.map[name] = attrValue; bgneal@442: attrList.push({name: name, value: attrValue}); bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: // Handle default attributes bgneal@442: if (attributesDefault) { bgneal@442: i = attributesDefault.length; bgneal@442: while (i--) { bgneal@442: attr = attributesDefault[i]; bgneal@442: name = attr.name; bgneal@442: bgneal@442: if (!(name in attrList.map)) { bgneal@442: attrValue = attr.value; bgneal@442: bgneal@442: if (attrValue === '{$uid}') bgneal@442: attrValue = 'mce_' + idCount++; bgneal@442: bgneal@442: attrList.map[name] = attrValue; bgneal@442: attrList.push({name: name, value: attrValue}); bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: // Handle required attributes bgneal@442: if (attributesRequired) { bgneal@442: i = attributesRequired.length; bgneal@442: while (i--) { bgneal@442: if (attributesRequired[i] in attrList.map) bgneal@442: break; bgneal@442: } bgneal@442: bgneal@442: // None of the required attributes where found bgneal@442: if (i === -1) bgneal@442: isValidElement = false; bgneal@442: } bgneal@442: bgneal@442: // Invalidate element if it's marked as bogus bgneal@442: if (attrList.map['data-mce-bogus']) bgneal@442: isValidElement = false; bgneal@442: } bgneal@442: bgneal@442: if (isValidElement) bgneal@442: self.start(value, attrList, isShortEnded); bgneal@442: } else bgneal@442: isValidElement = false; bgneal@442: bgneal@442: // Treat script, noscript and style a bit different since they may include code that looks like elements bgneal@442: if (endRegExp = specialElements[value]) { bgneal@442: endRegExp.lastIndex = index = matches.index + matches[0].length; bgneal@442: bgneal@442: if (matches = endRegExp.exec(html)) { bgneal@442: if (isValidElement) bgneal@442: text = html.substr(index, matches.index - index); bgneal@442: bgneal@442: index = matches.index + matches[0].length; bgneal@442: } else { bgneal@442: text = html.substr(index); bgneal@442: index = html.length; bgneal@442: } bgneal@442: bgneal@442: if (isValidElement && text.length > 0) bgneal@442: self.text(text, true); bgneal@442: bgneal@442: if (isValidElement) bgneal@442: self.end(value); bgneal@442: bgneal@442: tokenRegExp.lastIndex = index; bgneal@442: continue; bgneal@442: } bgneal@442: bgneal@442: // Push value on to stack bgneal@442: if (!isShortEnded) { bgneal@442: if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1) bgneal@442: stack.push({name: value, valid: isValidElement}); bgneal@442: else if (isValidElement) bgneal@442: self.end(value); bgneal@442: } bgneal@442: } else if (value = matches[1]) { // Comment bgneal@442: self.comment(value); bgneal@442: } else if (value = matches[2]) { // CDATA bgneal@442: self.cdata(value); bgneal@442: } else if (value = matches[3]) { // DOCTYPE bgneal@442: self.doctype(value); bgneal@442: } else if (value = matches[4]) { // PI bgneal@442: self.pi(value, matches[5]); bgneal@442: } bgneal@442: bgneal@442: index = matches.index + matches[0].length; bgneal@442: } bgneal@442: bgneal@442: // Text bgneal@442: if (index < html.length) bgneal@442: self.text(decode(html.substr(index))); bgneal@442: bgneal@442: // Close any open elements bgneal@442: for (i = stack.length - 1; i >= 0; i--) { bgneal@442: value = stack[i]; bgneal@442: bgneal@442: if (value.valid) bgneal@442: self.end(value.name); bgneal@442: } bgneal@442: }; bgneal@442: } bgneal@442: })(tinymce); bgneal@442: bgneal@442: (function(tinymce) { bgneal@442: var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = { bgneal@442: '#text' : 3, bgneal@442: '#comment' : 8, bgneal@442: '#cdata' : 4, bgneal@442: '#pi' : 7, bgneal@442: '#doctype' : 10, bgneal@442: '#document-fragment' : 11 bgneal@442: }; bgneal@442: bgneal@442: // Walks the tree left/right bgneal@442: function walk(node, root_node, prev) { bgneal@442: var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next'; bgneal@442: bgneal@442: // Walk into nodes if it has a start bgneal@442: if (node[startName]) bgneal@442: return node[startName]; bgneal@442: bgneal@442: // Return the sibling if it has one bgneal@442: if (node !== root_node) { bgneal@442: sibling = node[siblingName]; bgneal@442: bgneal@442: if (sibling) bgneal@442: return sibling; bgneal@442: bgneal@442: // Walk up the parents to look for siblings bgneal@442: for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) { bgneal@442: sibling = parent[siblingName]; bgneal@442: bgneal@442: if (sibling) bgneal@442: return sibling; bgneal@442: } bgneal@442: } bgneal@442: }; bgneal@442: bgneal@442: function Node(name, type) { bgneal@442: this.name = name; bgneal@442: this.type = type; bgneal@442: bgneal@442: if (type === 1) { bgneal@442: this.attributes = []; bgneal@442: this.attributes.map = {}; bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: tinymce.extend(Node.prototype, { bgneal@442: replace : function(node) { bgneal@442: var self = this; bgneal@442: bgneal@442: if (node.parent) bgneal@442: node.remove(); bgneal@442: bgneal@442: self.insert(node, self); bgneal@442: self.remove(); bgneal@442: bgneal@442: return self; bgneal@442: }, bgneal@442: bgneal@442: attr : function(name, value) { bgneal@442: var self = this, attrs, i, undef; bgneal@442: bgneal@442: if (typeof name !== "string") { bgneal@442: for (i in name) bgneal@442: self.attr(i, name[i]); bgneal@442: bgneal@442: return self; bgneal@442: } bgneal@442: bgneal@442: if (attrs = self.attributes) { bgneal@442: if (value !== undef) { bgneal@442: // Remove attribute bgneal@442: if (value === null) { bgneal@442: if (name in attrs.map) { bgneal@442: delete attrs.map[name]; bgneal@442: bgneal@442: i = attrs.length; bgneal@442: while (i--) { bgneal@442: if (attrs[i].name === name) { bgneal@442: attrs = attrs.splice(i, 1); bgneal@442: return self; bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: return self; bgneal@442: } bgneal@442: bgneal@442: // Set attribute bgneal@442: if (name in attrs.map) { bgneal@442: // Set attribute bgneal@442: i = attrs.length; bgneal@442: while (i--) { bgneal@442: if (attrs[i].name === name) { bgneal@442: attrs[i].value = value; bgneal@442: break; bgneal@442: } bgneal@442: } bgneal@442: } else bgneal@442: attrs.push({name: name, value: value}); bgneal@442: bgneal@442: attrs.map[name] = value; bgneal@442: bgneal@442: return self; bgneal@442: } else { bgneal@442: return attrs.map[name]; bgneal@442: } bgneal@442: } bgneal@442: }, bgneal@442: bgneal@442: clone : function() { bgneal@442: var self = this, clone = new Node(self.name, self.type), i, l, selfAttrs, selfAttr, cloneAttrs; bgneal@442: bgneal@442: // Clone element attributes bgneal@442: if (selfAttrs = self.attributes) { bgneal@442: cloneAttrs = []; bgneal@442: cloneAttrs.map = {}; bgneal@442: bgneal@442: for (i = 0, l = selfAttrs.length; i < l; i++) { bgneal@442: selfAttr = selfAttrs[i]; bgneal@442: bgneal@442: // Clone everything except id bgneal@442: if (selfAttr.name !== 'id') { bgneal@442: cloneAttrs[cloneAttrs.length] = {name: selfAttr.name, value: selfAttr.value}; bgneal@442: cloneAttrs.map[selfAttr.name] = selfAttr.value; bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: clone.attributes = cloneAttrs; bgneal@442: } bgneal@442: bgneal@442: clone.value = self.value; bgneal@442: clone.shortEnded = self.shortEnded; bgneal@442: bgneal@442: return clone; bgneal@442: }, bgneal@442: bgneal@442: wrap : function(wrapper) { bgneal@442: var self = this; bgneal@442: bgneal@442: self.parent.insert(wrapper, self); bgneal@442: wrapper.append(self); bgneal@442: bgneal@442: return self; bgneal@442: }, bgneal@442: bgneal@442: unwrap : function() { bgneal@442: var self = this, node, next; bgneal@442: bgneal@442: for (node = self.firstChild; node; ) { bgneal@442: next = node.next; bgneal@442: self.insert(node, self, true); bgneal@442: node = next; bgneal@442: } bgneal@442: bgneal@442: self.remove(); bgneal@442: }, bgneal@442: bgneal@442: remove : function() { bgneal@442: var self = this, parent = self.parent, next = self.next, prev = self.prev; bgneal@442: bgneal@442: if (parent) { bgneal@442: if (parent.firstChild === self) { bgneal@442: parent.firstChild = next; bgneal@442: bgneal@442: if (next) bgneal@442: next.prev = null; bgneal@442: } else { bgneal@442: prev.next = next; bgneal@442: } bgneal@442: bgneal@442: if (parent.lastChild === self) { bgneal@442: parent.lastChild = prev; bgneal@442: bgneal@442: if (prev) bgneal@442: prev.next = null; bgneal@442: } else { bgneal@442: next.prev = prev; bgneal@442: } bgneal@442: bgneal@442: self.parent = self.next = self.prev = null; bgneal@442: } bgneal@442: bgneal@442: return self; bgneal@442: }, bgneal@442: bgneal@442: append : function(node) { bgneal@442: var self = this, last; bgneal@442: bgneal@442: if (node.parent) bgneal@442: node.remove(); bgneal@442: bgneal@442: last = self.lastChild; bgneal@442: if (last) { bgneal@442: last.next = node; bgneal@442: node.prev = last; bgneal@442: self.lastChild = node; bgneal@442: } else bgneal@442: self.lastChild = self.firstChild = node; bgneal@442: bgneal@442: node.parent = self; bgneal@442: bgneal@442: return node; bgneal@442: }, bgneal@442: bgneal@442: insert : function(node, ref_node, before) { bgneal@442: var parent; bgneal@442: bgneal@442: if (node.parent) bgneal@442: node.remove(); bgneal@442: bgneal@442: parent = ref_node.parent || this; bgneal@442: bgneal@442: if (before) { bgneal@442: if (ref_node === parent.firstChild) bgneal@442: parent.firstChild = node; bgneal@442: else bgneal@442: ref_node.prev.next = node; bgneal@442: bgneal@442: node.prev = ref_node.prev; bgneal@442: node.next = ref_node; bgneal@442: ref_node.prev = node; bgneal@442: } else { bgneal@442: if (ref_node === parent.lastChild) bgneal@442: parent.lastChild = node; bgneal@442: else bgneal@442: ref_node.next.prev = node; bgneal@442: bgneal@442: node.next = ref_node.next; bgneal@442: node.prev = ref_node; bgneal@442: ref_node.next = node; bgneal@442: } bgneal@442: bgneal@442: node.parent = parent; bgneal@442: bgneal@442: return node; bgneal@442: }, bgneal@442: bgneal@442: getAll : function(name) { bgneal@442: var self = this, node, collection = []; bgneal@442: bgneal@442: for (node = self.firstChild; node; node = walk(node, self)) { bgneal@442: if (node.name === name) bgneal@442: collection.push(node); bgneal@442: } bgneal@442: bgneal@442: return collection; bgneal@442: }, bgneal@442: bgneal@442: empty : function() { bgneal@442: var self = this, nodes, i, node; bgneal@442: bgneal@442: // Remove all children bgneal@442: if (self.firstChild) { bgneal@442: nodes = []; bgneal@442: bgneal@442: // Collect the children bgneal@442: for (node = self.firstChild; node; node = walk(node, self)) bgneal@442: nodes.push(node); bgneal@442: bgneal@442: // Remove the children bgneal@442: i = nodes.length; bgneal@442: while (i--) { bgneal@442: node = nodes[i]; bgneal@442: node.parent = node.firstChild = node.lastChild = node.next = node.prev = null; bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: self.firstChild = self.lastChild = null; bgneal@442: bgneal@442: return self; bgneal@442: }, bgneal@442: bgneal@442: isEmpty : function(elements) { bgneal@442: var self = this, node = self.firstChild, i, name; bgneal@442: bgneal@442: if (node) { bgneal@442: do { bgneal@442: if (node.type === 1) { bgneal@442: // Ignore bogus elements bgneal@442: if (node.attributes.map['data-mce-bogus']) bgneal@442: continue; bgneal@442: bgneal@442: // Keep empty elements like bgneal@442: if (elements[node.name]) bgneal@442: return false; bgneal@442: bgneal@442: // Keep elements with data attributes or name attribute like bgneal@442: i = node.attributes.length; bgneal@442: while (i--) { bgneal@442: name = node.attributes[i].name; bgneal@442: if (name === "name" || name.indexOf('data-') === 0) bgneal@442: return false; bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: // Keep non whitespace text nodes bgneal@442: if ((node.type === 3 && !whiteSpaceRegExp.test(node.value))) bgneal@442: return false; bgneal@442: } while (node = walk(node, self)); bgneal@442: } bgneal@442: bgneal@442: return true; bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: tinymce.extend(Node, { bgneal@442: create : function(name, attrs) { bgneal@442: var node, attrName; bgneal@442: bgneal@442: // Create node bgneal@442: node = new Node(name, typeLookup[name] || 1); bgneal@442: bgneal@442: // Add attributes if needed bgneal@442: if (attrs) { bgneal@442: for (attrName in attrs) bgneal@442: node.attr(attrName, attrs[attrName]); bgneal@442: } bgneal@442: bgneal@442: return node; bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: tinymce.html.Node = Node; bgneal@442: })(tinymce); bgneal@442: bgneal@442: (function(tinymce) { bgneal@442: var Node = tinymce.html.Node; bgneal@442: bgneal@442: tinymce.html.DomParser = function(settings, schema) { bgneal@442: var self = this, nodeFilters = {}, attributeFilters = [], matchedNodes = {}, matchedAttributes = {}; bgneal@442: bgneal@442: settings = settings || {}; bgneal@442: settings.validate = "validate" in settings ? settings.validate : true; bgneal@442: settings.root_name = settings.root_name || 'body'; bgneal@442: self.schema = schema = schema || new tinymce.html.Schema(); bgneal@442: bgneal@442: function fixInvalidChildren(nodes) { bgneal@442: var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i, bgneal@442: childClone, nonEmptyElements, nonSplitableElements, sibling, nextNode; bgneal@442: bgneal@442: nonSplitableElements = tinymce.makeMap('tr,td,th,tbody,thead,tfoot,table'); bgneal@442: nonEmptyElements = schema.getNonEmptyElements(); bgneal@442: bgneal@442: for (ni = 0; ni < nodes.length; ni++) { bgneal@442: node = nodes[ni]; bgneal@442: bgneal@442: // Already removed bgneal@442: if (!node.parent) bgneal@442: continue; bgneal@442: bgneal@442: // Get list of all parent nodes until we find a valid parent to stick the child into bgneal@442: parents = [node]; bgneal@442: for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && !nonSplitableElements[parent.name]; parent = parent.parent) bgneal@442: parents.push(parent); bgneal@442: bgneal@442: // Found a suitable parent bgneal@442: if (parent && parents.length > 1) { bgneal@442: // Reverse the array since it makes looping easier bgneal@442: parents.reverse(); bgneal@442: bgneal@442: // Clone the related parent and insert that after the moved node bgneal@442: newParent = currentNode = self.filterNode(parents[0].clone()); bgneal@442: bgneal@442: // Start cloning and moving children on the left side of the target node bgneal@442: for (i = 0; i < parents.length - 1; i++) { bgneal@442: if (schema.isValidChild(currentNode.name, parents[i].name)) { bgneal@442: tempNode = self.filterNode(parents[i].clone()); bgneal@442: currentNode.append(tempNode); bgneal@442: } else bgneal@442: tempNode = currentNode; bgneal@442: bgneal@442: for (childNode = parents[i].firstChild; childNode && childNode != parents[i + 1]; ) { bgneal@442: nextNode = childNode.next; bgneal@442: tempNode.append(childNode); bgneal@442: childNode = nextNode; bgneal@442: } bgneal@442: bgneal@442: currentNode = tempNode; bgneal@442: } bgneal@442: bgneal@442: if (!newParent.isEmpty(nonEmptyElements)) { bgneal@442: parent.insert(newParent, parents[0], true); bgneal@442: parent.insert(node, newParent); bgneal@442: } else { bgneal@442: parent.insert(node, parents[0], true); bgneal@442: } bgneal@442: bgneal@442: // Check if the element is empty by looking through it's contents and special treatment for


    bgneal@442: parent = parents[0]; bgneal@442: if (parent.isEmpty(nonEmptyElements) || parent.firstChild === parent.lastChild && parent.firstChild.name === 'br') { bgneal@442: parent.empty().remove(); bgneal@442: } bgneal@442: } else if (node.parent) { bgneal@442: // If it's an LI try to find a UL/OL for it or wrap it bgneal@442: if (node.name === 'li') { bgneal@442: sibling = node.prev; bgneal@442: if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) { bgneal@442: sibling.append(node); bgneal@442: continue; bgneal@442: } bgneal@442: bgneal@442: sibling = node.next; bgneal@442: if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) { bgneal@442: sibling.insert(node, sibling.firstChild, true); bgneal@442: continue; bgneal@442: } bgneal@442: bgneal@442: node.wrap(self.filterNode(new Node('ul', 1))); bgneal@442: continue; bgneal@442: } bgneal@442: bgneal@442: // Try wrapping the element in a DIV bgneal@442: if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) { bgneal@442: node.wrap(self.filterNode(new Node('div', 1))); bgneal@442: } else { bgneal@442: // We failed wrapping it, then remove or unwrap it bgneal@442: if (node.name === 'style' || node.name === 'script') bgneal@442: node.empty().remove(); bgneal@442: else bgneal@442: node.unwrap(); bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: }; bgneal@442: bgneal@442: self.filterNode = function(node) { bgneal@442: var i, name, list; bgneal@442: bgneal@442: // Run element filters bgneal@442: if (name in nodeFilters) { bgneal@442: list = matchedNodes[name]; bgneal@442: bgneal@442: if (list) bgneal@442: list.push(node); bgneal@442: else bgneal@442: matchedNodes[name] = [node]; bgneal@442: } bgneal@442: bgneal@442: // Run attribute filters bgneal@442: i = attributeFilters.length; bgneal@442: while (i--) { bgneal@442: name = attributeFilters[i].name; bgneal@442: bgneal@442: if (name in node.attributes.map) { bgneal@442: list = matchedAttributes[name]; bgneal@442: bgneal@442: if (list) bgneal@442: list.push(node); bgneal@442: else bgneal@442: matchedAttributes[name] = [node]; bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: return node; bgneal@442: }; bgneal@442: bgneal@442: self.addNodeFilter = function(name, callback) { bgneal@442: tinymce.each(tinymce.explode(name), function(name) { bgneal@442: var list = nodeFilters[name]; bgneal@442: bgneal@442: if (!list) bgneal@442: nodeFilters[name] = list = []; bgneal@442: bgneal@442: list.push(callback); bgneal@442: }); bgneal@442: }; bgneal@442: bgneal@442: self.addAttributeFilter = function(name, callback) { bgneal@442: tinymce.each(tinymce.explode(name), function(name) { bgneal@442: var i; bgneal@442: bgneal@442: for (i = 0; i < attributeFilters.length; i++) { bgneal@442: if (attributeFilters[i].name === name) { bgneal@442: attributeFilters[i].callbacks.push(callback); bgneal@442: return; bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: attributeFilters.push({name: name, callbacks: [callback]}); bgneal@442: }); bgneal@442: }; bgneal@442: bgneal@442: self.parse = function(html, args) { bgneal@442: var parser, rootNode, node, nodes, i, l, fi, fl, list, name, validate, bgneal@442: blockElements, startWhiteSpaceRegExp, invalidChildren = [], bgneal@442: endWhiteSpaceRegExp, allWhiteSpaceRegExp, whiteSpaceElements, children, nonEmptyElements; bgneal@442: bgneal@442: args = args || {}; bgneal@442: matchedNodes = {}; bgneal@442: matchedAttributes = {}; bgneal@442: blockElements = tinymce.extend(tinymce.makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements()); bgneal@442: nonEmptyElements = schema.getNonEmptyElements(); bgneal@442: children = schema.children; bgneal@442: validate = settings.validate; bgneal@442: bgneal@442: whiteSpaceElements = schema.getWhiteSpaceElements(); bgneal@442: startWhiteSpaceRegExp = /^[ \t\r\n]+/; bgneal@442: endWhiteSpaceRegExp = /[ \t\r\n]+$/; bgneal@442: allWhiteSpaceRegExp = /[ \t\r\n]+/g; bgneal@442: bgneal@442: function createNode(name, type) { bgneal@442: var node = new Node(name, type), list; bgneal@442: bgneal@442: if (name in nodeFilters) { bgneal@442: list = matchedNodes[name]; bgneal@442: bgneal@442: if (list) bgneal@442: list.push(node); bgneal@442: else bgneal@442: matchedNodes[name] = [node]; bgneal@442: } bgneal@442: bgneal@442: return node; bgneal@442: }; bgneal@442: bgneal@442: function removeWhitespaceBefore(node) { bgneal@442: var textNode, textVal, sibling; bgneal@442: bgneal@442: for (textNode = node.prev; textNode && textNode.type === 3; ) { bgneal@442: textVal = textNode.value.replace(endWhiteSpaceRegExp, ''); bgneal@442: bgneal@442: if (textVal.length > 0) { bgneal@442: textNode.value = textVal; bgneal@442: textNode = textNode.prev; bgneal@442: } else { bgneal@442: sibling = textNode.prev; bgneal@442: textNode.remove(); bgneal@442: textNode = sibling; bgneal@442: } bgneal@442: } bgneal@442: }; bgneal@442: bgneal@442: parser = new tinymce.html.SaxParser({ bgneal@442: validate : validate, bgneal@442: fix_self_closing : !validate, // Let the DOM parser handle
  • in
  • or

    in

    for better results bgneal@442: bgneal@442: cdata: function(text) { bgneal@442: node.append(createNode('#cdata', 4)).value = text; bgneal@442: }, bgneal@442: bgneal@442: text: function(text, raw) { bgneal@442: var textNode; bgneal@442: bgneal@442: // Trim all redundant whitespace on non white space elements bgneal@442: if (!whiteSpaceElements[node.name]) { bgneal@442: text = text.replace(allWhiteSpaceRegExp, ' '); bgneal@442: bgneal@442: if (node.lastChild && blockElements[node.lastChild.name]) bgneal@442: text = text.replace(startWhiteSpaceRegExp, ''); bgneal@442: } bgneal@442: bgneal@442: // Do we need to create the node bgneal@442: if (text.length !== 0) { bgneal@442: textNode = createNode('#text', 3); bgneal@442: textNode.raw = !!raw; bgneal@442: node.append(textNode).value = text; bgneal@442: } bgneal@442: }, bgneal@442: bgneal@442: comment: function(text) { bgneal@442: node.append(createNode('#comment', 8)).value = text; bgneal@442: }, bgneal@442: bgneal@442: pi: function(name, text) { bgneal@442: node.append(createNode(name, 7)).value = text; bgneal@442: removeWhitespaceBefore(node); bgneal@442: }, bgneal@442: bgneal@442: doctype: function(text) { bgneal@442: var newNode; bgneal@442: bgneal@442: newNode = node.append(createNode('#doctype', 10)); bgneal@442: newNode.value = text; bgneal@442: removeWhitespaceBefore(node); bgneal@442: }, bgneal@442: bgneal@442: start: function(name, attrs, empty) { bgneal@442: var newNode, attrFiltersLen, elementRule, textNode, attrName, text, sibling, parent; bgneal@442: bgneal@442: elementRule = validate ? schema.getElementRule(name) : {}; bgneal@442: if (elementRule) { bgneal@442: newNode = createNode(elementRule.outputName || name, 1); bgneal@442: newNode.attributes = attrs; bgneal@442: newNode.shortEnded = empty; bgneal@442: bgneal@442: node.append(newNode); bgneal@442: bgneal@442: // Check if node is valid child of the parent node is the child is bgneal@442: // unknown we don't collect it since it's probably a custom element bgneal@442: parent = children[node.name]; bgneal@442: if (parent && children[newNode.name] && !parent[newNode.name]) bgneal@442: invalidChildren.push(newNode); bgneal@442: bgneal@442: attrFiltersLen = attributeFilters.length; bgneal@442: while (attrFiltersLen--) { bgneal@442: attrName = attributeFilters[attrFiltersLen].name; bgneal@442: bgneal@442: if (attrName in attrs.map) { bgneal@442: list = matchedAttributes[attrName]; bgneal@442: bgneal@442: if (list) bgneal@442: list.push(newNode); bgneal@442: else bgneal@442: matchedAttributes[attrName] = [newNode]; bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: // Trim whitespace before block bgneal@442: if (blockElements[name]) bgneal@442: removeWhitespaceBefore(newNode); bgneal@442: bgneal@442: // Change current node if the element wasn't empty i.e not
    or bgneal@442: if (!empty) bgneal@442: node = newNode; bgneal@442: } bgneal@442: }, bgneal@442: bgneal@442: end: function(name) { bgneal@442: var textNode, elementRule, text, sibling, tempNode; bgneal@442: bgneal@442: elementRule = validate ? schema.getElementRule(name) : {}; bgneal@442: if (elementRule) { bgneal@442: if (blockElements[name]) { bgneal@442: if (!whiteSpaceElements[node.name]) { bgneal@442: // Trim whitespace at beginning of block bgneal@442: for (textNode = node.firstChild; textNode && textNode.type === 3; ) { bgneal@442: text = textNode.value.replace(startWhiteSpaceRegExp, ''); bgneal@442: bgneal@442: if (text.length > 0) { bgneal@442: textNode.value = text; bgneal@442: textNode = textNode.next; bgneal@442: } else { bgneal@442: sibling = textNode.next; bgneal@442: textNode.remove(); bgneal@442: textNode = sibling; bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: // Trim whitespace at end of block bgneal@442: for (textNode = node.lastChild; textNode && textNode.type === 3; ) { bgneal@442: text = textNode.value.replace(endWhiteSpaceRegExp, ''); bgneal@442: bgneal@442: if (text.length > 0) { bgneal@442: textNode.value = text; bgneal@442: textNode = textNode.prev; bgneal@442: } else { bgneal@442: sibling = textNode.prev; bgneal@442: textNode.remove(); bgneal@442: textNode = sibling; bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: // Trim start white space bgneal@442: textNode = node.prev; bgneal@442: if (textNode && textNode.type === 3) { bgneal@442: text = textNode.value.replace(startWhiteSpaceRegExp, ''); bgneal@442: bgneal@442: if (text.length > 0) bgneal@442: textNode.value = text; bgneal@442: else bgneal@442: textNode.remove(); bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: // Handle empty nodes bgneal@442: if (elementRule.removeEmpty || elementRule.paddEmpty) { bgneal@442: if (node.isEmpty(nonEmptyElements)) { bgneal@442: if (elementRule.paddEmpty) bgneal@442: node.empty().append(new Node('#text', '3')).value = '\u00a0'; bgneal@442: else { bgneal@442: // Leave nodes that have a name like bgneal@442: if (!node.attributes.map.name) { bgneal@442: tempNode = node.parent; bgneal@442: node.empty().remove(); bgneal@442: node = tempNode; bgneal@442: return; bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: node = node.parent; bgneal@442: } bgneal@442: } bgneal@442: }, schema); bgneal@442: bgneal@442: rootNode = node = new Node(settings.root_name, 11); bgneal@442: bgneal@442: parser.parse(html); bgneal@442: bgneal@442: if (validate) bgneal@442: fixInvalidChildren(invalidChildren); bgneal@442: bgneal@442: // Run node filters bgneal@442: for (name in matchedNodes) { bgneal@442: list = nodeFilters[name]; bgneal@442: nodes = matchedNodes[name]; bgneal@442: bgneal@442: // Remove already removed children bgneal@442: fi = nodes.length; bgneal@442: while (fi--) { bgneal@442: if (!nodes[fi].parent) bgneal@442: nodes.splice(fi, 1); bgneal@442: } bgneal@442: bgneal@442: for (i = 0, l = list.length; i < l; i++) bgneal@442: list[i](nodes, name, args); bgneal@442: } bgneal@442: bgneal@442: // Run attribute filters bgneal@442: for (i = 0, l = attributeFilters.length; i < l; i++) { bgneal@442: list = attributeFilters[i]; bgneal@442: bgneal@442: if (list.name in matchedAttributes) { bgneal@442: nodes = matchedAttributes[list.name]; bgneal@442: bgneal@442: // Remove already removed children bgneal@442: fi = nodes.length; bgneal@442: while (fi--) { bgneal@442: if (!nodes[fi].parent) bgneal@442: nodes.splice(fi, 1); bgneal@442: } bgneal@442: bgneal@442: for (fi = 0, fl = list.callbacks.length; fi < fl; fi++) bgneal@442: list.callbacks[fi](nodes, list.name, args); bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: return rootNode; bgneal@442: }; bgneal@442: bgneal@442: // Remove
    at end of block elements Gecko and WebKit injects BR elements to bgneal@442: // make it possible to place the caret inside empty blocks. This logic tries to remove bgneal@442: // these elements and keep br elements that where intended to be there intact bgneal@442: if (settings.remove_trailing_brs) { bgneal@442: self.addNodeFilter('br', function(nodes, name) { bgneal@442: var i, l = nodes.length, node, blockElements = schema.getBlockElements(), bgneal@442: nonEmptyElements = schema.getNonEmptyElements(), parent, prev, prevName; bgneal@442: bgneal@442: // Must loop forwards since it will otherwise remove all brs in

    a


    bgneal@442: for (i = 0; i < l; i++) { bgneal@442: node = nodes[i]; bgneal@442: parent = node.parent; bgneal@442: bgneal@442: if (blockElements[node.parent.name] && node === parent.lastChild) { bgneal@442: // Loop all nodes to the right of the current node and check for other BR elements bgneal@442: // excluding bookmarks since they are invisible bgneal@442: prev = node.prev; bgneal@442: while (prev) { bgneal@442: prevName = prev.name; bgneal@442: bgneal@442: // Ignore bookmarks bgneal@442: if (prevName !== "span" || prev.attr('data-mce-type') !== 'bookmark') { bgneal@442: // Found a non BR element bgneal@442: if (prevName !== "br") bgneal@442: break; bgneal@442: bgneal@442: // Found another br it's a

    structure then don't remove anything bgneal@442: if (prevName === 'br') { bgneal@442: node = null; bgneal@442: break; bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: prev = prev.prev; bgneal@442: } bgneal@442: bgneal@442: if (node) { bgneal@442: node.remove(); bgneal@442: bgneal@442: // Is the parent to be considered empty after we removed the BR bgneal@442: if (parent.isEmpty(nonEmptyElements)) { bgneal@442: elementRule = schema.getElementRule(parent.name); bgneal@442: bgneal@442: // Remove or padd the element depending on schema rule bgneal@442: if (elementRule.removeEmpty) bgneal@442: parent.remove(); bgneal@442: else if (elementRule.paddEmpty) bgneal@442: parent.empty().append(new tinymce.html.Node('#text', 3)).value = '\u00a0'; bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: }); bgneal@442: } bgneal@442: } bgneal@442: })(tinymce); bgneal@442: bgneal@442: tinymce.html.Writer = function(settings) { bgneal@442: var html = [], indent, indentBefore, indentAfter, encode, htmlOutput; bgneal@442: bgneal@442: settings = settings || {}; bgneal@442: indent = settings.indent; bgneal@442: indentBefore = tinymce.makeMap(settings.indent_before || ''); bgneal@442: indentAfter = tinymce.makeMap(settings.indent_after || ''); bgneal@442: encode = tinymce.html.Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities); bgneal@442: htmlOutput = settings.element_format == "html"; bgneal@442: bgneal@442: return { bgneal@442: start: function(name, attrs, empty) { bgneal@442: var i, l, attr, value; bgneal@442: bgneal@442: if (indent && indentBefore[name] && html.length > 0) { bgneal@442: value = html[html.length - 1]; bgneal@442: bgneal@442: if (value.length > 0 && value !== '\n') bgneal@442: html.push('\n'); bgneal@442: } bgneal@442: bgneal@442: html.push('<', name); bgneal@442: bgneal@442: if (attrs) { bgneal@442: for (i = 0, l = attrs.length; i < l; i++) { bgneal@442: attr = attrs[i]; bgneal@442: html.push(' ', attr.name, '="', encode(attr.value, true), '"'); bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: if (!empty || htmlOutput) bgneal@442: html[html.length] = '>'; bgneal@442: else bgneal@442: html[html.length] = ' />'; bgneal@442: bgneal@442: if (empty && indent && indentAfter[name] && html.length > 0) { bgneal@442: value = html[html.length - 1]; bgneal@442: bgneal@442: if (value.length > 0 && value !== '\n') bgneal@442: html.push('\n'); bgneal@442: } bgneal@442: }, bgneal@442: bgneal@442: end: function(name) { bgneal@442: var value; bgneal@442: bgneal@442: /*if (indent && indentBefore[name] && html.length > 0) { bgneal@442: value = html[html.length - 1]; bgneal@442: bgneal@442: if (value.length > 0 && value !== '\n') bgneal@442: html.push('\n'); bgneal@442: }*/ bgneal@442: bgneal@442: html.push(''); bgneal@442: bgneal@442: if (indent && indentAfter[name] && html.length > 0) { bgneal@442: value = html[html.length - 1]; bgneal@442: bgneal@442: if (value.length > 0 && value !== '\n') bgneal@442: html.push('\n'); bgneal@442: } bgneal@442: }, bgneal@442: bgneal@442: text: function(text, raw) { bgneal@442: if (text.length > 0) bgneal@442: html[html.length] = raw ? text : encode(text); bgneal@442: }, bgneal@442: bgneal@442: cdata: function(text) { bgneal@442: html.push(''); bgneal@442: }, bgneal@442: bgneal@442: comment: function(text) { bgneal@442: html.push(''); bgneal@442: }, bgneal@442: bgneal@442: pi: function(name, text) { bgneal@442: if (text) bgneal@442: html.push(''); bgneal@442: else bgneal@442: html.push(''); bgneal@442: bgneal@442: if (indent) bgneal@442: html.push('\n'); bgneal@442: }, bgneal@442: bgneal@442: doctype: function(text) { bgneal@442: html.push('', indent ? '\n' : ''); bgneal@442: }, bgneal@442: bgneal@442: reset: function() { bgneal@442: html.length = 0; bgneal@442: }, bgneal@442: bgneal@442: getContent: function() { bgneal@442: return html.join('').replace(/\n$/, ''); bgneal@442: } bgneal@442: }; bgneal@442: }; bgneal@442: bgneal@442: (function(tinymce) { bgneal@442: tinymce.html.Serializer = function(settings, schema) { bgneal@442: var self = this, writer = new tinymce.html.Writer(settings); bgneal@442: bgneal@442: settings = settings || {}; bgneal@442: settings.validate = "validate" in settings ? settings.validate : true; bgneal@442: bgneal@442: self.schema = schema = schema || new tinymce.html.Schema(); bgneal@442: self.writer = writer; bgneal@442: bgneal@442: self.serialize = function(node) { bgneal@442: var handlers, validate; bgneal@442: bgneal@442: validate = settings.validate; bgneal@442: bgneal@442: handlers = { bgneal@442: // #text bgneal@442: 3: function(node, raw) { bgneal@442: writer.text(node.value, node.raw); bgneal@442: }, bgneal@442: bgneal@442: // #comment bgneal@442: 8: function(node) { bgneal@442: writer.comment(node.value); bgneal@442: }, bgneal@442: bgneal@442: // Processing instruction bgneal@442: 7: function(node) { bgneal@442: writer.pi(node.name, node.value); bgneal@442: }, bgneal@442: bgneal@442: // Doctype bgneal@442: 10: function(node) { bgneal@442: writer.doctype(node.value); bgneal@442: }, bgneal@442: bgneal@442: // CDATA bgneal@442: 4: function(node) { bgneal@442: writer.cdata(node.value); bgneal@442: }, bgneal@442: bgneal@442: // Document fragment bgneal@442: 11: function(node) { bgneal@442: if ((node = node.firstChild)) { bgneal@442: do { bgneal@442: walk(node); bgneal@442: } while (node = node.next); bgneal@442: } bgneal@442: } bgneal@442: }; bgneal@442: bgneal@442: writer.reset(); bgneal@442: bgneal@442: function walk(node) { bgneal@442: var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule; bgneal@442: bgneal@442: if (!handler) { bgneal@442: name = node.name; bgneal@442: isEmpty = node.shortEnded; bgneal@442: attrs = node.attributes; bgneal@442: bgneal@442: // Sort attributes bgneal@442: if (validate && attrs && attrs.length > 1) { bgneal@442: sortedAttrs = []; bgneal@442: sortedAttrs.map = {}; bgneal@442: bgneal@442: elementRule = schema.getElementRule(node.name); bgneal@442: for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) { bgneal@442: attrName = elementRule.attributesOrder[i]; bgneal@442: bgneal@442: if (attrName in attrs.map) { bgneal@442: attrValue = attrs.map[attrName]; bgneal@442: sortedAttrs.map[attrName] = attrValue; bgneal@442: sortedAttrs.push({name: attrName, value: attrValue}); bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: for (i = 0, l = attrs.length; i < l; i++) { bgneal@442: attrName = attrs[i].name; bgneal@442: bgneal@442: if (!(attrName in sortedAttrs.map)) { bgneal@442: attrValue = attrs.map[attrName]; bgneal@442: sortedAttrs.map[attrName] = attrValue; bgneal@442: sortedAttrs.push({name: attrName, value: attrValue}); bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: attrs = sortedAttrs; bgneal@442: } bgneal@442: bgneal@442: writer.start(node.name, attrs, isEmpty); bgneal@442: bgneal@442: if (!isEmpty) { bgneal@442: if ((node = node.firstChild)) { bgneal@442: do { bgneal@442: walk(node); bgneal@442: } while (node = node.next); bgneal@442: } bgneal@442: bgneal@442: writer.end(name); bgneal@442: } bgneal@442: } else bgneal@442: handler(node); bgneal@442: } bgneal@442: bgneal@442: // Serialize element and treat all non elements as fragments bgneal@442: if (node.type == 1 && !settings.inner) bgneal@442: walk(node); bgneal@442: else bgneal@442: handlers[11](node); bgneal@442: bgneal@442: return writer.getContent(); bgneal@442: }; bgneal@442: } bgneal@442: })(tinymce); bgneal@442: bgneal@442: (function(tinymce) { bgneal@312: // Shorten names bgneal@312: var each = tinymce.each, bgneal@312: is = tinymce.is, bgneal@312: isWebKit = tinymce.isWebKit, bgneal@312: isIE = tinymce.isIE, bgneal@442: Entities = tinymce.html.Entities, bgneal@312: simpleSelectorRe = /^([a-z0-9],?)+$/i, bgneal@442: blockElementsMap = tinymce.html.Schema.blockElementsMap, bgneal@442: whiteSpaceRegExp = /^[ \t\r\n]*$/; bgneal@312: bgneal@312: tinymce.create('tinymce.dom.DOMUtils', { bgneal@312: doc : null, bgneal@312: root : null, bgneal@312: files : null, bgneal@312: pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/, bgneal@312: props : { bgneal@312: "for" : "htmlFor", bgneal@312: "class" : "className", bgneal@312: className : "className", bgneal@312: checked : "checked", bgneal@312: disabled : "disabled", bgneal@312: maxlength : "maxLength", bgneal@312: readonly : "readOnly", bgneal@312: selected : "selected", bgneal@312: value : "value", bgneal@312: id : "id", bgneal@312: name : "name", bgneal@312: type : "type" bgneal@312: }, bgneal@312: bgneal@312: DOMUtils : function(d, s) { bgneal@312: var t = this, globalStyle; bgneal@312: bgneal@312: t.doc = d; bgneal@312: t.win = window; bgneal@312: t.files = {}; bgneal@312: t.cssFlicker = false; bgneal@312: t.counter = 0; bgneal@442: t.stdMode = !tinymce.isIE || d.documentMode >= 8; bgneal@442: t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode; bgneal@442: t.hasOuterHTML = "outerHTML" in d.createElement("a"); bgneal@312: bgneal@312: t.settings = s = tinymce.extend({ bgneal@312: keep_values : false, bgneal@442: hex_colors : 1 bgneal@312: }, s); bgneal@442: bgneal@442: t.schema = s.schema; bgneal@442: t.styles = new tinymce.html.Styles({ bgneal@442: url_converter : s.url_converter, bgneal@442: url_converter_scope : s.url_converter_scope bgneal@442: }, s.schema); bgneal@312: bgneal@312: // Fix IE6SP2 flicker and check it failed for pre SP2 bgneal@312: if (tinymce.isIE6) { bgneal@312: try { bgneal@312: d.execCommand('BackgroundImageCache', false, true); bgneal@312: } catch (e) { bgneal@312: t.cssFlicker = true; bgneal@312: } bgneal@312: } bgneal@312: bgneal@442: if (isIE) { bgneal@442: // Add missing HTML 4/5 elements to IE bgneal@442: ('abbr article aside audio canvas ' + bgneal@442: 'details figcaption figure footer ' + bgneal@442: 'header hgroup mark menu meter nav ' + bgneal@442: 'output progress section summary ' + bgneal@442: 'time video').replace(/\w+/g, function(name) { bgneal@442: d.createElement(name); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: tinymce.addUnload(t.destroy, t); bgneal@312: }, bgneal@312: bgneal@312: getRoot : function() { bgneal@312: var t = this, s = t.settings; bgneal@312: bgneal@312: return (s && t.get(s.root_element)) || t.doc.body; bgneal@312: }, bgneal@312: bgneal@312: getViewPort : function(w) { bgneal@312: var d, b; bgneal@312: bgneal@312: w = !w ? this.win : w; bgneal@312: d = w.document; bgneal@312: b = this.boxModel ? d.documentElement : d.body; bgneal@312: bgneal@312: // Returns viewport size excluding scrollbars bgneal@312: return { bgneal@312: x : w.pageXOffset || b.scrollLeft, bgneal@312: y : w.pageYOffset || b.scrollTop, bgneal@312: w : w.innerWidth || b.clientWidth, bgneal@312: h : w.innerHeight || b.clientHeight bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: getRect : function(e) { bgneal@312: var p, t = this, sr; bgneal@312: bgneal@312: e = t.get(e); bgneal@312: p = t.getPos(e); bgneal@312: sr = t.getSize(e); bgneal@312: bgneal@312: return { bgneal@312: x : p.x, bgneal@312: y : p.y, bgneal@312: w : sr.w, bgneal@312: h : sr.h bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: getSize : function(e) { bgneal@312: var t = this, w, h; bgneal@312: bgneal@312: e = t.get(e); bgneal@312: w = t.getStyle(e, 'width'); bgneal@312: h = t.getStyle(e, 'height'); bgneal@312: bgneal@312: // Non pixel value, then force offset/clientWidth bgneal@312: if (w.indexOf('px') === -1) bgneal@312: w = 0; bgneal@312: bgneal@312: // Non pixel value, then force offset/clientWidth bgneal@312: if (h.indexOf('px') === -1) bgneal@312: h = 0; bgneal@312: bgneal@312: return { bgneal@312: w : parseInt(w) || e.offsetWidth || e.clientWidth, bgneal@312: h : parseInt(h) || e.offsetHeight || e.clientHeight bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: getParent : function(n, f, r) { bgneal@312: return this.getParents(n, f, r, false); bgneal@312: }, bgneal@312: bgneal@312: getParents : function(n, f, r, c) { bgneal@312: var t = this, na, se = t.settings, o = []; bgneal@312: bgneal@312: n = t.get(n); bgneal@312: c = c === undefined; bgneal@312: bgneal@312: if (se.strict_root) bgneal@312: r = r || t.getRoot(); bgneal@312: bgneal@312: // Wrap node name as func bgneal@312: if (is(f, 'string')) { bgneal@312: na = f; bgneal@312: bgneal@312: if (f === '*') { bgneal@312: f = function(n) {return n.nodeType == 1;}; bgneal@312: } else { bgneal@312: f = function(n) { bgneal@312: return t.is(n, na); bgneal@312: }; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: while (n) { bgneal@312: if (n == r || !n.nodeType || n.nodeType === 9) bgneal@312: break; bgneal@312: bgneal@312: if (!f || f(n)) { bgneal@312: if (c) bgneal@312: o.push(n); bgneal@312: else bgneal@312: return n; bgneal@312: } bgneal@312: bgneal@312: n = n.parentNode; bgneal@312: } bgneal@312: bgneal@312: return c ? o : null; bgneal@312: }, bgneal@312: bgneal@312: get : function(e) { bgneal@312: var n; bgneal@312: bgneal@312: if (e && this.doc && typeof(e) == 'string') { bgneal@312: n = e; bgneal@312: e = this.doc.getElementById(e); bgneal@312: bgneal@312: // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick bgneal@312: if (e && e.id !== n) bgneal@312: return this.doc.getElementsByName(n)[1]; bgneal@312: } bgneal@312: bgneal@312: return e; bgneal@312: }, bgneal@312: bgneal@312: getNext : function(node, selector) { bgneal@312: return this._findSib(node, selector, 'nextSibling'); bgneal@312: }, bgneal@312: bgneal@312: getPrev : function(node, selector) { bgneal@312: return this._findSib(node, selector, 'previousSibling'); bgneal@312: }, bgneal@312: bgneal@312: bgneal@312: select : function(pa, s) { bgneal@312: var t = this; bgneal@312: bgneal@312: return tinymce.dom.Sizzle(pa, t.get(s) || t.get(t.settings.root_element) || t.doc, []); bgneal@312: }, bgneal@312: bgneal@312: is : function(n, selector) { bgneal@312: var i; bgneal@312: bgneal@312: // If it isn't an array then try to do some simple selectors instead of Sizzle for to boost performance bgneal@312: if (n.length === undefined) { bgneal@312: // Simple all selector bgneal@312: if (selector === '*') bgneal@312: return n.nodeType == 1; bgneal@312: bgneal@312: // Simple selector just elements bgneal@312: if (simpleSelectorRe.test(selector)) { bgneal@312: selector = selector.toLowerCase().split(/,/); bgneal@312: n = n.nodeName.toLowerCase(); bgneal@312: bgneal@312: for (i = selector.length - 1; i >= 0; i--) { bgneal@312: if (selector[i] == n) bgneal@312: return true; bgneal@312: } bgneal@312: bgneal@312: return false; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return tinymce.dom.Sizzle.matches(selector, n.nodeType ? [n] : n).length > 0; bgneal@312: }, bgneal@312: bgneal@312: bgneal@312: add : function(p, n, a, h, c) { bgneal@312: var t = this; bgneal@312: bgneal@312: return this.run(p, function(p) { bgneal@312: var e, k; bgneal@312: bgneal@312: e = is(n, 'string') ? t.doc.createElement(n) : n; bgneal@312: t.setAttribs(e, a); bgneal@312: bgneal@312: if (h) { bgneal@312: if (h.nodeType) bgneal@312: e.appendChild(h); bgneal@312: else bgneal@312: t.setHTML(e, h); bgneal@312: } bgneal@312: bgneal@312: return !c ? p.appendChild(e) : e; bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: create : function(n, a, h) { bgneal@312: return this.add(this.doc.createElement(n), n, a, h, 1); bgneal@312: }, bgneal@312: bgneal@312: createHTML : function(n, a, h) { bgneal@312: var o = '', t = this, k; bgneal@312: bgneal@312: o += '<' + n; bgneal@312: bgneal@312: for (k in a) { bgneal@312: if (a.hasOwnProperty(k)) bgneal@312: o += ' ' + k + '="' + t.encode(a[k]) + '"'; bgneal@312: } bgneal@312: bgneal@442: // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime bgneal@442: if (typeof(h) != "undefined") bgneal@312: return o + '>' + h + ''; bgneal@312: bgneal@312: return o + ' />'; bgneal@312: }, bgneal@312: bgneal@312: remove : function(node, keep_children) { bgneal@312: return this.run(node, function(node) { bgneal@442: var child, parent = node.parentNode; bgneal@312: bgneal@312: if (!parent) bgneal@312: return null; bgneal@312: bgneal@312: if (keep_children) { bgneal@312: while (child = node.firstChild) { bgneal@312: // IE 8 will crash if you don't remove completely empty text nodes bgneal@312: if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue) bgneal@312: parent.insertBefore(child, node); bgneal@312: else bgneal@312: node.removeChild(child); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return parent.removeChild(node); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: setStyle : function(n, na, v) { bgneal@312: var t = this; bgneal@312: bgneal@312: return t.run(n, function(e) { bgneal@312: var s, i; bgneal@312: bgneal@312: s = e.style; bgneal@312: bgneal@312: // Camelcase it, if needed bgneal@312: na = na.replace(/-(\D)/g, function(a, b){ bgneal@312: return b.toUpperCase(); bgneal@312: }); bgneal@312: bgneal@312: // Default px suffix on these bgneal@312: if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v))) bgneal@312: v += 'px'; bgneal@312: bgneal@312: switch (na) { bgneal@312: case 'opacity': bgneal@312: // IE specific opacity bgneal@312: if (isIE) { bgneal@312: s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")"; bgneal@312: bgneal@312: if (!n.currentStyle || !n.currentStyle.hasLayout) bgneal@312: s.display = 'inline-block'; bgneal@312: } bgneal@312: bgneal@312: // Fix for older browsers bgneal@312: s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || ''; bgneal@312: break; bgneal@312: bgneal@312: case 'float': bgneal@312: isIE ? s.styleFloat = v : s.cssFloat = v; bgneal@312: break; bgneal@312: bgneal@312: default: bgneal@312: s[na] = v || ''; bgneal@312: } bgneal@312: bgneal@312: // Force update of the style data bgneal@312: if (t.settings.update_styles) bgneal@442: t.setAttrib(e, 'data-mce-style'); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: getStyle : function(n, na, c) { bgneal@312: n = this.get(n); bgneal@312: bgneal@312: if (!n) bgneal@442: return; bgneal@312: bgneal@312: // Gecko bgneal@312: if (this.doc.defaultView && c) { bgneal@312: // Remove camelcase bgneal@312: na = na.replace(/[A-Z]/g, function(a){ bgneal@312: return '-' + a; bgneal@312: }); bgneal@312: bgneal@312: try { bgneal@312: return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na); bgneal@312: } catch (ex) { bgneal@312: // Old safari might fail bgneal@312: return null; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Camelcase it, if needed bgneal@312: na = na.replace(/-(\D)/g, function(a, b){ bgneal@312: return b.toUpperCase(); bgneal@312: }); bgneal@312: bgneal@312: if (na == 'float') bgneal@312: na = isIE ? 'styleFloat' : 'cssFloat'; bgneal@312: bgneal@312: // IE & Opera bgneal@312: if (n.currentStyle && c) bgneal@312: return n.currentStyle[na]; bgneal@312: bgneal@442: return n.style ? n.style[na] : undefined; bgneal@312: }, bgneal@312: bgneal@312: setStyles : function(e, o) { bgneal@312: var t = this, s = t.settings, ol; bgneal@312: bgneal@312: ol = s.update_styles; bgneal@312: s.update_styles = 0; bgneal@312: bgneal@312: each(o, function(v, n) { bgneal@312: t.setStyle(e, n, v); bgneal@312: }); bgneal@312: bgneal@312: // Update style info bgneal@312: s.update_styles = ol; bgneal@312: if (s.update_styles) bgneal@312: t.setAttrib(e, s.cssText); bgneal@312: }, bgneal@312: bgneal@442: removeAllAttribs: function(e) { bgneal@442: return this.run(e, function(e) { bgneal@442: var i, attrs = e.attributes; bgneal@442: for (i = attrs.length - 1; i >= 0; i--) { bgneal@442: e.removeAttributeNode(attrs.item(i)); bgneal@442: } bgneal@442: }); bgneal@442: }, bgneal@442: bgneal@312: setAttrib : function(e, n, v) { bgneal@312: var t = this; bgneal@312: bgneal@312: // Whats the point bgneal@312: if (!e || !n) bgneal@312: return; bgneal@312: bgneal@312: // Strict XML mode bgneal@312: if (t.settings.strict) bgneal@312: n = n.toLowerCase(); bgneal@312: bgneal@312: return this.run(e, function(e) { bgneal@312: var s = t.settings; bgneal@312: bgneal@312: switch (n) { bgneal@312: case "style": bgneal@312: if (!is(v, 'string')) { bgneal@312: each(v, function(v, n) { bgneal@312: t.setStyle(e, n, v); bgneal@312: }); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // No mce_style for elements with these since they might get resized by the user bgneal@312: if (s.keep_values) { bgneal@312: if (v && !t._isRes(v)) bgneal@442: e.setAttribute('data-mce-style', v, 2); bgneal@312: else bgneal@442: e.removeAttribute('data-mce-style', 2); bgneal@312: } bgneal@312: bgneal@312: e.style.cssText = v; bgneal@312: break; bgneal@312: bgneal@312: case "class": bgneal@312: e.className = v || ''; // Fix IE null bug bgneal@312: break; bgneal@312: bgneal@312: case "src": bgneal@312: case "href": bgneal@312: if (s.keep_values) { bgneal@312: if (s.url_converter) bgneal@312: v = s.url_converter.call(s.url_converter_scope || t, v, n, e); bgneal@312: bgneal@442: t.setAttrib(e, 'data-mce-' + n, v, 2); bgneal@312: } bgneal@312: bgneal@312: break; bgneal@442: bgneal@312: case "shape": bgneal@442: e.setAttribute('data-mce-style', v); bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: if (is(v) && v !== null && v.length !== 0) bgneal@312: e.setAttribute(n, '' + v, 2); bgneal@312: else bgneal@312: e.removeAttribute(n, 2); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: setAttribs : function(e, o) { bgneal@312: var t = this; bgneal@312: bgneal@312: return this.run(e, function(e) { bgneal@312: each(o, function(v, n) { bgneal@312: t.setAttrib(e, n, v); bgneal@312: }); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: getAttrib : function(e, n, dv) { bgneal@312: var v, t = this; bgneal@312: bgneal@312: e = t.get(e); bgneal@312: bgneal@312: if (!e || e.nodeType !== 1) bgneal@312: return false; bgneal@312: bgneal@312: if (!is(dv)) bgneal@312: dv = ''; bgneal@312: bgneal@312: // Try the mce variant for these bgneal@312: if (/^(src|href|style|coords|shape)$/.test(n)) { bgneal@442: v = e.getAttribute("data-mce-" + n); bgneal@312: bgneal@312: if (v) bgneal@312: return v; bgneal@312: } bgneal@312: bgneal@312: if (isIE && t.props[n]) { bgneal@312: v = e[t.props[n]]; bgneal@312: v = v && v.nodeValue ? v.nodeValue : v; bgneal@312: } bgneal@312: bgneal@312: if (!v) bgneal@312: v = e.getAttribute(n, 2); bgneal@312: bgneal@312: // Check boolean attribs bgneal@312: if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) { bgneal@312: if (e[t.props[n]] === true && v === '') bgneal@312: return n; bgneal@312: bgneal@312: return v ? n : ''; bgneal@312: } bgneal@312: bgneal@312: // Inner input elements will override attributes on form elements bgneal@312: if (e.nodeName === "FORM" && e.getAttributeNode(n)) bgneal@312: return e.getAttributeNode(n).nodeValue; bgneal@312: bgneal@312: if (n === 'style') { bgneal@312: v = v || e.style.cssText; bgneal@312: bgneal@312: if (v) { bgneal@312: v = t.serializeStyle(t.parseStyle(v), e.nodeName); bgneal@312: bgneal@312: if (t.settings.keep_values && !t._isRes(v)) bgneal@442: e.setAttribute('data-mce-style', v); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Remove Apple and WebKit stuff bgneal@312: if (isWebKit && n === "class" && v) bgneal@312: v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, ''); bgneal@312: bgneal@312: // Handle IE issues bgneal@312: if (isIE) { bgneal@312: switch (n) { bgneal@312: case 'rowspan': bgneal@312: case 'colspan': bgneal@312: // IE returns 1 as default value bgneal@312: if (v === 1) bgneal@312: v = ''; bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case 'size': bgneal@312: // IE returns +0 as default value for size bgneal@312: if (v === '+0' || v === 20 || v === 0) bgneal@312: v = ''; bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case 'width': bgneal@312: case 'height': bgneal@312: case 'vspace': bgneal@312: case 'checked': bgneal@312: case 'disabled': bgneal@312: case 'readonly': bgneal@312: if (v === 0) bgneal@312: v = ''; bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case 'hspace': bgneal@312: // IE returns -1 as default value bgneal@312: if (v === -1) bgneal@312: v = ''; bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case 'maxlength': bgneal@312: case 'tabindex': bgneal@312: // IE returns default value bgneal@312: if (v === 32768 || v === 2147483647 || v === '32768') bgneal@312: v = ''; bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case 'multiple': bgneal@312: case 'compact': bgneal@312: case 'noshade': bgneal@312: case 'nowrap': bgneal@312: if (v === 65535) bgneal@312: return n; bgneal@312: bgneal@312: return dv; bgneal@312: bgneal@312: case 'shape': bgneal@312: v = v.toLowerCase(); bgneal@312: break; bgneal@312: bgneal@312: default: bgneal@312: // IE has odd anonymous function for event attributes bgneal@312: if (n.indexOf('on') === 0 && v) bgneal@442: v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return (v !== undefined && v !== null && v !== '') ? '' + v : dv; bgneal@312: }, bgneal@312: bgneal@312: getPos : function(n, ro) { bgneal@312: var t = this, x = 0, y = 0, e, d = t.doc, r; bgneal@312: bgneal@312: n = t.get(n); bgneal@312: ro = ro || d.body; bgneal@312: bgneal@312: if (n) { bgneal@312: // Use getBoundingClientRect on IE, Opera has it but it's not perfect bgneal@312: if (isIE && !t.stdMode) { bgneal@312: n = n.getBoundingClientRect(); bgneal@312: e = t.boxModel ? d.documentElement : d.body; bgneal@312: x = t.getStyle(t.select('html')[0], 'borderWidth'); // Remove border bgneal@312: x = (x == 'medium' || t.boxModel && !t.isIE6) && 2 || x; bgneal@312: bgneal@312: return {x : n.left + e.scrollLeft - x, y : n.top + e.scrollTop - x}; bgneal@312: } bgneal@312: bgneal@312: r = n; bgneal@312: while (r && r != ro && r.nodeType) { bgneal@312: x += r.offsetLeft || 0; bgneal@312: y += r.offsetTop || 0; bgneal@312: r = r.offsetParent; bgneal@312: } bgneal@312: bgneal@312: r = n.parentNode; bgneal@312: while (r && r != ro && r.nodeType) { bgneal@312: x -= r.scrollLeft || 0; bgneal@312: y -= r.scrollTop || 0; bgneal@312: r = r.parentNode; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return {x : x, y : y}; bgneal@312: }, bgneal@312: bgneal@312: parseStyle : function(st) { bgneal@442: return this.styles.parse(st); bgneal@312: }, bgneal@312: bgneal@312: serializeStyle : function(o, name) { bgneal@442: return this.styles.serialize(o, name); bgneal@312: }, bgneal@312: bgneal@312: loadCSS : function(u) { bgneal@312: var t = this, d = t.doc, head; bgneal@312: bgneal@312: if (!u) bgneal@312: u = ''; bgneal@312: bgneal@312: head = t.select('head')[0]; bgneal@312: bgneal@312: each(u.split(','), function(u) { bgneal@312: var link; bgneal@312: bgneal@312: if (t.files[u]) bgneal@312: return; bgneal@312: bgneal@312: t.files[u] = true; bgneal@312: link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)}); bgneal@312: bgneal@312: // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug bgneal@312: // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading bgneal@312: // It's ugly but it seems to work fine. bgneal@442: if (isIE && d.documentMode && d.recalc) { bgneal@312: link.onload = function() { bgneal@442: if (d.recalc) bgneal@442: d.recalc(); bgneal@442: bgneal@312: link.onload = null; bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: head.appendChild(link); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: addClass : function(e, c) { bgneal@312: return this.run(e, function(e) { bgneal@312: var o; bgneal@312: bgneal@312: if (!c) bgneal@312: return 0; bgneal@312: bgneal@312: if (this.hasClass(e, c)) bgneal@312: return e.className; bgneal@312: bgneal@312: o = this.removeClass(e, c); bgneal@312: bgneal@312: return e.className = (o != '' ? (o + ' ') : '') + c; bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: removeClass : function(e, c) { bgneal@312: var t = this, re; bgneal@312: bgneal@312: return t.run(e, function(e) { bgneal@312: var v; bgneal@312: bgneal@312: if (t.hasClass(e, c)) { bgneal@312: if (!re) bgneal@312: re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g"); bgneal@312: bgneal@312: v = e.className.replace(re, ' '); bgneal@312: v = tinymce.trim(v != ' ' ? v : ''); bgneal@312: bgneal@312: e.className = v; bgneal@312: bgneal@312: // Empty class attr bgneal@312: if (!v) { bgneal@312: e.removeAttribute('class'); bgneal@312: e.removeAttribute('className'); bgneal@312: } bgneal@312: bgneal@312: return v; bgneal@312: } bgneal@312: bgneal@312: return e.className; bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: hasClass : function(n, c) { bgneal@312: n = this.get(n); bgneal@312: bgneal@312: if (!n || !c) bgneal@312: return false; bgneal@312: bgneal@312: return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1; bgneal@312: }, bgneal@312: bgneal@312: show : function(e) { bgneal@312: return this.setStyle(e, 'display', 'block'); bgneal@312: }, bgneal@312: bgneal@312: hide : function(e) { bgneal@312: return this.setStyle(e, 'display', 'none'); bgneal@312: }, bgneal@312: bgneal@312: isHidden : function(e) { bgneal@312: e = this.get(e); bgneal@312: bgneal@312: return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none'; bgneal@312: }, bgneal@312: bgneal@312: uniqueId : function(p) { bgneal@312: return (!p ? 'mce_' : p) + (this.counter++); bgneal@312: }, bgneal@312: bgneal@442: setHTML : function(element, html) { bgneal@442: var self = this; bgneal@442: bgneal@442: return self.run(element, function(element) { bgneal@312: if (isIE) { bgneal@442: // Remove all child nodes, IE keeps empty text nodes in DOM bgneal@442: while (element.firstChild) bgneal@442: element.removeChild(element.firstChild); bgneal@442: bgneal@442: try { bgneal@442: // IE will remove comments from the beginning bgneal@442: // unless you padd the contents with something bgneal@442: element.innerHTML = '
    ' + html; bgneal@442: element.removeChild(element.firstChild); bgneal@442: } catch (ex) { bgneal@442: // 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 bgneal@442: // This seems to fix this problem bgneal@442: bgneal@442: // Create new div with HTML contents and a BR infront to keep comments bgneal@442: element = self.create('div'); bgneal@442: element.innerHTML = '
    ' + html; bgneal@442: bgneal@442: // Add all children from div to target bgneal@442: each (element.childNodes, function(node, i) { bgneal@442: // Skip br element bgneal@442: if (i) bgneal@442: element.appendChild(node); bgneal@442: }); bgneal@312: } bgneal@312: } else bgneal@442: element.innerHTML = html; bgneal@442: bgneal@442: return html; bgneal@442: }); bgneal@442: }, bgneal@442: bgneal@442: getOuterHTML : function(elm) { bgneal@442: var doc, self = this; bgneal@442: bgneal@442: elm = self.get(elm); bgneal@442: bgneal@442: if (!elm) bgneal@312: return null; bgneal@312: bgneal@442: if (elm.nodeType === 1 && self.hasOuterHTML) bgneal@442: return elm.outerHTML; bgneal@442: bgneal@442: doc = (elm.ownerDocument || self.doc).createElement("body"); bgneal@442: doc.appendChild(elm.cloneNode(true)); bgneal@442: bgneal@442: return doc.innerHTML; bgneal@312: }, bgneal@312: bgneal@312: setOuterHTML : function(e, h, d) { bgneal@312: var t = this; bgneal@312: bgneal@312: function setHTML(e, h, d) { bgneal@312: var n, tp; bgneal@312: bgneal@312: tp = d.createElement("body"); bgneal@312: tp.innerHTML = h; bgneal@312: bgneal@312: n = tp.lastChild; bgneal@312: while (n) { bgneal@312: t.insertAfter(n.cloneNode(true), e); bgneal@312: n = n.previousSibling; bgneal@312: } bgneal@312: bgneal@312: t.remove(e); bgneal@312: }; bgneal@312: bgneal@312: return this.run(e, function(e) { bgneal@312: e = t.get(e); bgneal@312: bgneal@312: // Only set HTML on elements bgneal@312: if (e.nodeType == 1) { bgneal@312: d = d || e.ownerDocument || t.doc; bgneal@312: bgneal@312: if (isIE) { bgneal@312: try { bgneal@312: // Try outerHTML for IE it sometimes produces an unknown runtime error bgneal@312: if (isIE && e.nodeType == 1) bgneal@312: e.outerHTML = h; bgneal@312: else bgneal@312: setHTML(e, h, d); bgneal@312: } catch (ex) { bgneal@312: // Fix for unknown runtime error bgneal@312: setHTML(e, h, d); bgneal@312: } bgneal@312: } else bgneal@312: setHTML(e, h, d); bgneal@312: } bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@442: decode : Entities.decode, bgneal@442: bgneal@442: encode : Entities.encodeAllRaw, bgneal@312: bgneal@312: insertAfter : function(node, reference_node) { bgneal@312: reference_node = this.get(reference_node); bgneal@312: bgneal@312: return this.run(node, function(node) { bgneal@312: var parent, nextSibling; bgneal@312: bgneal@312: parent = reference_node.parentNode; bgneal@312: nextSibling = reference_node.nextSibling; bgneal@312: bgneal@312: if (nextSibling) bgneal@312: parent.insertBefore(node, nextSibling); bgneal@312: else bgneal@312: parent.appendChild(node); bgneal@312: bgneal@312: return node; bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@442: isBlock : function(node) { bgneal@442: var type = node.nodeType; bgneal@442: bgneal@442: // If it's a node then check the type and use the nodeName bgneal@442: if (type) bgneal@442: return !!(type === 1 && blockElementsMap[node.nodeName]); bgneal@442: bgneal@442: return !!blockElementsMap[node]; bgneal@312: }, bgneal@312: bgneal@312: replace : function(n, o, k) { bgneal@312: var t = this; bgneal@312: bgneal@312: if (is(o, 'array')) bgneal@312: n = n.cloneNode(true); bgneal@312: bgneal@312: return t.run(o, function(o) { bgneal@312: if (k) { bgneal@312: each(tinymce.grep(o.childNodes), function(c) { bgneal@312: n.appendChild(c); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: return o.parentNode.replaceChild(n, o); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: rename : function(elm, name) { bgneal@312: var t = this, newElm; bgneal@312: bgneal@312: if (elm.nodeName != name.toUpperCase()) { bgneal@312: // Rename block element bgneal@312: newElm = t.create(name); bgneal@312: bgneal@312: // Copy attribs to new block bgneal@312: each(t.getAttribs(elm), function(attr_node) { bgneal@312: t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName)); bgneal@312: }); bgneal@312: bgneal@312: // Replace block bgneal@312: t.replace(newElm, elm, 1); bgneal@312: } bgneal@312: bgneal@312: return newElm || elm; bgneal@312: }, bgneal@312: bgneal@312: findCommonAncestor : function(a, b) { bgneal@312: var ps = a, pe; bgneal@312: bgneal@312: while (ps) { bgneal@312: pe = b; bgneal@312: bgneal@312: while (pe && ps != pe) bgneal@312: pe = pe.parentNode; bgneal@312: bgneal@312: if (ps == pe) bgneal@312: break; bgneal@312: bgneal@312: ps = ps.parentNode; bgneal@312: } bgneal@312: bgneal@312: if (!ps && a.ownerDocument) bgneal@312: return a.ownerDocument.documentElement; bgneal@312: bgneal@312: return ps; bgneal@312: }, bgneal@312: bgneal@312: toHex : function(s) { bgneal@312: var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s); bgneal@312: bgneal@312: function hex(s) { bgneal@312: s = parseInt(s).toString(16); bgneal@312: bgneal@312: return s.length > 1 ? s : '0' + s; // 0 -> 00 bgneal@312: }; bgneal@312: bgneal@312: if (c) { bgneal@312: s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]); bgneal@312: bgneal@312: return s; bgneal@312: } bgneal@312: bgneal@312: return s; bgneal@312: }, bgneal@312: bgneal@312: getClasses : function() { bgneal@312: var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov; bgneal@312: bgneal@312: if (t.classes) bgneal@312: return t.classes; bgneal@312: bgneal@312: function addClasses(s) { bgneal@312: // IE style imports bgneal@312: each(s.imports, function(r) { bgneal@312: addClasses(r); bgneal@312: }); bgneal@312: bgneal@312: each(s.cssRules || s.rules, function(r) { bgneal@312: // Real type or fake it on IE bgneal@312: switch (r.type || 1) { bgneal@312: // Rule bgneal@312: case 1: bgneal@312: if (r.selectorText) { bgneal@312: each(r.selectorText.split(','), function(v) { bgneal@312: v = v.replace(/^\s*|\s*$|^\s\./g, ""); bgneal@312: bgneal@312: // Is internal or it doesn't contain a class bgneal@312: if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v)) bgneal@312: return; bgneal@312: bgneal@312: // Remove everything but class name bgneal@312: ov = v; bgneal@442: v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v); bgneal@312: bgneal@312: // Filter classes bgneal@312: if (f && !(v = f(v, ov))) bgneal@312: return; bgneal@312: bgneal@312: if (!lo[v]) { bgneal@312: cl.push({'class' : v}); bgneal@312: lo[v] = 1; bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: break; bgneal@312: bgneal@312: // Import bgneal@312: case 3: bgneal@312: addClasses(r.styleSheet); bgneal@312: break; bgneal@312: } bgneal@312: }); bgneal@312: }; bgneal@312: bgneal@312: try { bgneal@312: each(t.doc.styleSheets, addClasses); bgneal@312: } catch (ex) { bgneal@312: // Ignore bgneal@312: } bgneal@312: bgneal@312: if (cl.length > 0) bgneal@312: t.classes = cl; bgneal@312: bgneal@312: return cl; bgneal@312: }, bgneal@312: bgneal@312: run : function(e, f, s) { bgneal@312: var t = this, o; bgneal@312: bgneal@312: if (t.doc && typeof(e) === 'string') bgneal@312: e = t.get(e); bgneal@312: bgneal@312: if (!e) bgneal@312: return false; bgneal@312: bgneal@312: s = s || this; bgneal@312: if (!e.nodeType && (e.length || e.length === 0)) { bgneal@312: o = []; bgneal@312: bgneal@312: each(e, function(e, i) { bgneal@312: if (e) { bgneal@312: if (typeof(e) == 'string') bgneal@312: e = t.doc.getElementById(e); bgneal@312: bgneal@312: o.push(f.call(s, e, i)); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: return o; bgneal@312: } bgneal@312: bgneal@312: return f.call(s, e); bgneal@312: }, bgneal@312: bgneal@312: getAttribs : function(n) { bgneal@312: var o; bgneal@312: bgneal@312: n = this.get(n); bgneal@312: bgneal@312: if (!n) bgneal@312: return []; bgneal@312: bgneal@312: if (isIE) { bgneal@312: o = []; bgneal@312: bgneal@312: // Object will throw exception in IE bgneal@312: if (n.nodeName == 'OBJECT') bgneal@312: return n.attributes; bgneal@312: bgneal@312: // IE doesn't keep the selected attribute if you clone option elements bgneal@312: if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected')) bgneal@312: o.push({specified : 1, nodeName : 'selected'}); bgneal@312: bgneal@312: // It's crazy that this is faster in IE but it's because it returns all attributes all the time bgneal@312: n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) { bgneal@312: o.push({specified : 1, nodeName : a}); bgneal@312: }); bgneal@312: bgneal@312: return o; bgneal@312: } bgneal@312: bgneal@312: return n.attributes; bgneal@312: }, bgneal@312: bgneal@442: isEmpty : function(node, elements) { bgneal@442: var self = this, i, attributes, type, walker, name; bgneal@442: bgneal@442: node = node.firstChild; bgneal@442: if (node) { bgneal@442: walker = new tinymce.dom.TreeWalker(node); bgneal@442: elements = elements || self.schema ? self.schema.getNonEmptyElements() : null; bgneal@442: bgneal@442: do { bgneal@442: type = node.nodeType; bgneal@442: bgneal@442: if (type === 1) { bgneal@442: // Ignore bogus elements bgneal@442: if (node.getAttribute('data-mce-bogus')) bgneal@442: continue; bgneal@442: bgneal@442: // Keep empty elements like bgneal@442: if (elements && elements[node.nodeName.toLowerCase()]) bgneal@442: return false; bgneal@442: bgneal@442: // Keep elements with data attributes or name attribute like
    bgneal@442: attributes = self.getAttribs(node); bgneal@442: i = node.attributes.length; bgneal@442: while (i--) { bgneal@442: name = node.attributes[i].nodeName; bgneal@442: if (name === "name" || name.indexOf('data-') === 0) bgneal@442: return false; bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: // Keep non whitespace text nodes bgneal@442: if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue))) bgneal@442: return false; bgneal@442: } while (node = walker.next()); bgneal@442: } bgneal@442: bgneal@442: return true; bgneal@442: }, bgneal@442: bgneal@312: destroy : function(s) { bgneal@312: var t = this; bgneal@312: bgneal@312: if (t.events) bgneal@312: t.events.destroy(); bgneal@312: bgneal@312: t.win = t.doc = t.root = t.events = null; bgneal@312: bgneal@312: // Manual destroy then remove unload handler bgneal@312: if (!s) bgneal@312: tinymce.removeUnload(t.destroy); bgneal@312: }, bgneal@312: bgneal@312: createRng : function() { bgneal@312: var d = this.doc; bgneal@312: bgneal@312: return d.createRange ? d.createRange() : new tinymce.dom.Range(this); bgneal@312: }, bgneal@312: bgneal@312: nodeIndex : function(node, normalized) { bgneal@442: var idx = 0, lastNodeType, lastNode, nodeType, nodeValueExists; bgneal@312: bgneal@312: if (node) { bgneal@312: for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) { bgneal@312: nodeType = node.nodeType; bgneal@312: bgneal@312: // Normalize text nodes bgneal@312: if (normalized && nodeType == 3) { bgneal@442: // ensure that text nodes that have been removed are handled correctly in Internet Explorer. bgneal@442: // (the nodeValue attribute will not exist, and will error here). bgneal@442: nodeValueExists = false; bgneal@442: try {nodeValueExists = node.nodeValue.length} catch (c) {} bgneal@442: if (nodeType == lastNodeType || !nodeValueExists) bgneal@312: continue; bgneal@312: } bgneal@312: idx++; bgneal@312: lastNodeType = nodeType; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return idx; bgneal@312: }, bgneal@312: bgneal@312: split : function(pe, e, re) { bgneal@312: var t = this, r = t.createRng(), bef, aft, pa; bgneal@312: bgneal@312: // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense bgneal@312: // but we don't want that in our code since it serves no purpose for the end user bgneal@312: // For example if this is chopped: bgneal@312: //

    text 1CHOPtext 2

    bgneal@312: // would produce: bgneal@312: //

    text 1

    CHOP

    text 2

    bgneal@312: // this function will then trim of empty edges and produce: bgneal@312: //

    text 1

    CHOP

    text 2

    bgneal@312: function trim(node) { bgneal@442: var i, children = node.childNodes, type = node.nodeType; bgneal@442: bgneal@442: if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark') bgneal@312: return; bgneal@312: bgneal@312: for (i = children.length - 1; i >= 0; i--) bgneal@312: trim(children[i]); bgneal@312: bgneal@442: if (type != 9) { bgneal@312: // Keep non whitespace text nodes bgneal@442: if (type == 3 && node.nodeValue.length > 0) { bgneal@442: // If parent element isn't a block or there isn't any useful contents for example "

    " bgneal@442: if (!t.isBlock(node.parentNode) || tinymce.trim(node.nodeValue).length > 0) bgneal@442: return; bgneal@442: } else if (type == 1) { bgneal@312: // If the only child is a bookmark then move it up bgneal@312: children = node.childNodes; bgneal@442: if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('data-mce-type') == 'bookmark') bgneal@312: node.parentNode.insertBefore(children[0], node); bgneal@312: bgneal@312: // Keep non empty elements or img, hr etc bgneal@312: if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName)) bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: t.remove(node); bgneal@312: } bgneal@312: bgneal@312: return node; bgneal@312: }; bgneal@312: bgneal@312: if (pe && e) { bgneal@312: // Get before chunk bgneal@312: r.setStart(pe.parentNode, t.nodeIndex(pe)); bgneal@312: r.setEnd(e.parentNode, t.nodeIndex(e)); bgneal@312: bef = r.extractContents(); bgneal@312: bgneal@312: // Get after chunk bgneal@312: r = t.createRng(); bgneal@312: r.setStart(e.parentNode, t.nodeIndex(e) + 1); bgneal@312: r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1); bgneal@312: aft = r.extractContents(); bgneal@312: bgneal@312: // Insert before chunk bgneal@312: pa = pe.parentNode; bgneal@312: pa.insertBefore(trim(bef), pe); bgneal@312: bgneal@312: // Insert middle chunk bgneal@312: if (re) bgneal@312: pa.replaceChild(re, e); bgneal@312: else bgneal@312: pa.insertBefore(e, pe); bgneal@312: bgneal@312: // Insert after chunk bgneal@312: pa.insertBefore(trim(aft), pe); bgneal@312: t.remove(pe); bgneal@312: bgneal@312: return re || e; bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: bind : function(target, name, func, scope) { bgneal@312: var t = this; bgneal@312: bgneal@312: if (!t.events) bgneal@312: t.events = new tinymce.dom.EventUtils(); bgneal@312: bgneal@312: return t.events.add(target, name, func, scope || this); bgneal@312: }, bgneal@312: bgneal@312: unbind : function(target, name, func) { bgneal@312: var t = this; bgneal@312: bgneal@312: if (!t.events) bgneal@312: t.events = new tinymce.dom.EventUtils(); bgneal@312: bgneal@312: return t.events.remove(target, name, func); bgneal@312: }, bgneal@312: bgneal@312: bgneal@312: _findSib : function(node, selector, name) { bgneal@312: var t = this, f = selector; bgneal@312: bgneal@312: if (node) { bgneal@312: // If expression make a function of it using is bgneal@312: if (is(f, 'string')) { bgneal@312: f = function(node) { bgneal@312: return t.is(node, selector); bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: // Loop all siblings bgneal@312: for (node = node[name]; node; node = node[name]) { bgneal@312: if (f(node)) bgneal@312: return node; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return null; bgneal@312: }, bgneal@312: bgneal@312: _isRes : function(c) { bgneal@312: // Is live resizble element bgneal@312: return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c); bgneal@312: } bgneal@312: bgneal@312: /* bgneal@312: walk : function(n, f, s) { bgneal@312: var d = this.doc, w; bgneal@312: bgneal@312: if (d.createTreeWalker) { bgneal@312: w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false); bgneal@312: bgneal@312: while ((n = w.nextNode()) != null) bgneal@312: f.call(s || this, n); bgneal@312: } else bgneal@312: tinymce.walk(n, f, 'childNodes', s); bgneal@312: } bgneal@312: */ bgneal@312: bgneal@312: /* bgneal@312: toRGB : function(s) { bgneal@312: var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s); bgneal@312: bgneal@312: if (c) { bgneal@312: // #FFF -> #FFFFFF bgneal@312: if (!is(c[3])) bgneal@312: c[3] = c[2] = c[1]; bgneal@312: bgneal@312: return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")"; bgneal@312: } bgneal@312: bgneal@312: return s; bgneal@312: } bgneal@312: */ bgneal@312: }); bgneal@312: bgneal@312: tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0}); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(ns) { bgneal@312: // Range constructor bgneal@312: function Range(dom) { bgneal@312: var t = this, bgneal@312: doc = dom.doc, bgneal@312: EXTRACT = 0, bgneal@312: CLONE = 1, bgneal@312: DELETE = 2, bgneal@312: TRUE = true, bgneal@312: FALSE = false, bgneal@312: START_OFFSET = 'startOffset', bgneal@312: START_CONTAINER = 'startContainer', bgneal@312: END_CONTAINER = 'endContainer', bgneal@312: END_OFFSET = 'endOffset', bgneal@312: extend = tinymce.extend, bgneal@312: nodeIndex = dom.nodeIndex; bgneal@312: bgneal@312: extend(t, { bgneal@312: // Inital states bgneal@312: startContainer : doc, bgneal@312: startOffset : 0, bgneal@312: endContainer : doc, bgneal@312: endOffset : 0, bgneal@312: collapsed : TRUE, bgneal@312: commonAncestorContainer : doc, bgneal@312: bgneal@312: // Range constants bgneal@312: START_TO_START : 0, bgneal@312: START_TO_END : 1, bgneal@312: END_TO_END : 2, bgneal@312: END_TO_START : 3, bgneal@312: bgneal@312: // Public methods bgneal@312: setStart : setStart, bgneal@312: setEnd : setEnd, bgneal@312: setStartBefore : setStartBefore, bgneal@312: setStartAfter : setStartAfter, bgneal@312: setEndBefore : setEndBefore, bgneal@312: setEndAfter : setEndAfter, bgneal@312: collapse : collapse, bgneal@312: selectNode : selectNode, bgneal@312: selectNodeContents : selectNodeContents, bgneal@312: compareBoundaryPoints : compareBoundaryPoints, bgneal@312: deleteContents : deleteContents, bgneal@312: extractContents : extractContents, bgneal@312: cloneContents : cloneContents, bgneal@312: insertNode : insertNode, bgneal@312: surroundContents : surroundContents, bgneal@312: cloneRange : cloneRange bgneal@312: }); bgneal@312: bgneal@312: function setStart(n, o) { bgneal@312: _setEndPoint(TRUE, n, o); bgneal@312: }; bgneal@312: bgneal@312: function setEnd(n, o) { bgneal@312: _setEndPoint(FALSE, n, o); bgneal@312: }; bgneal@312: bgneal@312: function setStartBefore(n) { bgneal@312: setStart(n.parentNode, nodeIndex(n)); bgneal@312: }; bgneal@312: bgneal@312: function setStartAfter(n) { bgneal@312: setStart(n.parentNode, nodeIndex(n) + 1); bgneal@312: }; bgneal@312: bgneal@312: function setEndBefore(n) { bgneal@312: setEnd(n.parentNode, nodeIndex(n)); bgneal@312: }; bgneal@312: bgneal@312: function setEndAfter(n) { bgneal@312: setEnd(n.parentNode, nodeIndex(n) + 1); bgneal@312: }; bgneal@312: bgneal@312: function collapse(ts) { bgneal@312: if (ts) { bgneal@312: t[END_CONTAINER] = t[START_CONTAINER]; bgneal@312: t[END_OFFSET] = t[START_OFFSET]; bgneal@312: } else { bgneal@312: t[START_CONTAINER] = t[END_CONTAINER]; bgneal@312: t[START_OFFSET] = t[END_OFFSET]; bgneal@312: } bgneal@312: bgneal@312: t.collapsed = TRUE; bgneal@312: }; bgneal@312: bgneal@312: function selectNode(n) { bgneal@312: setStartBefore(n); bgneal@312: setEndAfter(n); bgneal@312: }; bgneal@312: bgneal@312: function selectNodeContents(n) { bgneal@312: setStart(n, 0); bgneal@312: setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length); bgneal@312: }; bgneal@312: bgneal@312: function compareBoundaryPoints(h, r) { bgneal@442: var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET], bgneal@442: rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset; bgneal@312: bgneal@312: // Check START_TO_START bgneal@312: if (h === 0) bgneal@442: return _compareBoundaryPoints(sc, so, rsc, rso); bgneal@442: bgneal@312: // Check START_TO_END bgneal@312: if (h === 1) bgneal@442: return _compareBoundaryPoints(ec, eo, rsc, rso); bgneal@442: bgneal@312: // Check END_TO_END bgneal@312: if (h === 2) bgneal@442: return _compareBoundaryPoints(ec, eo, rec, reo); bgneal@442: bgneal@312: // Check END_TO_START bgneal@442: if (h === 3) bgneal@442: return _compareBoundaryPoints(sc, so, rec, reo); bgneal@312: }; bgneal@312: bgneal@312: function deleteContents() { bgneal@312: _traverse(DELETE); bgneal@312: }; bgneal@312: bgneal@312: function extractContents() { bgneal@312: return _traverse(EXTRACT); bgneal@312: }; bgneal@312: bgneal@312: function cloneContents() { bgneal@312: return _traverse(CLONE); bgneal@312: }; bgneal@312: bgneal@312: function insertNode(n) { bgneal@312: var startContainer = this[START_CONTAINER], bgneal@312: startOffset = this[START_OFFSET], nn, o; bgneal@312: bgneal@312: // Node is TEXT_NODE or CDATA bgneal@312: if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) { bgneal@312: if (!startOffset) { bgneal@312: // At the start of text bgneal@312: startContainer.parentNode.insertBefore(n, startContainer); bgneal@312: } else if (startOffset >= startContainer.nodeValue.length) { bgneal@312: // At the end of text bgneal@312: dom.insertAfter(n, startContainer); bgneal@312: } else { bgneal@312: // Middle, need to split bgneal@312: nn = startContainer.splitText(startOffset); bgneal@312: startContainer.parentNode.insertBefore(n, nn); bgneal@312: } bgneal@312: } else { bgneal@312: // Insert element node bgneal@312: if (startContainer.childNodes.length > 0) bgneal@312: o = startContainer.childNodes[startOffset]; bgneal@312: bgneal@312: if (o) bgneal@312: startContainer.insertBefore(n, o); bgneal@312: else bgneal@312: startContainer.appendChild(n); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function surroundContents(n) { bgneal@312: var f = t.extractContents(); bgneal@312: bgneal@312: t.insertNode(n); bgneal@312: n.appendChild(f); bgneal@312: t.selectNode(n); bgneal@312: }; bgneal@312: bgneal@312: function cloneRange() { bgneal@312: return extend(new Range(dom), { bgneal@312: startContainer : t[START_CONTAINER], bgneal@312: startOffset : t[START_OFFSET], bgneal@312: endContainer : t[END_CONTAINER], bgneal@312: endOffset : t[END_OFFSET], bgneal@312: collapsed : t.collapsed, bgneal@312: commonAncestorContainer : t.commonAncestorContainer bgneal@312: }); bgneal@312: }; bgneal@312: bgneal@312: // Private methods bgneal@312: bgneal@312: function _getSelectedNode(container, offset) { bgneal@312: var child; bgneal@312: bgneal@312: if (container.nodeType == 3 /* TEXT_NODE */) bgneal@312: return container; bgneal@312: bgneal@312: if (offset < 0) bgneal@312: return container; bgneal@312: bgneal@312: child = container.firstChild; bgneal@312: while (child && offset > 0) { bgneal@312: --offset; bgneal@312: child = child.nextSibling; bgneal@312: } bgneal@312: bgneal@312: if (child) bgneal@312: return child; bgneal@312: bgneal@312: return container; bgneal@312: }; bgneal@312: bgneal@312: function _isCollapsed() { bgneal@312: return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]); bgneal@312: }; bgneal@312: bgneal@312: function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) { bgneal@312: var c, offsetC, n, cmnRoot, childA, childB; bgneal@442: bgneal@312: // In the first case the boundary-points have the same container. A is before B bgneal@312: // if its offset is less than the offset of B, A is equal to B if its offset is bgneal@312: // equal to the offset of B, and A is after B if its offset is greater than the bgneal@312: // offset of B. bgneal@312: if (containerA == containerB) { bgneal@312: if (offsetA == offsetB) bgneal@312: return 0; // equal bgneal@312: bgneal@312: if (offsetA < offsetB) bgneal@312: return -1; // before bgneal@312: bgneal@312: return 1; // after bgneal@312: } bgneal@312: bgneal@312: // In the second case a child node C of the container of A is an ancestor bgneal@312: // container of B. In this case, A is before B if the offset of A is less than or bgneal@312: // equal to the index of the child node C and A is after B otherwise. bgneal@312: c = containerB; bgneal@312: while (c && c.parentNode != containerA) bgneal@312: c = c.parentNode; bgneal@312: bgneal@312: if (c) { bgneal@312: offsetC = 0; bgneal@312: n = containerA.firstChild; bgneal@312: bgneal@312: while (n != c && offsetC < offsetA) { bgneal@312: offsetC++; bgneal@312: n = n.nextSibling; bgneal@312: } bgneal@312: bgneal@312: if (offsetA <= offsetC) bgneal@312: return -1; // before bgneal@312: bgneal@312: return 1; // after bgneal@312: } bgneal@312: bgneal@312: // In the third case a child node C of the container of B is an ancestor container bgneal@312: // of A. In this case, A is before B if the index of the child node C is less than bgneal@312: // the offset of B and A is after B otherwise. bgneal@312: c = containerA; bgneal@312: while (c && c.parentNode != containerB) { bgneal@312: c = c.parentNode; bgneal@312: } bgneal@312: bgneal@312: if (c) { bgneal@312: offsetC = 0; bgneal@312: n = containerB.firstChild; bgneal@312: bgneal@312: while (n != c && offsetC < offsetB) { bgneal@312: offsetC++; bgneal@312: n = n.nextSibling; bgneal@312: } bgneal@312: bgneal@312: if (offsetC < offsetB) bgneal@312: return -1; // before bgneal@312: bgneal@312: return 1; // after bgneal@312: } bgneal@312: bgneal@312: // In the fourth case, none of three other cases hold: the containers of A and B bgneal@312: // are siblings or descendants of sibling nodes. In this case, A is before B if bgneal@312: // the container of A is before the container of B in a pre-order traversal of the bgneal@312: // Ranges' context tree and A is after B otherwise. bgneal@312: cmnRoot = dom.findCommonAncestor(containerA, containerB); bgneal@312: childA = containerA; bgneal@312: bgneal@312: while (childA && childA.parentNode != cmnRoot) bgneal@312: childA = childA.parentNode; bgneal@312: bgneal@312: if (!childA) bgneal@312: childA = cmnRoot; bgneal@312: bgneal@312: childB = containerB; bgneal@312: while (childB && childB.parentNode != cmnRoot) bgneal@312: childB = childB.parentNode; bgneal@312: bgneal@312: if (!childB) bgneal@312: childB = cmnRoot; bgneal@312: bgneal@312: if (childA == childB) bgneal@312: return 0; // equal bgneal@312: bgneal@312: n = cmnRoot.firstChild; bgneal@312: while (n) { bgneal@312: if (n == childA) bgneal@312: return -1; // before bgneal@312: bgneal@312: if (n == childB) bgneal@312: return 1; // after bgneal@312: bgneal@312: n = n.nextSibling; bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function _setEndPoint(st, n, o) { bgneal@312: var ec, sc; bgneal@312: bgneal@312: if (st) { bgneal@312: t[START_CONTAINER] = n; bgneal@312: t[START_OFFSET] = o; bgneal@312: } else { bgneal@312: t[END_CONTAINER] = n; bgneal@312: t[END_OFFSET] = o; bgneal@312: } bgneal@312: bgneal@312: // If one boundary-point of a Range is set to have a root container bgneal@312: // other than the current one for the Range, the Range is collapsed to bgneal@312: // the new position. This enforces the restriction that both boundary- bgneal@312: // points of a Range must have the same root container. bgneal@312: ec = t[END_CONTAINER]; bgneal@312: while (ec.parentNode) bgneal@312: ec = ec.parentNode; bgneal@312: bgneal@312: sc = t[START_CONTAINER]; bgneal@312: while (sc.parentNode) bgneal@312: sc = sc.parentNode; bgneal@312: bgneal@312: if (sc == ec) { bgneal@312: // The start position of a Range is guaranteed to never be after the bgneal@312: // end position. To enforce this restriction, if the start is set to bgneal@312: // be at a position after the end, the Range is collapsed to that bgneal@312: // position. bgneal@312: if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0) bgneal@312: t.collapse(st); bgneal@312: } else bgneal@312: t.collapse(st); bgneal@312: bgneal@312: t.collapsed = _isCollapsed(); bgneal@312: t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]); bgneal@312: }; bgneal@312: bgneal@312: function _traverse(how) { bgneal@312: var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep; bgneal@312: bgneal@312: if (t[START_CONTAINER] == t[END_CONTAINER]) bgneal@312: return _traverseSameContainer(how); bgneal@312: bgneal@312: for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) { bgneal@312: if (p == t[START_CONTAINER]) bgneal@312: return _traverseCommonStartContainer(c, how); bgneal@312: bgneal@312: ++endContainerDepth; bgneal@312: } bgneal@312: bgneal@312: for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) { bgneal@312: if (p == t[END_CONTAINER]) bgneal@312: return _traverseCommonEndContainer(c, how); bgneal@312: bgneal@312: ++startContainerDepth; bgneal@312: } bgneal@312: bgneal@312: depthDiff = startContainerDepth - endContainerDepth; bgneal@312: bgneal@312: startNode = t[START_CONTAINER]; bgneal@312: while (depthDiff > 0) { bgneal@312: startNode = startNode.parentNode; bgneal@312: depthDiff--; bgneal@312: } bgneal@312: bgneal@312: endNode = t[END_CONTAINER]; bgneal@312: while (depthDiff < 0) { bgneal@312: endNode = endNode.parentNode; bgneal@312: depthDiff++; bgneal@312: } bgneal@312: bgneal@312: // ascend the ancestor hierarchy until we have a common parent. bgneal@312: for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) { bgneal@312: startNode = sp; bgneal@312: endNode = ep; bgneal@312: } bgneal@312: bgneal@312: return _traverseCommonAncestors(startNode, endNode, how); bgneal@312: }; bgneal@312: bgneal@312: function _traverseSameContainer(how) { bgneal@312: var frag, s, sub, n, cnt, sibling, xferNode; bgneal@312: bgneal@312: if (how != DELETE) bgneal@312: frag = doc.createDocumentFragment(); bgneal@312: bgneal@312: // If selection is empty, just return the fragment bgneal@312: if (t[START_OFFSET] == t[END_OFFSET]) bgneal@312: return frag; bgneal@312: bgneal@312: // Text node needs special case handling bgneal@312: if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) { bgneal@312: // get the substring bgneal@312: s = t[START_CONTAINER].nodeValue; bgneal@312: sub = s.substring(t[START_OFFSET], t[END_OFFSET]); bgneal@312: bgneal@312: // set the original text node to its new value bgneal@312: if (how != CLONE) { bgneal@312: t[START_CONTAINER].deleteData(t[START_OFFSET], t[END_OFFSET] - t[START_OFFSET]); bgneal@312: bgneal@312: // Nothing is partially selected, so collapse to start point bgneal@312: t.collapse(TRUE); bgneal@312: } bgneal@312: bgneal@312: if (how == DELETE) bgneal@312: return; bgneal@312: bgneal@312: frag.appendChild(doc.createTextNode(sub)); bgneal@312: return frag; bgneal@312: } bgneal@312: bgneal@312: // Copy nodes between the start/end offsets. bgneal@312: n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]); bgneal@312: cnt = t[END_OFFSET] - t[START_OFFSET]; bgneal@312: bgneal@312: while (cnt > 0) { bgneal@312: sibling = n.nextSibling; bgneal@312: xferNode = _traverseFullySelected(n, how); bgneal@312: bgneal@312: if (frag) bgneal@312: frag.appendChild( xferNode ); bgneal@312: bgneal@312: --cnt; bgneal@312: n = sibling; bgneal@312: } bgneal@312: bgneal@312: // Nothing is partially selected, so collapse to start point bgneal@312: if (how != CLONE) bgneal@312: t.collapse(TRUE); bgneal@312: bgneal@312: return frag; bgneal@312: }; bgneal@312: bgneal@312: function _traverseCommonStartContainer(endAncestor, how) { bgneal@312: var frag, n, endIdx, cnt, sibling, xferNode; bgneal@312: bgneal@312: if (how != DELETE) bgneal@312: frag = doc.createDocumentFragment(); bgneal@312: bgneal@312: n = _traverseRightBoundary(endAncestor, how); bgneal@312: bgneal@312: if (frag) bgneal@312: frag.appendChild(n); bgneal@312: bgneal@312: endIdx = nodeIndex(endAncestor); bgneal@312: cnt = endIdx - t[START_OFFSET]; bgneal@312: bgneal@312: if (cnt <= 0) { bgneal@312: // Collapse to just before the endAncestor, which bgneal@312: // is partially selected. bgneal@312: if (how != CLONE) { bgneal@312: t.setEndBefore(endAncestor); bgneal@312: t.collapse(FALSE); bgneal@312: } bgneal@312: bgneal@312: return frag; bgneal@312: } bgneal@312: bgneal@312: n = endAncestor.previousSibling; bgneal@312: while (cnt > 0) { bgneal@312: sibling = n.previousSibling; bgneal@312: xferNode = _traverseFullySelected(n, how); bgneal@312: bgneal@312: if (frag) bgneal@312: frag.insertBefore(xferNode, frag.firstChild); bgneal@312: bgneal@312: --cnt; bgneal@312: n = sibling; bgneal@312: } bgneal@312: bgneal@312: // Collapse to just before the endAncestor, which bgneal@312: // is partially selected. bgneal@312: if (how != CLONE) { bgneal@312: t.setEndBefore(endAncestor); bgneal@312: t.collapse(FALSE); bgneal@312: } bgneal@312: bgneal@312: return frag; bgneal@312: }; bgneal@312: bgneal@312: function _traverseCommonEndContainer(startAncestor, how) { bgneal@312: var frag, startIdx, n, cnt, sibling, xferNode; bgneal@312: bgneal@312: if (how != DELETE) bgneal@312: frag = doc.createDocumentFragment(); bgneal@312: bgneal@312: n = _traverseLeftBoundary(startAncestor, how); bgneal@312: if (frag) bgneal@312: frag.appendChild(n); bgneal@312: bgneal@312: startIdx = nodeIndex(startAncestor); bgneal@442: ++startIdx; // Because we already traversed it bgneal@312: bgneal@312: cnt = t[END_OFFSET] - startIdx; bgneal@312: n = startAncestor.nextSibling; bgneal@312: while (cnt > 0) { bgneal@312: sibling = n.nextSibling; bgneal@312: xferNode = _traverseFullySelected(n, how); bgneal@312: bgneal@312: if (frag) bgneal@312: frag.appendChild(xferNode); bgneal@312: bgneal@312: --cnt; bgneal@312: n = sibling; bgneal@312: } bgneal@312: bgneal@312: if (how != CLONE) { bgneal@312: t.setStartAfter(startAncestor); bgneal@312: t.collapse(TRUE); bgneal@312: } bgneal@312: bgneal@312: return frag; bgneal@312: }; bgneal@312: bgneal@312: function _traverseCommonAncestors(startAncestor, endAncestor, how) { bgneal@312: var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling; bgneal@312: bgneal@312: if (how != DELETE) bgneal@312: frag = doc.createDocumentFragment(); bgneal@312: bgneal@312: n = _traverseLeftBoundary(startAncestor, how); bgneal@312: if (frag) bgneal@312: frag.appendChild(n); bgneal@312: bgneal@312: commonParent = startAncestor.parentNode; bgneal@312: startOffset = nodeIndex(startAncestor); bgneal@312: endOffset = nodeIndex(endAncestor); bgneal@312: ++startOffset; bgneal@312: bgneal@312: cnt = endOffset - startOffset; bgneal@312: sibling = startAncestor.nextSibling; bgneal@312: bgneal@312: while (cnt > 0) { bgneal@312: nextSibling = sibling.nextSibling; bgneal@312: n = _traverseFullySelected(sibling, how); bgneal@312: bgneal@312: if (frag) bgneal@312: frag.appendChild(n); bgneal@312: bgneal@312: sibling = nextSibling; bgneal@312: --cnt; bgneal@312: } bgneal@312: bgneal@312: n = _traverseRightBoundary(endAncestor, how); bgneal@312: bgneal@312: if (frag) bgneal@312: frag.appendChild(n); bgneal@312: bgneal@312: if (how != CLONE) { bgneal@312: t.setStartAfter(startAncestor); bgneal@312: t.collapse(TRUE); bgneal@312: } bgneal@312: bgneal@312: return frag; bgneal@312: }; bgneal@312: bgneal@312: function _traverseRightBoundary(root, how) { bgneal@312: var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER]; bgneal@312: bgneal@312: if (next == root) bgneal@312: return _traverseNode(next, isFullySelected, FALSE, how); bgneal@312: bgneal@312: parent = next.parentNode; bgneal@312: clonedParent = _traverseNode(parent, FALSE, FALSE, how); bgneal@312: bgneal@312: while (parent) { bgneal@312: while (next) { bgneal@312: prevSibling = next.previousSibling; bgneal@312: clonedChild = _traverseNode(next, isFullySelected, FALSE, how); bgneal@312: bgneal@312: if (how != DELETE) bgneal@312: clonedParent.insertBefore(clonedChild, clonedParent.firstChild); bgneal@312: bgneal@312: isFullySelected = TRUE; bgneal@312: next = prevSibling; bgneal@312: } bgneal@312: bgneal@312: if (parent == root) bgneal@312: return clonedParent; bgneal@312: bgneal@312: next = parent.previousSibling; bgneal@312: parent = parent.parentNode; bgneal@312: bgneal@312: clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how); bgneal@312: bgneal@312: if (how != DELETE) bgneal@312: clonedGrandParent.appendChild(clonedParent); bgneal@312: bgneal@312: clonedParent = clonedGrandParent; bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function _traverseLeftBoundary(root, how) { bgneal@312: var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent; bgneal@312: bgneal@312: if (next == root) bgneal@312: return _traverseNode(next, isFullySelected, TRUE, how); bgneal@312: bgneal@312: parent = next.parentNode; bgneal@312: clonedParent = _traverseNode(parent, FALSE, TRUE, how); bgneal@312: bgneal@312: while (parent) { bgneal@312: while (next) { bgneal@312: nextSibling = next.nextSibling; bgneal@312: clonedChild = _traverseNode(next, isFullySelected, TRUE, how); bgneal@312: bgneal@312: if (how != DELETE) bgneal@312: clonedParent.appendChild(clonedChild); bgneal@312: bgneal@312: isFullySelected = TRUE; bgneal@312: next = nextSibling; bgneal@312: } bgneal@312: bgneal@312: if (parent == root) bgneal@312: return clonedParent; bgneal@312: bgneal@312: next = parent.nextSibling; bgneal@312: parent = parent.parentNode; bgneal@312: bgneal@312: clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how); bgneal@312: bgneal@312: if (how != DELETE) bgneal@312: clonedGrandParent.appendChild(clonedParent); bgneal@312: bgneal@312: clonedParent = clonedGrandParent; bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function _traverseNode(n, isFullySelected, isLeft, how) { bgneal@312: var txtValue, newNodeValue, oldNodeValue, offset, newNode; bgneal@312: bgneal@312: if (isFullySelected) bgneal@312: return _traverseFullySelected(n, how); bgneal@312: bgneal@312: if (n.nodeType == 3 /* TEXT_NODE */) { bgneal@312: txtValue = n.nodeValue; bgneal@312: bgneal@312: if (isLeft) { bgneal@312: offset = t[START_OFFSET]; bgneal@312: newNodeValue = txtValue.substring(offset); bgneal@312: oldNodeValue = txtValue.substring(0, offset); bgneal@312: } else { bgneal@312: offset = t[END_OFFSET]; bgneal@312: newNodeValue = txtValue.substring(0, offset); bgneal@312: oldNodeValue = txtValue.substring(offset); bgneal@312: } bgneal@312: bgneal@312: if (how != CLONE) bgneal@312: n.nodeValue = oldNodeValue; bgneal@312: bgneal@312: if (how == DELETE) bgneal@312: return; bgneal@312: bgneal@312: newNode = n.cloneNode(FALSE); bgneal@312: newNode.nodeValue = newNodeValue; bgneal@312: bgneal@312: return newNode; bgneal@312: } bgneal@312: bgneal@312: if (how == DELETE) bgneal@312: return; bgneal@312: bgneal@312: return n.cloneNode(FALSE); bgneal@312: }; bgneal@312: bgneal@312: function _traverseFullySelected(n, how) { bgneal@312: if (how != DELETE) bgneal@312: return how == CLONE ? n.cloneNode(TRUE) : n; bgneal@312: bgneal@312: n.parentNode.removeChild(n); bgneal@312: }; bgneal@312: }; bgneal@312: bgneal@312: ns.Range = Range; bgneal@312: })(tinymce.dom); bgneal@312: bgneal@312: (function() { bgneal@312: function Selection(selection) { bgneal@312: var t = this, invisibleChar = '\uFEFF', range, lastIERng, dom = selection.dom, TRUE = true, FALSE = false; bgneal@312: bgneal@312: // Returns a W3C DOM compatible range object by using the IE Range API bgneal@312: function getRange() { bgneal@312: var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed; bgneal@312: bgneal@312: // If selection is outside the current document just return an empty range bgneal@312: element = ieRange.item ? ieRange.item(0) : ieRange.parentElement(); bgneal@312: if (element.ownerDocument != dom.doc) bgneal@312: return domRange; bgneal@312: bgneal@442: collapsed = selection.isCollapsed(); bgneal@442: bgneal@312: // Handle control selection or text selection of a image bgneal@312: if (ieRange.item || !element.hasChildNodes()) { bgneal@442: if (collapsed) { bgneal@442: domRange.setStart(element, 0); bgneal@442: domRange.setEnd(element, 0); bgneal@442: } else { bgneal@442: domRange.setStart(element.parentNode, dom.nodeIndex(element)); bgneal@442: domRange.setEnd(domRange.startContainer, domRange.startOffset + 1); bgneal@442: } bgneal@312: bgneal@312: return domRange; bgneal@312: } bgneal@312: bgneal@312: function findEndPoint(start) { bgneal@312: var marker, container, offset, nodes, startIndex = 0, endIndex, index, parent, checkRng, position; bgneal@312: bgneal@312: // Setup temp range and collapse it bgneal@312: checkRng = ieRange.duplicate(); bgneal@312: checkRng.collapse(start); bgneal@312: bgneal@312: // Create marker and insert it at the end of the endpoints parent bgneal@312: marker = dom.create('a'); bgneal@312: parent = checkRng.parentElement(); bgneal@312: bgneal@312: // If parent doesn't have any children then set the container to that parent and the index to 0 bgneal@312: if (!parent.hasChildNodes()) { bgneal@312: domRange[start ? 'setStart' : 'setEnd'](parent, 0); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: parent.appendChild(marker); bgneal@312: checkRng.moveToElementText(marker); bgneal@312: position = ieRange.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', checkRng); bgneal@312: if (position > 0) { bgneal@312: // The position is after the end of the parent element. bgneal@312: // This is the case where IE puts the caret to the left edge of a table. bgneal@312: domRange[start ? 'setStartAfter' : 'setEndAfter'](parent); bgneal@312: dom.remove(marker); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Setup node list and endIndex bgneal@312: nodes = tinymce.grep(parent.childNodes); bgneal@312: endIndex = nodes.length - 1; bgneal@312: // Perform a binary search for the position bgneal@312: while (startIndex <= endIndex) { bgneal@312: index = Math.floor((startIndex + endIndex) / 2); bgneal@312: bgneal@312: // Insert marker and check it's position relative to the selection bgneal@312: parent.insertBefore(marker, nodes[index]); bgneal@312: checkRng.moveToElementText(marker); bgneal@312: position = ieRange.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', checkRng); bgneal@312: if (position > 0) { bgneal@312: // Marker is to the right bgneal@312: startIndex = index + 1; bgneal@312: } else if (position < 0) { bgneal@312: // Marker is to the left bgneal@312: endIndex = index - 1; bgneal@312: } else { bgneal@312: // Maker is where we are bgneal@312: found = true; bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Setup container bgneal@312: container = position > 0 || index == 0 ? marker.nextSibling : marker.previousSibling; bgneal@312: bgneal@312: // Handle element selection bgneal@312: if (container.nodeType == 1) { bgneal@312: dom.remove(marker); bgneal@312: bgneal@312: // Find offset and container bgneal@312: offset = dom.nodeIndex(container); bgneal@312: container = container.parentNode; bgneal@312: bgneal@312: // Move the offset if we are setting the end or the position is after an element bgneal@312: if (!start || index > 0) bgneal@312: offset++; bgneal@312: } else { bgneal@312: // Calculate offset within text node bgneal@312: if (position > 0 || index == 0) { bgneal@312: checkRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', ieRange); bgneal@312: offset = checkRng.text.length; bgneal@312: } else { bgneal@312: checkRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', ieRange); bgneal@312: offset = container.nodeValue.length - checkRng.text.length; bgneal@312: } bgneal@312: bgneal@312: dom.remove(marker); bgneal@312: } bgneal@312: bgneal@312: domRange[start ? 'setStart' : 'setEnd'](container, offset); bgneal@312: }; bgneal@312: bgneal@312: // Find start point bgneal@312: findEndPoint(true); bgneal@312: bgneal@312: // Find end point if needed bgneal@312: if (!collapsed) bgneal@312: findEndPoint(); bgneal@312: bgneal@312: return domRange; bgneal@312: }; bgneal@312: bgneal@312: this.addRange = function(rng) { bgneal@312: var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, doc = selection.dom.doc, body = doc.body; bgneal@312: bgneal@312: function setEndPoint(start) { bgneal@312: var container, offset, marker, tmpRng, nodes; bgneal@312: bgneal@312: marker = dom.create('a'); bgneal@312: container = start ? startContainer : endContainer; bgneal@312: offset = start ? startOffset : endOffset; bgneal@312: tmpRng = ieRng.duplicate(); bgneal@312: bgneal@442: if (container == doc || container == doc.documentElement) { bgneal@312: container = body; bgneal@312: offset = 0; bgneal@312: } bgneal@312: bgneal@312: if (container.nodeType == 3) { bgneal@312: container.parentNode.insertBefore(marker, container); bgneal@312: tmpRng.moveToElementText(marker); bgneal@312: tmpRng.moveStart('character', offset); bgneal@312: dom.remove(marker); bgneal@312: ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng); bgneal@312: } else { bgneal@312: nodes = container.childNodes; bgneal@312: bgneal@312: if (nodes.length) { bgneal@312: if (offset >= nodes.length) { bgneal@312: dom.insertAfter(marker, nodes[nodes.length - 1]); bgneal@312: } else { bgneal@312: container.insertBefore(marker, nodes[offset]); bgneal@312: } bgneal@312: bgneal@312: tmpRng.moveToElementText(marker); bgneal@312: } else { bgneal@312: // Empty node selection for example
    |
    bgneal@312: marker = doc.createTextNode(invisibleChar); bgneal@312: container.appendChild(marker); bgneal@312: tmpRng.moveToElementText(marker.parentNode); bgneal@312: tmpRng.collapse(TRUE); bgneal@312: } bgneal@312: bgneal@312: ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng); bgneal@312: dom.remove(marker); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Destroy cached range bgneal@312: this.destroy(); bgneal@312: bgneal@312: // Setup some shorter versions bgneal@312: startContainer = rng.startContainer; bgneal@312: startOffset = rng.startOffset; bgneal@312: endContainer = rng.endContainer; bgneal@312: endOffset = rng.endOffset; bgneal@312: ieRng = body.createTextRange(); bgneal@312: bgneal@312: // If single element selection then try making a control selection out of it bgneal@312: if (startContainer == endContainer && startContainer.nodeType == 1 && startOffset == endOffset - 1) { bgneal@312: if (startOffset == endOffset - 1) { bgneal@312: try { bgneal@312: ctrlRng = body.createControlRange(); bgneal@312: ctrlRng.addElement(startContainer.childNodes[startOffset]); bgneal@312: ctrlRng.select(); bgneal@312: return; bgneal@312: } catch (ex) { bgneal@312: // Ignore bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Set start/end point of selection bgneal@312: setEndPoint(true); bgneal@312: setEndPoint(); bgneal@312: bgneal@312: // Select the new range and scroll it into view bgneal@312: ieRng.select(); bgneal@312: }; bgneal@312: bgneal@312: this.getRangeAt = function() { bgneal@312: // Setup new range if the cache is empty bgneal@312: if (!range || !tinymce.dom.RangeUtils.compareRanges(lastIERng, selection.getRng())) { bgneal@312: range = getRange(); bgneal@312: bgneal@312: // Store away text range for next call bgneal@312: lastIERng = selection.getRng(); bgneal@312: } bgneal@312: bgneal@312: // IE will say that the range is equal then produce an invalid argument exception bgneal@312: // if you perform specific operations in a keyup event. For example Ctrl+Del. bgneal@312: // This hack will invalidate the range cache if the exception occurs bgneal@312: try { bgneal@312: range.startContainer.nextSibling; bgneal@312: } catch (ex) { bgneal@312: range = getRange(); bgneal@312: lastIERng = null; bgneal@312: } bgneal@312: bgneal@312: // Return cached range bgneal@312: return range; bgneal@312: }; bgneal@312: bgneal@312: this.destroy = function() { bgneal@312: // Destroy cached range and last IE range to avoid memory leaks bgneal@312: lastIERng = range = null; bgneal@312: }; bgneal@312: }; bgneal@312: bgneal@312: // Expose the selection object bgneal@312: tinymce.dom.TridentSelection = Selection; bgneal@312: })(); bgneal@312: bgneal@312: bgneal@312: /* bgneal@312: * Sizzle CSS Selector Engine - v1.0 bgneal@312: * Copyright 2009, The Dojo Foundation bgneal@312: * Released under the MIT, BSD, and GPL Licenses. bgneal@312: * More information: http://sizzlejs.com/ bgneal@312: */ bgneal@312: (function(){ bgneal@312: bgneal@312: var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, bgneal@312: done = 0, bgneal@312: toString = Object.prototype.toString, bgneal@312: hasDuplicate = false, bgneal@312: baseHasDuplicate = true; bgneal@312: bgneal@312: // Here we check if the JavaScript engine is using some sort of bgneal@312: // optimization where it does not always call our comparision bgneal@312: // function. If that is the case, discard the hasDuplicate value. bgneal@312: // Thus far that includes Google Chrome. bgneal@312: [0, 0].sort(function(){ bgneal@312: baseHasDuplicate = false; bgneal@312: return 0; bgneal@312: }); bgneal@312: bgneal@312: var Sizzle = function(selector, context, results, seed) { bgneal@312: results = results || []; bgneal@312: context = context || document; bgneal@312: bgneal@312: var origContext = context; bgneal@312: bgneal@312: if ( context.nodeType !== 1 && context.nodeType !== 9 ) { bgneal@312: return []; bgneal@312: } bgneal@312: bgneal@312: if ( !selector || typeof selector !== "string" ) { bgneal@312: return results; bgneal@312: } bgneal@312: bgneal@312: var parts = [], m, set, checkSet, extra, prune = true, contextXML = Sizzle.isXML(context), bgneal@312: soFar = selector, ret, cur, pop, i; bgneal@312: bgneal@312: // Reset the position of the chunker regexp (start from head) bgneal@312: do { bgneal@312: chunker.exec(""); bgneal@312: m = chunker.exec(soFar); bgneal@312: bgneal@312: if ( m ) { bgneal@312: soFar = m[3]; bgneal@312: bgneal@312: parts.push( m[1] ); bgneal@312: bgneal@312: if ( m[2] ) { bgneal@312: extra = m[3]; bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: } while ( m ); bgneal@312: bgneal@312: if ( parts.length > 1 && origPOS.exec( selector ) ) { bgneal@312: if ( parts.length === 2 && Expr.relative[ parts[0] ] ) { bgneal@312: set = posProcess( parts[0] + parts[1], context ); bgneal@312: } else { bgneal@312: set = Expr.relative[ parts[0] ] ? bgneal@312: [ context ] : bgneal@312: Sizzle( parts.shift(), context ); bgneal@312: bgneal@312: while ( parts.length ) { bgneal@312: selector = parts.shift(); bgneal@312: bgneal@312: if ( Expr.relative[ selector ] ) { bgneal@312: selector += parts.shift(); bgneal@312: } bgneal@312: bgneal@312: set = posProcess( selector, set ); bgneal@312: } bgneal@312: } bgneal@312: } else { bgneal@312: // Take a shortcut and set the context if the root selector is an ID bgneal@312: // (but not if it'll be faster if the inner selector is an ID) bgneal@312: if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML && bgneal@312: Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) { bgneal@312: ret = Sizzle.find( parts.shift(), context, contextXML ); bgneal@312: context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0]; bgneal@312: } bgneal@312: bgneal@312: if ( context ) { bgneal@312: ret = seed ? bgneal@312: { expr: parts.pop(), set: makeArray(seed) } : bgneal@312: Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML ); bgneal@312: set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set; bgneal@312: bgneal@312: if ( parts.length > 0 ) { bgneal@312: checkSet = makeArray(set); bgneal@312: } else { bgneal@312: prune = false; bgneal@312: } bgneal@312: bgneal@312: while ( parts.length ) { bgneal@312: cur = parts.pop(); bgneal@312: pop = cur; bgneal@312: bgneal@312: if ( !Expr.relative[ cur ] ) { bgneal@312: cur = ""; bgneal@312: } else { bgneal@312: pop = parts.pop(); bgneal@312: } bgneal@312: bgneal@312: if ( pop == null ) { bgneal@312: pop = context; bgneal@312: } bgneal@312: bgneal@312: Expr.relative[ cur ]( checkSet, pop, contextXML ); bgneal@312: } bgneal@312: } else { bgneal@312: checkSet = parts = []; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if ( !checkSet ) { bgneal@312: checkSet = set; bgneal@312: } bgneal@312: bgneal@312: if ( !checkSet ) { bgneal@312: Sizzle.error( cur || selector ); bgneal@312: } bgneal@312: bgneal@312: if ( toString.call(checkSet) === "[object Array]" ) { bgneal@312: if ( !prune ) { bgneal@312: results.push.apply( results, checkSet ); bgneal@312: } else if ( context && context.nodeType === 1 ) { bgneal@312: for ( i = 0; checkSet[i] != null; i++ ) { bgneal@312: if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) { bgneal@312: results.push( set[i] ); bgneal@312: } bgneal@312: } bgneal@312: } else { bgneal@312: for ( i = 0; checkSet[i] != null; i++ ) { bgneal@312: if ( checkSet[i] && checkSet[i].nodeType === 1 ) { bgneal@312: results.push( set[i] ); bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: } else { bgneal@312: makeArray( checkSet, results ); bgneal@312: } bgneal@312: bgneal@312: if ( extra ) { bgneal@312: Sizzle( extra, origContext, results, seed ); bgneal@312: Sizzle.uniqueSort( results ); bgneal@312: } bgneal@312: bgneal@312: return results; bgneal@312: }; bgneal@312: bgneal@312: Sizzle.uniqueSort = function(results){ bgneal@312: if ( sortOrder ) { bgneal@312: hasDuplicate = baseHasDuplicate; bgneal@312: results.sort(sortOrder); bgneal@312: bgneal@312: if ( hasDuplicate ) { bgneal@312: for ( var i = 1; i < results.length; i++ ) { bgneal@312: if ( results[i] === results[i-1] ) { bgneal@312: results.splice(i--, 1); bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return results; bgneal@312: }; bgneal@312: bgneal@312: Sizzle.matches = function(expr, set){ bgneal@312: return Sizzle(expr, null, null, set); bgneal@312: }; bgneal@312: bgneal@312: Sizzle.find = function(expr, context, isXML){ bgneal@312: var set; bgneal@312: bgneal@312: if ( !expr ) { bgneal@312: return []; bgneal@312: } bgneal@312: bgneal@312: for ( var i = 0, l = Expr.order.length; i < l; i++ ) { bgneal@312: var type = Expr.order[i], match; bgneal@312: bgneal@312: if ( (match = Expr.leftMatch[ type ].exec( expr )) ) { bgneal@312: var left = match[1]; bgneal@312: match.splice(1,1); bgneal@312: bgneal@312: if ( left.substr( left.length - 1 ) !== "\\" ) { bgneal@312: match[1] = (match[1] || "").replace(/\\/g, ""); bgneal@312: set = Expr.find[ type ]( match, context, isXML ); bgneal@312: if ( set != null ) { bgneal@312: expr = expr.replace( Expr.match[ type ], "" ); bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if ( !set ) { bgneal@312: set = context.getElementsByTagName("*"); bgneal@312: } bgneal@312: bgneal@312: return {set: set, expr: expr}; bgneal@312: }; bgneal@312: bgneal@312: Sizzle.filter = function(expr, set, inplace, not){ bgneal@312: var old = expr, result = [], curLoop = set, match, anyFound, bgneal@312: isXMLFilter = set && set[0] && Sizzle.isXML(set[0]); bgneal@312: bgneal@312: while ( expr && set.length ) { bgneal@312: for ( var type in Expr.filter ) { bgneal@312: if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) { bgneal@312: var filter = Expr.filter[ type ], found, item, left = match[1]; bgneal@312: anyFound = false; bgneal@312: bgneal@312: match.splice(1,1); bgneal@312: bgneal@312: if ( left.substr( left.length - 1 ) === "\\" ) { bgneal@312: continue; bgneal@312: } bgneal@312: bgneal@312: if ( curLoop === result ) { bgneal@312: result = []; bgneal@312: } bgneal@312: bgneal@312: if ( Expr.preFilter[ type ] ) { bgneal@312: match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter ); bgneal@312: bgneal@312: if ( !match ) { bgneal@312: anyFound = found = true; bgneal@312: } else if ( match === true ) { bgneal@312: continue; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if ( match ) { bgneal@312: for ( var i = 0; (item = curLoop[i]) != null; i++ ) { bgneal@312: if ( item ) { bgneal@312: found = filter( item, match, i, curLoop ); bgneal@312: var pass = not ^ !!found; bgneal@312: bgneal@312: if ( inplace && found != null ) { bgneal@312: if ( pass ) { bgneal@312: anyFound = true; bgneal@312: } else { bgneal@312: curLoop[i] = false; bgneal@312: } bgneal@312: } else if ( pass ) { bgneal@312: result.push( item ); bgneal@312: anyFound = true; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if ( found !== undefined ) { bgneal@312: if ( !inplace ) { bgneal@312: curLoop = result; bgneal@312: } bgneal@312: bgneal@312: expr = expr.replace( Expr.match[ type ], "" ); bgneal@312: bgneal@312: if ( !anyFound ) { bgneal@312: return []; bgneal@312: } bgneal@312: bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Improper expression bgneal@312: if ( expr === old ) { bgneal@312: if ( anyFound == null ) { bgneal@312: Sizzle.error( expr ); bgneal@312: } else { bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: old = expr; bgneal@312: } bgneal@312: bgneal@312: return curLoop; bgneal@312: }; bgneal@312: bgneal@312: Sizzle.error = function( msg ) { bgneal@312: throw "Syntax error, unrecognized expression: " + msg; bgneal@312: }; bgneal@312: bgneal@312: var Expr = Sizzle.selectors = { bgneal@312: order: [ "ID", "NAME", "TAG" ], bgneal@312: match: { bgneal@312: ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, bgneal@312: CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, bgneal@312: NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/, bgneal@312: ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/, bgneal@312: TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/, bgneal@312: CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+\-]*)\))?/, bgneal@312: POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/, bgneal@312: PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/ bgneal@312: }, bgneal@312: leftMatch: {}, bgneal@312: attrMap: { bgneal@312: "class": "className", bgneal@312: "for": "htmlFor" bgneal@312: }, bgneal@312: attrHandle: { bgneal@312: href: function(elem){ bgneal@312: return elem.getAttribute("href"); bgneal@312: } bgneal@312: }, bgneal@312: relative: { bgneal@312: "+": function(checkSet, part){ bgneal@312: var isPartStr = typeof part === "string", bgneal@312: isTag = isPartStr && !/\W/.test(part), bgneal@312: isPartStrNotTag = isPartStr && !isTag; bgneal@312: bgneal@312: if ( isTag ) { bgneal@312: part = part.toLowerCase(); bgneal@312: } bgneal@312: bgneal@312: for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) { bgneal@312: if ( (elem = checkSet[i]) ) { bgneal@312: while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {} bgneal@312: bgneal@312: checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ? bgneal@312: elem || false : bgneal@312: elem === part; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if ( isPartStrNotTag ) { bgneal@312: Sizzle.filter( part, checkSet, true ); bgneal@312: } bgneal@312: }, bgneal@312: ">": function(checkSet, part){ bgneal@312: var isPartStr = typeof part === "string", bgneal@312: elem, i = 0, l = checkSet.length; bgneal@312: bgneal@312: if ( isPartStr && !/\W/.test(part) ) { bgneal@312: part = part.toLowerCase(); bgneal@312: bgneal@312: for ( ; i < l; i++ ) { bgneal@312: elem = checkSet[i]; bgneal@312: if ( elem ) { bgneal@312: var parent = elem.parentNode; bgneal@312: checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false; bgneal@312: } bgneal@312: } bgneal@312: } else { bgneal@312: for ( ; i < l; i++ ) { bgneal@312: elem = checkSet[i]; bgneal@312: if ( elem ) { bgneal@312: checkSet[i] = isPartStr ? bgneal@312: elem.parentNode : bgneal@312: elem.parentNode === part; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if ( isPartStr ) { bgneal@312: Sizzle.filter( part, checkSet, true ); bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: "": function(checkSet, part, isXML){ bgneal@312: var doneName = done++, checkFn = dirCheck, nodeCheck; bgneal@312: bgneal@312: if ( typeof part === "string" && !/\W/.test(part) ) { bgneal@312: part = part.toLowerCase(); bgneal@312: nodeCheck = part; bgneal@312: checkFn = dirNodeCheck; bgneal@312: } bgneal@312: bgneal@312: checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML); bgneal@312: }, bgneal@312: "~": function(checkSet, part, isXML){ bgneal@312: var doneName = done++, checkFn = dirCheck, nodeCheck; bgneal@312: bgneal@312: if ( typeof part === "string" && !/\W/.test(part) ) { bgneal@312: part = part.toLowerCase(); bgneal@312: nodeCheck = part; bgneal@312: checkFn = dirNodeCheck; bgneal@312: } bgneal@312: bgneal@312: checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML); bgneal@312: } bgneal@312: }, bgneal@312: find: { bgneal@312: ID: function(match, context, isXML){ bgneal@312: if ( typeof context.getElementById !== "undefined" && !isXML ) { bgneal@312: var m = context.getElementById(match[1]); bgneal@312: return m ? [m] : []; bgneal@312: } bgneal@312: }, bgneal@312: NAME: function(match, context){ bgneal@312: if ( typeof context.getElementsByName !== "undefined" ) { bgneal@312: var ret = [], results = context.getElementsByName(match[1]); bgneal@312: bgneal@312: for ( var i = 0, l = results.length; i < l; i++ ) { bgneal@312: if ( results[i].getAttribute("name") === match[1] ) { bgneal@312: ret.push( results[i] ); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return ret.length === 0 ? null : ret; bgneal@312: } bgneal@312: }, bgneal@312: TAG: function(match, context){ bgneal@312: return context.getElementsByTagName(match[1]); bgneal@312: } bgneal@312: }, bgneal@312: preFilter: { bgneal@312: CLASS: function(match, curLoop, inplace, result, not, isXML){ bgneal@312: match = " " + match[1].replace(/\\/g, "") + " "; bgneal@312: bgneal@312: if ( isXML ) { bgneal@312: return match; bgneal@312: } bgneal@312: bgneal@312: for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) { bgneal@312: if ( elem ) { bgneal@312: if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n]/g, " ").indexOf(match) >= 0) ) { bgneal@312: if ( !inplace ) { bgneal@312: result.push( elem ); bgneal@312: } bgneal@312: } else if ( inplace ) { bgneal@312: curLoop[i] = false; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return false; bgneal@312: }, bgneal@312: ID: function(match){ bgneal@312: return match[1].replace(/\\/g, ""); bgneal@312: }, bgneal@312: TAG: function(match, curLoop){ bgneal@312: return match[1].toLowerCase(); bgneal@312: }, bgneal@312: CHILD: function(match){ bgneal@312: if ( match[1] === "nth" ) { bgneal@312: // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' bgneal@312: var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec( bgneal@312: match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" || bgneal@312: !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]); bgneal@312: bgneal@312: // calculate the numbers (first)n+(last) including if they are negative bgneal@312: match[2] = (test[1] + (test[2] || 1)) - 0; bgneal@312: match[3] = test[3] - 0; bgneal@312: } bgneal@312: bgneal@312: // TODO: Move to normal caching system bgneal@312: match[0] = done++; bgneal@312: bgneal@312: return match; bgneal@312: }, bgneal@312: ATTR: function(match, curLoop, inplace, result, not, isXML){ bgneal@312: var name = match[1].replace(/\\/g, ""); bgneal@312: bgneal@312: if ( !isXML && Expr.attrMap[name] ) { bgneal@312: match[1] = Expr.attrMap[name]; bgneal@312: } bgneal@312: bgneal@312: if ( match[2] === "~=" ) { bgneal@312: match[4] = " " + match[4] + " "; bgneal@312: } bgneal@312: bgneal@312: return match; bgneal@312: }, bgneal@312: PSEUDO: function(match, curLoop, inplace, result, not){ bgneal@312: if ( match[1] === "not" ) { bgneal@312: // If we're dealing with a complex expression, or a simple one bgneal@312: if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) { bgneal@312: match[3] = Sizzle(match[3], null, null, curLoop); bgneal@312: } else { bgneal@312: var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not); bgneal@312: if ( !inplace ) { bgneal@312: result.push.apply( result, ret ); bgneal@312: } bgneal@312: return false; bgneal@312: } bgneal@312: } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) { bgneal@312: return true; bgneal@312: } bgneal@312: bgneal@312: return match; bgneal@312: }, bgneal@312: POS: function(match){ bgneal@312: match.unshift( true ); bgneal@312: return match; bgneal@312: } bgneal@312: }, bgneal@312: filters: { bgneal@312: enabled: function(elem){ bgneal@312: return elem.disabled === false && elem.type !== "hidden"; bgneal@312: }, bgneal@312: disabled: function(elem){ bgneal@312: return elem.disabled === true; bgneal@312: }, bgneal@312: checked: function(elem){ bgneal@312: return elem.checked === true; bgneal@312: }, bgneal@312: selected: function(elem){ bgneal@312: // Accessing this property makes selected-by-default bgneal@312: // options in Safari work properly bgneal@312: elem.parentNode.selectedIndex; bgneal@312: return elem.selected === true; bgneal@312: }, bgneal@312: parent: function(elem){ bgneal@312: return !!elem.firstChild; bgneal@312: }, bgneal@312: empty: function(elem){ bgneal@312: return !elem.firstChild; bgneal@312: }, bgneal@312: has: function(elem, i, match){ bgneal@312: return !!Sizzle( match[3], elem ).length; bgneal@312: }, bgneal@312: header: function(elem){ bgneal@312: return (/h\d/i).test( elem.nodeName ); bgneal@312: }, bgneal@312: text: function(elem){ bgneal@312: return "text" === elem.type; bgneal@312: }, bgneal@312: radio: function(elem){ bgneal@312: return "radio" === elem.type; bgneal@312: }, bgneal@312: checkbox: function(elem){ bgneal@312: return "checkbox" === elem.type; bgneal@312: }, bgneal@312: file: function(elem){ bgneal@312: return "file" === elem.type; bgneal@312: }, bgneal@312: password: function(elem){ bgneal@312: return "password" === elem.type; bgneal@312: }, bgneal@312: submit: function(elem){ bgneal@312: return "submit" === elem.type; bgneal@312: }, bgneal@312: image: function(elem){ bgneal@312: return "image" === elem.type; bgneal@312: }, bgneal@312: reset: function(elem){ bgneal@312: return "reset" === elem.type; bgneal@312: }, bgneal@312: button: function(elem){ bgneal@312: return "button" === elem.type || elem.nodeName.toLowerCase() === "button"; bgneal@312: }, bgneal@312: input: function(elem){ bgneal@312: return (/input|select|textarea|button/i).test(elem.nodeName); bgneal@312: } bgneal@312: }, bgneal@312: setFilters: { bgneal@312: first: function(elem, i){ bgneal@312: return i === 0; bgneal@312: }, bgneal@312: last: function(elem, i, match, array){ bgneal@312: return i === array.length - 1; bgneal@312: }, bgneal@312: even: function(elem, i){ bgneal@312: return i % 2 === 0; bgneal@312: }, bgneal@312: odd: function(elem, i){ bgneal@312: return i % 2 === 1; bgneal@312: }, bgneal@312: lt: function(elem, i, match){ bgneal@312: return i < match[3] - 0; bgneal@312: }, bgneal@312: gt: function(elem, i, match){ bgneal@312: return i > match[3] - 0; bgneal@312: }, bgneal@312: nth: function(elem, i, match){ bgneal@312: return match[3] - 0 === i; bgneal@312: }, bgneal@312: eq: function(elem, i, match){ bgneal@312: return match[3] - 0 === i; bgneal@312: } bgneal@312: }, bgneal@312: filter: { bgneal@312: PSEUDO: function(elem, match, i, array){ bgneal@312: var name = match[1], filter = Expr.filters[ name ]; bgneal@312: bgneal@312: if ( filter ) { bgneal@312: return filter( elem, i, match, array ); bgneal@312: } else if ( name === "contains" ) { bgneal@312: return (elem.textContent || elem.innerText || Sizzle.getText([ elem ]) || "").indexOf(match[3]) >= 0; bgneal@312: } else if ( name === "not" ) { bgneal@312: var not = match[3]; bgneal@312: bgneal@312: for ( var j = 0, l = not.length; j < l; j++ ) { bgneal@312: if ( not[j] === elem ) { bgneal@312: return false; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return true; bgneal@312: } else { bgneal@312: Sizzle.error( "Syntax error, unrecognized expression: " + name ); bgneal@312: } bgneal@312: }, bgneal@312: CHILD: function(elem, match){ bgneal@312: var type = match[1], node = elem; bgneal@312: switch (type) { bgneal@312: case 'only': bgneal@312: case 'first': bgneal@312: while ( (node = node.previousSibling) ) { bgneal@312: if ( node.nodeType === 1 ) { bgneal@312: return false; bgneal@312: } bgneal@312: } bgneal@312: if ( type === "first" ) { bgneal@312: return true; bgneal@312: } bgneal@312: node = elem; bgneal@312: case 'last': bgneal@312: while ( (node = node.nextSibling) ) { bgneal@312: if ( node.nodeType === 1 ) { bgneal@312: return false; bgneal@312: } bgneal@312: } bgneal@312: return true; bgneal@312: case 'nth': bgneal@312: var first = match[2], last = match[3]; bgneal@312: bgneal@312: if ( first === 1 && last === 0 ) { bgneal@312: return true; bgneal@312: } bgneal@312: bgneal@312: var doneName = match[0], bgneal@312: parent = elem.parentNode; bgneal@312: bgneal@312: if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) { bgneal@312: var count = 0; bgneal@312: for ( node = parent.firstChild; node; node = node.nextSibling ) { bgneal@312: if ( node.nodeType === 1 ) { bgneal@312: node.nodeIndex = ++count; bgneal@312: } bgneal@312: } bgneal@312: parent.sizcache = doneName; bgneal@312: } bgneal@312: bgneal@312: var diff = elem.nodeIndex - last; bgneal@312: if ( first === 0 ) { bgneal@312: return diff === 0; bgneal@312: } else { bgneal@312: return ( diff % first === 0 && diff / first >= 0 ); bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: ID: function(elem, match){ bgneal@312: return elem.nodeType === 1 && elem.getAttribute("id") === match; bgneal@312: }, bgneal@312: TAG: function(elem, match){ bgneal@312: return (match === "*" && elem.nodeType === 1) || elem.nodeName.toLowerCase() === match; bgneal@312: }, bgneal@312: CLASS: function(elem, match){ bgneal@312: return (" " + (elem.className || elem.getAttribute("class")) + " ") bgneal@312: .indexOf( match ) > -1; bgneal@312: }, bgneal@312: ATTR: function(elem, match){ bgneal@312: var name = match[1], bgneal@312: result = Expr.attrHandle[ name ] ? bgneal@312: Expr.attrHandle[ name ]( elem ) : bgneal@312: elem[ name ] != null ? bgneal@312: elem[ name ] : bgneal@312: elem.getAttribute( name ), bgneal@312: value = result + "", bgneal@312: type = match[2], bgneal@312: check = match[4]; bgneal@312: bgneal@312: return result == null ? bgneal@312: type === "!=" : bgneal@312: type === "=" ? bgneal@312: value === check : bgneal@312: type === "*=" ? bgneal@312: value.indexOf(check) >= 0 : bgneal@312: type === "~=" ? bgneal@312: (" " + value + " ").indexOf(check) >= 0 : bgneal@312: !check ? bgneal@312: value && result !== false : bgneal@312: type === "!=" ? bgneal@312: value !== check : bgneal@312: type === "^=" ? bgneal@312: value.indexOf(check) === 0 : bgneal@312: type === "$=" ? bgneal@312: value.substr(value.length - check.length) === check : bgneal@312: type === "|=" ? bgneal@312: value === check || value.substr(0, check.length + 1) === check + "-" : bgneal@312: false; bgneal@312: }, bgneal@312: POS: function(elem, match, i, array){ bgneal@312: var name = match[2], filter = Expr.setFilters[ name ]; bgneal@312: bgneal@312: if ( filter ) { bgneal@312: return filter( elem, i, match, array ); bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: var origPOS = Expr.match.POS, bgneal@312: fescape = function(all, num){ bgneal@312: return "\\" + (num - 0 + 1); bgneal@312: }; bgneal@312: bgneal@312: for ( var type in Expr.match ) { bgneal@312: Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) ); bgneal@312: Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) ); bgneal@312: } bgneal@312: bgneal@312: var makeArray = function(array, results) { bgneal@312: array = Array.prototype.slice.call( array, 0 ); bgneal@312: bgneal@312: if ( results ) { bgneal@312: results.push.apply( results, array ); bgneal@312: return results; bgneal@312: } bgneal@312: bgneal@312: return array; bgneal@312: }; bgneal@312: bgneal@312: // Perform a simple check to determine if the browser is capable of bgneal@312: // converting a NodeList to an array using builtin methods. bgneal@312: // Also verifies that the returned array holds DOM nodes bgneal@312: // (which is not the case in the Blackberry browser) bgneal@312: try { bgneal@312: Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType; bgneal@312: bgneal@312: // Provide a fallback method if it does not work bgneal@312: } catch(e){ bgneal@312: makeArray = function(array, results) { bgneal@312: var ret = results || [], i = 0; bgneal@312: bgneal@312: if ( toString.call(array) === "[object Array]" ) { bgneal@312: Array.prototype.push.apply( ret, array ); bgneal@312: } else { bgneal@312: if ( typeof array.length === "number" ) { bgneal@312: for ( var l = array.length; i < l; i++ ) { bgneal@312: ret.push( array[i] ); bgneal@312: } bgneal@312: } else { bgneal@312: for ( ; array[i]; i++ ) { bgneal@312: ret.push( array[i] ); bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return ret; bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: var sortOrder; bgneal@312: bgneal@312: if ( document.documentElement.compareDocumentPosition ) { bgneal@312: sortOrder = function( a, b ) { bgneal@312: if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) { bgneal@312: if ( a == b ) { bgneal@312: hasDuplicate = true; bgneal@312: } bgneal@312: return a.compareDocumentPosition ? -1 : 1; bgneal@312: } bgneal@312: bgneal@312: var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1; bgneal@312: if ( ret === 0 ) { bgneal@312: hasDuplicate = true; bgneal@312: } bgneal@312: return ret; bgneal@312: }; bgneal@312: } else if ( "sourceIndex" in document.documentElement ) { bgneal@312: sortOrder = function( a, b ) { bgneal@312: if ( !a.sourceIndex || !b.sourceIndex ) { bgneal@312: if ( a == b ) { bgneal@312: hasDuplicate = true; bgneal@312: } bgneal@312: return a.sourceIndex ? -1 : 1; bgneal@312: } bgneal@312: bgneal@312: var ret = a.sourceIndex - b.sourceIndex; bgneal@312: if ( ret === 0 ) { bgneal@312: hasDuplicate = true; bgneal@312: } bgneal@312: return ret; bgneal@312: }; bgneal@312: } else if ( document.createRange ) { bgneal@312: sortOrder = function( a, b ) { bgneal@312: if ( !a.ownerDocument || !b.ownerDocument ) { bgneal@312: if ( a == b ) { bgneal@312: hasDuplicate = true; bgneal@312: } bgneal@312: return a.ownerDocument ? -1 : 1; bgneal@312: } bgneal@312: bgneal@312: var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange(); bgneal@312: aRange.setStart(a, 0); bgneal@312: aRange.setEnd(a, 0); bgneal@312: bRange.setStart(b, 0); bgneal@312: bRange.setEnd(b, 0); bgneal@312: var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange); bgneal@312: if ( ret === 0 ) { bgneal@312: hasDuplicate = true; bgneal@312: } bgneal@312: return ret; bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: // Utility function for retreiving the text value of an array of DOM nodes bgneal@312: Sizzle.getText = function( elems ) { bgneal@312: var ret = "", elem; bgneal@312: bgneal@312: for ( var i = 0; elems[i]; i++ ) { bgneal@312: elem = elems[i]; bgneal@312: bgneal@312: // Get the text from text nodes and CDATA nodes bgneal@312: if ( elem.nodeType === 3 || elem.nodeType === 4 ) { bgneal@312: ret += elem.nodeValue; bgneal@312: bgneal@312: // Traverse everything else, except comment nodes bgneal@312: } else if ( elem.nodeType !== 8 ) { bgneal@312: ret += Sizzle.getText( elem.childNodes ); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return ret; bgneal@312: }; bgneal@312: bgneal@312: // Check to see if the browser returns elements by name when bgneal@312: // querying by getElementById (and provide a workaround) bgneal@312: (function(){ bgneal@312: // We're going to inject a fake input element with a specified name bgneal@312: var form = document.createElement("div"), bgneal@312: id = "script" + (new Date()).getTime(); bgneal@312: form.innerHTML = ""; bgneal@312: bgneal@312: // Inject it into the root element, check its status, and remove it quickly bgneal@312: var root = document.documentElement; bgneal@312: root.insertBefore( form, root.firstChild ); bgneal@312: bgneal@312: // The workaround has to do additional checks after a getElementById bgneal@312: // Which slows things down for other browsers (hence the branching) bgneal@312: if ( document.getElementById( id ) ) { bgneal@312: Expr.find.ID = function(match, context, isXML){ bgneal@312: if ( typeof context.getElementById !== "undefined" && !isXML ) { bgneal@312: var m = context.getElementById(match[1]); bgneal@312: return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : []; bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: Expr.filter.ID = function(elem, match){ bgneal@312: var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id"); bgneal@312: return elem.nodeType === 1 && node && node.nodeValue === match; bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: root.removeChild( form ); bgneal@312: root = form = null; // release memory in IE bgneal@312: })(); bgneal@312: bgneal@312: (function(){ bgneal@312: // Check to see if the browser returns only elements bgneal@312: // when doing getElementsByTagName("*") bgneal@312: bgneal@312: // Create a fake element bgneal@312: var div = document.createElement("div"); bgneal@312: div.appendChild( document.createComment("") ); bgneal@312: bgneal@312: // Make sure no comments are found bgneal@312: if ( div.getElementsByTagName("*").length > 0 ) { bgneal@312: Expr.find.TAG = function(match, context){ bgneal@312: var results = context.getElementsByTagName(match[1]); bgneal@312: bgneal@312: // Filter out possible comments bgneal@312: if ( match[1] === "*" ) { bgneal@312: var tmp = []; bgneal@312: bgneal@312: for ( var i = 0; results[i]; i++ ) { bgneal@312: if ( results[i].nodeType === 1 ) { bgneal@312: tmp.push( results[i] ); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: results = tmp; bgneal@312: } bgneal@312: bgneal@312: return results; bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: // Check to see if an attribute returns normalized href attributes bgneal@312: div.innerHTML = ""; bgneal@312: if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" && bgneal@312: div.firstChild.getAttribute("href") !== "#" ) { bgneal@312: Expr.attrHandle.href = function(elem){ bgneal@312: return elem.getAttribute("href", 2); bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: div = null; // release memory in IE bgneal@312: })(); bgneal@312: bgneal@312: if ( document.querySelectorAll ) { bgneal@312: (function(){ bgneal@312: var oldSizzle = Sizzle, div = document.createElement("div"); bgneal@312: div.innerHTML = "

    "; bgneal@312: bgneal@312: // Safari can't handle uppercase or unicode characters when bgneal@312: // in quirks mode. bgneal@312: if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) { bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: Sizzle = function(query, context, extra, seed){ bgneal@312: context = context || document; bgneal@312: bgneal@312: // Only use querySelectorAll on non-XML documents bgneal@312: // (ID selectors don't work in non-HTML documents) bgneal@312: if ( !seed && context.nodeType === 9 && !Sizzle.isXML(context) ) { bgneal@312: try { bgneal@312: return makeArray( context.querySelectorAll(query), extra ); bgneal@312: } catch(e){} bgneal@312: } bgneal@312: bgneal@312: return oldSizzle(query, context, extra, seed); bgneal@312: }; bgneal@312: bgneal@312: for ( var prop in oldSizzle ) { bgneal@312: Sizzle[ prop ] = oldSizzle[ prop ]; bgneal@312: } bgneal@312: bgneal@312: div = null; // release memory in IE bgneal@312: })(); bgneal@312: } bgneal@312: bgneal@312: (function(){ bgneal@312: var div = document.createElement("div"); bgneal@312: bgneal@312: div.innerHTML = "
    "; bgneal@312: bgneal@312: // Opera can't find a second classname (in 9.6) bgneal@312: // Also, make sure that getElementsByClassName actually exists bgneal@312: if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) { bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Safari caches class attributes, doesn't catch changes (in 3.2) bgneal@312: div.lastChild.className = "e"; bgneal@312: bgneal@312: if ( div.getElementsByClassName("e").length === 1 ) { bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: Expr.order.splice(1, 0, "CLASS"); bgneal@312: Expr.find.CLASS = function(match, context, isXML) { bgneal@312: if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) { bgneal@312: return context.getElementsByClassName(match[1]); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: div = null; // release memory in IE bgneal@312: })(); bgneal@312: bgneal@312: function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { bgneal@312: for ( var i = 0, l = checkSet.length; i < l; i++ ) { bgneal@312: var elem = checkSet[i]; bgneal@312: if ( elem ) { bgneal@312: elem = elem[dir]; bgneal@312: var match = false; bgneal@312: bgneal@312: while ( elem ) { bgneal@312: if ( elem.sizcache === doneName ) { bgneal@312: match = checkSet[elem.sizset]; bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: if ( elem.nodeType === 1 && !isXML ){ bgneal@312: elem.sizcache = doneName; bgneal@312: elem.sizset = i; bgneal@312: } bgneal@312: bgneal@312: if ( elem.nodeName.toLowerCase() === cur ) { bgneal@312: match = elem; bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: elem = elem[dir]; bgneal@312: } bgneal@312: bgneal@312: checkSet[i] = match; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { bgneal@312: for ( var i = 0, l = checkSet.length; i < l; i++ ) { bgneal@312: var elem = checkSet[i]; bgneal@312: if ( elem ) { bgneal@312: elem = elem[dir]; bgneal@312: var match = false; bgneal@312: bgneal@312: while ( elem ) { bgneal@312: if ( elem.sizcache === doneName ) { bgneal@312: match = checkSet[elem.sizset]; bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: if ( elem.nodeType === 1 ) { bgneal@312: if ( !isXML ) { bgneal@312: elem.sizcache = doneName; bgneal@312: elem.sizset = i; bgneal@312: } bgneal@312: if ( typeof cur !== "string" ) { bgneal@312: if ( elem === cur ) { bgneal@312: match = true; bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) { bgneal@312: match = elem; bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: elem = elem[dir]; bgneal@312: } bgneal@312: bgneal@312: checkSet[i] = match; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: Sizzle.contains = document.compareDocumentPosition ? function(a, b){ bgneal@312: return !!(a.compareDocumentPosition(b) & 16); bgneal@312: } : function(a, b){ bgneal@312: return a !== b && (a.contains ? a.contains(b) : true); bgneal@312: }; bgneal@312: bgneal@312: Sizzle.isXML = function(elem){ bgneal@312: // documentElement is verified for cases where it doesn't yet exist bgneal@312: // (such as loading iframes in IE - #4833) bgneal@312: var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement; bgneal@312: return documentElement ? documentElement.nodeName !== "HTML" : false; bgneal@312: }; bgneal@312: bgneal@312: var posProcess = function(selector, context){ bgneal@312: var tmpSet = [], later = "", match, bgneal@312: root = context.nodeType ? [context] : context; bgneal@312: bgneal@312: // Position selectors must be done after the filter bgneal@312: // And so must :not(positional) so we move all PSEUDOs to the end bgneal@312: while ( (match = Expr.match.PSEUDO.exec( selector )) ) { bgneal@312: later += match[0]; bgneal@312: selector = selector.replace( Expr.match.PSEUDO, "" ); bgneal@312: } bgneal@312: bgneal@312: selector = Expr.relative[selector] ? selector + "*" : selector; bgneal@312: bgneal@312: for ( var i = 0, l = root.length; i < l; i++ ) { bgneal@312: Sizzle( selector, root[i], tmpSet ); bgneal@312: } bgneal@312: bgneal@312: return Sizzle.filter( later, tmpSet ); bgneal@312: }; bgneal@312: bgneal@312: // EXPOSE bgneal@312: bgneal@312: window.tinymce.dom.Sizzle = Sizzle; bgneal@312: bgneal@312: })(); bgneal@312: bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: // Shorten names bgneal@312: var each = tinymce.each, DOM = tinymce.DOM, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, Event; bgneal@312: bgneal@312: tinymce.create('tinymce.dom.EventUtils', { bgneal@312: EventUtils : function() { bgneal@312: this.inits = []; bgneal@312: this.events = []; bgneal@312: }, bgneal@312: bgneal@312: add : function(o, n, f, s) { bgneal@312: var cb, t = this, el = t.events, r; bgneal@312: bgneal@312: if (n instanceof Array) { bgneal@312: r = []; bgneal@312: bgneal@312: each(n, function(n) { bgneal@312: r.push(t.add(o, n, f, s)); bgneal@312: }); bgneal@312: bgneal@312: return r; bgneal@312: } bgneal@312: bgneal@312: // Handle array bgneal@312: if (o && o.hasOwnProperty && o instanceof Array) { bgneal@312: r = []; bgneal@312: bgneal@312: each(o, function(o) { bgneal@312: o = DOM.get(o); bgneal@312: r.push(t.add(o, n, f, s)); bgneal@312: }); bgneal@312: bgneal@312: return r; bgneal@312: } bgneal@312: bgneal@312: o = DOM.get(o); bgneal@312: bgneal@312: if (!o) bgneal@312: return; bgneal@312: bgneal@312: // Setup event callback bgneal@312: cb = function(e) { bgneal@312: // Is all events disabled bgneal@312: if (t.disabled) bgneal@312: return; bgneal@312: bgneal@312: e = e || window.event; bgneal@312: bgneal@312: // Patch in target, preventDefault and stopPropagation in IE it's W3C valid bgneal@312: if (e && isIE) { bgneal@312: if (!e.target) bgneal@312: e.target = e.srcElement; bgneal@312: bgneal@312: // Patch in preventDefault, stopPropagation methods for W3C compatibility bgneal@312: tinymce.extend(e, t._stoppers); bgneal@312: } bgneal@312: bgneal@312: if (!s) bgneal@312: return f(e); bgneal@312: bgneal@312: return f.call(s, e); bgneal@312: }; bgneal@312: bgneal@312: if (n == 'unload') { bgneal@312: tinymce.unloads.unshift({func : cb}); bgneal@312: return cb; bgneal@312: } bgneal@312: bgneal@312: if (n == 'init') { bgneal@312: if (t.domLoaded) bgneal@312: cb(); bgneal@312: else bgneal@312: t.inits.push(cb); bgneal@312: bgneal@312: return cb; bgneal@312: } bgneal@312: bgneal@312: // Store away listener reference bgneal@312: el.push({ bgneal@312: obj : o, bgneal@312: name : n, bgneal@312: func : f, bgneal@312: cfunc : cb, bgneal@312: scope : s bgneal@312: }); bgneal@312: bgneal@312: t._add(o, n, cb); bgneal@312: bgneal@312: return f; bgneal@312: }, bgneal@312: bgneal@312: remove : function(o, n, f) { bgneal@312: var t = this, a = t.events, s = false, r; bgneal@312: bgneal@312: // Handle array bgneal@312: if (o && o.hasOwnProperty && o instanceof Array) { bgneal@312: r = []; bgneal@312: bgneal@312: each(o, function(o) { bgneal@312: o = DOM.get(o); bgneal@312: r.push(t.remove(o, n, f)); bgneal@312: }); bgneal@312: bgneal@312: return r; bgneal@312: } bgneal@312: bgneal@312: o = DOM.get(o); bgneal@312: bgneal@312: each(a, function(e, i) { bgneal@312: if (e.obj == o && e.name == n && (!f || (e.func == f || e.cfunc == f))) { bgneal@312: a.splice(i, 1); bgneal@312: t._remove(o, n, e.cfunc); bgneal@312: s = true; bgneal@312: return false; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: return s; bgneal@312: }, bgneal@312: bgneal@312: clear : function(o) { bgneal@312: var t = this, a = t.events, i, e; bgneal@312: bgneal@312: if (o) { bgneal@312: o = DOM.get(o); bgneal@312: bgneal@312: for (i = a.length - 1; i >= 0; i--) { bgneal@312: e = a[i]; bgneal@312: bgneal@312: if (e.obj === o) { bgneal@312: t._remove(e.obj, e.name, e.cfunc); bgneal@312: e.obj = e.cfunc = null; bgneal@312: a.splice(i, 1); bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: cancel : function(e) { bgneal@312: if (!e) bgneal@312: return false; bgneal@312: bgneal@312: this.stop(e); bgneal@312: bgneal@312: return this.prevent(e); bgneal@312: }, bgneal@312: bgneal@312: stop : function(e) { bgneal@312: if (e.stopPropagation) bgneal@312: e.stopPropagation(); bgneal@312: else bgneal@312: e.cancelBubble = true; bgneal@312: bgneal@312: return false; bgneal@312: }, bgneal@312: bgneal@312: prevent : function(e) { bgneal@312: if (e.preventDefault) bgneal@312: e.preventDefault(); bgneal@312: else bgneal@312: e.returnValue = false; bgneal@312: bgneal@312: return false; bgneal@312: }, bgneal@312: bgneal@312: destroy : function() { bgneal@312: var t = this; bgneal@312: bgneal@312: each(t.events, function(e, i) { bgneal@312: t._remove(e.obj, e.name, e.cfunc); bgneal@312: e.obj = e.cfunc = null; bgneal@312: }); bgneal@312: bgneal@312: t.events = []; bgneal@312: t = null; bgneal@312: }, bgneal@312: bgneal@312: _add : function(o, n, f) { bgneal@312: if (o.attachEvent) bgneal@312: o.attachEvent('on' + n, f); bgneal@312: else if (o.addEventListener) bgneal@312: o.addEventListener(n, f, false); bgneal@312: else bgneal@312: o['on' + n] = f; bgneal@312: }, bgneal@312: bgneal@312: _remove : function(o, n, f) { bgneal@312: if (o) { bgneal@312: try { bgneal@312: if (o.detachEvent) bgneal@312: o.detachEvent('on' + n, f); bgneal@312: else if (o.removeEventListener) bgneal@312: o.removeEventListener(n, f, false); bgneal@312: else bgneal@312: o['on' + n] = null; bgneal@312: } catch (ex) { bgneal@312: // Might fail with permission denined on IE so we just ignore that bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: _pageInit : function(win) { bgneal@312: var t = this; bgneal@312: bgneal@312: // Keep it from running more than once bgneal@312: if (t.domLoaded) bgneal@312: return; bgneal@312: bgneal@312: t.domLoaded = true; bgneal@312: bgneal@312: each(t.inits, function(c) { bgneal@312: c(); bgneal@312: }); bgneal@312: bgneal@312: t.inits = []; bgneal@312: }, bgneal@312: bgneal@312: _wait : function(win) { bgneal@312: var t = this, doc = win.document; bgneal@312: bgneal@312: // No need since the document is already loaded bgneal@312: if (win.tinyMCE_GZ && tinyMCE_GZ.loaded) { bgneal@312: t.domLoaded = 1; bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Use IE method bgneal@312: if (doc.attachEvent) { bgneal@312: doc.attachEvent("onreadystatechange", function() { bgneal@312: if (doc.readyState === "complete") { bgneal@312: doc.detachEvent("onreadystatechange", arguments.callee); bgneal@312: t._pageInit(win); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: if (doc.documentElement.doScroll && win == win.top) { bgneal@312: (function() { bgneal@312: if (t.domLoaded) bgneal@312: return; bgneal@312: bgneal@312: try { bgneal@312: // If IE is used, use the trick by Diego Perini bgneal@312: // http://javascript.nwbox.com/IEContentLoaded/ bgneal@312: doc.documentElement.doScroll("left"); bgneal@312: } catch (ex) { bgneal@312: setTimeout(arguments.callee, 0); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: t._pageInit(win); bgneal@312: })(); bgneal@312: } bgneal@312: } else if (doc.addEventListener) { bgneal@312: t._add(win, 'DOMContentLoaded', function() { bgneal@312: t._pageInit(win); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: t._add(win, 'load', function() { bgneal@312: t._pageInit(win); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: _stoppers : { bgneal@442: preventDefault : function() { bgneal@312: this.returnValue = false; bgneal@312: }, bgneal@312: bgneal@312: stopPropagation : function() { bgneal@312: this.cancelBubble = true; bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: Event = tinymce.dom.Event = new tinymce.dom.EventUtils(); bgneal@312: bgneal@312: // Dispatch DOM content loaded event for IE and Safari bgneal@312: Event._wait(window); bgneal@312: bgneal@312: tinymce.addUnload(function() { bgneal@312: Event.destroy(); bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: tinymce.dom.Element = function(id, settings) { bgneal@312: var t = this, dom, el; bgneal@312: bgneal@312: t.settings = settings = settings || {}; bgneal@312: t.id = id; bgneal@312: t.dom = dom = settings.dom || tinymce.DOM; bgneal@312: bgneal@312: // Only IE leaks DOM references, this is a lot faster bgneal@312: if (!tinymce.isIE) bgneal@312: el = dom.get(t.id); bgneal@312: bgneal@312: tinymce.each( bgneal@312: ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' + bgneal@312: 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' + bgneal@312: 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' + bgneal@312: 'isHidden,setHTML,get').split(/,/) bgneal@312: , function(k) { bgneal@312: t[k] = function() { bgneal@312: var a = [id], i; bgneal@312: bgneal@312: for (i = 0; i < arguments.length; i++) bgneal@312: a.push(arguments[i]); bgneal@312: bgneal@312: a = dom[k].apply(dom, a); bgneal@312: t.update(k); bgneal@312: bgneal@312: return a; bgneal@312: }; bgneal@312: }); bgneal@312: bgneal@312: tinymce.extend(t, { bgneal@312: on : function(n, f, s) { bgneal@312: return tinymce.dom.Event.add(t.id, n, f, s); bgneal@312: }, bgneal@312: bgneal@312: getXY : function() { bgneal@312: return { bgneal@312: x : parseInt(t.getStyle('left')), bgneal@312: y : parseInt(t.getStyle('top')) bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: getSize : function() { bgneal@312: var n = dom.get(t.id); bgneal@312: bgneal@312: return { bgneal@312: w : parseInt(t.getStyle('width') || n.clientWidth), bgneal@312: h : parseInt(t.getStyle('height') || n.clientHeight) bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: moveTo : function(x, y) { bgneal@312: t.setStyles({left : x, top : y}); bgneal@312: }, bgneal@312: bgneal@312: moveBy : function(x, y) { bgneal@312: var p = t.getXY(); bgneal@312: bgneal@312: t.moveTo(p.x + x, p.y + y); bgneal@312: }, bgneal@312: bgneal@312: resizeTo : function(w, h) { bgneal@312: t.setStyles({width : w, height : h}); bgneal@312: }, bgneal@312: bgneal@312: resizeBy : function(w, h) { bgneal@312: var s = t.getSize(); bgneal@312: bgneal@312: t.resizeTo(s.w + w, s.h + h); bgneal@312: }, bgneal@312: bgneal@312: update : function(k) { bgneal@312: var b; bgneal@312: bgneal@312: if (tinymce.isIE6 && settings.blocker) { bgneal@312: k = k || ''; bgneal@312: bgneal@312: // Ignore getters bgneal@312: if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0) bgneal@312: return; bgneal@312: bgneal@312: // Remove blocker on remove bgneal@312: if (k == 'remove') { bgneal@312: dom.remove(t.blocker); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: if (!t.blocker) { bgneal@312: t.blocker = dom.uniqueId(); bgneal@312: b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'}); bgneal@312: dom.setStyle(b, 'opacity', 0); bgneal@312: } else bgneal@312: b = dom.get(t.blocker); bgneal@312: bgneal@312: dom.setStyles(b, { bgneal@312: left : t.getStyle('left', 1), bgneal@312: top : t.getStyle('top', 1), bgneal@312: width : t.getStyle('width', 1), bgneal@312: height : t.getStyle('height', 1), bgneal@312: display : t.getStyle('display', 1), bgneal@312: zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1 bgneal@312: }); bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: }; bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: function trimNl(s) { bgneal@312: return s.replace(/[\n\r]+/g, ''); bgneal@312: }; bgneal@312: bgneal@312: // Shorten names bgneal@312: var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each; bgneal@312: bgneal@312: tinymce.create('tinymce.dom.Selection', { bgneal@312: Selection : function(dom, win, serializer) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.dom = dom; bgneal@312: t.win = win; bgneal@312: t.serializer = serializer; bgneal@312: bgneal@312: // Add events bgneal@312: each([ bgneal@312: 'onBeforeSetContent', bgneal@442: bgneal@312: 'onBeforeGetContent', bgneal@442: bgneal@312: 'onSetContent', bgneal@442: bgneal@312: 'onGetContent' bgneal@312: ], function(e) { bgneal@312: t[e] = new tinymce.util.Dispatcher(t); bgneal@312: }); bgneal@312: bgneal@312: // No W3C Range support bgneal@312: if (!t.win.getSelection) bgneal@312: t.tridentSel = new tinymce.dom.TridentSelection(t); bgneal@312: bgneal@442: if (tinymce.isIE && dom.boxModel) bgneal@442: this._fixIESelection(); bgneal@442: bgneal@312: // Prevent leaks bgneal@312: tinymce.addUnload(t.destroy, t); bgneal@312: }, bgneal@312: bgneal@312: getContent : function(s) { bgneal@312: var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n; bgneal@312: bgneal@312: s = s || {}; bgneal@312: wb = wa = ''; bgneal@312: s.get = true; bgneal@312: s.format = s.format || 'html'; bgneal@312: t.onBeforeGetContent.dispatch(t, s); bgneal@312: bgneal@312: if (s.format == 'text') bgneal@312: return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : '')); bgneal@312: bgneal@312: if (r.cloneContents) { bgneal@312: n = r.cloneContents(); bgneal@312: bgneal@312: if (n) bgneal@312: e.appendChild(n); bgneal@312: } else if (is(r.item) || is(r.htmlText)) bgneal@312: e.innerHTML = r.item ? r.item(0).outerHTML : r.htmlText; bgneal@312: else bgneal@312: e.innerHTML = r.toString(); bgneal@312: bgneal@312: // Keep whitespace before and after bgneal@312: if (/^\s/.test(e.innerHTML)) bgneal@312: wb = ' '; bgneal@312: bgneal@312: if (/\s+$/.test(e.innerHTML)) bgneal@312: wa = ' '; bgneal@312: bgneal@312: s.getInner = true; bgneal@312: bgneal@312: s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa; bgneal@312: t.onGetContent.dispatch(t, s); bgneal@312: bgneal@312: return s.content; bgneal@312: }, bgneal@312: bgneal@442: setContent : function(content, args) { bgneal@442: var self = this, rng = self.getRng(), caretNode, doc = self.win.document, frag, temp; bgneal@442: bgneal@442: args = args || {format : 'html'}; bgneal@442: args.set = true; bgneal@442: content = args.content = content; bgneal@312: bgneal@312: // Dispatch before set content event bgneal@442: if (!args.no_events) bgneal@442: self.onBeforeSetContent.dispatch(self, args); bgneal@442: bgneal@442: content = args.content; bgneal@442: bgneal@442: if (rng.insertNode) { bgneal@312: // Make caret marker since insertNode places the caret in the beginning of text after insert bgneal@442: content += '_'; bgneal@312: bgneal@312: // Delete and insert new node bgneal@442: if (rng.startContainer == doc && rng.endContainer == doc) { bgneal@312: // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents bgneal@442: doc.body.innerHTML = content; bgneal@312: } else { bgneal@442: rng.deleteContents(); bgneal@442: bgneal@442: if (doc.body.childNodes.length == 0) { bgneal@442: doc.body.innerHTML = content; bgneal@312: } else { bgneal@442: // createContextualFragment doesn't exists in IE 9 DOMRanges bgneal@442: if (rng.createContextualFragment) { bgneal@442: rng.insertNode(rng.createContextualFragment(content)); bgneal@442: } else { bgneal@442: // Fake createContextualFragment call in IE 9 bgneal@442: frag = doc.createDocumentFragment(); bgneal@442: temp = doc.createElement('div'); bgneal@442: bgneal@442: frag.appendChild(temp); bgneal@442: temp.outerHTML = content; bgneal@442: bgneal@442: rng.insertNode(frag); bgneal@442: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Move to caret marker bgneal@442: caretNode = self.dom.get('__caret'); bgneal@442: bgneal@312: // Make sure we wrap it compleatly, Opera fails with a simple select call bgneal@442: rng = doc.createRange(); bgneal@442: rng.setStartBefore(caretNode); bgneal@442: rng.setEndBefore(caretNode); bgneal@442: self.setRng(rng); bgneal@312: bgneal@312: // Remove the caret position bgneal@442: self.dom.remove('__caret'); bgneal@442: self.setRng(rng); bgneal@312: } else { bgneal@442: if (rng.item) { bgneal@312: // Delete content and get caret text selection bgneal@442: doc.execCommand('Delete', false, null); bgneal@442: rng = self.getRng(); bgneal@442: } bgneal@442: bgneal@442: rng.pasteHTML(content); bgneal@312: } bgneal@312: bgneal@312: // Dispatch set content event bgneal@442: if (!args.no_events) bgneal@442: self.onSetContent.dispatch(self, args); bgneal@312: }, bgneal@312: bgneal@312: getStart : function() { bgneal@312: var rng = this.getRng(), startElement, parentElement, checkRng, node; bgneal@312: bgneal@312: if (rng.duplicate || rng.item) { bgneal@312: // Control selection, return first item bgneal@312: if (rng.item) bgneal@312: return rng.item(0); bgneal@312: bgneal@312: // Get start element bgneal@312: checkRng = rng.duplicate(); bgneal@312: checkRng.collapse(1); bgneal@312: startElement = checkRng.parentElement(); bgneal@312: bgneal@312: // Check if range parent is inside the start element, then return the inner parent element bgneal@312: // This will fix issues when a single element is selected, IE would otherwise return the wrong start element bgneal@312: parentElement = node = rng.parentElement(); bgneal@312: while (node = node.parentNode) { bgneal@312: if (node == startElement) { bgneal@312: startElement = parentElement; bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return startElement; bgneal@312: } else { bgneal@312: startElement = rng.startContainer; bgneal@312: bgneal@312: if (startElement.nodeType == 1 && startElement.hasChildNodes()) bgneal@312: startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)]; bgneal@312: bgneal@312: if (startElement && startElement.nodeType == 3) bgneal@312: return startElement.parentNode; bgneal@312: bgneal@312: return startElement; bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: getEnd : function() { bgneal@312: var t = this, r = t.getRng(), e, eo; bgneal@312: bgneal@312: if (r.duplicate || r.item) { bgneal@312: if (r.item) bgneal@312: return r.item(0); bgneal@312: bgneal@312: r = r.duplicate(); bgneal@312: r.collapse(0); bgneal@312: e = r.parentElement(); bgneal@312: bgneal@312: if (e && e.nodeName == 'BODY') bgneal@312: return e.lastChild || e; bgneal@312: bgneal@312: return e; bgneal@312: } else { bgneal@312: e = r.endContainer; bgneal@312: eo = r.endOffset; bgneal@312: bgneal@312: if (e.nodeType == 1 && e.hasChildNodes()) bgneal@312: e = e.childNodes[eo > 0 ? eo - 1 : eo]; bgneal@312: bgneal@312: if (e && e.nodeType == 3) bgneal@312: return e.parentNode; bgneal@312: bgneal@312: return e; bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: getBookmark : function(type, normalized) { bgneal@312: var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles; bgneal@312: bgneal@312: function findIndex(name, element) { bgneal@312: var index = 0; bgneal@312: bgneal@312: each(dom.select(name), function(node, i) { bgneal@312: if (node == element) bgneal@312: index = i; bgneal@312: }); bgneal@312: bgneal@312: return index; bgneal@312: }; bgneal@312: bgneal@312: if (type == 2) { bgneal@312: function getLocation() { bgneal@312: var rng = t.getRng(true), root = dom.getRoot(), bookmark = {}; bgneal@312: bgneal@312: function getPoint(rng, start) { bgneal@312: var container = rng[start ? 'startContainer' : 'endContainer'], bgneal@312: offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0; bgneal@312: bgneal@312: if (container.nodeType == 3) { bgneal@312: if (normalized) { bgneal@312: for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling) bgneal@312: offset += node.nodeValue.length; bgneal@312: } bgneal@312: bgneal@312: point.push(offset); bgneal@312: } else { bgneal@312: childNodes = container.childNodes; bgneal@312: bgneal@312: if (offset >= childNodes.length && childNodes.length) { bgneal@312: after = 1; bgneal@312: offset = Math.max(0, childNodes.length - 1); bgneal@312: } bgneal@312: bgneal@312: point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after); bgneal@312: } bgneal@312: bgneal@312: for (; container && container != root; container = container.parentNode) bgneal@312: point.push(t.dom.nodeIndex(container, normalized)); bgneal@312: bgneal@312: return point; bgneal@312: }; bgneal@312: bgneal@312: bookmark.start = getPoint(rng, true); bgneal@312: bgneal@312: if (!t.isCollapsed()) bgneal@312: bookmark.end = getPoint(rng); bgneal@312: bgneal@312: return bookmark; bgneal@312: }; bgneal@312: bgneal@312: return getLocation(); bgneal@312: } bgneal@312: bgneal@312: // Handle simple range bgneal@312: if (type) bgneal@312: return {rng : t.getRng()}; bgneal@312: bgneal@312: rng = t.getRng(); bgneal@312: id = dom.uniqueId(); bgneal@312: collapsed = tinyMCE.activeEditor.selection.isCollapsed(); bgneal@312: styles = 'overflow:hidden;line-height:0px'; bgneal@312: bgneal@312: // Explorer method bgneal@312: if (rng.duplicate || rng.item) { bgneal@312: // Text selection bgneal@312: if (!rng.item) { bgneal@312: rng2 = rng.duplicate(); bgneal@312: bgneal@442: try { bgneal@442: // Insert start marker bgneal@442: rng.collapse(); bgneal@442: rng.pasteHTML('' + chr + ''); bgneal@442: bgneal@442: // Insert end marker bgneal@442: if (!collapsed) { bgneal@442: rng2.collapse(false); bgneal@442: bgneal@442: // Detect the empty space after block elements in IE and move the end back one character

    ] becomes

    ]

    bgneal@442: rng.moveToElementText(rng2.parentElement()); bgneal@442: if (rng.compareEndPoints('StartToEnd', rng2) == 0) bgneal@442: rng2.move('character', -1); bgneal@442: bgneal@442: rng2.pasteHTML('' + chr + ''); bgneal@442: } bgneal@442: } catch (ex) { bgneal@442: // IE might throw unspecified error so lets ignore it bgneal@442: return null; bgneal@312: } bgneal@312: } else { bgneal@312: // Control selection bgneal@312: element = rng.item(0); bgneal@312: name = element.nodeName; bgneal@312: bgneal@312: return {name : name, index : findIndex(name, element)}; bgneal@312: } bgneal@312: } else { bgneal@312: element = t.getNode(); bgneal@312: name = element.nodeName; bgneal@312: if (name == 'IMG') bgneal@312: return {name : name, index : findIndex(name, element)}; bgneal@312: bgneal@312: // W3C method bgneal@312: rng2 = rng.cloneRange(); bgneal@312: bgneal@312: // Insert end marker bgneal@312: if (!collapsed) { bgneal@312: rng2.collapse(false); bgneal@442: rng2.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_end', style : styles}, chr)); bgneal@312: } bgneal@312: bgneal@312: rng.collapse(true); bgneal@442: rng.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_start', style : styles}, chr)); bgneal@312: } bgneal@312: bgneal@312: t.moveToBookmark({id : id, keep : 1}); bgneal@312: bgneal@312: return {id : id}; bgneal@312: }, bgneal@312: bgneal@312: moveToBookmark : function(bookmark) { bgneal@312: var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset; bgneal@312: bgneal@312: // Clear selection cache bgneal@312: if (t.tridentSel) bgneal@312: t.tridentSel.destroy(); bgneal@312: bgneal@312: if (bookmark) { bgneal@312: if (bookmark.start) { bgneal@312: rng = dom.createRng(); bgneal@312: root = dom.getRoot(); bgneal@312: bgneal@312: function setEndPoint(start) { bgneal@312: var point = bookmark[start ? 'start' : 'end'], i, node, offset, children; bgneal@312: bgneal@312: if (point) { bgneal@442: offset = point[0]; bgneal@442: bgneal@312: // Find container node bgneal@312: for (node = root, i = point.length - 1; i >= 1; i--) { bgneal@312: children = node.childNodes; bgneal@312: bgneal@442: if (point[i] > children.length - 1) bgneal@442: return; bgneal@442: bgneal@442: node = children[point[i]]; bgneal@312: } bgneal@312: bgneal@442: // Move text offset to best suitable location bgneal@442: if (node.nodeType === 3) bgneal@442: offset = Math.min(point[0], node.nodeValue.length); bgneal@442: bgneal@442: // Move element offset to best suitable location bgneal@442: if (node.nodeType === 1) bgneal@442: offset = Math.min(point[0], node.childNodes.length); bgneal@442: bgneal@312: // Set offset within container node bgneal@312: if (start) bgneal@442: rng.setStart(node, offset); bgneal@312: else bgneal@442: rng.setEnd(node, offset); bgneal@442: } bgneal@442: bgneal@442: return true; bgneal@312: }; bgneal@312: bgneal@442: if (setEndPoint(true) && setEndPoint()) { bgneal@442: t.setRng(rng); bgneal@442: } bgneal@312: } else if (bookmark.id) { bgneal@312: function restoreEndPoint(suffix) { bgneal@312: var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep; bgneal@312: bgneal@312: if (marker) { bgneal@312: node = marker.parentNode; bgneal@312: bgneal@312: if (suffix == 'start') { bgneal@312: if (!keep) { bgneal@312: idx = dom.nodeIndex(marker); bgneal@312: } else { bgneal@312: node = marker.firstChild; bgneal@312: idx = 1; bgneal@312: } bgneal@312: bgneal@312: startContainer = endContainer = node; bgneal@312: startOffset = endOffset = idx; bgneal@312: } else { bgneal@312: if (!keep) { bgneal@312: idx = dom.nodeIndex(marker); bgneal@312: } else { bgneal@312: node = marker.firstChild; bgneal@312: idx = 1; bgneal@312: } bgneal@312: bgneal@312: endContainer = node; bgneal@312: endOffset = idx; bgneal@312: } bgneal@312: bgneal@312: if (!keep) { bgneal@312: prev = marker.previousSibling; bgneal@312: next = marker.nextSibling; bgneal@312: bgneal@312: // Remove all marker text nodes bgneal@312: each(tinymce.grep(marker.childNodes), function(node) { bgneal@312: if (node.nodeType == 3) bgneal@312: node.nodeValue = node.nodeValue.replace(/\uFEFF/g, ''); bgneal@312: }); bgneal@312: bgneal@312: // Remove marker but keep children if for example contents where inserted into the marker bgneal@312: // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature bgneal@312: while (marker = dom.get(bookmark.id + '_' + suffix)) bgneal@312: dom.remove(marker, 1); bgneal@312: bgneal@442: // If siblings are text nodes then merge them unless it's Opera since it some how removes the node bgneal@442: // 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 bgneal@442: if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) { bgneal@312: idx = prev.nodeValue.length; bgneal@312: prev.appendData(next.nodeValue); bgneal@312: dom.remove(next); bgneal@312: bgneal@312: if (suffix == 'start') { bgneal@312: startContainer = endContainer = prev; bgneal@312: startOffset = endOffset = idx; bgneal@312: } else { bgneal@312: endContainer = prev; bgneal@312: endOffset = idx; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function addBogus(node) { bgneal@442: // Adds a bogus BR element for empty block elements or just a space on IE since it renders BR elements incorrectly bgneal@442: if (dom.isBlock(node) && !node.innerHTML) bgneal@442: node.innerHTML = !isIE ? '
    ' : ' '; bgneal@312: bgneal@312: return node; bgneal@312: }; bgneal@312: bgneal@312: // Restore start/end points bgneal@312: restoreEndPoint('start'); bgneal@312: restoreEndPoint('end'); bgneal@312: bgneal@312: if (startContainer) { bgneal@312: rng = dom.createRng(); bgneal@312: rng.setStart(addBogus(startContainer), startOffset); bgneal@312: rng.setEnd(addBogus(endContainer), endOffset); bgneal@312: t.setRng(rng); bgneal@312: } bgneal@312: } else if (bookmark.name) { bgneal@312: t.select(dom.select(bookmark.name)[bookmark.index]); bgneal@312: } else if (bookmark.rng) bgneal@312: t.setRng(bookmark.rng); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: select : function(node, content) { bgneal@312: var t = this, dom = t.dom, rng = dom.createRng(), idx; bgneal@312: bgneal@442: if (node) { bgneal@442: idx = dom.nodeIndex(node); bgneal@442: rng.setStart(node.parentNode, idx); bgneal@442: rng.setEnd(node.parentNode, idx + 1); bgneal@442: bgneal@442: // Find first/last text node or BR element bgneal@442: if (content) { bgneal@442: function setPoint(node, start) { bgneal@442: var walker = new tinymce.dom.TreeWalker(node, node); bgneal@442: bgneal@442: do { bgneal@442: // Text node bgneal@442: if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) { bgneal@442: if (start) bgneal@442: rng.setStart(node, 0); bgneal@442: else bgneal@442: rng.setEnd(node, node.nodeValue.length); bgneal@442: bgneal@442: return; bgneal@442: } bgneal@442: bgneal@442: // BR element bgneal@442: if (node.nodeName == 'BR') { bgneal@442: if (start) bgneal@442: rng.setStartBefore(node); bgneal@442: else bgneal@442: rng.setEndBefore(node); bgneal@442: bgneal@442: return; bgneal@442: } bgneal@442: } while (node = (start ? walker.next() : walker.prev())); bgneal@442: }; bgneal@442: bgneal@442: setPoint(node, 1); bgneal@442: setPoint(node); bgneal@442: } bgneal@442: bgneal@442: t.setRng(rng); bgneal@442: } bgneal@312: bgneal@312: return node; bgneal@312: }, bgneal@312: bgneal@312: isCollapsed : function() { bgneal@312: var t = this, r = t.getRng(), s = t.getSel(); bgneal@312: bgneal@312: if (!r || r.item) bgneal@312: return false; bgneal@312: bgneal@312: if (r.compareEndPoints) bgneal@312: return r.compareEndPoints('StartToEnd', r) === 0; bgneal@312: bgneal@312: return !s || r.collapsed; bgneal@312: }, bgneal@312: bgneal@442: collapse : function(to_start) { bgneal@442: var self = this, rng = self.getRng(), node; bgneal@312: bgneal@312: // Control range on IE bgneal@442: if (rng.item) { bgneal@442: node = rng.item(0); bgneal@442: rng = self.win.document.body.createTextRange(); bgneal@442: rng.moveToElementText(node); bgneal@442: } bgneal@442: bgneal@442: rng.collapse(!!to_start); bgneal@442: self.setRng(rng); bgneal@312: }, bgneal@312: bgneal@312: getSel : function() { bgneal@312: var t = this, w = this.win; bgneal@312: bgneal@312: return w.getSelection ? w.getSelection() : w.document.selection; bgneal@312: }, bgneal@312: bgneal@312: getRng : function(w3c) { bgneal@442: var t = this, s, r, elm, doc = t.win.document; bgneal@312: bgneal@312: // Found tridentSel object then we need to use that one bgneal@312: if (w3c && t.tridentSel) bgneal@312: return t.tridentSel.getRangeAt(0); bgneal@312: bgneal@312: try { bgneal@312: if (s = t.getSel()) bgneal@442: r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : doc.createRange()); bgneal@312: } catch (ex) { bgneal@312: // IE throws unspecified error here if TinyMCE is placed in a frame/iframe bgneal@312: } bgneal@312: bgneal@442: // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet bgneal@442: if (tinymce.isIE && r && r.setStart && doc.selection.createRange().item) { bgneal@442: elm = doc.selection.createRange().item(0); bgneal@442: r = doc.createRange(); bgneal@442: r.setStartBefore(elm); bgneal@442: r.setEndAfter(elm); bgneal@442: } bgneal@442: bgneal@312: // No range found then create an empty one bgneal@312: // This can occur when the editor is placed in a hidden container element on Gecko bgneal@312: // Or on IE when there was an exception bgneal@312: if (!r) bgneal@442: r = doc.createRange ? doc.createRange() : doc.body.createTextRange(); bgneal@312: bgneal@312: if (t.selectedRange && t.explicitRange) { bgneal@312: if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) { bgneal@312: // Safari, Opera and Chrome only ever select text which causes the range to change. bgneal@312: // This lets us use the originally set range if the selection hasn't been changed by the user. bgneal@312: r = t.explicitRange; bgneal@312: } else { bgneal@312: t.selectedRange = null; bgneal@312: t.explicitRange = null; bgneal@312: } bgneal@312: } bgneal@442: bgneal@312: return r; bgneal@312: }, bgneal@312: bgneal@312: setRng : function(r) { bgneal@312: var s, t = this; bgneal@312: bgneal@312: if (!t.tridentSel) { bgneal@312: s = t.getSel(); bgneal@312: bgneal@312: if (s) { bgneal@312: t.explicitRange = r; bgneal@442: bgneal@442: try { bgneal@442: s.removeAllRanges(); bgneal@442: } catch (ex) { bgneal@442: // IE9 might throw errors here don't know why bgneal@442: } bgneal@442: bgneal@312: s.addRange(r); bgneal@312: t.selectedRange = s.getRangeAt(0); bgneal@312: } bgneal@312: } else { bgneal@312: // Is W3C Range bgneal@312: if (r.cloneRange) { bgneal@312: t.tridentSel.addRange(r); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Is IE specific range bgneal@312: try { bgneal@312: r.select(); bgneal@312: } catch (ex) { bgneal@312: // Needed for some odd IE bug #1843306 bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: setNode : function(n) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.setContent(t.dom.getOuterHTML(n)); bgneal@312: bgneal@312: return n; bgneal@312: }, bgneal@312: bgneal@312: getNode : function() { bgneal@442: var t = this, rng = t.getRng(), sel = t.getSel(), elm, start = rng.startContainer, end = rng.endContainer; bgneal@442: bgneal@442: // Range maybe lost after the editor is made visible again bgneal@442: if (!rng) bgneal@442: return t.dom.getRoot(); bgneal@312: bgneal@312: if (rng.setStart) { bgneal@312: elm = rng.commonAncestorContainer; bgneal@312: bgneal@312: // Handle selection a image or other control like element such as anchors bgneal@312: if (!rng.collapsed) { bgneal@312: if (rng.startContainer == rng.endContainer) { bgneal@442: if (rng.endOffset - rng.startOffset < 2) { bgneal@312: if (rng.startContainer.hasChildNodes()) bgneal@312: elm = rng.startContainer.childNodes[rng.startOffset]; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // If the anchor node is a element instead of a text node then return this element bgneal@442: //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1) bgneal@442: // return sel.anchorNode.childNodes[sel.anchorOffset]; bgneal@442: bgneal@442: // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent. bgneal@442: // This happens when you double click an underlined word in FireFox. bgneal@442: if (start.nodeType === 3 && end.nodeType === 3) { bgneal@442: function skipEmptyTextNodes(n, forwards) { bgneal@442: var orig = n; bgneal@442: while (n && n.nodeType === 3 && n.length === 0) { bgneal@442: n = forwards ? n.nextSibling : n.previousSibling; bgneal@442: } bgneal@442: return n || orig; bgneal@442: } bgneal@442: if (start.length === rng.startOffset) { bgneal@442: start = skipEmptyTextNodes(start.nextSibling, true); bgneal@442: } else { bgneal@442: start = start.parentNode; bgneal@442: } bgneal@442: if (rng.endOffset === 0) { bgneal@442: end = skipEmptyTextNodes(end.previousSibling, false); bgneal@442: } else { bgneal@442: end = end.parentNode; bgneal@442: } bgneal@442: bgneal@442: if (start && start === end) bgneal@442: return start; bgneal@442: } bgneal@312: } bgneal@312: bgneal@312: if (elm && elm.nodeType == 3) bgneal@312: return elm.parentNode; bgneal@312: bgneal@312: return elm; bgneal@312: } bgneal@312: bgneal@312: return rng.item ? rng.item(0) : rng.parentElement(); bgneal@312: }, bgneal@312: bgneal@312: getSelectedBlocks : function(st, en) { bgneal@312: var t = this, dom = t.dom, sb, eb, n, bl = []; bgneal@312: bgneal@312: sb = dom.getParent(st || t.getStart(), dom.isBlock); bgneal@312: eb = dom.getParent(en || t.getEnd(), dom.isBlock); bgneal@312: bgneal@312: if (sb) bgneal@312: bl.push(sb); bgneal@312: bgneal@312: if (sb && eb && sb != eb) { bgneal@312: n = sb; bgneal@312: bgneal@312: while ((n = n.nextSibling) && n != eb) { bgneal@312: if (dom.isBlock(n)) bgneal@312: bl.push(n); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if (eb && sb != eb) bgneal@312: bl.push(eb); bgneal@312: bgneal@312: return bl; bgneal@312: }, bgneal@312: bgneal@312: destroy : function(s) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.win = null; bgneal@312: bgneal@312: if (t.tridentSel) bgneal@312: t.tridentSel.destroy(); bgneal@312: bgneal@312: // Manual destroy then remove unload handler bgneal@312: if (!s) bgneal@312: tinymce.removeUnload(t.destroy); bgneal@442: }, bgneal@442: bgneal@442: // IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode bgneal@442: _fixIESelection : function() { bgneal@442: var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng, htmlElm; bgneal@442: bgneal@442: // Make HTML element unselectable since we are going to handle selection by hand bgneal@442: doc.documentElement.unselectable = true; bgneal@442: bgneal@442: // Return range from point or null if it failed bgneal@442: function rngFromPoint(x, y) { bgneal@442: var rng = body.createTextRange(); bgneal@442: bgneal@442: try { bgneal@442: rng.moveToPoint(x, y); bgneal@442: } catch (ex) { bgneal@442: // IE sometimes throws and exception, so lets just ignore it bgneal@442: rng = null; bgneal@442: } bgneal@442: bgneal@442: return rng; bgneal@442: }; bgneal@442: bgneal@442: // Fires while the selection is changing bgneal@442: function selectionChange(e) { bgneal@442: var pointRng; bgneal@442: bgneal@442: // Check if the button is down or not bgneal@442: if (e.button) { bgneal@442: // Create range from mouse position bgneal@442: pointRng = rngFromPoint(e.x, e.y); bgneal@442: bgneal@442: if (pointRng) { bgneal@442: // Check if pointRange is before/after selection then change the endPoint bgneal@442: if (pointRng.compareEndPoints('StartToStart', startRng) > 0) bgneal@442: pointRng.setEndPoint('StartToStart', startRng); bgneal@442: else bgneal@442: pointRng.setEndPoint('EndToEnd', startRng); bgneal@442: bgneal@442: pointRng.select(); bgneal@442: } bgneal@442: } else bgneal@442: endSelection(); bgneal@442: } bgneal@442: bgneal@442: // Removes listeners bgneal@442: function endSelection() { bgneal@442: var rng = doc.selection.createRange(); bgneal@442: bgneal@442: // If the range is collapsed then use the last start range bgneal@442: if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0) bgneal@442: startRng.select(); bgneal@442: bgneal@442: dom.unbind(doc, 'mouseup', endSelection); bgneal@442: dom.unbind(doc, 'mousemove', selectionChange); bgneal@442: startRng = started = 0; bgneal@442: }; bgneal@442: bgneal@442: // Detect when user selects outside BODY bgneal@442: dom.bind(doc, ['mousedown', 'contextmenu'], function(e) { bgneal@442: if (e.target.nodeName === 'HTML') { bgneal@442: if (started) bgneal@442: endSelection(); bgneal@442: bgneal@442: // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML bgneal@442: htmlElm = doc.documentElement; bgneal@442: if (htmlElm.scrollHeight > htmlElm.clientHeight) bgneal@442: return; bgneal@442: bgneal@442: started = 1; bgneal@442: // Setup start position bgneal@442: startRng = rngFromPoint(e.x, e.y); bgneal@442: if (startRng) { bgneal@442: // Listen for selection change events bgneal@442: dom.bind(doc, 'mouseup', endSelection); bgneal@442: dom.bind(doc, 'mousemove', selectionChange); bgneal@442: bgneal@442: dom.win.focus(); bgneal@442: startRng.select(); bgneal@442: } bgneal@442: } bgneal@442: }); bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@442: tinymce.dom.Serializer = function(settings, dom, schema) { bgneal@442: var onPreProcess, onPostProcess, isIE = tinymce.isIE, each = tinymce.each, htmlParser; bgneal@442: bgneal@442: // Support the old apply_source_formatting option bgneal@442: if (!settings.apply_source_formatting) bgneal@442: settings.indent = false; bgneal@442: bgneal@442: settings.remove_trailing_brs = true; bgneal@442: bgneal@442: // Default DOM and Schema if they are undefined bgneal@442: dom = dom || tinymce.DOM; bgneal@442: schema = schema || new tinymce.html.Schema(settings); bgneal@442: settings.entity_encoding = settings.entity_encoding || 'named'; bgneal@442: bgneal@442: onPreProcess = new tinymce.util.Dispatcher(self); bgneal@442: bgneal@442: onPostProcess = new tinymce.util.Dispatcher(self); bgneal@442: bgneal@442: htmlParser = new tinymce.html.DomParser(settings, schema); bgneal@442: bgneal@442: // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed bgneal@442: htmlParser.addAttributeFilter('src,href,style', function(nodes, name) { bgneal@442: var i = nodes.length, node, value, internalName = 'data-mce-' + name, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef; bgneal@442: bgneal@442: while (i--) { bgneal@442: node = nodes[i]; bgneal@442: bgneal@442: value = node.attributes.map[internalName]; bgneal@442: if (value !== undef) { bgneal@442: // Set external name to internal value and remove internal bgneal@442: node.attr(name, value.length > 0 ? value : null); bgneal@442: node.attr(internalName, null); bgneal@442: } else { bgneal@442: // No internal attribute found then convert the value we have in the DOM bgneal@442: value = node.attributes.map[name]; bgneal@442: bgneal@442: if (name === "style") bgneal@442: value = dom.serializeStyle(dom.parseStyle(value), node.name); bgneal@442: else if (urlConverter) bgneal@442: value = urlConverter.call(urlConverterScope, value, name, node.name); bgneal@442: bgneal@442: node.attr(name, value.length > 0 ? value : null); bgneal@442: } bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: // Remove internal classes mceItem<..> bgneal@442: htmlParser.addAttributeFilter('class', function(nodes, name) { bgneal@442: var i = nodes.length, node, value; bgneal@442: bgneal@442: while (i--) { bgneal@442: node = nodes[i]; bgneal@442: value = node.attr('class').replace(/\s*mce(Item\w+|Selected)\s*/g, ''); bgneal@442: node.attr('class', value.length > 0 ? value : null); bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: // Remove bookmark elements bgneal@442: htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) { bgneal@442: var i = nodes.length, node; bgneal@442: bgneal@442: while (i--) { bgneal@442: node = nodes[i]; bgneal@442: bgneal@442: if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup) bgneal@442: node.remove(); bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: // Force script into CDATA sections and remove the mce- prefix also add comments around styles bgneal@442: htmlParser.addNodeFilter('script,style', function(nodes, name) { bgneal@442: var i = nodes.length, node, value; bgneal@442: bgneal@442: function trim(value) { bgneal@442: return value.replace(/()/g, '\n') bgneal@442: .replace(/^[\r\n]*|[\r\n]*$/g, '') bgneal@442: .replace(/^\s*(\/\/\s*|\]\]>|-->|\]\]-->)\s*$/g, ''); bgneal@442: }; bgneal@442: bgneal@442: while (i--) { bgneal@442: node = nodes[i]; bgneal@442: value = node.firstChild ? node.firstChild.value : ''; bgneal@442: bgneal@442: if (name === "script") { bgneal@442: // Remove mce- prefix from script elements bgneal@442: node.attr('type', (node.attr('type') || 'text/javascript').replace(/^mce\-/, '')); bgneal@442: bgneal@442: if (value.length > 0) bgneal@442: node.firstChild.value = '// '; bgneal@442: } else { bgneal@442: if (value.length > 0) bgneal@442: node.firstChild.value = ''; bgneal@442: } bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: // Convert comments to cdata and handle protected comments bgneal@442: htmlParser.addNodeFilter('#comment', function(nodes, name) { bgneal@442: var i = nodes.length, node; bgneal@442: bgneal@442: while (i--) { bgneal@442: node = nodes[i]; bgneal@442: bgneal@442: if (node.value.indexOf('[CDATA[') === 0) { bgneal@442: node.name = '#cdata'; bgneal@442: node.type = 4; bgneal@442: node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, ''); bgneal@442: } else if (node.value.indexOf('mce:protected ') === 0) { bgneal@442: node.name = "#text"; bgneal@442: node.type = 3; bgneal@442: node.raw = true; bgneal@442: node.value = unescape(node.value).substr(14); bgneal@442: } bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) { bgneal@442: var i = nodes.length, node; bgneal@442: bgneal@442: while (i--) { bgneal@442: node = nodes[i]; bgneal@442: if (node.type === 7) bgneal@442: node.remove(); bgneal@442: else if (node.type === 1) { bgneal@442: if (name === "input" && !("type" in node.attributes.map)) bgneal@442: node.attr('type', 'text'); bgneal@442: } bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: // Fix list elements, TODO: Replace this later bgneal@442: if (settings.fix_list_elements) { bgneal@442: htmlParser.addNodeFilter('ul,ol', function(nodes, name) { bgneal@442: var i = nodes.length, node, parentNode; bgneal@442: bgneal@442: while (i--) { bgneal@442: node = nodes[i]; bgneal@442: parentNode = node.parent; bgneal@442: bgneal@442: if (parentNode.name === 'ul' || parentNode.name === 'ol') { bgneal@442: if (node.prev && node.prev.name === 'li') { bgneal@442: node.prev.append(node); bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: }); bgneal@442: } bgneal@442: bgneal@442: // Remove internal data attributes bgneal@442: htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style', function(nodes, name) { bgneal@442: var i = nodes.length; bgneal@442: bgneal@442: while (i--) { bgneal@442: nodes[i].attr(name, null); bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: // Return public methods bgneal@442: return { bgneal@442: schema : schema, bgneal@442: bgneal@442: addNodeFilter : htmlParser.addNodeFilter, bgneal@442: bgneal@442: addAttributeFilter : htmlParser.addAttributeFilter, bgneal@442: bgneal@442: onPreProcess : onPreProcess, bgneal@442: bgneal@442: onPostProcess : onPostProcess, bgneal@442: bgneal@442: serialize : function(node, args) { bgneal@442: var impl, doc, oldDoc, htmlSerializer, content; bgneal@442: bgneal@442: // Explorer won't clone contents of script and style and the bgneal@442: // selected index of select elements are cleared on a clone operation. bgneal@442: if (isIE && dom.select('script,style,select').length > 0) { bgneal@442: content = node.innerHTML; bgneal@442: node = node.cloneNode(false); bgneal@442: dom.setHTML(node, content); bgneal@312: } else bgneal@442: node = node.cloneNode(true); bgneal@442: bgneal@442: // Nodes needs to be attached to something in WebKit/Opera bgneal@442: // Older builds of Opera crashes if you attach the node to an document created dynamically bgneal@442: // and since we can't feature detect a crash we need to sniff the acutal build number bgneal@442: // This fix will make DOM ranges and make Sizzle happy! bgneal@442: impl = node.ownerDocument.implementation; bgneal@442: if (impl.createHTMLDocument) { bgneal@442: // Create an empty HTML document bgneal@442: doc = impl.createHTMLDocument(""); bgneal@442: bgneal@442: // Add the element or it's children if it's a body element to the new document bgneal@442: each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) { bgneal@442: doc.body.appendChild(doc.importNode(node, true)); bgneal@442: }); bgneal@442: bgneal@442: // Grab first child or body element for serialization bgneal@442: if (node.nodeName != 'BODY') bgneal@442: node = doc.body.firstChild; bgneal@442: else bgneal@442: node = doc.body; bgneal@442: bgneal@442: // set the new document in DOMUtils so createElement etc works bgneal@442: oldDoc = dom.doc; bgneal@442: dom.doc = doc; bgneal@442: } bgneal@442: bgneal@442: args = args || {}; bgneal@442: args.format = args.format || 'html'; bgneal@442: bgneal@442: // Pre process bgneal@442: if (!args.no_events) { bgneal@442: args.node = node; bgneal@442: onPreProcess.dispatch(self, args); bgneal@442: } bgneal@442: bgneal@442: // Setup serializer bgneal@442: htmlSerializer = new tinymce.html.Serializer(settings, schema); bgneal@442: bgneal@442: // Parse and serialize HTML bgneal@442: args.content = htmlSerializer.serialize( bgneal@442: htmlParser.parse(args.getInner ? node.innerHTML : tinymce.trim(dom.getOuterHTML(node), args), args) bgneal@442: ); bgneal@442: bgneal@442: // Replace all BOM characters for now until we can find a better solution bgneal@442: if (!args.cleanup) bgneal@442: args.content = args.content.replace(/\uFEFF/g, ''); bgneal@442: bgneal@442: // Post process bgneal@442: if (!args.no_events) bgneal@442: onPostProcess.dispatch(self, args); bgneal@442: bgneal@442: // Restore the old document if it was changed bgneal@442: if (oldDoc) bgneal@442: dom.doc = oldDoc; bgneal@442: bgneal@442: args.node = null; bgneal@442: bgneal@442: return args.content; bgneal@442: }, bgneal@442: bgneal@442: addRules : function(rules) { bgneal@442: schema.addValidElements(rules); bgneal@442: }, bgneal@442: bgneal@442: setRules : function(rules) { bgneal@442: schema.setValidElements(rules); bgneal@442: } bgneal@442: }; bgneal@442: }; bgneal@312: })(tinymce); bgneal@312: (function(tinymce) { bgneal@312: tinymce.dom.ScriptLoader = function(settings) { bgneal@312: var QUEUED = 0, bgneal@312: LOADING = 1, bgneal@312: LOADED = 2, bgneal@312: states = {}, bgneal@312: queue = [], bgneal@312: scriptLoadedCallbacks = {}, bgneal@312: queueLoadedCallbacks = [], bgneal@312: loading = 0, bgneal@312: undefined; bgneal@312: bgneal@312: function loadScript(url, callback) { bgneal@312: var t = this, dom = tinymce.DOM, elm, uri, loc, id; bgneal@312: bgneal@312: // Execute callback when script is loaded bgneal@312: function done() { bgneal@312: dom.remove(id); bgneal@312: bgneal@312: if (elm) bgneal@312: elm.onreadystatechange = elm.onload = elm = null; bgneal@312: bgneal@312: callback(); bgneal@312: }; bgneal@442: bgneal@442: function error() { bgneal@442: // Report the error so it's easier for people to spot loading errors bgneal@442: if (typeof(console) !== "undefined" && console.log) bgneal@442: console.log("Failed to load: " + url); bgneal@442: bgneal@442: // We can't mark it as done if there is a load error since bgneal@442: // A) We don't want to produce 404 errors on the server and bgneal@442: // B) the onerror event won't fire on all browsers. bgneal@442: // done(); bgneal@442: }; bgneal@312: bgneal@312: id = dom.uniqueId(); bgneal@312: bgneal@312: if (tinymce.isIE6) { bgneal@312: uri = new tinymce.util.URI(url); bgneal@312: loc = location; bgneal@312: bgneal@312: // If script is from same domain and we bgneal@312: // use IE 6 then use XHR since it's more reliable bgneal@442: if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol && uri.protocol.toLowerCase() != 'file') { bgneal@312: tinymce.util.XHR.send({ bgneal@312: url : tinymce._addVer(uri.getURI()), bgneal@312: success : function(content) { bgneal@312: // Create new temp script element bgneal@312: var script = dom.create('script', { bgneal@312: type : 'text/javascript' bgneal@312: }); bgneal@312: bgneal@312: // Evaluate script in global scope bgneal@312: script.text = content; bgneal@312: document.getElementsByTagName('head')[0].appendChild(script); bgneal@312: dom.remove(script); bgneal@312: bgneal@312: done(); bgneal@442: }, bgneal@442: bgneal@442: error : error bgneal@312: }); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Create new script element bgneal@312: elm = dom.create('script', { bgneal@312: id : id, bgneal@312: type : 'text/javascript', bgneal@312: src : tinymce._addVer(url) bgneal@312: }); bgneal@312: bgneal@442: // Add onload listener for non IE browsers since IE9 bgneal@442: // fires onload event before the script is parsed and executed bgneal@442: if (!tinymce.isIE) bgneal@442: elm.onload = done; bgneal@442: bgneal@442: // Add onerror event will get fired on some browsers but not all of them bgneal@442: elm.onerror = error; bgneal@442: bgneal@442: // Opera 9.60 doesn't seem to fire the onreadystate event at correctly bgneal@442: if (!tinymce.isOpera) { bgneal@442: elm.onreadystatechange = function() { bgneal@442: var state = elm.readyState; bgneal@442: bgneal@442: // Loaded state is passed on IE 6 however there bgneal@442: // are known issues with this method but we can't use bgneal@442: // XHR in a cross domain loading bgneal@442: if (state == 'complete' || state == 'loaded') bgneal@442: done(); bgneal@442: }; bgneal@442: } bgneal@312: bgneal@312: // Most browsers support this feature so we report errors bgneal@312: // for those at least to help users track their missing plugins etc bgneal@312: // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option bgneal@312: /*elm.onerror = function() { bgneal@312: alert('Failed to load: ' + url); bgneal@312: };*/ bgneal@312: bgneal@312: // Add script to document bgneal@312: (document.getElementsByTagName('head')[0] || document.body).appendChild(elm); bgneal@312: }; bgneal@312: bgneal@312: this.isDone = function(url) { bgneal@312: return states[url] == LOADED; bgneal@312: }; bgneal@312: bgneal@312: this.markDone = function(url) { bgneal@312: states[url] = LOADED; bgneal@312: }; bgneal@312: bgneal@312: this.add = this.load = function(url, callback, scope) { bgneal@312: var item, state = states[url]; bgneal@312: bgneal@312: // Add url to load queue bgneal@312: if (state == undefined) { bgneal@312: queue.push(url); bgneal@312: states[url] = QUEUED; bgneal@312: } bgneal@312: bgneal@312: if (callback) { bgneal@312: // Store away callback for later execution bgneal@312: if (!scriptLoadedCallbacks[url]) bgneal@312: scriptLoadedCallbacks[url] = []; bgneal@312: bgneal@312: scriptLoadedCallbacks[url].push({ bgneal@312: func : callback, bgneal@312: scope : scope || this bgneal@312: }); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: this.loadQueue = function(callback, scope) { bgneal@312: this.loadScripts(queue, callback, scope); bgneal@312: }; bgneal@312: bgneal@312: this.loadScripts = function(scripts, callback, scope) { bgneal@312: var loadScripts; bgneal@312: bgneal@312: function execScriptLoadedCallbacks(url) { bgneal@312: // Execute URL callback functions bgneal@312: tinymce.each(scriptLoadedCallbacks[url], function(callback) { bgneal@312: callback.func.call(callback.scope); bgneal@312: }); bgneal@312: bgneal@312: scriptLoadedCallbacks[url] = undefined; bgneal@312: }; bgneal@312: bgneal@312: queueLoadedCallbacks.push({ bgneal@312: func : callback, bgneal@312: scope : scope || this bgneal@312: }); bgneal@312: bgneal@312: loadScripts = function() { bgneal@312: var loadingScripts = tinymce.grep(scripts); bgneal@312: bgneal@312: // Current scripts has been handled bgneal@312: scripts.length = 0; bgneal@312: bgneal@312: // Load scripts that needs to be loaded bgneal@312: tinymce.each(loadingScripts, function(url) { bgneal@312: // Script is already loaded then execute script callbacks directly bgneal@312: if (states[url] == LOADED) { bgneal@312: execScriptLoadedCallbacks(url); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Is script not loading then start loading it bgneal@312: if (states[url] != LOADING) { bgneal@312: states[url] = LOADING; bgneal@312: loading++; bgneal@312: bgneal@312: loadScript(url, function() { bgneal@312: states[url] = LOADED; bgneal@312: loading--; bgneal@312: bgneal@312: execScriptLoadedCallbacks(url); bgneal@312: bgneal@312: // Load more scripts if they where added by the recently loaded script bgneal@312: loadScripts(); bgneal@312: }); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // No scripts are currently loading then execute all pending queue loaded callbacks bgneal@312: if (!loading) { bgneal@312: tinymce.each(queueLoadedCallbacks, function(callback) { bgneal@312: callback.func.call(callback.scope); bgneal@312: }); bgneal@312: bgneal@312: queueLoadedCallbacks.length = 0; bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: loadScripts(); bgneal@312: }; bgneal@312: }; bgneal@312: bgneal@312: // Global script loader bgneal@312: tinymce.ScriptLoader = new tinymce.dom.ScriptLoader(); bgneal@312: })(tinymce); bgneal@312: bgneal@312: tinymce.dom.TreeWalker = function(start_node, root_node) { bgneal@312: var node = start_node; bgneal@312: bgneal@312: function findSibling(node, start_name, sibling_name, shallow) { bgneal@312: var sibling, parent; bgneal@312: bgneal@312: if (node) { bgneal@312: // Walk into nodes if it has a start bgneal@312: if (!shallow && node[start_name]) bgneal@312: return node[start_name]; bgneal@312: bgneal@312: // Return the sibling if it has one bgneal@312: if (node != root_node) { bgneal@312: sibling = node[sibling_name]; bgneal@312: if (sibling) bgneal@312: return sibling; bgneal@312: bgneal@312: // Walk up the parents to look for siblings bgneal@312: for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) { bgneal@312: sibling = parent[sibling_name]; bgneal@312: if (sibling) bgneal@312: return sibling; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: this.current = function() { bgneal@312: return node; bgneal@312: }; bgneal@312: bgneal@312: this.next = function(shallow) { bgneal@312: return (node = findSibling(node, 'firstChild', 'nextSibling', shallow)); bgneal@312: }; bgneal@312: bgneal@312: this.prev = function(shallow) { bgneal@442: return (node = findSibling(node, 'lastChild', 'previousSibling', shallow)); bgneal@312: }; bgneal@312: }; bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: tinymce.dom.RangeUtils = function(dom) { bgneal@312: var INVISIBLE_CHAR = '\uFEFF'; bgneal@312: bgneal@312: this.walk = function(rng, callback) { bgneal@312: var startContainer = rng.startContainer, bgneal@312: startOffset = rng.startOffset, bgneal@312: endContainer = rng.endContainer, bgneal@312: endOffset = rng.endOffset, bgneal@312: ancestor, startPoint, bgneal@312: endPoint, node, parent, siblings, nodes; bgneal@312: bgneal@312: // Handle table cell selection the table plugin enables bgneal@312: // you to fake select table cells and perform formatting actions on them bgneal@312: nodes = dom.select('td.mceSelected,th.mceSelected'); bgneal@312: if (nodes.length > 0) { bgneal@312: tinymce.each(nodes, function(node) { bgneal@312: callback([node]); bgneal@312: }); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: function collectSiblings(node, name, end_node) { bgneal@312: var siblings = []; bgneal@312: bgneal@312: for (; node && node != end_node; node = node[name]) bgneal@312: siblings.push(node); bgneal@312: bgneal@312: return siblings; bgneal@312: }; bgneal@312: bgneal@312: function findEndPoint(node, root) { bgneal@312: do { bgneal@312: if (node.parentNode == root) bgneal@312: return node; bgneal@312: bgneal@312: node = node.parentNode; bgneal@312: } while(node); bgneal@312: }; bgneal@312: bgneal@312: function walkBoundary(start_node, end_node, next) { bgneal@312: var siblingName = next ? 'nextSibling' : 'previousSibling'; bgneal@312: bgneal@312: for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) { bgneal@312: parent = node.parentNode; bgneal@312: siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName); bgneal@312: bgneal@312: if (siblings.length) { bgneal@312: if (!next) bgneal@312: siblings.reverse(); bgneal@312: bgneal@312: callback(siblings); bgneal@312: } bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: // If index based start position then resolve it bgneal@312: if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) bgneal@312: startContainer = startContainer.childNodes[startOffset]; bgneal@312: bgneal@312: // If index based end position then resolve it bgneal@312: if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) bgneal@442: endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)]; bgneal@312: bgneal@312: // Find common ancestor and end points bgneal@312: ancestor = dom.findCommonAncestor(startContainer, endContainer); bgneal@312: bgneal@312: // Same container bgneal@312: if (startContainer == endContainer) bgneal@312: return callback([startContainer]); bgneal@312: bgneal@312: // Process left side bgneal@312: for (node = startContainer; node; node = node.parentNode) { bgneal@312: if (node == endContainer) bgneal@312: return walkBoundary(startContainer, ancestor, true); bgneal@312: bgneal@312: if (node == ancestor) bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: // Process right side bgneal@312: for (node = endContainer; node; node = node.parentNode) { bgneal@312: if (node == startContainer) bgneal@312: return walkBoundary(endContainer, ancestor); bgneal@312: bgneal@312: if (node == ancestor) bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: // Find start/end point bgneal@312: startPoint = findEndPoint(startContainer, ancestor) || startContainer; bgneal@312: endPoint = findEndPoint(endContainer, ancestor) || endContainer; bgneal@312: bgneal@312: // Walk left leaf bgneal@312: walkBoundary(startContainer, startPoint, true); bgneal@312: bgneal@312: // Walk the middle from start to end point bgneal@312: siblings = collectSiblings( bgneal@312: startPoint == startContainer ? startPoint : startPoint.nextSibling, bgneal@312: 'nextSibling', bgneal@312: endPoint == endContainer ? endPoint.nextSibling : endPoint bgneal@312: ); bgneal@312: bgneal@312: if (siblings.length) bgneal@312: callback(siblings); bgneal@312: bgneal@312: // Walk right leaf bgneal@312: walkBoundary(endContainer, endPoint); bgneal@312: }; bgneal@312: bgneal@312: /* this.split = function(rng) { bgneal@312: var startContainer = rng.startContainer, bgneal@312: startOffset = rng.startOffset, bgneal@312: endContainer = rng.endContainer, bgneal@312: endOffset = rng.endOffset; bgneal@312: bgneal@312: function splitText(node, offset) { bgneal@312: if (offset == node.nodeValue.length) bgneal@312: node.appendData(INVISIBLE_CHAR); bgneal@312: bgneal@312: node = node.splitText(offset); bgneal@312: bgneal@312: if (node.nodeValue === INVISIBLE_CHAR) bgneal@312: node.nodeValue = ''; bgneal@312: bgneal@312: return node; bgneal@312: }; bgneal@312: bgneal@312: // Handle single text node bgneal@312: if (startContainer == endContainer) { bgneal@312: if (startContainer.nodeType == 3) { bgneal@312: if (startOffset != 0) bgneal@312: startContainer = endContainer = splitText(startContainer, startOffset); bgneal@312: bgneal@312: if (endOffset - startOffset != startContainer.nodeValue.length) bgneal@312: splitText(startContainer, endOffset - startOffset); bgneal@312: } bgneal@312: } else { bgneal@312: // Split startContainer text node if needed bgneal@312: if (startContainer.nodeType == 3 && startOffset != 0) { bgneal@312: startContainer = splitText(startContainer, startOffset); bgneal@312: startOffset = 0; bgneal@312: } bgneal@312: bgneal@312: // Split endContainer text node if needed bgneal@312: if (endContainer.nodeType == 3 && endOffset != endContainer.nodeValue.length) { bgneal@312: endContainer = splitText(endContainer, endOffset).previousSibling; bgneal@312: endOffset = endContainer.nodeValue.length; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return { bgneal@312: startContainer : startContainer, bgneal@312: startOffset : startOffset, bgneal@312: endContainer : endContainer, bgneal@312: endOffset : endOffset bgneal@312: }; bgneal@312: }; bgneal@312: */ bgneal@312: }; bgneal@312: bgneal@312: tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) { bgneal@312: if (rng1 && rng2) { bgneal@312: // Compare native IE ranges bgneal@312: if (rng1.item || rng1.duplicate) { bgneal@312: // Both are control ranges and the selected element matches bgneal@312: if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0)) bgneal@312: return true; bgneal@312: bgneal@312: // Both are text ranges and the range matches bgneal@312: if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1)) bgneal@312: return true; bgneal@312: } else { bgneal@312: // Compare w3c ranges bgneal@312: return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return false; bgneal@312: }; bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@442: var Event = tinymce.dom.Event, each = tinymce.each; bgneal@442: bgneal@442: tinymce.create('tinymce.ui.KeyboardNavigation', { bgneal@442: KeyboardNavigation: function(settings, dom) { bgneal@442: var t = this, root = settings.root, items = settings.items, bgneal@442: enableUpDown = settings.enableUpDown, enableLeftRight = settings.enableLeftRight || !settings.enableUpDown, bgneal@442: excludeFromTabOrder = settings.excludeFromTabOrder, bgneal@442: itemFocussed, itemBlurred, rootKeydown, rootFocussed, focussedId; bgneal@442: bgneal@442: dom = dom || tinymce.DOM; bgneal@442: bgneal@442: itemFocussed = function(evt) { bgneal@442: focussedId = evt.target.id; bgneal@442: }; bgneal@442: bgneal@442: itemBlurred = function(evt) { bgneal@442: dom.setAttrib(evt.target.id, 'tabindex', '-1'); bgneal@442: }; bgneal@442: bgneal@442: rootFocussed = function(evt) { bgneal@442: var item = dom.get(focussedId); bgneal@442: dom.setAttrib(item, 'tabindex', '0'); bgneal@442: item.focus(); bgneal@442: }; bgneal@442: bgneal@442: t.focus = function() { bgneal@442: dom.get(focussedId).focus(); bgneal@442: }; bgneal@442: bgneal@442: t.destroy = function() { bgneal@442: each(items, function(item) { bgneal@442: dom.unbind(dom.get(item.id), 'focus', itemFocussed); bgneal@442: dom.unbind(dom.get(item.id), 'blur', itemBlurred); bgneal@442: }); bgneal@442: bgneal@442: dom.unbind(dom.get(root), 'focus', rootFocussed); bgneal@442: dom.unbind(dom.get(root), 'keydown', rootKeydown); bgneal@442: bgneal@442: items = dom = root = t.focus = itemFocussed = itemBlurred = rootKeydown = rootFocussed = null; bgneal@442: t.destroy = function() {}; bgneal@442: }; bgneal@442: bgneal@442: t.moveFocus = function(dir, evt) { bgneal@442: var idx = -1, controls = t.controls, newFocus; bgneal@442: bgneal@442: if (!focussedId) bgneal@442: return; bgneal@442: bgneal@442: each(items, function(item, index) { bgneal@442: if (item.id === focussedId) { bgneal@442: idx = index; bgneal@442: return false; bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: idx += dir; bgneal@442: if (idx < 0) { bgneal@442: idx = items.length - 1; bgneal@442: } else if (idx >= items.length) { bgneal@442: idx = 0; bgneal@442: } bgneal@442: bgneal@442: newFocus = items[idx]; bgneal@442: dom.setAttrib(focussedId, 'tabindex', '-1'); bgneal@442: dom.setAttrib(newFocus.id, 'tabindex', '0'); bgneal@442: dom.get(newFocus.id).focus(); bgneal@442: bgneal@442: if (settings.actOnFocus) { bgneal@442: settings.onAction(newFocus.id); bgneal@442: } bgneal@442: bgneal@442: if (evt) bgneal@442: Event.cancel(evt); bgneal@442: }; bgneal@442: bgneal@442: rootKeydown = function(evt) { bgneal@442: 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; bgneal@442: bgneal@442: switch (evt.keyCode) { bgneal@442: case DOM_VK_LEFT: bgneal@442: if (enableLeftRight) t.moveFocus(-1); bgneal@442: break; bgneal@442: bgneal@442: case DOM_VK_RIGHT: bgneal@442: if (enableLeftRight) t.moveFocus(1); bgneal@442: break; bgneal@442: bgneal@442: case DOM_VK_UP: bgneal@442: if (enableUpDown) t.moveFocus(-1); bgneal@442: break; bgneal@442: bgneal@442: case DOM_VK_DOWN: bgneal@442: if (enableUpDown) t.moveFocus(1); bgneal@442: break; bgneal@442: bgneal@442: case DOM_VK_ESCAPE: bgneal@442: if (settings.onCancel) { bgneal@442: settings.onCancel(); bgneal@442: Event.cancel(evt); bgneal@442: } bgneal@442: break; bgneal@442: bgneal@442: case DOM_VK_ENTER: bgneal@442: case DOM_VK_RETURN: bgneal@442: case DOM_VK_SPACE: bgneal@442: if (settings.onAction) { bgneal@442: settings.onAction(focussedId); bgneal@442: Event.cancel(evt); bgneal@442: } bgneal@442: break; bgneal@442: } bgneal@442: }; bgneal@442: bgneal@442: // Set up state and listeners for each item. bgneal@442: each(items, function(item, idx) { bgneal@442: var tabindex; bgneal@442: bgneal@442: if (!item.id) { bgneal@442: item.id = dom.uniqueId('_mce_item_'); bgneal@442: } bgneal@442: bgneal@442: if (excludeFromTabOrder) { bgneal@442: dom.bind(item.id, 'blur', itemBlurred); bgneal@442: tabindex = '-1'; bgneal@442: } else { bgneal@442: tabindex = (idx === 0 ? '0' : '-1'); bgneal@442: } bgneal@442: bgneal@442: dom.setAttrib(item.id, 'tabindex', tabindex); bgneal@442: dom.bind(dom.get(item.id), 'focus', itemFocussed); bgneal@442: }); bgneal@442: bgneal@442: // Setup initial state for root element. bgneal@442: if (items[0]){ bgneal@442: focussedId = items[0].id; bgneal@442: } bgneal@442: bgneal@442: dom.setAttrib(root, 'tabindex', '-1'); bgneal@442: bgneal@442: // Setup listeners for root element. bgneal@442: dom.bind(dom.get(root), 'focus', rootFocussed); bgneal@442: dom.bind(dom.get(root), 'keydown', rootKeydown); bgneal@442: } bgneal@442: }); bgneal@442: })(tinymce); bgneal@442: (function(tinymce) { bgneal@312: // Shorten class names bgneal@312: var DOM = tinymce.DOM, is = tinymce.is; bgneal@312: bgneal@312: tinymce.create('tinymce.ui.Control', { bgneal@442: Control : function(id, s, editor) { bgneal@312: this.id = id; bgneal@312: this.settings = s = s || {}; bgneal@312: this.rendered = false; bgneal@312: this.onRender = new tinymce.util.Dispatcher(this); bgneal@312: this.classPrefix = ''; bgneal@312: this.scope = s.scope || this; bgneal@312: this.disabled = 0; bgneal@312: this.active = 0; bgneal@442: this.editor = editor; bgneal@442: }, bgneal@442: bgneal@442: setAriaProperty : function(property, value) { bgneal@442: var element = DOM.get(this.id + '_aria') || DOM.get(this.id); bgneal@442: if (element) { bgneal@442: DOM.setAttrib(element, 'aria-' + property, !!value); bgneal@442: } bgneal@442: }, bgneal@442: bgneal@442: focus : function() { bgneal@442: DOM.get(this.id).focus(); bgneal@312: }, bgneal@312: bgneal@312: setDisabled : function(s) { bgneal@312: if (s != this.disabled) { bgneal@442: this.setAriaProperty('disabled', s); bgneal@312: bgneal@312: this.setState('Disabled', s); bgneal@312: this.setState('Enabled', !s); bgneal@312: this.disabled = s; bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: isDisabled : function() { bgneal@312: return this.disabled; bgneal@312: }, bgneal@312: bgneal@312: setActive : function(s) { bgneal@312: if (s != this.active) { bgneal@312: this.setState('Active', s); bgneal@312: this.active = s; bgneal@442: this.setAriaProperty('pressed', s); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: isActive : function() { bgneal@312: return this.active; bgneal@312: }, bgneal@312: bgneal@312: setState : function(c, s) { bgneal@312: var n = DOM.get(this.id); bgneal@312: bgneal@312: c = this.classPrefix + c; bgneal@312: bgneal@312: if (s) bgneal@312: DOM.addClass(n, c); bgneal@312: else bgneal@312: DOM.removeClass(n, c); bgneal@312: }, bgneal@312: bgneal@312: isRendered : function() { bgneal@312: return this.rendered; bgneal@312: }, bgneal@312: bgneal@312: renderHTML : function() { bgneal@312: }, bgneal@312: bgneal@312: renderTo : function(n) { bgneal@312: DOM.setHTML(n, this.renderHTML()); bgneal@312: }, bgneal@312: bgneal@312: postRender : function() { bgneal@312: var t = this, b; bgneal@312: bgneal@312: // Set pending states bgneal@312: if (is(t.disabled)) { bgneal@312: b = t.disabled; bgneal@312: t.disabled = -1; bgneal@312: t.setDisabled(b); bgneal@312: } bgneal@312: bgneal@312: if (is(t.active)) { bgneal@312: b = t.active; bgneal@312: t.active = -1; bgneal@312: t.setActive(b); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: remove : function() { bgneal@312: DOM.remove(this.id); bgneal@312: this.destroy(); bgneal@312: }, bgneal@312: bgneal@312: destroy : function() { bgneal@312: tinymce.dom.Event.clear(this.id); bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: tinymce.create('tinymce.ui.Container:tinymce.ui.Control', { bgneal@442: Container : function(id, s, editor) { bgneal@442: this.parent(id, s, editor); bgneal@312: bgneal@312: this.controls = []; bgneal@312: bgneal@312: this.lookup = {}; bgneal@312: }, bgneal@312: bgneal@312: add : function(c) { bgneal@312: this.lookup[c.id] = c; bgneal@312: this.controls.push(c); bgneal@312: bgneal@312: return c; bgneal@312: }, bgneal@312: bgneal@312: get : function(n) { bgneal@312: return this.lookup[n]; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: bgneal@312: tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { bgneal@312: Separator : function(id, s) { bgneal@312: this.parent(id, s); bgneal@312: this.classPrefix = 'mceSeparator'; bgneal@442: this.setDisabled(true); bgneal@312: }, bgneal@312: bgneal@312: renderHTML : function() { bgneal@442: return tinymce.DOM.createHTML('span', {'class' : this.classPrefix, role : 'separator', 'aria-orientation' : 'vertical', tabindex : '-1'}); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk; bgneal@312: bgneal@312: tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', { bgneal@312: MenuItem : function(id, s) { bgneal@312: this.parent(id, s); bgneal@312: this.classPrefix = 'mceMenuItem'; bgneal@312: }, bgneal@312: bgneal@312: setSelected : function(s) { bgneal@312: this.setState('Selected', s); bgneal@442: this.setAriaProperty('checked', !!s); bgneal@312: this.selected = s; bgneal@312: }, bgneal@312: bgneal@312: isSelected : function() { bgneal@312: return this.selected; bgneal@312: }, bgneal@312: bgneal@312: postRender : function() { bgneal@312: var t = this; bgneal@312: bgneal@312: t.parent(); bgneal@312: bgneal@312: // Set pending state bgneal@312: if (is(t.selected)) bgneal@312: t.setSelected(t.selected); bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk; bgneal@312: bgneal@312: tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', { bgneal@312: Menu : function(id, s) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.parent(id, s); bgneal@312: t.items = {}; bgneal@312: t.collapsed = false; bgneal@312: t.menuCount = 0; bgneal@312: t.onAddItem = new tinymce.util.Dispatcher(this); bgneal@312: }, bgneal@312: bgneal@312: expand : function(d) { bgneal@312: var t = this; bgneal@312: bgneal@312: if (d) { bgneal@312: walk(t, function(o) { bgneal@312: if (o.expand) bgneal@312: o.expand(); bgneal@312: }, 'items', t); bgneal@312: } bgneal@312: bgneal@312: t.collapsed = false; bgneal@312: }, bgneal@312: bgneal@312: collapse : function(d) { bgneal@312: var t = this; bgneal@312: bgneal@312: if (d) { bgneal@312: walk(t, function(o) { bgneal@312: if (o.collapse) bgneal@312: o.collapse(); bgneal@312: }, 'items', t); bgneal@312: } bgneal@312: bgneal@312: t.collapsed = true; bgneal@312: }, bgneal@312: bgneal@312: isCollapsed : function() { bgneal@312: return this.collapsed; bgneal@312: }, bgneal@312: bgneal@312: add : function(o) { bgneal@312: if (!o.settings) bgneal@312: o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o); bgneal@312: bgneal@312: this.onAddItem.dispatch(this, o); bgneal@312: bgneal@312: return this.items[o.id] = o; bgneal@312: }, bgneal@312: bgneal@312: addSeparator : function() { bgneal@312: return this.add({separator : true}); bgneal@312: }, bgneal@312: bgneal@312: addMenu : function(o) { bgneal@312: if (!o.collapse) bgneal@312: o = this.createMenu(o); bgneal@312: bgneal@312: this.menuCount++; bgneal@312: bgneal@312: return this.add(o); bgneal@312: }, bgneal@312: bgneal@312: hasMenus : function() { bgneal@312: return this.menuCount !== 0; bgneal@312: }, bgneal@312: bgneal@312: remove : function(o) { bgneal@312: delete this.items[o.id]; bgneal@312: }, bgneal@312: bgneal@312: removeAll : function() { bgneal@312: var t = this; bgneal@312: bgneal@312: walk(t, function(o) { bgneal@312: if (o.removeAll) bgneal@312: o.removeAll(); bgneal@312: else bgneal@312: o.remove(); bgneal@312: bgneal@312: o.destroy(); bgneal@312: }, 'items', t); bgneal@312: bgneal@312: t.items = {}; bgneal@312: }, bgneal@312: bgneal@312: createMenu : function(o) { bgneal@312: var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o); bgneal@312: bgneal@312: m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem); bgneal@312: bgneal@312: return m; bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: (function(tinymce) { bgneal@312: var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element; bgneal@312: bgneal@312: tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', { bgneal@312: DropMenu : function(id, s) { bgneal@312: s = s || {}; bgneal@312: s.container = s.container || DOM.doc.body; bgneal@312: s.offset_x = s.offset_x || 0; bgneal@312: s.offset_y = s.offset_y || 0; bgneal@312: s.vp_offset_x = s.vp_offset_x || 0; bgneal@312: s.vp_offset_y = s.vp_offset_y || 0; bgneal@312: bgneal@312: if (is(s.icons) && !s.icons) bgneal@312: s['class'] += ' mceNoIcons'; bgneal@312: bgneal@312: this.parent(id, s); bgneal@312: this.onShowMenu = new tinymce.util.Dispatcher(this); bgneal@312: this.onHideMenu = new tinymce.util.Dispatcher(this); bgneal@312: this.classPrefix = 'mceMenu'; bgneal@312: }, bgneal@312: bgneal@312: createMenu : function(s) { bgneal@312: var t = this, cs = t.settings, m; bgneal@312: bgneal@312: s.container = s.container || cs.container; bgneal@312: s.parent = t; bgneal@312: s.constrain = s.constrain || cs.constrain; bgneal@312: s['class'] = s['class'] || cs['class']; bgneal@312: s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x; bgneal@312: s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y; bgneal@442: s.keyboard_focus = cs.keyboard_focus; bgneal@312: m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s); bgneal@312: bgneal@312: m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem); bgneal@312: bgneal@312: return m; bgneal@312: }, bgneal@442: bgneal@442: focus : function() { bgneal@442: var t = this; bgneal@442: if (t.keyboardNav) { bgneal@442: t.keyboardNav.focus(); bgneal@442: } bgneal@442: }, bgneal@312: bgneal@312: update : function() { bgneal@312: var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th; bgneal@312: bgneal@312: tw = s.max_width ? Math.min(tb.clientWidth, s.max_width) : tb.clientWidth; bgneal@312: th = s.max_height ? Math.min(tb.clientHeight, s.max_height) : tb.clientHeight; bgneal@312: bgneal@312: if (!DOM.boxModel) bgneal@312: t.element.setStyles({width : tw + 2, height : th + 2}); bgneal@312: else bgneal@312: t.element.setStyles({width : tw, height : th}); bgneal@312: bgneal@312: if (s.max_width) bgneal@312: DOM.setStyle(co, 'width', tw); bgneal@312: bgneal@312: if (s.max_height) { bgneal@312: DOM.setStyle(co, 'height', th); bgneal@312: bgneal@312: if (tb.clientHeight < s.max_height) bgneal@312: DOM.setStyle(co, 'overflow', 'hidden'); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: showMenu : function(x, y, px) { bgneal@312: var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix; bgneal@312: bgneal@312: t.collapse(1); bgneal@312: bgneal@312: if (t.isMenuVisible) bgneal@312: return; bgneal@312: bgneal@312: if (!t.rendered) { bgneal@312: co = DOM.add(t.settings.container, t.renderNode()); bgneal@312: bgneal@312: each(t.items, function(o) { bgneal@312: o.postRender(); bgneal@312: }); bgneal@312: bgneal@312: t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container}); bgneal@312: } else bgneal@312: co = DOM.get('menu_' + t.id); bgneal@312: bgneal@312: // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug bgneal@312: if (!tinymce.isOpera) bgneal@312: DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF}); bgneal@312: bgneal@312: DOM.show(co); bgneal@312: t.update(); bgneal@312: bgneal@312: x += s.offset_x || 0; bgneal@312: y += s.offset_y || 0; bgneal@312: vp.w -= 4; bgneal@312: vp.h -= 4; bgneal@312: bgneal@312: // Move inside viewport if not submenu bgneal@312: if (s.constrain) { bgneal@312: w = co.clientWidth - ot; bgneal@312: h = co.clientHeight - ot; bgneal@312: mx = vp.x + vp.w; bgneal@312: my = vp.y + vp.h; bgneal@312: bgneal@312: if ((x + s.vp_offset_x + w) > mx) bgneal@312: x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w); bgneal@312: bgneal@312: if ((y + s.vp_offset_y + h) > my) bgneal@312: y = Math.max(0, (my - s.vp_offset_y) - h); bgneal@312: } bgneal@312: bgneal@312: DOM.setStyles(co, {left : x , top : y}); bgneal@312: t.element.update(); bgneal@312: bgneal@312: t.isMenuVisible = 1; bgneal@312: t.mouseClickFunc = Event.add(co, 'click', function(e) { bgneal@312: var m; bgneal@312: bgneal@312: e = e.target; bgneal@312: bgneal@312: if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) { bgneal@312: m = t.items[e.id]; bgneal@312: bgneal@312: if (m.isDisabled()) bgneal@312: return; bgneal@312: bgneal@312: dm = t; bgneal@312: bgneal@312: while (dm) { bgneal@312: if (dm.hideMenu) bgneal@312: dm.hideMenu(); bgneal@312: bgneal@312: dm = dm.settings.parent; bgneal@312: } bgneal@312: bgneal@312: if (m.settings.onclick) bgneal@312: m.settings.onclick(e); bgneal@312: bgneal@312: return Event.cancel(e); // Cancel to fix onbeforeunload problem bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: if (t.hasMenus()) { bgneal@312: t.mouseOverFunc = Event.add(co, 'mouseover', function(e) { bgneal@312: var m, r, mi; bgneal@312: bgneal@312: e = e.target; bgneal@312: if (e && (e = DOM.getParent(e, 'tr'))) { bgneal@312: m = t.items[e.id]; bgneal@312: bgneal@312: if (t.lastMenu) bgneal@312: t.lastMenu.collapse(1); bgneal@312: bgneal@312: if (m.isDisabled()) bgneal@312: return; bgneal@312: bgneal@312: if (e && DOM.hasClass(e, cp + 'ItemSub')) { bgneal@312: //p = DOM.getPos(s.container); bgneal@312: r = DOM.getRect(e); bgneal@312: m.showMenu((r.x + r.w - ot), r.y - ot, r.x); bgneal@312: t.lastMenu = m; bgneal@312: DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive'); bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@442: bgneal@442: Event.add(co, 'keydown', t._keyHandler, t); bgneal@312: bgneal@312: t.onShowMenu.dispatch(t); bgneal@312: bgneal@442: if (s.keyboard_focus) { bgneal@442: t._setupKeyboardNav(); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: hideMenu : function(c) { bgneal@312: var t = this, co = DOM.get('menu_' + t.id), e; bgneal@312: bgneal@312: if (!t.isMenuVisible) bgneal@312: return; bgneal@312: bgneal@442: if (t.keyboardNav) t.keyboardNav.destroy(); bgneal@312: Event.remove(co, 'mouseover', t.mouseOverFunc); bgneal@312: Event.remove(co, 'click', t.mouseClickFunc); bgneal@312: Event.remove(co, 'keydown', t._keyHandler); bgneal@312: DOM.hide(co); bgneal@312: t.isMenuVisible = 0; bgneal@312: bgneal@312: if (!c) bgneal@312: t.collapse(1); bgneal@312: bgneal@312: if (t.element) bgneal@312: t.element.hide(); bgneal@312: bgneal@312: if (e = DOM.get(t.id)) bgneal@312: DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive'); bgneal@312: bgneal@312: t.onHideMenu.dispatch(t); bgneal@312: }, bgneal@312: bgneal@312: add : function(o) { bgneal@312: var t = this, co; bgneal@312: bgneal@312: o = t.parent(o); bgneal@312: bgneal@312: if (t.isRendered && (co = DOM.get('menu_' + t.id))) bgneal@312: t._add(DOM.select('tbody', co)[0], o); bgneal@312: bgneal@312: return o; bgneal@312: }, bgneal@312: bgneal@312: collapse : function(d) { bgneal@312: this.parent(d); bgneal@312: this.hideMenu(1); bgneal@312: }, bgneal@312: bgneal@312: remove : function(o) { bgneal@312: DOM.remove(o.id); bgneal@312: this.destroy(); bgneal@312: bgneal@312: return this.parent(o); bgneal@312: }, bgneal@312: bgneal@312: destroy : function() { bgneal@312: var t = this, co = DOM.get('menu_' + t.id); bgneal@312: bgneal@442: if (t.keyboardNav) t.keyboardNav.destroy(); bgneal@312: Event.remove(co, 'mouseover', t.mouseOverFunc); bgneal@442: Event.remove(DOM.select('a', co), 'focus', t.mouseOverFunc); bgneal@312: Event.remove(co, 'click', t.mouseClickFunc); bgneal@442: Event.remove(co, 'keydown', t._keyHandler); bgneal@312: bgneal@312: if (t.element) bgneal@312: t.element.remove(); bgneal@312: bgneal@312: DOM.remove(co); bgneal@312: }, bgneal@312: bgneal@312: renderNode : function() { bgneal@312: var t = this, s = t.settings, n, tb, co, w; bgneal@312: bgneal@442: 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'}); bgneal@442: if (t.settings.parent) { bgneal@442: DOM.setAttrib(w, 'aria-parent', 'menu_' + t.settings.parent.id); bgneal@442: } bgneal@442: co = DOM.add(w, 'div', {role: 'presentation', id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')}); bgneal@312: t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container}); bgneal@312: bgneal@312: if (s.menu_line) bgneal@312: DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'}); bgneal@312: bgneal@312: // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'}); bgneal@442: n = DOM.add(co, 'table', {role: 'presentation', id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0}); bgneal@312: tb = DOM.add(n, 'tbody'); bgneal@312: bgneal@312: each(t.items, function(o) { bgneal@312: t._add(tb, o); bgneal@312: }); bgneal@312: bgneal@312: t.rendered = true; bgneal@312: bgneal@312: return w; bgneal@312: }, bgneal@312: bgneal@312: // Internal functions bgneal@442: _setupKeyboardNav : function(){ bgneal@442: var contextMenu, menuItems, t=this; bgneal@442: contextMenu = DOM.select('#menu_' + t.id)[0]; bgneal@442: menuItems = DOM.select('a[role=option]', 'menu_' + t.id); bgneal@442: menuItems.splice(0,0,contextMenu); bgneal@442: t.keyboardNav = new tinymce.ui.KeyboardNavigation({ bgneal@442: root: 'menu_' + t.id, bgneal@442: items: menuItems, bgneal@442: onCancel: function() { bgneal@442: t.hideMenu(); bgneal@442: }, bgneal@442: enableUpDown: true bgneal@442: }); bgneal@442: contextMenu.focus(); bgneal@442: }, bgneal@442: bgneal@442: _keyHandler : function(evt) { bgneal@442: var t = this, e; bgneal@442: switch (evt.keyCode) { bgneal@442: case 37: // Left bgneal@442: if (t.settings.parent) { bgneal@442: t.hideMenu(); bgneal@442: t.settings.parent.focus(); bgneal@442: Event.cancel(evt); bgneal@442: } bgneal@442: break; bgneal@442: case 39: // Right bgneal@442: if (t.mouseOverFunc) bgneal@442: t.mouseOverFunc(evt); bgneal@442: break; bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: _add : function(tb, o) { bgneal@312: var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic; bgneal@312: bgneal@312: if (s.separator) { bgneal@312: ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'}); bgneal@312: DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'}); bgneal@312: bgneal@312: if (n = ro.previousSibling) bgneal@312: DOM.addClass(n, 'mceLast'); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'}); bgneal@442: n = it = DOM.add(n, s.titleItem ? 'th' : 'td'); bgneal@442: n = a = DOM.add(n, 'a', {id: o.id + '_aria', role: s.titleItem ? 'presentation' : 'option', href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'}); bgneal@442: bgneal@442: if (s.parent) { bgneal@442: DOM.setAttrib(a, 'aria-haspopup', 'true'); bgneal@442: DOM.setAttrib(a, 'aria-owns', 'menu_' + o.id); bgneal@442: } bgneal@312: bgneal@312: DOM.addClass(it, s['class']); bgneal@312: // n = DOM.add(n, 'span', {'class' : 'item'}); bgneal@312: bgneal@312: ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')}); bgneal@312: bgneal@312: if (s.icon_src) bgneal@312: DOM.add(ic, 'img', {src : s.icon_src}); bgneal@312: bgneal@312: n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title); bgneal@312: bgneal@312: if (o.settings.style) bgneal@312: DOM.setAttrib(n, 'style', o.settings.style); bgneal@312: bgneal@312: if (tb.childNodes.length == 1) bgneal@312: DOM.addClass(ro, 'mceFirst'); bgneal@312: bgneal@312: if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator')) bgneal@312: DOM.addClass(ro, 'mceFirst'); bgneal@312: bgneal@312: if (o.collapse) bgneal@312: DOM.addClass(ro, cp + 'ItemSub'); bgneal@312: bgneal@312: if (n = ro.previousSibling) bgneal@312: DOM.removeClass(n, 'mceLast'); bgneal@312: bgneal@312: DOM.addClass(ro, 'mceLast'); bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: (function(tinymce) { bgneal@312: var DOM = tinymce.DOM; bgneal@312: bgneal@312: tinymce.create('tinymce.ui.Button:tinymce.ui.Control', { bgneal@442: Button : function(id, s, ed) { bgneal@442: this.parent(id, s, ed); bgneal@312: this.classPrefix = 'mceButton'; bgneal@312: }, bgneal@312: bgneal@312: renderHTML : function() { bgneal@312: var cp = this.classPrefix, s = this.settings, h, l; bgneal@312: bgneal@312: l = DOM.encode(s.label || ''); bgneal@442: h = ''; bgneal@312: bgneal@312: if (s.image) bgneal@442: h += '' + DOM.encode(s.title) + '' + l; bgneal@312: else bgneal@442: h += '' + (l ? '' + l + '' : ''); bgneal@442: bgneal@442: h += ''; bgneal@442: h += ''; bgneal@312: return h; bgneal@312: }, bgneal@312: bgneal@312: postRender : function() { bgneal@312: var t = this, s = t.settings; bgneal@312: bgneal@312: tinymce.dom.Event.add(t.id, 'click', function(e) { bgneal@312: if (!t.isDisabled()) bgneal@312: return s.onclick.call(s.scope, e); bgneal@312: }); bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher; bgneal@312: bgneal@312: tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', { bgneal@442: ListBox : function(id, s, ed) { bgneal@312: var t = this; bgneal@312: bgneal@442: t.parent(id, s, ed); bgneal@312: bgneal@312: t.items = []; bgneal@312: bgneal@312: t.onChange = new Dispatcher(t); bgneal@312: bgneal@312: t.onPostRender = new Dispatcher(t); bgneal@312: bgneal@312: t.onAdd = new Dispatcher(t); bgneal@312: bgneal@312: t.onRenderMenu = new tinymce.util.Dispatcher(this); bgneal@312: bgneal@312: t.classPrefix = 'mceListBox'; bgneal@312: }, bgneal@312: bgneal@312: select : function(va) { bgneal@312: var t = this, fv, f; bgneal@312: bgneal@312: if (va == undefined) bgneal@312: return t.selectByIndex(-1); bgneal@312: bgneal@312: // Is string or number make function selector bgneal@312: if (va && va.call) bgneal@312: f = va; bgneal@312: else { bgneal@312: f = function(v) { bgneal@312: return v == va; bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: // Do we need to do something? bgneal@312: if (va != t.selectedValue) { bgneal@312: // Find item bgneal@312: each(t.items, function(o, i) { bgneal@312: if (f(o.value)) { bgneal@312: fv = 1; bgneal@312: t.selectByIndex(i); bgneal@312: return false; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: if (!fv) bgneal@312: t.selectByIndex(-1); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: selectByIndex : function(idx) { bgneal@312: var t = this, e, o; bgneal@312: bgneal@312: if (idx != t.selectedIndex) { bgneal@312: e = DOM.get(t.id + '_text'); bgneal@312: o = t.items[idx]; bgneal@312: bgneal@312: if (o) { bgneal@312: t.selectedValue = o.value; bgneal@312: t.selectedIndex = idx; bgneal@312: DOM.setHTML(e, DOM.encode(o.title)); bgneal@312: DOM.removeClass(e, 'mceTitle'); bgneal@442: DOM.setAttrib(t.id, 'aria-valuenow', o.title); bgneal@312: } else { bgneal@312: DOM.setHTML(e, DOM.encode(t.settings.title)); bgneal@312: DOM.addClass(e, 'mceTitle'); bgneal@312: t.selectedValue = t.selectedIndex = null; bgneal@442: DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title); bgneal@442: } bgneal@312: e = 0; bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: add : function(n, v, o) { bgneal@312: var t = this; bgneal@312: bgneal@312: o = o || {}; bgneal@312: o = tinymce.extend(o, { bgneal@312: title : n, bgneal@312: value : v bgneal@312: }); bgneal@312: bgneal@312: t.items.push(o); bgneal@312: t.onAdd.dispatch(t, o); bgneal@312: }, bgneal@312: bgneal@312: getLength : function() { bgneal@312: return this.items.length; bgneal@312: }, bgneal@312: bgneal@312: renderHTML : function() { bgneal@312: var h = '', t = this, s = t.settings, cp = t.classPrefix; bgneal@312: bgneal@442: h = ''; bgneal@442: h += ''; bgneal@442: h += ''; bgneal@442: h += ''; bgneal@312: bgneal@312: return h; bgneal@312: }, bgneal@312: bgneal@312: showMenu : function() { bgneal@312: var t = this, p1, p2, e = DOM.get(this.id), m; bgneal@312: bgneal@312: if (t.isDisabled() || t.items.length == 0) bgneal@312: return; bgneal@312: bgneal@312: if (t.menu && t.menu.isMenuVisible) bgneal@312: return t.hideMenu(); bgneal@312: bgneal@312: if (!t.isMenuRendered) { bgneal@312: t.renderMenu(); bgneal@312: t.isMenuRendered = true; bgneal@312: } bgneal@312: bgneal@312: p1 = DOM.getPos(this.settings.menu_container); bgneal@312: p2 = DOM.getPos(e); bgneal@312: bgneal@312: m = t.menu; bgneal@312: m.settings.offset_x = p2.x; bgneal@312: m.settings.offset_y = p2.y; bgneal@312: m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus bgneal@312: bgneal@312: // Select in menu bgneal@312: if (t.oldID) bgneal@312: m.items[t.oldID].setSelected(0); bgneal@312: bgneal@312: each(t.items, function(o) { bgneal@312: if (o.value === t.selectedValue) { bgneal@312: m.items[o.id].setSelected(1); bgneal@312: t.oldID = o.id; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: m.showMenu(0, e.clientHeight); bgneal@312: bgneal@312: Event.add(DOM.doc, 'mousedown', t.hideMenu, t); bgneal@312: DOM.addClass(t.id, t.classPrefix + 'Selected'); bgneal@312: bgneal@312: //DOM.get(t.id + '_text').focus(); bgneal@312: }, bgneal@312: bgneal@312: hideMenu : function(e) { bgneal@312: var t = this; bgneal@312: bgneal@312: if (t.menu && t.menu.isMenuVisible) { bgneal@442: DOM.removeClass(t.id, t.classPrefix + 'Selected'); bgneal@442: bgneal@312: // Prevent double toogles by canceling the mouse click event to the button bgneal@312: if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open')) bgneal@312: return; bgneal@312: bgneal@312: if (!e || !DOM.getParent(e.target, '.mceMenu')) { bgneal@312: DOM.removeClass(t.id, t.classPrefix + 'Selected'); bgneal@312: Event.remove(DOM.doc, 'mousedown', t.hideMenu, t); bgneal@312: t.menu.hideMenu(); bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: renderMenu : function() { bgneal@312: var t = this, m; bgneal@312: bgneal@312: m = t.settings.control_manager.createDropMenu(t.id + '_menu', { bgneal@312: menu_line : 1, bgneal@312: 'class' : t.classPrefix + 'Menu mceNoIcons', bgneal@312: max_width : 150, bgneal@312: max_height : 150 bgneal@312: }); bgneal@312: bgneal@442: m.onHideMenu.add(function() { bgneal@442: t.hideMenu(); bgneal@442: t.focus(); bgneal@442: }); bgneal@312: bgneal@312: m.add({ bgneal@312: title : t.settings.title, bgneal@312: 'class' : 'mceMenuItemTitle', bgneal@312: onclick : function() { bgneal@312: if (t.settings.onselect('') !== false) bgneal@312: t.select(''); // Must be runned after bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: each(t.items, function(o) { bgneal@312: // No value then treat it as a title bgneal@312: if (o.value === undefined) { bgneal@312: m.add({ bgneal@312: title : o.title, bgneal@312: 'class' : 'mceMenuItemTitle', bgneal@312: onclick : function() { bgneal@312: if (t.settings.onselect('') !== false) bgneal@312: t.select(''); // Must be runned after bgneal@312: } bgneal@312: }); bgneal@312: } else { bgneal@312: o.id = DOM.uniqueId(); bgneal@312: o.onclick = function() { bgneal@312: if (t.settings.onselect(o.value) !== false) bgneal@312: t.select(o.value); // Must be runned after bgneal@312: }; bgneal@312: bgneal@312: m.add(o); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: t.onRenderMenu.dispatch(t, m); bgneal@312: t.menu = m; bgneal@312: }, bgneal@312: bgneal@312: postRender : function() { bgneal@312: var t = this, cp = t.classPrefix; bgneal@312: bgneal@312: Event.add(t.id, 'click', t.showMenu, t); bgneal@442: Event.add(t.id, 'keydown', function(evt) { bgneal@442: if (evt.keyCode == 32) { // Space bgneal@442: t.showMenu(evt); bgneal@442: Event.cancel(evt); bgneal@442: } bgneal@442: }); bgneal@442: Event.add(t.id, 'focus', function() { bgneal@312: if (!t._focused) { bgneal@442: t.keyDownHandler = Event.add(t.id, 'keydown', function(e) { bgneal@442: if (e.keyCode == 40) { bgneal@442: t.showMenu(); bgneal@442: Event.cancel(e); bgneal@442: } bgneal@442: }); bgneal@442: t.keyPressHandler = Event.add(t.id, 'keypress', function(e) { bgneal@442: var v; bgneal@442: if (e.keyCode == 13) { bgneal@312: // Fake select on enter bgneal@312: v = t.selectedValue; bgneal@312: t.selectedValue = null; // Needs to be null to fake change bgneal@442: Event.cancel(e); bgneal@312: t.settings.onselect(v); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: t._focused = 1; bgneal@312: }); bgneal@442: Event.add(t.id, 'blur', function() { bgneal@442: Event.remove(t.id, 'keydown', t.keyDownHandler); bgneal@442: Event.remove(t.id, 'keypress', t.keyPressHandler); bgneal@442: t._focused = 0; bgneal@442: }); bgneal@312: bgneal@312: // Old IE doesn't have hover on all elements bgneal@312: if (tinymce.isIE6 || !DOM.boxModel) { bgneal@312: Event.add(t.id, 'mouseover', function() { bgneal@312: if (!DOM.hasClass(t.id, cp + 'Disabled')) bgneal@312: DOM.addClass(t.id, cp + 'Hover'); bgneal@312: }); bgneal@312: bgneal@312: Event.add(t.id, 'mouseout', function() { bgneal@312: if (!DOM.hasClass(t.id, cp + 'Disabled')) bgneal@312: DOM.removeClass(t.id, cp + 'Hover'); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: t.onPostRender.dispatch(t, DOM.get(t.id)); bgneal@312: }, bgneal@312: bgneal@312: destroy : function() { bgneal@312: this.parent(); bgneal@312: bgneal@312: Event.clear(this.id + '_text'); bgneal@312: Event.clear(this.id + '_open'); bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: (function(tinymce) { bgneal@312: var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher; bgneal@312: bgneal@312: tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', { bgneal@312: NativeListBox : function(id, s) { bgneal@312: this.parent(id, s); bgneal@312: this.classPrefix = 'mceNativeListBox'; bgneal@312: }, bgneal@312: bgneal@312: setDisabled : function(s) { bgneal@312: DOM.get(this.id).disabled = s; bgneal@442: this.setAriaProperty('disabled', s); bgneal@312: }, bgneal@312: bgneal@312: isDisabled : function() { bgneal@312: return DOM.get(this.id).disabled; bgneal@312: }, bgneal@312: bgneal@312: select : function(va) { bgneal@312: var t = this, fv, f; bgneal@312: bgneal@312: if (va == undefined) bgneal@312: return t.selectByIndex(-1); bgneal@312: bgneal@312: // Is string or number make function selector bgneal@312: if (va && va.call) bgneal@312: f = va; bgneal@312: else { bgneal@312: f = function(v) { bgneal@312: return v == va; bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: // Do we need to do something? bgneal@312: if (va != t.selectedValue) { bgneal@312: // Find item bgneal@312: each(t.items, function(o, i) { bgneal@312: if (f(o.value)) { bgneal@312: fv = 1; bgneal@312: t.selectByIndex(i); bgneal@312: return false; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: if (!fv) bgneal@312: t.selectByIndex(-1); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: selectByIndex : function(idx) { bgneal@312: DOM.get(this.id).selectedIndex = idx + 1; bgneal@312: this.selectedValue = this.items[idx] ? this.items[idx].value : null; bgneal@312: }, bgneal@312: bgneal@312: add : function(n, v, a) { bgneal@312: var o, t = this; bgneal@312: bgneal@312: a = a || {}; bgneal@312: a.value = v; bgneal@312: bgneal@312: if (t.isRendered()) bgneal@312: DOM.add(DOM.get(this.id), 'option', a, n); bgneal@312: bgneal@312: o = { bgneal@312: title : n, bgneal@312: value : v, bgneal@312: attribs : a bgneal@312: }; bgneal@312: bgneal@312: t.items.push(o); bgneal@312: t.onAdd.dispatch(t, o); bgneal@312: }, bgneal@312: bgneal@312: getLength : function() { bgneal@312: return this.items.length; bgneal@312: }, bgneal@312: bgneal@312: renderHTML : function() { bgneal@312: var h, t = this; bgneal@312: bgneal@312: h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --'); bgneal@312: bgneal@312: each(t.items, function(it) { bgneal@312: h += DOM.createHTML('option', {value : it.value}, it.title); bgneal@312: }); bgneal@312: bgneal@442: h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox', 'aria-labelledby': t.id + '_aria'}, h); bgneal@442: h += DOM.createHTML('span', {id : t.id + '_aria', 'style': 'display: none'}, t.settings.title); bgneal@312: return h; bgneal@312: }, bgneal@312: bgneal@312: postRender : function() { bgneal@442: var t = this, ch, changeListenerAdded = true; bgneal@312: bgneal@312: t.rendered = true; bgneal@312: bgneal@312: function onChange(e) { bgneal@312: var v = t.items[e.target.selectedIndex - 1]; bgneal@312: bgneal@312: if (v && (v = v.value)) { bgneal@312: t.onChange.dispatch(t, v); bgneal@312: bgneal@312: if (t.settings.onselect) bgneal@312: t.settings.onselect(v); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: Event.add(t.id, 'change', onChange); bgneal@312: bgneal@312: // Accessibility keyhandler bgneal@312: Event.add(t.id, 'keydown', function(e) { bgneal@312: var bf; bgneal@312: bgneal@312: Event.remove(t.id, 'change', ch); bgneal@442: changeListenerAdded = false; bgneal@312: bgneal@312: bf = Event.add(t.id, 'blur', function() { bgneal@442: if (changeListenerAdded) return; bgneal@442: changeListenerAdded = true; bgneal@312: Event.add(t.id, 'change', onChange); bgneal@312: Event.remove(t.id, 'blur', bf); bgneal@312: }); bgneal@312: bgneal@312: if (e.keyCode == 13 || e.keyCode == 32) { bgneal@312: onChange(e); bgneal@312: return Event.cancel(e); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: t.onPostRender.dispatch(t, DOM.get(t.id)); bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: (function(tinymce) { bgneal@312: var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each; bgneal@312: bgneal@312: tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', { bgneal@442: MenuButton : function(id, s, ed) { bgneal@442: this.parent(id, s, ed); bgneal@312: bgneal@312: this.onRenderMenu = new tinymce.util.Dispatcher(this); bgneal@312: bgneal@312: s.menu_container = s.menu_container || DOM.doc.body; bgneal@312: }, bgneal@312: bgneal@312: showMenu : function() { bgneal@312: var t = this, p1, p2, e = DOM.get(t.id), m; bgneal@312: bgneal@312: if (t.isDisabled()) bgneal@312: return; bgneal@312: bgneal@312: if (!t.isMenuRendered) { bgneal@312: t.renderMenu(); bgneal@312: t.isMenuRendered = true; bgneal@312: } bgneal@312: bgneal@312: if (t.isMenuVisible) bgneal@312: return t.hideMenu(); bgneal@312: bgneal@312: p1 = DOM.getPos(t.settings.menu_container); bgneal@312: p2 = DOM.getPos(e); bgneal@312: bgneal@312: m = t.menu; bgneal@312: m.settings.offset_x = p2.x; bgneal@312: m.settings.offset_y = p2.y; bgneal@312: m.settings.vp_offset_x = p2.x; bgneal@312: m.settings.vp_offset_y = p2.y; bgneal@312: m.settings.keyboard_focus = t._focused; bgneal@312: m.showMenu(0, e.clientHeight); bgneal@312: bgneal@312: Event.add(DOM.doc, 'mousedown', t.hideMenu, t); bgneal@312: t.setState('Selected', 1); bgneal@312: bgneal@312: t.isMenuVisible = 1; bgneal@312: }, bgneal@312: bgneal@312: renderMenu : function() { bgneal@312: var t = this, m; bgneal@312: bgneal@312: m = t.settings.control_manager.createDropMenu(t.id + '_menu', { bgneal@312: menu_line : 1, bgneal@312: 'class' : this.classPrefix + 'Menu', bgneal@312: icons : t.settings.icons bgneal@312: }); bgneal@312: bgneal@442: m.onHideMenu.add(function() { bgneal@442: t.hideMenu(); bgneal@442: t.focus(); bgneal@442: }); bgneal@312: bgneal@312: t.onRenderMenu.dispatch(t, m); bgneal@312: t.menu = m; bgneal@312: }, bgneal@312: bgneal@312: hideMenu : function(e) { bgneal@312: var t = this; bgneal@312: bgneal@312: // Prevent double toogles by canceling the mouse click event to the button bgneal@312: if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';})) bgneal@312: return; bgneal@312: bgneal@312: if (!e || !DOM.getParent(e.target, '.mceMenu')) { bgneal@312: t.setState('Selected', 0); bgneal@312: Event.remove(DOM.doc, 'mousedown', t.hideMenu, t); bgneal@312: if (t.menu) bgneal@312: t.menu.hideMenu(); bgneal@312: } bgneal@312: bgneal@312: t.isMenuVisible = 0; bgneal@312: }, bgneal@312: bgneal@312: postRender : function() { bgneal@312: var t = this, s = t.settings; bgneal@312: bgneal@312: Event.add(t.id, 'click', function() { bgneal@312: if (!t.isDisabled()) { bgneal@312: if (s.onclick) bgneal@312: s.onclick(t.value); bgneal@312: bgneal@312: t.showMenu(); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each; bgneal@312: bgneal@312: tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', { bgneal@442: SplitButton : function(id, s, ed) { bgneal@442: this.parent(id, s, ed); bgneal@312: this.classPrefix = 'mceSplitButton'; bgneal@312: }, bgneal@312: bgneal@312: renderHTML : function() { bgneal@312: var h, t = this, s = t.settings, h1; bgneal@312: bgneal@312: h = ''; bgneal@312: bgneal@312: if (s.image) bgneal@442: h1 = DOM.createHTML('img ', {src : s.image, role: 'presentation', 'class' : 'mceAction ' + s['class']}); bgneal@312: else bgneal@312: h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, ''); bgneal@312: bgneal@442: h1 += DOM.createHTML('span', {'class': 'mceVoiceLabel mceIconOnly', id: t.id + '_voice', style: 'display:none;'}, s.title); bgneal@442: h += '' + 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) + ''; bgneal@312: bgneal@442: h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}, ''); bgneal@442: h += '' + 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) + ''; bgneal@312: bgneal@312: h += ''; bgneal@442: h = DOM.createHTML('table', {id : t.id, role: 'presentation', tabindex: '0', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h); bgneal@442: return DOM.createHTML('span', {role: 'button', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h); bgneal@312: }, bgneal@312: bgneal@312: postRender : function() { bgneal@442: var t = this, s = t.settings, activate; bgneal@312: bgneal@312: if (s.onclick) { bgneal@442: activate = function(evt) { bgneal@442: if (!t.isDisabled()) { bgneal@312: s.onclick(t.value); bgneal@442: Event.cancel(evt); bgneal@442: } bgneal@442: }; bgneal@442: Event.add(t.id + '_action', 'click', activate); bgneal@442: Event.add(t.id, ['click', 'keydown'], function(evt) { bgneal@442: var DOM_VK_SPACE = 32, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_UP = 38, DOM_VK_DOWN = 40; bgneal@442: if ((evt.keyCode === 32 || evt.keyCode === 13 || evt.keyCode === 14) && !evt.altKey && !evt.ctrlKey && !evt.metaKey) { bgneal@442: activate(); bgneal@442: Event.cancel(evt); bgneal@442: } else if (evt.type === 'click' || evt.keyCode === DOM_VK_DOWN) { bgneal@442: t.showMenu(); bgneal@442: Event.cancel(evt); bgneal@442: } bgneal@442: }); bgneal@442: } bgneal@442: bgneal@442: Event.add(t.id + '_open', 'click', function (evt) { bgneal@442: t.showMenu(); bgneal@442: Event.cancel(evt); bgneal@442: }); bgneal@442: Event.add([t.id, t.id + '_open'], 'focus', function() {t._focused = 1;}); bgneal@442: Event.add([t.id, t.id + '_open'], 'blur', function() {t._focused = 0;}); bgneal@312: bgneal@312: // Old IE doesn't have hover on all elements bgneal@312: if (tinymce.isIE6 || !DOM.boxModel) { bgneal@312: Event.add(t.id, 'mouseover', function() { bgneal@312: if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled')) bgneal@312: DOM.addClass(t.id, 'mceSplitButtonHover'); bgneal@312: }); bgneal@312: bgneal@312: Event.add(t.id, 'mouseout', function() { bgneal@312: if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled')) bgneal@312: DOM.removeClass(t.id, 'mceSplitButtonHover'); bgneal@312: }); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: destroy : function() { bgneal@312: this.parent(); bgneal@312: bgneal@312: Event.clear(this.id + '_action'); bgneal@312: Event.clear(this.id + '_open'); bgneal@442: Event.clear(this.id); bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each; bgneal@312: bgneal@312: tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', { bgneal@442: ColorSplitButton : function(id, s, ed) { bgneal@312: var t = this; bgneal@312: bgneal@442: t.parent(id, s, ed); bgneal@312: bgneal@312: t.settings = s = tinymce.extend({ bgneal@312: 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', bgneal@312: grid_width : 8, bgneal@312: default_color : '#888888' bgneal@312: }, t.settings); bgneal@312: bgneal@312: t.onShowMenu = new tinymce.util.Dispatcher(t); bgneal@312: bgneal@312: t.onHideMenu = new tinymce.util.Dispatcher(t); bgneal@312: bgneal@312: t.value = s.default_color; bgneal@312: }, bgneal@312: bgneal@312: showMenu : function() { bgneal@312: var t = this, r, p, e, p2; bgneal@312: bgneal@312: if (t.isDisabled()) bgneal@312: return; bgneal@312: bgneal@312: if (!t.isMenuRendered) { bgneal@312: t.renderMenu(); bgneal@312: t.isMenuRendered = true; bgneal@312: } bgneal@312: bgneal@312: if (t.isMenuVisible) bgneal@312: return t.hideMenu(); bgneal@312: bgneal@312: e = DOM.get(t.id); bgneal@312: DOM.show(t.id + '_menu'); bgneal@312: DOM.addClass(e, 'mceSplitButtonSelected'); bgneal@312: p2 = DOM.getPos(e); bgneal@312: DOM.setStyles(t.id + '_menu', { bgneal@312: left : p2.x, bgneal@312: top : p2.y + e.clientHeight, bgneal@312: zIndex : 200000 bgneal@312: }); bgneal@312: e = 0; bgneal@312: bgneal@312: Event.add(DOM.doc, 'mousedown', t.hideMenu, t); bgneal@312: t.onShowMenu.dispatch(t); bgneal@312: bgneal@312: if (t._focused) { bgneal@312: t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) { bgneal@312: if (e.keyCode == 27) bgneal@312: t.hideMenu(); bgneal@312: }); bgneal@312: bgneal@312: DOM.select('a', t.id + '_menu')[0].focus(); // Select first link bgneal@312: } bgneal@312: bgneal@312: t.isMenuVisible = 1; bgneal@312: }, bgneal@312: bgneal@312: hideMenu : function(e) { bgneal@312: var t = this; bgneal@312: bgneal@442: if (t.isMenuVisible) { bgneal@442: // Prevent double toogles by canceling the mouse click event to the button bgneal@442: if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';})) bgneal@442: return; bgneal@442: bgneal@442: if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) { bgneal@442: DOM.removeClass(t.id, 'mceSplitButtonSelected'); bgneal@442: Event.remove(DOM.doc, 'mousedown', t.hideMenu, t); bgneal@442: Event.remove(t.id + '_menu', 'keydown', t._keyHandler); bgneal@442: DOM.hide(t.id + '_menu'); bgneal@442: } bgneal@442: bgneal@442: t.isMenuVisible = 0; bgneal@442: } bgneal@312: }, bgneal@312: bgneal@312: renderMenu : function() { bgneal@442: var t = this, m, i = 0, s = t.settings, n, tb, tr, w, context; bgneal@442: bgneal@442: 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;'}); bgneal@312: m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'}); bgneal@312: DOM.add(m, 'span', {'class' : 'mceMenuLine'}); bgneal@312: bgneal@442: n = DOM.add(m, 'table', {role: 'presentation', 'class' : 'mceColorSplitMenu'}); bgneal@312: tb = DOM.add(n, 'tbody'); bgneal@312: bgneal@312: // Generate color grid bgneal@312: i = 0; bgneal@312: each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) { bgneal@312: c = c.replace(/^#/, ''); bgneal@312: bgneal@312: if (!i--) { bgneal@312: tr = DOM.add(tb, 'tr'); bgneal@312: i = s.grid_width - 1; bgneal@312: } bgneal@312: bgneal@312: n = DOM.add(tr, 'td'); bgneal@312: n = DOM.add(n, 'a', { bgneal@442: role : 'option', bgneal@312: href : 'javascript:;', bgneal@312: style : { bgneal@312: backgroundColor : '#' + c bgneal@312: }, bgneal@442: 'title': t.editor.getLang('colors.' + c, c), bgneal@442: 'data-mce-color' : '#' + c bgneal@442: }); bgneal@442: bgneal@442: if (t.editor.forcedHighContrastMode) { bgneal@442: n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' }); bgneal@442: if (n.getContext && (context = n.getContext("2d"))) { bgneal@442: context.fillStyle = '#' + c; bgneal@442: context.fillRect(0, 0, 16, 16); bgneal@442: } else { bgneal@442: // No point leaving a canvas element around if it's not supported for drawing on anyway. bgneal@442: DOM.remove(n); bgneal@442: } bgneal@442: } bgneal@312: }); bgneal@312: bgneal@312: if (s.more_colors_func) { bgneal@312: n = DOM.add(tb, 'tr'); bgneal@312: n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'}); bgneal@442: n = DOM.add(n, 'a', {role: 'option', id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title); bgneal@312: bgneal@312: Event.add(n, 'click', function(e) { bgneal@312: s.more_colors_func.call(s.more_colors_scope || this); bgneal@312: return Event.cancel(e); // Cancel to fix onbeforeunload problem bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: DOM.addClass(m, 'mceColorSplitMenu'); bgneal@442: bgneal@442: new tinymce.ui.KeyboardNavigation({ bgneal@442: root: t.id + '_menu', bgneal@442: items: DOM.select('a', t.id + '_menu'), bgneal@442: onCancel: function() { bgneal@442: t.hideMenu(); bgneal@442: t.focus(); bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: // Prevent IE from scrolling and hindering click to occur #4019 bgneal@442: Event.add(t.id + '_menu', 'mousedown', function(e) {return Event.cancel(e);}); bgneal@312: bgneal@312: Event.add(t.id + '_menu', 'click', function(e) { bgneal@312: var c; bgneal@312: bgneal@442: e = DOM.getParent(e.target, 'a', tb); bgneal@442: bgneal@442: if (e && e.nodeName.toLowerCase() == 'a' && (c = e.getAttribute('data-mce-color'))) bgneal@312: t.setColor(c); bgneal@312: bgneal@312: return Event.cancel(e); // Prevent IE auto save warning bgneal@312: }); bgneal@312: bgneal@312: return w; bgneal@312: }, bgneal@312: bgneal@312: setColor : function(c) { bgneal@442: this.displayColor(c); bgneal@442: this.hideMenu(); bgneal@442: this.settings.onselect(c); bgneal@442: }, bgneal@442: bgneal@442: displayColor : function(c) { bgneal@312: var t = this; bgneal@312: bgneal@312: DOM.setStyle(t.id + '_preview', 'backgroundColor', c); bgneal@312: bgneal@312: t.value = c; bgneal@312: }, bgneal@312: bgneal@312: postRender : function() { bgneal@312: var t = this, id = t.id; bgneal@312: bgneal@312: t.parent(); bgneal@312: DOM.add(id + '_action', 'div', {id : id + '_preview', 'class' : 'mceColorPreview'}); bgneal@312: DOM.setStyle(t.id + '_preview', 'backgroundColor', t.value); bgneal@312: }, bgneal@312: bgneal@312: destroy : function() { bgneal@312: this.parent(); bgneal@312: bgneal@312: Event.clear(this.id + '_menu'); bgneal@312: Event.clear(this.id + '_more'); bgneal@312: DOM.remove(this.id + '_menu'); bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@442: (function(tinymce) { bgneal@442: // Shorten class names bgneal@442: var dom = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event; bgneal@442: tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', { bgneal@442: renderHTML : function() { bgneal@442: var t = this, h = [], controls = t.controls, each = tinymce.each, settings = t.settings; bgneal@442: bgneal@442: h.push('
    '); bgneal@442: //TODO: ACC test this out - adding a role = application for getting the landmarks working well. bgneal@442: h.push(""); bgneal@442: h.push(''); bgneal@442: each(controls, function(toolbar) { bgneal@442: h.push(toolbar.renderHTML()); bgneal@442: }); bgneal@442: h.push(""); bgneal@442: h.push('
    '); bgneal@442: bgneal@442: return h.join(''); bgneal@442: }, bgneal@442: bgneal@442: focus : function() { bgneal@442: this.keyNav.focus(); bgneal@442: }, bgneal@442: bgneal@442: postRender : function() { bgneal@442: var t = this, items = []; bgneal@442: bgneal@442: each(t.controls, function(toolbar) { bgneal@442: each (toolbar.controls, function(control) { bgneal@442: if (control.id) { bgneal@442: items.push(control); bgneal@442: } bgneal@442: }); bgneal@442: }); bgneal@442: bgneal@442: t.keyNav = new tinymce.ui.KeyboardNavigation({ bgneal@442: root: t.id, bgneal@442: items: items, bgneal@442: onCancel: function() { bgneal@442: t.editor.focus(); bgneal@442: }, bgneal@442: excludeFromTabOrder: !t.settings.tab_focus_toolbar bgneal@442: }); bgneal@442: }, bgneal@442: bgneal@442: destroy : function() { bgneal@442: var self = this; bgneal@442: bgneal@442: self.parent(); bgneal@442: self.keyNav.destroy(); bgneal@442: Event.clear(self.id); bgneal@442: } bgneal@442: }); bgneal@442: })(tinymce); bgneal@442: bgneal@442: (function(tinymce) { bgneal@442: // Shorten class names bgneal@442: var dom = tinymce.DOM, each = tinymce.each; bgneal@312: tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { bgneal@312: renderHTML : function() { bgneal@442: var t = this, h = '', c, co, s = t.settings, i, pr, nx, cl; bgneal@312: bgneal@312: cl = t.controls; bgneal@312: for (i=0; i')); bgneal@312: } bgneal@312: bgneal@312: // Add toolbar end before list box and after the previous button bgneal@312: // This is to fix the o2k7 editor skins bgneal@312: if (pr && co.ListBox) { bgneal@312: if (pr.Button || pr.SplitButton) bgneal@312: h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '')); bgneal@312: } bgneal@312: bgneal@312: // Render control HTML bgneal@312: bgneal@312: // IE 8 quick fix, needed to propertly generate a hit area for anchors bgneal@312: if (dom.stdMode) bgneal@312: h += '' + co.renderHTML() + ''; bgneal@312: else bgneal@312: h += '' + co.renderHTML() + ''; bgneal@312: bgneal@312: // Add toolbar start after list box and before the next button bgneal@312: // This is to fix the o2k7 editor skins bgneal@312: if (nx && co.ListBox) { bgneal@312: if (nx.Button || nx.SplitButton) bgneal@312: h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '')); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: c = 'mceToolbarEnd'; bgneal@312: bgneal@312: if (co.Button) bgneal@312: c += ' mceToolbarEndButton'; bgneal@312: else if (co.SplitButton) bgneal@312: c += ' mceToolbarEndSplitButton'; bgneal@312: else if (co.ListBox) bgneal@312: c += ' mceToolbarEndListBox'; bgneal@312: bgneal@312: h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '')); bgneal@312: bgneal@442: 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'}, '' + h + ''); bgneal@312: } bgneal@312: }); bgneal@442: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each; bgneal@312: bgneal@312: tinymce.create('tinymce.AddOnManager', { bgneal@312: AddOnManager : function() { bgneal@312: var self = this; bgneal@312: bgneal@312: self.items = []; bgneal@312: self.urls = {}; bgneal@312: self.lookup = {}; bgneal@312: self.onAdd = new Dispatcher(self); bgneal@312: }, bgneal@312: bgneal@312: get : function(n) { bgneal@312: return this.lookup[n]; bgneal@312: }, bgneal@312: bgneal@312: requireLangPack : function(n) { bgneal@312: var s = tinymce.settings; bgneal@312: bgneal@442: if (s && s.language && s.language_load !== false) bgneal@312: tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js'); bgneal@312: }, bgneal@312: bgneal@312: add : function(id, o) { bgneal@312: this.items.push(o); bgneal@312: this.lookup[id] = o; bgneal@312: this.onAdd.dispatch(this, id, o); bgneal@312: bgneal@312: return o; bgneal@312: }, bgneal@312: bgneal@312: load : function(n, u, cb, s) { bgneal@312: var t = this; bgneal@312: bgneal@312: if (t.urls[n]) bgneal@312: return; bgneal@312: bgneal@312: if (u.indexOf('/') != 0 && u.indexOf('://') == -1) bgneal@442: u = tinymce.baseURL + '/' + u; bgneal@312: bgneal@312: t.urls[n] = u.substring(0, u.lastIndexOf('/')); bgneal@312: bgneal@312: if (!t.lookup[n]) bgneal@312: tinymce.ScriptLoader.add(u, cb, s); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // Create plugin and theme managers bgneal@312: tinymce.PluginManager = new tinymce.AddOnManager(); bgneal@312: tinymce.ThemeManager = new tinymce.AddOnManager(); bgneal@312: }(tinymce)); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: // Shorten names bgneal@312: var each = tinymce.each, extend = tinymce.extend, bgneal@312: DOM = tinymce.DOM, Event = tinymce.dom.Event, bgneal@312: ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager, bgneal@312: explode = tinymce.explode, bgneal@312: Dispatcher = tinymce.util.Dispatcher, undefined, instanceCounter = 0; bgneal@312: bgneal@312: // Setup some URLs where the editor API is located and where the document is bgneal@312: tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, ''); bgneal@312: if (!/[\/\\]$/.test(tinymce.documentBaseURL)) bgneal@312: tinymce.documentBaseURL += '/'; bgneal@312: bgneal@312: tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL); bgneal@312: bgneal@312: tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL); bgneal@312: bgneal@312: // Add before unload listener bgneal@312: // This was required since IE was leaking memory if you added and removed beforeunload listeners bgneal@312: // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event bgneal@312: tinymce.onBeforeUnload = new Dispatcher(tinymce); bgneal@312: bgneal@312: // Must be on window or IE will leak if the editor is placed in frame or iframe bgneal@312: Event.add(window, 'beforeunload', function(e) { bgneal@312: tinymce.onBeforeUnload.dispatch(tinymce, e); bgneal@312: }); bgneal@312: bgneal@312: tinymce.onAddEditor = new Dispatcher(tinymce); bgneal@312: bgneal@312: tinymce.onRemoveEditor = new Dispatcher(tinymce); bgneal@312: bgneal@312: tinymce.EditorManager = extend(tinymce, { bgneal@312: editors : [], bgneal@312: bgneal@312: i18n : {}, bgneal@312: bgneal@312: activeEditor : null, bgneal@312: bgneal@312: init : function(s) { bgneal@312: var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed; bgneal@312: bgneal@312: function execCallback(se, n, s) { bgneal@312: var f = se[n]; bgneal@312: bgneal@312: if (!f) bgneal@312: return; bgneal@312: bgneal@312: if (tinymce.is(f, 'string')) { bgneal@312: s = f.replace(/\.\w+$/, ''); bgneal@312: s = s ? tinymce.resolve(s) : 0; bgneal@312: f = tinymce.resolve(f); bgneal@312: } bgneal@312: bgneal@312: return f.apply(s || this, Array.prototype.slice.call(arguments, 2)); bgneal@312: }; bgneal@312: bgneal@312: s = extend({ bgneal@312: theme : "simple", bgneal@312: language : "en" bgneal@312: }, s); bgneal@312: bgneal@312: t.settings = s; bgneal@312: bgneal@312: // Legacy call bgneal@312: Event.add(document, 'init', function() { bgneal@312: var l, co; bgneal@312: bgneal@312: execCallback(s, 'onpageload'); bgneal@312: bgneal@312: switch (s.mode) { bgneal@312: case "exact": bgneal@312: l = s.elements || ''; bgneal@312: bgneal@312: if(l.length > 0) { bgneal@312: each(explode(l), function(v) { bgneal@312: if (DOM.get(v)) { bgneal@312: ed = new tinymce.Editor(v, s); bgneal@312: el.push(ed); bgneal@312: ed.render(1); bgneal@312: } else { bgneal@312: each(document.forms, function(f) { bgneal@312: each(f.elements, function(e) { bgneal@312: if (e.name === v) { bgneal@312: v = 'mce_editor_' + instanceCounter++; bgneal@312: DOM.setAttrib(e, 'id', v); bgneal@312: bgneal@312: ed = new tinymce.Editor(v, s); bgneal@312: el.push(ed); bgneal@312: ed.render(1); bgneal@312: } bgneal@312: }); bgneal@312: }); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: break; bgneal@312: bgneal@312: case "textareas": bgneal@312: case "specific_textareas": bgneal@312: function hasClass(n, c) { bgneal@312: return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c); bgneal@312: }; bgneal@312: bgneal@312: each(DOM.select('textarea'), function(v) { bgneal@312: if (s.editor_deselector && hasClass(v, s.editor_deselector)) bgneal@312: return; bgneal@312: bgneal@312: if (!s.editor_selector || hasClass(v, s.editor_selector)) { bgneal@312: // Can we use the name bgneal@312: e = DOM.get(v.name); bgneal@312: if (!v.id && !e) bgneal@312: v.id = v.name; bgneal@312: bgneal@312: // Generate unique name if missing or already exists bgneal@312: if (!v.id || t.get(v.id)) bgneal@312: v.id = DOM.uniqueId(); bgneal@312: bgneal@312: ed = new tinymce.Editor(v.id, s); bgneal@312: el.push(ed); bgneal@312: ed.render(1); bgneal@312: } bgneal@312: }); bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: // Call onInit when all editors are initialized bgneal@312: if (s.oninit) { bgneal@312: l = co = 0; bgneal@312: bgneal@312: each(el, function(ed) { bgneal@312: co++; bgneal@312: bgneal@312: if (!ed.initialized) { bgneal@312: // Wait for it bgneal@312: ed.onInit.add(function() { bgneal@312: l++; bgneal@312: bgneal@312: // All done bgneal@312: if (l == co) bgneal@312: execCallback(s, 'oninit'); bgneal@312: }); bgneal@312: } else bgneal@312: l++; bgneal@312: bgneal@312: // All done bgneal@312: if (l == co) bgneal@312: execCallback(s, 'oninit'); bgneal@312: }); bgneal@312: } bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: get : function(id) { bgneal@312: if (id === undefined) bgneal@312: return this.editors; bgneal@312: bgneal@312: return this.editors[id]; bgneal@312: }, bgneal@312: bgneal@312: getInstanceById : function(id) { bgneal@312: return this.get(id); bgneal@312: }, bgneal@312: bgneal@312: add : function(editor) { bgneal@312: var self = this, editors = self.editors; bgneal@312: bgneal@312: // Add named and index editor instance bgneal@312: editors[editor.id] = editor; bgneal@312: editors.push(editor); bgneal@312: bgneal@312: self._setActive(editor); bgneal@312: self.onAddEditor.dispatch(self, editor); bgneal@312: bgneal@312: bgneal@312: return editor; bgneal@312: }, bgneal@312: bgneal@312: remove : function(editor) { bgneal@312: var t = this, i, editors = t.editors; bgneal@312: bgneal@312: // Not in the collection bgneal@312: if (!editors[editor.id]) bgneal@312: return null; bgneal@312: bgneal@312: delete editors[editor.id]; bgneal@312: bgneal@312: for (i = 0; i < editors.length; i++) { bgneal@312: if (editors[i] == editor) { bgneal@312: editors.splice(i, 1); bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Select another editor since the active one was removed bgneal@312: if (t.activeEditor == editor) bgneal@312: t._setActive(editors[0]); bgneal@312: bgneal@312: editor.destroy(); bgneal@312: t.onRemoveEditor.dispatch(t, editor); bgneal@312: bgneal@312: return editor; bgneal@312: }, bgneal@312: bgneal@312: execCommand : function(c, u, v) { bgneal@312: var t = this, ed = t.get(v), w; bgneal@312: bgneal@312: // Manager commands bgneal@312: switch (c) { bgneal@312: case "mceFocus": bgneal@312: ed.focus(); bgneal@312: return true; bgneal@312: bgneal@312: case "mceAddEditor": bgneal@312: case "mceAddControl": bgneal@312: if (!t.get(v)) bgneal@312: new tinymce.Editor(v, t.settings).render(); bgneal@312: bgneal@312: return true; bgneal@312: bgneal@312: case "mceAddFrameControl": bgneal@312: w = v.window; bgneal@312: bgneal@312: // Add tinyMCE global instance and tinymce namespace to specified window bgneal@312: w.tinyMCE = tinyMCE; bgneal@312: w.tinymce = tinymce; bgneal@312: bgneal@312: tinymce.DOM.doc = w.document; bgneal@312: tinymce.DOM.win = w; bgneal@312: bgneal@312: ed = new tinymce.Editor(v.element_id, v); bgneal@312: ed.render(); bgneal@312: bgneal@312: // Fix IE memory leaks bgneal@312: if (tinymce.isIE) { bgneal@312: function clr() { bgneal@312: ed.destroy(); bgneal@312: w.detachEvent('onunload', clr); bgneal@312: w = w.tinyMCE = w.tinymce = null; // IE leak bgneal@312: }; bgneal@312: bgneal@312: w.attachEvent('onunload', clr); bgneal@312: } bgneal@312: bgneal@312: v.page_window = null; bgneal@312: bgneal@312: return true; bgneal@312: bgneal@312: case "mceRemoveEditor": bgneal@312: case "mceRemoveControl": bgneal@312: if (ed) bgneal@312: ed.remove(); bgneal@312: bgneal@312: return true; bgneal@312: bgneal@312: case 'mceToggleEditor': bgneal@312: if (!ed) { bgneal@312: t.execCommand('mceAddControl', 0, v); bgneal@312: return true; bgneal@312: } bgneal@312: bgneal@312: if (ed.isHidden()) bgneal@312: ed.show(); bgneal@312: else bgneal@312: ed.hide(); bgneal@312: bgneal@312: return true; bgneal@312: } bgneal@312: bgneal@312: // Run command on active editor bgneal@312: if (t.activeEditor) bgneal@312: return t.activeEditor.execCommand(c, u, v); bgneal@312: bgneal@312: return false; bgneal@312: }, bgneal@312: bgneal@312: execInstanceCommand : function(id, c, u, v) { bgneal@312: var ed = this.get(id); bgneal@312: bgneal@312: if (ed) bgneal@312: return ed.execCommand(c, u, v); bgneal@312: bgneal@312: return false; bgneal@312: }, bgneal@312: bgneal@312: triggerSave : function() { bgneal@312: each(this.editors, function(e) { bgneal@312: e.save(); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: addI18n : function(p, o) { bgneal@312: var lo, i18n = this.i18n; bgneal@312: bgneal@312: if (!tinymce.is(p, 'string')) { bgneal@312: each(p, function(o, lc) { bgneal@312: each(o, function(o, g) { bgneal@312: each(o, function(o, k) { bgneal@312: if (g === 'common') bgneal@312: i18n[lc + '.' + k] = o; bgneal@312: else bgneal@312: i18n[lc + '.' + g + '.' + k] = o; bgneal@312: }); bgneal@312: }); bgneal@312: }); bgneal@312: } else { bgneal@312: each(o, function(o, k) { bgneal@312: i18n[p + '.' + k] = o; bgneal@312: }); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: // Private methods bgneal@312: bgneal@312: _setActive : function(editor) { bgneal@312: this.selectedInstance = this.activeEditor = editor; bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: // Shorten these names bgneal@312: var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, bgneal@312: Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isGecko = tinymce.isGecko, bgneal@312: isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is, bgneal@312: ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager, bgneal@312: inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode; bgneal@312: bgneal@312: tinymce.create('tinymce.Editor', { bgneal@312: Editor : function(id, s) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.id = t.editorId = id; bgneal@312: bgneal@312: t.execCommands = {}; bgneal@312: t.queryStateCommands = {}; bgneal@312: t.queryValueCommands = {}; bgneal@312: bgneal@312: t.isNotDirty = false; bgneal@312: bgneal@312: t.plugins = {}; bgneal@312: bgneal@312: // Add events to the editor bgneal@312: each([ bgneal@312: 'onPreInit', bgneal@312: bgneal@312: 'onBeforeRenderUI', bgneal@312: bgneal@312: 'onPostRender', bgneal@312: bgneal@312: 'onInit', bgneal@312: bgneal@312: 'onRemove', bgneal@312: bgneal@312: 'onActivate', bgneal@312: bgneal@312: 'onDeactivate', bgneal@312: bgneal@312: 'onClick', bgneal@312: bgneal@312: 'onEvent', bgneal@312: bgneal@312: 'onMouseUp', bgneal@312: bgneal@312: 'onMouseDown', bgneal@312: bgneal@312: 'onDblClick', bgneal@312: bgneal@312: 'onKeyDown', bgneal@312: bgneal@312: 'onKeyUp', bgneal@312: bgneal@312: 'onKeyPress', bgneal@312: bgneal@312: 'onContextMenu', bgneal@312: bgneal@312: 'onSubmit', bgneal@312: bgneal@312: 'onReset', bgneal@312: bgneal@312: 'onPaste', bgneal@312: bgneal@312: 'onPreProcess', bgneal@312: bgneal@312: 'onPostProcess', bgneal@312: bgneal@312: 'onBeforeSetContent', bgneal@312: bgneal@312: 'onBeforeGetContent', bgneal@312: bgneal@312: 'onSetContent', bgneal@312: bgneal@312: 'onGetContent', bgneal@312: bgneal@312: 'onLoadContent', bgneal@312: bgneal@312: 'onSaveContent', bgneal@312: bgneal@312: 'onNodeChange', bgneal@312: bgneal@312: 'onChange', bgneal@312: bgneal@312: 'onBeforeExecCommand', bgneal@312: bgneal@312: 'onExecCommand', bgneal@312: bgneal@312: 'onUndo', bgneal@312: bgneal@312: 'onRedo', bgneal@312: bgneal@312: 'onVisualAid', bgneal@312: bgneal@312: 'onSetProgressState' bgneal@312: ], function(e) { bgneal@312: t[e] = new Dispatcher(t); bgneal@312: }); bgneal@312: bgneal@312: t.settings = s = extend({ bgneal@312: id : id, bgneal@312: language : 'en', bgneal@312: docs_language : 'en', bgneal@312: theme : 'simple', bgneal@312: skin : 'default', bgneal@312: delta_width : 0, bgneal@312: delta_height : 0, bgneal@312: popup_css : '', bgneal@312: plugins : '', bgneal@312: document_base_url : tinymce.documentBaseURL, bgneal@312: add_form_submit_trigger : 1, bgneal@312: submit_patch : 1, bgneal@312: add_unload_trigger : 1, bgneal@312: convert_urls : 1, bgneal@312: relative_urls : 1, bgneal@312: remove_script_host : 1, bgneal@312: table_inline_editing : 0, bgneal@312: object_resizing : 1, bgneal@312: cleanup : 1, bgneal@312: accessibility_focus : 1, bgneal@312: custom_shortcuts : 1, bgneal@312: custom_undo_redo_keyboard_shortcuts : 1, bgneal@312: custom_undo_redo_restore_selection : 1, bgneal@312: custom_undo_redo : 1, bgneal@312: doctype : tinymce.isIE6 ? '' : '', // Use old doctype on IE 6 to avoid horizontal scroll bgneal@312: visual_table_class : 'mceItemTable', bgneal@312: visual : 1, bgneal@312: font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large', bgneal@312: apply_source_formatting : 1, bgneal@312: directionality : 'ltr', bgneal@312: forced_root_block : 'p', bgneal@312: hidden_input : 1, bgneal@312: padd_empty_editor : 1, bgneal@312: render_ui : 1, bgneal@312: init_theme : 1, bgneal@312: force_p_newlines : 1, bgneal@312: indentation : '30px', bgneal@312: keep_styles : 1, bgneal@312: fix_table_elements : 1, bgneal@312: inline_styles : 1, bgneal@442: convert_fonts_to_spans : true, bgneal@442: indent : 'simple', bgneal@442: indent_before : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr', bgneal@442: indent_after : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr', bgneal@442: validate : true, bgneal@442: entity_encoding : 'named', bgneal@442: url_converter : t.convertURL, bgneal@442: url_converter_scope : t, bgneal@442: ie7_compat : true bgneal@312: }, s); bgneal@312: bgneal@312: t.documentBaseURI = new tinymce.util.URI(s.document_base_url || tinymce.documentBaseURL, { bgneal@312: base_uri : tinyMCE.baseURI bgneal@312: }); bgneal@312: bgneal@312: t.baseURI = tinymce.baseURI; bgneal@312: bgneal@442: t.contentCSS = []; bgneal@442: bgneal@312: // Call setup bgneal@312: t.execCallback('setup', t); bgneal@312: }, bgneal@312: bgneal@312: render : function(nst) { bgneal@312: var t = this, s = t.settings, id = t.id, sl = tinymce.ScriptLoader; bgneal@312: bgneal@312: // Page is not loaded yet, wait for it bgneal@312: if (!Event.domLoaded) { bgneal@312: Event.add(document, 'init', function() { bgneal@312: t.render(); bgneal@312: }); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: tinyMCE.settings = s; bgneal@312: bgneal@312: // Element not found, then skip initialization bgneal@312: if (!t.getElement()) bgneal@312: return; bgneal@312: bgneal@312: // Is a iPad/iPhone, then skip initialization. We need to sniff here since the bgneal@312: // browser says it has contentEditable support but there is no visible caret bgneal@312: // We will remove this check ones Apple implements full contentEditable support bgneal@312: if (tinymce.isIDevice) bgneal@312: return; bgneal@312: bgneal@312: // Add hidden input for non input elements inside form elements bgneal@312: if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form')) bgneal@312: DOM.insertAfter(DOM.create('input', {type : 'hidden', name : id}), id); bgneal@312: bgneal@312: if (tinymce.WindowManager) bgneal@312: t.windowManager = new tinymce.WindowManager(t); bgneal@312: bgneal@312: if (s.encoding == 'xml') { bgneal@312: t.onGetContent.add(function(ed, o) { bgneal@312: if (o.save) bgneal@312: o.content = DOM.encode(o.content); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (s.add_form_submit_trigger) { bgneal@312: t.onSubmit.addToTop(function() { bgneal@312: if (t.initialized) { bgneal@312: t.save(); bgneal@312: t.isNotDirty = 1; bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (s.add_unload_trigger) { bgneal@312: t._beforeUnload = tinyMCE.onBeforeUnload.add(function() { bgneal@312: if (t.initialized && !t.destroyed && !t.isHidden()) bgneal@312: t.save({format : 'raw', no_events : true}); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: tinymce.addUnload(t.destroy, t); bgneal@312: bgneal@312: if (s.submit_patch) { bgneal@312: t.onBeforeRenderUI.add(function() { bgneal@312: var n = t.getElement().form; bgneal@312: bgneal@312: if (!n) bgneal@312: return; bgneal@312: bgneal@312: // Already patched bgneal@312: if (n._mceOldSubmit) bgneal@312: return; bgneal@312: bgneal@312: // Check page uses id="submit" or name="submit" for it's submit button bgneal@312: if (!n.submit.nodeType && !n.submit.length) { bgneal@312: t.formElement = n; bgneal@312: n._mceOldSubmit = n.submit; bgneal@312: n.submit = function() { bgneal@312: // Save all instances bgneal@312: tinymce.triggerSave(); bgneal@312: t.isNotDirty = 1; bgneal@312: bgneal@312: return t.formElement._mceOldSubmit(t.formElement); bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: n = null; bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: // Load scripts bgneal@312: function loadScripts() { bgneal@442: if (s.language && s.language_load !== false) bgneal@312: sl.add(tinymce.baseURL + '/langs/' + s.language + '.js'); bgneal@312: bgneal@312: if (s.theme && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme]) bgneal@312: ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js'); bgneal@312: bgneal@312: each(explode(s.plugins), function(p) { bgneal@312: if (p && p.charAt(0) != '-' && !PluginManager.urls[p]) { bgneal@312: // Skip safari plugin, since it is removed as of 3.3b1 bgneal@312: if (p == 'safari') bgneal@312: return; bgneal@312: bgneal@312: PluginManager.load(p, 'plugins/' + p + '/editor_plugin' + tinymce.suffix + '.js'); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // Init when que is loaded bgneal@312: sl.loadQueue(function() { bgneal@312: if (!t.removed) bgneal@312: t.init(); bgneal@312: }); bgneal@312: }; bgneal@312: bgneal@312: loadScripts(); bgneal@312: }, bgneal@312: bgneal@312: init : function() { bgneal@442: var n, t = this, s = t.settings, w, h, e = t.getElement(), o, ti, u, bi, bc, re, i; bgneal@312: bgneal@312: tinymce.add(t); bgneal@312: bgneal@442: s.aria_label = s.aria_label || DOM.getAttrib(e, 'aria-label', t.getLang('aria.rich_text_area')); bgneal@442: bgneal@312: if (s.theme) { bgneal@312: s.theme = s.theme.replace(/-/, ''); bgneal@312: o = ThemeManager.get(s.theme); bgneal@312: t.theme = new o(); bgneal@312: bgneal@312: if (t.theme.init && s.init_theme) bgneal@312: t.theme.init(t, ThemeManager.urls[s.theme] || tinymce.documentBaseURL.replace(/\/$/, '')); bgneal@312: } bgneal@312: bgneal@312: // Create all plugins bgneal@312: each(explode(s.plugins.replace(/\-/g, '')), function(p) { bgneal@312: var c = PluginManager.get(p), u = PluginManager.urls[p] || tinymce.documentBaseURL.replace(/\/$/, ''), po; bgneal@312: bgneal@312: if (c) { bgneal@312: po = new c(t, u); bgneal@312: bgneal@312: t.plugins[p] = po; bgneal@312: bgneal@312: if (po.init) bgneal@312: po.init(t, u); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // Setup popup CSS path(s) bgneal@312: if (s.popup_css !== false) { bgneal@312: if (s.popup_css) bgneal@312: s.popup_css = t.documentBaseURI.toAbsolute(s.popup_css); bgneal@312: else bgneal@312: s.popup_css = t.baseURI.toAbsolute("themes/" + s.theme + "/skins/" + s.skin + "/dialog.css"); bgneal@312: } bgneal@312: bgneal@312: if (s.popup_css_add) bgneal@312: s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add); bgneal@312: bgneal@312: t.controlManager = new tinymce.ControlManager(t); bgneal@312: bgneal@312: if (s.custom_undo_redo) { bgneal@312: t.onBeforeExecCommand.add(function(ed, cmd, ui, val, a) { bgneal@442: if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo)) bgneal@442: t.undoManager.beforeChange(); bgneal@312: }); bgneal@312: bgneal@312: t.onExecCommand.add(function(ed, cmd, ui, val, a) { bgneal@312: if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo)) bgneal@312: t.undoManager.add(); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: t.onExecCommand.add(function(ed, c) { bgneal@312: // Don't refresh the select lists until caret move bgneal@312: if (!/^(FontName|FontSize)$/.test(c)) bgneal@312: t.nodeChanged(); bgneal@312: }); bgneal@312: bgneal@312: // Remove ghost selections on images and tables in Gecko bgneal@312: if (isGecko) { bgneal@312: function repaint(a, o) { bgneal@312: if (!o || !o.initial) bgneal@312: t.execCommand('mceRepaint'); bgneal@312: }; bgneal@312: bgneal@312: t.onUndo.add(repaint); bgneal@312: t.onRedo.add(repaint); bgneal@312: t.onSetContent.add(repaint); bgneal@312: } bgneal@312: bgneal@312: // Enables users to override the control factory bgneal@312: t.onBeforeRenderUI.dispatch(t, t.controlManager); bgneal@312: bgneal@312: // Measure box bgneal@312: if (s.render_ui) { bgneal@312: w = s.width || e.style.width || e.offsetWidth; bgneal@312: h = s.height || e.style.height || e.offsetHeight; bgneal@312: t.orgDisplay = e.style.display; bgneal@312: re = /^[0-9\.]+(|px)$/i; bgneal@312: bgneal@312: if (re.test('' + w)) bgneal@312: w = Math.max(parseInt(w) + (o.deltaWidth || 0), 100); bgneal@312: bgneal@312: if (re.test('' + h)) bgneal@312: h = Math.max(parseInt(h) + (o.deltaHeight || 0), 100); bgneal@312: bgneal@312: // Render UI bgneal@312: o = t.theme.renderUI({ bgneal@312: targetNode : e, bgneal@312: width : w, bgneal@312: height : h, bgneal@312: deltaWidth : s.delta_width, bgneal@312: deltaHeight : s.delta_height bgneal@312: }); bgneal@312: bgneal@312: t.editorContainer = o.editorContainer; bgneal@312: } bgneal@312: bgneal@312: bgneal@312: // User specified a document.domain value bgneal@312: if (document.domain && location.hostname != document.domain) bgneal@312: tinymce.relaxedDomain = document.domain; bgneal@312: bgneal@312: // Resize editor bgneal@312: DOM.setStyles(o.sizeContainer || o.editorContainer, { bgneal@312: width : w, bgneal@312: height : h bgneal@312: }); bgneal@312: bgneal@442: // Load specified content CSS last bgneal@442: if (s.content_css) { bgneal@442: tinymce.each(explode(s.content_css), function(u) { bgneal@442: t.contentCSS.push(t.documentBaseURI.toAbsolute(u)); bgneal@442: }); bgneal@442: } bgneal@442: bgneal@312: h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : ''); bgneal@312: if (h < 100) bgneal@312: h = 100; bgneal@312: bgneal@312: t.iframeHTML = s.doctype + ''; bgneal@312: bgneal@312: // We only need to override paths if we have to bgneal@312: // IE has a bug where it remove site absolute urls to relative ones if this is specified bgneal@312: if (s.document_base_url != tinymce.documentBaseURL) bgneal@312: t.iframeHTML += ''; bgneal@312: bgneal@442: // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode. bgneal@442: if (s.ie7_compat) bgneal@442: t.iframeHTML += ''; bgneal@442: else bgneal@442: t.iframeHTML += ''; bgneal@442: bgneal@442: t.iframeHTML += ''; bgneal@442: bgneal@442: // Firefox 2 doesn't load stylesheets correctly this way bgneal@442: if (!isGecko || !/Firefox\/2/.test(navigator.userAgent)) { bgneal@442: for (i = 0; i < t.contentCSS.length; i++) bgneal@442: t.iframeHTML += ''; bgneal@442: bgneal@442: t.contentCSS = []; bgneal@442: } bgneal@312: bgneal@312: bi = s.body_id || 'tinymce'; bgneal@312: if (bi.indexOf('=') != -1) { bgneal@312: bi = t.getParam('body_id', '', 'hash'); bgneal@312: bi = bi[t.id] || bi; bgneal@312: } bgneal@312: bgneal@312: bc = s.body_class || ''; bgneal@312: if (bc.indexOf('=') != -1) { bgneal@312: bc = t.getParam('body_class', '', 'hash'); bgneal@312: bc = bc[t.id] || ''; bgneal@312: } bgneal@312: bgneal@312: t.iframeHTML += ''; bgneal@312: bgneal@312: // Domain relaxing enabled, then set document domain bgneal@442: if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) { bgneal@312: // We need to write the contents here in IE since multiple writes messes up refresh button and back button bgneal@442: 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();})()'; bgneal@312: } bgneal@312: bgneal@312: // Create iframe bgneal@442: // TODO: ACC add the appropriate description on this. bgneal@442: n = DOM.add(o.iframeContainer, 'iframe', { bgneal@312: id : t.id + "_ifr", bgneal@312: src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7 bgneal@442: frameBorder : '0', bgneal@442: title : s.aria_label, bgneal@312: style : { bgneal@312: width : '100%', bgneal@312: height : h bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: t.contentAreaContainer = o.iframeContainer; bgneal@312: DOM.get(o.editorContainer).style.display = t.orgDisplay; bgneal@312: DOM.get(t.id).style.display = 'none'; bgneal@442: DOM.setAttrib(t.id, 'aria-hidden', true); bgneal@442: bgneal@442: if (!tinymce.relaxedDomain || !u) bgneal@312: t.setupIframe(); bgneal@312: bgneal@312: e = n = o = null; // Cleanup bgneal@312: }, bgneal@312: bgneal@312: setupIframe : function() { bgneal@312: var t = this, s = t.settings, e = DOM.get(t.id), d = t.getDoc(), h, b; bgneal@312: bgneal@312: // Setup iframe body bgneal@312: if (!isIE || !tinymce.relaxedDomain) { bgneal@312: d.open(); bgneal@312: d.write(t.iframeHTML); bgneal@312: d.close(); bgneal@442: bgneal@442: if (tinymce.relaxedDomain) bgneal@442: d.domain = tinymce.relaxedDomain; bgneal@312: } bgneal@312: bgneal@312: // Design mode needs to be added here Ctrl+A will fail otherwise bgneal@312: if (!isIE) { bgneal@312: try { bgneal@312: if (!s.readonly) bgneal@312: d.designMode = 'On'; bgneal@312: } catch (ex) { bgneal@312: // Will fail on Gecko if the editor is placed in an hidden container element bgneal@312: // The design mode will be set ones the editor is focused bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // IE needs to use contentEditable or it will display non secure items for HTTPS bgneal@312: if (isIE) { bgneal@312: // It will not steal focus if we hide it while setting contentEditable bgneal@312: b = t.getBody(); bgneal@312: DOM.hide(b); bgneal@312: bgneal@312: if (!s.readonly) bgneal@312: b.contentEditable = true; bgneal@312: bgneal@312: DOM.show(b); bgneal@312: } bgneal@312: bgneal@442: t.schema = new tinymce.html.Schema(s); bgneal@442: bgneal@312: t.dom = new tinymce.dom.DOMUtils(t.getDoc(), { bgneal@312: keep_values : true, bgneal@312: url_converter : t.convertURL, bgneal@312: url_converter_scope : t, bgneal@312: hex_colors : s.force_hex_style_colors, bgneal@312: class_filter : s.class_filter, bgneal@312: update_styles : 1, bgneal@312: fix_ie_paragraphs : 1, bgneal@312: schema : t.schema bgneal@442: }); bgneal@442: bgneal@442: t.parser = new tinymce.html.DomParser(s, t.schema); bgneal@442: bgneal@442: // Force anchor names closed bgneal@442: t.parser.addAttributeFilter('name', function(nodes, name) { bgneal@442: var i = nodes.length, sibling, prevSibling, parent, node; bgneal@442: bgneal@442: while (i--) { bgneal@442: node = nodes[i]; bgneal@442: if (node.name === 'a' && node.firstChild) { bgneal@442: parent = node.parent; bgneal@442: bgneal@442: // Move children after current node bgneal@442: sibling = node.lastChild; bgneal@442: do { bgneal@442: prevSibling = sibling.prev; bgneal@442: parent.insert(sibling, node); bgneal@442: sibling = prevSibling; bgneal@442: } while (sibling); bgneal@442: } bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: // Convert src and href into data-mce-src, data-mce-href and data-mce-style bgneal@442: t.parser.addAttributeFilter('src,href,style', function(nodes, name) { bgneal@442: var i = nodes.length, node, dom = t.dom, value; bgneal@442: bgneal@442: while (i--) { bgneal@442: node = nodes[i]; bgneal@442: value = node.attr(name); bgneal@442: bgneal@442: if (name === "style") bgneal@442: node.attr('data-mce-style', dom.serializeStyle(dom.parseStyle(value), node.name)); bgneal@442: else bgneal@442: node.attr('data-mce-' + name, t.convertURL(value, name, node.name)); bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: // Keep scripts from executing bgneal@442: t.parser.addNodeFilter('script', function(nodes, name) { bgneal@442: var i = nodes.length; bgneal@442: bgneal@442: while (i--) bgneal@442: nodes[i].attr('type', 'mce-text/javascript'); bgneal@442: }); bgneal@442: bgneal@442: t.parser.addNodeFilter('#cdata', function(nodes, name) { bgneal@442: var i = nodes.length, node; bgneal@442: bgneal@442: while (i--) { bgneal@442: node = nodes[i]; bgneal@442: node.type = 8; bgneal@442: node.name = '#comment'; bgneal@442: node.value = '[CDATA[' + node.value + ']]'; bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: t.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes, name) { bgneal@442: var i = nodes.length, node, nonEmptyElements = t.schema.getNonEmptyElements(); bgneal@442: bgneal@442: while (i--) { bgneal@442: node = nodes[i]; bgneal@442: bgneal@442: if (node.isEmpty(nonEmptyElements)) bgneal@442: node.empty().append(new tinymce.html.Node('br', 1)).shortEnded = true; bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: t.serializer = new tinymce.dom.Serializer(s, t.dom, t.schema); bgneal@312: bgneal@312: t.selection = new tinymce.dom.Selection(t.dom, t.getWin(), t.serializer); bgneal@312: bgneal@312: t.formatter = new tinymce.Formatter(this); bgneal@312: bgneal@312: // Register default formats bgneal@312: t.formatter.register({ bgneal@312: alignleft : [ bgneal@312: {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}}, bgneal@442: {selector : 'img,table', collapsed : false, styles : {'float' : 'left'}} bgneal@312: ], bgneal@312: bgneal@312: aligncenter : [ bgneal@312: {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}}, bgneal@442: {selector : 'img', collapsed : false, styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}}, bgneal@442: {selector : 'table', collapsed : false, styles : {marginLeft : 'auto', marginRight : 'auto'}} bgneal@312: ], bgneal@312: bgneal@312: alignright : [ bgneal@312: {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}}, bgneal@442: {selector : 'img,table', collapsed : false, styles : {'float' : 'right'}} bgneal@312: ], bgneal@312: bgneal@312: alignfull : [ bgneal@312: {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}} bgneal@312: ], bgneal@312: bgneal@312: bold : [ bgneal@442: {inline : 'strong', remove : 'all'}, bgneal@312: {inline : 'span', styles : {fontWeight : 'bold'}}, bgneal@442: {inline : 'b', remove : 'all'} bgneal@312: ], bgneal@312: bgneal@312: italic : [ bgneal@442: {inline : 'em', remove : 'all'}, bgneal@312: {inline : 'span', styles : {fontStyle : 'italic'}}, bgneal@442: {inline : 'i', remove : 'all'} bgneal@312: ], bgneal@312: bgneal@312: underline : [ bgneal@312: {inline : 'span', styles : {textDecoration : 'underline'}, exact : true}, bgneal@442: {inline : 'u', remove : 'all'} bgneal@312: ], bgneal@312: bgneal@312: strikethrough : [ bgneal@312: {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true}, bgneal@442: {inline : 'strike', remove : 'all'} bgneal@312: ], bgneal@312: bgneal@442: forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false}, bgneal@442: hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false}, bgneal@312: fontname : {inline : 'span', styles : {fontFamily : '%value'}}, bgneal@312: fontsize : {inline : 'span', styles : {fontSize : '%value'}}, bgneal@312: fontsize_class : {inline : 'span', attributes : {'class' : '%value'}}, bgneal@312: blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'}, bgneal@442: subscript : {inline : 'sub'}, bgneal@442: superscript : {inline : 'sup'}, bgneal@312: bgneal@312: removeformat : [ bgneal@312: {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true}, bgneal@312: {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true}, bgneal@312: {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true} bgneal@312: ] bgneal@312: }); bgneal@312: bgneal@312: // Register default block formats bgneal@312: each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) { bgneal@312: t.formatter.register(name, {block : name, remove : 'all'}); bgneal@312: }); bgneal@312: bgneal@312: // Register user defined formats bgneal@312: t.formatter.register(t.settings.formats); bgneal@312: bgneal@312: t.undoManager = new tinymce.UndoManager(t); bgneal@312: bgneal@312: // Pass through bgneal@312: t.undoManager.onAdd.add(function(um, l) { bgneal@442: if (um.hasUndo()) bgneal@312: return t.onChange.dispatch(t, l, um); bgneal@312: }); bgneal@312: bgneal@312: t.undoManager.onUndo.add(function(um, l) { bgneal@312: return t.onUndo.dispatch(t, l, um); bgneal@312: }); bgneal@312: bgneal@312: t.undoManager.onRedo.add(function(um, l) { bgneal@312: return t.onRedo.dispatch(t, l, um); bgneal@312: }); bgneal@312: bgneal@312: t.forceBlocks = new tinymce.ForceBlocks(t, { bgneal@312: forced_root_block : s.forced_root_block bgneal@312: }); bgneal@312: bgneal@312: t.editorCommands = new tinymce.EditorCommands(t); bgneal@312: bgneal@312: // Pass through bgneal@312: t.serializer.onPreProcess.add(function(se, o) { bgneal@312: return t.onPreProcess.dispatch(t, o, se); bgneal@312: }); bgneal@312: bgneal@312: t.serializer.onPostProcess.add(function(se, o) { bgneal@312: return t.onPostProcess.dispatch(t, o, se); bgneal@312: }); bgneal@312: bgneal@312: t.onPreInit.dispatch(t); bgneal@312: bgneal@312: if (!s.gecko_spellcheck) bgneal@312: t.getBody().spellcheck = 0; bgneal@312: bgneal@312: if (!s.readonly) bgneal@312: t._addEvents(); bgneal@312: bgneal@312: t.controlManager.onPostRender.dispatch(t, t.controlManager); bgneal@312: t.onPostRender.dispatch(t); bgneal@312: bgneal@312: if (s.directionality) bgneal@312: t.getBody().dir = s.directionality; bgneal@312: bgneal@312: if (s.nowrap) bgneal@312: t.getBody().style.whiteSpace = "nowrap"; bgneal@312: bgneal@312: if (s.handle_node_change_callback) { bgneal@312: t.onNodeChange.add(function(ed, cm, n) { bgneal@312: t.execCallback('handle_node_change_callback', t.id, n, -1, -1, true, t.selection.isCollapsed()); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (s.save_callback) { bgneal@312: t.onSaveContent.add(function(ed, o) { bgneal@312: var h = t.execCallback('save_callback', t.id, o.content, t.getBody()); bgneal@312: bgneal@312: if (h) bgneal@312: o.content = h; bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (s.onchange_callback) { bgneal@312: t.onChange.add(function(ed, l) { bgneal@312: t.execCallback('onchange_callback', t, l); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@442: if (s.protect) { bgneal@442: t.onBeforeSetContent.add(function(ed, o) { bgneal@442: if (s.protect) { bgneal@442: each(s.protect, function(pattern) { bgneal@442: o.content = o.content.replace(pattern, function(str) { bgneal@442: return ''; bgneal@442: }); bgneal@442: }); bgneal@442: } bgneal@442: }); bgneal@442: } bgneal@442: bgneal@312: if (s.convert_newlines_to_brs) { bgneal@312: t.onBeforeSetContent.add(function(ed, o) { bgneal@312: if (o.initial) bgneal@312: o.content = o.content.replace(/\r?\n/g, '
    '); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (s.preformatted) { bgneal@312: t.onPostProcess.add(function(ed, o) { bgneal@312: o.content = o.content.replace(/^\s*/, ''); bgneal@312: o.content = o.content.replace(/<\/pre>\s*$/, ''); bgneal@312: bgneal@312: if (o.set) bgneal@312: o.content = '
    ' + o.content + '
    '; bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (s.verify_css_classes) { bgneal@312: t.serializer.attribValueFilter = function(n, v) { bgneal@312: var s, cl; bgneal@312: bgneal@312: if (n == 'class') { bgneal@312: // Build regexp for classes bgneal@312: if (!t.classesRE) { bgneal@312: cl = t.dom.getClasses(); bgneal@312: bgneal@312: if (cl.length > 0) { bgneal@312: s = ''; bgneal@312: bgneal@312: each (cl, function(o) { bgneal@312: s += (s ? '|' : '') + o['class']; bgneal@312: }); bgneal@312: bgneal@312: t.classesRE = new RegExp('(' + s + ')', 'gi'); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return !t.classesRE || /(\bmceItem\w+\b|\bmceTemp\w+\b)/g.test(v) || t.classesRE.test(v) ? v : ''; bgneal@312: } bgneal@312: bgneal@312: return v; bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: if (s.cleanup_callback) { bgneal@312: t.onBeforeSetContent.add(function(ed, o) { bgneal@312: o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o); bgneal@312: }); bgneal@312: bgneal@312: t.onPreProcess.add(function(ed, o) { bgneal@312: if (o.set) bgneal@312: t.execCallback('cleanup_callback', 'insert_to_editor_dom', o.node, o); bgneal@312: bgneal@312: if (o.get) bgneal@312: t.execCallback('cleanup_callback', 'get_from_editor_dom', o.node, o); bgneal@312: }); bgneal@312: bgneal@312: t.onPostProcess.add(function(ed, o) { bgneal@312: if (o.set) bgneal@312: o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o); bgneal@312: bgneal@312: if (o.get) bgneal@312: o.content = t.execCallback('cleanup_callback', 'get_from_editor', o.content, o); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (s.save_callback) { bgneal@312: t.onGetContent.add(function(ed, o) { bgneal@312: if (o.save) bgneal@312: o.content = t.execCallback('save_callback', t.id, o.content, t.getBody()); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (s.handle_event_callback) { bgneal@312: t.onEvent.add(function(ed, e, o) { bgneal@312: if (t.execCallback('handle_event_callback', e, ed, o) === false) bgneal@312: Event.cancel(e); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: // Add visual aids when new contents is added bgneal@312: t.onSetContent.add(function() { bgneal@312: t.addVisual(t.getBody()); bgneal@312: }); bgneal@312: bgneal@312: // Remove empty contents bgneal@312: if (s.padd_empty_editor) { bgneal@312: t.onPostProcess.add(function(ed, o) { bgneal@312: o.content = o.content.replace(/^(]*>( | |\s|\u00a0|)<\/p>[\r\n]*|
    [\r\n]*)$/, ''); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (isGecko) { bgneal@312: // Fix gecko link bug, when a link is placed at the end of block elements there is bgneal@312: // no way to move the caret behind the link. This fix adds a bogus br element after the link bgneal@312: function fixLinks(ed, o) { bgneal@312: each(ed.dom.select('a'), function(n) { bgneal@312: var pn = n.parentNode; bgneal@312: bgneal@312: if (ed.dom.isBlock(pn) && pn.lastChild === n) bgneal@442: ed.dom.add(pn, 'br', {'data-mce-bogus' : 1}); bgneal@312: }); bgneal@312: }; bgneal@312: bgneal@312: t.onExecCommand.add(function(ed, cmd) { bgneal@312: if (cmd === 'CreateLink') bgneal@312: fixLinks(ed); bgneal@312: }); bgneal@312: bgneal@312: t.onSetContent.add(t.selection.onSetContent.add(fixLinks)); bgneal@312: bgneal@312: if (!s.readonly) { bgneal@312: try { bgneal@312: // Design mode must be set here once again to fix a bug where bgneal@312: // Ctrl+A/Delete/Backspace didn't work if the editor was added using mceAddControl then removed then added again bgneal@312: d.designMode = 'Off'; bgneal@312: d.designMode = 'On'; bgneal@312: } catch (ex) { bgneal@312: // Will fail on Gecko if the editor is placed in an hidden container element bgneal@312: // The design mode will be set ones the editor is focused bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // A small timeout was needed since firefox will remove. Bug: #1838304 bgneal@312: setTimeout(function () { bgneal@312: if (t.removed) bgneal@312: return; bgneal@312: bgneal@442: t.load({initial : true, format : 'html'}); bgneal@312: t.startContent = t.getContent({format : 'raw'}); bgneal@442: t.undoManager.add(); bgneal@312: t.initialized = true; bgneal@312: bgneal@312: t.onInit.dispatch(t); bgneal@312: t.execCallback('setupcontent_callback', t.id, t.getBody(), t.getDoc()); bgneal@312: t.execCallback('init_instance_callback', t); bgneal@312: t.focus(true); bgneal@312: t.nodeChanged({initial : 1}); bgneal@312: bgneal@312: // Load specified content CSS last bgneal@442: each(t.contentCSS, function(u) { bgneal@442: t.dom.loadCSS(u); bgneal@442: }); bgneal@312: bgneal@312: // Handle auto focus bgneal@312: if (s.auto_focus) { bgneal@312: setTimeout(function () { bgneal@312: var ed = tinymce.get(s.auto_focus); bgneal@312: bgneal@312: ed.selection.select(ed.getBody(), 1); bgneal@312: ed.selection.collapse(1); bgneal@312: ed.getWin().focus(); bgneal@312: }, 100); bgneal@312: } bgneal@312: }, 1); bgneal@312: bgneal@312: e = null; bgneal@312: }, bgneal@312: bgneal@312: bgneal@312: focus : function(sf) { bgneal@312: var oed, t = this, ce = t.settings.content_editable, ieRng, controlElm, doc = t.getDoc(); bgneal@312: bgneal@312: if (!sf) { bgneal@312: // Get selected control element bgneal@312: ieRng = t.selection.getRng(); bgneal@312: if (ieRng.item) { bgneal@312: controlElm = ieRng.item(0); bgneal@312: } bgneal@312: bgneal@312: // Is not content editable bgneal@312: if (!ce) bgneal@312: t.getWin().focus(); bgneal@312: bgneal@312: // Restore selected control element bgneal@312: // This is needed when for example an image is selected within a bgneal@312: // layer a call to focus will then remove the control selection bgneal@312: if (controlElm && controlElm.ownerDocument == doc) { bgneal@312: ieRng = doc.body.createControlRange(); bgneal@312: ieRng.addElement(controlElm); bgneal@312: ieRng.select(); bgneal@312: } bgneal@312: bgneal@312: } bgneal@312: bgneal@312: if (tinymce.activeEditor != t) { bgneal@312: if ((oed = tinymce.activeEditor) != null) bgneal@312: oed.onDeactivate.dispatch(oed, t); bgneal@312: bgneal@312: t.onActivate.dispatch(t, oed); bgneal@312: } bgneal@312: bgneal@312: tinymce._setActive(t); bgneal@312: }, bgneal@312: bgneal@312: execCallback : function(n) { bgneal@312: var t = this, f = t.settings[n], s; bgneal@312: bgneal@312: if (!f) bgneal@312: return; bgneal@312: bgneal@312: // Look through lookup bgneal@312: if (t.callbackLookup && (s = t.callbackLookup[n])) { bgneal@312: f = s.func; bgneal@312: s = s.scope; bgneal@312: } bgneal@312: bgneal@312: if (is(f, 'string')) { bgneal@312: s = f.replace(/\.\w+$/, ''); bgneal@312: s = s ? tinymce.resolve(s) : 0; bgneal@312: f = tinymce.resolve(f); bgneal@312: t.callbackLookup = t.callbackLookup || {}; bgneal@312: t.callbackLookup[n] = {func : f, scope : s}; bgneal@312: } bgneal@312: bgneal@312: return f.apply(s || t, Array.prototype.slice.call(arguments, 1)); bgneal@312: }, bgneal@312: bgneal@312: translate : function(s) { bgneal@312: var c = this.settings.language || 'en', i18n = tinymce.i18n; bgneal@312: bgneal@312: if (!s) bgneal@312: return ''; bgneal@312: bgneal@312: return i18n[c + '.' + s] || s.replace(/{\#([^}]+)\}/g, function(a, b) { bgneal@312: return i18n[c + '.' + b] || '{#' + b + '}'; bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: getLang : function(n, dv) { bgneal@312: return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}'); bgneal@312: }, bgneal@312: bgneal@312: getParam : function(n, dv, ty) { bgneal@312: var tr = tinymce.trim, v = is(this.settings[n]) ? this.settings[n] : dv, o; bgneal@312: bgneal@312: if (ty === 'hash') { bgneal@312: o = {}; bgneal@312: bgneal@312: if (is(v, 'string')) { bgneal@312: each(v.indexOf('=') > 0 ? v.split(/[;,](?![^=;,]*(?:[;,]|$))/) : v.split(','), function(v) { bgneal@312: v = v.split('='); bgneal@312: bgneal@312: if (v.length > 1) bgneal@312: o[tr(v[0])] = tr(v[1]); bgneal@312: else bgneal@312: o[tr(v[0])] = tr(v); bgneal@312: }); bgneal@312: } else bgneal@312: o = v; bgneal@312: bgneal@312: return o; bgneal@312: } bgneal@312: bgneal@312: return v; bgneal@312: }, bgneal@312: bgneal@312: nodeChanged : function(o) { bgneal@442: var t = this, s = t.selection, n = s.getStart() || t.getBody(); bgneal@312: bgneal@312: // Fix for bug #1896577 it seems that this can not be fired while the editor is loading bgneal@312: if (t.initialized) { bgneal@312: o = o || {}; bgneal@312: n = isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n; // Fix for IE initial state bgneal@312: bgneal@312: // Get parents and add them to object bgneal@312: o.parents = []; bgneal@312: t.dom.getParent(n, function(node) { bgneal@312: if (node.nodeName == 'BODY') bgneal@312: return true; bgneal@312: bgneal@312: o.parents.push(node); bgneal@312: }); bgneal@312: bgneal@312: t.onNodeChange.dispatch( bgneal@312: t, bgneal@312: o ? o.controlManager || t.controlManager : t.controlManager, bgneal@312: n, bgneal@312: s.isCollapsed(), bgneal@312: o bgneal@312: ); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: addButton : function(n, s) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.buttons = t.buttons || {}; bgneal@312: t.buttons[n] = s; bgneal@312: }, bgneal@312: bgneal@442: addCommand : function(name, callback, scope) { bgneal@442: this.execCommands[name] = {func : callback, scope : scope || this}; bgneal@442: }, bgneal@442: bgneal@442: addQueryStateHandler : function(name, callback, scope) { bgneal@442: this.queryStateCommands[name] = {func : callback, scope : scope || this}; bgneal@442: }, bgneal@442: bgneal@442: addQueryValueHandler : function(name, callback, scope) { bgneal@442: this.queryValueCommands[name] = {func : callback, scope : scope || this}; bgneal@312: }, bgneal@312: bgneal@312: addShortcut : function(pa, desc, cmd_func, sc) { bgneal@312: var t = this, c; bgneal@312: bgneal@312: if (!t.settings.custom_shortcuts) bgneal@312: return false; bgneal@312: bgneal@312: t.shortcuts = t.shortcuts || {}; bgneal@312: bgneal@312: if (is(cmd_func, 'string')) { bgneal@312: c = cmd_func; bgneal@312: bgneal@312: cmd_func = function() { bgneal@312: t.execCommand(c, false, null); bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: if (is(cmd_func, 'object')) { bgneal@312: c = cmd_func; bgneal@312: bgneal@312: cmd_func = function() { bgneal@312: t.execCommand(c[0], c[1], c[2]); bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: each(explode(pa), function(pa) { bgneal@312: var o = { bgneal@312: func : cmd_func, bgneal@312: scope : sc || this, bgneal@312: desc : desc, bgneal@312: alt : false, bgneal@312: ctrl : false, bgneal@312: shift : false bgneal@312: }; bgneal@312: bgneal@312: each(explode(pa, '+'), function(v) { bgneal@312: switch (v) { bgneal@312: case 'alt': bgneal@312: case 'ctrl': bgneal@312: case 'shift': bgneal@312: o[v] = true; bgneal@312: break; bgneal@312: bgneal@312: default: bgneal@312: o.charCode = v.charCodeAt(0); bgneal@312: o.keyCode = v.toUpperCase().charCodeAt(0); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: t.shortcuts[(o.ctrl ? 'ctrl' : '') + ',' + (o.alt ? 'alt' : '') + ',' + (o.shift ? 'shift' : '') + ',' + o.keyCode] = o; bgneal@312: }); bgneal@312: bgneal@312: return true; bgneal@312: }, bgneal@312: bgneal@312: execCommand : function(cmd, ui, val, a) { bgneal@312: var t = this, s = 0, o, st; bgneal@312: bgneal@312: if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus)) bgneal@312: t.focus(); bgneal@312: bgneal@312: o = {}; bgneal@312: t.onBeforeExecCommand.dispatch(t, cmd, ui, val, o); bgneal@312: if (o.terminate) bgneal@312: return false; bgneal@312: bgneal@312: // Command callback bgneal@312: if (t.execCallback('execcommand_callback', t.id, t.selection.getNode(), cmd, ui, val)) { bgneal@312: t.onExecCommand.dispatch(t, cmd, ui, val, a); bgneal@312: return true; bgneal@312: } bgneal@312: bgneal@312: // Registred commands bgneal@312: if (o = t.execCommands[cmd]) { bgneal@312: st = o.func.call(o.scope, ui, val); bgneal@312: bgneal@312: // Fall through on true bgneal@312: if (st !== true) { bgneal@312: t.onExecCommand.dispatch(t, cmd, ui, val, a); bgneal@312: return st; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Plugin commands bgneal@312: each(t.plugins, function(p) { bgneal@312: if (p.execCommand && p.execCommand(cmd, ui, val)) { bgneal@312: t.onExecCommand.dispatch(t, cmd, ui, val, a); bgneal@312: s = 1; bgneal@312: return false; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: if (s) bgneal@312: return true; bgneal@312: bgneal@312: // Theme commands bgneal@312: if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) { bgneal@312: t.onExecCommand.dispatch(t, cmd, ui, val, a); bgneal@312: return true; bgneal@312: } bgneal@312: bgneal@312: // Editor commands bgneal@312: if (t.editorCommands.execCommand(cmd, ui, val)) { bgneal@312: t.onExecCommand.dispatch(t, cmd, ui, val, a); bgneal@312: return true; bgneal@312: } bgneal@312: bgneal@312: // Browser commands bgneal@312: t.getDoc().execCommand(cmd, ui, val); bgneal@312: t.onExecCommand.dispatch(t, cmd, ui, val, a); bgneal@312: }, bgneal@312: bgneal@312: queryCommandState : function(cmd) { bgneal@312: var t = this, o, s; bgneal@312: bgneal@312: // Is hidden then return undefined bgneal@312: if (t._isHidden()) bgneal@312: return; bgneal@312: bgneal@312: // Registred commands bgneal@312: if (o = t.queryStateCommands[cmd]) { bgneal@312: s = o.func.call(o.scope); bgneal@312: bgneal@312: // Fall though on true bgneal@312: if (s !== true) bgneal@312: return s; bgneal@312: } bgneal@312: bgneal@312: // Registred commands bgneal@312: o = t.editorCommands.queryCommandState(cmd); bgneal@312: if (o !== -1) bgneal@312: return o; bgneal@312: bgneal@312: // Browser commands bgneal@312: try { bgneal@312: return this.getDoc().queryCommandState(cmd); bgneal@312: } catch (ex) { bgneal@312: // Fails sometimes see bug: 1896577 bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: queryCommandValue : function(c) { bgneal@312: var t = this, o, s; bgneal@312: bgneal@312: // Is hidden then return undefined bgneal@312: if (t._isHidden()) bgneal@312: return; bgneal@312: bgneal@312: // Registred commands bgneal@312: if (o = t.queryValueCommands[c]) { bgneal@312: s = o.func.call(o.scope); bgneal@312: bgneal@312: // Fall though on true bgneal@312: if (s !== true) bgneal@312: return s; bgneal@312: } bgneal@312: bgneal@312: // Registred commands bgneal@312: o = t.editorCommands.queryCommandValue(c); bgneal@312: if (is(o)) bgneal@312: return o; bgneal@312: bgneal@312: // Browser commands bgneal@312: try { bgneal@312: return this.getDoc().queryCommandValue(c); bgneal@312: } catch (ex) { bgneal@312: // Fails sometimes see bug: 1896577 bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: show : function() { bgneal@312: var t = this; bgneal@312: bgneal@312: DOM.show(t.getContainer()); bgneal@312: DOM.hide(t.id); bgneal@312: t.load(); bgneal@312: }, bgneal@312: bgneal@312: hide : function() { bgneal@312: var t = this, d = t.getDoc(); bgneal@312: bgneal@312: // Fixed bug where IE has a blinking cursor left from the editor bgneal@312: if (isIE && d) bgneal@312: d.execCommand('SelectAll'); bgneal@312: bgneal@312: // We must save before we hide so Safari doesn't crash bgneal@312: t.save(); bgneal@312: DOM.hide(t.getContainer()); bgneal@312: DOM.setStyle(t.id, 'display', t.orgDisplay); bgneal@312: }, bgneal@312: bgneal@312: isHidden : function() { bgneal@312: return !DOM.isHidden(this.id); bgneal@312: }, bgneal@312: bgneal@312: setProgressState : function(b, ti, o) { bgneal@312: this.onSetProgressState.dispatch(this, b, ti, o); bgneal@312: bgneal@312: return b; bgneal@312: }, bgneal@312: bgneal@312: load : function(o) { bgneal@312: var t = this, e = t.getElement(), h; bgneal@312: bgneal@312: if (e) { bgneal@312: o = o || {}; bgneal@312: o.load = true; bgneal@312: bgneal@312: // Double encode existing entities in the value bgneal@312: h = t.setContent(is(e.value) ? e.value : e.innerHTML, o); bgneal@312: o.element = e; bgneal@312: bgneal@312: if (!o.no_events) bgneal@312: t.onLoadContent.dispatch(t, o); bgneal@312: bgneal@312: o.element = e = null; bgneal@312: bgneal@312: return h; bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: save : function(o) { bgneal@312: var t = this, e = t.getElement(), h, f; bgneal@312: bgneal@312: if (!e || !t.initialized) bgneal@312: return; bgneal@312: bgneal@312: o = o || {}; bgneal@312: o.save = true; bgneal@312: bgneal@312: // Add undo level will trigger onchange event bgneal@312: if (!o.no_events) { bgneal@442: t.undoManager.typing = false; bgneal@312: t.undoManager.add(); bgneal@312: } bgneal@312: bgneal@312: o.element = e; bgneal@312: h = o.content = t.getContent(o); bgneal@312: bgneal@312: if (!o.no_events) bgneal@312: t.onSaveContent.dispatch(t, o); bgneal@312: bgneal@312: h = o.content; bgneal@312: bgneal@312: if (!/TEXTAREA|INPUT/i.test(e.nodeName)) { bgneal@312: e.innerHTML = h; bgneal@312: bgneal@312: // Update hidden form element bgneal@312: if (f = DOM.getParent(t.id, 'form')) { bgneal@312: each(f.elements, function(e) { bgneal@312: if (e.name == t.id) { bgneal@312: e.value = h; bgneal@312: return false; bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: } else bgneal@312: e.value = h; bgneal@312: bgneal@312: o.element = e = null; bgneal@312: bgneal@312: return h; bgneal@312: }, bgneal@312: bgneal@442: setContent : function(content, args) { bgneal@442: var self = this, rootNode, body = self.getBody(); bgneal@442: bgneal@442: // Setup args object bgneal@442: args = args || {}; bgneal@442: args.format = args.format || 'html'; bgneal@442: args.set = true; bgneal@442: args.content = content; bgneal@442: bgneal@442: // Do preprocessing bgneal@442: if (!args.no_events) bgneal@442: self.onBeforeSetContent.dispatch(self, args); bgneal@442: bgneal@442: content = args.content; bgneal@312: bgneal@312: // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content bgneal@312: // It will also be impossible to place the caret in the editor unless there is a BR element present bgneal@442: if (!tinymce.isIE && (content.length === 0 || /^\s+$/.test(content))) { bgneal@442: body.innerHTML = '
    '; bgneal@442: return; bgneal@442: } bgneal@442: bgneal@442: // Parse and serialize the html bgneal@442: if (args.format !== 'raw') { bgneal@442: content = new tinymce.html.Serializer({}, self.schema).serialize( bgneal@442: self.parser.parse(content) bgneal@442: ); bgneal@442: } bgneal@442: bgneal@442: // Set the new cleaned contents to the editor bgneal@442: args.content = tinymce.trim(content); bgneal@442: self.dom.setHTML(body, args.content); bgneal@442: bgneal@442: // Do post processing bgneal@442: if (!args.no_events) bgneal@442: self.onSetContent.dispatch(self, args); bgneal@442: bgneal@442: return args.content; bgneal@442: }, bgneal@442: bgneal@442: getContent : function(args) { bgneal@442: var self = this, content; bgneal@442: bgneal@442: // Setup args object bgneal@442: args = args || {}; bgneal@442: args.format = args.format || 'html'; bgneal@442: args.get = true; bgneal@442: bgneal@442: // Do preprocessing bgneal@442: if (!args.no_events) bgneal@442: self.onBeforeGetContent.dispatch(self, args); bgneal@442: bgneal@442: // Get raw contents or by default the cleaned contents bgneal@442: if (args.format == 'raw') bgneal@442: content = self.getBody().innerHTML; bgneal@442: else bgneal@442: content = self.serializer.serialize(self.getBody(), args); bgneal@442: bgneal@442: args.content = tinymce.trim(content); bgneal@442: bgneal@442: // Do post processing bgneal@442: if (!args.no_events) bgneal@442: self.onGetContent.dispatch(self, args); bgneal@442: bgneal@442: return args.content; bgneal@312: }, bgneal@312: bgneal@312: isDirty : function() { bgneal@442: var self = this; bgneal@442: bgneal@442: return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty; bgneal@312: }, bgneal@312: bgneal@312: getContainer : function() { bgneal@312: var t = this; bgneal@312: bgneal@312: if (!t.container) bgneal@312: t.container = DOM.get(t.editorContainer || t.id + '_parent'); bgneal@312: bgneal@312: return t.container; bgneal@312: }, bgneal@312: bgneal@312: getContentAreaContainer : function() { bgneal@312: return this.contentAreaContainer; bgneal@312: }, bgneal@312: bgneal@312: getElement : function() { bgneal@312: return DOM.get(this.settings.content_element || this.id); bgneal@312: }, bgneal@312: bgneal@312: getWin : function() { bgneal@312: var t = this, e; bgneal@312: bgneal@312: if (!t.contentWindow) { bgneal@312: e = DOM.get(t.id + "_ifr"); bgneal@312: bgneal@312: if (e) bgneal@312: t.contentWindow = e.contentWindow; bgneal@312: } bgneal@312: bgneal@312: return t.contentWindow; bgneal@312: }, bgneal@312: bgneal@312: getDoc : function() { bgneal@312: var t = this, w; bgneal@312: bgneal@312: if (!t.contentDocument) { bgneal@312: w = t.getWin(); bgneal@312: bgneal@312: if (w) bgneal@312: t.contentDocument = w.document; bgneal@312: } bgneal@312: bgneal@312: return t.contentDocument; bgneal@312: }, bgneal@312: bgneal@312: getBody : function() { bgneal@312: return this.bodyElement || this.getDoc().body; bgneal@312: }, bgneal@312: bgneal@312: convertURL : function(u, n, e) { bgneal@312: var t = this, s = t.settings; bgneal@312: bgneal@312: // Use callback instead bgneal@312: if (s.urlconverter_callback) bgneal@312: return t.execCallback('urlconverter_callback', u, e, true, n); bgneal@312: bgneal@312: // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs bgneal@312: if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0) bgneal@312: return u; bgneal@312: bgneal@312: // Convert to relative bgneal@312: if (s.relative_urls) bgneal@312: return t.documentBaseURI.toRelative(u); bgneal@312: bgneal@312: // Convert to absolute bgneal@312: u = t.documentBaseURI.toAbsolute(u, s.remove_script_host); bgneal@312: bgneal@312: return u; bgneal@312: }, bgneal@312: bgneal@312: addVisual : function(e) { bgneal@312: var t = this, s = t.settings; bgneal@312: bgneal@312: e = e || t.getBody(); bgneal@312: bgneal@312: if (!is(t.hasVisual)) bgneal@312: t.hasVisual = s.visual; bgneal@312: bgneal@312: each(t.dom.select('table,a', e), function(e) { bgneal@312: var v; bgneal@312: bgneal@312: switch (e.nodeName) { bgneal@312: case 'TABLE': bgneal@312: v = t.dom.getAttrib(e, 'border'); bgneal@312: bgneal@312: if (!v || v == '0') { bgneal@312: if (t.hasVisual) bgneal@312: t.dom.addClass(e, s.visual_table_class); bgneal@312: else bgneal@312: t.dom.removeClass(e, s.visual_table_class); bgneal@312: } bgneal@312: bgneal@312: return; bgneal@312: bgneal@312: case 'A': bgneal@312: v = t.dom.getAttrib(e, 'name'); bgneal@312: bgneal@312: if (v) { bgneal@312: if (t.hasVisual) bgneal@312: t.dom.addClass(e, 'mceItemAnchor'); bgneal@312: else bgneal@312: t.dom.removeClass(e, 'mceItemAnchor'); bgneal@312: } bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: t.onVisualAid.dispatch(t, e, t.hasVisual); bgneal@312: }, bgneal@312: bgneal@312: remove : function() { bgneal@312: var t = this, e = t.getContainer(); bgneal@312: bgneal@312: t.removed = 1; // Cancels post remove event execution bgneal@312: t.hide(); bgneal@312: bgneal@312: t.execCallback('remove_instance_callback', t); bgneal@312: t.onRemove.dispatch(t); bgneal@312: bgneal@312: // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command bgneal@312: t.onExecCommand.listeners = []; bgneal@312: bgneal@312: tinymce.remove(t); bgneal@312: DOM.remove(e); bgneal@312: }, bgneal@312: bgneal@312: destroy : function(s) { bgneal@312: var t = this; bgneal@312: bgneal@312: // One time is enough bgneal@312: if (t.destroyed) bgneal@312: return; bgneal@312: bgneal@312: if (!s) { bgneal@312: tinymce.removeUnload(t.destroy); bgneal@312: tinyMCE.onBeforeUnload.remove(t._beforeUnload); bgneal@312: bgneal@312: // Manual destroy bgneal@312: if (t.theme && t.theme.destroy) bgneal@312: t.theme.destroy(); bgneal@312: bgneal@312: // Destroy controls, selection and dom bgneal@312: t.controlManager.destroy(); bgneal@312: t.selection.destroy(); bgneal@312: t.dom.destroy(); bgneal@312: bgneal@312: // Remove all events bgneal@312: bgneal@312: // Don't clear the window or document if content editable bgneal@312: // is enabled since other instances might still be present bgneal@312: if (!t.settings.content_editable) { bgneal@312: Event.clear(t.getWin()); bgneal@312: Event.clear(t.getDoc()); bgneal@312: } bgneal@312: bgneal@312: Event.clear(t.getBody()); bgneal@312: Event.clear(t.formElement); bgneal@312: } bgneal@312: bgneal@312: if (t.formElement) { bgneal@312: t.formElement.submit = t.formElement._mceOldSubmit; bgneal@312: t.formElement._mceOldSubmit = null; bgneal@312: } bgneal@312: bgneal@312: t.contentAreaContainer = t.formElement = t.container = t.settings.content_element = t.bodyElement = t.contentDocument = t.contentWindow = null; bgneal@312: bgneal@312: if (t.selection) bgneal@312: t.selection = t.selection.win = t.selection.dom = t.selection.dom.doc = null; bgneal@312: bgneal@312: t.destroyed = 1; bgneal@312: }, bgneal@312: bgneal@312: // Internal functions bgneal@312: bgneal@312: _addEvents : function() { bgneal@312: // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset bgneal@442: var t = this, i, s = t.settings, dom = t.dom, lo = { bgneal@312: mouseup : 'onMouseUp', bgneal@312: mousedown : 'onMouseDown', bgneal@312: click : 'onClick', bgneal@312: keyup : 'onKeyUp', bgneal@312: keydown : 'onKeyDown', bgneal@312: keypress : 'onKeyPress', bgneal@312: submit : 'onSubmit', bgneal@312: reset : 'onReset', bgneal@312: contextmenu : 'onContextMenu', bgneal@312: dblclick : 'onDblClick', bgneal@312: paste : 'onPaste' // Doesn't work in all browsers yet bgneal@312: }; bgneal@312: bgneal@312: function eventHandler(e, o) { bgneal@312: var ty = e.type; bgneal@312: bgneal@312: // Don't fire events when it's removed bgneal@312: if (t.removed) bgneal@312: return; bgneal@312: bgneal@312: // Generic event handler bgneal@312: if (t.onEvent.dispatch(t, e, o) !== false) { bgneal@312: // Specific event handler bgneal@312: t[lo[e.fakeType || e.type]].dispatch(t, e, o); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: // Add DOM events bgneal@312: each(lo, function(v, k) { bgneal@312: switch (k) { bgneal@312: case 'contextmenu': bgneal@442: dom.bind(t.getDoc(), k, eventHandler); bgneal@312: break; bgneal@312: bgneal@312: case 'paste': bgneal@442: dom.bind(t.getBody(), k, function(e) { bgneal@312: eventHandler(e); bgneal@312: }); bgneal@312: break; bgneal@312: bgneal@312: case 'submit': bgneal@312: case 'reset': bgneal@442: dom.bind(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler); bgneal@312: break; bgneal@312: bgneal@312: default: bgneal@442: dom.bind(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler); bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: dom.bind(s.content_editable ? t.getBody() : (isGecko ? t.getDoc() : t.getWin()), 'focus', function(e) { bgneal@312: t.focus(true); bgneal@312: }); bgneal@312: bgneal@312: bgneal@312: // Fixes bug where a specified document_base_uri could result in broken images bgneal@312: // This will also fix drag drop of images in Gecko bgneal@312: if (tinymce.isGecko) { bgneal@442: dom.bind(t.getDoc(), 'DOMNodeInserted', function(e) { bgneal@312: var v; bgneal@312: bgneal@312: e = e.target; bgneal@312: bgneal@442: if (e.nodeType === 1 && e.nodeName === 'IMG' && (v = e.getAttribute('data-mce-src'))) bgneal@312: e.src = t.documentBaseURI.toAbsolute(v); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: // Set various midas options in Gecko bgneal@312: if (isGecko) { bgneal@312: function setOpts() { bgneal@312: var t = this, d = t.getDoc(), s = t.settings; bgneal@312: bgneal@312: if (isGecko && !s.readonly) { bgneal@312: if (t._isHidden()) { bgneal@312: try { bgneal@312: if (!s.content_editable) bgneal@312: d.designMode = 'On'; bgneal@312: } catch (ex) { bgneal@312: // Fails if it's hidden bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: try { bgneal@312: // Try new Gecko method bgneal@312: d.execCommand("styleWithCSS", 0, false); bgneal@312: } catch (ex) { bgneal@312: // Use old method bgneal@312: if (!t._isHidden()) bgneal@312: try {d.execCommand("useCSS", 0, true);} catch (ex) {} bgneal@312: } bgneal@312: bgneal@312: if (!s.table_inline_editing) bgneal@312: try {d.execCommand('enableInlineTableEditing', false, false);} catch (ex) {} bgneal@312: bgneal@312: if (!s.object_resizing) bgneal@312: try {d.execCommand('enableObjectResizing', false, false);} catch (ex) {} bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: t.onBeforeExecCommand.add(setOpts); bgneal@312: t.onMouseDown.add(setOpts); bgneal@312: } bgneal@312: bgneal@312: // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250 bgneal@312: // WebKit can't even do simple things like selecting an image bgneal@312: // This also fixes so it's possible to select mceItemAnchors bgneal@312: if (tinymce.isWebKit) { bgneal@312: t.onClick.add(function(ed, e) { bgneal@312: e = e.target; bgneal@312: bgneal@312: // Needs tobe the setBaseAndExtend or it will fail to select floated images bgneal@442: if (e.nodeName == 'IMG' || (e.nodeName == 'A' && dom.hasClass(e, 'mceItemAnchor'))) { bgneal@312: t.selection.getSel().setBaseAndExtent(e, 0, e, 1); bgneal@442: t.nodeChanged(); bgneal@442: } bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: // Add node change handlers bgneal@312: t.onMouseUp.add(t.nodeChanged); bgneal@312: //t.onClick.add(t.nodeChanged); bgneal@312: t.onKeyUp.add(function(ed, e) { bgneal@312: var c = e.keyCode; bgneal@312: bgneal@312: if ((c >= 33 && c <= 36) || (c >= 37 && c <= 40) || c == 13 || c == 45 || c == 46 || c == 8 || (tinymce.isMac && (c == 91 || c == 93)) || e.ctrlKey) bgneal@312: t.nodeChanged(); bgneal@312: }); bgneal@312: bgneal@312: // Add reset handler bgneal@312: t.onReset.add(function() { bgneal@312: t.setContent(t.startContent, {format : 'raw'}); bgneal@312: }); bgneal@312: bgneal@312: // Add shortcuts bgneal@312: if (s.custom_shortcuts) { bgneal@312: if (s.custom_undo_redo_keyboard_shortcuts) { bgneal@312: t.addShortcut('ctrl+z', t.getLang('undo_desc'), 'Undo'); bgneal@312: t.addShortcut('ctrl+y', t.getLang('redo_desc'), 'Redo'); bgneal@312: } bgneal@312: bgneal@312: // Add default shortcuts for gecko bgneal@312: t.addShortcut('ctrl+b', t.getLang('bold_desc'), 'Bold'); bgneal@312: t.addShortcut('ctrl+i', t.getLang('italic_desc'), 'Italic'); bgneal@312: t.addShortcut('ctrl+u', t.getLang('underline_desc'), 'Underline'); bgneal@312: bgneal@312: // BlockFormat shortcuts keys bgneal@312: for (i=1; i<=6; i++) bgneal@312: t.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]); bgneal@312: bgneal@312: t.addShortcut('ctrl+7', '', ['FormatBlock', false, '

    ']); bgneal@312: t.addShortcut('ctrl+8', '', ['FormatBlock', false, '

    ']); bgneal@312: t.addShortcut('ctrl+9', '', ['FormatBlock', false, '
    ']); bgneal@312: bgneal@312: function find(e) { bgneal@312: var v = null; bgneal@312: bgneal@312: if (!e.altKey && !e.ctrlKey && !e.metaKey) bgneal@312: return v; bgneal@312: bgneal@312: each(t.shortcuts, function(o) { bgneal@312: if (tinymce.isMac && o.ctrl != e.metaKey) bgneal@312: return; bgneal@312: else if (!tinymce.isMac && o.ctrl != e.ctrlKey) bgneal@312: return; bgneal@312: bgneal@312: if (o.alt != e.altKey) bgneal@312: return; bgneal@312: bgneal@312: if (o.shift != e.shiftKey) bgneal@312: return; bgneal@312: bgneal@312: if (e.keyCode == o.keyCode || (e.charCode && e.charCode == o.charCode)) { bgneal@312: v = o; bgneal@312: return false; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: return v; bgneal@312: }; bgneal@312: bgneal@312: t.onKeyUp.add(function(ed, e) { bgneal@312: var o = find(e); bgneal@312: bgneal@312: if (o) bgneal@312: return Event.cancel(e); bgneal@312: }); bgneal@312: bgneal@312: t.onKeyPress.add(function(ed, e) { bgneal@312: var o = find(e); bgneal@312: bgneal@312: if (o) bgneal@312: return Event.cancel(e); bgneal@312: }); bgneal@312: bgneal@312: t.onKeyDown.add(function(ed, e) { bgneal@312: var o = find(e); bgneal@312: bgneal@312: if (o) { bgneal@312: o.func.call(o.scope); bgneal@312: return Event.cancel(e); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (tinymce.isIE) { bgneal@312: // Fix so resize will only update the width and height attributes not the styles of an image bgneal@312: // It will also block mceItemNoResize items bgneal@442: dom.bind(t.getDoc(), 'controlselect', function(e) { bgneal@312: var re = t.resizeInfo, cb; bgneal@312: bgneal@312: e = e.target; bgneal@312: bgneal@312: // Don't do this action for non image elements bgneal@312: if (e.nodeName !== 'IMG') bgneal@312: return; bgneal@312: bgneal@312: if (re) bgneal@442: dom.unbind(re.node, re.ev, re.cb); bgneal@442: bgneal@442: if (!dom.hasClass(e, 'mceItemNoResize')) { bgneal@312: ev = 'resizeend'; bgneal@442: cb = dom.bind(e, ev, function(e) { bgneal@312: var v; bgneal@312: bgneal@312: e = e.target; bgneal@312: bgneal@442: if (v = dom.getStyle(e, 'width')) { bgneal@442: dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, '')); bgneal@442: dom.setStyle(e, 'width', ''); bgneal@312: } bgneal@312: bgneal@442: if (v = dom.getStyle(e, 'height')) { bgneal@442: dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, '')); bgneal@442: dom.setStyle(e, 'height', ''); bgneal@312: } bgneal@312: }); bgneal@312: } else { bgneal@312: ev = 'resizestart'; bgneal@442: cb = dom.bind(e, 'resizestart', Event.cancel, Event); bgneal@312: } bgneal@312: bgneal@312: re = t.resizeInfo = { bgneal@312: node : e, bgneal@312: ev : ev, bgneal@312: cb : cb bgneal@312: }; bgneal@312: }); bgneal@312: bgneal@312: t.onKeyDown.add(function(ed, e) { bgneal@442: var sel; bgneal@442: bgneal@312: switch (e.keyCode) { bgneal@312: case 8: bgneal@442: sel = t.getDoc().selection; bgneal@442: bgneal@312: // Fix IE control + backspace browser bug bgneal@442: if (sel.createRange && sel.createRange().item) { bgneal@442: ed.dom.remove(sel.createRange().item(0)); bgneal@312: return Event.cancel(e); bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (tinymce.isOpera) { bgneal@312: t.onClick.add(function(ed, e) { bgneal@312: Event.prevent(e); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: // Add custom undo/redo handlers bgneal@312: if (s.custom_undo_redo) { bgneal@312: function addUndo() { bgneal@442: t.undoManager.typing = false; bgneal@312: t.undoManager.add(); bgneal@312: }; bgneal@312: bgneal@442: dom.bind(t.getDoc(), 'focusout', function(e) { bgneal@312: if (!t.removed && t.undoManager.typing) bgneal@312: addUndo(); bgneal@312: }); bgneal@312: bgneal@442: // Add undo level when contents is drag/dropped within the editor bgneal@442: t.dom.bind(t.dom.getRoot(), 'dragend', function(e) { bgneal@442: addUndo(); bgneal@442: }); bgneal@442: bgneal@312: t.onKeyUp.add(function(ed, e) { bgneal@442: var rng, parent, bookmark; bgneal@442: bgneal@442: // Fix for bug #3168, to remove odd ".." nodes from the DOM we need to get/set the HTML of the parent node. bgneal@442: if (isIE && e.keyCode == 8) { bgneal@442: rng = t.selection.getRng(); bgneal@442: if (rng.parentElement) { bgneal@442: parent = rng.parentElement(); bgneal@442: bookmark = t.selection.getBookmark(); bgneal@442: parent.innerHTML = parent.innerHTML; bgneal@442: t.selection.moveToBookmark(bookmark); bgneal@442: } bgneal@442: } bgneal@442: bgneal@312: if ((e.keyCode >= 33 && e.keyCode <= 36) || (e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 || e.keyCode == 45 || e.ctrlKey) bgneal@312: addUndo(); bgneal@312: }); bgneal@312: bgneal@312: t.onKeyDown.add(function(ed, e) { bgneal@442: var rng, parent, bookmark, keyCode = e.keyCode; bgneal@312: bgneal@312: // IE has a really odd bug where the DOM might include an node that doesn't have bgneal@312: // a proper structure. If you try to access nodeValue it would throw an illegal value exception. bgneal@312: // This seems to only happen when you delete contents and it seems to be avoidable if you refresh the element bgneal@312: // after you delete contents from it. See: #3008923 bgneal@442: if (isIE && keyCode == 46) { bgneal@312: rng = t.selection.getRng(); bgneal@312: bgneal@312: if (rng.parentElement) { bgneal@312: parent = rng.parentElement(); bgneal@312: bgneal@442: if (!t.undoManager.typing) { bgneal@442: t.undoManager.beforeChange(); bgneal@442: t.undoManager.typing = true; bgneal@442: t.undoManager.add(); bgneal@442: } bgneal@442: bgneal@312: // Select next word when ctrl key is used in combo with delete bgneal@312: if (e.ctrlKey) { bgneal@312: rng.moveEnd('word', 1); bgneal@312: rng.select(); bgneal@312: } bgneal@312: bgneal@312: // Delete contents bgneal@312: t.selection.getSel().clear(); bgneal@312: bgneal@312: // Check if we are within the same parent bgneal@312: if (rng.parentElement() == parent) { bgneal@312: bookmark = t.selection.getBookmark(); bgneal@312: bgneal@312: try { bgneal@312: // Update the HTML and hopefully it will remove the artifacts bgneal@312: parent.innerHTML = parent.innerHTML; bgneal@312: } catch (ex) { bgneal@312: // And since it's IE it can sometimes produce an unknown runtime error bgneal@312: } bgneal@312: bgneal@312: // Restore the caret position bgneal@312: t.selection.moveToBookmark(bookmark); bgneal@312: } bgneal@312: bgneal@312: // Block the default delete behavior since it might be broken bgneal@312: e.preventDefault(); bgneal@312: return; bgneal@312: } bgneal@312: } bgneal@312: bgneal@442: // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter bgneal@442: if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45) { bgneal@442: // Add position before enter key is pressed, used by IE since it still uses the default browser behavior bgneal@442: // Todo: Remove this once we normalize enter behavior on IE bgneal@442: if (tinymce.isIE && keyCode == 13) bgneal@442: t.undoManager.beforeChange(); bgneal@442: bgneal@312: if (t.undoManager.typing) bgneal@312: addUndo(); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: bgneal@442: // If key isn't shift,ctrl,alt,capslock,metakey bgneal@442: if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !t.undoManager.typing) { bgneal@442: t.undoManager.beforeChange(); bgneal@312: t.undoManager.add(); bgneal@442: t.undoManager.typing = true; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: t.onMouseDown.add(function() { bgneal@312: if (t.undoManager.typing) bgneal@312: addUndo(); bgneal@312: }); bgneal@312: } bgneal@442: bgneal@442: // Bug fix for FireFox keeping styles from end of selection instead of start. bgneal@442: if (tinymce.isGecko) { bgneal@442: function getAttributeApplyFunction() { bgneal@442: var template = t.dom.getAttribs(t.selection.getStart().cloneNode(false)); bgneal@442: bgneal@442: return function() { bgneal@442: var target = t.selection.getStart(); bgneal@442: t.dom.removeAllAttribs(target); bgneal@442: each(template, function(attr) { bgneal@442: target.setAttributeNode(attr.cloneNode(true)); bgneal@442: }); bgneal@442: }; bgneal@442: } bgneal@442: bgneal@442: function isSelectionAcrossElements() { bgneal@442: var s = t.selection; bgneal@442: bgneal@442: return !s.isCollapsed() && s.getStart() != s.getEnd(); bgneal@442: } bgneal@442: bgneal@442: t.onKeyPress.add(function(ed, e) { bgneal@442: var applyAttributes; bgneal@442: bgneal@442: if ((e.keyCode == 8 || e.keyCode == 46) && isSelectionAcrossElements()) { bgneal@442: applyAttributes = getAttributeApplyFunction(); bgneal@442: t.getDoc().execCommand('delete', false, null); bgneal@442: applyAttributes(); bgneal@442: bgneal@442: return Event.cancel(e); bgneal@442: } bgneal@442: }); bgneal@442: bgneal@442: t.dom.bind(t.getDoc(), 'cut', function(e) { bgneal@442: var applyAttributes; bgneal@442: bgneal@442: if (isSelectionAcrossElements()) { bgneal@442: applyAttributes = getAttributeApplyFunction(); bgneal@442: t.onKeyUp.addToTop(Event.cancel, Event); bgneal@442: bgneal@442: setTimeout(function() { bgneal@442: applyAttributes(); bgneal@442: t.onKeyUp.remove(Event.cancel, Event); bgneal@442: }, 0); bgneal@442: } bgneal@442: }); bgneal@442: } bgneal@312: }, bgneal@312: bgneal@312: _isHidden : function() { bgneal@312: var s; bgneal@312: bgneal@312: if (!isGecko) bgneal@312: return 0; bgneal@312: bgneal@312: // Weird, wheres that cursor selection? bgneal@312: s = this.selection.getSel(); bgneal@312: return (!s || !s.rangeCount || s.rangeCount == 0); bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: // Added for compression purposes bgneal@312: var each = tinymce.each, undefined, TRUE = true, FALSE = false; bgneal@312: bgneal@312: tinymce.EditorCommands = function(editor) { bgneal@312: var dom = editor.dom, bgneal@312: selection = editor.selection, bgneal@312: commands = {state: {}, exec : {}, value : {}}, bgneal@312: settings = editor.settings, bgneal@312: bookmark; bgneal@312: bgneal@312: function execCommand(command, ui, value) { bgneal@312: var func; bgneal@312: bgneal@312: command = command.toLowerCase(); bgneal@312: if (func = commands.exec[command]) { bgneal@312: func(command, ui, value); bgneal@312: return TRUE; bgneal@312: } bgneal@312: bgneal@312: return FALSE; bgneal@312: }; bgneal@312: bgneal@312: function queryCommandState(command) { bgneal@312: var func; bgneal@312: bgneal@312: command = command.toLowerCase(); bgneal@312: if (func = commands.state[command]) bgneal@312: return func(command); bgneal@312: bgneal@312: return -1; bgneal@312: }; bgneal@312: bgneal@312: function queryCommandValue(command) { bgneal@312: var func; bgneal@312: bgneal@312: command = command.toLowerCase(); bgneal@312: if (func = commands.value[command]) bgneal@312: return func(command); bgneal@312: bgneal@312: return FALSE; bgneal@312: }; bgneal@312: bgneal@312: function addCommands(command_list, type) { bgneal@312: type = type || 'exec'; bgneal@312: bgneal@312: each(command_list, function(callback, command) { bgneal@312: each(command.toLowerCase().split(','), function(command) { bgneal@312: commands[type][command] = callback; bgneal@312: }); bgneal@312: }); bgneal@312: }; bgneal@312: bgneal@312: // Expose public methods bgneal@312: tinymce.extend(this, { bgneal@312: execCommand : execCommand, bgneal@312: queryCommandState : queryCommandState, bgneal@312: queryCommandValue : queryCommandValue, bgneal@312: addCommands : addCommands bgneal@312: }); bgneal@312: bgneal@312: // Private methods bgneal@312: bgneal@312: function execNativeCommand(command, ui, value) { bgneal@312: if (ui === undefined) bgneal@312: ui = FALSE; bgneal@312: bgneal@312: if (value === undefined) bgneal@312: value = null; bgneal@312: bgneal@312: return editor.getDoc().execCommand(command, ui, value); bgneal@312: }; bgneal@312: bgneal@312: function isFormatMatch(name) { bgneal@312: return editor.formatter.match(name); bgneal@312: }; bgneal@312: bgneal@312: function toggleFormat(name, value) { bgneal@312: editor.formatter.toggle(name, value ? {value : value} : undefined); bgneal@312: }; bgneal@312: bgneal@312: function storeSelection(type) { bgneal@312: bookmark = selection.getBookmark(type); bgneal@312: }; bgneal@312: bgneal@312: function restoreSelection() { bgneal@312: selection.moveToBookmark(bookmark); bgneal@312: }; bgneal@312: bgneal@312: // Add execCommand overrides bgneal@312: addCommands({ bgneal@312: // Ignore these, added for compatibility bgneal@312: 'mceResetDesignMode,mceBeginUndoLevel' : function() {}, bgneal@312: bgneal@312: // Add undo manager logic bgneal@312: 'mceEndUndoLevel,mceAddUndoLevel' : function() { bgneal@312: editor.undoManager.add(); bgneal@312: }, bgneal@312: bgneal@312: 'Cut,Copy,Paste' : function(command) { bgneal@312: var doc = editor.getDoc(), failed; bgneal@312: bgneal@312: // Try executing the native command bgneal@312: try { bgneal@312: execNativeCommand(command); bgneal@312: } catch (ex) { bgneal@312: // Command failed bgneal@312: failed = TRUE; bgneal@312: } bgneal@312: bgneal@312: // Present alert message about clipboard access not being available bgneal@312: if (failed || !doc.queryCommandSupported(command)) { bgneal@312: if (tinymce.isGecko) { bgneal@312: editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) { bgneal@312: if (state) bgneal@312: open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank'); bgneal@312: }); bgneal@312: } else bgneal@312: editor.windowManager.alert(editor.getLang('clipboard_no_support')); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: // Override unlink command bgneal@312: unlink : function(command) { bgneal@312: if (selection.isCollapsed()) bgneal@312: selection.select(selection.getNode()); bgneal@312: bgneal@312: execNativeCommand(command); bgneal@312: selection.collapse(FALSE); bgneal@312: }, bgneal@312: bgneal@312: // Override justify commands to use the text formatter engine bgneal@312: 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) { bgneal@312: var align = command.substring(7); bgneal@312: bgneal@312: // Remove all other alignments first bgneal@312: each('left,center,right,full'.split(','), function(name) { bgneal@312: if (align != name) bgneal@312: editor.formatter.remove('align' + name); bgneal@312: }); bgneal@312: bgneal@312: toggleFormat('align' + align); bgneal@442: execCommand('mceRepaint'); bgneal@312: }, bgneal@312: bgneal@312: // Override list commands to fix WebKit bug bgneal@312: 'InsertUnorderedList,InsertOrderedList' : function(command) { bgneal@312: var listElm, listParent; bgneal@312: bgneal@312: execNativeCommand(command); bgneal@312: bgneal@312: // WebKit produces lists within block elements so we need to split them bgneal@312: // we will replace the native list creation logic to custom logic later on bgneal@312: // TODO: Remove this when the list creation logic is removed bgneal@312: listElm = dom.getParent(selection.getNode(), 'ol,ul'); bgneal@312: if (listElm) { bgneal@312: listParent = listElm.parentNode; bgneal@312: bgneal@312: // If list is within a text block then split that block bgneal@312: if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) { bgneal@312: storeSelection(); bgneal@312: dom.split(listParent, listElm); bgneal@312: restoreSelection(); bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: // Override commands to use the text formatter engine bgneal@442: 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) { bgneal@312: toggleFormat(command); bgneal@312: }, bgneal@312: bgneal@312: // Override commands to use the text formatter engine bgneal@312: 'ForeColor,HiliteColor,FontName' : function(command, ui, value) { bgneal@312: toggleFormat(command, value); bgneal@312: }, bgneal@312: bgneal@312: FontSize : function(command, ui, value) { bgneal@312: var fontClasses, fontSizes; bgneal@312: bgneal@312: // Convert font size 1-7 to styles bgneal@312: if (value >= 1 && value <= 7) { bgneal@312: fontSizes = tinymce.explode(settings.font_size_style_values); bgneal@312: fontClasses = tinymce.explode(settings.font_size_classes); bgneal@312: bgneal@312: if (fontClasses) bgneal@312: value = fontClasses[value - 1] || value; bgneal@312: else bgneal@312: value = fontSizes[value - 1] || value; bgneal@312: } bgneal@312: bgneal@312: toggleFormat(command, value); bgneal@312: }, bgneal@312: bgneal@312: RemoveFormat : function(command) { bgneal@312: editor.formatter.remove(command); bgneal@312: }, bgneal@312: bgneal@312: mceBlockQuote : function(command) { bgneal@312: toggleFormat('blockquote'); bgneal@312: }, bgneal@312: bgneal@312: FormatBlock : function(command, ui, value) { bgneal@312: return toggleFormat(value || 'p'); bgneal@312: }, bgneal@312: bgneal@312: mceCleanup : function() { bgneal@312: var bookmark = selection.getBookmark(); bgneal@312: bgneal@312: editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE}); bgneal@312: bgneal@312: selection.moveToBookmark(bookmark); bgneal@312: }, bgneal@312: bgneal@312: mceRemoveNode : function(command, ui, value) { bgneal@312: var node = value || selection.getNode(); bgneal@312: bgneal@312: // Make sure that the body node isn't removed bgneal@312: if (node != editor.getBody()) { bgneal@312: storeSelection(); bgneal@312: editor.dom.remove(node, TRUE); bgneal@312: restoreSelection(); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: mceSelectNodeDepth : function(command, ui, value) { bgneal@312: var counter = 0; bgneal@312: bgneal@312: dom.getParent(selection.getNode(), function(node) { bgneal@312: if (node.nodeType == 1 && counter++ == value) { bgneal@312: selection.select(node); bgneal@312: return FALSE; bgneal@312: } bgneal@312: }, editor.getBody()); bgneal@312: }, bgneal@312: bgneal@312: mceSelectNode : function(command, ui, value) { bgneal@312: selection.select(value); bgneal@312: }, bgneal@312: bgneal@312: mceInsertContent : function(command, ui, value) { bgneal@442: var caretNode, rng, rootNode, parent, node, rng, nodeRect, viewPortRect, args; bgneal@442: bgneal@442: function findSuitableCaretNode(node, root_node, next) { bgneal@442: var walker = new tinymce.dom.TreeWalker(next ? node.nextSibling : node.previousSibling, root_node); bgneal@442: bgneal@442: while ((node = walker.current())) { bgneal@442: if ((node.nodeType == 3 && tinymce.trim(node.nodeValue).length) || node.nodeName == 'BR' || node.nodeName == 'IMG') bgneal@442: return node; bgneal@442: bgneal@442: if (next) bgneal@442: walker.next(); bgneal@442: else bgneal@442: walker.prev(); bgneal@442: } bgneal@442: }; bgneal@442: bgneal@442: args = {content: value, format: 'html'}; bgneal@442: selection.onBeforeSetContent.dispatch(selection, args); bgneal@442: value = args.content; bgneal@442: bgneal@442: // Add caret at end of contents if it's missing bgneal@442: if (value.indexOf('{$caret}') == -1) bgneal@442: value += '{$caret}'; bgneal@442: bgneal@442: // Set the content at selection to a span and replace it's contents with the value bgneal@442: selection.setContent('\uFEFF', {no_events : false}); bgneal@442: dom.setOuterHTML('__mce', value.replace(/\{\$caret\}/, '\uFEFF')); bgneal@442: bgneal@442: caretNode = dom.select('#__mce')[0]; bgneal@442: rootNode = dom.getRoot(); bgneal@442: bgneal@442: // Move the caret into the last suitable location within the previous sibling if it's a block since the block might be split bgneal@442: if (caretNode.previousSibling && dom.isBlock(caretNode.previousSibling) || caretNode.parentNode == rootNode) { bgneal@442: node = findSuitableCaretNode(caretNode, rootNode); bgneal@442: if (node) { bgneal@442: if (node.nodeName == 'BR') bgneal@442: node.parentNode.insertBefore(caretNode, node); bgneal@442: else bgneal@442: dom.insertAfter(caretNode, node); bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: // Find caret root parent and clean it up using the serializer to avoid nesting bgneal@442: while (caretNode) { bgneal@442: if (caretNode === rootNode) { bgneal@442: // Clean up the parent element by parsing and serializing it bgneal@442: // This will remove invalid elements/attributes and fix nesting issues bgneal@442: dom.setOuterHTML(parent, bgneal@442: new tinymce.html.Serializer({}, editor.schema).serialize( bgneal@442: editor.parser.parse(dom.getOuterHTML(parent)) bgneal@442: ) bgneal@442: ); bgneal@442: bgneal@442: break; bgneal@442: } bgneal@442: bgneal@442: parent = caretNode; bgneal@442: caretNode = caretNode.parentNode; bgneal@442: } bgneal@442: bgneal@442: // Find caret after cleanup and move selection to that location bgneal@442: caretNode = dom.select('#__mce')[0]; bgneal@442: if (caretNode) { bgneal@442: node = findSuitableCaretNode(caretNode, rootNode) || findSuitableCaretNode(caretNode, rootNode, true); bgneal@442: dom.remove(caretNode); bgneal@442: bgneal@442: if (node) { bgneal@442: rng = dom.createRng(); bgneal@442: bgneal@442: if (node.nodeType == 3) { bgneal@442: rng.setStart(node, node.length); bgneal@442: rng.setEnd(node, node.length); bgneal@442: } else { bgneal@442: if (node.nodeName == 'BR') { bgneal@442: rng.setStartBefore(node); bgneal@442: rng.setEndBefore(node); bgneal@442: } else { bgneal@442: rng.setStartAfter(node); bgneal@442: rng.setEndAfter(node); bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: selection.setRng(rng); bgneal@442: bgneal@442: // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well bgneal@442: if (!tinymce.isIE) { bgneal@442: node = dom.create('span', null, '\u00a0'); bgneal@442: rng.insertNode(node); bgneal@442: nodeRect = dom.getRect(node); bgneal@442: viewPortRect = dom.getViewPort(editor.getWin()); bgneal@442: bgneal@442: // Check if node is out side the viewport if it is then scroll to it bgneal@442: if ((nodeRect.y > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) || bgneal@442: (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) { bgneal@442: editor.getBody().scrollLeft = nodeRect.x; bgneal@442: editor.getBody().scrollTop = nodeRect.y; bgneal@442: } bgneal@442: bgneal@442: dom.remove(node); bgneal@442: } bgneal@442: bgneal@442: // Make sure that the selection is collapsed after we removed the node fixes a WebKit bug bgneal@442: // where WebKit would place the endContainer/endOffset at a different location than the startContainer/startOffset bgneal@442: selection.collapse(true); bgneal@442: } bgneal@442: } bgneal@442: bgneal@442: selection.onSetContent.dispatch(selection, args); bgneal@442: editor.addVisual(); bgneal@312: }, bgneal@312: bgneal@312: mceInsertRawHTML : function(command, ui, value) { bgneal@312: selection.setContent('tiny_mce_marker'); bgneal@312: editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value })); bgneal@312: }, bgneal@312: bgneal@312: mceSetContent : function(command, ui, value) { bgneal@312: editor.setContent(value); bgneal@312: }, bgneal@312: bgneal@312: 'Indent,Outdent' : function(command) { bgneal@312: var intentValue, indentUnit, value; bgneal@312: bgneal@312: // Setup indent level bgneal@312: intentValue = settings.indentation; bgneal@312: indentUnit = /[a-z%]+$/i.exec(intentValue); bgneal@312: intentValue = parseInt(intentValue); bgneal@312: bgneal@312: if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) { bgneal@312: each(selection.getSelectedBlocks(), function(element) { bgneal@312: if (command == 'outdent') { bgneal@312: value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue); bgneal@312: dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : ''); bgneal@312: } else bgneal@312: dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit); bgneal@312: }); bgneal@312: } else bgneal@312: execNativeCommand(command); bgneal@312: }, bgneal@312: bgneal@312: mceRepaint : function() { bgneal@312: var bookmark; bgneal@312: bgneal@312: if (tinymce.isGecko) { bgneal@312: try { bgneal@312: storeSelection(TRUE); bgneal@312: bgneal@312: if (selection.getSel()) bgneal@312: selection.getSel().selectAllChildren(editor.getBody()); bgneal@312: bgneal@312: selection.collapse(TRUE); bgneal@312: restoreSelection(); bgneal@312: } catch (ex) { bgneal@312: // Ignore bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: mceToggleFormat : function(command, ui, value) { bgneal@312: editor.formatter.toggle(value); bgneal@312: }, bgneal@312: bgneal@312: InsertHorizontalRule : function() { bgneal@442: editor.execCommand('mceInsertContent', false, '
    '); bgneal@312: }, bgneal@312: bgneal@312: mceToggleVisualAid : function() { bgneal@312: editor.hasVisual = !editor.hasVisual; bgneal@312: editor.addVisual(); bgneal@312: }, bgneal@312: bgneal@312: mceReplaceContent : function(command, ui, value) { bgneal@442: editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'}))); bgneal@312: }, bgneal@312: bgneal@312: mceInsertLink : function(command, ui, value) { bgneal@442: var link = dom.getParent(selection.getNode(), 'a'), img, floatVal; bgneal@312: bgneal@312: if (tinymce.is(value, 'string')) bgneal@312: value = {href : value}; bgneal@312: bgneal@442: // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here. bgneal@442: value.href = value.href.replace(' ', '%20'); bgneal@442: bgneal@312: if (!link) { bgneal@442: // WebKit can't create links on float images for some odd reason so just remove it and restore it later bgneal@442: if (tinymce.isWebKit) { bgneal@442: img = dom.getParent(selection.getNode(), 'img'); bgneal@442: bgneal@442: if (img) { bgneal@442: floatVal = img.style.cssFloat; bgneal@442: img.style.cssFloat = null; bgneal@442: } bgneal@442: } bgneal@442: bgneal@312: execNativeCommand('CreateLink', FALSE, 'javascript:mctmp(0);'); bgneal@442: bgneal@442: // Restore float value bgneal@442: if (floatVal) bgneal@442: img.style.cssFloat = floatVal; bgneal@442: bgneal@442: each(dom.select("a[href='javascript:mctmp(0);']"), function(link) { bgneal@312: dom.setAttribs(link, value); bgneal@312: }); bgneal@312: } else { bgneal@312: if (value.href) bgneal@312: dom.setAttribs(link, value); bgneal@312: else bgneal@312: editor.dom.remove(link, TRUE); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: selectAll : function() { bgneal@312: var root = dom.getRoot(), rng = dom.createRng(); bgneal@312: bgneal@312: rng.setStart(root, 0); bgneal@312: rng.setEnd(root, root.childNodes.length); bgneal@312: bgneal@312: editor.selection.setRng(rng); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // Add queryCommandState overrides bgneal@312: addCommands({ bgneal@312: // Override justify commands bgneal@312: 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) { bgneal@312: return isFormatMatch('align' + command.substring(7)); bgneal@312: }, bgneal@312: bgneal@442: 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) { bgneal@312: return isFormatMatch(command); bgneal@312: }, bgneal@312: bgneal@312: mceBlockQuote : function() { bgneal@312: return isFormatMatch('blockquote'); bgneal@312: }, bgneal@312: bgneal@312: Outdent : function() { bgneal@312: var node; bgneal@312: bgneal@312: if (settings.inline_styles) { bgneal@312: if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0) bgneal@312: return TRUE; bgneal@312: bgneal@312: if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0) bgneal@312: return TRUE; bgneal@312: } bgneal@312: bgneal@312: return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE')); bgneal@312: }, bgneal@312: bgneal@312: 'InsertUnorderedList,InsertOrderedList' : function(command) { bgneal@312: return dom.getParent(selection.getNode(), command == 'insertunorderedlist' ? 'UL' : 'OL'); bgneal@312: } bgneal@312: }, 'state'); bgneal@312: bgneal@312: // Add queryCommandValue overrides bgneal@312: addCommands({ bgneal@312: 'FontSize,FontName' : function(command) { bgneal@312: var value = 0, parent; bgneal@312: bgneal@312: if (parent = dom.getParent(selection.getNode(), 'span')) { bgneal@312: if (command == 'fontsize') bgneal@312: value = parent.style.fontSize; bgneal@312: else bgneal@312: value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase(); bgneal@312: } bgneal@312: bgneal@312: return value; bgneal@312: } bgneal@312: }, 'value'); bgneal@312: bgneal@312: // Add undo manager logic bgneal@312: if (settings.custom_undo_redo) { bgneal@312: addCommands({ bgneal@312: Undo : function() { bgneal@312: editor.undoManager.undo(); bgneal@312: }, bgneal@312: bgneal@312: Redo : function() { bgneal@312: editor.undoManager.redo(); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: }; bgneal@312: })(tinymce); bgneal@442: bgneal@312: (function(tinymce) { bgneal@312: var Dispatcher = tinymce.util.Dispatcher; bgneal@312: bgneal@312: tinymce.UndoManager = function(editor) { bgneal@312: var self, index = 0, data = []; bgneal@312: bgneal@312: function getContent() { bgneal@312: return tinymce.trim(editor.getContent({format : 'raw', no_events : 1})); bgneal@312: }; bgneal@312: bgneal@312: return self = { bgneal@442: typing : false, bgneal@312: bgneal@312: onAdd : new Dispatcher(self), bgneal@442: bgneal@312: onUndo : new Dispatcher(self), bgneal@442: bgneal@312: onRedo : new Dispatcher(self), bgneal@312: bgneal@442: beforeChange : function() { bgneal@442: // Set before bookmark on previous level bgneal@442: if (data[index]) bgneal@442: data[index].beforeBookmark = editor.selection.getBookmark(2, true); bgneal@442: }, bgneal@442: bgneal@312: add : function(level) { bgneal@312: var i, settings = editor.settings, lastLevel; bgneal@312: bgneal@312: level = level || {}; bgneal@312: level.content = getContent(); bgneal@312: bgneal@312: // Add undo level if needed bgneal@312: lastLevel = data[index]; bgneal@442: if (lastLevel && lastLevel.content == level.content) bgneal@442: return null; bgneal@312: bgneal@312: // Time to compress bgneal@312: if (settings.custom_undo_redo_levels) { bgneal@312: if (data.length > settings.custom_undo_redo_levels) { bgneal@312: for (i = 0; i < data.length - 1; i++) bgneal@312: data[i] = data[i + 1]; bgneal@312: bgneal@312: data.length--; bgneal@312: index = data.length; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Get a non intrusive normalized bookmark bgneal@312: level.bookmark = editor.selection.getBookmark(2, true); bgneal@312: bgneal@312: // Crop array if needed bgneal@442: if (index < data.length - 1) bgneal@442: data.length = index + 1; bgneal@312: bgneal@312: data.push(level); bgneal@312: index = data.length - 1; bgneal@312: bgneal@312: self.onAdd.dispatch(self, level); bgneal@312: editor.isNotDirty = 0; bgneal@312: bgneal@312: return level; bgneal@312: }, bgneal@312: bgneal@312: undo : function() { bgneal@312: var level, i; bgneal@312: bgneal@312: if (self.typing) { bgneal@312: self.add(); bgneal@442: self.typing = false; bgneal@312: } bgneal@312: bgneal@312: if (index > 0) { bgneal@312: level = data[--index]; bgneal@312: bgneal@312: editor.setContent(level.content, {format : 'raw'}); bgneal@442: editor.selection.moveToBookmark(level.beforeBookmark); bgneal@312: bgneal@312: self.onUndo.dispatch(self, level); bgneal@312: } bgneal@312: bgneal@312: return level; bgneal@312: }, bgneal@312: bgneal@312: redo : function() { bgneal@312: var level; bgneal@312: bgneal@312: if (index < data.length - 1) { bgneal@312: level = data[++index]; bgneal@312: bgneal@312: editor.setContent(level.content, {format : 'raw'}); bgneal@312: editor.selection.moveToBookmark(level.bookmark); bgneal@312: bgneal@312: self.onRedo.dispatch(self, level); bgneal@312: } bgneal@312: bgneal@312: return level; bgneal@312: }, bgneal@312: bgneal@312: clear : function() { bgneal@312: data = []; bgneal@442: index = 0; bgneal@442: self.typing = false; bgneal@312: }, bgneal@312: bgneal@312: hasUndo : function() { bgneal@442: return index > 0 || this.typing; bgneal@312: }, bgneal@312: bgneal@312: hasRedo : function() { bgneal@442: return index < data.length - 1 && !this.typing; bgneal@312: } bgneal@312: }; bgneal@312: }; bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: // Shorten names bgneal@312: var Event = tinymce.dom.Event, bgneal@312: isIE = tinymce.isIE, bgneal@312: isGecko = tinymce.isGecko, bgneal@312: isOpera = tinymce.isOpera, bgneal@312: each = tinymce.each, bgneal@312: extend = tinymce.extend, bgneal@312: TRUE = true, bgneal@312: FALSE = false; bgneal@312: bgneal@312: function cloneFormats(node) { bgneal@312: var clone, temp, inner; bgneal@312: bgneal@312: do { bgneal@312: if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) { bgneal@312: if (clone) { bgneal@312: temp = node.cloneNode(false); bgneal@312: temp.appendChild(clone); bgneal@312: clone = temp; bgneal@312: } else { bgneal@312: clone = inner = node.cloneNode(false); bgneal@312: } bgneal@312: bgneal@312: clone.removeAttribute('id'); bgneal@312: } bgneal@312: } while (node = node.parentNode); bgneal@312: bgneal@312: if (clone) bgneal@312: return {wrapper : clone, inner : inner}; bgneal@312: }; bgneal@312: bgneal@312: // Checks if the selection/caret is at the end of the specified block element bgneal@312: function isAtEnd(rng, par) { bgneal@312: var rng2 = par.ownerDocument.createRange(); bgneal@312: bgneal@312: rng2.setStart(rng.endContainer, rng.endOffset); bgneal@312: rng2.setEndAfter(par); bgneal@312: bgneal@312: // 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 bgneal@312: return rng2.cloneContents().textContent.length == 0; bgneal@312: }; bgneal@312: bgneal@312: function splitList(selection, dom, li) { bgneal@312: var listBlock, block; bgneal@312: bgneal@442: if (dom.isEmpty(li)) { bgneal@312: listBlock = dom.getParent(li, 'ul,ol'); bgneal@312: bgneal@312: if (!dom.getParent(listBlock.parentNode, 'ul,ol')) { bgneal@312: dom.split(listBlock, li); bgneal@442: block = dom.create('p', 0, '
    '); bgneal@312: dom.replace(block, li); bgneal@312: selection.select(block, 1); bgneal@312: } bgneal@312: bgneal@312: return FALSE; bgneal@312: } bgneal@312: bgneal@312: return TRUE; bgneal@312: }; bgneal@312: bgneal@312: tinymce.create('tinymce.ForceBlocks', { bgneal@312: ForceBlocks : function(ed) { bgneal@312: var t = this, s = ed.settings, elm; bgneal@312: bgneal@312: t.editor = ed; bgneal@312: t.dom = ed.dom; bgneal@312: elm = (s.forced_root_block || 'p').toLowerCase(); bgneal@312: s.element = elm.toUpperCase(); bgneal@312: bgneal@312: ed.onPreInit.add(t.setup, t); bgneal@312: bgneal@312: if (s.forced_root_block) { bgneal@312: ed.onInit.add(t.forceRoots, t); bgneal@312: ed.onSetContent.add(t.forceRoots, t); bgneal@312: ed.onBeforeGetContent.add(t.forceRoots, t); bgneal@442: ed.onExecCommand.add(function(ed, cmd) { bgneal@442: if (cmd == 'mceInsertContent') { bgneal@442: t.forceRoots(); bgneal@442: ed.nodeChanged(); bgneal@442: } bgneal@442: }); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: setup : function() { bgneal@312: var t = this, ed = t.editor, s = ed.settings, dom = ed.dom, selection = ed.selection; bgneal@312: bgneal@312: // Force root blocks when typing and when getting output bgneal@312: if (s.forced_root_block) { bgneal@312: ed.onBeforeExecCommand.add(t.forceRoots, t); bgneal@312: ed.onKeyUp.add(t.forceRoots, t); bgneal@312: ed.onPreProcess.add(t.forceRoots, t); bgneal@312: } bgneal@312: bgneal@312: if (s.force_br_newlines) { bgneal@312: // Force IE to produce BRs on enter bgneal@312: if (isIE) { bgneal@312: ed.onKeyPress.add(function(ed, e) { bgneal@312: var n; bgneal@312: bgneal@312: if (e.keyCode == 13 && selection.getNode().nodeName != 'LI') { bgneal@312: selection.setContent('
    ', {format : 'raw'}); bgneal@312: n = dom.get('__'); bgneal@312: n.removeAttribute('id'); bgneal@312: selection.select(n); bgneal@312: selection.collapse(); bgneal@312: return Event.cancel(e); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if (s.force_p_newlines) { bgneal@312: if (!isIE) { bgneal@312: ed.onKeyPress.add(function(ed, e) { bgneal@312: if (e.keyCode == 13 && !e.shiftKey && !t.insertPara(e)) bgneal@312: Event.cancel(e); bgneal@312: }); bgneal@312: } else { bgneal@312: // Ungly hack to for IE to preserve the formatting when you press bgneal@312: // enter at the end of a block element with formatted contents bgneal@312: // This logic overrides the browsers default logic with bgneal@312: // custom logic that enables us to control the output bgneal@312: tinymce.addUnload(function() { bgneal@312: t._previousFormats = 0; // Fix IE leak bgneal@312: }); bgneal@312: bgneal@312: ed.onKeyPress.add(function(ed, e) { bgneal@312: t._previousFormats = 0; bgneal@312: bgneal@312: // Clone the current formats, this will later be applied to the new block contents bgneal@312: if (e.keyCode == 13 && !e.shiftKey && ed.selection.isCollapsed() && s.keep_styles) bgneal@312: t._previousFormats = cloneFormats(ed.selection.getStart()); bgneal@312: }); bgneal@312: bgneal@312: ed.onKeyUp.add(function(ed, e) { bgneal@312: // Let IE break the element and the wrap the new caret location in the previous formats bgneal@312: if (e.keyCode == 13 && !e.shiftKey) { bgneal@312: var parent = ed.selection.getStart(), fmt = t._previousFormats; bgneal@312: bgneal@312: // Parent is an empty block bgneal@312: if (!parent.hasChildNodes() && fmt) { bgneal@312: parent = dom.getParent(parent, dom.isBlock); bgneal@312: bgneal@312: if (parent && parent.nodeName != 'LI') { bgneal@312: parent.innerHTML = ''; bgneal@312: bgneal@312: if (t._previousFormats) { bgneal@312: parent.appendChild(fmt.wrapper); bgneal@312: fmt.inner.innerHTML = '\uFEFF'; bgneal@312: } else bgneal@312: parent.innerHTML = '\uFEFF'; bgneal@312: bgneal@312: selection.select(parent, 1); bgneal@442: selection.collapse(true); bgneal@312: ed.getDoc().execCommand('Delete', false, null); bgneal@312: t._previousFormats = 0; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (isGecko) { bgneal@312: ed.onKeyDown.add(function(ed, e) { bgneal@312: if ((e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) bgneal@312: t.backspaceDelete(e, e.keyCode == 8); bgneal@312: }); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Workaround for missing shift+enter support, http://bugs.webkit.org/show_bug.cgi?id=16973 bgneal@312: if (tinymce.isWebKit) { bgneal@312: function insertBr(ed) { bgneal@312: var rng = selection.getRng(), br, div = dom.create('div', null, ' '), divYPos, vpHeight = dom.getViewPort(ed.getWin()).h; bgneal@312: bgneal@312: // Insert BR element bgneal@312: rng.insertNode(br = dom.create('br')); bgneal@312: bgneal@312: // Place caret after BR bgneal@312: rng.setStartAfter(br); bgneal@312: rng.setEndAfter(br); bgneal@312: selection.setRng(rng); bgneal@312: bgneal@312: // Could not place caret after BR then insert an nbsp entity and move the caret bgneal@312: if (selection.getSel().focusNode == br.previousSibling) { bgneal@312: selection.select(dom.insertAfter(dom.doc.createTextNode('\u00a0'), br)); bgneal@312: selection.collapse(TRUE); bgneal@312: } bgneal@312: bgneal@312: // Create a temporary DIV after the BR and get the position as it bgneal@312: // seems like getPos() returns 0 for text nodes and BR elements. bgneal@312: dom.insertAfter(div, br); bgneal@312: divYPos = dom.getPos(div).y; bgneal@312: dom.remove(div); bgneal@312: bgneal@312: // Scroll to new position, scrollIntoView can't be used due to bug: http://bugs.webkit.org/show_bug.cgi?id=16117 bgneal@312: if (divYPos > vpHeight) // It is not necessary to scroll if the DIV is inside the view port. bgneal@312: ed.getWin().scrollTo(0, divYPos); bgneal@312: }; bgneal@312: bgneal@312: ed.onKeyPress.add(function(ed, e) { bgneal@312: if (e.keyCode == 13 && (e.shiftKey || (s.force_br_newlines && !dom.getParent(selection.getNode(), 'h1,h2,h3,h4,h5,h6,ol,ul')))) { bgneal@312: insertBr(ed); bgneal@312: Event.cancel(e); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: // IE specific fixes bgneal@312: if (isIE) { bgneal@312: // Replaces IE:s auto generated paragraphs with the specified element name bgneal@312: if (s.element != 'P') { bgneal@312: ed.onKeyPress.add(function(ed, e) { bgneal@312: t.lastElm = selection.getNode().nodeName; bgneal@312: }); bgneal@312: bgneal@312: ed.onKeyUp.add(function(ed, e) { bgneal@312: var bl, n = selection.getNode(), b = ed.getBody(); bgneal@312: bgneal@312: if (b.childNodes.length === 1 && n.nodeName == 'P') { bgneal@312: n = dom.rename(n, s.element); bgneal@312: selection.select(n); bgneal@312: selection.collapse(); bgneal@312: ed.nodeChanged(); bgneal@312: } else if (e.keyCode == 13 && !e.shiftKey && t.lastElm != 'P') { bgneal@312: bl = dom.getParent(n, 'p'); bgneal@312: bgneal@312: if (bl) { bgneal@312: dom.rename(bl, s.element); bgneal@312: ed.nodeChanged(); bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: find : function(n, t, s) { bgneal@312: var ed = this.editor, w = ed.getDoc().createTreeWalker(n, 4, null, FALSE), c = -1; bgneal@312: bgneal@312: while (n = w.nextNode()) { bgneal@312: c++; bgneal@312: bgneal@312: // Index by node bgneal@312: if (t == 0 && n == s) bgneal@312: return c; bgneal@312: bgneal@312: // Node by index bgneal@312: if (t == 1 && c == s) bgneal@312: return n; bgneal@312: } bgneal@312: bgneal@312: return -1; bgneal@312: }, bgneal@312: bgneal@312: forceRoots : function(ed, e) { bgneal@312: var t = this, ed = t.editor, b = ed.getBody(), d = ed.getDoc(), se = ed.selection, s = se.getSel(), r = se.getRng(), si = -2, ei, so, eo, tr, c = -0xFFFFFF; bgneal@312: var nx, bl, bp, sp, le, nl = b.childNodes, i, n, eid; bgneal@312: bgneal@312: // Fix for bug #1863847 bgneal@312: //if (e && e.keyCode == 13) bgneal@312: // return TRUE; bgneal@312: bgneal@312: // Wrap non blocks into blocks bgneal@312: for (i = nl.length - 1; i >= 0; i--) { bgneal@312: nx = nl[i]; bgneal@312: bgneal@312: // Ignore internal elements bgneal@442: if (nx.nodeType === 1 && nx.getAttribute('data-mce-type')) { bgneal@312: bl = null; bgneal@312: continue; bgneal@312: } bgneal@312: bgneal@312: // Is text or non block element bgneal@312: if (nx.nodeType === 3 || (!t.dom.isBlock(nx) && nx.nodeType !== 8 && !/^(script|mce:script|style|mce:style)$/i.test(nx.nodeName))) { bgneal@312: if (!bl) { bgneal@312: // Create new block but ignore whitespace bgneal@312: if (nx.nodeType != 3 || /[^\s]/g.test(nx.nodeValue)) { bgneal@312: // Store selection bgneal@312: if (si == -2 && r) { bgneal@442: if (!isIE || r.setStart) { bgneal@312: // If selection is element then mark it bgneal@312: if (r.startContainer.nodeType == 1 && (n = r.startContainer.childNodes[r.startOffset]) && n.nodeType == 1) { bgneal@312: // Save the id of the selected element bgneal@312: eid = n.getAttribute("id"); bgneal@312: n.setAttribute("id", "__mce"); bgneal@312: } else { bgneal@312: // If element is inside body, might not be the case in contentEdiable mode bgneal@312: if (ed.dom.getParent(r.startContainer, function(e) {return e === b;})) { bgneal@312: so = r.startOffset; bgneal@312: eo = r.endOffset; bgneal@312: si = t.find(b, 0, r.startContainer); bgneal@312: ei = t.find(b, 0, r.endContainer); bgneal@312: } bgneal@312: } bgneal@312: } else { bgneal@312: // Force control range into text range bgneal@312: if (r.item) { bgneal@312: tr = d.body.createTextRange(); bgneal@312: tr.moveToElementText(r.item(0)); bgneal@312: r = tr; bgneal@312: } bgneal@312: bgneal@312: tr = d.body.createTextRange(); bgneal@312: tr.moveToElementText(b); bgneal@312: tr.collapse(1); bgneal@312: bp = tr.move('character', c) * -1; bgneal@312: bgneal@312: tr = r.duplicate(); bgneal@312: tr.collapse(1); bgneal@312: sp = tr.move('character', c) * -1; bgneal@312: bgneal@312: tr = r.duplicate(); bgneal@312: tr.collapse(0); bgneal@312: le = (tr.move('character', c) * -1) - sp; bgneal@312: bgneal@312: si = sp - bp; bgneal@312: ei = le; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Uses replaceChild instead of cloneNode since it removes selected attribute from option elements on IE bgneal@312: // See: http://support.microsoft.com/kb/829907 bgneal@312: bl = ed.dom.create(ed.settings.forced_root_block); bgneal@312: nx.parentNode.replaceChild(bl, nx); bgneal@312: bl.appendChild(nx); bgneal@312: } bgneal@312: } else { bgneal@312: if (bl.hasChildNodes()) bgneal@312: bl.insertBefore(nx, bl.firstChild); bgneal@312: else bgneal@312: bl.appendChild(nx); bgneal@312: } bgneal@312: } else bgneal@312: bl = null; // Time to create new block bgneal@312: } bgneal@312: bgneal@312: // Restore selection bgneal@312: if (si != -2) { bgneal@442: if (!isIE || r.setStart) { bgneal@312: bl = b.getElementsByTagName(ed.settings.element)[0]; bgneal@312: r = d.createRange(); bgneal@312: bgneal@312: // Select last location or generated block bgneal@312: if (si != -1) bgneal@312: r.setStart(t.find(b, 1, si), so); bgneal@312: else bgneal@312: r.setStart(bl, 0); bgneal@312: bgneal@312: // Select last location or generated block bgneal@312: if (ei != -1) bgneal@312: r.setEnd(t.find(b, 1, ei), eo); bgneal@312: else bgneal@312: r.setEnd(bl, 0); bgneal@312: bgneal@312: if (s) { bgneal@312: s.removeAllRanges(); bgneal@312: s.addRange(r); bgneal@312: } bgneal@312: } else { bgneal@312: try { bgneal@312: r = s.createRange(); bgneal@312: r.moveToElementText(b); bgneal@312: r.collapse(1); bgneal@312: r.moveStart('character', si); bgneal@312: r.moveEnd('character', ei); bgneal@312: r.select(); bgneal@312: } catch (ex) { bgneal@312: // Ignore bgneal@312: } bgneal@312: } bgneal@442: } else if ((!isIE || r.setStart) && (n = ed.dom.get('__mce'))) { bgneal@312: // Restore the id of the selected element bgneal@312: if (eid) bgneal@312: n.setAttribute('id', eid); bgneal@312: else bgneal@312: n.removeAttribute('id'); bgneal@312: bgneal@312: // Move caret before selected element bgneal@312: r = d.createRange(); bgneal@312: r.setStartBefore(n); bgneal@312: r.setEndBefore(n); bgneal@312: se.setRng(r); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: getParentBlock : function(n) { bgneal@312: var d = this.dom; bgneal@312: bgneal@312: return d.getParent(n, d.isBlock); bgneal@312: }, bgneal@312: bgneal@312: insertPara : function(e) { bgneal@312: 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; bgneal@312: var rb, ra, dir, sn, so, en, eo, sb, eb, bn, bef, aft, sc, ec, n, vp = dom.getViewPort(ed.getWin()), y, ch, car; bgneal@312: bgneal@442: ed.undoManager.beforeChange(); bgneal@442: bgneal@312: // If root blocks are forced then use Operas default behavior since it's really good bgneal@312: // Removed due to bug: #1853816 bgneal@312: // if (se.forced_root_block && isOpera) bgneal@312: // return TRUE; bgneal@312: bgneal@312: // Setup before range bgneal@312: rb = d.createRange(); bgneal@312: bgneal@312: // If is before the first block element and in body, then move it into first block element bgneal@312: rb.setStart(s.anchorNode, s.anchorOffset); bgneal@312: rb.collapse(TRUE); bgneal@312: bgneal@312: // Setup after range bgneal@312: ra = d.createRange(); bgneal@312: bgneal@312: // If is before the first block element and in body, then move it into first block element bgneal@312: ra.setStart(s.focusNode, s.focusOffset); bgneal@312: ra.collapse(TRUE); bgneal@312: bgneal@312: // Setup start/end points bgneal@312: dir = rb.compareBoundaryPoints(rb.START_TO_END, ra) < 0; bgneal@312: sn = dir ? s.anchorNode : s.focusNode; bgneal@312: so = dir ? s.anchorOffset : s.focusOffset; bgneal@312: en = dir ? s.focusNode : s.anchorNode; bgneal@312: eo = dir ? s.focusOffset : s.anchorOffset; bgneal@312: bgneal@312: // If selection is in empty table cell bgneal@312: if (sn === en && /^(TD|TH)$/.test(sn.nodeName)) { bgneal@312: if (sn.firstChild.nodeName == 'BR') bgneal@312: dom.remove(sn.firstChild); // Remove BR bgneal@312: bgneal@312: // Create two new block elements bgneal@312: if (sn.childNodes.length == 0) { bgneal@312: ed.dom.add(sn, se.element, null, '
    '); bgneal@312: aft = ed.dom.add(sn, se.element, null, '
    '); bgneal@312: } else { bgneal@312: n = sn.innerHTML; bgneal@312: sn.innerHTML = ''; bgneal@312: ed.dom.add(sn, se.element, null, n); bgneal@312: aft = ed.dom.add(sn, se.element, null, '
    '); bgneal@312: } bgneal@312: bgneal@312: // Move caret into the last one bgneal@312: r = d.createRange(); bgneal@312: r.selectNodeContents(aft); bgneal@312: r.collapse(1); bgneal@312: ed.selection.setRng(r); bgneal@312: bgneal@312: return FALSE; bgneal@312: } bgneal@312: bgneal@312: // If the caret is in an invalid location in FF we need to move it into the first block bgneal@312: if (sn == b && en == b && b.firstChild && ed.dom.isBlock(b.firstChild)) { bgneal@312: sn = en = sn.firstChild; bgneal@312: so = eo = 0; bgneal@312: rb = d.createRange(); bgneal@312: rb.setStart(sn, 0); bgneal@312: ra = d.createRange(); bgneal@312: ra.setStart(en, 0); bgneal@312: } bgneal@312: bgneal@312: // Never use body as start or end node bgneal@312: sn = sn.nodeName == "HTML" ? d.body : sn; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes bgneal@312: sn = sn.nodeName == "BODY" ? sn.firstChild : sn; bgneal@312: en = en.nodeName == "HTML" ? d.body : en; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes bgneal@312: en = en.nodeName == "BODY" ? en.firstChild : en; bgneal@312: bgneal@312: // Get start and end blocks bgneal@312: sb = t.getParentBlock(sn); bgneal@312: eb = t.getParentBlock(en); bgneal@312: bn = sb ? sb.nodeName : se.element; // Get block name to create bgneal@312: bgneal@312: // Return inside list use default browser behavior bgneal@312: if (n = t.dom.getParent(sb, 'li,pre')) { bgneal@312: if (n.nodeName == 'LI') bgneal@312: return splitList(ed.selection, t.dom, n); bgneal@312: bgneal@312: return TRUE; bgneal@312: } bgneal@312: bgneal@312: // If caption or absolute layers then always generate new blocks within bgneal@312: if (sb && (sb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) { bgneal@312: bn = se.element; bgneal@312: sb = null; bgneal@312: } bgneal@312: bgneal@312: // If caption or absolute layers then always generate new blocks within bgneal@312: if (eb && (eb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) { bgneal@312: bn = se.element; bgneal@312: eb = null; bgneal@312: } bgneal@312: bgneal@312: // Use P instead bgneal@312: if (/(TD|TABLE|TH|CAPTION)/.test(bn) || (sb && bn == "DIV" && /left|right/gi.test(dom.getStyle(sb, 'float', 1)))) { bgneal@312: bn = se.element; bgneal@312: sb = eb = null; bgneal@312: } bgneal@312: bgneal@312: // Setup new before and after blocks bgneal@312: bef = (sb && sb.nodeName == bn) ? sb.cloneNode(0) : ed.dom.create(bn); bgneal@312: aft = (eb && eb.nodeName == bn) ? eb.cloneNode(0) : ed.dom.create(bn); bgneal@312: bgneal@312: // Remove id from after clone bgneal@312: aft.removeAttribute('id'); bgneal@312: bgneal@312: // Is header and cursor is at the end, then force paragraph under bgneal@312: if (/^(H[1-6])$/.test(bn) && isAtEnd(r, sb)) bgneal@312: aft = ed.dom.create(se.element); bgneal@312: bgneal@312: // Find start chop node bgneal@312: n = sc = sn; bgneal@312: do { bgneal@312: if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName)) bgneal@312: break; bgneal@312: bgneal@312: sc = n; bgneal@312: } while ((n = n.previousSibling ? n.previousSibling : n.parentNode)); bgneal@312: bgneal@312: // Find end chop node bgneal@312: n = ec = en; bgneal@312: do { bgneal@312: if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName)) bgneal@312: break; bgneal@312: bgneal@312: ec = n; bgneal@312: } while ((n = n.nextSibling ? n.nextSibling : n.parentNode)); bgneal@312: bgneal@312: // Place first chop part into before block element bgneal@312: if (sc.nodeName == bn) bgneal@312: rb.setStart(sc, 0); bgneal@312: else bgneal@312: rb.setStartBefore(sc); bgneal@312: bgneal@312: rb.setEnd(sn, so); bgneal@312: bef.appendChild(rb.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari bgneal@312: bgneal@312: // Place secnd chop part within new block element bgneal@312: try { bgneal@312: ra.setEndAfter(ec); bgneal@312: } catch(ex) { bgneal@312: //console.debug(s.focusNode, s.focusOffset); bgneal@312: } bgneal@312: bgneal@312: ra.setStart(en, eo); bgneal@312: aft.appendChild(ra.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari bgneal@312: bgneal@312: // Create range around everything bgneal@312: r = d.createRange(); bgneal@312: if (!sc.previousSibling && sc.parentNode.nodeName == bn) { bgneal@312: r.setStartBefore(sc.parentNode); bgneal@312: } else { bgneal@312: if (rb.startContainer.nodeName == bn && rb.startOffset == 0) bgneal@312: r.setStartBefore(rb.startContainer); bgneal@312: else bgneal@312: r.setStart(rb.startContainer, rb.startOffset); bgneal@312: } bgneal@312: bgneal@312: if (!ec.nextSibling && ec.parentNode.nodeName == bn) bgneal@312: r.setEndAfter(ec.parentNode); bgneal@312: else bgneal@312: r.setEnd(ra.endContainer, ra.endOffset); bgneal@312: bgneal@312: // Delete and replace it with new block elements bgneal@312: r.deleteContents(); bgneal@312: bgneal@312: if (isOpera) bgneal@312: ed.getWin().scrollTo(0, vp.y); bgneal@312: bgneal@312: // Never wrap blocks in blocks bgneal@312: if (bef.firstChild && bef.firstChild.nodeName == bn) bgneal@312: bef.innerHTML = bef.firstChild.innerHTML; bgneal@312: bgneal@312: if (aft.firstChild && aft.firstChild.nodeName == bn) bgneal@312: aft.innerHTML = aft.firstChild.innerHTML; bgneal@312: bgneal@312: // Padd empty blocks bgneal@442: if (dom.isEmpty(bef)) bgneal@312: bef.innerHTML = '
    '; bgneal@312: bgneal@312: function appendStyles(e, en) { bgneal@312: var nl = [], nn, n, i; bgneal@312: bgneal@312: e.innerHTML = ''; bgneal@312: bgneal@312: // Make clones of style elements bgneal@312: if (se.keep_styles) { bgneal@312: n = en; bgneal@312: do { bgneal@312: // We only want style specific elements bgneal@312: if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(n.nodeName)) { bgneal@312: nn = n.cloneNode(FALSE); bgneal@312: dom.setAttrib(nn, 'id', ''); // Remove ID since it needs to be unique bgneal@312: nl.push(nn); bgneal@312: } bgneal@312: } while (n = n.parentNode); bgneal@312: } bgneal@312: bgneal@312: // Append style elements to aft bgneal@312: if (nl.length > 0) { bgneal@312: for (i = nl.length - 1, nn = e; i >= 0; i--) bgneal@312: nn = nn.appendChild(nl[i]); bgneal@312: bgneal@312: // Padd most inner style element bgneal@442: nl[0].innerHTML = isOpera ? '\u00a0' : '
    '; // Extra space for Opera so that the caret can move there bgneal@312: return nl[0]; // Move caret to most inner element bgneal@312: } else bgneal@442: e.innerHTML = isOpera ? '\u00a0' : '
    '; // Extra space for Opera so that the caret can move there bgneal@312: }; bgneal@312: bgneal@312: // Fill empty afterblook with current style bgneal@442: if (dom.isEmpty(aft)) bgneal@312: car = appendStyles(aft, en); bgneal@312: bgneal@312: // Opera needs this one backwards for older versions bgneal@312: if (isOpera && parseFloat(opera.version()) < 9.5) { bgneal@312: r.insertNode(bef); bgneal@312: r.insertNode(aft); bgneal@312: } else { bgneal@312: r.insertNode(aft); bgneal@312: r.insertNode(bef); bgneal@312: } bgneal@312: bgneal@312: // Normalize bgneal@312: aft.normalize(); bgneal@312: bef.normalize(); bgneal@312: bgneal@312: function first(n) { bgneal@312: return d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, FALSE).nextNode() || n; bgneal@312: }; bgneal@312: bgneal@312: // Move cursor and scroll into view bgneal@312: r = d.createRange(); bgneal@312: r.selectNodeContents(isGecko ? first(car || aft) : car || aft); bgneal@312: r.collapse(1); bgneal@312: s.removeAllRanges(); bgneal@312: s.addRange(r); bgneal@312: bgneal@312: // 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 bgneal@312: y = ed.dom.getPos(aft).y; bgneal@442: //ch = aft.clientHeight; bgneal@312: bgneal@312: // Is element within viewport bgneal@442: if (y < vp.y || y + 25 > vp.y + vp.h) { bgneal@312: 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 bgneal@442: bgneal@442: /*console.debug( bgneal@442: 'Element: y=' + y + ', h=' + ch + ', ' + bgneal@442: 'Viewport: y=' + vp.y + ", h=" + vp.h + ', bottom=' + (vp.y + vp.h) bgneal@442: );*/ bgneal@442: } bgneal@442: bgneal@442: ed.undoManager.add(); bgneal@312: bgneal@312: return FALSE; bgneal@312: }, bgneal@312: bgneal@312: backspaceDelete : function(e, bs) { bgneal@312: var t = this, ed = t.editor, b = ed.getBody(), dom = ed.dom, n, se = ed.selection, r = se.getRng(), sc = r.startContainer, n, w, tn, walker; bgneal@312: bgneal@312: // Delete when caret is behind a element doesn't work correctly on Gecko see #3011651 bgneal@312: if (!bs && r.collapsed && sc.nodeType == 1 && r.startOffset == sc.childNodes.length) { bgneal@312: walker = new tinymce.dom.TreeWalker(sc.lastChild, sc); bgneal@312: bgneal@312: // Walk the dom backwards until we find a text node bgneal@312: for (n = sc.lastChild; n; n = walker.prev()) { bgneal@312: if (n.nodeType == 3) { bgneal@312: r.setStart(n, n.nodeValue.length); bgneal@312: r.collapse(true); bgneal@312: se.setRng(r); bgneal@312: return; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // The caret sometimes gets stuck in Gecko if you delete empty paragraphs bgneal@312: // This workaround removes the element by hand and moves the caret to the previous element bgneal@312: if (sc && ed.dom.isBlock(sc) && !/^(TD|TH)$/.test(sc.nodeName) && bs) { bgneal@312: if (sc.childNodes.length == 0 || (sc.childNodes.length == 1 && sc.firstChild.nodeName == 'BR')) { bgneal@312: // Find previous block element bgneal@312: n = sc; bgneal@312: while ((n = n.previousSibling) && !ed.dom.isBlock(n)) ; bgneal@312: bgneal@312: if (n) { bgneal@312: if (sc != b.firstChild) { bgneal@312: // Find last text node bgneal@312: w = ed.dom.doc.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, FALSE); bgneal@312: while (tn = w.nextNode()) bgneal@312: n = tn; bgneal@312: bgneal@312: // Place caret at the end of last text node bgneal@312: r = ed.getDoc().createRange(); bgneal@312: r.setStart(n, n.nodeValue ? n.nodeValue.length : 0); bgneal@312: r.setEnd(n, n.nodeValue ? n.nodeValue.length : 0); bgneal@312: se.setRng(r); bgneal@312: bgneal@312: // Remove the target container bgneal@312: ed.dom.remove(sc); bgneal@312: } bgneal@312: bgneal@312: return Event.cancel(e); bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: // Shorten names bgneal@312: var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend; bgneal@312: bgneal@312: tinymce.create('tinymce.ControlManager', { bgneal@312: ControlManager : function(ed, s) { bgneal@312: var t = this, i; bgneal@312: bgneal@312: s = s || {}; bgneal@312: t.editor = ed; bgneal@312: t.controls = {}; bgneal@312: t.onAdd = new tinymce.util.Dispatcher(t); bgneal@312: t.onPostRender = new tinymce.util.Dispatcher(t); bgneal@312: t.prefix = s.prefix || ed.id + '_'; bgneal@312: t._cls = {}; bgneal@312: bgneal@312: t.onPostRender.add(function() { bgneal@312: each(t.controls, function(c) { bgneal@312: c.postRender(); bgneal@312: }); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: get : function(id) { bgneal@312: return this.controls[this.prefix + id] || this.controls[id]; bgneal@312: }, bgneal@312: bgneal@312: setActive : function(id, s) { bgneal@312: var c = null; bgneal@312: bgneal@312: if (c = this.get(id)) bgneal@312: c.setActive(s); bgneal@312: bgneal@312: return c; bgneal@312: }, bgneal@312: bgneal@312: setDisabled : function(id, s) { bgneal@312: var c = null; bgneal@312: bgneal@312: if (c = this.get(id)) bgneal@312: c.setDisabled(s); bgneal@312: bgneal@312: return c; bgneal@312: }, bgneal@312: bgneal@312: add : function(c) { bgneal@312: var t = this; bgneal@312: bgneal@312: if (c) { bgneal@312: t.controls[c.id] = c; bgneal@312: t.onAdd.dispatch(c, t); bgneal@312: } bgneal@312: bgneal@312: return c; bgneal@312: }, bgneal@312: bgneal@312: createControl : function(n) { bgneal@312: var c, t = this, ed = t.editor; bgneal@312: bgneal@312: each(ed.plugins, function(p) { bgneal@312: if (p.createControl) { bgneal@312: c = p.createControl(n, t); bgneal@312: bgneal@312: if (c) bgneal@312: return false; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: switch (n) { bgneal@312: case "|": bgneal@312: case "separator": bgneal@312: return t.createSeparator(); bgneal@312: } bgneal@312: bgneal@312: if (!c && ed.buttons && (c = ed.buttons[n])) bgneal@312: return t.createButton(n, c); bgneal@312: bgneal@312: return t.add(c); bgneal@312: }, bgneal@312: bgneal@312: createDropMenu : function(id, s, cc) { bgneal@312: var t = this, ed = t.editor, c, bm, v, cls; bgneal@312: bgneal@312: s = extend({ bgneal@312: 'class' : 'mceDropDown', bgneal@312: constrain : ed.settings.constrain_menus bgneal@312: }, s); bgneal@312: bgneal@312: s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin'; bgneal@312: if (v = ed.getParam('skin_variant')) bgneal@312: s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1); bgneal@312: bgneal@312: id = t.prefix + id; bgneal@312: cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu; bgneal@312: c = t.controls[id] = new cls(id, s); bgneal@312: c.onAddItem.add(function(c, o) { bgneal@312: var s = o.settings; bgneal@312: bgneal@312: s.title = ed.getLang(s.title, s.title); bgneal@312: bgneal@312: if (!s.onclick) { bgneal@312: s.onclick = function(v) { bgneal@312: if (s.cmd) bgneal@312: ed.execCommand(s.cmd, s.ui || false, s.value); bgneal@312: }; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: ed.onRemove.add(function() { bgneal@312: c.destroy(); bgneal@312: }); bgneal@312: bgneal@312: // Fix for bug #1897785, #1898007 bgneal@312: if (tinymce.isIE) { bgneal@312: c.onShowMenu.add(function() { bgneal@312: // IE 8 needs focus in order to store away a range with the current collapsed caret location bgneal@312: ed.focus(); bgneal@312: bgneal@312: bm = ed.selection.getBookmark(1); bgneal@312: }); bgneal@312: bgneal@312: c.onHideMenu.add(function() { bgneal@312: if (bm) { bgneal@312: ed.selection.moveToBookmark(bm); bgneal@312: bm = 0; bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: return t.add(c); bgneal@312: }, bgneal@312: bgneal@312: createListBox : function(id, s, cc) { bgneal@312: var t = this, ed = t.editor, cmd, c, cls; bgneal@312: bgneal@312: if (t.get(id)) bgneal@312: return null; bgneal@312: bgneal@312: s.title = ed.translate(s.title); bgneal@312: s.scope = s.scope || ed; bgneal@312: bgneal@312: if (!s.onselect) { bgneal@312: s.onselect = function(v) { bgneal@312: ed.execCommand(s.cmd, s.ui || false, v || s.value); bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: s = extend({ bgneal@312: title : s.title, bgneal@312: 'class' : 'mce_' + id, bgneal@312: scope : s.scope, bgneal@312: control_manager : t bgneal@312: }, s); bgneal@312: bgneal@312: id = t.prefix + id; bgneal@312: bgneal@312: if (ed.settings.use_native_selects) bgneal@312: c = new tinymce.ui.NativeListBox(id, s); bgneal@312: else { bgneal@312: cls = cc || t._cls.listbox || tinymce.ui.ListBox; bgneal@442: c = new cls(id, s, ed); bgneal@312: } bgneal@312: bgneal@312: t.controls[id] = c; bgneal@312: bgneal@312: // Fix focus problem in Safari bgneal@312: if (tinymce.isWebKit) { bgneal@312: c.onPostRender.add(function(c, n) { bgneal@312: // Store bookmark on mousedown bgneal@312: Event.add(n, 'mousedown', function() { bgneal@312: ed.bookmark = ed.selection.getBookmark(1); bgneal@312: }); bgneal@312: bgneal@312: // Restore on focus, since it might be lost bgneal@312: Event.add(n, 'focus', function() { bgneal@312: ed.selection.moveToBookmark(ed.bookmark); bgneal@312: ed.bookmark = null; bgneal@312: }); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (c.hideMenu) bgneal@312: ed.onMouseDown.add(c.hideMenu, c); bgneal@312: bgneal@312: return t.add(c); bgneal@312: }, bgneal@312: bgneal@312: createButton : function(id, s, cc) { bgneal@312: var t = this, ed = t.editor, o, c, cls; bgneal@312: bgneal@312: if (t.get(id)) bgneal@312: return null; bgneal@312: bgneal@312: s.title = ed.translate(s.title); bgneal@312: s.label = ed.translate(s.label); bgneal@312: s.scope = s.scope || ed; bgneal@312: bgneal@312: if (!s.onclick && !s.menu_button) { bgneal@312: s.onclick = function() { bgneal@312: ed.execCommand(s.cmd, s.ui || false, s.value); bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: s = extend({ bgneal@312: title : s.title, bgneal@312: 'class' : 'mce_' + id, bgneal@312: unavailable_prefix : ed.getLang('unavailable', ''), bgneal@312: scope : s.scope, bgneal@312: control_manager : t bgneal@312: }, s); bgneal@312: bgneal@312: id = t.prefix + id; bgneal@312: bgneal@312: if (s.menu_button) { bgneal@312: cls = cc || t._cls.menubutton || tinymce.ui.MenuButton; bgneal@442: c = new cls(id, s, ed); bgneal@312: ed.onMouseDown.add(c.hideMenu, c); bgneal@312: } else { bgneal@312: cls = t._cls.button || tinymce.ui.Button; bgneal@312: c = new cls(id, s); bgneal@312: } bgneal@312: bgneal@312: return t.add(c); bgneal@312: }, bgneal@312: bgneal@312: createMenuButton : function(id, s, cc) { bgneal@312: s = s || {}; bgneal@312: s.menu_button = 1; bgneal@312: bgneal@312: return this.createButton(id, s, cc); bgneal@312: }, bgneal@312: bgneal@312: createSplitButton : function(id, s, cc) { bgneal@312: var t = this, ed = t.editor, cmd, c, cls; bgneal@312: bgneal@312: if (t.get(id)) bgneal@312: return null; bgneal@312: bgneal@312: s.title = ed.translate(s.title); bgneal@312: s.scope = s.scope || ed; bgneal@312: bgneal@312: if (!s.onclick) { bgneal@312: s.onclick = function(v) { bgneal@312: ed.execCommand(s.cmd, s.ui || false, v || s.value); bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: if (!s.onselect) { bgneal@312: s.onselect = function(v) { bgneal@312: ed.execCommand(s.cmd, s.ui || false, v || s.value); bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: s = extend({ bgneal@312: title : s.title, bgneal@312: 'class' : 'mce_' + id, bgneal@312: scope : s.scope, bgneal@312: control_manager : t bgneal@312: }, s); bgneal@312: bgneal@312: id = t.prefix + id; bgneal@312: cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton; bgneal@442: c = t.add(new cls(id, s, ed)); bgneal@312: ed.onMouseDown.add(c.hideMenu, c); bgneal@312: bgneal@312: return c; bgneal@312: }, bgneal@312: bgneal@312: createColorSplitButton : function(id, s, cc) { bgneal@312: var t = this, ed = t.editor, cmd, c, cls, bm; bgneal@312: bgneal@312: if (t.get(id)) bgneal@312: return null; bgneal@312: bgneal@312: s.title = ed.translate(s.title); bgneal@312: s.scope = s.scope || ed; bgneal@312: bgneal@312: if (!s.onclick) { bgneal@312: s.onclick = function(v) { bgneal@312: if (tinymce.isIE) bgneal@312: bm = ed.selection.getBookmark(1); bgneal@312: bgneal@312: ed.execCommand(s.cmd, s.ui || false, v || s.value); bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: if (!s.onselect) { bgneal@312: s.onselect = function(v) { bgneal@312: ed.execCommand(s.cmd, s.ui || false, v || s.value); bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: s = extend({ bgneal@312: title : s.title, bgneal@312: 'class' : 'mce_' + id, bgneal@312: 'menu_class' : ed.getParam('skin') + 'Skin', bgneal@312: scope : s.scope, bgneal@312: more_colors_title : ed.getLang('more_colors') bgneal@312: }, s); bgneal@312: bgneal@312: id = t.prefix + id; bgneal@312: cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton; bgneal@442: c = new cls(id, s, ed); bgneal@312: ed.onMouseDown.add(c.hideMenu, c); bgneal@312: bgneal@312: // Remove the menu element when the editor is removed bgneal@312: ed.onRemove.add(function() { bgneal@312: c.destroy(); bgneal@312: }); bgneal@312: bgneal@312: // Fix for bug #1897785, #1898007 bgneal@312: if (tinymce.isIE) { bgneal@312: c.onShowMenu.add(function() { bgneal@312: // IE 8 needs focus in order to store away a range with the current collapsed caret location bgneal@312: ed.focus(); bgneal@312: bm = ed.selection.getBookmark(1); bgneal@312: }); bgneal@312: bgneal@312: c.onHideMenu.add(function() { bgneal@312: if (bm) { bgneal@312: ed.selection.moveToBookmark(bm); bgneal@312: bm = 0; bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: return t.add(c); bgneal@312: }, bgneal@312: bgneal@312: createToolbar : function(id, s, cc) { bgneal@312: var c, t = this, cls; bgneal@312: bgneal@312: id = t.prefix + id; bgneal@312: cls = cc || t._cls.toolbar || tinymce.ui.Toolbar; bgneal@442: c = new cls(id, s, t.editor); bgneal@312: bgneal@312: if (t.get(id)) bgneal@312: return null; bgneal@312: bgneal@312: return t.add(c); bgneal@312: }, bgneal@442: bgneal@442: createToolbarGroup : function(id, s, cc) { bgneal@442: var c, t = this, cls; bgneal@442: id = t.prefix + id; bgneal@442: cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup; bgneal@442: c = new cls(id, s, t.editor); bgneal@442: bgneal@442: if (t.get(id)) bgneal@442: return null; bgneal@442: bgneal@442: return t.add(c); bgneal@442: }, bgneal@312: bgneal@312: createSeparator : function(cc) { bgneal@312: var cls = cc || this._cls.separator || tinymce.ui.Separator; bgneal@312: bgneal@312: return new cls(); bgneal@312: }, bgneal@312: bgneal@312: setControlType : function(n, c) { bgneal@312: return this._cls[n.toLowerCase()] = c; bgneal@312: }, bgneal@312: bgneal@312: destroy : function() { bgneal@312: each(this.controls, function(c) { bgneal@312: c.destroy(); bgneal@312: }); bgneal@312: bgneal@312: this.controls = null; bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera; bgneal@312: bgneal@312: tinymce.create('tinymce.WindowManager', { bgneal@312: WindowManager : function(ed) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.editor = ed; bgneal@312: t.onOpen = new Dispatcher(t); bgneal@312: t.onClose = new Dispatcher(t); bgneal@312: t.params = {}; bgneal@312: t.features = {}; bgneal@312: }, bgneal@312: bgneal@312: open : function(s, p) { bgneal@312: var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u; bgneal@312: bgneal@312: // Default some options bgneal@312: s = s || {}; bgneal@312: p = p || {}; bgneal@312: sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window bgneal@312: sh = isOpera ? vp.h : screen.height; bgneal@312: s.name = s.name || 'mc_' + new Date().getTime(); bgneal@312: s.width = parseInt(s.width || 320); bgneal@312: s.height = parseInt(s.height || 240); bgneal@312: s.resizable = true; bgneal@312: s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0); bgneal@312: s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0); bgneal@312: p.inline = false; bgneal@312: p.mce_width = s.width; bgneal@312: p.mce_height = s.height; bgneal@312: p.mce_auto_focus = s.auto_focus; bgneal@312: bgneal@312: if (mo) { bgneal@312: if (isIE) { bgneal@312: s.center = true; bgneal@312: s.help = false; bgneal@312: s.dialogWidth = s.width + 'px'; bgneal@312: s.dialogHeight = s.height + 'px'; bgneal@312: s.scroll = s.scrollbars || false; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Build features string bgneal@312: each(s, function(v, k) { bgneal@312: if (tinymce.is(v, 'boolean')) bgneal@312: v = v ? 'yes' : 'no'; bgneal@312: bgneal@312: if (!/^(name|url)$/.test(k)) { bgneal@312: if (isIE && mo) bgneal@312: f += (f ? ';' : '') + k + ':' + v; bgneal@312: else bgneal@312: f += (f ? ',' : '') + k + '=' + v; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: t.features = s; bgneal@312: t.params = p; bgneal@312: t.onOpen.dispatch(t, s, p); bgneal@312: bgneal@312: u = s.url || s.file; bgneal@312: u = tinymce._addVer(u); bgneal@312: bgneal@312: try { bgneal@312: if (isIE && mo) { bgneal@312: w = 1; bgneal@312: window.showModalDialog(u, window, f); bgneal@312: } else bgneal@312: w = window.open(u, s.name, f); bgneal@312: } catch (ex) { bgneal@312: // Ignore bgneal@312: } bgneal@312: bgneal@312: if (!w) bgneal@312: alert(t.editor.getLang('popup_blocked')); bgneal@312: }, bgneal@312: bgneal@312: close : function(w) { bgneal@312: w.close(); bgneal@312: this.onClose.dispatch(this); bgneal@312: }, bgneal@312: bgneal@312: createInstance : function(cl, a, b, c, d, e) { bgneal@312: var f = tinymce.resolve(cl); bgneal@312: bgneal@312: return new f(a, b, c, d, e); bgneal@312: }, bgneal@312: bgneal@312: confirm : function(t, cb, s, w) { bgneal@312: w = w || window; bgneal@312: bgneal@312: cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t)))); bgneal@312: }, bgneal@312: bgneal@312: alert : function(tx, cb, s, w) { bgneal@312: var t = this; bgneal@312: bgneal@312: w = w || window; bgneal@312: w.alert(t._decode(t.editor.getLang(tx, tx))); bgneal@312: bgneal@312: if (cb) bgneal@312: cb.call(s || t); bgneal@312: }, bgneal@312: bgneal@312: resizeBy : function(dw, dh, win) { bgneal@312: win.resizeBy(dw, dh); bgneal@312: }, bgneal@312: bgneal@312: // Internal functions bgneal@312: bgneal@312: _decode : function(s) { bgneal@312: return tinymce.DOM.decode(s).replace(/\\n/g, '\n'); bgneal@312: } bgneal@312: }); bgneal@312: }(tinymce)); bgneal@312: (function(tinymce) { bgneal@312: tinymce.Formatter = function(ed) { bgneal@312: var formats = {}, bgneal@312: each = tinymce.each, bgneal@312: dom = ed.dom, bgneal@312: selection = ed.selection, bgneal@312: TreeWalker = tinymce.dom.TreeWalker, bgneal@312: rangeUtils = new tinymce.dom.RangeUtils(dom), bgneal@442: isValid = ed.schema.isValidChild, bgneal@312: isBlock = dom.isBlock, bgneal@312: forcedRootBlock = ed.settings.forced_root_block, bgneal@312: nodeIndex = dom.nodeIndex, bgneal@312: INVISIBLE_CHAR = '\uFEFF', bgneal@312: MCE_ATTR_RE = /^(src|href|style)$/, bgneal@312: FALSE = false, bgneal@312: TRUE = true, bgneal@312: undefined, bgneal@312: pendingFormats = {apply : [], remove : []}; bgneal@312: bgneal@312: function isArray(obj) { bgneal@312: return obj instanceof Array; bgneal@312: }; bgneal@312: bgneal@312: function getParents(node, selector) { bgneal@312: return dom.getParents(node, selector, dom.getRoot()); bgneal@312: }; bgneal@312: bgneal@312: function isCaretNode(node) { bgneal@312: return node.nodeType === 1 && (node.face === 'mceinline' || node.style.fontFamily === 'mceinline'); bgneal@312: }; bgneal@312: bgneal@312: // Public functions bgneal@312: bgneal@312: function get(name) { bgneal@312: return name ? formats[name] : formats; bgneal@312: }; bgneal@312: bgneal@312: function register(name, format) { bgneal@312: if (name) { bgneal@312: if (typeof(name) !== 'string') { bgneal@312: each(name, function(format, name) { bgneal@312: register(name, format); bgneal@312: }); bgneal@312: } else { bgneal@312: // Force format into array and add it to internal collection bgneal@312: format = format.length ? format : [format]; bgneal@312: bgneal@312: each(format, function(format) { bgneal@312: // Set deep to false by default on selector formats this to avoid removing bgneal@312: // alignment on images inside paragraphs when alignment is changed on paragraphs bgneal@312: if (format.deep === undefined) bgneal@312: format.deep = !format.selector; bgneal@312: bgneal@312: // Default to true bgneal@312: if (format.split === undefined) bgneal@312: format.split = !format.selector || format.inline; bgneal@312: bgneal@312: // Default to true bgneal@312: if (format.remove === undefined && format.selector && !format.inline) bgneal@312: format.remove = 'none'; bgneal@312: bgneal@312: // Mark format as a mixed format inline + block level bgneal@312: if (format.selector && format.inline) { bgneal@312: format.mixed = true; bgneal@312: format.block_expand = true; bgneal@312: } bgneal@312: bgneal@312: // Split classes if needed bgneal@312: if (typeof(format.classes) === 'string') bgneal@312: format.classes = format.classes.split(/\s+/); bgneal@312: }); bgneal@312: bgneal@312: formats[name] = format; bgneal@312: } bgneal@312: } bgneal@312: }; bgneal@312: bgneal@442: var getTextDecoration = function(node) { bgneal@442: var decoration; bgneal@442: bgneal@442: ed.dom.getParent(node, function(n) { bgneal@442: decoration = ed.dom.getStyle(n, 'text-decoration'); bgneal@442: return decoration && decoration !== 'none'; bgneal@442: }); bgneal@442: bgneal@442: return decoration; bgneal@442: }; bgneal@442: bgneal@442: var processUnderlineAndColor = function(node) { bgneal@442: var textDecoration; bgneal@442: if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) { bgneal@442: textDecoration = getTextDecoration(node.parentNode); bgneal@442: if (ed.dom.getStyle(node, 'color') && textDecoration) { bgneal@442: ed.dom.setStyle(node, 'text-decoration', textDecoration); bgneal@442: } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) { bgneal@442: ed.dom.setStyle(node, 'text-decoration', null); bgneal@442: } bgneal@442: } bgneal@442: }; bgneal@442: bgneal@312: function apply(name, vars, node) { bgneal@442: var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed(); bgneal@312: bgneal@312: function moveStart(rng) { bgneal@312: var container = rng.startContainer, bgneal@312: offset = rng.startOffset, bgneal@312: walker, node; bgneal@312: bgneal@312: // Move startContainer/startOffset in to a suitable node bgneal@312: if (container.nodeType == 1 || container.nodeValue === "") { bgneal@312: container = container.nodeType == 1 ? container.childNodes[offset] : container; bgneal@312: bgneal@312: // Might fail if the offset is behind the last element in it's container bgneal@312: if (container) { bgneal@312: walker = new TreeWalker(container, container.parentNode); bgneal@312: for (node = walker.current(); node; node = walker.next()) { bgneal@312: if (node.nodeType == 3 && !isWhiteSpaceNode(node)) { bgneal@312: rng.setStart(node, 0); bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return rng; bgneal@312: }; bgneal@312: bgneal@312: function setElementFormat(elm, fmt) { bgneal@312: fmt = fmt || format; bgneal@312: bgneal@312: if (elm) { bgneal@312: each(fmt.styles, function(value, name) { bgneal@312: dom.setStyle(elm, name, replaceVars(value, vars)); bgneal@312: }); bgneal@312: bgneal@312: each(fmt.attributes, function(value, name) { bgneal@312: dom.setAttrib(elm, name, replaceVars(value, vars)); bgneal@312: }); bgneal@312: bgneal@312: each(fmt.classes, function(value) { bgneal@312: value = replaceVars(value, vars); bgneal@312: bgneal@312: if (!dom.hasClass(elm, value)) bgneal@312: dom.addClass(elm, value); bgneal@312: }); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function applyRngStyle(rng) { bgneal@312: var newWrappers = [], wrapName, wrapElm; bgneal@312: bgneal@312: // Setup wrapper element bgneal@312: wrapName = format.inline || format.block; bgneal@312: wrapElm = dom.create(wrapName); bgneal@312: setElementFormat(wrapElm); bgneal@312: bgneal@312: rangeUtils.walk(rng, function(nodes) { bgneal@312: var currentWrapElm; bgneal@312: bgneal@312: function process(node) { bgneal@312: var nodeName = node.nodeName.toLowerCase(), parentName = node.parentNode.nodeName.toLowerCase(), found; bgneal@312: bgneal@312: // Stop wrapping on br elements bgneal@312: if (isEq(nodeName, 'br')) { bgneal@312: currentWrapElm = 0; bgneal@312: bgneal@312: // Remove any br elements when we wrap things bgneal@312: if (format.block) bgneal@312: dom.remove(node); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // If node is wrapper type bgneal@312: if (format.wrapper && matchNode(node, name, vars)) { bgneal@312: currentWrapElm = 0; bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Can we rename the block bgneal@312: if (format.block && !format.wrapper && isTextBlock(nodeName)) { bgneal@312: node = dom.rename(node, wrapName); bgneal@312: setElementFormat(node); bgneal@312: newWrappers.push(node); bgneal@312: currentWrapElm = 0; bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Handle selector patterns bgneal@312: if (format.selector) { bgneal@312: // Look for matching formats bgneal@312: each(formatList, function(format) { bgneal@442: // Check collapsed state if it exists bgneal@442: if ('collapsed' in format && format.collapsed !== isCollapsed) { bgneal@442: return; bgneal@442: } bgneal@442: bgneal@312: if (dom.is(node, format.selector) && !isCaretNode(node)) { bgneal@312: setElementFormat(node, format); bgneal@312: found = true; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // Continue processing if a selector match wasn't found and a inline element is defined bgneal@312: if (!format.inline || found) { bgneal@312: currentWrapElm = 0; bgneal@312: return; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Is it valid to wrap this item bgneal@442: if (isValid(wrapName, nodeName) && isValid(parentName, wrapName) && bgneal@442: !(node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279)) { bgneal@312: // Start wrapping bgneal@312: if (!currentWrapElm) { bgneal@312: // Wrap the node bgneal@312: currentWrapElm = wrapElm.cloneNode(FALSE); bgneal@312: node.parentNode.insertBefore(currentWrapElm, node); bgneal@312: newWrappers.push(currentWrapElm); bgneal@312: } bgneal@312: bgneal@312: currentWrapElm.appendChild(node); bgneal@312: } else { bgneal@312: // Start a new wrapper for possible children bgneal@312: currentWrapElm = 0; bgneal@312: bgneal@312: each(tinymce.grep(node.childNodes), process); bgneal@312: bgneal@312: // End the last wrapper bgneal@312: currentWrapElm = 0; bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: // Process siblings from range bgneal@312: each(nodes, process); bgneal@312: }); bgneal@312: bgneal@442: // Wrap links inside as well, for example color inside a link when the wrapper is around the link bgneal@442: if (format.wrap_links === false) { bgneal@442: each(newWrappers, function(node) { bgneal@442: function process(node) { bgneal@442: var i, currentWrapElm, children; bgneal@442: bgneal@442: if (node.nodeName === 'A') { bgneal@442: currentWrapElm = wrapElm.cloneNode(FALSE); bgneal@442: newWrappers.push(currentWrapElm); bgneal@442: bgneal@442: children = tinymce.grep(node.childNodes); bgneal@442: for (i = 0; i < children.length; i++) bgneal@442: currentWrapElm.appendChild(children[i]); bgneal@442: bgneal@442: node.appendChild(currentWrapElm); bgneal@442: } bgneal@442: bgneal@442: each(tinymce.grep(node.childNodes), process); bgneal@442: }; bgneal@442: bgneal@442: process(node); bgneal@442: }); bgneal@442: } bgneal@442: bgneal@312: // Cleanup bgneal@312: each(newWrappers, function(node) { bgneal@312: var childCount; bgneal@312: bgneal@312: function getChildCount(node) { bgneal@312: var count = 0; bgneal@312: bgneal@312: each(node.childNodes, function(node) { bgneal@312: if (!isWhiteSpaceNode(node) && !isBookmarkNode(node)) bgneal@312: count++; bgneal@312: }); bgneal@312: bgneal@312: return count; bgneal@312: }; bgneal@312: bgneal@312: function mergeStyles(node) { bgneal@312: var child, clone; bgneal@312: bgneal@312: each(node.childNodes, function(node) { bgneal@312: if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) { bgneal@312: child = node; bgneal@312: return FALSE; // break loop bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // If child was found and of the same type as the current node bgneal@312: if (child && matchName(child, format)) { bgneal@312: clone = child.cloneNode(FALSE); bgneal@312: setElementFormat(clone); bgneal@312: bgneal@312: dom.replace(clone, node, TRUE); bgneal@312: dom.remove(child, 1); bgneal@312: } bgneal@312: bgneal@312: return clone || node; bgneal@312: }; bgneal@312: bgneal@312: childCount = getChildCount(node); bgneal@312: bgneal@442: // Remove empty nodes but only if there is multiple wrappers and they are not block bgneal@442: // elements so never remove single

    since that would remove the currrent empty block element where the caret is at bgneal@442: if ((newWrappers.length > 1 || !isBlock(node)) && childCount === 0) { bgneal@312: dom.remove(node, 1); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: if (format.inline || format.wrapper) { bgneal@312: // Merges the current node with it's children of similar type to reduce the number of elements bgneal@312: if (!format.exact && childCount === 1) bgneal@312: node = mergeStyles(node); bgneal@312: bgneal@312: // Remove/merge children bgneal@312: each(formatList, function(format) { bgneal@312: // Merge all children of similar type will move styles from child to parent bgneal@312: // this: text bgneal@312: // will become: text bgneal@312: each(dom.select(format.inline, node), function(child) { bgneal@442: var parent; bgneal@442: bgneal@442: // When wrap_links is set to false we don't want bgneal@442: // to remove the format on children within links bgneal@442: if (format.wrap_links === false) { bgneal@442: parent = child.parentNode; bgneal@442: bgneal@442: do { bgneal@442: if (parent.nodeName === 'A') bgneal@442: return; bgneal@442: } while (parent = parent.parentNode); bgneal@442: } bgneal@442: bgneal@312: removeFormat(format, vars, child, format.exact ? child : null); bgneal@312: }); bgneal@312: }); bgneal@312: bgneal@312: // Remove child if direct parent is of same type bgneal@312: if (matchNode(node.parentNode, name, vars)) { bgneal@312: dom.remove(node, 1); bgneal@312: node = 0; bgneal@312: return TRUE; bgneal@312: } bgneal@312: bgneal@312: // Look for parent with similar style format bgneal@312: if (format.merge_with_parents) { bgneal@312: dom.getParent(node.parentNode, function(parent) { bgneal@312: if (matchNode(parent, name, vars)) { bgneal@312: dom.remove(node, 1); bgneal@312: node = 0; bgneal@312: return TRUE; bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: // Merge next and previous siblings if they are similar texttext becomes texttext bgneal@312: if (node) { bgneal@312: node = mergeSiblings(getNonWhiteSpaceSibling(node), node); bgneal@312: node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE)); bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: }; bgneal@312: bgneal@312: if (format) { bgneal@312: if (node) { bgneal@312: rng = dom.createRng(); bgneal@312: bgneal@312: rng.setStartBefore(node); bgneal@312: rng.setEndAfter(node); bgneal@312: bgneal@312: applyRngStyle(expandRng(rng, formatList)); bgneal@312: } else { bgneal@442: if (!isCollapsed || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) { bgneal@442: // Obtain selection node before selection is unselected by applyRngStyle() bgneal@442: var curSelNode = ed.selection.getNode(); bgneal@442: bgneal@312: // Apply formatting to selection bgneal@312: bookmark = selection.getBookmark(); bgneal@312: applyRngStyle(expandRng(selection.getRng(TRUE), formatList)); bgneal@312: bgneal@442: // Colored nodes should be underlined so that the color of the underline matches the text color. bgneal@442: if (format.styles && (format.styles.color || format.styles.textDecoration)) { bgneal@442: tinymce.walk(curSelNode, processUnderlineAndColor, 'childNodes'); bgneal@442: processUnderlineAndColor(curSelNode); bgneal@442: } bgneal@442: bgneal@312: selection.moveToBookmark(bookmark); bgneal@312: selection.setRng(moveStart(selection.getRng(TRUE))); bgneal@312: ed.nodeChanged(); bgneal@312: } else bgneal@312: performCaretAction('apply', name, vars); bgneal@312: } bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function remove(name, vars, node) { bgneal@312: var formatList = get(name), format = formatList[0], bookmark, i, rng; bgneal@312: bgneal@312: function moveStart(rng) { bgneal@312: var container = rng.startContainer, bgneal@312: offset = rng.startOffset, bgneal@312: walker, node, nodes, tmpNode; bgneal@312: bgneal@312: // Convert text node into index if possible bgneal@312: if (container.nodeType == 3 && offset >= container.nodeValue.length - 1) { bgneal@312: container = container.parentNode; bgneal@312: offset = nodeIndex(container) + 1; bgneal@312: } bgneal@312: bgneal@312: // Move startContainer/startOffset in to a suitable node bgneal@312: if (container.nodeType == 1) { bgneal@312: nodes = container.childNodes; bgneal@312: container = nodes[Math.min(offset, nodes.length - 1)]; bgneal@312: walker = new TreeWalker(container); bgneal@312: bgneal@312: // If offset is at end of the parent node walk to the next one bgneal@312: if (offset > nodes.length - 1) bgneal@312: walker.next(); bgneal@312: bgneal@312: for (node = walker.current(); node; node = walker.next()) { bgneal@312: if (node.nodeType == 3 && !isWhiteSpaceNode(node)) { bgneal@312: // IE has a "neat" feature where it moves the start node into the closest element bgneal@312: // we can avoid this by inserting an element before it and then remove it after we set the selection bgneal@312: tmpNode = dom.create('a', null, INVISIBLE_CHAR); bgneal@312: node.parentNode.insertBefore(tmpNode, node); bgneal@312: bgneal@312: // Set selection and remove tmpNode bgneal@312: rng.setStart(node, 0); bgneal@312: selection.setRng(rng); bgneal@312: dom.remove(tmpNode); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: // Merges the styles for each node bgneal@312: function process(node) { bgneal@312: var children, i, l; bgneal@312: bgneal@312: // Grab the children first since the nodelist might be changed bgneal@312: children = tinymce.grep(node.childNodes); bgneal@312: bgneal@312: // Process current node bgneal@312: for (i = 0, l = formatList.length; i < l; i++) { bgneal@312: if (removeFormat(formatList[i], vars, node, node)) bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: // Process the children bgneal@312: if (format.deep) { bgneal@312: for (i = 0, l = children.length; i < l; i++) bgneal@312: process(children[i]); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function findFormatRoot(container) { bgneal@312: var formatRoot; bgneal@312: bgneal@312: // Find format root bgneal@312: each(getParents(container.parentNode).reverse(), function(parent) { bgneal@312: var format; bgneal@312: bgneal@312: // Find format root element bgneal@312: if (!formatRoot && parent.id != '_start' && parent.id != '_end') { bgneal@312: // Is the node matching the format we are looking for bgneal@312: format = matchNode(parent, name, vars); bgneal@312: if (format && format.split !== false) bgneal@312: formatRoot = parent; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: return formatRoot; bgneal@312: }; bgneal@312: bgneal@312: function wrapAndSplit(format_root, container, target, split) { bgneal@312: var parent, clone, lastClone, firstClone, i, formatRootParent; bgneal@312: bgneal@312: // Format root found then clone formats and split it bgneal@312: if (format_root) { bgneal@312: formatRootParent = format_root.parentNode; bgneal@312: bgneal@312: for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) { bgneal@312: clone = parent.cloneNode(FALSE); bgneal@312: bgneal@312: for (i = 0; i < formatList.length; i++) { bgneal@312: if (removeFormat(formatList[i], vars, clone, clone)) { bgneal@312: clone = 0; bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Build wrapper node bgneal@312: if (clone) { bgneal@312: if (lastClone) bgneal@312: clone.appendChild(lastClone); bgneal@312: bgneal@312: if (!firstClone) bgneal@312: firstClone = clone; bgneal@312: bgneal@312: lastClone = clone; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Never split block elements if the format is mixed bgneal@312: if (split && (!format.mixed || !isBlock(format_root))) bgneal@312: container = dom.split(format_root, container); bgneal@312: bgneal@312: // Wrap container in cloned formats bgneal@312: if (lastClone) { bgneal@312: target.parentNode.insertBefore(lastClone, target); bgneal@312: firstClone.appendChild(target); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return container; bgneal@312: }; bgneal@312: bgneal@312: function splitToFormatRoot(container) { bgneal@312: return wrapAndSplit(findFormatRoot(container), container, container, true); bgneal@312: }; bgneal@312: bgneal@312: function unwrap(start) { bgneal@312: var node = dom.get(start ? '_start' : '_end'), bgneal@312: out = node[start ? 'firstChild' : 'lastChild']; bgneal@312: bgneal@312: // If the end is placed within the start the result will be removed bgneal@312: // So this checks if the out node is a bookmark node if it is it bgneal@312: // checks for another more suitable node bgneal@312: if (isBookmarkNode(out)) bgneal@312: out = out[start ? 'firstChild' : 'lastChild']; bgneal@312: bgneal@312: dom.remove(node, true); bgneal@312: bgneal@312: return out; bgneal@312: }; bgneal@312: bgneal@312: function removeRngStyle(rng) { bgneal@312: var startContainer, endContainer; bgneal@312: bgneal@312: rng = expandRng(rng, formatList, TRUE); bgneal@312: bgneal@312: if (format.split) { bgneal@312: startContainer = getContainer(rng, TRUE); bgneal@312: endContainer = getContainer(rng); bgneal@312: bgneal@312: if (startContainer != endContainer) { bgneal@312: // Wrap start/end nodes in span element since these might be cloned/moved bgneal@442: startContainer = wrap(startContainer, 'span', {id : '_start', 'data-mce-type' : 'bookmark'}); bgneal@442: endContainer = wrap(endContainer, 'span', {id : '_end', 'data-mce-type' : 'bookmark'}); bgneal@312: bgneal@312: // Split start/end bgneal@312: splitToFormatRoot(startContainer); bgneal@312: splitToFormatRoot(endContainer); bgneal@312: bgneal@312: // Unwrap start/end to get real elements again bgneal@312: startContainer = unwrap(TRUE); bgneal@312: endContainer = unwrap(); bgneal@312: } else bgneal@312: startContainer = endContainer = splitToFormatRoot(startContainer); bgneal@312: bgneal@312: // Update range positions since they might have changed after the split operations bgneal@312: rng.startContainer = startContainer.parentNode; bgneal@312: rng.startOffset = nodeIndex(startContainer); bgneal@312: rng.endContainer = endContainer.parentNode; bgneal@312: rng.endOffset = nodeIndex(endContainer) + 1; bgneal@312: } bgneal@312: bgneal@312: // Remove items between start/end bgneal@312: rangeUtils.walk(rng, function(nodes) { bgneal@312: each(nodes, function(node) { bgneal@312: process(node); bgneal@442: bgneal@442: // Remove parent span if it only contains text-decoration: underline, yet a parent node is also underlined. bgneal@442: if (node.nodeType === 1 && ed.dom.getStyle(node, 'text-decoration') === 'underline' && node.parentNode && getTextDecoration(node.parentNode) === 'underline') { bgneal@442: removeFormat({'deep': false, 'exact': true, 'inline': 'span', 'styles': {'textDecoration' : 'underline'}}, null, node); bgneal@442: } bgneal@312: }); bgneal@312: }); bgneal@312: }; bgneal@312: bgneal@312: // Handle node bgneal@312: if (node) { bgneal@312: rng = dom.createRng(); bgneal@312: rng.setStartBefore(node); bgneal@312: rng.setEndAfter(node); bgneal@312: removeRngStyle(rng); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@442: if (!selection.isCollapsed() || !format.inline || dom.select('td.mceSelected,th.mceSelected').length) { bgneal@312: bookmark = selection.getBookmark(); bgneal@312: removeRngStyle(selection.getRng(TRUE)); bgneal@312: selection.moveToBookmark(bookmark); bgneal@312: bgneal@312: // Check if start element still has formatting then we are at: "text|text" and need to move the start into the next text node bgneal@312: if (match(name, vars, selection.getStart())) { bgneal@312: moveStart(selection.getRng(true)); bgneal@312: } bgneal@312: bgneal@312: ed.nodeChanged(); bgneal@312: } else bgneal@312: performCaretAction('remove', name, vars); bgneal@312: }; bgneal@312: bgneal@312: function toggle(name, vars, node) { bgneal@442: var fmt = get(name); bgneal@442: bgneal@442: if (match(name, vars, node) && (!('toggle' in fmt[0]) || fmt[0]['toggle'])) bgneal@312: remove(name, vars, node); bgneal@312: else bgneal@312: apply(name, vars, node); bgneal@312: }; bgneal@312: bgneal@312: function matchNode(node, name, vars, similar) { bgneal@312: var formatList = get(name), format, i, classes; bgneal@312: bgneal@312: function matchItems(node, format, item_name) { bgneal@312: var key, value, items = format[item_name], i; bgneal@312: bgneal@312: // Check all items bgneal@312: if (items) { bgneal@312: // Non indexed object bgneal@312: if (items.length === undefined) { bgneal@312: for (key in items) { bgneal@312: if (items.hasOwnProperty(key)) { bgneal@312: if (item_name === 'attributes') bgneal@312: value = dom.getAttrib(node, key); bgneal@312: else bgneal@312: value = getStyle(node, key); bgneal@312: bgneal@312: if (similar && !value && !format.exact) bgneal@312: return; bgneal@312: bgneal@312: if ((!similar || format.exact) && !isEq(value, replaceVars(items[key], vars))) bgneal@312: return; bgneal@312: } bgneal@312: } bgneal@312: } else { bgneal@312: // Only one match needed for indexed arrays bgneal@312: for (i = 0; i < items.length; i++) { bgneal@312: if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i])) bgneal@312: return format; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return format; bgneal@312: }; bgneal@312: bgneal@312: if (formatList && node) { bgneal@312: // Check each format in list bgneal@312: for (i = 0; i < formatList.length; i++) { bgneal@312: format = formatList[i]; bgneal@312: bgneal@312: // Name name, attributes, styles and classes bgneal@312: if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) { bgneal@312: // Match classes bgneal@312: if (classes = format.classes) { bgneal@312: for (i = 0; i < classes.length; i++) { bgneal@312: if (!dom.hasClass(node, classes[i])) bgneal@312: return; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return format; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function match(name, vars, node) { bgneal@312: var startNode, i; bgneal@312: bgneal@312: function matchParents(node) { bgneal@312: // Find first node with similar format settings bgneal@312: node = dom.getParent(node, function(node) { bgneal@312: return !!matchNode(node, name, vars, true); bgneal@312: }); bgneal@312: bgneal@312: // Do an exact check on the similar format element bgneal@312: return matchNode(node, name, vars); bgneal@312: }; bgneal@312: bgneal@312: // Check specified node bgneal@312: if (node) bgneal@312: return matchParents(node); bgneal@312: bgneal@312: // Check pending formats bgneal@312: if (selection.isCollapsed()) { bgneal@312: for (i = pendingFormats.apply.length - 1; i >= 0; i--) { bgneal@312: if (pendingFormats.apply[i].name == name) bgneal@312: return true; bgneal@312: } bgneal@312: bgneal@312: for (i = pendingFormats.remove.length - 1; i >= 0; i--) { bgneal@312: if (pendingFormats.remove[i].name == name) bgneal@312: return false; bgneal@312: } bgneal@312: bgneal@312: return matchParents(selection.getNode()); bgneal@312: } bgneal@312: bgneal@312: // Check selected node bgneal@312: node = selection.getNode(); bgneal@312: if (matchParents(node)) bgneal@312: return TRUE; bgneal@312: bgneal@312: // Check start node if it's different bgneal@312: startNode = selection.getStart(); bgneal@312: if (startNode != node) { bgneal@312: if (matchParents(startNode)) bgneal@312: return TRUE; bgneal@312: } bgneal@312: bgneal@312: return FALSE; bgneal@312: }; bgneal@312: bgneal@312: function matchAll(names, vars) { bgneal@312: var startElement, matchedFormatNames = [], checkedMap = {}, i, ni, name; bgneal@312: bgneal@312: // If the selection is collapsed then check pending formats bgneal@312: if (selection.isCollapsed()) { bgneal@312: for (ni = 0; ni < names.length; ni++) { bgneal@312: // If the name is to be removed, then stop it from being added bgneal@312: for (i = pendingFormats.remove.length - 1; i >= 0; i--) { bgneal@312: name = names[ni]; bgneal@312: bgneal@312: if (pendingFormats.remove[i].name == name) { bgneal@312: checkedMap[name] = true; bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // If the format is to be applied bgneal@312: for (i = pendingFormats.apply.length - 1; i >= 0; i--) { bgneal@312: for (ni = 0; ni < names.length; ni++) { bgneal@312: name = names[ni]; bgneal@312: bgneal@312: if (!checkedMap[name] && pendingFormats.apply[i].name == name) { bgneal@312: checkedMap[name] = true; bgneal@312: matchedFormatNames.push(name); bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Check start of selection for formats bgneal@312: startElement = selection.getStart(); bgneal@312: dom.getParent(startElement, function(node) { bgneal@312: var i, name; bgneal@312: bgneal@312: for (i = 0; i < names.length; i++) { bgneal@312: name = names[i]; bgneal@312: bgneal@312: if (!checkedMap[name] && matchNode(node, name, vars)) { bgneal@312: checkedMap[name] = true; bgneal@312: matchedFormatNames.push(name); bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: return matchedFormatNames; bgneal@312: }; bgneal@312: bgneal@312: function canApply(name) { bgneal@312: var formatList = get(name), startNode, parents, i, x, selector; bgneal@312: bgneal@312: if (formatList) { bgneal@312: startNode = selection.getStart(); bgneal@312: parents = getParents(startNode); bgneal@312: bgneal@312: for (x = formatList.length - 1; x >= 0; x--) { bgneal@312: selector = formatList[x].selector; bgneal@312: bgneal@312: // Format is not selector based, then always return TRUE bgneal@312: if (!selector) bgneal@312: return TRUE; bgneal@312: bgneal@312: for (i = parents.length - 1; i >= 0; i--) { bgneal@312: if (dom.is(parents[i], selector)) bgneal@312: return TRUE; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return FALSE; bgneal@312: }; bgneal@312: bgneal@312: // Expose to public bgneal@312: tinymce.extend(this, { bgneal@312: get : get, bgneal@312: register : register, bgneal@312: apply : apply, bgneal@312: remove : remove, bgneal@312: toggle : toggle, bgneal@312: match : match, bgneal@312: matchAll : matchAll, bgneal@312: matchNode : matchNode, bgneal@312: canApply : canApply bgneal@312: }); bgneal@312: bgneal@312: // Private functions bgneal@312: bgneal@312: function matchName(node, format) { bgneal@312: // Check for inline match bgneal@312: if (isEq(node, format.inline)) bgneal@312: return TRUE; bgneal@312: bgneal@312: // Check for block match bgneal@312: if (isEq(node, format.block)) bgneal@312: return TRUE; bgneal@312: bgneal@312: // Check for selector match bgneal@312: if (format.selector) bgneal@312: return dom.is(node, format.selector); bgneal@312: }; bgneal@312: bgneal@312: function isEq(str1, str2) { bgneal@312: str1 = str1 || ''; bgneal@312: str2 = str2 || ''; bgneal@312: bgneal@312: str1 = '' + (str1.nodeName || str1); bgneal@312: str2 = '' + (str2.nodeName || str2); bgneal@312: bgneal@312: return str1.toLowerCase() == str2.toLowerCase(); bgneal@312: }; bgneal@312: bgneal@312: function getStyle(node, name) { bgneal@312: var styleVal = dom.getStyle(node, name); bgneal@312: bgneal@312: // Force the format to hex bgneal@312: if (name == 'color' || name == 'backgroundColor') bgneal@312: styleVal = dom.toHex(styleVal); bgneal@312: bgneal@312: // Opera will return bold as 700 bgneal@312: if (name == 'fontWeight' && styleVal == 700) bgneal@312: styleVal = 'bold'; bgneal@312: bgneal@312: return '' + styleVal; bgneal@312: }; bgneal@312: bgneal@312: function replaceVars(value, vars) { bgneal@312: if (typeof(value) != "string") bgneal@312: value = value(vars); bgneal@312: else if (vars) { bgneal@312: value = value.replace(/%(\w+)/g, function(str, name) { bgneal@312: return vars[name] || str; bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: return value; bgneal@312: }; bgneal@312: bgneal@312: function isWhiteSpaceNode(node) { bgneal@312: return node && node.nodeType === 3 && /^([\s\r\n]+|)$/.test(node.nodeValue); bgneal@312: }; bgneal@312: bgneal@312: function wrap(node, name, attrs) { bgneal@312: var wrapper = dom.create(name, attrs); bgneal@312: bgneal@312: node.parentNode.insertBefore(wrapper, node); bgneal@312: wrapper.appendChild(node); bgneal@312: bgneal@312: return wrapper; bgneal@312: }; bgneal@312: bgneal@312: function expandRng(rng, format, remove) { bgneal@312: var startContainer = rng.startContainer, bgneal@312: startOffset = rng.startOffset, bgneal@312: endContainer = rng.endContainer, bgneal@442: endOffset = rng.endOffset, sibling, lastIdx, leaf; bgneal@312: bgneal@312: // This function walks up the tree if there is no siblings before/after the node bgneal@312: function findParentContainer(container, child_name, sibling_name, root) { bgneal@312: var parent, child; bgneal@312: bgneal@312: root = root || dom.getRoot(); bgneal@312: bgneal@312: for (;;) { bgneal@312: // Check if we can move up are we at root level or body level bgneal@312: parent = container.parentNode; bgneal@312: bgneal@312: // Stop expanding on block elements or root depending on format bgneal@312: if (parent == root || (!format[0].block_expand && isBlock(parent))) bgneal@312: return container; bgneal@312: bgneal@312: for (sibling = parent[child_name]; sibling && sibling != container; sibling = sibling[sibling_name]) { bgneal@312: if (sibling.nodeType == 1 && !isBookmarkNode(sibling)) bgneal@312: return container; bgneal@312: bgneal@312: if (sibling.nodeType == 3 && !isWhiteSpaceNode(sibling)) bgneal@312: return container; bgneal@312: } bgneal@312: bgneal@312: container = container.parentNode; bgneal@312: } bgneal@312: bgneal@312: return container; bgneal@312: }; bgneal@312: bgneal@442: // This function walks down the tree to find the leaf at the selection. bgneal@442: // The offset is also returned as if node initially a leaf, the offset may be in the middle of the text node. bgneal@442: function findLeaf(node, offset) { bgneal@442: if (offset === undefined) bgneal@442: offset = node.nodeType === 3 ? node.length : node.childNodes.length; bgneal@442: while (node && node.hasChildNodes()) { bgneal@442: node = node.childNodes[offset]; bgneal@442: if (node) bgneal@442: offset = node.nodeType === 3 ? node.length : node.childNodes.length; bgneal@442: } bgneal@442: return { node: node, offset: offset }; bgneal@442: } bgneal@442: bgneal@312: // If index based start position then resolve it bgneal@312: if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) { bgneal@312: lastIdx = startContainer.childNodes.length - 1; bgneal@312: startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset]; bgneal@312: bgneal@312: if (startContainer.nodeType == 3) bgneal@312: startOffset = 0; bgneal@312: } bgneal@312: bgneal@312: // If index based end position then resolve it bgneal@312: if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) { bgneal@312: lastIdx = endContainer.childNodes.length - 1; bgneal@312: endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1]; bgneal@312: bgneal@312: if (endContainer.nodeType == 3) bgneal@312: endOffset = endContainer.nodeValue.length; bgneal@312: } bgneal@312: bgneal@312: // Exclude bookmark nodes if possible bgneal@312: if (isBookmarkNode(startContainer.parentNode)) bgneal@312: startContainer = startContainer.parentNode; bgneal@312: bgneal@312: if (isBookmarkNode(startContainer)) bgneal@312: startContainer = startContainer.nextSibling || startContainer; bgneal@312: bgneal@442: if (isBookmarkNode(endContainer.parentNode)) { bgneal@442: endOffset = dom.nodeIndex(endContainer); bgneal@312: endContainer = endContainer.parentNode; bgneal@442: } bgneal@442: bgneal@442: if (isBookmarkNode(endContainer) && endContainer.previousSibling) { bgneal@442: endContainer = endContainer.previousSibling; bgneal@442: endOffset = endContainer.length; bgneal@442: } bgneal@442: bgneal@442: if (format[0].inline) { bgneal@442: // Avoid applying formatting to a trailing space. bgneal@442: leaf = findLeaf(endContainer, endOffset); bgneal@442: if (leaf.node) { bgneal@442: while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling) bgneal@442: leaf = findLeaf(leaf.node.previousSibling); bgneal@442: bgneal@442: if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 && bgneal@442: leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') { bgneal@442: bgneal@442: if (leaf.offset > 1) { bgneal@442: endContainer = leaf.node; bgneal@442: endContainer.splitText(leaf.offset - 1); bgneal@442: } else if (leaf.node.previousSibling) { bgneal@442: endContainer = leaf.node.previousSibling; bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: } bgneal@442: bgneal@312: // Move start/end point up the tree if the leaves are sharp and if we are in different containers bgneal@312: // Example * becomes !: !

    *texttext*

    ! bgneal@312: // This will reduce the number of wrapper elements that needs to be created bgneal@312: // Move start point up the tree bgneal@312: if (format[0].inline || format[0].block_expand) { bgneal@312: startContainer = findParentContainer(startContainer, 'firstChild', 'nextSibling'); bgneal@312: endContainer = findParentContainer(endContainer, 'lastChild', 'previousSibling'); bgneal@312: } bgneal@312: bgneal@312: // Expand start/end container to matching selector bgneal@312: if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) { bgneal@312: function findSelectorEndPoint(container, sibling_name) { bgneal@442: var parents, i, y, curFormat; bgneal@312: bgneal@312: if (container.nodeType == 3 && container.nodeValue.length == 0 && container[sibling_name]) bgneal@312: container = container[sibling_name]; bgneal@312: bgneal@312: parents = getParents(container); bgneal@312: for (i = 0; i < parents.length; i++) { bgneal@312: for (y = 0; y < format.length; y++) { bgneal@442: curFormat = format[y]; bgneal@442: bgneal@442: // If collapsed state is set then skip formats that doesn't match that bgneal@442: if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed) bgneal@442: continue; bgneal@442: bgneal@442: if (dom.is(parents[i], curFormat.selector)) bgneal@312: return parents[i]; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return container; bgneal@312: }; bgneal@312: bgneal@312: // Find new startContainer/endContainer if there is better one bgneal@312: startContainer = findSelectorEndPoint(startContainer, 'previousSibling'); bgneal@312: endContainer = findSelectorEndPoint(endContainer, 'nextSibling'); bgneal@312: } bgneal@312: bgneal@312: // Expand start/end container to matching block element or text node bgneal@312: if (format[0].block || format[0].selector) { bgneal@312: function findBlockEndPoint(container, sibling_name, sibling_name2) { bgneal@312: var node; bgneal@312: bgneal@312: // Expand to block of similar type bgneal@312: if (!format[0].wrapper) bgneal@312: node = dom.getParent(container, format[0].block); bgneal@312: bgneal@312: // Expand to first wrappable block element or any block element bgneal@312: if (!node) bgneal@312: node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isBlock); bgneal@312: bgneal@312: // Exclude inner lists from wrapping bgneal@312: if (node && format[0].wrapper) bgneal@312: node = getParents(node, 'ul,ol').reverse()[0] || node; bgneal@312: bgneal@312: // Didn't find a block element look for first/last wrappable element bgneal@312: if (!node) { bgneal@312: node = container; bgneal@312: bgneal@312: while (node[sibling_name] && !isBlock(node[sibling_name])) { bgneal@312: node = node[sibling_name]; bgneal@312: bgneal@312: // Break on BR but include it will be removed later on bgneal@312: // we can't remove it now since we need to check if it can be wrapped bgneal@312: if (isEq(node, 'br')) bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return node || container; bgneal@312: }; bgneal@312: bgneal@312: // Find new startContainer/endContainer if there is better one bgneal@312: startContainer = findBlockEndPoint(startContainer, 'previousSibling'); bgneal@312: endContainer = findBlockEndPoint(endContainer, 'nextSibling'); bgneal@312: bgneal@312: // Non block element then try to expand up the leaf bgneal@312: if (format[0].block) { bgneal@312: if (!isBlock(startContainer)) bgneal@312: startContainer = findParentContainer(startContainer, 'firstChild', 'nextSibling'); bgneal@312: bgneal@312: if (!isBlock(endContainer)) bgneal@312: endContainer = findParentContainer(endContainer, 'lastChild', 'previousSibling'); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Setup index for startContainer bgneal@312: if (startContainer.nodeType == 1) { bgneal@312: startOffset = nodeIndex(startContainer); bgneal@312: startContainer = startContainer.parentNode; bgneal@312: } bgneal@312: bgneal@312: // Setup index for endContainer bgneal@312: if (endContainer.nodeType == 1) { bgneal@312: endOffset = nodeIndex(endContainer) + 1; bgneal@312: endContainer = endContainer.parentNode; bgneal@312: } bgneal@312: bgneal@312: // Return new range like object bgneal@312: return { bgneal@312: startContainer : startContainer, bgneal@312: startOffset : startOffset, bgneal@312: endContainer : endContainer, bgneal@312: endOffset : endOffset bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: function removeFormat(format, vars, node, compare_node) { bgneal@312: var i, attrs, stylesModified; bgneal@312: bgneal@312: // Check if node matches format bgneal@312: if (!matchName(node, format)) bgneal@312: return FALSE; bgneal@312: bgneal@312: // Should we compare with format attribs and styles bgneal@312: if (format.remove != 'all') { bgneal@312: // Remove styles bgneal@312: each(format.styles, function(value, name) { bgneal@312: value = replaceVars(value, vars); bgneal@312: bgneal@312: // Indexed array bgneal@312: if (typeof(name) === 'number') { bgneal@312: name = value; bgneal@312: compare_node = 0; bgneal@312: } bgneal@312: bgneal@312: if (!compare_node || isEq(getStyle(compare_node, name), value)) bgneal@312: dom.setStyle(node, name, ''); bgneal@312: bgneal@312: stylesModified = 1; bgneal@312: }); bgneal@312: bgneal@312: // Remove style attribute if it's empty bgneal@312: if (stylesModified && dom.getAttrib(node, 'style') == '') { bgneal@312: node.removeAttribute('style'); bgneal@442: node.removeAttribute('data-mce-style'); bgneal@312: } bgneal@312: bgneal@312: // Remove attributes bgneal@312: each(format.attributes, function(value, name) { bgneal@312: var valueOut; bgneal@312: bgneal@312: value = replaceVars(value, vars); bgneal@312: bgneal@312: // Indexed array bgneal@312: if (typeof(name) === 'number') { bgneal@312: name = value; bgneal@312: compare_node = 0; bgneal@312: } bgneal@312: bgneal@312: if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) { bgneal@312: // Keep internal classes bgneal@312: if (name == 'class') { bgneal@312: value = dom.getAttrib(node, name); bgneal@312: if (value) { bgneal@312: // Build new class value where everything is removed except the internal prefixed classes bgneal@312: valueOut = ''; bgneal@312: each(value.split(/\s+/), function(cls) { bgneal@312: if (/mce\w+/.test(cls)) bgneal@312: valueOut += (valueOut ? ' ' : '') + cls; bgneal@312: }); bgneal@312: bgneal@312: // We got some internal classes left bgneal@312: if (valueOut) { bgneal@312: dom.setAttrib(node, name, valueOut); bgneal@312: return; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // IE6 has a bug where the attribute doesn't get removed correctly bgneal@312: if (name == "class") bgneal@312: node.removeAttribute('className'); bgneal@312: bgneal@312: // Remove mce prefixed attributes bgneal@312: if (MCE_ATTR_RE.test(name)) bgneal@442: node.removeAttribute('data-mce-' + name); bgneal@312: bgneal@312: node.removeAttribute(name); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // Remove classes bgneal@312: each(format.classes, function(value) { bgneal@312: value = replaceVars(value, vars); bgneal@312: bgneal@312: if (!compare_node || dom.hasClass(compare_node, value)) bgneal@312: dom.removeClass(node, value); bgneal@312: }); bgneal@312: bgneal@312: // Check for non internal attributes bgneal@312: attrs = dom.getAttribs(node); bgneal@312: for (i = 0; i < attrs.length; i++) { bgneal@312: if (attrs[i].nodeName.indexOf('_') !== 0) bgneal@312: return FALSE; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Remove the inline child if it's empty for example or bgneal@312: if (format.remove != 'none') { bgneal@312: removeNode(node, format); bgneal@312: return TRUE; bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function removeNode(node, format) { bgneal@312: var parentNode = node.parentNode, rootBlockElm; bgneal@312: bgneal@312: if (format.block) { bgneal@312: if (!forcedRootBlock) { bgneal@312: function find(node, next, inc) { bgneal@312: node = getNonWhiteSpaceSibling(node, next, inc); bgneal@312: bgneal@312: return !node || (node.nodeName == 'BR' || isBlock(node)); bgneal@312: }; bgneal@312: bgneal@312: // Append BR elements if needed before we remove the block bgneal@312: if (isBlock(node) && !isBlock(parentNode)) { bgneal@312: if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1)) bgneal@312: node.insertBefore(dom.create('br'), node.firstChild); bgneal@312: bgneal@312: if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1)) bgneal@312: node.appendChild(dom.create('br')); bgneal@312: } bgneal@312: } else { bgneal@312: // Wrap the block in a forcedRootBlock if we are at the root of document bgneal@312: if (parentNode == dom.getRoot()) { bgneal@312: if (!format.list_block || !isEq(node, format.list_block)) { bgneal@312: each(tinymce.grep(node.childNodes), function(node) { bgneal@312: if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) { bgneal@312: if (!rootBlockElm) bgneal@312: rootBlockElm = wrap(node, forcedRootBlock); bgneal@312: else bgneal@312: rootBlockElm.appendChild(node); bgneal@312: } else bgneal@312: rootBlockElm = 0; bgneal@312: }); bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Never remove nodes that isn't the specified inline element if a selector is specified too bgneal@312: if (format.selector && format.inline && !isEq(format.inline, node)) bgneal@312: return; bgneal@312: bgneal@312: dom.remove(node, 1); bgneal@312: }; bgneal@312: bgneal@312: function getNonWhiteSpaceSibling(node, next, inc) { bgneal@312: if (node) { bgneal@312: next = next ? 'nextSibling' : 'previousSibling'; bgneal@312: bgneal@312: for (node = inc ? node : node[next]; node; node = node[next]) { bgneal@312: if (node.nodeType == 1 || !isWhiteSpaceNode(node)) bgneal@312: return node; bgneal@312: } bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function isBookmarkNode(node) { bgneal@442: return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark'; bgneal@312: }; bgneal@312: bgneal@312: function mergeSiblings(prev, next) { bgneal@312: var marker, sibling, tmpSibling; bgneal@312: bgneal@312: function compareElements(node1, node2) { bgneal@312: // Not the same name bgneal@312: if (node1.nodeName != node2.nodeName) bgneal@312: return FALSE; bgneal@312: bgneal@312: function getAttribs(node) { bgneal@312: var attribs = {}; bgneal@312: bgneal@312: each(dom.getAttribs(node), function(attr) { bgneal@312: var name = attr.nodeName.toLowerCase(); bgneal@312: bgneal@312: // Don't compare internal attributes or style bgneal@312: if (name.indexOf('_') !== 0 && name !== 'style') bgneal@312: attribs[name] = dom.getAttrib(node, name); bgneal@312: }); bgneal@312: bgneal@312: return attribs; bgneal@312: }; bgneal@312: bgneal@312: function compareObjects(obj1, obj2) { bgneal@312: var value, name; bgneal@312: bgneal@312: for (name in obj1) { bgneal@312: // Obj1 has item obj2 doesn't have bgneal@312: if (obj1.hasOwnProperty(name)) { bgneal@312: value = obj2[name]; bgneal@312: bgneal@312: // Obj2 doesn't have obj1 item bgneal@312: if (value === undefined) bgneal@312: return FALSE; bgneal@312: bgneal@312: // Obj2 item has a different value bgneal@312: if (obj1[name] != value) bgneal@312: return FALSE; bgneal@312: bgneal@312: // Delete similar value bgneal@312: delete obj2[name]; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Check if obj 2 has something obj 1 doesn't have bgneal@312: for (name in obj2) { bgneal@312: // Obj2 has item obj1 doesn't have bgneal@312: if (obj2.hasOwnProperty(name)) bgneal@312: return FALSE; bgneal@312: } bgneal@312: bgneal@312: return TRUE; bgneal@312: }; bgneal@312: bgneal@312: // Attribs are not the same bgneal@312: if (!compareObjects(getAttribs(node1), getAttribs(node2))) bgneal@312: return FALSE; bgneal@312: bgneal@312: // Styles are not the same bgneal@312: if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style')))) bgneal@312: return FALSE; bgneal@312: bgneal@312: return TRUE; bgneal@312: }; bgneal@312: bgneal@312: // Check if next/prev exists and that they are elements bgneal@312: if (prev && next) { bgneal@312: function findElementSibling(node, sibling_name) { bgneal@312: for (sibling = node; sibling; sibling = sibling[sibling_name]) { bgneal@442: if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0) bgneal@312: return node; bgneal@312: bgneal@312: if (sibling.nodeType == 1 && !isBookmarkNode(sibling)) bgneal@312: return sibling; bgneal@312: } bgneal@312: bgneal@312: return node; bgneal@312: }; bgneal@312: bgneal@312: // If previous sibling is empty then jump over it bgneal@312: prev = findElementSibling(prev, 'previousSibling'); bgneal@312: next = findElementSibling(next, 'nextSibling'); bgneal@312: bgneal@312: // Compare next and previous nodes bgneal@312: if (compareElements(prev, next)) { bgneal@312: // Append nodes between bgneal@312: for (sibling = prev.nextSibling; sibling && sibling != next;) { bgneal@312: tmpSibling = sibling; bgneal@312: sibling = sibling.nextSibling; bgneal@312: prev.appendChild(tmpSibling); bgneal@312: } bgneal@312: bgneal@312: // Remove next node bgneal@312: dom.remove(next); bgneal@312: bgneal@312: // Move children into prev node bgneal@312: each(tinymce.grep(next.childNodes), function(node) { bgneal@312: prev.appendChild(node); bgneal@312: }); bgneal@312: bgneal@312: return prev; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return next; bgneal@312: }; bgneal@312: bgneal@312: function isTextBlock(name) { bgneal@312: return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name); bgneal@312: }; bgneal@312: bgneal@312: function getContainer(rng, start) { bgneal@312: var container, offset, lastIdx; bgneal@312: bgneal@312: container = rng[start ? 'startContainer' : 'endContainer']; bgneal@312: offset = rng[start ? 'startOffset' : 'endOffset']; bgneal@312: bgneal@312: if (container.nodeType == 1) { bgneal@312: lastIdx = container.childNodes.length - 1; bgneal@312: bgneal@312: if (!start && offset) bgneal@312: offset--; bgneal@312: bgneal@312: container = container.childNodes[offset > lastIdx ? lastIdx : offset]; bgneal@312: } bgneal@312: bgneal@312: return container; bgneal@312: }; bgneal@312: bgneal@312: function performCaretAction(type, name, vars) { bgneal@312: var i, currentPendingFormats = pendingFormats[type], bgneal@312: otherPendingFormats = pendingFormats[type == 'apply' ? 'remove' : 'apply']; bgneal@312: bgneal@312: function hasPending() { bgneal@312: return pendingFormats.apply.length || pendingFormats.remove.length; bgneal@312: }; bgneal@312: bgneal@312: function resetPending() { bgneal@312: pendingFormats.apply = []; bgneal@312: pendingFormats.remove = []; bgneal@312: }; bgneal@312: bgneal@312: function perform(caret_node) { bgneal@312: // Apply pending formats bgneal@312: each(pendingFormats.apply.reverse(), function(item) { bgneal@312: apply(item.name, item.vars, caret_node); bgneal@442: bgneal@442: // Colored nodes should be underlined so that the color of the underline matches the text color. bgneal@442: if (item.name === 'forecolor' && item.vars.value) bgneal@442: processUnderlineAndColor(caret_node.parentNode); bgneal@312: }); bgneal@312: bgneal@312: // Remove pending formats bgneal@312: each(pendingFormats.remove.reverse(), function(item) { bgneal@312: remove(item.name, item.vars, caret_node); bgneal@312: }); bgneal@312: bgneal@312: dom.remove(caret_node, 1); bgneal@312: resetPending(); bgneal@312: }; bgneal@312: bgneal@312: // Check if it already exists then ignore it bgneal@312: for (i = currentPendingFormats.length - 1; i >= 0; i--) { bgneal@312: if (currentPendingFormats[i].name == name) bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: currentPendingFormats.push({name : name, vars : vars}); bgneal@312: bgneal@312: // Check if it's in the other type, then remove it bgneal@312: for (i = otherPendingFormats.length - 1; i >= 0; i--) { bgneal@312: if (otherPendingFormats[i].name == name) bgneal@312: otherPendingFormats.splice(i, 1); bgneal@312: } bgneal@312: bgneal@312: // Pending apply or remove formats bgneal@312: if (hasPending()) { bgneal@312: ed.getDoc().execCommand('FontName', false, 'mceinline'); bgneal@312: pendingFormats.lastRng = selection.getRng(); bgneal@312: bgneal@312: // IE will convert the current word bgneal@312: each(dom.select('font,span'), function(node) { bgneal@312: var bookmark; bgneal@312: bgneal@312: if (isCaretNode(node)) { bgneal@312: bookmark = selection.getBookmark(); bgneal@312: perform(node); bgneal@312: selection.moveToBookmark(bookmark); bgneal@312: ed.nodeChanged(); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // Only register listeners once if we need to bgneal@312: if (!pendingFormats.isListening && hasPending()) { bgneal@312: pendingFormats.isListening = true; bgneal@312: bgneal@312: each('onKeyDown,onKeyUp,onKeyPress,onMouseUp'.split(','), function(event) { bgneal@312: ed[event].addToTop(function(ed, e) { bgneal@312: // Do we have pending formats and is the selection moved has moved bgneal@312: if (hasPending() && !tinymce.dom.RangeUtils.compareRanges(pendingFormats.lastRng, selection.getRng())) { bgneal@312: each(dom.select('font,span'), function(node) { bgneal@312: var textNode, rng; bgneal@312: bgneal@312: // Look for marker bgneal@312: if (isCaretNode(node)) { bgneal@312: textNode = node.firstChild; bgneal@312: bgneal@312: if (textNode) { bgneal@312: perform(node); bgneal@312: bgneal@312: rng = dom.createRng(); bgneal@312: rng.setStart(textNode, textNode.nodeValue.length); bgneal@312: rng.setEnd(textNode, textNode.nodeValue.length); bgneal@312: selection.setRng(rng); bgneal@312: ed.nodeChanged(); bgneal@312: } else bgneal@312: dom.remove(node); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // Always unbind and clear pending styles on keyup bgneal@312: if (e.type == 'keyup' || e.type == 'mouseup') bgneal@312: resetPending(); bgneal@312: } bgneal@312: }); bgneal@312: }); bgneal@312: } bgneal@312: } bgneal@312: }; bgneal@312: }; bgneal@312: })(tinymce); bgneal@312: bgneal@312: tinymce.onAddEditor.add(function(tinymce, ed) { bgneal@312: var filters, fontSizes, dom, settings = ed.settings; bgneal@312: bgneal@312: if (settings.inline_styles) { bgneal@312: fontSizes = tinymce.explode(settings.font_size_style_values); bgneal@312: bgneal@312: function replaceWithSpan(node, styles) { bgneal@312: tinymce.each(styles, function(value, name) { bgneal@312: if (value) bgneal@312: dom.setStyle(node, name, value); bgneal@312: }); bgneal@312: bgneal@312: dom.rename(node, 'span'); bgneal@312: }; bgneal@312: bgneal@312: filters = { bgneal@312: font : function(dom, node) { bgneal@312: replaceWithSpan(node, { bgneal@312: backgroundColor : node.style.backgroundColor, bgneal@312: color : node.color, bgneal@312: fontFamily : node.face, bgneal@312: fontSize : fontSizes[parseInt(node.size) - 1] bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: u : function(dom, node) { bgneal@312: replaceWithSpan(node, { bgneal@312: textDecoration : 'underline' bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: strike : function(dom, node) { bgneal@312: replaceWithSpan(node, { bgneal@312: textDecoration : 'line-through' bgneal@312: }); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function convert(editor, params) { bgneal@312: dom = editor.dom; bgneal@312: bgneal@312: if (settings.convert_fonts_to_spans) { bgneal@312: tinymce.each(dom.select('font,u,strike', params.node), function(node) { bgneal@312: filters[node.nodeName.toLowerCase()](ed.dom, node); bgneal@312: }); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: ed.onPreProcess.add(convert); bgneal@442: ed.onSetContent.add(convert); bgneal@312: bgneal@312: ed.onInit.add(function() { bgneal@312: ed.selection.onSetContent.add(convert); bgneal@312: }); bgneal@312: } bgneal@312: }); bgneal@312: