📄 script_gecko.js.php
字号:
// control registration array var spaw_editors = new Array(); // returns true if editor is already registered function SPAW_editor_registered(editor) { var found = false; for(var i=0;i<spaw_editors.length;i++) { if (spaw_editors[i] == editor) { found = true; break; } } return(found); } // onsubmit function SPAW_UpdateFields() { for (var i=0; i<spaw_editors.length; i++) { SPAW_updateField(spaw_editors[i], null); } } // adds event handler for the form to update hidden fields function SPAW_addOnSubmitHandler(editor) { thefield = SPAW_getFieldByEditor(editor, null); var sTemp = ""; oForm = document.getElementById(thefield).form; if(oForm.onsubmit != null) { sTemp = oForm.onsubmit.toString(); iStart = sTemp.indexOf("{") + 2; sTemp = sTemp.substr(iStart,sTemp.length-iStart-2); } if (sTemp.indexOf("SPAW_UpdateFields();") == -1) { oForm.onsubmit = new Function("SPAW_UpdateFields();" + sTemp); } } // editor initialization function SPAW_editorInit(editor, css_stylesheet, direction) { var ed = document.getElementById(editor+'_rEdit'); if (!SPAW_editor_registered(editor)) { // register the editor spaw_editors[spaw_editors.length] = editor; // add on submit handler SPAW_addOnSubmitHandler(editor); ed.contentDocument.designMode = 'on'; var s_sheet = ed.contentDocument.createElement("link"); s_sheet.setAttribute("rel","stylesheet"); s_sheet.setAttribute("type","text/css"); s_sheet.setAttribute("href",css_stylesheet); var head = ed.contentDocument.getElementsByTagName("head"); head[0].appendChild(s_sheet); // set initial value var ta_field = document.getElementById(editor); var html = ta_field.value; if (html != null && html != "\n") ed.contentDocument.body.innerHTML = html; // hookup active toolbar related events ed.contentDocument.addEventListener('keyup', new Function("e","SPAW_onkeyup('"+editor+"',e);"), false); ed.contentDocument.addEventListener('mouseup', new Function("SPAW_update_toolbar('"+editor+"', true);"), false); // initialize toolbar spaw_context_html = ""; SPAW_update_toolbar(editor, true); // workaround to missing cursor on first load ed.contentDocument.designMode = 'on'; } } function SPAW_showColorPicker(editor,curcolor,callback) { var wnd = window.open('<?php echo $spaw_dir?>dialogs/colorpicker.php?lang=' + document.getElementById('SPAW_'+editor+'_lang').value + '&theme=' + document.getElementById('SPAW_'+editor+'_theme').value + '&editor=' + editor + '&callback=' + callback, "color_picker", 'status=no,modal=yes,width=350,height=250'); wnd.dialogArguments = curcolor; return wnd; } function SPAW_bold_click(editor, sender) { var ed = document.getElementById(editor+'_rEdit'); ed.contentDocument.execCommand('bold', false, null); ed.contentWindow.focus(); SPAW_update_toolbar(editor, true); } function SPAW_italic_click(editor, sender) { var ed = document.getElementById(editor+'_rEdit'); ed.contentDocument.execCommand('italic', false, null); ed.contentWindow.focus(); SPAW_update_toolbar(editor, true); } function SPAW_underline_click(editor, sender) { var ed = document.getElementById(editor+'_rEdit'); ed.contentDocument.execCommand('underline', false, null); ed.contentWindow.focus(); SPAW_update_toolbar(editor, true); } function SPAW_left_click(editor, sender) { var ed = document.getElementById(editor+'_rEdit'); ed.contentDocument.execCommand('justifyleft', false, null); ed.contentWindow.focus(); SPAW_update_toolbar(editor, true); } function SPAW_center_click(editor, sender) { var ed = document.getElementById(editor+'_rEdit'); ed.contentDocument.execCommand('justifycenter', false, null); ed.contentWindow.focus(); SPAW_update_toolbar(editor, true); } function SPAW_right_click(editor, sender) { var ed = document.getElementById(editor+'_rEdit'); ed.contentDocument.execCommand('justifyright', false, null); ed.contentWindow.focus(); SPAW_update_toolbar(editor, true); } function SPAW_justify_click(editor, sender) { var ed = document.getElementById(editor+'_rEdit'); ed.contentDocument.execCommand('justifyfull', false, null); ed.contentWindow.focus(); SPAW_update_toolbar(editor, true); } function SPAW_ordered_list_click(editor, sender) { var ed = document.getElementById(editor+'_rEdit'); ed.contentDocument.execCommand('insertorderedlist', false, null); ed.contentWindow.focus(); SPAW_update_toolbar(editor, true); } function SPAW_bulleted_list_click(editor, sender) { var ed = document.getElementById(editor+'_rEdit'); ed.contentDocument.execCommand('insertunorderedlist', false, null); ed.contentWindow.focus(); SPAW_update_toolbar(editor, true); } function SPAW_fore_color_click(editor, sender) { var wnd = SPAW_showColorPicker(editor,null,'SPAW_fore_color_click_callback'); } function SPAW_fore_color_click_callback(editor, sender) { var fCol = sender.returnValue; if (fCol != null) { var ed = document.getElementById(editor+'_rEdit'); ed.contentDocument.execCommand('forecolor', false, fCol); } ed.contentWindow.focus(); } function SPAW_bg_color_click(editor, sender) { var wnd = SPAW_showColorPicker(editor,null,'SPAW_bg_color_click_callback'); } function SPAW_bg_color_click_callback(editor, sender) { var fCol = sender.returnValue; if (fCol != null) { var ed = document.getElementById(editor+'_rEdit'); ed.contentDocument.execCommand('hilitecolor', false, fCol); } ed.contentWindow.focus(); } function SPAW_getA(editor) { var ed = document.getElementById(editor+'_rEdit'); var selection = ed.contentWindow.getSelection(); var selectedRange; if (selection.rangeCount > 0) { selectedRange = selection.getRangeAt(0); } var aControl = selectedRange.startContainer; while ((aControl.tagName != 'A') && (aControl.tagName != 'BODY')) { aControl = aControl.parentNode; } if (aControl.tagName == 'A') return(aControl); else return(null); } function SPAW_hyperlink_click(editor, sender) { var ed = document.getElementById(editor+'_rEdit'); var a = SPAW_getA(editor); var aProps = {}; // get anchors on the page aProps.anchors = new Array(); var links = ed.contentDocument.getElementsByTagName('A'); var aln = 0; if (links != null) aln = links.length; for (var i=0;i<aln;i++) { if (links[i].name != null && links[i].name != '') aProps.anchors[aProps.anchors.length] = links[i].name; } if (a) { aProps.href = a.attributes["href"]?a.attributes["href"].nodeValue:''; aProps.name = a.name; aProps.target = a.target; aProps.title = a.title; } var wnd = window.open('<?php echo $spaw_dir?>dialogs/a.php?lang=' + document.getElementById('SPAW_'+editor+'_lang').value + '&theme=' + document.getElementById('SPAW_'+editor+'_theme').value + '&editor=' + editor + '&callback=SPAW_hyperlink_click_callback', "link_window", 'status=no,modal=yes,width=350,height=250'); wnd.dialogArguments = aProps; } /***********************/ function insertNodeAtSelection(win, insertNode) { // get current selection var sel = win.getSelection(); // get the first range of the selection // (there's almost always only one range) var range = sel.getRangeAt(0); // deselect everything sel.removeAllRanges(); // remove content of current selection from document range.deleteContents(); // get location of current selection var container = range.startContainer; var pos = range.startOffset; // make a new range for the new selection range=document.createRange(); if (container.nodeType==3 && insertNode.nodeType==3) { // if we insert text in a textnode, do optimized insertion container.insertData(pos, insertNode.nodeValue); // put cursor after inserted text range.setEnd(container, pos+insertNode.length); range.setStart(container, pos+insertNode.length); } else { var afterNode; if (container.nodeType==3) { // when inserting into a textnode // we create 2 new textnodes // and put the insertNode in between var textNode = container; container = textNode.parentNode; var text = textNode.nodeValue; // text before the split var textBefore = text.substr(0,pos); // text after the split var textAfter = text.substr(pos); var beforeNode = document.createTextNode(textBefore); var afterNode = document.createTextNode(textAfter); // insert the 3 new nodes before the old one container.insertBefore(afterNode, textNode); container.insertBefore(insertNode, afterNode); container.insertBefore(beforeNode, insertNode); // remove the old node container.removeChild(textNode); } else { // else simply insert the node afterNode = container.childNodes[pos]; container.insertBefore(insertNode, afterNode); } range.setEnd(afterNode, 0); range.setStart(afterNode, 0); } sel.addRange(range); // remove all ranges win.getSelection().removeAllRanges(); }; /***********************/ function SPAW_hyperlink_click_callback(editor, sender) { var naProps = sender.returnValue; var ed = document.getElementById(editor+'_rEdit'); var a = SPAW_getA(editor); if (a) { // edit link if (!naProps.href && !naProps.name) { // remove hyperlink a.outerHTML = a.innerHTML; } else { // set link properties if (naProps.href) a.href = naProps.href; else a.removeAttribute('href',0); if (naProps.name) a.name = naProps.name; else a.removeAttribute('name',0); if (naProps.target && naProps.target!='_self') a.target = naProps.target; else a.removeAttribute('target',0); if (naProps.title) a.title = naProps.title; else a.removeAttribute('title',0); a.removeAttribute('onclick',0); } } else { // new link var a; a = document.createElement('A'); if (naProps.name) { a.name = naProps.name; } else if (naProps.href) a.href = naProps.href; if (naProps.target && naProps.target!='_self') a.target = naProps.target; if (naProps.title) a.title = naProps.title; if (ed.contentWindow.getSelection().rangeCount>0 && ed.contentWindow.getSelection().getRangeAt(0).startOffset != ed.contentWindow.getSelection().getRangeAt(0).endOffset) { a.appendChild(ed.contentWindow.getSelection().getRangeAt(0).cloneContents()); } else { a.innerHTML = (a.href && a.attributes["href"].nodeValue!='')?a.attributes["href"].nodeValue:a.name; } insertNodeAtSelection(ed.contentWindow, a); } } function SPAW_internal_link_click(editor, sender) { } function SPAW_image_insert_click(editor, sender) { var wnd = window.open('<?php echo $spaw_dir?>dialogs/img_library.php?lang=' + document.getElementById('SPAW_'+editor+'_lang').value + '&theme=' + document.getElementById('SPAW_'+editor+'_theme').value + '&editor=' + editor + '&callback=SPAW_image_insert_click_callback', "img_library", 'status=no,modal=yes,width=420,height=420'); } function SPAW_image_insert_click_callback(editor, sender) { var imgSrc = sender.returnValue; if (imgSrc != null) { var ed = document.getElementById(editor+'_rEdit'); ed.contentDocument.execCommand('insertimage', false, imgSrc); } ed.contentWindow.focus(); } function SPAW_image_prop_click(editor, sender) { var im = SPAW_getImg(editor); // current img if (im) { var iProps = {}; if (im.attributes["src"]) iProps.src = im.attributes["src"].nodeValue; iProps.alt = im.alt; iProps.width = (im.style.width)?im.style.width:im.width; iProps.height = (im.style.height)?im.style.height:im.height; iProps.border = im.border; iProps.align = im.align; if (im.hspace>-1) // (-1 when not set under gecko for some reason) iProps.hspace = im.attributes["hspace"].nodeValue; if (im.vspace>-1) iProps.vspace = im.attributes["vspace"].nodeValue; var wnd = window.open('<?php echo $spaw_dir?>dialogs/img.php?lang=' + document.getElementById('SPAW_'+editor+'_lang').value + '&theme=' + document.getElementById('SPAW_'+editor+'_theme').value + '&editor=' + editor + '&callback=SPAW_image_prop_click_callback', "img_prop", 'status=no,modal=yes,width=420,height=420'); wnd.dialogArguments = iProps; } } function SPAW_image_prop_click_callback(editor, sender) { var ed = document.getElementById(editor+'_rEdit'); var niProps = sender.returnValue; var im = SPAW_getImg(editor); // current img if (im && niProps) { im.src = (niProps.src)?niProps.src:''; if (niProps.alt) { im.alt = niProps.alt; } else { im.removeAttribute("alt",0); } im.align = (niProps.align)?niProps.align:''; im.width = (niProps.width)?niProps.width:''; //im.style.width = (niProps.width)?niProps.width:''; im.height = (niProps.height)?niProps.height:''; //im.style.height = (niProps.height)?niProps.height:''; if (niProps.border) { im.border = niProps.border; } else { im.removeAttribute("border",0); } if (niProps.hspace) { im.hspace = niProps.hspace; } else { im.removeAttribute("hspace",0); } if (niProps.vspace) { im.vspace = niProps.vspace; } else { im.removeAttribute("vspace",0); } } ed.contentWindow.focus(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -