Login   Register  
PHP Classes
elePHPant
Icontem

File: js/1mix.details.js

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alex Lau  >  Mix2ool  >  js/1mix.details.js  >  Download  
File: js/1mix.details.js
Role: Auxiliary data
Content type: text/plain
Description: The details component
Class: Mix2ool
Web development framework integrated with jQuery
Author: By
Last change:
Date: 2009-09-02 16:57
Size: 1,692 bytes
 

Contents

Class file image Download
mixElements.append("details");
document.createElement("details");
mixElements.append("mixlegend");
document.createElement("mixlegend");
mix.details = function (elements){
	var details;
	if (type(elements) == "undefined"){
		details = $(document.createElement("details"));
	}else{
		details = $(elements).filter(function (){
			var el = this.parentNode;
			var inTemplate = false;
			while (el.nodeType == 1 && el.nodeName.toLowerCase() != "html" && el.nodeName.toLowerCase() != "template")
				el = el.parentNode;
			return (("" + this.nodeName).toLowerCase() == "details" 
					&& this._mixInit !== true
					&& el.nodeName.toLowerCase() != "template");
					//node name is details and has not been initialized
		});
	}
	
	
	details.each(function (){
		this._mixInit = true;
	}).find("mixlegend").bind("click", function (){
		var opened = ($(this).parent().attr("open") == "open");
		$(this).parent().attr("open", opened ? "" : "open");
	}).end().redraw();
	$(window).resize(function (){
		details.redraw();
	});
	return details;
};
mix.details.redraw = function (el){
	if ($(el).attr("open") == "open"){
		$(el).children(":first").addClass("open").end().children(":not(:first)").show().children().redraw();
	}else{
		$(el).children(":first").removeClass("open").end().children(":not(:first)").hide();
	}
};
mix.details.attr = function (el, name, value){
	if (type(value) == "undefined"){ //getter
		if (name == "open")
			return el.getAttribute("open");
		return;
	}
	
	el.setAttribute(name, value);
	$(el).trigger("attrChange", [name, value]);
	mix.details.redraw(el);
	
	return value;
};
mix.details.customAttrList = "open".split(",");