Login   Register  
PHP Classes
elePHPant
Icontem

File: css/1mix.accordion.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  >  css/1mix.accordion.js  >  Download  
File: css/1mix.accordion.js
Role: Auxiliary data
Content type: text/plain
Description: The accordion component
Class: Mix2ool
Web development framework integrated with jQuery
Author: By
Last change:
Date: 2009-09-02 16:55
Size: 2,114 bytes
 

Contents

Class file image Download
mixElements.append("accordion");
"accordion,heading,content".split(",").each(function (v){
	document.createElement(v);
});
mix.accordion = function (elements){
	var accordion;
	if (type(elements) == "undefined"){
		accordion = $(document.createElement("accordion"));
	}else{
		accordion = $(elements).filter(function (){
			var el = this.parentNode;
			while (el.nodeType == 1 && el.nodeName.toLowerCase() != "html" && el.nodeName.toLowerCase() != "template")
				el = el.parentNode;
			return (("" + this.nodeName).toLowerCase() == "accordion" 
					&& this._mixInit !== true
					&& el.nodeName.toLowerCase() != "template");
					//node name is accordion and has not been initialized
					//and it is not in template
		});
	}
	accordion.bind("attrChange", function (){
		mix.accordion.redraw(this);
	}).each(function (){
		this._mixInit = true;
	}).find("heading").bind("click", function (e){
		$(this.parentNode).attr("selected", $(this).parent().find("heading").index(this));
	}).end().redraw();
	
	$(window).resize(function (){
		accordion.redraw();
	});
	return accordion;
};
mix.accordion.redraw = function (el){
	var selectedIdx = $(el).attr("selected");
	if (type(selectedIdx) != "string" && type(selectedIdx) != "number")
		selectedIdx = 0;
	else
		selectedIdx = selectedIdx.toInteger();
	var currSelect = $(el).find("heading").index($(el).find("heading.selected"));
	if (currSelect == selectedIdx)
		return;
	$(el).find("content").slideUp().filter(function (idx){
		return idx == selectedIdx;
	}).slideDown().end().end().find("heading").removeClass("selected").filter(function (idx){
		return idx == selectedIdx;
	}).addClass("selected");
};

mix.accordion.attr = function (el, name, value){
	if (type(value) == "undefined"){ //getter
		switch (name){
			case "selected":
				return el.getAttribute(name);
			break;
		}
		return;
	}
	
	switch (name){
		case "selected":
			el.setAttribute(name, value);
			$(el).trigger("attrChange", [name, value]);
		break;
	}
	
	return value;
};
mix.accordion.customAttrList = "selected".split(",");