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

📄 app.js

📁 ajax source code .
💻 JS
📖 第 1 页 / 共 5 页
字号:
		}

		// set sizes to images + update the urls
		var imgs = node.getElementsByTagName("img");
		var ln = imgs.length;
		for (var z=0; z<ln; z++) {
			imgs[z].onload = function() {
				this.style.width = this.currentStyle.width;
				this.style.height = this.currentStyle.height;
			}
			fixAttribute(imgs[z], "src");			
		}

		// remove the scripts
		var scripts = node.getElementsByTagName("script");
		var ln = scripts.length;
		for (var z=0; z<ln; z++) {
			scripts[z].removeNode(true);
		}
		
		// let's remove some ads + update the links
		var links = node.getElementsByTagName("a");
		var ln = links.length;
		for (var z=0; z<ln; z++) {
			/*if (links[z].getAttribute("href").indexOf("googleadservices")!=-1) {
				links[z].style.display = "none";
			} else if (links[z].getAttribute("href").indexOf("ads_by_google")!=-1) {
				links[z].style.display = "none";
			} else if (links[z].getAttribute("href").indexOf("feeds.gawker.com")!=-1) {
				links[z].style.display = "none";
			} else {*/
				var first = links[z].firstChild;
				if (first) {
					if (first.nodeType==1) {
						if (first.nodeName=="IMG" || first.nodeName=="img") {
							links[z].className = "noBottomLine";
						}
					}
				}
				fixAttribute(links[z], "href");
				links[z].setAttribute("target", "_blank");
			//}
		}
		
		var enclosures = itemNode.getElementsByTagName("enclosure");
		var ln = enclosures.length;
		for (var z=0; z<ln; z++) {
			var typ = enclosures[z].getAttribute("type");
			if (typ=="audio/mpeg" || typ=="" || typ=="enclosureType") {
				var file = enclosures[z].getAttribute("url");
				if (file.indexOf(".mp3")!=-1) {
					var div = document.createElement("div");
					div.className = "podcast";
					div.innerHTML = '<table cellpadding="0" cellspacing="0" style="float:left;margin-right:6px"><div class="listen"><div><div>'+App.Loc.listenPod+'</div></div></div></table>'+
									'<table cellpadding="0" cellspacing="0"><a href="'+file+'"><div class="download"><div><div>'+App.Loc.downloadPod+'</div></div></div></a></table>';
					applyPodcastEvents(div, file, nodeTitle.lastChild.firstChild.nodeValue);
					if (node.firstChild) {
						node.insertBefore(div, node.firstChild);
					} else {
						node.appendChild(div);
					}
				}
			}
		}

	}
	
	function displayContent(index) {
		var itemNode = data.moduleLocalData.items[index];
		var contentValue = '';
		
		var link = itemNode.getElementsByTagName("link")[0];
		if (link!=null) {
			link = (data.moduleLocalData.type == 1) ? link.getAttribute("href") : link.firstChild.nodeValue;
		} else {
			link = null;
		}
		
		if (data.moduleLocalData.type==1) { // atom
			var content = itemNode.getElementsByTagName("content")[0];
			var desc = itemNode.getElementsByTagName("summary")[0];
		} else { // rss
			var content = (Browser.isIE) ? itemNode.getElementsByTagName("content:encoded")[0] : itemNode.getElementsByTagName("encoded")[0];
			var desc = itemNode.getElementsByTagName("description")[0];
		}
		
		if (content && content.hasChildNodes()) {
			for (var n=content.firstChild; n!=null; n=n.nextSibling) {
				if (n.innerHTML) {
					contentValue += n.innerHTML;
				} else if (n.nodeValue) {
					contentValue += n.nodeValue;
				}
			}
		} else if (desc && desc.hasChildNodes()) {
			for (var n=desc.firstChild; n!=null; n=n.nextSibling) contentValue += n.nodeValue;
		}
		
		var titleDiv = document.createElement("div");
		titleDiv.className = "title";
		titleDiv.innerHTML = '<div class="moreLink"><a href="'+link+'" target="_blank">'+App.Loc.link+' ?</a></div><a href="'+link+'" target="_blank">'+getTitleValue(index)+'</a>';
			
		var contentDiv = document.createElement("div");
		contentDiv.className = "feedContent";
		contentDiv.innerHTML = contentValue;
		//contentDiv.appendChild(contentValue);
		
		cleanContent(contentDiv, titleDiv, itemNode);
		tdContent.firstChild.firstChild.appendChild(titleDiv);
		tdContent.firstChild.firstChild.appendChild(contentDiv);
	}

	function getTitleValue(index) {
		var itemNode = data.moduleLocalData.items[index];
		var title = itemNode.getElementsByTagName("title")[0];
		if (title.firstChild) {
			title = title.firstChild.nodeValue;
		} else {
			if (itemNode.getElementsByTagName("description")[0].firstChild) {
				title = itemNode.getElementsByTagName("description")[0].firstChild.nodeValue.substring(0,40)+"...";
			} else {
				title = '[...]';
			}
		}
		return title;
	}

	function headlineSelect(index) {
		var ln = headlinesBorderShape.childNodes.length;
		for (var z=0; z<ln; z++) {
			headlinesBorderShape.childNodes[z].setAttribute("selected", 0);
			headlinesBorderShape.childNodes[z].style.backgroundColor = "transparent";
		}
		tdContent.firstChild.firstChild.innerHTML = "";
		displayContent(index);
		tdContent.firstChild.scrollTop = 0;
		headlinesBorderShape.childNodes[index].setAttribute("selected", 1);
		headlinesBorderShape.childNodes[index].style.backgroundColor = "#D8FED2";		
	}
	
	function headlineSelectAll(index) {
		var ln = headlinesBorderShape.childNodes.length;		
		tdContent.firstChild.firstChild.innerHTML = "";
		for (var z=0; z<ln; z++) {
			headlinesBorderShape.childNodes[z].setAttribute("selected", 1);
			headlinesBorderShape.childNodes[z].style.backgroundColor = "#D8FED2";
			displayContent(z);
			var divSep = document.createElement("div");
			divSep.className = "postSeparator";
			if (z==(ln-1)) divSep.style.borderBottom = "1px solid #FFF";			
			tdContent.firstChild.firstChild.appendChild(divSep);
		}
		tdContent.firstChild.scrollTop = 0;
		
	}

	var headlinesBorderShape = document.createElement("div");
	headlinesBorderShape.id = "feedReaderHeadlinesFrame";
		
	var ln = data.moduleLocalData.items.length;	
	for (var z=0; z<ln; z++) {
		var itemNode = data.moduleLocalData.items[z];
		//var link = itemNode.getElementsByTagName("link")[0];
		
		var headlineDiv = document.createElement("div");
		headlineDiv.setAttribute("itemIndex", z);
		//headlineDiv.setAttribute("selected", 0);
		headlineDiv.className = "headline";
		
		headlineDiv.onmouseover = function() {
			this.style.backgroundColor = (this.getAttribute("selected")==0) ? "#EFF5FF" : "#CDF1C7";
		}
		headlineDiv.onmouseout = function() {
			this.style.backgroundColor = (this.getAttribute("selected")==0) ? "transparent" : "#D8FED2";
		}
		headlineDiv.onclick = function() {
			headlineSelect(this.getAttribute("itemIndex"));
		}		
		headlineDiv.innerHTML = getTitleValue(z);
		headlinesBorderShape.appendChild(headlineDiv);
	}
	
	headlineSelect(data.selectedItemIndex);
		
	tdHeadlines.appendChild(headlinesBorderShape);
	
	frame.appendChild(header);
	frame.appendChild(contentFrame);	
	readerFrame.appendChild(frame);

	div.innerHTML = "";
	div.appendChild(readerFrame);
	App.FeedReader.resize();

	setTimeout(App.FeedReader.resize, 1);
	setTimeout(App.FeedReader.resize, 100);

	window.onresize = function() {
		App.FeedReader.resize();
	}

}

// ========== REQUEST ====================================================================================================

var Request = new Object();

Request.send = function(url, method, callback, data) {	
	alert(url);
	var req;	
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.onreadystatechange = function() {
		if (req.readyState == 4) {// only if req shows "loaded"
			if (req.status < 400) {// only if "OK"
				(method=="POST") ? callback(req) : callback(req,data);
			} else {
				alert("There was a problem saving your changes :\n" + req.status+ "/" + req.statusText);
			}
		}
	}
	if (method=="POST") {
		req.open("POST", url, true);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		//req.setRequestHeader('Connection','close'); //STUPID 400 FF ERROR FIX
		req.send(data);
	} else {
		req.open("GET", url, true);
		req.send(null);
	}
	
	return req;
}

Request.sendPOST = function(url, data, callback) {
	Request.send(url, "POST", callback, data);
}
Request.sendGET = function(url, callback, args) {
	return Request.send(url, "GET", callback, args);
}

// ================ SERVER  SAVE ================================================================

App.moduleObjWaitingForId = [];

App.doResponseAction = function(mode, success, args) {

	function setModuleId(tempId, newId) {
		var ln = App.moduleObjWaitingForId.length;
		for (var z=0; z<ln; z++) {
			if (App.moduleObjWaitingForId[z].tempId==tempId) {
				var mod = App.moduleObjWaitingForId[z];
				mod.dataObj.id = newId;
				App.moduleObjWaitingForId.splice(z, 1);
				break;
			}
		}
		App.saveUserData('order');
		mod.loadContent(); // ici ou attendre le retour de l'enregistrement du nouveau layout ?
	}

	if (success) {
		switch(mode) {
			case 'module':
				break;
			case 'order':
				break;
			case 'collapseExpand':
				break;
			case 'close':
				break;
			case 'new':
				setModuleId(args.tempId, args.newId);
				break;
			case 'pageTitle':
				break;
		}
	} else {
		alert(App.Loc.errorSavingUserData);
	}
}

App.saveUserDataResponse = function(response) {
	//alert(response.responseText);
	eval('App.doResponseAction('+response.responseText+')');
	App.savingStatusElm.style.backgroundColor = "transparent";
}

App.saveUserData = function(mode, obj) {
	if (App.mode=='userPage') App.saveUserDataNow(mode, obj);
}

App.saveUserDataNow = function(mode, obj) {
	App.savingStatusElm.style.backgroundColor = "#F00";
	
	function getOrder() {
		var arr = [];
		for (var z=1; z<=3; z++) {
			var col = App.columnsObj["col"+z];
			var ln = col.childNodes.length;	
			var arr2 = [];
			for (var i=0; i<ln; i++) {
				var obj = col.childNodes[i].dataObj;
				if (obj.id!=null) arr2.push(obj.id);
			}
			arr.push(arr2.join(','));
		}
		return arr.join(":");
	}

	var data = '';
	switch(mode) {
		case 'module':
			var dataObjStr = '';
			for (var n in obj.data) {
				var value = obj.data[n];
				if (typeof(value)=="string") value = Utils.htmlEncode(value);
				dataObjStr += '&arrData['+n+']='+encodeURIComponent(value);
			}			
			data = 'id='+obj.id+'&title='+encodeURIComponent(Utils.htmlEncode(obj.title))+'&status='+obj.status+'&share='+obj.share+dataObjStr;
			break;
		case 'order':
			data = 'order='+getOrder();
			break;
		case 'collapseExpand' :
			data = 'status='+obj;
			break;
		case 'close':
			data = 'order='+getOrder()+'&id='+obj.id;
			break;
		case 'new':
			var dataObj = obj.dataObj;
			var dataObjStr = '';
			for (var n in dataObj.data) {
				var value = dataObj.data[n];
				if (typeof(value)=="string") value = Utils.htmlEncode(value);
				dataObjStr += '&arrData['+n+']='+encodeURIComponent(value);
			}
			var title = (dataObj.title==null) ? '' : encodeURIComponent(Utils.htmlEncode(dataObj.title));
			var moduleRndId = Math.random()*100000;
			data = 'moduleRndId='+moduleRndId+'&title='+title+'&status='+dataObj.status+'&name='+dataObj.moduleName+'&share='+dataObj.share+dataObjStr;
			obj.tempId = moduleRndId;
			App.moduleObjWaitingForId.push(obj);
			break;
		case 'pageTitle':
			data = 'title='+encodeURIComponent(obj);
			break;
	}
	Request.sendPOST('saveUserData.asp', 'mode='+mode+'&'+data, App.saveUserDataResponse);
}

// ========================================================================================

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;

⌨️ 快捷键说明

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