📄 bs_wysiwygnew.class.js_
字号:
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;
}
/**
* resize stuff
var currentResizeObj;
var currentResizeElm;
var currentResizeStartX;
var currentResizeStartY;
var currentResizeHeight;
var currentResizeWidth;
function resize() {
var container = document.getElementById(currentResizeElm.resizeElm);
var diffWidth = event.clientX - currentResizeStartX;
var diffHeight = event.clientY - currentResizeStartY;
container.style.width = currentResizeWidth + diffWidth;
container.style.height = currentResizeHeight + diffHeight;
container.width = currentResizeWidth + diffWidth;
container.height = currentResizeHeight + diffHeight;
currentResizeObj.resize(diffWidth, diffHeight);
}
function resizeEnd() {
document.body.detachEvent('onmousemove', resize);
document.body.detachEvent('onmouseup', resizeEnd);
currentResizeObj.resizeEnd();
}
*/
//some global arrays we need, hacky things because js is limited.
if (typeof(bsWysiwygInstances) == 'undefined') {
var bsWysiwygInstances = new Object;
}
//hash where key is the id of the editable area, value is the wysiwyg instance (ref).
//needed for the dynamic onBlur and onBeforeDeactivate events if in toolbar mode.
if (typeof(bsWysiwygDivToInstanceArray) == 'undefined') {
var bsWysiwygDivToInstanceArray = new Object;
}
/**
* function gets triggered by onBlur event of the editable area if in toolbar mode.
* it's just some wrapper function.
* @param string tagId
* @return void
*/
function bsWysiwygEditorOnBlurWrapper(tagId) {
bsWysiwygDivToInstanceArray[tagId].fireOnBlur();
}
function bsWysiwygEditorOnFocusWrapper(tagId) {
bsWysiwygDivToInstanceArray[tagId].fireOnFocus();
}
/**
* @param string ev (event)
* @param string tagId
*/
function bsWysiwygEditorEventWrapper(ev, tagId) {
switch (ev) {
case 'editareaMouseOver':
case 'editareaMouseOut':
bsWysiwygDivToInstanceArray[tagId].fireEvent(ev);
break;
case 'editareaPaste':
bsWysiwygDivToInstanceArray[tagId]._fireEditareaOnPaste();
break;
}
}
/**
* similar to bsWysiwygEditorOnBlurWrapper() so look there.
*
* the real function name would be: bsWysiwygEditorOnBeforeDeactivateWrapper
* but that name is too long and gives a js error.
*/
function bsWysiwygEditorObdWrapper(tagId) {
bsWysiwygDivToInstanceArray[tagId].saveCursorPos();
}
/**
* the popup-opened special chars selector window.
* @var object bsWysiwygSpecialCharsWindow
*/
var bsWysiwygSpecialCharsWindow;
function bsSpecialCharsOnloadCallback() {
bsWysiwygSpecialCharsOpener.specialCharsOnloadCallback();
}
function bsSpecialCharsDoneCallback(code) {
bsWysiwygSpecialCharsOpener.specialCharsDoneCallback(code);
}
/*******************************************************************************************************
* Bs_Wysiwyg.class.js - clientside wysiwyg editor.
*
* Dependences: /_bsJavascript/core/form/Bs_FormFieldSelect.class.js,
* /_bsJavascript/core/html/Bs_HtmlUtil.lib.js,
*
* @Version 4.0 (2003/06/11)
* @Author andrej arn <andrej at blueshoes dot org>
* @copyright blueshoes
*/
function Bs_Wysiwyg(objectName) {
/**
* the name of this object instance that is in the global scope.
* absolutely needed, gets set in the constructor.
* @access private
* @var string _objectName
*/
this._objectName;
/**
* the data type of the data that gets edited.
*
* one of: whtml (wysiwyg html, default)
* html (only html edit is possible, no wysiwyg)
* xhtml
* xml
* text
*
* @access public
* @param string dataType
*/
this.dataType = 'whtml';
/**
* what should be done on a paste operation, what kind of pasts are accepted?
*
* a user can really fuck up html code by pasting parts of websites, word documents
* and the like. if your users are not familiar with html, you should not leave the
* default.
*
* pasting can be done in different ways, not only with the
* - paste button, but also
* - ctrl-v
* - shift-insert
* - right mouse, paste (contect menu
*
* the options:
* 0 = no pasting allowed, just ignore it silently.
* 1 = no pasting allowed, alert such a message on paste.
* 2 = allow paste of plain text, remove tags silently.
* 3 = allow paste of plain text, remove tags, alert such a message.
* 4 = if tags are pasted, ask the user if he wants to keep them or have them removed.
* 5 = just paste what's pasted, don't do anything, allow everything.
* or alternatively, you can set a function to this var which will then be called, and
* you can handle it yourself. return a text to paste, or return bool false to paste nothing.
* alert the user yourself if you want.
*
* @access public
* @var mixed editareaOnPaste (int or function)
* @see this._fireEditareaOnPaste()
* @since bs4.4
*/
this.editareaOnPaste = 5;
/**
* how the wysiwyg editor should be displayed.
*
* 'inline' => as fixed field, non-moveable. (default)
* 'floating' => as box, moveable
* 'toolbar' => toolbar only, the editable part is directly in the page. toolbar is moveable.
*
* @access public
* @var string style
*/
this.style = 'inline';
/**
* if style is not set to 'toolbar' then our editor area is used for both, wysiwyg and
* html editing. if we're in html mode, we need to do some things differently, so we need
* to know.
* you as a coder don't need to do anything with it.
* @access private
* @var bool _inHtmlMode
*/
this._inHtmlMode = false;
/**
* the value, content, however you wanna call it.
* @access private
* @var string _value (default is an empty string '')
* @see this.setValue(), this.getValue()
*/
this._value = '';
/**
* if the style is set to 'inline' or 'floating' (not 'toolbar') then you can
* use a (hidden) form field which will be updated with the editors content
* (whenever the editor loses the focus). if you want that feature, specify
* a field name here. otherwise just leave it unset.
* @access public
* @var string formFieldName
*/
this.formFieldName;
/**
* a reference to the wysiwyg element (div). gets set after the toolbar got loaded.
* @access public
* @var object wysiwygElm
*/
this.wysiwygElm;
this.wysiwygDoc;
this.htmlElm;
this.htmlDoc;
this.workingElm;
this.workingDoc;
this.iframeElm;
this._currentRegister = '';
/**
* tells if we're already rendered to the browser.
* @access public (read only)
* @var bool outrendered
*/
this.outrendered = false;
/**
* @access private
* @var string _imageSelectorUrl
* @see this.setImageSelector()
*/
this._imageSelectorUrl;
/**
* @access private
* @var array _codeSnippets
* @see setCodeSnippets()
*/
this._codeSnippets;
/**
* the saved cursor position of the editor field.
* @access private
* @var ? _editorCursorPos
* @see this.saveCursorPos()
*/
this._editorCursorPos;
/**
* TextRange.
* see http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_textrange.asp
* see where it's used to understand it.
* @access public (used internally, but you can use it too if you want.)
* @var object lastSelection
*/
this.lastSelection;
/**
* can be used to stick in any data.
* maybe you don't see a reason for it, but i do.
* @access public
* @var mixed dataContainer
* @since bs4.4
*/
this.dataContainer;
this.imagePath = '/_bsJavascript/components/wysiwyg/img/';
/**
* array with 3 elements.
* 0 = url
* 1 = width
* 2 = height
* @access public
* @var array hrefSelector
*/
this.hrefSelector = new Array('/_bsJavascript/components/wysiwyg/windowHref.html', 490, 350);
/**
* array with 4 elements.
* 0 = url
* 1 = width
* 2 = height
* 3 = image browser; array with 3 elements: (not set = don't use a server image browser)
* 0 = url
* 1 = width
* 2 = height
*
* @access public
* @var array imageSelector
*/
this.imageSelector = new Array('/_bsJavascript/components/wysiwyg/windowImage.html', 525, 330);
/**
* array with 3 elements.
* 0 = url
* 1 = width
* 2 = height
* @access public
* @var array fgColorSelector
*/
this.fgColorSelector = new Array('/_bsJavascript/components/wysiwyg/windowColor.html', 500, 600);
/**
* array with 3 elements.
* 0 = url
* 1 = width
* 2 = height
* @access public
* @var array fontSelector
*/
this.fontSelector = new Array('/_bsJavascript/components/wysiwyg/windowFont.html', 420, 300);
/**
* array with 3 elements.
* 0 = url
* 1 = width
* 2 = height
* @access public
* @var array specialCharSelector
*/
this.specialCharSelector = new Array('/_bsJavascript/components/wysiwyg/windowSpecialChar.html', 450, 300);
/**
* cached value of 2nd param in drawAsToolbar().
* @access private
* @var bool _toolbarStartActivated
*/
this._toolbarStartActivated = false;
/**
* instance of Bs_TabSet. used for the toolbar if there is more than one to choose from.
* @access private
* @var object _tabset
*/
this._tabset;
/**
* @access public
* @var bool mayResize
*/
this.mayResize = true;
/**
* max width of the editor window. not specified = no limit.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -