📄 tiny_mce_src.js
字号:
if (t.elmClassPattern.test(pa)) {
pl = t.elmClassPattern.exec(pa);
x = get(s, pl[1] || '*');
c = ' ' + pl[2] + ' ';
for (i = 0, l = x.length; i<l; i++) {
n = x[i];
if (n.className && (' ' + n.className + ' ').indexOf(c) !== -1)
o.push(n);
}
return o;
}
function collect(n) {
if (!n.mce_save) {
n.mce_save = 1;
o.push(n);
}
};
function collectIE(n) {
if (!n.getAttribute('mce_save')) {
n.setAttribute('mce_save', '1');
o.push(n);
}
};
function find(n, f, r) {
var i, l, nl = get(r, n);
for (i = 0, l = nl.length; i < l; i++)
f(nl[i]);
};
each(pa.split(','), function(v, i) {
v = tinymce.trim(v);
// Simple element pattern, most common in TinyMCE
if (t.elmPattern.test(v)) {
each(get(s, v), function(n) {
collect(n);
});
return;
}
// Simple element pattern with class, fairly common in TinyMCE
if (t.elmClassPattern.test(v)) {
x = t.elmClassPattern.exec(v);
each(get(s, x[1]), function(n) {
if (t.hasClass(n, x[2]))
collect(n);
});
return;
}
if (!(cs = t.cache[pa])) {
cs = 'x=(function(cf, s) {';
pl = v.split(' ');
each(pl, function(v) {
var p = t.selectorRe.exec(v);
// Find elements
p[1] = p[1] || '*';
cs += 'find("' + p[1] + '", function(n) {';
// Check id
if (p[2])
cs += 'if (n.id !== "' + p[2] + '") return;';
// Check classes
if (p[3]) {
cs += 'var c = " " + n.className + " ";';
cs += 'if (';
c = '';
each(p[3].split('.'), function(v) {
if (v)
c += (c ? '||' : '') + 'c.indexOf(" ' + v + ' ") === -1';
});
cs += c + ') return;';
}
});
cs += 'cf(n);';
for (i = pl.length - 1; i >= 0; i--)
cs += '}, ' + (i ? 'n' : 's') + ');';
cs += '})';
// Compile CSS pattern function
t.cache[pa] = cs = eval(cs);
}
// Run selector function
cs(isIE ? collectIE : collect, s);
});
// Cleanup
each(o, function(n) {
if (isIE)
n.removeAttribute('mce_save');
else
delete n.mce_save;
});
return o;
},
// #endif
add : function(p, n, a, h, c) {
var t = this;
return this.run(p, function(p) {
var e, k;
e = is(n, 'string') ? t.doc.createElement(n) : n;
t.setAttribs(e, a);
if (h) {
if (h.nodeType)
e.appendChild(h);
else
t.setHTML(e, h);
}
return !c ? p.appendChild(e) : e;
});
},
create : function(n, a, h) {
return this.add(this.doc.createElement(n), n, a, h, 1);
},
createHTML : function(n, a, h) {
var o = '', t = this, k;
o += '<' + n;
for (k in a) {
if (a.hasOwnProperty(k))
o += ' ' + k + '="' + t.encode(a[k]) + '"';
}
if (tinymce.is(h))
return o + '>' + h + '</' + n + '>';
return o + ' />';
},
remove : function(n, k) {
return this.run(n, function(n) {
var p, g;
p = n.parentNode;
if (!p)
return null;
if (k) {
each (n.childNodes, function(c) {
p.insertBefore(c.cloneNode(true), n);
});
}
// Fix IE psuedo leak
/* if (isIE) {
p = n.cloneNode(true);
n.outerHTML = '';
return p;
}*/
return p.removeChild(n);
});
},
// #if !jquery
setStyle : function(n, na, v) {
var t = this;
return t.run(n, function(e) {
var s, i;
s = e.style;
// Camelcase it, if needed
na = na.replace(/-(\D)/g, function(a, b){
return b.toUpperCase();
});
// Default px suffix on these
if (t.pixelStyles.test(na) && (tinymce.is(v, 'number') || /^[\-0-9\.]+$/.test(v)))
v += 'px';
switch (na) {
case 'opacity':
// IE specific opacity
if (isIE) {
s.filter = v === '' ? '' : "alpha(opacity=" + (v * 100) + ")";
if (!n.currentStyle || !n.currentStyle.hasLayout)
s.display = 'inline-block';
}
// Fix for older browsers
s[na] = s['-moz-opacity'] = s['-khtml-opacity'] = v || '';
break;
case 'float':
isIE ? s.styleFloat = v : s.cssFloat = v;
break;
default:
s[na] = v || '';
}
// Force update of the style data
if (t.settings.update_styles)
t.setAttrib(e, 'mce_style');
});
},
getStyle : function(n, na, c) {
n = this.get(n);
if (!n)
return false;
// Gecko
if (this.doc.defaultView && c) {
// Remove camelcase
na = na.replace(/[A-Z]/g, function(a){
return '-' + a;
});
try {
return this.doc.defaultView.getComputedStyle(n, null).getPropertyValue(na);
} catch (ex) {
// Old safari might fail
return null;
}
}
// Camelcase it, if needed
na = na.replace(/-(\D)/g, function(a, b){
return b.toUpperCase();
});
if (na == 'float')
na = isIE ? 'styleFloat' : 'cssFloat';
// IE & Opera
if (n.currentStyle && c)
return n.currentStyle[na];
return n.style[na];
},
setStyles : function(e, o) {
var t = this, s = t.settings, ol;
ol = s.update_styles;
s.update_styles = 0;
each(o, function(v, n) {
t.setStyle(e, n, v);
});
// Update style info
s.update_styles = ol;
if (s.update_styles)
t.setAttrib(e, s.cssText);
},
setAttrib : function(e, n, v) {
var t = this;
// Whats the point
if (!e || !n)
return;
// Strict XML mode
if (t.settings.strict)
n = n.toLowerCase();
return this.run(e, function(e) {
var s = t.settings;
switch (n) {
case "style":
if (!is(v, 'string')) {
each(v, function(v, n) {
t.setStyle(e, n, v);
});
return;
}
// No mce_style for elements with these since they might get resized by the user
if (s.keep_values) {
if (v && !t._isRes(v))
e.setAttribute('mce_style', v, 2);
else
e.removeAttribute('mce_style', 2);
}
e.style.cssText = v;
break;
case "class":
e.className = v || ''; // Fix IE null bug
break;
case "src":
case "href":
if (s.keep_values) {
if (s.url_converter)
v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
t.setAttrib(e, 'mce_' + n, v, 2);
}
break;
case "shape":
e.setAttribute('mce_style', v);
break;
}
if (is(v) && v !== null && v.length !== 0)
e.setAttribute(n, '' + v, 2);
else
e.removeAttribute(n, 2);
});
},
setAttribs : function(e, o) {
var t = this;
return this.run(e, function(e) {
each(o, function(v, n) {
t.setAttrib(e, n, v);
});
});
},
// #endif
getAttrib : function(e, n, dv) {
var v, t = this;
e = t.get(e);
if (!e || e.nodeType !== 1)
return false;
if (!is(dv))
dv = '';
// Try the mce variant for these
if (/^(src|href|style|coords|shape)$/.test(n)) {
v = e.getAttribute("mce_" + n);
if (v)
return v;
}
if (isIE && t.props[n]) {
v = e[t.props[n]];
v = v && v.nodeValue ? v.nodeValue : v;
}
if (!v)
v = e.getAttribute(n, 2);
if (n === 'style') {
v = v || e.style.cssText;
if (v) {
v = t.serializeStyle(t.parseStyle(v));
if (t.settings.keep_values && !t._isRes(v))
e.setAttribute('mce_style', v);
}
}
// Remove Apple and WebKit stuff
if (isWebKit && n === "class" && v)
v = v.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
// Handle IE issues
if (isIE) {
switch (n) {
case 'rowspan':
case 'colspan':
// IE returns 1 as default value
if (v === 1)
v = '';
break;
case 'size':
// IE returns +0 as default value for size
if (v === '+0' || v === 20)
v = '';
break;
case 'width':
case 'height':
case 'vspace':
if (v === 0)
v = '';
break;
case 'hspace':
// IE returns -1 as default value
if (v === -1)
v = '';
break;
case 'maxlength':
case 'tabindex':
// IE returns default value
if (v === 32768 || v === 2147483647)
v = '';
break;
case 'compact':
case 'noshade':
if (v === 65535)
return n;
return dv;
case 'shape':
v = v.toLowerCase();
break;
default:
// IE has odd anonymous function for event attributes
if (n.indexOf('on') === 0 && v)
v = ('' + v).replace(/^function\s+anonymous\(\)\s+\{\s+(.*)\s+\}$/, '$1');
}
}
return (v !== undefined && v !== null && v !== '') ? '' + v : dv;
},
getPos : function(n) {
var t = this, x = 0, y = 0, e, d = t.doc, r;
n = t.get(n);
// Use getBoundingClientRect on IE, Opera has it but it's not perfect
if (n && isIE) {
n = n.getBoundingClientRect();
e = t.boxModel ? d.documentElement : d.body;
x = t.getStyle(t.select('html')[0], 'borderWidth'); // Remove border
x = (x == 'medium' || t.boxModel && !t.isIE6) && 2 || x;
n.top += t.win.self != t.win.top ? 2 : 0; // IE adds some strange extra cord if used in a frameset
return {x : n.left + e.scrollLeft - x, y : n.top + e.scrollTop - x};
}
r = n;
while (r) {
x += r.offsetLeft || 0;
y += r.offsetTop || 0;
r = r.offsetParent;
}
r = n;
while (r) {
// Opera 9.25 bug fix, fixed in 9.50
if (!/^table-row|inline.*/i.test(t.getStyle(r, "display", 1))) {
x -= r.scrollLeft || 0;
y -= r.scrollTop || 0;
}
r = r.parentNode;
if (r == d.body)
break;
}
return {x : x, y : y};
},
parseStyle : function(st) {
var t = this, s = t.settings, o = {};
if (!st)
return o;
function compress(p, s, ot) {
var t, r, b, l;
// Get values and check it it needs compressing
t = o[p + '-top' + s];
if (!t)
return;
r = o[p + '-right' + s];
if (t != r)
return;
b = o[p + '-bottom' + s];
if (r != b)
return;
l = o[p + '-left' + s];
if (b != l)
return;
// Compress
o[ot] = l;
delete o[p + '-top' + s];
delete o[p + '-right' + s];
delete o[p + '-bottom' + s];
delete o[p + '-left' + s];
};
function compress2(ta, a, b, c) {
var t;
t = o[a];
if (!t)
return;
t = o[b];
if (!t)
return;
t = o[c];
if (!t)
return;
// Compress
o[ta] = o[a] + ' ' + o[b] + ' ' + o[c];
delete o[a];
delete o[b];
delete o[c];
};
st = st.replace(/&(#?[a-z0-9]+);/g, '&$1_MCE_SEMI_'); // Protect entities
each(st.split(';'), function(v) {
var sv, ur = [];
if (v) {
v = v.replace(/_MCE_SEMI_/g, ';'); // Restore entities
v = v.replace(/url\([^\)]+\)/g, function(v) {ur.push(v);return 'url(' + ur.length + ')';});
v = v.split(':');
sv = tinymce.trim(v[1]);
sv = sv.replace(/url\(([^\)]+)\)/g, function(a, b) {return ur[parseInt(b) - 1];});
sv = sv.replace(/rgb\([^\)]+\)/g, function(v) {
return t.toHex(v);
});
if (s.url_converter) {
sv = sv.replace(/url\([\'\"]?([^\)\'\"]+)[\'\"]?\)/g, function(x, c) {
return 'url(' + s.url_converter.call(s.url_converter_scope || t, t.decode(c), 'style', null) + ')';
});
}
o[tinymce.trim(v[0]).toLowerCase()] = sv;
}
});
compress("border", "", "border");
compress("border", "-width", "border-width");
compress("border", "-color", "border-color");
compress("border", "-style", "border-style");
compress("padding", "", "padding");
compress("margin", "", "margin");
compress2('border', 'border-width', 'border-style', 'border-color');
if (isIE) {
// Remove pointless border
if (o.border == 'medium none')
o.border = '';
}
return o;
},
serializeStyle : function(o) {
var s = '';
each(o, function(v, k) {
if (k && v) {
if (tinymce.isGecko && k.indexOf('-moz-') === 0)
return;
switch (k) {
case 'color':
case 'background-color':
v = v.toLowerCase();
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -