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


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

    in

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

    a


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

    structure then don't remove anything bgneal@45: if (prevName === 'br') { bgneal@45: node = null; bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: prev = prev.prev; bgneal@45: } bgneal@45: bgneal@45: if (node) { bgneal@45: node.remove(); bgneal@45: bgneal@45: // Is the parent to be considered empty after we removed the BR bgneal@45: if (parent.isEmpty(nonEmptyElements)) { bgneal@45: elementRule = schema.getElementRule(parent.name); bgneal@45: bgneal@45: // Remove or padd the element depending on schema rule bgneal@45: if (elementRule) { bgneal@45: if (elementRule.removeEmpty) bgneal@45: parent.remove(); bgneal@45: else if (elementRule.paddEmpty) bgneal@45: parent.empty().append(new tinymce.html.Node('#text', 3)).value = '\u00a0'; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: } bgneal@45: })(tinymce); bgneal@45: bgneal@45: tinymce.html.Writer = function(settings) { bgneal@45: var html = [], indent, indentBefore, indentAfter, encode, htmlOutput; bgneal@45: bgneal@45: settings = settings || {}; bgneal@45: indent = settings.indent; bgneal@45: indentBefore = tinymce.makeMap(settings.indent_before || ''); bgneal@45: indentAfter = tinymce.makeMap(settings.indent_after || ''); bgneal@45: encode = tinymce.html.Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities); bgneal@45: htmlOutput = settings.element_format == "html"; bgneal@45: bgneal@45: return { bgneal@45: start: function(name, attrs, empty) { bgneal@45: var i, l, attr, value; bgneal@45: bgneal@45: if (indent && indentBefore[name] && html.length > 0) { bgneal@45: value = html[html.length - 1]; bgneal@45: bgneal@45: if (value.length > 0 && value !== '\n') bgneal@45: html.push('\n'); bgneal@45: } bgneal@45: bgneal@45: html.push('<', name); bgneal@45: bgneal@45: if (attrs) { bgneal@45: for (i = 0, l = attrs.length; i < l; i++) { bgneal@45: attr = attrs[i]; bgneal@45: html.push(' ', attr.name, '="', encode(attr.value, true), '"'); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if (!empty || htmlOutput) bgneal@45: html[html.length] = '>'; bgneal@45: else bgneal@45: html[html.length] = ' />'; bgneal@45: bgneal@45: if (empty && indent && indentAfter[name] && html.length > 0) { bgneal@45: value = html[html.length - 1]; bgneal@45: bgneal@45: if (value.length > 0 && value !== '\n') bgneal@45: html.push('\n'); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: end: function(name) { bgneal@45: var value; bgneal@45: bgneal@45: /*if (indent && indentBefore[name] && html.length > 0) { bgneal@45: value = html[html.length - 1]; bgneal@45: bgneal@45: if (value.length > 0 && value !== '\n') bgneal@45: html.push('\n'); bgneal@45: }*/ bgneal@45: bgneal@45: html.push(''); bgneal@45: bgneal@45: if (indent && indentAfter[name] && html.length > 0) { bgneal@45: value = html[html.length - 1]; bgneal@45: bgneal@45: if (value.length > 0 && value !== '\n') bgneal@45: html.push('\n'); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: text: function(text, raw) { bgneal@45: if (text.length > 0) bgneal@45: html[html.length] = raw ? text : encode(text); bgneal@45: }, bgneal@45: bgneal@45: cdata: function(text) { bgneal@45: html.push(''); bgneal@45: }, bgneal@45: bgneal@45: comment: function(text) { bgneal@45: html.push(''); bgneal@45: }, bgneal@45: bgneal@45: pi: function(name, text) { bgneal@45: if (text) bgneal@45: html.push(''); bgneal@45: else bgneal@45: html.push(''); bgneal@45: bgneal@45: if (indent) bgneal@45: html.push('\n'); bgneal@45: }, bgneal@45: bgneal@45: doctype: function(text) { bgneal@45: html.push('', indent ? '\n' : ''); bgneal@45: }, bgneal@45: bgneal@45: reset: function() { bgneal@45: html.length = 0; bgneal@45: }, bgneal@45: bgneal@45: getContent: function() { bgneal@45: return html.join('').replace(/\n$/, ''); bgneal@45: } bgneal@45: }; bgneal@45: }; bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: tinymce.html.Serializer = function(settings, schema) { bgneal@45: var self = this, writer = new tinymce.html.Writer(settings); bgneal@45: bgneal@45: settings = settings || {}; bgneal@45: settings.validate = "validate" in settings ? settings.validate : true; bgneal@45: bgneal@45: self.schema = schema = schema || new tinymce.html.Schema(); bgneal@45: self.writer = writer; bgneal@45: bgneal@45: self.serialize = function(node) { bgneal@45: var handlers, validate; bgneal@45: bgneal@45: validate = settings.validate; bgneal@45: bgneal@45: handlers = { bgneal@45: // #text bgneal@45: 3: function(node, raw) { bgneal@45: writer.text(node.value, node.raw); bgneal@45: }, bgneal@45: bgneal@45: // #comment bgneal@45: 8: function(node) { bgneal@45: writer.comment(node.value); bgneal@45: }, bgneal@45: bgneal@45: // Processing instruction bgneal@45: 7: function(node) { bgneal@45: writer.pi(node.name, node.value); bgneal@45: }, bgneal@45: bgneal@45: // Doctype bgneal@45: 10: function(node) { bgneal@45: writer.doctype(node.value); bgneal@45: }, bgneal@45: bgneal@45: // CDATA bgneal@45: 4: function(node) { bgneal@45: writer.cdata(node.value); bgneal@45: }, bgneal@45: bgneal@45: // Document fragment bgneal@45: 11: function(node) { bgneal@45: if ((node = node.firstChild)) { bgneal@45: do { bgneal@45: walk(node); bgneal@45: } while (node = node.next); bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: writer.reset(); bgneal@45: bgneal@45: function walk(node) { bgneal@45: var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule; bgneal@45: bgneal@45: if (!handler) { bgneal@45: name = node.name; bgneal@45: isEmpty = node.shortEnded; bgneal@45: attrs = node.attributes; bgneal@45: bgneal@45: // Sort attributes bgneal@45: if (validate && attrs && attrs.length > 1) { bgneal@45: sortedAttrs = []; bgneal@45: sortedAttrs.map = {}; bgneal@45: bgneal@45: elementRule = schema.getElementRule(node.name); bgneal@45: for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) { bgneal@45: attrName = elementRule.attributesOrder[i]; bgneal@45: bgneal@45: if (attrName in attrs.map) { bgneal@45: attrValue = attrs.map[attrName]; bgneal@45: sortedAttrs.map[attrName] = attrValue; bgneal@45: sortedAttrs.push({name: attrName, value: attrValue}); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: for (i = 0, l = attrs.length; i < l; i++) { bgneal@45: attrName = attrs[i].name; bgneal@45: bgneal@45: if (!(attrName in sortedAttrs.map)) { bgneal@45: attrValue = attrs.map[attrName]; bgneal@45: sortedAttrs.map[attrName] = attrValue; bgneal@45: sortedAttrs.push({name: attrName, value: attrValue}); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: attrs = sortedAttrs; bgneal@45: } bgneal@45: bgneal@45: writer.start(node.name, attrs, isEmpty); bgneal@45: bgneal@45: if (!isEmpty) { bgneal@45: if ((node = node.firstChild)) { bgneal@45: do { bgneal@45: walk(node); bgneal@45: } while (node = node.next); bgneal@45: } bgneal@45: bgneal@45: writer.end(name); bgneal@45: } bgneal@45: } else bgneal@45: handler(node); bgneal@45: } bgneal@45: bgneal@45: // Serialize element and treat all non elements as fragments bgneal@45: if (node.type == 1 && !settings.inner) bgneal@45: walk(node); bgneal@45: else bgneal@45: handlers[11](node); bgneal@45: bgneal@45: return writer.getContent(); bgneal@45: }; bgneal@45: } bgneal@45: })(tinymce); bgneal@45: bgneal@45: // JSLint defined globals bgneal@45: /*global tinymce:false, window:false */ bgneal@45: bgneal@45: tinymce.dom = {}; bgneal@45: bgneal@45: (function(namespace, expando) { bgneal@45: var w3cEventModel = !!document.addEventListener; bgneal@45: bgneal@45: function addEvent(target, name, callback, capture) { bgneal@45: if (target.addEventListener) { bgneal@45: target.addEventListener(name, callback, capture || false); bgneal@45: } else if (target.attachEvent) { bgneal@45: target.attachEvent('on' + name, callback); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: function removeEvent(target, name, callback, capture) { bgneal@45: if (target.removeEventListener) { bgneal@45: target.removeEventListener(name, callback, capture || false); bgneal@45: } else if (target.detachEvent) { bgneal@45: target.detachEvent('on' + name, callback); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: function fix(original_event, data) { bgneal@45: var name, event = data || {}; bgneal@45: bgneal@45: // Dummy function that gets replaced on the delegation state functions bgneal@45: function returnFalse() { bgneal@45: return false; bgneal@45: } bgneal@45: bgneal@45: // Dummy function that gets replaced on the delegation state functions bgneal@45: function returnTrue() { bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: // Copy all properties from the original event bgneal@45: for (name in original_event) { bgneal@45: // layerX/layerY is deprecated in Chrome and produces a warning bgneal@45: if (name !== "layerX" && name !== "layerY") { bgneal@45: event[name] = original_event[name]; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Normalize target IE uses srcElement bgneal@45: if (!event.target) { bgneal@45: event.target = event.srcElement || document; bgneal@45: } bgneal@45: bgneal@45: // Add preventDefault method bgneal@45: event.preventDefault = function() { bgneal@45: event.isDefaultPrevented = returnTrue; bgneal@45: bgneal@45: // Execute preventDefault on the original event object bgneal@45: if (original_event) { bgneal@45: if (original_event.preventDefault) { bgneal@45: original_event.preventDefault(); bgneal@45: } else { bgneal@45: original_event.returnValue = false; // IE bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Add stopPropagation bgneal@45: event.stopPropagation = function() { bgneal@45: event.isPropagationStopped = returnTrue; bgneal@45: bgneal@45: // Execute stopPropagation on the original event object bgneal@45: if (original_event) { bgneal@45: if (original_event.stopPropagation) { bgneal@45: original_event.stopPropagation(); bgneal@45: } else { bgneal@45: original_event.cancelBubble = true; // IE bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Add stopImmediatePropagation bgneal@45: event.stopImmediatePropagation = function() { bgneal@45: event.isImmediatePropagationStopped = returnTrue; bgneal@45: event.stopPropagation(); bgneal@45: }; bgneal@45: bgneal@45: // Add event delegation states bgneal@45: if (!event.isDefaultPrevented) { bgneal@45: event.isDefaultPrevented = returnFalse; bgneal@45: event.isPropagationStopped = returnFalse; bgneal@45: event.isImmediatePropagationStopped = returnFalse; bgneal@45: } bgneal@45: bgneal@45: return event; bgneal@45: } bgneal@45: bgneal@45: function bindOnReady(win, callback, event_utils) { bgneal@45: var doc = win.document, event = {type: 'ready'}; bgneal@45: bgneal@45: // Gets called when the DOM is ready bgneal@45: function readyHandler() { bgneal@45: if (!event_utils.domLoaded) { bgneal@45: event_utils.domLoaded = true; bgneal@45: callback(event); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Use W3C method bgneal@45: if (w3cEventModel) { bgneal@45: addEvent(win, 'DOMContentLoaded', readyHandler); bgneal@45: } else { bgneal@45: // Use IE method bgneal@45: addEvent(doc, "readystatechange", function() { bgneal@45: if (doc.readyState === "complete") { bgneal@45: removeEvent(doc, "readystatechange", arguments.callee); bgneal@45: readyHandler(); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Wait until we can scroll, when we can the DOM is initialized bgneal@45: if (doc.documentElement.doScroll && win === win.top) { bgneal@45: (function() { bgneal@45: try { bgneal@45: // If IE is used, use the trick by Diego Perini licensed under MIT by request to the author. bgneal@45: // http://javascript.nwbox.com/IEContentLoaded/ bgneal@45: doc.documentElement.doScroll("left"); bgneal@45: } catch (ex) { bgneal@45: setTimeout(arguments.callee, 0); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: readyHandler(); bgneal@45: })(); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Fallback if any of the above methods should fail for some odd reason bgneal@45: addEvent(win, 'load', readyHandler); bgneal@45: } bgneal@45: bgneal@45: function EventUtils(proxy) { bgneal@45: var self = this, events = {}, count, isFocusBlurBound, hasFocusIn, hasMouseEnterLeave, mouseEnterLeave; bgneal@45: bgneal@45: hasMouseEnterLeave = "onmouseenter" in document.documentElement; bgneal@45: hasFocusIn = "onfocusin" in document.documentElement; bgneal@45: mouseEnterLeave = {mouseenter: 'mouseover', mouseleave: 'mouseout'}; bgneal@45: count = 1; bgneal@45: bgneal@45: // State if the DOMContentLoaded was executed or not bgneal@45: self.domLoaded = false; bgneal@45: self.events = events; bgneal@45: bgneal@45: function executeHandlers(evt, id) { bgneal@45: var callbackList, i, l, callback; bgneal@45: bgneal@45: callbackList = events[id][evt.type]; bgneal@45: if (callbackList) { bgneal@45: for (i = 0, l = callbackList.length; i < l; i++) { bgneal@45: callback = callbackList[i]; bgneal@45: bgneal@45: // Check if callback exists might be removed if a unbind is called inside the callback bgneal@45: if (callback && callback.func.call(callback.scope, evt) === false) { bgneal@45: evt.preventDefault(); bgneal@45: } bgneal@45: bgneal@45: // Should we stop propagation to immediate listeners bgneal@45: if (evt.isImmediatePropagationStopped()) { bgneal@45: return; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: self.bind = function(target, names, callback, scope) { bgneal@45: var id, callbackList, i, name, fakeName, nativeHandler, capture, win = window; bgneal@45: bgneal@45: // Native event handler function patches the event and executes the callbacks for the expando bgneal@45: function defaultNativeHandler(evt) { bgneal@45: executeHandlers(fix(evt || win.event), id); bgneal@45: } bgneal@45: bgneal@45: // Don't bind to text nodes or comments bgneal@45: if (!target || target.nodeType === 3 || target.nodeType === 8) { bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Create or get events id for the target bgneal@45: if (!target[expando]) { bgneal@45: id = count++; bgneal@45: target[expando] = id; bgneal@45: events[id] = {}; bgneal@45: } else { bgneal@45: id = target[expando]; bgneal@45: bgneal@45: if (!events[id]) { bgneal@45: events[id] = {}; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Setup the specified scope or use the target as a default bgneal@45: scope = scope || target; bgneal@45: bgneal@45: // Split names and bind each event, enables you to bind multiple events with one call bgneal@45: names = names.split(' '); bgneal@45: i = names.length; bgneal@45: while (i--) { bgneal@45: name = names[i]; bgneal@45: nativeHandler = defaultNativeHandler; bgneal@45: fakeName = capture = false; bgneal@45: bgneal@45: // Use ready instead of DOMContentLoaded bgneal@45: if (name === "DOMContentLoaded") { bgneal@45: name = "ready"; bgneal@45: } bgneal@45: bgneal@45: // DOM is already ready bgneal@45: if ((self.domLoaded || target.readyState == 'complete') && name === "ready") { bgneal@45: self.domLoaded = true; bgneal@45: callback.call(scope, fix({type: name})); bgneal@45: continue; bgneal@45: } bgneal@45: bgneal@45: // Handle mouseenter/mouseleaver bgneal@45: if (!hasMouseEnterLeave) { bgneal@45: fakeName = mouseEnterLeave[name]; bgneal@45: bgneal@45: if (fakeName) { bgneal@45: nativeHandler = function(evt) { bgneal@45: var current, related; bgneal@45: bgneal@45: current = evt.currentTarget; bgneal@45: related = evt.relatedTarget; bgneal@45: bgneal@45: // Check if related is inside the current target if it's not then the event should be ignored since it's a mouseover/mouseout inside the element bgneal@45: if (related && current.contains) { bgneal@45: // Use contains for performance bgneal@45: related = current.contains(related); bgneal@45: } else { bgneal@45: while (related && related !== current) { bgneal@45: related = related.parentNode; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Fire fake event bgneal@45: if (!related) { bgneal@45: evt = fix(evt || win.event); bgneal@45: evt.type = evt.type === 'mouseout' ? 'mouseleave' : 'mouseenter'; bgneal@45: evt.target = current; bgneal@45: executeHandlers(evt, id); bgneal@45: } bgneal@45: }; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Fake bubbeling of focusin/focusout bgneal@45: if (!hasFocusIn && (name === "focusin" || name === "focusout")) { bgneal@45: capture = true; bgneal@45: fakeName = name === "focusin" ? "focus" : "blur"; bgneal@45: nativeHandler = function(evt) { bgneal@45: evt = fix(evt || win.event); bgneal@45: evt.type = evt.type === 'focus' ? 'focusin' : 'focusout'; bgneal@45: executeHandlers(evt, id); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: // Setup callback list and bind native event bgneal@45: callbackList = events[id][name]; bgneal@45: if (!callbackList) { bgneal@45: events[id][name] = callbackList = [{func: callback, scope: scope}]; bgneal@45: callbackList.fakeName = fakeName; bgneal@45: callbackList.capture = capture; bgneal@45: bgneal@45: // Add the nativeHandler to the callback list so that we can later unbind it bgneal@45: callbackList.nativeHandler = nativeHandler; bgneal@45: if (!w3cEventModel) { bgneal@45: callbackList.proxyHandler = proxy(id); bgneal@45: } bgneal@45: bgneal@45: // Check if the target has native events support bgneal@45: if (name === "ready") { bgneal@45: bindOnReady(target, nativeHandler, self); bgneal@45: } else { bgneal@45: addEvent(target, fakeName || name, w3cEventModel ? nativeHandler : callbackList.proxyHandler, capture); bgneal@45: } bgneal@45: } else { bgneal@45: // If it already has an native handler then just push the callback bgneal@45: callbackList.push({func: callback, scope: scope}); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: target = callbackList = 0; // Clean memory for IE bgneal@45: bgneal@45: return callback; bgneal@45: }; bgneal@45: bgneal@45: self.unbind = function(target, names, callback) { bgneal@45: var id, callbackList, i, ci, name, eventMap; bgneal@45: bgneal@45: // Don't bind to text nodes or comments bgneal@45: if (!target || target.nodeType === 3 || target.nodeType === 8) { bgneal@45: return self; bgneal@45: } bgneal@45: bgneal@45: // Unbind event or events if the target has the expando bgneal@45: id = target[expando]; bgneal@45: if (id) { bgneal@45: eventMap = events[id]; bgneal@45: bgneal@45: // Specific callback bgneal@45: if (names) { bgneal@45: names = names.split(' '); bgneal@45: i = names.length; bgneal@45: while (i--) { bgneal@45: name = names[i]; bgneal@45: callbackList = eventMap[name]; bgneal@45: bgneal@45: // Unbind the event if it exists in the map bgneal@45: if (callbackList) { bgneal@45: // Remove specified callback bgneal@45: if (callback) { bgneal@45: ci = callbackList.length; bgneal@45: while (ci--) { bgneal@45: if (callbackList[ci].func === callback) { bgneal@45: callbackList.splice(ci, 1); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Remove all callbacks if there isn't a specified callback or there is no callbacks left bgneal@45: if (!callback || callbackList.length === 0) { bgneal@45: delete eventMap[name]; bgneal@45: removeEvent(target, callbackList.fakeName || name, w3cEventModel ? callbackList.nativeHandler : callbackList.proxyHandler, callbackList.capture); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } else { bgneal@45: // All events for a specific element bgneal@45: for (name in eventMap) { bgneal@45: callbackList = eventMap[name]; bgneal@45: removeEvent(target, callbackList.fakeName || name, w3cEventModel ? callbackList.nativeHandler : callbackList.proxyHandler, callbackList.capture); bgneal@45: } bgneal@45: bgneal@45: eventMap = {}; bgneal@45: } bgneal@45: bgneal@45: // Check if object is empty, if it isn't then we won't remove the expando map bgneal@45: for (name in eventMap) { bgneal@45: return self; bgneal@45: } bgneal@45: bgneal@45: // Delete event object bgneal@45: delete events[id]; bgneal@45: bgneal@45: // Remove expando from target bgneal@45: try { bgneal@45: // IE will fail here since it can't delete properties from window bgneal@45: delete target[expando]; bgneal@45: } catch (ex) { bgneal@45: // IE will set it to null bgneal@45: target[expando] = null; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return self; bgneal@45: }; bgneal@45: bgneal@45: self.fire = function(target, name, args) { bgneal@45: var id, event; bgneal@45: bgneal@45: // Don't bind to text nodes or comments bgneal@45: if (!target || target.nodeType === 3 || target.nodeType === 8) { bgneal@45: return self; bgneal@45: } bgneal@45: bgneal@45: // Build event object by patching the args bgneal@45: event = fix(null, args); bgneal@45: event.type = name; bgneal@45: bgneal@45: do { bgneal@45: // Found an expando that means there is listeners to execute bgneal@45: id = target[expando]; bgneal@45: if (id) { bgneal@45: executeHandlers(event, id); bgneal@45: } bgneal@45: bgneal@45: // Walk up the DOM bgneal@45: target = target.parentNode || target.ownerDocument || target.defaultView || target.parentWindow; bgneal@45: } while (target && !event.isPropagationStopped()); bgneal@45: bgneal@45: return self; bgneal@45: }; bgneal@45: bgneal@45: self.clean = function(target) { bgneal@45: var i, children, unbind = self.unbind; bgneal@45: bgneal@45: // Don't bind to text nodes or comments bgneal@45: if (!target || target.nodeType === 3 || target.nodeType === 8) { bgneal@45: return self; bgneal@45: } bgneal@45: bgneal@45: // Unbind any element on the specificed target bgneal@45: if (target[expando]) { bgneal@45: unbind(target); bgneal@45: } bgneal@45: bgneal@45: // Target doesn't have getElementsByTagName it's probably a window object then use it's document to find the children bgneal@45: if (!target.getElementsByTagName) { bgneal@45: target = target.document; bgneal@45: } bgneal@45: bgneal@45: // Remove events from each child element bgneal@45: if (target && target.getElementsByTagName) { bgneal@45: unbind(target); bgneal@45: bgneal@45: children = target.getElementsByTagName('*'); bgneal@45: i = children.length; bgneal@45: while (i--) { bgneal@45: target = children[i]; bgneal@45: bgneal@45: if (target[expando]) { bgneal@45: unbind(target); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return self; bgneal@45: }; bgneal@45: bgneal@45: self.callNativeHandler = function(id, evt) { bgneal@45: if (events) { bgneal@45: events[id][evt.type].nativeHandler(evt); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: self.destory = function() { bgneal@45: events = {}; bgneal@45: }; bgneal@45: bgneal@45: // Legacy function calls bgneal@45: bgneal@45: self.add = function(target, events, func, scope) { bgneal@45: // Old API supported direct ID assignment bgneal@45: if (typeof(target) === "string") { bgneal@45: target = document.getElementById(target); bgneal@45: } bgneal@45: bgneal@45: // Old API supported multiple targets bgneal@45: if (target && target instanceof Array) { bgneal@45: var i = target; bgneal@45: bgneal@45: while (i--) { bgneal@45: self.add(target[i], events, func, scope); bgneal@45: } bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Old API called ready init bgneal@45: if (events === "init") { bgneal@45: events = "ready"; bgneal@45: } bgneal@45: bgneal@45: return self.bind(target, events instanceof Array ? events.join(' ') : events, func, scope); bgneal@45: }; bgneal@45: bgneal@45: self.remove = function(target, events, func) { bgneal@45: // Old API supported direct ID assignment bgneal@45: if (typeof(target) === "string") { bgneal@45: target = document.getElementById(target); bgneal@45: } bgneal@45: bgneal@45: // Old API supported multiple targets bgneal@45: if (target instanceof Array) { bgneal@45: var i = target; bgneal@45: bgneal@45: while (i--) { bgneal@45: self.remove(target[i], events, func, scope); bgneal@45: } bgneal@45: bgneal@45: return self; bgneal@45: } bgneal@45: bgneal@45: return self.unbind(target, events instanceof Array ? events.join(' ') : events, func); bgneal@45: }; bgneal@45: bgneal@45: self.clear = function(target) { bgneal@45: // Old API supported direct ID assignment bgneal@45: if (typeof(target) === "string") { bgneal@45: target = document.getElementById(target); bgneal@45: } bgneal@45: bgneal@45: return self.clean(target); bgneal@45: }; bgneal@45: bgneal@45: self.cancel = function(e) { bgneal@45: if (e) { bgneal@45: self.prevent(e); bgneal@45: self.stop(e); bgneal@45: } bgneal@45: bgneal@45: return false; bgneal@45: }; bgneal@45: bgneal@45: self.prevent = function(e) { bgneal@45: e.preventDefault(); bgneal@45: bgneal@45: return false; bgneal@45: }; bgneal@45: bgneal@45: self.stop = function(e) { bgneal@45: e.stopPropagation(); bgneal@45: bgneal@45: return false; bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: namespace.EventUtils = EventUtils; bgneal@45: bgneal@45: namespace.Event = new EventUtils(function(id) { bgneal@45: return function(evt) { bgneal@45: tinymce.dom.Event.callNativeHandler(id, evt); bgneal@45: }; bgneal@45: }); bgneal@45: bgneal@45: // Bind ready event when tinymce script is loaded bgneal@45: namespace.Event.bind(window, 'ready', function() {}); bgneal@45: bgneal@45: namespace = 0; bgneal@45: })(tinymce.dom, 'data-mce-expando'); // Namespace and expando bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: // Shorten names bgneal@45: var each = tinymce.each, bgneal@45: is = tinymce.is, bgneal@45: isWebKit = tinymce.isWebKit, bgneal@45: isIE = tinymce.isIE, bgneal@45: Entities = tinymce.html.Entities, bgneal@45: simpleSelectorRe = /^([a-z0-9],?)+$/i, bgneal@45: whiteSpaceRegExp = /^[ \t\r\n]*$/; bgneal@45: bgneal@45: tinymce.create('tinymce.dom.DOMUtils', { bgneal@45: doc : null, bgneal@45: root : null, bgneal@45: files : null, bgneal@45: pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/, bgneal@45: props : { bgneal@45: "for" : "htmlFor", bgneal@45: "class" : "className", bgneal@45: className : "className", bgneal@45: checked : "checked", bgneal@45: disabled : "disabled", bgneal@45: maxlength : "maxLength", bgneal@45: readonly : "readOnly", bgneal@45: selected : "selected", bgneal@45: value : "value", bgneal@45: id : "id", bgneal@45: name : "name", bgneal@45: type : "type" bgneal@45: }, bgneal@45: bgneal@45: DOMUtils : function(d, s) { bgneal@45: var t = this, globalStyle, name, blockElementsMap; bgneal@45: bgneal@45: t.doc = d; bgneal@45: t.win = window; bgneal@45: t.files = {}; bgneal@45: t.cssFlicker = false; bgneal@45: t.counter = 0; bgneal@45: t.stdMode = !tinymce.isIE || d.documentMode >= 8; bgneal@45: t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat" || t.stdMode; bgneal@45: t.hasOuterHTML = "outerHTML" in d.createElement("a"); bgneal@45: bgneal@45: t.settings = s = tinymce.extend({ bgneal@45: keep_values : false, bgneal@45: hex_colors : 1 bgneal@45: }, s); bgneal@45: bgneal@45: t.schema = s.schema; bgneal@45: t.styles = new tinymce.html.Styles({ bgneal@45: url_converter : s.url_converter, bgneal@45: url_converter_scope : s.url_converter_scope bgneal@45: }, s.schema); bgneal@45: bgneal@45: // Fix IE6SP2 flicker and check it failed for pre SP2 bgneal@45: if (tinymce.isIE6) { bgneal@45: try { bgneal@45: d.execCommand('BackgroundImageCache', false, true); bgneal@45: } catch (e) { bgneal@45: t.cssFlicker = true; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: t.fixDoc(d); bgneal@45: t.events = s.ownEvents ? new tinymce.dom.EventUtils(s.proxy) : tinymce.dom.Event; bgneal@45: tinymce.addUnload(t.destroy, t); bgneal@45: blockElementsMap = s.schema ? s.schema.getBlockElements() : {}; bgneal@45: bgneal@45: t.isBlock = function(node) { bgneal@45: // This function is called in module pattern style since it might be executed with the wrong this scope bgneal@45: var type = node.nodeType; bgneal@45: bgneal@45: // If it's a node then check the type and use the nodeName bgneal@45: if (type) bgneal@45: return !!(type === 1 && blockElementsMap[node.nodeName]); bgneal@45: bgneal@45: return !!blockElementsMap[node]; bgneal@45: }; bgneal@45: }, bgneal@45: bgneal@45: fixDoc: function(doc) { bgneal@45: var settings = this.settings, name; bgneal@45: bgneal@45: if (isIE && settings.schema) { bgneal@45: // Add missing HTML 4/5 elements to IE bgneal@45: ('abbr article aside audio canvas ' + bgneal@45: 'details figcaption figure footer ' + bgneal@45: 'header hgroup mark menu meter nav ' + bgneal@45: 'output progress section summary ' + bgneal@45: 'time video').replace(/\w+/g, function(name) { bgneal@45: doc.createElement(name); bgneal@45: }); bgneal@45: bgneal@45: // Create all custom elements bgneal@45: for (name in settings.schema.getCustomElements()) { bgneal@45: doc.createElement(name); bgneal@45: } bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: clone: function(node, deep) { bgneal@45: var self = this, clone, doc; bgneal@45: bgneal@45: // TODO: Add feature detection here in the future bgneal@45: if (!isIE || node.nodeType !== 1 || deep) { bgneal@45: return node.cloneNode(deep); bgneal@45: } bgneal@45: bgneal@45: doc = self.doc; bgneal@45: bgneal@45: // Make a HTML5 safe shallow copy bgneal@45: if (!deep) { bgneal@45: clone = doc.createElement(node.nodeName); bgneal@45: bgneal@45: // Copy attribs bgneal@45: each(self.getAttribs(node), function(attr) { bgneal@45: self.setAttrib(clone, attr.nodeName, self.getAttrib(node, attr.nodeName)); bgneal@45: }); bgneal@45: bgneal@45: return clone; bgneal@45: } bgneal@45: /* bgneal@45: // Setup HTML5 patched document fragment bgneal@45: if (!self.frag) { bgneal@45: self.frag = doc.createDocumentFragment(); bgneal@45: self.fixDoc(self.frag); bgneal@45: } bgneal@45: bgneal@45: // Make a deep copy by adding it to the document fragment then removing it this removed the :section bgneal@45: clone = doc.createElement('div'); bgneal@45: self.frag.appendChild(clone); bgneal@45: clone.innerHTML = node.outerHTML; bgneal@45: self.frag.removeChild(clone); bgneal@45: */ bgneal@45: return clone.firstChild; bgneal@45: }, bgneal@45: bgneal@45: getRoot : function() { bgneal@45: var t = this, s = t.settings; bgneal@45: bgneal@45: return (s && t.get(s.root_element)) || t.doc.body; bgneal@45: }, bgneal@45: bgneal@45: getViewPort : function(w) { bgneal@45: var d, b; bgneal@45: bgneal@45: w = !w ? this.win : w; bgneal@45: d = w.document; bgneal@45: b = this.boxModel ? d.documentElement : d.body; bgneal@45: bgneal@45: // Returns viewport size excluding scrollbars bgneal@45: return { bgneal@45: x : w.pageXOffset || b.scrollLeft, bgneal@45: y : w.pageYOffset || b.scrollTop, bgneal@45: w : w.innerWidth || b.clientWidth, bgneal@45: h : w.innerHeight || b.clientHeight bgneal@45: }; bgneal@45: }, bgneal@45: bgneal@45: getRect : function(e) { bgneal@45: var p, t = this, sr; bgneal@45: bgneal@45: e = t.get(e); bgneal@45: p = t.getPos(e); bgneal@45: sr = t.getSize(e); bgneal@45: bgneal@45: return { bgneal@45: x : p.x, bgneal@45: y : p.y, bgneal@45: w : sr.w, bgneal@45: h : sr.h bgneal@45: }; bgneal@45: }, bgneal@45: bgneal@45: getSize : function(e) { bgneal@45: var t = this, w, h; bgneal@45: bgneal@45: e = t.get(e); bgneal@45: w = t.getStyle(e, 'width'); bgneal@45: h = t.getStyle(e, 'height'); bgneal@45: bgneal@45: // Non pixel value, then force offset/clientWidth bgneal@45: if (w.indexOf('px') === -1) bgneal@45: w = 0; bgneal@45: bgneal@45: // Non pixel value, then force offset/clientWidth bgneal@45: if (h.indexOf('px') === -1) bgneal@45: h = 0; bgneal@45: bgneal@45: return { bgneal@45: w : parseInt(w) || e.offsetWidth || e.clientWidth, bgneal@45: h : parseInt(h) || e.offsetHeight || e.clientHeight bgneal@45: }; bgneal@45: }, bgneal@45: bgneal@45: getParent : function(n, f, r) { bgneal@45: return this.getParents(n, f, r, false); bgneal@45: }, bgneal@45: bgneal@45: getParents : function(n, f, r, c) { bgneal@45: var t = this, na, se = t.settings, o = []; bgneal@45: bgneal@45: n = t.get(n); bgneal@45: c = c === undefined; bgneal@45: bgneal@45: if (se.strict_root) bgneal@45: r = r || t.getRoot(); bgneal@45: bgneal@45: // Wrap node name as func bgneal@45: if (is(f, 'string')) { bgneal@45: na = f; bgneal@45: bgneal@45: if (f === '*') { bgneal@45: f = function(n) {return n.nodeType == 1;}; bgneal@45: } else { bgneal@45: f = function(n) { bgneal@45: return t.is(n, na); bgneal@45: }; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: while (n) { bgneal@45: if (n == r || !n.nodeType || n.nodeType === 9) bgneal@45: break; bgneal@45: bgneal@45: if (!f || f(n)) { bgneal@45: if (c) bgneal@45: o.push(n); bgneal@45: else bgneal@45: return n; bgneal@45: } bgneal@45: bgneal@45: n = n.parentNode; bgneal@45: } bgneal@45: bgneal@45: return c ? o : null; bgneal@45: }, bgneal@45: bgneal@45: get : function(e) { bgneal@45: var n; bgneal@45: bgneal@45: if (e && this.doc && typeof(e) == 'string') { bgneal@45: n = e; bgneal@45: e = this.doc.getElementById(e); bgneal@45: bgneal@45: // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick bgneal@45: if (e && e.id !== n) bgneal@45: return this.doc.getElementsByName(n)[1]; bgneal@45: } bgneal@45: bgneal@45: return e; bgneal@45: }, bgneal@45: bgneal@45: getNext : function(node, selector) { bgneal@45: return this._findSib(node, selector, 'nextSibling'); bgneal@45: }, bgneal@45: bgneal@45: getPrev : function(node, selector) { bgneal@45: return this._findSib(node, selector, 'previousSibling'); bgneal@45: }, bgneal@45: bgneal@45: bgneal@45: select : function(pa, s) { bgneal@45: var t = this; bgneal@45: bgneal@45: return tinymce.dom.Sizzle(pa, t.get(s) || t.get(t.settings.root_element) || t.doc, []); bgneal@45: }, bgneal@45: bgneal@45: is : function(n, selector) { bgneal@45: var i; bgneal@45: bgneal@45: // If it isn't an array then try to do some simple selectors instead of Sizzle for to boost performance bgneal@45: if (n.length === undefined) { bgneal@45: // Simple all selector bgneal@45: if (selector === '*') bgneal@45: return n.nodeType == 1; bgneal@45: bgneal@45: // Simple selector just elements bgneal@45: if (simpleSelectorRe.test(selector)) { bgneal@45: selector = selector.toLowerCase().split(/,/); bgneal@45: n = n.nodeName.toLowerCase(); bgneal@45: bgneal@45: for (i = selector.length - 1; i >= 0; i--) { bgneal@45: if (selector[i] == n) bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: return false; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return tinymce.dom.Sizzle.matches(selector, n.nodeType ? [n] : n).length > 0; bgneal@45: }, bgneal@45: bgneal@45: bgneal@45: add : function(p, n, a, h, c) { bgneal@45: var t = this; bgneal@45: bgneal@45: return this.run(p, function(p) { bgneal@45: var e, k; bgneal@45: bgneal@45: e = is(n, 'string') ? t.doc.createElement(n) : n; bgneal@45: t.setAttribs(e, a); bgneal@45: bgneal@45: if (h) { bgneal@45: if (h.nodeType) bgneal@45: e.appendChild(h); bgneal@45: else bgneal@45: t.setHTML(e, h); bgneal@45: } bgneal@45: bgneal@45: return !c ? p.appendChild(e) : e; bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: create : function(n, a, h) { bgneal@45: return this.add(this.doc.createElement(n), n, a, h, 1); bgneal@45: }, bgneal@45: bgneal@45: createHTML : function(n, a, h) { bgneal@45: var o = '', t = this, k; bgneal@45: bgneal@45: o += '<' + n; bgneal@45: bgneal@45: for (k in a) { bgneal@45: if (a.hasOwnProperty(k)) bgneal@45: o += ' ' + k + '="' + t.encode(a[k]) + '"'; bgneal@45: } bgneal@45: bgneal@45: // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime bgneal@45: if (typeof(h) != "undefined") bgneal@45: return o + '>' + h + ''; bgneal@45: bgneal@45: return o + ' />'; bgneal@45: }, bgneal@45: bgneal@45: remove : function(node, keep_children) { bgneal@45: return this.run(node, function(node) { bgneal@45: var child, parent = node.parentNode; bgneal@45: bgneal@45: if (!parent) bgneal@45: return null; bgneal@45: bgneal@45: if (keep_children) { bgneal@45: while (child = node.firstChild) { bgneal@45: // IE 8 will crash if you don't remove completely empty text nodes bgneal@45: if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue) bgneal@45: parent.insertBefore(child, node); bgneal@45: else bgneal@45: node.removeChild(child); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return parent.removeChild(node); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: setStyle : function(n, na, v) { bgneal@45: var t = this; bgneal@45: bgneal@45: return t.run(n, function(e) { bgneal@45: var s, i; bgneal@45: bgneal@45: s = e.style; bgneal@45: bgneal@45: // Camelcase it, if needed bgneal@45: na = na.replace(/-(\D)/g, function(a, b){ bgneal@45: return b.toUpperCase(); bgneal@45: }); bgneal@45: bgneal@45: // Default px suffix on these bgneal@45: if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v))) bgneal@45: v += 'px'; bgneal@45: bgneal@45: switch (na) { bgneal@45: case 'opacity': bgneal@45: // IE specific opacity bgneal@45: if (isIE) { bgneal@45: s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")"; bgneal@45: bgneal@45: if (!n.currentStyle || !n.currentStyle.hasLayout) bgneal@45: s.display = 'inline-block'; bgneal@45: } bgneal@45: bgneal@45: // Fix for older browsers bgneal@45: s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || ''; bgneal@45: break; bgneal@45: bgneal@45: case 'float': bgneal@45: isIE ? s.styleFloat = v : s.cssFloat = v; bgneal@45: break; bgneal@45: bgneal@45: default: bgneal@45: s[na] = v || ''; bgneal@45: } bgneal@45: bgneal@45: // Force update of the style data bgneal@45: if (t.settings.update_styles) bgneal@45: t.setAttrib(e, 'data-mce-style'); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: getStyle : function(n, na, c) { bgneal@45: n = this.get(n); bgneal@45: bgneal@45: if (!n) bgneal@45: return; bgneal@45: bgneal@45: // Gecko bgneal@45: if (this.doc.defaultView && c) { bgneal@45: // Remove camelcase bgneal@45: na = na.replace(/[A-Z]/g, function(a){ bgneal@45: return '-' + a; bgneal@45: }); bgneal@45: bgneal@45: try { bgneal@45: return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na); bgneal@45: } catch (ex) { bgneal@45: // Old safari might fail bgneal@45: return null; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Camelcase it, if needed bgneal@45: na = na.replace(/-(\D)/g, function(a, b){ bgneal@45: return b.toUpperCase(); bgneal@45: }); bgneal@45: bgneal@45: if (na == 'float') bgneal@45: na = isIE ? 'styleFloat' : 'cssFloat'; bgneal@45: bgneal@45: // IE & Opera bgneal@45: if (n.currentStyle && c) bgneal@45: return n.currentStyle[na]; bgneal@45: bgneal@45: return n.style ? n.style[na] : undefined; bgneal@45: }, bgneal@45: bgneal@45: setStyles : function(e, o) { bgneal@45: var t = this, s = t.settings, ol; bgneal@45: bgneal@45: ol = s.update_styles; bgneal@45: s.update_styles = 0; bgneal@45: bgneal@45: each(o, function(v, n) { bgneal@45: t.setStyle(e, n, v); bgneal@45: }); bgneal@45: bgneal@45: // Update style info bgneal@45: s.update_styles = ol; bgneal@45: if (s.update_styles) bgneal@45: t.setAttrib(e, s.cssText); bgneal@45: }, bgneal@45: bgneal@45: removeAllAttribs: function(e) { bgneal@45: return this.run(e, function(e) { bgneal@45: var i, attrs = e.attributes; bgneal@45: for (i = attrs.length - 1; i >= 0; i--) { bgneal@45: e.removeAttributeNode(attrs.item(i)); bgneal@45: } bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: setAttrib : function(e, n, v) { bgneal@45: var t = this; bgneal@45: bgneal@45: // Whats the point bgneal@45: if (!e || !n) bgneal@45: return; bgneal@45: bgneal@45: // Strict XML mode bgneal@45: if (t.settings.strict) bgneal@45: n = n.toLowerCase(); bgneal@45: bgneal@45: return this.run(e, function(e) { bgneal@45: var s = t.settings; bgneal@45: var originalValue = e.getAttribute(n); bgneal@45: if (v !== null) { bgneal@45: switch (n) { bgneal@45: case "style": bgneal@45: if (!is(v, 'string')) { bgneal@45: each(v, function(v, n) { bgneal@45: t.setStyle(e, n, v); bgneal@45: }); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // No mce_style for elements with these since they might get resized by the user bgneal@45: if (s.keep_values) { bgneal@45: if (v && !t._isRes(v)) bgneal@45: e.setAttribute('data-mce-style', v, 2); bgneal@45: else bgneal@45: e.removeAttribute('data-mce-style', 2); bgneal@45: } bgneal@45: bgneal@45: e.style.cssText = v; bgneal@45: break; bgneal@45: bgneal@45: case "class": bgneal@45: e.className = v || ''; // Fix IE null bug bgneal@45: break; bgneal@45: bgneal@45: case "src": bgneal@45: case "href": bgneal@45: if (s.keep_values) { bgneal@45: if (s.url_converter) bgneal@45: v = s.url_converter.call(s.url_converter_scope || t, v, n, e); bgneal@45: bgneal@45: t.setAttrib(e, 'data-mce-' + n, v, 2); bgneal@45: } bgneal@45: bgneal@45: break; bgneal@45: bgneal@45: case "shape": bgneal@45: e.setAttribute('data-mce-style', v); bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: if (is(v) && v !== null && v.length !== 0) bgneal@45: e.setAttribute(n, '' + v, 2); bgneal@45: else bgneal@45: e.removeAttribute(n, 2); bgneal@45: bgneal@45: // fire onChangeAttrib event for attributes that have changed bgneal@45: if (tinyMCE.activeEditor && originalValue != v) { bgneal@45: var ed = tinyMCE.activeEditor; bgneal@45: ed.onSetAttrib.dispatch(ed, e, n, v); bgneal@45: } bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: setAttribs : function(e, o) { bgneal@45: var t = this; bgneal@45: bgneal@45: return this.run(e, function(e) { bgneal@45: each(o, function(v, n) { bgneal@45: t.setAttrib(e, n, v); bgneal@45: }); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: getAttrib : function(e, n, dv) { bgneal@45: var v, t = this, undef; bgneal@45: bgneal@45: e = t.get(e); bgneal@45: bgneal@45: if (!e || e.nodeType !== 1) bgneal@45: return dv === undef ? false : dv; bgneal@45: bgneal@45: if (!is(dv)) bgneal@45: dv = ''; bgneal@45: bgneal@45: // Try the mce variant for these bgneal@45: if (/^(src|href|style|coords|shape)$/.test(n)) { bgneal@45: v = e.getAttribute("data-mce-" + n); bgneal@45: bgneal@45: if (v) bgneal@45: return v; bgneal@45: } bgneal@45: bgneal@45: if (isIE && t.props[n]) { bgneal@45: v = e[t.props[n]]; bgneal@45: v = v && v.nodeValue ? v.nodeValue : v; bgneal@45: } bgneal@45: bgneal@45: if (!v) bgneal@45: v = e.getAttribute(n, 2); bgneal@45: bgneal@45: // Check boolean attribs bgneal@45: if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) { bgneal@45: if (e[t.props[n]] === true && v === '') bgneal@45: return n; bgneal@45: bgneal@45: return v ? n : ''; bgneal@45: } bgneal@45: bgneal@45: // Inner input elements will override attributes on form elements bgneal@45: if (e.nodeName === "FORM" && e.getAttributeNode(n)) bgneal@45: return e.getAttributeNode(n).nodeValue; bgneal@45: bgneal@45: if (n === 'style') { bgneal@45: v = v || e.style.cssText; bgneal@45: bgneal@45: if (v) { bgneal@45: v = t.serializeStyle(t.parseStyle(v), e.nodeName); bgneal@45: bgneal@45: if (t.settings.keep_values && !t._isRes(v)) bgneal@45: e.setAttribute('data-mce-style', v); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Remove Apple and WebKit stuff bgneal@45: if (isWebKit && n === "class" && v) bgneal@45: v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, ''); bgneal@45: bgneal@45: // Handle IE issues bgneal@45: if (isIE) { bgneal@45: switch (n) { bgneal@45: case 'rowspan': bgneal@45: case 'colspan': bgneal@45: // IE returns 1 as default value bgneal@45: if (v === 1) bgneal@45: v = ''; bgneal@45: bgneal@45: break; bgneal@45: bgneal@45: case 'size': bgneal@45: // IE returns +0 as default value for size bgneal@45: if (v === '+0' || v === 20 || v === 0) bgneal@45: v = ''; bgneal@45: bgneal@45: break; bgneal@45: bgneal@45: case 'width': bgneal@45: case 'height': bgneal@45: case 'vspace': bgneal@45: case 'checked': bgneal@45: case 'disabled': bgneal@45: case 'readonly': bgneal@45: if (v === 0) bgneal@45: v = ''; bgneal@45: bgneal@45: break; bgneal@45: bgneal@45: case 'hspace': bgneal@45: // IE returns -1 as default value bgneal@45: if (v === -1) bgneal@45: v = ''; bgneal@45: bgneal@45: break; bgneal@45: bgneal@45: case 'maxlength': bgneal@45: case 'tabindex': bgneal@45: // IE returns default value bgneal@45: if (v === 32768 || v === 2147483647 || v === '32768') bgneal@45: v = ''; bgneal@45: bgneal@45: break; bgneal@45: bgneal@45: case 'multiple': bgneal@45: case 'compact': bgneal@45: case 'noshade': bgneal@45: case 'nowrap': bgneal@45: if (v === 65535) bgneal@45: return n; bgneal@45: bgneal@45: return dv; bgneal@45: bgneal@45: case 'shape': bgneal@45: v = v.toLowerCase(); bgneal@45: break; bgneal@45: bgneal@45: default: bgneal@45: // IE has odd anonymous function for event attributes bgneal@45: if (n.indexOf('on') === 0 && v) bgneal@45: v = tinymce._replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1', '' + v); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return (v !== undef && v !== null && v !== '') ? '' + v : dv; bgneal@45: }, bgneal@45: bgneal@45: getPos : function(n, ro) { bgneal@45: var t = this, x = 0, y = 0, e, d = t.doc, r; bgneal@45: bgneal@45: n = t.get(n); bgneal@45: ro = ro || d.body; bgneal@45: bgneal@45: if (n) { bgneal@45: // Use getBoundingClientRect if it exists since it's faster than looping offset nodes bgneal@45: if (n.getBoundingClientRect) { bgneal@45: n = n.getBoundingClientRect(); bgneal@45: e = t.boxModel ? d.documentElement : d.body; bgneal@45: bgneal@45: // Add scroll offsets from documentElement or body since IE with the wrong box model will use d.body and so do WebKit bgneal@45: // Also remove the body/documentelement clientTop/clientLeft on IE 6, 7 since they offset the position bgneal@45: x = n.left + (d.documentElement.scrollLeft || d.body.scrollLeft) - e.clientTop; bgneal@45: y = n.top + (d.documentElement.scrollTop || d.body.scrollTop) - e.clientLeft; bgneal@45: bgneal@45: return {x : x, y : y}; bgneal@45: } bgneal@45: bgneal@45: r = n; bgneal@45: while (r && r != ro && r.nodeType) { bgneal@45: x += r.offsetLeft || 0; bgneal@45: y += r.offsetTop || 0; bgneal@45: r = r.offsetParent; bgneal@45: } bgneal@45: bgneal@45: r = n.parentNode; bgneal@45: while (r && r != ro && r.nodeType) { bgneal@45: x -= r.scrollLeft || 0; bgneal@45: y -= r.scrollTop || 0; bgneal@45: r = r.parentNode; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return {x : x, y : y}; bgneal@45: }, bgneal@45: bgneal@45: parseStyle : function(st) { bgneal@45: return this.styles.parse(st); bgneal@45: }, bgneal@45: bgneal@45: serializeStyle : function(o, name) { bgneal@45: return this.styles.serialize(o, name); bgneal@45: }, bgneal@45: bgneal@45: loadCSS : function(u) { bgneal@45: var t = this, d = t.doc, head; bgneal@45: bgneal@45: if (!u) bgneal@45: u = ''; bgneal@45: bgneal@45: head = t.select('head')[0]; bgneal@45: bgneal@45: each(u.split(','), function(u) { bgneal@45: var link; bgneal@45: bgneal@45: if (t.files[u]) bgneal@45: return; bgneal@45: bgneal@45: t.files[u] = true; bgneal@45: link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)}); bgneal@45: bgneal@45: // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug bgneal@45: // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading bgneal@45: // It's ugly but it seems to work fine. bgneal@45: if (isIE && d.documentMode && d.recalc) { bgneal@45: link.onload = function() { bgneal@45: if (d.recalc) bgneal@45: d.recalc(); bgneal@45: bgneal@45: link.onload = null; bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: head.appendChild(link); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: addClass : function(e, c) { bgneal@45: return this.run(e, function(e) { bgneal@45: var o; bgneal@45: bgneal@45: if (!c) bgneal@45: return 0; bgneal@45: bgneal@45: if (this.hasClass(e, c)) bgneal@45: return e.className; bgneal@45: bgneal@45: o = this.removeClass(e, c); bgneal@45: bgneal@45: return e.className = (o != '' ? (o + ' ') : '') + c; bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: removeClass : function(e, c) { bgneal@45: var t = this, re; bgneal@45: bgneal@45: return t.run(e, function(e) { bgneal@45: var v; bgneal@45: bgneal@45: if (t.hasClass(e, c)) { bgneal@45: if (!re) bgneal@45: re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g"); bgneal@45: bgneal@45: v = e.className.replace(re, ' '); bgneal@45: v = tinymce.trim(v != ' ' ? v : ''); bgneal@45: bgneal@45: e.className = v; bgneal@45: bgneal@45: // Empty class attr bgneal@45: if (!v) { bgneal@45: e.removeAttribute('class'); bgneal@45: e.removeAttribute('className'); bgneal@45: } bgneal@45: bgneal@45: return v; bgneal@45: } bgneal@45: bgneal@45: return e.className; bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: hasClass : function(n, c) { bgneal@45: n = this.get(n); bgneal@45: bgneal@45: if (!n || !c) bgneal@45: return false; bgneal@45: bgneal@45: return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1; bgneal@45: }, bgneal@45: bgneal@45: show : function(e) { bgneal@45: return this.setStyle(e, 'display', 'block'); bgneal@45: }, bgneal@45: bgneal@45: hide : function(e) { bgneal@45: return this.setStyle(e, 'display', 'none'); bgneal@45: }, bgneal@45: bgneal@45: isHidden : function(e) { bgneal@45: e = this.get(e); bgneal@45: bgneal@45: return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none'; bgneal@45: }, bgneal@45: bgneal@45: uniqueId : function(p) { bgneal@45: return (!p ? 'mce_' : p) + (this.counter++); bgneal@45: }, bgneal@45: bgneal@45: setHTML : function(element, html) { bgneal@45: var self = this; bgneal@45: bgneal@45: return self.run(element, function(element) { bgneal@45: if (isIE) { bgneal@45: // Remove all child nodes, IE keeps empty text nodes in DOM bgneal@45: while (element.firstChild) bgneal@45: element.removeChild(element.firstChild); bgneal@45: bgneal@45: try { bgneal@45: // IE will remove comments from the beginning bgneal@45: // unless you padd the contents with something bgneal@45: element.innerHTML = '
    ' + html; bgneal@45: element.removeChild(element.firstChild); bgneal@45: } catch (ex) { bgneal@45: // 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@45: // This seems to fix this problem bgneal@45: bgneal@45: // Create new div with HTML contents and a BR infront to keep comments bgneal@45: element = self.create('div'); bgneal@45: element.innerHTML = '
    ' + html; bgneal@45: bgneal@45: // Add all children from div to target bgneal@45: each (element.childNodes, function(node, i) { bgneal@45: // Skip br element bgneal@45: if (i) bgneal@45: element.appendChild(node); bgneal@45: }); bgneal@45: } bgneal@45: } else bgneal@45: element.innerHTML = html; bgneal@45: bgneal@45: return html; bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: getOuterHTML : function(elm) { bgneal@45: var doc, self = this; bgneal@45: bgneal@45: elm = self.get(elm); bgneal@45: bgneal@45: if (!elm) bgneal@45: return null; bgneal@45: bgneal@45: if (elm.nodeType === 1 && self.hasOuterHTML) bgneal@45: return elm.outerHTML; bgneal@45: bgneal@45: doc = (elm.ownerDocument || self.doc).createElement("body"); bgneal@45: doc.appendChild(elm.cloneNode(true)); bgneal@45: bgneal@45: return doc.innerHTML; bgneal@45: }, bgneal@45: bgneal@45: setOuterHTML : function(e, h, d) { bgneal@45: var t = this; bgneal@45: bgneal@45: function setHTML(e, h, d) { bgneal@45: var n, tp; bgneal@45: bgneal@45: tp = d.createElement("body"); bgneal@45: tp.innerHTML = h; bgneal@45: bgneal@45: n = tp.lastChild; bgneal@45: while (n) { bgneal@45: t.insertAfter(n.cloneNode(true), e); bgneal@45: n = n.previousSibling; bgneal@45: } bgneal@45: bgneal@45: t.remove(e); bgneal@45: }; bgneal@45: bgneal@45: return this.run(e, function(e) { bgneal@45: e = t.get(e); bgneal@45: bgneal@45: // Only set HTML on elements bgneal@45: if (e.nodeType == 1) { bgneal@45: d = d || e.ownerDocument || t.doc; bgneal@45: bgneal@45: if (isIE) { bgneal@45: try { bgneal@45: // Try outerHTML for IE it sometimes produces an unknown runtime error bgneal@45: if (isIE && e.nodeType == 1) bgneal@45: e.outerHTML = h; bgneal@45: else bgneal@45: setHTML(e, h, d); bgneal@45: } catch (ex) { bgneal@45: // Fix for unknown runtime error bgneal@45: setHTML(e, h, d); bgneal@45: } bgneal@45: } else bgneal@45: setHTML(e, h, d); bgneal@45: } bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: decode : Entities.decode, bgneal@45: bgneal@45: encode : Entities.encodeAllRaw, bgneal@45: bgneal@45: insertAfter : function(node, reference_node) { bgneal@45: reference_node = this.get(reference_node); bgneal@45: bgneal@45: return this.run(node, function(node) { bgneal@45: var parent, nextSibling; bgneal@45: bgneal@45: parent = reference_node.parentNode; bgneal@45: nextSibling = reference_node.nextSibling; bgneal@45: bgneal@45: if (nextSibling) bgneal@45: parent.insertBefore(node, nextSibling); bgneal@45: else bgneal@45: parent.appendChild(node); bgneal@45: bgneal@45: return node; bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: replace : function(n, o, k) { bgneal@45: var t = this; bgneal@45: bgneal@45: if (is(o, 'array')) bgneal@45: n = n.cloneNode(true); bgneal@45: bgneal@45: return t.run(o, function(o) { bgneal@45: if (k) { bgneal@45: each(tinymce.grep(o.childNodes), function(c) { bgneal@45: n.appendChild(c); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: return o.parentNode.replaceChild(n, o); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: rename : function(elm, name) { bgneal@45: var t = this, newElm; bgneal@45: bgneal@45: if (elm.nodeName != name.toUpperCase()) { bgneal@45: // Rename block element bgneal@45: newElm = t.create(name); bgneal@45: bgneal@45: // Copy attribs to new block bgneal@45: each(t.getAttribs(elm), function(attr_node) { bgneal@45: t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName)); bgneal@45: }); bgneal@45: bgneal@45: // Replace block bgneal@45: t.replace(newElm, elm, 1); bgneal@45: } bgneal@45: bgneal@45: return newElm || elm; bgneal@45: }, bgneal@45: bgneal@45: findCommonAncestor : function(a, b) { bgneal@45: var ps = a, pe; bgneal@45: bgneal@45: while (ps) { bgneal@45: pe = b; bgneal@45: bgneal@45: while (pe && ps != pe) bgneal@45: pe = pe.parentNode; bgneal@45: bgneal@45: if (ps == pe) bgneal@45: break; bgneal@45: bgneal@45: ps = ps.parentNode; bgneal@45: } bgneal@45: bgneal@45: if (!ps && a.ownerDocument) bgneal@45: return a.ownerDocument.documentElement; bgneal@45: bgneal@45: return ps; bgneal@45: }, bgneal@45: bgneal@45: toHex : function(s) { bgneal@45: var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s); bgneal@45: bgneal@45: function hex(s) { bgneal@45: s = parseInt(s).toString(16); bgneal@45: bgneal@45: return s.length > 1 ? s : '0' + s; // 0 -> 00 bgneal@45: }; bgneal@45: bgneal@45: if (c) { bgneal@45: s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]); bgneal@45: bgneal@45: return s; bgneal@45: } bgneal@45: bgneal@45: return s; bgneal@45: }, bgneal@45: bgneal@45: getClasses : function() { bgneal@45: var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov; bgneal@45: bgneal@45: if (t.classes) bgneal@45: return t.classes; bgneal@45: bgneal@45: function addClasses(s) { bgneal@45: // IE style imports bgneal@45: each(s.imports, function(r) { bgneal@45: addClasses(r); bgneal@45: }); bgneal@45: bgneal@45: each(s.cssRules || s.rules, function(r) { bgneal@45: // Real type or fake it on IE bgneal@45: switch (r.type || 1) { bgneal@45: // Rule bgneal@45: case 1: bgneal@45: if (r.selectorText) { bgneal@45: each(r.selectorText.split(','), function(v) { bgneal@45: v = v.replace(/^\s*|\s*$|^\s\./g, ""); bgneal@45: bgneal@45: // Is internal or it doesn't contain a class bgneal@45: if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v)) bgneal@45: return; bgneal@45: bgneal@45: // Remove everything but class name bgneal@45: ov = v; bgneal@45: v = tinymce._replace(/.*\.([a-z0-9_\-]+).*/i, '$1', v); bgneal@45: bgneal@45: // Filter classes bgneal@45: if (f && !(v = f(v, ov))) bgneal@45: return; bgneal@45: bgneal@45: if (!lo[v]) { bgneal@45: cl.push({'class' : v}); bgneal@45: lo[v] = 1; bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: break; bgneal@45: bgneal@45: // Import bgneal@45: case 3: bgneal@45: addClasses(r.styleSheet); bgneal@45: break; bgneal@45: } bgneal@45: }); bgneal@45: }; bgneal@45: bgneal@45: try { bgneal@45: each(t.doc.styleSheets, addClasses); bgneal@45: } catch (ex) { bgneal@45: // Ignore bgneal@45: } bgneal@45: bgneal@45: if (cl.length > 0) bgneal@45: t.classes = cl; bgneal@45: bgneal@45: return cl; bgneal@45: }, bgneal@45: bgneal@45: run : function(e, f, s) { bgneal@45: var t = this, o; bgneal@45: bgneal@45: if (t.doc && typeof(e) === 'string') bgneal@45: e = t.get(e); bgneal@45: bgneal@45: if (!e) bgneal@45: return false; bgneal@45: bgneal@45: s = s || this; bgneal@45: if (!e.nodeType && (e.length || e.length === 0)) { bgneal@45: o = []; bgneal@45: bgneal@45: each(e, function(e, i) { bgneal@45: if (e) { bgneal@45: if (typeof(e) == 'string') bgneal@45: e = t.doc.getElementById(e); bgneal@45: bgneal@45: o.push(f.call(s, e, i)); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: return o; bgneal@45: } bgneal@45: bgneal@45: return f.call(s, e); bgneal@45: }, bgneal@45: bgneal@45: getAttribs : function(n) { bgneal@45: var o; bgneal@45: bgneal@45: n = this.get(n); bgneal@45: bgneal@45: if (!n) bgneal@45: return []; bgneal@45: bgneal@45: if (isIE) { bgneal@45: o = []; bgneal@45: bgneal@45: // Object will throw exception in IE bgneal@45: if (n.nodeName == 'OBJECT') bgneal@45: return n.attributes; bgneal@45: bgneal@45: // IE doesn't keep the selected attribute if you clone option elements bgneal@45: if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected')) bgneal@45: o.push({specified : 1, nodeName : 'selected'}); bgneal@45: bgneal@45: // It's crazy that this is faster in IE but it's because it returns all attributes all the time bgneal@45: n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) { bgneal@45: o.push({specified : 1, nodeName : a}); bgneal@45: }); bgneal@45: bgneal@45: return o; bgneal@45: } bgneal@45: bgneal@45: return n.attributes; bgneal@45: }, bgneal@45: bgneal@45: isEmpty : function(node, elements) { bgneal@45: var self = this, i, attributes, type, walker, name, parentNode; bgneal@45: bgneal@45: node = node.firstChild; bgneal@45: if (node) { bgneal@45: walker = new tinymce.dom.TreeWalker(node, node.parentNode); bgneal@45: elements = elements || self.schema ? self.schema.getNonEmptyElements() : null; bgneal@45: bgneal@45: do { bgneal@45: type = node.nodeType; bgneal@45: bgneal@45: if (type === 1) { bgneal@45: // Ignore bogus elements bgneal@45: if (node.getAttribute('data-mce-bogus')) bgneal@45: continue; bgneal@45: bgneal@45: // Keep empty elements like bgneal@45: name = node.nodeName.toLowerCase(); bgneal@45: if (elements && elements[name]) { bgneal@45: // Ignore single BR elements in blocks like


    bgneal@45: parentNode = node.parentNode; bgneal@45: if (name === 'br' && self.isBlock(parentNode) && parentNode.firstChild === node && parentNode.lastChild === node) { bgneal@45: continue; bgneal@45: } bgneal@45: bgneal@45: return false; bgneal@45: } bgneal@45: bgneal@45: // Keep elements with data-bookmark attributes or name attribute like
    bgneal@45: attributes = self.getAttribs(node); bgneal@45: i = node.attributes.length; bgneal@45: while (i--) { bgneal@45: name = node.attributes[i].nodeName; bgneal@45: if (name === "name" || name === 'data-mce-bookmark') bgneal@45: return false; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Keep comment nodes bgneal@45: if (type == 8) bgneal@45: return false; bgneal@45: bgneal@45: // Keep non whitespace text nodes bgneal@45: if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue))) bgneal@45: return false; bgneal@45: } while (node = walker.next()); bgneal@45: } bgneal@45: bgneal@45: return true; bgneal@45: }, bgneal@45: bgneal@45: destroy : function(s) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.win = t.doc = t.root = t.events = t.frag = null; bgneal@45: bgneal@45: // Manual destroy then remove unload handler bgneal@45: if (!s) bgneal@45: tinymce.removeUnload(t.destroy); bgneal@45: }, bgneal@45: bgneal@45: createRng : function() { bgneal@45: var d = this.doc; bgneal@45: bgneal@45: return d.createRange ? d.createRange() : new tinymce.dom.Range(this); bgneal@45: }, bgneal@45: bgneal@45: nodeIndex : function(node, normalized) { bgneal@45: var idx = 0, lastNodeType, lastNode, nodeType; bgneal@45: bgneal@45: if (node) { bgneal@45: for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) { bgneal@45: nodeType = node.nodeType; bgneal@45: bgneal@45: // Normalize text nodes bgneal@45: if (normalized && nodeType == 3) { bgneal@45: if (nodeType == lastNodeType || !node.nodeValue.length) bgneal@45: continue; bgneal@45: } bgneal@45: idx++; bgneal@45: lastNodeType = nodeType; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return idx; bgneal@45: }, bgneal@45: bgneal@45: split : function(pe, e, re) { bgneal@45: var t = this, r = t.createRng(), bef, aft, pa; bgneal@45: bgneal@45: // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense bgneal@45: // but we don't want that in our code since it serves no purpose for the end user bgneal@45: // For example if this is chopped: bgneal@45: //

    text 1CHOPtext 2

    bgneal@45: // would produce: bgneal@45: //

    text 1

    CHOP

    text 2

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

    text 1

    CHOP

    text 2

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

    " bgneal@45: // Also keep text nodes with only spaces if surrounded by spans. bgneal@45: // eg. "

    a b

    " should keep space between a and b bgneal@45: var trimmedLength = tinymce.trim(node.nodeValue).length; bgneal@45: if (!t.isBlock(node.parentNode) || trimmedLength > 0 || trimmedLength == 0 && surroundedBySpans(node)) bgneal@45: return; bgneal@45: } else if (type == 1) { bgneal@45: // If the only child is a bookmark then move it up bgneal@45: children = node.childNodes; bgneal@45: if (children.length == 1 && children[0] && children[0].nodeType == 1 && children[0].getAttribute('data-mce-type') == 'bookmark') bgneal@45: node.parentNode.insertBefore(children[0], node); bgneal@45: bgneal@45: // Keep non empty elements or img, hr etc bgneal@45: if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName)) bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: t.remove(node); bgneal@45: } bgneal@45: bgneal@45: return node; bgneal@45: }; bgneal@45: bgneal@45: if (pe && e) { bgneal@45: // Get before chunk bgneal@45: r.setStart(pe.parentNode, t.nodeIndex(pe)); bgneal@45: r.setEnd(e.parentNode, t.nodeIndex(e)); bgneal@45: bef = r.extractContents(); bgneal@45: bgneal@45: // Get after chunk bgneal@45: r = t.createRng(); bgneal@45: r.setStart(e.parentNode, t.nodeIndex(e) + 1); bgneal@45: r.setEnd(pe.parentNode, t.nodeIndex(pe) + 1); bgneal@45: aft = r.extractContents(); bgneal@45: bgneal@45: // Insert before chunk bgneal@45: pa = pe.parentNode; bgneal@45: pa.insertBefore(trim(bef), pe); bgneal@45: bgneal@45: // Insert middle chunk bgneal@45: if (re) bgneal@45: pa.replaceChild(re, e); bgneal@45: else bgneal@45: pa.insertBefore(e, pe); bgneal@45: bgneal@45: // Insert after chunk bgneal@45: pa.insertBefore(trim(aft), pe); bgneal@45: t.remove(pe); bgneal@45: bgneal@45: return re || e; bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: bind : function(target, name, func, scope) { bgneal@45: return this.events.add(target, name, func, scope || this); bgneal@45: }, bgneal@45: bgneal@45: unbind : function(target, name, func) { bgneal@45: return this.events.remove(target, name, func); bgneal@45: }, bgneal@45: bgneal@45: fire : function(target, name, evt) { bgneal@45: return this.events.fire(target, name, evt); bgneal@45: }, bgneal@45: bgneal@45: bgneal@45: _findSib : function(node, selector, name) { bgneal@45: var t = this, f = selector; bgneal@45: bgneal@45: if (node) { bgneal@45: // If expression make a function of it using is bgneal@45: if (is(f, 'string')) { bgneal@45: f = function(node) { bgneal@45: return t.is(node, selector); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: // Loop all siblings bgneal@45: for (node = node[name]; node; node = node[name]) { bgneal@45: if (f(node)) bgneal@45: return node; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return null; bgneal@45: }, bgneal@45: bgneal@45: _isRes : function(c) { bgneal@45: // Is live resizble element bgneal@45: return /^(top|left|bottom|right|width|height)/i.test(c) || /;\s*(top|left|bottom|right|width|height)/i.test(c); bgneal@45: } bgneal@45: bgneal@45: /* bgneal@45: walk : function(n, f, s) { bgneal@45: var d = this.doc, w; bgneal@45: bgneal@45: if (d.createTreeWalker) { bgneal@45: w = d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false); bgneal@45: bgneal@45: while ((n = w.nextNode()) != null) bgneal@45: f.call(s || this, n); bgneal@45: } else bgneal@45: tinymce.walk(n, f, 'childNodes', s); bgneal@45: } bgneal@45: */ bgneal@45: bgneal@45: /* bgneal@45: toRGB : function(s) { bgneal@45: var c = /^\s*?#([0-9A-F]{2})([0-9A-F]{1,2})([0-9A-F]{2})?\s*?$/.exec(s); bgneal@45: bgneal@45: if (c) { bgneal@45: // #FFF -> #FFFFFF bgneal@45: if (!is(c[3])) bgneal@45: c[3] = c[2] = c[1]; bgneal@45: bgneal@45: return "rgb(" + parseInt(c[1], 16) + "," + parseInt(c[2], 16) + "," + parseInt(c[3], 16) + ")"; bgneal@45: } bgneal@45: bgneal@45: return s; bgneal@45: } bgneal@45: */ bgneal@45: }); bgneal@45: bgneal@45: tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0}); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(ns) { bgneal@45: // Range constructor bgneal@45: function Range(dom) { bgneal@45: var t = this, bgneal@45: doc = dom.doc, bgneal@45: EXTRACT = 0, bgneal@45: CLONE = 1, bgneal@45: DELETE = 2, bgneal@45: TRUE = true, bgneal@45: FALSE = false, bgneal@45: START_OFFSET = 'startOffset', bgneal@45: START_CONTAINER = 'startContainer', bgneal@45: END_CONTAINER = 'endContainer', bgneal@45: END_OFFSET = 'endOffset', bgneal@45: extend = tinymce.extend, bgneal@45: nodeIndex = dom.nodeIndex; bgneal@45: bgneal@45: extend(t, { bgneal@45: // Inital states bgneal@45: startContainer : doc, bgneal@45: startOffset : 0, bgneal@45: endContainer : doc, bgneal@45: endOffset : 0, bgneal@45: collapsed : TRUE, bgneal@45: commonAncestorContainer : doc, bgneal@45: bgneal@45: // Range constants bgneal@45: START_TO_START : 0, bgneal@45: START_TO_END : 1, bgneal@45: END_TO_END : 2, bgneal@45: END_TO_START : 3, bgneal@45: bgneal@45: // Public methods bgneal@45: setStart : setStart, bgneal@45: setEnd : setEnd, bgneal@45: setStartBefore : setStartBefore, bgneal@45: setStartAfter : setStartAfter, bgneal@45: setEndBefore : setEndBefore, bgneal@45: setEndAfter : setEndAfter, bgneal@45: collapse : collapse, bgneal@45: selectNode : selectNode, bgneal@45: selectNodeContents : selectNodeContents, bgneal@45: compareBoundaryPoints : compareBoundaryPoints, bgneal@45: deleteContents : deleteContents, bgneal@45: extractContents : extractContents, bgneal@45: cloneContents : cloneContents, bgneal@45: insertNode : insertNode, bgneal@45: surroundContents : surroundContents, bgneal@45: cloneRange : cloneRange bgneal@45: }); bgneal@45: bgneal@45: function createDocumentFragment() { bgneal@45: return doc.createDocumentFragment(); bgneal@45: }; bgneal@45: bgneal@45: function setStart(n, o) { bgneal@45: _setEndPoint(TRUE, n, o); bgneal@45: }; bgneal@45: bgneal@45: function setEnd(n, o) { bgneal@45: _setEndPoint(FALSE, n, o); bgneal@45: }; bgneal@45: bgneal@45: function setStartBefore(n) { bgneal@45: setStart(n.parentNode, nodeIndex(n)); bgneal@45: }; bgneal@45: bgneal@45: function setStartAfter(n) { bgneal@45: setStart(n.parentNode, nodeIndex(n) + 1); bgneal@45: }; bgneal@45: bgneal@45: function setEndBefore(n) { bgneal@45: setEnd(n.parentNode, nodeIndex(n)); bgneal@45: }; bgneal@45: bgneal@45: function setEndAfter(n) { bgneal@45: setEnd(n.parentNode, nodeIndex(n) + 1); bgneal@45: }; bgneal@45: bgneal@45: function collapse(ts) { bgneal@45: if (ts) { bgneal@45: t[END_CONTAINER] = t[START_CONTAINER]; bgneal@45: t[END_OFFSET] = t[START_OFFSET]; bgneal@45: } else { bgneal@45: t[START_CONTAINER] = t[END_CONTAINER]; bgneal@45: t[START_OFFSET] = t[END_OFFSET]; bgneal@45: } bgneal@45: bgneal@45: t.collapsed = TRUE; bgneal@45: }; bgneal@45: bgneal@45: function selectNode(n) { bgneal@45: setStartBefore(n); bgneal@45: setEndAfter(n); bgneal@45: }; bgneal@45: bgneal@45: function selectNodeContents(n) { bgneal@45: setStart(n, 0); bgneal@45: setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length); bgneal@45: }; bgneal@45: bgneal@45: function compareBoundaryPoints(h, r) { bgneal@45: var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET], bgneal@45: rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset; bgneal@45: bgneal@45: // Check START_TO_START bgneal@45: if (h === 0) bgneal@45: return _compareBoundaryPoints(sc, so, rsc, rso); bgneal@45: bgneal@45: // Check START_TO_END bgneal@45: if (h === 1) bgneal@45: return _compareBoundaryPoints(ec, eo, rsc, rso); bgneal@45: bgneal@45: // Check END_TO_END bgneal@45: if (h === 2) bgneal@45: return _compareBoundaryPoints(ec, eo, rec, reo); bgneal@45: bgneal@45: // Check END_TO_START bgneal@45: if (h === 3) bgneal@45: return _compareBoundaryPoints(sc, so, rec, reo); bgneal@45: }; bgneal@45: bgneal@45: function deleteContents() { bgneal@45: _traverse(DELETE); bgneal@45: }; bgneal@45: bgneal@45: function extractContents() { bgneal@45: return _traverse(EXTRACT); bgneal@45: }; bgneal@45: bgneal@45: function cloneContents() { bgneal@45: return _traverse(CLONE); bgneal@45: }; bgneal@45: bgneal@45: function insertNode(n) { bgneal@45: var startContainer = this[START_CONTAINER], bgneal@45: startOffset = this[START_OFFSET], nn, o; bgneal@45: bgneal@45: // Node is TEXT_NODE or CDATA bgneal@45: if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) { bgneal@45: if (!startOffset) { bgneal@45: // At the start of text bgneal@45: startContainer.parentNode.insertBefore(n, startContainer); bgneal@45: } else if (startOffset >= startContainer.nodeValue.length) { bgneal@45: // At the end of text bgneal@45: dom.insertAfter(n, startContainer); bgneal@45: } else { bgneal@45: // Middle, need to split bgneal@45: nn = startContainer.splitText(startOffset); bgneal@45: startContainer.parentNode.insertBefore(n, nn); bgneal@45: } bgneal@45: } else { bgneal@45: // Insert element node bgneal@45: if (startContainer.childNodes.length > 0) bgneal@45: o = startContainer.childNodes[startOffset]; bgneal@45: bgneal@45: if (o) bgneal@45: startContainer.insertBefore(n, o); bgneal@45: else bgneal@45: startContainer.appendChild(n); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function surroundContents(n) { bgneal@45: var f = t.extractContents(); bgneal@45: bgneal@45: t.insertNode(n); bgneal@45: n.appendChild(f); bgneal@45: t.selectNode(n); bgneal@45: }; bgneal@45: bgneal@45: function cloneRange() { bgneal@45: return extend(new Range(dom), { bgneal@45: startContainer : t[START_CONTAINER], bgneal@45: startOffset : t[START_OFFSET], bgneal@45: endContainer : t[END_CONTAINER], bgneal@45: endOffset : t[END_OFFSET], bgneal@45: collapsed : t.collapsed, bgneal@45: commonAncestorContainer : t.commonAncestorContainer bgneal@45: }); bgneal@45: }; bgneal@45: bgneal@45: // Private methods bgneal@45: bgneal@45: function _getSelectedNode(container, offset) { bgneal@45: var child; bgneal@45: bgneal@45: if (container.nodeType == 3 /* TEXT_NODE */) bgneal@45: return container; bgneal@45: bgneal@45: if (offset < 0) bgneal@45: return container; bgneal@45: bgneal@45: child = container.firstChild; bgneal@45: while (child && offset > 0) { bgneal@45: --offset; bgneal@45: child = child.nextSibling; bgneal@45: } bgneal@45: bgneal@45: if (child) bgneal@45: return child; bgneal@45: bgneal@45: return container; bgneal@45: }; bgneal@45: bgneal@45: function _isCollapsed() { bgneal@45: return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]); bgneal@45: }; bgneal@45: bgneal@45: function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) { bgneal@45: var c, offsetC, n, cmnRoot, childA, childB; bgneal@45: bgneal@45: // In the first case the boundary-points have the same container. A is before B bgneal@45: // if its offset is less than the offset of B, A is equal to B if its offset is bgneal@45: // equal to the offset of B, and A is after B if its offset is greater than the bgneal@45: // offset of B. bgneal@45: if (containerA == containerB) { bgneal@45: if (offsetA == offsetB) bgneal@45: return 0; // equal bgneal@45: bgneal@45: if (offsetA < offsetB) bgneal@45: return -1; // before bgneal@45: bgneal@45: return 1; // after bgneal@45: } bgneal@45: bgneal@45: // In the second case a child node C of the container of A is an ancestor bgneal@45: // container of B. In this case, A is before B if the offset of A is less than or bgneal@45: // equal to the index of the child node C and A is after B otherwise. bgneal@45: c = containerB; bgneal@45: while (c && c.parentNode != containerA) bgneal@45: c = c.parentNode; bgneal@45: bgneal@45: if (c) { bgneal@45: offsetC = 0; bgneal@45: n = containerA.firstChild; bgneal@45: bgneal@45: while (n != c && offsetC < offsetA) { bgneal@45: offsetC++; bgneal@45: n = n.nextSibling; bgneal@45: } bgneal@45: bgneal@45: if (offsetA <= offsetC) bgneal@45: return -1; // before bgneal@45: bgneal@45: return 1; // after bgneal@45: } bgneal@45: bgneal@45: // In the third case a child node C of the container of B is an ancestor container bgneal@45: // of A. In this case, A is before B if the index of the child node C is less than bgneal@45: // the offset of B and A is after B otherwise. bgneal@45: c = containerA; bgneal@45: while (c && c.parentNode != containerB) { bgneal@45: c = c.parentNode; bgneal@45: } bgneal@45: bgneal@45: if (c) { bgneal@45: offsetC = 0; bgneal@45: n = containerB.firstChild; bgneal@45: bgneal@45: while (n != c && offsetC < offsetB) { bgneal@45: offsetC++; bgneal@45: n = n.nextSibling; bgneal@45: } bgneal@45: bgneal@45: if (offsetC < offsetB) bgneal@45: return -1; // before bgneal@45: bgneal@45: return 1; // after bgneal@45: } bgneal@45: bgneal@45: // In the fourth case, none of three other cases hold: the containers of A and B bgneal@45: // are siblings or descendants of sibling nodes. In this case, A is before B if bgneal@45: // the container of A is before the container of B in a pre-order traversal of the bgneal@45: // Ranges' context tree and A is after B otherwise. bgneal@45: cmnRoot = dom.findCommonAncestor(containerA, containerB); bgneal@45: childA = containerA; bgneal@45: bgneal@45: while (childA && childA.parentNode != cmnRoot) bgneal@45: childA = childA.parentNode; bgneal@45: bgneal@45: if (!childA) bgneal@45: childA = cmnRoot; bgneal@45: bgneal@45: childB = containerB; bgneal@45: while (childB && childB.parentNode != cmnRoot) bgneal@45: childB = childB.parentNode; bgneal@45: bgneal@45: if (!childB) bgneal@45: childB = cmnRoot; bgneal@45: bgneal@45: if (childA == childB) bgneal@45: return 0; // equal bgneal@45: bgneal@45: n = cmnRoot.firstChild; bgneal@45: while (n) { bgneal@45: if (n == childA) bgneal@45: return -1; // before bgneal@45: bgneal@45: if (n == childB) bgneal@45: return 1; // after bgneal@45: bgneal@45: n = n.nextSibling; bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function _setEndPoint(st, n, o) { bgneal@45: var ec, sc; bgneal@45: bgneal@45: if (st) { bgneal@45: t[START_CONTAINER] = n; bgneal@45: t[START_OFFSET] = o; bgneal@45: } else { bgneal@45: t[END_CONTAINER] = n; bgneal@45: t[END_OFFSET] = o; bgneal@45: } bgneal@45: bgneal@45: // If one boundary-point of a Range is set to have a root container bgneal@45: // other than the current one for the Range, the Range is collapsed to bgneal@45: // the new position. This enforces the restriction that both boundary- bgneal@45: // points of a Range must have the same root container. bgneal@45: ec = t[END_CONTAINER]; bgneal@45: while (ec.parentNode) bgneal@45: ec = ec.parentNode; bgneal@45: bgneal@45: sc = t[START_CONTAINER]; bgneal@45: while (sc.parentNode) bgneal@45: sc = sc.parentNode; bgneal@45: bgneal@45: if (sc == ec) { bgneal@45: // The start position of a Range is guaranteed to never be after the bgneal@45: // end position. To enforce this restriction, if the start is set to bgneal@45: // be at a position after the end, the Range is collapsed to that bgneal@45: // position. bgneal@45: if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0) bgneal@45: t.collapse(st); bgneal@45: } else bgneal@45: t.collapse(st); bgneal@45: bgneal@45: t.collapsed = _isCollapsed(); bgneal@45: t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]); bgneal@45: }; bgneal@45: bgneal@45: function _traverse(how) { bgneal@45: var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep; bgneal@45: bgneal@45: if (t[START_CONTAINER] == t[END_CONTAINER]) bgneal@45: return _traverseSameContainer(how); bgneal@45: bgneal@45: for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) { bgneal@45: if (p == t[START_CONTAINER]) bgneal@45: return _traverseCommonStartContainer(c, how); bgneal@45: bgneal@45: ++endContainerDepth; bgneal@45: } bgneal@45: bgneal@45: for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) { bgneal@45: if (p == t[END_CONTAINER]) bgneal@45: return _traverseCommonEndContainer(c, how); bgneal@45: bgneal@45: ++startContainerDepth; bgneal@45: } bgneal@45: bgneal@45: depthDiff = startContainerDepth - endContainerDepth; bgneal@45: bgneal@45: startNode = t[START_CONTAINER]; bgneal@45: while (depthDiff > 0) { bgneal@45: startNode = startNode.parentNode; bgneal@45: depthDiff--; bgneal@45: } bgneal@45: bgneal@45: endNode = t[END_CONTAINER]; bgneal@45: while (depthDiff < 0) { bgneal@45: endNode = endNode.parentNode; bgneal@45: depthDiff++; bgneal@45: } bgneal@45: bgneal@45: // ascend the ancestor hierarchy until we have a common parent. bgneal@45: for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) { bgneal@45: startNode = sp; bgneal@45: endNode = ep; bgneal@45: } bgneal@45: bgneal@45: return _traverseCommonAncestors(startNode, endNode, how); bgneal@45: }; bgneal@45: bgneal@45: function _traverseSameContainer(how) { bgneal@45: var frag, s, sub, n, cnt, sibling, xferNode, start, len; bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: frag = createDocumentFragment(); bgneal@45: bgneal@45: // If selection is empty, just return the fragment bgneal@45: if (t[START_OFFSET] == t[END_OFFSET]) bgneal@45: return frag; bgneal@45: bgneal@45: // Text node needs special case handling bgneal@45: if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) { bgneal@45: // get the substring bgneal@45: s = t[START_CONTAINER].nodeValue; bgneal@45: sub = s.substring(t[START_OFFSET], t[END_OFFSET]); bgneal@45: bgneal@45: // set the original text node to its new value bgneal@45: if (how != CLONE) { bgneal@45: n = t[START_CONTAINER]; bgneal@45: start = t[START_OFFSET]; bgneal@45: len = t[END_OFFSET] - t[START_OFFSET]; bgneal@45: bgneal@45: if (start === 0 && len >= n.nodeValue.length - 1) { bgneal@45: n.parentNode.removeChild(n); bgneal@45: } else { bgneal@45: n.deleteData(start, len); bgneal@45: } bgneal@45: bgneal@45: // Nothing is partially selected, so collapse to start point bgneal@45: t.collapse(TRUE); bgneal@45: } bgneal@45: bgneal@45: if (how == DELETE) bgneal@45: return; bgneal@45: bgneal@45: if (sub.length > 0) { bgneal@45: frag.appendChild(doc.createTextNode(sub)); bgneal@45: } bgneal@45: bgneal@45: return frag; bgneal@45: } bgneal@45: bgneal@45: // Copy nodes between the start/end offsets. bgneal@45: n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]); bgneal@45: cnt = t[END_OFFSET] - t[START_OFFSET]; bgneal@45: bgneal@45: while (n && cnt > 0) { bgneal@45: sibling = n.nextSibling; bgneal@45: xferNode = _traverseFullySelected(n, how); bgneal@45: bgneal@45: if (frag) bgneal@45: frag.appendChild( xferNode ); bgneal@45: bgneal@45: --cnt; bgneal@45: n = sibling; bgneal@45: } bgneal@45: bgneal@45: // Nothing is partially selected, so collapse to start point bgneal@45: if (how != CLONE) bgneal@45: t.collapse(TRUE); bgneal@45: bgneal@45: return frag; bgneal@45: }; bgneal@45: bgneal@45: function _traverseCommonStartContainer(endAncestor, how) { bgneal@45: var frag, n, endIdx, cnt, sibling, xferNode; bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: frag = createDocumentFragment(); bgneal@45: bgneal@45: n = _traverseRightBoundary(endAncestor, how); bgneal@45: bgneal@45: if (frag) bgneal@45: frag.appendChild(n); bgneal@45: bgneal@45: endIdx = nodeIndex(endAncestor); bgneal@45: cnt = endIdx - t[START_OFFSET]; bgneal@45: bgneal@45: if (cnt <= 0) { bgneal@45: // Collapse to just before the endAncestor, which bgneal@45: // is partially selected. bgneal@45: if (how != CLONE) { bgneal@45: t.setEndBefore(endAncestor); bgneal@45: t.collapse(FALSE); bgneal@45: } bgneal@45: bgneal@45: return frag; bgneal@45: } bgneal@45: bgneal@45: n = endAncestor.previousSibling; bgneal@45: while (cnt > 0) { bgneal@45: sibling = n.previousSibling; bgneal@45: xferNode = _traverseFullySelected(n, how); bgneal@45: bgneal@45: if (frag) bgneal@45: frag.insertBefore(xferNode, frag.firstChild); bgneal@45: bgneal@45: --cnt; bgneal@45: n = sibling; bgneal@45: } bgneal@45: bgneal@45: // Collapse to just before the endAncestor, which bgneal@45: // is partially selected. bgneal@45: if (how != CLONE) { bgneal@45: t.setEndBefore(endAncestor); bgneal@45: t.collapse(FALSE); bgneal@45: } bgneal@45: bgneal@45: return frag; bgneal@45: }; bgneal@45: bgneal@45: function _traverseCommonEndContainer(startAncestor, how) { bgneal@45: var frag, startIdx, n, cnt, sibling, xferNode; bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: frag = createDocumentFragment(); bgneal@45: bgneal@45: n = _traverseLeftBoundary(startAncestor, how); bgneal@45: if (frag) bgneal@45: frag.appendChild(n); bgneal@45: bgneal@45: startIdx = nodeIndex(startAncestor); bgneal@45: ++startIdx; // Because we already traversed it bgneal@45: bgneal@45: cnt = t[END_OFFSET] - startIdx; bgneal@45: n = startAncestor.nextSibling; bgneal@45: while (n && cnt > 0) { bgneal@45: sibling = n.nextSibling; bgneal@45: xferNode = _traverseFullySelected(n, how); bgneal@45: bgneal@45: if (frag) bgneal@45: frag.appendChild(xferNode); bgneal@45: bgneal@45: --cnt; bgneal@45: n = sibling; bgneal@45: } bgneal@45: bgneal@45: if (how != CLONE) { bgneal@45: t.setStartAfter(startAncestor); bgneal@45: t.collapse(TRUE); bgneal@45: } bgneal@45: bgneal@45: return frag; bgneal@45: }; bgneal@45: bgneal@45: function _traverseCommonAncestors(startAncestor, endAncestor, how) { bgneal@45: var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling; bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: frag = createDocumentFragment(); bgneal@45: bgneal@45: n = _traverseLeftBoundary(startAncestor, how); bgneal@45: if (frag) bgneal@45: frag.appendChild(n); bgneal@45: bgneal@45: commonParent = startAncestor.parentNode; bgneal@45: startOffset = nodeIndex(startAncestor); bgneal@45: endOffset = nodeIndex(endAncestor); bgneal@45: ++startOffset; bgneal@45: bgneal@45: cnt = endOffset - startOffset; bgneal@45: sibling = startAncestor.nextSibling; bgneal@45: bgneal@45: while (cnt > 0) { bgneal@45: nextSibling = sibling.nextSibling; bgneal@45: n = _traverseFullySelected(sibling, how); bgneal@45: bgneal@45: if (frag) bgneal@45: frag.appendChild(n); bgneal@45: bgneal@45: sibling = nextSibling; bgneal@45: --cnt; bgneal@45: } bgneal@45: bgneal@45: n = _traverseRightBoundary(endAncestor, how); bgneal@45: bgneal@45: if (frag) bgneal@45: frag.appendChild(n); bgneal@45: bgneal@45: if (how != CLONE) { bgneal@45: t.setStartAfter(startAncestor); bgneal@45: t.collapse(TRUE); bgneal@45: } bgneal@45: bgneal@45: return frag; bgneal@45: }; bgneal@45: bgneal@45: function _traverseRightBoundary(root, how) { bgneal@45: var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER]; bgneal@45: bgneal@45: if (next == root) bgneal@45: return _traverseNode(next, isFullySelected, FALSE, how); bgneal@45: bgneal@45: parent = next.parentNode; bgneal@45: clonedParent = _traverseNode(parent, FALSE, FALSE, how); bgneal@45: bgneal@45: while (parent) { bgneal@45: while (next) { bgneal@45: prevSibling = next.previousSibling; bgneal@45: clonedChild = _traverseNode(next, isFullySelected, FALSE, how); bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: clonedParent.insertBefore(clonedChild, clonedParent.firstChild); bgneal@45: bgneal@45: isFullySelected = TRUE; bgneal@45: next = prevSibling; bgneal@45: } bgneal@45: bgneal@45: if (parent == root) bgneal@45: return clonedParent; bgneal@45: bgneal@45: next = parent.previousSibling; bgneal@45: parent = parent.parentNode; bgneal@45: bgneal@45: clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how); bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: clonedGrandParent.appendChild(clonedParent); bgneal@45: bgneal@45: clonedParent = clonedGrandParent; bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function _traverseLeftBoundary(root, how) { bgneal@45: var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER], parent, clonedParent, nextSibling, clonedChild, clonedGrandParent; bgneal@45: bgneal@45: if (next == root) bgneal@45: return _traverseNode(next, isFullySelected, TRUE, how); bgneal@45: bgneal@45: parent = next.parentNode; bgneal@45: clonedParent = _traverseNode(parent, FALSE, TRUE, how); bgneal@45: bgneal@45: while (parent) { bgneal@45: while (next) { bgneal@45: nextSibling = next.nextSibling; bgneal@45: clonedChild = _traverseNode(next, isFullySelected, TRUE, how); bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: clonedParent.appendChild(clonedChild); bgneal@45: bgneal@45: isFullySelected = TRUE; bgneal@45: next = nextSibling; bgneal@45: } bgneal@45: bgneal@45: if (parent == root) bgneal@45: return clonedParent; bgneal@45: bgneal@45: next = parent.nextSibling; bgneal@45: parent = parent.parentNode; bgneal@45: bgneal@45: clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how); bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: clonedGrandParent.appendChild(clonedParent); bgneal@45: bgneal@45: clonedParent = clonedGrandParent; bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function _traverseNode(n, isFullySelected, isLeft, how) { bgneal@45: var txtValue, newNodeValue, oldNodeValue, offset, newNode; bgneal@45: bgneal@45: if (isFullySelected) bgneal@45: return _traverseFullySelected(n, how); bgneal@45: bgneal@45: if (n.nodeType == 3 /* TEXT_NODE */) { bgneal@45: txtValue = n.nodeValue; bgneal@45: bgneal@45: if (isLeft) { bgneal@45: offset = t[START_OFFSET]; bgneal@45: newNodeValue = txtValue.substring(offset); bgneal@45: oldNodeValue = txtValue.substring(0, offset); bgneal@45: } else { bgneal@45: offset = t[END_OFFSET]; bgneal@45: newNodeValue = txtValue.substring(0, offset); bgneal@45: oldNodeValue = txtValue.substring(offset); bgneal@45: } bgneal@45: bgneal@45: if (how != CLONE) bgneal@45: n.nodeValue = oldNodeValue; bgneal@45: bgneal@45: if (how == DELETE) bgneal@45: return; bgneal@45: bgneal@45: newNode = dom.clone(n, FALSE); bgneal@45: newNode.nodeValue = newNodeValue; bgneal@45: bgneal@45: return newNode; bgneal@45: } bgneal@45: bgneal@45: if (how == DELETE) bgneal@45: return; bgneal@45: bgneal@45: return dom.clone(n, FALSE); bgneal@45: }; bgneal@45: bgneal@45: function _traverseFullySelected(n, how) { bgneal@45: if (how != DELETE) bgneal@45: return how == CLONE ? dom.clone(n, TRUE) : n; bgneal@45: bgneal@45: n.parentNode.removeChild(n); bgneal@45: }; bgneal@45: }; bgneal@45: bgneal@45: ns.Range = Range; bgneal@45: })(tinymce.dom); bgneal@45: bgneal@45: (function() { bgneal@45: function Selection(selection) { bgneal@45: var self = this, dom = selection.dom, TRUE = true, FALSE = false; bgneal@45: bgneal@45: function getPosition(rng, start) { bgneal@45: var checkRng, startIndex = 0, endIndex, inside, bgneal@45: children, child, offset, index, position = -1, parent; bgneal@45: bgneal@45: // Setup test range, collapse it and get the parent bgneal@45: checkRng = rng.duplicate(); bgneal@45: checkRng.collapse(start); bgneal@45: parent = checkRng.parentElement(); bgneal@45: bgneal@45: // Check if the selection is within the right document bgneal@45: if (parent.ownerDocument !== selection.dom.doc) bgneal@45: return; bgneal@45: bgneal@45: // IE will report non editable elements as it's parent so look for an editable one bgneal@45: while (parent.contentEditable === "false") { bgneal@45: parent = parent.parentNode; bgneal@45: } bgneal@45: bgneal@45: // If parent doesn't have any children then return that we are inside the element bgneal@45: if (!parent.hasChildNodes()) { bgneal@45: return {node : parent, inside : 1}; bgneal@45: } bgneal@45: bgneal@45: // Setup node list and endIndex bgneal@45: children = parent.children; bgneal@45: endIndex = children.length - 1; bgneal@45: bgneal@45: // Perform a binary search for the position bgneal@45: while (startIndex <= endIndex) { bgneal@45: index = Math.floor((startIndex + endIndex) / 2); bgneal@45: bgneal@45: // Move selection to node and compare the ranges bgneal@45: child = children[index]; bgneal@45: checkRng.moveToElementText(child); bgneal@45: position = checkRng.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', rng); bgneal@45: bgneal@45: // Before/after or an exact match bgneal@45: if (position > 0) { bgneal@45: endIndex = index - 1; bgneal@45: } else if (position < 0) { bgneal@45: startIndex = index + 1; bgneal@45: } else { bgneal@45: return {node : child}; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Check if child position is before or we didn't find a position bgneal@45: if (position < 0) { bgneal@45: // No element child was found use the parent element and the offset inside that bgneal@45: if (!child) { bgneal@45: checkRng.moveToElementText(parent); bgneal@45: checkRng.collapse(true); bgneal@45: child = parent; bgneal@45: inside = true; bgneal@45: } else bgneal@45: checkRng.collapse(false); bgneal@45: bgneal@45: checkRng.setEndPoint(start ? 'EndToStart' : 'EndToEnd', rng); bgneal@45: bgneal@45: // Fix for edge case:
    ..
    ab|c
    bgneal@45: if (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) > 0) { bgneal@45: checkRng = rng.duplicate(); bgneal@45: checkRng.collapse(start); bgneal@45: bgneal@45: offset = -1; bgneal@45: while (parent == checkRng.parentElement()) { bgneal@45: if (checkRng.move('character', -1) == 0) bgneal@45: break; bgneal@45: bgneal@45: offset++; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: offset = offset || checkRng.text.replace('\r\n', ' ').length; bgneal@45: } else { bgneal@45: // Child position is after the selection endpoint bgneal@45: checkRng.collapse(true); bgneal@45: checkRng.setEndPoint(start ? 'StartToStart' : 'StartToEnd', rng); bgneal@45: bgneal@45: // Get the length of the text to find where the endpoint is relative to it's container bgneal@45: offset = checkRng.text.replace('\r\n', ' ').length; bgneal@45: } bgneal@45: bgneal@45: return {node : child, position : position, offset : offset, inside : inside}; bgneal@45: }; bgneal@45: bgneal@45: // Returns a W3C DOM compatible range object by using the IE Range API bgneal@45: function getRange() { bgneal@45: var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed, tmpRange, element2, bookmark, fail; bgneal@45: bgneal@45: // If selection is outside the current document just return an empty range bgneal@45: element = ieRange.item ? ieRange.item(0) : ieRange.parentElement(); bgneal@45: if (element.ownerDocument != dom.doc) bgneal@45: return domRange; bgneal@45: bgneal@45: collapsed = selection.isCollapsed(); bgneal@45: bgneal@45: // Handle control selection bgneal@45: if (ieRange.item) { bgneal@45: domRange.setStart(element.parentNode, dom.nodeIndex(element)); bgneal@45: domRange.setEnd(domRange.startContainer, domRange.startOffset + 1); bgneal@45: bgneal@45: return domRange; bgneal@45: } bgneal@45: bgneal@45: function findEndPoint(start) { bgneal@45: var endPoint = getPosition(ieRange, start), container, offset, textNodeOffset = 0, sibling, undef, nodeValue; bgneal@45: bgneal@45: container = endPoint.node; bgneal@45: offset = endPoint.offset; bgneal@45: bgneal@45: if (endPoint.inside && !container.hasChildNodes()) { bgneal@45: domRange[start ? 'setStart' : 'setEnd'](container, 0); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: if (offset === undef) { bgneal@45: domRange[start ? 'setStartBefore' : 'setEndAfter'](container); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: if (endPoint.position < 0) { bgneal@45: sibling = endPoint.inside ? container.firstChild : container.nextSibling; bgneal@45: bgneal@45: if (!sibling) { bgneal@45: domRange[start ? 'setStartAfter' : 'setEndAfter'](container); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: if (!offset) { bgneal@45: if (sibling.nodeType == 3) bgneal@45: domRange[start ? 'setStart' : 'setEnd'](sibling, 0); bgneal@45: else bgneal@45: domRange[start ? 'setStartBefore' : 'setEndBefore'](sibling); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Find the text node and offset bgneal@45: while (sibling) { bgneal@45: nodeValue = sibling.nodeValue; bgneal@45: textNodeOffset += nodeValue.length; bgneal@45: bgneal@45: // We are at or passed the position we where looking for bgneal@45: if (textNodeOffset >= offset) { bgneal@45: container = sibling; bgneal@45: textNodeOffset -= offset; bgneal@45: textNodeOffset = nodeValue.length - textNodeOffset; bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: sibling = sibling.nextSibling; bgneal@45: } bgneal@45: } else { bgneal@45: // Find the text node and offset bgneal@45: sibling = container.previousSibling; bgneal@45: bgneal@45: if (!sibling) bgneal@45: return domRange[start ? 'setStartBefore' : 'setEndBefore'](container); bgneal@45: bgneal@45: // If there isn't any text to loop then use the first position bgneal@45: if (!offset) { bgneal@45: if (container.nodeType == 3) bgneal@45: domRange[start ? 'setStart' : 'setEnd'](sibling, container.nodeValue.length); bgneal@45: else bgneal@45: domRange[start ? 'setStartAfter' : 'setEndAfter'](sibling); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: while (sibling) { bgneal@45: textNodeOffset += sibling.nodeValue.length; bgneal@45: bgneal@45: // We are at or passed the position we where looking for bgneal@45: if (textNodeOffset >= offset) { bgneal@45: container = sibling; bgneal@45: textNodeOffset -= offset; bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: sibling = sibling.previousSibling; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: domRange[start ? 'setStart' : 'setEnd'](container, textNodeOffset); bgneal@45: }; bgneal@45: bgneal@45: try { bgneal@45: // Find start point bgneal@45: findEndPoint(true); bgneal@45: bgneal@45: // Find end point if needed bgneal@45: if (!collapsed) bgneal@45: findEndPoint(); bgneal@45: } catch (ex) { bgneal@45: // IE has a nasty bug where text nodes might throw "invalid argument" when you bgneal@45: // access the nodeValue or other properties of text nodes. This seems to happend when bgneal@45: // text nodes are split into two nodes by a delete/backspace call. So lets detect it and try to fix it. bgneal@45: if (ex.number == -2147024809) { bgneal@45: // Get the current selection bgneal@45: bookmark = self.getBookmark(2); bgneal@45: bgneal@45: // Get start element bgneal@45: tmpRange = ieRange.duplicate(); bgneal@45: tmpRange.collapse(true); bgneal@45: element = tmpRange.parentElement(); bgneal@45: bgneal@45: // Get end element bgneal@45: if (!collapsed) { bgneal@45: tmpRange = ieRange.duplicate(); bgneal@45: tmpRange.collapse(false); bgneal@45: element2 = tmpRange.parentElement(); bgneal@45: element2.innerHTML = element2.innerHTML; bgneal@45: } bgneal@45: bgneal@45: // Remove the broken elements bgneal@45: element.innerHTML = element.innerHTML; bgneal@45: bgneal@45: // Restore the selection bgneal@45: self.moveToBookmark(bookmark); bgneal@45: bgneal@45: // Since the range has moved we need to re-get it bgneal@45: ieRange = selection.getRng(); bgneal@45: bgneal@45: // Find start point bgneal@45: findEndPoint(true); bgneal@45: bgneal@45: // Find end point if needed bgneal@45: if (!collapsed) bgneal@45: findEndPoint(); bgneal@45: } else bgneal@45: throw ex; // Throw other errors bgneal@45: } bgneal@45: bgneal@45: return domRange; bgneal@45: }; bgneal@45: bgneal@45: this.getBookmark = function(type) { bgneal@45: var rng = selection.getRng(), start, end, bookmark = {}; bgneal@45: bgneal@45: function getIndexes(node) { bgneal@45: var node, parent, root, children, i, indexes = []; bgneal@45: bgneal@45: parent = node.parentNode; bgneal@45: root = dom.getRoot().parentNode; bgneal@45: bgneal@45: while (parent != root && parent.nodeType !== 9) { bgneal@45: children = parent.children; bgneal@45: bgneal@45: i = children.length; bgneal@45: while (i--) { bgneal@45: if (node === children[i]) { bgneal@45: indexes.push(i); bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: node = parent; bgneal@45: parent = parent.parentNode; bgneal@45: } bgneal@45: bgneal@45: return indexes; bgneal@45: }; bgneal@45: bgneal@45: function getBookmarkEndPoint(start) { bgneal@45: var position; bgneal@45: bgneal@45: position = getPosition(rng, start); bgneal@45: if (position) { bgneal@45: return { bgneal@45: position : position.position, bgneal@45: offset : position.offset, bgneal@45: indexes : getIndexes(position.node), bgneal@45: inside : position.inside bgneal@45: }; bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Non ubstructive bookmark bgneal@45: if (type === 2) { bgneal@45: // Handle text selection bgneal@45: if (!rng.item) { bgneal@45: bookmark.start = getBookmarkEndPoint(true); bgneal@45: bgneal@45: if (!selection.isCollapsed()) bgneal@45: bookmark.end = getBookmarkEndPoint(); bgneal@45: } else bgneal@45: bookmark.start = {ctrl : true, indexes : getIndexes(rng.item(0))}; bgneal@45: } bgneal@45: bgneal@45: return bookmark; bgneal@45: }; bgneal@45: bgneal@45: this.moveToBookmark = function(bookmark) { bgneal@45: var rng, body = dom.doc.body; bgneal@45: bgneal@45: function resolveIndexes(indexes) { bgneal@45: var node, i, idx, children; bgneal@45: bgneal@45: node = dom.getRoot(); bgneal@45: for (i = indexes.length - 1; i >= 0; i--) { bgneal@45: children = node.children; bgneal@45: idx = indexes[i]; bgneal@45: bgneal@45: if (idx <= children.length - 1) { bgneal@45: node = children[idx]; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return node; bgneal@45: }; bgneal@45: bgneal@45: function setBookmarkEndPoint(start) { bgneal@45: var endPoint = bookmark[start ? 'start' : 'end'], moveLeft, moveRng, undef; bgneal@45: bgneal@45: if (endPoint) { bgneal@45: moveLeft = endPoint.position > 0; bgneal@45: bgneal@45: moveRng = body.createTextRange(); bgneal@45: moveRng.moveToElementText(resolveIndexes(endPoint.indexes)); bgneal@45: bgneal@45: offset = endPoint.offset; bgneal@45: if (offset !== undef) { bgneal@45: moveRng.collapse(endPoint.inside || moveLeft); bgneal@45: moveRng.moveStart('character', moveLeft ? -offset : offset); bgneal@45: } else bgneal@45: moveRng.collapse(start); bgneal@45: bgneal@45: rng.setEndPoint(start ? 'StartToStart' : 'EndToStart', moveRng); bgneal@45: bgneal@45: if (start) bgneal@45: rng.collapse(true); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: if (bookmark.start) { bgneal@45: if (bookmark.start.ctrl) { bgneal@45: rng = body.createControlRange(); bgneal@45: rng.addElement(resolveIndexes(bookmark.start.indexes)); bgneal@45: rng.select(); bgneal@45: } else { bgneal@45: rng = body.createTextRange(); bgneal@45: setBookmarkEndPoint(true); bgneal@45: setBookmarkEndPoint(); bgneal@45: rng.select(); bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: this.addRange = function(rng) { bgneal@45: var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, doc = selection.dom.doc, body = doc.body; bgneal@45: bgneal@45: function setEndPoint(start) { bgneal@45: var container, offset, marker, tmpRng, nodes; bgneal@45: bgneal@45: marker = dom.create('a'); bgneal@45: container = start ? startContainer : endContainer; bgneal@45: offset = start ? startOffset : endOffset; bgneal@45: tmpRng = ieRng.duplicate(); bgneal@45: bgneal@45: if (container == doc || container == doc.documentElement) { bgneal@45: container = body; bgneal@45: offset = 0; bgneal@45: } bgneal@45: bgneal@45: if (container.nodeType == 3) { bgneal@45: container.parentNode.insertBefore(marker, container); bgneal@45: tmpRng.moveToElementText(marker); bgneal@45: tmpRng.moveStart('character', offset); bgneal@45: dom.remove(marker); bgneal@45: ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng); bgneal@45: } else { bgneal@45: nodes = container.childNodes; bgneal@45: bgneal@45: if (nodes.length) { bgneal@45: if (offset >= nodes.length) { bgneal@45: dom.insertAfter(marker, nodes[nodes.length - 1]); bgneal@45: } else { bgneal@45: container.insertBefore(marker, nodes[offset]); bgneal@45: } bgneal@45: bgneal@45: tmpRng.moveToElementText(marker); bgneal@45: } else if (container.canHaveHTML) { bgneal@45: // Empty node selection for example
    |
    bgneal@45: // Setting innerHTML with a span marker then remove that marker seems to keep empty block elements open bgneal@45: container.innerHTML = '\uFEFF'; bgneal@45: marker = container.firstChild; bgneal@45: tmpRng.moveToElementText(marker); bgneal@45: tmpRng.collapse(FALSE); // Collapse false works better than true for some odd reason bgneal@45: } bgneal@45: bgneal@45: ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng); bgneal@45: dom.remove(marker); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Setup some shorter versions bgneal@45: startContainer = rng.startContainer; bgneal@45: startOffset = rng.startOffset; bgneal@45: endContainer = rng.endContainer; bgneal@45: endOffset = rng.endOffset; bgneal@45: ieRng = body.createTextRange(); bgneal@45: bgneal@45: // If single element selection then try making a control selection out of it bgneal@45: if (startContainer == endContainer && startContainer.nodeType == 1) { bgneal@45: // Trick to place the caret inside an empty block element like

    bgneal@45: if (!startContainer.hasChildNodes()) { bgneal@45: startContainer.innerHTML = '\uFEFF\uFEFF'; bgneal@45: ieRng.moveToElementText(startContainer.lastChild); bgneal@45: ieRng.select(); bgneal@45: dom.doc.selection.clear(); bgneal@45: startContainer.innerHTML = ''; bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: if (startOffset == endOffset - 1) { bgneal@45: try { bgneal@45: ctrlRng = body.createControlRange(); bgneal@45: ctrlRng.addElement(startContainer.childNodes[startOffset]); bgneal@45: ctrlRng.select(); bgneal@45: return; bgneal@45: } catch (ex) { bgneal@45: // Ignore bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Set start/end point of selection bgneal@45: setEndPoint(true); bgneal@45: setEndPoint(); bgneal@45: bgneal@45: // Select the new range and scroll it into view bgneal@45: ieRng.select(); bgneal@45: }; bgneal@45: bgneal@45: // Expose range method bgneal@45: this.getRangeAt = getRange; bgneal@45: }; bgneal@45: bgneal@45: // Expose the selection object bgneal@45: tinymce.dom.TridentSelection = Selection; bgneal@45: })(); bgneal@45: bgneal@45: bgneal@45: /* bgneal@45: * Sizzle CSS Selector Engine - v1.0 bgneal@45: * Copyright 2009, The Dojo Foundation bgneal@45: * Released under the MIT, BSD, and GPL Licenses. bgneal@45: * More information: http://sizzlejs.com/ bgneal@45: */ bgneal@45: (function(){ bgneal@45: bgneal@45: var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g, bgneal@45: done = 0, bgneal@45: toString = Object.prototype.toString, bgneal@45: hasDuplicate = false, bgneal@45: baseHasDuplicate = true; bgneal@45: bgneal@45: // Here we check if the JavaScript engine is using some sort of bgneal@45: // optimization where it does not always call our comparision bgneal@45: // function. If that is the case, discard the hasDuplicate value. bgneal@45: // Thus far that includes Google Chrome. bgneal@45: [0, 0].sort(function(){ bgneal@45: baseHasDuplicate = false; bgneal@45: return 0; bgneal@45: }); bgneal@45: bgneal@45: var Sizzle = function(selector, context, results, seed) { bgneal@45: results = results || []; bgneal@45: context = context || document; bgneal@45: bgneal@45: var origContext = context; bgneal@45: bgneal@45: if ( context.nodeType !== 1 && context.nodeType !== 9 ) { bgneal@45: return []; bgneal@45: } bgneal@45: bgneal@45: if ( !selector || typeof selector !== "string" ) { bgneal@45: return results; bgneal@45: } bgneal@45: bgneal@45: var parts = [], m, set, checkSet, extra, prune = true, contextXML = Sizzle.isXML(context), bgneal@45: soFar = selector, ret, cur, pop, i; bgneal@45: bgneal@45: // Reset the position of the chunker regexp (start from head) bgneal@45: do { bgneal@45: chunker.exec(""); bgneal@45: m = chunker.exec(soFar); bgneal@45: bgneal@45: if ( m ) { bgneal@45: soFar = m[3]; bgneal@45: bgneal@45: parts.push( m[1] ); bgneal@45: bgneal@45: if ( m[2] ) { bgneal@45: extra = m[3]; bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: } while ( m ); bgneal@45: bgneal@45: if ( parts.length > 1 && origPOS.exec( selector ) ) { bgneal@45: if ( parts.length === 2 && Expr.relative[ parts[0] ] ) { bgneal@45: set = posProcess( parts[0] + parts[1], context ); bgneal@45: } else { bgneal@45: set = Expr.relative[ parts[0] ] ? bgneal@45: [ context ] : bgneal@45: Sizzle( parts.shift(), context ); bgneal@45: bgneal@45: while ( parts.length ) { bgneal@45: selector = parts.shift(); bgneal@45: bgneal@45: if ( Expr.relative[ selector ] ) { bgneal@45: selector += parts.shift(); bgneal@45: } bgneal@45: bgneal@45: set = posProcess( selector, set ); bgneal@45: } bgneal@45: } bgneal@45: } else { bgneal@45: // Take a shortcut and set the context if the root selector is an ID bgneal@45: // (but not if it'll be faster if the inner selector is an ID) bgneal@45: if ( !seed && parts.length > 1 && context.nodeType === 9 && !contextXML && bgneal@45: Expr.match.ID.test(parts[0]) && !Expr.match.ID.test(parts[parts.length - 1]) ) { bgneal@45: ret = Sizzle.find( parts.shift(), context, contextXML ); bgneal@45: context = ret.expr ? Sizzle.filter( ret.expr, ret.set )[0] : ret.set[0]; bgneal@45: } bgneal@45: bgneal@45: if ( context ) { bgneal@45: ret = seed ? bgneal@45: { expr: parts.pop(), set: makeArray(seed) } : bgneal@45: Sizzle.find( parts.pop(), parts.length === 1 && (parts[0] === "~" || parts[0] === "+") && context.parentNode ? context.parentNode : context, contextXML ); bgneal@45: set = ret.expr ? Sizzle.filter( ret.expr, ret.set ) : ret.set; bgneal@45: bgneal@45: if ( parts.length > 0 ) { bgneal@45: checkSet = makeArray(set); bgneal@45: } else { bgneal@45: prune = false; bgneal@45: } bgneal@45: bgneal@45: while ( parts.length ) { bgneal@45: cur = parts.pop(); bgneal@45: pop = cur; bgneal@45: bgneal@45: if ( !Expr.relative[ cur ] ) { bgneal@45: cur = ""; bgneal@45: } else { bgneal@45: pop = parts.pop(); bgneal@45: } bgneal@45: bgneal@45: if ( pop == null ) { bgneal@45: pop = context; bgneal@45: } bgneal@45: bgneal@45: Expr.relative[ cur ]( checkSet, pop, contextXML ); bgneal@45: } bgneal@45: } else { bgneal@45: checkSet = parts = []; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if ( !checkSet ) { bgneal@45: checkSet = set; bgneal@45: } bgneal@45: bgneal@45: if ( !checkSet ) { bgneal@45: Sizzle.error( cur || selector ); bgneal@45: } bgneal@45: bgneal@45: if ( toString.call(checkSet) === "[object Array]" ) { bgneal@45: if ( !prune ) { bgneal@45: results.push.apply( results, checkSet ); bgneal@45: } else if ( context && context.nodeType === 1 ) { bgneal@45: for ( i = 0; checkSet[i] != null; i++ ) { bgneal@45: if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && Sizzle.contains(context, checkSet[i])) ) { bgneal@45: results.push( set[i] ); bgneal@45: } bgneal@45: } bgneal@45: } else { bgneal@45: for ( i = 0; checkSet[i] != null; i++ ) { bgneal@45: if ( checkSet[i] && checkSet[i].nodeType === 1 ) { bgneal@45: results.push( set[i] ); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } else { bgneal@45: makeArray( checkSet, results ); bgneal@45: } bgneal@45: bgneal@45: if ( extra ) { bgneal@45: Sizzle( extra, origContext, results, seed ); bgneal@45: Sizzle.uniqueSort( results ); bgneal@45: } bgneal@45: bgneal@45: return results; bgneal@45: }; bgneal@45: bgneal@45: Sizzle.uniqueSort = function(results){ bgneal@45: if ( sortOrder ) { bgneal@45: hasDuplicate = baseHasDuplicate; bgneal@45: results.sort(sortOrder); bgneal@45: bgneal@45: if ( hasDuplicate ) { bgneal@45: for ( var i = 1; i < results.length; i++ ) { bgneal@45: if ( results[i] === results[i-1] ) { bgneal@45: results.splice(i--, 1); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return results; bgneal@45: }; bgneal@45: bgneal@45: Sizzle.matches = function(expr, set){ bgneal@45: return Sizzle(expr, null, null, set); bgneal@45: }; bgneal@45: bgneal@45: Sizzle.find = function(expr, context, isXML){ bgneal@45: var set; bgneal@45: bgneal@45: if ( !expr ) { bgneal@45: return []; bgneal@45: } bgneal@45: bgneal@45: for ( var i = 0, l = Expr.order.length; i < l; i++ ) { bgneal@45: var type = Expr.order[i], match; bgneal@45: bgneal@45: if ( (match = Expr.leftMatch[ type ].exec( expr )) ) { bgneal@45: var left = match[1]; bgneal@45: match.splice(1,1); bgneal@45: bgneal@45: if ( left.substr( left.length - 1 ) !== "\\" ) { bgneal@45: match[1] = (match[1] || "").replace(/\\/g, ""); bgneal@45: set = Expr.find[ type ]( match, context, isXML ); bgneal@45: if ( set != null ) { bgneal@45: expr = expr.replace( Expr.match[ type ], "" ); bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if ( !set ) { bgneal@45: set = context.getElementsByTagName("*"); bgneal@45: } bgneal@45: bgneal@45: return {set: set, expr: expr}; bgneal@45: }; bgneal@45: bgneal@45: Sizzle.filter = function(expr, set, inplace, not){ bgneal@45: var old = expr, result = [], curLoop = set, match, anyFound, bgneal@45: isXMLFilter = set && set[0] && Sizzle.isXML(set[0]); bgneal@45: bgneal@45: while ( expr && set.length ) { bgneal@45: for ( var type in Expr.filter ) { bgneal@45: if ( (match = Expr.leftMatch[ type ].exec( expr )) != null && match[2] ) { bgneal@45: var filter = Expr.filter[ type ], found, item, left = match[1]; bgneal@45: anyFound = false; bgneal@45: bgneal@45: match.splice(1,1); bgneal@45: bgneal@45: if ( left.substr( left.length - 1 ) === "\\" ) { bgneal@45: continue; bgneal@45: } bgneal@45: bgneal@45: if ( curLoop === result ) { bgneal@45: result = []; bgneal@45: } bgneal@45: bgneal@45: if ( Expr.preFilter[ type ] ) { bgneal@45: match = Expr.preFilter[ type ]( match, curLoop, inplace, result, not, isXMLFilter ); bgneal@45: bgneal@45: if ( !match ) { bgneal@45: anyFound = found = true; bgneal@45: } else if ( match === true ) { bgneal@45: continue; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if ( match ) { bgneal@45: for ( var i = 0; (item = curLoop[i]) != null; i++ ) { bgneal@45: if ( item ) { bgneal@45: found = filter( item, match, i, curLoop ); bgneal@45: var pass = not ^ !!found; bgneal@45: bgneal@45: if ( inplace && found != null ) { bgneal@45: if ( pass ) { bgneal@45: anyFound = true; bgneal@45: } else { bgneal@45: curLoop[i] = false; bgneal@45: } bgneal@45: } else if ( pass ) { bgneal@45: result.push( item ); bgneal@45: anyFound = true; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if ( found !== undefined ) { bgneal@45: if ( !inplace ) { bgneal@45: curLoop = result; bgneal@45: } bgneal@45: bgneal@45: expr = expr.replace( Expr.match[ type ], "" ); bgneal@45: bgneal@45: if ( !anyFound ) { bgneal@45: return []; bgneal@45: } bgneal@45: bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Improper expression bgneal@45: if ( expr === old ) { bgneal@45: if ( anyFound == null ) { bgneal@45: Sizzle.error( expr ); bgneal@45: } else { bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: old = expr; bgneal@45: } bgneal@45: bgneal@45: return curLoop; bgneal@45: }; bgneal@45: bgneal@45: Sizzle.error = function( msg ) { bgneal@45: throw "Syntax error, unrecognized expression: " + msg; bgneal@45: }; bgneal@45: bgneal@45: var Expr = Sizzle.selectors = { bgneal@45: order: [ "ID", "NAME", "TAG" ], bgneal@45: match: { bgneal@45: ID: /#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, bgneal@45: CLASS: /\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/, bgneal@45: NAME: /\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/, bgneal@45: ATTR: /\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(['"]*)(.*?)\3|)\s*\]/, bgneal@45: TAG: /^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/, bgneal@45: CHILD: /:(only|nth|last|first)-child(?:\((even|odd|[\dn+\-]*)\))?/, bgneal@45: POS: /:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/, bgneal@45: PSEUDO: /:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/ bgneal@45: }, bgneal@45: leftMatch: {}, bgneal@45: attrMap: { bgneal@45: "class": "className", bgneal@45: "for": "htmlFor" bgneal@45: }, bgneal@45: attrHandle: { bgneal@45: href: function(elem){ bgneal@45: return elem.getAttribute("href"); bgneal@45: } bgneal@45: }, bgneal@45: relative: { bgneal@45: "+": function(checkSet, part){ bgneal@45: var isPartStr = typeof part === "string", bgneal@45: isTag = isPartStr && !/\W/.test(part), bgneal@45: isPartStrNotTag = isPartStr && !isTag; bgneal@45: bgneal@45: if ( isTag ) { bgneal@45: part = part.toLowerCase(); bgneal@45: } bgneal@45: bgneal@45: for ( var i = 0, l = checkSet.length, elem; i < l; i++ ) { bgneal@45: if ( (elem = checkSet[i]) ) { bgneal@45: while ( (elem = elem.previousSibling) && elem.nodeType !== 1 ) {} bgneal@45: bgneal@45: checkSet[i] = isPartStrNotTag || elem && elem.nodeName.toLowerCase() === part ? bgneal@45: elem || false : bgneal@45: elem === part; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if ( isPartStrNotTag ) { bgneal@45: Sizzle.filter( part, checkSet, true ); bgneal@45: } bgneal@45: }, bgneal@45: ">": function(checkSet, part){ bgneal@45: var isPartStr = typeof part === "string", bgneal@45: elem, i = 0, l = checkSet.length; bgneal@45: bgneal@45: if ( isPartStr && !/\W/.test(part) ) { bgneal@45: part = part.toLowerCase(); bgneal@45: bgneal@45: for ( ; i < l; i++ ) { bgneal@45: elem = checkSet[i]; bgneal@45: if ( elem ) { bgneal@45: var parent = elem.parentNode; bgneal@45: checkSet[i] = parent.nodeName.toLowerCase() === part ? parent : false; bgneal@45: } bgneal@45: } bgneal@45: } else { bgneal@45: for ( ; i < l; i++ ) { bgneal@45: elem = checkSet[i]; bgneal@45: if ( elem ) { bgneal@45: checkSet[i] = isPartStr ? bgneal@45: elem.parentNode : bgneal@45: elem.parentNode === part; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if ( isPartStr ) { bgneal@45: Sizzle.filter( part, checkSet, true ); bgneal@45: } bgneal@45: } bgneal@45: }, bgneal@45: "": function(checkSet, part, isXML){ bgneal@45: var doneName = done++, checkFn = dirCheck, nodeCheck; bgneal@45: bgneal@45: if ( typeof part === "string" && !/\W/.test(part) ) { bgneal@45: part = part.toLowerCase(); bgneal@45: nodeCheck = part; bgneal@45: checkFn = dirNodeCheck; bgneal@45: } bgneal@45: bgneal@45: checkFn("parentNode", part, doneName, checkSet, nodeCheck, isXML); bgneal@45: }, bgneal@45: "~": function(checkSet, part, isXML){ bgneal@45: var doneName = done++, checkFn = dirCheck, nodeCheck; bgneal@45: bgneal@45: if ( typeof part === "string" && !/\W/.test(part) ) { bgneal@45: part = part.toLowerCase(); bgneal@45: nodeCheck = part; bgneal@45: checkFn = dirNodeCheck; bgneal@45: } bgneal@45: bgneal@45: checkFn("previousSibling", part, doneName, checkSet, nodeCheck, isXML); bgneal@45: } bgneal@45: }, bgneal@45: find: { bgneal@45: ID: function(match, context, isXML){ bgneal@45: if ( typeof context.getElementById !== "undefined" && !isXML ) { bgneal@45: var m = context.getElementById(match[1]); bgneal@45: return m ? [m] : []; bgneal@45: } bgneal@45: }, bgneal@45: NAME: function(match, context){ bgneal@45: if ( typeof context.getElementsByName !== "undefined" ) { bgneal@45: var ret = [], results = context.getElementsByName(match[1]); bgneal@45: bgneal@45: for ( var i = 0, l = results.length; i < l; i++ ) { bgneal@45: if ( results[i].getAttribute("name") === match[1] ) { bgneal@45: ret.push( results[i] ); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return ret.length === 0 ? null : ret; bgneal@45: } bgneal@45: }, bgneal@45: TAG: function(match, context){ bgneal@45: return context.getElementsByTagName(match[1]); bgneal@45: } bgneal@45: }, bgneal@45: preFilter: { bgneal@45: CLASS: function(match, curLoop, inplace, result, not, isXML){ bgneal@45: match = " " + match[1].replace(/\\/g, "") + " "; bgneal@45: bgneal@45: if ( isXML ) { bgneal@45: return match; bgneal@45: } bgneal@45: bgneal@45: for ( var i = 0, elem; (elem = curLoop[i]) != null; i++ ) { bgneal@45: if ( elem ) { bgneal@45: if ( not ^ (elem.className && (" " + elem.className + " ").replace(/[\t\n]/g, " ").indexOf(match) >= 0) ) { bgneal@45: if ( !inplace ) { bgneal@45: result.push( elem ); bgneal@45: } bgneal@45: } else if ( inplace ) { bgneal@45: curLoop[i] = false; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return false; bgneal@45: }, bgneal@45: ID: function(match){ bgneal@45: return match[1].replace(/\\/g, ""); bgneal@45: }, bgneal@45: TAG: function(match, curLoop){ bgneal@45: return match[1].toLowerCase(); bgneal@45: }, bgneal@45: CHILD: function(match){ bgneal@45: if ( match[1] === "nth" ) { bgneal@45: // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' bgneal@45: var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec( bgneal@45: match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" || bgneal@45: !/\D/.test( match[2] ) && "0n+" + match[2] || match[2]); bgneal@45: bgneal@45: // calculate the numbers (first)n+(last) including if they are negative bgneal@45: match[2] = (test[1] + (test[2] || 1)) - 0; bgneal@45: match[3] = test[3] - 0; bgneal@45: } bgneal@45: bgneal@45: // TODO: Move to normal caching system bgneal@45: match[0] = done++; bgneal@45: bgneal@45: return match; bgneal@45: }, bgneal@45: ATTR: function(match, curLoop, inplace, result, not, isXML){ bgneal@45: var name = match[1].replace(/\\/g, ""); bgneal@45: bgneal@45: if ( !isXML && Expr.attrMap[name] ) { bgneal@45: match[1] = Expr.attrMap[name]; bgneal@45: } bgneal@45: bgneal@45: if ( match[2] === "~=" ) { bgneal@45: match[4] = " " + match[4] + " "; bgneal@45: } bgneal@45: bgneal@45: return match; bgneal@45: }, bgneal@45: PSEUDO: function(match, curLoop, inplace, result, not){ bgneal@45: if ( match[1] === "not" ) { bgneal@45: // If we're dealing with a complex expression, or a simple one bgneal@45: if ( ( chunker.exec(match[3]) || "" ).length > 1 || /^\w/.test(match[3]) ) { bgneal@45: match[3] = Sizzle(match[3], null, null, curLoop); bgneal@45: } else { bgneal@45: var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not); bgneal@45: if ( !inplace ) { bgneal@45: result.push.apply( result, ret ); bgneal@45: } bgneal@45: return false; bgneal@45: } bgneal@45: } else if ( Expr.match.POS.test( match[0] ) || Expr.match.CHILD.test( match[0] ) ) { bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: return match; bgneal@45: }, bgneal@45: POS: function(match){ bgneal@45: match.unshift( true ); bgneal@45: return match; bgneal@45: } bgneal@45: }, bgneal@45: filters: { bgneal@45: enabled: function(elem){ bgneal@45: return elem.disabled === false && elem.type !== "hidden"; bgneal@45: }, bgneal@45: disabled: function(elem){ bgneal@45: return elem.disabled === true; bgneal@45: }, bgneal@45: checked: function(elem){ bgneal@45: return elem.checked === true; bgneal@45: }, bgneal@45: selected: function(elem){ bgneal@45: // Accessing this property makes selected-by-default bgneal@45: // options in Safari work properly bgneal@45: elem.parentNode.selectedIndex; bgneal@45: return elem.selected === true; bgneal@45: }, bgneal@45: parent: function(elem){ bgneal@45: return !!elem.firstChild; bgneal@45: }, bgneal@45: empty: function(elem){ bgneal@45: return !elem.firstChild; bgneal@45: }, bgneal@45: has: function(elem, i, match){ bgneal@45: return !!Sizzle( match[3], elem ).length; bgneal@45: }, bgneal@45: header: function(elem){ bgneal@45: return (/h\d/i).test( elem.nodeName ); bgneal@45: }, bgneal@45: text: function(elem){ bgneal@45: return "text" === elem.type; bgneal@45: }, bgneal@45: radio: function(elem){ bgneal@45: return "radio" === elem.type; bgneal@45: }, bgneal@45: checkbox: function(elem){ bgneal@45: return "checkbox" === elem.type; bgneal@45: }, bgneal@45: file: function(elem){ bgneal@45: return "file" === elem.type; bgneal@45: }, bgneal@45: password: function(elem){ bgneal@45: return "password" === elem.type; bgneal@45: }, bgneal@45: submit: function(elem){ bgneal@45: return "submit" === elem.type; bgneal@45: }, bgneal@45: image: function(elem){ bgneal@45: return "image" === elem.type; bgneal@45: }, bgneal@45: reset: function(elem){ bgneal@45: return "reset" === elem.type; bgneal@45: }, bgneal@45: button: function(elem){ bgneal@45: return "button" === elem.type || elem.nodeName.toLowerCase() === "button"; bgneal@45: }, bgneal@45: input: function(elem){ bgneal@45: return (/input|select|textarea|button/i).test(elem.nodeName); bgneal@45: } bgneal@45: }, bgneal@45: setFilters: { bgneal@45: first: function(elem, i){ bgneal@45: return i === 0; bgneal@45: }, bgneal@45: last: function(elem, i, match, array){ bgneal@45: return i === array.length - 1; bgneal@45: }, bgneal@45: even: function(elem, i){ bgneal@45: return i % 2 === 0; bgneal@45: }, bgneal@45: odd: function(elem, i){ bgneal@45: return i % 2 === 1; bgneal@45: }, bgneal@45: lt: function(elem, i, match){ bgneal@45: return i < match[3] - 0; bgneal@45: }, bgneal@45: gt: function(elem, i, match){ bgneal@45: return i > match[3] - 0; bgneal@45: }, bgneal@45: nth: function(elem, i, match){ bgneal@45: return match[3] - 0 === i; bgneal@45: }, bgneal@45: eq: function(elem, i, match){ bgneal@45: return match[3] - 0 === i; bgneal@45: } bgneal@45: }, bgneal@45: filter: { bgneal@45: PSEUDO: function(elem, match, i, array){ bgneal@45: var name = match[1], filter = Expr.filters[ name ]; bgneal@45: bgneal@45: if ( filter ) { bgneal@45: return filter( elem, i, match, array ); bgneal@45: } else if ( name === "contains" ) { bgneal@45: return (elem.textContent || elem.innerText || Sizzle.getText([ elem ]) || "").indexOf(match[3]) >= 0; bgneal@45: } else if ( name === "not" ) { bgneal@45: var not = match[3]; bgneal@45: bgneal@45: for ( var j = 0, l = not.length; j < l; j++ ) { bgneal@45: if ( not[j] === elem ) { bgneal@45: return false; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return true; bgneal@45: } else { bgneal@45: Sizzle.error( "Syntax error, unrecognized expression: " + name ); bgneal@45: } bgneal@45: }, bgneal@45: CHILD: function(elem, match){ bgneal@45: var type = match[1], node = elem; bgneal@45: switch (type) { bgneal@45: case 'only': bgneal@45: case 'first': bgneal@45: while ( (node = node.previousSibling) ) { bgneal@45: if ( node.nodeType === 1 ) { bgneal@45: return false; bgneal@45: } bgneal@45: } bgneal@45: if ( type === "first" ) { bgneal@45: return true; bgneal@45: } bgneal@45: node = elem; bgneal@45: case 'last': bgneal@45: while ( (node = node.nextSibling) ) { bgneal@45: if ( node.nodeType === 1 ) { bgneal@45: return false; bgneal@45: } bgneal@45: } bgneal@45: return true; bgneal@45: case 'nth': bgneal@45: var first = match[2], last = match[3]; bgneal@45: bgneal@45: if ( first === 1 && last === 0 ) { bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: var doneName = match[0], bgneal@45: parent = elem.parentNode; bgneal@45: bgneal@45: if ( parent && (parent.sizcache !== doneName || !elem.nodeIndex) ) { bgneal@45: var count = 0; bgneal@45: for ( node = parent.firstChild; node; node = node.nextSibling ) { bgneal@45: if ( node.nodeType === 1 ) { bgneal@45: node.nodeIndex = ++count; bgneal@45: } bgneal@45: } bgneal@45: parent.sizcache = doneName; bgneal@45: } bgneal@45: bgneal@45: var diff = elem.nodeIndex - last; bgneal@45: if ( first === 0 ) { bgneal@45: return diff === 0; bgneal@45: } else { bgneal@45: return ( diff % first === 0 && diff / first >= 0 ); bgneal@45: } bgneal@45: } bgneal@45: }, bgneal@45: ID: function(elem, match){ bgneal@45: return elem.nodeType === 1 && elem.getAttribute("id") === match; bgneal@45: }, bgneal@45: TAG: function(elem, match){ bgneal@45: return (match === "*" && elem.nodeType === 1) || elem.nodeName.toLowerCase() === match; bgneal@45: }, bgneal@45: CLASS: function(elem, match){ bgneal@45: return (" " + (elem.className || elem.getAttribute("class")) + " ") bgneal@45: .indexOf( match ) > -1; bgneal@45: }, bgneal@45: ATTR: function(elem, match){ bgneal@45: var name = match[1], bgneal@45: result = Expr.attrHandle[ name ] ? bgneal@45: Expr.attrHandle[ name ]( elem ) : bgneal@45: elem[ name ] != null ? bgneal@45: elem[ name ] : bgneal@45: elem.getAttribute( name ), bgneal@45: value = result + "", bgneal@45: type = match[2], bgneal@45: check = match[4]; bgneal@45: bgneal@45: return result == null ? bgneal@45: type === "!=" : bgneal@45: type === "=" ? bgneal@45: value === check : bgneal@45: type === "*=" ? bgneal@45: value.indexOf(check) >= 0 : bgneal@45: type === "~=" ? bgneal@45: (" " + value + " ").indexOf(check) >= 0 : bgneal@45: !check ? bgneal@45: value && result !== false : bgneal@45: type === "!=" ? bgneal@45: value !== check : bgneal@45: type === "^=" ? bgneal@45: value.indexOf(check) === 0 : bgneal@45: type === "$=" ? bgneal@45: value.substr(value.length - check.length) === check : bgneal@45: type === "|=" ? bgneal@45: value === check || value.substr(0, check.length + 1) === check + "-" : bgneal@45: false; bgneal@45: }, bgneal@45: POS: function(elem, match, i, array){ bgneal@45: var name = match[2], filter = Expr.setFilters[ name ]; bgneal@45: bgneal@45: if ( filter ) { bgneal@45: return filter( elem, i, match, array ); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: var origPOS = Expr.match.POS, bgneal@45: fescape = function(all, num){ bgneal@45: return "\\" + (num - 0 + 1); bgneal@45: }; bgneal@45: bgneal@45: for ( var type in Expr.match ) { bgneal@45: Expr.match[ type ] = new RegExp( Expr.match[ type ].source + (/(?![^\[]*\])(?![^\(]*\))/.source) ); bgneal@45: Expr.leftMatch[ type ] = new RegExp( /(^(?:.|\r|\n)*?)/.source + Expr.match[ type ].source.replace(/\\(\d+)/g, fescape) ); bgneal@45: } bgneal@45: bgneal@45: var makeArray = function(array, results) { bgneal@45: array = Array.prototype.slice.call( array, 0 ); bgneal@45: bgneal@45: if ( results ) { bgneal@45: results.push.apply( results, array ); bgneal@45: return results; bgneal@45: } bgneal@45: bgneal@45: return array; bgneal@45: }; bgneal@45: bgneal@45: // Perform a simple check to determine if the browser is capable of bgneal@45: // converting a NodeList to an array using builtin methods. bgneal@45: // Also verifies that the returned array holds DOM nodes bgneal@45: // (which is not the case in the Blackberry browser) bgneal@45: try { bgneal@45: Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType; bgneal@45: bgneal@45: // Provide a fallback method if it does not work bgneal@45: } catch(e){ bgneal@45: makeArray = function(array, results) { bgneal@45: var ret = results || [], i = 0; bgneal@45: bgneal@45: if ( toString.call(array) === "[object Array]" ) { bgneal@45: Array.prototype.push.apply( ret, array ); bgneal@45: } else { bgneal@45: if ( typeof array.length === "number" ) { bgneal@45: for ( var l = array.length; i < l; i++ ) { bgneal@45: ret.push( array[i] ); bgneal@45: } bgneal@45: } else { bgneal@45: for ( ; array[i]; i++ ) { bgneal@45: ret.push( array[i] ); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return ret; bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: var sortOrder; bgneal@45: bgneal@45: if ( document.documentElement.compareDocumentPosition ) { bgneal@45: sortOrder = function( a, b ) { bgneal@45: if ( !a.compareDocumentPosition || !b.compareDocumentPosition ) { bgneal@45: if ( a == b ) { bgneal@45: hasDuplicate = true; bgneal@45: } bgneal@45: return a.compareDocumentPosition ? -1 : 1; bgneal@45: } bgneal@45: bgneal@45: var ret = a.compareDocumentPosition(b) & 4 ? -1 : a === b ? 0 : 1; bgneal@45: if ( ret === 0 ) { bgneal@45: hasDuplicate = true; bgneal@45: } bgneal@45: return ret; bgneal@45: }; bgneal@45: } else if ( "sourceIndex" in document.documentElement ) { bgneal@45: sortOrder = function( a, b ) { bgneal@45: if ( !a.sourceIndex || !b.sourceIndex ) { bgneal@45: if ( a == b ) { bgneal@45: hasDuplicate = true; bgneal@45: } bgneal@45: return a.sourceIndex ? -1 : 1; bgneal@45: } bgneal@45: bgneal@45: var ret = a.sourceIndex - b.sourceIndex; bgneal@45: if ( ret === 0 ) { bgneal@45: hasDuplicate = true; bgneal@45: } bgneal@45: return ret; bgneal@45: }; bgneal@45: } else if ( document.createRange ) { bgneal@45: sortOrder = function( a, b ) { bgneal@45: if ( !a.ownerDocument || !b.ownerDocument ) { bgneal@45: if ( a == b ) { bgneal@45: hasDuplicate = true; bgneal@45: } bgneal@45: return a.ownerDocument ? -1 : 1; bgneal@45: } bgneal@45: bgneal@45: var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange(); bgneal@45: aRange.setStart(a, 0); bgneal@45: aRange.setEnd(a, 0); bgneal@45: bRange.setStart(b, 0); bgneal@45: bRange.setEnd(b, 0); bgneal@45: var ret = aRange.compareBoundaryPoints(Range.START_TO_END, bRange); bgneal@45: if ( ret === 0 ) { bgneal@45: hasDuplicate = true; bgneal@45: } bgneal@45: return ret; bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: // Utility function for retreiving the text value of an array of DOM nodes bgneal@45: Sizzle.getText = function( elems ) { bgneal@45: var ret = "", elem; bgneal@45: bgneal@45: for ( var i = 0; elems[i]; i++ ) { bgneal@45: elem = elems[i]; bgneal@45: bgneal@45: // Get the text from text nodes and CDATA nodes bgneal@45: if ( elem.nodeType === 3 || elem.nodeType === 4 ) { bgneal@45: ret += elem.nodeValue; bgneal@45: bgneal@45: // Traverse everything else, except comment nodes bgneal@45: } else if ( elem.nodeType !== 8 ) { bgneal@45: ret += Sizzle.getText( elem.childNodes ); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return ret; bgneal@45: }; bgneal@45: bgneal@45: // Check to see if the browser returns elements by name when bgneal@45: // querying by getElementById (and provide a workaround) bgneal@45: (function(){ bgneal@45: // We're going to inject a fake input element with a specified name bgneal@45: var form = document.createElement("div"), bgneal@45: id = "script" + (new Date()).getTime(); bgneal@45: form.innerHTML = ""; bgneal@45: bgneal@45: // Inject it into the root element, check its status, and remove it quickly bgneal@45: var root = document.documentElement; bgneal@45: root.insertBefore( form, root.firstChild ); bgneal@45: bgneal@45: // The workaround has to do additional checks after a getElementById bgneal@45: // Which slows things down for other browsers (hence the branching) bgneal@45: if ( document.getElementById( id ) ) { bgneal@45: Expr.find.ID = function(match, context, isXML){ bgneal@45: if ( typeof context.getElementById !== "undefined" && !isXML ) { bgneal@45: var m = context.getElementById(match[1]); bgneal@45: return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : []; bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: Expr.filter.ID = function(elem, match){ bgneal@45: var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id"); bgneal@45: return elem.nodeType === 1 && node && node.nodeValue === match; bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: root.removeChild( form ); bgneal@45: root = form = null; // release memory in IE bgneal@45: })(); bgneal@45: bgneal@45: (function(){ bgneal@45: // Check to see if the browser returns only elements bgneal@45: // when doing getElementsByTagName("*") bgneal@45: bgneal@45: // Create a fake element bgneal@45: var div = document.createElement("div"); bgneal@45: div.appendChild( document.createComment("") ); bgneal@45: bgneal@45: // Make sure no comments are found bgneal@45: if ( div.getElementsByTagName("*").length > 0 ) { bgneal@45: Expr.find.TAG = function(match, context){ bgneal@45: var results = context.getElementsByTagName(match[1]); bgneal@45: bgneal@45: // Filter out possible comments bgneal@45: if ( match[1] === "*" ) { bgneal@45: var tmp = []; bgneal@45: bgneal@45: for ( var i = 0; results[i]; i++ ) { bgneal@45: if ( results[i].nodeType === 1 ) { bgneal@45: tmp.push( results[i] ); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: results = tmp; bgneal@45: } bgneal@45: bgneal@45: return results; bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: // Check to see if an attribute returns normalized href attributes bgneal@45: div.innerHTML = ""; bgneal@45: if ( div.firstChild && typeof div.firstChild.getAttribute !== "undefined" && bgneal@45: div.firstChild.getAttribute("href") !== "#" ) { bgneal@45: Expr.attrHandle.href = function(elem){ bgneal@45: return elem.getAttribute("href", 2); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: div = null; // release memory in IE bgneal@45: })(); bgneal@45: bgneal@45: if ( document.querySelectorAll ) { bgneal@45: (function(){ bgneal@45: var oldSizzle = Sizzle, div = document.createElement("div"); bgneal@45: div.innerHTML = "

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

    ] becomes

    ]

    bgneal@45: rng.moveToElementText(rng2.parentElement()); bgneal@45: if (rng.compareEndPoints('StartToEnd', rng2) == 0) bgneal@45: rng2.move('character', -1); bgneal@45: bgneal@45: rng2.pasteHTML('' + chr + ''); bgneal@45: } bgneal@45: } catch (ex) { bgneal@45: // IE might throw unspecified error so lets ignore it bgneal@45: return null; bgneal@45: } bgneal@45: } else { bgneal@45: // Control selection bgneal@45: element = rng.item(0); bgneal@45: name = element.nodeName; bgneal@45: bgneal@45: return {name : name, index : findIndex(name, element)}; bgneal@45: } bgneal@45: } else { bgneal@45: element = t.getNode(); bgneal@45: name = element.nodeName; bgneal@45: if (name == 'IMG') bgneal@45: return {name : name, index : findIndex(name, element)}; bgneal@45: bgneal@45: // W3C method bgneal@45: rng2 = rng.cloneRange(); bgneal@45: bgneal@45: // Insert end marker bgneal@45: if (!collapsed) { bgneal@45: rng2.collapse(false); bgneal@45: rng2.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_end', style : styles}, chr)); bgneal@45: } bgneal@45: bgneal@45: rng.collapse(true); bgneal@45: rng.insertNode(dom.create('span', {'data-mce-type' : "bookmark", id : id + '_start', style : styles}, chr)); bgneal@45: } bgneal@45: bgneal@45: t.moveToBookmark({id : id, keep : 1}); bgneal@45: bgneal@45: return {id : id}; bgneal@45: }, bgneal@45: bgneal@45: moveToBookmark : function(bookmark) { bgneal@45: var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset; bgneal@45: bgneal@45: if (bookmark) { bgneal@45: if (bookmark.start) { bgneal@45: rng = dom.createRng(); bgneal@45: root = dom.getRoot(); bgneal@45: bgneal@45: function setEndPoint(start) { bgneal@45: var point = bookmark[start ? 'start' : 'end'], i, node, offset, children; bgneal@45: bgneal@45: if (point) { bgneal@45: offset = point[0]; bgneal@45: bgneal@45: // Find container node bgneal@45: for (node = root, i = point.length - 1; i >= 1; i--) { bgneal@45: children = node.childNodes; bgneal@45: bgneal@45: if (point[i] > children.length - 1) bgneal@45: return; bgneal@45: bgneal@45: node = children[point[i]]; bgneal@45: } bgneal@45: bgneal@45: // Move text offset to best suitable location bgneal@45: if (node.nodeType === 3) bgneal@45: offset = Math.min(point[0], node.nodeValue.length); bgneal@45: bgneal@45: // Move element offset to best suitable location bgneal@45: if (node.nodeType === 1) bgneal@45: offset = Math.min(point[0], node.childNodes.length); bgneal@45: bgneal@45: // Set offset within container node bgneal@45: if (start) bgneal@45: rng.setStart(node, offset); bgneal@45: else bgneal@45: rng.setEnd(node, offset); bgneal@45: } bgneal@45: bgneal@45: return true; bgneal@45: }; bgneal@45: bgneal@45: if (t.tridentSel) bgneal@45: return t.tridentSel.moveToBookmark(bookmark); bgneal@45: bgneal@45: if (setEndPoint(true) && setEndPoint()) { bgneal@45: t.setRng(rng); bgneal@45: } bgneal@45: } else if (bookmark.id) { bgneal@45: function restoreEndPoint(suffix) { bgneal@45: var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep; bgneal@45: bgneal@45: if (marker) { bgneal@45: node = marker.parentNode; bgneal@45: bgneal@45: if (suffix == 'start') { bgneal@45: if (!keep) { bgneal@45: idx = dom.nodeIndex(marker); bgneal@45: } else { bgneal@45: node = marker.firstChild; bgneal@45: idx = 1; bgneal@45: } bgneal@45: bgneal@45: startContainer = endContainer = node; bgneal@45: startOffset = endOffset = idx; bgneal@45: } else { bgneal@45: if (!keep) { bgneal@45: idx = dom.nodeIndex(marker); bgneal@45: } else { bgneal@45: node = marker.firstChild; bgneal@45: idx = 1; bgneal@45: } bgneal@45: bgneal@45: endContainer = node; bgneal@45: endOffset = idx; bgneal@45: } bgneal@45: bgneal@45: if (!keep) { bgneal@45: prev = marker.previousSibling; bgneal@45: next = marker.nextSibling; bgneal@45: bgneal@45: // Remove all marker text nodes bgneal@45: each(tinymce.grep(marker.childNodes), function(node) { bgneal@45: if (node.nodeType == 3) bgneal@45: node.nodeValue = node.nodeValue.replace(/\uFEFF/g, ''); bgneal@45: }); bgneal@45: bgneal@45: // Remove marker but keep children if for example contents where inserted into the marker bgneal@45: // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature bgneal@45: while (marker = dom.get(bookmark.id + '_' + suffix)) bgneal@45: dom.remove(marker, 1); bgneal@45: bgneal@45: // If siblings are text nodes then merge them unless it's Opera since it some how removes the node bgneal@45: // 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@45: if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !tinymce.isOpera) { bgneal@45: idx = prev.nodeValue.length; bgneal@45: prev.appendData(next.nodeValue); bgneal@45: dom.remove(next); bgneal@45: bgneal@45: if (suffix == 'start') { bgneal@45: startContainer = endContainer = prev; bgneal@45: startOffset = endOffset = idx; bgneal@45: } else { bgneal@45: endContainer = prev; bgneal@45: endOffset = idx; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function addBogus(node) { bgneal@45: // Adds a bogus BR element for empty block elements or just a space on IE since it renders BR elements incorrectly bgneal@45: if (dom.isBlock(node) && !node.innerHTML) bgneal@45: node.innerHTML = !isIE ? '
    ' : ' '; bgneal@45: bgneal@45: return node; bgneal@45: }; bgneal@45: bgneal@45: // Restore start/end points bgneal@45: restoreEndPoint('start'); bgneal@45: restoreEndPoint('end'); bgneal@45: bgneal@45: if (startContainer) { bgneal@45: rng = dom.createRng(); bgneal@45: rng.setStart(addBogus(startContainer), startOffset); bgneal@45: rng.setEnd(addBogus(endContainer), endOffset); bgneal@45: t.setRng(rng); bgneal@45: } bgneal@45: } else if (bookmark.name) { bgneal@45: t.select(dom.select(bookmark.name)[bookmark.index]); bgneal@45: } else if (bookmark.rng) bgneal@45: t.setRng(bookmark.rng); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: select : function(node, content) { bgneal@45: var t = this, dom = t.dom, rng = dom.createRng(), idx; bgneal@45: bgneal@45: if (node) { bgneal@45: idx = dom.nodeIndex(node); bgneal@45: rng.setStart(node.parentNode, idx); bgneal@45: rng.setEnd(node.parentNode, idx + 1); bgneal@45: bgneal@45: // Find first/last text node or BR element bgneal@45: if (content) { bgneal@45: function setPoint(node, start) { bgneal@45: var walker = new tinymce.dom.TreeWalker(node, node); bgneal@45: bgneal@45: do { bgneal@45: // Text node bgneal@45: if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) { bgneal@45: if (start) bgneal@45: rng.setStart(node, 0); bgneal@45: else bgneal@45: rng.setEnd(node, node.nodeValue.length); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // BR element bgneal@45: if (node.nodeName == 'BR') { bgneal@45: if (start) bgneal@45: rng.setStartBefore(node); bgneal@45: else bgneal@45: rng.setEndBefore(node); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: } while (node = (start ? walker.next() : walker.prev())); bgneal@45: }; bgneal@45: bgneal@45: setPoint(node, 1); bgneal@45: setPoint(node); bgneal@45: } bgneal@45: bgneal@45: t.setRng(rng); bgneal@45: } bgneal@45: bgneal@45: return node; bgneal@45: }, bgneal@45: bgneal@45: isCollapsed : function() { bgneal@45: var t = this, r = t.getRng(), s = t.getSel(); bgneal@45: bgneal@45: if (!r || r.item) bgneal@45: return false; bgneal@45: bgneal@45: if (r.compareEndPoints) bgneal@45: return r.compareEndPoints('StartToEnd', r) === 0; bgneal@45: bgneal@45: return !s || r.collapsed; bgneal@45: }, bgneal@45: bgneal@45: collapse : function(to_start) { bgneal@45: var self = this, rng = self.getRng(), node; bgneal@45: bgneal@45: // Control range on IE bgneal@45: if (rng.item) { bgneal@45: node = rng.item(0); bgneal@45: rng = self.win.document.body.createTextRange(); bgneal@45: rng.moveToElementText(node); bgneal@45: } bgneal@45: bgneal@45: rng.collapse(!!to_start); bgneal@45: self.setRng(rng); bgneal@45: }, bgneal@45: bgneal@45: getSel : function() { bgneal@45: var t = this, w = this.win; bgneal@45: bgneal@45: return w.getSelection ? w.getSelection() : w.document.selection; bgneal@45: }, bgneal@45: bgneal@45: getRng : function(w3c) { bgneal@45: var t = this, s, r, elm, doc = t.win.document; bgneal@45: bgneal@45: // Found tridentSel object then we need to use that one bgneal@45: if (w3c && t.tridentSel) bgneal@45: return t.tridentSel.getRangeAt(0); bgneal@45: bgneal@45: try { bgneal@45: if (s = t.getSel()) bgneal@45: r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : doc.createRange()); bgneal@45: } catch (ex) { bgneal@45: // IE throws unspecified error here if TinyMCE is placed in a frame/iframe bgneal@45: } bgneal@45: bgneal@45: // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet bgneal@45: if (tinymce.isIE && r && r.setStart && doc.selection.createRange().item) { bgneal@45: elm = doc.selection.createRange().item(0); bgneal@45: r = doc.createRange(); bgneal@45: r.setStartBefore(elm); bgneal@45: r.setEndAfter(elm); bgneal@45: } bgneal@45: bgneal@45: // No range found then create an empty one bgneal@45: // This can occur when the editor is placed in a hidden container element on Gecko bgneal@45: // Or on IE when there was an exception bgneal@45: if (!r) bgneal@45: r = doc.createRange ? doc.createRange() : doc.body.createTextRange(); bgneal@45: bgneal@45: if (t.selectedRange && t.explicitRange) { bgneal@45: if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) { bgneal@45: // Safari, Opera and Chrome only ever select text which causes the range to change. bgneal@45: // This lets us use the originally set range if the selection hasn't been changed by the user. bgneal@45: r = t.explicitRange; bgneal@45: } else { bgneal@45: t.selectedRange = null; bgneal@45: t.explicitRange = null; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return r; bgneal@45: }, bgneal@45: bgneal@45: setRng : function(r) { bgneal@45: var s, t = this; bgneal@45: bgneal@45: if (!t.tridentSel) { bgneal@45: s = t.getSel(); bgneal@45: bgneal@45: if (s) { bgneal@45: t.explicitRange = r; bgneal@45: bgneal@45: try { bgneal@45: s.removeAllRanges(); bgneal@45: } catch (ex) { bgneal@45: // IE9 might throw errors here don't know why bgneal@45: } bgneal@45: bgneal@45: s.addRange(r); bgneal@45: // adding range isn't always successful so we need to check range count otherwise an exception can occur bgneal@45: t.selectedRange = s.rangeCount > 0 ? s.getRangeAt(0) : null; bgneal@45: } bgneal@45: } else { bgneal@45: // Is W3C Range bgneal@45: if (r.cloneRange) { bgneal@45: try { bgneal@45: t.tridentSel.addRange(r); bgneal@45: return; bgneal@45: } catch (ex) { bgneal@45: //IE9 throws an error here if called before selection is placed in the editor bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Is IE specific range bgneal@45: try { bgneal@45: r.select(); bgneal@45: } catch (ex) { bgneal@45: // Needed for some odd IE bug #1843306 bgneal@45: } bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: setNode : function(n) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.setContent(t.dom.getOuterHTML(n)); bgneal@45: bgneal@45: return n; bgneal@45: }, bgneal@45: bgneal@45: getNode : function() { bgneal@45: var t = this, rng = t.getRng(), sel = t.getSel(), elm, start = rng.startContainer, end = rng.endContainer; bgneal@45: bgneal@45: // Range maybe lost after the editor is made visible again bgneal@45: if (!rng) bgneal@45: return t.dom.getRoot(); bgneal@45: bgneal@45: if (rng.setStart) { bgneal@45: elm = rng.commonAncestorContainer; bgneal@45: bgneal@45: // Handle selection a image or other control like element such as anchors bgneal@45: if (!rng.collapsed) { bgneal@45: if (rng.startContainer == rng.endContainer) { bgneal@45: if (rng.endOffset - rng.startOffset < 2) { bgneal@45: if (rng.startContainer.hasChildNodes()) bgneal@45: elm = rng.startContainer.childNodes[rng.startOffset]; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // If the anchor node is a element instead of a text node then return this element bgneal@45: //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1) bgneal@45: // return sel.anchorNode.childNodes[sel.anchorOffset]; bgneal@45: bgneal@45: // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent. bgneal@45: // This happens when you double click an underlined word in FireFox. bgneal@45: if (start.nodeType === 3 && end.nodeType === 3) { bgneal@45: function skipEmptyTextNodes(n, forwards) { bgneal@45: var orig = n; bgneal@45: while (n && n.nodeType === 3 && n.length === 0) { bgneal@45: n = forwards ? n.nextSibling : n.previousSibling; bgneal@45: } bgneal@45: return n || orig; bgneal@45: } bgneal@45: if (start.length === rng.startOffset) { bgneal@45: start = skipEmptyTextNodes(start.nextSibling, true); bgneal@45: } else { bgneal@45: start = start.parentNode; bgneal@45: } bgneal@45: if (rng.endOffset === 0) { bgneal@45: end = skipEmptyTextNodes(end.previousSibling, false); bgneal@45: } else { bgneal@45: end = end.parentNode; bgneal@45: } bgneal@45: bgneal@45: if (start && start === end) bgneal@45: return start; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if (elm && elm.nodeType == 3) bgneal@45: return elm.parentNode; bgneal@45: bgneal@45: return elm; bgneal@45: } bgneal@45: bgneal@45: return rng.item ? rng.item(0) : rng.parentElement(); bgneal@45: }, bgneal@45: bgneal@45: getSelectedBlocks : function(st, en) { bgneal@45: var t = this, dom = t.dom, sb, eb, n, bl = []; bgneal@45: bgneal@45: sb = dom.getParent(st || t.getStart(), dom.isBlock); bgneal@45: eb = dom.getParent(en || t.getEnd(), dom.isBlock); bgneal@45: bgneal@45: if (sb) bgneal@45: bl.push(sb); bgneal@45: bgneal@45: if (sb && eb && sb != eb) { bgneal@45: n = sb; bgneal@45: bgneal@45: var walker = new tinymce.dom.TreeWalker(sb, dom.getRoot()); bgneal@45: while ((n = walker.next()) && n != eb) { bgneal@45: if (dom.isBlock(n)) bgneal@45: bl.push(n); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if (eb && sb != eb) bgneal@45: bl.push(eb); bgneal@45: bgneal@45: return bl; bgneal@45: }, bgneal@45: bgneal@45: normalize : function() { bgneal@45: var self = this, rng, normalized; bgneal@45: bgneal@45: // TODO: bgneal@45: // Retain selection direction. bgneal@45: // Lean left/right on Gecko for inline elements. bgneal@45: // Run this on mouse up/key up when the user manually moves the selection bgneal@45: bgneal@45: // Normalize only on non IE browsers for now bgneal@45: if (tinymce.isIE) bgneal@45: return; bgneal@45: bgneal@45: function normalizeEndPoint(start) { bgneal@45: var container, offset, walker, dom = self.dom, body = dom.getRoot(), node; bgneal@45: bgneal@45: container = rng[(start ? 'start' : 'end') + 'Container']; bgneal@45: offset = rng[(start ? 'start' : 'end') + 'Offset']; bgneal@45: bgneal@45: // If the container is a document move it to the body element bgneal@45: if (container.nodeType === 9) { bgneal@45: container = container.body; bgneal@45: offset = 0; bgneal@45: } bgneal@45: bgneal@45: // If the container is body try move it into the closest text node or position bgneal@45: // TODO: Add more logic here to handle element selection cases bgneal@45: if (container === body) { bgneal@45: // Resolve the index bgneal@45: if (container.hasChildNodes()) { bgneal@45: container = container.childNodes[Math.min(!start && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1)]; bgneal@45: offset = 0; bgneal@45: bgneal@45: // Don't walk into elements that doesn't have any child nodes like a IMG bgneal@45: if (container.hasChildNodes()) { bgneal@45: // Walk the DOM to find a text node to place the caret at or a BR bgneal@45: node = container; bgneal@45: walker = new tinymce.dom.TreeWalker(container, body); bgneal@45: do { bgneal@45: // Found a text node use that position bgneal@45: if (node.nodeType === 3) { bgneal@45: offset = start ? 0 : node.nodeValue.length - 1; bgneal@45: container = node; bgneal@45: normalized = true; bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: // Found a BR/IMG element that we can place the caret before bgneal@45: if (/^(BR|IMG)$/.test(node.nodeName)) { bgneal@45: offset = dom.nodeIndex(node); bgneal@45: container = node.parentNode; bgneal@45: bgneal@45: // Put caret after image when moving the end point bgneal@45: if (node.nodeName == "IMG" && !start) { bgneal@45: offset++; bgneal@45: } bgneal@45: bgneal@45: normalized = true; bgneal@45: break; bgneal@45: } bgneal@45: } while (node = (start ? walker.next() : walker.prev())); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Set endpoint if it was normalized bgneal@45: if (normalized) bgneal@45: rng['set' + (start ? 'Start' : 'End')](container, offset); bgneal@45: }; bgneal@45: bgneal@45: rng = self.getRng(); bgneal@45: bgneal@45: // Normalize the end points bgneal@45: normalizeEndPoint(true); bgneal@45: bgneal@45: if (!rng.collapsed) bgneal@45: normalizeEndPoint(); bgneal@45: bgneal@45: // Set the selection if it was normalized bgneal@45: if (normalized) { bgneal@45: //console.log(self.dom.dumpRng(rng)); bgneal@45: self.setRng(rng); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: destroy : function(s) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.win = null; bgneal@45: bgneal@45: // Manual destroy then remove unload handler bgneal@45: if (!s) bgneal@45: tinymce.removeUnload(t.destroy); bgneal@45: }, bgneal@45: bgneal@45: // 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@45: _fixIESelection : function() { bgneal@45: var dom = this.dom, doc = dom.doc, body = doc.body, started, startRng, htmlElm; bgneal@45: bgneal@45: // Make HTML element unselectable since we are going to handle selection by hand bgneal@45: doc.documentElement.unselectable = true; bgneal@45: bgneal@45: // Return range from point or null if it failed bgneal@45: function rngFromPoint(x, y) { bgneal@45: var rng = body.createTextRange(); bgneal@45: bgneal@45: try { bgneal@45: rng.moveToPoint(x, y); bgneal@45: } catch (ex) { bgneal@45: // IE sometimes throws and exception, so lets just ignore it bgneal@45: rng = null; bgneal@45: } bgneal@45: bgneal@45: return rng; bgneal@45: }; bgneal@45: bgneal@45: // Fires while the selection is changing bgneal@45: function selectionChange(e) { bgneal@45: var pointRng; bgneal@45: bgneal@45: // Check if the button is down or not bgneal@45: if (e.button) { bgneal@45: // Create range from mouse position bgneal@45: pointRng = rngFromPoint(e.x, e.y); bgneal@45: bgneal@45: if (pointRng) { bgneal@45: // Check if pointRange is before/after selection then change the endPoint bgneal@45: if (pointRng.compareEndPoints('StartToStart', startRng) > 0) bgneal@45: pointRng.setEndPoint('StartToStart', startRng); bgneal@45: else bgneal@45: pointRng.setEndPoint('EndToEnd', startRng); bgneal@45: bgneal@45: pointRng.select(); bgneal@45: } bgneal@45: } else bgneal@45: endSelection(); bgneal@45: } bgneal@45: bgneal@45: // Removes listeners bgneal@45: function endSelection() { bgneal@45: var rng = doc.selection.createRange(); bgneal@45: bgneal@45: // If the range is collapsed then use the last start range bgneal@45: if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0) bgneal@45: startRng.select(); bgneal@45: bgneal@45: dom.unbind(doc, 'mouseup', endSelection); bgneal@45: dom.unbind(doc, 'mousemove', selectionChange); bgneal@45: startRng = started = 0; bgneal@45: }; bgneal@45: bgneal@45: // Detect when user selects outside BODY bgneal@45: dom.bind(doc, ['mousedown', 'contextmenu'], function(e) { bgneal@45: if (e.target.nodeName === 'HTML') { bgneal@45: if (started) bgneal@45: endSelection(); bgneal@45: bgneal@45: // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML bgneal@45: htmlElm = doc.documentElement; bgneal@45: if (htmlElm.scrollHeight > htmlElm.clientHeight) bgneal@45: return; bgneal@45: bgneal@45: started = 1; bgneal@45: // Setup start position bgneal@45: startRng = rngFromPoint(e.x, e.y); bgneal@45: if (startRng) { bgneal@45: // Listen for selection change events bgneal@45: dom.bind(doc, 'mouseup', endSelection); bgneal@45: dom.bind(doc, 'mousemove', selectionChange); bgneal@45: bgneal@45: dom.win.focus(); bgneal@45: startRng.select(); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: tinymce.dom.Serializer = function(settings, dom, schema) { bgneal@45: var onPreProcess, onPostProcess, isIE = tinymce.isIE, each = tinymce.each, htmlParser; bgneal@45: bgneal@45: // Support the old apply_source_formatting option bgneal@45: if (!settings.apply_source_formatting) bgneal@45: settings.indent = false; bgneal@45: bgneal@45: // Default DOM and Schema if they are undefined bgneal@45: dom = dom || tinymce.DOM; bgneal@45: schema = schema || new tinymce.html.Schema(settings); bgneal@45: settings.entity_encoding = settings.entity_encoding || 'named'; bgneal@45: settings.remove_trailing_brs = "remove_trailing_brs" in settings ? settings.remove_trailing_brs : true; bgneal@45: bgneal@45: onPreProcess = new tinymce.util.Dispatcher(self); bgneal@45: bgneal@45: onPostProcess = new tinymce.util.Dispatcher(self); bgneal@45: bgneal@45: htmlParser = new tinymce.html.DomParser(settings, schema); bgneal@45: bgneal@45: // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed bgneal@45: htmlParser.addAttributeFilter('src,href,style', function(nodes, name) { bgneal@45: var i = nodes.length, node, value, internalName = 'data-mce-' + name, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef; bgneal@45: bgneal@45: while (i--) { bgneal@45: node = nodes[i]; bgneal@45: bgneal@45: value = node.attributes.map[internalName]; bgneal@45: if (value !== undef) { bgneal@45: // Set external name to internal value and remove internal bgneal@45: node.attr(name, value.length > 0 ? value : null); bgneal@45: node.attr(internalName, null); bgneal@45: } else { bgneal@45: // No internal attribute found then convert the value we have in the DOM bgneal@45: value = node.attributes.map[name]; bgneal@45: bgneal@45: if (name === "style") bgneal@45: value = dom.serializeStyle(dom.parseStyle(value), node.name); bgneal@45: else if (urlConverter) bgneal@45: value = urlConverter.call(urlConverterScope, value, name, node.name); bgneal@45: bgneal@45: node.attr(name, value.length > 0 ? value : null); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Remove internal classes mceItem<..> bgneal@45: htmlParser.addAttributeFilter('class', function(nodes, name) { bgneal@45: var i = nodes.length, node, value; bgneal@45: bgneal@45: while (i--) { bgneal@45: node = nodes[i]; bgneal@45: value = node.attr('class').replace(/\s*mce(Item\w+|Selected)\s*/g, ''); bgneal@45: node.attr('class', value.length > 0 ? value : null); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Remove bookmark elements bgneal@45: htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) { bgneal@45: var i = nodes.length, node; bgneal@45: bgneal@45: while (i--) { bgneal@45: node = nodes[i]; bgneal@45: bgneal@45: if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup) bgneal@45: node.remove(); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Remove expando attributes bgneal@45: htmlParser.addAttributeFilter('data-mce-expando', function(nodes, name, args) { bgneal@45: var i = nodes.length; bgneal@45: bgneal@45: while (i--) { bgneal@45: nodes[i].attr(name, null); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Force script into CDATA sections and remove the mce- prefix also add comments around styles bgneal@45: htmlParser.addNodeFilter('script,style', function(nodes, name) { bgneal@45: var i = nodes.length, node, value; bgneal@45: bgneal@45: function trim(value) { bgneal@45: return value.replace(/()/g, '\n') bgneal@45: .replace(/^[\r\n]*|[\r\n]*$/g, '') bgneal@45: .replace(/^\s*(()?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, ''); bgneal@45: }; bgneal@45: bgneal@45: while (i--) { bgneal@45: node = nodes[i]; bgneal@45: value = node.firstChild ? node.firstChild.value : ''; bgneal@45: bgneal@45: if (name === "script") { bgneal@45: // Remove mce- prefix from script elements bgneal@45: node.attr('type', (node.attr('type') || 'text/javascript').replace(/^mce\-/, '')); bgneal@45: bgneal@45: if (value.length > 0) bgneal@45: node.firstChild.value = '// '; bgneal@45: } else { bgneal@45: if (value.length > 0) bgneal@45: node.firstChild.value = ''; bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Convert comments to cdata and handle protected comments bgneal@45: htmlParser.addNodeFilter('#comment', function(nodes, name) { bgneal@45: var i = nodes.length, node; bgneal@45: bgneal@45: while (i--) { bgneal@45: node = nodes[i]; bgneal@45: bgneal@45: if (node.value.indexOf('[CDATA[') === 0) { bgneal@45: node.name = '#cdata'; bgneal@45: node.type = 4; bgneal@45: node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, ''); bgneal@45: } else if (node.value.indexOf('mce:protected ') === 0) { bgneal@45: node.name = "#text"; bgneal@45: node.type = 3; bgneal@45: node.raw = true; bgneal@45: node.value = unescape(node.value).substr(14); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) { bgneal@45: var i = nodes.length, node; bgneal@45: bgneal@45: while (i--) { bgneal@45: node = nodes[i]; bgneal@45: if (node.type === 7) bgneal@45: node.remove(); bgneal@45: else if (node.type === 1) { bgneal@45: if (name === "input" && !("type" in node.attributes.map)) bgneal@45: node.attr('type', 'text'); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Fix list elements, TODO: Replace this later bgneal@45: if (settings.fix_list_elements) { bgneal@45: htmlParser.addNodeFilter('ul,ol', function(nodes, name) { bgneal@45: var i = nodes.length, node, parentNode; bgneal@45: bgneal@45: while (i--) { bgneal@45: node = nodes[i]; bgneal@45: parentNode = node.parent; bgneal@45: bgneal@45: if (parentNode.name === 'ul' || parentNode.name === 'ol') { bgneal@45: if (node.prev && node.prev.name === 'li') { bgneal@45: node.prev.append(node); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // Remove internal data attributes bgneal@45: htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style', function(nodes, name) { bgneal@45: var i = nodes.length; bgneal@45: bgneal@45: while (i--) { bgneal@45: nodes[i].attr(name, null); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Return public methods bgneal@45: return { bgneal@45: schema : schema, bgneal@45: bgneal@45: addNodeFilter : htmlParser.addNodeFilter, bgneal@45: bgneal@45: addAttributeFilter : htmlParser.addAttributeFilter, bgneal@45: bgneal@45: onPreProcess : onPreProcess, bgneal@45: bgneal@45: onPostProcess : onPostProcess, bgneal@45: bgneal@45: serialize : function(node, args) { bgneal@45: var impl, doc, oldDoc, htmlSerializer, content; bgneal@45: bgneal@45: // Explorer won't clone contents of script and style and the bgneal@45: // selected index of select elements are cleared on a clone operation. bgneal@45: if (isIE && dom.select('script,style,select,map').length > 0) { bgneal@45: content = node.innerHTML; bgneal@45: node = node.cloneNode(false); bgneal@45: dom.setHTML(node, content); bgneal@45: } else bgneal@45: node = node.cloneNode(true); bgneal@45: bgneal@45: // Nodes needs to be attached to something in WebKit/Opera bgneal@45: // Older builds of Opera crashes if you attach the node to an document created dynamically bgneal@45: // and since we can't feature detect a crash we need to sniff the acutal build number bgneal@45: // This fix will make DOM ranges and make Sizzle happy! bgneal@45: impl = node.ownerDocument.implementation; bgneal@45: if (impl.createHTMLDocument) { bgneal@45: // Create an empty HTML document bgneal@45: doc = impl.createHTMLDocument(""); bgneal@45: bgneal@45: // Add the element or it's children if it's a body element to the new document bgneal@45: each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) { bgneal@45: doc.body.appendChild(doc.importNode(node, true)); bgneal@45: }); bgneal@45: bgneal@45: // Grab first child or body element for serialization bgneal@45: if (node.nodeName != 'BODY') bgneal@45: node = doc.body.firstChild; bgneal@45: else bgneal@45: node = doc.body; bgneal@45: bgneal@45: // set the new document in DOMUtils so createElement etc works bgneal@45: oldDoc = dom.doc; bgneal@45: dom.doc = doc; bgneal@45: } bgneal@45: bgneal@45: args = args || {}; bgneal@45: args.format = args.format || 'html'; bgneal@45: bgneal@45: // Pre process bgneal@45: if (!args.no_events) { bgneal@45: args.node = node; bgneal@45: onPreProcess.dispatch(self, args); bgneal@45: } bgneal@45: bgneal@45: // Setup serializer bgneal@45: htmlSerializer = new tinymce.html.Serializer(settings, schema); bgneal@45: bgneal@45: // Parse and serialize HTML bgneal@45: args.content = htmlSerializer.serialize( bgneal@45: htmlParser.parse(args.getInner ? node.innerHTML : tinymce.trim(dom.getOuterHTML(node), args), args) bgneal@45: ); bgneal@45: bgneal@45: // Replace all BOM characters for now until we can find a better solution bgneal@45: if (!args.cleanup) bgneal@45: args.content = args.content.replace(/\uFEFF|\u200B/g, ''); bgneal@45: bgneal@45: // Post process bgneal@45: if (!args.no_events) bgneal@45: onPostProcess.dispatch(self, args); bgneal@45: bgneal@45: // Restore the old document if it was changed bgneal@45: if (oldDoc) bgneal@45: dom.doc = oldDoc; bgneal@45: bgneal@45: args.node = null; bgneal@45: bgneal@45: return args.content; bgneal@45: }, bgneal@45: bgneal@45: addRules : function(rules) { bgneal@45: schema.addValidElements(rules); bgneal@45: }, bgneal@45: bgneal@45: setRules : function(rules) { bgneal@45: schema.setValidElements(rules); bgneal@45: } bgneal@45: }; bgneal@45: }; bgneal@45: })(tinymce); bgneal@45: (function(tinymce) { bgneal@45: tinymce.dom.ScriptLoader = function(settings) { bgneal@45: var QUEUED = 0, bgneal@45: LOADING = 1, bgneal@45: LOADED = 2, bgneal@45: states = {}, bgneal@45: queue = [], bgneal@45: scriptLoadedCallbacks = {}, bgneal@45: queueLoadedCallbacks = [], bgneal@45: loading = 0, bgneal@45: undefined; bgneal@45: bgneal@45: function loadScript(url, callback) { bgneal@45: var t = this, dom = tinymce.DOM, elm, uri, loc, id; bgneal@45: bgneal@45: // Execute callback when script is loaded bgneal@45: function done() { bgneal@45: dom.remove(id); bgneal@45: bgneal@45: if (elm) bgneal@45: elm.onreadystatechange = elm.onload = elm = null; bgneal@45: bgneal@45: callback(); bgneal@45: }; bgneal@45: bgneal@45: function error() { bgneal@45: // Report the error so it's easier for people to spot loading errors bgneal@45: if (typeof(console) !== "undefined" && console.log) bgneal@45: console.log("Failed to load: " + url); bgneal@45: bgneal@45: // We can't mark it as done if there is a load error since bgneal@45: // A) We don't want to produce 404 errors on the server and bgneal@45: // B) the onerror event won't fire on all browsers. bgneal@45: // done(); bgneal@45: }; bgneal@45: bgneal@45: id = dom.uniqueId(); bgneal@45: bgneal@45: if (tinymce.isIE6) { bgneal@45: uri = new tinymce.util.URI(url); bgneal@45: loc = location; bgneal@45: bgneal@45: // If script is from same domain and we bgneal@45: // use IE 6 then use XHR since it's more reliable bgneal@45: if (uri.host == loc.hostname && uri.port == loc.port && (uri.protocol + ':') == loc.protocol && uri.protocol.toLowerCase() != 'file') { bgneal@45: tinymce.util.XHR.send({ bgneal@45: url : tinymce._addVer(uri.getURI()), bgneal@45: success : function(content) { bgneal@45: // Create new temp script element bgneal@45: var script = dom.create('script', { bgneal@45: type : 'text/javascript' bgneal@45: }); bgneal@45: bgneal@45: // Evaluate script in global scope bgneal@45: script.text = content; bgneal@45: document.getElementsByTagName('head')[0].appendChild(script); bgneal@45: dom.remove(script); bgneal@45: bgneal@45: done(); bgneal@45: }, bgneal@45: bgneal@45: error : error bgneal@45: }); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Create new script element bgneal@45: elm = dom.create('script', { bgneal@45: id : id, bgneal@45: type : 'text/javascript', bgneal@45: src : tinymce._addVer(url) bgneal@45: }); bgneal@45: bgneal@45: // Add onload listener for non IE browsers since IE9 bgneal@45: // fires onload event before the script is parsed and executed bgneal@45: if (!tinymce.isIE) bgneal@45: elm.onload = done; bgneal@45: bgneal@45: // Add onerror event will get fired on some browsers but not all of them bgneal@45: elm.onerror = error; bgneal@45: bgneal@45: // Opera 9.60 doesn't seem to fire the onreadystate event at correctly bgneal@45: if (!tinymce.isOpera) { bgneal@45: elm.onreadystatechange = function() { bgneal@45: var state = elm.readyState; bgneal@45: bgneal@45: // Loaded state is passed on IE 6 however there bgneal@45: // are known issues with this method but we can't use bgneal@45: // XHR in a cross domain loading bgneal@45: if (state == 'complete' || state == 'loaded') bgneal@45: done(); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: // Most browsers support this feature so we report errors bgneal@45: // for those at least to help users track their missing plugins etc bgneal@45: // todo: Removed since it produced error if the document is unloaded by navigating away, re-add it as an option bgneal@45: /*elm.onerror = function() { bgneal@45: alert('Failed to load: ' + url); bgneal@45: };*/ bgneal@45: bgneal@45: // Add script to document bgneal@45: (document.getElementsByTagName('head')[0] || document.body).appendChild(elm); bgneal@45: }; bgneal@45: bgneal@45: this.isDone = function(url) { bgneal@45: return states[url] == LOADED; bgneal@45: }; bgneal@45: bgneal@45: this.markDone = function(url) { bgneal@45: states[url] = LOADED; bgneal@45: }; bgneal@45: bgneal@45: this.add = this.load = function(url, callback, scope) { bgneal@45: var item, state = states[url]; bgneal@45: bgneal@45: // Add url to load queue bgneal@45: if (state == undefined) { bgneal@45: queue.push(url); bgneal@45: states[url] = QUEUED; bgneal@45: } bgneal@45: bgneal@45: if (callback) { bgneal@45: // Store away callback for later execution bgneal@45: if (!scriptLoadedCallbacks[url]) bgneal@45: scriptLoadedCallbacks[url] = []; bgneal@45: bgneal@45: scriptLoadedCallbacks[url].push({ bgneal@45: func : callback, bgneal@45: scope : scope || this bgneal@45: }); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: this.loadQueue = function(callback, scope) { bgneal@45: this.loadScripts(queue, callback, scope); bgneal@45: }; bgneal@45: bgneal@45: this.loadScripts = function(scripts, callback, scope) { bgneal@45: var loadScripts; bgneal@45: bgneal@45: function execScriptLoadedCallbacks(url) { bgneal@45: // Execute URL callback functions bgneal@45: tinymce.each(scriptLoadedCallbacks[url], function(callback) { bgneal@45: callback.func.call(callback.scope); bgneal@45: }); bgneal@45: bgneal@45: scriptLoadedCallbacks[url] = undefined; bgneal@45: }; bgneal@45: bgneal@45: queueLoadedCallbacks.push({ bgneal@45: func : callback, bgneal@45: scope : scope || this bgneal@45: }); bgneal@45: bgneal@45: loadScripts = function() { bgneal@45: var loadingScripts = tinymce.grep(scripts); bgneal@45: bgneal@45: // Current scripts has been handled bgneal@45: scripts.length = 0; bgneal@45: bgneal@45: // Load scripts that needs to be loaded bgneal@45: tinymce.each(loadingScripts, function(url) { bgneal@45: // Script is already loaded then execute script callbacks directly bgneal@45: if (states[url] == LOADED) { bgneal@45: execScriptLoadedCallbacks(url); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Is script not loading then start loading it bgneal@45: if (states[url] != LOADING) { bgneal@45: states[url] = LOADING; bgneal@45: loading++; bgneal@45: bgneal@45: loadScript(url, function() { bgneal@45: states[url] = LOADED; bgneal@45: loading--; bgneal@45: bgneal@45: execScriptLoadedCallbacks(url); bgneal@45: bgneal@45: // Load more scripts if they where added by the recently loaded script bgneal@45: loadScripts(); bgneal@45: }); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // No scripts are currently loading then execute all pending queue loaded callbacks bgneal@45: if (!loading) { bgneal@45: tinymce.each(queueLoadedCallbacks, function(callback) { bgneal@45: callback.func.call(callback.scope); bgneal@45: }); bgneal@45: bgneal@45: queueLoadedCallbacks.length = 0; bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: loadScripts(); bgneal@45: }; bgneal@45: }; bgneal@45: bgneal@45: // Global script loader bgneal@45: tinymce.ScriptLoader = new tinymce.dom.ScriptLoader(); bgneal@45: })(tinymce); bgneal@45: bgneal@45: tinymce.dom.TreeWalker = function(start_node, root_node) { bgneal@45: var node = start_node; bgneal@45: bgneal@45: function findSibling(node, start_name, sibling_name, shallow) { bgneal@45: var sibling, parent; bgneal@45: bgneal@45: if (node) { bgneal@45: // Walk into nodes if it has a start bgneal@45: if (!shallow && node[start_name]) bgneal@45: return node[start_name]; bgneal@45: bgneal@45: // Return the sibling if it has one bgneal@45: if (node != root_node) { bgneal@45: sibling = node[sibling_name]; bgneal@45: if (sibling) bgneal@45: return sibling; bgneal@45: bgneal@45: // Walk up the parents to look for siblings bgneal@45: for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) { bgneal@45: sibling = parent[sibling_name]; bgneal@45: if (sibling) bgneal@45: return sibling; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: this.current = function() { bgneal@45: return node; bgneal@45: }; bgneal@45: bgneal@45: this.next = function(shallow) { bgneal@45: return (node = findSibling(node, 'firstChild', 'nextSibling', shallow)); bgneal@45: }; bgneal@45: bgneal@45: this.prev = function(shallow) { bgneal@45: return (node = findSibling(node, 'lastChild', 'previousSibling', shallow)); bgneal@45: }; bgneal@45: }; bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: tinymce.dom.RangeUtils = function(dom) { bgneal@45: var INVISIBLE_CHAR = '\uFEFF'; bgneal@45: bgneal@45: this.walk = function(rng, callback) { bgneal@45: var startContainer = rng.startContainer, bgneal@45: startOffset = rng.startOffset, bgneal@45: endContainer = rng.endContainer, bgneal@45: endOffset = rng.endOffset, bgneal@45: ancestor, startPoint, bgneal@45: endPoint, node, parent, siblings, nodes; bgneal@45: bgneal@45: // Handle table cell selection the table plugin enables bgneal@45: // you to fake select table cells and perform formatting actions on them bgneal@45: nodes = dom.select('td.mceSelected,th.mceSelected'); bgneal@45: if (nodes.length > 0) { bgneal@45: tinymce.each(nodes, function(node) { bgneal@45: callback([node]); bgneal@45: }); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: function exclude(nodes) { bgneal@45: var node; bgneal@45: bgneal@45: // First node is excluded bgneal@45: node = nodes[0]; bgneal@45: if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) { bgneal@45: nodes.splice(0, 1); bgneal@45: } bgneal@45: bgneal@45: // Last node is excluded bgneal@45: node = nodes[nodes.length - 1]; bgneal@45: if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) { bgneal@45: nodes.splice(nodes.length - 1, 1); bgneal@45: } bgneal@45: bgneal@45: return nodes; bgneal@45: }; bgneal@45: bgneal@45: function collectSiblings(node, name, end_node) { bgneal@45: var siblings = []; bgneal@45: bgneal@45: for (; node && node != end_node; node = node[name]) bgneal@45: siblings.push(node); bgneal@45: bgneal@45: return siblings; bgneal@45: }; bgneal@45: bgneal@45: function findEndPoint(node, root) { bgneal@45: do { bgneal@45: if (node.parentNode == root) bgneal@45: return node; bgneal@45: bgneal@45: node = node.parentNode; bgneal@45: } while(node); bgneal@45: }; bgneal@45: bgneal@45: function walkBoundary(start_node, end_node, next) { bgneal@45: var siblingName = next ? 'nextSibling' : 'previousSibling'; bgneal@45: bgneal@45: for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) { bgneal@45: parent = node.parentNode; bgneal@45: siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName); bgneal@45: bgneal@45: if (siblings.length) { bgneal@45: if (!next) bgneal@45: siblings.reverse(); bgneal@45: bgneal@45: callback(exclude(siblings)); bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // If index based start position then resolve it bgneal@45: if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) bgneal@45: startContainer = startContainer.childNodes[startOffset]; bgneal@45: bgneal@45: // If index based end position then resolve it bgneal@45: if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) bgneal@45: endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)]; bgneal@45: bgneal@45: // Same container bgneal@45: if (startContainer == endContainer) bgneal@45: return callback(exclude([startContainer])); bgneal@45: bgneal@45: // Find common ancestor and end points bgneal@45: ancestor = dom.findCommonAncestor(startContainer, endContainer); bgneal@45: bgneal@45: // Process left side bgneal@45: for (node = startContainer; node; node = node.parentNode) { bgneal@45: if (node === endContainer) bgneal@45: return walkBoundary(startContainer, ancestor, true); bgneal@45: bgneal@45: if (node === ancestor) bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: // Process right side bgneal@45: for (node = endContainer; node; node = node.parentNode) { bgneal@45: if (node === startContainer) bgneal@45: return walkBoundary(endContainer, ancestor); bgneal@45: bgneal@45: if (node === ancestor) bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: // Find start/end point bgneal@45: startPoint = findEndPoint(startContainer, ancestor) || startContainer; bgneal@45: endPoint = findEndPoint(endContainer, ancestor) || endContainer; bgneal@45: bgneal@45: // Walk left leaf bgneal@45: walkBoundary(startContainer, startPoint, true); bgneal@45: bgneal@45: // Walk the middle from start to end point bgneal@45: siblings = collectSiblings( bgneal@45: startPoint == startContainer ? startPoint : startPoint.nextSibling, bgneal@45: 'nextSibling', bgneal@45: endPoint == endContainer ? endPoint.nextSibling : endPoint bgneal@45: ); bgneal@45: bgneal@45: if (siblings.length) bgneal@45: callback(exclude(siblings)); bgneal@45: bgneal@45: // Walk right leaf bgneal@45: walkBoundary(endContainer, endPoint); bgneal@45: }; bgneal@45: bgneal@45: this.split = function(rng) { bgneal@45: var startContainer = rng.startContainer, bgneal@45: startOffset = rng.startOffset, bgneal@45: endContainer = rng.endContainer, bgneal@45: endOffset = rng.endOffset; bgneal@45: bgneal@45: function splitText(node, offset) { bgneal@45: return node.splitText(offset); bgneal@45: }; bgneal@45: bgneal@45: // Handle single text node bgneal@45: if (startContainer == endContainer && startContainer.nodeType == 3) { bgneal@45: if (startOffset > 0 && startOffset < startContainer.nodeValue.length) { bgneal@45: endContainer = splitText(startContainer, startOffset); bgneal@45: startContainer = endContainer.previousSibling; bgneal@45: bgneal@45: if (endOffset > startOffset) { bgneal@45: endOffset = endOffset - startOffset; bgneal@45: startContainer = endContainer = splitText(endContainer, endOffset).previousSibling; bgneal@45: endOffset = endContainer.nodeValue.length; bgneal@45: startOffset = 0; bgneal@45: } else { bgneal@45: endOffset = 0; bgneal@45: } bgneal@45: } bgneal@45: } else { bgneal@45: // Split startContainer text node if needed bgneal@45: if (startContainer.nodeType == 3 && startOffset > 0 && startOffset < startContainer.nodeValue.length) { bgneal@45: startContainer = splitText(startContainer, startOffset); bgneal@45: startOffset = 0; bgneal@45: } bgneal@45: bgneal@45: // Split endContainer text node if needed bgneal@45: if (endContainer.nodeType == 3 && endOffset > 0 && endOffset < endContainer.nodeValue.length) { bgneal@45: endContainer = splitText(endContainer, endOffset).previousSibling; bgneal@45: endOffset = endContainer.nodeValue.length; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return { bgneal@45: startContainer : startContainer, bgneal@45: startOffset : startOffset, bgneal@45: endContainer : endContainer, bgneal@45: endOffset : endOffset bgneal@45: }; bgneal@45: }; bgneal@45: bgneal@45: }; bgneal@45: bgneal@45: tinymce.dom.RangeUtils.compareRanges = function(rng1, rng2) { bgneal@45: if (rng1 && rng2) { bgneal@45: // Compare native IE ranges bgneal@45: if (rng1.item || rng1.duplicate) { bgneal@45: // Both are control ranges and the selected element matches bgneal@45: if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0)) bgneal@45: return true; bgneal@45: bgneal@45: // Both are text ranges and the range matches bgneal@45: if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1)) bgneal@45: return true; bgneal@45: } else { bgneal@45: // Compare w3c ranges bgneal@45: return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return false; bgneal@45: }; bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: var Event = tinymce.dom.Event, each = tinymce.each; bgneal@45: bgneal@45: tinymce.create('tinymce.ui.KeyboardNavigation', { bgneal@45: KeyboardNavigation: function(settings, dom) { bgneal@45: var t = this, root = settings.root, items = settings.items, bgneal@45: enableUpDown = settings.enableUpDown, enableLeftRight = settings.enableLeftRight || !settings.enableUpDown, bgneal@45: excludeFromTabOrder = settings.excludeFromTabOrder, bgneal@45: itemFocussed, itemBlurred, rootKeydown, rootFocussed, focussedId; bgneal@45: bgneal@45: dom = dom || tinymce.DOM; bgneal@45: bgneal@45: itemFocussed = function(evt) { bgneal@45: focussedId = evt.target.id; bgneal@45: }; bgneal@45: bgneal@45: itemBlurred = function(evt) { bgneal@45: dom.setAttrib(evt.target.id, 'tabindex', '-1'); bgneal@45: }; bgneal@45: bgneal@45: rootFocussed = function(evt) { bgneal@45: var item = dom.get(focussedId); bgneal@45: dom.setAttrib(item, 'tabindex', '0'); bgneal@45: item.focus(); bgneal@45: }; bgneal@45: bgneal@45: t.focus = function() { bgneal@45: dom.get(focussedId).focus(); bgneal@45: }; bgneal@45: bgneal@45: t.destroy = function() { bgneal@45: each(items, function(item) { bgneal@45: dom.unbind(dom.get(item.id), 'focus', itemFocussed); bgneal@45: dom.unbind(dom.get(item.id), 'blur', itemBlurred); bgneal@45: }); bgneal@45: bgneal@45: dom.unbind(dom.get(root), 'focus', rootFocussed); bgneal@45: dom.unbind(dom.get(root), 'keydown', rootKeydown); bgneal@45: bgneal@45: items = dom = root = t.focus = itemFocussed = itemBlurred = rootKeydown = rootFocussed = null; bgneal@45: t.destroy = function() {}; bgneal@45: }; bgneal@45: bgneal@45: t.moveFocus = function(dir, evt) { bgneal@45: var idx = -1, controls = t.controls, newFocus; bgneal@45: bgneal@45: if (!focussedId) bgneal@45: return; bgneal@45: bgneal@45: each(items, function(item, index) { bgneal@45: if (item.id === focussedId) { bgneal@45: idx = index; bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: idx += dir; bgneal@45: if (idx < 0) { bgneal@45: idx = items.length - 1; bgneal@45: } else if (idx >= items.length) { bgneal@45: idx = 0; bgneal@45: } bgneal@45: bgneal@45: newFocus = items[idx]; bgneal@45: dom.setAttrib(focussedId, 'tabindex', '-1'); bgneal@45: dom.setAttrib(newFocus.id, 'tabindex', '0'); bgneal@45: dom.get(newFocus.id).focus(); bgneal@45: bgneal@45: if (settings.actOnFocus) { bgneal@45: settings.onAction(newFocus.id); bgneal@45: } bgneal@45: bgneal@45: if (evt) bgneal@45: Event.cancel(evt); bgneal@45: }; bgneal@45: bgneal@45: rootKeydown = function(evt) { bgneal@45: 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@45: bgneal@45: switch (evt.keyCode) { bgneal@45: case DOM_VK_LEFT: bgneal@45: if (enableLeftRight) t.moveFocus(-1); bgneal@45: break; bgneal@45: bgneal@45: case DOM_VK_RIGHT: bgneal@45: if (enableLeftRight) t.moveFocus(1); bgneal@45: break; bgneal@45: bgneal@45: case DOM_VK_UP: bgneal@45: if (enableUpDown) t.moveFocus(-1); bgneal@45: break; bgneal@45: bgneal@45: case DOM_VK_DOWN: bgneal@45: if (enableUpDown) t.moveFocus(1); bgneal@45: break; bgneal@45: bgneal@45: case DOM_VK_ESCAPE: bgneal@45: if (settings.onCancel) { bgneal@45: settings.onCancel(); bgneal@45: Event.cancel(evt); bgneal@45: } bgneal@45: break; bgneal@45: bgneal@45: case DOM_VK_ENTER: bgneal@45: case DOM_VK_RETURN: bgneal@45: case DOM_VK_SPACE: bgneal@45: if (settings.onAction) { bgneal@45: settings.onAction(focussedId); bgneal@45: Event.cancel(evt); bgneal@45: } bgneal@45: break; bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Set up state and listeners for each item. bgneal@45: each(items, function(item, idx) { bgneal@45: var tabindex; bgneal@45: bgneal@45: if (!item.id) { bgneal@45: item.id = dom.uniqueId('_mce_item_'); bgneal@45: } bgneal@45: bgneal@45: if (excludeFromTabOrder) { bgneal@45: dom.bind(item.id, 'blur', itemBlurred); bgneal@45: tabindex = '-1'; bgneal@45: } else { bgneal@45: tabindex = (idx === 0 ? '0' : '-1'); bgneal@45: } bgneal@45: bgneal@45: dom.setAttrib(item.id, 'tabindex', tabindex); bgneal@45: dom.bind(dom.get(item.id), 'focus', itemFocussed); bgneal@45: }); bgneal@45: bgneal@45: // Setup initial state for root element. bgneal@45: if (items[0]){ bgneal@45: focussedId = items[0].id; bgneal@45: } bgneal@45: bgneal@45: dom.setAttrib(root, 'tabindex', '-1'); bgneal@45: bgneal@45: // Setup listeners for root element. bgneal@45: dom.bind(dom.get(root), 'focus', rootFocussed); bgneal@45: dom.bind(dom.get(root), 'keydown', rootKeydown); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: // Shorten class names bgneal@45: var DOM = tinymce.DOM, is = tinymce.is; bgneal@45: bgneal@45: tinymce.create('tinymce.ui.Control', { bgneal@45: Control : function(id, s, editor) { bgneal@45: this.id = id; bgneal@45: this.settings = s = s || {}; bgneal@45: this.rendered = false; bgneal@45: this.onRender = new tinymce.util.Dispatcher(this); bgneal@45: this.classPrefix = ''; bgneal@45: this.scope = s.scope || this; bgneal@45: this.disabled = 0; bgneal@45: this.active = 0; bgneal@45: this.editor = editor; bgneal@45: }, bgneal@45: bgneal@45: setAriaProperty : function(property, value) { bgneal@45: var element = DOM.get(this.id + '_aria') || DOM.get(this.id); bgneal@45: if (element) { bgneal@45: DOM.setAttrib(element, 'aria-' + property, !!value); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: focus : function() { bgneal@45: DOM.get(this.id).focus(); bgneal@45: }, bgneal@45: bgneal@45: setDisabled : function(s) { bgneal@45: if (s != this.disabled) { bgneal@45: this.setAriaProperty('disabled', s); bgneal@45: bgneal@45: this.setState('Disabled', s); bgneal@45: this.setState('Enabled', !s); bgneal@45: this.disabled = s; bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: isDisabled : function() { bgneal@45: return this.disabled; bgneal@45: }, bgneal@45: bgneal@45: setActive : function(s) { bgneal@45: if (s != this.active) { bgneal@45: this.setState('Active', s); bgneal@45: this.active = s; bgneal@45: this.setAriaProperty('pressed', s); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: isActive : function() { bgneal@45: return this.active; bgneal@45: }, bgneal@45: bgneal@45: setState : function(c, s) { bgneal@45: var n = DOM.get(this.id); bgneal@45: bgneal@45: c = this.classPrefix + c; bgneal@45: bgneal@45: if (s) bgneal@45: DOM.addClass(n, c); bgneal@45: else bgneal@45: DOM.removeClass(n, c); bgneal@45: }, bgneal@45: bgneal@45: isRendered : function() { bgneal@45: return this.rendered; bgneal@45: }, bgneal@45: bgneal@45: renderHTML : function() { bgneal@45: }, bgneal@45: bgneal@45: renderTo : function(n) { bgneal@45: DOM.setHTML(n, this.renderHTML()); bgneal@45: }, bgneal@45: bgneal@45: postRender : function() { bgneal@45: var t = this, b; bgneal@45: bgneal@45: // Set pending states bgneal@45: if (is(t.disabled)) { bgneal@45: b = t.disabled; bgneal@45: t.disabled = -1; bgneal@45: t.setDisabled(b); bgneal@45: } bgneal@45: bgneal@45: if (is(t.active)) { bgneal@45: b = t.active; bgneal@45: t.active = -1; bgneal@45: t.setActive(b); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: remove : function() { bgneal@45: DOM.remove(this.id); bgneal@45: this.destroy(); bgneal@45: }, bgneal@45: bgneal@45: destroy : function() { bgneal@45: tinymce.dom.Event.clear(this.id); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: tinymce.create('tinymce.ui.Container:tinymce.ui.Control', { bgneal@45: Container : function(id, s, editor) { bgneal@45: this.parent(id, s, editor); bgneal@45: bgneal@45: this.controls = []; bgneal@45: bgneal@45: this.lookup = {}; bgneal@45: }, bgneal@45: bgneal@45: add : function(c) { bgneal@45: this.lookup[c.id] = c; bgneal@45: this.controls.push(c); bgneal@45: bgneal@45: return c; bgneal@45: }, bgneal@45: bgneal@45: get : function(n) { bgneal@45: return this.lookup[n]; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: bgneal@45: tinymce.create('tinymce.ui.Separator:tinymce.ui.Control', { bgneal@45: Separator : function(id, s) { bgneal@45: this.parent(id, s); bgneal@45: this.classPrefix = 'mceSeparator'; bgneal@45: this.setDisabled(true); bgneal@45: }, bgneal@45: bgneal@45: renderHTML : function() { bgneal@45: return tinymce.DOM.createHTML('span', {'class' : this.classPrefix, role : 'separator', 'aria-orientation' : 'vertical', tabindex : '-1'}); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk; bgneal@45: bgneal@45: tinymce.create('tinymce.ui.MenuItem:tinymce.ui.Control', { bgneal@45: MenuItem : function(id, s) { bgneal@45: this.parent(id, s); bgneal@45: this.classPrefix = 'mceMenuItem'; bgneal@45: }, bgneal@45: bgneal@45: setSelected : function(s) { bgneal@45: this.setState('Selected', s); bgneal@45: this.setAriaProperty('checked', !!s); bgneal@45: this.selected = s; bgneal@45: }, bgneal@45: bgneal@45: isSelected : function() { bgneal@45: return this.selected; bgneal@45: }, bgneal@45: bgneal@45: postRender : function() { bgneal@45: var t = this; bgneal@45: bgneal@45: t.parent(); bgneal@45: bgneal@45: // Set pending state bgneal@45: if (is(t.selected)) bgneal@45: t.setSelected(t.selected); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, walk = tinymce.walk; bgneal@45: bgneal@45: tinymce.create('tinymce.ui.Menu:tinymce.ui.MenuItem', { bgneal@45: Menu : function(id, s) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.parent(id, s); bgneal@45: t.items = {}; bgneal@45: t.collapsed = false; bgneal@45: t.menuCount = 0; bgneal@45: t.onAddItem = new tinymce.util.Dispatcher(this); bgneal@45: }, bgneal@45: bgneal@45: expand : function(d) { bgneal@45: var t = this; bgneal@45: bgneal@45: if (d) { bgneal@45: walk(t, function(o) { bgneal@45: if (o.expand) bgneal@45: o.expand(); bgneal@45: }, 'items', t); bgneal@45: } bgneal@45: bgneal@45: t.collapsed = false; bgneal@45: }, bgneal@45: bgneal@45: collapse : function(d) { bgneal@45: var t = this; bgneal@45: bgneal@45: if (d) { bgneal@45: walk(t, function(o) { bgneal@45: if (o.collapse) bgneal@45: o.collapse(); bgneal@45: }, 'items', t); bgneal@45: } bgneal@45: bgneal@45: t.collapsed = true; bgneal@45: }, bgneal@45: bgneal@45: isCollapsed : function() { bgneal@45: return this.collapsed; bgneal@45: }, bgneal@45: bgneal@45: add : function(o) { bgneal@45: if (!o.settings) bgneal@45: o = new tinymce.ui.MenuItem(o.id || DOM.uniqueId(), o); bgneal@45: bgneal@45: this.onAddItem.dispatch(this, o); bgneal@45: bgneal@45: return this.items[o.id] = o; bgneal@45: }, bgneal@45: bgneal@45: addSeparator : function() { bgneal@45: return this.add({separator : true}); bgneal@45: }, bgneal@45: bgneal@45: addMenu : function(o) { bgneal@45: if (!o.collapse) bgneal@45: o = this.createMenu(o); bgneal@45: bgneal@45: this.menuCount++; bgneal@45: bgneal@45: return this.add(o); bgneal@45: }, bgneal@45: bgneal@45: hasMenus : function() { bgneal@45: return this.menuCount !== 0; bgneal@45: }, bgneal@45: bgneal@45: remove : function(o) { bgneal@45: delete this.items[o.id]; bgneal@45: }, bgneal@45: bgneal@45: removeAll : function() { bgneal@45: var t = this; bgneal@45: bgneal@45: walk(t, function(o) { bgneal@45: if (o.removeAll) bgneal@45: o.removeAll(); bgneal@45: else bgneal@45: o.remove(); bgneal@45: bgneal@45: o.destroy(); bgneal@45: }, 'items', t); bgneal@45: bgneal@45: t.items = {}; bgneal@45: }, bgneal@45: bgneal@45: createMenu : function(o) { bgneal@45: var m = new tinymce.ui.Menu(o.id || DOM.uniqueId(), o); bgneal@45: bgneal@45: m.onAddItem.add(this.onAddItem.dispatch, this.onAddItem); bgneal@45: bgneal@45: return m; bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: (function(tinymce) { bgneal@45: var is = tinymce.is, DOM = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event, Element = tinymce.dom.Element; bgneal@45: bgneal@45: tinymce.create('tinymce.ui.DropMenu:tinymce.ui.Menu', { bgneal@45: DropMenu : function(id, s) { bgneal@45: s = s || {}; bgneal@45: s.container = s.container || DOM.doc.body; bgneal@45: s.offset_x = s.offset_x || 0; bgneal@45: s.offset_y = s.offset_y || 0; bgneal@45: s.vp_offset_x = s.vp_offset_x || 0; bgneal@45: s.vp_offset_y = s.vp_offset_y || 0; bgneal@45: bgneal@45: if (is(s.icons) && !s.icons) bgneal@45: s['class'] += ' mceNoIcons'; bgneal@45: bgneal@45: this.parent(id, s); bgneal@45: this.onShowMenu = new tinymce.util.Dispatcher(this); bgneal@45: this.onHideMenu = new tinymce.util.Dispatcher(this); bgneal@45: this.classPrefix = 'mceMenu'; bgneal@45: }, bgneal@45: bgneal@45: createMenu : function(s) { bgneal@45: var t = this, cs = t.settings, m; bgneal@45: bgneal@45: s.container = s.container || cs.container; bgneal@45: s.parent = t; bgneal@45: s.constrain = s.constrain || cs.constrain; bgneal@45: s['class'] = s['class'] || cs['class']; bgneal@45: s.vp_offset_x = s.vp_offset_x || cs.vp_offset_x; bgneal@45: s.vp_offset_y = s.vp_offset_y || cs.vp_offset_y; bgneal@45: s.keyboard_focus = cs.keyboard_focus; bgneal@45: m = new tinymce.ui.DropMenu(s.id || DOM.uniqueId(), s); bgneal@45: bgneal@45: m.onAddItem.add(t.onAddItem.dispatch, t.onAddItem); bgneal@45: bgneal@45: return m; bgneal@45: }, bgneal@45: bgneal@45: focus : function() { bgneal@45: var t = this; bgneal@45: if (t.keyboardNav) { bgneal@45: t.keyboardNav.focus(); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: update : function() { bgneal@45: var t = this, s = t.settings, tb = DOM.get('menu_' + t.id + '_tbl'), co = DOM.get('menu_' + t.id + '_co'), tw, th; bgneal@45: bgneal@45: tw = s.max_width ? Math.min(tb.clientWidth, s.max_width) : tb.clientWidth; bgneal@45: th = s.max_height ? Math.min(tb.clientHeight, s.max_height) : tb.clientHeight; bgneal@45: bgneal@45: if (!DOM.boxModel) bgneal@45: t.element.setStyles({width : tw + 2, height : th + 2}); bgneal@45: else bgneal@45: t.element.setStyles({width : tw, height : th}); bgneal@45: bgneal@45: if (s.max_width) bgneal@45: DOM.setStyle(co, 'width', tw); bgneal@45: bgneal@45: if (s.max_height) { bgneal@45: DOM.setStyle(co, 'height', th); bgneal@45: bgneal@45: if (tb.clientHeight < s.max_height) bgneal@45: DOM.setStyle(co, 'overflow', 'hidden'); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: showMenu : function(x, y, px) { bgneal@45: var t = this, s = t.settings, co, vp = DOM.getViewPort(), w, h, mx, my, ot = 2, dm, tb, cp = t.classPrefix; bgneal@45: bgneal@45: t.collapse(1); bgneal@45: bgneal@45: if (t.isMenuVisible) bgneal@45: return; bgneal@45: bgneal@45: if (!t.rendered) { bgneal@45: co = DOM.add(t.settings.container, t.renderNode()); bgneal@45: bgneal@45: each(t.items, function(o) { bgneal@45: o.postRender(); bgneal@45: }); bgneal@45: bgneal@45: t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container}); bgneal@45: } else bgneal@45: co = DOM.get('menu_' + t.id); bgneal@45: bgneal@45: // Move layer out of sight unless it's Opera since it scrolls to top of page due to an bug bgneal@45: if (!tinymce.isOpera) bgneal@45: DOM.setStyles(co, {left : -0xFFFF , top : -0xFFFF}); bgneal@45: bgneal@45: DOM.show(co); bgneal@45: t.update(); bgneal@45: bgneal@45: x += s.offset_x || 0; bgneal@45: y += s.offset_y || 0; bgneal@45: vp.w -= 4; bgneal@45: vp.h -= 4; bgneal@45: bgneal@45: // Move inside viewport if not submenu bgneal@45: if (s.constrain) { bgneal@45: w = co.clientWidth - ot; bgneal@45: h = co.clientHeight - ot; bgneal@45: mx = vp.x + vp.w; bgneal@45: my = vp.y + vp.h; bgneal@45: bgneal@45: if ((x + s.vp_offset_x + w) > mx) bgneal@45: x = px ? px - w : Math.max(0, (mx - s.vp_offset_x) - w); bgneal@45: bgneal@45: if ((y + s.vp_offset_y + h) > my) bgneal@45: y = Math.max(0, (my - s.vp_offset_y) - h); bgneal@45: } bgneal@45: bgneal@45: DOM.setStyles(co, {left : x , top : y}); bgneal@45: t.element.update(); bgneal@45: bgneal@45: t.isMenuVisible = 1; bgneal@45: t.mouseClickFunc = Event.add(co, 'click', function(e) { bgneal@45: var m; bgneal@45: bgneal@45: e = e.target; bgneal@45: bgneal@45: if (e && (e = DOM.getParent(e, 'tr')) && !DOM.hasClass(e, cp + 'ItemSub')) { bgneal@45: m = t.items[e.id]; bgneal@45: bgneal@45: if (m.isDisabled()) bgneal@45: return; bgneal@45: bgneal@45: dm = t; bgneal@45: bgneal@45: while (dm) { bgneal@45: if (dm.hideMenu) bgneal@45: dm.hideMenu(); bgneal@45: bgneal@45: dm = dm.settings.parent; bgneal@45: } bgneal@45: bgneal@45: if (m.settings.onclick) bgneal@45: m.settings.onclick(e); bgneal@45: bgneal@45: return false; // Cancel to fix onbeforeunload problem bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: if (t.hasMenus()) { bgneal@45: t.mouseOverFunc = Event.add(co, 'mouseover', function(e) { bgneal@45: var m, r, mi; bgneal@45: bgneal@45: e = e.target; bgneal@45: if (e && (e = DOM.getParent(e, 'tr'))) { bgneal@45: m = t.items[e.id]; bgneal@45: bgneal@45: if (t.lastMenu) bgneal@45: t.lastMenu.collapse(1); bgneal@45: bgneal@45: if (m.isDisabled()) bgneal@45: return; bgneal@45: bgneal@45: if (e && DOM.hasClass(e, cp + 'ItemSub')) { bgneal@45: //p = DOM.getPos(s.container); bgneal@45: r = DOM.getRect(e); bgneal@45: m.showMenu((r.x + r.w - ot), r.y - ot, r.x); bgneal@45: t.lastMenu = m; bgneal@45: DOM.addClass(DOM.get(m.id).firstChild, cp + 'ItemActive'); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: Event.add(co, 'keydown', t._keyHandler, t); bgneal@45: bgneal@45: t.onShowMenu.dispatch(t); bgneal@45: bgneal@45: if (s.keyboard_focus) { bgneal@45: t._setupKeyboardNav(); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: hideMenu : function(c) { bgneal@45: var t = this, co = DOM.get('menu_' + t.id), e; bgneal@45: bgneal@45: if (!t.isMenuVisible) bgneal@45: return; bgneal@45: bgneal@45: if (t.keyboardNav) t.keyboardNav.destroy(); bgneal@45: Event.remove(co, 'mouseover', t.mouseOverFunc); bgneal@45: Event.remove(co, 'click', t.mouseClickFunc); bgneal@45: Event.remove(co, 'keydown', t._keyHandler); bgneal@45: DOM.hide(co); bgneal@45: t.isMenuVisible = 0; bgneal@45: bgneal@45: if (!c) bgneal@45: t.collapse(1); bgneal@45: bgneal@45: if (t.element) bgneal@45: t.element.hide(); bgneal@45: bgneal@45: if (e = DOM.get(t.id)) bgneal@45: DOM.removeClass(e.firstChild, t.classPrefix + 'ItemActive'); bgneal@45: bgneal@45: t.onHideMenu.dispatch(t); bgneal@45: }, bgneal@45: bgneal@45: add : function(o) { bgneal@45: var t = this, co; bgneal@45: bgneal@45: o = t.parent(o); bgneal@45: bgneal@45: if (t.isRendered && (co = DOM.get('menu_' + t.id))) bgneal@45: t._add(DOM.select('tbody', co)[0], o); bgneal@45: bgneal@45: return o; bgneal@45: }, bgneal@45: bgneal@45: collapse : function(d) { bgneal@45: this.parent(d); bgneal@45: this.hideMenu(1); bgneal@45: }, bgneal@45: bgneal@45: remove : function(o) { bgneal@45: DOM.remove(o.id); bgneal@45: this.destroy(); bgneal@45: bgneal@45: return this.parent(o); bgneal@45: }, bgneal@45: bgneal@45: destroy : function() { bgneal@45: var t = this, co = DOM.get('menu_' + t.id); bgneal@45: bgneal@45: if (t.keyboardNav) t.keyboardNav.destroy(); bgneal@45: Event.remove(co, 'mouseover', t.mouseOverFunc); bgneal@45: Event.remove(DOM.select('a', co), 'focus', t.mouseOverFunc); bgneal@45: Event.remove(co, 'click', t.mouseClickFunc); bgneal@45: Event.remove(co, 'keydown', t._keyHandler); bgneal@45: bgneal@45: if (t.element) bgneal@45: t.element.remove(); bgneal@45: bgneal@45: DOM.remove(co); bgneal@45: }, bgneal@45: bgneal@45: renderNode : function() { bgneal@45: var t = this, s = t.settings, n, tb, co, w; bgneal@45: bgneal@45: 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@45: if (t.settings.parent) { bgneal@45: DOM.setAttrib(w, 'aria-parent', 'menu_' + t.settings.parent.id); bgneal@45: } bgneal@45: co = DOM.add(w, 'div', {role: 'presentation', id : 'menu_' + t.id + '_co', 'class' : t.classPrefix + (s['class'] ? ' ' + s['class'] : '')}); bgneal@45: t.element = new Element('menu_' + t.id, {blocker : 1, container : s.container}); bgneal@45: bgneal@45: if (s.menu_line) bgneal@45: DOM.add(co, 'span', {'class' : t.classPrefix + 'Line'}); bgneal@45: bgneal@45: // n = DOM.add(co, 'div', {id : 'menu_' + t.id + '_co', 'class' : 'mceMenuContainer'}); bgneal@45: n = DOM.add(co, 'table', {role: 'presentation', id : 'menu_' + t.id + '_tbl', border : 0, cellPadding : 0, cellSpacing : 0}); bgneal@45: tb = DOM.add(n, 'tbody'); bgneal@45: bgneal@45: each(t.items, function(o) { bgneal@45: t._add(tb, o); bgneal@45: }); bgneal@45: bgneal@45: t.rendered = true; bgneal@45: bgneal@45: return w; bgneal@45: }, bgneal@45: bgneal@45: // Internal functions bgneal@45: _setupKeyboardNav : function(){ bgneal@45: var contextMenu, menuItems, t=this; bgneal@45: contextMenu = DOM.get('menu_' + t.id); bgneal@45: menuItems = DOM.select('a[role=option]', 'menu_' + t.id); bgneal@45: menuItems.splice(0,0,contextMenu); bgneal@45: t.keyboardNav = new tinymce.ui.KeyboardNavigation({ bgneal@45: root: 'menu_' + t.id, bgneal@45: items: menuItems, bgneal@45: onCancel: function() { bgneal@45: t.hideMenu(); bgneal@45: }, bgneal@45: enableUpDown: true bgneal@45: }); bgneal@45: contextMenu.focus(); bgneal@45: }, bgneal@45: bgneal@45: _keyHandler : function(evt) { bgneal@45: var t = this, e; bgneal@45: switch (evt.keyCode) { bgneal@45: case 37: // Left bgneal@45: if (t.settings.parent) { bgneal@45: t.hideMenu(); bgneal@45: t.settings.parent.focus(); bgneal@45: Event.cancel(evt); bgneal@45: } bgneal@45: break; bgneal@45: case 39: // Right bgneal@45: if (t.mouseOverFunc) bgneal@45: t.mouseOverFunc(evt); bgneal@45: break; bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: _add : function(tb, o) { bgneal@45: var n, s = o.settings, a, ro, it, cp = this.classPrefix, ic; bgneal@45: bgneal@45: if (s.separator) { bgneal@45: ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'ItemSeparator'}); bgneal@45: DOM.add(ro, 'td', {'class' : cp + 'ItemSeparator'}); bgneal@45: bgneal@45: if (n = ro.previousSibling) bgneal@45: DOM.addClass(n, 'mceLast'); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: n = ro = DOM.add(tb, 'tr', {id : o.id, 'class' : cp + 'Item ' + cp + 'ItemEnabled'}); bgneal@45: n = it = DOM.add(n, s.titleItem ? 'th' : 'td'); bgneal@45: n = a = DOM.add(n, 'a', {id: o.id + '_aria', role: s.titleItem ? 'presentation' : 'option', href : 'javascript:;', onclick : "return false;", onmousedown : 'return false;'}); bgneal@45: bgneal@45: if (s.parent) { bgneal@45: DOM.setAttrib(a, 'aria-haspopup', 'true'); bgneal@45: DOM.setAttrib(a, 'aria-owns', 'menu_' + o.id); bgneal@45: } bgneal@45: bgneal@45: DOM.addClass(it, s['class']); bgneal@45: // n = DOM.add(n, 'span', {'class' : 'item'}); bgneal@45: bgneal@45: ic = DOM.add(n, 'span', {'class' : 'mceIcon' + (s.icon ? ' mce_' + s.icon : '')}); bgneal@45: bgneal@45: if (s.icon_src) bgneal@45: DOM.add(ic, 'img', {src : s.icon_src}); bgneal@45: bgneal@45: n = DOM.add(n, s.element || 'span', {'class' : 'mceText', title : o.settings.title}, o.settings.title); bgneal@45: bgneal@45: if (o.settings.style) { bgneal@45: if (typeof o.settings.style == "function") bgneal@45: o.settings.style = o.settings.style(); bgneal@45: bgneal@45: DOM.setAttrib(n, 'style', o.settings.style); bgneal@45: } bgneal@45: bgneal@45: if (tb.childNodes.length == 1) bgneal@45: DOM.addClass(ro, 'mceFirst'); bgneal@45: bgneal@45: if ((n = ro.previousSibling) && DOM.hasClass(n, cp + 'ItemSeparator')) bgneal@45: DOM.addClass(ro, 'mceFirst'); bgneal@45: bgneal@45: if (o.collapse) bgneal@45: DOM.addClass(ro, cp + 'ItemSub'); bgneal@45: bgneal@45: if (n = ro.previousSibling) bgneal@45: DOM.removeClass(n, 'mceLast'); bgneal@45: bgneal@45: DOM.addClass(ro, 'mceLast'); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: (function(tinymce) { bgneal@45: var DOM = tinymce.DOM; bgneal@45: bgneal@45: tinymce.create('tinymce.ui.Button:tinymce.ui.Control', { bgneal@45: Button : function(id, s, ed) { bgneal@45: this.parent(id, s, ed); bgneal@45: this.classPrefix = 'mceButton'; bgneal@45: }, bgneal@45: bgneal@45: renderHTML : function() { bgneal@45: var cp = this.classPrefix, s = this.settings, h, l; bgneal@45: bgneal@45: l = DOM.encode(s.label || ''); bgneal@45: h = ''; bgneal@45: if (s.image && !(this.editor &&this.editor.forcedHighContrastMode) ) bgneal@45: h += '' + DOM.encode(s.title) + '' + l; bgneal@45: else bgneal@45: h += '' + (l ? '' + l + '' : ''); bgneal@45: bgneal@45: h += ''; bgneal@45: h += ''; bgneal@45: return h; bgneal@45: }, bgneal@45: bgneal@45: postRender : function() { bgneal@45: var t = this, s = t.settings, imgBookmark; bgneal@45: bgneal@45: // In IE a large image that occupies the entire editor area will be deselected when a button is clicked, so bgneal@45: // need to keep the selection in case the selection is lost bgneal@45: if (tinymce.isIE && t.editor) { bgneal@45: tinymce.dom.Event.add(t.id, 'mousedown', function(e) { bgneal@45: var nodeName = t.editor.selection.getNode().nodeName; bgneal@45: imgBookmark = nodeName === 'IMG' ? t.editor.selection.getBookmark() : null; bgneal@45: }); bgneal@45: } bgneal@45: tinymce.dom.Event.add(t.id, 'click', function(e) { bgneal@45: if (!t.isDisabled()) { bgneal@45: // restore the selection in case the selection is lost in IE bgneal@45: if (tinymce.isIE && t.editor && imgBookmark !== null) { bgneal@45: t.editor.selection.moveToBookmark(imgBookmark); bgneal@45: } bgneal@45: return s.onclick.call(s.scope, e); bgneal@45: } bgneal@45: }); bgneal@45: tinymce.dom.Event.add(t.id, 'keyup', function(e) { bgneal@45: if (!t.isDisabled() && e.keyCode==tinymce.VK.SPACEBAR) bgneal@45: return s.onclick.call(s.scope, e); bgneal@45: }); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher; bgneal@45: bgneal@45: tinymce.create('tinymce.ui.ListBox:tinymce.ui.Control', { bgneal@45: ListBox : function(id, s, ed) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.parent(id, s, ed); bgneal@45: bgneal@45: t.items = []; bgneal@45: bgneal@45: t.onChange = new Dispatcher(t); bgneal@45: bgneal@45: t.onPostRender = new Dispatcher(t); bgneal@45: bgneal@45: t.onAdd = new Dispatcher(t); bgneal@45: bgneal@45: t.onRenderMenu = new tinymce.util.Dispatcher(this); bgneal@45: bgneal@45: t.classPrefix = 'mceListBox'; bgneal@45: t.marked = {}; bgneal@45: }, bgneal@45: bgneal@45: select : function(va) { bgneal@45: var t = this, fv, f; bgneal@45: bgneal@45: t.marked = {}; bgneal@45: bgneal@45: if (va == undefined) bgneal@45: return t.selectByIndex(-1); bgneal@45: bgneal@45: // Is string or number make function selector bgneal@45: if (va && typeof(va)=="function") bgneal@45: f = va; bgneal@45: else { bgneal@45: f = function(v) { bgneal@45: return v == va; bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: // Do we need to do something? bgneal@45: if (va != t.selectedValue) { bgneal@45: // Find item bgneal@45: each(t.items, function(o, i) { bgneal@45: if (f(o.value)) { bgneal@45: fv = 1; bgneal@45: t.selectByIndex(i); bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: if (!fv) bgneal@45: t.selectByIndex(-1); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: selectByIndex : function(idx) { bgneal@45: var t = this, e, o, label; bgneal@45: bgneal@45: t.marked = {}; bgneal@45: bgneal@45: if (idx != t.selectedIndex) { bgneal@45: e = DOM.get(t.id + '_text'); bgneal@45: label = DOM.get(t.id + '_voiceDesc'); bgneal@45: o = t.items[idx]; bgneal@45: bgneal@45: if (o) { bgneal@45: t.selectedValue = o.value; bgneal@45: t.selectedIndex = idx; bgneal@45: DOM.setHTML(e, DOM.encode(o.title)); bgneal@45: DOM.setHTML(label, t.settings.title + " - " + o.title); bgneal@45: DOM.removeClass(e, 'mceTitle'); bgneal@45: DOM.setAttrib(t.id, 'aria-valuenow', o.title); bgneal@45: } else { bgneal@45: DOM.setHTML(e, DOM.encode(t.settings.title)); bgneal@45: DOM.setHTML(label, DOM.encode(t.settings.title)); bgneal@45: DOM.addClass(e, 'mceTitle'); bgneal@45: t.selectedValue = t.selectedIndex = null; bgneal@45: DOM.setAttrib(t.id, 'aria-valuenow', t.settings.title); bgneal@45: } bgneal@45: e = 0; bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: mark : function(value) { bgneal@45: this.marked[value] = true; bgneal@45: }, bgneal@45: bgneal@45: add : function(n, v, o) { bgneal@45: var t = this; bgneal@45: bgneal@45: o = o || {}; bgneal@45: o = tinymce.extend(o, { bgneal@45: title : n, bgneal@45: value : v bgneal@45: }); bgneal@45: bgneal@45: t.items.push(o); bgneal@45: t.onAdd.dispatch(t, o); bgneal@45: }, bgneal@45: bgneal@45: getLength : function() { bgneal@45: return this.items.length; bgneal@45: }, bgneal@45: bgneal@45: renderHTML : function() { bgneal@45: var h = '', t = this, s = t.settings, cp = t.classPrefix; bgneal@45: bgneal@45: h = ''; bgneal@45: h += ''; bgneal@45: h += ''; bgneal@45: h += ''; bgneal@45: bgneal@45: return h; bgneal@45: }, bgneal@45: bgneal@45: showMenu : function() { bgneal@45: var t = this, p2, e = DOM.get(this.id), m; bgneal@45: bgneal@45: if (t.isDisabled() || t.items.length == 0) bgneal@45: return; bgneal@45: bgneal@45: if (t.menu && t.menu.isMenuVisible) bgneal@45: return t.hideMenu(); bgneal@45: bgneal@45: if (!t.isMenuRendered) { bgneal@45: t.renderMenu(); bgneal@45: t.isMenuRendered = true; bgneal@45: } bgneal@45: bgneal@45: p2 = DOM.getPos(e); bgneal@45: bgneal@45: m = t.menu; bgneal@45: m.settings.offset_x = p2.x; bgneal@45: m.settings.offset_y = p2.y; bgneal@45: m.settings.keyboard_focus = !tinymce.isOpera; // Opera is buggy when it comes to auto focus bgneal@45: bgneal@45: // Select in menu bgneal@45: each(t.items, function(o) { bgneal@45: if (m.items[o.id]) { bgneal@45: m.items[o.id].setSelected(0); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: each(t.items, function(o) { bgneal@45: if (m.items[o.id] && t.marked[o.value]) { bgneal@45: m.items[o.id].setSelected(1); bgneal@45: } bgneal@45: bgneal@45: if (o.value === t.selectedValue) { bgneal@45: m.items[o.id].setSelected(1); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: m.showMenu(0, e.clientHeight); bgneal@45: bgneal@45: Event.add(DOM.doc, 'mousedown', t.hideMenu, t); bgneal@45: DOM.addClass(t.id, t.classPrefix + 'Selected'); bgneal@45: bgneal@45: //DOM.get(t.id + '_text').focus(); bgneal@45: }, bgneal@45: bgneal@45: hideMenu : function(e) { bgneal@45: var t = this; bgneal@45: bgneal@45: if (t.menu && t.menu.isMenuVisible) { bgneal@45: DOM.removeClass(t.id, t.classPrefix + 'Selected'); bgneal@45: bgneal@45: // Prevent double toogles by canceling the mouse click event to the button bgneal@45: if (e && e.type == "mousedown" && (e.target.id == t.id + '_text' || e.target.id == t.id + '_open')) bgneal@45: return; bgneal@45: bgneal@45: if (!e || !DOM.getParent(e.target, '.mceMenu')) { bgneal@45: DOM.removeClass(t.id, t.classPrefix + 'Selected'); bgneal@45: Event.remove(DOM.doc, 'mousedown', t.hideMenu, t); bgneal@45: t.menu.hideMenu(); bgneal@45: } bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: renderMenu : function() { bgneal@45: var t = this, m; bgneal@45: bgneal@45: m = t.settings.control_manager.createDropMenu(t.id + '_menu', { bgneal@45: menu_line : 1, bgneal@45: 'class' : t.classPrefix + 'Menu mceNoIcons', bgneal@45: max_width : 150, bgneal@45: max_height : 150 bgneal@45: }); bgneal@45: bgneal@45: m.onHideMenu.add(function() { bgneal@45: t.hideMenu(); bgneal@45: t.focus(); bgneal@45: }); bgneal@45: bgneal@45: m.add({ bgneal@45: title : t.settings.title, bgneal@45: 'class' : 'mceMenuItemTitle', bgneal@45: onclick : function() { bgneal@45: if (t.settings.onselect('') !== false) bgneal@45: t.select(''); // Must be runned after bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: each(t.items, function(o) { bgneal@45: // No value then treat it as a title bgneal@45: if (o.value === undefined) { bgneal@45: m.add({ bgneal@45: title : o.title, bgneal@45: role : "option", bgneal@45: 'class' : 'mceMenuItemTitle', bgneal@45: onclick : function() { bgneal@45: if (t.settings.onselect('') !== false) bgneal@45: t.select(''); // Must be runned after bgneal@45: } bgneal@45: }); bgneal@45: } else { bgneal@45: o.id = DOM.uniqueId(); bgneal@45: o.role= "option"; bgneal@45: o.onclick = function() { bgneal@45: if (t.settings.onselect(o.value) !== false) bgneal@45: t.select(o.value); // Must be runned after bgneal@45: }; bgneal@45: bgneal@45: m.add(o); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: t.onRenderMenu.dispatch(t, m); bgneal@45: t.menu = m; bgneal@45: }, bgneal@45: bgneal@45: postRender : function() { bgneal@45: var t = this, cp = t.classPrefix; bgneal@45: bgneal@45: Event.add(t.id, 'click', t.showMenu, t); bgneal@45: Event.add(t.id, 'keydown', function(evt) { bgneal@45: if (evt.keyCode == 32) { // Space bgneal@45: t.showMenu(evt); bgneal@45: Event.cancel(evt); bgneal@45: } bgneal@45: }); bgneal@45: Event.add(t.id, 'focus', function() { bgneal@45: if (!t._focused) { bgneal@45: t.keyDownHandler = Event.add(t.id, 'keydown', function(e) { bgneal@45: if (e.keyCode == 40) { bgneal@45: t.showMenu(); bgneal@45: Event.cancel(e); bgneal@45: } bgneal@45: }); bgneal@45: t.keyPressHandler = Event.add(t.id, 'keypress', function(e) { bgneal@45: var v; bgneal@45: if (e.keyCode == 13) { bgneal@45: // Fake select on enter bgneal@45: v = t.selectedValue; bgneal@45: t.selectedValue = null; // Needs to be null to fake change bgneal@45: Event.cancel(e); bgneal@45: t.settings.onselect(v); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: t._focused = 1; bgneal@45: }); bgneal@45: Event.add(t.id, 'blur', function() { bgneal@45: Event.remove(t.id, 'keydown', t.keyDownHandler); bgneal@45: Event.remove(t.id, 'keypress', t.keyPressHandler); bgneal@45: t._focused = 0; bgneal@45: }); bgneal@45: bgneal@45: // Old IE doesn't have hover on all elements bgneal@45: if (tinymce.isIE6 || !DOM.boxModel) { bgneal@45: Event.add(t.id, 'mouseover', function() { bgneal@45: if (!DOM.hasClass(t.id, cp + 'Disabled')) bgneal@45: DOM.addClass(t.id, cp + 'Hover'); bgneal@45: }); bgneal@45: bgneal@45: Event.add(t.id, 'mouseout', function() { bgneal@45: if (!DOM.hasClass(t.id, cp + 'Disabled')) bgneal@45: DOM.removeClass(t.id, cp + 'Hover'); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: t.onPostRender.dispatch(t, DOM.get(t.id)); bgneal@45: }, bgneal@45: bgneal@45: destroy : function() { bgneal@45: this.parent(); bgneal@45: bgneal@45: Event.clear(this.id + '_text'); bgneal@45: Event.clear(this.id + '_open'); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher; bgneal@45: bgneal@45: tinymce.create('tinymce.ui.NativeListBox:tinymce.ui.ListBox', { bgneal@45: NativeListBox : function(id, s) { bgneal@45: this.parent(id, s); bgneal@45: this.classPrefix = 'mceNativeListBox'; bgneal@45: }, bgneal@45: bgneal@45: setDisabled : function(s) { bgneal@45: DOM.get(this.id).disabled = s; bgneal@45: this.setAriaProperty('disabled', s); bgneal@45: }, bgneal@45: bgneal@45: isDisabled : function() { bgneal@45: return DOM.get(this.id).disabled; bgneal@45: }, bgneal@45: bgneal@45: select : function(va) { bgneal@45: var t = this, fv, f; bgneal@45: bgneal@45: if (va == undefined) bgneal@45: return t.selectByIndex(-1); bgneal@45: bgneal@45: // Is string or number make function selector bgneal@45: if (va && typeof(va)=="function") bgneal@45: f = va; bgneal@45: else { bgneal@45: f = function(v) { bgneal@45: return v == va; bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: // Do we need to do something? bgneal@45: if (va != t.selectedValue) { bgneal@45: // Find item bgneal@45: each(t.items, function(o, i) { bgneal@45: if (f(o.value)) { bgneal@45: fv = 1; bgneal@45: t.selectByIndex(i); bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: if (!fv) bgneal@45: t.selectByIndex(-1); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: selectByIndex : function(idx) { bgneal@45: DOM.get(this.id).selectedIndex = idx + 1; bgneal@45: this.selectedValue = this.items[idx] ? this.items[idx].value : null; bgneal@45: }, bgneal@45: bgneal@45: add : function(n, v, a) { bgneal@45: var o, t = this; bgneal@45: bgneal@45: a = a || {}; bgneal@45: a.value = v; bgneal@45: bgneal@45: if (t.isRendered()) bgneal@45: DOM.add(DOM.get(this.id), 'option', a, n); bgneal@45: bgneal@45: o = { bgneal@45: title : n, bgneal@45: value : v, bgneal@45: attribs : a bgneal@45: }; bgneal@45: bgneal@45: t.items.push(o); bgneal@45: t.onAdd.dispatch(t, o); bgneal@45: }, bgneal@45: bgneal@45: getLength : function() { bgneal@45: return this.items.length; bgneal@45: }, bgneal@45: bgneal@45: renderHTML : function() { bgneal@45: var h, t = this; bgneal@45: bgneal@45: h = DOM.createHTML('option', {value : ''}, '-- ' + t.settings.title + ' --'); bgneal@45: bgneal@45: each(t.items, function(it) { bgneal@45: h += DOM.createHTML('option', {value : it.value}, it.title); bgneal@45: }); bgneal@45: bgneal@45: h = DOM.createHTML('select', {id : t.id, 'class' : 'mceNativeListBox', 'aria-labelledby': t.id + '_aria'}, h); bgneal@45: h += DOM.createHTML('span', {id : t.id + '_aria', 'style': 'display: none'}, t.settings.title); bgneal@45: return h; bgneal@45: }, bgneal@45: bgneal@45: postRender : function() { bgneal@45: var t = this, ch, changeListenerAdded = true; bgneal@45: bgneal@45: t.rendered = true; bgneal@45: bgneal@45: function onChange(e) { bgneal@45: var v = t.items[e.target.selectedIndex - 1]; bgneal@45: bgneal@45: if (v && (v = v.value)) { bgneal@45: t.onChange.dispatch(t, v); bgneal@45: bgneal@45: if (t.settings.onselect) bgneal@45: t.settings.onselect(v); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: Event.add(t.id, 'change', onChange); bgneal@45: bgneal@45: // Accessibility keyhandler bgneal@45: Event.add(t.id, 'keydown', function(e) { bgneal@45: var bf; bgneal@45: bgneal@45: Event.remove(t.id, 'change', ch); bgneal@45: changeListenerAdded = false; bgneal@45: bgneal@45: bf = Event.add(t.id, 'blur', function() { bgneal@45: if (changeListenerAdded) return; bgneal@45: changeListenerAdded = true; bgneal@45: Event.add(t.id, 'change', onChange); bgneal@45: Event.remove(t.id, 'blur', bf); bgneal@45: }); bgneal@45: bgneal@45: //prevent default left and right keys on chrome - so that the keyboard navigation is used. bgneal@45: if (tinymce.isWebKit && (e.keyCode==37 ||e.keyCode==39)) { bgneal@45: return Event.prevent(e); bgneal@45: } bgneal@45: bgneal@45: if (e.keyCode == 13 || e.keyCode == 32) { bgneal@45: onChange(e); bgneal@45: return Event.cancel(e); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: t.onPostRender.dispatch(t, DOM.get(t.id)); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each; bgneal@45: bgneal@45: tinymce.create('tinymce.ui.MenuButton:tinymce.ui.Button', { bgneal@45: MenuButton : function(id, s, ed) { bgneal@45: this.parent(id, s, ed); bgneal@45: bgneal@45: this.onRenderMenu = new tinymce.util.Dispatcher(this); bgneal@45: bgneal@45: s.menu_container = s.menu_container || DOM.doc.body; bgneal@45: }, bgneal@45: bgneal@45: showMenu : function() { bgneal@45: var t = this, p1, p2, e = DOM.get(t.id), m; bgneal@45: bgneal@45: if (t.isDisabled()) bgneal@45: return; bgneal@45: bgneal@45: if (!t.isMenuRendered) { bgneal@45: t.renderMenu(); bgneal@45: t.isMenuRendered = true; bgneal@45: } bgneal@45: bgneal@45: if (t.isMenuVisible) bgneal@45: return t.hideMenu(); bgneal@45: bgneal@45: p1 = DOM.getPos(t.settings.menu_container); bgneal@45: p2 = DOM.getPos(e); bgneal@45: bgneal@45: m = t.menu; bgneal@45: m.settings.offset_x = p2.x; bgneal@45: m.settings.offset_y = p2.y; bgneal@45: m.settings.vp_offset_x = p2.x; bgneal@45: m.settings.vp_offset_y = p2.y; bgneal@45: m.settings.keyboard_focus = t._focused; bgneal@45: m.showMenu(0, e.clientHeight); bgneal@45: bgneal@45: Event.add(DOM.doc, 'mousedown', t.hideMenu, t); bgneal@45: t.setState('Selected', 1); bgneal@45: bgneal@45: t.isMenuVisible = 1; bgneal@45: }, bgneal@45: bgneal@45: renderMenu : function() { bgneal@45: var t = this, m; bgneal@45: bgneal@45: m = t.settings.control_manager.createDropMenu(t.id + '_menu', { bgneal@45: menu_line : 1, bgneal@45: 'class' : this.classPrefix + 'Menu', bgneal@45: icons : t.settings.icons bgneal@45: }); bgneal@45: bgneal@45: m.onHideMenu.add(function() { bgneal@45: t.hideMenu(); bgneal@45: t.focus(); bgneal@45: }); bgneal@45: bgneal@45: t.onRenderMenu.dispatch(t, m); bgneal@45: t.menu = m; bgneal@45: }, bgneal@45: bgneal@45: hideMenu : function(e) { bgneal@45: var t = this; bgneal@45: bgneal@45: // Prevent double toogles by canceling the mouse click event to the button bgneal@45: if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id || e.id === t.id + '_open';})) bgneal@45: return; bgneal@45: bgneal@45: if (!e || !DOM.getParent(e.target, '.mceMenu')) { bgneal@45: t.setState('Selected', 0); bgneal@45: Event.remove(DOM.doc, 'mousedown', t.hideMenu, t); bgneal@45: if (t.menu) bgneal@45: t.menu.hideMenu(); bgneal@45: } bgneal@45: bgneal@45: t.isMenuVisible = 0; bgneal@45: }, bgneal@45: bgneal@45: postRender : function() { bgneal@45: var t = this, s = t.settings; bgneal@45: bgneal@45: Event.add(t.id, 'click', function() { bgneal@45: if (!t.isDisabled()) { bgneal@45: if (s.onclick) bgneal@45: s.onclick(t.value); bgneal@45: bgneal@45: t.showMenu(); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each; bgneal@45: bgneal@45: tinymce.create('tinymce.ui.SplitButton:tinymce.ui.MenuButton', { bgneal@45: SplitButton : function(id, s, ed) { bgneal@45: this.parent(id, s, ed); bgneal@45: this.classPrefix = 'mceSplitButton'; bgneal@45: }, bgneal@45: bgneal@45: renderHTML : function() { bgneal@45: var h, t = this, s = t.settings, h1; bgneal@45: bgneal@45: h = ''; bgneal@45: bgneal@45: if (s.image) bgneal@45: h1 = DOM.createHTML('img ', {src : s.image, role: 'presentation', 'class' : 'mceAction ' + s['class']}); bgneal@45: else bgneal@45: h1 = DOM.createHTML('span', {'class' : 'mceAction ' + s['class']}, ''); bgneal@45: bgneal@45: h1 += DOM.createHTML('span', {'class': 'mceVoiceLabel mceIconOnly', id: t.id + '_voice', style: 'display:none;'}, s.title); bgneal@45: 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@45: bgneal@45: h1 = DOM.createHTML('span', {'class' : 'mceOpen ' + s['class']}, ''); bgneal@45: 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@45: bgneal@45: h += ''; bgneal@45: h = DOM.createHTML('table', { role: 'presentation', 'class' : 'mceSplitButton mceSplitButtonEnabled ' + s['class'], cellpadding : '0', cellspacing : '0', title : s.title}, h); bgneal@45: return DOM.createHTML('div', {id : t.id, role: 'button', tabindex: '0', 'aria-labelledby': t.id + '_voice', 'aria-haspopup': 'true'}, h); bgneal@45: }, bgneal@45: bgneal@45: postRender : function() { bgneal@45: var t = this, s = t.settings, activate; bgneal@45: bgneal@45: if (s.onclick) { bgneal@45: activate = function(evt) { bgneal@45: if (!t.isDisabled()) { bgneal@45: s.onclick(t.value); bgneal@45: Event.cancel(evt); bgneal@45: } bgneal@45: }; bgneal@45: Event.add(t.id + '_action', 'click', activate); bgneal@45: Event.add(t.id, ['click', 'keydown'], function(evt) { bgneal@45: var DOM_VK_SPACE = 32, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_UP = 38, DOM_VK_DOWN = 40; bgneal@45: if ((evt.keyCode === 32 || evt.keyCode === 13 || evt.keyCode === 14) && !evt.altKey && !evt.ctrlKey && !evt.metaKey) { bgneal@45: activate(); bgneal@45: Event.cancel(evt); bgneal@45: } else if (evt.type === 'click' || evt.keyCode === DOM_VK_DOWN) { bgneal@45: t.showMenu(); bgneal@45: Event.cancel(evt); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: Event.add(t.id + '_open', 'click', function (evt) { bgneal@45: t.showMenu(); bgneal@45: Event.cancel(evt); bgneal@45: }); bgneal@45: Event.add([t.id, t.id + '_open'], 'focus', function() {t._focused = 1;}); bgneal@45: Event.add([t.id, t.id + '_open'], 'blur', function() {t._focused = 0;}); bgneal@45: bgneal@45: // Old IE doesn't have hover on all elements bgneal@45: if (tinymce.isIE6 || !DOM.boxModel) { bgneal@45: Event.add(t.id, 'mouseover', function() { bgneal@45: if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled')) bgneal@45: DOM.addClass(t.id, 'mceSplitButtonHover'); bgneal@45: }); bgneal@45: bgneal@45: Event.add(t.id, 'mouseout', function() { bgneal@45: if (!DOM.hasClass(t.id, 'mceSplitButtonDisabled')) bgneal@45: DOM.removeClass(t.id, 'mceSplitButtonHover'); bgneal@45: }); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: destroy : function() { bgneal@45: this.parent(); bgneal@45: bgneal@45: Event.clear(this.id + '_action'); bgneal@45: Event.clear(this.id + '_open'); bgneal@45: Event.clear(this.id); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: var DOM = tinymce.DOM, Event = tinymce.dom.Event, is = tinymce.is, each = tinymce.each; bgneal@45: bgneal@45: tinymce.create('tinymce.ui.ColorSplitButton:tinymce.ui.SplitButton', { bgneal@45: ColorSplitButton : function(id, s, ed) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.parent(id, s, ed); bgneal@45: bgneal@45: t.settings = s = tinymce.extend({ bgneal@45: 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@45: grid_width : 8, bgneal@45: default_color : '#888888' bgneal@45: }, t.settings); bgneal@45: bgneal@45: t.onShowMenu = new tinymce.util.Dispatcher(t); bgneal@45: bgneal@45: t.onHideMenu = new tinymce.util.Dispatcher(t); bgneal@45: bgneal@45: t.value = s.default_color; bgneal@45: }, bgneal@45: bgneal@45: showMenu : function() { bgneal@45: var t = this, r, p, e, p2; bgneal@45: bgneal@45: if (t.isDisabled()) bgneal@45: return; bgneal@45: bgneal@45: if (!t.isMenuRendered) { bgneal@45: t.renderMenu(); bgneal@45: t.isMenuRendered = true; bgneal@45: } bgneal@45: bgneal@45: if (t.isMenuVisible) bgneal@45: return t.hideMenu(); bgneal@45: bgneal@45: e = DOM.get(t.id); bgneal@45: DOM.show(t.id + '_menu'); bgneal@45: DOM.addClass(e, 'mceSplitButtonSelected'); bgneal@45: p2 = DOM.getPos(e); bgneal@45: DOM.setStyles(t.id + '_menu', { bgneal@45: left : p2.x, bgneal@45: top : p2.y + e.clientHeight, bgneal@45: zIndex : 200000 bgneal@45: }); bgneal@45: e = 0; bgneal@45: bgneal@45: Event.add(DOM.doc, 'mousedown', t.hideMenu, t); bgneal@45: t.onShowMenu.dispatch(t); bgneal@45: bgneal@45: if (t._focused) { bgneal@45: t._keyHandler = Event.add(t.id + '_menu', 'keydown', function(e) { bgneal@45: if (e.keyCode == 27) bgneal@45: t.hideMenu(); bgneal@45: }); bgneal@45: bgneal@45: DOM.select('a', t.id + '_menu')[0].focus(); // Select first link bgneal@45: } bgneal@45: bgneal@45: t.isMenuVisible = 1; bgneal@45: }, bgneal@45: bgneal@45: hideMenu : function(e) { bgneal@45: var t = this; bgneal@45: bgneal@45: if (t.isMenuVisible) { bgneal@45: // Prevent double toogles by canceling the mouse click event to the button bgneal@45: if (e && e.type == "mousedown" && DOM.getParent(e.target, function(e) {return e.id === t.id + '_open';})) bgneal@45: return; bgneal@45: bgneal@45: if (!e || !DOM.getParent(e.target, '.mceSplitButtonMenu')) { bgneal@45: DOM.removeClass(t.id, 'mceSplitButtonSelected'); bgneal@45: Event.remove(DOM.doc, 'mousedown', t.hideMenu, t); bgneal@45: Event.remove(t.id + '_menu', 'keydown', t._keyHandler); bgneal@45: DOM.hide(t.id + '_menu'); bgneal@45: } bgneal@45: bgneal@45: t.isMenuVisible = 0; bgneal@45: t.onHideMenu.dispatch(); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: renderMenu : function() { bgneal@45: var t = this, m, i = 0, s = t.settings, n, tb, tr, w, context; bgneal@45: bgneal@45: 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@45: m = DOM.add(w, 'div', {'class' : s['class'] + ' mceSplitButtonMenu'}); bgneal@45: DOM.add(m, 'span', {'class' : 'mceMenuLine'}); bgneal@45: bgneal@45: n = DOM.add(m, 'table', {role: 'presentation', 'class' : 'mceColorSplitMenu'}); bgneal@45: tb = DOM.add(n, 'tbody'); bgneal@45: bgneal@45: // Generate color grid bgneal@45: i = 0; bgneal@45: each(is(s.colors, 'array') ? s.colors : s.colors.split(','), function(c) { bgneal@45: c = c.replace(/^#/, ''); bgneal@45: bgneal@45: if (!i--) { bgneal@45: tr = DOM.add(tb, 'tr'); bgneal@45: i = s.grid_width - 1; bgneal@45: } bgneal@45: bgneal@45: n = DOM.add(tr, 'td'); bgneal@45: var settings = { bgneal@45: href : 'javascript:;', bgneal@45: style : { bgneal@45: backgroundColor : '#' + c bgneal@45: }, bgneal@45: 'title': t.editor.getLang('colors.' + c, c), bgneal@45: 'data-mce-color' : '#' + c bgneal@45: }; bgneal@45: bgneal@45: // adding a proper ARIA role = button causes JAWS to read things incorrectly on IE. bgneal@45: if (!tinymce.isIE ) { bgneal@45: settings['role']= 'option'; bgneal@45: } bgneal@45: bgneal@45: n = DOM.add(n, 'a', settings); bgneal@45: bgneal@45: if (t.editor.forcedHighContrastMode) { bgneal@45: n = DOM.add(n, 'canvas', { width: 16, height: 16, 'aria-hidden': 'true' }); bgneal@45: if (n.getContext && (context = n.getContext("2d"))) { bgneal@45: context.fillStyle = '#' + c; bgneal@45: context.fillRect(0, 0, 16, 16); bgneal@45: } else { bgneal@45: // No point leaving a canvas element around if it's not supported for drawing on anyway. bgneal@45: DOM.remove(n); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: if (s.more_colors_func) { bgneal@45: n = DOM.add(tb, 'tr'); bgneal@45: n = DOM.add(n, 'td', {colspan : s.grid_width, 'class' : 'mceMoreColors'}); bgneal@45: n = DOM.add(n, 'a', {role: 'option', id : t.id + '_more', href : 'javascript:;', onclick : 'return false;', 'class' : 'mceMoreColors'}, s.more_colors_title); bgneal@45: bgneal@45: Event.add(n, 'click', function(e) { bgneal@45: s.more_colors_func.call(s.more_colors_scope || this); bgneal@45: return Event.cancel(e); // Cancel to fix onbeforeunload problem bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: DOM.addClass(m, 'mceColorSplitMenu'); bgneal@45: bgneal@45: new tinymce.ui.KeyboardNavigation({ bgneal@45: root: t.id + '_menu', bgneal@45: items: DOM.select('a', t.id + '_menu'), bgneal@45: onCancel: function() { bgneal@45: t.hideMenu(); bgneal@45: t.focus(); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Prevent IE from scrolling and hindering click to occur #4019 bgneal@45: Event.add(t.id + '_menu', 'mousedown', function(e) {return Event.cancel(e);}); bgneal@45: bgneal@45: Event.add(t.id + '_menu', 'click', function(e) { bgneal@45: var c; bgneal@45: bgneal@45: e = DOM.getParent(e.target, 'a', tb); bgneal@45: bgneal@45: if (e && e.nodeName.toLowerCase() == 'a' && (c = e.getAttribute('data-mce-color'))) bgneal@45: t.setColor(c); bgneal@45: bgneal@45: return false; // Prevent IE auto save warning bgneal@45: }); bgneal@45: bgneal@45: return w; bgneal@45: }, bgneal@45: bgneal@45: setColor : function(c) { bgneal@45: this.displayColor(c); bgneal@45: this.hideMenu(); bgneal@45: this.settings.onselect(c); bgneal@45: }, bgneal@45: bgneal@45: displayColor : function(c) { bgneal@45: var t = this; bgneal@45: bgneal@45: DOM.setStyle(t.id + '_preview', 'backgroundColor', c); bgneal@45: bgneal@45: t.value = c; bgneal@45: }, bgneal@45: bgneal@45: postRender : function() { bgneal@45: var t = this, id = t.id; bgneal@45: bgneal@45: t.parent(); bgneal@45: DOM.add(id + '_action', 'div', {id : id + '_preview', 'class' : 'mceColorPreview'}); bgneal@45: DOM.setStyle(t.id + '_preview', 'backgroundColor', t.value); bgneal@45: }, bgneal@45: bgneal@45: destroy : function() { bgneal@45: this.parent(); bgneal@45: bgneal@45: Event.clear(this.id + '_menu'); bgneal@45: Event.clear(this.id + '_more'); bgneal@45: DOM.remove(this.id + '_menu'); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: // Shorten class names bgneal@45: var dom = tinymce.DOM, each = tinymce.each, Event = tinymce.dom.Event; bgneal@45: tinymce.create('tinymce.ui.ToolbarGroup:tinymce.ui.Container', { bgneal@45: renderHTML : function() { bgneal@45: var t = this, h = [], controls = t.controls, each = tinymce.each, settings = t.settings; bgneal@45: bgneal@45: h.push('
    '); bgneal@45: //TODO: ACC test this out - adding a role = application for getting the landmarks working well. bgneal@45: h.push(""); bgneal@45: h.push(''); bgneal@45: each(controls, function(toolbar) { bgneal@45: h.push(toolbar.renderHTML()); bgneal@45: }); bgneal@45: h.push(""); bgneal@45: h.push('
    '); bgneal@45: bgneal@45: return h.join(''); bgneal@45: }, bgneal@45: bgneal@45: focus : function() { bgneal@45: var t = this; bgneal@45: dom.get(t.id).focus(); bgneal@45: }, bgneal@45: bgneal@45: postRender : function() { bgneal@45: var t = this, items = []; bgneal@45: bgneal@45: each(t.controls, function(toolbar) { bgneal@45: each (toolbar.controls, function(control) { bgneal@45: if (control.id) { bgneal@45: items.push(control); bgneal@45: } bgneal@45: }); bgneal@45: }); bgneal@45: bgneal@45: t.keyNav = new tinymce.ui.KeyboardNavigation({ bgneal@45: root: t.id, bgneal@45: items: items, bgneal@45: onCancel: function() { bgneal@45: //Move focus if webkit so that navigation back will read the item. bgneal@45: if (tinymce.isWebKit) { bgneal@45: dom.get(t.editor.id+"_ifr").focus(); bgneal@45: } bgneal@45: t.editor.focus(); bgneal@45: }, bgneal@45: excludeFromTabOrder: !t.settings.tab_focus_toolbar bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: destroy : function() { bgneal@45: var self = this; bgneal@45: bgneal@45: self.parent(); bgneal@45: self.keyNav.destroy(); bgneal@45: Event.clear(self.id); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: // Shorten class names bgneal@45: var dom = tinymce.DOM, each = tinymce.each; bgneal@45: tinymce.create('tinymce.ui.Toolbar:tinymce.ui.Container', { bgneal@45: renderHTML : function() { bgneal@45: var t = this, h = '', c, co, s = t.settings, i, pr, nx, cl; bgneal@45: bgneal@45: cl = t.controls; bgneal@45: for (i=0; i')); bgneal@45: } bgneal@45: bgneal@45: // Add toolbar end before list box and after the previous button bgneal@45: // This is to fix the o2k7 editor skins bgneal@45: if (pr && co.ListBox) { bgneal@45: if (pr.Button || pr.SplitButton) bgneal@45: h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '')); bgneal@45: } bgneal@45: bgneal@45: // Render control HTML bgneal@45: bgneal@45: // IE 8 quick fix, needed to propertly generate a hit area for anchors bgneal@45: if (dom.stdMode) bgneal@45: h += '' + co.renderHTML() + ''; bgneal@45: else bgneal@45: h += '' + co.renderHTML() + ''; bgneal@45: bgneal@45: // Add toolbar start after list box and before the next button bgneal@45: // This is to fix the o2k7 editor skins bgneal@45: if (nx && co.ListBox) { bgneal@45: if (nx.Button || nx.SplitButton) bgneal@45: h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '')); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: c = 'mceToolbarEnd'; bgneal@45: bgneal@45: if (co.Button) bgneal@45: c += ' mceToolbarEndButton'; bgneal@45: else if (co.SplitButton) bgneal@45: c += ' mceToolbarEndSplitButton'; bgneal@45: else if (co.ListBox) bgneal@45: c += ' mceToolbarEndListBox'; bgneal@45: bgneal@45: h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '')); bgneal@45: bgneal@45: 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@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each; bgneal@45: bgneal@45: tinymce.create('tinymce.AddOnManager', { bgneal@45: AddOnManager : function() { bgneal@45: var self = this; bgneal@45: bgneal@45: self.items = []; bgneal@45: self.urls = {}; bgneal@45: self.lookup = {}; bgneal@45: self.onAdd = new Dispatcher(self); bgneal@45: }, bgneal@45: bgneal@45: get : function(n) { bgneal@45: if (this.lookup[n]) { bgneal@45: return this.lookup[n].instance; bgneal@45: } else { bgneal@45: return undefined; bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: dependencies : function(n) { bgneal@45: var result; bgneal@45: if (this.lookup[n]) { bgneal@45: result = this.lookup[n].dependencies; bgneal@45: } bgneal@45: return result || []; bgneal@45: }, bgneal@45: bgneal@45: requireLangPack : function(n) { bgneal@45: var s = tinymce.settings; bgneal@45: bgneal@45: if (s && s.language && s.language_load !== false) bgneal@45: tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js'); bgneal@45: }, bgneal@45: bgneal@45: add : function(id, o, dependencies) { bgneal@45: this.items.push(o); bgneal@45: this.lookup[id] = {instance:o, dependencies:dependencies}; bgneal@45: this.onAdd.dispatch(this, id, o); bgneal@45: bgneal@45: return o; bgneal@45: }, bgneal@45: createUrl: function(baseUrl, dep) { bgneal@45: if (typeof dep === "object") { bgneal@45: return dep bgneal@45: } else { bgneal@45: return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix}; bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: addComponents: function(pluginName, scripts) { bgneal@45: var pluginUrl = this.urls[pluginName]; bgneal@45: tinymce.each(scripts, function(script){ bgneal@45: tinymce.ScriptLoader.add(pluginUrl+"/"+script); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: load : function(n, u, cb, s) { bgneal@45: var t = this, url = u; bgneal@45: bgneal@45: function loadDependencies() { bgneal@45: var dependencies = t.dependencies(n); bgneal@45: tinymce.each(dependencies, function(dep) { bgneal@45: var newUrl = t.createUrl(u, dep); bgneal@45: t.load(newUrl.resource, newUrl, undefined, undefined); bgneal@45: }); bgneal@45: if (cb) { bgneal@45: if (s) { bgneal@45: cb.call(s); bgneal@45: } else { bgneal@45: cb.call(tinymce.ScriptLoader); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if (t.urls[n]) bgneal@45: return; bgneal@45: if (typeof u === "object") bgneal@45: url = u.prefix + u.resource + u.suffix; bgneal@45: bgneal@45: if (url.indexOf('/') != 0 && url.indexOf('://') == -1) bgneal@45: url = tinymce.baseURL + '/' + url; bgneal@45: bgneal@45: t.urls[n] = url.substring(0, url.lastIndexOf('/')); bgneal@45: bgneal@45: if (t.lookup[n]) { bgneal@45: loadDependencies(); bgneal@45: } else { bgneal@45: tinymce.ScriptLoader.add(url, loadDependencies, s); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Create plugin and theme managers bgneal@45: tinymce.PluginManager = new tinymce.AddOnManager(); bgneal@45: tinymce.ThemeManager = new tinymce.AddOnManager(); bgneal@45: }(tinymce)); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: // Shorten names bgneal@45: var each = tinymce.each, extend = tinymce.extend, bgneal@45: DOM = tinymce.DOM, Event = tinymce.dom.Event, bgneal@45: ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager, bgneal@45: explode = tinymce.explode, bgneal@45: Dispatcher = tinymce.util.Dispatcher, undefined, instanceCounter = 0; bgneal@45: bgneal@45: // Setup some URLs where the editor API is located and where the document is bgneal@45: tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, ''); bgneal@45: if (!/[\/\\]$/.test(tinymce.documentBaseURL)) bgneal@45: tinymce.documentBaseURL += '/'; bgneal@45: bgneal@45: tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL); bgneal@45: bgneal@45: tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL); bgneal@45: bgneal@45: // Add before unload listener bgneal@45: // This was required since IE was leaking memory if you added and removed beforeunload listeners bgneal@45: // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event bgneal@45: tinymce.onBeforeUnload = new Dispatcher(tinymce); bgneal@45: bgneal@45: // Must be on window or IE will leak if the editor is placed in frame or iframe bgneal@45: Event.add(window, 'beforeunload', function(e) { bgneal@45: tinymce.onBeforeUnload.dispatch(tinymce, e); bgneal@45: }); bgneal@45: bgneal@45: tinymce.onAddEditor = new Dispatcher(tinymce); bgneal@45: bgneal@45: tinymce.onRemoveEditor = new Dispatcher(tinymce); bgneal@45: bgneal@45: tinymce.EditorManager = extend(tinymce, { bgneal@45: editors : [], bgneal@45: bgneal@45: i18n : {}, bgneal@45: bgneal@45: activeEditor : null, bgneal@45: bgneal@45: init : function(s) { bgneal@45: var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed; bgneal@45: bgneal@45: function createId(elm) { bgneal@45: var id = elm.id; bgneal@45: bgneal@45: // Use element id, or unique name or generate a unique id bgneal@45: if (!id) { bgneal@45: id = elm.name; bgneal@45: bgneal@45: if (id && !DOM.get(id)) { bgneal@45: id = elm.name; bgneal@45: } else { bgneal@45: // Generate unique name bgneal@45: id = DOM.uniqueId(); bgneal@45: } bgneal@45: bgneal@45: elm.setAttribute('id', id); bgneal@45: } bgneal@45: bgneal@45: return id; bgneal@45: }; bgneal@45: bgneal@45: function execCallback(se, n, s) { bgneal@45: var f = se[n]; bgneal@45: bgneal@45: if (!f) bgneal@45: return; bgneal@45: bgneal@45: if (tinymce.is(f, 'string')) { bgneal@45: s = f.replace(/\.\w+$/, ''); bgneal@45: s = s ? tinymce.resolve(s) : 0; bgneal@45: f = tinymce.resolve(f); bgneal@45: } bgneal@45: bgneal@45: return f.apply(s || this, Array.prototype.slice.call(arguments, 2)); bgneal@45: }; bgneal@45: bgneal@45: s = extend({ bgneal@45: theme : "simple", bgneal@45: language : "en" bgneal@45: }, s); bgneal@45: bgneal@45: t.settings = s; bgneal@45: bgneal@45: // Legacy call bgneal@45: Event.bind(window, 'ready', function() { bgneal@45: var l, co; bgneal@45: bgneal@45: execCallback(s, 'onpageload'); bgneal@45: bgneal@45: switch (s.mode) { bgneal@45: case "exact": bgneal@45: l = s.elements || ''; bgneal@45: bgneal@45: if(l.length > 0) { bgneal@45: each(explode(l), function(v) { bgneal@45: if (DOM.get(v)) { bgneal@45: ed = new tinymce.Editor(v, s); bgneal@45: el.push(ed); bgneal@45: ed.render(1); bgneal@45: } else { bgneal@45: each(document.forms, function(f) { bgneal@45: each(f.elements, function(e) { bgneal@45: if (e.name === v) { bgneal@45: v = 'mce_editor_' + instanceCounter++; bgneal@45: DOM.setAttrib(e, 'id', v); bgneal@45: bgneal@45: ed = new tinymce.Editor(v, s); bgneal@45: el.push(ed); bgneal@45: ed.render(1); bgneal@45: } bgneal@45: }); bgneal@45: }); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: break; bgneal@45: bgneal@45: case "textareas": bgneal@45: case "specific_textareas": bgneal@45: function hasClass(n, c) { bgneal@45: return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c); bgneal@45: }; bgneal@45: bgneal@45: each(DOM.select('textarea'), function(elm) { bgneal@45: if (s.editor_deselector && hasClass(elm, s.editor_deselector)) bgneal@45: return; bgneal@45: bgneal@45: if (!s.editor_selector || hasClass(elm, s.editor_selector)) { bgneal@45: ed = new tinymce.Editor(createId(elm), s); bgneal@45: el.push(ed); bgneal@45: ed.render(1); bgneal@45: } bgneal@45: }); bgneal@45: break; bgneal@45: bgneal@45: default: bgneal@45: if (s.types) { bgneal@45: // Process type specific selector bgneal@45: each(s.types, function(type) { bgneal@45: each(DOM.select(type.selector), function(elm) { bgneal@45: var editor = new tinymce.Editor(createId(elm), tinymce.extend({}, s, type)); bgneal@45: el.push(editor); bgneal@45: editor.render(1); bgneal@45: }); bgneal@45: }); bgneal@45: } else if (s.selector) { bgneal@45: // Process global selector bgneal@45: each(DOM.select(s.selector), function(elm) { bgneal@45: var editor = new tinymce.Editor(createId(elm), s); bgneal@45: el.push(editor); bgneal@45: editor.render(1); bgneal@45: }); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Call onInit when all editors are initialized bgneal@45: if (s.oninit) { bgneal@45: l = co = 0; bgneal@45: bgneal@45: each(el, function(ed) { bgneal@45: co++; bgneal@45: bgneal@45: if (!ed.initialized) { bgneal@45: // Wait for it bgneal@45: ed.onInit.add(function() { bgneal@45: l++; bgneal@45: bgneal@45: // All done bgneal@45: if (l == co) bgneal@45: execCallback(s, 'oninit'); bgneal@45: }); bgneal@45: } else bgneal@45: l++; bgneal@45: bgneal@45: // All done bgneal@45: if (l == co) bgneal@45: execCallback(s, 'oninit'); bgneal@45: }); bgneal@45: } bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: get : function(id) { bgneal@45: if (id === undefined) bgneal@45: return this.editors; bgneal@45: bgneal@45: return this.editors[id]; bgneal@45: }, bgneal@45: bgneal@45: getInstanceById : function(id) { bgneal@45: return this.get(id); bgneal@45: }, bgneal@45: bgneal@45: add : function(editor) { bgneal@45: var self = this, editors = self.editors; bgneal@45: bgneal@45: // Add named and index editor instance bgneal@45: editors[editor.id] = editor; bgneal@45: editors.push(editor); bgneal@45: bgneal@45: self._setActive(editor); bgneal@45: self.onAddEditor.dispatch(self, editor); bgneal@45: bgneal@45: bgneal@45: return editor; bgneal@45: }, bgneal@45: bgneal@45: remove : function(editor) { bgneal@45: var t = this, i, editors = t.editors; bgneal@45: bgneal@45: // Not in the collection bgneal@45: if (!editors[editor.id]) bgneal@45: return null; bgneal@45: bgneal@45: delete editors[editor.id]; bgneal@45: bgneal@45: for (i = 0; i < editors.length; i++) { bgneal@45: if (editors[i] == editor) { bgneal@45: editors.splice(i, 1); bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Select another editor since the active one was removed bgneal@45: if (t.activeEditor == editor) bgneal@45: t._setActive(editors[0]); bgneal@45: bgneal@45: editor.destroy(); bgneal@45: t.onRemoveEditor.dispatch(t, editor); bgneal@45: bgneal@45: return editor; bgneal@45: }, bgneal@45: bgneal@45: execCommand : function(c, u, v) { bgneal@45: var t = this, ed = t.get(v), w; bgneal@45: bgneal@45: // Manager commands bgneal@45: switch (c) { bgneal@45: case "mceFocus": bgneal@45: ed.focus(); bgneal@45: return true; bgneal@45: bgneal@45: case "mceAddEditor": bgneal@45: case "mceAddControl": bgneal@45: if (!t.get(v)) bgneal@45: new tinymce.Editor(v, t.settings).render(); bgneal@45: bgneal@45: return true; bgneal@45: bgneal@45: case "mceAddFrameControl": bgneal@45: w = v.window; bgneal@45: bgneal@45: // Add tinyMCE global instance and tinymce namespace to specified window bgneal@45: w.tinyMCE = tinyMCE; bgneal@45: w.tinymce = tinymce; bgneal@45: bgneal@45: tinymce.DOM.doc = w.document; bgneal@45: tinymce.DOM.win = w; bgneal@45: bgneal@45: ed = new tinymce.Editor(v.element_id, v); bgneal@45: ed.render(); bgneal@45: bgneal@45: // Fix IE memory leaks bgneal@45: if (tinymce.isIE) { bgneal@45: function clr() { bgneal@45: ed.destroy(); bgneal@45: w.detachEvent('onunload', clr); bgneal@45: w = w.tinyMCE = w.tinymce = null; // IE leak bgneal@45: }; bgneal@45: bgneal@45: w.attachEvent('onunload', clr); bgneal@45: } bgneal@45: bgneal@45: v.page_window = null; bgneal@45: bgneal@45: return true; bgneal@45: bgneal@45: case "mceRemoveEditor": bgneal@45: case "mceRemoveControl": bgneal@45: if (ed) bgneal@45: ed.remove(); bgneal@45: bgneal@45: return true; bgneal@45: bgneal@45: case 'mceToggleEditor': bgneal@45: if (!ed) { bgneal@45: t.execCommand('mceAddControl', 0, v); bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: if (ed.isHidden()) bgneal@45: ed.show(); bgneal@45: else bgneal@45: ed.hide(); bgneal@45: bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: // Run command on active editor bgneal@45: if (t.activeEditor) bgneal@45: return t.activeEditor.execCommand(c, u, v); bgneal@45: bgneal@45: return false; bgneal@45: }, bgneal@45: bgneal@45: execInstanceCommand : function(id, c, u, v) { bgneal@45: var ed = this.get(id); bgneal@45: bgneal@45: if (ed) bgneal@45: return ed.execCommand(c, u, v); bgneal@45: bgneal@45: return false; bgneal@45: }, bgneal@45: bgneal@45: triggerSave : function() { bgneal@45: each(this.editors, function(e) { bgneal@45: e.save(); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: addI18n : function(p, o) { bgneal@45: var lo, i18n = this.i18n; bgneal@45: bgneal@45: if (!tinymce.is(p, 'string')) { bgneal@45: each(p, function(o, lc) { bgneal@45: each(o, function(o, g) { bgneal@45: each(o, function(o, k) { bgneal@45: if (g === 'common') bgneal@45: i18n[lc + '.' + k] = o; bgneal@45: else bgneal@45: i18n[lc + '.' + g + '.' + k] = o; bgneal@45: }); bgneal@45: }); bgneal@45: }); bgneal@45: } else { bgneal@45: each(o, function(o, k) { bgneal@45: i18n[p + '.' + k] = o; bgneal@45: }); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: // Private methods bgneal@45: bgneal@45: _setActive : function(editor) { bgneal@45: this.selectedInstance = this.activeEditor = editor; bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: // Shorten these names bgneal@45: var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, bgneal@45: Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isGecko = tinymce.isGecko, bgneal@45: isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is, bgneal@45: ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager, bgneal@45: inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode, VK = tinymce.VK; bgneal@45: bgneal@45: tinymce.create('tinymce.Editor', { bgneal@45: Editor : function(id, s) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.id = t.editorId = id; bgneal@45: bgneal@45: t.execCommands = {}; bgneal@45: t.queryStateCommands = {}; bgneal@45: t.queryValueCommands = {}; bgneal@45: bgneal@45: t.isNotDirty = false; bgneal@45: bgneal@45: t.plugins = {}; bgneal@45: bgneal@45: // Add events to the editor bgneal@45: each([ bgneal@45: 'onPreInit', bgneal@45: bgneal@45: 'onBeforeRenderUI', bgneal@45: bgneal@45: 'onPostRender', bgneal@45: bgneal@45: 'onLoad', bgneal@45: bgneal@45: 'onInit', bgneal@45: bgneal@45: 'onRemove', bgneal@45: bgneal@45: 'onActivate', bgneal@45: bgneal@45: 'onDeactivate', bgneal@45: bgneal@45: 'onClick', bgneal@45: bgneal@45: 'onEvent', bgneal@45: bgneal@45: 'onMouseUp', bgneal@45: bgneal@45: 'onMouseDown', bgneal@45: bgneal@45: 'onDblClick', bgneal@45: bgneal@45: 'onKeyDown', bgneal@45: bgneal@45: 'onKeyUp', bgneal@45: bgneal@45: 'onKeyPress', bgneal@45: bgneal@45: 'onContextMenu', bgneal@45: bgneal@45: 'onSubmit', bgneal@45: bgneal@45: 'onReset', bgneal@45: bgneal@45: 'onPaste', bgneal@45: bgneal@45: 'onPreProcess', bgneal@45: bgneal@45: 'onPostProcess', bgneal@45: bgneal@45: 'onBeforeSetContent', bgneal@45: bgneal@45: 'onBeforeGetContent', bgneal@45: bgneal@45: 'onSetContent', bgneal@45: bgneal@45: 'onGetContent', bgneal@45: bgneal@45: 'onLoadContent', bgneal@45: bgneal@45: 'onSaveContent', bgneal@45: bgneal@45: 'onNodeChange', bgneal@45: bgneal@45: 'onChange', bgneal@45: bgneal@45: 'onBeforeExecCommand', bgneal@45: bgneal@45: 'onExecCommand', bgneal@45: bgneal@45: 'onUndo', bgneal@45: bgneal@45: 'onRedo', bgneal@45: bgneal@45: 'onVisualAid', bgneal@45: bgneal@45: 'onSetProgressState', bgneal@45: bgneal@45: 'onSetAttrib' bgneal@45: ], function(e) { bgneal@45: t[e] = new Dispatcher(t); bgneal@45: }); bgneal@45: bgneal@45: t.settings = s = extend({ bgneal@45: id : id, bgneal@45: language : 'en', bgneal@45: docs_language : 'en', bgneal@45: theme : 'simple', bgneal@45: skin : 'default', bgneal@45: delta_width : 0, bgneal@45: delta_height : 0, bgneal@45: popup_css : '', bgneal@45: plugins : '', bgneal@45: document_base_url : tinymce.documentBaseURL, bgneal@45: add_form_submit_trigger : 1, bgneal@45: submit_patch : 1, bgneal@45: add_unload_trigger : 1, bgneal@45: convert_urls : 1, bgneal@45: relative_urls : 1, bgneal@45: remove_script_host : 1, bgneal@45: table_inline_editing : 0, bgneal@45: object_resizing : 1, bgneal@45: cleanup : 1, bgneal@45: accessibility_focus : 1, bgneal@45: custom_shortcuts : 1, bgneal@45: custom_undo_redo_keyboard_shortcuts : 1, bgneal@45: custom_undo_redo_restore_selection : 1, bgneal@45: custom_undo_redo : 1, bgneal@45: doctype : tinymce.isIE6 ? '' : '', // Use old doctype on IE 6 to avoid horizontal scroll bgneal@45: visual_table_class : 'mceItemTable', bgneal@45: visual : 1, bgneal@45: font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large', bgneal@45: font_size_legacy_values : 'xx-small,small,medium,large,x-large,xx-large,300%', // See: http://www.w3.org/TR/CSS2/fonts.html#propdef-font-size bgneal@45: apply_source_formatting : 1, bgneal@45: directionality : 'ltr', bgneal@45: forced_root_block : 'p', bgneal@45: hidden_input : 1, bgneal@45: padd_empty_editor : 1, bgneal@45: render_ui : 1, bgneal@45: init_theme : 1, bgneal@45: force_p_newlines : 1, bgneal@45: indentation : '30px', bgneal@45: keep_styles : 1, bgneal@45: fix_table_elements : 1, bgneal@45: inline_styles : 1, bgneal@45: convert_fonts_to_spans : true, bgneal@45: indent : 'simple', bgneal@45: indent_before : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr,section,article,hgroup,aside', bgneal@45: indent_after : 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr,section,article,hgroup,aside', bgneal@45: validate : true, bgneal@45: entity_encoding : 'named', bgneal@45: url_converter : t.convertURL, bgneal@45: url_converter_scope : t, bgneal@45: ie7_compat : true bgneal@45: }, s); bgneal@45: bgneal@45: t.documentBaseURI = new tinymce.util.URI(s.document_base_url || tinymce.documentBaseURL, { bgneal@45: base_uri : tinyMCE.baseURI bgneal@45: }); bgneal@45: bgneal@45: t.baseURI = tinymce.baseURI; bgneal@45: bgneal@45: t.contentCSS = []; bgneal@45: bgneal@45: // Call setup bgneal@45: t.execCallback('setup', t); bgneal@45: }, bgneal@45: bgneal@45: render : function(nst) { bgneal@45: var t = this, s = t.settings, id = t.id, sl = tinymce.ScriptLoader; bgneal@45: bgneal@45: // Page is not loaded yet, wait for it bgneal@45: if (!Event.domLoaded) { bgneal@45: Event.add(window, 'ready', function() { bgneal@45: t.render(); bgneal@45: }); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: tinyMCE.settings = s; bgneal@45: bgneal@45: // Element not found, then skip initialization bgneal@45: if (!t.getElement()) bgneal@45: return; bgneal@45: bgneal@45: // Is a iPad/iPhone and not on iOS5, then skip initialization. We need to sniff bgneal@45: // here since the browser says it has contentEditable support but there is no visible bgneal@45: // caret We will remove this check ones Apple implements full contentEditable support bgneal@45: if (tinymce.isIDevice && !tinymce.isIOS5) bgneal@45: return; bgneal@45: bgneal@45: // Add hidden input for non input elements inside form elements bgneal@45: if (!/TEXTAREA|INPUT/i.test(t.getElement().nodeName) && s.hidden_input && DOM.getParent(id, 'form')) bgneal@45: DOM.insertAfter(DOM.create('input', {type : 'hidden', name : id}), id); bgneal@45: bgneal@45: if (tinymce.WindowManager) bgneal@45: t.windowManager = new tinymce.WindowManager(t); bgneal@45: bgneal@45: if (s.encoding == 'xml') { bgneal@45: t.onGetContent.add(function(ed, o) { bgneal@45: if (o.save) bgneal@45: o.content = DOM.encode(o.content); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (s.add_form_submit_trigger) { bgneal@45: t.onSubmit.addToTop(function() { bgneal@45: if (t.initialized) { bgneal@45: t.save(); bgneal@45: t.isNotDirty = 1; bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (s.add_unload_trigger) { bgneal@45: t._beforeUnload = tinyMCE.onBeforeUnload.add(function() { bgneal@45: if (t.initialized && !t.destroyed && !t.isHidden()) bgneal@45: t.save({format : 'raw', no_events : true}); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: tinymce.addUnload(t.destroy, t); bgneal@45: bgneal@45: if (s.submit_patch) { bgneal@45: t.onBeforeRenderUI.add(function() { bgneal@45: var n = t.getElement().form; bgneal@45: bgneal@45: if (!n) bgneal@45: return; bgneal@45: bgneal@45: // Already patched bgneal@45: if (n._mceOldSubmit) bgneal@45: return; bgneal@45: bgneal@45: // Check page uses id="submit" or name="submit" for it's submit button bgneal@45: if (!n.submit.nodeType && !n.submit.length) { bgneal@45: t.formElement = n; bgneal@45: n._mceOldSubmit = n.submit; bgneal@45: n.submit = function() { bgneal@45: // Save all instances bgneal@45: tinymce.triggerSave(); bgneal@45: t.isNotDirty = 1; bgneal@45: bgneal@45: return t.formElement._mceOldSubmit(t.formElement); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: n = null; bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // Load scripts bgneal@45: function loadScripts() { bgneal@45: if (s.language && s.language_load !== false) bgneal@45: sl.add(tinymce.baseURL + '/langs/' + s.language + '.js'); bgneal@45: bgneal@45: if (s.theme && s.theme.charAt(0) != '-' && !ThemeManager.urls[s.theme]) bgneal@45: ThemeManager.load(s.theme, 'themes/' + s.theme + '/editor_template' + tinymce.suffix + '.js'); bgneal@45: bgneal@45: each(explode(s.plugins), function(p) { bgneal@45: if (p &&!PluginManager.urls[p]) { bgneal@45: if (p.charAt(0) == '-') { bgneal@45: p = p.substr(1, p.length); bgneal@45: var dependencies = PluginManager.dependencies(p); bgneal@45: each(dependencies, function(dep) { bgneal@45: var defaultSettings = {prefix:'plugins/', resource: dep, suffix:'/editor_plugin' + tinymce.suffix + '.js'}; bgneal@45: var dep = PluginManager.createUrl(defaultSettings, dep); bgneal@45: PluginManager.load(dep.resource, dep); bgneal@45: bgneal@45: }); bgneal@45: } else { bgneal@45: // Skip safari plugin, since it is removed as of 3.3b1 bgneal@45: if (p == 'safari') { bgneal@45: return; bgneal@45: } bgneal@45: PluginManager.load(p, {prefix:'plugins/', resource: p, suffix:'/editor_plugin' + tinymce.suffix + '.js'}); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Init when que is loaded bgneal@45: sl.loadQueue(function() { bgneal@45: if (!t.removed) bgneal@45: t.init(); bgneal@45: }); bgneal@45: }; bgneal@45: bgneal@45: loadScripts(); bgneal@45: }, bgneal@45: bgneal@45: init : function() { bgneal@45: var n, t = this, s = t.settings, w, h, e = t.getElement(), o, ti, u, bi, bc, re, i, initializedPlugins = []; bgneal@45: bgneal@45: tinymce.add(t); bgneal@45: bgneal@45: s.aria_label = s.aria_label || DOM.getAttrib(e, 'aria-label', t.getLang('aria.rich_text_area')); bgneal@45: bgneal@45: if (s.theme) { bgneal@45: s.theme = s.theme.replace(/-/, ''); bgneal@45: o = ThemeManager.get(s.theme); bgneal@45: t.theme = new o(); bgneal@45: bgneal@45: if (t.theme.init && s.init_theme) bgneal@45: t.theme.init(t, ThemeManager.urls[s.theme] || tinymce.documentBaseURL.replace(/\/$/, '')); bgneal@45: } bgneal@45: function initPlugin(p) { bgneal@45: var c = PluginManager.get(p), u = PluginManager.urls[p] || tinymce.documentBaseURL.replace(/\/$/, ''), po; bgneal@45: if (c && tinymce.inArray(initializedPlugins,p) === -1) { bgneal@45: each(PluginManager.dependencies(p), function(dep){ bgneal@45: initPlugin(dep); bgneal@45: }); bgneal@45: po = new c(t, u); bgneal@45: bgneal@45: t.plugins[p] = po; bgneal@45: bgneal@45: if (po.init) { bgneal@45: po.init(t, u); bgneal@45: initializedPlugins.push(p); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Create all plugins bgneal@45: each(explode(s.plugins.replace(/\-/g, '')), initPlugin); bgneal@45: bgneal@45: // Setup popup CSS path(s) bgneal@45: if (s.popup_css !== false) { bgneal@45: if (s.popup_css) bgneal@45: s.popup_css = t.documentBaseURI.toAbsolute(s.popup_css); bgneal@45: else bgneal@45: s.popup_css = t.baseURI.toAbsolute("themes/" + s.theme + "/skins/" + s.skin + "/dialog.css"); bgneal@45: } bgneal@45: bgneal@45: if (s.popup_css_add) bgneal@45: s.popup_css += ',' + t.documentBaseURI.toAbsolute(s.popup_css_add); bgneal@45: bgneal@45: t.controlManager = new tinymce.ControlManager(t); bgneal@45: bgneal@45: if (s.custom_undo_redo) { bgneal@45: t.onBeforeExecCommand.add(function(ed, cmd, ui, val, a) { bgneal@45: if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo)) bgneal@45: t.undoManager.beforeChange(); bgneal@45: }); bgneal@45: bgneal@45: t.onExecCommand.add(function(ed, cmd, ui, val, a) { bgneal@45: if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint' && (!a || !a.skip_undo)) bgneal@45: t.undoManager.add(); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: t.onExecCommand.add(function(ed, c) { bgneal@45: // Don't refresh the select lists until caret move bgneal@45: if (!/^(FontName|FontSize)$/.test(c)) bgneal@45: t.nodeChanged(); bgneal@45: }); bgneal@45: bgneal@45: // Remove ghost selections on images and tables in Gecko bgneal@45: if (isGecko) { bgneal@45: function repaint(a, o) { bgneal@45: if (!o || !o.initial) bgneal@45: t.execCommand('mceRepaint'); bgneal@45: }; bgneal@45: bgneal@45: t.onUndo.add(repaint); bgneal@45: t.onRedo.add(repaint); bgneal@45: t.onSetContent.add(repaint); bgneal@45: } bgneal@45: bgneal@45: // Enables users to override the control factory bgneal@45: t.onBeforeRenderUI.dispatch(t, t.controlManager); bgneal@45: bgneal@45: // Measure box bgneal@45: if (s.render_ui) { bgneal@45: w = s.width || e.style.width || e.offsetWidth; bgneal@45: h = s.height || e.style.height || e.offsetHeight; bgneal@45: t.orgDisplay = e.style.display; bgneal@45: re = /^[0-9\.]+(|px)$/i; bgneal@45: bgneal@45: if (re.test('' + w)) bgneal@45: w = Math.max(parseInt(w) + (o.deltaWidth || 0), 100); bgneal@45: bgneal@45: if (re.test('' + h)) bgneal@45: h = Math.max(parseInt(h) + (o.deltaHeight || 0), 100); bgneal@45: bgneal@45: // Render UI bgneal@45: o = t.theme.renderUI({ bgneal@45: targetNode : e, bgneal@45: width : w, bgneal@45: height : h, bgneal@45: deltaWidth : s.delta_width, bgneal@45: deltaHeight : s.delta_height bgneal@45: }); bgneal@45: bgneal@45: t.editorContainer = o.editorContainer; bgneal@45: } bgneal@45: bgneal@45: bgneal@45: // User specified a document.domain value bgneal@45: if (document.domain && location.hostname != document.domain) bgneal@45: tinymce.relaxedDomain = document.domain; bgneal@45: bgneal@45: // Resize editor bgneal@45: DOM.setStyles(o.sizeContainer || o.editorContainer, { bgneal@45: width : w, bgneal@45: height : h bgneal@45: }); bgneal@45: bgneal@45: // Load specified content CSS last bgneal@45: if (s.content_css) { bgneal@45: tinymce.each(explode(s.content_css), function(u) { bgneal@45: t.contentCSS.push(t.documentBaseURI.toAbsolute(u)); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : ''); bgneal@45: if (h < 100) bgneal@45: h = 100; bgneal@45: bgneal@45: t.iframeHTML = s.doctype + ''; bgneal@45: bgneal@45: // We only need to override paths if we have to bgneal@45: // IE has a bug where it remove site absolute urls to relative ones if this is specified bgneal@45: if (s.document_base_url != tinymce.documentBaseURL) bgneal@45: t.iframeHTML += ''; bgneal@45: bgneal@45: // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode. bgneal@45: if (s.ie7_compat) bgneal@45: t.iframeHTML += ''; bgneal@45: else bgneal@45: t.iframeHTML += ''; bgneal@45: bgneal@45: t.iframeHTML += ''; bgneal@45: bgneal@45: // Load the CSS by injecting them into the HTML this will reduce "flicker" bgneal@45: for (i = 0; i < t.contentCSS.length; i++) { bgneal@45: t.iframeHTML += ''; bgneal@45: } bgneal@45: bgneal@45: t.contentCSS = []; bgneal@45: bgneal@45: bi = s.body_id || 'tinymce'; bgneal@45: if (bi.indexOf('=') != -1) { bgneal@45: bi = t.getParam('body_id', '', 'hash'); bgneal@45: bi = bi[t.id] || bi; bgneal@45: } bgneal@45: bgneal@45: bc = s.body_class || ''; bgneal@45: if (bc.indexOf('=') != -1) { bgneal@45: bc = t.getParam('body_class', '', 'hash'); bgneal@45: bc = bc[t.id] || ''; bgneal@45: } bgneal@45: bgneal@45: t.iframeHTML += '
    '; bgneal@45: bgneal@45: // Domain relaxing enabled, then set document domain bgneal@45: if (tinymce.relaxedDomain && (isIE || (tinymce.isOpera && parseFloat(opera.version()) < 11))) { bgneal@45: // We need to write the contents here in IE since multiple writes messes up refresh button and back button bgneal@45: 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@45: } bgneal@45: bgneal@45: // Create iframe bgneal@45: // TODO: ACC add the appropriate description on this. bgneal@45: n = DOM.add(o.iframeContainer, 'iframe', { bgneal@45: id : t.id + "_ifr", bgneal@45: src : u || 'javascript:""', // Workaround for HTTPS warning in IE6/7 bgneal@45: frameBorder : '0', bgneal@45: allowTransparency : "true", bgneal@45: title : s.aria_label, bgneal@45: style : { bgneal@45: width : '100%', bgneal@45: height : h, bgneal@45: display : 'block' // Important for Gecko to render the iframe correctly bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: t.contentAreaContainer = o.iframeContainer; bgneal@45: DOM.get(o.editorContainer).style.display = t.orgDisplay; bgneal@45: DOM.get(t.id).style.display = 'none'; bgneal@45: DOM.setAttrib(t.id, 'aria-hidden', true); bgneal@45: bgneal@45: if (!tinymce.relaxedDomain || !u) bgneal@45: t.setupIframe(); bgneal@45: bgneal@45: e = n = o = null; // Cleanup bgneal@45: }, bgneal@45: bgneal@45: setupIframe : function() { bgneal@45: var t = this, s = t.settings, e = DOM.get(t.id), d = t.getDoc(), h, b; bgneal@45: bgneal@45: // Setup iframe body bgneal@45: if (!isIE || !tinymce.relaxedDomain) { bgneal@45: d.open(); bgneal@45: d.write(t.iframeHTML); bgneal@45: d.close(); bgneal@45: bgneal@45: if (tinymce.relaxedDomain) bgneal@45: d.domain = tinymce.relaxedDomain; bgneal@45: } bgneal@45: bgneal@45: // It will not steal focus while setting contentEditable bgneal@45: b = t.getBody(); bgneal@45: b.disabled = true; bgneal@45: bgneal@45: if (!s.readonly) bgneal@45: b.contentEditable = true; bgneal@45: bgneal@45: b.disabled = false; bgneal@45: bgneal@45: t.schema = new tinymce.html.Schema(s); bgneal@45: bgneal@45: t.dom = new tinymce.dom.DOMUtils(t.getDoc(), { bgneal@45: keep_values : true, bgneal@45: url_converter : t.convertURL, bgneal@45: url_converter_scope : t, bgneal@45: hex_colors : s.force_hex_style_colors, bgneal@45: class_filter : s.class_filter, bgneal@45: update_styles : 1, bgneal@45: fix_ie_paragraphs : 1, bgneal@45: schema : t.schema bgneal@45: }); bgneal@45: bgneal@45: t.parser = new tinymce.html.DomParser(s, t.schema); bgneal@45: bgneal@45: // Force anchor names closed, unless the setting "allow_html_in_named_anchor" is explicitly included. bgneal@45: if (!t.settings.allow_html_in_named_anchor) { bgneal@45: t.parser.addAttributeFilter('name', function(nodes, name) { bgneal@45: var i = nodes.length, sibling, prevSibling, parent, node; bgneal@45: bgneal@45: while (i--) { bgneal@45: node = nodes[i]; bgneal@45: if (node.name === 'a' && node.firstChild) { bgneal@45: parent = node.parent; bgneal@45: bgneal@45: // Move children after current node bgneal@45: sibling = node.lastChild; bgneal@45: do { bgneal@45: prevSibling = sibling.prev; bgneal@45: parent.insert(sibling, node); bgneal@45: sibling = prevSibling; bgneal@45: } while (sibling); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // Convert src and href into data-mce-src, data-mce-href and data-mce-style bgneal@45: t.parser.addAttributeFilter('src,href,style', function(nodes, name) { bgneal@45: var i = nodes.length, node, dom = t.dom, value, internalName; bgneal@45: bgneal@45: while (i--) { bgneal@45: node = nodes[i]; bgneal@45: value = node.attr(name); bgneal@45: internalName = 'data-mce-' + name; bgneal@45: bgneal@45: // Add internal attribute if we need to we don't on a refresh of the document bgneal@45: if (!node.attributes.map[internalName]) { bgneal@45: if (name === "style") bgneal@45: node.attr(internalName, dom.serializeStyle(dom.parseStyle(value), node.name)); bgneal@45: else bgneal@45: node.attr(internalName, t.convertURL(value, name, node.name)); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Keep scripts from executing bgneal@45: t.parser.addNodeFilter('script', function(nodes, name) { bgneal@45: var i = nodes.length, node; bgneal@45: bgneal@45: while (i--) { bgneal@45: node = nodes[i]; bgneal@45: node.attr('type', 'mce-' + (node.attr('type') || 'text/javascript')); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: t.parser.addNodeFilter('#cdata', function(nodes, name) { bgneal@45: var i = nodes.length, node; bgneal@45: bgneal@45: while (i--) { bgneal@45: node = nodes[i]; bgneal@45: node.type = 8; bgneal@45: node.name = '#comment'; bgneal@45: node.value = '[CDATA[' + node.value + ']]'; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: t.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes, name) { bgneal@45: var i = nodes.length, node, nonEmptyElements = t.schema.getNonEmptyElements(); bgneal@45: bgneal@45: while (i--) { bgneal@45: node = nodes[i]; bgneal@45: bgneal@45: if (node.isEmpty(nonEmptyElements)) bgneal@45: node.empty().append(new tinymce.html.Node('br', 1)).shortEnded = true; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: t.serializer = new tinymce.dom.Serializer(s, t.dom, t.schema); bgneal@45: bgneal@45: t.selection = new tinymce.dom.Selection(t.dom, t.getWin(), t.serializer); bgneal@45: bgneal@45: t.formatter = new tinymce.Formatter(this); bgneal@45: bgneal@45: // Register default formats bgneal@45: t.formatter.register({ bgneal@45: alignleft : [ bgneal@45: {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'left'}}, bgneal@45: {selector : 'img,table', collapsed : false, styles : {'float' : 'left'}} bgneal@45: ], bgneal@45: bgneal@45: aligncenter : [ bgneal@45: {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'center'}}, bgneal@45: {selector : 'img', collapsed : false, styles : {display : 'block', marginLeft : 'auto', marginRight : 'auto'}}, bgneal@45: {selector : 'table', collapsed : false, styles : {marginLeft : 'auto', marginRight : 'auto'}} bgneal@45: ], bgneal@45: bgneal@45: alignright : [ bgneal@45: {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'right'}}, bgneal@45: {selector : 'img,table', collapsed : false, styles : {'float' : 'right'}} bgneal@45: ], bgneal@45: bgneal@45: alignfull : [ bgneal@45: {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles : {textAlign : 'justify'}} bgneal@45: ], bgneal@45: bgneal@45: bold : [ bgneal@45: {inline : 'strong', remove : 'all'}, bgneal@45: {inline : 'span', styles : {fontWeight : 'bold'}}, bgneal@45: {inline : 'b', remove : 'all'} bgneal@45: ], bgneal@45: bgneal@45: italic : [ bgneal@45: {inline : 'em', remove : 'all'}, bgneal@45: {inline : 'span', styles : {fontStyle : 'italic'}}, bgneal@45: {inline : 'i', remove : 'all'} bgneal@45: ], bgneal@45: bgneal@45: underline : [ bgneal@45: {inline : 'span', styles : {textDecoration : 'underline'}, exact : true}, bgneal@45: {inline : 'u', remove : 'all'} bgneal@45: ], bgneal@45: bgneal@45: strikethrough : [ bgneal@45: {inline : 'span', styles : {textDecoration : 'line-through'}, exact : true}, bgneal@45: {inline : 'strike', remove : 'all'} bgneal@45: ], bgneal@45: bgneal@45: forecolor : {inline : 'span', styles : {color : '%value'}, wrap_links : false}, bgneal@45: hilitecolor : {inline : 'span', styles : {backgroundColor : '%value'}, wrap_links : false}, bgneal@45: fontname : {inline : 'span', styles : {fontFamily : '%value'}}, bgneal@45: fontsize : {inline : 'span', styles : {fontSize : '%value'}}, bgneal@45: fontsize_class : {inline : 'span', attributes : {'class' : '%value'}}, bgneal@45: blockquote : {block : 'blockquote', wrapper : 1, remove : 'all'}, bgneal@45: subscript : {inline : 'sub'}, bgneal@45: superscript : {inline : 'sup'}, bgneal@45: bgneal@45: link : {inline : 'a', selector : 'a', remove : 'all', split : true, deep : true, bgneal@45: onmatch : function(node) { bgneal@45: return true; bgneal@45: }, bgneal@45: bgneal@45: onformat : function(elm, fmt, vars) { bgneal@45: each(vars, function(value, key) { bgneal@45: t.dom.setAttrib(elm, key, value); bgneal@45: }); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: removeformat : [ bgneal@45: {selector : 'b,strong,em,i,font,u,strike', remove : 'all', split : true, expand : false, block_expand : true, deep : true}, bgneal@45: {selector : 'span', attributes : ['style', 'class'], remove : 'empty', split : true, expand : false, deep : true}, bgneal@45: {selector : '*', attributes : ['style', 'class'], split : false, expand : false, deep : true} bgneal@45: ] bgneal@45: }); bgneal@45: bgneal@45: // Register default block formats bgneal@45: each('p h1 h2 h3 h4 h5 h6 div address pre div code dt dd samp'.split(/\s/), function(name) { bgneal@45: t.formatter.register(name, {block : name, remove : 'all'}); bgneal@45: }); bgneal@45: bgneal@45: // Register user defined formats bgneal@45: t.formatter.register(t.settings.formats); bgneal@45: bgneal@45: t.undoManager = new tinymce.UndoManager(t); bgneal@45: bgneal@45: // Pass through bgneal@45: t.undoManager.onAdd.add(function(um, l) { bgneal@45: if (um.hasUndo()) bgneal@45: return t.onChange.dispatch(t, l, um); bgneal@45: }); bgneal@45: bgneal@45: t.undoManager.onUndo.add(function(um, l) { bgneal@45: return t.onUndo.dispatch(t, l, um); bgneal@45: }); bgneal@45: bgneal@45: t.undoManager.onRedo.add(function(um, l) { bgneal@45: return t.onRedo.dispatch(t, l, um); bgneal@45: }); bgneal@45: bgneal@45: t.forceBlocks = new tinymce.ForceBlocks(t, { bgneal@45: forced_root_block : s.forced_root_block bgneal@45: }); bgneal@45: bgneal@45: t.editorCommands = new tinymce.EditorCommands(t); bgneal@45: bgneal@45: // Pass through bgneal@45: t.serializer.onPreProcess.add(function(se, o) { bgneal@45: return t.onPreProcess.dispatch(t, o, se); bgneal@45: }); bgneal@45: bgneal@45: t.serializer.onPostProcess.add(function(se, o) { bgneal@45: return t.onPostProcess.dispatch(t, o, se); bgneal@45: }); bgneal@45: bgneal@45: t.onPreInit.dispatch(t); bgneal@45: bgneal@45: if (!s.gecko_spellcheck) bgneal@45: t.getBody().spellcheck = 0; bgneal@45: bgneal@45: if (!s.readonly) bgneal@45: t._addEvents(); bgneal@45: bgneal@45: t.controlManager.onPostRender.dispatch(t, t.controlManager); bgneal@45: t.onPostRender.dispatch(t); bgneal@45: bgneal@45: t.quirks = new tinymce.util.Quirks(this); bgneal@45: bgneal@45: if (s.directionality) bgneal@45: t.getBody().dir = s.directionality; bgneal@45: bgneal@45: if (s.nowrap) bgneal@45: t.getBody().style.whiteSpace = "nowrap"; bgneal@45: bgneal@45: if (s.handle_node_change_callback) { bgneal@45: t.onNodeChange.add(function(ed, cm, n) { bgneal@45: t.execCallback('handle_node_change_callback', t.id, n, -1, -1, true, t.selection.isCollapsed()); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (s.save_callback) { bgneal@45: t.onSaveContent.add(function(ed, o) { bgneal@45: var h = t.execCallback('save_callback', t.id, o.content, t.getBody()); bgneal@45: bgneal@45: if (h) bgneal@45: o.content = h; bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (s.onchange_callback) { bgneal@45: t.onChange.add(function(ed, l) { bgneal@45: t.execCallback('onchange_callback', t, l); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (s.protect) { bgneal@45: t.onBeforeSetContent.add(function(ed, o) { bgneal@45: if (s.protect) { bgneal@45: each(s.protect, function(pattern) { bgneal@45: o.content = o.content.replace(pattern, function(str) { bgneal@45: return ''; bgneal@45: }); bgneal@45: }); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (s.convert_newlines_to_brs) { bgneal@45: t.onBeforeSetContent.add(function(ed, o) { bgneal@45: if (o.initial) bgneal@45: o.content = o.content.replace(/\r?\n/g, '
    '); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (s.preformatted) { bgneal@45: t.onPostProcess.add(function(ed, o) { bgneal@45: o.content = o.content.replace(/^\s*/, ''); bgneal@45: o.content = o.content.replace(/<\/pre>\s*$/, ''); bgneal@45: bgneal@45: if (o.set) bgneal@45: o.content = '
    ' + o.content + '
    '; bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (s.verify_css_classes) { bgneal@45: t.serializer.attribValueFilter = function(n, v) { bgneal@45: var s, cl; bgneal@45: bgneal@45: if (n == 'class') { bgneal@45: // Build regexp for classes bgneal@45: if (!t.classesRE) { bgneal@45: cl = t.dom.getClasses(); bgneal@45: bgneal@45: if (cl.length > 0) { bgneal@45: s = ''; bgneal@45: bgneal@45: each (cl, function(o) { bgneal@45: s += (s ? '|' : '') + o['class']; bgneal@45: }); bgneal@45: bgneal@45: t.classesRE = new RegExp('(' + s + ')', 'gi'); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return !t.classesRE || /(\bmceItem\w+\b|\bmceTemp\w+\b)/g.test(v) || t.classesRE.test(v) ? v : ''; bgneal@45: } bgneal@45: bgneal@45: return v; bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: if (s.cleanup_callback) { bgneal@45: t.onBeforeSetContent.add(function(ed, o) { bgneal@45: o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o); bgneal@45: }); bgneal@45: bgneal@45: t.onPreProcess.add(function(ed, o) { bgneal@45: if (o.set) bgneal@45: t.execCallback('cleanup_callback', 'insert_to_editor_dom', o.node, o); bgneal@45: bgneal@45: if (o.get) bgneal@45: t.execCallback('cleanup_callback', 'get_from_editor_dom', o.node, o); bgneal@45: }); bgneal@45: bgneal@45: t.onPostProcess.add(function(ed, o) { bgneal@45: if (o.set) bgneal@45: o.content = t.execCallback('cleanup_callback', 'insert_to_editor', o.content, o); bgneal@45: bgneal@45: if (o.get) bgneal@45: o.content = t.execCallback('cleanup_callback', 'get_from_editor', o.content, o); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (s.save_callback) { bgneal@45: t.onGetContent.add(function(ed, o) { bgneal@45: if (o.save) bgneal@45: o.content = t.execCallback('save_callback', t.id, o.content, t.getBody()); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (s.handle_event_callback) { bgneal@45: t.onEvent.add(function(ed, e, o) { bgneal@45: if (t.execCallback('handle_event_callback', e, ed, o) === false) bgneal@45: Event.cancel(e); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // Add visual aids when new contents is added bgneal@45: t.onSetContent.add(function() { bgneal@45: t.addVisual(t.getBody()); bgneal@45: }); bgneal@45: bgneal@45: // Remove empty contents bgneal@45: if (s.padd_empty_editor) { bgneal@45: t.onPostProcess.add(function(ed, o) { bgneal@45: o.content = o.content.replace(/^(]*>( | |\s|\u00a0|)<\/p>[\r\n]*|
    [\r\n]*)$/, ''); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (isGecko) { bgneal@45: // Fix gecko link bug, when a link is placed at the end of block elements there is bgneal@45: // no way to move the caret behind the link. This fix adds a bogus br element after the link bgneal@45: function fixLinks(ed, o) { bgneal@45: each(ed.dom.select('a'), function(n) { bgneal@45: var pn = n.parentNode; bgneal@45: bgneal@45: if (ed.dom.isBlock(pn) && pn.lastChild === n) bgneal@45: ed.dom.add(pn, 'br', {'data-mce-bogus' : 1}); bgneal@45: }); bgneal@45: }; bgneal@45: bgneal@45: t.onExecCommand.add(function(ed, cmd) { bgneal@45: if (cmd === 'CreateLink') bgneal@45: fixLinks(ed); bgneal@45: }); bgneal@45: bgneal@45: t.onSetContent.add(t.selection.onSetContent.add(fixLinks)); bgneal@45: } bgneal@45: bgneal@45: t.load({initial : true, format : 'html'}); bgneal@45: t.startContent = t.getContent({format : 'raw'}); bgneal@45: t.undoManager.add(); bgneal@45: t.initialized = true; bgneal@45: bgneal@45: t.onInit.dispatch(t); bgneal@45: t.execCallback('setupcontent_callback', t.id, t.getBody(), t.getDoc()); bgneal@45: t.execCallback('init_instance_callback', t); bgneal@45: t.focus(true); bgneal@45: t.nodeChanged({initial : 1}); bgneal@45: bgneal@45: // Load specified content CSS last bgneal@45: each(t.contentCSS, function(u) { bgneal@45: t.dom.loadCSS(u); bgneal@45: }); bgneal@45: bgneal@45: // Handle auto focus bgneal@45: if (s.auto_focus) { bgneal@45: setTimeout(function () { bgneal@45: var ed = tinymce.get(s.auto_focus); bgneal@45: bgneal@45: ed.selection.select(ed.getBody(), 1); bgneal@45: ed.selection.collapse(1); bgneal@45: ed.getBody().focus(); bgneal@45: ed.getWin().focus(); bgneal@45: }, 100); bgneal@45: } bgneal@45: bgneal@45: e = null; bgneal@45: }, bgneal@45: bgneal@45: bgneal@45: focus : function(sf) { bgneal@45: var oed, t = this, selection = t.selection, ce = t.settings.content_editable, ieRng, controlElm, doc = t.getDoc(); bgneal@45: bgneal@45: if (!sf) { bgneal@45: // Get selected control element bgneal@45: ieRng = selection.getRng(); bgneal@45: if (ieRng.item) { bgneal@45: controlElm = ieRng.item(0); bgneal@45: } bgneal@45: bgneal@45: t._refreshContentEditable(); bgneal@45: bgneal@45: // Is not content editable bgneal@45: if (!ce) bgneal@45: t.getWin().focus(); bgneal@45: bgneal@45: // Focus the body as well since it's contentEditable bgneal@45: if (tinymce.isGecko) { bgneal@45: t.getBody().focus(); bgneal@45: } bgneal@45: bgneal@45: // Restore selected control element bgneal@45: // This is needed when for example an image is selected within a bgneal@45: // layer a call to focus will then remove the control selection bgneal@45: if (controlElm && controlElm.ownerDocument == doc) { bgneal@45: ieRng = doc.body.createControlRange(); bgneal@45: ieRng.addElement(controlElm); bgneal@45: ieRng.select(); bgneal@45: } bgneal@45: bgneal@45: } bgneal@45: bgneal@45: if (tinymce.activeEditor != t) { bgneal@45: if ((oed = tinymce.activeEditor) != null) bgneal@45: oed.onDeactivate.dispatch(oed, t); bgneal@45: bgneal@45: t.onActivate.dispatch(t, oed); bgneal@45: } bgneal@45: bgneal@45: tinymce._setActive(t); bgneal@45: }, bgneal@45: bgneal@45: execCallback : function(n) { bgneal@45: var t = this, f = t.settings[n], s; bgneal@45: bgneal@45: if (!f) bgneal@45: return; bgneal@45: bgneal@45: // Look through lookup bgneal@45: if (t.callbackLookup && (s = t.callbackLookup[n])) { bgneal@45: f = s.func; bgneal@45: s = s.scope; bgneal@45: } bgneal@45: bgneal@45: if (is(f, 'string')) { bgneal@45: s = f.replace(/\.\w+$/, ''); bgneal@45: s = s ? tinymce.resolve(s) : 0; bgneal@45: f = tinymce.resolve(f); bgneal@45: t.callbackLookup = t.callbackLookup || {}; bgneal@45: t.callbackLookup[n] = {func : f, scope : s}; bgneal@45: } bgneal@45: bgneal@45: return f.apply(s || t, Array.prototype.slice.call(arguments, 1)); bgneal@45: }, bgneal@45: bgneal@45: translate : function(s) { bgneal@45: var c = this.settings.language || 'en', i18n = tinymce.i18n; bgneal@45: bgneal@45: if (!s) bgneal@45: return ''; bgneal@45: bgneal@45: return i18n[c + '.' + s] || s.replace(/{\#([^}]+)\}/g, function(a, b) { bgneal@45: return i18n[c + '.' + b] || '{#' + b + '}'; bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: getLang : function(n, dv) { bgneal@45: return tinymce.i18n[(this.settings.language || 'en') + '.' + n] || (is(dv) ? dv : '{#' + n + '}'); bgneal@45: }, bgneal@45: bgneal@45: getParam : function(n, dv, ty) { bgneal@45: var tr = tinymce.trim, v = is(this.settings[n]) ? this.settings[n] : dv, o; bgneal@45: bgneal@45: if (ty === 'hash') { bgneal@45: o = {}; bgneal@45: bgneal@45: if (is(v, 'string')) { bgneal@45: each(v.indexOf('=') > 0 ? v.split(/[;,](?![^=;,]*(?:[;,]|$))/) : v.split(','), function(v) { bgneal@45: v = v.split('='); bgneal@45: bgneal@45: if (v.length > 1) bgneal@45: o[tr(v[0])] = tr(v[1]); bgneal@45: else bgneal@45: o[tr(v[0])] = tr(v); bgneal@45: }); bgneal@45: } else bgneal@45: o = v; bgneal@45: bgneal@45: return o; bgneal@45: } bgneal@45: bgneal@45: return v; bgneal@45: }, bgneal@45: bgneal@45: nodeChanged : function(o) { bgneal@45: var t = this, s = t.selection, n = s.getStart() || t.getBody(); bgneal@45: bgneal@45: // Fix for bug #1896577 it seems that this can not be fired while the editor is loading bgneal@45: if (t.initialized) { bgneal@45: o = o || {}; bgneal@45: n = isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n; // Fix for IE initial state bgneal@45: bgneal@45: // Get parents and add them to object bgneal@45: o.parents = []; bgneal@45: t.dom.getParent(n, function(node) { bgneal@45: if (node.nodeName == 'BODY') bgneal@45: return true; bgneal@45: bgneal@45: o.parents.push(node); bgneal@45: }); bgneal@45: bgneal@45: t.onNodeChange.dispatch( bgneal@45: t, bgneal@45: o ? o.controlManager || t.controlManager : t.controlManager, bgneal@45: n, bgneal@45: s.isCollapsed(), bgneal@45: o bgneal@45: ); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: addButton : function(n, s) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.buttons = t.buttons || {}; bgneal@45: t.buttons[n] = s; bgneal@45: }, bgneal@45: bgneal@45: addCommand : function(name, callback, scope) { bgneal@45: this.execCommands[name] = {func : callback, scope : scope || this}; bgneal@45: }, bgneal@45: bgneal@45: addQueryStateHandler : function(name, callback, scope) { bgneal@45: this.queryStateCommands[name] = {func : callback, scope : scope || this}; bgneal@45: }, bgneal@45: bgneal@45: addQueryValueHandler : function(name, callback, scope) { bgneal@45: this.queryValueCommands[name] = {func : callback, scope : scope || this}; bgneal@45: }, bgneal@45: bgneal@45: addShortcut : function(pa, desc, cmd_func, sc) { bgneal@45: var t = this, c; bgneal@45: bgneal@45: if (!t.settings.custom_shortcuts) bgneal@45: return false; bgneal@45: bgneal@45: t.shortcuts = t.shortcuts || {}; bgneal@45: bgneal@45: if (is(cmd_func, 'string')) { bgneal@45: c = cmd_func; bgneal@45: bgneal@45: cmd_func = function() { bgneal@45: t.execCommand(c, false, null); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: if (is(cmd_func, 'object')) { bgneal@45: c = cmd_func; bgneal@45: bgneal@45: cmd_func = function() { bgneal@45: t.execCommand(c[0], c[1], c[2]); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: each(explode(pa), function(pa) { bgneal@45: var o = { bgneal@45: func : cmd_func, bgneal@45: scope : sc || this, bgneal@45: desc : desc, bgneal@45: alt : false, bgneal@45: ctrl : false, bgneal@45: shift : false bgneal@45: }; bgneal@45: bgneal@45: each(explode(pa, '+'), function(v) { bgneal@45: switch (v) { bgneal@45: case 'alt': bgneal@45: case 'ctrl': bgneal@45: case 'shift': bgneal@45: o[v] = true; bgneal@45: break; bgneal@45: bgneal@45: default: bgneal@45: o.charCode = v.charCodeAt(0); bgneal@45: o.keyCode = v.toUpperCase().charCodeAt(0); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: t.shortcuts[(o.ctrl ? 'ctrl' : '') + ',' + (o.alt ? 'alt' : '') + ',' + (o.shift ? 'shift' : '') + ',' + o.keyCode] = o; bgneal@45: }); bgneal@45: bgneal@45: return true; bgneal@45: }, bgneal@45: bgneal@45: execCommand : function(cmd, ui, val, a) { bgneal@45: var t = this, s = 0, o, st; bgneal@45: bgneal@45: if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint|SelectAll)$/.test(cmd) && (!a || !a.skip_focus)) bgneal@45: t.focus(); bgneal@45: bgneal@45: a = extend({}, a); bgneal@45: t.onBeforeExecCommand.dispatch(t, cmd, ui, val, a); bgneal@45: if (a.terminate) bgneal@45: return false; bgneal@45: bgneal@45: // Command callback bgneal@45: if (t.execCallback('execcommand_callback', t.id, t.selection.getNode(), cmd, ui, val)) { bgneal@45: t.onExecCommand.dispatch(t, cmd, ui, val, a); bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: // Registred commands bgneal@45: if (o = t.execCommands[cmd]) { bgneal@45: st = o.func.call(o.scope, ui, val); bgneal@45: bgneal@45: // Fall through on true bgneal@45: if (st !== true) { bgneal@45: t.onExecCommand.dispatch(t, cmd, ui, val, a); bgneal@45: return st; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Plugin commands bgneal@45: each(t.plugins, function(p) { bgneal@45: if (p.execCommand && p.execCommand(cmd, ui, val)) { bgneal@45: t.onExecCommand.dispatch(t, cmd, ui, val, a); bgneal@45: s = 1; bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: if (s) bgneal@45: return true; bgneal@45: bgneal@45: // Theme commands bgneal@45: if (t.theme && t.theme.execCommand && t.theme.execCommand(cmd, ui, val)) { bgneal@45: t.onExecCommand.dispatch(t, cmd, ui, val, a); bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: // Editor commands bgneal@45: if (t.editorCommands.execCommand(cmd, ui, val)) { bgneal@45: t.onExecCommand.dispatch(t, cmd, ui, val, a); bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: // Browser commands bgneal@45: t.getDoc().execCommand(cmd, ui, val); bgneal@45: t.onExecCommand.dispatch(t, cmd, ui, val, a); bgneal@45: }, bgneal@45: bgneal@45: queryCommandState : function(cmd) { bgneal@45: var t = this, o, s; bgneal@45: bgneal@45: // Is hidden then return undefined bgneal@45: if (t._isHidden()) bgneal@45: return; bgneal@45: bgneal@45: // Registred commands bgneal@45: if (o = t.queryStateCommands[cmd]) { bgneal@45: s = o.func.call(o.scope); bgneal@45: bgneal@45: // Fall though on true bgneal@45: if (s !== true) bgneal@45: return s; bgneal@45: } bgneal@45: bgneal@45: // Registred commands bgneal@45: o = t.editorCommands.queryCommandState(cmd); bgneal@45: if (o !== -1) bgneal@45: return o; bgneal@45: bgneal@45: // Browser commands bgneal@45: try { bgneal@45: return this.getDoc().queryCommandState(cmd); bgneal@45: } catch (ex) { bgneal@45: // Fails sometimes see bug: 1896577 bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: queryCommandValue : function(c) { bgneal@45: var t = this, o, s; bgneal@45: bgneal@45: // Is hidden then return undefined bgneal@45: if (t._isHidden()) bgneal@45: return; bgneal@45: bgneal@45: // Registred commands bgneal@45: if (o = t.queryValueCommands[c]) { bgneal@45: s = o.func.call(o.scope); bgneal@45: bgneal@45: // Fall though on true bgneal@45: if (s !== true) bgneal@45: return s; bgneal@45: } bgneal@45: bgneal@45: // Registred commands bgneal@45: o = t.editorCommands.queryCommandValue(c); bgneal@45: if (is(o)) bgneal@45: return o; bgneal@45: bgneal@45: // Browser commands bgneal@45: try { bgneal@45: return this.getDoc().queryCommandValue(c); bgneal@45: } catch (ex) { bgneal@45: // Fails sometimes see bug: 1896577 bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: show : function() { bgneal@45: var t = this; bgneal@45: bgneal@45: DOM.show(t.getContainer()); bgneal@45: DOM.hide(t.id); bgneal@45: t.load(); bgneal@45: }, bgneal@45: bgneal@45: hide : function() { bgneal@45: var t = this, d = t.getDoc(); bgneal@45: bgneal@45: // Fixed bug where IE has a blinking cursor left from the editor bgneal@45: if (isIE && d) bgneal@45: d.execCommand('SelectAll'); bgneal@45: bgneal@45: // We must save before we hide so Safari doesn't crash bgneal@45: t.save(); bgneal@45: DOM.hide(t.getContainer()); bgneal@45: DOM.setStyle(t.id, 'display', t.orgDisplay); bgneal@45: }, bgneal@45: bgneal@45: isHidden : function() { bgneal@45: return !DOM.isHidden(this.id); bgneal@45: }, bgneal@45: bgneal@45: setProgressState : function(b, ti, o) { bgneal@45: this.onSetProgressState.dispatch(this, b, ti, o); bgneal@45: bgneal@45: return b; bgneal@45: }, bgneal@45: bgneal@45: load : function(o) { bgneal@45: var t = this, e = t.getElement(), h; bgneal@45: bgneal@45: if (e) { bgneal@45: o = o || {}; bgneal@45: o.load = true; bgneal@45: bgneal@45: // Double encode existing entities in the value bgneal@45: h = t.setContent(is(e.value) ? e.value : e.innerHTML, o); bgneal@45: o.element = e; bgneal@45: bgneal@45: if (!o.no_events) bgneal@45: t.onLoadContent.dispatch(t, o); bgneal@45: bgneal@45: o.element = e = null; bgneal@45: bgneal@45: return h; bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: save : function(o) { bgneal@45: var t = this, e = t.getElement(), h, f; bgneal@45: bgneal@45: if (!e || !t.initialized) bgneal@45: return; bgneal@45: bgneal@45: o = o || {}; bgneal@45: o.save = true; bgneal@45: bgneal@45: // Add undo level will trigger onchange event bgneal@45: if (!o.no_events) { bgneal@45: t.undoManager.typing = false; bgneal@45: t.undoManager.add(); bgneal@45: } bgneal@45: bgneal@45: o.element = e; bgneal@45: h = o.content = t.getContent(o); bgneal@45: bgneal@45: if (!o.no_events) bgneal@45: t.onSaveContent.dispatch(t, o); bgneal@45: bgneal@45: h = o.content; bgneal@45: bgneal@45: if (!/TEXTAREA|INPUT/i.test(e.nodeName)) { bgneal@45: e.innerHTML = h; bgneal@45: bgneal@45: // Update hidden form element bgneal@45: if (f = DOM.getParent(t.id, 'form')) { bgneal@45: each(f.elements, function(e) { bgneal@45: if (e.name == t.id) { bgneal@45: e.value = h; bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: } else bgneal@45: e.value = h; bgneal@45: bgneal@45: o.element = e = null; bgneal@45: bgneal@45: return h; bgneal@45: }, bgneal@45: bgneal@45: setContent : function(content, args) { bgneal@45: var self = this, rootNode, body = self.getBody(), forcedRootBlockName; bgneal@45: bgneal@45: // Setup args object bgneal@45: args = args || {}; bgneal@45: args.format = args.format || 'html'; bgneal@45: args.set = true; bgneal@45: args.content = content; bgneal@45: bgneal@45: // Do preprocessing bgneal@45: if (!args.no_events) bgneal@45: self.onBeforeSetContent.dispatch(self, args); bgneal@45: bgneal@45: content = args.content; bgneal@45: bgneal@45: // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content bgneal@45: // It will also be impossible to place the caret in the editor unless there is a BR element present bgneal@45: if (!tinymce.isIE && (content.length === 0 || /^\s+$/.test(content))) { bgneal@45: forcedRootBlockName = self.settings.forced_root_block; bgneal@45: if (forcedRootBlockName) bgneal@45: content = '<' + forcedRootBlockName + '>
    '; bgneal@45: else bgneal@45: content = '
    '; bgneal@45: bgneal@45: body.innerHTML = content; bgneal@45: self.selection.select(body, true); bgneal@45: self.selection.collapse(true); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Parse and serialize the html bgneal@45: if (args.format !== 'raw') { bgneal@45: content = new tinymce.html.Serializer({}, self.schema).serialize( bgneal@45: self.parser.parse(content) bgneal@45: ); bgneal@45: } bgneal@45: bgneal@45: // Set the new cleaned contents to the editor bgneal@45: args.content = tinymce.trim(content); bgneal@45: self.dom.setHTML(body, args.content); bgneal@45: bgneal@45: // Do post processing bgneal@45: if (!args.no_events) bgneal@45: self.onSetContent.dispatch(self, args); bgneal@45: bgneal@45: self.selection.normalize(); bgneal@45: bgneal@45: return args.content; bgneal@45: }, bgneal@45: bgneal@45: getContent : function(args) { bgneal@45: var self = this, content; bgneal@45: bgneal@45: // Setup args object bgneal@45: args = args || {}; bgneal@45: args.format = args.format || 'html'; bgneal@45: args.get = true; bgneal@45: bgneal@45: // Do preprocessing bgneal@45: if (!args.no_events) bgneal@45: self.onBeforeGetContent.dispatch(self, args); bgneal@45: bgneal@45: // Get raw contents or by default the cleaned contents bgneal@45: if (args.format == 'raw') bgneal@45: content = self.getBody().innerHTML; bgneal@45: else bgneal@45: content = self.serializer.serialize(self.getBody(), args); bgneal@45: bgneal@45: args.content = tinymce.trim(content); bgneal@45: bgneal@45: // Do post processing bgneal@45: if (!args.no_events) bgneal@45: self.onGetContent.dispatch(self, args); bgneal@45: bgneal@45: return args.content; bgneal@45: }, bgneal@45: bgneal@45: isDirty : function() { bgneal@45: var self = this; bgneal@45: bgneal@45: return tinymce.trim(self.startContent) != tinymce.trim(self.getContent({format : 'raw', no_events : 1})) && !self.isNotDirty; bgneal@45: }, bgneal@45: bgneal@45: getContainer : function() { bgneal@45: var t = this; bgneal@45: bgneal@45: if (!t.container) bgneal@45: t.container = DOM.get(t.editorContainer || t.id + '_parent'); bgneal@45: bgneal@45: return t.container; bgneal@45: }, bgneal@45: bgneal@45: getContentAreaContainer : function() { bgneal@45: return this.contentAreaContainer; bgneal@45: }, bgneal@45: bgneal@45: getElement : function() { bgneal@45: return DOM.get(this.settings.content_element || this.id); bgneal@45: }, bgneal@45: bgneal@45: getWin : function() { bgneal@45: var t = this, e; bgneal@45: bgneal@45: if (!t.contentWindow) { bgneal@45: e = DOM.get(t.id + "_ifr"); bgneal@45: bgneal@45: if (e) bgneal@45: t.contentWindow = e.contentWindow; bgneal@45: } bgneal@45: bgneal@45: return t.contentWindow; bgneal@45: }, bgneal@45: bgneal@45: getDoc : function() { bgneal@45: var t = this, w; bgneal@45: bgneal@45: if (!t.contentDocument) { bgneal@45: w = t.getWin(); bgneal@45: bgneal@45: if (w) bgneal@45: t.contentDocument = w.document; bgneal@45: } bgneal@45: bgneal@45: return t.contentDocument; bgneal@45: }, bgneal@45: bgneal@45: getBody : function() { bgneal@45: return this.bodyElement || this.getDoc().body; bgneal@45: }, bgneal@45: bgneal@45: convertURL : function(u, n, e) { bgneal@45: var t = this, s = t.settings; bgneal@45: bgneal@45: // Use callback instead bgneal@45: if (s.urlconverter_callback) bgneal@45: return t.execCallback('urlconverter_callback', u, e, true, n); bgneal@45: bgneal@45: // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs bgneal@45: if (!s.convert_urls || (e && e.nodeName == 'LINK') || u.indexOf('file:') === 0) bgneal@45: return u; bgneal@45: bgneal@45: // Convert to relative bgneal@45: if (s.relative_urls) bgneal@45: return t.documentBaseURI.toRelative(u); bgneal@45: bgneal@45: // Convert to absolute bgneal@45: u = t.documentBaseURI.toAbsolute(u, s.remove_script_host); bgneal@45: bgneal@45: return u; bgneal@45: }, bgneal@45: bgneal@45: addVisual : function(e) { bgneal@45: var t = this, s = t.settings; bgneal@45: bgneal@45: e = e || t.getBody(); bgneal@45: bgneal@45: if (!is(t.hasVisual)) bgneal@45: t.hasVisual = s.visual; bgneal@45: bgneal@45: each(t.dom.select('table,a', e), function(e) { bgneal@45: var v; bgneal@45: bgneal@45: switch (e.nodeName) { bgneal@45: case 'TABLE': bgneal@45: v = t.dom.getAttrib(e, 'border'); bgneal@45: bgneal@45: if (!v || v == '0') { bgneal@45: if (t.hasVisual) bgneal@45: t.dom.addClass(e, s.visual_table_class); bgneal@45: else bgneal@45: t.dom.removeClass(e, s.visual_table_class); bgneal@45: } bgneal@45: bgneal@45: return; bgneal@45: bgneal@45: case 'A': bgneal@45: v = t.dom.getAttrib(e, 'name'); bgneal@45: bgneal@45: if (v) { bgneal@45: if (t.hasVisual) bgneal@45: t.dom.addClass(e, 'mceItemAnchor'); bgneal@45: else bgneal@45: t.dom.removeClass(e, 'mceItemAnchor'); bgneal@45: } bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: t.onVisualAid.dispatch(t, e, t.hasVisual); bgneal@45: }, bgneal@45: bgneal@45: remove : function() { bgneal@45: var t = this, e = t.getContainer(); bgneal@45: bgneal@45: if (!t.removed) { bgneal@45: t.removed = 1; // Cancels post remove event execution bgneal@45: t.hide(); bgneal@45: bgneal@45: // Remove all events bgneal@45: bgneal@45: // Don't clear the window or document if content editable bgneal@45: // is enabled since other instances might still be present bgneal@45: if (!t.settings.content_editable) { bgneal@45: Event.clear(t.getWin()); bgneal@45: Event.clear(t.getDoc()); bgneal@45: } bgneal@45: bgneal@45: Event.clear(t.getBody()); bgneal@45: Event.clear(t.formElement); bgneal@45: Event.unbind(e); bgneal@45: bgneal@45: t.execCallback('remove_instance_callback', t); bgneal@45: t.onRemove.dispatch(t); bgneal@45: bgneal@45: // Clear all execCommand listeners this is required to avoid errors if the editor was removed inside another command bgneal@45: t.onExecCommand.listeners = []; bgneal@45: bgneal@45: tinymce.remove(t); bgneal@45: DOM.remove(e); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: destroy : function(s) { bgneal@45: var t = this; bgneal@45: bgneal@45: // One time is enough bgneal@45: if (t.destroyed) bgneal@45: return; bgneal@45: bgneal@45: // We must unbind on Gecko since it would otherwise produce the pesky "attempt to run compile-and-go script on a cleared scope" message bgneal@45: if (isGecko) { bgneal@45: Event.unbind(t.getDoc()); bgneal@45: Event.unbind(t.getWin()); bgneal@45: Event.unbind(t.getBody()); bgneal@45: } bgneal@45: bgneal@45: if (!s) { bgneal@45: tinymce.removeUnload(t.destroy); bgneal@45: tinyMCE.onBeforeUnload.remove(t._beforeUnload); bgneal@45: bgneal@45: // Manual destroy bgneal@45: if (t.theme && t.theme.destroy) bgneal@45: t.theme.destroy(); bgneal@45: bgneal@45: // Destroy controls, selection and dom bgneal@45: t.controlManager.destroy(); bgneal@45: t.selection.destroy(); bgneal@45: t.dom.destroy(); bgneal@45: } bgneal@45: bgneal@45: if (t.formElement) { bgneal@45: t.formElement.submit = t.formElement._mceOldSubmit; bgneal@45: t.formElement._mceOldSubmit = null; bgneal@45: } bgneal@45: bgneal@45: t.contentAreaContainer = t.formElement = t.container = t.settings.content_element = t.bodyElement = t.contentDocument = t.contentWindow = null; bgneal@45: bgneal@45: if (t.selection) bgneal@45: t.selection = t.selection.win = t.selection.dom = t.selection.dom.doc = null; bgneal@45: bgneal@45: t.destroyed = 1; bgneal@45: }, bgneal@45: bgneal@45: // Internal functions bgneal@45: bgneal@45: _addEvents : function() { bgneal@45: // 'focus', 'blur', 'dblclick', 'beforedeactivate', submit, reset bgneal@45: var t = this, i, s = t.settings, dom = t.dom, lo = { bgneal@45: mouseup : 'onMouseUp', bgneal@45: mousedown : 'onMouseDown', bgneal@45: click : 'onClick', bgneal@45: keyup : 'onKeyUp', bgneal@45: keydown : 'onKeyDown', bgneal@45: keypress : 'onKeyPress', bgneal@45: submit : 'onSubmit', bgneal@45: reset : 'onReset', bgneal@45: contextmenu : 'onContextMenu', bgneal@45: dblclick : 'onDblClick', bgneal@45: paste : 'onPaste' // Doesn't work in all browsers yet bgneal@45: }; bgneal@45: bgneal@45: function eventHandler(e, o) { bgneal@45: var ty = e.type; bgneal@45: bgneal@45: // Don't fire events when it's removed bgneal@45: if (t.removed) bgneal@45: return; bgneal@45: bgneal@45: // Generic event handler bgneal@45: if (t.onEvent.dispatch(t, e, o) !== false) { bgneal@45: // Specific event handler bgneal@45: t[lo[e.fakeType || e.type]].dispatch(t, e, o); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Add DOM events bgneal@45: each(lo, function(v, k) { bgneal@45: switch (k) { bgneal@45: case 'contextmenu': bgneal@45: dom.bind(t.getDoc(), k, eventHandler); bgneal@45: break; bgneal@45: bgneal@45: case 'paste': bgneal@45: dom.bind(t.getBody(), k, function(e) { bgneal@45: eventHandler(e); bgneal@45: }); bgneal@45: break; bgneal@45: bgneal@45: case 'submit': bgneal@45: case 'reset': bgneal@45: dom.bind(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler); bgneal@45: break; bgneal@45: bgneal@45: default: bgneal@45: dom.bind(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: dom.bind(s.content_editable ? t.getBody() : (isGecko ? t.getDoc() : t.getWin()), 'focus', function(e) { bgneal@45: t.focus(true); bgneal@45: }); bgneal@45: bgneal@45: bgneal@45: // Fixes bug where a specified document_base_uri could result in broken images bgneal@45: // This will also fix drag drop of images in Gecko bgneal@45: if (tinymce.isGecko) { bgneal@45: dom.bind(t.getDoc(), 'DOMNodeInserted', function(e) { bgneal@45: var v; bgneal@45: bgneal@45: e = e.target; bgneal@45: bgneal@45: if (e.nodeType === 1 && e.nodeName === 'IMG' && (v = e.getAttribute('data-mce-src'))) bgneal@45: e.src = t.documentBaseURI.toAbsolute(v); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // Set various midas options in Gecko bgneal@45: if (isGecko) { bgneal@45: function setOpts() { bgneal@45: var t = this, d = t.getDoc(), s = t.settings; bgneal@45: bgneal@45: if (isGecko && !s.readonly) { bgneal@45: t._refreshContentEditable(); bgneal@45: bgneal@45: try { bgneal@45: // Try new Gecko method bgneal@45: d.execCommand("styleWithCSS", 0, false); bgneal@45: } catch (ex) { bgneal@45: // Use old method bgneal@45: if (!t._isHidden()) bgneal@45: try {d.execCommand("useCSS", 0, true);} catch (ex) {} bgneal@45: } bgneal@45: bgneal@45: if (!s.table_inline_editing) bgneal@45: try {d.execCommand('enableInlineTableEditing', false, false);} catch (ex) {} bgneal@45: bgneal@45: if (!s.object_resizing) bgneal@45: try {d.execCommand('enableObjectResizing', false, false);} catch (ex) {} bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: t.onBeforeExecCommand.add(setOpts); bgneal@45: t.onMouseDown.add(setOpts); bgneal@45: } bgneal@45: bgneal@45: // Add node change handlers bgneal@45: t.onMouseUp.add(t.nodeChanged); bgneal@45: //t.onClick.add(t.nodeChanged); bgneal@45: t.onKeyUp.add(function(ed, e) { bgneal@45: var c = e.keyCode; bgneal@45: bgneal@45: 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@45: t.nodeChanged(); bgneal@45: }); bgneal@45: bgneal@45: bgneal@45: // Add block quote deletion handler bgneal@45: t.onKeyDown.add(function(ed, e) { bgneal@45: if (e.keyCode != VK.BACKSPACE) bgneal@45: return; bgneal@45: bgneal@45: var rng = ed.selection.getRng(); bgneal@45: if (!rng.collapsed) bgneal@45: return; bgneal@45: bgneal@45: var n = rng.startContainer; bgneal@45: var offset = rng.startOffset; bgneal@45: bgneal@45: while (n && n.nodeType && n.nodeType != 1 && n.parentNode) bgneal@45: n = n.parentNode; bgneal@45: bgneal@45: // Is the cursor at the beginning of a blockquote? bgneal@45: if (n && n.parentNode && n.parentNode.tagName === 'BLOCKQUOTE' && n.parentNode.firstChild == n && offset == 0) { bgneal@45: // Remove the blockquote bgneal@45: ed.formatter.toggle('blockquote', null, n.parentNode); bgneal@45: bgneal@45: // Move the caret to the beginning of n bgneal@45: rng.setStart(n, 0); bgneal@45: rng.setEnd(n, 0); bgneal@45: ed.selection.setRng(rng); bgneal@45: ed.selection.collapse(false); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: bgneal@45: bgneal@45: // Add reset handler bgneal@45: t.onReset.add(function() { bgneal@45: t.setContent(t.startContent, {format : 'raw'}); bgneal@45: }); bgneal@45: bgneal@45: // Add shortcuts bgneal@45: if (s.custom_shortcuts) { bgneal@45: if (s.custom_undo_redo_keyboard_shortcuts) { bgneal@45: t.addShortcut('ctrl+z', t.getLang('undo_desc'), 'Undo'); bgneal@45: t.addShortcut('ctrl+y', t.getLang('redo_desc'), 'Redo'); bgneal@45: } bgneal@45: bgneal@45: // Add default shortcuts for gecko bgneal@45: t.addShortcut('ctrl+b', t.getLang('bold_desc'), 'Bold'); bgneal@45: t.addShortcut('ctrl+i', t.getLang('italic_desc'), 'Italic'); bgneal@45: t.addShortcut('ctrl+u', t.getLang('underline_desc'), 'Underline'); bgneal@45: bgneal@45: // BlockFormat shortcuts keys bgneal@45: for (i=1; i<=6; i++) bgneal@45: t.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]); bgneal@45: bgneal@45: t.addShortcut('ctrl+7', '', ['FormatBlock', false, 'p']); bgneal@45: t.addShortcut('ctrl+8', '', ['FormatBlock', false, 'div']); bgneal@45: t.addShortcut('ctrl+9', '', ['FormatBlock', false, 'address']); bgneal@45: bgneal@45: function find(e) { bgneal@45: var v = null; bgneal@45: bgneal@45: if (!e.altKey && !e.ctrlKey && !e.metaKey) bgneal@45: return v; bgneal@45: bgneal@45: each(t.shortcuts, function(o) { bgneal@45: if (tinymce.isMac && o.ctrl != e.metaKey) bgneal@45: return; bgneal@45: else if (!tinymce.isMac && o.ctrl != e.ctrlKey) bgneal@45: return; bgneal@45: bgneal@45: if (o.alt != e.altKey) bgneal@45: return; bgneal@45: bgneal@45: if (o.shift != e.shiftKey) bgneal@45: return; bgneal@45: bgneal@45: if (e.keyCode == o.keyCode || (e.charCode && e.charCode == o.charCode)) { bgneal@45: v = o; bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: return v; bgneal@45: }; bgneal@45: bgneal@45: t.onKeyUp.add(function(ed, e) { bgneal@45: var o = find(e); bgneal@45: bgneal@45: if (o) bgneal@45: return Event.cancel(e); bgneal@45: }); bgneal@45: bgneal@45: t.onKeyPress.add(function(ed, e) { bgneal@45: var o = find(e); bgneal@45: bgneal@45: if (o) bgneal@45: return Event.cancel(e); bgneal@45: }); bgneal@45: bgneal@45: t.onKeyDown.add(function(ed, e) { bgneal@45: var o = find(e); bgneal@45: bgneal@45: if (o) { bgneal@45: o.func.call(o.scope); bgneal@45: return Event.cancel(e); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (tinymce.isIE) { bgneal@45: // Fix so resize will only update the width and height attributes not the styles of an image bgneal@45: // It will also block mceItemNoResize items bgneal@45: dom.bind(t.getDoc(), 'controlselect', function(e) { bgneal@45: var re = t.resizeInfo, cb; bgneal@45: bgneal@45: e = e.target; bgneal@45: bgneal@45: // Don't do this action for non image elements bgneal@45: if (e.nodeName !== 'IMG') bgneal@45: return; bgneal@45: bgneal@45: if (re) bgneal@45: dom.unbind(re.node, re.ev, re.cb); bgneal@45: bgneal@45: if (!dom.hasClass(e, 'mceItemNoResize')) { bgneal@45: ev = 'resizeend'; bgneal@45: cb = dom.bind(e, ev, function(e) { bgneal@45: var v; bgneal@45: bgneal@45: e = e.target; bgneal@45: bgneal@45: if (v = dom.getStyle(e, 'width')) { bgneal@45: dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, '')); bgneal@45: dom.setStyle(e, 'width', ''); bgneal@45: } bgneal@45: bgneal@45: if (v = dom.getStyle(e, 'height')) { bgneal@45: dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, '')); bgneal@45: dom.setStyle(e, 'height', ''); bgneal@45: } bgneal@45: }); bgneal@45: } else { bgneal@45: ev = 'resizestart'; bgneal@45: cb = dom.bind(e, 'resizestart', Event.cancel, Event); bgneal@45: } bgneal@45: bgneal@45: re = t.resizeInfo = { bgneal@45: node : e, bgneal@45: ev : ev, bgneal@45: cb : cb bgneal@45: }; bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (tinymce.isOpera) { bgneal@45: t.onClick.add(function(ed, e) { bgneal@45: Event.prevent(e); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // Add custom undo/redo handlers bgneal@45: if (s.custom_undo_redo) { bgneal@45: function addUndo() { bgneal@45: t.undoManager.typing = false; bgneal@45: t.undoManager.add(); bgneal@45: }; bgneal@45: bgneal@45: var focusLostFunc = tinymce.isGecko ? 'blur' : 'focusout'; bgneal@45: dom.bind(t.getDoc(), focusLostFunc, function(e){ bgneal@45: if (!t.removed && t.undoManager.typing) bgneal@45: addUndo(); bgneal@45: }); bgneal@45: bgneal@45: // Add undo level when contents is drag/dropped within the editor bgneal@45: t.dom.bind(t.dom.getRoot(), 'dragend', function(e) { bgneal@45: addUndo(); bgneal@45: }); bgneal@45: bgneal@45: t.onKeyUp.add(function(ed, e) { bgneal@45: var keyCode = e.keyCode; bgneal@45: bgneal@45: if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45 || e.ctrlKey) bgneal@45: addUndo(); bgneal@45: }); bgneal@45: bgneal@45: t.onKeyDown.add(function(ed, e) { bgneal@45: var keyCode = e.keyCode, sel; bgneal@45: bgneal@45: if (keyCode == 8) { bgneal@45: sel = t.getDoc().selection; bgneal@45: bgneal@45: // Fix IE control + backspace browser bug bgneal@45: if (sel && sel.createRange && sel.createRange().item) { bgneal@45: t.undoManager.beforeChange(); bgneal@45: ed.dom.remove(sel.createRange().item(0)); bgneal@45: addUndo(); bgneal@45: bgneal@45: return Event.cancel(e); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter bgneal@45: if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 13 || keyCode == 45) { bgneal@45: // Add position before enter key is pressed, used by IE since it still uses the default browser behavior bgneal@45: // Todo: Remove this once we normalize enter behavior on IE bgneal@45: if (tinymce.isIE && keyCode == 13) bgneal@45: t.undoManager.beforeChange(); bgneal@45: bgneal@45: if (t.undoManager.typing) bgneal@45: addUndo(); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // If key isn't shift,ctrl,alt,capslock,metakey bgneal@45: if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !t.undoManager.typing) { bgneal@45: t.undoManager.beforeChange(); bgneal@45: t.undoManager.typing = true; bgneal@45: t.undoManager.add(); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: t.onMouseDown.add(function() { bgneal@45: if (t.undoManager.typing) bgneal@45: addUndo(); bgneal@45: }); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: _refreshContentEditable : function() { bgneal@45: var self = this, body, parent; bgneal@45: bgneal@45: // Check if the editor was hidden and the re-initalize contentEditable mode by removing and adding the body again bgneal@45: if (self._isHidden()) { bgneal@45: body = self.getBody(); bgneal@45: parent = body.parentNode; bgneal@45: bgneal@45: parent.removeChild(body); bgneal@45: parent.appendChild(body); bgneal@45: bgneal@45: body.focus(); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: _isHidden : function() { bgneal@45: var s; bgneal@45: bgneal@45: if (!isGecko) bgneal@45: return 0; bgneal@45: bgneal@45: // Weird, wheres that cursor selection? bgneal@45: s = this.selection.getSel(); bgneal@45: return (!s || !s.rangeCount || s.rangeCount == 0); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: // Added for compression purposes bgneal@45: var each = tinymce.each, undefined, TRUE = true, FALSE = false; bgneal@45: bgneal@45: tinymce.EditorCommands = function(editor) { bgneal@45: var dom = editor.dom, bgneal@45: selection = editor.selection, bgneal@45: commands = {state: {}, exec : {}, value : {}}, bgneal@45: settings = editor.settings, bgneal@45: formatter = editor.formatter, bgneal@45: bookmark; bgneal@45: bgneal@45: function execCommand(command, ui, value) { bgneal@45: var func; bgneal@45: bgneal@45: command = command.toLowerCase(); bgneal@45: if (func = commands.exec[command]) { bgneal@45: func(command, ui, value); bgneal@45: return TRUE; bgneal@45: } bgneal@45: bgneal@45: return FALSE; bgneal@45: }; bgneal@45: bgneal@45: function queryCommandState(command) { bgneal@45: var func; bgneal@45: bgneal@45: command = command.toLowerCase(); bgneal@45: if (func = commands.state[command]) bgneal@45: return func(command); bgneal@45: bgneal@45: return -1; bgneal@45: }; bgneal@45: bgneal@45: function queryCommandValue(command) { bgneal@45: var func; bgneal@45: bgneal@45: command = command.toLowerCase(); bgneal@45: if (func = commands.value[command]) bgneal@45: return func(command); bgneal@45: bgneal@45: return FALSE; bgneal@45: }; bgneal@45: bgneal@45: function addCommands(command_list, type) { bgneal@45: type = type || 'exec'; bgneal@45: bgneal@45: each(command_list, function(callback, command) { bgneal@45: each(command.toLowerCase().split(','), function(command) { bgneal@45: commands[type][command] = callback; bgneal@45: }); bgneal@45: }); bgneal@45: }; bgneal@45: bgneal@45: // Expose public methods bgneal@45: tinymce.extend(this, { bgneal@45: execCommand : execCommand, bgneal@45: queryCommandState : queryCommandState, bgneal@45: queryCommandValue : queryCommandValue, bgneal@45: addCommands : addCommands bgneal@45: }); bgneal@45: bgneal@45: // Private methods bgneal@45: bgneal@45: function execNativeCommand(command, ui, value) { bgneal@45: if (ui === undefined) bgneal@45: ui = FALSE; bgneal@45: bgneal@45: if (value === undefined) bgneal@45: value = null; bgneal@45: bgneal@45: return editor.getDoc().execCommand(command, ui, value); bgneal@45: }; bgneal@45: bgneal@45: function isFormatMatch(name) { bgneal@45: return formatter.match(name); bgneal@45: }; bgneal@45: bgneal@45: function toggleFormat(name, value) { bgneal@45: formatter.toggle(name, value ? {value : value} : undefined); bgneal@45: }; bgneal@45: bgneal@45: function storeSelection(type) { bgneal@45: bookmark = selection.getBookmark(type); bgneal@45: }; bgneal@45: bgneal@45: function restoreSelection() { bgneal@45: selection.moveToBookmark(bookmark); bgneal@45: }; bgneal@45: bgneal@45: // Add execCommand overrides bgneal@45: addCommands({ bgneal@45: // Ignore these, added for compatibility bgneal@45: 'mceResetDesignMode,mceBeginUndoLevel' : function() {}, bgneal@45: bgneal@45: // Add undo manager logic bgneal@45: 'mceEndUndoLevel,mceAddUndoLevel' : function() { bgneal@45: editor.undoManager.add(); bgneal@45: }, bgneal@45: bgneal@45: 'Cut,Copy,Paste' : function(command) { bgneal@45: var doc = editor.getDoc(), failed; bgneal@45: bgneal@45: // Try executing the native command bgneal@45: try { bgneal@45: execNativeCommand(command); bgneal@45: } catch (ex) { bgneal@45: // Command failed bgneal@45: failed = TRUE; bgneal@45: } bgneal@45: bgneal@45: // Present alert message about clipboard access not being available bgneal@45: if (failed || !doc.queryCommandSupported(command)) { bgneal@45: if (tinymce.isGecko) { bgneal@45: editor.windowManager.confirm(editor.getLang('clipboard_msg'), function(state) { bgneal@45: if (state) bgneal@45: open('http://www.mozilla.org/editor/midasdemo/securityprefs.html', '_blank'); bgneal@45: }); bgneal@45: } else bgneal@45: editor.windowManager.alert(editor.getLang('clipboard_no_support')); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: // Override unlink command bgneal@45: unlink : function(command) { bgneal@45: if (selection.isCollapsed()) bgneal@45: selection.select(selection.getNode()); bgneal@45: bgneal@45: execNativeCommand(command); bgneal@45: selection.collapse(FALSE); bgneal@45: }, bgneal@45: bgneal@45: // Override justify commands to use the text formatter engine bgneal@45: 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) { bgneal@45: var align = command.substring(7); bgneal@45: bgneal@45: // Remove all other alignments first bgneal@45: each('left,center,right,full'.split(','), function(name) { bgneal@45: if (align != name) bgneal@45: formatter.remove('align' + name); bgneal@45: }); bgneal@45: bgneal@45: toggleFormat('align' + align); bgneal@45: execCommand('mceRepaint'); bgneal@45: }, bgneal@45: bgneal@45: // Override list commands to fix WebKit bug bgneal@45: 'InsertUnorderedList,InsertOrderedList' : function(command) { bgneal@45: var listElm, listParent; bgneal@45: bgneal@45: execNativeCommand(command); bgneal@45: bgneal@45: // WebKit produces lists within block elements so we need to split them bgneal@45: // we will replace the native list creation logic to custom logic later on bgneal@45: // TODO: Remove this when the list creation logic is removed bgneal@45: listElm = dom.getParent(selection.getNode(), 'ol,ul'); bgneal@45: if (listElm) { bgneal@45: listParent = listElm.parentNode; bgneal@45: bgneal@45: // If list is within a text block then split that block bgneal@45: if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) { bgneal@45: storeSelection(); bgneal@45: dom.split(listParent, listElm); bgneal@45: restoreSelection(); bgneal@45: } bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: // Override commands to use the text formatter engine bgneal@45: 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) { bgneal@45: toggleFormat(command); bgneal@45: }, bgneal@45: bgneal@45: // Override commands to use the text formatter engine bgneal@45: 'ForeColor,HiliteColor,FontName' : function(command, ui, value) { bgneal@45: toggleFormat(command, value); bgneal@45: }, bgneal@45: bgneal@45: FontSize : function(command, ui, value) { bgneal@45: var fontClasses, fontSizes; bgneal@45: bgneal@45: // Convert font size 1-7 to styles bgneal@45: if (value >= 1 && value <= 7) { bgneal@45: fontSizes = tinymce.explode(settings.font_size_style_values); bgneal@45: fontClasses = tinymce.explode(settings.font_size_classes); bgneal@45: bgneal@45: if (fontClasses) bgneal@45: value = fontClasses[value - 1] || value; bgneal@45: else bgneal@45: value = fontSizes[value - 1] || value; bgneal@45: } bgneal@45: bgneal@45: toggleFormat(command, value); bgneal@45: }, bgneal@45: bgneal@45: RemoveFormat : function(command) { bgneal@45: formatter.remove(command); bgneal@45: }, bgneal@45: bgneal@45: mceBlockQuote : function(command) { bgneal@45: toggleFormat('blockquote'); bgneal@45: }, bgneal@45: bgneal@45: FormatBlock : function(command, ui, value) { bgneal@45: return toggleFormat(value || 'p'); bgneal@45: }, bgneal@45: bgneal@45: mceCleanup : function() { bgneal@45: var bookmark = selection.getBookmark(); bgneal@45: bgneal@45: editor.setContent(editor.getContent({cleanup : TRUE}), {cleanup : TRUE}); bgneal@45: bgneal@45: selection.moveToBookmark(bookmark); bgneal@45: }, bgneal@45: bgneal@45: mceRemoveNode : function(command, ui, value) { bgneal@45: var node = value || selection.getNode(); bgneal@45: bgneal@45: // Make sure that the body node isn't removed bgneal@45: if (node != editor.getBody()) { bgneal@45: storeSelection(); bgneal@45: editor.dom.remove(node, TRUE); bgneal@45: restoreSelection(); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: mceSelectNodeDepth : function(command, ui, value) { bgneal@45: var counter = 0; bgneal@45: bgneal@45: dom.getParent(selection.getNode(), function(node) { bgneal@45: if (node.nodeType == 1 && counter++ == value) { bgneal@45: selection.select(node); bgneal@45: return FALSE; bgneal@45: } bgneal@45: }, editor.getBody()); bgneal@45: }, bgneal@45: bgneal@45: mceSelectNode : function(command, ui, value) { bgneal@45: selection.select(value); bgneal@45: }, bgneal@45: bgneal@45: mceInsertContent : function(command, ui, value) { bgneal@45: var parser, serializer, parentNode, rootNode, fragment, args, bgneal@45: marker, nodeRect, viewPortRect, rng, node, node2, bookmarkHtml, viewportBodyElement; bgneal@45: bgneal@45: //selection.normalize(); bgneal@45: bgneal@45: // Setup parser and serializer bgneal@45: parser = editor.parser; bgneal@45: serializer = new tinymce.html.Serializer({}, editor.schema); bgneal@45: bookmarkHtml = '\uFEFF'; bgneal@45: bgneal@45: // Run beforeSetContent handlers on the HTML to be inserted bgneal@45: args = {content: value, format: 'html'}; bgneal@45: selection.onBeforeSetContent.dispatch(selection, args); bgneal@45: value = args.content; bgneal@45: bgneal@45: // Add caret at end of contents if it's missing bgneal@45: if (value.indexOf('{$caret}') == -1) bgneal@45: value += '{$caret}'; bgneal@45: bgneal@45: // Replace the caret marker with a span bookmark element bgneal@45: value = value.replace(/\{\$caret\}/, bookmarkHtml); bgneal@45: bgneal@45: // Insert node maker where we will insert the new HTML and get it's parent bgneal@45: if (!selection.isCollapsed()) bgneal@45: editor.getDoc().execCommand('Delete', false, null); bgneal@45: bgneal@45: parentNode = selection.getNode(); bgneal@45: bgneal@45: // Parse the fragment within the context of the parent node bgneal@45: args = {context : parentNode.nodeName.toLowerCase()}; bgneal@45: fragment = parser.parse(value, args); bgneal@45: bgneal@45: // Move the caret to a more suitable location bgneal@45: node = fragment.lastChild; bgneal@45: if (node.attr('id') == 'mce_marker') { bgneal@45: marker = node; bgneal@45: bgneal@45: for (node = node.prev; node; node = node.walk(true)) { bgneal@45: if (node.type == 3 || !dom.isBlock(node.name)) { bgneal@45: node.parent.insert(marker, node, node.name === 'br'); bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // If parser says valid we can insert the contents into that parent bgneal@45: if (!args.invalid) { bgneal@45: value = serializer.serialize(fragment); bgneal@45: bgneal@45: // Check if parent is empty or only has one BR element then set the innerHTML of that parent bgneal@45: node = parentNode.firstChild; bgneal@45: node2 = parentNode.lastChild; bgneal@45: if (!node || (node === node2 && node.nodeName === 'BR')) bgneal@45: dom.setHTML(parentNode, value); bgneal@45: else bgneal@45: selection.setContent(value); bgneal@45: } else { bgneal@45: // If the fragment was invalid within that context then we need bgneal@45: // to parse and process the parent it's inserted into bgneal@45: bgneal@45: // Insert bookmark node and get the parent bgneal@45: selection.setContent(bookmarkHtml); bgneal@45: parentNode = editor.selection.getNode(); bgneal@45: rootNode = editor.getBody(); bgneal@45: bgneal@45: // Opera will return the document node when selection is in root bgneal@45: if (parentNode.nodeType == 9) bgneal@45: parentNode = node = rootNode; bgneal@45: else bgneal@45: node = parentNode; bgneal@45: bgneal@45: // Find the ancestor just before the root element bgneal@45: while (node !== rootNode) { bgneal@45: parentNode = node; bgneal@45: node = node.parentNode; bgneal@45: } bgneal@45: bgneal@45: // Get the outer/inner HTML depending on if we are in the root and parser and serialize that bgneal@45: value = parentNode == rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode); bgneal@45: value = serializer.serialize( bgneal@45: parser.parse( bgneal@45: // Need to replace by using a function since $ in the contents would otherwise be a problem bgneal@45: value.replace(//i, function() { bgneal@45: return serializer.serialize(fragment); bgneal@45: }) bgneal@45: ) bgneal@45: ); bgneal@45: bgneal@45: // Set the inner/outer HTML depending on if we are in the root or not bgneal@45: if (parentNode == rootNode) bgneal@45: dom.setHTML(rootNode, value); bgneal@45: else bgneal@45: dom.setOuterHTML(parentNode, value); bgneal@45: } bgneal@45: bgneal@45: marker = dom.get('mce_marker'); bgneal@45: bgneal@45: // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well bgneal@45: nodeRect = dom.getRect(marker); bgneal@45: viewPortRect = dom.getViewPort(editor.getWin()); bgneal@45: bgneal@45: // Check if node is out side the viewport if it is then scroll to it bgneal@45: if ((nodeRect.y + nodeRect.h > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) || bgneal@45: (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) { bgneal@45: viewportBodyElement = tinymce.isIE ? editor.getDoc().documentElement : editor.getBody(); bgneal@45: viewportBodyElement.scrollLeft = nodeRect.x; bgneal@45: viewportBodyElement.scrollTop = nodeRect.y - viewPortRect.h + 25; bgneal@45: } bgneal@45: bgneal@45: // Move selection before marker and remove it bgneal@45: rng = dom.createRng(); bgneal@45: bgneal@45: // If previous sibling is a text node set the selection to the end of that node bgneal@45: node = marker.previousSibling; bgneal@45: if (node && node.nodeType == 3) { bgneal@45: rng.setStart(node, node.nodeValue.length); bgneal@45: } else { bgneal@45: // If the previous sibling isn't a text node or doesn't exist set the selection before the marker node bgneal@45: rng.setStartBefore(marker); bgneal@45: rng.setEndBefore(marker); bgneal@45: } bgneal@45: bgneal@45: // Remove the marker node and set the new range bgneal@45: dom.remove(marker); bgneal@45: selection.setRng(rng); bgneal@45: bgneal@45: // Dispatch after event and add any visual elements needed bgneal@45: selection.onSetContent.dispatch(selection, args); bgneal@45: editor.addVisual(); bgneal@45: }, bgneal@45: bgneal@45: mceInsertRawHTML : function(command, ui, value) { bgneal@45: selection.setContent('tiny_mce_marker'); bgneal@45: editor.setContent(editor.getContent().replace(/tiny_mce_marker/g, function() { return value })); bgneal@45: }, bgneal@45: bgneal@45: mceSetContent : function(command, ui, value) { bgneal@45: editor.setContent(value); bgneal@45: }, bgneal@45: bgneal@45: 'Indent,Outdent' : function(command) { bgneal@45: var intentValue, indentUnit, value; bgneal@45: bgneal@45: // Setup indent level bgneal@45: intentValue = settings.indentation; bgneal@45: indentUnit = /[a-z%]+$/i.exec(intentValue); bgneal@45: intentValue = parseInt(intentValue); bgneal@45: bgneal@45: if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) { bgneal@45: each(selection.getSelectedBlocks(), function(element) { bgneal@45: if (command == 'outdent') { bgneal@45: value = Math.max(0, parseInt(element.style.paddingLeft || 0) - intentValue); bgneal@45: dom.setStyle(element, 'paddingLeft', value ? value + indentUnit : ''); bgneal@45: } else bgneal@45: dom.setStyle(element, 'paddingLeft', (parseInt(element.style.paddingLeft || 0) + intentValue) + indentUnit); bgneal@45: }); bgneal@45: } else bgneal@45: execNativeCommand(command); bgneal@45: }, bgneal@45: bgneal@45: mceRepaint : function() { bgneal@45: var bookmark; bgneal@45: bgneal@45: if (tinymce.isGecko) { bgneal@45: try { bgneal@45: storeSelection(TRUE); bgneal@45: bgneal@45: if (selection.getSel()) bgneal@45: selection.getSel().selectAllChildren(editor.getBody()); bgneal@45: bgneal@45: selection.collapse(TRUE); bgneal@45: restoreSelection(); bgneal@45: } catch (ex) { bgneal@45: // Ignore bgneal@45: } bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: mceToggleFormat : function(command, ui, value) { bgneal@45: formatter.toggle(value); bgneal@45: }, bgneal@45: bgneal@45: InsertHorizontalRule : function() { bgneal@45: editor.execCommand('mceInsertContent', false, '
    '); bgneal@45: }, bgneal@45: bgneal@45: mceToggleVisualAid : function() { bgneal@45: editor.hasVisual = !editor.hasVisual; bgneal@45: editor.addVisual(); bgneal@45: }, bgneal@45: bgneal@45: mceReplaceContent : function(command, ui, value) { bgneal@45: editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format : 'text'}))); bgneal@45: }, bgneal@45: bgneal@45: mceInsertLink : function(command, ui, value) { bgneal@45: var anchor; bgneal@45: bgneal@45: if (typeof(value) == 'string') bgneal@45: value = {href : value}; bgneal@45: bgneal@45: anchor = dom.getParent(selection.getNode(), 'a'); bgneal@45: bgneal@45: // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here. bgneal@45: value.href = value.href.replace(' ', '%20'); bgneal@45: bgneal@45: // Remove existing links if there could be child links or that the href isn't specified bgneal@45: if (!anchor || !value.href) { bgneal@45: formatter.remove('link'); bgneal@45: } bgneal@45: bgneal@45: // Apply new link to selection bgneal@45: if (value.href) { bgneal@45: formatter.apply('link', value, anchor); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: selectAll : function() { bgneal@45: var root = dom.getRoot(), rng = dom.createRng(); bgneal@45: bgneal@45: rng.setStart(root, 0); bgneal@45: rng.setEnd(root, root.childNodes.length); bgneal@45: bgneal@45: editor.selection.setRng(rng); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Add queryCommandState overrides bgneal@45: addCommands({ bgneal@45: // Override justify commands bgneal@45: 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull' : function(command) { bgneal@45: var name = 'align' + command.substring(7); bgneal@45: // Use Formatter.matchNode instead of Formatter.match so that we don't match on parent node. This fixes bug where for both left bgneal@45: // and right align buttons can be active. This could occur when selected nodes have align right and the parent has align left. bgneal@45: var nodes = selection.isCollapsed() ? [selection.getNode()] : selection.getSelectedBlocks(); bgneal@45: var matches = tinymce.map(nodes, function(node) { bgneal@45: return !!formatter.matchNode(node, name); bgneal@45: }); bgneal@45: return tinymce.inArray(matches, TRUE) !== -1; bgneal@45: }, bgneal@45: bgneal@45: 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript' : function(command) { bgneal@45: return isFormatMatch(command); bgneal@45: }, bgneal@45: bgneal@45: mceBlockQuote : function() { bgneal@45: return isFormatMatch('blockquote'); bgneal@45: }, bgneal@45: bgneal@45: Outdent : function() { bgneal@45: var node; bgneal@45: bgneal@45: if (settings.inline_styles) { bgneal@45: if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0) bgneal@45: return TRUE; bgneal@45: bgneal@45: if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft) > 0) bgneal@45: return TRUE; bgneal@45: } bgneal@45: bgneal@45: return queryCommandState('InsertUnorderedList') || queryCommandState('InsertOrderedList') || (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE')); bgneal@45: }, bgneal@45: bgneal@45: 'InsertUnorderedList,InsertOrderedList' : function(command) { bgneal@45: return dom.getParent(selection.getNode(), command == 'insertunorderedlist' ? 'UL' : 'OL'); bgneal@45: } bgneal@45: }, 'state'); bgneal@45: bgneal@45: // Add queryCommandValue overrides bgneal@45: addCommands({ bgneal@45: 'FontSize,FontName' : function(command) { bgneal@45: var value = 0, parent; bgneal@45: bgneal@45: if (parent = dom.getParent(selection.getNode(), 'span')) { bgneal@45: if (command == 'fontsize') bgneal@45: value = parent.style.fontSize; bgneal@45: else bgneal@45: value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase(); bgneal@45: } bgneal@45: bgneal@45: return value; bgneal@45: } bgneal@45: }, 'value'); bgneal@45: bgneal@45: // Add undo manager logic bgneal@45: if (settings.custom_undo_redo) { bgneal@45: addCommands({ bgneal@45: Undo : function() { bgneal@45: editor.undoManager.undo(); bgneal@45: }, bgneal@45: bgneal@45: Redo : function() { bgneal@45: editor.undoManager.redo(); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: }; bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: var Dispatcher = tinymce.util.Dispatcher; bgneal@45: bgneal@45: tinymce.UndoManager = function(editor) { bgneal@45: var self, index = 0, data = [], beforeBookmark; bgneal@45: bgneal@45: function getContent() { bgneal@45: // Remove whitespace before/after and remove pure bogus nodes bgneal@45: return tinymce.trim(editor.getContent({format : 'raw', no_events : 1}).replace(/]+data-mce-bogus[^>]+>[\u200B\uFEFF]+<\/span>/g, '')); bgneal@45: }; bgneal@45: bgneal@45: return self = { bgneal@45: typing : false, bgneal@45: bgneal@45: onAdd : new Dispatcher(self), bgneal@45: bgneal@45: onUndo : new Dispatcher(self), bgneal@45: bgneal@45: onRedo : new Dispatcher(self), bgneal@45: bgneal@45: beforeChange : function() { bgneal@45: beforeBookmark = editor.selection.getBookmark(2, true); bgneal@45: }, bgneal@45: bgneal@45: add : function(level) { bgneal@45: var i, settings = editor.settings, lastLevel; bgneal@45: bgneal@45: level = level || {}; bgneal@45: level.content = getContent(); bgneal@45: bgneal@45: // Add undo level if needed bgneal@45: lastLevel = data[index]; bgneal@45: if (lastLevel && lastLevel.content == level.content) bgneal@45: return null; bgneal@45: bgneal@45: // Set before bookmark on previous level bgneal@45: if (data[index]) bgneal@45: data[index].beforeBookmark = beforeBookmark; bgneal@45: bgneal@45: // Time to compress bgneal@45: if (settings.custom_undo_redo_levels) { bgneal@45: if (data.length > settings.custom_undo_redo_levels) { bgneal@45: for (i = 0; i < data.length - 1; i++) bgneal@45: data[i] = data[i + 1]; bgneal@45: bgneal@45: data.length--; bgneal@45: index = data.length; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Get a non intrusive normalized bookmark bgneal@45: level.bookmark = editor.selection.getBookmark(2, true); bgneal@45: bgneal@45: // Crop array if needed bgneal@45: if (index < data.length - 1) bgneal@45: data.length = index + 1; bgneal@45: bgneal@45: data.push(level); bgneal@45: index = data.length - 1; bgneal@45: bgneal@45: self.onAdd.dispatch(self, level); bgneal@45: editor.isNotDirty = 0; bgneal@45: bgneal@45: return level; bgneal@45: }, bgneal@45: bgneal@45: undo : function() { bgneal@45: var level, i; bgneal@45: bgneal@45: if (self.typing) { bgneal@45: self.add(); bgneal@45: self.typing = false; bgneal@45: } bgneal@45: bgneal@45: if (index > 0) { bgneal@45: level = data[--index]; bgneal@45: bgneal@45: editor.setContent(level.content, {format : 'raw'}); bgneal@45: editor.selection.moveToBookmark(level.beforeBookmark); bgneal@45: bgneal@45: self.onUndo.dispatch(self, level); bgneal@45: } bgneal@45: bgneal@45: return level; bgneal@45: }, bgneal@45: bgneal@45: redo : function() { bgneal@45: var level; bgneal@45: bgneal@45: if (index < data.length - 1) { bgneal@45: level = data[++index]; bgneal@45: bgneal@45: editor.setContent(level.content, {format : 'raw'}); bgneal@45: editor.selection.moveToBookmark(level.bookmark); bgneal@45: bgneal@45: self.onRedo.dispatch(self, level); bgneal@45: } bgneal@45: bgneal@45: return level; bgneal@45: }, bgneal@45: bgneal@45: clear : function() { bgneal@45: data = []; bgneal@45: index = 0; bgneal@45: self.typing = false; bgneal@45: }, bgneal@45: bgneal@45: hasUndo : function() { bgneal@45: return index > 0 || this.typing; bgneal@45: }, bgneal@45: bgneal@45: hasRedo : function() { bgneal@45: return index < data.length - 1 && !this.typing; bgneal@45: } bgneal@45: }; bgneal@45: }; bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: // Shorten names bgneal@45: var Event = tinymce.dom.Event, bgneal@45: isIE = tinymce.isIE, bgneal@45: isGecko = tinymce.isGecko, bgneal@45: isOpera = tinymce.isOpera, bgneal@45: each = tinymce.each, bgneal@45: extend = tinymce.extend, bgneal@45: TRUE = true, bgneal@45: FALSE = false; bgneal@45: bgneal@45: function splitList(selection, dom, li) { bgneal@45: var listBlock, block; bgneal@45: bgneal@45: // TODO: Fix so this doesn't use native IE logic bgneal@45: if (dom.isEmpty(li) && !isIE) { bgneal@45: listBlock = dom.getParent(li, 'ul,ol'); bgneal@45: bgneal@45: if (!dom.getParent(listBlock.parentNode, 'ul,ol')) { bgneal@45: dom.split(listBlock, li); bgneal@45: block = dom.create('p', 0, '
    '); bgneal@45: dom.replace(block, li); bgneal@45: selection.select(block, 1); bgneal@45: } bgneal@45: bgneal@45: return FALSE; bgneal@45: } bgneal@45: bgneal@45: return TRUE; bgneal@45: }; bgneal@45: bgneal@45: tinymce.create('tinymce.ForceBlocks', { bgneal@45: ForceBlocks : function(ed) { bgneal@45: var t = this, s = ed.settings, elm; bgneal@45: bgneal@45: t.editor = ed; bgneal@45: t.dom = ed.dom; bgneal@45: elm = (s.forced_root_block || 'p').toLowerCase(); bgneal@45: s.element = elm.toUpperCase(); bgneal@45: bgneal@45: ed.onPreInit.add(t.setup, t); bgneal@45: }, bgneal@45: bgneal@45: setup : function() { bgneal@45: var t = this, ed = t.editor, s = ed.settings, dom = ed.dom, selection = ed.selection, blockElements = ed.schema.getBlockElements(); bgneal@45: bgneal@45: // Force root blocks bgneal@45: if (s.forced_root_block) { bgneal@45: function addRootBlocks() { bgneal@45: var node = selection.getStart(), rootNode = ed.getBody(), rng, startContainer, startOffset, endContainer, endOffset, rootBlockNode, tempNode, offset = -0xFFFFFF; bgneal@45: bgneal@45: if (!node || node.nodeType !== 1) bgneal@45: return; bgneal@45: bgneal@45: // Check if node is wrapped in block bgneal@45: while (node != rootNode) { bgneal@45: if (blockElements[node.nodeName]) bgneal@45: return; bgneal@45: bgneal@45: node = node.parentNode; bgneal@45: } bgneal@45: bgneal@45: // Get current selection bgneal@45: rng = selection.getRng(); bgneal@45: if (rng.setStart) { bgneal@45: startContainer = rng.startContainer; bgneal@45: startOffset = rng.startOffset; bgneal@45: endContainer = rng.endContainer; bgneal@45: endOffset = rng.endOffset; bgneal@45: } else { bgneal@45: // Force control range into text range bgneal@45: if (rng.item) { bgneal@45: rng = ed.getDoc().body.createTextRange(); bgneal@45: rng.moveToElementText(rng.item(0)); bgneal@45: } bgneal@45: bgneal@45: tmpRng = rng.duplicate(); bgneal@45: tmpRng.collapse(true); bgneal@45: startOffset = tmpRng.move('character', offset) * -1; bgneal@45: bgneal@45: if (!tmpRng.collapsed) { bgneal@45: tmpRng = rng.duplicate(); bgneal@45: tmpRng.collapse(false); bgneal@45: endOffset = (tmpRng.move('character', offset) * -1) - startOffset; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Wrap non block elements and text nodes bgneal@45: for (node = rootNode.firstChild; node; node) { bgneal@45: if (node.nodeType === 3 || (node.nodeType == 1 && !blockElements[node.nodeName])) { bgneal@45: if (!rootBlockNode) { bgneal@45: rootBlockNode = dom.create(s.forced_root_block); bgneal@45: node.parentNode.insertBefore(rootBlockNode, node); bgneal@45: } bgneal@45: bgneal@45: tempNode = node; bgneal@45: node = node.nextSibling; bgneal@45: rootBlockNode.appendChild(tempNode); bgneal@45: } else { bgneal@45: rootBlockNode = null; bgneal@45: node = node.nextSibling; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if (rng.setStart) { bgneal@45: rng.setStart(startContainer, startOffset); bgneal@45: rng.setEnd(endContainer, endOffset); bgneal@45: selection.setRng(rng); bgneal@45: } else { bgneal@45: try { bgneal@45: rng = ed.getDoc().body.createTextRange(); bgneal@45: rng.moveToElementText(rootNode); bgneal@45: rng.collapse(true); bgneal@45: rng.moveStart('character', startOffset); bgneal@45: bgneal@45: if (endOffset > 0) bgneal@45: rng.moveEnd('character', endOffset); bgneal@45: bgneal@45: rng.select(); bgneal@45: } catch (ex) { bgneal@45: // Ignore bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: ed.nodeChanged(); bgneal@45: }; bgneal@45: bgneal@45: ed.onKeyUp.add(addRootBlocks); bgneal@45: ed.onClick.add(addRootBlocks); bgneal@45: } bgneal@45: bgneal@45: if (s.force_br_newlines) { bgneal@45: // Force IE to produce BRs on enter bgneal@45: if (isIE) { bgneal@45: ed.onKeyPress.add(function(ed, e) { bgneal@45: var n; bgneal@45: bgneal@45: if (e.keyCode == 13 && selection.getNode().nodeName != 'LI') { bgneal@45: selection.setContent('
    ', {format : 'raw'}); bgneal@45: n = dom.get('__'); bgneal@45: n.removeAttribute('id'); bgneal@45: selection.select(n); bgneal@45: selection.collapse(); bgneal@45: return Event.cancel(e); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if (s.force_p_newlines) { bgneal@45: ed.onKeyPress.add(function(ed, e) { bgneal@45: if (e.keyCode == 13 && !e.shiftKey && !t.insertPara(e)) bgneal@45: Event.cancel(e); bgneal@45: }); bgneal@45: bgneal@45: if (isGecko) { bgneal@45: ed.onKeyDown.add(function(ed, e) { bgneal@45: if ((e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) bgneal@45: t.backspaceDelete(e, e.keyCode == 8); bgneal@45: }); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Workaround for missing shift+enter support, http://bugs.webkit.org/show_bug.cgi?id=16973 bgneal@45: if (tinymce.isWebKit) { bgneal@45: function insertBr(ed) { bgneal@45: var rng = selection.getRng(), br, div = dom.create('div', null, ' '), divYPos, vpHeight = dom.getViewPort(ed.getWin()).h; bgneal@45: bgneal@45: // Insert BR element bgneal@45: rng.insertNode(br = dom.create('br')); bgneal@45: bgneal@45: // Place caret after BR bgneal@45: rng.setStartAfter(br); bgneal@45: rng.setEndAfter(br); bgneal@45: selection.setRng(rng); bgneal@45: bgneal@45: // Could not place caret after BR then insert an nbsp entity and move the caret bgneal@45: if (selection.getSel().focusNode == br.previousSibling) { bgneal@45: selection.select(dom.insertAfter(dom.doc.createTextNode('\u00a0'), br)); bgneal@45: selection.collapse(TRUE); bgneal@45: } bgneal@45: bgneal@45: // Create a temporary DIV after the BR and get the position as it bgneal@45: // seems like getPos() returns 0 for text nodes and BR elements. bgneal@45: dom.insertAfter(div, br); bgneal@45: divYPos = dom.getPos(div).y; bgneal@45: dom.remove(div); bgneal@45: bgneal@45: // Scroll to new position, scrollIntoView can't be used due to bug: http://bugs.webkit.org/show_bug.cgi?id=16117 bgneal@45: if (divYPos > vpHeight) // It is not necessary to scroll if the DIV is inside the view port. bgneal@45: ed.getWin().scrollTo(0, divYPos); bgneal@45: }; bgneal@45: bgneal@45: ed.onKeyPress.add(function(ed, e) { bgneal@45: if (e.keyCode == 13 && (e.shiftKey || (s.force_br_newlines && !dom.getParent(selection.getNode(), 'h1,h2,h3,h4,h5,h6,ol,ul')))) { bgneal@45: insertBr(ed); bgneal@45: Event.cancel(e); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // IE specific fixes bgneal@45: if (isIE) { bgneal@45: // Replaces IE:s auto generated paragraphs with the specified element name bgneal@45: if (s.element != 'P') { bgneal@45: ed.onKeyPress.add(function(ed, e) { bgneal@45: t.lastElm = selection.getNode().nodeName; bgneal@45: }); bgneal@45: bgneal@45: ed.onKeyUp.add(function(ed, e) { bgneal@45: var bl, n = selection.getNode(), b = ed.getBody(); bgneal@45: bgneal@45: if (b.childNodes.length === 1 && n.nodeName == 'P') { bgneal@45: n = dom.rename(n, s.element); bgneal@45: selection.select(n); bgneal@45: selection.collapse(); bgneal@45: ed.nodeChanged(); bgneal@45: } else if (e.keyCode == 13 && !e.shiftKey && t.lastElm != 'P') { bgneal@45: bl = dom.getParent(n, 'p'); bgneal@45: bgneal@45: if (bl) { bgneal@45: dom.rename(bl, s.element); bgneal@45: ed.nodeChanged(); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: getParentBlock : function(n) { bgneal@45: var d = this.dom; bgneal@45: bgneal@45: return d.getParent(n, d.isBlock); bgneal@45: }, bgneal@45: bgneal@45: insertPara : function(e) { bgneal@45: var t = this, ed = t.editor, dom = ed.dom, selection = ed.selection, d = ed.getDoc(), se = ed.settings, s = selection.getSel(), r = selection.getRng(true), b = d.body; bgneal@45: var rb, ra, dir, sn, so, en, eo, sb, eb, bn, bef, aft, sc, ec, n, ch, containerBlock, beforeCaretNode, afterCaretNode; bgneal@45: bgneal@45: // Checks if the selection/caret is at the end of the specified block element bgneal@45: function isAtEnd(rng, par) { bgneal@45: var rng2 = rng.cloneRange(); bgneal@45: bgneal@45: rng2.setStart(rng.endContainer, rng.endOffset); bgneal@45: rng2.setEndAfter(par); bgneal@45: bgneal@45: // 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@45: return dom.isEmpty(rng2.cloneContents()); bgneal@45: }; bgneal@45: bgneal@45: function moveToCaretPosition(root, scroll) { bgneal@45: var walker, node, rng, y, vp; bgneal@45: bgneal@45: rng = dom.createRng(); bgneal@45: bgneal@45: if (root.hasChildNodes()) { bgneal@45: walker = new tinymce.dom.TreeWalker(root, root); bgneal@45: bgneal@45: while (node = walker.current()) { bgneal@45: if (node.nodeType == 3) { bgneal@45: rng.setStart(node, 0); bgneal@45: rng.setEnd(node, 0); bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: if (/^(BR|IMG)$/.test(node.nodeName)) { bgneal@45: rng.setStartBefore(node); bgneal@45: rng.setEndBefore(node); bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: node = walker.next(); bgneal@45: } bgneal@45: } else { bgneal@45: rng.setStart(root, 0); bgneal@45: rng.setEnd(root, 0); bgneal@45: } bgneal@45: bgneal@45: selection.setRng(rng); bgneal@45: bgneal@45: if (scroll !== false) { bgneal@45: vp = dom.getViewPort(ed.getWin()); bgneal@45: bgneal@45: // 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@45: y = dom.getPos(root).y; bgneal@45: bgneal@45: // Is element within viewport bgneal@45: if (y < vp.y || y + 25 > vp.y + vp.h) { bgneal@45: 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@45: bgneal@45: /*console.debug( bgneal@45: 'Element: y=' + y + ', h=' + ch + ', ' + bgneal@45: 'Viewport: y=' + vp.y + ", h=" + vp.h + ', bottom=' + (vp.y + vp.h) bgneal@45: );*/ bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function clean(node) { bgneal@45: if (node.nodeType == 3 && node.nodeValue.length == 0) { bgneal@45: dom.remove(node); bgneal@45: } bgneal@45: bgneal@45: if (node.hasChildNodes()) { bgneal@45: for (var i = 0; i < node.childNodes.length; i++) { bgneal@45: clean(node.childNodes[i]); bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: ed.undoManager.beforeChange(); bgneal@45: bgneal@45: // If root blocks are forced then use Operas default behavior since it's really good bgneal@45: // Removed due to bug: #1853816 bgneal@45: // if (se.forced_root_block && isOpera) bgneal@45: // return TRUE; bgneal@45: bgneal@45: // Handle selection direction for browsers that support it bgneal@45: if (typeof s.anchorNode != "undefined") { bgneal@45: // Setup before range bgneal@45: rb = dom.createRng(); bgneal@45: bgneal@45: // If is before the first block element and in body, then move it into first block element bgneal@45: rb.setStart(s.anchorNode, s.anchorOffset); bgneal@45: rb.collapse(TRUE); bgneal@45: bgneal@45: // Setup after range bgneal@45: ra = dom.createRng(); bgneal@45: bgneal@45: // If is before the first block element and in body, then move it into first block element bgneal@45: ra.setStart(s.focusNode, s.focusOffset); bgneal@45: ra.collapse(TRUE); bgneal@45: bgneal@45: // Setup start/end points bgneal@45: dir = rb.compareBoundaryPoints(rb.START_TO_END, ra) < 0; bgneal@45: sn = dir ? s.anchorNode : s.focusNode; bgneal@45: so = dir ? s.anchorOffset : s.focusOffset; bgneal@45: en = dir ? s.focusNode : s.anchorNode; bgneal@45: eo = dir ? s.focusOffset : s.anchorOffset; bgneal@45: } else { bgneal@45: rb = r.cloneRange(); bgneal@45: rb.collapse(TRUE); bgneal@45: bgneal@45: ra = r.cloneRange(); bgneal@45: ra.collapse(FALSE); bgneal@45: bgneal@45: sn = r.startContainer; bgneal@45: so = r.startOffset; bgneal@45: en = r.endContainer; bgneal@45: eo = r.endOffset; bgneal@45: } bgneal@45: bgneal@45: // If selection is in empty table cell bgneal@45: if (sn === en && /^(TD|TH)$/.test(sn.nodeName)) { bgneal@45: sn.innerHTML = ''; bgneal@45: bgneal@45: // Create two new block elements bgneal@45: dom.add(sn, se.element, null, isIE ? '' : '
    '); bgneal@45: aft = dom.add(sn, se.element, null, isIE ? '' : '
    '); bgneal@45: moveToCaretPosition(aft); bgneal@45: bgneal@45: return FALSE; bgneal@45: } bgneal@45: bgneal@45: // If the caret is in an invalid location in FF we need to move it into the first block bgneal@45: if (sn == b && en == b && b.firstChild && dom.isBlock(b.firstChild)) { bgneal@45: sn = en = sn.firstChild; bgneal@45: so = eo = 0; bgneal@45: rb = dom.createRng(); bgneal@45: rb.setStart(sn, 0); bgneal@45: ra = dom.createRng(); bgneal@45: ra.setStart(en, 0); bgneal@45: } bgneal@45: bgneal@45: // If the body is totally empty add a BR element this might happen on webkit bgneal@45: if (!b.hasChildNodes()) { bgneal@45: b.appendChild(dom.create('br')); bgneal@45: } bgneal@45: bgneal@45: // Never use body as start or end node bgneal@45: sn = sn.nodeName == "HTML" ? d.body : sn; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes bgneal@45: sn = sn.nodeName == "BODY" ? sn.firstChild : sn; bgneal@45: en = en.nodeName == "HTML" ? d.body : en; // Fix for Opera bug: https://bugs.opera.com/show_bug.cgi?id=273224&comments=yes bgneal@45: en = en.nodeName == "BODY" ? en.firstChild : en; bgneal@45: bgneal@45: // Get start and end blocks bgneal@45: sb = t.getParentBlock(sn); bgneal@45: eb = t.getParentBlock(en); bgneal@45: bn = sb ? sb.nodeName : se.element; // Get block name to create bgneal@45: bgneal@45: // Break container blocks on enter in empty block element (experimental feature) bgneal@45: if (ed.settings.end_container_on_empty_block) { bgneal@45: containerBlock = dom.getParent(sb, 'hgroup,blockquote,section,article'); bgneal@45: if (containerBlock && (dom.isEmpty(sb) || (sb.firstChild === sb.lastChild && (!sb.firstChild || sb.firstChild.nodeName == 'BR')))) { bgneal@45: dom.split(containerBlock, sb); bgneal@45: selection.select(sb, true); bgneal@45: selection.collapse(true); bgneal@45: return; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Return inside list use default browser behavior bgneal@45: if (n = t.dom.getParent(sb, 'li')) { bgneal@45: if (n.nodeName == 'LI') bgneal@45: return splitList(selection, t.dom, n); bgneal@45: bgneal@45: return TRUE; bgneal@45: } bgneal@45: bgneal@45: // If caption or absolute layers then always generate new blocks within bgneal@45: if (sb && (sb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) { bgneal@45: bn = se.element; bgneal@45: sb = null; bgneal@45: } bgneal@45: bgneal@45: // If caption or absolute layers then always generate new blocks within bgneal@45: if (eb && (eb.nodeName == 'CAPTION' || /absolute|relative|fixed/gi.test(dom.getStyle(sb, 'position', 1)))) { bgneal@45: bn = se.element; bgneal@45: eb = null; bgneal@45: } bgneal@45: bgneal@45: // Use P instead bgneal@45: if (/(TD|TABLE|TH|CAPTION)/.test(bn) || (sb && bn == "DIV" && /left|right/gi.test(dom.getStyle(sb, 'float', 1)))) { bgneal@45: bn = se.element; bgneal@45: sb = eb = null; bgneal@45: } bgneal@45: bgneal@45: // Setup new before and after blocks bgneal@45: bef = (sb && sb.nodeName == bn) ? dom.clone(sb, false) : dom.create(bn); bgneal@45: aft = (eb && eb.nodeName == bn) ? dom.clone(eb, false) : dom.create(bn); bgneal@45: bgneal@45: // Remove id from after clone bgneal@45: aft.removeAttribute('id'); bgneal@45: bgneal@45: // Is header and cursor is at the end, then force paragraph under bgneal@45: if (/^(H[1-6])$/.test(bn) && isAtEnd(r, sb, dom)) { bgneal@45: aft = dom.create(se.element); bgneal@45: bgneal@45: // Use header name as copy if we are in a hgroup bgneal@45: if (t.dom.getParent(sb, 'hgroup')) { bgneal@45: aft = dom.create(bn); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Find start chop node bgneal@45: n = sc = sn; bgneal@45: do { bgneal@45: if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName)) bgneal@45: break; bgneal@45: bgneal@45: sc = n; bgneal@45: } while ((n = n.previousSibling ? n.previousSibling : n.parentNode)); bgneal@45: bgneal@45: // Find end chop node bgneal@45: n = ec = en; bgneal@45: do { bgneal@45: if (n == b || n.nodeType == 9 || t.dom.isBlock(n) || /(TD|TABLE|TH|CAPTION)/.test(n.nodeName)) bgneal@45: break; bgneal@45: bgneal@45: ec = n; bgneal@45: } while ((n = n.nextSibling ? n.nextSibling : n.parentNode)); bgneal@45: bgneal@45: // Place first chop part into before block element bgneal@45: if (sc.nodeName == bn) bgneal@45: rb.setStart(sc, 0); bgneal@45: else bgneal@45: rb.setStartBefore(sc); bgneal@45: bgneal@45: rb.setEnd(sn, so); bgneal@45: bef.appendChild(rb.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari bgneal@45: bgneal@45: // Place secnd chop part within new block element bgneal@45: try { bgneal@45: ra.setEndAfter(ec); bgneal@45: } catch(ex) { bgneal@45: //console.debug(s.focusNode, s.focusOffset); bgneal@45: } bgneal@45: bgneal@45: ra.setStart(en, eo); bgneal@45: aft.appendChild(ra.cloneContents() || d.createTextNode('')); // Empty text node needed for Safari bgneal@45: bgneal@45: // Create range around everything bgneal@45: r = dom.createRng(); bgneal@45: if (!sc.previousSibling && sc.parentNode.nodeName == bn) { bgneal@45: r.setStartBefore(sc.parentNode); bgneal@45: } else { bgneal@45: if (rb.startContainer.nodeName == bn && rb.startOffset == 0) bgneal@45: r.setStartBefore(rb.startContainer); bgneal@45: else bgneal@45: r.setStart(rb.startContainer, rb.startOffset); bgneal@45: } bgneal@45: bgneal@45: if (!ec.nextSibling && ec.parentNode.nodeName == bn) bgneal@45: r.setEndAfter(ec.parentNode); bgneal@45: else bgneal@45: r.setEnd(ra.endContainer, ra.endOffset); bgneal@45: bgneal@45: if (!isIE || sb != eb || (sb && !dom.isEmpty(sb))) { bgneal@45: r.deleteContents(); bgneal@45: } bgneal@45: bgneal@45: // Remove range end point if it's empty bgneal@45: n = r.startContainer.childNodes[r.startOffset]; bgneal@45: if (n && !n.hasChildNodes()) { bgneal@45: dom.remove(n); bgneal@45: } bgneal@45: bgneal@45: // Never wrap blocks in blocks bgneal@45: if (bef.firstChild && bef.firstChild.nodeName == bn) bgneal@45: bef.innerHTML = bef.firstChild.innerHTML; bgneal@45: bgneal@45: if (aft.firstChild && aft.firstChild.nodeName == bn) bgneal@45: aft.innerHTML = aft.firstChild.innerHTML; bgneal@45: bgneal@45: function appendStyles(e, en) { bgneal@45: var nl = [], nn, n, i, padd; bgneal@45: bgneal@45: // Use BR on W3C browsers and empty string on IE bgneal@45: padd = isIE ? '' : '
    '; bgneal@45: bgneal@45: // Needs to be removed using removeChild since innerHTML adds   on IE bgneal@45: while (e.firstChild) { bgneal@45: e.removeChild(e.firstChild); bgneal@45: } bgneal@45: bgneal@45: // Make clones of style elements bgneal@45: if (se.keep_styles) { bgneal@45: n = en; bgneal@45: do { bgneal@45: // We only want style specific elements bgneal@45: if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(n.nodeName)) { bgneal@45: nn = n.cloneNode(FALSE); bgneal@45: dom.setAttrib(nn, 'id', ''); // Remove ID since it needs to be unique bgneal@45: nl.push(nn); bgneal@45: } bgneal@45: } while (n = n.parentNode); bgneal@45: } bgneal@45: bgneal@45: // Append style elements to aft bgneal@45: if (nl.length > 0) { bgneal@45: for (i = nl.length - 1, nn = e; i >= 0; i--) bgneal@45: nn = nn.appendChild(nl[i]); bgneal@45: bgneal@45: // Padd most inner style element bgneal@45: nl[0].innerHTML = padd; bgneal@45: return nl[0]; // Move caret to most inner element bgneal@45: } else bgneal@45: e.innerHTML = padd; bgneal@45: bgneal@45: return e; bgneal@45: }; bgneal@45: bgneal@45: // IE gets messed up if the elements has empty text nodes in them this might bgneal@45: // happen when the range spits at the end/beginning of a text node. bgneal@45: // @todo: The acutal bug should be fixed in the Range.js file this is a hot patch bgneal@45: if (isIE) { bgneal@45: clean(bef); bgneal@45: clean(aft); bgneal@45: } bgneal@45: bgneal@45: // Padd empty blocks bgneal@45: if (dom.isEmpty(bef)) { bgneal@45: beforeCaretNode = appendStyles(bef, sn); bgneal@45: } bgneal@45: bgneal@45: // Fill empty afterblook with current style bgneal@45: if (dom.isEmpty(aft)) bgneal@45: afterCaretNode = appendStyles(aft, en); bgneal@45: bgneal@45: // Opera needs this one backwards for older versions bgneal@45: if (isOpera && parseFloat(opera.version()) < 9.5) { bgneal@45: r.insertNode(bef); bgneal@45: r.insertNode(aft); bgneal@45: } else { bgneal@45: r.insertNode(aft); bgneal@45: r.insertNode(bef); bgneal@45: } bgneal@45: bgneal@45: // IE doesn't render empty block elements unless you poke it with a selection bgneal@45: // So we need to detect old IE and then move the caret into that block to "render it" bgneal@45: if (selection.tridentSel && beforeCaretNode) { bgneal@45: moveToCaretPosition(beforeCaretNode, false); bgneal@45: } bgneal@45: bgneal@45: moveToCaretPosition(afterCaretNode || aft); bgneal@45: ed.undoManager.add(); bgneal@45: bgneal@45: return FALSE; bgneal@45: }, bgneal@45: bgneal@45: backspaceDelete : function(e, bs) { bgneal@45: 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@45: bgneal@45: // Delete when caret is behind a element doesn't work correctly on Gecko see #3011651 bgneal@45: if (!bs && r.collapsed && sc.nodeType == 1 && r.startOffset == sc.childNodes.length) { bgneal@45: walker = new tinymce.dom.TreeWalker(sc.lastChild, sc); bgneal@45: bgneal@45: // Walk the dom backwards until we find a text node bgneal@45: for (n = sc.lastChild; n; n = walker.prev()) { bgneal@45: if (n.nodeType == 3) { bgneal@45: r.setStart(n, n.nodeValue.length); bgneal@45: r.collapse(true); bgneal@45: se.setRng(r); bgneal@45: return; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // The caret sometimes gets stuck in Gecko if you delete empty paragraphs bgneal@45: // This workaround removes the element by hand and moves the caret to the previous element bgneal@45: if (sc && ed.dom.isBlock(sc) && !/^(TD|TH)$/.test(sc.nodeName) && bs) { bgneal@45: if (sc.childNodes.length == 0 || (sc.childNodes.length == 1 && sc.firstChild.nodeName == 'BR')) { bgneal@45: // Find previous block element bgneal@45: n = sc; bgneal@45: while ((n = n.previousSibling) && !ed.dom.isBlock(n)) ; bgneal@45: bgneal@45: if (n) { bgneal@45: if (sc != b.firstChild) { bgneal@45: // Find last text node bgneal@45: w = ed.dom.doc.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, FALSE); bgneal@45: while (tn = w.nextNode()) bgneal@45: n = tn; bgneal@45: bgneal@45: // Place caret at the end of last text node bgneal@45: r = ed.getDoc().createRange(); bgneal@45: r.setStart(n, n.nodeValue ? n.nodeValue.length : 0); bgneal@45: r.setEnd(n, n.nodeValue ? n.nodeValue.length : 0); bgneal@45: se.setRng(r); bgneal@45: bgneal@45: // Remove the target container bgneal@45: ed.dom.remove(sc); bgneal@45: } bgneal@45: bgneal@45: return Event.cancel(e); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: // Shorten names bgneal@45: var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend; bgneal@45: bgneal@45: tinymce.create('tinymce.ControlManager', { bgneal@45: ControlManager : function(ed, s) { bgneal@45: var t = this, i; bgneal@45: bgneal@45: s = s || {}; bgneal@45: t.editor = ed; bgneal@45: t.controls = {}; bgneal@45: t.onAdd = new tinymce.util.Dispatcher(t); bgneal@45: t.onPostRender = new tinymce.util.Dispatcher(t); bgneal@45: t.prefix = s.prefix || ed.id + '_'; bgneal@45: t._cls = {}; bgneal@45: bgneal@45: t.onPostRender.add(function() { bgneal@45: each(t.controls, function(c) { bgneal@45: c.postRender(); bgneal@45: }); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: get : function(id) { bgneal@45: return this.controls[this.prefix + id] || this.controls[id]; bgneal@45: }, bgneal@45: bgneal@45: setActive : function(id, s) { bgneal@45: var c = null; bgneal@45: bgneal@45: if (c = this.get(id)) bgneal@45: c.setActive(s); bgneal@45: bgneal@45: return c; bgneal@45: }, bgneal@45: bgneal@45: setDisabled : function(id, s) { bgneal@45: var c = null; bgneal@45: bgneal@45: if (c = this.get(id)) bgneal@45: c.setDisabled(s); bgneal@45: bgneal@45: return c; bgneal@45: }, bgneal@45: bgneal@45: add : function(c) { bgneal@45: var t = this; bgneal@45: bgneal@45: if (c) { bgneal@45: t.controls[c.id] = c; bgneal@45: t.onAdd.dispatch(c, t); bgneal@45: } bgneal@45: bgneal@45: return c; bgneal@45: }, bgneal@45: bgneal@45: createControl : function(n) { bgneal@45: var c, t = this, ed = t.editor; bgneal@45: bgneal@45: each(ed.plugins, function(p) { bgneal@45: if (p.createControl) { bgneal@45: c = p.createControl(n, t); bgneal@45: bgneal@45: if (c) bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: switch (n) { bgneal@45: case "|": bgneal@45: case "separator": bgneal@45: return t.createSeparator(); bgneal@45: } bgneal@45: bgneal@45: if (!c && ed.buttons && (c = ed.buttons[n])) bgneal@45: return t.createButton(n, c); bgneal@45: bgneal@45: return t.add(c); bgneal@45: }, bgneal@45: bgneal@45: createDropMenu : function(id, s, cc) { bgneal@45: var t = this, ed = t.editor, c, bm, v, cls; bgneal@45: bgneal@45: s = extend({ bgneal@45: 'class' : 'mceDropDown', bgneal@45: constrain : ed.settings.constrain_menus bgneal@45: }, s); bgneal@45: bgneal@45: s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin'; bgneal@45: if (v = ed.getParam('skin_variant')) bgneal@45: s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1); bgneal@45: bgneal@45: id = t.prefix + id; bgneal@45: cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu; bgneal@45: c = t.controls[id] = new cls(id, s); bgneal@45: c.onAddItem.add(function(c, o) { bgneal@45: var s = o.settings; bgneal@45: bgneal@45: s.title = ed.getLang(s.title, s.title); bgneal@45: bgneal@45: if (!s.onclick) { bgneal@45: s.onclick = function(v) { bgneal@45: if (s.cmd) bgneal@45: ed.execCommand(s.cmd, s.ui || false, s.value); bgneal@45: }; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: ed.onRemove.add(function() { bgneal@45: c.destroy(); bgneal@45: }); bgneal@45: bgneal@45: // Fix for bug #1897785, #1898007 bgneal@45: if (tinymce.isIE) { bgneal@45: c.onShowMenu.add(function() { bgneal@45: // IE 8 needs focus in order to store away a range with the current collapsed caret location bgneal@45: ed.focus(); bgneal@45: bgneal@45: bm = ed.selection.getBookmark(1); bgneal@45: }); bgneal@45: bgneal@45: c.onHideMenu.add(function() { bgneal@45: if (bm) { bgneal@45: ed.selection.moveToBookmark(bm); bgneal@45: bm = 0; bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: return t.add(c); bgneal@45: }, bgneal@45: bgneal@45: createListBox : function(id, s, cc) { bgneal@45: var t = this, ed = t.editor, cmd, c, cls; bgneal@45: bgneal@45: if (t.get(id)) bgneal@45: return null; bgneal@45: bgneal@45: s.title = ed.translate(s.title); bgneal@45: s.scope = s.scope || ed; bgneal@45: bgneal@45: if (!s.onselect) { bgneal@45: s.onselect = function(v) { bgneal@45: ed.execCommand(s.cmd, s.ui || false, v || s.value); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: s = extend({ bgneal@45: title : s.title, bgneal@45: 'class' : 'mce_' + id, bgneal@45: scope : s.scope, bgneal@45: control_manager : t bgneal@45: }, s); bgneal@45: bgneal@45: id = t.prefix + id; bgneal@45: bgneal@45: bgneal@45: function useNativeListForAccessibility(ed) { bgneal@45: return ed.settings.use_accessible_selects && !tinymce.isGecko bgneal@45: } bgneal@45: bgneal@45: if (ed.settings.use_native_selects || useNativeListForAccessibility(ed)) bgneal@45: c = new tinymce.ui.NativeListBox(id, s); bgneal@45: else { bgneal@45: cls = cc || t._cls.listbox || tinymce.ui.ListBox; bgneal@45: c = new cls(id, s, ed); bgneal@45: } bgneal@45: bgneal@45: t.controls[id] = c; bgneal@45: bgneal@45: // Fix focus problem in Safari bgneal@45: if (tinymce.isWebKit) { bgneal@45: c.onPostRender.add(function(c, n) { bgneal@45: // Store bookmark on mousedown bgneal@45: Event.add(n, 'mousedown', function() { bgneal@45: ed.bookmark = ed.selection.getBookmark(1); bgneal@45: }); bgneal@45: bgneal@45: // Restore on focus, since it might be lost bgneal@45: Event.add(n, 'focus', function() { bgneal@45: ed.selection.moveToBookmark(ed.bookmark); bgneal@45: ed.bookmark = null; bgneal@45: }); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (c.hideMenu) bgneal@45: ed.onMouseDown.add(c.hideMenu, c); bgneal@45: bgneal@45: return t.add(c); bgneal@45: }, bgneal@45: bgneal@45: createButton : function(id, s, cc) { bgneal@45: var t = this, ed = t.editor, o, c, cls; bgneal@45: bgneal@45: if (t.get(id)) bgneal@45: return null; bgneal@45: bgneal@45: s.title = ed.translate(s.title); bgneal@45: s.label = ed.translate(s.label); bgneal@45: s.scope = s.scope || ed; bgneal@45: bgneal@45: if (!s.onclick && !s.menu_button) { bgneal@45: s.onclick = function() { bgneal@45: ed.execCommand(s.cmd, s.ui || false, s.value); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: s = extend({ bgneal@45: title : s.title, bgneal@45: 'class' : 'mce_' + id, bgneal@45: unavailable_prefix : ed.getLang('unavailable', ''), bgneal@45: scope : s.scope, bgneal@45: control_manager : t bgneal@45: }, s); bgneal@45: bgneal@45: id = t.prefix + id; bgneal@45: bgneal@45: if (s.menu_button) { bgneal@45: cls = cc || t._cls.menubutton || tinymce.ui.MenuButton; bgneal@45: c = new cls(id, s, ed); bgneal@45: ed.onMouseDown.add(c.hideMenu, c); bgneal@45: } else { bgneal@45: cls = t._cls.button || tinymce.ui.Button; bgneal@45: c = new cls(id, s, ed); bgneal@45: } bgneal@45: bgneal@45: return t.add(c); bgneal@45: }, bgneal@45: bgneal@45: createMenuButton : function(id, s, cc) { bgneal@45: s = s || {}; bgneal@45: s.menu_button = 1; bgneal@45: bgneal@45: return this.createButton(id, s, cc); bgneal@45: }, bgneal@45: bgneal@45: createSplitButton : function(id, s, cc) { bgneal@45: var t = this, ed = t.editor, cmd, c, cls; bgneal@45: bgneal@45: if (t.get(id)) bgneal@45: return null; bgneal@45: bgneal@45: s.title = ed.translate(s.title); bgneal@45: s.scope = s.scope || ed; bgneal@45: bgneal@45: if (!s.onclick) { bgneal@45: s.onclick = function(v) { bgneal@45: ed.execCommand(s.cmd, s.ui || false, v || s.value); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: if (!s.onselect) { bgneal@45: s.onselect = function(v) { bgneal@45: ed.execCommand(s.cmd, s.ui || false, v || s.value); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: s = extend({ bgneal@45: title : s.title, bgneal@45: 'class' : 'mce_' + id, bgneal@45: scope : s.scope, bgneal@45: control_manager : t bgneal@45: }, s); bgneal@45: bgneal@45: id = t.prefix + id; bgneal@45: cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton; bgneal@45: c = t.add(new cls(id, s, ed)); bgneal@45: ed.onMouseDown.add(c.hideMenu, c); bgneal@45: bgneal@45: return c; bgneal@45: }, bgneal@45: bgneal@45: createColorSplitButton : function(id, s, cc) { bgneal@45: var t = this, ed = t.editor, cmd, c, cls, bm; bgneal@45: bgneal@45: if (t.get(id)) bgneal@45: return null; bgneal@45: bgneal@45: s.title = ed.translate(s.title); bgneal@45: s.scope = s.scope || ed; bgneal@45: bgneal@45: if (!s.onclick) { bgneal@45: s.onclick = function(v) { bgneal@45: if (tinymce.isIE) bgneal@45: bm = ed.selection.getBookmark(1); bgneal@45: bgneal@45: ed.execCommand(s.cmd, s.ui || false, v || s.value); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: if (!s.onselect) { bgneal@45: s.onselect = function(v) { bgneal@45: ed.execCommand(s.cmd, s.ui || false, v || s.value); bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: s = extend({ bgneal@45: title : s.title, bgneal@45: 'class' : 'mce_' + id, bgneal@45: 'menu_class' : ed.getParam('skin') + 'Skin', bgneal@45: scope : s.scope, bgneal@45: more_colors_title : ed.getLang('more_colors') bgneal@45: }, s); bgneal@45: bgneal@45: id = t.prefix + id; bgneal@45: cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton; bgneal@45: c = new cls(id, s, ed); bgneal@45: ed.onMouseDown.add(c.hideMenu, c); bgneal@45: bgneal@45: // Remove the menu element when the editor is removed bgneal@45: ed.onRemove.add(function() { bgneal@45: c.destroy(); bgneal@45: }); bgneal@45: bgneal@45: // Fix for bug #1897785, #1898007 bgneal@45: if (tinymce.isIE) { bgneal@45: c.onShowMenu.add(function() { bgneal@45: // IE 8 needs focus in order to store away a range with the current collapsed caret location bgneal@45: ed.focus(); bgneal@45: bm = ed.selection.getBookmark(1); bgneal@45: }); bgneal@45: bgneal@45: c.onHideMenu.add(function() { bgneal@45: if (bm) { bgneal@45: ed.selection.moveToBookmark(bm); bgneal@45: bm = 0; bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: return t.add(c); bgneal@45: }, bgneal@45: bgneal@45: createToolbar : function(id, s, cc) { bgneal@45: var c, t = this, cls; bgneal@45: bgneal@45: id = t.prefix + id; bgneal@45: cls = cc || t._cls.toolbar || tinymce.ui.Toolbar; bgneal@45: c = new cls(id, s, t.editor); bgneal@45: bgneal@45: if (t.get(id)) bgneal@45: return null; bgneal@45: bgneal@45: return t.add(c); bgneal@45: }, bgneal@45: bgneal@45: createToolbarGroup : function(id, s, cc) { bgneal@45: var c, t = this, cls; bgneal@45: id = t.prefix + id; bgneal@45: cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup; bgneal@45: c = new cls(id, s, t.editor); bgneal@45: bgneal@45: if (t.get(id)) bgneal@45: return null; bgneal@45: bgneal@45: return t.add(c); bgneal@45: }, bgneal@45: bgneal@45: createSeparator : function(cc) { bgneal@45: var cls = cc || this._cls.separator || tinymce.ui.Separator; bgneal@45: bgneal@45: return new cls(); bgneal@45: }, bgneal@45: bgneal@45: setControlType : function(n, c) { bgneal@45: return this._cls[n.toLowerCase()] = c; bgneal@45: }, bgneal@45: bgneal@45: destroy : function() { bgneal@45: each(this.controls, function(c) { bgneal@45: c.destroy(); bgneal@45: }); bgneal@45: bgneal@45: this.controls = null; bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@45: var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera; bgneal@45: bgneal@45: tinymce.create('tinymce.WindowManager', { bgneal@45: WindowManager : function(ed) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.editor = ed; bgneal@45: t.onOpen = new Dispatcher(t); bgneal@45: t.onClose = new Dispatcher(t); bgneal@45: t.params = {}; bgneal@45: t.features = {}; bgneal@45: }, bgneal@45: bgneal@45: open : function(s, p) { bgneal@45: var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u; bgneal@45: bgneal@45: // Default some options bgneal@45: s = s || {}; bgneal@45: p = p || {}; bgneal@45: sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window bgneal@45: sh = isOpera ? vp.h : screen.height; bgneal@45: s.name = s.name || 'mc_' + new Date().getTime(); bgneal@45: s.width = parseInt(s.width || 320); bgneal@45: s.height = parseInt(s.height || 240); bgneal@45: s.resizable = true; bgneal@45: s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0); bgneal@45: s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0); bgneal@45: p.inline = false; bgneal@45: p.mce_width = s.width; bgneal@45: p.mce_height = s.height; bgneal@45: p.mce_auto_focus = s.auto_focus; bgneal@45: bgneal@45: if (mo) { bgneal@45: if (isIE) { bgneal@45: s.center = true; bgneal@45: s.help = false; bgneal@45: s.dialogWidth = s.width + 'px'; bgneal@45: s.dialogHeight = s.height + 'px'; bgneal@45: s.scroll = s.scrollbars || false; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Build features string bgneal@45: each(s, function(v, k) { bgneal@45: if (tinymce.is(v, 'boolean')) bgneal@45: v = v ? 'yes' : 'no'; bgneal@45: bgneal@45: if (!/^(name|url)$/.test(k)) { bgneal@45: if (isIE && mo) bgneal@45: f += (f ? ';' : '') + k + ':' + v; bgneal@45: else bgneal@45: f += (f ? ',' : '') + k + '=' + v; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: t.features = s; bgneal@45: t.params = p; bgneal@45: t.onOpen.dispatch(t, s, p); bgneal@45: bgneal@45: u = s.url || s.file; bgneal@45: u = tinymce._addVer(u); bgneal@45: bgneal@45: try { bgneal@45: if (isIE && mo) { bgneal@45: w = 1; bgneal@45: window.showModalDialog(u, window, f); bgneal@45: } else bgneal@45: w = window.open(u, s.name, f); bgneal@45: } catch (ex) { bgneal@45: // Ignore bgneal@45: } bgneal@45: bgneal@45: if (!w) bgneal@45: alert(t.editor.getLang('popup_blocked')); bgneal@45: }, bgneal@45: bgneal@45: close : function(w) { bgneal@45: w.close(); bgneal@45: this.onClose.dispatch(this); bgneal@45: }, bgneal@45: bgneal@45: createInstance : function(cl, a, b, c, d, e) { bgneal@45: var f = tinymce.resolve(cl); bgneal@45: bgneal@45: return new f(a, b, c, d, e); bgneal@45: }, bgneal@45: bgneal@45: confirm : function(t, cb, s, w) { bgneal@45: w = w || window; bgneal@45: bgneal@45: cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t)))); bgneal@45: }, bgneal@45: bgneal@45: alert : function(tx, cb, s, w) { bgneal@45: var t = this; bgneal@45: bgneal@45: w = w || window; bgneal@45: w.alert(t._decode(t.editor.getLang(tx, tx))); bgneal@45: bgneal@45: if (cb) bgneal@45: cb.call(s || t); bgneal@45: }, bgneal@45: bgneal@45: resizeBy : function(dw, dh, win) { bgneal@45: win.resizeBy(dw, dh); bgneal@45: }, bgneal@45: bgneal@45: // Internal functions bgneal@45: bgneal@45: _decode : function(s) { bgneal@45: return tinymce.DOM.decode(s).replace(/\\n/g, '\n'); bgneal@45: } bgneal@45: }); bgneal@45: }(tinymce)); bgneal@45: (function(tinymce) { bgneal@45: tinymce.Formatter = function(ed) { bgneal@45: var formats = {}, bgneal@45: each = tinymce.each, bgneal@45: dom = ed.dom, bgneal@45: selection = ed.selection, bgneal@45: TreeWalker = tinymce.dom.TreeWalker, bgneal@45: rangeUtils = new tinymce.dom.RangeUtils(dom), bgneal@45: isValid = ed.schema.isValidChild, bgneal@45: isBlock = dom.isBlock, bgneal@45: forcedRootBlock = ed.settings.forced_root_block, bgneal@45: nodeIndex = dom.nodeIndex, bgneal@45: INVISIBLE_CHAR = tinymce.isGecko ? '\u200B' : '\uFEFF', bgneal@45: MCE_ATTR_RE = /^(src|href|style)$/, bgneal@45: FALSE = false, bgneal@45: TRUE = true, bgneal@45: undefined; bgneal@45: bgneal@45: // Returns the content editable state of a node bgneal@45: function getContentEditable(node) { bgneal@45: var contentEditable = node.getAttribute("data-mce-contenteditable"); bgneal@45: bgneal@45: // Check for fake content editable bgneal@45: if (contentEditable && contentEditable !== "inherit") { bgneal@45: return contentEditable; bgneal@45: } bgneal@45: bgneal@45: // Check for real content editable bgneal@45: return node.contentEditable !== "inherit" ? node.contentEditable : null; bgneal@45: }; bgneal@45: bgneal@45: function isArray(obj) { bgneal@45: return obj instanceof Array; bgneal@45: }; bgneal@45: bgneal@45: function getParents(node, selector) { bgneal@45: return dom.getParents(node, selector, dom.getRoot()); bgneal@45: }; bgneal@45: bgneal@45: function isCaretNode(node) { bgneal@45: return node.nodeType === 1 && node.id === '_mce_caret'; bgneal@45: }; bgneal@45: bgneal@45: // Public functions bgneal@45: bgneal@45: function get(name) { bgneal@45: return name ? formats[name] : formats; bgneal@45: }; bgneal@45: bgneal@45: function register(name, format) { bgneal@45: if (name) { bgneal@45: if (typeof(name) !== 'string') { bgneal@45: each(name, function(format, name) { bgneal@45: register(name, format); bgneal@45: }); bgneal@45: } else { bgneal@45: // Force format into array and add it to internal collection bgneal@45: format = format.length ? format : [format]; bgneal@45: bgneal@45: each(format, function(format) { bgneal@45: // Set deep to false by default on selector formats this to avoid removing bgneal@45: // alignment on images inside paragraphs when alignment is changed on paragraphs bgneal@45: if (format.deep === undefined) bgneal@45: format.deep = !format.selector; bgneal@45: bgneal@45: // Default to true bgneal@45: if (format.split === undefined) bgneal@45: format.split = !format.selector || format.inline; bgneal@45: bgneal@45: // Default to true bgneal@45: if (format.remove === undefined && format.selector && !format.inline) bgneal@45: format.remove = 'none'; bgneal@45: bgneal@45: // Mark format as a mixed format inline + block level bgneal@45: if (format.selector && format.inline) { bgneal@45: format.mixed = true; bgneal@45: format.block_expand = true; bgneal@45: } bgneal@45: bgneal@45: // Split classes if needed bgneal@45: if (typeof(format.classes) === 'string') bgneal@45: format.classes = format.classes.split(/\s+/); bgneal@45: }); bgneal@45: bgneal@45: formats[name] = format; bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: var getTextDecoration = function(node) { bgneal@45: var decoration; bgneal@45: bgneal@45: ed.dom.getParent(node, function(n) { bgneal@45: decoration = ed.dom.getStyle(n, 'text-decoration'); bgneal@45: return decoration && decoration !== 'none'; bgneal@45: }); bgneal@45: bgneal@45: return decoration; bgneal@45: }; bgneal@45: bgneal@45: var processUnderlineAndColor = function(node) { bgneal@45: var textDecoration; bgneal@45: if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) { bgneal@45: textDecoration = getTextDecoration(node.parentNode); bgneal@45: if (ed.dom.getStyle(node, 'color') && textDecoration) { bgneal@45: ed.dom.setStyle(node, 'text-decoration', textDecoration); bgneal@45: } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) { bgneal@45: ed.dom.setStyle(node, 'text-decoration', null); bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function apply(name, vars, node) { bgneal@45: var formatList = get(name), format = formatList[0], bookmark, rng, i, isCollapsed = selection.isCollapsed(); bgneal@45: bgneal@45: function setElementFormat(elm, fmt) { bgneal@45: fmt = fmt || format; bgneal@45: bgneal@45: if (elm) { bgneal@45: if (fmt.onformat) { bgneal@45: fmt.onformat(elm, fmt, vars, node); bgneal@45: } bgneal@45: bgneal@45: each(fmt.styles, function(value, name) { bgneal@45: dom.setStyle(elm, name, replaceVars(value, vars)); bgneal@45: }); bgneal@45: bgneal@45: each(fmt.attributes, function(value, name) { bgneal@45: dom.setAttrib(elm, name, replaceVars(value, vars)); bgneal@45: }); bgneal@45: bgneal@45: each(fmt.classes, function(value) { bgneal@45: value = replaceVars(value, vars); bgneal@45: bgneal@45: if (!dom.hasClass(elm, value)) bgneal@45: dom.addClass(elm, value); bgneal@45: }); bgneal@45: } bgneal@45: }; bgneal@45: function adjustSelectionToVisibleSelection() { bgneal@45: function findSelectionEnd(start, end) { bgneal@45: var walker = new TreeWalker(end); bgneal@45: for (node = walker.current(); node; node = walker.prev()) { bgneal@45: if (node.childNodes.length > 1 || node == start) { bgneal@45: return node; bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Adjust selection so that a end container with a end offset of zero is not included in the selection bgneal@45: // as this isn't visible to the user. bgneal@45: var rng = ed.selection.getRng(); bgneal@45: var start = rng.startContainer; bgneal@45: var end = rng.endContainer; bgneal@45: bgneal@45: if (start != end && rng.endOffset == 0) { bgneal@45: var newEnd = findSelectionEnd(start, end); bgneal@45: var endOffset = newEnd.nodeType == 3 ? newEnd.length : newEnd.childNodes.length; bgneal@45: bgneal@45: rng.setEnd(newEnd, endOffset); bgneal@45: } bgneal@45: bgneal@45: return rng; bgneal@45: } bgneal@45: bgneal@45: function applyStyleToList(node, bookmark, wrapElm, newWrappers, process){ bgneal@45: var nodes = [], listIndex = -1, list, startIndex = -1, endIndex = -1, currentWrapElm; bgneal@45: bgneal@45: // find the index of the first child list. bgneal@45: each(node.childNodes, function(n, index) { bgneal@45: if (n.nodeName === "UL" || n.nodeName === "OL") { bgneal@45: listIndex = index; bgneal@45: list = n; bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // get the index of the bookmarks bgneal@45: each(node.childNodes, function(n, index) { bgneal@45: if (n.nodeName === "SPAN" && dom.getAttrib(n, "data-mce-type") == "bookmark") { bgneal@45: if (n.id == bookmark.id + "_start") { bgneal@45: startIndex = index; bgneal@45: } else if (n.id == bookmark.id + "_end") { bgneal@45: endIndex = index; bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // if the selection spans across an embedded list, or there isn't an embedded list - handle processing normally bgneal@45: if (listIndex <= 0 || (startIndex < listIndex && endIndex > listIndex)) { bgneal@45: each(tinymce.grep(node.childNodes), process); bgneal@45: return 0; bgneal@45: } else { bgneal@45: currentWrapElm = dom.clone(wrapElm, FALSE); bgneal@45: bgneal@45: // create a list of the nodes on the same side of the list as the selection bgneal@45: each(tinymce.grep(node.childNodes), function(n, index) { bgneal@45: if ((startIndex < listIndex && index < listIndex) || (startIndex > listIndex && index > listIndex)) { bgneal@45: nodes.push(n); bgneal@45: n.parentNode.removeChild(n); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // insert the wrapping element either before or after the list. bgneal@45: if (startIndex < listIndex) { bgneal@45: node.insertBefore(currentWrapElm, list); bgneal@45: } else if (startIndex > listIndex) { bgneal@45: node.insertBefore(currentWrapElm, list.nextSibling); bgneal@45: } bgneal@45: bgneal@45: // add the new nodes to the list. bgneal@45: newWrappers.push(currentWrapElm); bgneal@45: bgneal@45: each(nodes, function(node) { bgneal@45: currentWrapElm.appendChild(node); bgneal@45: }); bgneal@45: bgneal@45: return currentWrapElm; bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function applyRngStyle(rng, bookmark, node_specific) { bgneal@45: var newWrappers = [], wrapName, wrapElm, contentEditable = true; bgneal@45: bgneal@45: // Setup wrapper element bgneal@45: wrapName = format.inline || format.block; bgneal@45: wrapElm = dom.create(wrapName); bgneal@45: setElementFormat(wrapElm); bgneal@45: bgneal@45: rangeUtils.walk(rng, function(nodes) { bgneal@45: var currentWrapElm; bgneal@45: bgneal@45: function process(node) { bgneal@45: var nodeName, parentName, found, hasContentEditableState, lastContentEditable; bgneal@45: bgneal@45: lastContentEditable = contentEditable; bgneal@45: nodeName = node.nodeName.toLowerCase(); bgneal@45: parentName = node.parentNode.nodeName.toLowerCase(); bgneal@45: bgneal@45: // Node has a contentEditable value bgneal@45: if (node.nodeType === 1 && getContentEditable(node)) { bgneal@45: lastContentEditable = contentEditable; bgneal@45: contentEditable = getContentEditable(node) === "true"; bgneal@45: hasContentEditableState = true; // We don't want to wrap the container only it's children bgneal@45: } bgneal@45: bgneal@45: // Stop wrapping on br elements bgneal@45: if (isEq(nodeName, 'br')) { bgneal@45: currentWrapElm = 0; bgneal@45: bgneal@45: // Remove any br elements when we wrap things bgneal@45: if (format.block) bgneal@45: dom.remove(node); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // If node is wrapper type bgneal@45: if (format.wrapper && matchNode(node, name, vars)) { bgneal@45: currentWrapElm = 0; bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Can we rename the block bgneal@45: if (contentEditable && !hasContentEditableState && format.block && !format.wrapper && isTextBlock(nodeName)) { bgneal@45: node = dom.rename(node, wrapName); bgneal@45: setElementFormat(node); bgneal@45: newWrappers.push(node); bgneal@45: currentWrapElm = 0; bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Handle selector patterns bgneal@45: if (format.selector) { bgneal@45: // Look for matching formats bgneal@45: each(formatList, function(format) { bgneal@45: // Check collapsed state if it exists bgneal@45: if ('collapsed' in format && format.collapsed !== isCollapsed) { bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: if (dom.is(node, format.selector) && !isCaretNode(node)) { bgneal@45: setElementFormat(node, format); bgneal@45: found = true; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Continue processing if a selector match wasn't found and a inline element is defined bgneal@45: if (!format.inline || found) { bgneal@45: currentWrapElm = 0; bgneal@45: return; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Is it valid to wrap this item bgneal@45: if (contentEditable && !hasContentEditableState && isValid(wrapName, nodeName) && isValid(parentName, wrapName) && bgneal@45: !(!node_specific && node.nodeType === 3 && node.nodeValue.length === 1 && node.nodeValue.charCodeAt(0) === 65279) && !isCaretNode(node)) { bgneal@45: // Start wrapping bgneal@45: if (!currentWrapElm) { bgneal@45: // Wrap the node bgneal@45: currentWrapElm = dom.clone(wrapElm, FALSE); bgneal@45: node.parentNode.insertBefore(currentWrapElm, node); bgneal@45: newWrappers.push(currentWrapElm); bgneal@45: } bgneal@45: bgneal@45: currentWrapElm.appendChild(node); bgneal@45: } else if (nodeName == 'li' && bookmark) { bgneal@45: // Start wrapping - if we are in a list node and have a bookmark, then we will always begin by wrapping in a new element. bgneal@45: currentWrapElm = applyStyleToList(node, bookmark, wrapElm, newWrappers, process); bgneal@45: } else { bgneal@45: // Start a new wrapper for possible children bgneal@45: currentWrapElm = 0; bgneal@45: bgneal@45: each(tinymce.grep(node.childNodes), process); bgneal@45: bgneal@45: if (hasContentEditableState) { bgneal@45: contentEditable = lastContentEditable; // Restore last contentEditable state from stack bgneal@45: } bgneal@45: bgneal@45: // End the last wrapper bgneal@45: currentWrapElm = 0; bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Process siblings from range bgneal@45: each(nodes, process); bgneal@45: }); bgneal@45: bgneal@45: // Wrap links inside as well, for example color inside a link when the wrapper is around the link bgneal@45: if (format.wrap_links === false) { bgneal@45: each(newWrappers, function(node) { bgneal@45: function process(node) { bgneal@45: var i, currentWrapElm, children; bgneal@45: bgneal@45: if (node.nodeName === 'A') { bgneal@45: currentWrapElm = dom.clone(wrapElm, FALSE); bgneal@45: newWrappers.push(currentWrapElm); bgneal@45: bgneal@45: children = tinymce.grep(node.childNodes); bgneal@45: for (i = 0; i < children.length; i++) bgneal@45: currentWrapElm.appendChild(children[i]); bgneal@45: bgneal@45: node.appendChild(currentWrapElm); bgneal@45: } bgneal@45: bgneal@45: each(tinymce.grep(node.childNodes), process); bgneal@45: }; bgneal@45: bgneal@45: process(node); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // Cleanup bgneal@45: bgneal@45: each(newWrappers, function(node) { bgneal@45: var childCount; bgneal@45: bgneal@45: function getChildCount(node) { bgneal@45: var count = 0; bgneal@45: bgneal@45: each(node.childNodes, function(node) { bgneal@45: if (!isWhiteSpaceNode(node) && !isBookmarkNode(node)) bgneal@45: count++; bgneal@45: }); bgneal@45: bgneal@45: return count; bgneal@45: }; bgneal@45: bgneal@45: function mergeStyles(node) { bgneal@45: var child, clone; bgneal@45: bgneal@45: each(node.childNodes, function(node) { bgneal@45: if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) { bgneal@45: child = node; bgneal@45: return FALSE; // break loop bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // If child was found and of the same type as the current node bgneal@45: if (child && matchName(child, format)) { bgneal@45: clone = dom.clone(child, FALSE); bgneal@45: setElementFormat(clone); bgneal@45: bgneal@45: dom.replace(clone, node, TRUE); bgneal@45: dom.remove(child, 1); bgneal@45: } bgneal@45: bgneal@45: return clone || node; bgneal@45: }; bgneal@45: bgneal@45: childCount = getChildCount(node); bgneal@45: bgneal@45: // Remove empty nodes but only if there is multiple wrappers and they are not block bgneal@45: // elements so never remove single

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

    *texttext*

    ! bgneal@45: // This will reduce the number of wrapper elements that needs to be created bgneal@45: // Move start point up the tree bgneal@45: if (format[0].inline || format[0].block_expand) { bgneal@45: if (!format[0].inline || (startContainer.nodeType != 3 || startOffset === 0)) { bgneal@45: startContainer = findParentContainer(true); bgneal@45: } bgneal@45: bgneal@45: if (!format[0].inline || (endContainer.nodeType != 3 || endOffset === endContainer.nodeValue.length)) { bgneal@45: endContainer = findParentContainer(); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Expand start/end container to matching selector bgneal@45: if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) { bgneal@45: function findSelectorEndPoint(container, sibling_name) { bgneal@45: var parents, i, y, curFormat; bgneal@45: bgneal@45: if (container.nodeType == 3 && container.nodeValue.length == 0 && container[sibling_name]) bgneal@45: container = container[sibling_name]; bgneal@45: bgneal@45: parents = getParents(container); bgneal@45: for (i = 0; i < parents.length; i++) { bgneal@45: for (y = 0; y < format.length; y++) { bgneal@45: curFormat = format[y]; bgneal@45: bgneal@45: // If collapsed state is set then skip formats that doesn't match that bgneal@45: if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed) bgneal@45: continue; bgneal@45: bgneal@45: if (dom.is(parents[i], curFormat.selector)) bgneal@45: return parents[i]; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return container; bgneal@45: }; bgneal@45: bgneal@45: // Find new startContainer/endContainer if there is better one bgneal@45: startContainer = findSelectorEndPoint(startContainer, 'previousSibling'); bgneal@45: endContainer = findSelectorEndPoint(endContainer, 'nextSibling'); bgneal@45: } bgneal@45: bgneal@45: // Expand start/end container to matching block element or text node bgneal@45: if (format[0].block || format[0].selector) { bgneal@45: function findBlockEndPoint(container, sibling_name, sibling_name2) { bgneal@45: var node; bgneal@45: bgneal@45: // Expand to block of similar type bgneal@45: if (!format[0].wrapper) bgneal@45: node = dom.getParent(container, format[0].block); bgneal@45: bgneal@45: // Expand to first wrappable block element or any block element bgneal@45: if (!node) bgneal@45: node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, isBlock); bgneal@45: bgneal@45: // Exclude inner lists from wrapping bgneal@45: if (node && format[0].wrapper) bgneal@45: node = getParents(node, 'ul,ol').reverse()[0] || node; bgneal@45: bgneal@45: // Didn't find a block element look for first/last wrappable element bgneal@45: if (!node) { bgneal@45: node = container; bgneal@45: bgneal@45: while (node[sibling_name] && !isBlock(node[sibling_name])) { bgneal@45: node = node[sibling_name]; bgneal@45: bgneal@45: // Break on BR but include it will be removed later on bgneal@45: // we can't remove it now since we need to check if it can be wrapped bgneal@45: if (isEq(node, 'br')) bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return node || container; bgneal@45: }; bgneal@45: bgneal@45: // Find new startContainer/endContainer if there is better one bgneal@45: startContainer = findBlockEndPoint(startContainer, 'previousSibling'); bgneal@45: endContainer = findBlockEndPoint(endContainer, 'nextSibling'); bgneal@45: bgneal@45: // Non block element then try to expand up the leaf bgneal@45: if (format[0].block) { bgneal@45: if (!isBlock(startContainer)) bgneal@45: startContainer = findParentContainer(true); bgneal@45: bgneal@45: if (!isBlock(endContainer)) bgneal@45: endContainer = findParentContainer(); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Setup index for startContainer bgneal@45: if (startContainer.nodeType == 1) { bgneal@45: startOffset = nodeIndex(startContainer); bgneal@45: startContainer = startContainer.parentNode; bgneal@45: } bgneal@45: bgneal@45: // Setup index for endContainer bgneal@45: if (endContainer.nodeType == 1) { bgneal@45: endOffset = nodeIndex(endContainer) + 1; bgneal@45: endContainer = endContainer.parentNode; bgneal@45: } bgneal@45: bgneal@45: // Return new range like object bgneal@45: return { bgneal@45: startContainer : startContainer, bgneal@45: startOffset : startOffset, bgneal@45: endContainer : endContainer, bgneal@45: endOffset : endOffset bgneal@45: }; bgneal@45: } bgneal@45: bgneal@45: function removeFormat(format, vars, node, compare_node) { bgneal@45: var i, attrs, stylesModified; bgneal@45: bgneal@45: // Check if node matches format bgneal@45: if (!matchName(node, format)) bgneal@45: return FALSE; bgneal@45: bgneal@45: // Should we compare with format attribs and styles bgneal@45: if (format.remove != 'all') { bgneal@45: // Remove styles bgneal@45: each(format.styles, function(value, name) { bgneal@45: value = replaceVars(value, vars); bgneal@45: bgneal@45: // Indexed array bgneal@45: if (typeof(name) === 'number') { bgneal@45: name = value; bgneal@45: compare_node = 0; bgneal@45: } bgneal@45: bgneal@45: if (!compare_node || isEq(getStyle(compare_node, name), value)) bgneal@45: dom.setStyle(node, name, ''); bgneal@45: bgneal@45: stylesModified = 1; bgneal@45: }); bgneal@45: bgneal@45: // Remove style attribute if it's empty bgneal@45: if (stylesModified && dom.getAttrib(node, 'style') == '') { bgneal@45: node.removeAttribute('style'); bgneal@45: node.removeAttribute('data-mce-style'); bgneal@45: } bgneal@45: bgneal@45: // Remove attributes bgneal@45: each(format.attributes, function(value, name) { bgneal@45: var valueOut; bgneal@45: bgneal@45: value = replaceVars(value, vars); bgneal@45: bgneal@45: // Indexed array bgneal@45: if (typeof(name) === 'number') { bgneal@45: name = value; bgneal@45: compare_node = 0; bgneal@45: } bgneal@45: bgneal@45: if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) { bgneal@45: // Keep internal classes bgneal@45: if (name == 'class') { bgneal@45: value = dom.getAttrib(node, name); bgneal@45: if (value) { bgneal@45: // Build new class value where everything is removed except the internal prefixed classes bgneal@45: valueOut = ''; bgneal@45: each(value.split(/\s+/), function(cls) { bgneal@45: if (/mce\w+/.test(cls)) bgneal@45: valueOut += (valueOut ? ' ' : '') + cls; bgneal@45: }); bgneal@45: bgneal@45: // We got some internal classes left bgneal@45: if (valueOut) { bgneal@45: dom.setAttrib(node, name, valueOut); bgneal@45: return; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // IE6 has a bug where the attribute doesn't get removed correctly bgneal@45: if (name == "class") bgneal@45: node.removeAttribute('className'); bgneal@45: bgneal@45: // Remove mce prefixed attributes bgneal@45: if (MCE_ATTR_RE.test(name)) bgneal@45: node.removeAttribute('data-mce-' + name); bgneal@45: bgneal@45: node.removeAttribute(name); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Remove classes bgneal@45: each(format.classes, function(value) { bgneal@45: value = replaceVars(value, vars); bgneal@45: bgneal@45: if (!compare_node || dom.hasClass(compare_node, value)) bgneal@45: dom.removeClass(node, value); bgneal@45: }); bgneal@45: bgneal@45: // Check for non internal attributes bgneal@45: attrs = dom.getAttribs(node); bgneal@45: for (i = 0; i < attrs.length; i++) { bgneal@45: if (attrs[i].nodeName.indexOf('_') !== 0) bgneal@45: return FALSE; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Remove the inline child if it's empty for example or bgneal@45: if (format.remove != 'none') { bgneal@45: removeNode(node, format); bgneal@45: return TRUE; bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function removeNode(node, format) { bgneal@45: var parentNode = node.parentNode, rootBlockElm; bgneal@45: bgneal@45: if (format.block) { bgneal@45: if (!forcedRootBlock) { bgneal@45: function find(node, next, inc) { bgneal@45: node = getNonWhiteSpaceSibling(node, next, inc); bgneal@45: bgneal@45: return !node || (node.nodeName == 'BR' || isBlock(node)); bgneal@45: }; bgneal@45: bgneal@45: // Append BR elements if needed before we remove the block bgneal@45: if (isBlock(node) && !isBlock(parentNode)) { bgneal@45: if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1)) bgneal@45: node.insertBefore(dom.create('br'), node.firstChild); bgneal@45: bgneal@45: if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1)) bgneal@45: node.appendChild(dom.create('br')); bgneal@45: } bgneal@45: } else { bgneal@45: // Wrap the block in a forcedRootBlock if we are at the root of document bgneal@45: if (parentNode == dom.getRoot()) { bgneal@45: if (!format.list_block || !isEq(node, format.list_block)) { bgneal@45: each(tinymce.grep(node.childNodes), function(node) { bgneal@45: if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) { bgneal@45: if (!rootBlockElm) bgneal@45: rootBlockElm = wrap(node, forcedRootBlock); bgneal@45: else bgneal@45: rootBlockElm.appendChild(node); bgneal@45: } else bgneal@45: rootBlockElm = 0; bgneal@45: }); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Never remove nodes that isn't the specified inline element if a selector is specified too bgneal@45: if (format.selector && format.inline && !isEq(format.inline, node)) bgneal@45: return; bgneal@45: bgneal@45: dom.remove(node, 1); bgneal@45: }; bgneal@45: bgneal@45: function getNonWhiteSpaceSibling(node, next, inc) { bgneal@45: if (node) { bgneal@45: next = next ? 'nextSibling' : 'previousSibling'; bgneal@45: bgneal@45: for (node = inc ? node : node[next]; node; node = node[next]) { bgneal@45: if (node.nodeType == 1 || !isWhiteSpaceNode(node)) bgneal@45: return node; bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function isBookmarkNode(node) { bgneal@45: return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark'; bgneal@45: }; bgneal@45: bgneal@45: function mergeSiblings(prev, next) { bgneal@45: var marker, sibling, tmpSibling; bgneal@45: bgneal@45: function compareElements(node1, node2) { bgneal@45: // Not the same name bgneal@45: if (node1.nodeName != node2.nodeName) bgneal@45: return FALSE; bgneal@45: bgneal@45: function getAttribs(node) { bgneal@45: var attribs = {}; bgneal@45: bgneal@45: each(dom.getAttribs(node), function(attr) { bgneal@45: var name = attr.nodeName.toLowerCase(); bgneal@45: bgneal@45: // Don't compare internal attributes or style bgneal@45: if (name.indexOf('_') !== 0 && name !== 'style') bgneal@45: attribs[name] = dom.getAttrib(node, name); bgneal@45: }); bgneal@45: bgneal@45: return attribs; bgneal@45: }; bgneal@45: bgneal@45: function compareObjects(obj1, obj2) { bgneal@45: var value, name; bgneal@45: bgneal@45: for (name in obj1) { bgneal@45: // Obj1 has item obj2 doesn't have bgneal@45: if (obj1.hasOwnProperty(name)) { bgneal@45: value = obj2[name]; bgneal@45: bgneal@45: // Obj2 doesn't have obj1 item bgneal@45: if (value === undefined) bgneal@45: return FALSE; bgneal@45: bgneal@45: // Obj2 item has a different value bgneal@45: if (obj1[name] != value) bgneal@45: return FALSE; bgneal@45: bgneal@45: // Delete similar value bgneal@45: delete obj2[name]; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Check if obj 2 has something obj 1 doesn't have bgneal@45: for (name in obj2) { bgneal@45: // Obj2 has item obj1 doesn't have bgneal@45: if (obj2.hasOwnProperty(name)) bgneal@45: return FALSE; bgneal@45: } bgneal@45: bgneal@45: return TRUE; bgneal@45: }; bgneal@45: bgneal@45: // Attribs are not the same bgneal@45: if (!compareObjects(getAttribs(node1), getAttribs(node2))) bgneal@45: return FALSE; bgneal@45: bgneal@45: // Styles are not the same bgneal@45: if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style')))) bgneal@45: return FALSE; bgneal@45: bgneal@45: return TRUE; bgneal@45: }; bgneal@45: bgneal@45: // Check if next/prev exists and that they are elements bgneal@45: if (prev && next) { bgneal@45: function findElementSibling(node, sibling_name) { bgneal@45: for (sibling = node; sibling; sibling = sibling[sibling_name]) { bgneal@45: if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0) bgneal@45: return node; bgneal@45: bgneal@45: if (sibling.nodeType == 1 && !isBookmarkNode(sibling)) bgneal@45: return sibling; bgneal@45: } bgneal@45: bgneal@45: return node; bgneal@45: }; bgneal@45: bgneal@45: // If previous sibling is empty then jump over it bgneal@45: prev = findElementSibling(prev, 'previousSibling'); bgneal@45: next = findElementSibling(next, 'nextSibling'); bgneal@45: bgneal@45: // Compare next and previous nodes bgneal@45: if (compareElements(prev, next)) { bgneal@45: // Append nodes between bgneal@45: for (sibling = prev.nextSibling; sibling && sibling != next;) { bgneal@45: tmpSibling = sibling; bgneal@45: sibling = sibling.nextSibling; bgneal@45: prev.appendChild(tmpSibling); bgneal@45: } bgneal@45: bgneal@45: // Remove next node bgneal@45: dom.remove(next); bgneal@45: bgneal@45: // Move children into prev node bgneal@45: each(tinymce.grep(next.childNodes), function(node) { bgneal@45: prev.appendChild(node); bgneal@45: }); bgneal@45: bgneal@45: return prev; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return next; bgneal@45: }; bgneal@45: bgneal@45: function isTextBlock(name) { bgneal@45: return /^(h[1-6]|p|div|pre|address|dl|dt|dd)$/.test(name); bgneal@45: }; bgneal@45: bgneal@45: function getContainer(rng, start) { bgneal@45: var container, offset, lastIdx, walker; bgneal@45: bgneal@45: container = rng[start ? 'startContainer' : 'endContainer']; bgneal@45: offset = rng[start ? 'startOffset' : 'endOffset']; bgneal@45: bgneal@45: if (container.nodeType == 1) { bgneal@45: lastIdx = container.childNodes.length - 1; bgneal@45: bgneal@45: if (!start && offset) bgneal@45: offset--; bgneal@45: bgneal@45: container = container.childNodes[offset > lastIdx ? lastIdx : offset]; bgneal@45: } bgneal@45: bgneal@45: // If start text node is excluded then walk to the next node bgneal@45: if (container.nodeType === 3 && start && offset >= container.nodeValue.length) { bgneal@45: container = new TreeWalker(container, ed.getBody()).next() || container; bgneal@45: } bgneal@45: bgneal@45: // If end text node is excluded then walk to the previous node bgneal@45: if (container.nodeType === 3 && !start && offset == 0) { bgneal@45: container = new TreeWalker(container, ed.getBody()).prev() || container; bgneal@45: } bgneal@45: bgneal@45: return container; bgneal@45: }; bgneal@45: bgneal@45: function performCaretAction(type, name, vars) { bgneal@45: var caretContainerId = '_mce_caret', debug = ed.settings.caret_debug; bgneal@45: bgneal@45: // Creates a caret container bogus element bgneal@45: function createCaretContainer(fill) { bgneal@45: var caretContainer = dom.create('span', {id: caretContainerId, 'data-mce-bogus': true, style: debug ? 'color:red' : ''}); bgneal@45: bgneal@45: if (fill) { bgneal@45: caretContainer.appendChild(ed.getDoc().createTextNode(INVISIBLE_CHAR)); bgneal@45: } bgneal@45: bgneal@45: return caretContainer; bgneal@45: }; bgneal@45: bgneal@45: function isCaretContainerEmpty(node, nodes) { bgneal@45: while (node) { bgneal@45: if ((node.nodeType === 3 && node.nodeValue !== INVISIBLE_CHAR) || node.childNodes.length > 1) { bgneal@45: return false; bgneal@45: } bgneal@45: bgneal@45: // Collect nodes bgneal@45: if (nodes && node.nodeType === 1) { bgneal@45: nodes.push(node); bgneal@45: } bgneal@45: bgneal@45: node = node.firstChild; bgneal@45: } bgneal@45: bgneal@45: return true; bgneal@45: }; bgneal@45: bgneal@45: // Returns any parent caret container element bgneal@45: function getParentCaretContainer(node) { bgneal@45: while (node) { bgneal@45: if (node.id === caretContainerId) { bgneal@45: return node; bgneal@45: } bgneal@45: bgneal@45: node = node.parentNode; bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Finds the first text node in the specified node bgneal@45: function findFirstTextNode(node) { bgneal@45: var walker; bgneal@45: bgneal@45: if (node) { bgneal@45: walker = new TreeWalker(node, node); bgneal@45: bgneal@45: for (node = walker.current(); node; node = walker.next()) { bgneal@45: if (node.nodeType === 3) { bgneal@45: return node; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Removes the caret container for the specified node or all on the current document bgneal@45: function removeCaretContainer(node, move_caret) { bgneal@45: var child, rng; bgneal@45: bgneal@45: if (!node) { bgneal@45: node = getParentCaretContainer(selection.getStart()); bgneal@45: bgneal@45: if (!node) { bgneal@45: while (node = dom.get(caretContainerId)) { bgneal@45: removeCaretContainer(node, false); bgneal@45: } bgneal@45: } bgneal@45: } else { bgneal@45: rng = selection.getRng(true); bgneal@45: bgneal@45: if (isCaretContainerEmpty(node)) { bgneal@45: if (move_caret !== false) { bgneal@45: rng.setStartBefore(node); bgneal@45: rng.setEndBefore(node); bgneal@45: } bgneal@45: bgneal@45: dom.remove(node); bgneal@45: } else { bgneal@45: child = findFirstTextNode(node); bgneal@45: bgneal@45: if (child.nodeValue.charAt(0) === INVISIBLE_CHAR) { bgneal@45: child = child.deleteData(0, 1); bgneal@45: } bgneal@45: bgneal@45: dom.remove(node, 1); bgneal@45: } bgneal@45: bgneal@45: selection.setRng(rng); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Applies formatting to the caret postion bgneal@45: function applyCaretFormat() { bgneal@45: var rng, caretContainer, textNode, offset, bookmark, container, text; bgneal@45: bgneal@45: rng = selection.getRng(true); bgneal@45: offset = rng.startOffset; bgneal@45: container = rng.startContainer; bgneal@45: text = container.nodeValue; bgneal@45: bgneal@45: caretContainer = getParentCaretContainer(selection.getStart()); bgneal@45: if (caretContainer) { bgneal@45: textNode = findFirstTextNode(caretContainer); bgneal@45: } bgneal@45: bgneal@45: // Expand to word is caret is in the middle of a text node and the char before/after is a alpha numeric character bgneal@45: if (text && offset > 0 && offset < text.length && /\w/.test(text.charAt(offset)) && /\w/.test(text.charAt(offset - 1))) { bgneal@45: // Get bookmark of caret position bgneal@45: bookmark = selection.getBookmark(); bgneal@45: bgneal@45: // Collapse bookmark range (WebKit) bgneal@45: rng.collapse(true); bgneal@45: bgneal@45: // Expand the range to the closest word and split it at those points bgneal@45: rng = expandRng(rng, get(name)); bgneal@45: rng = rangeUtils.split(rng); bgneal@45: bgneal@45: // Apply the format to the range bgneal@45: apply(name, vars, rng); bgneal@45: bgneal@45: // Move selection back to caret position bgneal@45: selection.moveToBookmark(bookmark); bgneal@45: } else { bgneal@45: if (!caretContainer || textNode.nodeValue !== INVISIBLE_CHAR) { bgneal@45: caretContainer = createCaretContainer(true); bgneal@45: textNode = caretContainer.firstChild; bgneal@45: bgneal@45: rng.insertNode(caretContainer); bgneal@45: offset = 1; bgneal@45: bgneal@45: apply(name, vars, caretContainer); bgneal@45: } else { bgneal@45: apply(name, vars, caretContainer); bgneal@45: } bgneal@45: bgneal@45: // Move selection to text node bgneal@45: selection.setCursorLocation(textNode, offset); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function removeCaretFormat() { bgneal@45: var rng = selection.getRng(true), container, offset, bookmark, bgneal@45: hasContentAfter, node, formatNode, parents = [], i, caretContainer; bgneal@45: bgneal@45: container = rng.startContainer; bgneal@45: offset = rng.startOffset; bgneal@45: node = container; bgneal@45: bgneal@45: if (container.nodeType == 3) { bgneal@45: if (offset != container.nodeValue.length || container.nodeValue === INVISIBLE_CHAR) { bgneal@45: hasContentAfter = true; bgneal@45: } bgneal@45: bgneal@45: node = node.parentNode; bgneal@45: } bgneal@45: bgneal@45: while (node) { bgneal@45: if (matchNode(node, name, vars)) { bgneal@45: formatNode = node; bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: if (node.nextSibling) { bgneal@45: hasContentAfter = true; bgneal@45: } bgneal@45: bgneal@45: parents.push(node); bgneal@45: node = node.parentNode; bgneal@45: } bgneal@45: bgneal@45: // Node doesn't have the specified format bgneal@45: if (!formatNode) { bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Is there contents after the caret then remove the format on the element bgneal@45: if (hasContentAfter) { bgneal@45: // Get bookmark of caret position bgneal@45: bookmark = selection.getBookmark(); bgneal@45: bgneal@45: // Collapse bookmark range (WebKit) bgneal@45: rng.collapse(true); bgneal@45: bgneal@45: // Expand the range to the closest word and split it at those points bgneal@45: rng = expandRng(rng, get(name), true); bgneal@45: rng = rangeUtils.split(rng); bgneal@45: bgneal@45: // Remove the format from the range bgneal@45: remove(name, vars, rng); bgneal@45: bgneal@45: // Move selection back to caret position bgneal@45: selection.moveToBookmark(bookmark); bgneal@45: } else { bgneal@45: caretContainer = createCaretContainer(); bgneal@45: bgneal@45: node = caretContainer; bgneal@45: for (i = parents.length - 1; i >= 0; i--) { bgneal@45: node.appendChild(dom.clone(parents[i], false)); bgneal@45: node = node.firstChild; bgneal@45: } bgneal@45: bgneal@45: // Insert invisible character into inner most format element bgneal@45: node.appendChild(dom.doc.createTextNode(INVISIBLE_CHAR)); bgneal@45: node = node.firstChild; bgneal@45: bgneal@45: // Insert caret container after the formated node bgneal@45: dom.insertAfter(caretContainer, formatNode); bgneal@45: bgneal@45: // Move selection to text node bgneal@45: selection.setCursorLocation(node, 1); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Only bind the caret events once bgneal@45: if (!self._hasCaretEvents) { bgneal@45: // Mark current caret container elements as bogus when getting the contents so we don't end up with empty elements bgneal@45: ed.onBeforeGetContent.addToTop(function() { bgneal@45: var nodes = [], i; bgneal@45: bgneal@45: if (isCaretContainerEmpty(getParentCaretContainer(selection.getStart()), nodes)) { bgneal@45: // Mark children bgneal@45: i = nodes.length; bgneal@45: while (i--) { bgneal@45: dom.setAttrib(nodes[i], 'data-mce-bogus', '1'); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Remove caret container on mouse up and on key up bgneal@45: tinymce.each('onMouseUp onKeyUp'.split(' '), function(name) { bgneal@45: ed[name].addToTop(function() { bgneal@45: removeCaretContainer(); bgneal@45: }); bgneal@45: }); bgneal@45: bgneal@45: // Remove caret container on keydown and it's a backspace, enter or left/right arrow keys bgneal@45: ed.onKeyDown.addToTop(function(ed, e) { bgneal@45: var keyCode = e.keyCode; bgneal@45: bgneal@45: if (keyCode == 8 || keyCode == 37 || keyCode == 39) { bgneal@45: removeCaretContainer(getParentCaretContainer(selection.getStart())); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: self._hasCaretEvents = true; bgneal@45: } bgneal@45: bgneal@45: // Do apply or remove caret format bgneal@45: if (type == "apply") { bgneal@45: applyCaretFormat(); bgneal@45: } else { bgneal@45: removeCaretFormat(); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function moveStart(rng) { bgneal@45: var container = rng.startContainer, bgneal@45: offset = rng.startOffset, bgneal@45: walker, node, nodes, tmpNode; bgneal@45: bgneal@45: // Convert text node into index if possible bgneal@45: if (container.nodeType == 3 && offset >= container.nodeValue.length - 1) { bgneal@45: container = container.parentNode; bgneal@45: offset = nodeIndex(container) + 1; bgneal@45: } bgneal@45: bgneal@45: // Move startContainer/startOffset in to a suitable node bgneal@45: if (container.nodeType == 1) { bgneal@45: nodes = container.childNodes; bgneal@45: container = nodes[Math.min(offset, nodes.length - 1)]; bgneal@45: walker = new TreeWalker(container); bgneal@45: bgneal@45: // If offset is at end of the parent node walk to the next one bgneal@45: if (offset > nodes.length - 1) bgneal@45: walker.next(); bgneal@45: bgneal@45: for (node = walker.current(); node; node = walker.next()) { bgneal@45: if (node.nodeType == 3 && !isWhiteSpaceNode(node)) { bgneal@45: // IE has a "neat" feature where it moves the start node into the closest element bgneal@45: // we can avoid this by inserting an element before it and then remove it after we set the selection bgneal@45: tmpNode = dom.create('a', null, INVISIBLE_CHAR); bgneal@45: node.parentNode.insertBefore(tmpNode, node); bgneal@45: bgneal@45: // Set selection and remove tmpNode bgneal@45: rng.setStart(node, 0); bgneal@45: selection.setRng(rng); bgneal@45: dom.remove(tmpNode); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: }; bgneal@45: })(tinymce); bgneal@45: bgneal@45: tinymce.onAddEditor.add(function(tinymce, ed) { bgneal@45: var filters, fontSizes, dom, settings = ed.settings; bgneal@45: bgneal@45: if (settings.inline_styles) { bgneal@45: fontSizes = tinymce.explode(settings.font_size_legacy_values); bgneal@45: bgneal@45: function replaceWithSpan(node, styles) { bgneal@45: tinymce.each(styles, function(value, name) { bgneal@45: if (value) bgneal@45: dom.setStyle(node, name, value); bgneal@45: }); bgneal@45: bgneal@45: dom.rename(node, 'span'); bgneal@45: }; bgneal@45: bgneal@45: filters = { bgneal@45: font : function(dom, node) { bgneal@45: replaceWithSpan(node, { bgneal@45: backgroundColor : node.style.backgroundColor, bgneal@45: color : node.color, bgneal@45: fontFamily : node.face, bgneal@45: fontSize : fontSizes[parseInt(node.size) - 1] bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: u : function(dom, node) { bgneal@45: replaceWithSpan(node, { bgneal@45: textDecoration : 'underline' bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: strike : function(dom, node) { bgneal@45: replaceWithSpan(node, { bgneal@45: textDecoration : 'line-through' bgneal@45: }); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: function convert(editor, params) { bgneal@45: dom = editor.dom; bgneal@45: bgneal@45: if (settings.convert_fonts_to_spans) { bgneal@45: tinymce.each(dom.select('font,u,strike', params.node), function(node) { bgneal@45: filters[node.nodeName.toLowerCase()](ed.dom, node); bgneal@45: }); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: ed.onPreProcess.add(convert); bgneal@45: ed.onSetContent.add(convert); bgneal@45: bgneal@45: ed.onInit.add(function() { bgneal@45: ed.selection.onSetContent.add(convert); bgneal@45: }); bgneal@45: } bgneal@45: }); bgneal@45: