📄 tiny_mce_src.js
字号:
// Not loaded correctly hit it again, Mozilla bug #997860
if (!tinyMCE.isMSIE && tinyMCE.getParam("setupcontent_reload", false) && doc.title != "blank_page") {
// This part will remove the designMode status
// Failes first time in Firefox 1.5b2 on Mac
try {doc.location.href = tinyMCE.baseURL + "/blank.htm";} catch (ex) {}
window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 1000);
return;
}
if (!head) {
window.setTimeout("tinyMCE.setupContent('" + editor_id + "');", 10);
return;
}
// Import theme specific content CSS the user specific
tinyMCE.importCSS(inst.getDoc(), tinyMCE.baseURL + "/themes/" + inst.settings['theme'] + "/css/editor_content.css");
tinyMCE.importCSS(inst.getDoc(), inst.settings['content_css']);
tinyMCE.dispatchCallback(inst, 'init_instance_callback', 'initInstance', inst);
// Setup keyboard shortcuts
if (tinyMCE.getParam('custom_undo_redo_keyboard_shortcuts')) {
inst.addShortcut('ctrl', 'z', 'lang_undo_desc', 'Undo');
inst.addShortcut('ctrl', 'y', 'lang_redo_desc', 'Redo');
}
// Add default shortcuts for gecko
if (tinyMCE.isGecko) {
inst.addShortcut('ctrl', 'b', 'lang_bold_desc', 'Bold');
inst.addShortcut('ctrl', 'i', 'lang_italic_desc', 'Italic');
inst.addShortcut('ctrl', 'u', 'lang_underline_desc', 'Underline');
}
// Setup span styles
if (tinyMCE.getParam("convert_fonts_to_spans"))
inst.getDoc().body.setAttribute('id', 'mceSpanFonts');
if (tinyMCE.settings['nowrap'])
doc.body.style.whiteSpace = "nowrap";
doc.body.dir = this.settings['directionality'];
doc.editorId = editor_id;
// Add on document element in Mozilla
if (!tinyMCE.isMSIE)
doc.documentElement.editorId = editor_id;
inst.setBaseHREF(tinyMCE.settings['base_href']);
// Replace new line characters to BRs
if (tinyMCE.settings['convert_newlines_to_brs']) {
content = tinyMCE.regexpReplace(content, "\r\n", "<br />", "gi");
content = tinyMCE.regexpReplace(content, "\r", "<br />", "gi");
content = tinyMCE.regexpReplace(content, "\n", "<br />", "gi");
}
// Open closed anchors
// content = content.replace(new RegExp('<a(.*?)/>', 'gi'), '<a$1></a>');
// Call custom cleanup code
content = tinyMCE.storeAwayURLs(content);
content = tinyMCE._customCleanup(inst, "insert_to_editor", content);
if (tinyMCE.isMSIE) {
// Ugly!!!
window.setInterval('try{tinyMCE.getCSSClasses(tinyMCE.instances["' + editor_id + '"].getDoc(), "' + editor_id + '");}catch(e){}', 500);
if (tinyMCE.settings["force_br_newlines"])
doc.styleSheets[0].addRule("p", "margin: 0;");
var body = inst.getBody();
body.editorId = editor_id;
}
content = tinyMCE.cleanupHTMLCode(content);
// Fix for bug #958637
if (!tinyMCE.isMSIE) {
var contentElement = inst.getDoc().createElement("body");
var doc = inst.getDoc();
contentElement.innerHTML = content;
// Remove weridness!
if (tinyMCE.isGecko && tinyMCE.settings['remove_lt_gt'])
content = content.replace(new RegExp('<>', 'g'), "");
if (tinyMCE.settings['cleanup_on_startup'])
tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, doc, this.settings, contentElement));
else {
// Convert all strong/em to b/i
content = tinyMCE.regexpReplace(content, "<strong", "<b", "gi");
content = tinyMCE.regexpReplace(content, "<em(/?)>", "<i$1>", "gi");
content = tinyMCE.regexpReplace(content, "<em ", "<i ", "gi");
content = tinyMCE.regexpReplace(content, "</strong>", "</b>", "gi");
content = tinyMCE.regexpReplace(content, "</em>", "</i>", "gi");
tinyMCE.setInnerHTML(inst.getBody(), content);
}
tinyMCE.convertAllRelativeURLs(inst.getBody());
} else {
if (tinyMCE.settings['cleanup_on_startup']) {
tinyMCE._setHTML(inst.getDoc(), content);
// Produces permission denied error in MSIE 5.5
eval('try {tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, inst.contentDocument, this.settings, inst.getBody()));} catch(e) {}');
} else
tinyMCE._setHTML(inst.getDoc(), content);
}
// Fix for bug #957681
//inst.getDoc().designMode = inst.getDoc().designMode;
// Setup element references
var parentElm = inst.targetDoc.getElementById(inst.editorId + '_parent');
inst.formElement = tinyMCE.isGecko ? parentElm.previousSibling : parentElm.nextSibling;
tinyMCE.handleVisualAid(inst.getBody(), true, tinyMCE.settings['visual'], inst);
tinyMCE.dispatchCallback(inst, 'setupcontent_callback', 'setupContent', editor_id, inst.getBody(), inst.getDoc());
// Re-add design mode on mozilla
if (!tinyMCE.isMSIE)
tinyMCE.addEventHandlers(inst);
// Add blur handler
if (tinyMCE.isMSIE) {
tinyMCE.addEvent(inst.getBody(), "blur", TinyMCE_Engine.prototype._eventPatch);
tinyMCE.addEvent(inst.getBody(), "beforedeactivate", TinyMCE_Engine.prototype._eventPatch); // Bug #1439953
// Workaround for drag drop/copy paste base href bug
if (!tinyMCE.isOpera) {
tinyMCE.addEvent(doc.body, "mousemove", TinyMCE_Engine.prototype.onMouseMove);
tinyMCE.addEvent(doc.body, "beforepaste", TinyMCE_Engine.prototype._eventPatch);
tinyMCE.addEvent(doc.body, "drop", TinyMCE_Engine.prototype._eventPatch);
}
}
// Trigger node change, this call locks buttons for tables and so forth
tinyMCE.selectedInstance = inst;
tinyMCE.selectedElement = inst.contentWindow.document.body;
// Call custom DOM cleanup
tinyMCE._customCleanup(inst, "insert_to_editor_dom", inst.getBody());
tinyMCE._customCleanup(inst, "setup_content_dom", inst.getBody());
tinyMCE._setEventsEnabled(inst.getBody(), false);
tinyMCE.cleanupAnchors(inst.getDoc());
if (tinyMCE.getParam("convert_fonts_to_spans"))
tinyMCE.convertSpansToFonts(inst.getDoc());
inst.startContent = tinyMCE.trim(inst.getBody().innerHTML);
inst.undoRedo.add({ content : inst.startContent });
// Cleanup any mess left from storyAwayURLs
if (tinyMCE.isGecko) {
// Remove mce_src from textnodes and comments
tinyMCE.selectNodes(inst.getBody(), function(n) {
if (n.nodeType == 3 || n.nodeType == 8) {
n.nodeValue = n.nodeValue.replace(new RegExp('\\smce_src=\"[^\"]*\"', 'gi'), "");
n.nodeValue = n.nodeValue.replace(new RegExp('\\smce_href=\"[^\"]*\"', 'gi'), "");
}
return false;
});
}
// Cleanup any mess left from storyAwayURLs
tinyMCE._removeInternal(inst.getBody());
tinyMCE.selectedInstance = inst;
tinyMCE.triggerNodeChange(false, true);
},
storeAwayURLs : function(s) {
// Remove all mce_src, mce_href and replace them with new ones
// s = s.replace(new RegExp('mce_src\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
// s = s.replace(new RegExp('mce_href\\s*=\\s*\"[^ >\"]*\"', 'gi'), '');
if (!s.match(/(mce_src|mce_href)/gi, s)) {
s = s.replace(new RegExp('src\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'src="$1" mce_src="$1"');
s = s.replace(new RegExp('href\\s*=\\s*\"([^ >\"]*)\"', 'gi'), 'href="$1" mce_href="$1"');
}
return s;
},
_removeInternal : function(n) {
if (tinyMCE.isGecko) {
// Remove mce_src from textnodes and comments
tinyMCE.selectNodes(n, function(n) {
if (n.nodeType == 3 || n.nodeType == 8) {
n.nodeValue = n.nodeValue.replace(new RegExp('\\smce_src=\"[^\"]*\"', 'gi'), "");
n.nodeValue = n.nodeValue.replace(new RegExp('\\smce_href=\"[^\"]*\"', 'gi'), "");
}
return false;
});
}
},
removeTinyMCEFormElements : function(form_obj) {
// Check if form is valid
if (typeof(form_obj) == "undefined" || form_obj == null)
return;
// If not a form, find the form
if (form_obj.nodeName != "FORM") {
if (form_obj.form)
form_obj = form_obj.form;
else
form_obj = tinyMCE.getParentElement(form_obj, "form");
}
// Still nothing
if (form_obj == null)
return;
// Disable all UI form elements that TinyMCE created
for (var i=0; i<form_obj.elements.length; i++) {
var elementId = form_obj.elements[i].name ? form_obj.elements[i].name : form_obj.elements[i].id;
if (elementId.indexOf('mce_editor_') == 0)
form_obj.elements[i].disabled = true;
}
},
handleEvent : function(e) {
var inst = tinyMCE.selectedInstance;
// Remove odd, error
if (typeof(tinyMCE) == "undefined")
return true;
//tinyMCE.debug(e.type + " " + e.target.nodeName + " " + (e.relatedTarget ? e.relatedTarget.nodeName : ""));
if (tinyMCE.executeCallback(tinyMCE.selectedInstance, 'handle_event_callback', 'handleEvent', e))
return false;
switch (e.type) {
case "beforedeactivate": // Was added due to bug #1439953
case "blur":
if (tinyMCE.selectedInstance)
tinyMCE.selectedInstance.execCommand('mceEndTyping');
tinyMCE.hideMenus();
return;
// Workaround for drag drop/copy paste base href bug
case "drop":
case "beforepaste":
if (tinyMCE.selectedInstance)
tinyMCE.selectedInstance.setBaseHREF(null);
// Fixes odd MSIE bug where drag/droping elements in a iframe with height 100% breaks
// This logic forces the width/height to be in pixels while the user is drag/dropping
if (tinyMCE.isMSIE && !tinyMCE.isOpera) {
var ife = tinyMCE.selectedInstance.iframeElement;
/*if (ife.style.width.indexOf('%') != -1) {
ife._oldWidth = ife.width.height;
ife.style.width = ife.clientWidth;
}*/
if (ife.style.height.indexOf('%') != -1) {
ife._oldHeight = ife.style.height;
ife.style.height = ife.clientHeight;
}
}
window.setTimeout("tinyMCE.selectedInstance.setBaseHREF(tinyMCE.settings['base_href']);tinyMCE._resetIframeHeight();", 1);
return;
case "submit":
tinyMCE.removeTinyMCEFormElements(tinyMCE.isMSIE ? window.event.srcElement : e.target);
tinyMCE.triggerSave();
tinyMCE.isNotDirty = true;
return;
case "reset":
var formObj = tinyMCE.isMSIE ? window.event.srcElement : e.target;
for (var i=0; i<document.forms.length; i++) {
if (document.forms[i] == formObj)
window.setTimeout('tinyMCE.resetForm(' + i + ');', 10);
}
return;
case "keypress":
if (inst && inst.handleShortcut(e))
return false;
if (e.target.editorId) {
tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId];
} else {
if (e.target.ownerDocument.editorId)
tinyMCE.selectedInstance = tinyMCE.instances[e.target.ownerDocument.editorId];
}
if (tinyMCE.selectedInstance)
tinyMCE.selectedInstance.switchSettings();
// Insert P element
if (tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && e.keyCode == 13 && !e.shiftKey) {
// Insert P element instead of BR
if (TinyMCE_ForceParagraphs._insertPara(tinyMCE.selectedInstance, e)) {
// Cancel event
tinyMCE.execCommand("mceAddUndoLevel");
tinyMCE.cancelEvent(e);
return false;
}
}
// Handle backspace
if (tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && (e.keyCode == 8 || e.keyCode == 46) && !e.shiftKey) {
// Insert P element instead of BR
if (TinyMCE_ForceParagraphs._handleBackSpace(tinyMCE.selectedInstance, e.type)) {
// Cancel event
tinyMCE.execCommand("mceAddUndoLevel");
tinyMCE.cancelEvent(e);
return false;
}
}
// Return key pressed
if (tinyMCE.isMSIE && tinyMCE.settings['force_br_newlines'] && e.keyCode == 13) {
if (e.target.editorId)
tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId];
if (tinyMCE.selectedInstance) {
var sel = tinyMCE.selectedInstance.getDoc().selection;
var rng = sel.createRange();
if (tinyMCE.getParentElement(rng.parentElement(), "li") != null)
return false;
// Cancel event
e.returnValue = false;
e.cancelBubble = true;
// Insert BR element
rng.pasteHTML("<br />");
rng.collapse(false);
rng.select();
tinyMCE.execCommand("mceAddUndoLevel");
tinyMCE.triggerNodeChange(false);
return false;
}
}
// Backspace or delete
if (e.keyCode == 8 || e.keyCode == 46) {
tinyMCE.selectedElement = e.target;
tinyMCE.linkElement = tinyMCE.getParentElement(e.target, "a");
tinyMCE.imgElement = tinyMCE.getParentElement(e.target, "img");
tinyMCE.triggerNodeChange(false);
}
return false;
break;
case "keyup":
case "keydown":
tinyMCE.hideMenus();
tinyMCE.hasMouseMoved = false;
if (inst && inst.handleShortcut(e))
return false;
if (e.target.editorId)
tinyMCE.selectedInstance = tinyMCE.instances[e.target.editorId];
else
return;
if (tinyMCE.selectedInstance)
tinyMCE.selectedInstance.switchSettings();
var inst = tinyMCE.selectedInstance;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -