📄 htmlarea.js
字号:
HTMLArea.freeLater(this, '_toolbar');
var tb_row = null;
var tb_objects = new Object();
this._toolbarObjects = tb_objects;
this._createToolbar1(editor, toolbar, tb_objects);
this._htmlArea.appendChild(toolbar);
return toolbar;
};
HTMLArea.prototype._setConfig = function(config) {
this.config = config;
};
HTMLArea.prototype._addToolbar = function() {
this._createToolbar1(this, this._toolbar, this._toolbarObjects);
};
// separate from previous createToolBar to allow dynamic change of toolbar
HTMLArea.prototype._createToolbar1 = function (editor, toolbar, tb_objects) {
// This shouldn't be necessary, but IE seems to float outside of the container
// when we float toolbar sections, so we have to clear:both here as well
// as at the end (which we do have to do).
if(editor.config.flowToolbars)
{
var brk = document.createElement('div');
brk.style.height =
brk.style.width =
brk.style.lineHeight =
brk.style.fontSize = '1px';
brk.style.clear = 'both';
toolbar.appendChild(brk);
}
// creates a new line in the toolbar
function newLine() {
if(typeof tb_row != 'undefined' && tb_row.childNodes.length == 0) return;
var table = document.createElement("table");
table.border = "0px";
table.cellSpacing = "0px";
table.cellPadding = "0px";
if(editor.config.flowToolbars)
{
if(HTMLArea.is_ie)
{
table.style.styleFloat = "left";
}
else
{
table.style.cssFloat = "left";
}
}
toolbar.appendChild(table);
// TBODY is required for IE, otherwise you don't see anything
// in the TABLE.
var tb_body = document.createElement("tbody");
table.appendChild(tb_body);
tb_row = document.createElement("tr");
tb_body.appendChild(tb_row);
table.className = 'toolbarRow'; // meh, kinda.
} // END of function: newLine
// init first line
newLine();
// updates the state of a toolbar element. This function is member of
// a toolbar element object (unnamed objects created by createButton or
// createSelect functions below).
function setButtonStatus(id, newval) {
var oldval = this[id];
var el = this.element;
if (oldval != newval) {
switch (id) {
case "enabled":
if (newval) {
HTMLArea._removeClass(el, "buttonDisabled");
el.disabled = false;
} else {
HTMLArea._addClass(el, "buttonDisabled");
el.disabled = true;
}
break;
case "active":
if (newval) {
HTMLArea._addClass(el, "buttonPressed");
} else {
HTMLArea._removeClass(el, "buttonPressed");
}
break;
}
this[id] = newval;
}
} // END of function: setButtonStatus
// this function will handle creation of combo boxes. Receives as
// parameter the name of a button as defined in the toolBar config.
// This function is called from createButton, above, if the given "txt"
// doesn't match a button.
function createSelect(txt) {
var options = null;
var el = null;
var cmd = null;
var customSelects = editor.config.customSelects;
var context = null;
var tooltip = "";
switch (txt) {
case "fontsize":
case "fontname":
case "formatblock":
// the following line retrieves the correct
// configuration option because the variable name
// inside the Config object is named the same as the
// button/select in the toolbar. For instance, if txt
// == "formatblock" we retrieve config.formatblock (or
// a different way to write it in JS is
// config["formatblock"].
options = editor.config[txt];
cmd = txt;
break;
default:
// try to fetch it from the list of registered selects
cmd = txt;
var dropdown = customSelects[cmd];
if (typeof dropdown != "undefined") {
options = dropdown.options;
context = dropdown.context;
if (typeof dropdown.tooltip != "undefined") {
tooltip = dropdown.tooltip;
}
} else {
alert("ERROR [createSelect]:\nCan't find the requested dropdown definition");
}
break;
}
if (options) {
el = document.createElement("select");
el.title = tooltip;
var obj = {
name : txt, // field name
element : el, // the UI element (SELECT)
enabled : true, // is it enabled?
text : false, // enabled in text mode?
cmd : cmd, // command ID
state : setButtonStatus, // for changing state
context : context
};
HTMLArea.freeLater(obj);
tb_objects[txt] = obj;
for (var i in options) {
if (typeof(options[i]) != 'string') continue; // prevent iterating over wrong type
var op = document.createElement("option");
op.innerHTML = HTMLArea._lc(i);
op.value = options[i];
el.appendChild(op);
}
HTMLArea._addEvent(el, "change", function () {
editor._comboSelected(el, txt);
});
}
return el;
} // END of function: createSelect
// appends a new button to toolbar
function createButton(txt) {
// the element that will be created
var el = null;
var btn = null;
switch (txt) {
case "separator":
if(editor.config.flowToolbars) newLine();
el = document.createElement("div");
el.className = "separator";
break;
case "space":
el = document.createElement("div");
el.className = "space";
break;
case "linebreak":
newLine();
return false;
case "textindicator":
el = document.createElement("div");
el.appendChild(document.createTextNode("A"));
el.className = "indicator";
el.title = HTMLArea._lc("Current style");
var obj = {
name : txt, // the button name (i.e. 'bold')
element : el, // the UI element (DIV)
enabled : true, // is it enabled?
active : false, // is it pressed?
text : false, // enabled in text mode?
cmd : "textindicator", // the command ID
state : setButtonStatus // for changing state
};
HTMLArea.freeLater(obj);
tb_objects[txt] = obj;
break;
default:
btn = editor.config.btnList[txt];
}
if (!el && btn) {
el = document.createElement("a");
el.style.display = 'block';
el.href = 'javascript:void(0)';
el.style.textDecoration = 'none';
el.title = btn[0];
el.className = "button";
// let's just pretend we have a button object, and
// assign all the needed information to it.
var obj = {
name : txt, // the button name (i.e. 'bold')
element : el, // the UI element (DIV)
enabled : true, // is it enabled?
active : false, // is it pressed?
text : btn[2], // enabled in text mode?
cmd : btn[3], // the command ID
state : setButtonStatus, // for changing state
context : btn[4] || null // enabled in a certain context?
};
HTMLArea.freeLater(obj);
tb_objects[txt] = obj;
// handlers to emulate nice flat toolbar buttons
HTMLArea._addEvent(el, "mouseout", function () {
if (obj.enabled) with (HTMLArea) {
//_removeClass(el, "buttonHover");
_removeClass(el, "buttonActive");
(obj.active) && _addClass(el, "buttonPressed");
}
});
HTMLArea._addEvent(el, "mousedown", function (ev) {
if (obj.enabled) with (HTMLArea) {
_addClass(el, "buttonActive");
_removeClass(el, "buttonPressed");
_stopEvent(is_ie ? window.event : ev);
}
});
// when clicked, do the following:
HTMLArea._addEvent(el, "click", function (ev) {
if (obj.enabled) with (HTMLArea) {
_removeClass(el, "buttonActive");
//_removeClass(el, "buttonHover");
if(HTMLArea.is_gecko)
{
editor.activateEditor();
}
obj.cmd(editor, obj.name, obj);
_stopEvent(is_ie ? window.event : ev);
}
});
var i_contain = HTMLArea.makeBtnImg(btn[1]);
var img = i_contain.firstChild;
el.appendChild(i_contain);
obj.imgel = img;
obj.swapImage = function(newimg)
{
if(typeof newimg != 'string')
{
img.src = newimg[0];
img.style.position = 'relative';
img.style.top = newimg[2] ? ('-' + (18 * (newimg[2] + 1)) + 'px') : '-18px';
img.style.left = newimg[1] ? ('-' + (18 * (newimg[1] + 1)) + 'px') : '-18px';
}
else
{
obj.imgel.src = newimg;
img.style.top = '0px';
img.style.left = '0px';
}
};
} else if (!el) {
el = createSelect(txt);
}
return el;
}
var first = true;
for (var i = 0; i < this.config.toolbar.length; ++i) {
if (!first) {
// createButton("linebreak");
} else {
first = false;
}
if(this.config.toolbar[i] == null) this.config.toolbar[i] = ['separator'];
var group = this.config.toolbar[i];
for (var j = 0; j < group.length; ++j)
{
var code = group[j];
if (/^([IT])\[(.*?)\]/.test(code))
{
// special case, create text label
var l7ed = RegExp.$1 == "I"; // localized?
var label = RegExp.$2;
if (l7ed) {
label = HTMLArea._lc(label);
}
var tb_cell = document.createElement("td");
tb_row.appendChild(tb_cell);
tb_cell.className = "label";
tb_cell.innerHTML = label;
}
else if(typeof code != 'function')
{
var tb_element = createButton(code);
if (tb_element)
{
var tb_cell = document.createElement("td");
tb_cell.className = 'toolbarElement';
tb_row.appendChild(tb_cell);
tb_cell.appendChild(tb_element);
}
else if (tb_element == null)
{
alert("FIXME: Unknown toolbar item: " + code);
}
}
}
}
if(editor.config.flowToolbars)
{
var brk = document.createElement('div');
brk.style.height =
brk.style.width =
brk.style.lineHeight =
brk.style.fontSize = '1px';
brk.style.clear = 'both';
toolbar.appendChild(brk);
}
return toolbar;
};
use_clone_img = false;
HTMLArea.makeBtnImg = function(imgDef, doc)
{
if(!doc) doc = document;
if(!doc._htmlareaImgCache)
{
doc._htmlareaImgCache = { };
HTMLArea.freeLater(doc._htmlareaImgCache);
}
var i_contain = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -