📄 bs_editor.class.js
字号:
var url = this.specialCharSelector[0] + '?objectName=' + this._objectName;url += '&callbackLoad=callbackWindowSpecialChars&callbackSave=insertSpecialChar';if (moz) {window.open(url, "specialCharSelector", "width=" + this.specialCharSelector[1] + ",height=" + this.specialCharSelector[2] + ",left=0,top=0,scrollbars=no,status=no,toolbar=no,resizable=no,location=no,hotkeys=no,dependent=yes");} else {var ret = window.showModalDialog(url, true, "dialogWidth:" + this.specialCharSelector[1] + "px; dialogHeight:" + this.specialCharSelector[2] + "px;");if (ret) this.insertSpecialChar(ret);}break;case 'x':this.workingDoc.execCommand('FontName', true, 'arial');break;default:window[btnObj.action]();}}this.loadButtonsText = function() {var buttons = new Array();this.buttonsText = buttons;buttons['cut'] = new Array();buttons['cut'].action = 'Cut';buttons['cut'].imgName = 'bs_cut';buttons['copy'] = new Array();buttons['copy'].action = 'Copy';buttons['copy'].imgName = 'bs_copy';buttons['paste'] = new Array();buttons['paste'].action = 'Paste';buttons['paste'].imgName = 'bs_paste';var i = buttons.length;buttons[i] = '__SEPARATOR__';buttons['undo'] = new Array();buttons['undo'].action = 'Undo';buttons['undo'].imgName = 'bs_undo';buttons['redo'] = new Array();buttons['redo'].action = 'Redo';buttons['redo'].imgName = 'bs_redo';var i = buttons.length;buttons[i] = '__SEPARATOR__';}this._drawButtonBarText = function() {toolbarText = new Bs_ButtonBar();toolbarText.useHelpBar = 'toolbarHelptext';if (typeof(this.buttonsText) == 'undefined') this.loadButtonsText();this._drawButtonBarHelper(this.buttonsText, 'toolbarText', 'text');}this.loadButtonsWysiwyg = function() {var buttons = new Array();this.buttonsWysiwyg = buttons;buttons['cut'] = new Array();buttons['cut'].action = 'Cut';buttons['cut'].imgName = 'bs_cut';buttons['copy'] = new Array();buttons['copy'].action = 'Copy';buttons['copy'].imgName = 'bs_copy';buttons['paste'] = new Array();buttons['paste'].action = 'Paste';buttons['paste'].imgName = 'bs_paste';var i = buttons.length;buttons[i] = '__SEPARATOR__';buttons['undo'] = new Array();buttons['undo'].action = 'Undo';buttons['undo'].imgName = 'bs_undo';buttons['redo'] = new Array();buttons['redo'].action = 'Redo';buttons['redo'].imgName = 'bs_redo';var i = buttons.length;buttons[i] = '__SEPARATOR__';buttons['bold'] = new Array();buttons['bold'].action = 'Bold';buttons['italic'] = new Array();buttons['italic'].action = 'Italic';buttons['underline'] = new Array();buttons['underline'].action = 'Underline';buttons['underline'].imgName = 'bs_formatUnderline';var i = buttons.length;buttons[i] = '__SEPARATOR__';buttons['font'] = new Array();buttons['font'].action = 'Font';buttons['font'].imgName = 'bs_font';buttons['forecolor'] = new Array();buttons['forecolor'].action = 'ForeColor';buttons['forecolor'].imgName = 'bs_fgColor';var i = buttons.length;buttons[i] = '__SEPARATOR__';buttons['justifyleft'] = new Array();buttons['justifyleft'].action = 'JustifyLeft';buttons['justifyleft'].imgName = 'bs_alignLeft';buttons['justifycenter'] = new Array();buttons['justifycenter'].action = 'JustifyCenter';buttons['justifycenter'].imgName = 'bs_alignCenter';buttons['justifyright'] = new Array();buttons['justifyright'].action = 'JustifyRight';buttons['justifyright'].imgName = 'bs_alignRight';var i = buttons.length;buttons[i] = '__SEPARATOR__';buttons['insertorderedlist'] = new Array();buttons['insertorderedlist'].action = 'InsertOrderedList';buttons['insertorderedlist'].imgName = 'bs_ol';buttons['insertunorderedlist'] = new Array();buttons['insertunorderedlist'].action = 'InsertUnorderedList';buttons['insertunorderedlist'].imgName = 'bs_ul';var i = buttons.length;buttons[i] = '__SEPARATOR__';buttons['outdent'] = new Array();buttons['outdent'].action = 'Outdent';buttons['outdent'].imgName = 'bs_outdent';buttons['indent'] = new Array();buttons['indent'].action = 'Indent';buttons['indent'].imgName = 'bs_indent';var i = buttons.length;buttons[i] = '__SEPARATOR__';buttons['createlink'] = new Array();buttons['createlink'].action = 'CreateLink';buttons['createlink'].imgName = 'bs_createLink';buttons['unlink'] = new Array();buttons['unlink'].action = 'UnLink';buttons['unlink'].imgName = 'bs_unLink';var i = buttons.length;buttons[i] = '__SEPARATOR__';buttons['insertimage'] = new Array();buttons['insertimage'].action = 'InsertImage';buttons['insertimage'].imgName = 'bs_image';buttons['specialchars'] = new Array();buttons['specialchars'].action = 'SpecialChars';buttons['specialchars'].imgName = 'bs_specialChars';var i = buttons.length;buttons[i] = '__SEPARATOR__';}this._drawButtonBarWysiwyg = function() {toolbarWysiwyg = new Bs_ButtonBar();toolbarWysiwyg.useHelpBar = 'toolbarHelptext';if (typeof(this.buttonsWysiwyg) == 'undefined') this.loadButtonsWysiwyg();this._drawButtonBarHelper(this.buttonsWysiwyg, 'toolbarWysiwyg', 'wysiwyg');}this.loadButtonsHtml = function() {var buttons = new Array();this.buttonsHtml = buttons;buttons['cut'] = new Array();buttons['cut'].action = 'Cut';buttons['cut'].imgName = 'bs_cut';buttons['copy'] = new Array();buttons['copy'].action = 'Copy';buttons['copy'].imgName = 'bs_copy';buttons['paste'] = new Array();buttons['paste'].action = 'Paste';buttons['paste'].imgName = 'bs_paste';var i = buttons.length;buttons[i] = '__SEPARATOR__';buttons['undo'] = new Array();buttons['undo'].action = 'Undo';buttons['undo'].imgName = 'bs_undo';buttons['redo'] = new Array();buttons['redo'].action = 'Redo';buttons['redo'].imgName = 'bs_redo';var i = buttons.length;buttons[i] = '__SEPARATOR__';buttons['createlink'] = new Array();buttons['createlink'].action = 'CreateLink';buttons['createlink'].imgName = 'bs_createLink';buttons['insertimage'] = new Array();buttons['insertimage'].action = 'InsertImage';buttons['insertimage'].imgName = 'bs_image';buttons['specialchars'] = new Array();buttons['specialchars'].action = 'SpecialChars';buttons['specialchars'].imgName = 'bs_specialChars';buttons['color'] = new Array();buttons['color'].action = 'Color';buttons['color'].imgName = 'bs_bgColor';}this._drawButtonBarHtml = function() {toolbarHtml = new Bs_ButtonBar();toolbarHtml.useHelpBar = 'toolbarHelptext';if (typeof(this.buttonsHtml) == 'undefined') this.loadButtonsHtml();this._drawButtonBarHelper(this.buttonsHtml, 'toolbarHtml', 'html');}this._drawButtonBarHelper = function(buttonArr, toolbarName, buttonNamePrefix) {var lastWasSeparator = true;for (var i in buttonArr) {if (bs_isNull(buttonArr[i]) || (typeof(buttonArr[i]) != 'object')) {continue;} else if (buttonArr[i] == '__SEPARATOR__') {if (lastWasSeparator) continue;eval(toolbarName + ".newGroup();");lastWasSeparator = true;} else {lastWasSeparator = false;if (typeof(buttonArr[i]['title']) == 'undefined') {if (!bs_isEmpty(bsWyLa['btn'][i + '_title'])) buttonArr[i]['title'] = bsWyLa['btn'][i + '_title'];}if (typeof(buttonArr[i]['helpText']) == 'undefined') {if (!bs_isEmpty(bsWyLa['btn'][i + '_helpText'])) buttonArr[i]['helpText'] = bsWyLa['btn'][i + '_helpText'];}if (typeof(buttonArr[i]['imgName']) == 'undefined') {if (!bs_isEmpty(bsWyLa['btn'][i + '_imgName'])) buttonArr[i]['imgName'] = bsWyLa['btn'][i + '_imgName'];}var varName = this._objectName + '_' + buttonNamePrefix + 'Button' + i;var tempButton = new Bs_Button();tempButton.objectName = varName;tempButton.action = buttonArr[i]['action'];tempButton.title = buttonArr[i]['title'];tempButton.imgName = buttonArr[i]['imgName'];if (typeof(buttonArr[i]['imgPath']) != 'undefined') {tempButton.imgPath = buttonArr[i]['imgPath'];} else {tempButton.imgPath = this.buttonsDefaultPath;}if (typeof(buttonArr[i]['group']) != 'undefined') {tempButton.group = buttonArr[i]['group'];}tempButton.attachEvent(this._objectName + ".toolbarButtonClicked(this);");eval(varName + ' = tempButton;');eval(toolbarName + ".addButton(" + varName + ", \"" + buttonArr[i]['helpText'] + "\");");}}}this._getDrawnButtonBar = function() {var out = new Array();out[out.length] = '<div id="' + this._objectName + '_buttonbar" style="background-color:menu; padding:3px;">';if (this.dataType == 'whtml') {out[out.length] = '<div id="' + this._objectName + '_tabset" style="background-color:menu;">';out[out.length] = ' <div id="' + this._objectName + '_tabset_tabs"></div>';out[out.length] = ' <div id="' + this._objectName + '_tabset_content" class="tabsetContentDiv">';}switch (this.dataType) {case 'whtml':out[out.length] = '<div id="' + this._objectName + '_registerWysiwygButtons" style="display:inline;"></div>';out[out.length] = '<div id="' + this._objectName + '_registerHtmlButtons" style="display:inline;"></div>';this._drawButtonBarWysiwyg();this._drawButtonBarHtml();break;case 'html':out[out.length] = '<div id="' + this._objectName + '_registerHtmlButtons"></div>';this._drawButtonBarHtml();break;case 'xhtml':case 'xml':case 'text':out[out.length] = '<div id="' + this._objectName + '_registerTextButtons"></div>';this._drawButtonBarText();break;}if (this.dataType == 'whtml') {out[out.length] = ' </div>';out[out.length] = '</div>';}out[out.length] = '</div>';return out.join('');}this._getDrawnFormField = function() {if (typeof(this.formFieldName) == 'undefined') return '';return '<input type="hidden" name="' + this.formFieldName + '" id="' + this.formFieldName + '" value="' + bs_filterForHtml(this._value) + '">';}this._updateButtons = function() {if (moz) return;if ((this.dataType == 'text') || (this.dataType == 'xhtml') || (this.dataType == 'xml')) {} else if ((this.dataType == 'html') || this._inHtmlMode) {} else {this._updateButtonsHelper('wysiwygButton', 'bold');this._updateButtonsHelper('wysiwygButton', 'italic');this._updateButtonsHelper('wysiwygButton', 'underline');this._updateButtonsHelper('wysiwygButton', 'justifyleft');this._updateButtonsHelper('wysiwygButton', 'justifycenter');this._updateButtonsHelper('wysiwygButton', 'justifyright');this._updateButtonsHelper('wysiwygButton', 'insertorderedlist');this._updateButtonsHelper('wysiwygButton', 'insertunorderedlist');try {var tempRange = this.workingDoc.selection.createRange().duplicate();var tempElm = findWrappingElement('A', tempRange);if (typeof(wysiwygButtonunlink) != 'undefined') {wysiwygButtonunlink.setStatus((tempElm == false) ? 0 : 1);}var t = new Array('font', 'specialchars', 'forecolor');for (var i=0; i<t.length; i++) {var varName = this._objectName + '_' + 'wysiwygButton' + t[i];if (typeof(window[varName]) != 'undefined') window[varName].setStatus(1);}} catch (e) {var t = new Array('bold', 'italic', 'underline', 'insertorderedlist', 'insertunorderedlist', 'font', 'specialchars', 'forecolor');for (var i=0; i<t.length; i++) {var varName = this._objectName + '_' + 'wysiwygButton' + t[i];if (typeof(window[varName]) != 'undefined') window[varName].setStatus(0);}}}}this._updateButtonsHelper = function(cat, what) {if (typeof(window[this._objectName + '_' + cat + what]) != 'undefined') {try {window[this._objectName + '_' + cat + what].setStatus(window[this._objectName].wysiwygDoc.queryCommandValue(what) ? 2 : 1);} catch (e) {}}}this.switchToWysiwygTab = function() {if (!this._inHtmlMode) return;this._inHtmlMode = false;this._value = this.htmlElm.innerText;this.wysiwygElm.innerHTML = this._value;this.workingDoc = this.wysiwygDoc;this.workingElm = this.wysiwygElm;if (this.style == 'toolbar') {this.htmlElm.contentEditable = false;this.iframeElm.height = 0;this.wysiwygElm.contentEditable = true;this.wysiwygElm.focus();}}this.switchToHtmlTab = function() {if (this._inHtmlMode) return;this._inHtmlMode = true;this._value = this.wysiwygElm.innerHTML;this.htmlElm.innerText = this._value;this.workingDoc = this.htmlDoc;this.workingElm = this.htmlElm;if (this.style == 'toolbar') {this.wysiwygElm.contentEditable = false;this.iframeElm.height = 200;this.htmlElm.contentEditable = true;this.iframeElm.contentWindow.focus();}}this.toggleToolbar = function(hide) {var toolbarDiv = document.getElementById(this._objectName + '_outerDiv');if (bs_isNull(toolbarDiv)) return false;toolbarDiv.style.display = (hide) ? 'none' : 'block';}this.toolbarButtonUndo = function() {this.toggleToolbar(true);}this.toolbarButtonSave = function() {this.toggleToolbar(true);}this.toolbarButtonClose = function() {this.toggleToolbar(true);document.body.focus();this.fireOnBlur();this.fireEvent('toolbarButtonClose');}this._setupResizeGrip = function(outerDivId) {if (this.mayResize) {var resizeGripObjName = this._objectName + '_rg';var rg = new Bs_ResizeGrip(resizeGripObjName, outerDivId);rg.gripIcon = this.bsImgPath + 'windows/resizeWindow.gif';rg.minWidth = 150;rg.minHeight = 150;if (typeof(this.maxWidth) != 'undefined') rg.maxWidth = this.maxWidth;if (typeof(this.maxHeight) != 'undefined') rg.maxHeight = this.maxHeight;rg.onBeforeResizeStart = this._objectName + '.resizeWindowStart();';rg.onAfterResizeEnd = this._objectName + '.resizeEnd();';eval(resizeGripObjName + ' = rg;');rg.draw();}}this.resizeWindowStart = function(elm) {this.iframeElm.width = 0;this.iframeElm.height = 0;this.iframeElm.style.display = 'none';}this.resizeEnd = function() {this._updateIframeSize();this.iframeElm.style.display = 'block';this.iframeElm.width = '100%';}this._updateIframeSize = function() {var totalHeight = document.getElementById(this._objectName + '_outerDiv').offsetHeight;var statusHeight = document.getElementById(this._objectName + '_statusbar').offsetHeight;var buttonHeight = document.getElementById(this._objectName + '_buttonbar').offsetHeight;this.iframeElm.style.height = totalHeight - statusHeight - buttonHeight + 'px';this.iframeElm.height = totalHeight - statusHeight - buttonHeight;}this._drawStatusBar = function() {var out = new Array;out[out.length] = '<div style="height:20px; background-color:menu;"> </div>';out[out.length] = '<div id="' + this._objectName + '_statusbar" style="position:absolute; bottom:0px; right:0px; width:100%; height:20px; background-color:menu;">';out[out.length] = '<div unselectable="On" style="z-index:5; position:absolute; display:inline; left:5px; bottom:3px; align:left; border-right:10px solid menu; background-color:menu; font-family:arial,helvetica; font-size:11px;" id="toolbarHelptext"></div>';out[out.length] = '<div unselectable="On" style="z-index:4; position:absolute; display:inline; width:110px; right:18px; bottom:3px; text-align:right;" class="wysiwygBaseline"><a href="http://www.blueshoes.org/en/javascript/editor/" target="_blank" style="color:black; text-decoration:none; font-family:arial,helvetica; font-size:11px;"><img src="' + this.bsImgPath + 'powered/blueshoes/shoe_xxs.gif" border="0" align="top"> BlueShoes Editor</a></div>';return out.join('');}this._getDrawnIframe = function(tagId) {if (typeof(tagId) != 'undefined') {var initIframeHeight = document.getElementById(tagId).offsetHeight - 100;} else {var initIframeHeight = 0;}return '<iframe align="top" id="' + this._objectName + '_iframe' + '" width="100%" height="' + initIframeHeight + 'px"></iframe>';}this._setupIframeDoc = function() {var docHead = '';if (moz) {docHead += "<script>";docHead += ' function convertTextToHTML(s) {\n'; docHead += ' s = s.replace(/\&/g, "&")\n'; docHead += ' s = s.replace(/</g, "<")\n'; docHead += ' s = s.replace(/>/g, ">")\n'; docHead += ' s = s.replace(/\n/g, "<BR>");\n'; //<= escaped \n here!!!docHead += ' while (/\s\s/.test(s))\n'; docHead += ' s = s.replace(/\s\s/, " ");\n'; docHead += ' return s.replace(/\s/g, " ");\n';docHead += ' }\n';docHead += ' HTMLElement.prototype.__defineSetter__("innerText", function (sText) {';docHead += ' this.innerHTML = convertTextToHTML(sText);';docHead += ' return sText; ';docHead += ' });';docHead += ' var tmpGet;';docHead += ' HTMLElement.prototype.__defineGetter__("innerText", tmpGet = function () {';docHead += ' var r = this.ownerDocument.createRange();';docHead += ' r.selectNodeContents(this);';docHead += ' return r.toString();';docHead += ' });';docHead += "</script>\n";}docHead += "<style>\n";docHead += this.editorCssString;docHead += "</style>\n";var emptyDoc = '';emptyDoc += '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';emptyDoc += '<html><head>' + docHead + '</head>';emptyDoc += '<body>';if ((this.dataType == 'whtml') && !this._inHtmlMode) {emptyDoc += this._value;} else {emptyDoc += bs_filterForHtml(this._value);}emptyDoc += '</body></html>';this.htmlDoc.write(emptyDoc);}this._afterDrawStuff = function(isToolbar) {switch (this.dataType) {case 'whtml':toolbarWysiwyg.drawInto(this._objectName + '_registerWysiwygButtons');toolbarHtml.drawInto(this._objectName + '_registerHtmlButtons');break;case 'html':toolbarHtml.drawInto(this._objectName + '_registerHtmlButtons');break;case 'xhtml':case 'xml':case 'text':toolbarText.drawInto(this._objectName + '_registerTextButtons');break;}try {this.wysiwygDoc.execCommand("undo", false, null);} catch (e) {alert("This is not supported on your level of Mozilla. Please update.1");}if (this.dataType == 'whtml') {if ((this.buttonsWysiwyg != false) && (this.buttonsHtml != false)) {this._tabset = new Bs_TabSet(this._objectName + '._tabset', this._objectName + '_tabset');var tabWysiwygObj = new Object;tabWysiwygObj.caption = 'Wysiwyg';tabWysiwygObj.container = document.getElementById(this._objectName + '_registerWysiwygButtons');tabWysiwygObj.onFocus = this._objectName + '.switchToWysiwygTab();';this._tabset.addTab(tabWysiwygObj);var tabHtmlObj = new Object;tabHtmlObj.caption = 'HTML';tabHtmlObj.container = document.getElementById(this._objectName + '_registerHtmlButtons');tabHtmlObj.onFocus = this._objectName + '.switchToHtmlTab();';this._tabset.addTab(tabHtmlObj);this._tabset.draw();}}if (!isToolbar) this._updateIframeSize();window.setInterval(this._objectName + "._updateButtons()", 200);this.outrendered = true;return true;}this._attachEditorEvents = function(editableAreaId) {bsWysiwygDivToInstanceArray[editableAreaId] = this;this.wysiwygElm.attachEvent('onbeforedeactivate', function() { bsWysiwygEditorObdWrapper(editableAreaId); } );this.wysiwygElm.attachEvent('onblur', function() { bsWysiwygEditorOnBlurWrapper(editableAreaId); } );this.wysiwygElm.attachEvent('onfocus', function() { bsWysiwygEditorOnFocusWrapper(editableAreaId); } );this.wysiwygElm.attachEvent('onmouseover', function() { bsWysiwygEditorEventWrapper('editareaMouseOver', editableAreaId); } );this.wysiwygElm.attachEvent('onmouseout', function() { bsWysiwygEditorEventWrapper('editareaMouseOut', editableAreaId); } );this.wysiwygElm.attachEvent('onpaste', function() { return bsWysiwygEditorEventWrapper('editareaPaste', editableAreaId); } );}this._objectName = objectName;bsWysiwygInstances[this._objectName] = this;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -