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

📄 common.js

📁 一个网上购物商城系统
💻 JS
📖 第 1 页 / 共 2 页
字号:

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;
}


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 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行
				row = smilieytable.insertRow(-1);			
				col = row.insertCell(-1);
				col.colSpan = 4
				col.align = "center";
				col.className = "altbg1";
				col.innerHTML = "";
			}
		
			
		//smilies行

		sCount = smilies.length;
		if (sCount > smiliesCount){
			sCount = smiliesCount;
		}
		
		var temp_sCount = 0
		for(var i = 0; i < smilies.length; i++)
		{
		
			if (smilies[i]){
				temp_sCount ++;
				if (temp_sCount > sCount){
					break;
				}
				if (colIndex > colCount || colIndex < 1){
					row = smilieytable.insertRow(-1);			
					colIndex = 1;
				}
				col = row.insertCell(-1);
				col.vAlign = "top";
				col.innerHTML += "<img src=\"editor/images/smilies/" + smilies[i][2] + "\" alt=\"" + smilies[i][1] + "\" id=\"" + editor_id + "_smilie_" + smilies[i][0] + "\" border='0' onclick='insertSmiley(this);' />"
				/*
				img = document.createElement('img');
				img.src = "editor/images/smilies/" + smilies[i][2];
				img.alt = smilies[i][1];
				img.id = editor_id + "_smilie_" + smilies[i][0];
				img.border = 0;
				col.appendChild(img);
				*/
				
				colIndex++;
				
			}
		}
		
		for (var i = colIndex; i < colCount; i++)
		{
			if (row != null){
				col = row.insertCell(-1);
				col.vAlign = "top";
				col.innerHTML = "&nbsp;";
			}
		}
		
			//bottom行
			row = smilieytable.insertRow(-1);
			col = row.insertCell(-1);
			col.colSpan = 4
			col.align = "center";
			col.height = 24;

			var a = document.createElement('a');
			col.appendChild(a);
			a.href = "#";
			a.onclick = function(){open_smilie_window(200, 500); return false;};
				var span = document.createElement('span');
				span.className = "bold";
				span.innerHTML = "更多表情";
			a.appendChild(span);
		
		smilie_container.appendChild(smilieytable);
		
		smiliesIsCreate = 1;
	}
	catch(e){
		alert(e.message);
		return;
	}
}

⌨️ 快捷键说明

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