📄 tiny_mce_src.js
字号:
if (tinyMCE.isLoaded)
return true;
tinyMCE.isLoaded = true;
// IE produces JS error if TinyMCE is placed in a frame
// It seems to have something to do with the selection not beeing
// correctly initialized in IE so this hack solves the problem
if (tinyMCE.isRealIE && document.body) {
r = document.body.createTextRange();
r.collapse(true);
r.select();
}
tinyMCE.dispatchCallback(null, 'onpageload', 'onPageLoad');
for (var c=0; c<tinyMCE.configs.length; c++) {
tinyMCE.settings = tinyMCE.configs[c];
var selector = tinyMCE.getParam("editor_selector");
var deselector = tinyMCE.getParam("editor_deselector");
var elementRefAr = new Array();
// Add submit triggers
if (document.forms && tinyMCE.settings['add_form_submit_trigger'] && !tinyMCE.submitTriggers) {
for (var i=0; i<document.forms.length; i++) {
var form = document.forms[i];
tinyMCE.addEvent(form, "submit", TinyMCE_Engine.prototype.handleEvent);
tinyMCE.addEvent(form, "reset", TinyMCE_Engine.prototype.handleEvent);
tinyMCE.submitTriggers = true; // Do it only once
// Patch the form.submit function
if (tinyMCE.settings['submit_patch']) {
try {
form.mceOldSubmit = form.submit;
form.submit = TinyMCE_Engine.prototype.submitPatch;
} catch (e) {
// Do nothing
}
}
}
}
// Add editor instances based on mode
var mode = tinyMCE.settings['mode'];
switch (mode) {
case "exact":
var elements = tinyMCE.getParam('elements', '', true, ',');
for (var i=0; i<elements.length; i++) {
var element = tinyMCE._getElementById(elements[i]);
var trigger = element ? element.getAttribute(tinyMCE.settings['textarea_trigger']) : "";
if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(element, "class")))
continue;
if (trigger == "false")
continue;
if ((tinyMCE.settings['ask'] || tinyMCE.settings['convert_on_click']) && element) {
elementRefAr[elementRefAr.length] = element;
continue;
}
if (element)
tinyMCE.addMCEControl(element, elements[i]);
else if (tinyMCE.settings['debug'])
alert("Error: Could not find element by id or name: " + elements[i]);
}
break;
case "specific_textareas":
case "textareas":
var nodeList = document.getElementsByTagName("textarea");
for (var i=0; i<nodeList.length; i++) {
var elm = nodeList.item(i);
var trigger = elm.getAttribute(tinyMCE.settings['textarea_trigger']);
if (selector != '' && !new RegExp('\\b' + selector + '\\b').test(tinyMCE.getAttrib(elm, "class")))
continue;
if (selector != '')
trigger = selector != "" ? "true" : "";
if (new RegExp('\\b' + deselector + '\\b').test(tinyMCE.getAttrib(elm, "class")))
continue;
if ((mode == "specific_textareas" && trigger == "true") || (mode == "textareas" && trigger != "false"))
elementRefAr[elementRefAr.length] = elm;
}
break;
}
for (var i=0; i<elementRefAr.length; i++) {
var element = elementRefAr[i];
var elementId = element.name ? element.name : element.id;
if (tinyMCE.settings['ask'] || tinyMCE.settings['convert_on_click']) {
// Focus breaks in Mozilla
if (tinyMCE.isGecko) {
var settings = tinyMCE.settings;
tinyMCE.addEvent(element, "focus", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
if (element.nodeName != "TEXTAREA" && element.nodeName != "INPUT")
tinyMCE.addEvent(element, "click", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
// tinyMCE.addEvent(element, "mouseover", function (e) {window.setTimeout(function() {TinyMCE_Engine.prototype.confirmAdd(e, settings);}, 10);});
} else {
var settings = tinyMCE.settings;
tinyMCE.addEvent(element, "focus", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
tinyMCE.addEvent(element, "click", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
// tinyMCE.addEvent(element, "mouseenter", function () { TinyMCE_Engine.prototype.confirmAdd(null, settings); });
}
} else
tinyMCE.addMCEControl(element, elementId);
}
// Handle auto focus
if (tinyMCE.settings['auto_focus']) {
window.setTimeout(function () {
var inst = tinyMCE.getInstanceById(tinyMCE.settings['auto_focus']);
inst.selection.selectNode(inst.getBody(), true, true);
inst.contentWindow.focus();
}, 100);
}
tinyMCE.dispatchCallback(null, 'oninit', 'onInit');
}
},
isInstance : function(o) {
return o != null && typeof(o) == "object" && o.isTinyMCE_Control;
},
getParam : function(name, default_value, strip_whitespace, split_chr) {
var value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
// Fix bool values
if (value == "true" || value == "false")
return (value == "true");
if (strip_whitespace)
value = tinyMCE.regexpReplace(value, "[ \t\r\n]", "");
if (typeof(split_chr) != "undefined" && split_chr != null) {
value = value.split(split_chr);
var outArray = new Array();
for (var i=0; i<value.length; i++) {
if (value[i] && value[i] != "")
outArray[outArray.length] = value[i];
}
value = outArray;
}
return value;
},
getLang : function(name, default_value, parse_entities, va) {
var v = (typeof(tinyMCELang[name]) == "undefined") ? default_value : tinyMCELang[name], n;
if (parse_entities)
v = tinyMCE.entityDecode(v);
if (va) {
for (n in va)
v = this.replaceVar(v, n, va[n]);
}
return v;
},
entityDecode : function(s) {
var e = document.createElement("div");
e.innerHTML = s;
return e.firstChild.nodeValue;
},
addToLang : function(prefix, ar) {
for (var key in ar) {
if (typeof(ar[key]) == 'function')
continue;
tinyMCELang[(key.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix != '' ? (prefix + "_") : '') + key] = ar[key];
}
this.loadNextScript();
// for (var key in ar)
// tinyMCELang[(key.indexOf('lang_') == -1 ? 'lang_' : '') + (prefix != '' ? (prefix + "_") : '') + key] = "|" + ar[key] + "|";
},
triggerNodeChange : function(focus, setup_content) {
var elm, inst, editorId, undoIndex = -1, undoLevels = -1, doc, anySelection = false;
if (tinyMCE.selectedInstance) {
inst = tinyMCE.selectedInstance;
elm = (typeof(setup_content) != "undefined" && setup_content) ? tinyMCE.selectedElement : inst.getFocusElement();
/* if (elm == inst.lastTriggerEl)
return;
inst.lastTriggerEl = elm;*/
editorId = inst.editorId;
selectedText = inst.selection.getSelectedText();
if (tinyMCE.settings.auto_resize)
inst.resizeToContent();
if (setup_content && tinyMCE.isGecko && inst.isHidden())
elm = inst.getBody();
inst.switchSettings();
if (tinyMCE.selectedElement)
anySelection = (tinyMCE.selectedElement.nodeName.toLowerCase() == "img") || (selectedText && selectedText.length > 0);
if (tinyMCE.settings['custom_undo_redo']) {
undoIndex = inst.undoRedo.undoIndex;
undoLevels = inst.undoRedo.undoLevels.length;
}
tinyMCE.dispatchCallback(inst, 'handle_node_change_callback', 'handleNodeChange', editorId, elm, undoIndex, undoLevels, inst.visualAid, anySelection, setup_content);
}
if (this.selectedInstance && (typeof(focus) == "undefined" || focus))
this.selectedInstance.contentWindow.focus();
},
_customCleanup : function(inst, type, content) {
var pl, po, i;
// Call custom cleanup
var customCleanup = tinyMCE.settings['cleanup_callback'];
if (customCleanup != "" && eval("typeof(" + customCleanup + ")") != "undefined")
content = eval(customCleanup + "(type, content, inst);");
// Trigger theme cleanup
po = tinyMCE.themes[tinyMCE.settings['theme']];
if (po && po.cleanup)
content = po.cleanup(type, content, inst);
// Trigger plugin cleanups
pl = inst.plugins;
for (i=0; i<pl.length; i++) {
po = tinyMCE.plugins[pl[i]];
if (po && po.cleanup)
content = po.cleanup(type, content, inst);
}
return content;
},
setContent : function(h) {
if (tinyMCE.selectedInstance) {
tinyMCE.selectedInstance.execCommand('mceSetContent', false, h);
tinyMCE.selectedInstance.repaint();
}
},
importThemeLanguagePack : function(name) {
if (typeof(name) == "undefined")
name = tinyMCE.settings['theme'];
tinyMCE.loadScript(tinyMCE.baseURL + '/themes/' + name + '/langs/' + tinyMCE.settings['language'] + '.js');
},
importPluginLanguagePack : function(name) {
var b = tinyMCE.baseURL + '/plugins/' + name;
if (this.plugins[name])
b = this.plugins[name].baseURL;
tinyMCE.loadScript(b + '/langs/' + tinyMCE.settings['language'] + '.js');
},
applyTemplate : function(h, as) {
return h.replace(new RegExp('\\{\\$([a-z0-9_]+)\\}', 'gi'), function(m, s) {
if (s.indexOf('lang_') == 0 && tinyMCELang[s])
return tinyMCELang[s];
if (as && as[s])
return as[s];
if (tinyMCE.settings[s])
return tinyMCE.settings[s];
if (m == 'themeurl')
return tinyMCE.themeURL;
return m;
});
},
replaceVar : function(h, r, v) {
return h.replace(new RegExp('{\\\$' + r + '}', 'g'), v);
},
openWindow : function(template, args) {
var html, width, height, x, y, resizable, scrollbars, url;
args = !args ? {} : args;
args['mce_template_file'] = template['file'];
args['mce_width'] = template['width'];
args['mce_height'] = template['height'];
tinyMCE.windowArgs = args;
html = template['html'];
if (!(width = parseInt(template['width'])))
width = 320;
if (!(height = parseInt(template['height'])))
height = 200;
// Add to height in M$ due to SP2 WHY DON'T YOU GUYS IMPLEMENT innerWidth of windows!!
if (tinyMCE.isIE)
height += 40;
else
height += 20;
x = parseInt(screen.width / 2.0) - (width / 2.0);
y = parseInt(screen.height / 2.0) - (height / 2.0);
resizable = (args && args['resizable']) ? args['resizable'] : "no";
scrollbars = (args && args['scrollbars']) ? args['scrollbars'] : "no";
if (template['file'].charAt(0) != '/' && template['file'].indexOf('://') == -1)
url = tinyMCE.baseURL + "/themes/" + tinyMCE.getParam("theme") + "/" + template['file'];
else
url = template['file'];
// Replace all args as variables in URL
for (var name in args) {
if (typeof(args[name]) == 'function')
continue;
url = tinyMCE.replaceVar(url, name, escape(args[name]));
}
if (html) {
html = tinyMCE.replaceVar(html, "css", this.settings['popups_css']);
html = tinyMCE.applyTemplate(html, args);
var win = window.open("", "mcePopup" + new Date().getTime(), "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=yes,minimizable=" + resizable + ",modal=yes,width=" + width + ",height=" + height + ",resizable=" + resizable);
if (win == null) {
alert(tinyMCELang['lang_popup_blocked']);
return;
}
win.document.write(html);
win.document.close();
win.resizeTo(width, height);
win.focus();
} else {
if ((tinyMCE.isRealIE) && resizable != 'yes' && tinyMCE.settings["dialog_type"] == "modal") {
height += 10;
var features = "resizable:" + resizable
+ ";scroll:"
+ scrollbars + ";status:yes;center:yes;help:no;dialogWidth:"
+ width + "px;dialogHeight:" + height
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -