📄 htmlarea_bak.php
字号:
var collapsed = (typeof pos != "undefined"); if (HTMLArea.is_ie) { range = this._doc.body.createTextRange(); range.moveToElementText(node); (collapsed) && range.collapse(pos); range.select(); } else { var sel = this._getSelection(); range = this._doc.createRange(); range.selectNodeContents(node); (collapsed) && range.collapse(pos); sel.removeAllRanges(); sel.addRange(range); }};/** Call this function to insert HTML code at the current position. It deletes * the selection, if any. */HTMLArea.prototype.insertHTML = function(html) { var sel = this._getSelection(); var range = this._createRange(sel); if (HTMLArea.is_ie) { range.pasteHTML(html); } else { // construct a new document fragment with the given HTML var fragment = this._doc.createDocumentFragment(); var div = this._doc.createElement("div"); div.innerHTML = html; while (div.firstChild) { // the following call also removes the node from div fragment.appendChild(div.firstChild); } // this also removes the selection var node = this.insertNodeAtSelection(fragment); }};/** * Call this function to surround the existing HTML code in the selection with * your tags. FIXME: buggy! This function will be deprecated "soon". */HTMLArea.prototype.surroundHTML = function(startTag, endTag) { var html = this.getSelectedHTML(); // the following also deletes the selection this.insertHTML(startTag + html + endTag);};/// Retrieve the selected blockHTMLArea.prototype.getSelectedHTML = function() { var sel = this._getSelection(); var range = this._createRange(sel); var existing = null; if (HTMLArea.is_ie) { existing = range.htmlText; } else { existing = HTMLArea.getHTML(range.cloneContents(), false, this); } return existing;};/// Return true if we have some selectionHTMLArea.prototype.hasSelectedText = function() { // FIXME: come _on_ mishoo, you can do better than this ;-) return this.getSelectedHTML() != '';};HTMLArea.prototype._createLink = function(link) { var editor = this; var outparam = null; if (typeof link == "undefined") { link = this.getParentElement(); if (link && !/^a$/i.test(link.tagName)) link = null; } if (link) outparam = { f_href : HTMLArea.is_ie ? editor.stripBaseURL(link.href) : link.getAttribute("href"), f_title : link.title, f_target : link.target }; this._popupDialog("link_std.php?id=<?php echo $id; ?>", function(param) { if (!param) return false; var a = link; if (!a) { editor._doc.execCommand("createlink", false, param.f_href); a = editor.getParentElement(); var sel = editor._getSelection(); var range = editor._createRange(sel); // if (!HTMLArea.is_ie) { /// Removed by PJ and Martin, Moodle bug #1455 // a = range.startContainer; // if (!/^a$/i.test(a.tagName)) // a = a.nextSibling; // } } else a.href = param.f_href.trim(); if (!/^a$/i.test(a.tagName)) return false; a.target = param.f_target.trim(); a.title = param.f_title.trim(); editor.selectNodeContents(a); editor.updateToolbar(); }, outparam);};// Called when the user clicks on "InsertImage" button. If an image is already// there, it will just modify it's properties.HTMLArea.prototype._insertImage = function(image) { var editor = this; // for nested functions var outparam = null; if (typeof image == "undefined") { image = this.getParentElement(); if (image && !/^img$/i.test(image.tagName)) image = null; } if (image) outparam = { f_url : HTMLArea.is_ie ? editor.stripBaseURL(image.src) : image.getAttribute("src"), f_alt : image.alt, f_border : image.border, f_align : image.align, f_vert : image.vspace, f_horiz : image.hspace, f_width : image.width, f_height : image.height }; this._popupDialog("<?php if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) { echo "insert_image.php?id=$id"; } else { echo "insert_image_std.php?id=$id"; }?>", function(param) { if (!param) { // user must have pressed Cancel return false; } var img = image; if (!img) { var sel = editor._getSelection(); var range = editor._createRange(sel); editor._doc.execCommand("insertimage", false, param.f_url); if (HTMLArea.is_ie) { img = range.parentElement(); // wonder if this works... if (img.tagName.toLowerCase() != "img") { img = img.previousSibling; } } else { img = range.startContainer.previousSibling; } } else { img.src = param.f_url; } for (field in param) { var value = param[field]; switch (field) { case "f_alt" : img.alt = value; break; case "f_border" : img.border = parseInt(value || "0"); break; case "f_align" : img.align = value; break; case "f_vert" : img.vspace = parseInt(value || "0"); break; case "f_horiz" : img.hspace = parseInt(value || "0"); break; case "f_width" : if(value != 0) { img.width = parseInt(value); } else { break; } break; case "f_height" : if(value != 0) { img.height = parseInt(value); } else { break; } break; } } }, outparam);};// Called when the user clicks the Insert Table buttonHTMLArea.prototype._insertTable = function() { var sel = this._getSelection(); var range = this._createRange(sel); var editor = this; // for nested functions this._popupDialog("insert_table.php", function(param) { if (!param) { // user must have pressed Cancel return false; } var doc = editor._doc; // create the table element var table = doc.createElement("table"); // assign the given arguments for (var field in param) { var value = param[field]; if (!value) { continue; } switch (field) { case "f_width" : table.width = value + param["f_unit"]; break; case "f_align" : table.align = value; break; case "f_border" : table.border = parseInt(value); break; case "f_spacing" : table.cellspacing = parseInt(value); break; case "f_padding" : table.cellpadding = parseInt(value); break; } } var tbody = doc.createElement("tbody"); table.appendChild(tbody); for (var i = 0; i < param["f_rows"]; ++i) { var tr = doc.createElement("tr"); tbody.appendChild(tr); for (var j = 0; j < param["f_cols"]; ++j) { var td = doc.createElement("td"); /// Moodle hack if(param["f_unit"] == "px") { tdwidth = Math.round(table.width / param["f_cols"]); } else { tdwidth = Math.round(100 / param["f_cols"]); } td.setAttribute("width",tdwidth + param["f_unit"]); td.setAttribute("valign","top"); /// Moodle hack -ends tr.appendChild(td); // Mozilla likes to see something inside the cell. (HTMLArea.is_gecko) && td.appendChild(doc.createElement("br")); } } if (HTMLArea.is_ie) { range.pasteHTML(table.outerHTML); } else { // insert the table editor.insertNodeAtSelection(table); } return true; }, null);};/******************************************************************* Moodle hack - insertSmile******************************************************************//// since method insertimage doesn't work the same way in mozilla/// as it does in IE, let's go around this for both browsers.HTMLArea.prototype._insertSmile = function() { var sel = this._getSelection(); var range = this._createRange(sel); var editor = this; // for nested functions this._popupDialog("dlg_ins_smile.php", function(imgString) { if(!imgString) { return false; } if (HTMLArea.is_ie) { range.pasteHTML(imgString); } else { // insert the table editor.insertHTML(imgString); } return true; }, null);};HTMLArea.prototype._insertChar = function() { var sel = this._getSelection(); var range = this._createRange(sel); var editor = this; // for nested functions this._popupDialog("dlg_ins_char.php", function(sChar) { if(!sChar) { return false; } if (HTMLArea.is_ie) { range.pasteHTML(sChar); } else { // insert the table editor.insertHTML(sChar); } return true; }, null);};HTMLArea.prototype._removelink = function() { var editor = this; link = this.getParentElement(); editor.selectNodeContents(link); this._doc.execCommand("unlink", false, null); this.focusEditor();};/************************************************************************* Moodle hack's ends************************************************************************//*************************************************** * Category: EVENT HANDLERS ***************************************************/// el is reference to the SELECT object// txt is the name of the select field, as in config.toolbarHTMLArea.prototype._comboSelected = function(el, txt) { this.focusEditor(); var value = el.options[el.selectedIndex].value; switch (txt) { case "fontname": case "fontsize": this.execCommand(txt, false, value); break; case "formatblock": (HTMLArea.is_ie) && (value = "<" + value + ">"); this.execCommand(txt, false, value); break; default: // try to look it up in the registered dropdowns var dropdown = this.config.customSelects[txt]; if (typeof dropdown != "undefined") { dropdown.action(this); } else { alert("FIXME: combo box " + txt + " not implemented"); } }};// the execCommand function (intercepts some commands and replaces them with// our own implementation)HTMLArea.prototype.execCommand = function(cmdID, UI, param) { var editor = this; // for nested functions this.focusEditor(); cmdID = cmdID.toLowerCase(); switch (cmdID) { case "htmlmode" : this.setMode(); break; case "hilitecolor": (HTMLArea.is_ie) && (cmdID = "backcolor"); case "forecolor": this._popupDialog("select_color.php", function(color) { if (color) { // selection not canceled editor._doc.execCommand(cmdID, false, "#" + color); } }, HTMLArea._colorToRgb(this._doc.queryCommandValue(cmdID))); break; case "createlink": this._createLink(); break; case "unlink": this._removelink(); break; case "popupeditor": // this object will be passed to the newly opened window HTMLArea._object = this; if (HTMLArea.i
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -