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 + '' + n + '>';
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
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 (/';
bgneal@312:
bgneal@312: bi = s.body_id || 'tinymce';
bgneal@312: if (bi.indexOf('=') != -1) {
bgneal@312: bi = t.getParam('body_id', '', 'hash');
bgneal@312: bi = bi[t.id] || bi;
bgneal@312: }
bgneal@312:
bgneal@312: bc = s.body_class || '';
bgneal@312: if (bc.indexOf('=') != -1) {
bgneal@312: bc = t.getParam('body_class', '', 'hash');
bgneal@312: bc = bc[t.id] || '';
bgneal@312: }
bgneal@312:
bgneal@312: t.iframeHTML += '