⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editor.js

📁 采用模块化设计,自由组合文章,软件,论坛等模块,安装方便快捷 模板支持Dreamweaver可视化编辑,创建风格更为容易,专业
💻 JS
📖 第 1 页 / 共 4 页
字号:

		var nexttag = strlower.indexOf(head,firsttag);
		while (nexttag != -1 && end != -1) {
			if (nexttag > end) break;
			end = strlower.indexOf(foot, end + foot_len);
			nexttag = strlower.indexOf(head, nexttag + head_len);
		}
		if (end == -1) {
			strpos = firsttag;
			continue;
		}

		firsttag++;
		var findstr = str.substr(firsttag, end - firsttag);
		str = str.substr(0,begin) + eval(action)(style,findstr,tagname) + str.substr(end+foot_len);

		strpos = begin;

	}while (begin != -1);

	return str;
}
function h(style,code,size) {
	size = 7 - size;
	code = '[size=' + size + '][b]' + code + '[/b][/size]';
	return p(style,code);
}
function p(style,code) {
	if (style.indexOf('align=') != -1) {
		style = findvalue(style,'align=');
		code  = '[align=' + style + ']' + code + '[/align]';
	} else {
		code += "\n";
	}
	return code;
}
function ds(style,code) {
	var styles = [
		['align' , 1, 'align='],
		['align', 1 , 'text-align:'],
		['backcolor' , 2 , 'background-color:'],
		['color' , 2 , 'color:'],
		['font' , 1 , 'font-family:'],
		['b' , 0 , 'font-weight:' , 'bold'],
		['i' , 0 , 'font-style:' , 'italic'],
		['u' , 0 , 'text-decoration:' , 'underline'],
		['strike' , 0 , 'text-decoration:' , 'line-through']
	];

	style = style.toLowerCase();
	for (var i=0;i<styles.length;i++) {
		var begin = style.indexOf(styles[i][2]);
		if (begin == -1) {
			continue;
		}
		var value = findvalue(style,styles[i][2]);
		if (styles[i][1] == 2 && value.indexOf('rgb')!=-1) {
			value = WYSIWYD._colorToRgb(value);
		}
		if (styles[i][1] == 0) {
			if (value == styles[i][3]) {
				code = '[' + styles[i][0] + ']' + code + '[/' + styles[i][0] + ']';
			}
		} else {
			code = '[' + styles[i][0] + '=' + value + ']' + code + '[/' + styles[i][0] + ']';
		}
		style = style.replace(styles[i][2],'');
	}
	
	return code;
}
function list(type,code,tagname) {
	code = code.replace(/<(\/)?li>/ig,'[$1li]');
	if (tagname == 'ul') {
		return '[list]'+code+'[/list]';
	}
	if (type && type.indexOf('type=')!='-1') {
		type = findvalue(type,'type=');
		if (type!='a' && type!='A' && type!='1') {
			type='1';
		}
		return '[list=' + type + ']' + code + '[/list]';
	} else {
		return '[list=1]'+code+'[/list]';
	}
}
function Font(style,str) {
	var styles = new Array();

	styles ={'size' : 'size=','color' : 'color=','font' : 'face=','backcolor' : 'background-color:'};
	style = style.toLowerCase();
	
	for (st in styles) {
		var begin = style.indexOf(styles[st]);
		if (begin == -1) {
			continue;
		}
		var value = findvalue(style,styles[st]);
		if (in_array(st,['backcolor','color']) && value.indexOf('rgb')!=-1) {
			value = WYSIWYD._colorToRgb(value);
		}
		str = '[' + st + '=' + value + ']' + str + '[/' + st + ']';
	}
	return str;
}
function table(style,str) {

	str = str.replace(/<tr([^>]*)>/ig,'[tr]');
	str = str.replace(/<\/tr>/ig,'[/tr]');
	str = searchtag('td',str,'td',1);
	str = searchtag('th',str,'td',1);

	var styles = ['width=','width:'];
	style = style.toLowerCase();

	var s = '';
	for (i in styles) {
		if (style.indexOf(styles[i]) == -1) {
			continue;
		}
		s = '=' + findvalue(style,styles[i]);
		break;
	}
	return '[table' + s + ']' + str + '[/table]';
}
function td(style,str) {
	if (style == '') {
		return '[td]' + str + '[/td]';
	}
	
	var colspan = 1;
	var rowspan = 1;
	var width = '';
	var value;
	
	if (style.indexOf('colspan=') != -1) {
		value = findvalue(style,'colspan=');
		if (value>1) colspan = value;
	}
	if (style.indexOf('rowspan=') != -1) {
		value = findvalue(style,'rowspan=');
		if (value>1) rowspan = value;
	}
	if (style.indexOf('width=') != -1) {
		width = findvalue(style,'width=');
	}
	if (width == '') {
		return (colspan == 1 && rowspan == 1 ? '[td]' : '[td=' + colspan + ',' + rowspan + ']') + str + '[/td]';	
	} else {
		return '[td=' + colspan + ',' + rowspan + ',' + width + ']' + str + '[/td]';		
	}
}
function findvalue(style,find) {
	var firstpos = style.indexOf(find)+find.length;
	var len = style.length;
	var start = 0;
	for (var i = firstpos; i < len; i++) {
		var t_char = style.charAt(i);
		if (start == 0) {
			if (t_char == '"' || t_char == "'") {
				start = i+1;
			} else if (t_char != ' ') {
				start = i;
			}
			continue;
		}
		if (t_char == '"' || t_char == "'" || t_char == ';') {
			break;
		}
	}
	return style.substr(start,i-start);
}
function codetohtml(str) {
	
	code_htm = new Array();
	code_num = 0;
	str = str.replace(/&(?!(#[0-9]+|[a-z]+);)/ig,'&amp;');
	if (!IsChecked('atc_html')) {
		str = str.replace(/</ig,'&lt;');
		str = str.replace(/>/ig,'&gt;');
	}
	str = str.replace(/\n/ig,'<br />');
	str = str.replace(/\[code\](.+?)\[\/code\]/ig, function($1, $2) {return phpcode($2);});

	if (IsChecked('atc_convert')) {
		str = str.replace(/\[hr\]/ig,'<hr />');
		str = str.replace(/\[\/(size|color|font|backcolor)\]/ig,'</font>');
		str = str.replace(/\[(sub|sup|u|i|strike|b|blockquote|li)\]/ig,'<$1>');
		str = str.replace(/\[\/(sub|sup|u|i|strike|b|blockquote|li)\]/ig,'</$1>');
		str = str.replace(/\[\/align\]/ig,'</p>');
		str = str.replace(/\[(\/)?h([1-6])\]/ig,'<$1h$2>');

		str = str.replace(/\[align=(left|center|right|justify)\]/ig,'<p align="$1">');
		str = str.replace(/\[size=(\d+?)\]/ig,'<font size="$1">');
		str = str.replace(/\[color=([^\[\<]+?)\]/ig, '<font color="$1">');
		str = str.replace(/\[backcolor=([^\[\<]+?)\]/ig, '<font style="background-color:$1">');
		str = str.replace(/\[font=([^\[\<]+?)\]/ig, '<font face="$1">');
		str = str.replace(/\[list=(a|A|1)\](.+?)\[\/list\]/ig,'<ol type="$1">$2</ol>');
		str = str.replace(/\[(\/)?list\]/ig,'<$1ul>');
		
		str = str.replace(/\[(attachment|upload)=(\d+)\]/ig,function($1,$2,$3) {return attpath($3,$2);});
		
		str = str.replace(/\[em(\d+)\]/ig,function($1,$2) { return smilepath($2);});
		str = str.replace(/\[img\]([^\[]*)\[\/img\]/ig,'<img src="$1" border="0" />');
		str = str.replace(/\[url=([^\]]+)\]([^\[]+)\[\/url\]/ig, '<a href="$1">'+'$2'+'</a>');
		str = searchtag('table',str,'tableshow',2);
	}
	for (i in code_htm) {
		str = str.replace("[\twind_phpcode_" + i + "\t]", code_htm[i]);
	}
	return str;
}
function phpcode(code) {
	code_num ++;
	code_htm[code_num] = '[code]' + code.replace(/<\/p>/ig,'\n') + '[/code]';
	return "[\twind_phpcode_" + code_num + "\t]";
}
function tableshow(style,str) {
	if (style.substr(0,1) == '=') {
		var width = style.substr(1);
	} else {
		var width = '100%';
	}
	str = str.replace(/\[td=(\d{1,2}),(\d{1,2})(,(\d{1,3}%?))?\]/ig,'<td colspan="$1" rowspan="$2" width="$4">');
	str = str.replace(/\[(tr|td)\]/ig,'<$1>');
	str = str.replace(/\[\/(tr|td)\]/ig,'</$1>');

	return '<table width=' + width + ' class="t" cellspacing=0>' + str + '</table>';
}
function smilepath(NewCode) {
	return '<img src="./images/emotes/em' + NewCode + '.gif" smile="' + NewCode + '" />';
}
function attpath(attid,type) {
	var path = '';
	if (type == 'attachment' && IsElement('atturl_'+attid)) {
		path = getObj('atturl_'+attid).innerHTML;
	} else if (type == 'upload' && is_ie && IsElement('attachment_'+attid)) {
		path = getObj('attachment_'+attid).value;
	}
	if (!path) {
		return '[' + type + '=' + attid + ']';
	} else {
		if (!path.match(/\.(jpg|gif|png|bmp|jpeg)$/ig)) {
			path = imgpath + '/' + stylepath + '/file/zip.gif';
		}
		var img = imgmaxwh(path,320);
		return '<img src="' + path + '" type="' + type + '_' + attid + '" width="'+img.width+'" />';
	}
}
function addattach(attid) {
	editor.focusEditor();
	if (editor._editMode == 'textmode') {
		AddText(' [attachment=' + attid + '] ','');
	} else if (IsElement('atturl_' + attid)) {
		var path = getObj('atturl_'+attid).innerHTML;
		if (!path.match(/\.(jpg|gif|png|bmp|jpeg)$/ig)) {
			path = imgpath + '/' + stylepath + '/file/zip.gif';
		}
		var img = imgmaxwh(path,320);
		editor.insertHTML('<img src="'+img.src+'" type="attachment_'+attid+'" width="'+img.width+'" />');
	}
	closep();
}
function imgmaxwh(url,maxwh) {
	var img = new Image();
	img.src = url;
	if (img.width>maxwh || img.width>maxwh) {
		img.width = (img.width/img.height)>1 ? maxwh : maxwh*img.width/img.height;
	}
	return img;
}

function addsmile(NewCode) {
	editor.focusEditor();
	if (editor._editMode=='textmode') {
		sm = '[em' + NewCode + ']';
		AddText(sm,'');
	} else {
		sm = '<img src="./images/emotes/em' + NewCode + '.gif" smile="' + NewCode + '" /> ';
		editor.insertHTML(sm);
	}
}

function addannex(NewCode) {
	editor.focusEditor();
	sm = '[a' + NewCode + ']';
	if (editor._editMode=='textmode') {		
		AddText(sm,'');
	} else {		
		editor.insertHTML(sm);
	}
}

function extend(cmdID) {
	if (cmdID == 'setform') {
		editor._pos = editor.getpos();
	}
	if (typeof read == 'object' && read.obj != null && read.obj.id == 'wy_'+cmdID) {
		closep();read.obj=null;
	} else {
		read.obj = getObj('wy_'+cmdID);
		ajax.send('pw_ajax.php','action=extend&type='+cmdID,ajax.get);
	}
}
function upcode(id,param) {
	var d = getObj(id).lastChild.innerHTML.split('|');
	var t = id.substr(id.indexOf('_')+1);
	var c = new Array();
	for (var i=0;i<param;i++) {
		do{
			c[i] = prompt(d[i],'');
			if (c[i] == null)
				return;
		}while (c[i]=='');
	}
	switch(param) {
		case '2' : code = '[' + t + '=' + c[0] + ']' + c[1] + '[/' + t + ']';break;
		case '3' : code = '[' + t + '=' + c[0] + ',' + c[1] + ']' + c[2] + '[/' + t + ']';break;
		default: code = '[' + t + ']' + c[0] + '[/' + t + ']';break;
	}
	editor.focusEditor();
	AddCode(code,'');
	closep();
}
function IsChecked(id) {
	return document.getElementById(id) && document.getElementById(id).checked === true ? true : false;
}
function insertform(id) {
	editor.setpos();
	var code = '<table class="t" width="60%">';
	code += '<tr class="tr3"><td colspan=2><b>'+id+'</b></td></tr>'
	var ds   = getObj('formstyle').getElementsByTagName('tr');
	for (var i=1;i<ds.length;i++) {
		code += '<tr class="tr3"><td>'+ds[i].firstChild.innerHTML+'</td><td>'+ds[i].lastChild.firstChild.value+'</td></tr>';
	}
	code += '</table>';
	if (editor._editMode=='textmode') {
		AddText(htmltocode(code),'');
	} else {
		editor.insertHTML(code);
	}
	closep();
}
function showform(id) {
	ajax.send('pw_ajax.php','action=extend&type=setform&id='+id,ajax.get);
}
function flex(type) {
	var height = parseInt(editor._textArea.style.height);
	if (type==0) {
		if (height<300) return;
		height-=100;
	} else {
		height+=100;
	}
	editor._textArea.style.height = height + 'px';
	if (editor._iframe != null) {
		editor._iframe.style.height = height + 'px';
	}
}

//表情
function showemote(cmdID) {
	var menu_editor = getObj("menu_editor");
	
	var html = '<div id="emotebox">';
	for (var i=1;i<emotes;i++) {
		html += '<img src="./images/emotes/em'+i+'.gif" title="" onclick="javascript:addsmile('+i+');" style="margin: 5px; cursor: pointer;">'+(i%10>0?'':'<br />');
		}
	html += '</div>';
	menu_editor.innerHTML = html;
	read.open('menu_editor','wy_' + cmdID);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -