📄 tiny_mce_src.js
字号:
inst.useCSS = false; tinyMCE.dispatchCallback(inst, 'show_instance_callback', 'showInstance', inst); } } else tinyMCE.addMCEControl(tinyMCE._getElementById(value), value); return; case "mceResetDesignMode": // Resets the designmode state of the editors in Gecko if (tinyMCE.isGecko) { for (n in tinyMCE.instances) { if (!tinyMCE.isInstance(tinyMCE.instances[n])) continue; try { tinyMCE.instances[n].getDoc().designMode = "off"; tinyMCE.instances[n].getDoc().designMode = "on"; tinyMCE.instances[n].useCSS = false; } catch (e) { // Ignore any errors } } } return; } if (inst) { inst.execCommand(command, user_interface, value); } else if (tinyMCE.settings.focus_alert) alert(tinyMCELang.lang_focus_alert); }, _createIFrame : function(replace_element, doc, win) { var iframe, id = replace_element.getAttribute("id"); var aw, ah; if (typeof(doc) == "undefined") doc = document; if (typeof(win) == "undefined") win = window; iframe = doc.createElement("iframe"); aw = "" + tinyMCE.settings.area_width; ah = "" + tinyMCE.settings.area_height; if (aw.indexOf('%') == -1) { aw = parseInt(aw); aw = (isNaN(aw) || aw < 0) ? 300 : aw; aw = aw + "px"; } if (ah.indexOf('%') == -1) { ah = parseInt(ah); ah = (isNaN(ah) || ah < 0) ? 240 : ah; ah = ah + "px"; } iframe.setAttribute("id", id); iframe.setAttribute("name", id); iframe.setAttribute("class", "mceEditorIframe"); 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"); iframe.className = 'mceEditorIframe'; if (tinyMCE.settings.auto_resize) iframe.setAttribute("scrolling", "no"); // Must have a src element in MSIE HTTPs breaks aswell as absoute URLs if (tinyMCE.isRealIE) iframe.setAttribute("src", this.settings.default_document); iframe.style.width = aw; iframe.style.height = ah; // Ugly hack for Gecko problem in strict mode if (tinyMCE.settings.strict_loading_mode) iframe.style.marginBottom = '-5px'; // MSIE 5.0 issue if (tinyMCE.isRealIE) replace_element.outerHTML = iframe.outerHTML; else replace_element.parentNode.replaceChild(iframe, replace_element); if (tinyMCE.isRealIE) return win.frames[id]; else return iframe; }, setupContent : function(editor_id) { var inst = tinyMCE.instances[editor_id], i, doc = inst.getDoc(), head = doc.getElementsByTagName('head').item(0); var content = inst.startContent, contentElement, body; // HTML values get XML encoded in strict mode if (tinyMCE.settings.strict_loading_mode) { content = content.replace(/</g, '<'); content = content.replace(/>/g, '>'); content = content.replace(/"/g, '"'); content = content.replace(/&/g, '&'); } tinyMCE.selectedInstance = inst; inst.switchSettings(); // Not loaded correctly hit it again, Mozilla bug #997860 if (!tinyMCE.isIE && 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; } // Wait for it to load if (!head || !doc.body) { 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'); } // BlockFormat shortcuts keys for (i=1; i<=6; i++) inst.addShortcut('ctrl', '' + i, '', 'FormatBlock', false, '<h' + i + '>'); inst.addShortcut('ctrl', '7', '', 'FormatBlock', false, '<p>'); inst.addShortcut('ctrl', '8', '', 'FormatBlock', false, '<div>'); inst.addShortcut('ctrl', '9', '', 'FormatBlock', false, '<address>'); // 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.getBody().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.isIE) 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.isIE) { // 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;"); body = inst.getBody(); body.editorId = editor_id; } content = tinyMCE.cleanupHTMLCode(content); // Fix for bug #958637 if (!tinyMCE.isIE) { contentElement = inst.getDoc().createElement("body"); doc = inst.getDoc(); contentElement.innerHTML = content; if (tinyMCE.settings.cleanup_on_startup) tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, doc, this.settings, contentElement)); else 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 try { tinyMCE.setInnerHTML(inst.getBody(), tinyMCE._cleanupHTML(inst, inst.contentDocument, this.settings, inst.getBody())); } catch(e) { // Ignore } } else tinyMCE._setHTML(inst.getDoc(), content); } // Fix for bug #957681 //inst.getDoc().designMode = inst.getDoc().designMode; 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.isIE) tinyMCE.addEventHandlers(inst); // Add blur handler if (tinyMCE.isIE) { 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 inst.select(); 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('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), ""); return false; }); } // Remove Gecko spellchecking if (tinyMCE.isGecko) inst.getBody().spellcheck = tinyMCE.getParam("gecko_spellcheck"); // Cleanup any mess left from storyAwayURLs tinyMCE._removeInternal(inst.getBody()); inst.select(); 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('\\s(mce_src|mce_href)=\"[^\"]*\"', 'gi'), ""); return false; }); } }, removeTinyMCEFormElements : function(form_obj) { var i, elementId; // Skip form element removal if (!tinyMCE.getParam('hide_selects_on_submit')) return; // 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 (i=0; i<form_obj.elements.length; i++) { 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, i, elm, keys; // 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.isRealIE) { 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.formSubmit(tinyMCE.isMSIE ? window.event.srcElement : e.target); return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -