common.js

来自「基于struts+hibernate的电子商务网站。可运行。数据库mysql」· JavaScript 代码 · 共 620 行 · 第 1/2 页

JS
620
字号
	if(!smdiv[ctrl.id]) {
		smdiv[ctrl.id] = document.createElement('div');
		smdiv[ctrl.id].id = ctrl.id + '_menu';
		smdiv[ctrl.id].style.display = 'none';
		smdiv[ctrl.id].className = 'popupmenu_popup';
		ctrl.parentNode.appendChild(smdiv[ctrl.id]);
	}
	smdiv[ctrl.id].innerHTML = '<table style="width: 60px;height: 60px;text-align: center;vertical-align: middle;" class="altbg2"><tr><td><img src="' + ctrl.src + '" border="0" width="' + ctrl.lw + '" /></td></tr></table>';
	showMenu(ctrl.id, 0, 0, 1, 0);
}

function announcement() {
	$('announcement').innerHTML = '<marquee style="margin: 0px 8px" direction="left" scrollamount="2" scrolldelay="1" onMouseOver="this.stop();" onMouseOut="this.start();">' +
		$('announcement').innerHTML + '</marquee>';
	$('announcement').style.display = 'block';
}

function $(id) {
	return document.getElementById(id);
}

function in_array(needle, haystack) {
	if(typeof needle == 'string') {
		for(var i in haystack) {
			if(haystack[i] == needle) {
					return true;
			}
		}
	}
	return false;
}

function saveData(data, del) {
	if(!data && isUndefined(del)) {
		return;
	}
	if(typeof wysiwyg != 'undefined' && typeof editorid != 'undefined' && typeof bbinsert != 'undefined' && bbinsert && $(editorid + '_mode') && $(editorid + '_mode').value == 1) {
		data = html2bbcode(data);
	}
	if(is_ie) {
		try {
			var oXMLDoc = textobj.XMLDocument;
			var root = oXMLDoc.firstChild;
			if(root.childNodes.length > 0) {
				root.removeChild(root.firstChild);
			}
			var node = oXMLDoc.createNode(1, 'POST', '');
			var oTimeNow = new Date();
			oTimeNow.setHours(oTimeNow.getHours() + 24);
			textobj.expires = oTimeNow.toUTCString();
			node.setAttribute('message', data);
			oXMLDoc.documentElement.appendChild(node);
			textobj.save('GerWeb!');
		} catch(e) {}
	} else if(window.sessionStorage) {
		try {
			sessionStorage.setItem('GerWeb!', data);
		} catch(e) {}
	}
}

function loadData() {
	var message = '';
	if(is_ie) {
		try {
			textobj.load('GerWeb!');
			var oXMLDoc = textobj.XMLDocument;
			var nodes = oXMLDoc.documentElement.childNodes;
			message = nodes.item(nodes.length - 1).getAttribute('message');
		} catch(e) {}
	} else if(window.sessionStorage) {
		try {
			message = sessionStorage.getItem('GerWeb!');
		} catch(e) {}
	}

	if(in_array((message = trim(message)), ['', 'null', 'false', null, false])) {
		alert(lang['post_autosave_none']);
		return;
	}
	if((typeof wysiwyg == 'undefined' || !wysiwyg ? textobj.value : editdoc.body.innerHTML) == '' || confirm(lang['post_autosave_confirm'])) {
		if(typeof wysiwyg == 'undefined' || !wysiwyg) {
			textobj.value = message;
		} else {
			editdoc.body.innerHTML = bbcode2html(message);
		}
	}
}

function deleteData() {
	if(is_ie) {
		saveData('', 'delete');
	} else if(window.sessionStorage) {
		try {
			sessionStorage.removeItem('GerWeb!');
		} catch(e) {}
	}
}

function updateseccode(width, height) {
	$('seccodeimage').innerHTML = '<img id="seccode" onclick="updateseccode(' + width + ', '+ height + ')" width="' + width + '" height="' + height + '" src="seccode.php?update=' + Math.random() + '" class="absmiddle" alt="" />';
}

function signature(obj) {
	if(obj.style.maxHeightIE != '') {
		var height = (obj.scrollHeight > parseInt(obj.style.maxHeightIE)) ? obj.style.maxHeightIE : obj.scrollHeight;
		if(obj.innerHTML.indexOf('<IMG ') == -1) {
			obj.style.maxHeightIE = '';
		}
		return height;
	}
}

function trim(str) {
	return (str + '').replace(/(\s+)$/g, '').replace(/^\s+/g, '');
}

function fetchCheckbox(cbn) {
	return $(cbn) && $(cbn).checked == true ? 1 : 0;
}

function parseurl(str, mode) {
	str = str.replace(/([^>=\]"'\/]|^)((((https?|ftp):\/\/)|www\.)([\w\-]+\.)*[\w\-\u4e00-\u9fa5]+\.([\.a-zA-Z0-9]+|\u4E2D\u56FD|\u7F51\u7EDC|\u516C\u53F8)((\?|\/|:)+[\w\.\/=\?%\-&~`@':+!]*)+\.(jpg|gif|png|bmp))/ig, mode == 'html' ? '$1<img src="$2" border="0">' : '$1[img]$2[/img]');
	str = str.replace(/([^>=\]"'\/@]|^)((((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|ed2k):\/\/)|www\.)([\w\-]+\.)*[:\.@\-\w\u4e00-\u9fa5]+\.([\.a-zA-Z0-9]+|\u4E2D\u56FD|\u7F51\u7EDC|\u516C\u53F8)((\?|\/|:)+[\w\.\/=\?%\-&~`@':+!#]*)*)/ig, mode == 'html' ? '$1<a href="$2" target="_blank">$2</a>' : '$1[url]$2[/url]');
	str = str.replace(/([^\w>=\]:"'\.\/]|^)(([\-\.\w]+@[\.\-\w]+(\.\w+)+))/ig, mode == 'html' ? '$1<a href="mailto:$2">$2</a>' : '$1[email]$2[/email]');
	return str;
}

function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}

function addbookmark(url, site){
	if(is_ie) {
		window.external.addFavorite(url, site);
	} else {
		alert('Please press "Ctrl+D" to add bookmark');
	}
}

function doane(event) {
	e = event ? event : window.event ;
	if(is_ie) {
		e.returnValue = false;
		e.cancelBubble = true;
	} else {
		e.stopPropagation();
		e.preventDefault();
	}
}



/* GerWeb! NT */

function insertSmiley(obj) {
	var smilieid = obj.id.substr(18);

	checkFocus();
	var src = obj.src;
	var code = obj.alt;
	if(typeof wysiwyg != 'undefined' && wysiwyg && allowsmilies && (!$('smileyoff') || $('smileyoff').checked == false)) {
		if(is_moz) {
			applyFormat('InsertImage', false, src);
			var smilies = findtags(editdoc.body, 'img');
			for(var i = 0; i < smilies.length; i++) {
				if(smilies[i].src == src && smilies[i].getAttribute('smilieid') < 1) {
					smilies[i].setAttribute('smilieid', smilieid);
					smilies[i].setAttribute('border', "0");
				}
			}
		} else {
			insertText('<img src="' + src + '" border="0" smilieid="' + smilieid + '" alt="" /> ', false);
		}
	} else {
		code += ' ';
		AddText(code);
	}
}


function smiliewindow_onunload(e) {
	if(typeof smilie_window != 'undefined' && !smilie_window.closed) {
		smilie_window.close();
	}
}


/**
function open_smilie_window(width, height) {
	smilie_window = window.open('showsmilies.aspx?editid=' + editor_id, 'Popup', 'width=200,height=500,resizable=yes,scrollbars=yes');
	window.onunload = smiliewindow_onunload;
}
*/
var textcontent = [/:\)/g,/:\(/g,/:D/g,/:\'\(/g,/:@/g,/:P/g,/:B/g,/:\$/g,/;P/g,/:L/g,/:Q/g,/:lol/g];
var imgcontent = ['editor/images/smilies/smile.gif',
				  'editor/images/smilies/sad.gif',
				  'editor/images/smilies/biggrin.gif',
				  'editor/images/smilies/cry.gif',
				  'editor/images/smilies/huffy.gif',
				  'editor/images/smilies/shocked.gif',
				  'editor/images/smilies/tongue.gif',
				  'editor/images/smilies/shy.gif',
				  'editor/images/smilies/titter.gif',
				  'editor/images/smilies/sweat.gif',
				  'editor/images/smilies/mad.gif',
				  'editor/images/smilies/lol.gif'];
				  
function stringToSmaile(content){			
	if(content){
		for(var i=0;i<textcontent.length;i++){										
			content = content.replace(textcontent[i],"<img src='"+imgcontent[i]+"' />");							
		}
	}
	return content;
}

function smiley_insert() {
	if(smileyinsert) {
		showsmilies();
		var smilie_container = $(editor_id + '_smiliebox');
		if(smilie_container != null) {
			var smilies = findtags(smilie_container, 'img');
			for(var i = 0; i < smilies.length; i++) {
				if(smilies[i].id && smilies[i].id.indexOf('_smilie_') > -1) {
					smilies[i].style.cursor = is_ie ? 'hand' : 'pointer';
					
				}
			}
		}

		var smilie_container2 = $('smilietable');
		if(smilie_container2 != null) {
			var smilies = findtags(smilie_container2, 'img');
			for(var i = 0; i < smilies.length; i++) {
				if(smilies[i].id && smilies[i].id.indexOf('_smilie_') > -1) {
					smilies[i].style.cursor = is_ie ? 'hand' : 'pointer';
				}
			}
		}
	}
}

//==================================
function findobj(n, d) {
	
	var p, i, x;	
	if(!d) d = document;
	if((p = n.indexOf("?"))>0 && parent.frames.length) {
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}
	if(x != d[n] && d.all) x = d.all[n];
	for(i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
	for(i = 0; !x && d.layers && i < d.layers.length; i++) x = findobj(n, d.layers[i].document);
	if(!x && document.getElementById) x = document.getElementById(n);
	
	return x;
}
//==================================


function showsmilies(){
	var row = null;
	var col = null;
	var img = null;
	var rowIndex = 0;
	var colIndex = 0;
	
	if(isUndefined(smiliesIsCreate)) {
		var smiliesIsCreate = 0;
	}
	
	if(isUndefined(showsmiliestitle)) {
		var showsmiliestitle = 1;
	}
	
	if(isUndefined(title)) {
		var title = "";
	}
	
	if(isUndefined(editor_id)) {
		return;
	}
	
	if (smiliesIsCreate!=0){
		return;
	}
	
	

	try{
		if (!smilies.length){
			return;
		}
		
		var smilie_container = findobj(editor_id + '_smiliebox');
		var smilieytable = document.createElement('table');
				smilieytable.cellPadding = "3";
				smilieytable.cellSpacing = "0";
				smilieytable.width = "100%";
				smilieytable.border = 0;
				smilieytable.className = "altbg1";
				
				smilieytable.style.border = "0px";
				
				smilieytable.id = editor_id + "_smilieytable";
				
			if (showsmiliestitle == 1){
				//top琛

⌨️ 快捷键说明

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