tiny_mce_src.js
来自「很棒的在线教学系统」· JavaScript 代码 · 共 2,013 行 · 第 1/5 页
JS
2,013 行
tinyMCE._setHTML(doc, inst.formElement.value); if (!tinyMCE.isMSIE) doc.body.innerHTML = tinyMCE._cleanupHTML(inst, doc, this.settings, doc.body, inst.visualAid); } } }, addMCEControl : function(replace_element, form_element_name, target_document) { var id = "mce_editor_" + tinyMCE.idCounter++; var inst = new TinyMCE_Control(tinyMCE.settings); inst.editorId = id; this.instances[id] = inst; inst._onAdd(replace_element, form_element_name, target_document); }, removeMCEControl : function(editor_id) { var inst = tinyMCE.getInstanceById(editor_id); if (inst) { inst.switchSettings(); editor_id = inst.editorId; var html = tinyMCE.getContent(editor_id); // Remove editor instance from instances array var tmpInstances = new Array(); for (var instanceName in tinyMCE.instances) { var instance = tinyMCE.instances[instanceName]; if (!tinyMCE.isInstance(instance)) continue; if (instanceName != editor_id) tmpInstances[instanceName] = instance; } tinyMCE.instances = tmpInstances; tinyMCE.selectedElement = null; tinyMCE.selectedInstance = null; // Remove element var replaceElement = document.getElementById(editor_id + "_parent"); var oldTargetElement = inst.oldTargetElement; var targetName = oldTargetElement.nodeName.toLowerCase(); if (targetName == "textarea" || targetName == "input") { // Just show the old text area replaceElement.parentNode.removeChild(replaceElement); oldTargetElement.style.display = "inline"; oldTargetElement.value = html; } else { oldTargetElement.innerHTML = html; oldTargetElement.style.display = 'block'; replaceElement.parentNode.insertBefore(oldTargetElement, replaceElement); replaceElement.parentNode.removeChild(replaceElement); } } }, triggerSave : function(skip_cleanup, skip_callback) { // Cleanup and set all form fields for (var n in tinyMCE.instances) { var inst = tinyMCE.instances[n]; if (!tinyMCE.isInstance(inst)) continue; inst.switchSettings(); tinyMCE.settings['preformatted'] = false; // Default to false if (typeof(skip_cleanup) == "undefined") skip_cleanup = false; // Default to false if (typeof(skip_callback) == "undefined") skip_callback = false; tinyMCE._setHTML(inst.getDoc(), inst.getBody().innerHTML); // Remove visual aids when cleanup is disabled if (inst.settings['cleanup'] == false) { tinyMCE.handleVisualAid(inst.getBody(), true, false, inst); tinyMCE._setEventsEnabled(inst.getBody(), true); } tinyMCE._customCleanup(inst, "submit_content_dom", inst.contentWindow.document.body); var htm = skip_cleanup ? inst.getBody().innerHTML : tinyMCE._cleanupHTML(inst, inst.getDoc(), this.settings, inst.getBody(), this.visualAid, true, true); htm = tinyMCE._customCleanup(inst, "submit_content", htm); if (!skip_callback && tinyMCE.settings['save_callback'] != "") var content = eval(tinyMCE.settings['save_callback'] + "(inst.formTargetElementId,htm,inst.getBody());"); // Use callback content if available if ((typeof(content) != "undefined") && content != null) htm = content; // Replace some weird entities (Bug: #1056343) htm = tinyMCE.regexpReplace(htm, "(", "(", "gi"); htm = tinyMCE.regexpReplace(htm, ")", ")", "gi"); htm = tinyMCE.regexpReplace(htm, ";", ";", "gi"); htm = tinyMCE.regexpReplace(htm, """, """, "gi"); htm = tinyMCE.regexpReplace(htm, "^", "^", "gi"); if (inst.formElement) inst.formElement.value = htm; if (tinyMCE.isSafari && inst.formElement) inst.formElement.innerText = htm; } }, resetForm : function(form_index) { var i, inst, n, formObj = document.forms[form_index]; for (n in tinyMCE.instances) { inst = tinyMCE.instances[n]; if (!tinyMCE.isInstance(inst)) continue; inst.switchSettings(); for (i=0; i<formObj.elements.length; i++) { if (inst.formTargetElementId == formObj.elements[i].name) inst.getBody().innerHTML = inst.startContent; } } }, execInstanceCommand : function(editor_id, command, user_interface, value, focus) { var inst = tinyMCE.getInstanceById(editor_id); if (inst) { if (typeof(focus) == "undefined") focus = true; if (focus) inst.contentWindow.focus(); // Reset design mode if lost inst.autoResetDesignMode(); this.selectedElement = inst.getFocusElement(); this.selectedInstance = inst; tinyMCE.execCommand(command, user_interface, value); // Cancel event so it doesn't call onbeforeonunlaod if (tinyMCE.isMSIE && window.event != null) tinyMCE.cancelEvent(window.event); } }, execCommand : function(command, user_interface, value) { // Default input user_interface = user_interface ? user_interface : false; value = value ? value : null; if (tinyMCE.selectedInstance) tinyMCE.selectedInstance.switchSettings(); switch (command) { case 'mceHelp': tinyMCE.openWindow({ file : 'about.htm', width : 480, height : 380 }, { tinymce_version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion, tinymce_releasedate : tinyMCE.releaseDate, inline : "yes" }); return; case 'mceFocus': var inst = tinyMCE.getInstanceById(value); if (inst) inst.contentWindow.focus(); return; case "mceAddControl": case "mceAddEditor": tinyMCE.addMCEControl(tinyMCE._getElementById(value), value); return; case "mceAddFrameControl": tinyMCE.addMCEControl(tinyMCE._getElementById(value), value['element'], value['document']); return; case "mceRemoveControl": case "mceRemoveEditor": tinyMCE.removeMCEControl(value); return; case "mceResetDesignMode": // Resets the designmode state of the editors in Gecko if (!tinyMCE.isMSIE) { for (var n in tinyMCE.instances) { if (!tinyMCE.isInstance(tinyMCE.instances[n])) continue; try { tinyMCE.instances[n].getDoc().designMode = "on"; } catch (e) { // Ignore any errors } } } return; } if (this.selectedInstance) { this.selectedInstance.execCommand(command, user_interface, value); } else if (tinyMCE.settings['focus_alert']) alert(tinyMCELang['lang_focus_alert']); }, _createIFrame : function(replace_element) { var iframe = document.createElement("iframe"); var id = replace_element.getAttribute("id"); var aw, ah; aw = "" + tinyMCE.settings['area_width']; ah = "" + tinyMCE.settings['area_height']; if (aw.indexOf('%') == -1) { aw = parseInt(aw); aw = aw < 0 ? 300 : aw; aw = aw + "px"; } if (ah.indexOf('%') == -1) { ah = parseInt(ah); ah = ah < 0 ? 240 : ah; ah = ah + "px"; } iframe.setAttribute("id", id); //iframe.setAttribute("className", "mceEditorArea"); iframe.setAttribute("border", "0"); iframe.setAttribute("frameBorder", "0"); iframe.setAttribute("marginWidth", "0"); iframe.setAttribute("marginHeight", "0"); iframe.setAttribute("leftMargin", "0"); iframe.setAttribute("topMargin", "0"); iframe.setAttribute("width", aw); iframe.setAttribute("height", ah); iframe.setAttribute("allowtransparency", "true"); if (tinyMCE.settings["auto_resize"]) iframe.setAttribute("scrolling", "no"); // Must have a src element in MSIE HTTPs breaks aswell as absoute URLs if (tinyMCE.isMSIE && !tinyMCE.isOpera) iframe.setAttribute("src", this.settings['default_document']); iframe.style.width = aw; iframe.style.height = ah; // MSIE 5.0 issue if (tinyMCE.isMSIE && !tinyMCE.isOpera) replace_element.outerHTML = iframe.outerHTML; else replace_element.parentNode.replaceChild(iframe, replace_element); if (tinyMCE.isMSIE) return window.frames[id]; else return iframe; }, setupContent : function(editor_id) { var inst = tinyMCE.instances[editor_id]; var doc = inst.getDoc(); var head = doc.getElementsByTagName('head').item(0); var content = inst.startContent; inst.switchSettings(); // 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(document.frames["' + editor_id + '"].document, "' + editor_id + '");}catch(e){}', 500); if (tinyMCE.settings["force_br_newlines"]) document.frames[editor_id].document.styleSheets[0].addRule("p", "margin: 0;"); var body = document.frames[editor_id].document.body; 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 = document.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());
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?