bgneal@183: (function(win) { bgneal@183: var whiteSpaceRe = /^\s*|\s*$/g, bgneal@183: undefined; bgneal@183: bgneal@183: var tinymce = { bgneal@183: majorVersion : '3', bgneal@183: bgneal@247: minorVersion : '3.9', bgneal@247: bgneal@247: releaseDate : '2010-09-08', bgneal@183: bgneal@183: _init : function() { bgneal@183: var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v; bgneal@183: bgneal@183: t.isOpera = win.opera && opera.buildNumber; bgneal@183: bgneal@183: t.isWebKit = /WebKit/.test(ua); bgneal@183: bgneal@183: t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName); bgneal@183: bgneal@183: t.isIE6 = t.isIE && /MSIE [56]/.test(ua); bgneal@183: bgneal@183: t.isGecko = !t.isWebKit && /Gecko/.test(ua); bgneal@183: bgneal@183: t.isMac = ua.indexOf('Mac') != -1; bgneal@183: bgneal@183: t.isAir = /adobeair/i.test(ua); bgneal@183: bgneal@217: t.isIDevice = /(iPad|iPhone)/.test(ua); bgneal@217: bgneal@183: // TinyMCE .NET webcontrol might be setting the values for TinyMCE bgneal@183: if (win.tinyMCEPreInit) { bgneal@183: t.suffix = tinyMCEPreInit.suffix; bgneal@183: t.baseURL = tinyMCEPreInit.base; bgneal@183: t.query = tinyMCEPreInit.query; bgneal@45: return; bgneal@183: } bgneal@183: bgneal@183: // Get suffix and base bgneal@183: t.suffix = ''; bgneal@183: bgneal@183: // If base element found, add that infront of baseURL bgneal@183: nl = d.getElementsByTagName('base'); bgneal@183: for (i=0; i : bgneal@183: s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s); bgneal@183: cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name bgneal@183: bgneal@183: // Create namespace for new class bgneal@183: ns = t.createNS(s[3].replace(/\.\w+$/, '')); bgneal@183: bgneal@183: // Class already exists bgneal@183: if (ns[cn]) bgneal@183: return; bgneal@183: bgneal@183: // Make pure static class bgneal@183: if (s[2] == 'static') { bgneal@183: ns[cn] = p; bgneal@183: bgneal@183: if (this.onCreate) bgneal@183: this.onCreate(s[2], s[3], ns[cn]); bgneal@183: bgneal@183: return; bgneal@183: } bgneal@183: bgneal@183: // Create default constructor bgneal@183: if (!p[cn]) { bgneal@183: p[cn] = function() {}; bgneal@183: de = 1; bgneal@183: } bgneal@183: bgneal@183: // Add constructor and methods bgneal@183: ns[cn] = p[cn]; bgneal@183: t.extend(ns[cn].prototype, p); bgneal@183: bgneal@183: // Extend bgneal@183: if (s[5]) { bgneal@183: sp = t.resolve(s[5]).prototype; bgneal@183: scn = s[5].match(/\.(\w+)$/i)[1]; // Class name bgneal@183: bgneal@183: // Extend constructor bgneal@183: c = ns[cn]; bgneal@183: if (de) { bgneal@183: // Add passthrough constructor bgneal@183: ns[cn] = function() { bgneal@183: return sp[scn].apply(this, arguments); bgneal@45: }; bgneal@45: } else { bgneal@183: // Add inherit constructor bgneal@183: ns[cn] = function() { bgneal@183: this.parent = sp[scn]; bgneal@183: return c.apply(this, arguments); bgneal@183: }; bgneal@183: } bgneal@183: ns[cn].prototype[cn] = ns[cn]; bgneal@183: bgneal@183: // Add super methods bgneal@183: t.each(sp, function(f, n) { bgneal@183: ns[cn].prototype[n] = sp[n]; bgneal@183: }); bgneal@183: bgneal@183: // Add overridden methods bgneal@183: t.each(p, function(f, n) { bgneal@183: // Extend methods if needed bgneal@183: if (sp[n]) { bgneal@183: ns[cn].prototype[n] = function() { bgneal@183: this.parent = sp[n]; bgneal@183: return f.apply(this, arguments); bgneal@183: }; bgneal@183: } else { bgneal@183: if (n != cn) bgneal@183: ns[cn].prototype[n] = f; bgneal@183: } bgneal@183: }); bgneal@183: } bgneal@183: bgneal@183: // Add static methods bgneal@183: t.each(p['static'], function(f, n) { bgneal@183: ns[cn][n] = f; bgneal@183: }); bgneal@183: bgneal@183: if (this.onCreate) bgneal@183: this.onCreate(s[2], s[3], ns[cn].prototype); bgneal@183: }, bgneal@183: bgneal@183: walk : function(o, f, n, s) { bgneal@183: s = s || this; bgneal@183: bgneal@183: if (o) { bgneal@183: if (n) bgneal@183: o = o[n]; bgneal@183: bgneal@183: tinymce.each(o, function(o, i) { bgneal@183: if (f.call(s, o, i, n) === false) bgneal@183: return false; bgneal@183: bgneal@183: tinymce.walk(o, f, n, s); bgneal@183: }); bgneal@183: } bgneal@183: }, bgneal@183: bgneal@183: createNS : function(n, o) { bgneal@183: var i, v; bgneal@183: bgneal@183: o = o || win; bgneal@183: bgneal@183: n = n.split('.'); bgneal@183: 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@183: var i, nb = 0, o = [], tr, outPath; bgneal@45: bgneal@45: // Split paths bgneal@45: tr = /\/$/.test(path) ? '/' : ''; bgneal@45: base = base.split('/'); bgneal@45: path = path.split('/'); bgneal@45: bgneal@45: // Remove empty chunks bgneal@45: each(base, function(k) { bgneal@45: if (k) bgneal@45: o.push(k); bgneal@45: }); bgneal@45: bgneal@45: base = o; bgneal@45: bgneal@45: // Merge relURLParts chunks bgneal@45: for (i = path.length - 1, o = []; i >= 0; i--) { bgneal@45: // Ignore empty or . bgneal@45: if (path[i].length == 0 || path[i] == ".") bgneal@45: continue; bgneal@45: bgneal@45: // Is parent bgneal@45: if (path[i] == '..') { bgneal@45: nb++; bgneal@45: continue; bgneal@45: } bgneal@45: bgneal@45: // Move up bgneal@45: if (nb > 0) { bgneal@45: nb--; bgneal@45: continue; bgneal@45: } bgneal@45: bgneal@45: o.push(path[i]); bgneal@45: } bgneal@45: bgneal@45: i = base.length - nb; bgneal@45: bgneal@45: // If /a/b/c or / bgneal@45: if (i <= 0) bgneal@183: outPath = o.reverse().join('/'); bgneal@183: else bgneal@183: outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/'); bgneal@183: bgneal@183: // Add front / if it's needed bgneal@183: if (outPath.indexOf('/') !== 0) bgneal@183: outPath = '/' + outPath; bgneal@183: bgneal@183: // Add traling / if it's needed bgneal@183: if (tr && outPath.lastIndexOf('/') !== outPath.length - 1) bgneal@183: outPath += tr; bgneal@183: bgneal@183: return outPath; bgneal@45: }, bgneal@45: bgneal@45: getURI : function(nh) { bgneal@45: var s, t = this; bgneal@45: bgneal@45: // Rebuild source bgneal@45: if (!t.source || nh) { bgneal@45: s = ''; bgneal@45: bgneal@45: if (!nh) { bgneal@45: if (t.protocol) bgneal@45: s += t.protocol + '://'; bgneal@45: bgneal@45: if (t.userInfo) bgneal@45: s += t.userInfo + '@'; bgneal@45: bgneal@45: if (t.host) bgneal@45: s += t.host; bgneal@45: bgneal@45: if (t.port) bgneal@45: s += ':' + t.port; bgneal@45: } bgneal@45: bgneal@45: if (t.path) bgneal@45: s += t.path; bgneal@45: bgneal@45: if (t.query) bgneal@45: s += '?' + t.query; bgneal@45: bgneal@45: if (t.anchor) bgneal@45: s += '#' + t.anchor; bgneal@45: bgneal@45: t.source = s; bgneal@45: } bgneal@45: bgneal@45: return t.source; bgneal@45: } bgneal@183: }); bgneal@45: })(); bgneal@183: 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@183: }); bgneal@45: })(); bgneal@183: 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@183: 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@183: x.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); bgneal@183: 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@183: } bgneal@45: }); bgneal@183: 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@183: }); bgneal@183: }()); bgneal@183: (function(tinymce) { bgneal@45: // Shorten names bgneal@183: var each = tinymce.each, bgneal@183: is = tinymce.is, bgneal@183: isWebKit = tinymce.isWebKit, bgneal@183: isIE = tinymce.isIE, bgneal@183: blockRe = /^(H[1-6R]|P|DIV|ADDRESS|PRE|FORM|T(ABLE|BODY|HEAD|FOOT|H|R|D)|LI|OL|UL|CAPTION|BLOCKQUOTE|CENTER|DL|DT|DD|DIR|FIELDSET|NOSCRIPT|MENU|ISINDEX|SAMP)$/, bgneal@183: boolAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'), bgneal@183: mceAttribs = makeMap('src,href,style,coords,shape'), bgneal@183: encodedChars = {'&' : '&', '"' : '"', '<' : '<', '>' : '>'}, bgneal@183: encodeCharsRe = /[<>&\"]/g, bgneal@183: simpleSelectorRe = /^([a-z0-9],?)+$/i, bgneal@183: tagRegExp = /<(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)(\s*\/?)>/g, bgneal@183: attrRegExp = /(\w+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g; bgneal@183: bgneal@183: function makeMap(str) { bgneal@183: var map = {}, i; bgneal@183: bgneal@183: str = str.split(','); bgneal@183: for (i = str.length; i >= 0; i--) bgneal@183: map[str[i]] = 1; bgneal@183: bgneal@183: return map; bgneal@183: }; 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@183: var t = this, globalStyle; 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@183: t.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@183: // Build styles list bgneal@183: if (s.valid_styles) { bgneal@183: t._styles = {}; bgneal@183: bgneal@183: // Convert styles into a rule list bgneal@183: each(s.valid_styles, function(value, key) { bgneal@183: t._styles[key] = tinymce.explode(value); bgneal@183: }); bgneal@183: } bgneal@183: 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: 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@183: if (n == r || !n.nodeType || n.nodeType === 9) bgneal@45: break; bgneal@45: bgneal@45: if (!f || f(n)) { bgneal@45: if (c) bgneal@45: o.push(n); bgneal@45: else bgneal@45: return n; bgneal@45: } bgneal@45: bgneal@45: n = n.parentNode; bgneal@45: } bgneal@45: bgneal@45: return c ? o : null; bgneal@45: }, bgneal@45: bgneal@45: get : function(e) { bgneal@45: var n; bgneal@45: bgneal@45: if (e && this.doc && typeof(e) == 'string') { bgneal@45: n = e; bgneal@45: e = this.doc.getElementById(e); bgneal@45: bgneal@45: // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick bgneal@45: if (e && e.id !== n) bgneal@45: return this.doc.getElementsByName(n)[1]; bgneal@45: } bgneal@45: bgneal@45: return e; bgneal@45: }, bgneal@45: bgneal@183: getNext : function(node, selector) { bgneal@183: return this._findSib(node, selector, 'nextSibling'); bgneal@183: }, bgneal@183: bgneal@183: getPrev : function(node, selector) { bgneal@183: return this._findSib(node, selector, 'previousSibling'); bgneal@183: }, bgneal@183: 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@183: is : function(n, selector) { bgneal@183: var i; bgneal@183: bgneal@183: // If it isn't an array then try to do some simple selectors instead of Sizzle for to boost performance bgneal@183: if (n.length === undefined) { bgneal@183: // Simple all selector bgneal@183: if (selector === '*') bgneal@183: return n.nodeType == 1; bgneal@183: bgneal@183: // Simple selector just elements bgneal@183: if (simpleSelectorRe.test(selector)) { bgneal@183: selector = selector.toLowerCase().split(/,/); bgneal@183: n = n.nodeName.toLowerCase(); bgneal@183: bgneal@183: for (i = selector.length - 1; i >= 0; i--) { bgneal@183: if (selector[i] == n) bgneal@183: return true; bgneal@183: } bgneal@183: bgneal@183: return false; bgneal@183: } bgneal@183: } bgneal@183: bgneal@183: return tinymce.dom.Sizzle.matches(selector, n.nodeType ? [n] : n).length > 0; bgneal@183: }, bgneal@183: 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@183: remove : function(node, keep_children) { bgneal@183: return this.run(node, function(node) { bgneal@183: var parent, child; bgneal@183: bgneal@183: parent = node.parentNode; bgneal@183: bgneal@183: if (!parent) bgneal@45: return null; bgneal@45: bgneal@183: if (keep_children) { bgneal@183: while (child = node.firstChild) { bgneal@183: // IE 8 will crash if you don't remove completely empty text nodes bgneal@217: if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue) bgneal@183: parent.insertBefore(child, node); bgneal@183: else bgneal@183: node.removeChild(child); bgneal@183: } bgneal@183: } bgneal@183: bgneal@183: return parent.removeChild(node); bgneal@183: }); bgneal@183: }, 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@183: 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@183: e.setAttribute('_mce_style', v, 2); bgneal@45: else bgneal@183: 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@183: t.setAttrib(e, '_mce_' + n, v, 2); bgneal@45: } bgneal@45: bgneal@45: break; bgneal@45: bgneal@45: case "shape": bgneal@183: 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: 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@183: 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@183: // Check boolean attribs bgneal@183: if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) { bgneal@183: if (e[t.props[n]] === true && v === '') bgneal@183: return n; bgneal@183: bgneal@183: return v ? n : ''; bgneal@183: } bgneal@183: bgneal@183: // Inner input elements will override attributes on form elements bgneal@183: if (e.nodeName === "FORM" && e.getAttributeNode(n)) bgneal@183: return e.getAttributeNode(n).nodeValue; bgneal@183: bgneal@45: if (n === 'style') { bgneal@45: v = v || e.style.cssText; bgneal@45: bgneal@45: if (v) { bgneal@183: v = t.serializeStyle(t.parseStyle(v), e.nodeName); bgneal@45: bgneal@45: if (t.settings.keep_values && !t._isRes(v)) bgneal@183: 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@183: v = ('' + v).replace(/^function\s+\w+\(\)\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@183: getPos : function(n, ro) { bgneal@45: var t = this, x = 0, y = 0, e, d = t.doc, r; bgneal@45: bgneal@45: n = t.get(n); bgneal@183: ro = ro || d.body; bgneal@183: bgneal@183: if (n) { bgneal@183: // Use getBoundingClientRect on IE, Opera has it but it's not perfect bgneal@183: if (isIE && !t.stdMode) { bgneal@183: n = n.getBoundingClientRect(); bgneal@183: e = t.boxModel ? d.documentElement : d.body; bgneal@183: x = t.getStyle(t.select('html')[0], 'borderWidth'); // Remove border bgneal@183: x = (x == 'medium' || t.boxModel && !t.isIE6) && 2 || x; bgneal@183: bgneal@183: return {x : n.left + e.scrollLeft - x, y : n.top + e.scrollTop - x}; bgneal@183: } bgneal@183: bgneal@183: r = n; bgneal@183: while (r && r != ro && r.nodeType) { bgneal@183: x += r.offsetLeft || 0; bgneal@183: y += r.offsetTop || 0; bgneal@183: r = r.offsetParent; bgneal@183: } bgneal@183: bgneal@183: r = n.parentNode; bgneal@183: while (r && r != ro && r.nodeType) { bgneal@45: x -= r.scrollLeft || 0; bgneal@45: y -= r.scrollTop || 0; bgneal@183: r = r.parentNode; bgneal@183: } 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@183: serializeStyle : function(o, name) { bgneal@183: var t = this, s = ''; bgneal@183: bgneal@183: function add(v, k) { bgneal@45: if (k && v) { bgneal@183: // Remove browser specific styles like -moz- or -webkit- bgneal@183: if (k.indexOf('-') === 0) bgneal@45: return; bgneal@45: bgneal@45: switch (k) { bgneal@183: case 'font-weight': bgneal@183: // Opera will output bold as 700 bgneal@183: if (v == 700) bgneal@183: v = 'bold'; bgneal@183: bgneal@183: break; bgneal@183: 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@183: }; bgneal@183: bgneal@183: // Validate style output bgneal@183: if (name && t._styles) { bgneal@183: each(t._styles['*'], function(name) { bgneal@183: add(o[name], name); bgneal@183: }); bgneal@183: bgneal@183: each(t._styles[name.toLowerCase()], function(name) { bgneal@183: add(o[name], name); bgneal@183: }); bgneal@183: } else bgneal@183: each(o, add); bgneal@45: bgneal@45: return s; bgneal@45: }, bgneal@45: bgneal@45: loadCSS : function(u) { bgneal@183: var t = this, d = t.doc, head; bgneal@45: bgneal@45: if (!u) bgneal@45: u = ''; bgneal@45: bgneal@183: head = t.select('head')[0]; bgneal@183: bgneal@45: each(u.split(','), function(u) { bgneal@183: var link; bgneal@183: bgneal@45: if (t.files[u]) bgneal@45: return; bgneal@45: bgneal@45: t.files[u] = true; bgneal@183: link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)}); bgneal@183: bgneal@183: // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug bgneal@183: // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading bgneal@183: // It's ugly but it seems to work fine. bgneal@183: if (isIE && d.documentMode) { bgneal@183: link.onload = function() { bgneal@183: d.recalc(); bgneal@183: link.onload = null; bgneal@183: }; bgneal@183: } bgneal@183: bgneal@183: head.appendChild(link); bgneal@183: }); bgneal@183: }, 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@183: v = tinymce.trim(v != ' ' ? v : ''); bgneal@183: bgneal@183: e.className = v; bgneal@183: bgneal@183: // Empty class attr bgneal@183: if (!v) { bgneal@183: e.removeAttribute('class'); bgneal@183: e.removeAttribute('className'); bgneal@183: } bgneal@183: bgneal@183: return v; bgneal@45: } bgneal@45: bgneal@45: return e.className; bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: hasClass : function(n, c) { bgneal@45: n = this.get(n); bgneal@45: bgneal@45: if (!n || !c) bgneal@45: return false; bgneal@45: bgneal@45: return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1; bgneal@45: }, bgneal@45: bgneal@45: show : function(e) { bgneal@45: return this.setStyle(e, 'display', 'block'); bgneal@45: }, bgneal@45: bgneal@45: hide : function(e) { bgneal@45: return this.setStyle(e, 'display', 'none'); bgneal@45: }, bgneal@45: bgneal@45: isHidden : function(e) { bgneal@45: e = this.get(e); bgneal@45: bgneal@45: return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none'; bgneal@45: }, bgneal@45: bgneal@45: uniqueId : function(p) { bgneal@45: return (!p ? 'mce_' : p) + (this.counter++); bgneal@45: }, bgneal@45: bgneal@45: setHTML : function(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@183: // Remove all child nodes bgneal@183: while (e.firstChild) bgneal@183: e.firstChild.removeNode(); bgneal@183: 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: // 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@183: 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@183: if (!n._mce_keep) { bgneal@45: x = 1; // Is broken bgneal@45: break; bgneal@45: } bgneal@45: bgneal@183: 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@183: h = h.replace(/

]+)>|

/ig, '

'); bgneal@217: h = h.replace(/<\/p>/gi, '
'); bgneal@45: bgneal@45: // Set the new HTML with DIVs bgneal@45: set(); bgneal@45: bgneal@183: // Replace all DIV elements with the _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@183: 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@183: 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, ''); // Force open bgneal@45: bgneal@183: // 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@183: 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@183: // Wrap the script contents in CDATA and keep them from executing bgneal@183: h = h.replace(/]+|)>([\s\S]*?)<\/script>/gi, function(v, attribs, text) { bgneal@45: // Force type attribute bgneal@183: if (!attribs) bgneal@183: attribs = ' type="text/javascript"'; bgneal@183: bgneal@183: // Convert the src attribute of the scripts bgneal@183: attribs = attribs.replace(/src=\"([^\"]+)\"?/i, function(a, url) { bgneal@183: if (s.url_converter) bgneal@183: url = t.encode(s.url_converter.call(s.url_converter_scope || t, t.decode(url), 'src', 'script')); bgneal@183: bgneal@183: return '_mce_src="' + url + '"'; bgneal@183: }); bgneal@183: bgneal@183: // Wrap text contents bgneal@183: if (tinymce.trim(text)) { bgneal@183: codeBlocks.push(trim(text)); bgneal@183: text = ''; bgneal@183: } bgneal@183: bgneal@183: return '' + text + ''; bgneal@45: }); bgneal@45: bgneal@183: // Wrap style elements bgneal@183: h = h.replace(/]+|)>([\s\S]*?)<\/style>/gi, function(v, attribs, text) { bgneal@183: // Wrap text contents bgneal@183: if (text) { bgneal@183: codeBlocks.push(trim(text)); bgneal@183: text = ''; bgneal@183: } bgneal@183: bgneal@183: return '' + text + ''; bgneal@45: }); bgneal@183: bgneal@183: // Wrap noscript elements bgneal@183: h = h.replace(/]+|)>([\s\S]*?)<\/noscript>/g, function(v, attribs, text) { bgneal@183: return ''; bgneal@183: }); bgneal@45: } bgneal@45: bgneal@45: h = h.replace(//g, ''); bgneal@45: bgneal@183: // This function processes the attributes in the HTML string to force boolean bgneal@183: // attributes to the attr="attr" format and convert style, src and href to _mce_ versions bgneal@183: function processTags(html) { bgneal@183: return html.replace(tagRegExp, function(match, elm_name, attrs, end) { bgneal@183: return '<' + elm_name + attrs.replace(attrRegExp, function(match, name, value, val2, val3) { bgneal@183: var mceValue; bgneal@183: bgneal@183: name = name.toLowerCase(); bgneal@183: value = value || val2 || val3 || ""; bgneal@183: bgneal@183: // Treat boolean attributes bgneal@183: if (boolAttrs[name]) { bgneal@183: // false or 0 is treated as a missing attribute bgneal@183: if (value === 'false' || value === '0') bgneal@183: return; bgneal@183: bgneal@183: return name + '="' + name + '"'; bgneal@45: } bgneal@45: bgneal@183: // Is attribute one that needs special treatment bgneal@183: if (mceAttribs[name] && attrs.indexOf('_mce_' + name) == -1) { bgneal@183: mceValue = t.decode(value); bgneal@183: bgneal@183: // Convert URLs to relative/absolute ones bgneal@183: if (s.url_converter && (name == "src" || name == "href")) bgneal@183: mceValue = s.url_converter.call(s.url_converter_scope || t, mceValue, name, elm_name); bgneal@183: bgneal@183: // Process styles lowercases them and compresses them bgneal@183: if (name == 'style') bgneal@183: mceValue = t.serializeStyle(t.parseStyle(mceValue), name); bgneal@183: bgneal@183: return name + '="' + value + '"' + ' _mce_' + name + '="' + t.encode(mceValue) + '"'; bgneal@45: } bgneal@183: bgneal@183: return match; bgneal@183: }) + end + '>'; bgneal@183: }); bgneal@183: }; bgneal@183: bgneal@183: h = processTags(h); bgneal@183: bgneal@183: // Restore script blocks bgneal@183: h = h.replace(/MCE_SCRIPT:([0-9]+)/g, function(val, idx) { bgneal@183: return codeBlocks[idx]; 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@183: function setHTML(e, h, d) { bgneal@183: var n, tp; bgneal@183: bgneal@183: tp = d.createElement("body"); bgneal@183: tp.innerHTML = h; bgneal@183: bgneal@183: n = tp.lastChild; bgneal@183: while (n) { bgneal@183: t.insertAfter(n.cloneNode(true), e); bgneal@183: n = n.previousSibling; bgneal@183: } bgneal@183: bgneal@183: t.remove(e); bgneal@183: }; bgneal@183: bgneal@45: return this.run(e, function(e) { bgneal@45: e = t.get(e); bgneal@183: bgneal@183: // Only set HTML on elements bgneal@183: if (e.nodeType == 1) { bgneal@183: d = d || e.ownerDocument || t.doc; bgneal@183: bgneal@183: if (isIE) { bgneal@183: try { bgneal@183: // Try outerHTML for IE it sometimes produces an unknown runtime error bgneal@183: if (isIE && e.nodeType == 1) bgneal@183: e.outerHTML = h; bgneal@183: else bgneal@183: setHTML(e, h, d); bgneal@183: } catch (ex) { bgneal@183: // Fix for unknown runtime error bgneal@183: setHTML(e, h, d); bgneal@183: } bgneal@183: } else bgneal@183: setHTML(e, h, d); 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@183: if (/&[\w#]+;/.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@183: } while (n = n.nextSibling); bgneal@45: } bgneal@45: bgneal@45: return v || s; bgneal@45: } bgneal@45: bgneal@45: return s; bgneal@45: }, bgneal@45: bgneal@183: encode : function(str) { bgneal@183: return ('' + str).replace(encodeCharsRe, function(chr) { bgneal@183: return encodedChars[chr]; bgneal@183: }); bgneal@183: }, bgneal@183: bgneal@183: insertAfter : function(node, reference_node) { bgneal@183: reference_node = this.get(reference_node); bgneal@183: bgneal@183: return this.run(node, function(node) { bgneal@183: var parent, nextSibling; bgneal@183: bgneal@183: parent = reference_node.parentNode; bgneal@183: nextSibling = reference_node.nextSibling; bgneal@183: bgneal@183: if (nextSibling) bgneal@183: parent.insertBefore(node, nextSibling); bgneal@45: else bgneal@183: parent.appendChild(node); bgneal@183: bgneal@183: return node; bgneal@183: }); bgneal@183: }, 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@183: return blockRe.test(n); bgneal@183: }, 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@183: each(tinymce.grep(o.childNodes), function(c) { bgneal@183: n.appendChild(c); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: return o.parentNode.replaceChild(n, o); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@183: rename : function(elm, name) { bgneal@183: var t = this, newElm; bgneal@183: bgneal@183: if (elm.nodeName != name.toUpperCase()) { bgneal@183: // Rename block element bgneal@183: newElm = t.create(name); bgneal@183: bgneal@183: // Copy attribs to new block bgneal@183: each(t.getAttribs(elm), function(attr_node) { bgneal@183: t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName)); bgneal@183: }); bgneal@183: bgneal@183: // Replace block bgneal@183: t.replace(newElm, elm, 1); bgneal@183: } bgneal@183: bgneal@183: return newElm || elm; bgneal@183: }, 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@183: // IE doesn't keep the selected attribute if you clone option elements bgneal@183: if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected')) bgneal@183: o.push({specified : 1, nodeName : 'selected'}); bgneal@183: bgneal@45: // It's crazy that this is faster in IE but it's because it returns all attributes all the time bgneal@183: n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) { bgneal@183: o.push({specified : 1, nodeName : a}); bgneal@45: }); bgneal@45: bgneal@45: return o; bgneal@45: } bgneal@45: bgneal@45: return n.attributes; bgneal@45: }, bgneal@45: bgneal@45: destroy : function(s) { bgneal@45: var t = this; bgneal@45: bgneal@183: if (t.events) bgneal@183: t.events.destroy(); bgneal@183: bgneal@183: t.win = t.doc = t.root = t.events = 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@183: nodeIndex : function(node, normalized) { bgneal@183: var idx = 0, lastNodeType, lastNode, nodeType; bgneal@183: bgneal@183: if (node) { bgneal@183: for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) { bgneal@183: nodeType = node.nodeType; bgneal@183: bgneal@217: // Normalize text nodes bgneal@217: if (normalized && nodeType == 3) { bgneal@217: if (nodeType == lastNodeType || !node.nodeValue.length) bgneal@217: continue; bgneal@217: } bgneal@217: bgneal@217: idx++; bgneal@183: lastNodeType = nodeType; bgneal@183: } bgneal@183: } bgneal@183: bgneal@183: return idx; bgneal@183: }, bgneal@183: bgneal@45: split : function(pe, e, re) { bgneal@45: var t = this, r = t.createRng(), bef, aft, pa; bgneal@45: bgneal@183: // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense bgneal@183: // but we don't want that in our code since it serves no purpose for the end user bgneal@45: // For example if this is chopped: bgneal@45: //

text 1CHOPtext 2

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

text 1

CHOP

text 2

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

text 1

CHOP

text 2

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

"; bgneal@247: bgneal@247: // Safari can't handle uppercase or unicode characters when bgneal@247: // in quirks mode. bgneal@247: if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) { bgneal@247: return; bgneal@247: } bgneal@247: bgneal@247: Sizzle = function(query, context, extra, seed){ bgneal@247: context = context || document; bgneal@247: bgneal@247: // Only use querySelectorAll on non-XML documents bgneal@247: // (ID selectors don't work in non-HTML documents) bgneal@247: if ( !seed && context.nodeType === 9 && !Sizzle.isXML(context) ) { bgneal@247: try { bgneal@247: return makeArray( context.querySelectorAll(query), extra ); bgneal@247: } catch(e){} bgneal@247: } bgneal@247: bgneal@247: return oldSizzle(query, context, extra, seed); bgneal@247: }; bgneal@247: bgneal@247: for ( var prop in oldSizzle ) { bgneal@247: Sizzle[ prop ] = oldSizzle[ prop ]; bgneal@247: } bgneal@247: bgneal@247: div = null; // release memory in IE bgneal@247: })(); bgneal@247: } bgneal@247: bgneal@247: (function(){ bgneal@247: var div = document.createElement("div"); bgneal@247: bgneal@247: div.innerHTML = "
"; bgneal@247: bgneal@247: // Opera can't find a second classname (in 9.6) bgneal@247: // Also, make sure that getElementsByClassName actually exists bgneal@247: if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) { bgneal@247: return; bgneal@247: } bgneal@247: bgneal@247: // Safari caches class attributes, doesn't catch changes (in 3.2) bgneal@247: div.lastChild.className = "e"; bgneal@247: bgneal@247: if ( div.getElementsByClassName("e").length === 1 ) { bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: Expr.order.splice(1, 0, "CLASS"); bgneal@45: Expr.find.CLASS = function(match, context, isXML) { bgneal@45: if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) { bgneal@45: return context.getElementsByClassName(match[1]); bgneal@45: } bgneal@45: }; bgneal@247: bgneal@247: div = null; // release memory in IE bgneal@45: })(); bgneal@45: bgneal@45: function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { bgneal@45: for ( var i = 0, l = checkSet.length; i < l; i++ ) { bgneal@45: var elem = checkSet[i]; bgneal@45: if ( elem ) { bgneal@45: elem = elem[dir]; bgneal@45: var match = false; bgneal@45: bgneal@45: while ( elem ) { bgneal@45: if ( elem.sizcache === doneName ) { bgneal@45: match = checkSet[elem.sizset]; bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: if ( elem.nodeType === 1 && !isXML ){ bgneal@45: elem.sizcache = doneName; bgneal@45: elem.sizset = i; bgneal@45: } bgneal@45: bgneal@247: if ( elem.nodeName.toLowerCase() === cur ) { bgneal@45: match = elem; bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: elem = elem[dir]; bgneal@45: } bgneal@45: bgneal@45: checkSet[i] = match; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { bgneal@45: for ( var i = 0, l = checkSet.length; i < l; i++ ) { bgneal@45: var elem = checkSet[i]; bgneal@45: if ( elem ) { bgneal@45: elem = elem[dir]; bgneal@45: var match = false; bgneal@45: bgneal@45: while ( elem ) { bgneal@45: if ( elem.sizcache === doneName ) { bgneal@45: match = checkSet[elem.sizset]; bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: if ( elem.nodeType === 1 ) { bgneal@45: if ( !isXML ) { bgneal@45: elem.sizcache = doneName; bgneal@45: elem.sizset = i; bgneal@45: } bgneal@45: if ( typeof cur !== "string" ) { bgneal@45: if ( elem === cur ) { bgneal@45: match = true; bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) { bgneal@45: match = elem; bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: elem = elem[dir]; bgneal@45: } bgneal@45: bgneal@45: checkSet[i] = match; bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@247: Sizzle.contains = document.compareDocumentPosition ? function(a, b){ bgneal@247: 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@247: Sizzle.isXML = function(elem){ bgneal@247: // documentElement is verified for cases where it doesn't yet exist bgneal@247: // (such as loading iframes in IE - #4833) bgneal@247: var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement; bgneal@247: return documentElement ? documentElement.nodeName !== "HTML" : false; bgneal@45: }; bgneal@45: bgneal@45: var posProcess = function(selector, context){ bgneal@45: var tmpSet = [], later = "", match, bgneal@45: root = context.nodeType ? [context] : context; bgneal@45: bgneal@45: // Position selectors must be done after the filter bgneal@45: // And so must :not(positional) so we move all PSEUDOs to the end bgneal@45: while ( (match = Expr.match.PSEUDO.exec( selector )) ) { bgneal@45: later += match[0]; bgneal@45: selector = selector.replace( Expr.match.PSEUDO, "" ); bgneal@45: } bgneal@45: bgneal@45: selector = Expr.relative[selector] ? selector + "*" : selector; bgneal@45: bgneal@45: for ( var i = 0, l = root.length; i < l; i++ ) { bgneal@45: Sizzle( selector, root[i], tmpSet ); bgneal@45: } bgneal@45: bgneal@45: return Sizzle.filter( later, tmpSet ); bgneal@45: }; bgneal@45: bgneal@45: // EXPOSE bgneal@45: bgneal@45: window.tinymce.dom.Sizzle = Sizzle; bgneal@45: bgneal@45: })(); bgneal@183: bgneal@183: 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@183: tinymce.create('tinymce.dom.EventUtils', { bgneal@183: EventUtils : function() { bgneal@183: this.inits = []; bgneal@183: this.events = []; bgneal@183: }, bgneal@45: bgneal@45: add : function(o, n, f, s) { bgneal@45: var cb, t = this, el = t.events, r; bgneal@45: bgneal@183: if (n instanceof Array) { bgneal@183: r = []; bgneal@183: bgneal@183: each(n, function(n) { bgneal@183: r.push(t.add(o, n, f, s)); bgneal@183: }); bgneal@183: bgneal@183: return r; bgneal@183: } bgneal@183: 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@183: // Is all events disabled bgneal@183: if (t.disabled) bgneal@183: return; bgneal@183: bgneal@45: e = e || window.event; bgneal@45: bgneal@183: // Patch in target, preventDefault and stopPropagation in IE it's W3C valid bgneal@183: if (e && isIE) { bgneal@183: if (!e.target) bgneal@183: e.target = e.srcElement; bgneal@183: bgneal@183: // Patch in preventDefault, stopPropagation methods for W3C compatibility bgneal@183: tinymce.extend(e, t._stoppers); bgneal@183: } 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: cancel : function(e) { bgneal@45: if (!e) bgneal@45: return false; bgneal@45: bgneal@45: this.stop(e); bgneal@183: 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@183: destroy : function() { bgneal@183: var t = this; 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@183: _pageInit : function(win) { bgneal@183: var t = this; bgneal@183: bgneal@183: // Keep it from running more than once bgneal@183: if (t.domLoaded) bgneal@45: return; bgneal@45: bgneal@183: t.domLoaded = true; bgneal@183: bgneal@183: each(t.inits, function(c) { bgneal@45: c(); bgneal@45: }); bgneal@45: bgneal@183: t.inits = []; bgneal@183: }, bgneal@183: bgneal@183: _wait : function(win) { bgneal@183: var t = this, doc = win.document; bgneal@45: bgneal@45: // No need since the document is already loaded bgneal@183: if (win.tinyMCE_GZ && tinyMCE_GZ.loaded) { bgneal@183: t.domLoaded = 1; bgneal@45: return; bgneal@45: } bgneal@45: bgneal@183: // Use IE method bgneal@183: if (doc.attachEvent) { bgneal@183: doc.attachEvent("onreadystatechange", function() { bgneal@183: if (doc.readyState === "complete") { bgneal@183: doc.detachEvent("onreadystatechange", arguments.callee); bgneal@183: t._pageInit(win); bgneal@183: } bgneal@183: }); bgneal@183: bgneal@183: if (doc.documentElement.doScroll && win == win.top) { bgneal@183: (function() { bgneal@183: if (t.domLoaded) bgneal@183: return; bgneal@183: bgneal@183: try { bgneal@183: // If IE is used, use the trick by Diego Perini bgneal@183: // http://javascript.nwbox.com/IEContentLoaded/ bgneal@183: doc.documentElement.doScroll("left"); bgneal@183: } catch (ex) { bgneal@183: setTimeout(arguments.callee, 0); bgneal@183: return; bgneal@183: } bgneal@183: bgneal@183: t._pageInit(win); bgneal@183: })(); bgneal@183: } bgneal@183: } else if (doc.addEventListener) { bgneal@183: t._add(win, 'DOMContentLoaded', function() { bgneal@183: t._pageInit(win); bgneal@183: }); bgneal@183: } bgneal@183: bgneal@183: t._add(win, 'load', function() { bgneal@183: t._pageInit(win); bgneal@183: }); bgneal@183: }, bgneal@183: bgneal@183: _stoppers : { bgneal@183: preventDefault : function() { bgneal@183: this.returnValue = false; bgneal@183: }, bgneal@183: bgneal@183: stopPropagation : function() { bgneal@183: this.cancelBubble = true; bgneal@45: } bgneal@45: } bgneal@183: }); bgneal@183: bgneal@183: Event = tinymce.dom.Event = new tinymce.dom.EventUtils(); bgneal@45: bgneal@45: // Dispatch DOM content loaded event for IE and Safari bgneal@183: Event._wait(window); bgneal@183: bgneal@183: tinymce.addUnload(function() { bgneal@183: Event.destroy(); bgneal@183: }); bgneal@45: })(tinymce); bgneal@183: bgneal@45: (function(tinymce) { bgneal@183: tinymce.dom.Element = function(id, settings) { bgneal@183: var t = this, dom, el; bgneal@183: bgneal@183: t.settings = settings = settings || {}; bgneal@183: t.id = id; bgneal@183: t.dom = dom = settings.dom || tinymce.DOM; bgneal@183: bgneal@183: // Only IE leaks DOM references, this is a lot faster bgneal@183: if (!tinymce.isIE) bgneal@183: el = dom.get(t.id); bgneal@183: bgneal@183: tinymce.each( bgneal@183: ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' + bgneal@183: 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' + bgneal@183: 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' + bgneal@183: 'isHidden,setHTML,get').split(/,/) bgneal@183: , function(k) { bgneal@45: t[k] = function() { bgneal@45: var a = [id], i; bgneal@45: bgneal@45: for (i = 0; i < arguments.length; i++) bgneal@45: a.push(arguments[i]); bgneal@45: bgneal@45: a = dom[k].apply(dom, a); bgneal@45: t.update(k); bgneal@45: bgneal@45: return a; bgneal@45: }; bgneal@45: }); bgneal@183: bgneal@183: tinymce.extend(t, { bgneal@183: on : function(n, f, s) { bgneal@183: return tinymce.dom.Event.add(t.id, n, f, s); bgneal@183: }, bgneal@183: bgneal@183: getXY : function() { bgneal@183: return { bgneal@183: x : parseInt(t.getStyle('left')), bgneal@183: y : parseInt(t.getStyle('top')) bgneal@183: }; bgneal@183: }, bgneal@183: bgneal@183: getSize : function() { bgneal@183: var n = dom.get(t.id); bgneal@183: bgneal@183: return { bgneal@183: w : parseInt(t.getStyle('width') || n.clientWidth), bgneal@183: h : parseInt(t.getStyle('height') || n.clientHeight) bgneal@183: }; bgneal@183: }, bgneal@183: bgneal@183: moveTo : function(x, y) { bgneal@183: t.setStyles({left : x, top : y}); bgneal@183: }, bgneal@183: bgneal@183: moveBy : function(x, y) { bgneal@183: var p = t.getXY(); bgneal@183: bgneal@183: t.moveTo(p.x + x, p.y + y); bgneal@183: }, bgneal@183: bgneal@183: resizeTo : function(w, h) { bgneal@183: t.setStyles({width : w, height : h}); bgneal@183: }, bgneal@183: bgneal@183: resizeBy : function(w, h) { bgneal@183: var s = t.getSize(); bgneal@183: bgneal@183: t.resizeTo(s.w + w, s.h + h); bgneal@183: }, bgneal@183: bgneal@183: update : function(k) { bgneal@183: var b; bgneal@183: bgneal@183: if (tinymce.isIE6 && settings.blocker) { bgneal@183: k = k || ''; bgneal@183: bgneal@183: // Ignore getters bgneal@183: if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0) bgneal@183: return; bgneal@183: bgneal@183: // Remove blocker on remove bgneal@183: if (k == 'remove') { bgneal@183: dom.remove(t.blocker); bgneal@183: return; bgneal@183: } bgneal@183: bgneal@183: if (!t.blocker) { bgneal@183: t.blocker = dom.uniqueId(); bgneal@183: b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'}); bgneal@183: dom.setStyle(b, 'opacity', 0); bgneal@183: } else bgneal@183: b = dom.get(t.blocker); bgneal@183: bgneal@183: dom.setStyles(b, { bgneal@183: left : t.getStyle('left', 1), bgneal@183: top : t.getStyle('top', 1), bgneal@183: width : t.getStyle('width', 1), bgneal@183: height : t.getStyle('height', 1), bgneal@183: display : t.getStyle('display', 1), bgneal@183: zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1 bgneal@183: }); bgneal@183: } bgneal@183: } bgneal@183: }); bgneal@183: }; bgneal@45: })(tinymce); bgneal@183: bgneal@45: (function(tinymce) { bgneal@45: function trimNl(s) { bgneal@45: return s.replace(/[\n\r]+/g, ''); bgneal@45: }; bgneal@45: bgneal@45: // Shorten names bgneal@45: var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each; bgneal@45: bgneal@45: tinymce.create('tinymce.dom.Selection', { bgneal@45: Selection : function(dom, win, serializer) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.dom = dom; bgneal@45: t.win = win; bgneal@45: t.serializer = serializer; bgneal@45: bgneal@45: // Add events bgneal@45: each([ bgneal@45: 'onBeforeSetContent', bgneal@45: 'onBeforeGetContent', bgneal@45: 'onSetContent', bgneal@45: 'onGetContent' bgneal@45: ], function(e) { bgneal@45: t[e] = new tinymce.util.Dispatcher(t); bgneal@45: }); bgneal@45: bgneal@45: // No W3C Range support bgneal@45: if (!t.win.getSelection) bgneal@45: t.tridentSel = new tinymce.dom.TridentSelection(t); bgneal@45: bgneal@45: // Prevent leaks bgneal@45: tinymce.addUnload(t.destroy, t); bgneal@45: }, bgneal@45: bgneal@45: getContent : function(s) { bgneal@45: var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n; bgneal@45: bgneal@45: s = s || {}; bgneal@45: wb = wa = ''; bgneal@45: s.get = true; bgneal@45: s.format = s.format || 'html'; bgneal@45: t.onBeforeGetContent.dispatch(t, s); bgneal@45: bgneal@45: if (s.format == 'text') bgneal@45: return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : '')); bgneal@45: bgneal@45: if (r.cloneContents) { bgneal@45: n = r.cloneContents(); bgneal@45: bgneal@45: if (n) bgneal@45: e.appendChild(n); bgneal@45: } else if (is(r.item) || is(r.htmlText)) bgneal@45: e.innerHTML = r.item ? r.item(0).outerHTML : r.htmlText; bgneal@45: else bgneal@45: e.innerHTML = r.toString(); bgneal@45: bgneal@45: // Keep whitespace before and after bgneal@45: if (/^\s/.test(e.innerHTML)) bgneal@45: wb = ' '; bgneal@45: bgneal@45: if (/\s+$/.test(e.innerHTML)) bgneal@45: wa = ' '; bgneal@45: bgneal@45: s.getInner = true; bgneal@45: bgneal@45: s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa; bgneal@45: t.onGetContent.dispatch(t, s); bgneal@45: bgneal@45: return s.content; bgneal@45: }, bgneal@45: bgneal@45: setContent : function(h, s) { bgneal@45: var t = this, r = t.getRng(), c, d = t.win.document; bgneal@45: bgneal@45: s = s || {format : 'html'}; bgneal@45: s.set = true; bgneal@45: h = s.content = t.dom.processHTML(h); bgneal@45: bgneal@45: // Dispatch before set content event bgneal@45: t.onBeforeSetContent.dispatch(t, s); bgneal@45: h = s.content; bgneal@45: bgneal@45: if (r.insertNode) { bgneal@45: // Make caret marker since insertNode places the caret in the beginning of text after insert bgneal@45: h += '_'; bgneal@45: bgneal@45: // Delete and insert new node bgneal@217: bgneal@217: if (r.startContainer == d && r.endContainer == d) { bgneal@183: // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents bgneal@183: d.body.innerHTML = h; bgneal@183: } else { bgneal@183: r.deleteContents(); bgneal@217: if (d.body.childNodes.length == 0) { bgneal@217: d.body.innerHTML = h; bgneal@217: } else { bgneal@217: r.insertNode(r.createContextualFragment(h)); bgneal@217: } bgneal@183: } bgneal@45: bgneal@45: // Move to caret marker bgneal@45: c = t.dom.get('__caret'); bgneal@45: // Make sure we wrap it compleatly, Opera fails with a simple select call bgneal@45: r = d.createRange(); bgneal@45: r.setStartBefore(c); bgneal@183: r.setEndBefore(c); bgneal@45: t.setRng(r); bgneal@45: bgneal@45: // Remove the caret position bgneal@45: t.dom.remove('__caret'); bgneal@45: } else { bgneal@45: if (r.item) { bgneal@45: // Delete content and get caret text selection bgneal@45: d.execCommand('Delete', false, null); bgneal@45: r = t.getRng(); bgneal@45: } bgneal@45: bgneal@45: r.pasteHTML(h); bgneal@45: } bgneal@45: bgneal@45: // Dispatch set content event bgneal@45: t.onSetContent.dispatch(t, s); bgneal@45: }, bgneal@45: bgneal@45: getStart : function() { bgneal@247: var rng = this.getRng(), startElement, parentElement, checkRng, node; bgneal@247: bgneal@247: if (rng.duplicate || rng.item) { bgneal@247: // Control selection, return first item bgneal@247: if (rng.item) bgneal@247: return rng.item(0); bgneal@247: bgneal@247: // Get start element bgneal@247: checkRng = rng.duplicate(); bgneal@247: checkRng.collapse(1); bgneal@247: startElement = checkRng.parentElement(); bgneal@247: bgneal@247: // Check if range parent is inside the start element, then return the inner parent element bgneal@247: // This will fix issues when a single element is selected, IE would otherwise return the wrong start element bgneal@247: parentElement = node = rng.parentElement(); bgneal@247: while (node = node.parentNode) { bgneal@247: if (node == startElement) { bgneal@247: startElement = parentElement; bgneal@247: break; bgneal@247: } bgneal@247: } bgneal@247: bgneal@247: // If start element is body element try to move to the first child if it exists bgneal@247: if (startElement && startElement.nodeName == 'BODY') bgneal@247: return startElement.firstChild || startElement; bgneal@247: bgneal@247: return startElement; bgneal@45: } else { bgneal@247: startElement = rng.startContainer; bgneal@247: bgneal@247: if (startElement.nodeType == 1 && startElement.hasChildNodes()) bgneal@247: startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)]; bgneal@247: bgneal@247: if (startElement && startElement.nodeType == 3) bgneal@247: return startElement.parentNode; bgneal@247: bgneal@247: return startElement; bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: getEnd : function() { bgneal@183: var t = this, r = t.getRng(), e, eo; bgneal@183: bgneal@183: if (r.duplicate || r.item) { bgneal@45: if (r.item) bgneal@45: return r.item(0); bgneal@45: bgneal@45: r = r.duplicate(); bgneal@45: r.collapse(0); bgneal@45: e = r.parentElement(); bgneal@45: bgneal@45: if (e && e.nodeName == 'BODY') bgneal@183: return e.lastChild || e; bgneal@45: bgneal@45: return e; bgneal@45: } else { bgneal@45: e = r.endContainer; bgneal@183: eo = r.endOffset; bgneal@183: bgneal@183: if (e.nodeType == 1 && e.hasChildNodes()) bgneal@183: e = e.childNodes[eo > 0 ? eo - 1 : eo]; bgneal@183: bgneal@183: if (e && e.nodeType == 3) bgneal@183: return e.parentNode; bgneal@183: bgneal@183: return e; bgneal@183: } bgneal@183: }, bgneal@183: bgneal@183: getBookmark : function(type, normalized) { bgneal@183: var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles; bgneal@183: bgneal@183: function findIndex(name, element) { bgneal@183: var index = 0; bgneal@183: bgneal@183: each(dom.select(name), function(node, i) { bgneal@183: if (node == element) bgneal@183: index = i; bgneal@183: }); bgneal@183: bgneal@183: return index; bgneal@183: }; bgneal@183: bgneal@183: if (type == 2) { bgneal@183: function getLocation() { bgneal@183: var rng = t.getRng(true), root = dom.getRoot(), bookmark = {}; bgneal@183: bgneal@183: function getPoint(rng, start) { bgneal@183: var container = rng[start ? 'startContainer' : 'endContainer'], bgneal@183: offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0; bgneal@183: bgneal@183: if (container.nodeType == 3) { bgneal@183: if (normalized) { bgneal@183: for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling) bgneal@183: offset += node.nodeValue.length; bgneal@183: } bgneal@183: bgneal@183: point.push(offset); bgneal@183: } else { bgneal@183: childNodes = container.childNodes; bgneal@217: bgneal@217: if (offset >= childNodes.length && childNodes.length) { bgneal@183: after = 1; bgneal@217: offset = Math.max(0, childNodes.length - 1); bgneal@183: } bgneal@183: bgneal@183: point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after); bgneal@183: } bgneal@183: bgneal@183: for (; container && container != root; container = container.parentNode) bgneal@183: point.push(t.dom.nodeIndex(container, normalized)); bgneal@183: bgneal@183: return point; bgneal@45: }; bgneal@183: bgneal@183: bookmark.start = getPoint(rng, true); bgneal@183: bgneal@183: if (!t.isCollapsed()) bgneal@183: bookmark.end = getPoint(rng); bgneal@183: bgneal@183: return bookmark; bgneal@183: }; bgneal@183: bgneal@183: return getLocation(); bgneal@183: } bgneal@183: bgneal@183: // Handle simple range bgneal@183: if (type) bgneal@183: return {rng : t.getRng()}; bgneal@183: bgneal@183: rng = t.getRng(); bgneal@183: id = dom.uniqueId(); bgneal@183: collapsed = tinyMCE.activeEditor.selection.isCollapsed(); bgneal@183: styles = 'overflow:hidden;line-height:0px'; bgneal@183: bgneal@183: // Explorer method bgneal@183: if (rng.duplicate || rng.item) { bgneal@45: // Text selection bgneal@183: if (!rng.item) { bgneal@183: rng2 = rng.duplicate(); bgneal@183: bgneal@183: // Insert start marker bgneal@183: rng.collapse(); bgneal@183: rng.pasteHTML('' + chr + ''); bgneal@183: bgneal@183: // Insert end marker bgneal@183: if (!collapsed) { bgneal@183: rng2.collapse(false); bgneal@183: rng2.pasteHTML('' + chr + ''); bgneal@183: } bgneal@183: } else { bgneal@183: // Control selection bgneal@183: element = rng.item(0); bgneal@183: name = element.nodeName; bgneal@183: bgneal@183: return {name : name, index : findIndex(name, element)}; bgneal@183: } bgneal@183: } else { bgneal@183: element = t.getNode(); bgneal@183: name = element.nodeName; bgneal@183: if (name == 'IMG') bgneal@183: return {name : name, index : findIndex(name, element)}; bgneal@183: bgneal@183: // W3C method bgneal@183: rng2 = rng.cloneRange(); bgneal@183: bgneal@183: // Insert end marker bgneal@183: if (!collapsed) { bgneal@183: rng2.collapse(false); bgneal@183: rng2.insertNode(dom.create('span', {_mce_type : "bookmark", id : id + '_end', style : styles}, chr)); bgneal@183: } bgneal@183: bgneal@183: rng.collapse(true); bgneal@183: rng.insertNode(dom.create('span', {_mce_type : "bookmark", id : id + '_start', style : styles}, chr)); bgneal@183: } bgneal@183: bgneal@183: t.moveToBookmark({id : id, keep : 1}); bgneal@183: bgneal@183: return {id : id}; bgneal@183: }, bgneal@183: bgneal@183: moveToBookmark : function(bookmark) { bgneal@217: var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset; bgneal@183: bgneal@183: // Clear selection cache bgneal@183: if (t.tridentSel) bgneal@183: t.tridentSel.destroy(); bgneal@183: bgneal@183: if (bookmark) { bgneal@183: if (bookmark.start) { bgneal@183: rng = dom.createRng(); bgneal@183: root = dom.getRoot(); bgneal@183: bgneal@183: function setEndPoint(start) { bgneal@247: var point = bookmark[start ? 'start' : 'end'], i, node, offset, children; bgneal@183: bgneal@183: if (point) { bgneal@183: // Find container node bgneal@247: for (node = root, i = point.length - 1; i >= 1; i--) { bgneal@247: children = node.childNodes; bgneal@247: bgneal@247: if (children.length) bgneal@247: node = children[point[i]]; bgneal@247: } bgneal@183: bgneal@183: // Set offset within container node bgneal@183: if (start) bgneal@183: rng.setStart(node, point[0]); bgneal@183: else bgneal@183: rng.setEnd(node, point[0]); bgneal@183: } bgneal@183: }; bgneal@183: bgneal@183: setEndPoint(true); bgneal@183: setEndPoint(); bgneal@183: bgneal@183: t.setRng(rng); bgneal@183: } else if (bookmark.id) { bgneal@183: function restoreEndPoint(suffix) { bgneal@183: var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep; bgneal@183: bgneal@183: if (marker) { bgneal@183: node = marker.parentNode; bgneal@183: bgneal@183: if (suffix == 'start') { bgneal@183: if (!keep) { bgneal@183: idx = dom.nodeIndex(marker); bgneal@183: } else { bgneal@247: node = marker.firstChild; bgneal@183: idx = 1; bgneal@183: } bgneal@183: bgneal@217: startContainer = endContainer = node; bgneal@217: startOffset = endOffset = idx; bgneal@183: } else { bgneal@183: if (!keep) { bgneal@183: idx = dom.nodeIndex(marker); bgneal@183: } else { bgneal@247: node = marker.firstChild; bgneal@183: idx = 1; bgneal@183: } bgneal@183: bgneal@217: endContainer = node; bgneal@217: endOffset = idx; bgneal@183: } bgneal@183: bgneal@183: if (!keep) { bgneal@183: prev = marker.previousSibling; bgneal@183: next = marker.nextSibling; bgneal@183: bgneal@183: // Remove all marker text nodes bgneal@183: each(tinymce.grep(marker.childNodes), function(node) { bgneal@183: if (node.nodeType == 3) bgneal@183: node.nodeValue = node.nodeValue.replace(/\uFEFF/g, ''); bgneal@183: }); bgneal@183: bgneal@183: // Remove marker but keep children if for example contents where inserted into the marker bgneal@183: // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature bgneal@183: while (marker = dom.get(bookmark.id + '_' + suffix)) bgneal@183: dom.remove(marker, 1); bgneal@183: bgneal@183: // If siblings are text nodes then merge them bgneal@183: if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3) { bgneal@183: idx = prev.nodeValue.length; bgneal@183: prev.appendData(next.nodeValue); bgneal@183: dom.remove(next); bgneal@183: bgneal@183: if (suffix == 'start') { bgneal@217: startContainer = endContainer = prev; bgneal@217: startOffset = endOffset = idx; bgneal@217: } else { bgneal@217: endContainer = prev; bgneal@217: endOffset = idx; bgneal@217: } bgneal@183: } bgneal@183: } bgneal@183: } bgneal@183: }; bgneal@183: bgneal@247: function addBogus(node) { bgneal@247: // Adds a bogus BR element for empty block elements bgneal@247: // on non IE browsers just to have a place to put the caret bgneal@247: if (!isIE && dom.isBlock(node) && !node.innerHTML) bgneal@247: node.innerHTML = '
'; bgneal@247: bgneal@247: return node; bgneal@247: }; bgneal@247: bgneal@183: // Restore start/end points bgneal@183: restoreEndPoint('start'); bgneal@183: restoreEndPoint('end'); bgneal@183: bgneal@247: if (startContainer) { bgneal@247: rng = dom.createRng(); bgneal@247: rng.setStart(addBogus(startContainer), startOffset); bgneal@247: rng.setEnd(addBogus(endContainer), endOffset); bgneal@247: t.setRng(rng); bgneal@247: } bgneal@183: } else if (bookmark.name) { bgneal@183: t.select(dom.select(bookmark.name)[bookmark.index]); bgneal@183: } else if (bookmark.rng) bgneal@183: t.setRng(bookmark.rng); bgneal@183: } bgneal@183: }, bgneal@183: bgneal@183: select : function(node, content) { bgneal@183: var t = this, dom = t.dom, rng = dom.createRng(), idx; bgneal@183: bgneal@183: idx = dom.nodeIndex(node); bgneal@183: rng.setStart(node.parentNode, idx); bgneal@183: rng.setEnd(node.parentNode, idx + 1); bgneal@183: bgneal@183: // Find first/last text node or BR element bgneal@183: if (content) { bgneal@183: function setPoint(node, start) { bgneal@183: var walker = new tinymce.dom.TreeWalker(node, node); bgneal@183: bgneal@183: do { bgneal@183: // Text node bgneal@183: if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) { bgneal@183: if (start) bgneal@183: rng.setStart(node, 0); bgneal@183: else bgneal@183: rng.setEnd(node, node.nodeValue.length); bgneal@183: bgneal@183: return; bgneal@183: } bgneal@183: bgneal@183: // BR element bgneal@183: if (node.nodeName == 'BR') { bgneal@183: if (start) bgneal@183: rng.setStartBefore(node); bgneal@183: else bgneal@183: rng.setEndBefore(node); bgneal@183: bgneal@183: return; bgneal@183: } bgneal@183: } while (node = (start ? walker.next() : walker.prev())); bgneal@45: }; bgneal@183: bgneal@183: setPoint(node, 1); bgneal@183: setPoint(node); bgneal@183: } bgneal@183: bgneal@183: t.setRng(rng); bgneal@183: bgneal@183: return node; bgneal@45: }, bgneal@45: bgneal@45: isCollapsed : function() { bgneal@45: var t = this, r = t.getRng(), s = t.getSel(); bgneal@45: bgneal@45: if (!r || r.item) bgneal@45: return false; bgneal@45: bgneal@183: if (r.compareEndPoints) bgneal@183: return r.compareEndPoints('StartToEnd', r) === 0; bgneal@183: bgneal@183: return !s || r.collapsed; bgneal@45: }, bgneal@45: bgneal@45: collapse : function(b) { bgneal@45: var t = this, r = t.getRng(), n; bgneal@45: bgneal@45: // Control range on IE bgneal@45: if (r.item) { bgneal@45: n = r.item(0); bgneal@45: r = this.win.document.body.createTextRange(); bgneal@45: r.moveToElementText(n); bgneal@45: } bgneal@45: bgneal@45: r.collapse(!!b); bgneal@45: t.setRng(r); bgneal@45: }, bgneal@45: bgneal@45: getSel : function() { bgneal@45: var t = this, w = this.win; bgneal@45: bgneal@45: return w.getSelection ? w.getSelection() : w.document.selection; bgneal@45: }, bgneal@45: bgneal@45: getRng : function(w3c) { bgneal@45: var t = this, s, r; bgneal@45: bgneal@45: // Found tridentSel object then we need to use that one bgneal@45: if (w3c && t.tridentSel) bgneal@45: return t.tridentSel.getRangeAt(0); bgneal@45: bgneal@45: try { bgneal@45: if (s = t.getSel()) bgneal@45: r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : t.win.document.createRange()); bgneal@45: } catch (ex) { bgneal@45: // IE throws unspecified error here if TinyMCE is placed in a frame/iframe bgneal@45: } bgneal@45: bgneal@45: // No range found then create an empty one bgneal@45: // This can occur when the editor is placed in a hidden container element on Gecko bgneal@45: // Or on IE when there was an exception bgneal@45: if (!r) bgneal@183: r = t.win.document.createRange ? t.win.document.createRange() : t.win.document.body.createTextRange(); bgneal@45: bgneal@217: if (t.selectedRange && t.explicitRange) { bgneal@217: if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) { bgneal@217: // Safari, Opera and Chrome only ever select text which causes the range to change. bgneal@217: // This lets us use the originally set range if the selection hasn't been changed by the user. bgneal@217: r = t.explicitRange; bgneal@217: } else { bgneal@217: t.selectedRange = null; bgneal@217: t.explicitRange = null; bgneal@217: } bgneal@217: } bgneal@45: return r; bgneal@45: }, bgneal@45: bgneal@45: setRng : function(r) { bgneal@45: var s, t = this; bgneal@217: bgneal@45: if (!t.tridentSel) { bgneal@45: s = t.getSel(); bgneal@45: bgneal@45: if (s) { bgneal@217: t.explicitRange = r; bgneal@45: s.removeAllRanges(); bgneal@45: s.addRange(r); bgneal@217: t.selectedRange = s.getRangeAt(0); bgneal@45: } bgneal@45: } else { bgneal@45: // Is W3C Range bgneal@45: if (r.cloneRange) { bgneal@45: t.tridentSel.addRange(r); bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Is IE specific range bgneal@45: try { bgneal@45: r.select(); bgneal@45: } catch (ex) { bgneal@45: // Needed for some odd IE bug #1843306 bgneal@45: } bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: setNode : function(n) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.setContent(t.dom.getOuterHTML(n)); bgneal@45: bgneal@45: return n; bgneal@45: }, bgneal@45: bgneal@45: getNode : function() { bgneal@183: var t = this, rng = t.getRng(), sel = t.getSel(), elm; bgneal@183: bgneal@183: if (rng.setStart) { bgneal@45: // Range maybe lost after the editor is made visible again bgneal@183: if (!rng) bgneal@45: return t.dom.getRoot(); bgneal@45: bgneal@183: elm = rng.commonAncestorContainer; bgneal@45: bgneal@45: // Handle selection a image or other control like element such as anchors bgneal@183: if (!rng.collapsed) { bgneal@183: if (rng.startContainer == rng.endContainer) { bgneal@183: if (rng.startOffset - rng.endOffset < 2) { bgneal@183: if (rng.startContainer.hasChildNodes()) bgneal@183: elm = rng.startContainer.childNodes[rng.startOffset]; bgneal@183: } bgneal@183: } bgneal@183: bgneal@45: // If the anchor node is a element instead of a text node then return this element bgneal@183: if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1) bgneal@183: return sel.anchorNode.childNodes[sel.anchorOffset]; bgneal@183: } bgneal@183: bgneal@183: if (elm && elm.nodeType == 3) bgneal@183: return elm.parentNode; bgneal@183: bgneal@183: return elm; bgneal@183: } bgneal@183: bgneal@183: return rng.item ? rng.item(0) : rng.parentElement(); bgneal@45: }, bgneal@45: bgneal@45: getSelectedBlocks : function(st, en) { bgneal@45: var t = this, dom = t.dom, sb, eb, n, bl = []; bgneal@45: bgneal@45: sb = dom.getParent(st || t.getStart(), dom.isBlock); bgneal@45: eb = dom.getParent(en || t.getEnd(), dom.isBlock); bgneal@45: bgneal@45: if (sb) bgneal@45: bl.push(sb); bgneal@45: bgneal@45: if (sb && eb && sb != eb) { bgneal@45: n = sb; bgneal@45: bgneal@45: while ((n = n.nextSibling) && n != eb) { bgneal@45: if (dom.isBlock(n)) bgneal@45: bl.push(n); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: if (eb && sb != eb) bgneal@45: bl.push(eb); bgneal@45: bgneal@45: return bl; bgneal@45: }, bgneal@45: bgneal@45: destroy : function(s) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.win = null; bgneal@45: bgneal@183: if (t.tridentSel) bgneal@183: t.tridentSel.destroy(); bgneal@183: bgneal@45: // Manual destroy then remove unload handler bgneal@45: if (!s) bgneal@45: tinymce.removeUnload(t.destroy); bgneal@45: } bgneal@183: }); bgneal@45: })(tinymce); bgneal@183: bgneal@45: (function(tinymce) { bgneal@45: tinymce.create('tinymce.dom.XMLWriter', { bgneal@45: node : null, bgneal@45: bgneal@45: XMLWriter : function(s) { bgneal@45: // Get XML document bgneal@45: function getXML() { bgneal@45: var i = document.implementation; bgneal@45: bgneal@45: if (!i || !i.createDocument) { bgneal@45: // Try IE objects bgneal@45: try {return new ActiveXObject('MSXML2.DOMDocument');} catch (ex) {} bgneal@45: try {return new ActiveXObject('Microsoft.XmlDom');} catch (ex) {} bgneal@45: } else bgneal@45: return i.createDocument('', '', null); bgneal@45: }; bgneal@45: bgneal@45: this.doc = getXML(); bgneal@45: bgneal@45: // Since Opera and WebKit doesn't escape > into > we need to do it our self to normalize the output for all browsers bgneal@45: this.valid = tinymce.isOpera || tinymce.isWebKit; bgneal@45: bgneal@45: this.reset(); bgneal@45: }, bgneal@45: bgneal@45: reset : function() { bgneal@45: var t = this, d = t.doc; bgneal@45: bgneal@45: if (d.firstChild) bgneal@45: d.removeChild(d.firstChild); bgneal@45: bgneal@45: t.node = d.appendChild(d.createElement("html")); bgneal@45: }, bgneal@45: bgneal@45: writeStartElement : function(n) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.node = t.node.appendChild(t.doc.createElement(n)); bgneal@45: }, bgneal@45: bgneal@45: writeAttribute : function(n, v) { bgneal@45: if (this.valid) bgneal@45: v = v.replace(/>/g, '%MCGT%'); bgneal@45: bgneal@45: this.node.setAttribute(n, v); bgneal@45: }, bgneal@45: bgneal@45: writeEndElement : function() { bgneal@45: this.node = this.node.parentNode; bgneal@45: }, bgneal@45: bgneal@45: writeFullEndElement : function() { bgneal@45: var t = this, n = t.node; bgneal@45: bgneal@45: n.appendChild(t.doc.createTextNode("")); bgneal@45: t.node = n.parentNode; bgneal@45: }, bgneal@45: bgneal@45: writeText : function(v) { bgneal@45: if (this.valid) bgneal@45: v = v.replace(/>/g, '%MCGT%'); bgneal@45: bgneal@45: this.node.appendChild(this.doc.createTextNode(v)); bgneal@45: }, bgneal@45: bgneal@45: writeCDATA : function(v) { bgneal@183: this.node.appendChild(this.doc.createCDATASection(v)); bgneal@45: }, bgneal@45: bgneal@45: writeComment : function(v) { bgneal@45: // Fix for bug #2035694 bgneal@45: if (tinymce.isIE) bgneal@45: v = v.replace(/^\-|\-$/g, ' '); bgneal@45: bgneal@45: this.node.appendChild(this.doc.createComment(v.replace(/\-\-/g, ' '))); bgneal@45: }, bgneal@45: bgneal@45: getContent : function() { bgneal@45: var h; bgneal@45: bgneal@45: h = this.doc.xml || new XMLSerializer().serializeToString(this.doc); bgneal@45: h = h.replace(/<\?[^?]+\?>||<\/html>||]+>/g, ''); bgneal@45: h = h.replace(/ ?\/>/g, ' />'); bgneal@45: bgneal@45: if (this.valid) bgneal@45: h = h.replace(/\%MCGT%/g, '>'); bgneal@45: bgneal@45: return h; bgneal@45: } bgneal@183: }); bgneal@45: })(tinymce); bgneal@183: bgneal@45: (function(tinymce) { bgneal@45: tinymce.create('tinymce.dom.StringWriter', { bgneal@45: str : null, bgneal@45: tags : null, bgneal@45: count : 0, bgneal@45: settings : null, bgneal@45: indent : null, bgneal@45: bgneal@45: StringWriter : function(s) { bgneal@45: this.settings = tinymce.extend({ bgneal@45: indent_char : ' ', bgneal@183: indentation : 0 bgneal@45: }, s); bgneal@45: bgneal@45: this.reset(); bgneal@45: }, bgneal@45: bgneal@45: reset : function() { bgneal@45: this.indent = ''; bgneal@45: this.str = ""; bgneal@45: this.tags = []; bgneal@45: this.count = 0; bgneal@45: }, bgneal@45: bgneal@45: writeStartElement : function(n) { bgneal@45: this._writeAttributesEnd(); bgneal@45: this.writeRaw('<' + n); bgneal@45: this.tags.push(n); bgneal@45: this.inAttr = true; bgneal@45: this.count++; bgneal@45: this.elementCount = this.count; bgneal@45: }, bgneal@45: bgneal@45: writeAttribute : function(n, v) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.writeRaw(" " + t.encode(n) + '="' + t.encode(v) + '"'); bgneal@45: }, bgneal@45: bgneal@45: writeEndElement : function() { bgneal@45: var n; bgneal@45: bgneal@45: if (this.tags.length > 0) { bgneal@45: n = this.tags.pop(); bgneal@45: bgneal@45: if (this._writeAttributesEnd(1)) bgneal@45: this.writeRaw(''); bgneal@45: bgneal@45: if (this.settings.indentation > 0) bgneal@45: this.writeRaw('\n'); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: writeFullEndElement : function() { bgneal@45: if (this.tags.length > 0) { bgneal@45: this._writeAttributesEnd(); bgneal@45: this.writeRaw(''); bgneal@45: bgneal@45: if (this.settings.indentation > 0) bgneal@45: this.writeRaw('\n'); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: writeText : function(v) { bgneal@45: this._writeAttributesEnd(); bgneal@45: this.writeRaw(this.encode(v)); bgneal@45: this.count++; bgneal@45: }, bgneal@45: bgneal@45: writeCDATA : function(v) { bgneal@45: this._writeAttributesEnd(); bgneal@45: this.writeRaw(''); bgneal@45: this.count++; bgneal@45: }, bgneal@45: bgneal@45: writeComment : function(v) { bgneal@45: this._writeAttributesEnd(); bgneal@45: this.writeRaw(''); bgneal@45: this.count++; bgneal@45: }, bgneal@45: bgneal@45: writeRaw : function(v) { bgneal@45: this.str += v; bgneal@45: }, bgneal@45: bgneal@45: encode : function(s) { bgneal@45: return s.replace(/[<>&"]/g, function(v) { bgneal@45: switch (v) { 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 v; bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: getContent : function() { bgneal@45: return this.str; bgneal@45: }, bgneal@45: bgneal@45: _writeAttributesEnd : function(s) { bgneal@45: if (!this.inAttr) bgneal@45: return; bgneal@45: bgneal@45: this.inAttr = false; bgneal@45: bgneal@45: if (s && this.elementCount == this.count) { bgneal@45: this.writeRaw(' />'); bgneal@45: return false; bgneal@45: } bgneal@45: bgneal@45: this.writeRaw('>'); bgneal@45: bgneal@45: return true; bgneal@45: } bgneal@183: }); bgneal@45: })(tinymce); bgneal@183: bgneal@45: (function(tinymce) { bgneal@45: // Shorten names bgneal@45: var extend = tinymce.extend, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, isIE = tinymce.isIE, isGecko = tinymce.isGecko; bgneal@45: bgneal@45: function wildcardToRE(s) { bgneal@45: return s.replace(/([?+*])/g, '.$1'); bgneal@45: }; bgneal@45: bgneal@45: tinymce.create('tinymce.dom.Serializer', { bgneal@45: Serializer : function(s) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.key = 0; bgneal@45: t.onPreProcess = new Dispatcher(t); bgneal@45: t.onPostProcess = new Dispatcher(t); bgneal@45: bgneal@45: try { bgneal@45: t.writer = new tinymce.dom.XMLWriter(); bgneal@45: } catch (ex) { bgneal@45: // IE might throw exception if ActiveX is disabled so we then switch to the slightly slower StringWriter bgneal@45: t.writer = new tinymce.dom.StringWriter(); bgneal@45: } bgneal@45: bgneal@45: // Default settings bgneal@45: t.settings = s = extend({ bgneal@45: dom : tinymce.DOM, bgneal@45: valid_nodes : 0, bgneal@45: node_filter : 0, bgneal@45: attr_filter : 0, bgneal@183: invalid_attrs : /^(_mce_|_moz_|sizset|sizcache)/, bgneal@183: closed : /^(br|hr|input|meta|img|link|param|area)$/, bgneal@45: entity_encoding : 'named', bgneal@45: entities : '160,nbsp,161,iexcl,162,cent,163,pound,164,curren,165,yen,166,brvbar,167,sect,168,uml,169,copy,170,ordf,171,laquo,172,not,173,shy,174,reg,175,macr,176,deg,177,plusmn,178,sup2,179,sup3,180,acute,181,micro,182,para,183,middot,184,cedil,185,sup1,186,ordm,187,raquo,188,frac14,189,frac12,190,frac34,191,iquest,192,Agrave,193,Aacute,194,Acirc,195,Atilde,196,Auml,197,Aring,198,AElig,199,Ccedil,200,Egrave,201,Eacute,202,Ecirc,203,Euml,204,Igrave,205,Iacute,206,Icirc,207,Iuml,208,ETH,209,Ntilde,210,Ograve,211,Oacute,212,Ocirc,213,Otilde,214,Ouml,215,times,216,Oslash,217,Ugrave,218,Uacute,219,Ucirc,220,Uuml,221,Yacute,222,THORN,223,szlig,224,agrave,225,aacute,226,acirc,227,atilde,228,auml,229,aring,230,aelig,231,ccedil,232,egrave,233,eacute,234,ecirc,235,euml,236,igrave,237,iacute,238,icirc,239,iuml,240,eth,241,ntilde,242,ograve,243,oacute,244,ocirc,245,otilde,246,ouml,247,divide,248,oslash,249,ugrave,250,uacute,251,ucirc,252,uuml,253,yacute,254,thorn,255,yuml,402,fnof,913,Alpha,914,Beta,915,Gamma,916,Delta,917,Epsilon,918,Zeta,919,Eta,920,Theta,921,Iota,922,Kappa,923,Lambda,924,Mu,925,Nu,926,Xi,927,Omicron,928,Pi,929,Rho,931,Sigma,932,Tau,933,Upsilon,934,Phi,935,Chi,936,Psi,937,Omega,945,alpha,946,beta,947,gamma,948,delta,949,epsilon,950,zeta,951,eta,952,theta,953,iota,954,kappa,955,lambda,956,mu,957,nu,958,xi,959,omicron,960,pi,961,rho,962,sigmaf,963,sigma,964,tau,965,upsilon,966,phi,967,chi,968,psi,969,omega,977,thetasym,978,upsih,982,piv,8226,bull,8230,hellip,8242,prime,8243,Prime,8254,oline,8260,frasl,8472,weierp,8465,image,8476,real,8482,trade,8501,alefsym,8592,larr,8593,uarr,8594,rarr,8595,darr,8596,harr,8629,crarr,8656,lArr,8657,uArr,8658,rArr,8659,dArr,8660,hArr,8704,forall,8706,part,8707,exist,8709,empty,8711,nabla,8712,isin,8713,notin,8715,ni,8719,prod,8721,sum,8722,minus,8727,lowast,8730,radic,8733,prop,8734,infin,8736,ang,8743,and,8744,or,8745,cap,8746,cup,8747,int,8756,there4,8764,sim,8773,cong,8776,asymp,8800,ne,8801,equiv,8804,le,8805,ge,8834,sub,8835,sup,8836,nsub,8838,sube,8839,supe,8853,oplus,8855,otimes,8869,perp,8901,sdot,8968,lceil,8969,rceil,8970,lfloor,8971,rfloor,9001,lang,9002,rang,9674,loz,9824,spades,9827,clubs,9829,hearts,9830,diams,338,OElig,339,oelig,352,Scaron,353,scaron,376,Yuml,710,circ,732,tilde,8194,ensp,8195,emsp,8201,thinsp,8204,zwnj,8205,zwj,8206,lrm,8207,rlm,8211,ndash,8212,mdash,8216,lsquo,8217,rsquo,8218,sbquo,8220,ldquo,8221,rdquo,8222,bdquo,8224,dagger,8225,Dagger,8240,permil,8249,lsaquo,8250,rsaquo,8364,euro', bgneal@45: valid_elements : '*[*]', bgneal@45: extended_valid_elements : 0, bgneal@45: invalid_elements : 0, bgneal@45: fix_table_elements : 1, bgneal@45: fix_list_elements : true, bgneal@45: fix_content_duplication : true, bgneal@45: convert_fonts_to_spans : false, bgneal@45: font_size_classes : 0, bgneal@45: apply_source_formatting : 0, bgneal@45: indent_mode : 'simple', bgneal@45: indent_char : '\t', bgneal@45: indent_levels : 1, bgneal@45: remove_linebreaks : 1, bgneal@45: remove_redundant_brs : 1, bgneal@45: element_format : 'xhtml' bgneal@45: }, s); bgneal@45: bgneal@45: t.dom = s.dom; bgneal@183: t.schema = s.schema; bgneal@183: bgneal@183: // Use raw entities if no entities are defined bgneal@183: if (s.entity_encoding == 'named' && !s.entities) bgneal@183: s.entity_encoding = 'raw'; bgneal@45: bgneal@45: if (s.remove_redundant_brs) { bgneal@45: t.onPostProcess.add(function(se, o) { bgneal@183: // Remove single BR at end of block elements since they get rendered bgneal@183: o.content = o.content.replace(/(
\s*)+<\/(p|h[1-6]|div|li)>/gi, function(a, b, c) { bgneal@183: // Check if it's a single element bgneal@183: if (/^
\s*<\//.test(a)) bgneal@183: return ''; bgneal@183: bgneal@183: return a; bgneal@183: }); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: // Remove XHTML element endings i.e. produce crap :) XHTML is better bgneal@45: if (s.element_format == 'html') { bgneal@45: t.onPostProcess.add(function(se, o) { bgneal@45: o.content = o.content.replace(/<([^>]+) \/>/g, '<$1>'); bgneal@45: }); bgneal@45: } bgneal@45: bgneal@45: if (s.fix_list_elements) { bgneal@45: t.onPreProcess.add(function(se, o) { bgneal@45: var nl, x, a = ['ol', 'ul'], i, n, p, r = /^(OL|UL)$/, np; bgneal@45: bgneal@45: function prevNode(e, n) { bgneal@45: var a = n.split(','), i; bgneal@45: bgneal@45: while ((e = e.previousSibling) != null) { bgneal@45: for (i=0; i= 1767) { bgneal@183: each(t.dom.select('p table', o.node).reverse(), function(n) { bgneal@183: var parent = t.dom.getParent(n.parentNode, 'table,p'); bgneal@183: bgneal@183: if (parent.nodeName != 'TABLE') { bgneal@183: try { bgneal@183: t.dom.split(parent, n); bgneal@183: } catch (ex) { bgneal@183: // IE can sometimes fire an unknown runtime error so we just ignore it bgneal@183: } bgneal@183: } bgneal@183: }); bgneal@183: } bgneal@45: }); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: setEntities : function(s) { bgneal@183: var t = this, a, i, l = {}, v; bgneal@45: bgneal@45: // No need to setup more than once bgneal@45: if (t.entityLookup) bgneal@45: return; bgneal@45: bgneal@45: // Build regex and lookup array bgneal@45: a = s.split(','); bgneal@45: for (i = 0; i < a.length; i += 2) { bgneal@45: v = a[i]; bgneal@45: bgneal@45: // Don't add default & " etc. bgneal@45: if (v == 34 || v == 38 || v == 60 || v == 62) bgneal@45: continue; bgneal@45: bgneal@45: l[String.fromCharCode(a[i])] = a[i + 1]; bgneal@45: bgneal@45: v = parseInt(a[i]).toString(16); bgneal@183: } bgneal@183: bgneal@45: t.entityLookup = l; bgneal@45: }, bgneal@45: bgneal@45: setRules : function(s) { bgneal@45: var t = this; bgneal@45: bgneal@45: t._setup(); bgneal@45: t.rules = {}; bgneal@45: t.wildRules = []; bgneal@45: t.validElements = {}; bgneal@45: bgneal@45: return t.addRules(s); bgneal@45: }, bgneal@45: bgneal@45: addRules : function(s) { bgneal@45: var t = this, dr; bgneal@45: bgneal@45: if (!s) bgneal@45: return; bgneal@45: bgneal@45: t._setup(); bgneal@45: bgneal@45: each(s.split(','), function(s) { bgneal@45: var p = s.split(/\[|\]/), tn = p[0].split('/'), ra, at, wat, va = []; bgneal@45: bgneal@45: // Extend with default rules bgneal@45: if (dr) bgneal@45: at = tinymce.extend([], dr.attribs); bgneal@45: bgneal@45: // Parse attributes bgneal@45: if (p.length > 1) { bgneal@45: each(p[1].split('|'), function(s) { bgneal@45: var ar = {}, i; bgneal@45: bgneal@45: at = at || []; bgneal@45: bgneal@45: // Parse attribute rule bgneal@45: s = s.replace(/::/g, '~'); bgneal@45: s = /^([!\-])?([\w*.?~_\-]+|)([=:<])?(.+)?$/.exec(s); bgneal@45: s[2] = s[2].replace(/~/g, ':'); bgneal@45: bgneal@45: // Add required attributes bgneal@45: if (s[1] == '!') { bgneal@45: ra = ra || []; bgneal@45: ra.push(s[2]); bgneal@45: } bgneal@45: bgneal@45: // Remove inherited attributes bgneal@45: if (s[1] == '-') { bgneal@45: for (i = 0; i = 1767)) { bgneal@183: // Create an empty HTML document bgneal@183: doc = impl.createHTMLDocument(""); bgneal@183: bgneal@183: // Add the element or it's children if it's a body element to the new document bgneal@183: each(n.nodeName == 'BODY' ? n.childNodes : [n], function(node) { bgneal@183: doc.body.appendChild(doc.importNode(node, true)); bgneal@183: }); bgneal@183: bgneal@183: // Grab first child or body element for serialization bgneal@183: if (n.nodeName != 'BODY') bgneal@183: n = doc.body.firstChild; bgneal@183: else bgneal@183: n = doc.body; bgneal@183: bgneal@183: // set the new document in DOMUtils so createElement etc works bgneal@183: oldDoc = t.dom.doc; bgneal@183: t.dom.doc = doc; bgneal@183: } bgneal@183: bgneal@45: t.key = '' + (parseInt(t.key) + 1); bgneal@45: bgneal@45: // Pre process bgneal@45: if (!o.no_events) { bgneal@45: o.node = n; bgneal@45: t.onPreProcess.dispatch(t, o); bgneal@45: } bgneal@45: bgneal@45: // Serialize HTML DOM into a string bgneal@45: t.writer.reset(); bgneal@183: t._info = o; bgneal@45: t._serializeNode(n, o.getInner); bgneal@45: bgneal@45: // Post process bgneal@45: o.content = t.writer.getContent(); bgneal@45: bgneal@183: // Restore the old document if it was changed bgneal@183: if (oldDoc) bgneal@183: t.dom.doc = oldDoc; bgneal@183: bgneal@45: if (!o.no_events) bgneal@45: t.onPostProcess.dispatch(t, o); bgneal@45: bgneal@45: t._postProcess(o); bgneal@45: o.node = null; bgneal@45: bgneal@45: return tinymce.trim(o.content); bgneal@45: }, bgneal@45: bgneal@45: // Internal functions bgneal@45: bgneal@45: _postProcess : function(o) { bgneal@45: var t = this, s = t.settings, h = o.content, sc = [], p; bgneal@45: bgneal@45: if (o.format == 'html') { bgneal@45: // Protect some elements bgneal@45: p = t._protect({ bgneal@45: content : h, bgneal@45: patterns : [ bgneal@45: {pattern : /(]*>)(.*?)(<\/script>)/g}, bgneal@183: {pattern : /(]*>)(.*?)(<\/noscript>)/g}, bgneal@45: {pattern : /(]*>)(.*?)(<\/style>)/g}, bgneal@45: {pattern : /(]*>)(.*?)(<\/pre>)/g, encode : 1}, bgneal@45: {pattern : /()/g} bgneal@45: ] bgneal@45: }); bgneal@45: bgneal@45: h = p.content; bgneal@45: bgneal@45: // Entity encode bgneal@45: if (s.entity_encoding !== 'raw') bgneal@45: h = t._encode(h); bgneal@45: bgneal@45: // Use BR instead of   padded P elements inside editor and use

 

outside editor bgneal@45: /* if (o.set) bgneal@45: h = h.replace(/

\s+( | |\u00a0|
)\s+<\/p>/g, '


'); bgneal@45: else bgneal@45: h = h.replace(/

\s+( | |\u00a0|
)\s+<\/p>/g, '

$1

');*/ bgneal@45: bgneal@45: // Since Gecko and Safari keeps whitespace in the DOM we need to bgneal@45: // remove it inorder to match other browsers. But I think Gecko and Safari is right. bgneal@45: // This process is only done when getting contents out from the editor. bgneal@45: if (!o.set) { bgneal@45: // We need to replace paragraph whitespace with an nbsp before indentation to keep the \u00a0 char bgneal@45: h = h.replace(/

\s+<\/p>|]+)>\s+<\/p>/g, s.entity_encoding == 'numeric' ? ' 

' : ' 

'); bgneal@45: bgneal@45: if (s.remove_linebreaks) { bgneal@45: h = h.replace(/\r?\n|\r/g, ' '); bgneal@45: h = h.replace(/(<[^>]+>)\s+/g, '$1 '); bgneal@45: h = h.replace(/\s+(<\/[^>]+>)/g, ' $1'); bgneal@45: h = h.replace(/<(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object) ([^>]+)>\s+/g, '<$1 $2>'); // Trim block start bgneal@45: h = h.replace(/<(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object)>\s+/g, '<$1>'); // Trim block start bgneal@45: h = h.replace(/\s+<\/(p|h[1-6]|blockquote|hr|div|table|tbody|tr|td|body|head|html|title|meta|style|pre|script|link|object)>/g, ''); // Trim block end bgneal@45: } bgneal@45: bgneal@45: // Simple indentation bgneal@45: if (s.apply_source_formatting && s.indent_mode == 'simple') { bgneal@45: // Add line breaks before and after block elements bgneal@45: h = h.replace(/<(\/?)(ul|hr|table|meta|link|tbody|tr|object|body|head|html|map)(|[^>]+)>\s*/g, '\n<$1$2$3>\n'); bgneal@45: h = h.replace(/\s*<(p|h[1-6]|blockquote|div|title|style|pre|script|td|li|area)(|[^>]+)>/g, '\n<$1$2>'); bgneal@45: h = h.replace(/<\/(p|h[1-6]|blockquote|div|title|style|pre|script|td|li)>\s*/g, '\n'); bgneal@45: h = h.replace(/\n\n/g, '\n'); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: h = t._unprotect(h, p); bgneal@45: bgneal@45: // Restore CDATA sections bgneal@45: h = h.replace(//g, ''); bgneal@45: bgneal@45: // Restore the \u00a0 character if raw mode is enabled bgneal@45: if (s.entity_encoding == 'raw') bgneal@45: h = h.replace(/

 <\/p>|]+)> <\/p>/g, '\u00a0

'); bgneal@183: bgneal@183: // Restore noscript elements bgneal@183: h = h.replace(/]+|)>([\s\S]*?)<\/noscript>/g, function(v, attribs, text) { bgneal@183: return '' + t.dom.decode(text.replace(//g, '')) + ''; bgneal@183: }); bgneal@45: } bgneal@45: bgneal@45: o.content = h; bgneal@45: }, bgneal@45: bgneal@183: _serializeNode : function(n, inner) { bgneal@247: var t = this, s = t.settings, w = t.writer, hc, el, cn, i, l, a, at, no, v, nn, ru, ar, iv, closed, keep, type, scopeName; bgneal@45: bgneal@45: if (!s.node_filter || s.node_filter(n)) { bgneal@45: switch (n.nodeType) { bgneal@45: case 1: // Element bgneal@183: if (n.hasAttribute ? n.hasAttribute('_mce_bogus') : n.getAttribute('_mce_bogus')) bgneal@45: return; bgneal@45: bgneal@183: iv = keep = false; bgneal@45: hc = n.hasChildNodes(); bgneal@183: nn = n.getAttribute('_mce_name') || n.nodeName.toLowerCase(); bgneal@183: bgneal@183: // Get internal type bgneal@183: type = n.getAttribute('_mce_type'); bgneal@183: if (type) { bgneal@183: if (!t._info.cleanup) { bgneal@183: iv = true; bgneal@183: return; bgneal@183: } else bgneal@183: keep = 1; bgneal@183: } bgneal@45: bgneal@45: // Add correct prefix on IE bgneal@45: if (isIE) { bgneal@247: scopeName = n.scopeName; bgneal@247: if (scopeName && scopeName !== 'HTML' && scopeName !== 'html') bgneal@247: nn = scopeName + ':' + nn; bgneal@45: } bgneal@45: bgneal@45: // Remove mce prefix on IE needed for the abbr element bgneal@45: if (nn.indexOf('mce:') === 0) bgneal@45: nn = nn.substring(4); bgneal@45: bgneal@45: // Check if valid bgneal@183: if (!keep) { bgneal@183: if (!t.validElementsRE || !t.validElementsRE.test(nn) || (t.invalidElementsRE && t.invalidElementsRE.test(nn)) || inner) { bgneal@183: iv = true; bgneal@183: break; bgneal@183: } bgneal@45: } bgneal@45: bgneal@45: if (isIE) { bgneal@45: // Fix IE content duplication (DOM can have multiple copies of the same node) bgneal@45: if (s.fix_content_duplication) { bgneal@183: if (n._mce_serialized == t.key) bgneal@45: return; bgneal@45: bgneal@183: n._mce_serialized = t.key; bgneal@45: } bgneal@45: bgneal@45: // IE sometimes adds a / infront of the node name bgneal@45: if (nn.charAt(0) == '/') bgneal@45: nn = nn.substring(1); bgneal@45: } else if (isGecko) { bgneal@45: // Ignore br elements bgneal@45: if (n.nodeName === 'BR' && n.getAttribute('type') == '_moz') bgneal@45: return; bgneal@45: } bgneal@45: bgneal@45: // Check if valid child bgneal@183: if (s.validate_children) { bgneal@183: if (t.elementName && !t.schema.isValid(t.elementName, nn)) { bgneal@183: iv = true; bgneal@183: break; bgneal@45: } bgneal@45: bgneal@45: t.elementName = nn; bgneal@45: } bgneal@45: bgneal@45: ru = t.findRule(nn); bgneal@183: bgneal@183: // No valid rule for this element could be found then skip it bgneal@183: if (!ru) { bgneal@183: iv = true; bgneal@183: break; bgneal@183: } bgneal@183: bgneal@45: nn = ru.name || nn; bgneal@183: closed = s.closed.test(nn); bgneal@45: bgneal@45: // Skip empty nodes or empty node name in IE bgneal@45: if ((!hc && ru.noEmpty) || (isIE && !nn)) { bgneal@45: iv = true; bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: // Check required bgneal@45: if (ru.requiredAttribs) { bgneal@45: a = ru.requiredAttribs; bgneal@45: bgneal@45: for (i = a.length - 1; i >= 0; i--) { bgneal@45: if (this.dom.getAttrib(n, a[i]) !== '') bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: // None of the required was there bgneal@45: if (i == -1) { bgneal@45: iv = true; bgneal@45: break; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: w.writeStartElement(nn); bgneal@45: bgneal@45: // Add ordered attributes bgneal@45: if (ru.attribs) { bgneal@45: for (i=0, at = ru.attribs, l = at.length; i-1; i--) { bgneal@45: no = at[i]; bgneal@45: bgneal@45: if (no.specified) { bgneal@45: a = no.nodeName.toLowerCase(); bgneal@45: bgneal@45: if (s.invalid_attrs.test(a) || !ru.validAttribsRE.test(a)) bgneal@45: continue; bgneal@45: bgneal@45: ar = t.findAttribRule(ru, a); bgneal@45: v = t._getAttrib(n, ar, a); bgneal@45: bgneal@45: if (v !== null) bgneal@45: w.writeAttribute(a, v); bgneal@45: } bgneal@45: } bgneal@45: } bgneal@45: bgneal@183: // Keep type attribute bgneal@183: if (type && keep) bgneal@183: w.writeAttribute('_mce_type', type); bgneal@183: bgneal@183: // Write text from script bgneal@183: if (nn === 'script' && tinymce.trim(n.innerHTML)) { bgneal@183: w.writeText('// '); // Padd it with a comment so it will parse on older browsers bgneal@183: w.writeCDATA(n.innerHTML.replace(/|<\[CDATA\[|\]\]>/g, '')); // Remove comments and cdata stuctures bgneal@183: hc = false; bgneal@183: break; bgneal@183: } bgneal@183: bgneal@45: // Padd empty nodes with a   bgneal@45: if (ru.padd) { bgneal@45: // If it has only one bogus child, padd it anyway workaround for
bug bgneal@45: if (hc && (cn = n.firstChild) && cn.nodeType === 1 && n.childNodes.length === 1) { bgneal@183: if (cn.hasAttribute ? cn.hasAttribute('_mce_bogus') : cn.getAttribute('_mce_bogus')) bgneal@45: w.writeText('\u00a0'); bgneal@45: } else if (!hc) bgneal@45: w.writeText('\u00a0'); // No children then padd it bgneal@45: } bgneal@45: bgneal@45: break; bgneal@45: bgneal@45: case 3: // Text bgneal@45: // Check if valid child bgneal@183: if (s.validate_children && t.elementName && !t.schema.isValid(t.elementName, '#text')) bgneal@183: return; bgneal@45: bgneal@45: return w.writeText(n.nodeValue); bgneal@45: bgneal@45: case 4: // CDATA bgneal@45: return w.writeCDATA(n.nodeValue); bgneal@45: bgneal@45: case 8: // Comment bgneal@45: return w.writeComment(n.nodeValue); bgneal@45: } bgneal@45: } else if (n.nodeType == 1) bgneal@45: hc = n.hasChildNodes(); bgneal@45: bgneal@183: if (hc && !closed) { bgneal@45: cn = n.firstChild; bgneal@45: bgneal@45: while (cn) { bgneal@45: t._serializeNode(cn); bgneal@45: t.elementName = nn; bgneal@45: cn = cn.nextSibling; bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: // Write element end bgneal@45: if (!iv) { bgneal@183: if (!closed) bgneal@45: w.writeFullEndElement(); bgneal@45: else bgneal@45: w.writeEndElement(); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: _protect : function(o) { bgneal@45: var t = this; bgneal@45: bgneal@45: o.items = o.items || []; bgneal@45: bgneal@45: function enc(s) { bgneal@45: return s.replace(/[\r\n\\]/g, function(c) { bgneal@45: if (c === '\n') bgneal@45: return '\\n'; bgneal@45: else if (c === '\\') bgneal@45: return '\\\\'; bgneal@45: bgneal@45: return '\\r'; bgneal@45: }); bgneal@45: }; bgneal@45: bgneal@45: function dec(s) { bgneal@45: return s.replace(/\\[\\rn]/g, function(c) { bgneal@45: if (c === '\\n') bgneal@45: return '\n'; bgneal@45: else if (c === '\\\\') bgneal@45: return '\\'; bgneal@45: bgneal@45: return '\r'; bgneal@45: }); bgneal@45: }; bgneal@45: bgneal@45: each(o.patterns, function(p) { bgneal@45: o.content = dec(enc(o.content).replace(p.pattern, function(x, a, b, c) { bgneal@45: b = dec(b); bgneal@45: bgneal@45: if (p.encode) bgneal@45: b = t._encode(b); bgneal@45: bgneal@45: o.items.push(b); bgneal@45: return a + '' + c; bgneal@45: })); bgneal@45: }); bgneal@45: bgneal@45: return o; bgneal@45: }, bgneal@45: bgneal@45: _unprotect : function(h, o) { bgneal@45: h = h.replace(/\')); bgneal@45: } bgneal@45: bgneal@45: // Add toolbar end before list box and after the previous button bgneal@45: // This is to fix the o2k7 editor skins bgneal@45: if (pr && co.ListBox) { bgneal@45: if (pr.Button || pr.SplitButton) bgneal@45: h += dom.createHTML('td', {'class' : 'mceToolbarEnd'}, dom.createHTML('span', null, '')); bgneal@45: } bgneal@45: bgneal@45: // Render control HTML bgneal@45: bgneal@45: // IE 8 quick fix, needed to propertly generate a hit area for anchors bgneal@45: if (dom.stdMode) bgneal@45: h += '' + co.renderHTML() + ''; bgneal@45: else bgneal@45: h += '' + co.renderHTML() + ''; bgneal@45: bgneal@45: // Add toolbar start after list box and before the next button bgneal@45: // This is to fix the o2k7 editor skins bgneal@45: if (nx && co.ListBox) { bgneal@45: if (nx.Button || nx.SplitButton) bgneal@45: h += dom.createHTML('td', {'class' : 'mceToolbarStart'}, dom.createHTML('span', null, '')); bgneal@45: } bgneal@45: } bgneal@45: bgneal@45: c = 'mceToolbarEnd'; bgneal@45: bgneal@45: if (co.Button) bgneal@45: c += ' mceToolbarEndButton'; bgneal@45: else if (co.SplitButton) bgneal@45: c += ' mceToolbarEndSplitButton'; bgneal@45: else if (co.ListBox) bgneal@45: c += ' mceToolbarEndListBox'; bgneal@45: bgneal@45: h += dom.createHTML('td', {'class' : c}, dom.createHTML('span', null, '')); bgneal@45: bgneal@45: return dom.createHTML('table', {id : t.id, 'class' : 'mceToolbar' + (s['class'] ? ' ' + s['class'] : ''), cellpadding : '0', cellspacing : '0', align : t.settings.align || ''}, '' + h + ''); bgneal@45: } bgneal@183: }); bgneal@183: bgneal@45: (function(tinymce) { bgneal@45: var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each; bgneal@45: bgneal@45: tinymce.create('tinymce.AddOnManager', { bgneal@247: AddOnManager : function() { bgneal@247: var self = this; bgneal@247: bgneal@247: self.items = []; bgneal@247: self.urls = {}; bgneal@247: self.lookup = {}; bgneal@247: self.onAdd = new Dispatcher(self); bgneal@247: }, bgneal@45: bgneal@45: get : function(n) { bgneal@45: return this.lookup[n]; bgneal@45: }, bgneal@45: bgneal@45: requireLangPack : function(n) { bgneal@183: var s = tinymce.settings; bgneal@183: bgneal@183: if (s && s.language) bgneal@183: tinymce.ScriptLoader.add(this.urls[n] + '/langs/' + s.language + '.js'); bgneal@45: }, bgneal@45: bgneal@45: add : function(id, o) { bgneal@45: this.items.push(o); bgneal@45: this.lookup[id] = o; bgneal@45: this.onAdd.dispatch(this, id, o); bgneal@45: bgneal@45: return o; bgneal@45: }, bgneal@45: bgneal@45: load : function(n, u, cb, s) { bgneal@45: var t = this; bgneal@45: bgneal@45: if (t.urls[n]) bgneal@45: return; bgneal@45: bgneal@45: if (u.indexOf('/') != 0 && u.indexOf('://') == -1) bgneal@45: u = tinymce.baseURL + '/' + u; bgneal@45: bgneal@45: t.urls[n] = u.substring(0, u.lastIndexOf('/')); bgneal@247: bgneal@247: if (!t.lookup[n]) bgneal@247: tinymce.ScriptLoader.add(u, cb, s); bgneal@45: } bgneal@183: }); bgneal@45: bgneal@45: // Create plugin and theme managers bgneal@45: tinymce.PluginManager = new tinymce.AddOnManager(); bgneal@45: tinymce.ThemeManager = new tinymce.AddOnManager(); bgneal@183: }(tinymce)); bgneal@183: bgneal@183: (function(tinymce) { bgneal@45: // Shorten names bgneal@183: var each = tinymce.each, extend = tinymce.extend, bgneal@183: DOM = tinymce.DOM, Event = tinymce.dom.Event, bgneal@183: ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager, bgneal@183: explode = tinymce.explode, bgneal@183: Dispatcher = tinymce.util.Dispatcher, undefined, instanceCounter = 0; bgneal@183: bgneal@183: // Setup some URLs where the editor API is located and where the document is bgneal@183: tinymce.documentBaseURL = window.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, ''); bgneal@183: if (!/[\/\\]$/.test(tinymce.documentBaseURL)) bgneal@183: tinymce.documentBaseURL += '/'; bgneal@183: bgneal@183: tinymce.baseURL = new tinymce.util.URI(tinymce.documentBaseURL).toAbsolute(tinymce.baseURL); bgneal@183: bgneal@183: tinymce.baseURI = new tinymce.util.URI(tinymce.baseURL); bgneal@183: bgneal@183: // Add before unload listener bgneal@183: // This was required since IE was leaking memory if you added and removed beforeunload listeners bgneal@183: // with attachEvent/detatchEvent so this only adds one listener and instances can the attach to the onBeforeUnload event bgneal@183: tinymce.onBeforeUnload = new Dispatcher(tinymce); bgneal@183: bgneal@183: // Must be on window or IE will leak if the editor is placed in frame or iframe bgneal@183: Event.add(window, 'beforeunload', function(e) { bgneal@183: tinymce.onBeforeUnload.dispatch(tinymce, e); bgneal@183: }); bgneal@183: bgneal@183: tinymce.onAddEditor = new Dispatcher(tinymce); bgneal@183: bgneal@183: tinymce.onRemoveEditor = new Dispatcher(tinymce); bgneal@183: bgneal@183: tinymce.EditorManager = extend(tinymce, { bgneal@183: editors : [], bgneal@183: bgneal@45: i18n : {}, bgneal@183: bgneal@45: activeEditor : null, bgneal@45: bgneal@45: init : function(s) { bgneal@183: var t = this, pl, sl = tinymce.ScriptLoader, e, el = [], ed; bgneal@45: bgneal@45: function execCallback(se, n, s) { bgneal@45: var f = se[n]; bgneal@45: bgneal@45: if (!f) bgneal@45: return; bgneal@45: bgneal@45: if (tinymce.is(f, 'string')) { bgneal@45: s = f.replace(/\.\w+$/, ''); bgneal@45: s = s ? tinymce.resolve(s) : 0; bgneal@45: f = tinymce.resolve(f); bgneal@45: } bgneal@45: bgneal@45: return f.apply(s || this, Array.prototype.slice.call(arguments, 2)); bgneal@45: }; bgneal@45: bgneal@45: s = extend({ bgneal@45: theme : "simple", bgneal@183: language : "en" bgneal@45: }, s); bgneal@45: bgneal@45: t.settings = s; bgneal@45: bgneal@45: // Legacy call bgneal@45: Event.add(document, 'init', function() { bgneal@45: var l, co; bgneal@45: bgneal@45: execCallback(s, 'onpageload'); bgneal@45: bgneal@45: switch (s.mode) { bgneal@45: case "exact": bgneal@45: l = s.elements || ''; bgneal@45: bgneal@45: if(l.length > 0) { bgneal@45: each(explode(l), function(v) { bgneal@45: if (DOM.get(v)) { bgneal@45: ed = new tinymce.Editor(v, s); bgneal@45: el.push(ed); bgneal@45: ed.render(1); bgneal@45: } else { bgneal@45: each(document.forms, function(f) { bgneal@45: each(f.elements, function(e) { bgneal@45: if (e.name === v) { bgneal@183: v = 'mce_editor_' + instanceCounter++; bgneal@45: DOM.setAttrib(e, 'id', v); bgneal@45: bgneal@45: ed = new tinymce.Editor(v, s); bgneal@45: el.push(ed); bgneal@45: ed.render(1); bgneal@45: } bgneal@45: }); bgneal@45: }); bgneal@45: } bgneal@45: }); bgneal@45: } bgneal@45: break; bgneal@45: bgneal@45: case "textareas": bgneal@45: case "specific_textareas": bgneal@45: function hasClass(n, c) { bgneal@45: return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c); bgneal@45: }; bgneal@45: bgneal@45: each(DOM.select('textarea'), function(v) { bgneal@45: if (s.editor_deselector && hasClass(v, s.editor_deselector)) bgneal@45: return; bgneal@45: bgneal@45: if (!s.editor_selector || hasClass(v, s.editor_selector)) { bgneal@45: // Can we use the name bgneal@45: e = DOM.get(v.name); bgneal@45: if (!v.id && !e) bgneal@45: v.id = v.name; bgneal@45: bgneal@45: // Generate unique name if missing or already exists bgneal@45: if (!v.id || t.get(v.id)) bgneal@45: v.id = DOM.uniqueId(); bgneal@45: bgneal@45: ed = new tinymce.Editor(v.id, s); bgneal@45: el.push(ed); bgneal@45: ed.render(1); bgneal@45: } bgneal@45: }); bgneal@45: break; bgneal@45: } bgneal@45: bgneal@45: // Call onInit when all editors are initialized bgneal@45: if (s.oninit) { bgneal@45: l = co = 0; bgneal@45: bgneal@183: each(el, function(ed) { bgneal@45: co++; bgneal@45: bgneal@45: if (!ed.initialized) { bgneal@45: // Wait for it bgneal@45: ed.onInit.add(function() { bgneal@45: l++; bgneal@45: bgneal@45: // All done bgneal@45: if (l == co) bgneal@45: execCallback(s, 'oninit'); bgneal@45: }); bgneal@45: } else bgneal@45: l++; bgneal@45: bgneal@45: // All done bgneal@45: if (l == co) bgneal@45: execCallback(s, 'oninit'); bgneal@45: }); bgneal@45: } bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: get : function(id) { bgneal@183: if (id === undefined) bgneal@183: return this.editors; bgneal@183: bgneal@45: return this.editors[id]; bgneal@45: }, bgneal@45: bgneal@45: getInstanceById : function(id) { bgneal@45: return this.get(id); bgneal@45: }, bgneal@45: bgneal@183: add : function(editor) { bgneal@183: var self = this, editors = self.editors; bgneal@183: bgneal@183: // Add named and index editor instance bgneal@183: editors[editor.id] = editor; bgneal@183: editors.push(editor); bgneal@183: bgneal@183: self._setActive(editor); bgneal@183: self.onAddEditor.dispatch(self, editor); bgneal@183: bgneal@183: bgneal@183: return editor; bgneal@183: }, bgneal@183: bgneal@183: remove : function(editor) { bgneal@183: var t = this, i, editors = t.editors; bgneal@45: bgneal@45: // Not in the collection bgneal@183: if (!editors[editor.id]) bgneal@45: return null; bgneal@45: bgneal@183: delete editors[editor.id]; bgneal@183: bgneal@183: for (i = 0; i < editors.length; i++) { bgneal@183: if (editors[i] == editor) { bgneal@183: editors.splice(i, 1); bgneal@183: break; bgneal@183: } bgneal@183: } bgneal@45: bgneal@45: // Select another editor since the active one was removed bgneal@183: if (t.activeEditor == editor) bgneal@183: t._setActive(editors[0]); bgneal@183: bgneal@183: editor.destroy(); bgneal@183: t.onRemoveEditor.dispatch(t, editor); bgneal@183: bgneal@183: return editor; bgneal@45: }, bgneal@45: bgneal@45: execCommand : function(c, u, v) { bgneal@45: var t = this, ed = t.get(v), w; bgneal@45: bgneal@45: // Manager commands bgneal@45: switch (c) { bgneal@45: case "mceFocus": bgneal@45: ed.focus(); bgneal@45: return true; bgneal@45: bgneal@45: case "mceAddEditor": bgneal@45: case "mceAddControl": bgneal@45: if (!t.get(v)) bgneal@45: new tinymce.Editor(v, t.settings).render(); bgneal@45: bgneal@45: return true; bgneal@45: bgneal@45: case "mceAddFrameControl": bgneal@45: w = v.window; bgneal@45: bgneal@45: // Add tinyMCE global instance and tinymce namespace to specified window bgneal@45: w.tinyMCE = tinyMCE; bgneal@45: w.tinymce = tinymce; bgneal@45: bgneal@45: tinymce.DOM.doc = w.document; bgneal@45: tinymce.DOM.win = w; bgneal@45: bgneal@45: ed = new tinymce.Editor(v.element_id, v); bgneal@45: ed.render(); bgneal@45: bgneal@45: // Fix IE memory leaks bgneal@45: if (tinymce.isIE) { bgneal@45: function clr() { bgneal@45: ed.destroy(); bgneal@45: w.detachEvent('onunload', clr); bgneal@45: w = w.tinyMCE = w.tinymce = null; // IE leak bgneal@45: }; bgneal@45: bgneal@45: w.attachEvent('onunload', clr); bgneal@45: } bgneal@45: bgneal@45: v.page_window = null; bgneal@45: bgneal@45: return true; bgneal@45: bgneal@45: case "mceRemoveEditor": bgneal@45: case "mceRemoveControl": bgneal@45: if (ed) bgneal@45: ed.remove(); bgneal@45: bgneal@45: return true; bgneal@45: bgneal@45: case 'mceToggleEditor': bgneal@45: if (!ed) { bgneal@45: t.execCommand('mceAddControl', 0, v); bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: if (ed.isHidden()) bgneal@45: ed.show(); bgneal@45: else bgneal@45: ed.hide(); bgneal@45: bgneal@45: return true; bgneal@45: } bgneal@45: bgneal@45: // Run command on active editor bgneal@45: if (t.activeEditor) bgneal@45: return t.activeEditor.execCommand(c, u, v); bgneal@45: bgneal@45: return false; bgneal@45: }, bgneal@45: bgneal@45: execInstanceCommand : function(id, c, u, v) { bgneal@45: var ed = this.get(id); bgneal@45: bgneal@45: if (ed) bgneal@45: return ed.execCommand(c, u, v); bgneal@45: bgneal@45: return false; bgneal@45: }, bgneal@45: bgneal@45: triggerSave : function() { bgneal@45: each(this.editors, function(e) { bgneal@45: e.save(); bgneal@45: }); bgneal@45: }, bgneal@45: bgneal@45: addI18n : function(p, o) { bgneal@45: var lo, i18n = this.i18n; bgneal@45: bgneal@45: if (!tinymce.is(p, 'string')) { bgneal@45: each(p, function(o, lc) { bgneal@45: each(o, function(o, g) { bgneal@45: each(o, function(o, k) { bgneal@45: if (g === 'common') bgneal@45: i18n[lc + '.' + k] = o; bgneal@45: else bgneal@45: i18n[lc + '.' + g + '.' + k] = o; bgneal@45: }); bgneal@45: }); bgneal@45: }); bgneal@45: } else { bgneal@45: each(o, function(o, k) { bgneal@45: i18n[p + '.' + k] = o; bgneal@45: }); bgneal@45: } bgneal@45: }, bgneal@45: bgneal@45: // Private methods bgneal@45: bgneal@183: _setActive : function(editor) { bgneal@183: this.selectedInstance = this.activeEditor = editor; bgneal@45: } bgneal@183: }); bgneal@45: })(tinymce); bgneal@45: bgneal@45: (function(tinymce) { bgneal@183: // Shorten these names bgneal@183: var DOM = tinymce.DOM, Event = tinymce.dom.Event, extend = tinymce.extend, bgneal@183: Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isGecko = tinymce.isGecko, bgneal@183: isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, is = tinymce.is, bgneal@183: ThemeManager = tinymce.ThemeManager, PluginManager = tinymce.PluginManager, bgneal@183: inArray = tinymce.inArray, grep = tinymce.grep, explode = tinymce.explode; bgneal@45: bgneal@45: tinymce.create('tinymce.Editor', { bgneal@45: Editor : function(id, s) { bgneal@45: var t = this; bgneal@45: bgneal@45: t.id = t.editorId = id; bgneal@183: bgneal@45: t.execCommands = {}; bgneal@45: t.queryStateCommands = {}; bgneal@45: t.queryValueCommands = {}; bgneal@183: bgneal@183: t.isNotDirty = false; bgneal@183: bgneal@45: t.plugins = {}; bgneal@45: bgneal@45: // Add events to the editor bgneal@45: each([ bgneal@45: 'onPreInit', bgneal@183: bgneal@45: 'onBeforeRenderUI', bgneal@183: bgneal@45: 'onPostRender', bgneal@183: bgneal@45: 'onInit', bgneal@183: bgneal@45: 'onRemove', bgneal@183: bgneal@45: 'onActivate', bgneal@183: bgneal@45: 'onDeactivate', bgneal@183: bgneal@45: 'onClick', bgneal@183: bgneal@45: 'onEvent', bgneal@183: bgneal@45: 'onMouseUp', bgneal@183: bgneal@45: 'onMouseDown', bgneal@183: bgneal@45: 'onDblClick', bgneal@183: bgneal@45: 'onKeyDown', bgneal@183: bgneal@45: 'onKeyUp', bgneal@183: bgneal@45: 'onKeyPress', bgneal@183: bgneal@45: 'onContextMenu', bgneal@183: bgneal@45: 'onSubmit', bgneal@183: bgneal@45: 'onReset', bgneal@183: bgneal@45: 'onPaste', bgneal@183: bgneal@45: 'onPreProcess', bgneal@183: bgneal@45: 'onPostProcess', bgneal@183: bgneal@45: 'onBeforeSetContent', bgneal@183: bgneal@45: 'onBeforeGetContent', bgneal@183: bgneal@45: 'onSetContent', bgneal@183: bgneal@45: 'onGetContent', bgneal@183: bgneal@45: 'onLoadContent', bgneal@183: bgneal@45: 'onSaveContent', bgneal@183: bgneal@45: 'onNodeChange', bgneal@183: bgneal@45: 'onChange', bgneal@183: bgneal@45: 'onBeforeExecCommand', bgneal@183: bgneal@45: 'onExecCommand', bgneal@183: bgneal@45: 'onUndo', bgneal@183: bgneal@45: 'onRedo', bgneal@183: bgneal@45: 'onVisualAid', bgneal@183: bgneal@45: 'onSetProgressState' bgneal@45: ], function(e) { bgneal@45: t[e] = new Dispatcher(t); bgneal@45: }); bgneal@45: bgneal@45: t.settings = s = extend({ bgneal@45: id : id, bgneal@45: language : 'en', bgneal@45: docs_language : 'en', bgneal@45: theme : 'simple', bgneal@45: skin : 'default', bgneal@45: delta_width : 0, bgneal@45: delta_height : 0, bgneal@45: popup_css : '', bgneal@45: plugins : '', bgneal@45: document_base_url : tinymce.documentBaseURL, bgneal@45: add_form_submit_trigger : 1, bgneal@45: submit_patch : 1, bgneal@45: add_unload_trigger : 1, bgneal@45: convert_urls : 1, bgneal@45: relative_urls : 1, bgneal@45: remove_script_host : 1, bgneal@45: table_inline_editing : 0, bgneal@45: object_resizing : 1, bgneal@45: cleanup : 1, bgneal@45: accessibility_focus : 1, bgneal@45: custom_shortcuts : 1, bgneal@45: custom_undo_redo_keyboard_shortcuts : 1, bgneal@45: custom_undo_redo_restore_selection : 1, bgneal@45: custom_undo_redo : 1, bgneal@183: doctype : tinymce.isIE6 ? '' : '', // Use old doctype on IE 6 to avoid horizontal scroll bgneal@45: visual_table_class : 'mceItemTable', bgneal@45: visual : 1, bgneal@45: font_size_style_values : 'xx-small,x-small,small,medium,large,x-large,xx-large', bgneal@45: apply_source_formatting : 1, bgneal@45: directionality : 'ltr', bgneal@45: forced_root_block : 'p', bgneal@183: valid_elements : '@[id|class|style|title|dir