bgneal@45: var tinymce = { bgneal@45: majorVersion : '3', bgneal@45: minorVersion : '2.2.3', bgneal@45: releaseDate : '2009-03-26', bgneal@45: bgneal@45: _init : function() { bgneal@45: var t = this, d = document, w = window, na = navigator, ua = na.userAgent, i, nl, n, base, p, v; bgneal@45: bgneal@45: // Browser checks bgneal@45: t.isOpera = w.opera && opera.buildNumber; bgneal@45: t.isWebKit = /WebKit/.test(ua); bgneal@45: t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName); bgneal@45: t.isIE6 = t.isIE && /MSIE [56]/.test(ua); bgneal@45: t.isGecko = !t.isWebKit && /Gecko/.test(ua); bgneal@45: t.isMac = ua.indexOf('Mac') != -1; bgneal@45: t.isAir = /adobeair/i.test(ua); bgneal@45: bgneal@45: // TinyMCE .NET webcontrol might be setting the values for TinyMCE bgneal@45: if (w.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+$/, '')); 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 || window; bgneal@45: bgneal@45: n = n.split('.'); bgneal@45: for (i=0; i= 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; 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: return '/' + o.reverse().join('/') + tr; bgneal@45: bgneal@45: return '/' + base.slice(0, i).join('/') + '/' + o.reverse().join('/') + tr; 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: tinymce.create('static tinymce.util.JSON', { bgneal@45: serialize : function(o) { bgneal@45: var i, v, s = tinymce.util.JSON.serialize, t; 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 '"' + o.replace(/([\u0080-\uFFFF\x00-\x1f\"])/g, function(a, b) { 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: }) + '"'; 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 ? ',' : '') + s(o[i]); bgneal@45: bgneal@45: return v + ']'; bgneal@45: } bgneal@45: bgneal@45: v = '{'; bgneal@45: bgneal@45: for (i in o) bgneal@45: v += typeof o[i] != 'function' ? (v.length > 1 ? ',"' : '"') + i + '":' + s(o[i]) : ''; bgneal@45: bgneal@45: return v + '}'; bgneal@45: } bgneal@45: bgneal@45: return '' + o; bgneal@45: }, 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: 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.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: 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: // Shorten names bgneal@45: var each = tinymce.each, is = tinymce.is; bgneal@45: var isWebKit = tinymce.isWebKit, isIE = tinymce.isIE; 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; 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.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat"; bgneal@45: t.stdMode = d.documentMode === 8; bgneal@45: bgneal@45: this.settings = s = tinymce.extend({ bgneal@45: keep_values : false, bgneal@45: hex_colors : 1, bgneal@45: process_html : 1 bgneal@45: }, s); 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: tinymce.addUnload(t.destroy, t); 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: is : function(n, patt) { bgneal@45: return tinymce.dom.Sizzle.matches(patt, n.nodeType ? [n] : n).length > 0; 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) 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: 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: 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: if (tinymce.is(h)) bgneal@45: return o + '>' + h + ''; bgneal@45: bgneal@45: return o + ' />'; bgneal@45: }, bgneal@45: bgneal@45: remove : function(n, k) { bgneal@45: var t = this; bgneal@45: bgneal@45: return this.run(n, function(n) { bgneal@45: var p, g, i; bgneal@45: bgneal@45: p = n.parentNode; bgneal@45: bgneal@45: if (!p) bgneal@45: return null; bgneal@45: bgneal@45: if (k) { bgneal@45: for (i = n.childNodes.length - 1; i >= 0; i--) bgneal@45: t.insertAfter(n.childNodes[i], n); bgneal@45: bgneal@45: //each(n.childNodes, function(c) { bgneal@45: // p.insertBefore(c.cloneNode(true), n); bgneal@45: //}); bgneal@45: } bgneal@45: bgneal@45: // Fix IE psuedo leak bgneal@45: if (t.fixPsuedoLeaks) { bgneal@45: p = n.cloneNode(true); bgneal@45: k = 'IELeakGarbageBin'; bgneal@45: g = t.get(k) || t.add(t.doc.body, 'div', {id : k, style : 'display:none'}); bgneal@45: g.appendChild(n); bgneal@45: g.innerHTML = ''; bgneal@45: bgneal@45: return p; bgneal@45: } bgneal@45: bgneal@45: return p.removeChild(n); bgneal@45: }); 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, '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 false; 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[na]; 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: 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: 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('mce_style', v, 2); bgneal@45: else bgneal@45: e.removeAttribute('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, 'mce_' + n, v, 2); bgneal@45: } bgneal@45: bgneal@45: break; bgneal@45: bgneal@45: case "shape": bgneal@45: e.setAttribute('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: }, 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: bgneal@45: getAttrib : function(e, n, dv) { bgneal@45: var v, t = this; bgneal@45: bgneal@45: e = t.get(e); bgneal@45: bgneal@45: if (!e || e.nodeType !== 1) bgneal@45: return false; 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("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: if (n === 'style') { bgneal@45: v = v || e.style.cssText; bgneal@45: bgneal@45: if (v) { bgneal@45: v = t.serializeStyle(t.parseStyle(v)); bgneal@45: bgneal@45: if (t.settings.keep_values && !t._isRes(v)) bgneal@45: e.setAttribute('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 = ('' + v).replace(/^function\s+anonymous\(\)\s+\{\s+(.*)\s+\}$/, '$1'); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return (v !== undefined && v !== null && v !== '') ? '' + v : dv; bgneal@45: }, bgneal@45: bgneal@45: getPos : function(n) { bgneal@45: var t = this, x = 0, y = 0, e, d = t.doc, r; bgneal@45: bgneal@45: n = t.get(n); bgneal@45: bgneal@45: // Use getBoundingClientRect on IE, Opera has it but it's not perfect bgneal@45: if (n && isIE && !t.stdMode) { bgneal@45: n = n.getBoundingClientRect(); bgneal@45: e = t.boxModel ? d.documentElement : d.body; bgneal@45: x = t.getStyle(t.select('html')[0], 'borderWidth'); // Remove border bgneal@45: x = (x == 'medium' || t.boxModel && !t.isIE6) && 2 || x; bgneal@45: n.top += t.win.self != t.win.top ? 2 : 0; // IE adds some strange extra cord if used in a frameset bgneal@45: bgneal@45: return {x : n.left + e.scrollLeft - x, y : n.top + e.scrollTop - x}; bgneal@45: } bgneal@45: bgneal@45: r = n; bgneal@45: while (r) { 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; bgneal@45: while (r) { bgneal@45: // Opera 9.25 bug fix, fixed in 9.50 bgneal@45: if (!/^table-row|inline.*/i.test(t.getStyle(r, "display", 1))) { bgneal@45: x -= r.scrollLeft || 0; bgneal@45: y -= r.scrollTop || 0; bgneal@45: } bgneal@45: bgneal@45: r = r.parentNode; bgneal@45: bgneal@45: // No node type or document type bgneal@45: if (!r.nodeType || r.nodeType == 9 || r.nodeName.toLowerCase() == 'body') bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: return {x : x, y : y}; bgneal@45: }, bgneal@45: bgneal@45: parseStyle : function(st) { bgneal@45: var t = this, s = t.settings, o = {}; bgneal@45: bgneal@45: if (!st) bgneal@45: return o; bgneal@45: bgneal@45: function compress(p, s, ot) { bgneal@45: var t, r, b, l; bgneal@45: bgneal@45: // Get values and check it it needs compressing bgneal@45: t = o[p + '-top' + s]; bgneal@45: if (!t) bgneal@45: return; bgneal@45: bgneal@45: r = o[p + '-right' + s]; bgneal@45: if (t != r) bgneal@45: return; bgneal@45: bgneal@45: b = o[p + '-bottom' + s]; bgneal@45: if (r != b) bgneal@45: return; bgneal@45: bgneal@45: l = o[p + '-left' + s]; bgneal@45: if (b != l) bgneal@45: return; bgneal@45: bgneal@45: // Compress bgneal@45: o[ot] = l; bgneal@45: delete o[p + '-top' + s]; bgneal@45: delete o[p + '-right' + s]; bgneal@45: delete o[p + '-bottom' + s]; bgneal@45: delete o[p + '-left' + s]; bgneal@45: }; bgneal@45: bgneal@45: function compress2(ta, a, b, c) { bgneal@45: var t; bgneal@45: bgneal@45: t = o[a]; bgneal@45: if (!t) bgneal@45: return; bgneal@45: bgneal@45: t = o[b]; bgneal@45: if (!t) bgneal@45: return; bgneal@45: bgneal@45: t = o[c]; bgneal@45: if (!t) bgneal@45: return; bgneal@45: bgneal@45: // Compress bgneal@45: o[ta] = o[a] + ' ' + o[b] + ' ' + o[c]; bgneal@45: delete o[a]; bgneal@45: delete o[b]; bgneal@45: delete o[c]; bgneal@45: }; bgneal@45: bgneal@45: st = st.replace(/&(#?[a-z0-9]+);/g, '&$1_MCE_SEMI_'); // Protect entities bgneal@45: bgneal@45: each(st.split(';'), function(v) { bgneal@45: var sv, ur = []; bgneal@45: bgneal@45: if (v) { bgneal@45: v = v.replace(/_MCE_SEMI_/g, ';'); // Restore entities bgneal@45: v = v.replace(/url\([^\)]+\)/g, function(v) {ur.push(v);return 'url(' + ur.length + ')';}); bgneal@45: v = v.split(':'); bgneal@45: sv = tinymce.trim(v[1]); bgneal@45: sv = sv.replace(/url\(([^\)]+)\)/g, function(a, b) {return ur[parseInt(b) - 1];}); bgneal@45: bgneal@45: sv = sv.replace(/rgb\([^\)]+\)/g, function(v) { bgneal@45: return t.toHex(v); bgneal@45: }); bgneal@45: bgneal@45: if (s.url_converter) { bgneal@45: sv = sv.replace(/url\([\'\"]?([^\)\'\"]+)[\'\"]?\)/g, function(x, c) { bgneal@45: return 'url(' + s.url_converter.call(s.url_converter_scope || t, t.decode(c), 'style', null) + ')'; bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: o[tinymce.trim(v[0]).toLowerCase()] = sv; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: compress("border", "", "border"); bgneal@45: compress("border", "-width", "border-width"); bgneal@45: compress("border", "-color", "border-color"); bgneal@45: compress("border", "-style", "border-style"); bgneal@45: compress("padding", "", "padding"); bgneal@45: compress("margin", "", "margin"); bgneal@45: compress2('border', 'border-width', 'border-style', 'border-color'); bgneal@45: bgneal@45: if (isIE) { bgneal@45: // Remove pointless border bgneal@45: if (o.border == 'medium none') bgneal@45: o.border = ''; bgneal@45: } bgneal@45: bgneal@45: return o; bgneal@45: }, bgneal@45: bgneal@45: serializeStyle : function(o) { bgneal@45: var s = ''; bgneal@45: bgneal@45: each(o, function(v, k) { bgneal@45: if (k && v) { bgneal@45: if (tinymce.isGecko && k.indexOf('-moz-') === 0) bgneal@45: return; bgneal@45: bgneal@45: switch (k) { bgneal@45: case 'color': bgneal@45: case 'background-color': bgneal@45: v = v.toLowerCase(); bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: s += (s ? ' ' : '') + k + ': ' + v + ';'; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: return s; bgneal@45: }, bgneal@45: bgneal@45: loadCSS : function(u) { bgneal@45: var t = this, d = t.doc; bgneal@45: bgneal@45: if (!u) bgneal@45: u = ''; bgneal@45: bgneal@45: each(u.split(','), function(u) { bgneal@45: if (t.files[u]) bgneal@45: return; bgneal@45: bgneal@45: t.files[u] = true; bgneal@45: t.add(t.select('head')[0], 'link', {rel : 'stylesheet', href : tinymce._addVer(u)}); bgneal@45: }); 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: bgneal@45: return e.className = tinymce.trim(v != ' ' ? 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: bgneal@45: uniqueId : function(p) { bgneal@45: return (!p ? 'mce_' : p) + (this.counter++); bgneal@45: }, bgneal@45: bgneal@45: setHTML : function(e, h) { bgneal@45: var t = this; bgneal@45: bgneal@45: return this.run(e, function(e) { bgneal@45: var x, i, nl, n, p, x; bgneal@45: bgneal@45: h = t.processHTML(h); bgneal@45: bgneal@45: if (isIE) { bgneal@45: function set() { bgneal@45: try { bgneal@45: // IE will remove comments from the beginning bgneal@45: // unless you padd the contents with something bgneal@45: e.innerHTML = '
' + h; bgneal@45: e.removeChild(e.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: // Remove all child nodes bgneal@45: while (e.firstChild) bgneal@45: e.firstChild.removeNode(); bgneal@45: bgneal@45: // Create new div with HTML contents and a BR infront to keep comments bgneal@45: x = t.create('div'); bgneal@45: x.innerHTML = '
' + h; bgneal@45: bgneal@45: // Add all children from div to target bgneal@45: each (x.childNodes, function(n, i) { bgneal@45: // Skip br element bgneal@45: if (i) bgneal@45: e.appendChild(n); bgneal@45: }); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // IE has a serious bug when it comes to paragraphs it can produce an invalid bgneal@45: // DOM tree if contents like this

  • Item 1

is inserted bgneal@45: // It seems to be that IE doesn't like a root block element placed inside another root block element bgneal@45: if (t.settings.fix_ie_paragraphs) bgneal@45: h = h.replace(/

<\/p>|]+)><\/p>|/gi, ' 

'); bgneal@45: bgneal@45: set(); bgneal@45: bgneal@45: if (t.settings.fix_ie_paragraphs) { bgneal@45: // Check for odd paragraphs this is a sign of a broken DOM bgneal@45: nl = e.getElementsByTagName("p"); bgneal@45: for (i = nl.length - 1, x = 0; i >= 0; i--) { bgneal@45: n = nl[i]; bgneal@45: bgneal@45: if (!n.hasChildNodes()) { bgneal@45: if (!n.mce_keep) { bgneal@45: x = 1; // Is broken bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: n.removeAttribute('mce_keep'); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Time to fix the madness IE left us bgneal@45: if (x) { bgneal@45: // So if we replace the p elements with divs and mark them and then replace them back to paragraphs bgneal@45: // after we use innerHTML we can fix the DOM tree bgneal@45: h = h.replace(/

]+)>|

/g, '

'); bgneal@45: h = h.replace(/<\/p>/g, '
'); bgneal@45: bgneal@45: // Set the new HTML with DIVs bgneal@45: set(); bgneal@45: bgneal@45: // Replace all DIV elements with he mce_tmp attibute back to paragraphs bgneal@45: // This is needed since IE has a annoying bug see above for details bgneal@45: // This is a slow process but it has to be done. :( bgneal@45: if (t.settings.fix_ie_paragraphs) { bgneal@45: nl = e.getElementsByTagName("DIV"); bgneal@45: for (i = nl.length - 1; i >= 0; i--) { bgneal@45: n = nl[i]; bgneal@45: bgneal@45: // Is it a temp div bgneal@45: if (n.mce_tmp) { bgneal@45: // Create new paragraph bgneal@45: p = t.doc.createElement('p'); bgneal@45: bgneal@45: // Copy all attributes bgneal@45: n.cloneNode(false).outerHTML.replace(/([a-z0-9\-_]+)=/gi, function(a, b) { bgneal@45: var v; bgneal@45: bgneal@45: if (b !== 'mce_tmp') { bgneal@45: v = n.getAttribute(b); bgneal@45: bgneal@45: if (!v && b === 'class') bgneal@45: v = n.className; bgneal@45: bgneal@45: p.setAttribute(b, v); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Append all children to new paragraph bgneal@45: for (x = 0; x|]+)>/gi, '<$1b$2>'); bgneal@45: h = h.replace(/<(\/?)em>|]+)>/gi, '<$1i$2>'); bgneal@45: } else if (isIE) { bgneal@45: h = h.replace(/'/g, '''); // IE can't handle apos bgneal@45: h = h.replace(/\s+(disabled|checked|readonly|selected)\s*=\s*[\"\']?(false|0)[\"\']?/gi, ''); // IE doesn't handle default values correct bgneal@45: } bgneal@45: bgneal@45: // Fix some issues bgneal@45: h = h.replace(/]+)\/>|/gi, ''); // Force open bgneal@45: bgneal@45: // Store away src and href in mce_src and mce_href since browsers mess them up bgneal@45: if (s.keep_values) { bgneal@45: // Wrap scripts and styles in comments for serialization purposes bgneal@45: if (/)/g, '\n'); bgneal@45: s = s.replace(/^[\r\n]*|[\r\n]*$/g, ''); bgneal@45: s = s.replace(/^\s*(\/\/\s*|\]\]>|-->|\]\]-->)\s*$/g, ''); bgneal@45: bgneal@45: return s; bgneal@45: }; bgneal@45: bgneal@45: // Preserve script elements bgneal@45: h = h.replace(/]+|)>([\s\S]*?)<\/script>/g, function(v, a, b) { bgneal@45: // Remove prefix and suffix code for script element bgneal@45: b = trim(b); bgneal@45: bgneal@45: // Force type attribute bgneal@45: if (!a) bgneal@45: a = ' type="text/javascript"'; bgneal@45: bgneal@45: // Wrap contents in a comment bgneal@45: if (b) bgneal@45: b = ''; bgneal@45: bgneal@45: // Output fake element bgneal@45: return '' + b + ''; bgneal@45: }); bgneal@45: bgneal@45: // Preserve style elements bgneal@45: h = h.replace(/]+|)>([\s\S]*?)<\/style>/g, function(v, a, b) { bgneal@45: b = trim(b); bgneal@45: return '' + b + ''; bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: h = h.replace(//g, ''); bgneal@45: bgneal@45: // Process all tags with src, href or style bgneal@45: h = h.replace(/<([\w:]+) [^>]*(src|href|style|shape|coords)[^>]*>/gi, function(a, n) { bgneal@45: function handle(m, b, c) { bgneal@45: var u = c; bgneal@45: bgneal@45: // Tag already got a mce_ version bgneal@45: if (a.indexOf('mce_' + b) != -1) bgneal@45: return m; bgneal@45: bgneal@45: if (b == 'style') { bgneal@45: // Why did I need this one? bgneal@45: //if (isIE) bgneal@45: // u = t.serializeStyle(t.parseStyle(u)); bgneal@45: bgneal@45: // No mce_style for elements with these since they might get resized by the user bgneal@45: if (t._isRes(c)) bgneal@45: return m; bgneal@45: bgneal@45: if (s.hex_colors) { bgneal@45: u = u.replace(/rgb\([^\)]+\)/g, function(v) { bgneal@45: return t.toHex(v); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (s.url_converter) { bgneal@45: u = u.replace(/url\([\'\"]?([^\)\'\"]+)\)/g, function(x, c) { bgneal@45: return 'url(' + t.encode(s.url_converter.call(s.url_converter_scope || t, t.decode(c), b, n)) + ')'; bgneal@45: }); bgneal@45: } bgneal@45: } else if (b != 'coords' && b != 'shape') { bgneal@45: if (s.url_converter) bgneal@45: u = t.encode(s.url_converter.call(s.url_converter_scope || t, t.decode(c), b, n)); bgneal@45: } bgneal@45: bgneal@45: return ' ' + b + '="' + c + '" mce_' + b + '="' + u + '"'; bgneal@45: }; bgneal@45: bgneal@45: a = a.replace(/ (src|href|style|coords|shape)=[\"]([^\"]+)[\"]/gi, handle); // W3C bgneal@45: a = a.replace(/ (src|href|style|coords|shape)=[\']([^\']+)[\']/gi, handle); // W3C bgneal@45: bgneal@45: return a.replace(/ (src|href|style|coords|shape)=([^\s\"\'>]+)/gi, handle); // IE bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: return h; bgneal@45: }, bgneal@45: bgneal@45: getOuterHTML : function(e) { bgneal@45: var d; bgneal@45: bgneal@45: e = this.get(e); bgneal@45: bgneal@45: if (!e) bgneal@45: return null; bgneal@45: bgneal@45: if (e.outerHTML !== undefined) bgneal@45: return e.outerHTML; bgneal@45: bgneal@45: d = (e.ownerDocument || this.doc).createElement("body"); bgneal@45: d.appendChild(e.cloneNode(true)); bgneal@45: bgneal@45: return d.innerHTML; bgneal@45: }, bgneal@45: bgneal@45: setOuterHTML : function(e, h, d) { bgneal@45: var t = this; bgneal@45: bgneal@45: return this.run(e, function(e) { bgneal@45: var n, tp; bgneal@45: bgneal@45: e = t.get(e); bgneal@45: d = d || e.ownerDocument || t.doc; bgneal@45: bgneal@45: if (isIE && e.nodeType == 1) bgneal@45: e.outerHTML = h; bgneal@45: else { 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: }, bgneal@45: bgneal@45: decode : function(s) { bgneal@45: var e, n, v; bgneal@45: bgneal@45: // Look for entities to decode bgneal@45: if (/&[^;]+;/.test(s)) { bgneal@45: // Decode the entities using a div element not super efficient but less code bgneal@45: e = this.doc.createElement("div"); bgneal@45: e.innerHTML = s; bgneal@45: n = e.firstChild; bgneal@45: v = ''; bgneal@45: bgneal@45: if (n) { bgneal@45: do { bgneal@45: v += n.nodeValue; bgneal@45: } while (n.nextSibling); bgneal@45: } bgneal@45: bgneal@45: return v || s; bgneal@45: } bgneal@45: bgneal@45: return s; bgneal@45: }, bgneal@45: bgneal@45: encode : function(s) { bgneal@45: return s ? ('' + s).replace(/[<>&\"]/g, function (c, b) { bgneal@45: switch (c) { bgneal@45: case '&': bgneal@45: return '&'; bgneal@45: bgneal@45: case '"': bgneal@45: return '"'; bgneal@45: bgneal@45: case '<': bgneal@45: return '<'; bgneal@45: bgneal@45: case '>': bgneal@45: return '>'; bgneal@45: } bgneal@45: bgneal@45: return c; bgneal@45: }) : s; bgneal@45: }, bgneal@45: bgneal@45: bgneal@45: insertAfter : function(n, r) { bgneal@45: var t = this; bgneal@45: bgneal@45: r = t.get(r); bgneal@45: bgneal@45: return this.run(n, function(n) { bgneal@45: var p, ns; bgneal@45: bgneal@45: p = r.parentNode; bgneal@45: ns = r.nextSibling; bgneal@45: bgneal@45: if (ns) bgneal@45: p.insertBefore(n, ns); bgneal@45: else bgneal@45: p.appendChild(n); bgneal@45: bgneal@45: return n; bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: bgneal@45: isBlock : function(n) { bgneal@45: if (n.nodeType && n.nodeType !== 1) bgneal@45: return false; bgneal@45: bgneal@45: n = n.nodeName || n; bgneal@45: bgneal@45: return /^(H[1-6]|HR|P|DIV|ADDRESS|PRE|FORM|TABLE|LI|OL|UL|TR|TD|CAPTION|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|NOSCRIPT|NOFRAMES|MENU|ISINDEX|SAMP)$/.test(n); 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(o.childNodes, function(c) { bgneal@45: n.appendChild(c.cloneNode(true)); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // Fix IE psuedo leak for elements since replacing elements if fairly common bgneal@45: // Will break parentNode for some unknown reason bgneal@45: if (t.fixPsuedoLeaks && o.nodeType === 1) { bgneal@45: o.parentNode.insertBefore(n, o); bgneal@45: t.remove(o); bgneal@45: return n; bgneal@45: } bgneal@45: bgneal@45: return o.parentNode.replaceChild(n, o); bgneal@45: }); bgneal@45: }, 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 = v.replace(/.*\.([a-z0-9_\-]+).*/i, '$1'); 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: // 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(/([a-z0-9\:\-_]+)=/gi, function(a, b) { bgneal@45: o.push({specified : 1, nodeName : b}); bgneal@45: }); bgneal@45: bgneal@45: return o; bgneal@45: } bgneal@45: bgneal@45: return n.attributes; bgneal@45: }, bgneal@45: bgneal@45: destroy : function(s) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.win = t.doc = t.root = 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: 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 sence bgneal@45: // but we don't want that in our code since it serves no purpose 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 trimEdge(n, na) { bgneal@45: n = n[na]; bgneal@45: bgneal@45: if (n && n[na] && n[na].nodeType == 1 && isEmpty(n[na])) bgneal@45: t.remove(n[na]); bgneal@45: }; bgneal@45: bgneal@45: function isEmpty(n) { bgneal@45: n = t.getOuterHTML(n); bgneal@45: n = n.replace(/<(img|hr|table)/gi, '-'); // Keep these convert them to - chars bgneal@45: n = n.replace(/<[^>]+>/g, ''); // Remove all tags bgneal@45: bgneal@45: return n.replace(/[ \t\r\n]+| | /g, '') == ''; bgneal@45: }; bgneal@45: bgneal@45: if (pe && e) { bgneal@45: // Get before chunk bgneal@45: r.setStartBefore(pe); bgneal@45: r.setEndBefore(e); bgneal@45: bef = r.extractContents(); bgneal@45: bgneal@45: // Get after chunk bgneal@45: r = t.createRng(); bgneal@45: r.setStartAfter(e); bgneal@45: r.setEndAfter(pe); bgneal@45: aft = r.extractContents(); bgneal@45: bgneal@45: // Insert chunks and remove parent bgneal@45: pa = pe.parentNode; bgneal@45: bgneal@45: // Remove right side edge of the before contents bgneal@45: trimEdge(bef, 'lastChild'); bgneal@45: bgneal@45: if (!isEmpty(bef)) bgneal@45: pa.insertBefore(bef, pe); bgneal@45: bgneal@45: if (re) bgneal@45: pa.replaceChild(re, e); bgneal@45: else bgneal@45: pa.insertBefore(e, pe); bgneal@45: bgneal@45: // Remove left site edge of the after contents bgneal@45: trimEdge(aft, 'firstChild'); bgneal@45: bgneal@45: if (!isEmpty(aft)) bgneal@45: pa.insertBefore(aft, pe); bgneal@45: bgneal@45: t.remove(pe); bgneal@45: bgneal@45: return re || e; bgneal@45: } 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: bgneal@45: // Setup page DOM bgneal@45: tinymce.DOM = new tinymce.dom.DOMUtils(document, {process_html : 0}); bgneal@45: })(tinymce); bgneal@45: (function(ns) { bgneal@45: // Traverse constants bgneal@45: var EXTRACT = 0, CLONE = 1, DELETE = 2, extend = tinymce.extend; bgneal@45: bgneal@45: function indexOf(child, parent) { bgneal@45: var i, node; bgneal@45: bgneal@45: if (child.parentNode != parent) bgneal@45: return -1; bgneal@45: bgneal@45: for (node = parent.firstChild, i = 0; node != child; node = node.nextSibling) bgneal@45: i++; bgneal@45: bgneal@45: return i; bgneal@45: }; bgneal@45: bgneal@45: function nodeIndex(n) { bgneal@45: var i = 0; bgneal@45: bgneal@45: while (n.previousSibling) { bgneal@45: i++; bgneal@45: n = n.previousSibling; bgneal@45: } bgneal@45: bgneal@45: return i; bgneal@45: }; 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 != null && offset > 0) { bgneal@45: --offset; bgneal@45: child = child.nextSibling; bgneal@45: } bgneal@45: bgneal@45: if (child != null) bgneal@45: return child; bgneal@45: bgneal@45: return container; bgneal@45: }; bgneal@45: bgneal@45: // Range constructor bgneal@45: function Range(dom) { bgneal@45: var d = dom.doc; bgneal@45: bgneal@45: extend(this, { bgneal@45: dom : dom, bgneal@45: bgneal@45: // Inital states bgneal@45: startContainer : d, bgneal@45: startOffset : 0, bgneal@45: endContainer : d, bgneal@45: endOffset : 0, bgneal@45: collapsed : true, bgneal@45: commonAncestorContainer : d, 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: }; bgneal@45: bgneal@45: // Add range methods bgneal@45: extend(Range.prototype, { bgneal@45: setStart : function(n, o) { bgneal@45: this._setEndPoint(true, n, o); bgneal@45: }, bgneal@45: bgneal@45: setEnd : function(n, o) { bgneal@45: this._setEndPoint(false, n, o); bgneal@45: }, bgneal@45: bgneal@45: setStartBefore : function(n) { bgneal@45: this.setStart(n.parentNode, nodeIndex(n)); bgneal@45: }, bgneal@45: bgneal@45: setStartAfter : function(n) { bgneal@45: this.setStart(n.parentNode, nodeIndex(n) + 1); bgneal@45: }, bgneal@45: bgneal@45: setEndBefore : function(n) { bgneal@45: this.setEnd(n.parentNode, nodeIndex(n)); bgneal@45: }, bgneal@45: bgneal@45: setEndAfter : function(n) { bgneal@45: this.setEnd(n.parentNode, nodeIndex(n) + 1); bgneal@45: }, bgneal@45: bgneal@45: collapse : function(ts) { bgneal@45: var t = this; bgneal@45: bgneal@45: if (ts) { bgneal@45: t.endContainer = t.startContainer; bgneal@45: t.endOffset = t.startOffset; bgneal@45: } else { bgneal@45: t.startContainer = t.endContainer; bgneal@45: t.startOffset = t.endOffset; bgneal@45: } bgneal@45: bgneal@45: t.collapsed = true; bgneal@45: }, bgneal@45: bgneal@45: selectNode : function(n) { bgneal@45: this.setStartBefore(n); bgneal@45: this.setEndAfter(n); bgneal@45: }, bgneal@45: bgneal@45: selectNodeContents : function(n) { bgneal@45: this.setStart(n, 0); bgneal@45: this.setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length); bgneal@45: }, bgneal@45: bgneal@45: compareBoundaryPoints : function(h, r) { bgneal@45: var t = this, sc = t.startContainer, so = t.startOffset, ec = t.endContainer, eo = t.endOffset; bgneal@45: bgneal@45: // Check START_TO_START bgneal@45: if (h === 0) bgneal@45: return t._compareBoundaryPoints(sc, so, sc, so); bgneal@45: bgneal@45: // Check START_TO_END bgneal@45: if (h === 1) bgneal@45: return t._compareBoundaryPoints(sc, so, ec, eo); bgneal@45: bgneal@45: // Check END_TO_END bgneal@45: if (h === 2) bgneal@45: return t._compareBoundaryPoints(ec, eo, ec, eo); bgneal@45: bgneal@45: // Check END_TO_START bgneal@45: if (h === 3) bgneal@45: return t._compareBoundaryPoints(ec, eo, sc, so); bgneal@45: }, bgneal@45: bgneal@45: deleteContents : function() { bgneal@45: this._traverse(DELETE); bgneal@45: }, bgneal@45: bgneal@45: extractContents : function() { bgneal@45: return this._traverse(EXTRACT); bgneal@45: }, bgneal@45: bgneal@45: cloneContents : function() { bgneal@45: return this._traverse(CLONE); bgneal@45: }, bgneal@45: bgneal@45: insertNode : function(n) { bgneal@45: var t = this, nn, o; bgneal@45: bgneal@45: // Node is TEXT_NODE or CDATA bgneal@45: if (n.nodeType === 3 || n.nodeType === 4) { bgneal@45: nn = t.startContainer.splitText(t.startOffset); bgneal@45: t.startContainer.parentNode.insertBefore(n, nn); bgneal@45: } else { bgneal@45: // Insert element node bgneal@45: if (t.startContainer.childNodes.length > 0) bgneal@45: o = t.startContainer.childNodes[t.startOffset]; bgneal@45: bgneal@45: t.startContainer.insertBefore(n, o); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: surroundContents : function(n) { bgneal@45: var t = this, 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: cloneRange : function() { bgneal@45: var t = this; bgneal@45: bgneal@45: return extend(new Range(t.dom), { bgneal@45: startContainer : t.startContainer, bgneal@45: startOffset : t.startOffset, bgneal@45: endContainer : t.endContainer, bgneal@45: endOffset : t.endOffset, bgneal@45: collapsed : t.collapsed, bgneal@45: commonAncestorContainer : t.commonAncestorContainer bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: /* bgneal@45: toString : function() { bgneal@45: // Not implemented bgneal@45: }, bgneal@45: bgneal@45: detach : function() { bgneal@45: // Not implemented bgneal@45: }, bgneal@45: */ bgneal@45: // Internal methods bgneal@45: bgneal@45: _isCollapsed : function() { bgneal@45: return (this.startContainer == this.endContainer && this.startOffset == this.endOffset); bgneal@45: }, bgneal@45: bgneal@45: _compareBoundaryPoints : function (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: } else if (offsetA < offsetB) { bgneal@45: return -1; // before bgneal@45: } else { bgneal@45: return 1; // after bgneal@45: } 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: } else { bgneal@45: return 1; // after bgneal@45: } 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: } else { bgneal@45: return 1; // after bgneal@45: } 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 = this.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: bgneal@45: if (!childA) { bgneal@45: childA = cmnRoot; bgneal@45: } bgneal@45: bgneal@45: childB = containerB; bgneal@45: while (childB && childB.parentNode != cmnRoot) { bgneal@45: childB = childB.parentNode; bgneal@45: } bgneal@45: bgneal@45: if (!childB) { bgneal@45: childB = cmnRoot; bgneal@45: } bgneal@45: bgneal@45: if (childA == childB) { bgneal@45: return 0; // equal bgneal@45: } 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: bgneal@45: if (n == childB) { bgneal@45: return 1; // after bgneal@45: } bgneal@45: bgneal@45: n = n.nextSibling; bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: _setEndPoint : function(st, n, o) { bgneal@45: var t = this, ec, sc; bgneal@45: bgneal@45: if (st) { bgneal@45: t.startContainer = n; bgneal@45: t.startOffset = o; bgneal@45: } else { bgneal@45: t.endContainer = n; bgneal@45: t.endOffset = 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.endContainer; bgneal@45: while (ec.parentNode) bgneal@45: ec = ec.parentNode; bgneal@45: bgneal@45: sc = t.startContainer; bgneal@45: while (sc.parentNode) bgneal@45: sc = sc.parentNode; bgneal@45: bgneal@45: if (sc != ec) { bgneal@45: t.collapse(st); bgneal@45: } else { 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 (t._compareBoundaryPoints(t.startContainer, t.startOffset, t.endContainer, t.endOffset) > 0) bgneal@45: t.collapse(st); bgneal@45: } bgneal@45: bgneal@45: t.collapsed = t._isCollapsed(); bgneal@45: t.commonAncestorContainer = t.dom.findCommonAncestor(t.startContainer, t.endContainer); bgneal@45: }, bgneal@45: bgneal@45: // This code is heavily "inspired" by the Apache Xerces implementation. I hope they don't mind. :) bgneal@45: bgneal@45: _traverse : function(how) { bgneal@45: var t = this, c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep; bgneal@45: bgneal@45: if (t.startContainer == t.endContainer) bgneal@45: return t._traverseSameContainer(how); bgneal@45: bgneal@45: for (c = t.endContainer, p = c.parentNode; p != null; c = p, p = p.parentNode) { bgneal@45: if (p == t.startContainer) bgneal@45: return t._traverseCommonStartContainer(c, how); bgneal@45: bgneal@45: ++endContainerDepth; bgneal@45: } bgneal@45: bgneal@45: for (c = t.startContainer, p = c.parentNode; p != null; c = p, p = p.parentNode) { bgneal@45: if (p == t.endContainer) bgneal@45: return t._traverseCommonEndContainer(c, how); bgneal@45: bgneal@45: ++startContainerDepth; bgneal@45: } bgneal@45: bgneal@45: depthDiff = startContainerDepth - endContainerDepth; bgneal@45: bgneal@45: startNode = t.startContainer; bgneal@45: while (depthDiff > 0) { bgneal@45: startNode = startNode.parentNode; bgneal@45: depthDiff--; bgneal@45: } bgneal@45: bgneal@45: endNode = t.endContainer; 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 t._traverseCommonAncestors(startNode, endNode, how); bgneal@45: }, bgneal@45: bgneal@45: _traverseSameContainer : function(how) { bgneal@45: var t = this, frag, s, sub, n, cnt, sibling, xferNode; bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: frag = t.dom.doc.createDocumentFragment(); bgneal@45: bgneal@45: // If selection is empty, just return the fragment bgneal@45: if (t.startOffset == t.endOffset) bgneal@45: return frag; bgneal@45: bgneal@45: // Text node needs special case handling bgneal@45: if (t.startContainer.nodeType == 3 /* TEXT_NODE */) { bgneal@45: // get the substring bgneal@45: s = t.startContainer.nodeValue; bgneal@45: sub = s.substring(t.startOffset, t.endOffset); bgneal@45: bgneal@45: // set the original text node to its new value bgneal@45: if (how != CLONE) { bgneal@45: t.startContainer.deleteData(t.startOffset, t.endOffset - t.startOffset); 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 null; bgneal@45: bgneal@45: frag.appendChild(t.dom.doc.createTextNode(sub)); bgneal@45: return frag; bgneal@45: } bgneal@45: bgneal@45: // Copy nodes between the start/end offsets. bgneal@45: n = getSelectedNode(t.startContainer, t.startOffset); bgneal@45: cnt = t.endOffset - t.startOffset; bgneal@45: bgneal@45: while (cnt > 0) { bgneal@45: sibling = n.nextSibling; bgneal@45: xferNode = t._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: _traverseCommonStartContainer : function(endAncestor, how) { bgneal@45: var t = this, frag, n, endIdx, cnt, sibling, xferNode; bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: frag = t.dom.doc.createDocumentFragment(); bgneal@45: bgneal@45: n = t._traverseRightBoundary(endAncestor, how); bgneal@45: bgneal@45: if (frag) bgneal@45: frag.appendChild(n); bgneal@45: bgneal@45: endIdx = indexOf(endAncestor, t.startContainer); bgneal@45: cnt = endIdx - t.startOffset; 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 = t._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: _traverseCommonEndContainer : function(startAncestor, how) { bgneal@45: var t = this, frag, startIdx, n, cnt, sibling, xferNode; bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: frag = t.dom.doc.createDocumentFragment(); bgneal@45: bgneal@45: n = t._traverseLeftBoundary(startAncestor, how); bgneal@45: if (frag) bgneal@45: frag.appendChild(n); bgneal@45: bgneal@45: startIdx = indexOf(startAncestor, t.endContainer); bgneal@45: ++startIdx; // Because we already traversed it.... bgneal@45: bgneal@45: cnt = t.endOffset - startIdx; bgneal@45: n = startAncestor.nextSibling; bgneal@45: while (cnt > 0) { bgneal@45: sibling = n.nextSibling; bgneal@45: xferNode = t._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: _traverseCommonAncestors : function(startAncestor, endAncestor, how) { bgneal@45: var t = this, n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling; bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: frag = t.dom.doc.createDocumentFragment(); bgneal@45: bgneal@45: n = t._traverseLeftBoundary(startAncestor, how); bgneal@45: if (frag) bgneal@45: frag.appendChild(n); bgneal@45: bgneal@45: commonParent = startAncestor.parentNode; bgneal@45: startOffset = indexOf(startAncestor, commonParent); bgneal@45: endOffset = indexOf(endAncestor, commonParent); 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 = t._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 = t._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: _traverseRightBoundary : function(root, how) { bgneal@45: var t = this, next = getSelectedNode(t.endContainer, t.endOffset - 1), parent, clonedParent, prevSibling, clonedChild, clonedGrandParent; bgneal@45: var isFullySelected = next != t.endContainer; bgneal@45: bgneal@45: if (next == root) bgneal@45: return t._traverseNode(next, isFullySelected, false, how); bgneal@45: bgneal@45: parent = next.parentNode; bgneal@45: clonedParent = t._traverseNode(parent, false, false, how); bgneal@45: bgneal@45: while (parent != null) { bgneal@45: while (next != null) { bgneal@45: prevSibling = next.previousSibling; bgneal@45: clonedChild = t._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 = t._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: // should never occur bgneal@45: return null; bgneal@45: }, bgneal@45: bgneal@45: _traverseLeftBoundary : function(root, how) { bgneal@45: var t = this, next = getSelectedNode(t.startContainer, t.startOffset); bgneal@45: var isFullySelected = next != t.startContainer, parent, clonedParent, nextSibling, clonedChild, clonedGrandParent; bgneal@45: bgneal@45: if (next == root) bgneal@45: return t._traverseNode(next, isFullySelected, true, how); bgneal@45: bgneal@45: parent = next.parentNode; bgneal@45: clonedParent = t._traverseNode(parent, false, true, how); bgneal@45: bgneal@45: while (parent != null) { bgneal@45: while (next != null) { bgneal@45: nextSibling = next.nextSibling; bgneal@45: clonedChild = t._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 = t._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: // should never occur bgneal@45: return null; bgneal@45: }, bgneal@45: bgneal@45: _traverseNode : function(n, isFullySelected, isLeft, how) { bgneal@45: var t = this, txtValue, newNodeValue, oldNodeValue, offset, newNode; bgneal@45: bgneal@45: if (isFullySelected) bgneal@45: return t._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.startOffset; bgneal@45: newNodeValue = txtValue.substring(offset); bgneal@45: oldNodeValue = txtValue.substring(0, offset); bgneal@45: } else { bgneal@45: offset = t.endOffset; 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 null; bgneal@45: bgneal@45: newNode = n.cloneNode(false); bgneal@45: newNode.nodeValue = newNodeValue; bgneal@45: bgneal@45: return newNode; bgneal@45: } bgneal@45: bgneal@45: if (how == DELETE) bgneal@45: return null; bgneal@45: bgneal@45: return n.cloneNode(false); bgneal@45: }, bgneal@45: bgneal@45: _traverseFullySelected : function(n, how) { bgneal@45: var t = this; bgneal@45: bgneal@45: if (how != DELETE) bgneal@45: return how == CLONE ? n.cloneNode(true) : n; bgneal@45: bgneal@45: n.parentNode.removeChild(n); bgneal@45: return null; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: ns.Range = Range; bgneal@45: })(tinymce.dom); bgneal@45: (function() { bgneal@45: function Selection(selection) { bgneal@45: var t = this; bgneal@45: bgneal@45: function getRange() { bgneal@45: var dom = selection.dom, ieRange = selection.getRng(), domRange = dom.createRng(), startPos = {}, endPos = {}; bgneal@45: bgneal@45: // Handle control selection bgneal@45: if (ieRange.item) { bgneal@45: domRange.setStartBefore(ieRange.item(0)); bgneal@45: domRange.setEndAfter(ieRange.item(0)); bgneal@45: bgneal@45: return domRange; bgneal@45: } bgneal@45: bgneal@45: function findEndPoint(ie_rng, start, pos) { bgneal@45: var rng, rng2, startElement; bgneal@45: bgneal@45: rng = ie_rng.duplicate(); bgneal@45: rng.collapse(start); bgneal@45: element = rng.parentElement(); bgneal@45: bgneal@45: // If element is block then we need to move one character bgneal@45: // since the selection has a extra invisible character bgneal@45: if (element.currentStyle.display == 'block') { bgneal@45: rng = ie_rng.duplicate(); bgneal@45: rng2 = ie_rng.duplicate(); bgneal@45: bgneal@45: // Move one character at beginning/end of selection bgneal@45: if (start) bgneal@45: rng.moveStart('character', 1); bgneal@45: else bgneal@45: rng.moveEnd('character', -1); bgneal@45: bgneal@45: // The range shouldn't have been changed so lets restore it bgneal@45: if (rng.text != rng2.text) bgneal@45: rng = rng2; bgneal@45: bgneal@45: rng.collapse(start); bgneal@45: element = rng.parentElement(); bgneal@45: } bgneal@45: bgneal@45: pos.parent = element; bgneal@45: pos.range = rng; bgneal@45: }; bgneal@45: bgneal@45: function findIndexAndOffset(pos) { bgneal@45: var rng = pos.range, i, nl, marker, sibling, idx = 0; bgneal@45: bgneal@45: // Set parent and offset bgneal@45: pos.offset = 0; bgneal@45: pos.parent = rng.parentElement(); bgneal@45: bgneal@45: // Insert marker bgneal@45: rng.pasteHTML(''); bgneal@45: marker = dom.get('_mce'); bgneal@45: bgneal@45: // Find the makers node index excluding text node fragmentation bgneal@45: nl = pos.parent.childNodes; bgneal@45: for (i = 0; i < nl.length; i++) { bgneal@45: if (nl[i] == marker) { bgneal@45: pos.index = idx; bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: if (i > 0 && (nl[i].nodeType != 3 || nl[i - 1].nodeType != 3)) bgneal@45: idx++; bgneal@45: } bgneal@45: bgneal@45: // Figure out the character offset excluding text node fragmentation bgneal@45: sibling = marker.previousSibling; bgneal@45: if (sibling) { bgneal@45: if (sibling.nodeType === 3) { bgneal@45: do { bgneal@45: pos.offset += sibling.nodeValue.length; bgneal@45: } while ((sibling = sibling.previousSibling) && sibling.nodeType == 3); bgneal@45: } else bgneal@45: pos.index++; bgneal@45: } bgneal@45: bgneal@45: // Remove the marker bgneal@45: dom.remove(marker); bgneal@45: bgneal@45: return pos; bgneal@45: }; bgneal@45: bgneal@45: // Find end points bgneal@45: findEndPoint(ieRange, true, startPos); bgneal@45: findEndPoint(ieRange, false, endPos); bgneal@45: bgneal@45: // Find start and end positions bgneal@45: findIndexAndOffset(startPos); bgneal@45: findIndexAndOffset(endPos); bgneal@45: bgneal@45: // Normalize the elements to avoid fragmented dom bgneal@45: startPos.parent.normalize(); bgneal@45: endPos.parent.normalize(); bgneal@45: bgneal@45: // Set start and end points of the domRange bgneal@45: domRange.setStart(startPos.parent.childNodes[startPos.index], startPos.offset); bgneal@45: domRange.setEnd(endPos.parent.childNodes[endPos.index], endPos.offset); bgneal@45: bgneal@45: // Restore selection to new range bgneal@45: t.addRange(domRange); bgneal@45: bgneal@45: return domRange; bgneal@45: }; bgneal@45: bgneal@45: this.addRange = function(rng) { bgneal@45: var ieRng, startPos, endPos, body = selection.dom.doc.body; bgneal@45: bgneal@45: // Element selection, then make a control range bgneal@45: if (rng.startContainer.nodeType == 1) { bgneal@45: ieRng = body.createControlRange(); bgneal@45: ieRng.addElement(rng.startContainer.childNodes[rng.startOffset]); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: function findPos(start) { bgneal@45: var container, offset, rng2, pos; bgneal@45: bgneal@45: // Get container and offset bgneal@45: container = start ? rng.startContainer : rng.endContainer; bgneal@45: offset = start ? rng.startOffset : rng.endOffset; bgneal@45: bgneal@45: // Insert marker character bgneal@45: container.nodeValue = container.nodeValue.substring(0, offset) + '\uFEFF' + container.nodeValue.substring(offset); bgneal@45: bgneal@45: // Create range for whole parent element bgneal@45: rng2 = body.createTextRange(); bgneal@45: rng2.moveToElementText(container.parentNode); bgneal@45: pos = rng2.text.indexOf('\uFEFF'); bgneal@45: container.nodeValue = container.nodeValue.replace(/\uFEFF/, ''); bgneal@45: bgneal@45: if (start) bgneal@45: startPos = pos; bgneal@45: else bgneal@45: endPos = pos; bgneal@45: }; bgneal@45: bgneal@45: function setPos(start) { bgneal@45: var rng2, container = start ? rng.startContainer : rng.endContainer; bgneal@45: bgneal@45: rng2 = body.createTextRange(); bgneal@45: rng2.moveToElementText(container.parentNode); bgneal@45: rng2.collapse(true); bgneal@45: rng2.move('character', start ? startPos : endPos); bgneal@45: bgneal@45: if (start) bgneal@45: ieRng.setEndPoint('StartToStart', rng2); bgneal@45: else bgneal@45: ieRng.setEndPoint('EndToStart', rng2); bgneal@45: }; bgneal@45: bgneal@45: // Create IE specific range bgneal@45: ieRng = body.createTextRange(); bgneal@45: bgneal@45: // Find start/end pos bgneal@45: findPos(true); bgneal@45: findPos(false); bgneal@45: bgneal@45: // Set start/end pos bgneal@45: setPos(true); bgneal@45: setPos(false); bgneal@45: bgneal@45: ieRng.select(); bgneal@45: }; bgneal@45: bgneal@45: this.getRangeAt = function() { bgneal@45: // todo: Implement range caching here later bgneal@45: return getRange(); bgneal@45: }; bgneal@45: }; bgneal@45: bgneal@45: // Expose the selection object bgneal@45: tinymce.dom.TridentSelection = Selection; 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*)?/g, bgneal@45: done = 0, bgneal@45: toString = Object.prototype.toString, bgneal@45: arraySplice = Array.prototype.splice, bgneal@45: arrayPush = Array.prototype.push, bgneal@45: arraySort = Array.prototype.sort; bgneal@45: bgneal@45: var Sizzle = function(selector, context, results, seed) { bgneal@45: results = results || []; bgneal@45: var origContext = context = context || document; 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, check, mode, extra, prune = true, contextXML = isXML(context); bgneal@45: bgneal@45: // Reset the position of the chunker regexp (start from head) bgneal@45: chunker.lastIndex = 0; bgneal@45: bgneal@45: while ( (m = chunker.exec(selector)) !== null ) { bgneal@45: parts.push( m[1] ); bgneal@45: bgneal@45: if ( m[2] ) { bgneal@45: extra = RegExp.rightContext; bgneal@45: break; bgneal@45: } bgneal@45: } 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: 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: var 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: var 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: var cur = parts.pop(), 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: throw "Syntax error, unrecognized expression: " + (cur || selector); bgneal@45: } bgneal@45: bgneal@45: if ( toString.call(checkSet) === "[object Array]" ) { bgneal@45: if ( !prune ) { bgneal@45: arrayPush.apply( results, checkSet ); bgneal@45: } else if ( context && context.nodeType === 1 ) { bgneal@45: for ( var i = 0; checkSet[i] != null; i++ ) { bgneal@45: if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) { bgneal@45: arrayPush.call( results, set[i] ); bgneal@45: } bgneal@45: } bgneal@45: } else { bgneal@45: for ( var i = 0; checkSet[i] != null; i++ ) { bgneal@45: if ( checkSet[i] && checkSet[i].nodeType === 1 ) { bgneal@45: arrayPush.call( results, 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 = false; bgneal@45: arraySort.call(results, 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: arraySplice.call(results, i--, 1); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } 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, match; 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.match[ type ].exec( expr )) ) { bgneal@45: var left = RegExp.leftContext; 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] && isXML(set[0]); bgneal@45: bgneal@45: while ( expr && set.length ) { bgneal@45: for ( var type in Expr.filter ) { bgneal@45: if ( (match = Expr.match[ type ].exec( expr )) != null ) { bgneal@45: var filter = Expr.filter[ type ], found, item; bgneal@45: anyFound = false; 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: throw "Syntax error, unrecognized expression: " + 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: 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\(\)]*)+)\2\))?/ bgneal@45: }, 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, isXML){ 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 && !isXML ) { bgneal@45: part = part.toUpperCase(); 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 === 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, isXML){ bgneal@45: var isPartStr = typeof part === "string"; bgneal@45: bgneal@45: if ( isPartStr && !/\W/.test(part) ) { bgneal@45: part = isXML ? part : part.toUpperCase(); bgneal@45: bgneal@45: for ( var i = 0, l = checkSet.length; i < l; i++ ) { bgneal@45: var elem = checkSet[i]; bgneal@45: if ( elem ) { bgneal@45: var parent = elem.parentNode; bgneal@45: checkSet[i] = parent.nodeName === part ? parent : false; bgneal@45: } bgneal@45: } bgneal@45: } else { bgneal@45: for ( var i = 0, l = checkSet.length; i < l; i++ ) { bgneal@45: var 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; bgneal@45: bgneal@45: if ( !part.match(/\W/) ) { bgneal@45: var nodeCheck = part = isXML ? part : part.toUpperCase(); 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; bgneal@45: bgneal@45: if ( typeof part === "string" && !part.match(/\W/) ) { bgneal@45: var nodeCheck = part = isXML ? part : part.toUpperCase(); 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, isXML){ 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 + " ").indexOf(match) >= 0) ) { bgneal@45: if ( !inplace ) bgneal@45: result.push( elem ); 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: for ( var i = 0; curLoop[i] === false; i++ ){} bgneal@45: return curLoop[i] && isXML(curLoop[i]) ? match[1] : match[1].toUpperCase(); 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 ( match[3].match(chunker).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.toUpperCase() === "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 || "").indexOf(match[3]) >= 0; bgneal@45: } else if ( name === "not" ) { bgneal@45: var not = match[3]; bgneal@45: bgneal@45: for ( var i = 0, l = not.length; i < l; i++ ) { bgneal@45: if ( not[i] === elem ) { bgneal@45: return false; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return true; 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 ) return false; bgneal@45: } bgneal@45: if ( type == 'first') return true; bgneal@45: node = elem; bgneal@45: case 'last': bgneal@45: while (node = node.nextSibling) { bgneal@45: if ( node.nodeType === 1 ) return false; 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 === 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: bgneal@45: for ( var type in Expr.match ) { bgneal@45: Expr.match[ type ] = new RegExp( Expr.match[ type ].source + /(?![^\[]*\])(?![^\(]*\))/.source ); bgneal@45: } bgneal@45: bgneal@45: var makeArray = function(array, results) { bgneal@45: array = Array.prototype.slice.call( array ); bgneal@45: bgneal@45: if ( results ) { bgneal@45: arrayPush.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: try { bgneal@45: Array.prototype.slice.call( document.documentElement.childNodes ); 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 || []; 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 i = 0, l = array.length; i < l; i++ ) { bgneal@45: ret.push( array[i] ); bgneal@45: } bgneal@45: } else { bgneal@45: for ( var i = 0; 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: 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: 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: var aRange = a.ownerDocument.createRange(), bRange = b.ownerDocument.createRange(); bgneal@45: aRange.selectNode(a); bgneal@45: aRange.collapse(true); bgneal@45: bRange.selectNode(b); bgneal@45: bRange.collapse(true); 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: // 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("form"), 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: })(); 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: bgneal@45: if ( document.querySelectorAll ) (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 && !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: bgneal@45: if ( document.getElementsByClassName && document.documentElement.getElementsByClassName ) (function(){ bgneal@45: var div = document.createElement("div"); bgneal@45: div.innerHTML = "
"; bgneal@45: bgneal@45: // Opera can't find a second classname (in 9.6) bgneal@45: if ( div.getElementsByClassName("e").length === 0 ) bgneal@45: return; 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: 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: bgneal@45: function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { bgneal@45: var sibDir = dir == "previousSibling" && !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: if ( sibDir && elem.nodeType === 1 ){ bgneal@45: elem.sizcache = doneName; bgneal@45: elem.sizset = i; bgneal@45: } 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 === 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: var sibDir = dir == "previousSibling" && !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: if ( sibDir && elem.nodeType === 1 ) { bgneal@45: elem.sizcache = doneName; bgneal@45: elem.sizset = i; bgneal@45: } 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: var 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: var isXML = function(elem){ bgneal@45: return elem.nodeType === 9 && elem.documentElement.nodeName !== "HTML" || bgneal@45: !!elem.ownerDocument && elem.ownerDocument.documentElement.nodeName !== "HTML"; 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: (function(tinymce) { bgneal@45: // Shorten names bgneal@45: var each = tinymce.each, DOM = tinymce.DOM, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, Event; bgneal@45: bgneal@45: tinymce.create('static tinymce.dom.Event', { bgneal@45: inits : [], bgneal@45: events : [], bgneal@45: bgneal@45: bgneal@45: add : function(o, n, f, s) { bgneal@45: var cb, t = this, el = t.events, r; bgneal@45: bgneal@45: // Handle array bgneal@45: if (o && o.hasOwnProperty && o instanceof Array) { bgneal@45: r = []; bgneal@45: bgneal@45: each(o, function(o) { bgneal@45: o = DOM.get(o); bgneal@45: r.push(t.add(o, n, f, s)); bgneal@45: }); bgneal@45: bgneal@45: return r; bgneal@45: } bgneal@45: bgneal@45: o = DOM.get(o); bgneal@45: bgneal@45: if (!o) bgneal@45: return; bgneal@45: bgneal@45: // Setup event callback bgneal@45: cb = function(e) { bgneal@45: e = e || window.event; bgneal@45: bgneal@45: // Patch in target in IE it's W3C valid bgneal@45: if (e && !e.target && isIE) bgneal@45: e.target = e.srcElement; bgneal@45: bgneal@45: if (!s) bgneal@45: return f(e); bgneal@45: bgneal@45: return f.call(s, e); bgneal@45: }; bgneal@45: bgneal@45: if (n == 'unload') { bgneal@45: tinymce.unloads.unshift({func : cb}); bgneal@45: return cb; bgneal@45: } bgneal@45: bgneal@45: if (n == 'init') { bgneal@45: if (t.domLoaded) bgneal@45: cb(); bgneal@45: else bgneal@45: t.inits.push(cb); bgneal@45: bgneal@45: return cb; bgneal@45: } bgneal@45: bgneal@45: // Store away listener reference bgneal@45: el.push({ bgneal@45: obj : o, bgneal@45: name : n, bgneal@45: func : f, bgneal@45: cfunc : cb, bgneal@45: scope : s bgneal@45: }); bgneal@45: bgneal@45: t._add(o, n, cb); bgneal@45: bgneal@45: return f; bgneal@45: }, bgneal@45: bgneal@45: remove : function(o, n, f) { bgneal@45: var t = this, a = t.events, s = false, r; bgneal@45: bgneal@45: // Handle array bgneal@45: if (o && o.hasOwnProperty && o instanceof Array) { bgneal@45: r = []; bgneal@45: bgneal@45: each(o, function(o) { bgneal@45: o = DOM.get(o); bgneal@45: r.push(t.remove(o, n, f)); bgneal@45: }); bgneal@45: bgneal@45: return r; bgneal@45: } bgneal@45: bgneal@45: o = DOM.get(o); bgneal@45: bgneal@45: each(a, function(e, i) { bgneal@45: if (e.obj == o && e.name == n && (!f || (e.func == f || e.cfunc == f))) { bgneal@45: a.splice(i, 1); bgneal@45: t._remove(o, n, e.cfunc); bgneal@45: s = true; bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: return s; bgneal@45: }, bgneal@45: bgneal@45: clear : function(o) { bgneal@45: var t = this, a = t.events, i, e; bgneal@45: bgneal@45: if (o) { bgneal@45: o = DOM.get(o); bgneal@45: bgneal@45: for (i = a.length - 1; i >= 0; i--) { bgneal@45: e = a[i]; bgneal@45: bgneal@45: if (e.obj === o) { bgneal@45: t._remove(e.obj, e.name, e.cfunc); bgneal@45: e.obj = e.cfunc = null; bgneal@45: a.splice(i, 1); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: bgneal@45: cancel : function(e) { bgneal@45: if (!e) bgneal@45: return false; bgneal@45: bgneal@45: this.stop(e); bgneal@45: return this.prevent(e); bgneal@45: }, bgneal@45: bgneal@45: stop : function(e) { bgneal@45: if (e.stopPropagation) bgneal@45: e.stopPropagation(); bgneal@45: else bgneal@45: e.cancelBubble = true; bgneal@45: bgneal@45: return false; bgneal@45: }, bgneal@45: bgneal@45: prevent : function(e) { bgneal@45: if (e.preventDefault) bgneal@45: e.preventDefault(); bgneal@45: else bgneal@45: e.returnValue = false; bgneal@45: bgneal@45: return false; bgneal@45: }, bgneal@45: bgneal@45: _unload : function() { bgneal@45: var t = Event; bgneal@45: bgneal@45: each(t.events, function(e, i) { bgneal@45: t._remove(e.obj, e.name, e.cfunc); bgneal@45: e.obj = e.cfunc = null; bgneal@45: }); bgneal@45: bgneal@45: t.events = []; bgneal@45: t = null; bgneal@45: }, bgneal@45: bgneal@45: _add : function(o, n, f) { bgneal@45: if (o.attachEvent) bgneal@45: o.attachEvent('on' + n, f); bgneal@45: else if (o.addEventListener) bgneal@45: o.addEventListener(n, f, false); bgneal@45: else bgneal@45: o['on' + n] = f; bgneal@45: }, bgneal@45: bgneal@45: _remove : function(o, n, f) { bgneal@45: if (o) { bgneal@45: try { bgneal@45: if (o.detachEvent) bgneal@45: o.detachEvent('on' + n, f); bgneal@45: else if (o.removeEventListener) bgneal@45: o.removeEventListener(n, f, false); bgneal@45: else bgneal@45: o['on' + n] = null; bgneal@45: } catch (ex) { bgneal@45: // Might fail with permission denined on IE so we just ignore that bgneal@45: } bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: _pageInit : function() { bgneal@45: var e = Event; bgneal@45: bgneal@45: // Safari on Mac fires this twice bgneal@45: if (e.domLoaded) bgneal@45: return; bgneal@45: bgneal@45: e._remove(window, 'DOMContentLoaded', e._pageInit); bgneal@45: e.domLoaded = true; bgneal@45: bgneal@45: each(e.inits, function(c) { bgneal@45: c(); bgneal@45: }); bgneal@45: bgneal@45: e.inits = []; bgneal@45: }, bgneal@45: bgneal@45: _wait : function() { bgneal@45: var t; bgneal@45: bgneal@45: // No need since the document is already loaded bgneal@45: if (window.tinyMCE_GZ && tinyMCE_GZ.loaded) { bgneal@45: Event.domLoaded = 1; bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: if (isIE && document.location.protocol != 'https:') { bgneal@45: // Fake DOMContentLoaded on IE bgneal@45: document.write(''; 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) { bgneal@45: // We need to write the contents here in IE since multiple writes messes up refresh button and back button bgneal@45: if (isIE || (tinymce.isOpera && parseFloat(opera.version()) >= 9.5)) 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: else if (tinymce.isOpera) bgneal@45: u = 'javascript:(function(){document.open();document.domain="' + document.domain + '";document.close();ed.setupIframe();})()'; bgneal@45: } bgneal@45: bgneal@45: // Create iframe 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: style : { bgneal@45: width : '100%', bgneal@45: height : h 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: bgneal@45: if (!isIE || !tinymce.relaxedDomain) 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: bgneal@45: // Design mode needs to be added here Ctrl+A will fail otherwise bgneal@45: if (!isIE) { bgneal@45: try { bgneal@45: if (!s.readonly) bgneal@45: d.designMode = 'On'; bgneal@45: } catch (ex) { bgneal@45: // Will fail on Gecko if the editor is placed in an hidden container element bgneal@45: // The design mode will be set ones the editor is focused bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // IE needs to use contentEditable or it will display non secure items for HTTPS bgneal@45: if (isIE) { bgneal@45: // It will not steal focus if we hide it while setting contentEditable bgneal@45: b = t.getBody(); bgneal@45: DOM.hide(b); bgneal@45: bgneal@45: if (!s.readonly) bgneal@45: b.contentEditable = true; bgneal@45: bgneal@45: DOM.show(b); bgneal@45: } bgneal@45: bgneal@45: // Setup objects 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: }); bgneal@45: bgneal@45: t.serializer = new tinymce.dom.Serializer({ bgneal@45: entity_encoding : s.entity_encoding, bgneal@45: entities : s.entities, bgneal@45: valid_elements : s.verify_html === false ? '*[*]' : s.valid_elements, bgneal@45: extended_valid_elements : s.extended_valid_elements, bgneal@45: valid_child_elements : s.valid_child_elements, bgneal@45: invalid_elements : s.invalid_elements, bgneal@45: fix_table_elements : s.fix_table_elements, bgneal@45: fix_list_elements : s.fix_list_elements, bgneal@45: fix_content_duplication : s.fix_content_duplication, bgneal@45: convert_fonts_to_spans : s.convert_fonts_to_spans, bgneal@45: font_size_classes : s.font_size_classes, bgneal@45: font_size_style_values : s.font_size_style_values, bgneal@45: apply_source_formatting : s.apply_source_formatting, bgneal@45: remove_linebreaks : s.remove_linebreaks, bgneal@45: element_format : s.element_format, bgneal@45: dom : t.dom bgneal@45: }); bgneal@45: bgneal@45: t.selection = new tinymce.dom.Selection(t.dom, t.getWin(), t.serializer); bgneal@45: t.forceBlocks = new tinymce.ForceBlocks(t, { bgneal@45: forced_root_block : s.forced_root_block 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: 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.auto_resize) bgneal@45: t.onNodeChange.add(t.resizeToContent, t); bgneal@45: bgneal@45: if (s.custom_elements) { bgneal@45: function handleCustom(ed, o) { bgneal@45: each(explode(s.custom_elements), function(v) { bgneal@45: var n; bgneal@45: bgneal@45: if (v.indexOf('~') === 0) { bgneal@45: v = v.substring(1); bgneal@45: n = 'span'; bgneal@45: } else bgneal@45: n = 'div'; bgneal@45: bgneal@45: o.content = o.content.replace(new RegExp('<(' + v + ')([^>]*)>', 'g'), '<' + n + ' mce_name="$1"$2>'); bgneal@45: o.content = o.content.replace(new RegExp('', 'g'), ''); bgneal@45: }); bgneal@45: }; bgneal@45: bgneal@45: t.onBeforeSetContent.add(handleCustom); bgneal@45: t.onPostProcess.add(function(ed, o) { bgneal@45: if (o.set) bgneal@45: handleCustom(ed, o) bgneal@45: }); bgneal@45: } 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.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.fix_nesting && isIE) { bgneal@45: t.onBeforeSetContent.add(function(ed, o) { bgneal@45: o.content = t._fixNesting(o.content); 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.convert_fonts_to_spans) bgneal@45: t._convertFonts(); bgneal@45: bgneal@45: if (s.inline_styles) bgneal@45: t._convertInlineElements(); 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: // 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: if (isGecko) { 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', {'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: if (isGecko && !s.readonly) { bgneal@45: try { bgneal@45: // Design mode must be set here once again to fix a bug where bgneal@45: // Ctrl+A/Delete/Backspace didn't work if the editor was added using mceAddControl then removed then added again bgneal@45: d.designMode = 'Off'; bgneal@45: d.designMode = 'On'; bgneal@45: } catch (ex) { bgneal@45: // Will fail on Gecko if the editor is placed in an hidden container element bgneal@45: // The design mode will be set ones the editor is focused bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // A small timeout was needed since firefox will remove. Bug: #1838304 bgneal@45: setTimeout(function () { bgneal@45: if (t.removed) bgneal@45: return; bgneal@45: bgneal@45: t.load({initial : true, format : (s.cleanup_on_startup ? 'html' : 'raw')}); bgneal@45: t.startContent = t.getContent({format : 'raw'}); bgneal@45: t.undoManager.add({initial : true}); 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: if (s.content_css) { bgneal@45: tinymce.each(explode(s.content_css), function(u) { bgneal@45: t.dom.loadCSS(t.documentBaseURI.toAbsolute(u)); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // Handle auto focus bgneal@45: if (s.auto_focus) { bgneal@45: setTimeout(function () { bgneal@45: var ed = EditorManager.get(s.auto_focus); bgneal@45: bgneal@45: ed.selection.select(ed.getBody(), 1); bgneal@45: ed.selection.collapse(1); bgneal@45: ed.getWin().focus(); bgneal@45: }, 100); bgneal@45: } bgneal@45: }, 1); bgneal@45: bgneal@45: e = null; bgneal@45: }, bgneal@45: bgneal@45: bgneal@45: focus : function(sf) { bgneal@45: var oed, t = this, ce = t.settings.content_editable; bgneal@45: bgneal@45: if (!sf) { bgneal@45: // Is not content editable or the selection is outside the area in IE bgneal@45: // the IE statement is needed to avoid bluring if element selections inside layers since bgneal@45: // the layer is like it's own document in IE bgneal@45: if (!ce && (!isIE || t.selection.getNode().ownerDocument != t.getDoc())) bgneal@45: t.getWin().focus(); bgneal@45: bgneal@45: } bgneal@45: bgneal@45: if (EditorManager.activeEditor != t) { bgneal@45: if ((oed = EditorManager.activeEditor) != null) bgneal@45: oed.onDeactivate.dispatch(oed, t); bgneal@45: bgneal@45: t.onActivate.dispatch(t, oed); bgneal@45: } bgneal@45: bgneal@45: EditorManager._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 = EditorManager.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 EditorManager.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.getNode() || 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: t.onNodeChange.dispatch( bgneal@45: t, bgneal@45: o ? o.controlManager || t.controlManager : t.controlManager, bgneal@45: isIE && n.ownerDocument != t.getDoc() ? t.getBody() : n, // Fix for IE initial state 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(n, f, s) { bgneal@45: this.execCommands[n] = {func : f, scope : s || this}; bgneal@45: }, bgneal@45: bgneal@45: addQueryStateHandler : function(n, f, s) { bgneal@45: this.queryStateCommands[n] = {func : f, scope : s || this}; bgneal@45: }, bgneal@45: bgneal@45: addQueryValueHandler : function(n, f, s) { bgneal@45: this.queryValueCommands[n] = {func : f, scope : s || 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: o = {}; bgneal@45: t.onBeforeExecCommand.dispatch(t, cmd, ui, val, o); bgneal@45: if (o.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: // Execute global commands bgneal@45: if (tinymce.GlobalCommands.execCommand(t, 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(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.queryStateCommands[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.queryCommandState(c); bgneal@45: if (o !== -1) bgneal@45: return o; bgneal@45: bgneal@45: // Browser commands bgneal@45: try { bgneal@45: return this.getDoc().queryCommandState(c); 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: resizeToContent : function() { bgneal@45: var t = this; bgneal@45: bgneal@45: DOM.setStyle(t.id + "_ifr", 'height', t.getBody().scrollHeight); 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 = 0; 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(h, o) { bgneal@45: var t = this; bgneal@45: bgneal@45: o = o || {}; bgneal@45: o.format = o.format || 'html'; bgneal@45: o.set = true; bgneal@45: o.content = h; bgneal@45: bgneal@45: if (!o.no_events) bgneal@45: t.onBeforeSetContent.dispatch(t, o); 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 && (h.length === 0 || /^\s+$/.test(h))) { bgneal@45: o.content = t.dom.setHTML(t.getBody(), '
'); bgneal@45: o.format = 'raw'; bgneal@45: } bgneal@45: bgneal@45: o.content = t.dom.setHTML(t.getBody(), tinymce.trim(o.content)); bgneal@45: bgneal@45: if (o.format != 'raw' && t.settings.cleanup) { bgneal@45: o.getInner = true; bgneal@45: o.content = t.dom.setHTML(t.getBody(), t.serializer.serialize(t.getBody(), o)); bgneal@45: } bgneal@45: bgneal@45: if (!o.no_events) bgneal@45: t.onSetContent.dispatch(t, o); bgneal@45: bgneal@45: return o.content; bgneal@45: }, bgneal@45: bgneal@45: getContent : function(o) { bgneal@45: var t = this, h; bgneal@45: bgneal@45: o = o || {}; bgneal@45: o.format = o.format || 'html'; bgneal@45: o.get = true; bgneal@45: bgneal@45: if (!o.no_events) bgneal@45: t.onBeforeGetContent.dispatch(t, o); bgneal@45: bgneal@45: if (o.format != 'raw' && t.settings.cleanup) { bgneal@45: o.getInner = true; bgneal@45: h = t.serializer.serialize(t.getBody(), o); bgneal@45: } else bgneal@45: h = t.getBody().innerHTML; bgneal@45: bgneal@45: h = h.replace(/^\s*|\s*$/g, ''); bgneal@45: o.content = h; bgneal@45: bgneal@45: if (!o.no_events) bgneal@45: t.onGetContent.dispatch(t, o); bgneal@45: bgneal@45: return o.content; bgneal@45: }, bgneal@45: bgneal@45: isDirty : function() { bgneal@45: var t = this; bgneal@45: bgneal@45: return tinymce.trim(t.startContent) != tinymce.trim(t.getContent({format : 'raw', no_events : 1})) && !t.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: t.removed = 1; // Cancels post remove event execution bgneal@45: t.hide(); 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: EditorManager.remove(t); bgneal@45: DOM.remove(e); 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: 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: // 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: } 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, 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: if (tinymce.isOpera) { bgneal@45: // Fake contextmenu on Opera bgneal@45: Event.add(t.getBody(), 'mousedown', function(e) { bgneal@45: if (e.ctrlKey) { bgneal@45: e.fakeType = 'contextmenu'; bgneal@45: eventHandler(e); bgneal@45: } bgneal@45: }); bgneal@45: } else bgneal@45: Event.add(t.getBody(), k, eventHandler); bgneal@45: break; bgneal@45: bgneal@45: case 'paste': bgneal@45: Event.add(t.getBody(), k, function(e) { bgneal@45: var tx, h, el, r; bgneal@45: bgneal@45: // Get plain text data bgneal@45: if (e.clipboardData) bgneal@45: tx = e.clipboardData.getData('text/plain'); bgneal@45: else if (tinymce.isIE) bgneal@45: tx = t.getWin().clipboardData.getData('Text'); bgneal@45: bgneal@45: // Get HTML data bgneal@45: /*if (tinymce.isIE) { bgneal@45: el = DOM.add(DOM.doc.body, 'div', {style : 'visibility:hidden;overflow:hidden;position:absolute;width:1px;height:1px'}); bgneal@45: r = DOM.doc.body.createTextRange(); bgneal@45: r.moveToElementText(el); bgneal@45: r.execCommand('Paste'); bgneal@45: h = el.innerHTML; bgneal@45: DOM.remove(el); bgneal@45: }*/ bgneal@45: bgneal@45: eventHandler(e, {text : tx, html : h}); bgneal@45: }); bgneal@45: break; bgneal@45: bgneal@45: case 'submit': bgneal@45: case 'reset': bgneal@45: Event.add(t.getElement().form || DOM.getParent(t.id, 'form'), k, eventHandler); bgneal@45: break; bgneal@45: bgneal@45: default: bgneal@45: Event.add(s.content_editable ? t.getBody() : t.getDoc(), k, eventHandler); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: Event.add(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: // Convert all images to absolute URLs bgneal@45: /* t.onSetContent.add(function(ed, o) { bgneal@45: each(ed.dom.select('img'), function(e) { bgneal@45: var v; bgneal@45: bgneal@45: if (v = e.getAttribute('mce_src')) bgneal@45: e.src = t.documentBaseURI.toAbsolute(v); bgneal@45: }) bgneal@45: });*/ bgneal@45: bgneal@45: Event.add(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('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: if (t._isHidden()) { bgneal@45: try { bgneal@45: if (!s.content_editable) bgneal@45: d.designMode = 'On'; bgneal@45: } catch (ex) { bgneal@45: // Fails if it's hidden bgneal@45: } bgneal@45: } 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: // 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: if (isGecko) { 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: bgneal@45: // BlockFormat shortcuts keys bgneal@45: for (i=1; i<=6; i++) bgneal@45: t.addShortcut('ctrl+' + i, '', ['FormatBlock', false, '']); bgneal@45: bgneal@45: t.addShortcut('ctrl+7', '', ['FormatBlock', false, '

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

']); bgneal@45: t.addShortcut('ctrl+9', '', ['FormatBlock', false, '
']); 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: Event.add(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: Event.remove(re.node, re.ev, re.cb); bgneal@45: bgneal@45: if (!t.dom.hasClass(e, 'mceItemNoResize')) { bgneal@45: ev = 'resizeend'; bgneal@45: cb = Event.add(e, ev, function(e) { bgneal@45: var v; bgneal@45: bgneal@45: e = e.target; bgneal@45: bgneal@45: if (v = t.dom.getStyle(e, 'width')) { bgneal@45: t.dom.setAttrib(e, 'width', v.replace(/[^0-9%]+/g, '')); bgneal@45: t.dom.setStyle(e, 'width', ''); bgneal@45: } bgneal@45: bgneal@45: if (v = t.dom.getStyle(e, 'height')) { bgneal@45: t.dom.setAttrib(e, 'height', v.replace(/[^0-9%]+/g, '')); bgneal@45: t.dom.setStyle(e, 'height', ''); bgneal@45: } bgneal@45: }); bgneal@45: } else { bgneal@45: ev = 'resizestart'; bgneal@45: cb = Event.add(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: t.onKeyDown.add(function(ed, e) { bgneal@45: switch (e.keyCode) { bgneal@45: case 8: bgneal@45: // Fix IE control + backspace browser bug bgneal@45: if (t.selection.getRng().item) { bgneal@45: t.selection.getRng().item(0).removeNode(); bgneal@45: return Event.cancel(e); bgneal@45: } 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 = 0; bgneal@45: t.undoManager.add(); bgneal@45: }; bgneal@45: bgneal@45: // Add undo level on editor blur bgneal@45: if (tinymce.isIE) { bgneal@45: Event.add(t.getWin(), 'blur', function(e) { bgneal@45: var n; bgneal@45: bgneal@45: // Check added for fullscreen bug bgneal@45: if (t.selection) { bgneal@45: n = t.selection.getNode(); bgneal@45: bgneal@45: // Add undo level is selection was lost to another document bgneal@45: if (!t.removed && n.ownerDocument && n.ownerDocument != t.getDoc()) bgneal@45: addUndo(); bgneal@45: } bgneal@45: }); bgneal@45: } else { bgneal@45: Event.add(t.getDoc(), 'blur', function() { bgneal@45: if (t.selection && !t.removed) bgneal@45: addUndo(); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: t.onMouseDown.add(addUndo); bgneal@45: bgneal@45: t.onKeyUp.add(function(ed, e) { bgneal@45: if ((e.keyCode >= 33 && e.keyCode <= 36) || (e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 || e.keyCode == 45 || e.ctrlKey) { bgneal@45: t.undoManager.typing = 0; bgneal@45: t.undoManager.add(); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: t.onKeyDown.add(function(ed, e) { bgneal@45: // Is caracter positon keys bgneal@45: if ((e.keyCode >= 33 && e.keyCode <= 36) || (e.keyCode >= 37 && e.keyCode <= 40) || e.keyCode == 13 || e.keyCode == 45) { bgneal@45: if (t.undoManager.typing) { bgneal@45: t.undoManager.add(); bgneal@45: t.undoManager.typing = 0; bgneal@45: } bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: if (!t.undoManager.typing) { bgneal@45: t.undoManager.add(); bgneal@45: t.undoManager.typing = 1; bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: _convertInlineElements : function() { bgneal@45: var t = this, s = t.settings, dom = t.dom, v, e, na, st, sp; bgneal@45: bgneal@45: function convert(ed, o) { bgneal@45: if (!s.inline_styles) bgneal@45: return; bgneal@45: bgneal@45: if (o.get) { bgneal@45: each(t.dom.select('table,u,strike', o.node), function(n) { bgneal@45: switch (n.nodeName) { bgneal@45: case 'TABLE': bgneal@45: if (v = dom.getAttrib(n, 'height')) { bgneal@45: dom.setStyle(n, 'height', v); bgneal@45: dom.setAttrib(n, 'height', ''); bgneal@45: } bgneal@45: break; bgneal@45: bgneal@45: case 'U': bgneal@45: case 'STRIKE': bgneal@45: //sp = dom.create('span', {style : dom.getAttrib(n, 'style')}); bgneal@45: n.style.textDecoration = n.nodeName == 'U' ? 'underline' : 'line-through'; bgneal@45: dom.setAttrib(n, 'mce_style', ''); bgneal@45: dom.setAttrib(n, 'mce_name', 'span'); bgneal@45: break; bgneal@45: } bgneal@45: }); bgneal@45: } else if (o.set) { bgneal@45: each(t.dom.select('table,span', o.node).reverse(), function(n) { bgneal@45: if (n.nodeName == 'TABLE') { bgneal@45: if (v = dom.getStyle(n, 'height')) bgneal@45: dom.setAttrib(n, 'height', v.replace(/[^0-9%]+/g, '')); bgneal@45: } else { bgneal@45: // Convert spans to elements bgneal@45: if (n.style.textDecoration == 'underline') bgneal@45: na = 'u'; bgneal@45: else if (n.style.textDecoration == 'line-through') bgneal@45: na = 'strike'; bgneal@45: else bgneal@45: na = ''; bgneal@45: bgneal@45: if (na) { bgneal@45: n.style.textDecoration = ''; bgneal@45: dom.setAttrib(n, 'mce_style', ''); bgneal@45: bgneal@45: e = dom.create(na, { bgneal@45: style : dom.getAttrib(n, 'style') bgneal@45: }); bgneal@45: bgneal@45: dom.replace(e, n, 1); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: t.onPreProcess.add(convert); bgneal@45: bgneal@45: if (!s.cleanup_on_startup) { bgneal@45: t.onSetContent.add(function(ed, o) { bgneal@45: if (o.initial) bgneal@45: convert(t, {node : t.getBody(), set : 1}); bgneal@45: }); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: _convertFonts : function() { bgneal@45: var t = this, s = t.settings, dom = t.dom, fz, fzn, sl, cl; bgneal@45: bgneal@45: // No need bgneal@45: if (!s.inline_styles) bgneal@45: return; bgneal@45: bgneal@45: // Font pt values and font size names bgneal@45: fz = [8, 10, 12, 14, 18, 24, 36]; bgneal@45: fzn = ['xx-small', 'x-small','small','medium','large','x-large', 'xx-large']; bgneal@45: bgneal@45: if (sl = s.font_size_style_values) bgneal@45: sl = explode(sl); bgneal@45: bgneal@45: if (cl = s.font_size_classes) bgneal@45: cl = explode(cl); bgneal@45: bgneal@45: function process(no) { bgneal@45: var n, sp, nl, x; bgneal@45: bgneal@45: // Keep unit tests happy bgneal@45: if (!s.inline_styles) bgneal@45: return; bgneal@45: bgneal@45: nl = t.dom.select('font', no); bgneal@45: for (x = nl.length - 1; x >= 0; x--) { bgneal@45: n = nl[x]; bgneal@45: bgneal@45: sp = dom.create('span', { bgneal@45: style : dom.getAttrib(n, 'style'), bgneal@45: 'class' : dom.getAttrib(n, 'class') bgneal@45: }); bgneal@45: bgneal@45: dom.setStyles(sp, { bgneal@45: fontFamily : dom.getAttrib(n, 'face'), bgneal@45: color : dom.getAttrib(n, 'color'), bgneal@45: backgroundColor : n.style.backgroundColor bgneal@45: }); bgneal@45: bgneal@45: if (n.size) { bgneal@45: if (sl) bgneal@45: dom.setStyle(sp, 'fontSize', sl[parseInt(n.size) - 1]); bgneal@45: else bgneal@45: dom.setAttrib(sp, 'class', cl[parseInt(n.size) - 1]); bgneal@45: } bgneal@45: bgneal@45: dom.setAttrib(sp, 'mce_style', ''); bgneal@45: dom.replace(sp, n, 1); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Run on cleanup bgneal@45: t.onPreProcess.add(function(ed, o) { bgneal@45: if (o.get) bgneal@45: process(o.node); bgneal@45: }); bgneal@45: bgneal@45: t.onSetContent.add(function(ed, o) { bgneal@45: if (o.initial) bgneal@45: process(o.node); 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: // Fix for bug #1867292 bgneal@45: _fixNesting : function(s) { bgneal@45: var d = [], i; bgneal@45: bgneal@45: s = s.replace(/<(\/)?([^\s>]+)[^>]*?>/g, function(a, b, c) { bgneal@45: var e; bgneal@45: bgneal@45: // Handle end element bgneal@45: if (b === '/') { bgneal@45: if (!d.length) bgneal@45: return ''; bgneal@45: bgneal@45: if (c !== d[d.length - 1].tag) { bgneal@45: for (i=d.length - 1; i>=0; i--) { bgneal@45: if (d[i].tag === c) { bgneal@45: d[i].close = 1; bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return ''; bgneal@45: } else { bgneal@45: d.pop(); bgneal@45: bgneal@45: if (d.length && d[d.length - 1].close) { bgneal@45: a = a + ''; bgneal@45: d.pop(); bgneal@45: } bgneal@45: } bgneal@45: } else { bgneal@45: // Ignore these bgneal@45: if (/^(br|hr|input|meta|img|link|param)$/i.test(c)) bgneal@45: return a; bgneal@45: bgneal@45: // Ignore closed ones bgneal@45: if (/\/>$/.test(a)) bgneal@45: return a; bgneal@45: bgneal@45: d.push({tag : c}); // Push start element bgneal@45: } bgneal@45: bgneal@45: return a; bgneal@45: }); bgneal@45: bgneal@45: // End all open tags bgneal@45: for (i=d.length - 1; i>=0; i--) bgneal@45: s += ''; bgneal@45: bgneal@45: return s; bgneal@45: } bgneal@45: bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: (function(tinymce) { bgneal@45: var each = tinymce.each, isIE = tinymce.isIE, isGecko = tinymce.isGecko, isOpera = tinymce.isOpera, isWebKit = tinymce.isWebKit; bgneal@45: bgneal@45: tinymce.create('tinymce.EditorCommands', { bgneal@45: EditorCommands : function(ed) { bgneal@45: this.editor = ed; bgneal@45: }, bgneal@45: bgneal@45: execCommand : function(cmd, ui, val) { bgneal@45: var t = this, ed = t.editor, f; bgneal@45: bgneal@45: switch (cmd) { bgneal@45: // Ignore these bgneal@45: case 'mceResetDesignMode': bgneal@45: case 'mceBeginUndoLevel': bgneal@45: return true; bgneal@45: bgneal@45: // Ignore these bgneal@45: case 'unlink': bgneal@45: t.UnLink(); bgneal@45: return true; bgneal@45: bgneal@45: // Bundle these together bgneal@45: case 'JustifyLeft': bgneal@45: case 'JustifyCenter': bgneal@45: case 'JustifyRight': bgneal@45: case 'JustifyFull': bgneal@45: t.mceJustify(cmd, cmd.substring(7).toLowerCase()); bgneal@45: return true; bgneal@45: bgneal@45: default: bgneal@45: f = this[cmd]; bgneal@45: bgneal@45: if (f) { bgneal@45: f.call(this, ui, val); bgneal@45: return true; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return false; bgneal@45: }, bgneal@45: bgneal@45: Indent : function() { bgneal@45: var ed = this.editor, d = ed.dom, s = ed.selection, e, iv, iu; bgneal@45: bgneal@45: // Setup indent level bgneal@45: iv = ed.settings.indentation; bgneal@45: iu = /[a-z%]+$/i.exec(iv); bgneal@45: iv = parseInt(iv); bgneal@45: bgneal@45: if (ed.settings.inline_styles && (!this.queryStateInsertUnorderedList() && !this.queryStateInsertOrderedList())) { bgneal@45: each(s.getSelectedBlocks(), function(e) { bgneal@45: d.setStyle(e, 'paddingLeft', (parseInt(e.style.paddingLeft || 0) + iv) + iu); bgneal@45: }); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: ed.getDoc().execCommand('Indent', false, null); bgneal@45: bgneal@45: if (isIE) { bgneal@45: d.getParent(s.getNode(), function(n) { bgneal@45: if (n.nodeName == 'BLOCKQUOTE') { bgneal@45: n.dir = n.style.cssText = ''; bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: Outdent : function() { bgneal@45: var ed = this.editor, d = ed.dom, s = ed.selection, e, v, iv, iu; bgneal@45: bgneal@45: // Setup indent level bgneal@45: iv = ed.settings.indentation; bgneal@45: iu = /[a-z%]+$/i.exec(iv); bgneal@45: iv = parseInt(iv); bgneal@45: bgneal@45: if (ed.settings.inline_styles && (!this.queryStateInsertUnorderedList() && !this.queryStateInsertOrderedList())) { bgneal@45: each(s.getSelectedBlocks(), function(e) { bgneal@45: v = Math.max(0, parseInt(e.style.paddingLeft || 0) - iv); bgneal@45: d.setStyle(e, 'paddingLeft', v ? v + iu : ''); bgneal@45: }); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: ed.getDoc().execCommand('Outdent', false, null); bgneal@45: }, bgneal@45: bgneal@45: /* bgneal@45: mceSetAttribute : function(u, v) { bgneal@45: var ed = this.editor, d = ed.dom, e; bgneal@45: bgneal@45: if (e = d.getParent(ed.selection.getNode(), d.isBlock)) bgneal@45: d.setAttrib(e, v.name, v.value); bgneal@45: }, bgneal@45: */ bgneal@45: mceSetContent : function(u, v) { bgneal@45: this.editor.setContent(v); bgneal@45: }, bgneal@45: bgneal@45: mceToggleVisualAid : function() { bgneal@45: var ed = this.editor; bgneal@45: bgneal@45: ed.hasVisual = !ed.hasVisual; bgneal@45: ed.addVisual(); bgneal@45: }, bgneal@45: bgneal@45: mceReplaceContent : function(u, v) { bgneal@45: var s = this.editor.selection; bgneal@45: bgneal@45: s.setContent(v.replace(/\{\$selection\}/g, s.getContent({format : 'text'}))); bgneal@45: }, bgneal@45: bgneal@45: mceInsertLink : function(u, v) { bgneal@45: var ed = this.editor, s = ed.selection, e = ed.dom.getParent(s.getNode(), 'A'); bgneal@45: bgneal@45: if (tinymce.is(v, 'string')) bgneal@45: v = {href : v}; bgneal@45: bgneal@45: function set(e) { bgneal@45: each(v, function(v, k) { bgneal@45: ed.dom.setAttrib(e, k, v); bgneal@45: }); bgneal@45: }; bgneal@45: bgneal@45: if (!e) { bgneal@45: ed.execCommand('CreateLink', false, 'javascript:mctmp(0);'); bgneal@45: each(ed.dom.select('a[href=javascript:mctmp(0);]'), function(e) { bgneal@45: set(e); bgneal@45: }); bgneal@45: } else { bgneal@45: if (v.href) bgneal@45: set(e); bgneal@45: else bgneal@45: ed.dom.remove(e, 1); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: UnLink : function() { bgneal@45: var ed = this.editor, s = ed.selection; bgneal@45: bgneal@45: if (s.isCollapsed()) bgneal@45: s.select(s.getNode()); bgneal@45: bgneal@45: ed.getDoc().execCommand('unlink', false, null); bgneal@45: s.collapse(0); bgneal@45: }, bgneal@45: bgneal@45: FontName : function(u, v) { bgneal@45: var t = this, ed = t.editor, s = ed.selection, e; bgneal@45: bgneal@45: if (!v) { bgneal@45: if (s.isCollapsed()) bgneal@45: s.select(s.getNode()); bgneal@45: } else { bgneal@45: if (ed.settings.convert_fonts_to_spans) bgneal@45: t._applyInlineStyle('span', {style : {fontFamily : v}}); bgneal@45: else bgneal@45: ed.getDoc().execCommand('FontName', false, v); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: FontSize : function(u, v) { bgneal@45: var ed = this.editor, s = ed.settings, fc, fs; bgneal@45: bgneal@45: // Use style options instead bgneal@45: if (s.convert_fonts_to_spans && v >= 1 && v <= 7) { bgneal@45: fs = tinymce.explode(s.font_size_style_values); bgneal@45: fc = tinymce.explode(s.font_size_classes); bgneal@45: bgneal@45: if (fc) bgneal@45: v = fc[v - 1] || v; bgneal@45: else bgneal@45: v = fs[v - 1] || v; bgneal@45: } bgneal@45: bgneal@45: if (v >= 1 && v <= 7) bgneal@45: ed.getDoc().execCommand('FontSize', false, v); bgneal@45: else bgneal@45: this._applyInlineStyle('span', {style : {fontSize : v}}); bgneal@45: }, bgneal@45: bgneal@45: queryCommandValue : function(c) { bgneal@45: var f = this['queryValue' + c]; bgneal@45: bgneal@45: if (f) bgneal@45: return f.call(this, c); bgneal@45: bgneal@45: return false; bgneal@45: }, bgneal@45: bgneal@45: queryCommandState : function(cmd) { bgneal@45: var f; bgneal@45: bgneal@45: switch (cmd) { bgneal@45: // Bundle these together bgneal@45: case 'JustifyLeft': bgneal@45: case 'JustifyCenter': bgneal@45: case 'JustifyRight': bgneal@45: case 'JustifyFull': bgneal@45: return this.queryStateJustify(cmd, cmd.substring(7).toLowerCase()); bgneal@45: bgneal@45: default: bgneal@45: if (f = this['queryState' + cmd]) bgneal@45: return f.call(this, cmd); bgneal@45: } bgneal@45: bgneal@45: return -1; bgneal@45: }, bgneal@45: bgneal@45: _queryState : function(c) { bgneal@45: try { bgneal@45: return this.editor.getDoc().queryCommandState(c); bgneal@45: } catch (ex) { bgneal@45: // Ignore exception bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: _queryVal : function(c) { bgneal@45: try { bgneal@45: return this.editor.getDoc().queryCommandValue(c); bgneal@45: } catch (ex) { bgneal@45: // Ignore exception bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: queryValueFontSize : function() { bgneal@45: var ed = this.editor, v = 0, p; bgneal@45: bgneal@45: if (p = ed.dom.getParent(ed.selection.getNode(), 'SPAN')) bgneal@45: v = p.style.fontSize; bgneal@45: bgneal@45: if (!v && (isOpera || isWebKit)) { bgneal@45: if (p = ed.dom.getParent(ed.selection.getNode(), 'FONT')) bgneal@45: v = p.size; bgneal@45: bgneal@45: return v; bgneal@45: } bgneal@45: bgneal@45: return v || this._queryVal('FontSize'); bgneal@45: }, bgneal@45: bgneal@45: queryValueFontName : function() { bgneal@45: var ed = this.editor, v = 0, p; bgneal@45: bgneal@45: if (p = ed.dom.getParent(ed.selection.getNode(), 'FONT')) bgneal@45: v = p.face; bgneal@45: bgneal@45: if (p = ed.dom.getParent(ed.selection.getNode(), 'SPAN')) bgneal@45: v = p.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase(); bgneal@45: bgneal@45: if (!v) bgneal@45: v = this._queryVal('FontName'); bgneal@45: bgneal@45: return v; bgneal@45: }, bgneal@45: bgneal@45: mceJustify : function(c, v) { bgneal@45: var ed = this.editor, se = ed.selection, n = se.getNode(), nn = n.nodeName, bl, nb, dom = ed.dom, rm; bgneal@45: bgneal@45: if (ed.settings.inline_styles && this.queryStateJustify(c, v)) bgneal@45: rm = 1; bgneal@45: bgneal@45: bl = dom.getParent(n, ed.dom.isBlock); bgneal@45: bgneal@45: if (nn == 'IMG') { bgneal@45: if (v == 'full') bgneal@45: return; bgneal@45: bgneal@45: if (rm) { bgneal@45: if (v == 'center') bgneal@45: dom.setStyle(bl || n.parentNode, 'textAlign', ''); bgneal@45: bgneal@45: dom.setStyle(n, 'float', ''); bgneal@45: this.mceRepaint(); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: if (v == 'center') { bgneal@45: // Do not change table elements bgneal@45: if (bl && /^(TD|TH)$/.test(bl.nodeName)) bgneal@45: bl = 0; bgneal@45: bgneal@45: if (!bl || bl.childNodes.length > 1) { bgneal@45: nb = dom.create('p'); bgneal@45: nb.appendChild(n.cloneNode(false)); bgneal@45: bgneal@45: if (bl) bgneal@45: dom.insertAfter(nb, bl); bgneal@45: else bgneal@45: dom.insertAfter(nb, n); bgneal@45: bgneal@45: dom.remove(n); bgneal@45: n = nb.firstChild; bgneal@45: bl = nb; bgneal@45: } bgneal@45: bgneal@45: dom.setStyle(bl, 'textAlign', v); bgneal@45: dom.setStyle(n, 'float', ''); bgneal@45: } else { bgneal@45: dom.setStyle(n, 'float', v); bgneal@45: dom.setStyle(bl || n.parentNode, 'textAlign', ''); bgneal@45: } bgneal@45: bgneal@45: this.mceRepaint(); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Handle the alignment outselfs, less quirks in all browsers bgneal@45: if (ed.settings.inline_styles && ed.settings.forced_root_block) { bgneal@45: if (rm) bgneal@45: v = ''; bgneal@45: bgneal@45: each(se.getSelectedBlocks(dom.getParent(se.getStart(), dom.isBlock), dom.getParent(se.getEnd(), dom.isBlock)), function(e) { bgneal@45: dom.setAttrib(e, 'align', ''); bgneal@45: dom.setStyle(e, 'textAlign', v == 'full' ? 'justify' : v); bgneal@45: }); bgneal@45: bgneal@45: return; bgneal@45: } else if (!rm) bgneal@45: ed.getDoc().execCommand(c, false, null); bgneal@45: bgneal@45: if (ed.settings.inline_styles) { bgneal@45: if (rm) { bgneal@45: dom.getParent(ed.selection.getNode(), function(n) { bgneal@45: if (n.style && n.style.textAlign) bgneal@45: dom.setStyle(n, 'textAlign', ''); bgneal@45: }); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: each(dom.select('*'), function(n) { bgneal@45: var v = n.align; bgneal@45: bgneal@45: if (v) { bgneal@45: if (v == 'full') bgneal@45: v = 'justify'; bgneal@45: bgneal@45: dom.setStyle(n, 'textAlign', v); bgneal@45: dom.setAttrib(n, 'align', ''); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: mceSetCSSClass : function(u, v) { bgneal@45: this.mceSetStyleInfo(0, {command : 'setattrib', name : 'class', value : v}); bgneal@45: }, bgneal@45: bgneal@45: getSelectedElement : function() { bgneal@45: var t = this, ed = t.editor, dom = ed.dom, se = ed.selection, r = se.getRng(), r1, r2, sc, ec, so, eo, e, sp, ep, re; bgneal@45: bgneal@45: if (se.isCollapsed() || r.item) bgneal@45: return se.getNode(); bgneal@45: bgneal@45: // Setup regexp bgneal@45: re = ed.settings.merge_styles_invalid_parents; bgneal@45: if (tinymce.is(re, 'string')) bgneal@45: re = new RegExp(re, 'i'); bgneal@45: bgneal@45: if (isIE) { bgneal@45: r1 = r.duplicate(); bgneal@45: r1.collapse(true); bgneal@45: sc = r1.parentElement(); bgneal@45: bgneal@45: r2 = r.duplicate(); bgneal@45: r2.collapse(false); bgneal@45: ec = r2.parentElement(); bgneal@45: bgneal@45: if (sc != ec) { bgneal@45: r1.move('character', 1); bgneal@45: sc = r1.parentElement(); bgneal@45: } bgneal@45: bgneal@45: if (sc == ec) { bgneal@45: r1 = r.duplicate(); bgneal@45: r1.moveToElementText(sc); bgneal@45: bgneal@45: if (r1.compareEndPoints('StartToStart', r) == 0 && r1.compareEndPoints('EndToEnd', r) == 0) bgneal@45: return re && re.test(sc.nodeName) ? null : sc; bgneal@45: } bgneal@45: } else { bgneal@45: function getParent(n) { bgneal@45: return dom.getParent(n, '*'); bgneal@45: }; bgneal@45: bgneal@45: sc = r.startContainer; bgneal@45: ec = r.endContainer; bgneal@45: so = r.startOffset; bgneal@45: eo = r.endOffset; bgneal@45: bgneal@45: if (!r.collapsed) { bgneal@45: if (sc == ec) { bgneal@45: if (so - eo < 2) { bgneal@45: if (sc.hasChildNodes()) { bgneal@45: sp = sc.childNodes[so]; bgneal@45: return re && re.test(sp.nodeName) ? null : sp; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if (sc.nodeType != 3 || ec.nodeType != 3) bgneal@45: return null; bgneal@45: bgneal@45: if (so == 0) { bgneal@45: sp = getParent(sc); bgneal@45: bgneal@45: if (sp && sp.firstChild != sc) bgneal@45: sp = null; bgneal@45: } bgneal@45: bgneal@45: if (so == sc.nodeValue.length) { bgneal@45: e = sc.nextSibling; bgneal@45: bgneal@45: if (e && e.nodeType == 1) bgneal@45: sp = sc.nextSibling; bgneal@45: } bgneal@45: bgneal@45: if (eo == 0) { bgneal@45: e = ec.previousSibling; bgneal@45: bgneal@45: if (e && e.nodeType == 1) bgneal@45: ep = e; bgneal@45: } bgneal@45: bgneal@45: if (eo == ec.nodeValue.length) { bgneal@45: ep = getParent(ec); bgneal@45: bgneal@45: if (ep && ep.lastChild != ec) bgneal@45: ep = null; bgneal@45: } bgneal@45: bgneal@45: // Same element bgneal@45: if (sp == ep) bgneal@45: return re && sp && re.test(sp.nodeName) ? null : sp; bgneal@45: } bgneal@45: bgneal@45: return null; bgneal@45: }, bgneal@45: bgneal@45: mceSetStyleInfo : function(u, v) { bgneal@45: var t = this, ed = t.editor, d = ed.getDoc(), dom = ed.dom, e, b, s = ed.selection, nn = v.wrapper || 'span', b = s.getBookmark(), re; bgneal@45: bgneal@45: function set(n, e) { bgneal@45: if (n.nodeType == 1) { bgneal@45: switch (v.command) { bgneal@45: case 'setattrib': bgneal@45: return dom.setAttrib(n, v.name, v.value); bgneal@45: bgneal@45: case 'setstyle': bgneal@45: return dom.setStyle(n, v.name, v.value); bgneal@45: bgneal@45: case 'removeformat': bgneal@45: return dom.setAttrib(n, 'class', ''); bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Setup regexp bgneal@45: re = ed.settings.merge_styles_invalid_parents; bgneal@45: if (tinymce.is(re, 'string')) bgneal@45: re = new RegExp(re, 'i'); bgneal@45: bgneal@45: // Set style info on selected element bgneal@45: if ((e = t.getSelectedElement()) && !ed.settings.force_span_wrappers) bgneal@45: set(e, 1); bgneal@45: else { bgneal@45: // Generate wrappers and set styles on them bgneal@45: d.execCommand('FontName', false, '__'); bgneal@45: each(dom.select('span,font'), function(n) { bgneal@45: var sp, e; bgneal@45: bgneal@45: if (dom.getAttrib(n, 'face') == '__' || n.style.fontFamily === '__') { bgneal@45: sp = dom.create(nn, {mce_new : '1'}); bgneal@45: bgneal@45: set(sp); bgneal@45: bgneal@45: each (n.childNodes, function(n) { bgneal@45: sp.appendChild(n.cloneNode(true)); bgneal@45: }); bgneal@45: bgneal@45: dom.replace(sp, n); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // Remove wrappers inside new ones bgneal@45: each(dom.select(nn).reverse(), function(n) { bgneal@45: var p = n.parentNode; bgneal@45: bgneal@45: // Check if it's an old span in a new wrapper bgneal@45: if (!dom.getAttrib(n, 'mce_new')) { bgneal@45: // Find new wrapper bgneal@45: p = dom.getParent(n, '*[mce_new]'); bgneal@45: bgneal@45: if (p) bgneal@45: dom.remove(n, 1); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Merge wrappers with parent wrappers bgneal@45: each(dom.select(nn).reverse(), function(n) { bgneal@45: var p = n.parentNode; bgneal@45: bgneal@45: if (!p || !dom.getAttrib(n, 'mce_new')) bgneal@45: return; bgneal@45: bgneal@45: if (ed.settings.force_span_wrappers && p.nodeName != 'SPAN') bgneal@45: return; bgneal@45: bgneal@45: // Has parent of the same type and only child bgneal@45: if (p.nodeName == nn.toUpperCase() && p.childNodes.length == 1) bgneal@45: return dom.remove(p, 1); bgneal@45: bgneal@45: // Has parent that is more suitable to have the class and only child bgneal@45: if (n.nodeType == 1 && (!re || !re.test(p.nodeName)) && p.childNodes.length == 1) { bgneal@45: set(p); // Set style info on parent instead bgneal@45: dom.setAttrib(n, 'class', ''); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Remove empty wrappers bgneal@45: each(dom.select(nn).reverse(), function(n) { bgneal@45: if (dom.getAttrib(n, 'mce_new') || (dom.getAttribs(n).length <= 1 && n.className === '')) { bgneal@45: if (!dom.getAttrib(n, 'class') && !dom.getAttrib(n, 'style')) bgneal@45: return dom.remove(n, 1); bgneal@45: bgneal@45: dom.setAttrib(n, 'mce_new', ''); // Remove mce_new marker bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: s.moveToBookmark(b); bgneal@45: }, bgneal@45: bgneal@45: queryStateJustify : function(c, v) { bgneal@45: var ed = this.editor, n = ed.selection.getNode(), dom = ed.dom; bgneal@45: bgneal@45: if (n && n.nodeName == 'IMG') { bgneal@45: if (dom.getStyle(n, 'float') == v) bgneal@45: return 1; bgneal@45: bgneal@45: return n.parentNode.style.textAlign == v; bgneal@45: } bgneal@45: bgneal@45: n = dom.getParent(ed.selection.getStart(), function(n) { bgneal@45: return n.nodeType == 1 && n.style.textAlign; bgneal@45: }); bgneal@45: bgneal@45: if (v == 'full') bgneal@45: v = 'justify'; bgneal@45: bgneal@45: if (ed.settings.inline_styles) bgneal@45: return (n && n.style.textAlign == v); bgneal@45: bgneal@45: return this._queryState(c); bgneal@45: }, bgneal@45: bgneal@45: ForeColor : function(ui, v) { bgneal@45: var ed = this.editor; bgneal@45: bgneal@45: if (ed.settings.convert_fonts_to_spans) { bgneal@45: this._applyInlineStyle('span', {style : {color : v}}); bgneal@45: return; bgneal@45: } else bgneal@45: ed.getDoc().execCommand('ForeColor', false, v); bgneal@45: }, bgneal@45: bgneal@45: HiliteColor : function(ui, val) { bgneal@45: var t = this, ed = t.editor, d = ed.getDoc(); bgneal@45: bgneal@45: if (ed.settings.convert_fonts_to_spans) { bgneal@45: this._applyInlineStyle('span', {style : {backgroundColor : val}}); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: function set(s) { bgneal@45: if (!isGecko) bgneal@45: return; bgneal@45: bgneal@45: try { bgneal@45: // Try new Gecko method bgneal@45: d.execCommand("styleWithCSS", 0, s); bgneal@45: } catch (ex) { bgneal@45: // Use old bgneal@45: d.execCommand("useCSS", 0, !s); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: if (isGecko || isOpera) { bgneal@45: set(true); bgneal@45: d.execCommand('hilitecolor', false, val); bgneal@45: set(false); bgneal@45: } else bgneal@45: d.execCommand('BackColor', false, val); bgneal@45: }, bgneal@45: bgneal@45: FormatBlock : function(ui, val) { bgneal@45: var t = this, ed = t.editor, s = ed.selection, dom = ed.dom, bl, nb, b; bgneal@45: bgneal@45: function isBlock(n) { bgneal@45: return /^(P|DIV|H[1-6]|ADDRESS|BLOCKQUOTE|PRE)$/.test(n.nodeName); bgneal@45: }; bgneal@45: bgneal@45: bl = dom.getParent(s.getNode(), function(n) { bgneal@45: return isBlock(n); bgneal@45: }); bgneal@45: bgneal@45: // IE has an issue where it removes the parent div if you change format on the paragrah in

Content

bgneal@45: // FF and Opera doesn't change parent DIV elements if you switch format bgneal@45: if (bl) { bgneal@45: if ((isIE && isBlock(bl.parentNode)) || bl.nodeName == 'DIV') { bgneal@45: // Rename block element bgneal@45: nb = ed.dom.create(val); bgneal@45: bgneal@45: each(dom.getAttribs(bl), function(v) { bgneal@45: dom.setAttrib(nb, v.nodeName, dom.getAttrib(bl, v.nodeName)); bgneal@45: }); bgneal@45: bgneal@45: b = s.getBookmark(); bgneal@45: dom.replace(nb, bl, 1); bgneal@45: s.moveToBookmark(b); bgneal@45: ed.nodeChanged(); bgneal@45: return; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: val = ed.settings.forced_root_block ? (val || '

') : val; bgneal@45: bgneal@45: if (val.indexOf('<') == -1) bgneal@45: val = '<' + val + '>'; bgneal@45: bgneal@45: if (tinymce.isGecko) bgneal@45: val = val.replace(/<(div|blockquote|code|dt|dd|dl|samp)>/gi, '$1'); bgneal@45: bgneal@45: ed.getDoc().execCommand('FormatBlock', false, val); bgneal@45: }, bgneal@45: bgneal@45: mceCleanup : function() { bgneal@45: var ed = this.editor, s = ed.selection, b = s.getBookmark(); bgneal@45: ed.setContent(ed.getContent()); bgneal@45: s.moveToBookmark(b); bgneal@45: }, bgneal@45: bgneal@45: mceRemoveNode : function(ui, val) { bgneal@45: var ed = this.editor, s = ed.selection, b, n = val || s.getNode(); bgneal@45: bgneal@45: // Make sure that the body node isn't removed bgneal@45: if (n == ed.getBody()) bgneal@45: return; bgneal@45: bgneal@45: b = s.getBookmark(); bgneal@45: ed.dom.remove(n, 1); bgneal@45: s.moveToBookmark(b); bgneal@45: ed.nodeChanged(); bgneal@45: }, bgneal@45: bgneal@45: mceSelectNodeDepth : function(ui, val) { bgneal@45: var ed = this.editor, s = ed.selection, c = 0; bgneal@45: bgneal@45: ed.dom.getParent(s.getNode(), function(n) { bgneal@45: if (n.nodeType == 1 && c++ == val) { bgneal@45: s.select(n); bgneal@45: ed.nodeChanged(); bgneal@45: return false; bgneal@45: } bgneal@45: }, ed.getBody()); bgneal@45: }, bgneal@45: bgneal@45: mceSelectNode : function(u, v) { bgneal@45: this.editor.selection.select(v); bgneal@45: }, bgneal@45: bgneal@45: mceInsertContent : function(ui, val) { bgneal@45: this.editor.selection.setContent(val); bgneal@45: }, bgneal@45: bgneal@45: mceInsertRawHTML : function(ui, val) { bgneal@45: var ed = this.editor; bgneal@45: bgneal@45: ed.selection.setContent('tiny_mce_marker'); bgneal@45: ed.setContent(ed.getContent().replace(/tiny_mce_marker/g, val)); bgneal@45: }, bgneal@45: bgneal@45: mceRepaint : function() { bgneal@45: var s, b, e = this.editor; bgneal@45: bgneal@45: if (tinymce.isGecko) { bgneal@45: try { bgneal@45: s = e.selection; bgneal@45: b = s.getBookmark(true); bgneal@45: bgneal@45: if (s.getSel()) bgneal@45: s.getSel().selectAllChildren(e.getBody()); bgneal@45: bgneal@45: s.collapse(true); bgneal@45: s.moveToBookmark(b); bgneal@45: } catch (ex) { bgneal@45: // Ignore bgneal@45: } bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: queryStateUnderline : function() { bgneal@45: var ed = this.editor, n = ed.selection.getNode(); bgneal@45: bgneal@45: if (n && n.nodeName == 'A') bgneal@45: return false; bgneal@45: bgneal@45: return this._queryState('Underline'); bgneal@45: }, bgneal@45: bgneal@45: queryStateOutdent : function() { bgneal@45: var ed = this.editor, n; bgneal@45: bgneal@45: if (ed.settings.inline_styles) { bgneal@45: if ((n = ed.dom.getParent(ed.selection.getStart(), ed.dom.isBlock)) && parseInt(n.style.paddingLeft) > 0) bgneal@45: return true; bgneal@45: bgneal@45: if ((n = ed.dom.getParent(ed.selection.getEnd(), ed.dom.isBlock)) && parseInt(n.style.paddingLeft) > 0) bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: return this.queryStateInsertUnorderedList() || this.queryStateInsertOrderedList() || (!ed.settings.inline_styles && !!ed.dom.getParent(ed.selection.getNode(), 'BLOCKQUOTE')); bgneal@45: }, bgneal@45: bgneal@45: queryStateInsertUnorderedList : function() { bgneal@45: return this.editor.dom.getParent(this.editor.selection.getNode(), 'UL'); bgneal@45: }, bgneal@45: bgneal@45: queryStateInsertOrderedList : function() { bgneal@45: return this.editor.dom.getParent(this.editor.selection.getNode(), 'OL'); bgneal@45: }, bgneal@45: bgneal@45: queryStatemceBlockQuote : function() { bgneal@45: return !!this.editor.dom.getParent(this.editor.selection.getStart(), function(n) {return n.nodeName === 'BLOCKQUOTE';}); bgneal@45: }, bgneal@45: bgneal@45: _applyInlineStyle : function(na, at, op) { bgneal@45: var t = this, ed = t.editor, dom = ed.dom, bm, lo = {}, kh, found; bgneal@45: bgneal@45: na = na.toUpperCase(); bgneal@45: bgneal@45: if (op && op.check_classes && at['class']) bgneal@45: op.check_classes.push(at['class']); bgneal@45: bgneal@45: function removeEmpty() { bgneal@45: each(dom.select(na).reverse(), function(n) { bgneal@45: var c = 0; bgneal@45: bgneal@45: // Check if there is any attributes bgneal@45: each(dom.getAttribs(n), function(an) { bgneal@45: if (an.nodeName.substring(0, 1) != '_' && dom.getAttrib(n, an.nodeName) != '') { bgneal@45: //console.log(dom.getOuterHTML(n), dom.getAttrib(n, an.nodeName)); bgneal@45: c++; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // No attributes then remove the element and keep the children bgneal@45: if (c == 0) bgneal@45: dom.remove(n, 1); bgneal@45: }); bgneal@45: }; bgneal@45: bgneal@45: function replaceFonts() { bgneal@45: var bm; bgneal@45: bgneal@45: each(dom.select('span,font'), function(n) { bgneal@45: if (n.style.fontFamily == 'mceinline' || n.face == 'mceinline') { bgneal@45: if (!bm) bgneal@45: bm = ed.selection.getBookmark(); bgneal@45: bgneal@45: at._mce_new = '1'; bgneal@45: dom.replace(dom.create(na, at), n, 1); bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: // Remove redundant elements bgneal@45: each(dom.select(na + '[_mce_new]'), function(n) { bgneal@45: function removeStyle(n) { bgneal@45: if (n.nodeType == 1) { bgneal@45: each(at.style, function(v, k) { bgneal@45: dom.setStyle(n, k, ''); bgneal@45: }); bgneal@45: bgneal@45: // Remove spans with the same class or marked classes bgneal@45: if (at['class'] && n.className && op) { bgneal@45: each(op.check_classes, function(c) { bgneal@45: if (dom.hasClass(n, c)) bgneal@45: dom.removeClass(n, c); bgneal@45: }); bgneal@45: } bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Remove specified style information from child elements bgneal@45: each(dom.select(na, n), removeStyle); bgneal@45: bgneal@45: // Remove the specified style information on parent if current node is only child (IE) bgneal@45: if (n.parentNode && n.parentNode.nodeType == 1 && n.parentNode.childNodes.length == 1) bgneal@45: removeStyle(n.parentNode); bgneal@45: bgneal@45: // Remove the child elements style info if a parent already has it bgneal@45: dom.getParent(n.parentNode, function(pn) { bgneal@45: if (pn.nodeType == 1) { bgneal@45: if (at.style) { bgneal@45: each(at.style, function(v, k) { bgneal@45: var sv; bgneal@45: bgneal@45: if (!lo[k] && (sv = dom.getStyle(pn, k))) { bgneal@45: if (sv === v) bgneal@45: dom.setStyle(n, k, ''); bgneal@45: bgneal@45: lo[k] = 1; bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // Remove spans with the same class or marked classes bgneal@45: if (at['class'] && pn.className && op) { bgneal@45: each(op.check_classes, function(c) { bgneal@45: if (dom.hasClass(pn, c)) bgneal@45: dom.removeClass(n, c); bgneal@45: }); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: return false; bgneal@45: }); bgneal@45: bgneal@45: n.removeAttribute('_mce_new'); bgneal@45: }); bgneal@45: bgneal@45: removeEmpty(); bgneal@45: ed.selection.moveToBookmark(bm); bgneal@45: bgneal@45: return !!bm; bgneal@45: }; bgneal@45: bgneal@45: // Create inline elements bgneal@45: ed.focus(); bgneal@45: ed.getDoc().execCommand('FontName', false, 'mceinline'); bgneal@45: replaceFonts(); bgneal@45: bgneal@45: if (kh = t._applyInlineStyle.keyhandler) { bgneal@45: ed.onKeyUp.remove(kh); bgneal@45: ed.onKeyPress.remove(kh); bgneal@45: ed.onKeyDown.remove(kh); bgneal@45: ed.onSetContent.remove(t._applyInlineStyle.chandler); bgneal@45: } bgneal@45: bgneal@45: if (ed.selection.isCollapsed()) { bgneal@45: // IE will format the current word so this code can't be executed on that browser bgneal@45: if (!isIE) { bgneal@45: each(dom.getParents(ed.selection.getNode(), 'span'), function(n) { bgneal@45: each(at.style, function(v, k) { bgneal@45: var kv; bgneal@45: bgneal@45: if (kv = dom.getStyle(n, k)) { bgneal@45: if (kv == v) { bgneal@45: dom.setStyle(n, k, ''); bgneal@45: found = 2; bgneal@45: return false; bgneal@45: } bgneal@45: bgneal@45: found = 1; bgneal@45: return false; bgneal@45: } bgneal@45: }); bgneal@45: bgneal@45: if (found) bgneal@45: return false; bgneal@45: }); bgneal@45: bgneal@45: if (found == 2) { bgneal@45: bm = ed.selection.getBookmark(); bgneal@45: bgneal@45: removeEmpty(); bgneal@45: bgneal@45: ed.selection.moveToBookmark(bm); bgneal@45: bgneal@45: // Node change needs to be detached since the onselect event bgneal@45: // for the select box will run the onclick handler after onselect call. Todo: Add a nicer fix! bgneal@45: window.setTimeout(function() { bgneal@45: ed.nodeChanged(); bgneal@45: }, 1); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Start collecting styles bgneal@45: t._pendingStyles = tinymce.extend(t._pendingStyles || {}, at.style); bgneal@45: bgneal@45: t._applyInlineStyle.chandler = ed.onSetContent.add(function() { bgneal@45: delete t._pendingStyles; bgneal@45: }); bgneal@45: bgneal@45: t._applyInlineStyle.keyhandler = kh = function(e) { bgneal@45: // Use pending styles bgneal@45: if (t._pendingStyles) { bgneal@45: at.style = t._pendingStyles; bgneal@45: delete t._pendingStyles; bgneal@45: } bgneal@45: bgneal@45: if (replaceFonts()) { bgneal@45: ed.onKeyDown.remove(t._applyInlineStyle.keyhandler); bgneal@45: ed.onKeyPress.remove(t._applyInlineStyle.keyhandler); bgneal@45: } bgneal@45: bgneal@45: if (e.type == 'keyup') bgneal@45: ed.onKeyUp.remove(t._applyInlineStyle.keyhandler); bgneal@45: }; bgneal@45: bgneal@45: ed.onKeyDown.add(kh); bgneal@45: ed.onKeyPress.add(kh); bgneal@45: ed.onKeyUp.add(kh); bgneal@45: } else bgneal@45: t._pendingStyles = 0; bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce);(function(tinymce) { bgneal@45: tinymce.create('tinymce.UndoManager', { bgneal@45: index : 0, bgneal@45: data : null, bgneal@45: typing : 0, bgneal@45: bgneal@45: UndoManager : function(ed) { bgneal@45: var t = this, Dispatcher = tinymce.util.Dispatcher; bgneal@45: bgneal@45: t.editor = ed; bgneal@45: t.data = []; bgneal@45: t.onAdd = new Dispatcher(this); bgneal@45: t.onUndo = new Dispatcher(this); bgneal@45: t.onRedo = new Dispatcher(this); bgneal@45: }, bgneal@45: bgneal@45: add : function(l) { bgneal@45: var t = this, i, ed = t.editor, b, s = ed.settings, la; bgneal@45: bgneal@45: l = l || {}; bgneal@45: l.content = l.content || ed.getContent({format : 'raw', no_events : 1}); bgneal@45: bgneal@45: // Add undo level if needed bgneal@45: l.content = l.content.replace(/^\s*|\s*$/g, ''); bgneal@45: la = t.data[t.index > 0 && (t.index == 0 || t.index == t.data.length) ? t.index - 1 : t.index]; bgneal@45: if (!l.initial && la && l.content == la.content) bgneal@45: return null; bgneal@45: bgneal@45: // Time to compress bgneal@45: if (s.custom_undo_redo_levels) { bgneal@45: if (t.data.length > s.custom_undo_redo_levels) { bgneal@45: for (i = 0; i < t.data.length - 1; i++) bgneal@45: t.data[i] = t.data[i + 1]; bgneal@45: bgneal@45: t.data.length--; bgneal@45: t.index = t.data.length; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if (s.custom_undo_redo_restore_selection && !l.initial) bgneal@45: l.bookmark = b = l.bookmark || ed.selection.getBookmark(); bgneal@45: bgneal@45: if (t.index < t.data.length) bgneal@45: t.index++; bgneal@45: bgneal@45: // Only initial marked undo levels should be allowed as first item bgneal@45: // This to workaround a bug with Firefox and the blur event bgneal@45: if (t.data.length === 0 && !l.initial) bgneal@45: return null; bgneal@45: bgneal@45: // Add level bgneal@45: t.data.length = t.index + 1; bgneal@45: t.data[t.index++] = l; bgneal@45: bgneal@45: if (l.initial) bgneal@45: t.index = 0; bgneal@45: bgneal@45: // Set initial bookmark use first real undo level bgneal@45: if (t.data.length == 2 && t.data[0].initial) bgneal@45: t.data[0].bookmark = b; bgneal@45: bgneal@45: t.onAdd.dispatch(t, l); bgneal@45: ed.isNotDirty = 0; bgneal@45: bgneal@45: //console.dir(t.data); bgneal@45: bgneal@45: return l; bgneal@45: }, bgneal@45: bgneal@45: undo : function() { bgneal@45: var t = this, ed = t.editor, l = l, i; bgneal@45: bgneal@45: if (t.typing) { bgneal@45: t.add(); bgneal@45: t.typing = 0; bgneal@45: } bgneal@45: bgneal@45: if (t.index > 0) { bgneal@45: // If undo on last index then take snapshot bgneal@45: if (t.index == t.data.length && t.index > 1) { bgneal@45: i = t.index; bgneal@45: t.typing = 0; bgneal@45: bgneal@45: if (!t.add()) bgneal@45: t.index = i; bgneal@45: bgneal@45: --t.index; bgneal@45: } bgneal@45: bgneal@45: l = t.data[--t.index]; bgneal@45: ed.setContent(l.content, {format : 'raw'}); bgneal@45: ed.selection.moveToBookmark(l.bookmark); bgneal@45: bgneal@45: t.onUndo.dispatch(t, l); bgneal@45: } bgneal@45: bgneal@45: return l; bgneal@45: }, bgneal@45: bgneal@45: redo : function() { bgneal@45: var t = this, ed = t.editor, l = null; bgneal@45: bgneal@45: if (t.index < t.data.length - 1) { bgneal@45: l = t.data[++t.index]; bgneal@45: ed.setContent(l.content, {format : 'raw'}); bgneal@45: ed.selection.moveToBookmark(l.bookmark); bgneal@45: bgneal@45: t.onRedo.dispatch(t, l); bgneal@45: } bgneal@45: bgneal@45: return l; bgneal@45: }, bgneal@45: bgneal@45: clear : function() { bgneal@45: var t = this; bgneal@45: bgneal@45: t.data = []; bgneal@45: t.index = 0; bgneal@45: t.typing = 0; bgneal@45: t.add({initial : true}); bgneal@45: }, bgneal@45: bgneal@45: hasUndo : function() { bgneal@45: return this.index != 0 || this.typing; bgneal@45: }, bgneal@45: bgneal@45: hasRedo : function() { bgneal@45: return this.index < this.data.length - 1; bgneal@45: } bgneal@45: bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: (function(tinymce) { bgneal@45: // Shorten names bgneal@45: var Event, isIE, isGecko, isOpera, each, extend; bgneal@45: bgneal@45: 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: 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: t.reOpera = new RegExp('(\\u00a0| | )<\/' + elm + '>', 'gi'); bgneal@45: t.rePadd = new RegExp(']+)><\\\/p>|]+)\\\/>|]+)>\\s+<\\\/p>|

<\\\/p>||

\\s+<\\\/p>'.replace(/p/g, elm), 'gi'); bgneal@45: t.reNbsp2BR1 = new RegExp(']+)>[\\s\\u00a0]+<\\\/p>|

[\\s\\u00a0]+<\\\/p>'.replace(/p/g, elm), 'gi'); bgneal@45: t.reNbsp2BR2 = new RegExp('<%p()([^>]+)>( | )<\\\/%p>|<%p>( | )<\\\/%p>'.replace(/%p/g, elm), 'gi'); bgneal@45: t.reBR2Nbsp = new RegExp(']+)>\\s*
\\s*<\\\/p>|

\\s*
\\s*<\\\/p>'.replace(/p/g, elm), 'gi'); bgneal@45: t.reTrailBr = new RegExp('\\s*
\\s*<\\\/p>'.replace(/p/g, elm), 'gi'); bgneal@45: bgneal@45: function padd(ed, o) { bgneal@45: if (isOpera) bgneal@45: o.content = o.content.replace(t.reOpera, ''); bgneal@45: bgneal@45: o.content = o.content.replace(t.rePadd, '<' + elm + '$1$2$3$4$5$6>\u00a0'); bgneal@45: bgneal@45: if (!isIE && !isOpera && o.set) { bgneal@45: // Use   instead of BR in padded paragraphs bgneal@45: o.content = o.content.replace(t.reNbsp2BR1, '<' + elm + '$1$2>
'); bgneal@45: o.content = o.content.replace(t.reNbsp2BR2, '<' + elm + '$1$2>
'); bgneal@45: } else { bgneal@45: o.content = o.content.replace(t.reBR2Nbsp, '<' + elm + '$1$2>\u00a0'); bgneal@45: o.content = o.content.replace(t.reTrailBr, ''); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: ed.onBeforeSetContent.add(padd); bgneal@45: ed.onPostProcess.add(padd); bgneal@45: bgneal@45: if (s.forced_root_block) { bgneal@45: ed.onInit.add(t.forceRoots, t); bgneal@45: ed.onSetContent.add(t.forceRoots, t); bgneal@45: ed.onBeforeGetContent.add(t.forceRoots, t); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: setup : function() { bgneal@45: var t = this, ed = t.editor, s = ed.settings; bgneal@45: bgneal@45: // Force root blocks when typing and when getting output bgneal@45: if (s.forced_root_block) { bgneal@45: ed.onKeyUp.add(t.forceRoots, t); bgneal@45: ed.onPreProcess.add(t.forceRoots, t); 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, s = ed.selection; bgneal@45: bgneal@45: if (e.keyCode == 13 && s.getNode().nodeName != 'LI') { bgneal@45: s.setContent('
', {format : 'raw'}); bgneal@45: n = ed.dom.get('__'); bgneal@45: n.removeAttribute('id'); bgneal@45: s.select(n); bgneal@45: s.collapse(); bgneal@45: return Event.cancel(e); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: if (!isIE && s.force_p_newlines) { bgneal@45: /* ed.onPreProcess.add(function(ed, o) { bgneal@45: each(ed.dom.select('br', o.node), function(n) { bgneal@45: var p = n.parentNode; bgneal@45: bgneal@45: // Replace


with

 

bgneal@45: if (p && p.nodeName == 'p' && (p.childNodes.length == 1 || p.lastChild == n)) { bgneal@45: p.replaceChild(ed.getDoc().createTextNode('\u00a0'), n); bgneal@45: } bgneal@45: }); bgneal@45: });*/ bgneal@45: bgneal@45: ed.onKeyPress.add(function(ed, e) { bgneal@45: if (e.keyCode == 13 && !e.shiftKey) { bgneal@45: if (!t.insertPara(e)) bgneal@45: Event.cancel(e); bgneal@45: } 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: function ren(rn, na) { bgneal@45: var ne = ed.dom.create(na); bgneal@45: bgneal@45: each(rn.attributes, function(a) { bgneal@45: if (a.specified && a.nodeValue) bgneal@45: ne.setAttribute(a.nodeName.toLowerCase(), a.nodeValue); bgneal@45: }); bgneal@45: bgneal@45: each(rn.childNodes, function(n) { bgneal@45: ne.appendChild(n.cloneNode(true)); bgneal@45: }); bgneal@45: bgneal@45: rn.parentNode.replaceChild(ne, rn); bgneal@45: bgneal@45: return ne; bgneal@45: }; bgneal@45: bgneal@45: // Replaces IE:s auto generated paragraphs with the specified element name bgneal@45: if (isIE && s.element != 'P') { bgneal@45: ed.onKeyPress.add(function(ed, e) { bgneal@45: t.lastElm = ed.selection.getNode().nodeName; bgneal@45: }); bgneal@45: bgneal@45: ed.onKeyUp.add(function(ed, e) { bgneal@45: var bl, sel = ed.selection, n = sel.getNode(), b = ed.getBody(); bgneal@45: bgneal@45: if (b.childNodes.length === 1 && n.nodeName == 'P') { bgneal@45: n = ren(n, s.element); bgneal@45: sel.select(n); bgneal@45: sel.collapse(); bgneal@45: ed.nodeChanged(); bgneal@45: } else if (e.keyCode == 13 && !e.shiftKey && t.lastElm != 'P') { bgneal@45: bl = ed.dom.getParent(n, 'P'); bgneal@45: bgneal@45: if (bl) { bgneal@45: ren(bl, s.element); bgneal@45: ed.nodeChanged(); bgneal@45: } bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: find : function(n, t, s) { bgneal@45: var ed = this.editor, w = ed.getDoc().createTreeWalker(n, 4, null, false), c = -1; bgneal@45: bgneal@45: while (n = w.nextNode()) { bgneal@45: c++; bgneal@45: bgneal@45: // Index by node bgneal@45: if (t == 0 && n == s) bgneal@45: return c; bgneal@45: bgneal@45: // Node by index bgneal@45: if (t == 1 && c == s) bgneal@45: return n; bgneal@45: } bgneal@45: bgneal@45: return -1; bgneal@45: }, bgneal@45: bgneal@45: forceRoots : function(ed, e) { bgneal@45: var t = this, ed = t.editor, b = ed.getBody(), d = ed.getDoc(), se = ed.selection, s = se.getSel(), r = se.getRng(), si = -2, ei, so, eo, tr, c = -0xFFFFFF; bgneal@45: var nx, bl, bp, sp, le, nl = b.childNodes, i, n, eid; bgneal@45: bgneal@45: // Fix for bug #1863847 bgneal@45: //if (e && e.keyCode == 13) bgneal@45: // return true; bgneal@45: bgneal@45: // Wrap non blocks into blocks bgneal@45: for (i = nl.length - 1; i >= 0; i--) { bgneal@45: nx = nl[i]; bgneal@45: bgneal@45: // Is text or non block element bgneal@45: if (nx.nodeType == 3 || (!t.dom.isBlock(nx) && nx.nodeType != 8)) { bgneal@45: if (!bl) { bgneal@45: // Create new block but ignore whitespace bgneal@45: if (nx.nodeType != 3 || /[^\s]/g.test(nx.nodeValue)) { bgneal@45: // Store selection bgneal@45: if (si == -2 && r) { bgneal@45: if (!isIE) { bgneal@45: // If selection is element then mark it bgneal@45: if (r.startContainer.nodeType == 1 && (n = r.startContainer.childNodes[r.startOffset]) && n.nodeType == 1) { bgneal@45: // Save the id of the selected element bgneal@45: eid = n.getAttribute("id"); bgneal@45: n.setAttribute("id", "__mce"); bgneal@45: } else { bgneal@45: // If element is inside body, might not be the case in contentEdiable mode bgneal@45: if (ed.dom.getParent(r.startContainer, function(e) {return e === b;})) { bgneal@45: so = r.startOffset; bgneal@45: eo = r.endOffset; bgneal@45: si = t.find(b, 0, r.startContainer); bgneal@45: ei = t.find(b, 0, r.endContainer); bgneal@45: } bgneal@45: } bgneal@45: } else { bgneal@45: tr = d.body.createTextRange(); bgneal@45: tr.moveToElementText(b); bgneal@45: tr.collapse(1); bgneal@45: bp = tr.move('character', c) * -1; bgneal@45: bgneal@45: tr = r.duplicate(); bgneal@45: tr.collapse(1); bgneal@45: sp = tr.move('character', c) * -1; bgneal@45: bgneal@45: tr = r.duplicate(); bgneal@45: tr.collapse(0); bgneal@45: le = (tr.move('character', c) * -1) - sp; bgneal@45: bgneal@45: si = sp - bp; bgneal@45: ei = le; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: bl = ed.dom.create(ed.settings.forced_root_block); bgneal@45: bl.appendChild(nx.cloneNode(1)); bgneal@45: nx.parentNode.replaceChild(bl, nx); bgneal@45: } bgneal@45: } else { bgneal@45: if (bl.hasChildNodes()) bgneal@45: bl.insertBefore(nx, bl.firstChild); bgneal@45: else bgneal@45: bl.appendChild(nx); bgneal@45: } bgneal@45: } else bgneal@45: bl = null; // Time to create new block bgneal@45: } bgneal@45: bgneal@45: // Restore selection bgneal@45: if (si != -2) { bgneal@45: if (!isIE) { bgneal@45: bl = b.getElementsByTagName(ed.settings.element)[0]; bgneal@45: r = d.createRange(); bgneal@45: bgneal@45: // Select last location or generated block bgneal@45: if (si != -1) bgneal@45: r.setStart(t.find(b, 1, si), so); bgneal@45: else bgneal@45: r.setStart(bl, 0); bgneal@45: bgneal@45: // Select last location or generated block bgneal@45: if (ei != -1) bgneal@45: r.setEnd(t.find(b, 1, ei), eo); bgneal@45: else bgneal@45: r.setEnd(bl, 0); bgneal@45: bgneal@45: if (s) { bgneal@45: s.removeAllRanges(); bgneal@45: s.addRange(r); bgneal@45: } bgneal@45: } else { bgneal@45: try { bgneal@45: r = s.createRange(); bgneal@45: r.moveToElementText(b); bgneal@45: r.collapse(1); bgneal@45: r.moveStart('character', si); bgneal@45: r.moveEnd('character', ei); bgneal@45: r.select(); bgneal@45: } catch (ex) { bgneal@45: // Ignore bgneal@45: } bgneal@45: } bgneal@45: } else if (!isIE && (n = ed.dom.get('__mce'))) { bgneal@45: // Restore the id of the selected element bgneal@45: if (eid) bgneal@45: n.setAttribute('id', eid); bgneal@45: else bgneal@45: n.removeAttribute('id'); bgneal@45: bgneal@45: // Move caret before selected element bgneal@45: r = d.createRange(); bgneal@45: r.setStartBefore(n); bgneal@45: r.setEndBefore(n); bgneal@45: se.setRng(r); 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, d = ed.getDoc(), se = ed.settings, s = ed.selection.getSel(), r = s.getRangeAt(0), b = d.body; bgneal@45: var rb, ra, dir, sn, so, en, eo, sb, eb, bn, bef, aft, sc, ec, n, vp = dom.getViewPort(ed.getWin()), y, ch, car; bgneal@45: bgneal@45: function isEmpty(n) { bgneal@45: n = n.innerHTML; bgneal@45: n = n.replace(/<(img|hr|table)/gi, '-'); // Keep these convert them to - chars bgneal@45: n = n.replace(/<[^>]+>/g, ''); // Remove all tags bgneal@45: bgneal@45: return n.replace(/[ \t\r\n]+/g, '') == ''; bgneal@45: }; 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: // Setup before range bgneal@45: rb = d.createRange(); 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 = d.createRange(); 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: bgneal@45: // If selection is in empty table cell bgneal@45: if (sn === en && /^(TD|TH)$/.test(sn.nodeName)) { bgneal@45: dom.remove(sn.firstChild); // Remove BR bgneal@45: bgneal@45: // Create two new block elements bgneal@45: ed.dom.add(sn, se.element, null, '
'); bgneal@45: aft = ed.dom.add(sn, se.element, null, '
'); bgneal@45: bgneal@45: // Move caret into the last one bgneal@45: r = d.createRange(); bgneal@45: r.selectNodeContents(aft); bgneal@45: r.collapse(1); bgneal@45: ed.selection.setRng(r); 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 && ed.dom.isBlock(b.firstChild)) { bgneal@45: sn = en = sn.firstChild; bgneal@45: so = eo = 0; bgneal@45: rb = d.createRange(); bgneal@45: rb.setStart(sn, 0); bgneal@45: ra = d.createRange(); bgneal@45: ra.setStart(en, 0); 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: // Return inside list use default browser behavior bgneal@45: if (t.dom.getParent(sb, 'OL,UL,PRE')) bgneal@45: return true; 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) ? sb.cloneNode(0) : ed.dom.create(bn); bgneal@45: aft = (eb && eb.nodeName == bn) ? eb.cloneNode(0) : ed.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) && sn.nodeValue && so == sn.nodeValue.length) bgneal@45: aft = ed.dom.create(se.element); 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 = d.createRange(); 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: // Delete and replace it with new block elements bgneal@45: r.deleteContents(); bgneal@45: bgneal@45: if (isOpera) bgneal@45: ed.getWin().scrollTo(0, vp.y); 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: // Padd empty blocks bgneal@45: if (isEmpty(bef)) bgneal@45: bef.innerHTML = '
'; bgneal@45: bgneal@45: function appendStyles(e, en) { bgneal@45: var nl = [], nn, n, i; bgneal@45: bgneal@45: e.innerHTML = ''; 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 = isOpera ? ' ' : '
'; // Extra space for Opera so that the caret can move there bgneal@45: return nl[0]; // Move caret to most inner element bgneal@45: } else bgneal@45: e.innerHTML = isOpera ? ' ' : '
'; // Extra space for Opera so that the caret can move there bgneal@45: }; bgneal@45: bgneal@45: // Fill empty afterblook with current style bgneal@45: if (isEmpty(aft)) bgneal@45: car = 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: // Normalize bgneal@45: aft.normalize(); bgneal@45: bef.normalize(); bgneal@45: bgneal@45: function first(n) { bgneal@45: return d.createTreeWalker(n, NodeFilter.SHOW_TEXT, null, false).nextNode() || n; bgneal@45: }; bgneal@45: bgneal@45: // Move cursor and scroll into view bgneal@45: r = d.createRange(); bgneal@45: r.selectNodeContents(isGecko ? first(car || aft) : car || aft); bgneal@45: r.collapse(1); bgneal@45: s.removeAllRanges(); bgneal@45: s.addRange(r); 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 = ed.dom.getPos(aft).y; bgneal@45: ch = aft.clientHeight; bgneal@45: bgneal@45: // Is element within viewport bgneal@45: if (y < vp.y || y + ch > 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: //console.debug('SCROLL!', 'vp.y: ' + vp.y, 'y' + y, 'vp.h' + vp.h, 'clientHeight' + aft.clientHeight, 'yyy: ' + (y < vp.y ? y : y - vp.h + aft.clientHeight)); bgneal@45: } 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(), n, se = ed.selection, r = se.getRng(), sc = r.startContainer, n, w, tn; 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: // Gecko generates BR elements here and there, we don't like those so lets remove them bgneal@45: function handler(e) { bgneal@45: var pr; bgneal@45: bgneal@45: e = e.target; bgneal@45: bgneal@45: // A new BR was created in a block element, remove it bgneal@45: if (e && e.parentNode && e.nodeName == 'BR' && (n = t.getParentBlock(e))) { bgneal@45: pr = e.previousSibling; bgneal@45: bgneal@45: Event.remove(b, 'DOMNodeInserted', handler); bgneal@45: bgneal@45: // Is there whitespace at the end of the node before then we might need the pesky BR bgneal@45: // to place the caret at a correct location see bug: #2013943 bgneal@45: if (pr && pr.nodeType == 3 && /\s+$/.test(pr.nodeValue)) bgneal@45: return; bgneal@45: bgneal@45: // Only remove BR elements that got inserted in the middle of the text bgneal@45: if (e.previousSibling || e.nextSibling) bgneal@45: ed.dom.remove(e); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: // Listen for new nodes bgneal@45: Event._add(b, 'DOMNodeInserted', handler); bgneal@45: bgneal@45: // Remove listener bgneal@45: window.setTimeout(function() { bgneal@45: Event._remove(b, 'DOMNodeInserted', handler); bgneal@45: }, 1); bgneal@45: } bgneal@45: }); bgneal@45: })(tinymce); 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: 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: 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: if (ed.settings.use_native_selects) 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); 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('simple'); 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); 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); 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)); 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); 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.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); 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: }); bgneal@45: })(tinymce); 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: // 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: }); bgneal@45: }(tinymce));(function(tinymce) { bgneal@45: tinymce.CommandManager = function() { bgneal@45: var execCommands = {}, queryStateCommands = {}, queryValueCommands = {}; bgneal@45: bgneal@45: function add(collection, cmd, func, scope) { bgneal@45: if (typeof(cmd) == 'string') bgneal@45: cmd = [cmd]; bgneal@45: bgneal@45: tinymce.each(cmd, function(cmd) { bgneal@45: collection[cmd.toLowerCase()] = {func : func, scope : scope}; bgneal@45: }); bgneal@45: }; bgneal@45: bgneal@45: tinymce.extend(this, { bgneal@45: add : function(cmd, func, scope) { bgneal@45: add(execCommands, cmd, func, scope); bgneal@45: }, bgneal@45: bgneal@45: addQueryStateHandler : function(cmd, func, scope) { bgneal@45: add(queryStateCommands, cmd, func, scope); bgneal@45: }, bgneal@45: bgneal@45: addQueryValueHandler : function(cmd, func, scope) { bgneal@45: add(queryValueCommands, cmd, func, scope); bgneal@45: }, bgneal@45: bgneal@45: execCommand : function(scope, cmd, ui, value, args) { bgneal@45: if (cmd = execCommands[cmd.toLowerCase()]) { bgneal@45: if (cmd.func.call(scope || cmd.scope, ui, value, args) !== false) bgneal@45: return true; bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: queryCommandValue : function() { bgneal@45: if (cmd = queryValueCommands[cmd.toLowerCase()]) bgneal@45: return cmd.func.call(scope || cmd.scope, ui, value, args); bgneal@45: }, bgneal@45: bgneal@45: queryCommandState : function() { bgneal@45: if (cmd = queryStateCommands[cmd.toLowerCase()]) bgneal@45: return cmd.func.call(scope || cmd.scope, ui, value, args); bgneal@45: } bgneal@45: }); bgneal@45: }; bgneal@45: bgneal@45: tinymce.GlobalCommands = new tinymce.CommandManager(); bgneal@45: })(tinymce);(function(tinymce) { bgneal@45: function processRange(dom, start, end, callback) { bgneal@45: var ancestor, n, startPoint, endPoint, sib; bgneal@45: bgneal@45: function findEndPoint(n, c) { bgneal@45: do { bgneal@45: if (n.parentNode == c) bgneal@45: return n; bgneal@45: bgneal@45: n = n.parentNode; bgneal@45: } while(n); bgneal@45: }; bgneal@45: bgneal@45: function process(n) { bgneal@45: callback(n); bgneal@45: tinymce.walk(n, callback, 'childNodes'); bgneal@45: }; bgneal@45: bgneal@45: // Find common ancestor and end points bgneal@45: ancestor = dom.findCommonAncestor(start, end); bgneal@45: startPoint = findEndPoint(start, ancestor) || start; bgneal@45: endPoint = findEndPoint(end, ancestor) || end; bgneal@45: bgneal@45: // Process left leaf bgneal@45: for (n = start; n && n != startPoint; n = n.parentNode) { bgneal@45: for (sib = n.nextSibling; sib; sib = sib.nextSibling) bgneal@45: process(sib); bgneal@45: } bgneal@45: bgneal@45: // Process middle from start to end point bgneal@45: if (startPoint != endPoint) { bgneal@45: for (n = startPoint.nextSibling; n && n != endPoint; n = n.nextSibling) bgneal@45: process(n); bgneal@45: } else bgneal@45: process(startPoint); bgneal@45: bgneal@45: // Process right leaf bgneal@45: for (n = end; n && n != endPoint; n = n.parentNode) { bgneal@45: for (sib = n.previousSibling; sib; sib = sib.previousSibling) bgneal@45: process(sib); bgneal@45: } bgneal@45: }; bgneal@45: bgneal@45: tinymce.GlobalCommands.add('RemoveFormat', function() { bgneal@45: var ed = this, dom = ed.dom, s = ed.selection, r = s.getRng(1), nodes = [], bm, start, end, sc, so, ec, eo, n; bgneal@45: bgneal@45: function findFormatRoot(n) { bgneal@45: var sp; bgneal@45: bgneal@45: dom.getParent(n, function(n) { bgneal@45: if (dom.is(n, ed.getParam('removeformat_selector'))) bgneal@45: sp = n; bgneal@45: bgneal@45: return dom.isBlock(n); bgneal@45: }, ed.getBody()) bgneal@45: bgneal@45: return sp; bgneal@45: }; bgneal@45: bgneal@45: function collect(n) { bgneal@45: if (dom.is(n, ed.getParam('removeformat_selector'))) bgneal@45: nodes.push(n); bgneal@45: }; bgneal@45: bgneal@45: function walk(n) { bgneal@45: collect(n); bgneal@45: tinymce.walk(n, collect, 'childNodes'); bgneal@45: }; bgneal@45: bgneal@45: bm = s.getBookmark(); bgneal@45: sc = r.startContainer; bgneal@45: ec = r.endContainer; bgneal@45: so = r.startOffset; bgneal@45: eo = r.endOffset; bgneal@45: sc = sc.nodeType == 1 ? sc.childNodes[so] : sc; bgneal@45: ec = ec.nodeType == 1 ? ec.childNodes[eo - 1] : ec; bgneal@45: bgneal@45: // Same container bgneal@45: if (sc == ec) { // TEXT_NODE bgneal@45: start = findFormatRoot(sc); bgneal@45: bgneal@45: // Handle single text node bgneal@45: if (sc.nodeType == 3) { bgneal@45: if (start && start.nodeType == 1) { // ELEMENT bgneal@45: n = sc.splitText(so); bgneal@45: n.splitText(eo - so); bgneal@45: dom.split(start, n); bgneal@45: bgneal@45: s.moveToBookmark(bm); bgneal@45: } bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Handle single element bgneal@45: walk(dom.split(start, sc) || sc); bgneal@45: } else { bgneal@45: // Find start/end format root bgneal@45: start = findFormatRoot(sc); bgneal@45: end = findFormatRoot(ec); bgneal@45: bgneal@45: // Split start text node bgneal@45: if (start) { bgneal@45: if (sc.nodeType == 3) { // TEXT bgneal@45: // Since IE doesn't support white space nodes in the DOM we need to bgneal@45: // add this invisible character so that the splitText function can split the contents bgneal@45: if (so == sc.nodeValue.length) bgneal@45: sc.nodeValue += '\uFEFF'; // Yet another pesky IE fix bgneal@45: bgneal@45: sc = sc.splitText(so); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Split end text node bgneal@45: if (end) { bgneal@45: if (ec.nodeType == 3) // TEXT bgneal@45: ec.splitText(eo); bgneal@45: } bgneal@45: bgneal@45: // If the start and end format root is the same then we need to wrap bgneal@45: // the end node in a span since the split calls might change the reference bgneal@45: // Example:

x[yz---12]3

bgneal@45: if (start && start == end) bgneal@45: dom.replace(dom.create('span', {id : '__end'}, ec.cloneNode(true)), ec); bgneal@45: bgneal@45: // Split all start containers down to the format root bgneal@45: if (start) bgneal@45: start = dom.split(start, sc); bgneal@45: else bgneal@45: start = sc; bgneal@45: bgneal@45: // If there is a span wrapper use that one instead bgneal@45: if (n = dom.get('__end')) { bgneal@45: ec = n; bgneal@45: end = findFormatRoot(ec); bgneal@45: } bgneal@45: bgneal@45: // Split all end containers down to the format root bgneal@45: if (end) bgneal@45: end = dom.split(end, ec); bgneal@45: else bgneal@45: end = ec; bgneal@45: bgneal@45: // Collect nodes in between bgneal@45: processRange(dom, start, end, collect); bgneal@45: bgneal@45: // Remove invisible character for IE workaround if we find it bgneal@45: if (sc.nodeValue == '\uFEFF') bgneal@45: sc.nodeValue = ''; bgneal@45: bgneal@45: // Process start/end container elements bgneal@45: walk(ec); bgneal@45: walk(sc); bgneal@45: } bgneal@45: bgneal@45: // Remove all collected nodes bgneal@45: tinymce.each(nodes, function(n) { bgneal@45: dom.remove(n, 1); bgneal@45: }); bgneal@45: bgneal@45: // Remove leftover wrapper bgneal@45: dom.remove('__end', 1); bgneal@45: bgneal@45: s.moveToBookmark(bm); bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: (function(tinymce) { bgneal@45: tinymce.GlobalCommands.add('mceBlockQuote', function() { bgneal@45: var ed = this, s = ed.selection, dom = ed.dom, sb, eb, n, bm, bq, r, bq2, i, nl; bgneal@45: bgneal@45: function getBQ(e) { bgneal@45: return dom.getParent(e, function(n) {return n.nodeName === 'BLOCKQUOTE';}); bgneal@45: }; bgneal@45: bgneal@45: // Get start/end block bgneal@45: sb = dom.getParent(s.getStart(), dom.isBlock); bgneal@45: eb = dom.getParent(s.getEnd(), dom.isBlock); bgneal@45: bgneal@45: // Remove blockquote(s) bgneal@45: if (bq = getBQ(sb)) { bgneal@45: if (sb != eb || sb.childNodes.length > 1 || (sb.childNodes.length == 1 && sb.firstChild.nodeName != 'BR')) bgneal@45: bm = s.getBookmark(); bgneal@45: bgneal@45: // Move all elements after the end block into new bq bgneal@45: if (getBQ(eb)) { bgneal@45: bq2 = bq.cloneNode(false); bgneal@45: bgneal@45: while (n = eb.nextSibling) bgneal@45: bq2.appendChild(n.parentNode.removeChild(n)); bgneal@45: } bgneal@45: bgneal@45: // Add new bq after bgneal@45: if (bq2) bgneal@45: dom.insertAfter(bq2, bq); bgneal@45: bgneal@45: // Move all selected blocks after the current bq bgneal@45: nl = s.getSelectedBlocks(sb, eb); bgneal@45: for (i = nl.length - 1; i >= 0; i--) { bgneal@45: dom.insertAfter(nl[i], bq); bgneal@45: } bgneal@45: bgneal@45: // Empty bq, then remove it bgneal@45: if (/^\s*$/.test(bq.innerHTML)) bgneal@45: dom.remove(bq, 1); // Keep children so boomark restoration works correctly bgneal@45: bgneal@45: // Empty bq, then remote it bgneal@45: if (bq2 && /^\s*$/.test(bq2.innerHTML)) bgneal@45: dom.remove(bq2, 1); // Keep children so boomark restoration works correctly bgneal@45: bgneal@45: if (!bm) { bgneal@45: // Move caret inside empty block element bgneal@45: if (!tinymce.isIE) { bgneal@45: r = ed.getDoc().createRange(); bgneal@45: r.setStart(sb, 0); bgneal@45: r.setEnd(sb, 0); bgneal@45: s.setRng(r); bgneal@45: } else { bgneal@45: s.select(sb); bgneal@45: s.collapse(0); bgneal@45: bgneal@45: // IE misses the empty block some times element so we must move back the caret bgneal@45: if (dom.getParent(s.getStart(), dom.isBlock) != sb) { bgneal@45: r = s.getRng(); bgneal@45: r.move('character', -1); bgneal@45: r.select(); bgneal@45: } bgneal@45: } bgneal@45: } else bgneal@45: ed.selection.moveToBookmark(bm); bgneal@45: bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Since IE can start with a totally empty document we need to add the first bq and paragraph bgneal@45: if (tinymce.isIE && !sb && !eb) { bgneal@45: ed.getDoc().execCommand('Indent'); bgneal@45: n = getBQ(s.getNode()); bgneal@45: n.style.margin = n.dir = ''; // IE adds margin and dir to bq bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: if (!sb || !eb) bgneal@45: return; bgneal@45: bgneal@45: // If empty paragraph node then do not use bookmark bgneal@45: if (sb != eb || sb.childNodes.length > 1 || (sb.childNodes.length == 1 && sb.firstChild.nodeName != 'BR')) bgneal@45: bm = s.getBookmark(); bgneal@45: bgneal@45: // Move selected block elements into a bq bgneal@45: tinymce.each(s.getSelectedBlocks(getBQ(s.getStart()), getBQ(s.getEnd())), function(e) { bgneal@45: // Found existing BQ add to this one bgneal@45: if (e.nodeName == 'BLOCKQUOTE' && !bq) { bgneal@45: bq = e; bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // No BQ found, create one bgneal@45: if (!bq) { bgneal@45: bq = dom.create('blockquote'); bgneal@45: e.parentNode.insertBefore(bq, e); bgneal@45: } bgneal@45: bgneal@45: // Add children from existing BQ bgneal@45: if (e.nodeName == 'BLOCKQUOTE' && bq) { bgneal@45: n = e.firstChild; bgneal@45: bgneal@45: while (n) { bgneal@45: bq.appendChild(n.cloneNode(true)); bgneal@45: n = n.nextSibling; bgneal@45: } bgneal@45: bgneal@45: dom.remove(e); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Add non BQ element to BQ bgneal@45: bq.appendChild(dom.remove(e)); bgneal@45: }); bgneal@45: bgneal@45: if (!bm) { bgneal@45: // Move caret inside empty block element bgneal@45: if (!tinymce.isIE) { bgneal@45: r = ed.getDoc().createRange(); bgneal@45: r.setStart(sb, 0); bgneal@45: r.setEnd(sb, 0); bgneal@45: s.setRng(r); bgneal@45: } else { bgneal@45: s.select(sb); bgneal@45: s.collapse(1); bgneal@45: } bgneal@45: } else bgneal@45: s.moveToBookmark(bm); bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: (function(tinymce) { bgneal@45: tinymce.each(['Cut', 'Copy', 'Paste'], function(cmd) { bgneal@45: tinymce.GlobalCommands.add(cmd, function() { bgneal@45: var ed = this, doc = ed.getDoc(); bgneal@45: bgneal@45: try { bgneal@45: doc.execCommand(cmd, false, null); bgneal@45: bgneal@45: // On WebKit the command will just be ignored if it's not enabled bgneal@45: if (!doc.queryCommandSupported(cmd)) bgneal@45: throw 'Error'; bgneal@45: } catch (ex) { bgneal@45: ed.windowManager.alert(ed.getLang('clipboard_no_support')); bgneal@45: } bgneal@45: }); bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: (function(tinymce) { bgneal@45: tinymce.GlobalCommands.add('InsertHorizontalRule', function() { bgneal@45: if (tinymce.isOpera) bgneal@45: return this.getDoc().execCommand('InsertHorizontalRule', false, ''); bgneal@45: bgneal@45: this.selection.setContent('
'); bgneal@45: }); bgneal@45: })(tinymce); bgneal@45: (function() { bgneal@45: var cmds = tinymce.GlobalCommands; bgneal@45: bgneal@45: cmds.add(['mceEndUndoLevel', 'mceAddUndoLevel'], function() { bgneal@45: this.undoManager.add(); bgneal@45: }); bgneal@45: bgneal@45: cmds.add('Undo', function() { bgneal@45: var ed = this; bgneal@45: bgneal@45: if (ed.settings.custom_undo_redo) { bgneal@45: ed.undoManager.undo(); bgneal@45: ed.nodeChanged(); bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: return false; // Run browser command bgneal@45: }); bgneal@45: bgneal@45: cmds.add('Redo', function() { bgneal@45: var ed = this; bgneal@45: bgneal@45: if (ed.settings.custom_undo_redo) { bgneal@45: ed.undoManager.redo(); bgneal@45: ed.nodeChanged(); bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: return false; // Run browser command bgneal@45: }); bgneal@45: })();