📄 kindeditor.js
字号:
var autostart = $2.match(/name="autostart" value="(\w+)"/i);
var controls = $2.match(/name="EnableContextMenu" value="(\w+)"/i);
var title = autostart[1] + '-' + controls[1];
var ret = '<img id="mediapreviewimg" src="'+url+'" style="' +
'width:'+width[1]+'px;height:'+height[1]+'px;" alt="'+alt[1]+'" title="'+title+'" border="0">';
return ret;
}
);
str = str.replace(/<object([^>]*type="audio\/x-pn-realaudio-plugin"[^>]*)>(.*?)<\/object>/gi, function ($0,$1,$2) {
var url = IMAGE_PATH + 'realpreview.gif';
var width = $1.match(/width="([^"\s>]+)"/i);
var height = $1.match(/height="([^"\s>]+)"/i);
var alt = $1.match(/data="([^"\s>]+)"/i);
var autostart = $2.match(/name="autostart" value="(\w+)"/i);
var controls = $2.match(/name="controls" value="([\w,]+)"/i);
var title = autostart[1] + '-' + controls[1];
var ret = '<img id="realpreviewimg" src="'+url+'" style="' +
'width:'+width[1]+'px;height:'+height[1]+'px;" alt="'+alt[1]+'" title="'+title+'" border="0">';
return ret;
}
);
return str;
}
function KindHtmlToXhtml(str)
{
str = str.replace(/<p(.*?>)/gi, "<div$1");
str = str.replace(/<\/p>/gi, "</div>");
str = str.replace(/<br.*?>/gi, "<br />");
str = str.replace(/(<hr[^>]*[^\/])(>)/gi, "$1 />");
str = str.replace(/(<img[^>]*[^\/])(>)/gi, "$1 />");
str = str.replace(/(<\w+)(.*?>)/gi, function ($0,$1,$2) {
return($1.toLowerCase() + KindConvertAttribute($2));
}
);
str = str.replace(/(<\/\w+>)/gi, function ($0,$1) {
return($1.toLowerCase());
}
);
str = KindTrim(str);
return str;
}
function KindConvertAttribute(str)
{
str = KindConvertAttributeChild(str, 'style', '[^\"\'>]+');
str = KindConvertAttributeChild(str, 'src', '[^\"\'\\s>]+');
str = KindConvertAttributeChild(str, 'href', '[^\"\'\\s>]+');
str = KindConvertAttributeChild(str, 'color', '[^\"\'\\s>]+');
str = KindConvertAttributeChild(str, 'alt', '[^\"\'\\s>]+');
str = KindConvertAttributeChild(str, 'title', '[^\"\'\\s>]+');
str = KindConvertAttributeChild(str, 'type', '[^\"\'\\s>]+');
str = KindConvertAttributeChild(str, 'face', '[^\"\'>]+');
str = KindConvertAttributeChild(str, 'id', '\\w+');
str = KindConvertAttributeChild(str, 'name', '\\w+');
str = KindConvertAttributeChild(str, 'dir', '\\w+');
str = KindConvertAttributeChild(str, 'target', '\\w+');
str = KindConvertAttributeChild(str, 'align', '\\w+');
str = KindConvertAttributeChild(str, 'width', '[\\w%]+');
str = KindConvertAttributeChild(str, 'height', '[\\w%]+');
str = KindConvertAttributeChild(str, 'border', '[\\w%]+');
str = KindConvertAttributeChild(str, 'hspace', '[\\w%]+');
str = KindConvertAttributeChild(str, 'vspace', '[\\w%]+');
str = KindConvertAttributeChild(str, 'size', '[\\w%]+');
str = KindConvertAttributeChild(str, 'cellspacing', '\\d+');
str = KindConvertAttributeChild(str, 'cellpadding', '\\d+');
if (SAFE_MODE == true) {
str = KindClearAttributeScriptTag(str);
}
return str;
}
function KindConvertAttributeChild(str, attName, regStr)
{
var re = new RegExp("("+attName+"=)[\"']?("+regStr+")[\"']?", "ig");
var reUrl = new RegExp("http://" + SITE_DOMAIN + "(/.*)", "i");
str = str.replace(re, function ($0,$1,$2) {
var val = $2;
if (val.match(reUrl) != null) {
val = val.replace(reUrl, "$1");
}
if (BROWSER == 'IE' && attName.match(/style/i) != null) {
return($1.toLowerCase() + "\"" + val.toLowerCase() + "\"");
} else {
return($1.toLowerCase() + "\"" + val + "\"");
}
}
);
return str;
}
function KindClearAttributeScriptTag(str)
{
var re = new RegExp("(\\son[a-z]+=)[\"']?[^>]*?[^\\\\\>][\"']?([\\s>])","ig");
str = str.replace(re, function ($0,$1,$2) {
return($1.toLowerCase() + "\"\"" + $2);
}
);
return str;
}
function KindClearScriptTag(str)
{
if (SAFE_MODE == false) {
return str;
}
str = str.replace(/<(script.*?)>/gi, "[$1]");
str = str.replace(/<\/script>/gi, "[/script]");
return str;
}
function KindTrim(str)
{
str = str.replace(/^\s+|\s+$/g, "");
str = str.replace(/[\r\n]+/g, "\r\n");
return str;
}
function KindHtmlentities(str)
{
str = str.replace(/&/g,'&');
str = str.replace(/</g,'<');
str = str.replace(/>/g,'>');
str = str.replace(/"/g,'"');
return str;
}
function KindHtmlentitiesDecode(str)
{
str = str.replace(/</g,'<');
str = str.replace(/>/g,'>');
str = str.replace(/"/g,'"');
str = str.replace(/&/g,'&');
return str;
}
function KindGetTop(id)
{
var top = 28;
var tmp = '';
var obj = document.getElementById(id);
while (eval("obj" + tmp).tagName != "BODY") {
tmp += ".offsetParent";
top += eval("obj" + tmp).offsetTop;
}
return top;
}
function KindGetLeft(id)
{
var left = 2;
var tmp = '';
var obj = document.getElementById(id);
while (eval("obj" + tmp).tagName != "BODY") {
tmp += ".offsetParent";
left += eval("obj" + tmp).offsetLeft;
}
return left;
}
function KindDisplayMenu(cmd)
{
KindEditorForm.focus();
KindSelection();
KindDisableMenu();
var top, left;
top = KindGetTop(cmd);
left = KindGetLeft(cmd);
if (cmd == 'KIND_ABOUT') {
left -= 168;
} else if (cmd == 'KIND_LINK') {
left -= 220;
}
document.getElementById('POPUP_'+cmd).style.top = top.toString(10) + 'px';
document.getElementById('POPUP_'+cmd).style.left = left.toString(10) + 'px';
document.getElementById('POPUP_'+cmd).style.display = 'block';
}
function KindDisableMenu()
{
for (i = 0; i < POPUP_MENU_TABLE.length; i++) {
document.getElementById('POPUP_'+POPUP_MENU_TABLE[i]).style.display = 'none';
}
}
function KindReloadIframe()
{
var str = '';
str += KindPopupMenu('KIND_IMAGE');
str += KindPopupMenu('KIND_FLASH');
str += KindPopupMenu('KIND_MEDIA');
str += KindPopupMenu('KIND_REAL');
document.getElementById('InsertIframe').innerHTML = str;
KindDrawIframe('KIND_IMAGE');
KindDrawIframe('KIND_FLASH');
KindDrawIframe('KIND_MEDIA');
KindDrawIframe('KIND_REAL');
}
function KindGetMenuCommonStyle()
{
var str = 'position:absolute;top:1px;left:1px;font-size:12px;color:'+MENU_TEXT_COLOR+
';background-color:'+MENU_BG_COLOR+';border:solid 1px '+MENU_BORDER_COLOR+';z-index:1;display:none;';
return str;
}
function KindGetCommonMenu(cmd, content)
{
var str = '';
str += '<div id="POPUP_'+cmd+'" style="'+KindGetMenuCommonStyle()+'">';
str += content;
str += '</div>';
return str;
}
function KindCreateColorTable(cmd, eventStr)
{
var str = '';
str += '<table cellpadding="0" cellspacing="2" border="0">';
for (i = 0; i < COLOR_TABLE.length; i++) {
if (i == 0 || (i >= 10 && i%10 == 0)) {
str += '<tr>';
}
str += '<td style="width:12px;height:12px;border:1px solid #AAAAAA;font-size:1px;cursor:pointer;background-color:' +
COLOR_TABLE[i] + ';" onmouseover="javascript:this.style.borderColor=\'#000000\';' + ((eventStr) ? eventStr : '') + '" ' +
'onmouseout="javascript:this.style.borderColor=\'#AAAAAA\';" ' +
'onclick="javascript:KindExecute(\''+cmd+'_END\', \'' + COLOR_TABLE[i] + '\');"> </td>';
if (i >= 9 && i%(i-1) == 0) {
str += '</tr>';
}
}
str += '</table>';
return str;
}
function KindDrawColorTable(cmd)
{
var str = '';
str += '<div id="POPUP_'+cmd+'" style="width:160px;padding:2px;'+KindGetMenuCommonStyle()+'">';
str += KindCreateColorTable(cmd);
str += '</div>';
return str;
}
function KindDrawMedia(cmd)
{
var str = '';
str += '<table cellpadding="0" cellspacing="0" style="width:100%">' +
'<tr><td colspan="2"><table border="0"><tr><td id="'+cmd+'preview" style="width:240px;height:240px;border:1px solid #AAAAAA;background-color:#FFFFFF;" align="center" valign="middle"> </td></tr></table></td></tr>' +
'<tr><td style="width:40px;padding:5px;">'+STR_IMAGE_REMOTE+'</td>' +
'<td style="width:210px;padding-bottom:5px;"><input type="text" id="'+cmd+'link" value="http://" style="width:190px;border:1px solid #555555;" /></td></tr>' +
'<tr><td colspan="2" style="margin:5px;padding-bottom:5px;" align="center">' +
'<input type="button" name="button" value="'+STR_BUTTON_LISTENING+'" onclick="javascript:parent.KindMediaPreview(\''+cmd+'\');" style="border:1px solid #555555;background-color:'+BUTTON_COLOR+';" /> ' +
'<input type="submit" name="button" id="'+cmd+'submitButton" value="'+STR_BUTTON_CONFIRM+'" onclick="javascript:parent.KindDrawMediaEnd(\''+cmd+'\');" style="border:1px solid #555555;background-color:'+BUTTON_COLOR+';" /> ' +
'<input type="button" name="button" value="'+STR_BUTTON_CANCEL+'" onclick="javascript:parent.KindDisableMenu();parent.KindReloadIframe();" style="border:1px solid #555555;background-color:'+BUTTON_COLOR+';" /></td></tr>' +
'</table>';
return str;
}
function KindPopupMenu(cmd)
{
switch (cmd)
{
case 'KIND_ZOOM':
var str = '';
for (i = 0; i < ZOOM_TABLE.length; i++) {
str += '<div style="padding:2px;width:120px;cursor:pointer;" ' +
'onclick="javascript:KindExecute(\'KIND_ZOOM_END\', \'' + ZOOM_TABLE[i] + '\');" ' +
'onmouseover="javascript:this.style.backgroundColor=\''+MENU_SELECTED_COLOR+'\';" ' +
'onmouseout="javascript:this.style.backgroundColor=\''+MENU_BG_COLOR+'\';">' +
ZOOM_TABLE[i] + '</div>';
}
str = KindGetCommonMenu('KIND_ZOOM', str);
return str;
break;
case 'KIND_TITLE':
var str = '';
for (i = 0; i < TITLE_TABLE.length; i++) {
str += '<div style="width:140px;cursor:pointer;" ' +
'onclick="javascript:KindExecute(\'KIND_TITLE_END\', \'' + TITLE_TABLE[i][0] + '\');" ' +
'onmouseover="javascript:this.style.backgroundColor=\''+MENU_SELECTED_COLOR+'\';" ' +
'onmouseout="javascript:this.style.backgroundColor=\''+MENU_BG_COLOR+'\';"><' + TITLE_TABLE[i][0] + ' style="margin:2px;">' +
TITLE_TABLE[i][1] + '</' + TITLE_TABLE[i][0] + '></div>';
}
str = KindGetCommonMenu('KIND_TITLE', str);
return str;
break;
case 'KIND_FONTNAME':
var str = '';
for (i = 0; i < FONT_NAME.length; i++) {
str += '<div style="font-family:' + FONT_NAME[i][0] +
';padding:2px;width:160px;cursor:pointer;" ' +
'onclick="javascript:KindExecute(\'KIND_FONTNAME_END\', \'' + FONT_NAME[i][0] + '\');" ' +
'onmouseover="javascript:this.style.backgroundColor=\''+MENU_SELECTED_COLOR+'\';" ' +
'onmouseout="javascript:this.style.backgroundColor=\''+MENU_BG_COLOR+'\';">' +
FONT_NAME[i][1] + '</div>';
}
str = KindGetCommonMenu('KIND_FONTNAME', str);
return str;
break;
case 'KIND_FONTSIZE':
var str = '';
for (i = 0; i < FONT_SIZE.length; i++) {
str += '<div style="font-size:' + FONT_SIZE[i][1] +
';padding:2px;width:120px;cursor:pointer;" ' +
'onclick="javascript:KindExecute(\'KIND_FONTSIZE_END\', \'' + FONT_SIZE[i][0] + '\');" ' +
'onmouseover="javascript:this.style.backgroundColor=\''+MENU_SELECTED_COLOR+'\';" ' +
'onmouseout="javascript:this.style.backgroundColor=\''+MENU_BG_COLOR+'\';">' +
FONT_SIZE[i][1] + '</div>';
}
str = KindGetCommonMenu('KIND_FONTSIZE', str);
return str;
break;
case 'KIND_TEXTCOLOR':
var str = '';
str = KindDrawColorTable('KIND_TEXTCOLOR');
return str;
break;
case 'KIND_BGCOLOR':
var str = '';
str = KindDrawColorTable('KIND_BGCOLOR');
return str;
break;
case 'KIND_HR':
var str = '';
str += '<div id="POPUP_'+cmd+'" style="width:160px;'+KindGetMenuCommonStyle()+'">';
str += '<div id="hrPreview" style="margin:10px 2px 10px 2px;height:1px;border:0;font-size:0;background-color:#FFFFFF;"></div>';
str += KindCreateColorTable(cmd, 'document.getElementById(\'hrPreview\').style.backgroundColor = this.style.backgroundColor;');
str += '</div>';
return str;
break;
case 'KIND_LAYER':
var str = '';
str += '<div id="POPUP_'+cmd+'" style="width:160px;'+KindGetMenuCommonStyle()+'">';
str += '<div id="divPreview" style="margin:5px 2px 5px 2px;height:20px;border:1px solid #AAAAAA;font-size:1px;background-color:#FFFFFF;"></div>';
str += KindCreateColorTable(cmd, 'document.getElementById(\'divPreview\').style.backgroundColor = this.style.backgroundColor;');
str += '</div>';
return str;
break;
case 'KIND_ICON':
var str = '';
var iconNum = 36;
str += '<table id="POPUP_'+cmd+'" cellpadding="0" cellspacing="2" style="'+KindGetMenuCommonStyle()+'">';
for (i = 0; i < iconNum; i++) {
if (i == 0 || (i >= 6 && i%6 == 0)) {
str += '<tr>';
}
var num;
if ((i+1).toString(10).length < 2) {
num = '0' + (i+1);
} else {
num = (i+1).toString(10);
}
var iconUrl = ICON_PATH + 'etc_' + num + '.gif';
str += '<td style="padding:2px;border:0;cursor:pointer;" ' +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -