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

📄 wysiwyg.js

📁 自己写的一个网络日志(BLOG)系统
💻 JS
📖 第 1 页 / 共 3 页
字号:
				AddTxt = "[list][li]" + text + "[/li][/list]";			} else{				AddTxt="[list]";				txt="1";				while(txt!="" && txt!=null){					txt=prompt(I18N['listitem'],"");					if(txt!=""){						AddTxt+="[li]"+txt+"[/li]";					}				}				AddTxt+="[/list]";			}			break;		default : return false;	}	AddText(AddTxt,text);}function windselect(cmdID,value){	text = editor.getsel();	switch(cmdID){	    case "fontname": AddTxt = "[font=" + value + "]" + text + "[/font]";break;	    case "fontsize": AddTxt = "[size=" + value + "]" + text + "[/size]";break;	    case "formatblock": AddTxt = value ? "[" + value + "]" + text + "[/" + value + "]" : "";break;		default : AddTxt = "";	}	AddText(AddTxt,text);}function AddText(code,text){	var startpos = text == '' ? code.indexOf(']') + 1 : code.indexOf(text);	if(document.selection){		var sel = document.selection.createRange();		sel.text = code;		sel.moveStart('character',-code.length + startpos);		sel.moveEnd('character', -code.length + text.length + startpos);		sel.select();	} else if(typeof editor._textArea.selectionStart != 'undefined'){		var prepos = editor._textArea.selectionStart;		editor._textArea.value = editor._textArea.value.substr(0,prepos) + code + editor._textArea.value.substr(editor._textArea.selectionEnd);		editor._textArea.selectionStart = prepos + startpos;		editor._textArea.selectionEnd = prepos + startpos + text.length;	} else{		document.FORM.atc_content.value += code;	}}function AddCode(code,text){	if(editor._editMode=='textmode'){		AddText(code,text);	} else{		editor.insertHTML(code);	}}function htmltocode(str){	if(IsChecked('atc_html')){		return str;	}	code_htm = new Array();	code_num = 0;	str = str.replace(/(\r\n|\n|\r)/ig, '');	str = str.replace(/<br[^>]*>/ig,'\n');	str = str.replace(/<p[^>\/]*\/>/ig,'\n');	str = str.replace(/\[code\](.+?)\[\/code\]/ig, function($1, $2) {return phpcode($2);});		str = str.replace(/\son[\w]{3,16}\s?=\s*([\'\"]).+?\1/ig,'');	//if(IsChecked('atc_convert')){		str = str.replace(/<hr[^>]*>/ig,'[hr]');		str = str.replace(/<(sub|sup|u|strike|b|i|pre)>/ig,'[$1]');		str = str.replace(/<\/(sub|sup|u|strike|b|i|pre)>/ig,'[/$1]');		str = str.replace(/<(\/)?strong>/ig,'[$1b]');		str = str.replace(/<(\/)?em>/ig,'[$1i]');		str = str.replace(/<(\/)?blockquote([^>]*)>/ig,'[$1blockquote]');				str = str.replace(/<img[^>]*smile=\"(\d+)\"[^>]*>/ig,'[s:$1]');		str = str.replace(/<img[^>]*src=[\'\"\s]*([^\s\'\"]+)[^>]*>/ig,'[img]'+'$1'+'[/img]');		str = str.replace(/<a[^>]*href=[\'\"\s]*([^\s\'\"]*)[^>]*>(.+?)<\/a>/ig,'[url=$1]'+'$2'+'[/url]');		str = str.replace(/<h([1-6]+)([^>]*)>(.*?)<\/h\1>/ig,function($1,$2,$3,$4){return h($3,$4,$2);});				str = searchtag('table',str,'table',1);		str = searchtag('font',str,'Font',1);		str = searchtag('div',str,'ds',1);		str = searchtag('p',str,'p',1);		str = searchtag('span',str,'ds',1);		str = searchtag('ol',str,'list',1);		str = searchtag('ul',str,'list',1);	//}	for(i in code_htm){		str = str.replace("[\twind_phpcode_" + i + "\t]", code_htm[i]);	}	str = str.replace(/<[^>]*?>/ig, '');	str = str.replace(/&amp;/ig, '&');	str = str.replace(/&lt;/ig, '<');	str = str.replace(/&gt;/ig, '>');	return str;}function searchtag(tagname,str,action,type){	if(type == 2){		var tag = ['[',']'];	} else{		var tag = ['<','>'];	}	var head = tag[0] + tagname;	var head_len = head.length;	var foot = tag[0] + '/' + tagname + tag[1];	var foot_len = foot.length;	var strpos = 0;		do{		var strlower = str.toLowerCase();		var begin = strlower.indexOf(head,strpos);		if(begin == -1){			break;		}		var strlen = str.length;		for(var i = begin + head_len; i < strlen; i++){			if(str.charAt(i)==tag[1]) break;		}		if(i>=strlen) break;		var firsttag = i;		var style = str.substr(begin + head_len, firsttag - begin - head_len);		var end = strlower.indexOf(foot,firsttag);		if (end == -1) break;		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:'],		['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 = '';		if(styles[i][1] < 2){			value = findvalue(style,styles[i][2]);		} else{			begin = style.indexOf('rgb',begin);			if(begin == -1){				continue;			} else{				value = WYSIWYD._colorToRgb(style.substr(begin,style.indexOf(')')-begin+1));			}		}		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] + ']';		}	}		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]);		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);	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==' ' || t_char==';'){			break;		}	}	return style.substr(start,i-start);}function codetohtml(str){	code_htm = new Array();	code_num = 0;	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(/\[s:(\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 + '[/code]';	return "[\twind_phpcode_" + code_num + "\t]";}function tableshow(style,str){	if(style.substr(0,1) == '='){		width = style.substr(1);	} else{		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 checklength(theform,postmaxchars){	if (postmaxchars != 0) {		message = '\n' + I18N['maxbits'] + postmaxchars;	} else {		message = '';	}	var msg = editor._editMode == 'textmode' ? editor.getHTML() : htmltocode(editor.getHTML());	alert(I18N['currentbits'] + strlen(msg) + message);}function Addaction(addTitle){	editor.focusEditor();	AddCode(addTitle,'');}function IsChecked(id){	return document.getElementById(id) && document.getElementById(id).checked === true ? true : false;}function quickpost(event){	if ((event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83)) {		document.FORM.Submit.click();	}}function click_open(idName,object,type){	if (GE('showmenu').style.display=='') {		closep();		return false;	}	cookie_name = 1;	mouseover_open(idName,object,type);}function mouseover_open(idName,object,type){	if (typeof type == 'undefined') {		type = 1;	}	if (cookie_name == 1 || type>2) {		obj  = GE('showmenu');		obj2 = GE(idName);		obj3 = GE(object);		var left = findPosX(obj3) + ietruebody().scrollLeft;		var top = findPosY(obj3) + ietruebody().scrollTop;		obj.innerHTML = obj2.innerHTML;        obj.className = obj2.className;		obj.style.filter = 'alpha(opacity=96);opacity:0.96;';		obj.style.display = '';		var height = obj.offsetHeight;		var width  = obj.offsetWidth;		if (left + width > ietruebody().scrollLeft + ietruebody().clientWidth) {			left -= width;		}		if (type=='2' && height + top > ietruebody().scrollTop + ietruebody().clientHeight) {			top -= height;		} else {			top += type=='4' ? 31 : 15;		}		obj.style.top = top + 'px';		obj.style.left = left + 'px';		if (type>'2') {			addEvent(document,'mouseout',doc_mouseout);		} else if (type<'2') {			addEvent(document,'mousedown',doc_mousedown);		}	}	return false;}function closep(type){	if (typeof type == 'undefined') {		type = 'down';	}	cookie_name = 0;	obj = GE('showmenu');	obj.innerHTML = '';	obj.className = '';	obj.style.display = 'none';	if (type=='out') {		removeEvent(document,'mouseout',doc_mouseout);	} else {		removeEvent(document,'mousedown',doc_mousedown);	}	return false;}function doc_mousedown(e){	var e = is_ie ? event : e;	obj	= GE('showmenu');	_x	= is_ie ? e.x : e.pageX;	_y	= is_ie ? e.y + ietruebody().scrollTop : e.pageY;	_x1 = obj.offsetLeft;	_x2 = obj.offsetLeft + obj.offsetWidth;	_y1 = obj.offsetTop - 25;	_y2 = obj.offsetTop + obj.offsetHeight;	if (_x<_x1 || _x>_x2 || _y<_y1 || _y>_y2) {		closep('down');	}}function doc_mouseout(e){	var e = is_ie ? event : e;	obj	= GE('showmenu');	_x	= is_ie ? e.x : e.pageX;	_y	= is_ie ? e.y + ietruebody().scrollTop : e.pageY;	_x1 = obj.offsetLeft - 20;	_x2 = obj.offsetLeft + obj.offsetWidth + 20;	_y1 = obj.offsetTop - 35;	_y2 = obj.offsetTop + obj.offsetHeight + 20;	if (_x<_x1 || _x>_x2 || _y<_y1 || _y>_y2) {		closep('out');	}}function ietruebody(){	return (document.compatMode && document.compatMode!='BackCompat') ? document.documentElement : document.body;}function IsElement(id){	return GE(id)!=null ? true : false;}function addEvent(el,evname,func){	if (is_ie) {		el.attachEvent('on' + evname,func);	} else {		el.addEventListener(evname,func,true);	}}function removeEvent(el,evname,func){	if (is_ie) {		el.detachEvent('on' + evname,func);	} else {		el.removeEventListener(evname,func,true);	}}

⌨️ 快捷键说明

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