📄 bs_editor.class.js
字号:
/********************************************************************************************* BlueShoes Framework; This file is part of the php application framework.* NOTE: This code is stripped (obfuscated). To get the clean documented code goto * www.blueshoes.org and register for the free open source *DEVELOPER* version or * buy the commercial version.* * In case you've already got the developer version, then this is one of the few * packages/classes that is only available to *PAYING* customers.* To get it go to www.blueshoes.org and buy a commercial version.* * @copyright www.blueshoes.org* @author Samuel Blume <sam at blueshoes dot org>* @author Andrej Arn <andrej at blueshoes dot org>*/var bs_move_elm;var bs_move_startX;var bs_move_startY;var bs_move_left;var bs_move_top;function bs_move_moveStart(elmId) {bs_move_elm = document.getElementById(elmId);bs_move_startX = event.clientX;bs_move_startY = event.clientY;bs_move_left = bs_move_elm.offsetLeft;bs_move_top = bs_move_elm.offsetTop;document.body.attachEvent('onmousemove', bs_move_move);document.body.attachEvent('onmouseup', bs_move_moveEnd);}function bs_move_moveEnd() {document.body.detachEvent('onmousemove', bs_move_move);document.body.detachEvent('onmouseup', bs_move_moveEnd);}function bs_move_move() {var diffLeft = event.clientX - bs_move_startX;var diffTop = event.clientY - bs_move_startY;var newLeft = bs_move_left + diffLeft;var newTop = bs_move_top + diffTop;bs_move_elm.style.left = newLeft;bs_move_elm.style.top = newTop;}if (typeof(bsWysiwygInstances) == 'undefined') {var bsWysiwygInstances = new Object;}if (typeof(bsWysiwygDivToInstanceArray) == 'undefined') {var bsWysiwygDivToInstanceArray = new Object;}function bsWysiwygEditorOnBlurWrapper(tagId) {bsWysiwygDivToInstanceArray[tagId].fireOnBlur();}function bsWysiwygEditorOnFocusWrapper(tagId) {bsWysiwygDivToInstanceArray[tagId].fireOnFocus();}function bsWysiwygEditorEventWrapper(ev, tagId) {switch (ev) {case 'editareaMouseOver':case 'editareaMouseOut':bsWysiwygDivToInstanceArray[tagId].fireEvent(ev);break;case 'editareaPaste':return bsWysiwygDivToInstanceArray[tagId]._fireEditareaOnPaste(Event);break;}}function bsWysiwygEditorObdWrapper(tagId) {}var bsWysiwygSpecialCharsWindow;function bsSpecialCharsOnloadCallback() {bsWysiwygSpecialCharsOpener.specialCharsOnloadCallback();}function bsSpecialCharsDoneCallback(code) {bsWysiwygSpecialCharsOpener.specialCharsDoneCallback(code);}function Bs_Editor(objectName) {this._objectName;this.dataType = 'whtml';this.editareaOnPaste = 5;this.style = 'inline';this._inHtmlMode = false;this._value = '';this.formFieldName;this.wysiwygElm;this.wysiwygDoc;this.htmlElm;this.htmlDoc;this.workingElm;this.workingDoc;this.iframeElm;this.outrendered = false;this.lastSelection;this.dataContainer;this.hrefSelector = new Array('/_bsJavascript/components/editor/windowHref.html', 490, 350);this.imageSelector = new Array('/_bsJavascript/components/editor/windowImage.html', 525, 330);this.fgColorSelector = new Array('/_bsJavascript/components/colorpicker/windowColor.html', 500, 600);this.fontSelector = new Array('/_bsJavascript/components/editor/windowFont.html', 420, 300);this.specialCharSelector = new Array('/_bsJavascript/components/editor/windowSpecialChar.html', 450, 300);this.editorCssFile;this.editorCssString = "body { \n font-family:arial,helvetica; \n font-size: 12px; \n }\n td { \n font-size: 12px; \n } \n ";this.mayResize = true;this.maxWidth;this.maxHeight;this.buttonsWysiwyg;this.buttonsHtml;this.buttonsText;this.buttonsDefaultPath = '/_bsImages/buttons/';this.bsImgPath = '/_bsImages/';this._toolbarStartActivated = false;this._tabset;this._attachedEvents;this.drawInto = function(tagId) {var tag = document.getElementById(tagId);if (tag == null) return false;tag.innerHTML = this._renderBoxed(tagId);this._afterRender(tagId);return true;}this.convertField = function(tagId) {var tag = document.getElementById(tagId);if (tag == null) return false;this.formFieldName = (!bs_isEmpty(tag.name)) ? tag.name : tagId;this._value = tag.value;var width = tag.offsetWidth;var height = tag.offsetHeight;if (width == 0) width = parseInt(tag.currentStyle.width);if (height == 0) height = parseInt(tag.currentStyle.height);tag.outerHTML = this._renderBoxed(tagId, width, height);this._afterRender(tagId);return true;}this._renderBoxed = function(tagId, width, height) {var out = new Array;var outerDivId = this._objectName + '_outerDiv';if (typeof(width) == 'undefined') width = '100%';if (typeof(height) == 'undefined') height = '100%';out[out.length] = '<div id="' + outerDivId + '" style="position:relative; width:' + width + '; height:' + height + '; border:2px solid outset; background-color:white;">';out[out.length] = this._getDrawnFormField();out[out.length] = this._getDrawnButtonBar();out[out.length] = this._getDrawnIframe(tagId);out[out.length] = this._drawStatusBar();out[out.length] = '</div>';return out.join('')}this._afterRender = function(tagId) {var outerDivId = this._objectName + '_outerDiv';this.iframeElm = document.getElementById(this._objectName + '_iframe');this.wysiwygDoc = this.iframeElm.contentWindow.document;this.htmlDoc = this.wysiwygDoc;if (!moz) {this.wysiwygDoc.designMode = "on";this.wysiwygDoc = this.iframeElm.contentWindow.document;}this._setupIframeDoc();this._setupResizeGrip(outerDivId);if (moz) {this.wysiwygDoc.designMode = "on";}this.wysiwygElm = this.wysiwygDoc.getElementsByTagName('body').item(0);this.htmlElm = this.wysiwygElm;this.workingElm = this.wysiwygElm;this.workingDoc = this.wysiwygDoc;this._afterDrawStuff(false);this._attachEditorEvents(tagId);}this.drawAsToolbar = function(editableAreaId, startActivated) {this.style = 'toolbar';this.wysiwygElm = document.getElementById(editableAreaId);this.workingElm = this.wysiwygElm;this.wysiwygDoc = document;if (this.workingElm == null) return false;if (startActivated) this._toolbarStartActivated = true;this._value = this.wysiwygElm.innerHTML;this._attachEditorEvents(editableAreaId);this.mayResize = false;var out = new Array;var outerDivId = this._objectName + '_outerDiv';out[out.length] = '<div id="' + outerDivId + '"';out[out.length] = ' style="';if (this._toolbarStartActivated) {out[out.length] = ' display:block;';} else {out[out.length] = ' display:none;';}out[out.length] = ' position:absolute; left;50; top:50; width:446;';out[out.length] = ' border:1px solid gray;"';out[out.length] = '>';out[out.length] = '<div id="' + this._objectName + '_titleBar" style="width:100%; padding:3px; cursor:default; background-color:#08246B; color:white; font-family:verdana,arial; font-size:12px; font-weight:bold;">';out[out.length] = '<div onclick="' + this._objectName + '.toolbarButtonClose();" style="position:absolute; width:20px; display:inline; text-align:right; right:5px;">x</div>';out[out.length] = '<div ondragstart="return false;" onmousedown="bs_move_moveStart(\'' + outerDivId + '\');"><nobr>BlueShoes Wysiwyg Toolbar</nobr></div>';out[out.length] = '</div>';out[out.length] = this._getDrawnFormField();out[out.length] = this._getDrawnButtonBar();out[out.length] = this._getDrawnIframe();out[out.length] = this._drawStatusBar();var body = document.getElementsByTagName('body').item(0);body.insertAdjacentHTML('beforeEnd', out.join(''));this.iframeElm = document.getElementById(this._objectName + '_iframe');this.htmlDoc = this.iframeElm.contentWindow.document;this._setupIframeDoc();this._setupResizeGrip(outerDivId);this.wysiwygElm = document.getElementById(editableAreaId);this.workingElm = this.wysiwygElm;this.wysiwygDoc = document;this.workingDoc = this.wysiwygDoc;this.htmlElm = this.htmlDoc.getElementsByTagName('body').item(0);this._afterDrawStuff(true);return true;}this.setValue = function(str) {this._value = str;if (this.outrendered) {if ((this.dataType == 'text') || this._inHtmlMode) {this.wysiwygElm.innerText = str;} else {this.wysiwygElm.innerHTML = str;}}return true;}this.getValue = function() {return this._value;}this.insertSpecialChar = function(code) {var r = this.workingDoc.selection.createRange();if (this._inHtmlMode) {r.text = code;} else {r.pasteHTML(code);}}this.insertString = function(str) {var r = this.workingDoc.selection.createRange();if (this._inHtmlMode) {r.text = str;} else {r.pasteHTML(str);}}this.fireOnBlur = function() {if (!bs_isNull(this.wysiwygElm)) {if (this._inHtmlMode) {this._value = this.htmlElm.innerText;this.wysiwygElm.innerHTML = this._value;} else {this._value = this.wysiwygElm.innerHTML;}if (typeof(this.formFieldName) != 'undefined') {var fld = document.getElementById(this.formFieldName);if (typeof(fld) != 'unknown') fld.value = this._value;}}this.fireEvent('editEnd');}this.fireOnFocus = function() {if (this.style == 'toolbar') {this.toggleToolbar(false);}this.fireEvent('editStart');}this._fireEditareaOnPaste = function(ev) {if (typeof(this.editareaOnPaste) == 'function') {var status = this.editareaOnPaste();if (typeof(status) == 'string') {this.insertString(clipValStrip)}ev.returnValue = false;return false;} else {switch (this.editareaOnPaste) {case 1:alert('Sorry, no pasting allowed.');case 0:ev.returnValue = false;return false;break;case 5:ev.returnValue = true;return true;break;default:var clipValOrig = window.clipboardData.getData("Text");var clipValStrip = bs_stripTags(clipValOrig);if ((clipValOrig == clipValStrip) || (this.editareaOnPaste == 2)) {ev.returnValue = true;return true;} else {switch (this.editareaOnPaste) {case 3:alert("Formatting tags have been removed from the clipboard.");case 2:this.insertString(clipValStrip)ev.returnValue = false;return false;break;case 4:var status = confirm("The pasted content includes formatting tags. Click OK to paste your content with them. Click cancel to have them removed.");if (!status) {this.insertString(clipValStrip)ev.returnValue = false;return false;} else {ev.returnValue = true;}break;}}}}return true;}this.createLink = function(paramObj) {var propArr = new Array('href', 'target', 'name', 'title', 'id', 'class', 'style');var tempRange = this.workingDoc.selection.createRange();if ((this.dataType == 'whtml') && !this._inHtmlMode) {if (bs_isEmpty(paramObj.href)) {tempRange.execCommand('UnLink', false, null);return;}var tempElm = findWrappingElement('A', tempRange);if (tempElm == false) {if (bs_isEmpty(paramObj['value'])) {if (tempRange.htmlText == '') {tempRange.expand('word');}var htmlText = tempRange.htmlText;if (typeof(htmlText) == 'string') {if (htmlText.substr(htmlText.length -1) == ' ') {tempRange.moveEnd('character', -1)}}paramObj['value'] = tempRange.htmlText;}tempRange.execCommand('CreateLink', false, paramObj.href);tempElm = findWrappingElement('A', tempRange);}if (tempElm == false) {if (bs_isEmpty(paramObj['value'])) {if (tempRange.htmlText == '') {tempRange.expand('word');}var htmlText = tempRange.htmlText;if (typeof(htmlText) == 'string') {if (htmlText.substr(htmlText.length -1) == ' ') {tempRange.moveEnd('character', -1)}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -