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

📄 elementcollection.js

📁 Phidget21.NET Ebox4300下的一个重要组件
💻 JS
字号:

	// a collection of elements whoose style can be changed based on the values of attributes

	function ElementCollection(parentId) {

		// get the tabbed region
		this.parent = document.getElementById(parentId);


		// get the children
		this.elements = new Array();
		if (this.parent.tagName == 'TABLE') {
			// special handling for tables
			var bodies = this.parent.tBodies;
			for(i=0; i<bodies.length; i++) {
				var rows = bodies[i].rows;
				for(j=0; j<rows.length; j++) {
					if (rows[j].nodeType == 1) this.elements.push(rows[j]);
				}
			}
			// this.elements = this.parent.tBodies[0].rows;
		} else {
			// all other cases
			var nodes = this.parent.childNodes;
			for(i=0; i<nodes.length; i++) {
				if (nodes[i].nodeType == 1) this.elements.push(nodes[i]);
			}
		}

	}

	ElementCollection.prototype.process = function(processFunction) {
		for(var i=0; i<this.elements.length; i++) {
			var element = this.elements[i];
			processFunction(element);
		}
	}

	ElementCollection.prototype.changeStyle = function(attributeName, attributeValue, styleName, styleValue) {
		for(var i=0; i<this.elements.length; i++) {
			var element = this.elements[i];
			var value = element.getAttribute(attributeName);
			if (value != null) {
				if (value == attributeValue) {
					element.style[styleName] = styleValue;
				}
			}
		}
	}


	ElementCollection.prototype.toggleStyle = function(attributeName, attributeValue, styleName, trueStyleValue, falseStyleValue) {
		for(var i=0; i<this.elements.length; i++) {
			var element = this.elements[i];
			if (element.nodeType != 1) continue;
			var value = element.getAttribute(attributeName);
			if (value == null) continue;

			if (value == attributeValue) {
				element.style[styleName] = trueStyleValue;
			} else {
				element.style[styleName] = falseStyleValue;
			}
		}
	}

	ElementCollection.prototype.toggleClass = function(attributeName, attributeValue, trueClass, falseClass) {
		for(var i=0; i<this.elements.length; i++) {
			var element = this.elements[i];
			if (element.nodeType != 1) continue;
			var value = element.getAttribute(attributeName);
			if (value == null) continue;

			if (value == attributeValue) {
				element.className = trueClass;
			} else {
				element.className = falseClass;
			}
		}
	}

	function useShowAttribute(element) {
		if (element == null) return;
		var value = element.getAttribute("show");
		if (value == null) return;
		if (value == "true") {
			element.style["display"] = "block";
		} else {
			element.style["display"] = "none";
		}
	}

⌨️ 快捷键说明

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