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

📄 common.js

📁 make project on java
💻 JS
字号:
var postSubmited = false;
var ctrlobjclassName;
var jsmenuobj;
var jsmenu = new Array();
var timeout = 100;

var userAgent = navigator.userAgent.toLowerCase();
var is_opera = (userAgent.indexOf('opera') != -1);
var is_saf = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == 'Apple Computer, Inc.'));
var is_webtv = (userAgent.indexOf('webtv') != -1);
var is_ie = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4 = ((is_ie) && (userAgent.indexOf('msie 4.') != -1));
var is_moz = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon = (userAgent.indexOf('konqueror') != -1);
var is_ns = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4 = ((is_ns) && (parseInt(navigator.appVersion) == 4));
var is_mac = (userAgent.indexOf('mac') != -1);

function ctlent(event) {
	if(postSubmited == false && (event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83) && $('postsubmit')) {
		if(in_array($('postsubmit').name, ['topicsubmit', 'replysubmit', 'editsubmit']) && !validate($('postform'))) {
			return;
		}
		postSubmited = true;
		$('postsubmit').disabled = true;
		$('postform').submit();
	}
}

function storeCaret(textEl){
	if(textEl.createTextRange){
		textEl.caretPos = document.selection.createRange().duplicate();
	}
}

function findtags(parentobj, tag) {
	if(typeof parentobj.getElementsByTagName != 'undefined') {return parentobj.getElementsByTagName(tag);}
	else if(parentobj.all && parentobj.all.tags) {return parentobj.all.tags(tag);}
	else {return null;}
}

function imgzoom(o) {
	if(event.ctrlKey) {
		var zoom = parseInt(o.style.zoom, 10) || 100;
		zoom -= event.wheelDelta / 12;
		if(zoom > 0) {
			o.style.zoom = zoom + '%';
		}
		return false;
	} else {
		return true;
	}
}

function AddText(txt) {
	obj = $('postform').message;
	selection = document.selection;
	checkFocus();
	if(typeof(obj.selectionStart) != 'undefined') {
		var opn = obj.selectionStart + 0;
		obj.value = obj.value.substr(0, obj.selectionStart) + txt + obj.value.substr(obj.selectionEnd);
	} else if(selection && selection.createRange) {
		var sel = selection.createRange();
		sel.text = txt;
		sel.moveStart('character', -mb_strlen(txt));
	} else {
		obj.value += txt;
	}
}

function insertAtCaret (textEl,	text){
	if(textEl.createTextRange && textEl.caretPos){
		var caretPos = textEl.caretPos;
		caretPos.text += caretPos.text.charAt(caretPos.text.length - 2)	== ' ' ? text +	' '	: text;
	} else if(textEl) {
		textEl.value +=	text;
	} else {
		textEl.value = text;
	}
}

function checkFocus() {
	var obj = typeof wysiwyg == 'undefined' || !wysiwyg ? $('postform').message : editwin;
	if(!obj.hasfocus) {
		obj.focus();
	}
}

function mb_strlen(str) {
	return (is_ie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
}

function insertSmiley(smilieid) {
	checkFocus();
	
	var src=imagedir + '/emote/em'+ smilieid +'.gif';
	var code='[em'+ smilieid +']';
	
	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.match( src )!=null) {
					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 $(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 titlecolor(colorCode,color) {

var target =document.getElementById("subject");
var tcolor =document.getElementById("tcolor");
target.style.color=color;
tcolor.value=colorCode;
	}

function boxActive(box,num) {
var menu = document.getElementById("box-"+ box);
var main = menu.parentNode;
var menudivs = menu.getElementsByTagName("DIV");
for (var i = 0; i < menudivs.length; i ++) {
menudivs[i].className = "boxmenu-off";
}
menudivs[num].className = "boxmenu-on";
var parent = menu.parentNode;
var childs = parent.childNodes;
var divs = [];
for (var i = 0, c = childs.length; i < c; i ++) {
if (childs[i].tagName == 'DIV') {
if (divs.length) childs[i].style.display = 'none';
divs[divs.length] = childs[i];
}
}
divs[num+1].style.display = 'block';

if (box ==1 ){
var target1=document.getElementById("annexmessage");
var target2 =document.getElementById("t"+num);
target1.innerHTML ="";
target1.style.display="none";
target2.style.display="block";
}
}

function postannex(a){
var target1 =document.getElementById(a);
var target2 =document.getElementById("annexmessage");
target1.style.display="none";
target2.style.display="block";
target2.innerHTML="Uploading...";
}

function loadannex(a){
var target =document.getElementById(a);
target.style.display="block";
}

/* */	  
function Dron_ScrollBox(reid)
{
 this.trun1 = document.getElementById(reid+'1');
 this.trun2 = document.getElementById(reid+'2');
 this.trun = document.getElementById(reid);

 this.trun2.innerHTML=this.trun1.innerHTML;

function Marquee(){

 this.trun1 = document.getElementById(reid+'1');
 this.trun2 = document.getElementById(reid+'2');
 this.trun = document.getElementById(reid);

if(this.trun2.offsetWidth-this.trun.scrollLeft<=0){
this.trun.scrollLeft-=this.trun1.offsetWidth;

}else{
this.trun.scrollLeft++;
}

}

var MyMar=setInterval(Marquee,10);

this.trun.onmouseover=function() {clearInterval(MyMar)}
this.trun.onmouseout=function() {MyMar=setInterval(Marquee,10)

}

} 


function MyImage(Img){ 
var image=new Image(); 
image.src=Img.src; 
width=600;
height=600;
if(image.width>width){
Img.height=image.height*width/image.width;
Img.width=width;
}
}
function MyImage2(Img){ 
var image=new Image(); 
image.src=Img.src; 
width=690;
height=600;
if(image.width>width){
Img.height=image.height*width/image.width;
Img.width=width;
}
}

function bbimg(o){
    var zoom=parseInt(o.style.zoom, 10)||100;
    zoom+=event.wheelDelta/12;
    if (zoom>0) 
        o.style.zoom=zoom+'%';
        return false;
}


function selectTag(showContent,id,selfObj){
	var tag = document.getElementById("tags"+ id).getElementsByTagName("li");
	var taglength = tag.length;
	for(i=0; i<taglength; i++){
		tag[i].className = "";
	}
	selfObj.parentNode.className = "selectTag";
	for(i=0; j=document.getElementById("tagContent"+ id +i); i++){
		j.style.display = "none";
	}
	document.getElementById(showContent).style.display = "block";
}  


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

function initCtrl(ctrlobj) {
	if(ctrlobj && !ctrlobj.initialized) {
		ctrlobj.initialized = true;
		ctrlobj.unselectable = true;

		ctrlobj.outfunc = typeof ctrlobj.onmouseout == 'function' ? ctrlobj.onmouseout : null;
		ctrlobj.onmouseout = function() {
			if(this.outfunc) this.outfunc();
			jsmenu[ctrlobj.id] = setTimeout('hideMenu()', timeout);
		}


		ctrlobj.overfunc = typeof ctrlobj.onmouseover == 'function' ? ctrlobj.onmouseover : null;
		ctrlobj.onmouseover = function(e) {
			doane(e);
			if(this.overfunc) this.overfunc();
			
				for(var id in jsmenu) {
					if(jsmenu[id]) clearTimeout(jsmenu[id]);
				}
			
		}
	}
}

function initMenu(ctrlid, menuobj) {
	if(menuobj && !menuobj.initialized) {
		menuobj.initialized = true;
		menuobj.ctrlkey = ctrlid;

		menuobj.style.position = 'absolute';
		
		menuobj.onmouseout = function() {
					jsmenu[ctrlid] = setTimeout('hideMenu()', timeout);
		}
		menuobj.onmouseover = function() {
					clearTimeout(jsmenu[ctrlid]);
				}
				
		menuobj.style.zIndex = 100;

	}
}


function showMenu(showid) {
	e = window.event ? window.event : showMenu.caller.arguments[0];
	var ctrlobj = $(showid);
	if(!ctrlobj) return;
	 

	
	var showobj = $(showid);
	var menuobj = $(showid + '_menu');
	if(!showobj|| !menuobj) return;

	hideMenu();


	initCtrl(ctrlobj);
	ctrlobjclassName = ctrlobj.className;
	ctrlobj.className += ' hover';
	initMenu(showid, menuobj);


	menuobj.style.display = '';
	if(!is_opera) {
		menuobj.style.clip = 'rect(auto, auto, auto, auto)';
	}

	setMenuPosition(showid);

	jsmenuobj = menuobj;
}

function setMenuPosition(showid) {
	var showobj = $(showid);
	var menuobj = $(showid + '_menu');
	//offset = 0;
	if(showobj) {
		showobj.pos = fetchOffset(showobj);
		showobj.X = showobj.pos['left'];
		showobj.Y = showobj.pos['top'];
		showobj.w = showobj.offsetWidth;
		showobj.h = showobj.offsetHeight;
		menuobj.w = menuobj.offsetWidth;
		menuobj.h = menuobj.offsetHeight;
		menuobj.style.left = (showobj.X + menuobj.w > document.body.clientWidth) && (showobj.X + showobj.w - menuobj.w >= 0) ? showobj.X + showobj.w - menuobj.w + 'px' : showobj.X + 'px';
		menuobj.style.top = ((showobj.Y + showobj.h + menuobj.h > document.documentElement.scrollTop + document.documentElement.clientHeight) && (showobj.Y - menuobj.h >= 0)) ? (showobj.Y - menuobj.h) + 'px' : showobj.Y + showobj.h + 'px';
		//debug ?
		if(menuobj.style.clip && !is_opera) {
			menuobj.style.clip = 'rect(auto, auto, auto, auto)';
		}
	}
}

function hideMenu() {

	if(jsmenuobj) {
		try {
			$(jsmenuobj.ctrlkey).className = ctrlobjclassName;
		} catch(e) {}
		clearTimeout(jsmenu[jsmenuobj.ctrlkey]);
		jsmenuobj.style.display = 'none';
		jsmenuobj = null;
	}
}

function fetchOffset(obj) {
	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;
	while((obj = obj.offsetParent) != null) {
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}
	return { 'left' : left_offset, 'top' : top_offset };
}
function getExpDate(days, hours, minutes) {

    var expDate = new Date( );

    if (typeof days == "number" && typeof hours == "number" && 

        typeof hours == "number") {

        expDate.setDate(expDate.getDate( ) + parseInt(days));

        expDate.setHours(expDate.getHours( ) + parseInt(hours));

        expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));

        return expDate.toGMTString( );

    }

}

//cookie
  
function getCookieVal(offset) {

    var endstr = document.cookie.indexOf (";", offset);

    if (endstr == -1) {

        endstr = document.cookie.length;

    }

    return unescape(document.cookie.substring(offset, endstr));

}

   

function getCookie(name) {

    var arg = name + "=";

    var alen = arg.length;

    var clen = document.cookie.length;

    var i = 0;

    while (i < clen) {

        var j = i + alen;

        if (document.cookie.substring(i, j) == arg) {

            return getCookieVal(j);

        }

        i = document.cookie.indexOf(" ", i) + 1;

        if (i == 0) break; 

    }

    return "";

}

   

function setCookie(name, value, expires, path, domain, secure) {

var expiresvalue='';
if (expires){
    var exp  = new Date(); 
        exp.setTime(exp.getTime() + expires*24*60*60*1000);
        expiresvalue = exp.toGMTString();
}
    document.cookie = name + "=" + escape (value) +

        ((expires) ? "; expires=" + expiresvalue : "") +

        ((path) ? "; path=" + path : "") +

        ((domain) ? "; domain=" + domain : "") +

        ((secure) ? "; secure" : "");

}

  
function deleteCookie(name,path,domain) {

    if (getCookie(name)) {

        document.cookie = name + "=" +

            ((path) ? "; path=" + path : "") +

            ((domain) ? "; domain=" + domain : "") +

            "; expires=Thu, 01-Jan-70 00:00:01 GMT";

    }

}

⌨️ 快捷键说明

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