bgneal@312: (function(win) { bgneal@312: var whiteSpaceRe = /^\s*|\s*$/g, bgneal@312: undefined; bgneal@312: bgneal@312: var tinymce = { bgneal@312: majorVersion : '3', bgneal@312: bgneal@312: minorVersion : '3.9', bgneal@312: bgneal@312: releaseDate : '2010-09-08', bgneal@312: bgneal@312: _init : function() { bgneal@312: var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v; bgneal@312: bgneal@312: t.isOpera = win.opera && opera.buildNumber; bgneal@312: bgneal@312: t.isWebKit = /WebKit/.test(ua); bgneal@312: bgneal@312: t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName); bgneal@312: bgneal@312: t.isIE6 = t.isIE && /MSIE [56]/.test(ua); bgneal@312: bgneal@312: t.isGecko = !t.isWebKit && /Gecko/.test(ua); bgneal@312: bgneal@312: t.isMac = ua.indexOf('Mac') != -1; bgneal@312: bgneal@312: t.isAir = /adobeair/i.test(ua); bgneal@312: bgneal@312: t.isIDevice = /(iPad|iPhone)/.test(ua); bgneal@312: bgneal@312: // TinyMCE .NET webcontrol might be setting the values for TinyMCE bgneal@312: if (win.tinyMCEPreInit) { bgneal@312: t.suffix = tinyMCEPreInit.suffix; bgneal@312: t.baseURL = tinyMCEPreInit.base; bgneal@312: t.query = tinyMCEPreInit.query; bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Get suffix and base bgneal@312: t.suffix = ''; bgneal@312: bgneal@312: // If base element found, add that infront of baseURL bgneal@312: nl = d.getElementsByTagName('base'); bgneal@312: for (i=0; i : bgneal@312: s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s); bgneal@312: cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name bgneal@312: bgneal@312: // Create namespace for new class bgneal@312: ns = t.createNS(s[3].replace(/\.\w+$/, '')); bgneal@312: bgneal@312: // Class already exists bgneal@312: if (ns[cn]) bgneal@312: return; bgneal@312: bgneal@312: // Make pure static class bgneal@312: if (s[2] == 'static') { bgneal@312: ns[cn] = p; bgneal@312: bgneal@312: if (this.onCreate) bgneal@312: this.onCreate(s[2], s[3], ns[cn]); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Create default constructor bgneal@312: if (!p[cn]) { bgneal@312: p[cn] = function() {}; bgneal@312: de = 1; bgneal@312: } bgneal@312: bgneal@312: // Add constructor and methods bgneal@312: ns[cn] = p[cn]; bgneal@312: t.extend(ns[cn].prototype, p); bgneal@312: bgneal@312: // Extend bgneal@312: if (s[5]) { bgneal@312: sp = t.resolve(s[5]).prototype; bgneal@312: scn = s[5].match(/\.(\w+)$/i)[1]; // Class name bgneal@312: bgneal@312: // Extend constructor bgneal@312: c = ns[cn]; bgneal@312: if (de) { bgneal@312: // Add passthrough constructor bgneal@312: ns[cn] = function() { bgneal@312: return sp[scn].apply(this, arguments); bgneal@312: }; bgneal@312: } else { bgneal@312: // Add inherit constructor bgneal@312: ns[cn] = function() { bgneal@312: this.parent = sp[scn]; bgneal@312: return c.apply(this, arguments); bgneal@312: }; bgneal@312: } bgneal@312: ns[cn].prototype[cn] = ns[cn]; bgneal@312: bgneal@312: // Add super methods bgneal@312: t.each(sp, function(f, n) { bgneal@312: ns[cn].prototype[n] = sp[n]; bgneal@312: }); bgneal@312: bgneal@312: // Add overridden methods bgneal@312: t.each(p, function(f, n) { bgneal@312: // Extend methods if needed bgneal@312: if (sp[n]) { bgneal@312: ns[cn].prototype[n] = function() { bgneal@312: this.parent = sp[n]; bgneal@312: return f.apply(this, arguments); bgneal@312: }; bgneal@312: } else { bgneal@312: if (n != cn) bgneal@312: ns[cn].prototype[n] = f; bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: // Add static methods bgneal@312: t.each(p['static'], function(f, n) { bgneal@312: ns[cn][n] = f; bgneal@312: }); bgneal@312: bgneal@312: if (this.onCreate) bgneal@312: this.onCreate(s[2], s[3], ns[cn].prototype); bgneal@312: }, bgneal@312: bgneal@312: walk : function(o, f, n, s) { bgneal@312: s = s || this; bgneal@312: bgneal@312: if (o) { bgneal@312: if (n) bgneal@312: o = o[n]; bgneal@312: bgneal@312: tinymce.each(o, function(o, i) { bgneal@312: if (f.call(s, o, i, n) === false) bgneal@312: return false; bgneal@312: bgneal@312: tinymce.walk(o, f, n, s); bgneal@312: }); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: createNS : function(n, o) { bgneal@312: var i, v; bgneal@312: bgneal@312: o = o || win; bgneal@312: bgneal@312: n = n.split('.'); bgneal@312: for (i=0; i= items.length) { bgneal@312: for (i = 0, l = base.length; i < l; i++) { bgneal@312: if (i >= items.length || base[i] != items[i]) { bgneal@312: bp = i + 1; bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if (base.length < items.length) { bgneal@312: for (i = 0, l = items.length; i < l; i++) { bgneal@312: if (i >= base.length || base[i] != items[i]) { bgneal@312: bp = i + 1; bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if (bp == 1) bgneal@312: return path; bgneal@312: bgneal@312: for (i = 0, l = base.length - (bp - 1); i < l; i++) bgneal@312: out += "../"; bgneal@312: bgneal@312: for (i = bp - 1, l = items.length; i < l; i++) { bgneal@312: if (i != bp - 1) bgneal@312: out += "/" + items[i]; bgneal@312: else bgneal@312: out += items[i]; bgneal@312: } bgneal@312: bgneal@312: return out; bgneal@312: }, bgneal@312: bgneal@312: toAbsPath : function(base, path) { bgneal@312: var i, nb = 0, o = [], tr, outPath; bgneal@312: bgneal@312: // Split paths bgneal@312: tr = /\/$/.test(path) ? '/' : ''; bgneal@312: base = base.split('/'); bgneal@312: path = path.split('/'); bgneal@312: bgneal@312: // Remove empty chunks bgneal@312: each(base, function(k) { bgneal@312: if (k) bgneal@312: o.push(k); bgneal@312: }); bgneal@312: bgneal@312: base = o; bgneal@312: bgneal@312: // Merge relURLParts chunks bgneal@312: for (i = path.length - 1, o = []; i >= 0; i--) { bgneal@312: // Ignore empty or . bgneal@312: if (path[i].length == 0 || path[i] == ".") bgneal@312: continue; bgneal@312: bgneal@312: // Is parent bgneal@312: if (path[i] == '..') { bgneal@312: nb++; bgneal@312: continue; bgneal@312: } bgneal@312: bgneal@312: // Move up bgneal@312: if (nb > 0) { bgneal@312: nb--; bgneal@312: continue; bgneal@312: } bgneal@312: bgneal@312: o.push(path[i]); bgneal@312: } bgneal@312: bgneal@312: i = base.length - nb; bgneal@312: bgneal@312: // If /a/b/c or / bgneal@312: if (i <= 0) bgneal@312: outPath = o.reverse().join('/'); bgneal@312: else bgneal@312: outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/'); bgneal@312: bgneal@312: // Add front / if it's needed bgneal@312: if (outPath.indexOf('/') !== 0) bgneal@312: outPath = '/' + outPath; bgneal@312: bgneal@312: // Add traling / if it's needed bgneal@312: if (tr && outPath.lastIndexOf('/') !== outPath.length - 1) bgneal@312: outPath += tr; bgneal@312: bgneal@312: return outPath; bgneal@312: }, bgneal@312: bgneal@312: getURI : function(nh) { bgneal@312: var s, t = this; bgneal@312: bgneal@312: // Rebuild source bgneal@312: if (!t.source || nh) { bgneal@312: s = ''; bgneal@312: bgneal@312: if (!nh) { bgneal@312: if (t.protocol) bgneal@312: s += t.protocol + '://'; bgneal@312: bgneal@312: if (t.userInfo) bgneal@312: s += t.userInfo + '@'; bgneal@312: bgneal@312: if (t.host) bgneal@312: s += t.host; bgneal@312: bgneal@312: if (t.port) bgneal@312: s += ':' + t.port; bgneal@312: } bgneal@312: bgneal@312: if (t.path) bgneal@312: s += t.path; bgneal@312: bgneal@312: if (t.query) bgneal@312: s += '?' + t.query; bgneal@312: bgneal@312: if (t.anchor) bgneal@312: s += '#' + t.anchor; bgneal@312: bgneal@312: t.source = s; bgneal@312: } bgneal@312: bgneal@312: return t.source; bgneal@312: } bgneal@312: }); bgneal@312: })(); bgneal@312: bgneal@312: (function() { bgneal@312: var each = tinymce.each; bgneal@312: bgneal@312: tinymce.create('static tinymce.util.Cookie', { bgneal@312: getHash : function(n) { bgneal@312: var v = this.get(n), h; bgneal@312: bgneal@312: if (v) { bgneal@312: each(v.split('&'), function(v) { bgneal@312: v = v.split('='); bgneal@312: h = h || {}; bgneal@312: h[unescape(v[0])] = unescape(v[1]); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: return h; bgneal@312: }, bgneal@312: bgneal@312: setHash : function(n, v, e, p, d, s) { bgneal@312: var o = ''; bgneal@312: bgneal@312: each(v, function(v, k) { bgneal@312: o += (!o ? '' : '&') + escape(k) + '=' + escape(v); bgneal@312: }); bgneal@312: bgneal@312: this.set(n, o, e, p, d, s); bgneal@312: }, bgneal@312: bgneal@312: get : function(n) { bgneal@312: var c = document.cookie, e, p = n + "=", b; bgneal@312: bgneal@312: // Strict mode bgneal@312: if (!c) bgneal@312: return; bgneal@312: bgneal@312: b = c.indexOf("; " + p); bgneal@312: bgneal@312: if (b == -1) { bgneal@312: b = c.indexOf(p); bgneal@312: bgneal@312: if (b != 0) bgneal@312: return null; bgneal@312: } else bgneal@312: b += 2; bgneal@312: bgneal@312: e = c.indexOf(";", b); bgneal@312: bgneal@312: if (e == -1) bgneal@312: e = c.length; bgneal@312: bgneal@312: return unescape(c.substring(b + p.length, e)); bgneal@312: }, bgneal@312: bgneal@312: set : function(n, v, e, p, d, s) { bgneal@312: document.cookie = n + "=" + escape(v) + bgneal@312: ((e) ? "; expires=" + e.toGMTString() : "") + bgneal@312: ((p) ? "; path=" + escape(p) : "") + bgneal@312: ((d) ? "; domain=" + d : "") + bgneal@312: ((s) ? "; secure" : ""); bgneal@312: }, bgneal@312: bgneal@312: remove : function(n, p) { bgneal@312: var d = new Date(); bgneal@312: bgneal@312: d.setTime(d.getTime() - 1000); bgneal@312: bgneal@312: this.set(n, '', d, p, d); bgneal@312: } bgneal@312: }); bgneal@312: })(); bgneal@312: bgneal@312: tinymce.create('static tinymce.util.JSON', { bgneal@312: serialize : function(o) { bgneal@312: var i, v, s = tinymce.util.JSON.serialize, t; bgneal@312: bgneal@312: if (o == null) bgneal@312: return 'null'; bgneal@312: bgneal@312: t = typeof o; bgneal@312: bgneal@312: if (t == 'string') { bgneal@312: v = '\bb\tt\nn\ff\rr\""\'\'\\\\'; bgneal@312: bgneal@312: return '"' + o.replace(/([\u0080-\uFFFF\x00-\x1f\"])/g, function(a, b) { bgneal@312: i = v.indexOf(b); bgneal@312: bgneal@312: if (i + 1) bgneal@312: return '\\' + v.charAt(i + 1); bgneal@312: bgneal@312: a = b.charCodeAt().toString(16); bgneal@312: bgneal@312: return '\\u' + '0000'.substring(a.length) + a; bgneal@312: }) + '"'; bgneal@312: } bgneal@312: bgneal@312: if (t == 'object') { bgneal@312: if (o.hasOwnProperty && o instanceof Array) { bgneal@312: for (i=0, v = '['; i 0 ? ',' : '') + s(o[i]); bgneal@312: bgneal@312: return v + ']'; bgneal@312: } bgneal@312: bgneal@312: v = '{'; bgneal@312: bgneal@312: for (i in o) bgneal@312: v += typeof o[i] != 'function' ? (v.length > 1 ? ',"' : '"') + i + '":' + s(o[i]) : ''; bgneal@312: bgneal@312: return v + '}'; bgneal@312: } bgneal@312: bgneal@312: return '' + o; bgneal@312: }, bgneal@312: bgneal@312: parse : function(s) { bgneal@312: try { bgneal@312: return eval('(' + s + ')'); bgneal@312: } catch (ex) { bgneal@312: // Ignore bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: }); bgneal@312: bgneal@312: tinymce.create('static tinymce.util.XHR', { bgneal@312: send : function(o) { bgneal@312: var x, t, w = window, c = 0; bgneal@312: bgneal@312: // Default settings bgneal@312: o.scope = o.scope || this; bgneal@312: o.success_scope = o.success_scope || o.scope; bgneal@312: o.error_scope = o.error_scope || o.scope; bgneal@312: o.async = o.async === false ? false : true; bgneal@312: o.data = o.data || ''; bgneal@312: bgneal@312: function get(s) { bgneal@312: x = 0; bgneal@312: bgneal@312: try { bgneal@312: x = new ActiveXObject(s); bgneal@312: } catch (ex) { bgneal@312: } bgneal@312: bgneal@312: return x; bgneal@312: }; bgneal@312: bgneal@312: x = w.XMLHttpRequest ? new XMLHttpRequest() : get('Microsoft.XMLHTTP') || get('Msxml2.XMLHTTP'); bgneal@312: bgneal@312: if (x) { bgneal@312: if (x.overrideMimeType) bgneal@312: x.overrideMimeType(o.content_type); bgneal@312: bgneal@312: x.open(o.type || (o.data ? 'POST' : 'GET'), o.url, o.async); bgneal@312: bgneal@312: if (o.content_type) bgneal@312: x.setRequestHeader('Content-Type', o.content_type); bgneal@312: bgneal@312: x.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); bgneal@312: bgneal@312: x.send(o.data); bgneal@312: bgneal@312: function ready() { bgneal@312: if (!o.async || x.readyState == 4 || c++ > 10000) { bgneal@312: if (o.success && c < 10000 && x.status == 200) bgneal@312: o.success.call(o.success_scope, '' + x.responseText, x, o); bgneal@312: else if (o.error) bgneal@312: o.error.call(o.error_scope, c > 10000 ? 'TIMED_OUT' : 'GENERAL', x, o); bgneal@312: bgneal@312: x = null; bgneal@312: } else bgneal@312: w.setTimeout(ready, 10); bgneal@312: }; bgneal@312: bgneal@312: // Syncronous request bgneal@312: if (!o.async) bgneal@312: return ready(); bgneal@312: bgneal@312: // Wait for response, onReadyStateChange can not be used since it leaks memory in IE bgneal@312: t = w.setTimeout(ready, 10); bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: (function() { bgneal@312: var extend = tinymce.extend, JSON = tinymce.util.JSON, XHR = tinymce.util.XHR; bgneal@312: bgneal@312: tinymce.create('tinymce.util.JSONRequest', { bgneal@312: JSONRequest : function(s) { bgneal@312: this.settings = extend({ bgneal@312: }, s); bgneal@312: this.count = 0; bgneal@312: }, bgneal@312: bgneal@312: send : function(o) { bgneal@312: var ecb = o.error, scb = o.success; bgneal@312: bgneal@312: o = extend(this.settings, o); bgneal@312: bgneal@312: o.success = function(c, x) { bgneal@312: c = JSON.parse(c); bgneal@312: bgneal@312: if (typeof(c) == 'undefined') { bgneal@312: c = { bgneal@312: error : 'JSON Parse error.' bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: if (c.error) bgneal@312: ecb.call(o.error_scope || o.scope, c.error, x); bgneal@312: else bgneal@312: scb.call(o.success_scope || o.scope, c.result); bgneal@312: }; bgneal@312: bgneal@312: o.error = function(ty, x) { bgneal@312: ecb.call(o.error_scope || o.scope, ty, x); bgneal@312: }; bgneal@312: bgneal@312: o.data = JSON.serialize({ bgneal@312: id : o.id || 'c' + (this.count++), bgneal@312: method : o.method, bgneal@312: params : o.params bgneal@312: }); bgneal@312: bgneal@312: // JSON content type for Ruby on rails. Bug: #1883287 bgneal@312: o.content_type = 'application/json'; bgneal@312: bgneal@312: XHR.send(o); bgneal@312: }, bgneal@312: bgneal@312: 'static' : { bgneal@312: sendRPC : function(o) { bgneal@312: return new tinymce.util.JSONRequest().send(o); bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: }()); bgneal@312: (function(tinymce) { bgneal@312: // Shorten names bgneal@312: var each = tinymce.each, bgneal@312: is = tinymce.is, bgneal@312: isWebKit = tinymce.isWebKit, bgneal@312: isIE = tinymce.isIE, bgneal@312: 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@312: boolAttrs = makeMap('checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected'), bgneal@312: mceAttribs = makeMap('src,href,style,coords,shape'), bgneal@312: encodedChars = {'&' : '&', '"' : '"', '<' : '<', '>' : '>'}, bgneal@312: encodeCharsRe = /[<>&\"]/g, bgneal@312: simpleSelectorRe = /^([a-z0-9],?)+$/i, bgneal@312: tagRegExp = /<(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)(\s*\/?)>/g, bgneal@312: attrRegExp = /(\w+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g; bgneal@312: bgneal@312: function makeMap(str) { bgneal@312: var map = {}, i; bgneal@312: bgneal@312: str = str.split(','); bgneal@312: for (i = str.length; i >= 0; i--) bgneal@312: map[str[i]] = 1; bgneal@312: bgneal@312: return map; bgneal@312: }; bgneal@312: bgneal@312: tinymce.create('tinymce.dom.DOMUtils', { bgneal@312: doc : null, bgneal@312: root : null, bgneal@312: files : null, bgneal@312: pixelStyles : /^(top|left|bottom|right|width|height|borderWidth)$/, bgneal@312: props : { bgneal@312: "for" : "htmlFor", bgneal@312: "class" : "className", bgneal@312: className : "className", bgneal@312: checked : "checked", bgneal@312: disabled : "disabled", bgneal@312: maxlength : "maxLength", bgneal@312: readonly : "readOnly", bgneal@312: selected : "selected", bgneal@312: value : "value", bgneal@312: id : "id", bgneal@312: name : "name", bgneal@312: type : "type" bgneal@312: }, bgneal@312: bgneal@312: DOMUtils : function(d, s) { bgneal@312: var t = this, globalStyle; bgneal@312: bgneal@312: t.doc = d; bgneal@312: t.win = window; bgneal@312: t.files = {}; bgneal@312: t.cssFlicker = false; bgneal@312: t.counter = 0; bgneal@312: t.boxModel = !tinymce.isIE || d.compatMode == "CSS1Compat"; bgneal@312: t.stdMode = d.documentMode === 8; bgneal@312: bgneal@312: t.settings = s = tinymce.extend({ bgneal@312: keep_values : false, bgneal@312: hex_colors : 1, bgneal@312: process_html : 1 bgneal@312: }, s); bgneal@312: bgneal@312: // Fix IE6SP2 flicker and check it failed for pre SP2 bgneal@312: if (tinymce.isIE6) { bgneal@312: try { bgneal@312: d.execCommand('BackgroundImageCache', false, true); bgneal@312: } catch (e) { bgneal@312: t.cssFlicker = true; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Build styles list bgneal@312: if (s.valid_styles) { bgneal@312: t._styles = {}; bgneal@312: bgneal@312: // Convert styles into a rule list bgneal@312: each(s.valid_styles, function(value, key) { bgneal@312: t._styles[key] = tinymce.explode(value); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: tinymce.addUnload(t.destroy, t); bgneal@312: }, bgneal@312: bgneal@312: getRoot : function() { bgneal@312: var t = this, s = t.settings; bgneal@312: bgneal@312: return (s && t.get(s.root_element)) || t.doc.body; bgneal@312: }, bgneal@312: bgneal@312: getViewPort : function(w) { bgneal@312: var d, b; bgneal@312: bgneal@312: w = !w ? this.win : w; bgneal@312: d = w.document; bgneal@312: b = this.boxModel ? d.documentElement : d.body; bgneal@312: bgneal@312: // Returns viewport size excluding scrollbars bgneal@312: return { bgneal@312: x : w.pageXOffset || b.scrollLeft, bgneal@312: y : w.pageYOffset || b.scrollTop, bgneal@312: w : w.innerWidth || b.clientWidth, bgneal@312: h : w.innerHeight || b.clientHeight bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: getRect : function(e) { bgneal@312: var p, t = this, sr; bgneal@312: bgneal@312: e = t.get(e); bgneal@312: p = t.getPos(e); bgneal@312: sr = t.getSize(e); bgneal@312: bgneal@312: return { bgneal@312: x : p.x, bgneal@312: y : p.y, bgneal@312: w : sr.w, bgneal@312: h : sr.h bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: getSize : function(e) { bgneal@312: var t = this, w, h; bgneal@312: bgneal@312: e = t.get(e); bgneal@312: w = t.getStyle(e, 'width'); bgneal@312: h = t.getStyle(e, 'height'); bgneal@312: bgneal@312: // Non pixel value, then force offset/clientWidth bgneal@312: if (w.indexOf('px') === -1) bgneal@312: w = 0; bgneal@312: bgneal@312: // Non pixel value, then force offset/clientWidth bgneal@312: if (h.indexOf('px') === -1) bgneal@312: h = 0; bgneal@312: bgneal@312: return { bgneal@312: w : parseInt(w) || e.offsetWidth || e.clientWidth, bgneal@312: h : parseInt(h) || e.offsetHeight || e.clientHeight bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: getParent : function(n, f, r) { bgneal@312: return this.getParents(n, f, r, false); bgneal@312: }, bgneal@312: bgneal@312: getParents : function(n, f, r, c) { bgneal@312: var t = this, na, se = t.settings, o = []; bgneal@312: bgneal@312: n = t.get(n); bgneal@312: c = c === undefined; bgneal@312: bgneal@312: if (se.strict_root) bgneal@312: r = r || t.getRoot(); bgneal@312: bgneal@312: // Wrap node name as func bgneal@312: if (is(f, 'string')) { bgneal@312: na = f; bgneal@312: bgneal@312: if (f === '*') { bgneal@312: f = function(n) {return n.nodeType == 1;}; bgneal@312: } else { bgneal@312: f = function(n) { bgneal@312: return t.is(n, na); bgneal@312: }; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: while (n) { bgneal@312: if (n == r || !n.nodeType || n.nodeType === 9) bgneal@312: break; bgneal@312: bgneal@312: if (!f || f(n)) { bgneal@312: if (c) bgneal@312: o.push(n); bgneal@312: else bgneal@312: return n; bgneal@312: } bgneal@312: bgneal@312: n = n.parentNode; bgneal@312: } bgneal@312: bgneal@312: return c ? o : null; bgneal@312: }, bgneal@312: bgneal@312: get : function(e) { bgneal@312: var n; bgneal@312: bgneal@312: if (e && this.doc && typeof(e) == 'string') { bgneal@312: n = e; bgneal@312: e = this.doc.getElementById(e); bgneal@312: bgneal@312: // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick bgneal@312: if (e && e.id !== n) bgneal@312: return this.doc.getElementsByName(n)[1]; bgneal@312: } bgneal@312: bgneal@312: return e; bgneal@312: }, bgneal@312: bgneal@312: getNext : function(node, selector) { bgneal@312: return this._findSib(node, selector, 'nextSibling'); bgneal@312: }, bgneal@312: bgneal@312: getPrev : function(node, selector) { bgneal@312: return this._findSib(node, selector, 'previousSibling'); bgneal@312: }, bgneal@312: bgneal@312: bgneal@312: select : function(pa, s) { bgneal@312: var t = this; bgneal@312: bgneal@312: return tinymce.dom.Sizzle(pa, t.get(s) || t.get(t.settings.root_element) || t.doc, []); bgneal@312: }, bgneal@312: bgneal@312: is : function(n, selector) { bgneal@312: var i; bgneal@312: bgneal@312: // If it isn't an array then try to do some simple selectors instead of Sizzle for to boost performance bgneal@312: if (n.length === undefined) { bgneal@312: // Simple all selector bgneal@312: if (selector === '*') bgneal@312: return n.nodeType == 1; bgneal@312: bgneal@312: // Simple selector just elements bgneal@312: if (simpleSelectorRe.test(selector)) { bgneal@312: selector = selector.toLowerCase().split(/,/); bgneal@312: n = n.nodeName.toLowerCase(); bgneal@312: bgneal@312: for (i = selector.length - 1; i >= 0; i--) { bgneal@312: if (selector[i] == n) bgneal@312: return true; bgneal@312: } bgneal@312: bgneal@312: return false; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return tinymce.dom.Sizzle.matches(selector, n.nodeType ? [n] : n).length > 0; bgneal@312: }, bgneal@312: bgneal@312: bgneal@312: add : function(p, n, a, h, c) { bgneal@312: var t = this; bgneal@312: bgneal@312: return this.run(p, function(p) { bgneal@312: var e, k; bgneal@312: bgneal@312: e = is(n, 'string') ? t.doc.createElement(n) : n; bgneal@312: t.setAttribs(e, a); bgneal@312: bgneal@312: if (h) { bgneal@312: if (h.nodeType) bgneal@312: e.appendChild(h); bgneal@312: else bgneal@312: t.setHTML(e, h); bgneal@312: } bgneal@312: bgneal@312: return !c ? p.appendChild(e) : e; bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: create : function(n, a, h) { bgneal@312: return this.add(this.doc.createElement(n), n, a, h, 1); bgneal@312: }, bgneal@312: bgneal@312: createHTML : function(n, a, h) { bgneal@312: var o = '', t = this, k; bgneal@312: bgneal@312: o += '<' + n; bgneal@312: bgneal@312: for (k in a) { bgneal@312: if (a.hasOwnProperty(k)) bgneal@312: o += ' ' + k + '="' + t.encode(a[k]) + '"'; bgneal@312: } bgneal@312: bgneal@312: if (tinymce.is(h)) bgneal@312: return o + '>' + h + ''; bgneal@312: bgneal@312: return o + ' />'; bgneal@312: }, bgneal@312: bgneal@312: remove : function(node, keep_children) { bgneal@312: return this.run(node, function(node) { bgneal@312: var parent, child; bgneal@312: bgneal@312: parent = node.parentNode; bgneal@312: bgneal@312: if (!parent) bgneal@312: return null; bgneal@312: bgneal@312: if (keep_children) { bgneal@312: while (child = node.firstChild) { bgneal@312: // IE 8 will crash if you don't remove completely empty text nodes bgneal@312: if (!tinymce.isIE || child.nodeType !== 3 || child.nodeValue) bgneal@312: parent.insertBefore(child, node); bgneal@312: else bgneal@312: node.removeChild(child); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return parent.removeChild(node); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: setStyle : function(n, na, v) { bgneal@312: var t = this; bgneal@312: bgneal@312: return t.run(n, function(e) { bgneal@312: var s, i; bgneal@312: bgneal@312: s = e.style; bgneal@312: bgneal@312: // Camelcase it, if needed bgneal@312: na = na.replace(/-(\D)/g, function(a, b){ bgneal@312: return b.toUpperCase(); bgneal@312: }); bgneal@312: bgneal@312: // Default px suffix on these bgneal@312: if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v))) bgneal@312: v += 'px'; bgneal@312: bgneal@312: switch (na) { bgneal@312: case 'opacity': bgneal@312: // IE specific opacity bgneal@312: if (isIE) { bgneal@312: s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")"; bgneal@312: bgneal@312: if (!n.currentStyle || !n.currentStyle.hasLayout) bgneal@312: s.display = 'inline-block'; bgneal@312: } bgneal@312: bgneal@312: // Fix for older browsers bgneal@312: s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || ''; bgneal@312: break; bgneal@312: bgneal@312: case 'float': bgneal@312: isIE ? s.styleFloat = v : s.cssFloat = v; bgneal@312: break; bgneal@312: bgneal@312: default: bgneal@312: s[na] = v || ''; bgneal@312: } bgneal@312: bgneal@312: // Force update of the style data bgneal@312: if (t.settings.update_styles) bgneal@312: t.setAttrib(e, '_mce_style'); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: getStyle : function(n, na, c) { bgneal@312: n = this.get(n); bgneal@312: bgneal@312: if (!n) bgneal@312: return false; bgneal@312: bgneal@312: // Gecko bgneal@312: if (this.doc.defaultView && c) { bgneal@312: // Remove camelcase bgneal@312: na = na.replace(/[A-Z]/g, function(a){ bgneal@312: return '-' + a; bgneal@312: }); bgneal@312: bgneal@312: try { bgneal@312: return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na); bgneal@312: } catch (ex) { bgneal@312: // Old safari might fail bgneal@312: return null; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Camelcase it, if needed bgneal@312: na = na.replace(/-(\D)/g, function(a, b){ bgneal@312: return b.toUpperCase(); bgneal@312: }); bgneal@312: bgneal@312: if (na == 'float') bgneal@312: na = isIE ? 'styleFloat' : 'cssFloat'; bgneal@312: bgneal@312: // IE & Opera bgneal@312: if (n.currentStyle && c) bgneal@312: return n.currentStyle[na]; bgneal@312: bgneal@312: return n.style[na]; bgneal@312: }, bgneal@312: bgneal@312: setStyles : function(e, o) { bgneal@312: var t = this, s = t.settings, ol; bgneal@312: bgneal@312: ol = s.update_styles; bgneal@312: s.update_styles = 0; bgneal@312: bgneal@312: each(o, function(v, n) { bgneal@312: t.setStyle(e, n, v); bgneal@312: }); bgneal@312: bgneal@312: // Update style info bgneal@312: s.update_styles = ol; bgneal@312: if (s.update_styles) bgneal@312: t.setAttrib(e, s.cssText); bgneal@312: }, bgneal@312: bgneal@312: setAttrib : function(e, n, v) { bgneal@312: var t = this; bgneal@312: bgneal@312: // Whats the point bgneal@312: if (!e || !n) bgneal@312: return; bgneal@312: bgneal@312: // Strict XML mode bgneal@312: if (t.settings.strict) bgneal@312: n = n.toLowerCase(); bgneal@312: bgneal@312: return this.run(e, function(e) { bgneal@312: var s = t.settings; bgneal@312: bgneal@312: switch (n) { bgneal@312: case "style": bgneal@312: if (!is(v, 'string')) { bgneal@312: each(v, function(v, n) { bgneal@312: t.setStyle(e, n, v); bgneal@312: }); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // No mce_style for elements with these since they might get resized by the user bgneal@312: if (s.keep_values) { bgneal@312: if (v && !t._isRes(v)) bgneal@312: e.setAttribute('_mce_style', v, 2); bgneal@312: else bgneal@312: e.removeAttribute('_mce_style', 2); bgneal@312: } bgneal@312: bgneal@312: e.style.cssText = v; bgneal@312: break; bgneal@312: bgneal@312: case "class": bgneal@312: e.className = v || ''; // Fix IE null bug bgneal@312: break; bgneal@312: bgneal@312: case "src": bgneal@312: case "href": bgneal@312: if (s.keep_values) { bgneal@312: if (s.url_converter) bgneal@312: v = s.url_converter.call(s.url_converter_scope || t, v, n, e); bgneal@312: bgneal@312: t.setAttrib(e, '_mce_' + n, v, 2); bgneal@312: } bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case "shape": bgneal@312: e.setAttribute('_mce_style', v); bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: if (is(v) && v !== null && v.length !== 0) bgneal@312: e.setAttribute(n, '' + v, 2); bgneal@312: else bgneal@312: e.removeAttribute(n, 2); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: setAttribs : function(e, o) { bgneal@312: var t = this; bgneal@312: bgneal@312: return this.run(e, function(e) { bgneal@312: each(o, function(v, n) { bgneal@312: t.setAttrib(e, n, v); bgneal@312: }); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: getAttrib : function(e, n, dv) { bgneal@312: var v, t = this; bgneal@312: bgneal@312: e = t.get(e); bgneal@312: bgneal@312: if (!e || e.nodeType !== 1) bgneal@312: return false; bgneal@312: bgneal@312: if (!is(dv)) bgneal@312: dv = ''; bgneal@312: bgneal@312: // Try the mce variant for these bgneal@312: if (/^(src|href|style|coords|shape)$/.test(n)) { bgneal@312: v = e.getAttribute("_mce_" + n); bgneal@312: bgneal@312: if (v) bgneal@312: return v; bgneal@312: } bgneal@312: bgneal@312: if (isIE && t.props[n]) { bgneal@312: v = e[t.props[n]]; bgneal@312: v = v && v.nodeValue ? v.nodeValue : v; bgneal@312: } bgneal@312: bgneal@312: if (!v) bgneal@312: v = e.getAttribute(n, 2); bgneal@312: bgneal@312: // Check boolean attribs bgneal@312: if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(n)) { bgneal@312: if (e[t.props[n]] === true && v === '') bgneal@312: return n; bgneal@312: bgneal@312: return v ? n : ''; bgneal@312: } bgneal@312: bgneal@312: // Inner input elements will override attributes on form elements bgneal@312: if (e.nodeName === "FORM" && e.getAttributeNode(n)) bgneal@312: return e.getAttributeNode(n).nodeValue; bgneal@312: bgneal@312: if (n === 'style') { bgneal@312: v = v || e.style.cssText; bgneal@312: bgneal@312: if (v) { bgneal@312: v = t.serializeStyle(t.parseStyle(v), e.nodeName); bgneal@312: bgneal@312: if (t.settings.keep_values && !t._isRes(v)) bgneal@312: e.setAttribute('_mce_style', v); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Remove Apple and WebKit stuff bgneal@312: if (isWebKit && n === "class" && v) bgneal@312: v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, ''); bgneal@312: bgneal@312: // Handle IE issues bgneal@312: if (isIE) { bgneal@312: switch (n) { bgneal@312: case 'rowspan': bgneal@312: case 'colspan': bgneal@312: // IE returns 1 as default value bgneal@312: if (v === 1) bgneal@312: v = ''; bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case 'size': bgneal@312: // IE returns +0 as default value for size bgneal@312: if (v === '+0' || v === 20 || v === 0) bgneal@312: v = ''; bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case 'width': bgneal@312: case 'height': bgneal@312: case 'vspace': bgneal@312: case 'checked': bgneal@312: case 'disabled': bgneal@312: case 'readonly': bgneal@312: if (v === 0) bgneal@312: v = ''; bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case 'hspace': bgneal@312: // IE returns -1 as default value bgneal@312: if (v === -1) bgneal@312: v = ''; bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case 'maxlength': bgneal@312: case 'tabindex': bgneal@312: // IE returns default value bgneal@312: if (v === 32768 || v === 2147483647 || v === '32768') bgneal@312: v = ''; bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case 'multiple': bgneal@312: case 'compact': bgneal@312: case 'noshade': bgneal@312: case 'nowrap': bgneal@312: if (v === 65535) bgneal@312: return n; bgneal@312: bgneal@312: return dv; bgneal@312: bgneal@312: case 'shape': bgneal@312: v = v.toLowerCase(); bgneal@312: break; bgneal@312: bgneal@312: default: bgneal@312: // IE has odd anonymous function for event attributes bgneal@312: if (n.indexOf('on') === 0 && v) bgneal@312: v = ('' + v).replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1'); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return (v !== undefined && v !== null && v !== '') ? '' + v : dv; bgneal@312: }, bgneal@312: bgneal@312: getPos : function(n, ro) { bgneal@312: var t = this, x = 0, y = 0, e, d = t.doc, r; bgneal@312: bgneal@312: n = t.get(n); bgneal@312: ro = ro || d.body; bgneal@312: bgneal@312: if (n) { bgneal@312: // Use getBoundingClientRect on IE, Opera has it but it's not perfect bgneal@312: if (isIE && !t.stdMode) { bgneal@312: n = n.getBoundingClientRect(); bgneal@312: e = t.boxModel ? d.documentElement : d.body; bgneal@312: x = t.getStyle(t.select('html')[0], 'borderWidth'); // Remove border bgneal@312: x = (x == 'medium' || t.boxModel && !t.isIE6) && 2 || x; bgneal@312: bgneal@312: return {x : n.left + e.scrollLeft - x, y : n.top + e.scrollTop - x}; bgneal@312: } bgneal@312: bgneal@312: r = n; bgneal@312: while (r && r != ro && r.nodeType) { bgneal@312: x += r.offsetLeft || 0; bgneal@312: y += r.offsetTop || 0; bgneal@312: r = r.offsetParent; bgneal@312: } bgneal@312: bgneal@312: r = n.parentNode; bgneal@312: while (r && r != ro && r.nodeType) { bgneal@312: x -= r.scrollLeft || 0; bgneal@312: y -= r.scrollTop || 0; bgneal@312: r = r.parentNode; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return {x : x, y : y}; bgneal@312: }, bgneal@312: bgneal@312: parseStyle : function(st) { bgneal@312: var t = this, s = t.settings, o = {}; bgneal@312: bgneal@312: if (!st) bgneal@312: return o; bgneal@312: bgneal@312: function compress(p, s, ot) { bgneal@312: var t, r, b, l; bgneal@312: bgneal@312: // Get values and check it it needs compressing bgneal@312: t = o[p + '-top' + s]; bgneal@312: if (!t) bgneal@312: return; bgneal@312: bgneal@312: r = o[p + '-right' + s]; bgneal@312: if (t != r) bgneal@312: return; bgneal@312: bgneal@312: b = o[p + '-bottom' + s]; bgneal@312: if (r != b) bgneal@312: return; bgneal@312: bgneal@312: l = o[p + '-left' + s]; bgneal@312: if (b != l) bgneal@312: return; bgneal@312: bgneal@312: // Compress bgneal@312: o[ot] = l; bgneal@312: delete o[p + '-top' + s]; bgneal@312: delete o[p + '-right' + s]; bgneal@312: delete o[p + '-bottom' + s]; bgneal@312: delete o[p + '-left' + s]; bgneal@312: }; bgneal@312: bgneal@312: function compress2(ta, a, b, c) { bgneal@312: var t; bgneal@312: bgneal@312: t = o[a]; bgneal@312: if (!t) bgneal@312: return; bgneal@312: bgneal@312: t = o[b]; bgneal@312: if (!t) bgneal@312: return; bgneal@312: bgneal@312: t = o[c]; bgneal@312: if (!t) bgneal@312: return; bgneal@312: bgneal@312: // Compress bgneal@312: o[ta] = o[a] + ' ' + o[b] + ' ' + o[c]; bgneal@312: delete o[a]; bgneal@312: delete o[b]; bgneal@312: delete o[c]; bgneal@312: }; bgneal@312: bgneal@312: st = st.replace(/&(#?[a-z0-9]+);/g, '&$1_MCE_SEMI_'); // Protect entities bgneal@312: bgneal@312: each(st.split(';'), function(v) { bgneal@312: var sv, ur = []; bgneal@312: bgneal@312: if (v) { bgneal@312: v = v.replace(/_MCE_SEMI_/g, ';'); // Restore entities bgneal@312: v = v.replace(/url\([^\)]+\)/g, function(v) {ur.push(v);return 'url(' + ur.length + ')';}); bgneal@312: v = v.split(':'); bgneal@312: sv = tinymce.trim(v[1]); bgneal@312: sv = sv.replace(/url\(([^\)]+)\)/g, function(a, b) {return ur[parseInt(b) - 1];}); bgneal@312: bgneal@312: sv = sv.replace(/rgb\([^\)]+\)/g, function(v) { bgneal@312: return t.toHex(v); bgneal@312: }); bgneal@312: bgneal@312: if (s.url_converter) { bgneal@312: sv = sv.replace(/url\([\'\"]?([^\)\'\"]+)[\'\"]?\)/g, function(x, c) { bgneal@312: return 'url(' + s.url_converter.call(s.url_converter_scope || t, t.decode(c), 'style', null) + ')'; bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: o[tinymce.trim(v[0]).toLowerCase()] = sv; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: compress("border", "", "border"); bgneal@312: compress("border", "-width", "border-width"); bgneal@312: compress("border", "-color", "border-color"); bgneal@312: compress("border", "-style", "border-style"); bgneal@312: compress("padding", "", "padding"); bgneal@312: compress("margin", "", "margin"); bgneal@312: compress2('border', 'border-width', 'border-style', 'border-color'); bgneal@312: bgneal@312: if (isIE) { bgneal@312: // Remove pointless border bgneal@312: if (o.border == 'medium none') bgneal@312: o.border = ''; bgneal@312: } bgneal@312: bgneal@312: return o; bgneal@312: }, bgneal@312: bgneal@312: serializeStyle : function(o, name) { bgneal@312: var t = this, s = ''; bgneal@312: bgneal@312: function add(v, k) { bgneal@312: if (k && v) { bgneal@312: // Remove browser specific styles like -moz- or -webkit- bgneal@312: if (k.indexOf('-') === 0) bgneal@312: return; bgneal@312: bgneal@312: switch (k) { bgneal@312: case 'font-weight': bgneal@312: // Opera will output bold as 700 bgneal@312: if (v == 700) bgneal@312: v = 'bold'; bgneal@312: bgneal@312: break; bgneal@312: bgneal@312: case 'color': bgneal@312: case 'background-color': bgneal@312: v = v.toLowerCase(); bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: s += (s ? ' ' : '') + k + ': ' + v + ';'; bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: // Validate style output bgneal@312: if (name && t._styles) { bgneal@312: each(t._styles['*'], function(name) { bgneal@312: add(o[name], name); bgneal@312: }); bgneal@312: bgneal@312: each(t._styles[name.toLowerCase()], function(name) { bgneal@312: add(o[name], name); bgneal@312: }); bgneal@312: } else bgneal@312: each(o, add); bgneal@312: bgneal@312: return s; bgneal@312: }, bgneal@312: bgneal@312: loadCSS : function(u) { bgneal@312: var t = this, d = t.doc, head; bgneal@312: bgneal@312: if (!u) bgneal@312: u = ''; bgneal@312: bgneal@312: head = t.select('head')[0]; bgneal@312: bgneal@312: each(u.split(','), function(u) { bgneal@312: var link; bgneal@312: bgneal@312: if (t.files[u]) bgneal@312: return; bgneal@312: bgneal@312: t.files[u] = true; bgneal@312: link = t.create('link', {rel : 'stylesheet', href : tinymce._addVer(u)}); bgneal@312: bgneal@312: // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug bgneal@312: // This fix seems to resolve that issue by realcing the document ones a stylesheet finishes loading bgneal@312: // It's ugly but it seems to work fine. bgneal@312: if (isIE && d.documentMode) { bgneal@312: link.onload = function() { bgneal@312: d.recalc(); bgneal@312: link.onload = null; bgneal@312: }; bgneal@312: } bgneal@312: bgneal@312: head.appendChild(link); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: addClass : function(e, c) { bgneal@312: return this.run(e, function(e) { bgneal@312: var o; bgneal@312: bgneal@312: if (!c) bgneal@312: return 0; bgneal@312: bgneal@312: if (this.hasClass(e, c)) bgneal@312: return e.className; bgneal@312: bgneal@312: o = this.removeClass(e, c); bgneal@312: bgneal@312: return e.className = (o != '' ? (o + ' ') : '') + c; bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: removeClass : function(e, c) { bgneal@312: var t = this, re; bgneal@312: bgneal@312: return t.run(e, function(e) { bgneal@312: var v; bgneal@312: bgneal@312: if (t.hasClass(e, c)) { bgneal@312: if (!re) bgneal@312: re = new RegExp("(^|\\s+)" + c + "(\\s+|$)", "g"); bgneal@312: bgneal@312: v = e.className.replace(re, ' '); bgneal@312: v = tinymce.trim(v != ' ' ? v : ''); bgneal@312: bgneal@312: e.className = v; bgneal@312: bgneal@312: // Empty class attr bgneal@312: if (!v) { bgneal@312: e.removeAttribute('class'); bgneal@312: e.removeAttribute('className'); bgneal@312: } bgneal@312: bgneal@312: return v; bgneal@312: } bgneal@312: bgneal@312: return e.className; bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: hasClass : function(n, c) { bgneal@312: n = this.get(n); bgneal@312: bgneal@312: if (!n || !c) bgneal@312: return false; bgneal@312: bgneal@312: return (' ' + n.className + ' ').indexOf(' ' + c + ' ') !== -1; bgneal@312: }, bgneal@312: bgneal@312: show : function(e) { bgneal@312: return this.setStyle(e, 'display', 'block'); bgneal@312: }, bgneal@312: bgneal@312: hide : function(e) { bgneal@312: return this.setStyle(e, 'display', 'none'); bgneal@312: }, bgneal@312: bgneal@312: isHidden : function(e) { bgneal@312: e = this.get(e); bgneal@312: bgneal@312: return !e || e.style.display == 'none' || this.getStyle(e, 'display') == 'none'; bgneal@312: }, bgneal@312: bgneal@312: uniqueId : function(p) { bgneal@312: return (!p ? 'mce_' : p) + (this.counter++); bgneal@312: }, bgneal@312: bgneal@312: setHTML : function(e, h) { bgneal@312: var t = this; bgneal@312: bgneal@312: return this.run(e, function(e) { bgneal@312: var x, i, nl, n, p, x; bgneal@312: bgneal@312: h = t.processHTML(h); bgneal@312: bgneal@312: if (isIE) { bgneal@312: function set() { bgneal@312: // Remove all child nodes bgneal@312: while (e.firstChild) bgneal@312: e.firstChild.removeNode(); bgneal@312: bgneal@312: try { bgneal@312: // IE will remove comments from the beginning bgneal@312: // unless you padd the contents with something bgneal@312: e.innerHTML = '
' + h; bgneal@312: e.removeChild(e.firstChild); bgneal@312: } catch (ex) { bgneal@312: // 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@312: // This seems to fix this problem bgneal@312: bgneal@312: // Create new div with HTML contents and a BR infront to keep comments bgneal@312: x = t.create('div'); bgneal@312: x.innerHTML = '
' + h; bgneal@312: bgneal@312: // Add all children from div to target bgneal@312: each (x.childNodes, function(n, i) { bgneal@312: // Skip br element bgneal@312: if (i) bgneal@312: e.appendChild(n); bgneal@312: }); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: // IE has a serious bug when it comes to paragraphs it can produce an invalid bgneal@312: // DOM tree if contents like this

  • Item 1

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

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

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

]+)>|

/ig, '

'); bgneal@312: h = h.replace(/<\/p>/gi, '
'); bgneal@312: bgneal@312: // Set the new HTML with DIVs bgneal@312: set(); bgneal@312: bgneal@312: // Replace all DIV elements with the _mce_tmp attibute back to paragraphs bgneal@312: // This is needed since IE has a annoying bug see above for details bgneal@312: // This is a slow process but it has to be done. :( bgneal@312: if (t.settings.fix_ie_paragraphs) { bgneal@312: nl = e.getElementsByTagName("DIV"); bgneal@312: for (i = nl.length - 1; i >= 0; i--) { bgneal@312: n = nl[i]; bgneal@312: bgneal@312: // Is it a temp div bgneal@312: if (n._mce_tmp) { bgneal@312: // Create new paragraph bgneal@312: p = t.doc.createElement('p'); bgneal@312: bgneal@312: // Copy all attributes bgneal@312: n.cloneNode(false).outerHTML.replace(/([a-z0-9\-_]+)=/gi, function(a, b) { bgneal@312: var v; bgneal@312: bgneal@312: if (b !== '_mce_tmp') { bgneal@312: v = n.getAttribute(b); bgneal@312: bgneal@312: if (!v && b === 'class') bgneal@312: v = n.className; bgneal@312: bgneal@312: p.setAttribute(b, v); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: // Append all children to new paragraph bgneal@312: for (x = 0; x]+)\/>|/gi, ''); // Force open bgneal@312: bgneal@312: // Store away src and href in _mce_src and mce_href since browsers mess them up bgneal@312: if (s.keep_values) { bgneal@312: // Wrap scripts and styles in comments for serialization purposes bgneal@312: if (/)/g, '\n'); bgneal@312: s = s.replace(/^[\r\n]*|[\r\n]*$/g, ''); bgneal@312: s = s.replace(/^\s*(\/\/\s*|\]\]>|-->|\]\]-->)\s*$/g, ''); bgneal@312: bgneal@312: return s; bgneal@312: }; bgneal@312: bgneal@312: // Wrap the script contents in CDATA and keep them from executing bgneal@312: h = h.replace(/]+|)>([\s\S]*?)<\/script>/gi, function(v, attribs, text) { bgneal@312: // Force type attribute bgneal@312: if (!attribs) bgneal@312: attribs = ' type="text/javascript"'; bgneal@312: bgneal@312: // Convert the src attribute of the scripts bgneal@312: attribs = attribs.replace(/src=\"([^\"]+)\"?/i, function(a, url) { bgneal@312: if (s.url_converter) bgneal@312: url = t.encode(s.url_converter.call(s.url_converter_scope || t, t.decode(url), 'src', 'script')); bgneal@312: bgneal@312: return '_mce_src="' + url + '"'; bgneal@312: }); bgneal@312: bgneal@312: // Wrap text contents bgneal@312: if (tinymce.trim(text)) { bgneal@312: codeBlocks.push(trim(text)); bgneal@312: text = ''; bgneal@312: } bgneal@312: bgneal@312: return '' + text + ''; bgneal@312: }); bgneal@312: bgneal@312: // Wrap style elements bgneal@312: h = h.replace(/]+|)>([\s\S]*?)<\/style>/gi, function(v, attribs, text) { bgneal@312: // Wrap text contents bgneal@312: if (text) { bgneal@312: codeBlocks.push(trim(text)); bgneal@312: text = ''; bgneal@312: } bgneal@312: bgneal@312: return '' + text + ''; bgneal@312: }); bgneal@312: bgneal@312: // Wrap noscript elements bgneal@312: h = h.replace(/]+|)>([\s\S]*?)<\/noscript>/g, function(v, attribs, text) { bgneal@312: return ''; bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: h = h.replace(//g, ''); bgneal@312: bgneal@312: // This function processes the attributes in the HTML string to force boolean bgneal@312: // attributes to the attr="attr" format and convert style, src and href to _mce_ versions bgneal@312: function processTags(html) { bgneal@312: return html.replace(tagRegExp, function(match, elm_name, attrs, end) { bgneal@312: return '<' + elm_name + attrs.replace(attrRegExp, function(match, name, value, val2, val3) { bgneal@312: var mceValue; bgneal@312: bgneal@312: name = name.toLowerCase(); bgneal@312: value = value || val2 || val3 || ""; bgneal@312: bgneal@312: // Treat boolean attributes bgneal@312: if (boolAttrs[name]) { bgneal@312: // false or 0 is treated as a missing attribute bgneal@312: if (value === 'false' || value === '0') bgneal@312: return; bgneal@312: bgneal@312: return name + '="' + name + '"'; bgneal@312: } bgneal@312: bgneal@312: // Is attribute one that needs special treatment bgneal@312: if (mceAttribs[name] && attrs.indexOf('_mce_' + name) == -1) { bgneal@312: mceValue = t.decode(value); bgneal@312: bgneal@312: // Convert URLs to relative/absolute ones bgneal@312: if (s.url_converter && (name == "src" || name == "href")) bgneal@312: mceValue = s.url_converter.call(s.url_converter_scope || t, mceValue, name, elm_name); bgneal@312: bgneal@312: // Process styles lowercases them and compresses them bgneal@312: if (name == 'style') bgneal@312: mceValue = t.serializeStyle(t.parseStyle(mceValue), name); bgneal@312: bgneal@312: return name + '="' + value + '"' + ' _mce_' + name + '="' + t.encode(mceValue) + '"'; bgneal@312: } bgneal@312: bgneal@312: return match; bgneal@312: }) + end + '>'; bgneal@312: }); bgneal@312: }; bgneal@312: bgneal@312: h = processTags(h); bgneal@312: bgneal@312: // Restore script blocks bgneal@312: h = h.replace(/MCE_SCRIPT:([0-9]+)/g, function(val, idx) { bgneal@312: return codeBlocks[idx]; bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: return h; bgneal@312: }, bgneal@312: bgneal@312: getOuterHTML : function(e) { bgneal@312: var d; bgneal@312: bgneal@312: e = this.get(e); bgneal@312: bgneal@312: if (!e) bgneal@312: return null; bgneal@312: bgneal@312: if (e.outerHTML !== undefined) bgneal@312: return e.outerHTML; bgneal@312: bgneal@312: d = (e.ownerDocument || this.doc).createElement("body"); bgneal@312: d.appendChild(e.cloneNode(true)); bgneal@312: bgneal@312: return d.innerHTML; bgneal@312: }, bgneal@312: bgneal@312: setOuterHTML : function(e, h, d) { bgneal@312: var t = this; bgneal@312: bgneal@312: function setHTML(e, h, d) { bgneal@312: var n, tp; bgneal@312: bgneal@312: tp = d.createElement("body"); bgneal@312: tp.innerHTML = h; bgneal@312: bgneal@312: n = tp.lastChild; bgneal@312: while (n) { bgneal@312: t.insertAfter(n.cloneNode(true), e); bgneal@312: n = n.previousSibling; bgneal@312: } bgneal@312: bgneal@312: t.remove(e); bgneal@312: }; bgneal@312: bgneal@312: return this.run(e, function(e) { bgneal@312: e = t.get(e); bgneal@312: bgneal@312: // Only set HTML on elements bgneal@312: if (e.nodeType == 1) { bgneal@312: d = d || e.ownerDocument || t.doc; bgneal@312: bgneal@312: if (isIE) { bgneal@312: try { bgneal@312: // Try outerHTML for IE it sometimes produces an unknown runtime error bgneal@312: if (isIE && e.nodeType == 1) bgneal@312: e.outerHTML = h; bgneal@312: else bgneal@312: setHTML(e, h, d); bgneal@312: } catch (ex) { bgneal@312: // Fix for unknown runtime error bgneal@312: setHTML(e, h, d); bgneal@312: } bgneal@312: } else bgneal@312: setHTML(e, h, d); bgneal@312: } bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: decode : function(s) { bgneal@312: var e, n, v; bgneal@312: bgneal@312: // Look for entities to decode bgneal@312: if (/&[\w#]+;/.test(s)) { bgneal@312: // Decode the entities using a div element not super efficient but less code bgneal@312: e = this.doc.createElement("div"); bgneal@312: e.innerHTML = s; bgneal@312: n = e.firstChild; bgneal@312: v = ''; bgneal@312: bgneal@312: if (n) { bgneal@312: do { bgneal@312: v += n.nodeValue; bgneal@312: } while (n = n.nextSibling); bgneal@312: } bgneal@312: bgneal@312: return v || s; bgneal@312: } bgneal@312: bgneal@312: return s; bgneal@312: }, bgneal@312: bgneal@312: encode : function(str) { bgneal@312: return ('' + str).replace(encodeCharsRe, function(chr) { bgneal@312: return encodedChars[chr]; bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: insertAfter : function(node, reference_node) { bgneal@312: reference_node = this.get(reference_node); bgneal@312: bgneal@312: return this.run(node, function(node) { bgneal@312: var parent, nextSibling; bgneal@312: bgneal@312: parent = reference_node.parentNode; bgneal@312: nextSibling = reference_node.nextSibling; bgneal@312: bgneal@312: if (nextSibling) bgneal@312: parent.insertBefore(node, nextSibling); bgneal@312: else bgneal@312: parent.appendChild(node); bgneal@312: bgneal@312: return node; bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: isBlock : function(n) { bgneal@312: if (n.nodeType && n.nodeType !== 1) bgneal@312: return false; bgneal@312: bgneal@312: n = n.nodeName || n; bgneal@312: bgneal@312: return blockRe.test(n); bgneal@312: }, bgneal@312: bgneal@312: replace : function(n, o, k) { bgneal@312: var t = this; bgneal@312: bgneal@312: if (is(o, 'array')) bgneal@312: n = n.cloneNode(true); bgneal@312: bgneal@312: return t.run(o, function(o) { bgneal@312: if (k) { bgneal@312: each(tinymce.grep(o.childNodes), function(c) { bgneal@312: n.appendChild(c); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: return o.parentNode.replaceChild(n, o); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: rename : function(elm, name) { bgneal@312: var t = this, newElm; bgneal@312: bgneal@312: if (elm.nodeName != name.toUpperCase()) { bgneal@312: // Rename block element bgneal@312: newElm = t.create(name); bgneal@312: bgneal@312: // Copy attribs to new block bgneal@312: each(t.getAttribs(elm), function(attr_node) { bgneal@312: t.setAttrib(newElm, attr_node.nodeName, t.getAttrib(elm, attr_node.nodeName)); bgneal@312: }); bgneal@312: bgneal@312: // Replace block bgneal@312: t.replace(newElm, elm, 1); bgneal@312: } bgneal@312: bgneal@312: return newElm || elm; bgneal@312: }, bgneal@312: bgneal@312: findCommonAncestor : function(a, b) { bgneal@312: var ps = a, pe; bgneal@312: bgneal@312: while (ps) { bgneal@312: pe = b; bgneal@312: bgneal@312: while (pe && ps != pe) bgneal@312: pe = pe.parentNode; bgneal@312: bgneal@312: if (ps == pe) bgneal@312: break; bgneal@312: bgneal@312: ps = ps.parentNode; bgneal@312: } bgneal@312: bgneal@312: if (!ps && a.ownerDocument) bgneal@312: return a.ownerDocument.documentElement; bgneal@312: bgneal@312: return ps; bgneal@312: }, bgneal@312: bgneal@312: toHex : function(s) { bgneal@312: var c = /^\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*$/i.exec(s); bgneal@312: bgneal@312: function hex(s) { bgneal@312: s = parseInt(s).toString(16); bgneal@312: bgneal@312: return s.length > 1 ? s : '0' + s; // 0 -> 00 bgneal@312: }; bgneal@312: bgneal@312: if (c) { bgneal@312: s = '#' + hex(c[1]) + hex(c[2]) + hex(c[3]); bgneal@312: bgneal@312: return s; bgneal@312: } bgneal@312: bgneal@312: return s; bgneal@312: }, bgneal@312: bgneal@312: getClasses : function() { bgneal@312: var t = this, cl = [], i, lo = {}, f = t.settings.class_filter, ov; bgneal@312: bgneal@312: if (t.classes) bgneal@312: return t.classes; bgneal@312: bgneal@312: function addClasses(s) { bgneal@312: // IE style imports bgneal@312: each(s.imports, function(r) { bgneal@312: addClasses(r); bgneal@312: }); bgneal@312: bgneal@312: each(s.cssRules || s.rules, function(r) { bgneal@312: // Real type or fake it on IE bgneal@312: switch (r.type || 1) { bgneal@312: // Rule bgneal@312: case 1: bgneal@312: if (r.selectorText) { bgneal@312: each(r.selectorText.split(','), function(v) { bgneal@312: v = v.replace(/^\s*|\s*$|^\s\./g, ""); bgneal@312: bgneal@312: // Is internal or it doesn't contain a class bgneal@312: if (/\.mce/.test(v) || !/\.[\w\-]+$/.test(v)) bgneal@312: return; bgneal@312: bgneal@312: // Remove everything but class name bgneal@312: ov = v; bgneal@312: v = v.replace(/.*\.([a-z0-9_\-]+).*/i, '$1'); bgneal@312: bgneal@312: // Filter classes bgneal@312: if (f && !(v = f(v, ov))) bgneal@312: return; bgneal@312: bgneal@312: if (!lo[v]) { bgneal@312: cl.push({'class' : v}); bgneal@312: lo[v] = 1; bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: break; bgneal@312: bgneal@312: // Import bgneal@312: case 3: bgneal@312: addClasses(r.styleSheet); bgneal@312: break; bgneal@312: } bgneal@312: }); bgneal@312: }; bgneal@312: bgneal@312: try { bgneal@312: each(t.doc.styleSheets, addClasses); bgneal@312: } catch (ex) { bgneal@312: // Ignore bgneal@312: } bgneal@312: bgneal@312: if (cl.length > 0) bgneal@312: t.classes = cl; bgneal@312: bgneal@312: return cl; bgneal@312: }, bgneal@312: bgneal@312: run : function(e, f, s) { bgneal@312: var t = this, o; bgneal@312: bgneal@312: if (t.doc && typeof(e) === 'string') bgneal@312: e = t.get(e); bgneal@312: bgneal@312: if (!e) bgneal@312: return false; bgneal@312: bgneal@312: s = s || this; bgneal@312: if (!e.nodeType && (e.length || e.length === 0)) { bgneal@312: o = []; bgneal@312: bgneal@312: each(e, function(e, i) { bgneal@312: if (e) { bgneal@312: if (typeof(e) == 'string') bgneal@312: e = t.doc.getElementById(e); bgneal@312: bgneal@312: o.push(f.call(s, e, i)); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: return o; bgneal@312: } bgneal@312: bgneal@312: return f.call(s, e); bgneal@312: }, bgneal@312: bgneal@312: getAttribs : function(n) { bgneal@312: var o; bgneal@312: bgneal@312: n = this.get(n); bgneal@312: bgneal@312: if (!n) bgneal@312: return []; bgneal@312: bgneal@312: if (isIE) { bgneal@312: o = []; bgneal@312: bgneal@312: // Object will throw exception in IE bgneal@312: if (n.nodeName == 'OBJECT') bgneal@312: return n.attributes; bgneal@312: bgneal@312: // IE doesn't keep the selected attribute if you clone option elements bgneal@312: if (n.nodeName === 'OPTION' && this.getAttrib(n, 'selected')) bgneal@312: o.push({specified : 1, nodeName : 'selected'}); bgneal@312: bgneal@312: // It's crazy that this is faster in IE but it's because it returns all attributes all the time bgneal@312: n.cloneNode(false).outerHTML.replace(/<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi, '').replace(/[\w:\-]+/gi, function(a) { bgneal@312: o.push({specified : 1, nodeName : a}); bgneal@312: }); bgneal@312: bgneal@312: return o; bgneal@312: } bgneal@312: bgneal@312: return n.attributes; bgneal@312: }, bgneal@312: bgneal@312: destroy : function(s) { bgneal@312: var t = this; bgneal@312: bgneal@312: if (t.events) bgneal@312: t.events.destroy(); bgneal@312: bgneal@312: t.win = t.doc = t.root = t.events = null; bgneal@312: bgneal@312: // Manual destroy then remove unload handler bgneal@312: if (!s) bgneal@312: tinymce.removeUnload(t.destroy); bgneal@312: }, bgneal@312: bgneal@312: createRng : function() { bgneal@312: var d = this.doc; bgneal@312: bgneal@312: return d.createRange ? d.createRange() : new tinymce.dom.Range(this); bgneal@312: }, bgneal@312: bgneal@312: nodeIndex : function(node, normalized) { bgneal@312: var idx = 0, lastNodeType, lastNode, nodeType; bgneal@312: bgneal@312: if (node) { bgneal@312: for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) { bgneal@312: nodeType = node.nodeType; bgneal@312: bgneal@312: // Normalize text nodes bgneal@312: if (normalized && nodeType == 3) { bgneal@312: if (nodeType == lastNodeType || !node.nodeValue.length) bgneal@312: continue; bgneal@312: } bgneal@312: bgneal@312: idx++; bgneal@312: lastNodeType = nodeType; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: return idx; bgneal@312: }, bgneal@312: bgneal@312: split : function(pe, e, re) { bgneal@312: var t = this, r = t.createRng(), bef, aft, pa; bgneal@312: bgneal@312: // W3C valid browsers tend to leave empty nodes to the left/right side of the contents, this makes sense bgneal@312: // but we don't want that in our code since it serves no purpose for the end user bgneal@312: // For example if this is chopped: bgneal@312: //

text 1CHOPtext 2

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

text 1

CHOP

text 2

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

text 1

CHOP

text 2

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

"; bgneal@312: bgneal@312: // Safari can't handle uppercase or unicode characters when bgneal@312: // in quirks mode. bgneal@312: if ( div.querySelectorAll && div.querySelectorAll(".TEST").length === 0 ) { bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: Sizzle = function(query, context, extra, seed){ bgneal@312: context = context || document; bgneal@312: bgneal@312: // Only use querySelectorAll on non-XML documents bgneal@312: // (ID selectors don't work in non-HTML documents) bgneal@312: if ( !seed && context.nodeType === 9 && !Sizzle.isXML(context) ) { bgneal@312: try { bgneal@312: return makeArray( context.querySelectorAll(query), extra ); bgneal@312: } catch(e){} bgneal@312: } bgneal@312: bgneal@312: return oldSizzle(query, context, extra, seed); bgneal@312: }; bgneal@312: bgneal@312: for ( var prop in oldSizzle ) { bgneal@312: Sizzle[ prop ] = oldSizzle[ prop ]; bgneal@312: } bgneal@312: bgneal@312: div = null; // release memory in IE bgneal@312: })(); bgneal@312: } bgneal@312: bgneal@312: (function(){ bgneal@312: var div = document.createElement("div"); bgneal@312: bgneal@312: div.innerHTML = "
"; bgneal@312: bgneal@312: // Opera can't find a second classname (in 9.6) bgneal@312: // Also, make sure that getElementsByClassName actually exists bgneal@312: if ( !div.getElementsByClassName || div.getElementsByClassName("e").length === 0 ) { bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Safari caches class attributes, doesn't catch changes (in 3.2) bgneal@312: div.lastChild.className = "e"; bgneal@312: bgneal@312: if ( div.getElementsByClassName("e").length === 1 ) { bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: Expr.order.splice(1, 0, "CLASS"); bgneal@312: Expr.find.CLASS = function(match, context, isXML) { bgneal@312: if ( typeof context.getElementsByClassName !== "undefined" && !isXML ) { bgneal@312: return context.getElementsByClassName(match[1]); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: div = null; // release memory in IE bgneal@312: })(); bgneal@312: bgneal@312: function dirNodeCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { bgneal@312: for ( var i = 0, l = checkSet.length; i < l; i++ ) { bgneal@312: var elem = checkSet[i]; bgneal@312: if ( elem ) { bgneal@312: elem = elem[dir]; bgneal@312: var match = false; bgneal@312: bgneal@312: while ( elem ) { bgneal@312: if ( elem.sizcache === doneName ) { bgneal@312: match = checkSet[elem.sizset]; bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: if ( elem.nodeType === 1 && !isXML ){ bgneal@312: elem.sizcache = doneName; bgneal@312: elem.sizset = i; bgneal@312: } bgneal@312: bgneal@312: if ( elem.nodeName.toLowerCase() === cur ) { bgneal@312: match = elem; bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: elem = elem[dir]; bgneal@312: } bgneal@312: bgneal@312: checkSet[i] = match; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: function dirCheck( dir, cur, doneName, checkSet, nodeCheck, isXML ) { bgneal@312: for ( var i = 0, l = checkSet.length; i < l; i++ ) { bgneal@312: var elem = checkSet[i]; bgneal@312: if ( elem ) { bgneal@312: elem = elem[dir]; bgneal@312: var match = false; bgneal@312: bgneal@312: while ( elem ) { bgneal@312: if ( elem.sizcache === doneName ) { bgneal@312: match = checkSet[elem.sizset]; bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: if ( elem.nodeType === 1 ) { bgneal@312: if ( !isXML ) { bgneal@312: elem.sizcache = doneName; bgneal@312: elem.sizset = i; bgneal@312: } bgneal@312: if ( typeof cur !== "string" ) { bgneal@312: if ( elem === cur ) { bgneal@312: match = true; bgneal@312: break; bgneal@312: } bgneal@312: bgneal@312: } else if ( Sizzle.filter( cur, [elem] ).length > 0 ) { bgneal@312: match = elem; bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: elem = elem[dir]; bgneal@312: } bgneal@312: bgneal@312: checkSet[i] = match; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: Sizzle.contains = document.compareDocumentPosition ? function(a, b){ bgneal@312: return !!(a.compareDocumentPosition(b) & 16); bgneal@312: } : function(a, b){ bgneal@312: return a !== b && (a.contains ? a.contains(b) : true); bgneal@312: }; bgneal@312: bgneal@312: Sizzle.isXML = function(elem){ bgneal@312: // documentElement is verified for cases where it doesn't yet exist bgneal@312: // (such as loading iframes in IE - #4833) bgneal@312: var documentElement = (elem ? elem.ownerDocument || elem : 0).documentElement; bgneal@312: return documentElement ? documentElement.nodeName !== "HTML" : false; bgneal@312: }; bgneal@312: bgneal@312: var posProcess = function(selector, context){ bgneal@312: var tmpSet = [], later = "", match, bgneal@312: root = context.nodeType ? [context] : context; bgneal@312: bgneal@312: // Position selectors must be done after the filter bgneal@312: // And so must :not(positional) so we move all PSEUDOs to the end bgneal@312: while ( (match = Expr.match.PSEUDO.exec( selector )) ) { bgneal@312: later += match[0]; bgneal@312: selector = selector.replace( Expr.match.PSEUDO, "" ); bgneal@312: } bgneal@312: bgneal@312: selector = Expr.relative[selector] ? selector + "*" : selector; bgneal@312: bgneal@312: for ( var i = 0, l = root.length; i < l; i++ ) { bgneal@312: Sizzle( selector, root[i], tmpSet ); bgneal@312: } bgneal@312: bgneal@312: return Sizzle.filter( later, tmpSet ); bgneal@312: }; bgneal@312: bgneal@312: // EXPOSE bgneal@312: bgneal@312: window.tinymce.dom.Sizzle = Sizzle; bgneal@312: bgneal@312: })(); bgneal@312: bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: // Shorten names bgneal@312: var each = tinymce.each, DOM = tinymce.DOM, isIE = tinymce.isIE, isWebKit = tinymce.isWebKit, Event; bgneal@312: bgneal@312: tinymce.create('tinymce.dom.EventUtils', { bgneal@312: EventUtils : function() { bgneal@312: this.inits = []; bgneal@312: this.events = []; bgneal@312: }, bgneal@312: bgneal@312: add : function(o, n, f, s) { bgneal@312: var cb, t = this, el = t.events, r; bgneal@312: bgneal@312: if (n instanceof Array) { bgneal@312: r = []; bgneal@312: bgneal@312: each(n, function(n) { bgneal@312: r.push(t.add(o, n, f, s)); bgneal@312: }); bgneal@312: bgneal@312: return r; bgneal@312: } bgneal@312: bgneal@312: // Handle array bgneal@312: if (o && o.hasOwnProperty && o instanceof Array) { bgneal@312: r = []; bgneal@312: bgneal@312: each(o, function(o) { bgneal@312: o = DOM.get(o); bgneal@312: r.push(t.add(o, n, f, s)); bgneal@312: }); bgneal@312: bgneal@312: return r; bgneal@312: } bgneal@312: bgneal@312: o = DOM.get(o); bgneal@312: bgneal@312: if (!o) bgneal@312: return; bgneal@312: bgneal@312: // Setup event callback bgneal@312: cb = function(e) { bgneal@312: // Is all events disabled bgneal@312: if (t.disabled) bgneal@312: return; bgneal@312: bgneal@312: e = e || window.event; bgneal@312: bgneal@312: // Patch in target, preventDefault and stopPropagation in IE it's W3C valid bgneal@312: if (e && isIE) { bgneal@312: if (!e.target) bgneal@312: e.target = e.srcElement; bgneal@312: bgneal@312: // Patch in preventDefault, stopPropagation methods for W3C compatibility bgneal@312: tinymce.extend(e, t._stoppers); bgneal@312: } bgneal@312: bgneal@312: if (!s) bgneal@312: return f(e); bgneal@312: bgneal@312: return f.call(s, e); bgneal@312: }; bgneal@312: bgneal@312: if (n == 'unload') { bgneal@312: tinymce.unloads.unshift({func : cb}); bgneal@312: return cb; bgneal@312: } bgneal@312: bgneal@312: if (n == 'init') { bgneal@312: if (t.domLoaded) bgneal@312: cb(); bgneal@312: else bgneal@312: t.inits.push(cb); bgneal@312: bgneal@312: return cb; bgneal@312: } bgneal@312: bgneal@312: // Store away listener reference bgneal@312: el.push({ bgneal@312: obj : o, bgneal@312: name : n, bgneal@312: func : f, bgneal@312: cfunc : cb, bgneal@312: scope : s bgneal@312: }); bgneal@312: bgneal@312: t._add(o, n, cb); bgneal@312: bgneal@312: return f; bgneal@312: }, bgneal@312: bgneal@312: remove : function(o, n, f) { bgneal@312: var t = this, a = t.events, s = false, r; bgneal@312: bgneal@312: // Handle array bgneal@312: if (o && o.hasOwnProperty && o instanceof Array) { bgneal@312: r = []; bgneal@312: bgneal@312: each(o, function(o) { bgneal@312: o = DOM.get(o); bgneal@312: r.push(t.remove(o, n, f)); bgneal@312: }); bgneal@312: bgneal@312: return r; bgneal@312: } bgneal@312: bgneal@312: o = DOM.get(o); bgneal@312: bgneal@312: each(a, function(e, i) { bgneal@312: if (e.obj == o && e.name == n && (!f || (e.func == f || e.cfunc == f))) { bgneal@312: a.splice(i, 1); bgneal@312: t._remove(o, n, e.cfunc); bgneal@312: s = true; bgneal@312: return false; bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: return s; bgneal@312: }, bgneal@312: bgneal@312: clear : function(o) { bgneal@312: var t = this, a = t.events, i, e; bgneal@312: bgneal@312: if (o) { bgneal@312: o = DOM.get(o); bgneal@312: bgneal@312: for (i = a.length - 1; i >= 0; i--) { bgneal@312: e = a[i]; bgneal@312: bgneal@312: if (e.obj === o) { bgneal@312: t._remove(e.obj, e.name, e.cfunc); bgneal@312: e.obj = e.cfunc = null; bgneal@312: a.splice(i, 1); bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: cancel : function(e) { bgneal@312: if (!e) bgneal@312: return false; bgneal@312: bgneal@312: this.stop(e); bgneal@312: bgneal@312: return this.prevent(e); bgneal@312: }, bgneal@312: bgneal@312: stop : function(e) { bgneal@312: if (e.stopPropagation) bgneal@312: e.stopPropagation(); bgneal@312: else bgneal@312: e.cancelBubble = true; bgneal@312: bgneal@312: return false; bgneal@312: }, bgneal@312: bgneal@312: prevent : function(e) { bgneal@312: if (e.preventDefault) bgneal@312: e.preventDefault(); bgneal@312: else bgneal@312: e.returnValue = false; bgneal@312: bgneal@312: return false; bgneal@312: }, bgneal@312: bgneal@312: destroy : function() { bgneal@312: var t = this; bgneal@312: bgneal@312: each(t.events, function(e, i) { bgneal@312: t._remove(e.obj, e.name, e.cfunc); bgneal@312: e.obj = e.cfunc = null; bgneal@312: }); bgneal@312: bgneal@312: t.events = []; bgneal@312: t = null; bgneal@312: }, bgneal@312: bgneal@312: _add : function(o, n, f) { bgneal@312: if (o.attachEvent) bgneal@312: o.attachEvent('on' + n, f); bgneal@312: else if (o.addEventListener) bgneal@312: o.addEventListener(n, f, false); bgneal@312: else bgneal@312: o['on' + n] = f; bgneal@312: }, bgneal@312: bgneal@312: _remove : function(o, n, f) { bgneal@312: if (o) { bgneal@312: try { bgneal@312: if (o.detachEvent) bgneal@312: o.detachEvent('on' + n, f); bgneal@312: else if (o.removeEventListener) bgneal@312: o.removeEventListener(n, f, false); bgneal@312: else bgneal@312: o['on' + n] = null; bgneal@312: } catch (ex) { bgneal@312: // Might fail with permission denined on IE so we just ignore that bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: _pageInit : function(win) { bgneal@312: var t = this; bgneal@312: bgneal@312: // Keep it from running more than once bgneal@312: if (t.domLoaded) bgneal@312: return; bgneal@312: bgneal@312: t.domLoaded = true; bgneal@312: bgneal@312: each(t.inits, function(c) { bgneal@312: c(); bgneal@312: }); bgneal@312: bgneal@312: t.inits = []; bgneal@312: }, bgneal@312: bgneal@312: _wait : function(win) { bgneal@312: var t = this, doc = win.document; bgneal@312: bgneal@312: // No need since the document is already loaded bgneal@312: if (win.tinyMCE_GZ && tinyMCE_GZ.loaded) { bgneal@312: t.domLoaded = 1; bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Use IE method bgneal@312: if (doc.attachEvent) { bgneal@312: doc.attachEvent("onreadystatechange", function() { bgneal@312: if (doc.readyState === "complete") { bgneal@312: doc.detachEvent("onreadystatechange", arguments.callee); bgneal@312: t._pageInit(win); bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: if (doc.documentElement.doScroll && win == win.top) { bgneal@312: (function() { bgneal@312: if (t.domLoaded) bgneal@312: return; bgneal@312: bgneal@312: try { bgneal@312: // If IE is used, use the trick by Diego Perini bgneal@312: // http://javascript.nwbox.com/IEContentLoaded/ bgneal@312: doc.documentElement.doScroll("left"); bgneal@312: } catch (ex) { bgneal@312: setTimeout(arguments.callee, 0); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: t._pageInit(win); bgneal@312: })(); bgneal@312: } bgneal@312: } else if (doc.addEventListener) { bgneal@312: t._add(win, 'DOMContentLoaded', function() { bgneal@312: t._pageInit(win); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: t._add(win, 'load', function() { bgneal@312: t._pageInit(win); bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: _stoppers : { bgneal@312: preventDefault : function() { bgneal@312: this.returnValue = false; bgneal@312: }, bgneal@312: bgneal@312: stopPropagation : function() { bgneal@312: this.cancelBubble = true; bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: bgneal@312: Event = tinymce.dom.Event = new tinymce.dom.EventUtils(); bgneal@312: bgneal@312: // Dispatch DOM content loaded event for IE and Safari bgneal@312: Event._wait(window); bgneal@312: bgneal@312: tinymce.addUnload(function() { bgneal@312: Event.destroy(); bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: tinymce.dom.Element = function(id, settings) { bgneal@312: var t = this, dom, el; bgneal@312: bgneal@312: t.settings = settings = settings || {}; bgneal@312: t.id = id; bgneal@312: t.dom = dom = settings.dom || tinymce.DOM; bgneal@312: bgneal@312: // Only IE leaks DOM references, this is a lot faster bgneal@312: if (!tinymce.isIE) bgneal@312: el = dom.get(t.id); bgneal@312: bgneal@312: tinymce.each( bgneal@312: ('getPos,getRect,getParent,add,setStyle,getStyle,setStyles,' + bgneal@312: 'setAttrib,setAttribs,getAttrib,addClass,removeClass,' + bgneal@312: 'hasClass,getOuterHTML,setOuterHTML,remove,show,hide,' + bgneal@312: 'isHidden,setHTML,get').split(/,/) bgneal@312: , function(k) { bgneal@312: t[k] = function() { bgneal@312: var a = [id], i; bgneal@312: bgneal@312: for (i = 0; i < arguments.length; i++) bgneal@312: a.push(arguments[i]); bgneal@312: bgneal@312: a = dom[k].apply(dom, a); bgneal@312: t.update(k); bgneal@312: bgneal@312: return a; bgneal@312: }; bgneal@312: }); bgneal@312: bgneal@312: tinymce.extend(t, { bgneal@312: on : function(n, f, s) { bgneal@312: return tinymce.dom.Event.add(t.id, n, f, s); bgneal@312: }, bgneal@312: bgneal@312: getXY : function() { bgneal@312: return { bgneal@312: x : parseInt(t.getStyle('left')), bgneal@312: y : parseInt(t.getStyle('top')) bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: getSize : function() { bgneal@312: var n = dom.get(t.id); bgneal@312: bgneal@312: return { bgneal@312: w : parseInt(t.getStyle('width') || n.clientWidth), bgneal@312: h : parseInt(t.getStyle('height') || n.clientHeight) bgneal@312: }; bgneal@312: }, bgneal@312: bgneal@312: moveTo : function(x, y) { bgneal@312: t.setStyles({left : x, top : y}); bgneal@312: }, bgneal@312: bgneal@312: moveBy : function(x, y) { bgneal@312: var p = t.getXY(); bgneal@312: bgneal@312: t.moveTo(p.x + x, p.y + y); bgneal@312: }, bgneal@312: bgneal@312: resizeTo : function(w, h) { bgneal@312: t.setStyles({width : w, height : h}); bgneal@312: }, bgneal@312: bgneal@312: resizeBy : function(w, h) { bgneal@312: var s = t.getSize(); bgneal@312: bgneal@312: t.resizeTo(s.w + w, s.h + h); bgneal@312: }, bgneal@312: bgneal@312: update : function(k) { bgneal@312: var b; bgneal@312: bgneal@312: if (tinymce.isIE6 && settings.blocker) { bgneal@312: k = k || ''; bgneal@312: bgneal@312: // Ignore getters bgneal@312: if (k.indexOf('get') === 0 || k.indexOf('has') === 0 || k.indexOf('is') === 0) bgneal@312: return; bgneal@312: bgneal@312: // Remove blocker on remove bgneal@312: if (k == 'remove') { bgneal@312: dom.remove(t.blocker); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: if (!t.blocker) { bgneal@312: t.blocker = dom.uniqueId(); bgneal@312: b = dom.add(settings.container || dom.getRoot(), 'iframe', {id : t.blocker, style : 'position:absolute;', frameBorder : 0, src : 'javascript:""'}); bgneal@312: dom.setStyle(b, 'opacity', 0); bgneal@312: } else bgneal@312: b = dom.get(t.blocker); bgneal@312: bgneal@312: dom.setStyles(b, { bgneal@312: left : t.getStyle('left', 1), bgneal@312: top : t.getStyle('top', 1), bgneal@312: width : t.getStyle('width', 1), bgneal@312: height : t.getStyle('height', 1), bgneal@312: display : t.getStyle('display', 1), bgneal@312: zIndex : parseInt(t.getStyle('zIndex', 1) || 0) - 1 bgneal@312: }); bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: }; bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: function trimNl(s) { bgneal@312: return s.replace(/[\n\r]+/g, ''); bgneal@312: }; bgneal@312: bgneal@312: // Shorten names bgneal@312: var is = tinymce.is, isIE = tinymce.isIE, each = tinymce.each; bgneal@312: bgneal@312: tinymce.create('tinymce.dom.Selection', { bgneal@312: Selection : function(dom, win, serializer) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.dom = dom; bgneal@312: t.win = win; bgneal@312: t.serializer = serializer; bgneal@312: bgneal@312: // Add events bgneal@312: each([ bgneal@312: 'onBeforeSetContent', bgneal@312: 'onBeforeGetContent', bgneal@312: 'onSetContent', bgneal@312: 'onGetContent' bgneal@312: ], function(e) { bgneal@312: t[e] = new tinymce.util.Dispatcher(t); bgneal@312: }); bgneal@312: bgneal@312: // No W3C Range support bgneal@312: if (!t.win.getSelection) bgneal@312: t.tridentSel = new tinymce.dom.TridentSelection(t); bgneal@312: bgneal@312: // Prevent leaks bgneal@312: tinymce.addUnload(t.destroy, t); bgneal@312: }, bgneal@312: bgneal@312: getContent : function(s) { bgneal@312: var t = this, r = t.getRng(), e = t.dom.create("body"), se = t.getSel(), wb, wa, n; bgneal@312: bgneal@312: s = s || {}; bgneal@312: wb = wa = ''; bgneal@312: s.get = true; bgneal@312: s.format = s.format || 'html'; bgneal@312: t.onBeforeGetContent.dispatch(t, s); bgneal@312: bgneal@312: if (s.format == 'text') bgneal@312: return t.isCollapsed() ? '' : (r.text || (se.toString ? se.toString() : '')); bgneal@312: bgneal@312: if (r.cloneContents) { bgneal@312: n = r.cloneContents(); bgneal@312: bgneal@312: if (n) bgneal@312: e.appendChild(n); bgneal@312: } else if (is(r.item) || is(r.htmlText)) bgneal@312: e.innerHTML = r.item ? r.item(0).outerHTML : r.htmlText; bgneal@312: else bgneal@312: e.innerHTML = r.toString(); bgneal@312: bgneal@312: // Keep whitespace before and after bgneal@312: if (/^\s/.test(e.innerHTML)) bgneal@312: wb = ' '; bgneal@312: bgneal@312: if (/\s+$/.test(e.innerHTML)) bgneal@312: wa = ' '; bgneal@312: bgneal@312: s.getInner = true; bgneal@312: bgneal@312: s.content = t.isCollapsed() ? '' : wb + t.serializer.serialize(e, s) + wa; bgneal@312: t.onGetContent.dispatch(t, s); bgneal@312: bgneal@312: return s.content; bgneal@312: }, bgneal@312: bgneal@312: setContent : function(h, s) { bgneal@312: var t = this, r = t.getRng(), c, d = t.win.document; bgneal@312: bgneal@312: s = s || {format : 'html'}; bgneal@312: s.set = true; bgneal@312: h = s.content = t.dom.processHTML(h); bgneal@312: bgneal@312: // Dispatch before set content event bgneal@312: t.onBeforeSetContent.dispatch(t, s); bgneal@312: h = s.content; bgneal@312: bgneal@312: if (r.insertNode) { bgneal@312: // Make caret marker since insertNode places the caret in the beginning of text after insert bgneal@312: h += '_'; bgneal@312: bgneal@312: // Delete and insert new node bgneal@312: bgneal@312: if (r.startContainer == d && r.endContainer == d) { bgneal@312: // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents bgneal@312: d.body.innerHTML = h; bgneal@312: } else { bgneal@312: r.deleteContents(); bgneal@312: if (d.body.childNodes.length == 0) { bgneal@312: d.body.innerHTML = h; bgneal@312: } else { bgneal@312: r.insertNode(r.createContextualFragment(h)); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // Move to caret marker bgneal@312: c = t.dom.get('__caret'); bgneal@312: // Make sure we wrap it compleatly, Opera fails with a simple select call bgneal@312: r = d.createRange(); bgneal@312: r.setStartBefore(c); bgneal@312: r.setEndBefore(c); bgneal@312: t.setRng(r); bgneal@312: bgneal@312: // Remove the caret position bgneal@312: t.dom.remove('__caret'); bgneal@312: } else { bgneal@312: if (r.item) { bgneal@312: // Delete content and get caret text selection bgneal@312: d.execCommand('Delete', false, null); bgneal@312: r = t.getRng(); bgneal@312: } bgneal@312: bgneal@312: r.pasteHTML(h); bgneal@312: } bgneal@312: bgneal@312: // Dispatch set content event bgneal@312: t.onSetContent.dispatch(t, s); bgneal@312: }, bgneal@312: bgneal@312: getStart : function() { bgneal@312: var rng = this.getRng(), startElement, parentElement, checkRng, node; bgneal@312: bgneal@312: if (rng.duplicate || rng.item) { bgneal@312: // Control selection, return first item bgneal@312: if (rng.item) bgneal@312: return rng.item(0); bgneal@312: bgneal@312: // Get start element bgneal@312: checkRng = rng.duplicate(); bgneal@312: checkRng.collapse(1); bgneal@312: startElement = checkRng.parentElement(); bgneal@312: bgneal@312: // Check if range parent is inside the start element, then return the inner parent element bgneal@312: // This will fix issues when a single element is selected, IE would otherwise return the wrong start element bgneal@312: parentElement = node = rng.parentElement(); bgneal@312: while (node = node.parentNode) { bgneal@312: if (node == startElement) { bgneal@312: startElement = parentElement; bgneal@312: break; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // If start element is body element try to move to the first child if it exists bgneal@312: if (startElement && startElement.nodeName == 'BODY') bgneal@312: return startElement.firstChild || startElement; bgneal@312: bgneal@312: return startElement; bgneal@312: } else { bgneal@312: startElement = rng.startContainer; bgneal@312: bgneal@312: if (startElement.nodeType == 1 && startElement.hasChildNodes()) bgneal@312: startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)]; bgneal@312: bgneal@312: if (startElement && startElement.nodeType == 3) bgneal@312: return startElement.parentNode; bgneal@312: bgneal@312: return startElement; bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: getEnd : function() { bgneal@312: var t = this, r = t.getRng(), e, eo; bgneal@312: bgneal@312: if (r.duplicate || r.item) { bgneal@312: if (r.item) bgneal@312: return r.item(0); bgneal@312: bgneal@312: r = r.duplicate(); bgneal@312: r.collapse(0); bgneal@312: e = r.parentElement(); bgneal@312: bgneal@312: if (e && e.nodeName == 'BODY') bgneal@312: return e.lastChild || e; bgneal@312: bgneal@312: return e; bgneal@312: } else { bgneal@312: e = r.endContainer; bgneal@312: eo = r.endOffset; bgneal@312: bgneal@312: if (e.nodeType == 1 && e.hasChildNodes()) bgneal@312: e = e.childNodes[eo > 0 ? eo - 1 : eo]; bgneal@312: bgneal@312: if (e && e.nodeType == 3) bgneal@312: return e.parentNode; bgneal@312: bgneal@312: return e; bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: getBookmark : function(type, normalized) { bgneal@312: var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, index, chr = '\uFEFF', styles; bgneal@312: bgneal@312: function findIndex(name, element) { bgneal@312: var index = 0; bgneal@312: bgneal@312: each(dom.select(name), function(node, i) { bgneal@312: if (node == element) bgneal@312: index = i; bgneal@312: }); bgneal@312: bgneal@312: return index; bgneal@312: }; bgneal@312: bgneal@312: if (type == 2) { bgneal@312: function getLocation() { bgneal@312: var rng = t.getRng(true), root = dom.getRoot(), bookmark = {}; bgneal@312: bgneal@312: function getPoint(rng, start) { bgneal@312: var container = rng[start ? 'startContainer' : 'endContainer'], bgneal@312: offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0; bgneal@312: bgneal@312: if (container.nodeType == 3) { bgneal@312: if (normalized) { bgneal@312: for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling) bgneal@312: offset += node.nodeValue.length; bgneal@312: } bgneal@312: bgneal@312: point.push(offset); bgneal@312: } else { bgneal@312: childNodes = container.childNodes; bgneal@312: bgneal@312: if (offset >= childNodes.length && childNodes.length) { bgneal@312: after = 1; bgneal@312: offset = Math.max(0, childNodes.length - 1); bgneal@312: } bgneal@312: bgneal@312: point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after); bgneal@312: } bgneal@312: bgneal@312: for (; container && container != root; container = container.parentNode) bgneal@312: point.push(t.dom.nodeIndex(container, normalized)); bgneal@312: bgneal@312: return point; bgneal@312: }; bgneal@312: bgneal@312: bookmark.start = getPoint(rng, true); bgneal@312: bgneal@312: if (!t.isCollapsed()) bgneal@312: bookmark.end = getPoint(rng); bgneal@312: bgneal@312: return bookmark; bgneal@312: }; bgneal@312: bgneal@312: return getLocation(); bgneal@312: } bgneal@312: bgneal@312: // Handle simple range bgneal@312: if (type) bgneal@312: return {rng : t.getRng()}; bgneal@312: bgneal@312: rng = t.getRng(); bgneal@312: id = dom.uniqueId(); bgneal@312: collapsed = tinyMCE.activeEditor.selection.isCollapsed(); bgneal@312: styles = 'overflow:hidden;line-height:0px'; bgneal@312: bgneal@312: // Explorer method bgneal@312: if (rng.duplicate || rng.item) { bgneal@312: // Text selection bgneal@312: if (!rng.item) { bgneal@312: rng2 = rng.duplicate(); bgneal@312: bgneal@312: // Insert start marker bgneal@312: rng.collapse(); bgneal@312: rng.pasteHTML('' + chr + ''); bgneal@312: bgneal@312: // Insert end marker bgneal@312: if (!collapsed) { bgneal@312: rng2.collapse(false); bgneal@312: rng2.pasteHTML('' + chr + ''); bgneal@312: } bgneal@312: } else { bgneal@312: // Control selection bgneal@312: element = rng.item(0); bgneal@312: name = element.nodeName; bgneal@312: bgneal@312: return {name : name, index : findIndex(name, element)}; bgneal@312: } bgneal@312: } else { bgneal@312: element = t.getNode(); bgneal@312: name = element.nodeName; bgneal@312: if (name == 'IMG') bgneal@312: return {name : name, index : findIndex(name, element)}; bgneal@312: bgneal@312: // W3C method bgneal@312: rng2 = rng.cloneRange(); bgneal@312: bgneal@312: // Insert end marker bgneal@312: if (!collapsed) { bgneal@312: rng2.collapse(false); bgneal@312: rng2.insertNode(dom.create('span', {_mce_type : "bookmark", id : id + '_end', style : styles}, chr)); bgneal@312: } bgneal@312: bgneal@312: rng.collapse(true); bgneal@312: rng.insertNode(dom.create('span', {_mce_type : "bookmark", id : id + '_start', style : styles}, chr)); bgneal@312: } bgneal@312: bgneal@312: t.moveToBookmark({id : id, keep : 1}); bgneal@312: bgneal@312: return {id : id}; bgneal@312: }, bgneal@312: bgneal@312: moveToBookmark : function(bookmark) { bgneal@312: var t = this, dom = t.dom, marker1, marker2, rng, root, startContainer, endContainer, startOffset, endOffset; bgneal@312: bgneal@312: // Clear selection cache bgneal@312: if (t.tridentSel) bgneal@312: t.tridentSel.destroy(); bgneal@312: bgneal@312: if (bookmark) { bgneal@312: if (bookmark.start) { bgneal@312: rng = dom.createRng(); bgneal@312: root = dom.getRoot(); bgneal@312: bgneal@312: function setEndPoint(start) { bgneal@312: var point = bookmark[start ? 'start' : 'end'], i, node, offset, children; bgneal@312: bgneal@312: if (point) { bgneal@312: // Find container node bgneal@312: for (node = root, i = point.length - 1; i >= 1; i--) { bgneal@312: children = node.childNodes; bgneal@312: bgneal@312: if (children.length) bgneal@312: node = children[point[i]]; bgneal@312: } bgneal@312: bgneal@312: // Set offset within container node bgneal@312: if (start) bgneal@312: rng.setStart(node, point[0]); bgneal@312: else bgneal@312: rng.setEnd(node, point[0]); bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: setEndPoint(true); bgneal@312: setEndPoint(); bgneal@312: bgneal@312: t.setRng(rng); bgneal@312: } else if (bookmark.id) { bgneal@312: function restoreEndPoint(suffix) { bgneal@312: var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep; bgneal@312: bgneal@312: if (marker) { bgneal@312: node = marker.parentNode; bgneal@312: bgneal@312: if (suffix == 'start') { bgneal@312: if (!keep) { bgneal@312: idx = dom.nodeIndex(marker); bgneal@312: } else { bgneal@312: node = marker.firstChild; bgneal@312: idx = 1; bgneal@312: } bgneal@312: bgneal@312: startContainer = endContainer = node; bgneal@312: startOffset = endOffset = idx; bgneal@312: } else { bgneal@312: if (!keep) { bgneal@312: idx = dom.nodeIndex(marker); bgneal@312: } else { bgneal@312: node = marker.firstChild; bgneal@312: idx = 1; bgneal@312: } bgneal@312: bgneal@312: endContainer = node; bgneal@312: endOffset = idx; bgneal@312: } bgneal@312: bgneal@312: if (!keep) { bgneal@312: prev = marker.previousSibling; bgneal@312: next = marker.nextSibling; bgneal@312: bgneal@312: // Remove all marker text nodes bgneal@312: each(tinymce.grep(marker.childNodes), function(node) { bgneal@312: if (node.nodeType == 3) bgneal@312: node.nodeValue = node.nodeValue.replace(/\uFEFF/g, ''); bgneal@312: }); bgneal@312: bgneal@312: // Remove marker but keep children if for example contents where inserted into the marker bgneal@312: // Also remove duplicated instances of the marker for example by a split operation or by WebKit auto split on paste feature bgneal@312: while (marker = dom.get(bookmark.id + '_' + suffix)) bgneal@312: dom.remove(marker, 1); bgneal@312: bgneal@312: // If siblings are text nodes then merge them bgneal@312: if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3) { bgneal@312: idx = prev.nodeValue.length; bgneal@312: prev.appendData(next.nodeValue); bgneal@312: dom.remove(next); bgneal@312: bgneal@312: if (suffix == 'start') { bgneal@312: startContainer = endContainer = prev; bgneal@312: startOffset = endOffset = idx; bgneal@312: } else { bgneal@312: endContainer = prev; bgneal@312: endOffset = idx; bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: } bgneal@312: }; bgneal@312: bgneal@312: function addBogus(node) { bgneal@312: // Adds a bogus BR element for empty block elements bgneal@312: // on non IE browsers just to have a place to put the caret bgneal@312: if (!isIE && dom.isBlock(node) && !node.innerHTML) bgneal@312: node.innerHTML = '
'; bgneal@312: bgneal@312: return node; bgneal@312: }; bgneal@312: bgneal@312: // Restore start/end points bgneal@312: restoreEndPoint('start'); bgneal@312: restoreEndPoint('end'); bgneal@312: bgneal@312: if (startContainer) { bgneal@312: rng = dom.createRng(); bgneal@312: rng.setStart(addBogus(startContainer), startOffset); bgneal@312: rng.setEnd(addBogus(endContainer), endOffset); bgneal@312: t.setRng(rng); bgneal@312: } bgneal@312: } else if (bookmark.name) { bgneal@312: t.select(dom.select(bookmark.name)[bookmark.index]); bgneal@312: } else if (bookmark.rng) bgneal@312: t.setRng(bookmark.rng); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: select : function(node, content) { bgneal@312: var t = this, dom = t.dom, rng = dom.createRng(), idx; bgneal@312: bgneal@312: idx = dom.nodeIndex(node); bgneal@312: rng.setStart(node.parentNode, idx); bgneal@312: rng.setEnd(node.parentNode, idx + 1); bgneal@312: bgneal@312: // Find first/last text node or BR element bgneal@312: if (content) { bgneal@312: function setPoint(node, start) { bgneal@312: var walker = new tinymce.dom.TreeWalker(node, node); bgneal@312: bgneal@312: do { bgneal@312: // Text node bgneal@312: if (node.nodeType == 3 && tinymce.trim(node.nodeValue).length != 0) { bgneal@312: if (start) bgneal@312: rng.setStart(node, 0); bgneal@312: else bgneal@312: rng.setEnd(node, node.nodeValue.length); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // BR element bgneal@312: if (node.nodeName == 'BR') { bgneal@312: if (start) bgneal@312: rng.setStartBefore(node); bgneal@312: else bgneal@312: rng.setEndBefore(node); bgneal@312: bgneal@312: return; bgneal@312: } bgneal@312: } while (node = (start ? walker.next() : walker.prev())); bgneal@312: }; bgneal@312: bgneal@312: setPoint(node, 1); bgneal@312: setPoint(node); bgneal@312: } bgneal@312: bgneal@312: t.setRng(rng); bgneal@312: bgneal@312: return node; bgneal@312: }, bgneal@312: bgneal@312: isCollapsed : function() { bgneal@312: var t = this, r = t.getRng(), s = t.getSel(); bgneal@312: bgneal@312: if (!r || r.item) bgneal@312: return false; bgneal@312: bgneal@312: if (r.compareEndPoints) bgneal@312: return r.compareEndPoints('StartToEnd', r) === 0; bgneal@312: bgneal@312: return !s || r.collapsed; bgneal@312: }, bgneal@312: bgneal@312: collapse : function(b) { bgneal@312: var t = this, r = t.getRng(), n; bgneal@312: bgneal@312: // Control range on IE bgneal@312: if (r.item) { bgneal@312: n = r.item(0); bgneal@312: r = this.win.document.body.createTextRange(); bgneal@312: r.moveToElementText(n); bgneal@312: } bgneal@312: bgneal@312: r.collapse(!!b); bgneal@312: t.setRng(r); bgneal@312: }, bgneal@312: bgneal@312: getSel : function() { bgneal@312: var t = this, w = this.win; bgneal@312: bgneal@312: return w.getSelection ? w.getSelection() : w.document.selection; bgneal@312: }, bgneal@312: bgneal@312: getRng : function(w3c) { bgneal@312: var t = this, s, r; bgneal@312: bgneal@312: // Found tridentSel object then we need to use that one bgneal@312: if (w3c && t.tridentSel) bgneal@312: return t.tridentSel.getRangeAt(0); bgneal@312: bgneal@312: try { bgneal@312: if (s = t.getSel()) bgneal@312: r = s.rangeCount > 0 ? s.getRangeAt(0) : (s.createRange ? s.createRange() : t.win.document.createRange()); bgneal@312: } catch (ex) { bgneal@312: // IE throws unspecified error here if TinyMCE is placed in a frame/iframe bgneal@312: } bgneal@312: bgneal@312: // No range found then create an empty one bgneal@312: // This can occur when the editor is placed in a hidden container element on Gecko bgneal@312: // Or on IE when there was an exception bgneal@312: if (!r) bgneal@312: r = t.win.document.createRange ? t.win.document.createRange() : t.win.document.body.createTextRange(); bgneal@312: bgneal@312: if (t.selectedRange && t.explicitRange) { bgneal@312: if (r.compareBoundaryPoints(r.START_TO_START, t.selectedRange) === 0 && r.compareBoundaryPoints(r.END_TO_END, t.selectedRange) === 0) { bgneal@312: // Safari, Opera and Chrome only ever select text which causes the range to change. bgneal@312: // This lets us use the originally set range if the selection hasn't been changed by the user. bgneal@312: r = t.explicitRange; bgneal@312: } else { bgneal@312: t.selectedRange = null; bgneal@312: t.explicitRange = null; bgneal@312: } bgneal@312: } bgneal@312: return r; bgneal@312: }, bgneal@312: bgneal@312: setRng : function(r) { bgneal@312: var s, t = this; bgneal@312: bgneal@312: if (!t.tridentSel) { bgneal@312: s = t.getSel(); bgneal@312: bgneal@312: if (s) { bgneal@312: t.explicitRange = r; bgneal@312: s.removeAllRanges(); bgneal@312: s.addRange(r); bgneal@312: t.selectedRange = s.getRangeAt(0); bgneal@312: } bgneal@312: } else { bgneal@312: // Is W3C Range bgneal@312: if (r.cloneRange) { bgneal@312: t.tridentSel.addRange(r); bgneal@312: return; bgneal@312: } bgneal@312: bgneal@312: // Is IE specific range bgneal@312: try { bgneal@312: r.select(); bgneal@312: } catch (ex) { bgneal@312: // Needed for some odd IE bug #1843306 bgneal@312: } bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: setNode : function(n) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.setContent(t.dom.getOuterHTML(n)); bgneal@312: bgneal@312: return n; bgneal@312: }, bgneal@312: bgneal@312: getNode : function() { bgneal@312: var t = this, rng = t.getRng(), sel = t.getSel(), elm; bgneal@312: bgneal@312: if (rng.setStart) { bgneal@312: // Range maybe lost after the editor is made visible again bgneal@312: if (!rng) bgneal@312: return t.dom.getRoot(); bgneal@312: bgneal@312: elm = rng.commonAncestorContainer; bgneal@312: bgneal@312: // Handle selection a image or other control like element such as anchors bgneal@312: if (!rng.collapsed) { bgneal@312: if (rng.startContainer == rng.endContainer) { bgneal@312: if (rng.startOffset - rng.endOffset < 2) { bgneal@312: if (rng.startContainer.hasChildNodes()) bgneal@312: elm = rng.startContainer.childNodes[rng.startOffset]; bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: // If the anchor node is a element instead of a text node then return this element bgneal@312: if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1) bgneal@312: return sel.anchorNode.childNodes[sel.anchorOffset]; bgneal@312: } bgneal@312: bgneal@312: if (elm && elm.nodeType == 3) bgneal@312: return elm.parentNode; bgneal@312: bgneal@312: return elm; bgneal@312: } bgneal@312: bgneal@312: return rng.item ? rng.item(0) : rng.parentElement(); bgneal@312: }, bgneal@312: bgneal@312: getSelectedBlocks : function(st, en) { bgneal@312: var t = this, dom = t.dom, sb, eb, n, bl = []; bgneal@312: bgneal@312: sb = dom.getParent(st || t.getStart(), dom.isBlock); bgneal@312: eb = dom.getParent(en || t.getEnd(), dom.isBlock); bgneal@312: bgneal@312: if (sb) bgneal@312: bl.push(sb); bgneal@312: bgneal@312: if (sb && eb && sb != eb) { bgneal@312: n = sb; bgneal@312: bgneal@312: while ((n = n.nextSibling) && n != eb) { bgneal@312: if (dom.isBlock(n)) bgneal@312: bl.push(n); bgneal@312: } bgneal@312: } bgneal@312: bgneal@312: if (eb && sb != eb) bgneal@312: bl.push(eb); bgneal@312: bgneal@312: return bl; bgneal@312: }, bgneal@312: bgneal@312: destroy : function(s) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.win = null; bgneal@312: bgneal@312: if (t.tridentSel) bgneal@312: t.tridentSel.destroy(); bgneal@312: bgneal@312: // Manual destroy then remove unload handler bgneal@312: if (!s) bgneal@312: tinymce.removeUnload(t.destroy); bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: tinymce.create('tinymce.dom.XMLWriter', { bgneal@312: node : null, bgneal@312: bgneal@312: XMLWriter : function(s) { bgneal@312: // Get XML document bgneal@312: function getXML() { bgneal@312: var i = document.implementation; bgneal@312: bgneal@312: if (!i || !i.createDocument) { bgneal@312: // Try IE objects bgneal@312: try {return new ActiveXObject('MSXML2.DOMDocument');} catch (ex) {} bgneal@312: try {return new ActiveXObject('Microsoft.XmlDom');} catch (ex) {} bgneal@312: } else bgneal@312: return i.createDocument('', '', null); bgneal@312: }; bgneal@312: bgneal@312: this.doc = getXML(); bgneal@312: bgneal@312: // Since Opera and WebKit doesn't escape > into > we need to do it our self to normalize the output for all browsers bgneal@312: this.valid = tinymce.isOpera || tinymce.isWebKit; bgneal@312: bgneal@312: this.reset(); bgneal@312: }, bgneal@312: bgneal@312: reset : function() { bgneal@312: var t = this, d = t.doc; bgneal@312: bgneal@312: if (d.firstChild) bgneal@312: d.removeChild(d.firstChild); bgneal@312: bgneal@312: t.node = d.appendChild(d.createElement("html")); bgneal@312: }, bgneal@312: bgneal@312: writeStartElement : function(n) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.node = t.node.appendChild(t.doc.createElement(n)); bgneal@312: }, bgneal@312: bgneal@312: writeAttribute : function(n, v) { bgneal@312: if (this.valid) bgneal@312: v = v.replace(/>/g, '%MCGT%'); bgneal@312: bgneal@312: this.node.setAttribute(n, v); bgneal@312: }, bgneal@312: bgneal@312: writeEndElement : function() { bgneal@312: this.node = this.node.parentNode; bgneal@312: }, bgneal@312: bgneal@312: writeFullEndElement : function() { bgneal@312: var t = this, n = t.node; bgneal@312: bgneal@312: n.appendChild(t.doc.createTextNode("")); bgneal@312: t.node = n.parentNode; bgneal@312: }, bgneal@312: bgneal@312: writeText : function(v) { bgneal@312: if (this.valid) bgneal@312: v = v.replace(/>/g, '%MCGT%'); bgneal@312: bgneal@312: this.node.appendChild(this.doc.createTextNode(v)); bgneal@312: }, bgneal@312: bgneal@312: writeCDATA : function(v) { bgneal@312: this.node.appendChild(this.doc.createCDATASection(v)); bgneal@312: }, bgneal@312: bgneal@312: writeComment : function(v) { bgneal@312: // Fix for bug #2035694 bgneal@312: if (tinymce.isIE) bgneal@312: v = v.replace(/^\-|\-$/g, ' '); bgneal@312: bgneal@312: this.node.appendChild(this.doc.createComment(v.replace(/\-\-/g, ' '))); bgneal@312: }, bgneal@312: bgneal@312: getContent : function() { bgneal@312: var h; bgneal@312: bgneal@312: h = this.doc.xml || new XMLSerializer().serializeToString(this.doc); bgneal@312: h = h.replace(/<\?[^?]+\?>||<\/html>||]+>/g, ''); bgneal@312: h = h.replace(/ ?\/>/g, ' />'); bgneal@312: bgneal@312: if (this.valid) bgneal@312: h = h.replace(/\%MCGT%/g, '>'); bgneal@312: bgneal@312: return h; bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: tinymce.create('tinymce.dom.StringWriter', { bgneal@312: str : null, bgneal@312: tags : null, bgneal@312: count : 0, bgneal@312: settings : null, bgneal@312: indent : null, bgneal@312: bgneal@312: StringWriter : function(s) { bgneal@312: this.settings = tinymce.extend({ bgneal@312: indent_char : ' ', bgneal@312: indentation : 0 bgneal@312: }, s); bgneal@312: bgneal@312: this.reset(); bgneal@312: }, bgneal@312: bgneal@312: reset : function() { bgneal@312: this.indent = ''; bgneal@312: this.str = ""; bgneal@312: this.tags = []; bgneal@312: this.count = 0; bgneal@312: }, bgneal@312: bgneal@312: writeStartElement : function(n) { bgneal@312: this._writeAttributesEnd(); bgneal@312: this.writeRaw('<' + n); bgneal@312: this.tags.push(n); bgneal@312: this.inAttr = true; bgneal@312: this.count++; bgneal@312: this.elementCount = this.count; bgneal@312: }, bgneal@312: bgneal@312: writeAttribute : function(n, v) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.writeRaw(" " + t.encode(n) + '="' + t.encode(v) + '"'); bgneal@312: }, bgneal@312: bgneal@312: writeEndElement : function() { bgneal@312: var n; bgneal@312: bgneal@312: if (this.tags.length > 0) { bgneal@312: n = this.tags.pop(); bgneal@312: bgneal@312: if (this._writeAttributesEnd(1)) bgneal@312: this.writeRaw(''); bgneal@312: bgneal@312: if (this.settings.indentation > 0) bgneal@312: this.writeRaw('\n'); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: writeFullEndElement : function() { bgneal@312: if (this.tags.length > 0) { bgneal@312: this._writeAttributesEnd(); bgneal@312: this.writeRaw(''); bgneal@312: bgneal@312: if (this.settings.indentation > 0) bgneal@312: this.writeRaw('\n'); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: writeText : function(v) { bgneal@312: this._writeAttributesEnd(); bgneal@312: this.writeRaw(this.encode(v)); bgneal@312: this.count++; bgneal@312: }, bgneal@312: bgneal@312: writeCDATA : function(v) { bgneal@312: this._writeAttributesEnd(); bgneal@312: this.writeRaw(''); bgneal@312: this.count++; bgneal@312: }, bgneal@312: bgneal@312: writeComment : function(v) { bgneal@312: this._writeAttributesEnd(); bgneal@312: this.writeRaw(''); bgneal@312: this.count++; bgneal@312: }, bgneal@312: bgneal@312: writeRaw : function(v) { bgneal@312: this.str += v; bgneal@312: }, bgneal@312: bgneal@312: encode : function(s) { bgneal@312: return s.replace(/[<>&"]/g, function(v) { bgneal@312: switch (v) { bgneal@312: case '<': bgneal@312: return '<'; bgneal@312: bgneal@312: case '>': bgneal@312: return '>'; bgneal@312: bgneal@312: case '&': bgneal@312: return '&'; bgneal@312: bgneal@312: case '"': bgneal@312: return '"'; bgneal@312: } bgneal@312: bgneal@312: return v; bgneal@312: }); bgneal@312: }, bgneal@312: bgneal@312: getContent : function() { bgneal@312: return this.str; bgneal@312: }, bgneal@312: bgneal@312: _writeAttributesEnd : function(s) { bgneal@312: if (!this.inAttr) bgneal@312: return; bgneal@312: bgneal@312: this.inAttr = false; bgneal@312: bgneal@312: if (s && this.elementCount == this.count) { bgneal@312: this.writeRaw(' />'); bgneal@312: return false; bgneal@312: } bgneal@312: bgneal@312: this.writeRaw('>'); bgneal@312: bgneal@312: return true; bgneal@312: } bgneal@312: }); bgneal@312: })(tinymce); bgneal@312: bgneal@312: (function(tinymce) { bgneal@312: // Shorten names bgneal@312: var extend = tinymce.extend, each = tinymce.each, Dispatcher = tinymce.util.Dispatcher, isIE = tinymce.isIE, isGecko = tinymce.isGecko; bgneal@312: bgneal@312: function wildcardToRE(s) { bgneal@312: return s.replace(/([?+*])/g, '.$1'); bgneal@312: }; bgneal@312: bgneal@312: tinymce.create('tinymce.dom.Serializer', { bgneal@312: Serializer : function(s) { bgneal@312: var t = this; bgneal@312: bgneal@312: t.key = 0; bgneal@312: t.onPreProcess = new Dispatcher(t); bgneal@312: t.onPostProcess = new Dispatcher(t); bgneal@312: bgneal@312: try { bgneal@312: t.writer = new tinymce.dom.XMLWriter(); bgneal@312: } catch (ex) { bgneal@312: // IE might throw exception if ActiveX is disabled so we then switch to the slightly slower StringWriter bgneal@312: t.writer = new tinymce.dom.StringWriter(); bgneal@312: } bgneal@312: bgneal@312: // Default settings bgneal@312: t.settings = s = extend({ bgneal@312: dom : tinymce.DOM, bgneal@312: valid_nodes : 0, bgneal@312: node_filter : 0, bgneal@312: attr_filter : 0, bgneal@312: invalid_attrs : /^(_mce_|_moz_|sizset|sizcache)/, bgneal@312: closed : /^(br|hr|input|meta|img|link|param|area)$/, bgneal@312: entity_encoding : 'named', bgneal@312: 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@312: valid_elements : '*[*]', bgneal@312: extended_valid_elements : 0, bgneal@312: invalid_elements : 0, bgneal@312: fix_table_elements : 1, bgneal@312: fix_list_elements : true, bgneal@312: fix_content_duplication : true, bgneal@312: convert_fonts_to_spans : false, bgneal@312: font_size_classes : 0, bgneal@312: apply_source_formatting : 0, bgneal@312: indent_mode : 'simple', bgneal@312: indent_char : '\t', bgneal@312: indent_levels : 1, bgneal@312: remove_linebreaks : 1, bgneal@312: remove_redundant_brs : 1, bgneal@312: element_format : 'xhtml' bgneal@312: }, s); bgneal@312: bgneal@312: t.dom = s.dom; bgneal@312: t.schema = s.schema; bgneal@312: bgneal@312: // Use raw entities if no entities are defined bgneal@312: if (s.entity_encoding == 'named' && !s.entities) bgneal@312: s.entity_encoding = 'raw'; bgneal@312: bgneal@312: if (s.remove_redundant_brs) { bgneal@312: t.onPostProcess.add(function(se, o) { bgneal@312: // Remove single BR at end of block elements since they get rendered bgneal@312: o.content = o.content.replace(/(
\s*)+<\/(p|h[1-6]|div|li)>/gi, function(a, b, c) { bgneal@312: // Check if it's a single element bgneal@312: if (/^
\s*<\//.test(a)) bgneal@312: return ''; bgneal@312: bgneal@312: return a; bgneal@312: }); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: // Remove XHTML element endings i.e. produce crap :) XHTML is better bgneal@312: if (s.element_format == 'html') { bgneal@312: t.onPostProcess.add(function(se, o) { bgneal@312: o.content = o.content.replace(/<([^>]+) \/>/g, '<$1>'); bgneal@312: }); bgneal@312: } bgneal@312: bgneal@312: if (s.fix_list_elements) { bgneal@312: t.onPreProcess.add(function(se, o) { bgneal@312: var nl, x, a = ['ol', 'ul'], i, n, p, r = /^(OL|UL)$/, np; bgneal@312: bgneal@312: function prevNode(e, n) { bgneal@312: var a = n.split(','), i; bgneal@312: bgneal@312: while ((e = e.previousSibling) != null) { bgneal@312: for (i=0; i= 1767) { bgneal@312: each(t.dom.select('p table', o.node).reverse(), function(n) { bgneal@312: var parent = t.dom.getParent(n.parentNode, 'table,p'); bgneal@312: bgneal@312: if (parent.nodeName != 'TABLE') { bgneal@312: try { bgneal@312: t.dom.split(parent, n); bgneal@312: } catch (ex) { bgneal@312: // IE can sometimes fire an unknown runtime error so we just ignore it bgneal@312: } bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: }); bgneal@312: } bgneal@312: }, bgneal@312: bgneal@312: setEntities : function(s) { bgneal@312: var t = this, a, i, l = {}, v; bgneal@312: bgneal@312: // No need to setup more than once bgneal@312: if (t.entityLookup) bgneal@312: return; bgneal@312: bgneal@312: // Build regex and lookup array bgneal@312: a = s.split(','); bgneal@312: for (i = 0; i < a.length; i += 2) { bgneal@312: v = a[i]; bgneal@312: bgneal@312: // Don't add default & " etc. bgneal@312: if (v == 34 || v == 38 || v == 60 || v == 62) bgneal@312: continue; bgneal@312: bgneal@312: l[String.fromCharCode(a[i])] = a[i + 1]; bgneal@312: bgneal@312: v = parseInt(a[i]).toString(16); bgneal@312: } bgneal@312: bgneal@312: t.entityLookup = l; bgneal@312: }, bgneal@312: bgneal@312: setRules : function(s) { bgneal@312: var t = this; bgneal@312: bgneal@312: t._setup(); bgneal@312: t.rules = {}; bgneal@312: t.wildRules = []; bgneal@312: t.validElements = {}; bgneal@312: bgneal@312: return t.addRules(s); bgneal@312: }, bgneal@312: bgneal@312: addRules : function(s) { bgneal@312: var t = this, dr; bgneal@312: bgneal@312: if (!s) bgneal@312: return; bgneal@312: bgneal@312: t._setup(); bgneal@312: bgneal@312: each(s.split(','), function(s) { bgneal@312: var p = s.split(/\[|\]/), tn = p[0].split('/'), ra, at, wat, va = []; bgneal@312: bgneal@312: // Extend with default rules bgneal@312: if (dr) bgneal@312: at = tinymce.extend([], dr.attribs); bgneal@312: bgneal@312: // Parse attributes bgneal@312: if (p.length > 1) { bgneal@312: each(p[1].split('|'), function(s) { bgneal@312: var ar = {}, i; bgneal@312: bgneal@312: at = at || []; bgneal@312: bgneal@312: // Parse attribute rule bgneal@312: s = s.replace(/::/g, '~'); bgneal@312: s = /^([!\-])?([\w*.?~_\-]+|)([=:<])?(.+)?$/.exec(s); bgneal@312: s[2] = s[2].replace(/~/g, ':'); bgneal@312: bgneal@312: // Add required attributes bgneal@312: if (s[1] == '!') { bgneal@312: ra = ra || []; bgneal@312: ra.push(s[2]); bgneal@312: } bgneal@312: bgneal@312: // Remove inherited attributes bgneal@312: if (s[1] == '-') { bgneal@312: for (i = 0; i = 1767)) { bgneal@312: // Create an empty HTML document bgneal@312: doc = impl.createHTMLDocument(""); bgneal@312: bgneal@312: // Add the element or it's children if it's a body element to the new document bgneal@312: each(n.nodeName == 'BODY' ? n.childNodes : [n], function(node) { bgneal@312: doc.body.appendChild(doc.importNode(node, true)); bgneal@312: }); bgneal@312: bgneal@312: // Grab first child or body element for serialization bgneal@312: if (n.nodeName != 'BODY') bgneal@312: n = doc.body.firstChild; bgneal@312: else bgneal@312: n = doc.body; bgneal@312: bgneal@312: // set the new document in DOMUtils so createElement etc works bgneal@312: oldDoc = t.dom.doc; bgneal@312: t.dom.doc = doc; bgneal@312: } bgneal@312: bgneal@312: t.key = '' + (parseInt(t.key) + 1); bgneal@312: bgneal@312: // Pre process bgneal@312: if (!o.no_events) { bgneal@312: o.node = n; bgneal@312: t.onPreProcess.dispatch(t, o); bgneal@312: } bgneal@312: bgneal@312: // Serialize HTML DOM into a string bgneal@312: t.writer.reset(); bgneal@312: t._info = o; bgneal@312: t._serializeNode(n, o.getInner); bgneal@312: bgneal@312: // Post process bgneal@312: o.content = t.writer.getContent(); bgneal@312: bgneal@312: // Restore the old document if it was changed bgneal@312: if (oldDoc) bgneal@312: t.dom.doc = oldDoc; bgneal@312: bgneal@312: if (!o.no_events) bgneal@312: t.onPostProcess.dispatch(t, o); bgneal@312: bgneal@312: t._postProcess(o); bgneal@312: o.node = null; bgneal@312: bgneal@312: return tinymce.trim(o.content); bgneal@312: }, bgneal@312: bgneal@312: // Internal functions bgneal@312: bgneal@312: _postProcess : function(o) { bgneal@312: var t = this, s = t.settings, h = o.content, sc = [], p; bgneal@312: bgneal@312: if (o.format == 'html') { bgneal@312: // Protect some elements bgneal@312: p = t._protect({ bgneal@312: content : h, bgneal@312: patterns : [ bgneal@312: {pattern : /(]*>)(.*?)(<\/script>)/g}, bgneal@312: {pattern : /(]*>)(.*?)(<\/noscript>)/g}, bgneal@312: {pattern : /(]*>)(.*?)(<\/style>)/g}, bgneal@312: {pattern : /(]*>)(.*?)(<\/pre>)/g, encode : 1}, bgneal@312: {pattern : /()/g} bgneal@312: ] bgneal@312: }); bgneal@312: bgneal@312: h = p.content; bgneal@312: bgneal@312: // Entity encode bgneal@312: if (s.entity_encoding !== 'raw') bgneal@312: h = t._encode(h); bgneal@312: bgneal@312: // Use BR instead of   padded P elements inside editor and use

 

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

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


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

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

$1

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

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

' : ' 

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

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

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