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

📄 javascript.js

📁 一款文件上传程序
💻 JS
字号:
/* 	All contents (c) Tuan Do (www.celerondude.com)
	If you use any of this, please leave the copyright intact.
*/
var is_ie = document.all;
var timer = false;
var icons_url = 'templates/default2/images/icons/';
function getObj(sId){return document.getElementById(sId);}
function checkIt(b,c){if(b){b.checked=!c;b.click();b.checked=c;}}
function showIt(sId,v){var x=getObj(sId);if(x)x.style.display=(v?'block':'none');}
function togView(sId){var el=getObj(sId);if(el){el.style.display=el.style.display=='none'?'':'none';}}
function checkAllBoxes(formObj,fieldName,chkVal){if(!formObj)return false;var checkBoxes=formObj.getElementsByTagName('input');for(var i=0;i<checkBoxes.length;i++){if(checkBoxes[i].name==fieldName&&!checkBoxes[i].disabled){checkBoxes[i].checked=chkVal;}}}
function countCheckedBoxes(formObj,fieldName){if(!formObj)return false;var checkBoxes=formObj.getElementsByTagName('input');var checkedBoxes=0;for(var i=0;i<checkBoxes.length;i++){checkedBoxes+=(checkBoxes[i].name==fieldName&&!checkBoxes[i].disabled&&checkBoxes[i].checked)?1:0;}return checkedBoxes;}
function pInt(oF){if(oF){oF.value=parseInt(oF.value);if(oF.value=='NaN'){oF.value=0;}}}
function pop(sURL){return!window.open(sURL);}
function go(url){if(url.substr(0,7)!='http://')url=base_url+url;window.location=url;return false;}
function getXMLHttpObject(){return (typeof XMLHttpRequest!='undefined')?new XMLHttpRequest():(typeof ActiveXObject!='undefined'?new ActiveXObject('Microsoft.XMLHTTP'):false);}
function xmlhttpGet(sURL,process,xml){sURL+=('&'+(Math.floor(Math.random()*10000000))); var xmlhttp=getXMLHttpObject();if(xmlhttp){xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){if(xmlhttp.status==200){process(xml?xmlhttp.responseXML:xmlhttp.responseText);}else{alert('Request Failed: '+xmlhttp.status);}}};xmlhttp.open('GET',sURL,true);xmlhttp.send(null);}else go(sURL);}
function xmlhttpPost(aPostData,sURL,process){sURL+=('&'+(Math.floor(Math.random()*10000000))); var xmlhttp=getXMLHttpObject();if(xmlhttp){var sPostData = '';for(var f in aPostData){sPostData+=((sPostData.length>0?'&':'')+f+'='+encodeURIComponent(aPostData[f]));}xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){if(xmlhttp.status==200){process(xmlhttp.responseText);}else{alert('Request Failed');}}};xmlhttp.open('POST',sURL,true);xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=UTF-8');xmlhttp.send(sPostData);}else alert('Your browser does not support XMLHttp. If you are on Internet Explorer, enable ActiveX.');}
function htmlspecialchars(s){var t={'&':'&amp;','"':'&quot;',"'":'&#039;','<':'&lt;','>':'&gt;'};for(var k in t){rx=new RegExp(k,'g');s=s.replace(rx,t[k]);}return s;}
function addslashes(s){s=s.replace(/'/gi,"&#039;");s=s.replace(/"/gi,"&quot;");return s;}
function alternateRowColor(obj,el,c1,c2){if(obj){var els=obj.getElementsByTagName(el);var j=0;for(var i=0;i<els.length;i++)if(!els[i].getAttribute('skip_alternate')){els[i].style.backgroundColor=(j&1?c2:c1);j++;}}}
function basename(s){var p=-1;for(var i=0;i<s.length;i++){if( s.charAt(i)=='\\'||s.charAt(i)=='/')p=i;}if(p<0)return s;return s.substr(p+1,s.length-p);}
function dirname(s){var p=-1;for(var i=0;i<s.length;i++){if( s.charAt(i)=='\\'||s.charAt(i)=='/')p=i;}if(p<0)return s;return s.substr(0,p+1);}
function togImage(im,n){if(!im)return false;var alt=im.getAttribute('alternateImage');if(!alt)alt=dirname(im.src)+'/'+n;var cur=im.src;im.src=alt;im.setAttribute('alternateImage',cur);}
function get_extension(n){n=n.substr(n.lastIndexOf('.')+1);return n.toLowerCase();}
function str_slice(s,l){if(s.length>l)return s.substr(0,l/2)+'...'+s.substr(s.length-(l/2));return s;}
function setStyles(obj,styles){if(!obj)return false;for(var k in styles)obj.style[k]=styles[k];}
function Timer(){this.t=false;}
Timer.prototype.start=function(f,ms){this.t=window.setTimeout(f,ms);}
Timer.prototype.stop=function(){if(this.t)window.clearTimeout(this.t);}


function Bubble(t,o,s)
{
	this.t = t;
	this.o = o;
	this.b = false;
	this.s = typeof s != 'undefined' ? s : 0;
}

Bubble.prototype.display = function (s)
{
	if ( this.b )
	{
		this.b.innerHTML = s;
		this.b.style.marginTop =  -(this.b.offsetHeight+this.o+4)+'px';
		return true;
	}
	this.b = document.createElement ( 'span' );
	if(!this.b)return false;
	obj=this;
	this.b.onclick=function(){obj.hide();}

	var styles =
	{
		'backgroundColor' : '#FBFFDF',
		'border' : '1px solid #505050',
		'padding' : '5px',
		'position' : 'absolute',
		'lineHeight' : '1.4em',
		'MozBorderRadius' : '4px'
	};
	if ( this.s > 0 ) styles['width'] = this.s + 'px';

	setStyles ( this.b, styles );
	this.b.innerHTML = s;
	this.t.parentNode.insertBefore(this.b,this.t);
	this.b.style.marginTop =  -(this.b.clientHeight+this.o+4)+'px';
}

Bubble.prototype.hide = function()
{
	if(!this.b)return true;
	this.b.style.display='none';
	//deleteNode(this.b);
	this.b=false;
}

function get_icon ( extension )
{
    var icons = {
		'default':'file.gif',
		// images
		'jpg'	: 'images.gif',
		'jpeg'	: 'images.gif',
		'png'	: 'png.gif',
		'gif'	: 'gif.gif',
		// media
		'avi'	: 'video.gif',
		'wmv'	: 'video.gif',
		'mpeg'	: 'video2.gif',
		'mpg'	: 'video2.gif',
		'mov'	: 'quicktime.gif',
		'mp3'	: 'mp3.gif',
		// Archives
		'zip'	: 'zip.gif',
		'rar'	: 'zip.gif',
		'tar'	: 'zip.gif',
		// documents
		'pdf'	: 'acrobat.gif',
		'ppt'	: 'powerpoint.gif',
		'txt'	: 'text.gif',
		'doc'	: 'word.gif',
		'xls'	: 'excel.gif'
	}
    return icons[extension] ? icons[extension] : icons['default'];
}

function adjustRatio ( event, current, target, ratio, maxVal )
{
	if ( current.value != '' ) current.value = parseInt ( current.value );
	if ( current.value == 'NaN' ) current.value = 0;
	if ( current.value > maxVal ) current.value = maxVal;
	if ( current.value < 0 ) current.value = 0;
	target.value = Math.ceil ( current.value / ratio );
}

function copyTextArea ( id )
{
	var field = getObj ( id );
	if ( field )
	{
		if ( is_ie ) field.createTextRange ( ).execCommand ( 'copy' );
		else alert ( 'Sorry, this feature is only enabled for Internet Explorer at the moment. Select the text and press Ctrl+C to copy and Ctrl+V to paste.' );
	}
}

function help ( str )
{
	var x = getObj ( 'message_content' );
	if(!x)return false;
	x.innerHTML = str.replace(/\n/g,'<br />');
	showIt ( 'message', true );
}

function uplAlert ( str )
{
	var alert_box = getObj ( 'alert_box' );
	if ( !alert_box ) var alert_box = document.createElement ( 'div' );
	alert_box.id = 'alert_box';
	alert_box.innerHTML = '<h1>Oops!</h1>' +
	'<p><img src="templates/default2/images/exclamation.gif" alt="" class="img1" /> ' + str + '</p>';
	document.body.appendChild ( alert_box );
}


function deleteNode ( oNode )
{
	return oNode.parentNode.removeChild ( oNode );
}

function togFolderPublic(oImage,sAltImage,togURL)
{
	if ( togURL.substr ( 0, 7 ) != 'http://' )
	{
		togURL = base_url + togURL;
	}
	var func = function ( result )
	{
		if ( result == 'OK' )
		{
			togImage ( oImage, sAltImage );
		}
	}
	xmlhttpGet(togURL,func);
}

function quickUpdateDesc ( folder, description, container, maxLength )
{
	var _this = this;
	this.d = description;
	this.c = container;
	this.p = container.parentNode;
	this.fd = folder;
	this.l = ( maxLength ? maxLength : 100 );
	this.o = container.style.display;
	this.c.style.cursor = 'text';
	this.c.onmouseover = function ( ) { this.style.backgroundColor = '#FFFFE6'; }
	this.c.onmouseout = function ( ) { this.style.backgroundColor = ''; }
	this.c.onclick = function ( ) { _this.show(); }

	this.show = function ( )
	{
		var _this = this;
		this.w = document.createElement ( 'span' );
		this.w.id = 'qspan';
		this.w.className = 'qinput';
		this.w.innerHTML = '<input type="text" id="qfield" value="'+this.d+'" size="'+( this.d.length > this.l ? this.l : ( this.d.length > 0 ? this.d.length: 10 ) )+'" maxlength="255" />';
		this.c.parentNode.insertBefore ( this.w, this.c );
		deleteNode(this.c);

		var f = getObj('qfield');
		f.onblur = function ( ) { _this.up(); return true; }
		f.onkeyup = function ( e )
		{
			if ( typeof e == 'undefined' ) e = window.event;
			if ( e.keyCode == 27 ) { _this.up(); return true; }
			else if ( e.keyCode == 13 ) { this.blur(); return true; }
			else if ( this.value.length < _this.l ) this.size = this.value.length + 1;
			return true;
		}
		f.select();
		f.focus();
		this.f = f;
	}

	this.h = function ( )
	{
		this.p.insertBefore(this.c,this.w);
		this.p.removeChild ( this.w );
		this.c.style.backgroundColor = '';
		this.c.innerHTML = this.d == '' ? 'No description' : htmlspecialchars ( this.d.substr ( 0, this.l ) );
	}

	this.up = function ( )
	{
		var _this = this;
		var process = function ( response ) { _this.h(); }
		if ( this.f.value != this.d )
		{
			this.d = this.f.value;
			xmlhttpGet(base_url+'folders.php?action=update_description&folder='+this.fd+'&description='+encodeURIComponent(this.f.value), process );
		}
		else this.h();
	}
}

⌨️ 快捷键说明

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