📄 overview-summary-tinymce_cleanup.class.js.html
字号:
}
<span class="comment">// Force HEX colors</span>
<span class="reserved">if</span> (tinyMCE.getParam(<span class="literal">"force_hex_style_colors"</span>))
val = tinyMCE.convertRGBToHex(val, true);
<span class="reserved">if</span> (val != <span class="literal">"url('')"</span>)
str += key.toLowerCase() + <span class="literal">": "</span> + val + <span class="literal">"; "</span>;
}
}
<span class="reserved">if</span> (new RegExp(<span class="literal">'; $'</span>).test(str))
str = str.substring(0, str.length - 2);
<span class="reserved">return</span> str;
};
<span class="comment">/**
* Returns a hexadecimal version of the specified rgb(1,2,3) string.
*
* <span class="attrib">@param</span> {string} s RGB string to parse, if this doesn't isn't a rgb(n,n,n) it will passthrough the string.
* <span class="attrib">@param</span> {boolean} k Keep before/after contents. If enabled contents before after the rgb(n,n,n) will be intact.
* <span class="attrib">@return</span> Hexadecimal version of the specified rgb(1,2,3) string.
* <span class="attrib">@type</span> string
*/</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.convertRGBToHex = <span class="reserved">function</span>(s, k) {
<span class="reserved">if</span> (s.toLowerCase().indexOf(<span class="literal">'rgb'</span>) != -1) {
var re = new RegExp(<span class="literal">"(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)"</span>, <span class="literal">"gi"</span>);
var rgb = s.replace(re, <span class="literal">"$1,$2,$3,$4,$5"</span>).split(<span class="literal">','</span>);
<span class="reserved">if</span> (rgb.length == 5) {
r = parseInt(rgb[1]).toString(16);
g = parseInt(rgb[2]).toString(16);
b = parseInt(rgb[3]).toString(16);
r = r.length == 1 ? <span class="literal">'0'</span> + r : r;
g = g.length == 1 ? <span class="literal">'0'</span> + g : g;
b = b.length == 1 ? <span class="literal">'0'</span> + b : b;
s = <span class="literal">"#"</span> + r + g + b;
<span class="reserved">if</span> (k)
s = rgb[0] + s + rgb[4];
}
}
<span class="reserved">return</span> s;
};
<span class="comment">/**
* Returns a rgb(n,n,n) string from a hexadecimal value.
*
* <span class="attrib">@param</span> {string} s Hexadecimal string to parse.
* <span class="attrib">@return</span> rgb(n,n,n) string from a hexadecimal value.
* <span class="attrib">@type</span> string
*/</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.convertHexToRGB = <span class="reserved">function</span>(s) {
<span class="reserved">if</span> (s.indexOf(<span class="literal">'#'</span>) != -1) {
s = s.replace(new RegExp(<span class="literal">'[^0-9A-F]'</span>, <span class="literal">'gi'</span>), <span class="literal">''</span>);
<span class="reserved">return</span> <span class="literal">"rgb("</span> + parseInt(s.substring(0, 2), 16) + <span class="literal">","</span> + parseInt(s.substring(2, 4), 16) + <span class="literal">","</span> + parseInt(s.substring(4, 6), 16) + <span class="literal">")"</span>;
}
<span class="reserved">return</span> s;
};
<span class="comment">/**
* Converts span elements to font elements in the specified document instance.
* Todo: Move this function into a XHTML plugin or simmilar.
*
* <span class="attrib">@param</span> {DOMDocument} doc Document instance to convert spans in.
*/</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.convertSpansToFonts = <span class="reserved">function</span>(doc) {
var sizes = tinyMCE.getParam(<span class="literal">'font_size_style_values'</span>).replace(/\s+/, <span class="literal">''</span>).split(<span class="literal">','</span>);
var h = doc.body.innerHTML;
h = h.replace(/<span/gi, <span class="literal">'<font'</span>);
h = h.replace(/<\/span/gi, <span class="literal">'</font'</span>);
doc.body.innerHTML = h;
var s = doc.getElementsByTagName(<span class="literal">"font"</span>);
<span class="reserved">for</span> (var i=0; i<s.length; i++) {
var size = tinyMCE.trim(s[i].style.fontSize).toLowerCase();
var fSize = 0;
<span class="reserved">for</span> (var x=0; x<sizes.length; x++) {
<span class="reserved">if</span> (sizes[x] == size) {
fSize = x + 1;
break;
}
}
<span class="reserved">if</span> (fSize > 0) {
tinyMCE.setAttrib(s[i], <span class="literal">'size'</span>, fSize);
s[i].style.fontSize = <span class="literal">''</span>;
}
var fFace = s[i].style.fontFamily;
<span class="reserved">if</span> (fFace != null && fFace != <span class="literal">""</span>) {
tinyMCE.setAttrib(s[i], <span class="literal">'face'</span>, fFace);
s[i].style.fontFamily = <span class="literal">''</span>;
}
var fColor = s[i].style.color;
<span class="reserved">if</span> (fColor != null && fColor != <span class="literal">""</span>) {
tinyMCE.setAttrib(s[i], <span class="literal">'color'</span>, tinyMCE.convertRGBToHex(fColor));
s[i].style.color = <span class="literal">''</span>;
}
}
};
<span class="comment">/**
* Convers fonts to spans in the specified document.
* Todo: Move this function into a XHTML plugin or simmilar.
*
* <span class="attrib">@param</span> {DOMDocument} doc Document instance to convert fonts in.
*/</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.convertFontsToSpans = <span class="reserved">function</span>(doc) {
var sizes = tinyMCE.getParam(<span class="literal">'font_size_style_values'</span>).replace(/\s+/, <span class="literal">''</span>).split(<span class="literal">','</span>);
var h = doc.body.innerHTML;
h = h.replace(/<font/gi, <span class="literal">'<span'</span>);
h = h.replace(/<\/font/gi, <span class="literal">'</span'</span>);
doc.body.innerHTML = h;
var fsClasses = tinyMCE.getParam(<span class="literal">'font_size_classes'</span>);
<span class="reserved">if</span> (fsClasses != <span class="literal">''</span>)
fsClasses = fsClasses.replace(/\s+/, <span class="literal">''</span>).split(<span class="literal">','</span>);
<span class="reserved">else</span>
fsClasses = null;
var s = doc.getElementsByTagName(<span class="literal">"span"</span>);
<span class="reserved">for</span> (var i=0; i<s.length; i++) {
var fSize, fFace, fColor;
fSize = tinyMCE.getAttrib(s[i], <span class="literal">'size'</span>);
fFace = tinyMCE.getAttrib(s[i], <span class="literal">'face'</span>);
fColor = tinyMCE.getAttrib(s[i], <span class="literal">'color'</span>);
<span class="reserved">if</span> (fSize != <span class="literal">""</span>) {
fSize = parseInt(fSize);
<span class="reserved">if</span> (fSize > 0 && fSize < 8) {
<span class="reserved">if</span> (fsClasses != null)
tinyMCE.setAttrib(s[i], <span class="literal">'class'</span>, fsClasses[fSize-1]);
<span class="reserved">else</span>
s[i].style.fontSize = sizes[fSize-1];
}
s[i].removeAttribute(<span class="literal">'size'</span>);
}
<span class="reserved">if</span> (fFace != <span class="literal">""</span>) {
s[i].style.fontFamily = fFace;
s[i].removeAttribute(<span class="literal">'face'</span>);
}
<span class="reserved">if</span> (fColor != <span class="literal">""</span>) {
s[i].style.color = fColor;
s[i].removeAttribute(<span class="literal">'color'</span>);
}
}
};
<span class="comment">/**
* Moves the contents of a anchor outside and after the anchor. Only if the anchor doesn't
* have a href.
*
* <span class="attrib">@param</span> {DOMDocument} doc DOM document instance to fix anchors in.
*/</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.cleanupAnchors = <span class="reserved">function</span>(doc) {
var i, cn, x, an = doc.getElementsByTagName(<span class="literal">"a"</span>);
<span class="reserved">for</span> (i=0; i<an.length; i++) {
<span class="reserved">if</span> (tinyMCE.getAttrib(an[i], <span class="literal">"name"</span>) != <span class="literal">""</span> && tinyMCE.getAttrib(an[i], <span class="literal">"href"</span>) == <span class="literal">""</span>) {
cn = an[i].childNodes;
<span class="reserved">for</span> (x=cn.length-1; x>=0; x--)
tinyMCE.insertAfter(cn[x], an[i]);
}
}
};
<span class="comment">/**
* Returns the HTML contents of the specified editor instance id.
*
* <span class="attrib">@param</span> {string} editor_id Editor instance id to retrive HTML code from.
* <span class="attrib">@return</span> HTML contents of editor id or null if it wasn't found.
* <span class="attrib">@type</span> string
*/</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.getContent = <span class="reserved">function</span>(editor_id) {
<span class="reserved">if</span> (typeof(editor_id) != <span class="literal">"undefined"</span>)
tinyMCE.selectedInstance = tinyMCE.getInstanceById(editor_id);
<span class="reserved">if</span> (tinyMCE.selectedInstance)
<span class="reserved">return</span> tinyMCE._cleanupHTML(<span class="reserved">this</span>.selectedInstance, <span class="reserved">this</span>.selectedInstance.getDoc(), tinyMCE.settings, <span class="reserved">this</span>.selectedInstance.getBody(), false, true);
<span class="reserved">return</span> null;
};
<span class="comment">/**
* Performces cleanup of the contents of the specified instance.
* Todo: Finish documentation, and remove useless parameters.
*
* <span class="attrib">@param</span> {TinyMCE_Control} inst Editor instance.
* <span class="attrib">@param</span> {DOMDocument} doc ...
* <span class="attrib">@param</span> {Array} config ...
* <span class="attrib">@param</span> {HTMLElement} element ...
* <span class="attrib">@param</span> {boolean} visual ...
* <span class="attrib">@param</span> {boolean} on_save ...
* <span class="attrib">@param</span> {boolean} on_submit ...
* <span class="attrib">@return</span> Cleaned HTML contents of editor instance.
* <span class="attrib">@type</span> string
* <span class="attrib">@private</span>
*/</span>
TinyMCE_Engine.<span class="reserved">prototype</span>._cleanupHTML = <span class="reserved">function</span>(inst, doc, config, element, visual, on_save, on_submit) {
var h, d, t1, t2, t3, t4, t5, c, s;
<span class="reserved">if</span> (!tinyMCE.settings.cleanup)
<span class="reserved">return</span> inst.getBody().innerHTML;
on_save = typeof(on_save) == <span class="literal">'undefined'</span> ? false : on_save;
c = inst.cleanup;
s = inst.settings;
d = c.settings.debug;
<span class="reserved">if</span> (d)
t1 = new Date().getTime();
<span class="reserved">if</span> (on_save && tinyMCE.getParam(<span class="literal">"convert_fonts_to_spans"</span>))
tinyMCE.convertFontsToSpans(doc);
<span class="comment">// Call custom cleanup code</span>
tinyMCE._customCleanup(inst, on_save ? <span class="literal">"get_from_editor_dom"</span> : <span class="literal">"insert_to_editor_dom"</span>, doc.body);
<span class="reserved">if</span> (d)
t2 = new Date().getTime();
c.settings.on_save = on_save;
<span class="comment">//for (var i=0; i<100; i++)</span>
c.idCount = 0;
<span class="reserved">if</span> (s.cleanup_serializer == <span class="literal">"xml"</span>)
h = c.serializeNodeAsXML(element);
<span class="reserved">else</span>
h = c.serializeNodeAsHTML(element);
<span class="reserved">if</span> (d)
t3 = new Date().getTime();
<span class="comment">// Post processing</span>
h = h.replace(/<\/?(body|head|html)[^>]*>/gi, <span class="literal">''</span>);
h = h.replace(new RegExp(<span class="literal">' (rowspan="1"|colspan="1")'</span>, <span class="literal">'g'</span>), <span class="literal">''</span>);
h = h.replace(/<p><hr \/><\/p>/g, <span class="literal">'<hr />'</span>);
h = h.replace(/<p>(&nbsp;|&#160;)<\/p><hr \/><p>(&nbsp;|&#160;)<\/p>/g, <span class="literal">'<hr />'</span>);
h = h.replace(/<td>\s*<br \/>\s*<\/td>/g, <span class="literal">'<td>&nbsp;</td>'</span>);
h = h.replace(/<p>\s*<br \/>\s*<\/p>/g, <span class="literal">'<p>&nbsp;</p>'</span>);
h = h.replace(/<p>\s*(&nbsp;|&#160;)\s*<br \/>\s*(&nbsp;|&#160;)\s*<\/p>/g, <span class="literal">'<p>&nbsp;</p>'</span>);
h = h.replace(/<p>\s*(&nbsp;|&#160;)\s*<br \/>\s*<\/p>/g, <span class="literal">'<p>&nbsp;</p>'</span>);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -