📄 yqweditor.js
字号:
continue;
}
var tr;
if (i % 8 == 0){
tr = table.insertRow(-1);
}
i++;
var div = document.createElement('div');
div.style.backgroundColor = coloroptions[hex];
var option = tr.insertCell(-1);
option.style.textAlign = 'center';
option.className = 'ocolor';
option.appendChild(div);
option.cmd = obj.cmd;
option.editorId = this.editorId;
option.controlkey = obj.id;
option.colorname = coloroptions[hex];
option.id = this.editorId + '_color_' + coloroptions[hex];
option.onmouseover = option.onmouseout = option.onmouseup = option.onmousedown = YeQiangWeiEditor_Events.prototype.menuoption_onmouseevent;
option.onclick = YeQiangWeiEditor_Events.prototype.coloroption_onclick;
}
menu.appendChild(table);
}
/**
* Menu Context
*
* @param object The menu container object
* @param string The state of the control
*/
this.menuContext = function(obj, state)
{
if (this.disabled)
{
return;
}
switch (obj.state)
{
case true: // selected menu is open
{
this.setControlStyle(obj, 'button', 'down');
break;
}
default:
{
switch (state)
{
case 'mouseout':
{
this.setControlStyle(obj, 'button', 'normal');
break;
}
case 'mousedown':
{
this.setControlStyle(obj, 'popup', 'down');
break;
}
case 'mouseup':
case 'mouseover':
{
this.setControlStyle(obj, 'button', 'hover');
break;
}
}
}
}
};
/**
* Button Context
* @param object The button object
* @param string Incoming event type
* @param string Control type - 'button' or 'menu'
*/
this.buttonContext = function(obj, state, controltype)
{
if (this.disabled){return;}
if (typeof controltype == 'undefined'){
controltype = 'button';
}
switch (obj.state){
case true: // selected button
{
switch (state)
{
case 'mouseover':
case 'mousedown':
case 'mouseup':
{
this.setControlStyle(obj, controltype, 'down');
break;
}
case 'mouseout':
{
this.setControlStyle(obj, 'button', 'selected');
break;
}
}
break;
}
default: // not selected
{
switch (state)
{
case 'mouseover':
case 'mouseup':
{
this.setControlStyle(obj, controltype, 'hover');
break;
}
case 'mousedown':
{
this.setControlStyle(obj, controltype, 'down');
break;
}
case 'mouseout':
{
this.setControlStyle(obj, controltype, 'normal');
break;
}
}
break;
}
}
};
/**
* @param mode 鼠标动作 hover down normal........
*/
this.setControlStyle = function(obj, controltype, mode){
if (obj.mode != mode){
obj.mode = mode;
// construct the name of the appropriate array key from the istyles array
istyle = 'pi_' + controltype + '_' + obj.mode;
// set element background, color, padding and border
if (typeof istyles != 'undefined' && typeof istyles[istyle] != 'undefined'){
obj.style.background = istyles[istyle][0];
obj.style.color = istyles[istyle][1];
if (controltype != 'menu'){
obj.style.padding = istyles[istyle][2];
}
obj.style.border = istyles[istyle][3];
var tds = getTags(obj, 'td');
for (var i = 0; i < tds.length; i++){
switch (tds[i].className){
// set the right-border for popup_feedback class elements
case 'popup_feedback':
{
tds[i].style.borderRight = (mode == 'normal' ? istyles['pi_menu_normal'][3] : istyles[istyle][3]);
}
break;
// set the border colour for popup_pickbutton class elements
case 'popup_pickbutton':
{
tds[i].style.borderColor = (mode == 'normal' ? istyles['pi_menu_normal'][0] : istyles[istyle][0]);
}
break;
// set the left-padding and left-border for alt_pickbutton elements
case 'alt_pickbutton':
{
if (obj.state){
tds[i].style.paddingLeft = istyles['pi_button_normal'][2];
tds[i].style.borderLeft = istyles['pi_button_normal'][3];
}else{
tds[i].style.paddingLeft = istyles[istyle][2];
tds[i].style.borderLeft = istyles[istyle][3];
}
}
}
}
}
}
};
/**
* Format text
*
* @param event Event object
* @param string Formatting command
* @param string Optional argument to the formatting command
*
* @return boolean
*/
this.format = function(e, cmd, arg)
{
e = doEvent(e);
if (this.disabled){return false;}
if (cmd != 'redo'){
this.history.addSnapshot(this.getEditorContents());
}
if (cmd == 'switchmode'){
switch_editor_mode(this.editorId);
return;
}
else if (cmd.substr(0, 6) == 'resize'){
this.resizeEditor(parseInt(cmd.substr(9), 10) * (parseInt(cmd.substr(7, 1), 10) == '1' ? 1 : -1));
return;
}
this.checkFocus();
if (cmd.substr(0, 4) == 'wrap')
{
var ret = this.wrapTags(cmd.substr(6), (cmd.substr(4, 1) == '1' ? true : false));
}
else if (this[cmd])
{
var ret = this[cmd](e);
}
else
{
try
{
var ret = this.applyFormat(cmd, false, (typeof arg == 'undefined' ? true : arg));
}
catch(e)
{
this.handleError(cmd, e);
var ret = false;
}
}
if (cmd != 'undo')
{
this.history.addSnapshot(this.getEditorContents());
}
this.setContext(cmd);
this.checkFocus();
return ret;
};
/**
* Wrap Tags
* @param string Tag to wrap
* @param boolean Use option?
* @param string (Optional) selected text
* @return boolean
*/
this.wrapTags = function(tagname, useoption, selection)
{
//tagname = tagname.toLowerCase();
switch (tagname)
{
case 'CODE':
case 'HTML':
case 'PHP':
case 'Java':
{
this.applyFormat('removeformat');
}
break;
}
if (typeof selection == 'undefined')
{
selection = this.get_selection();
if (selection === false)
{
selection = '';
}
else
{
selection = new String(selection);
}
}
if (useoption == true)
{
var option = this.showPrompt(constructPhrase(vbphrase['enter_tag_option'], ('[' + tagname + ']')), '');
if (option = this.verifyPrompt(option))
{
var opentan = '[' + tagname + '=' + option + '' + ']';
}
else
{
return false;
}
}
else if (useoption !== false)
{
var opentag = '[' + tagname + '=' + useoption + '' + ']';
}
else
{
var opentag = '[' + tagname + ']';
}
var closetag = '[/' + tagname + ']';
var text = opentag + selection + closetag;
this.insertText(text, opentag.YQWlength(), closetag.YQWlength());
return false;
};
/**
* Insert Image
* @param event Event object
* @param string (Optional) Image URL
* @return boolean
*/
this.insertImage = function(e, img)
{
if (typeof img == 'undefined')
{
img = this.showPrompt(vbphrase['enter_image_url'], 'http://');
}
if (img = this.verifyPrompt(img))
{
return this.applyFormat('insertImage', false, img);
}
else
{
return false;
}
};
this.music = function(e, url){
if (typeof url == 'undefined')
{
url = this.showPrompt(vbphrase['enter_music_url'], 'http://');
}
if (url = this.verifyPrompt(url))
{
return this.wrapTags('video',"380,70",url);
}
else
{
return false;
}
}
this.media = function(e, url){
if (typeof url == 'undefined')
{
url = this.showPrompt(vbphrase['enter_media_url'], 'http://');
}
if (url = this.verifyPrompt(url))
{
return this.wrapTags('video','450,350',url);
}
else
{
return false;
}
}
this.real = function(e, url){
if (typeof url == 'undefined')
{
url = this.showPrompt(vbphrase['enter_real_url'], 'http://');
}
if (url = this.verifyPrompt(url))
{
return this.wrapTags('real',false,url);
}
else
{
return false;
}
}
this.flash = function(e, url){
if (typeof url == 'undefined')
{
url = this.showPrompt(vbphrase['enter_flash_url'], 'http://');
}
if (url = this.verifyPrompt(url))
{
return this.wrapTags('flash',false,url);
}
else
{
return false;
}
}
this.setFileUp = function(s){
this.setEditorContents(s);
}
/**
* Handle Error
*
* @param string Command name
* @param event Event object
*/
this.handle_error = function(cmd, e)
{
};
/**
* Show JS Prompt and filter result
*
* @param string Text for the dialog
* @param string Default value for the dialog
*
* @return string
*/
this.showPrompt = function(dialogtxt, defaultval){
return JAVA.trim(new String(prompt(dialogtxt, defaultval)));
};
/**
* Verify the return value of a javascript prompt
*
* @param string String to be checked
*
* @return mixed False on fail, string on success
*/
this.verifyPrompt = function(str)
{
switch(str)
{
case 'http://':
case 'null':
case 'undefined':
case 'false':
case '':
case null:
case false:
return false;
default:
return str;
}
};
this.resizeEditor = function(change)
{
var newheight = parseInt(this.editBox.style.height, 10) + change;
if (newheight >= 100)
{
this.editBox.style.height = newheight + 'px';
/* remember the setting for next time */
if (change % 99 != 0)
{
setCookie('editor_height', newheight, 100);
}
}
};
/**
* Destroy Popup
*/
this.destroyPopup = function(popupname){
this.popups[popupname].parentNode.removeChild(this.popups[popupname]);
this.popups[popupname] = null;
}
/**
* Destroy Editor
*/
this.destroy = function(){
// reset all buttons to default state
for (var i in this.buttons){
this.setControlStyle(this.buttons[i], 'button', 'normal');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -