Login   Register  
PHP Classes
elePHPant
Icontem

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

Contents

Class file image Download
mixElements.append("tab");
"tab,heading,content".split(",").each(function (v){
	document.createElement(v);
});
mix.tab = function (elements){
	var tab;
	if (type(elements) == "undefined"){
		tab = $(document.createElement("tab"));
	}else{
		tab = $(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() == "tab" 
					&& this._mixInit !== true
					&& el.nodeName.toLowerCase() != "template");
					//node name is tab and has not been initialized
					//and it is not in template
		});
	}
	
	tab.bind("attrChange", function (){
		mix.tab.redraw(this);
	}).each(function (){
		this._mixInit = true;
	}).childrenTag("heading").bind("click", function (e){
		$(this.parentNode).attr("selected", $(this).parent().find("heading").index(this));
	}).end().redraw();
	
	$(window).resize(function (){
		tab.redraw();
	});
	return tab;
};
mix.tab.redraw = function (el){
	var selectedIdx = $(el).attr("selected");
	if (type(selectedIdx) != "string" && type(selectedIdx) != "number")
		selectedIdx = 0;
	else
		selectedIdx = selectedIdx.toInteger();
	$(el).childrenTag("content").hide().filter(function (idx){
		return idx == selectedIdx;
	}).show().end().end().childrenTag("heading").removeClass("selected").filter(function (idx){
		return idx == selectedIdx;
	}).addClass("selected");
};

mix.tab.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.tab.customAttrList = "selected".split(",");