1/* 2 * Fabtabulous! Simple tabs using Prototype 3 * http://tetlaw.id.au/view/blog/fabtabulous-simple-tabs-using-prototype/ 4 * Andrew Tetlaw 5 * version 1.1 2006-05-06 6 * http://creativecommons.org/licenses/by-sa/2.5/ 7 */ 8 9if (typeof Class != "undefined"){ /* lukas: issue 40 */ 10 var Fabtabs = Class.create(); 11 12 Fabtabs.prototype = { 13 initialize : function(element) { 14 this.element = $(element); 15 var options = Object.extend({}, arguments[1] || {}); 16 17 if(this.element){ /* lukas: issue 40 */ 18 this.menu = $A(this.element.getElementsByTagName('a')); 19 this.show(this.getInitialTab()); 20 this.menu.each(this.setupTab.bind(this)); 21 } 22 23 }, 24 setupTab : function(elm) { 25 Event.observe(elm,'click',this.activate.bindAsEventListener(this),false) 26 }, 27 activate : function(ev) { 28 var elm = Event.findElement(ev, "a"); 29 Event.stop(ev); 30 this.show(elm); 31 this.menu.without(elm).each(this.hide.bind(this)); 32 }, 33 hide : function(elm) { 34 $(elm).removeClassName('active-tab'); 35 $(this.tabID(elm)).removeClassName('active-tab-body'); 36 }, 37 show : function(elm) { 38 $(elm).addClassName('active-tab'); 39 $(this.tabID(elm)).addClassName('active-tab-body'); 40 41 }, 42 tabID : function(elm) { 43 return elm.href.match(/#(\w.+)/)[1]; 44 }, 45 getInitialTab : function() { 46 if(document.location.href.match(/#(\w.+)/)) { 47 var loc = RegExp.$1; 48 var elm = this.menu.find(function(value) { return value.href.match(/#(\w.+)/)[1] == loc; }); 49 return elm || this.menu.first(); 50 } else { 51 return this.menu.first(); 52 } 53 } 54 } 55}