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

📄 main.js

📁 LiteBlaster 是一款基于 .NET Framework 原创的 ASP.NET 论坛系统。后台程序库采用 C#/VB.NET 编写
💻 JS
字号:
// main javascript shared
// x_core.js, x_event.js needed


// for responseXML
function getXmlElementText(xmlDoc, tagName, index){
	if(!index){
		index = 0;
	}
	var element;
	try{
		element = xmlDoc.getElementsByTagName(tagName)[index];
	}catch(e){
		return null;
	}
	if(element == null){
		return null;
	}else{
		var c = element.firstChild;
		if(c == null){
			return '';
		}else{
			if(c.data == null){
				return '';
			}else{
				return c.data;
			}
		}
	}
}
function parseXmlText(text){
	//invoke this only when needed
	if(!xStr(text)){
		return null;
	}
	if(!isNaN(text)){
		return parseFloat(text);
	}
	if(text == 'true' || text == 'True'){
		return true;
	}else if(text == 'false' || text == 'False'){
		return false;
	}
	return text;
}


// encode html
function encodeHtml(uncoded){
	return uncoded
		.replace(/&/g, '&')
		.replace(/ /g, ' ')
		.replace(/</g, '&lt;')
		.replace(/>/g, '&gt;')
		.replace(/"/g, '&quot;')
		.replace(/'/g, '&apos;')
		.replace(/“/g, '&ldquo;')
		.replace(/”/g, '&rdquo;')
		.replace(/‘/g, '&lsquo;')
		.replace(/’/g, '&rsquo;');
}


// for display
function setElementVisible(id, visible){
	xGetElementById(id).style.display = (visible ? '' : 'none');
}
function switchElementVisible(id){
	var ele = xGetElementById(id);
	var visible = ele.style.display;
	visible = (visible == 'none') ? '' : 'none';
	ele.style.display = visible;
}
function switchHeaderSwitcherVisible(target, e){
	var switcher = new xEvent(e).target;
	if(switcher == null){
		return;
	}
	var visible, newClass;
	if(switcher.className == 'ListHeaderExpanded'){
		newClass = 'ListHeaderCollapsed';
		visible = 'none';
	}else{
		newClass = 'ListHeaderExpanded';
		visible = '';
	}
	xGetElementById(target).style.display = visible;
	switcher.className = newClass;
}
function setInputDisabled(id, disabled){
	try{
		xGetElementById(id).disabled = disabled;
	}catch(e){}
}
function addExtraTitle(extraTitle){
	document.title = extraTitle + ' - ' + document.title;
}
function setExtraPathIndicator(extraPathHtml){
	xGetElementById('ExtraPathIndicator').innerHTML = extraPathHtml;
}


// getElementByName : the first one only
function getElementByName(parent, name){
	parent = xGetElementById(parent);
	var c = parent.firstChild;
	if(!c){
		return null;
	}
	var n;
	try{
		n = c.getAttribute('name');
		if(xStr(n) && n == name){
			return c;
		}
	}catch(e){
	}
	while(c = c.nextSibling){
		try{
			n = c.getAttribute('name');
			if(xStr(n) && n == name){
				return c;
			}
		}catch(e){
		}
	}
	return null;
}


// for arrays
Array.prototype.contains = function(ele){
	for(var i = 0; i < this.length; i++){
		if(this[i] == ele){
			return true;
		}
	}
	return false;
}


// wrappers
var wrappers = new Object();

// not compatible with style attibute
wrappers.aWrapper = function(id, disabledInner) {
	this.init(id, disabledInner);
}
wrappers.aWrapper.prototype = {
	getControl : function() {
		return xGetElementById(this.id);
	},
	init : function(id, disabledInner) {
		this.id = id;
		this.enabled = true;
		var ctrl = this.getControl();
		if(!ctrl){
			return;
		}
		this.inner = ctrl.innerHTML;
		this.disabledInner = disabledInner ? disabledInner : this.inner;
		this.classText = ctrl.className;
		this.title = ctrl.title;
		this.target = ctrl.target;
		this.href = ctrl.href;
		if(ctrl.getAttribute){
			this.onClickText = ctrl.getAttribute('onClick');
		}
	},
	disable : function() {
		if(!this.enabled){
			return;
		}
		var ctrl = this.getControl();
		if(!ctrl){
			return;
		}
		ctrl.outerHTML = '<span id="' + this.id + '"'
					+ (this.classText ? (' class="' + this.classText + '"') : '')
					+ '>' + this.disabledInner + '</span>';
		this.enabled = false;
	},
	enable : function() {
		if(this.enabled){
			return;
		}
		var ctrl = this.getControl();
		if(!ctrl){
			return;
		}
		ctrl.outerHTML = '<a id="' + this.id + '"'
						+ (this.classText ? (' class="' + this.classText + '"') : '')
						+ (this.title ? (' title="' + this.title + '"') : '')
						+ (this.target ? (' target="' + this.target + '"') : '')
						+ (this.href ? (' href="' + this.href + '"') : '')
						+ '>' + this.inner + '</a>';
		ctrl = null;
		ctrl = this.getControl();
		if(this.onClickText){
			if(typeof(this.onClickText) == 'function'){
				ctrl.onclick = this.onClickText;
			}else{
				ctrl.setAttribute('onClick', this.onClickText);
			}
		}
		this.enabled = true;
	},
	setText : function(text){
		var ctrl = this.getControl();
		if(!ctrl){
			return;
		}
		ctrl.innerHTML = encodeHtml(text);
	}
}


// menu
var currentMenu;
function showMenu(menu, parent, position){
	var m = xGetElementById(menu);
	if(currentMenu == m){
		return;
	}
	if(currentMenu){
		setElementVisible(currentMenu, false);
		currentMenu = null;
	}
	if(!position){
		position = 'bottom';
	}
	var p = xGetElementById(parent);
	m.style.position = 'absolute';
	switch(position){
		case 'bottom':
			xLeft(m, xPageX(p) - 20);
			xTop(m, xPageY(p) + xHeight(p));
			break;
		case 'left':
			xLeft(m, xPageX(p) - xWidth(m));
			xTop(m, xPageY(p));
			break;
	}
	currentMenu = m;
	setElementVisible(m, true);
}
function hideMenu(e){
	var m = currentMenu;
	if(m == null){
		return;
	}
	if(e != null){
		var t = new xEvent(e);
		var x = xPageX(m);
		var y = xPageY(m);
		if(t.pageX > x && t.pageX < x + xWidth(m) && t.pageY > y && t.pageY < y + xHeight(m)){
			return;
		}
	}
	setElementVisible(m, false);
	currentMenu = null;
}


// board jump
function jumpToBoard(e){
	var ctrl = new xEvent(e).target;		//select control
	var id = ctrl.value;					//board id - string
	if(isNaN(id) || parseInt(id) < 1){
		return;
	}
	window.location.href = 'Board.aspx?id=' + id;
}

⌨️ 快捷键说明

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