/* * Fabtabulous! Simple tabs using Prototype * http://tetlaw.id.au/view/blog/fabtabulous-simple-tabs-using-prototype/ * Andrew Tetlaw * version 1.1 2006-05-06 * http://creativecommons.org/licenses/by-sa/2.5/ */ var Fabtabs = Class.create(); Fabtabs.prototype = { initialize : function(element) { this.element = $(element); var options = Object.extend({}, arguments[1] || {}); this.menu = $A(this.element.getElementsByTagName('a')); this.getInitialTab(); this.menu.each(this.setupTab.bind(this)); }, setupTab : function(elm) { Event.observe(elm,'click',this.activate.bindAsEventListener(this),false) }, activate : function(ev) { var elm = Event.findElement(ev, "a"); Event.stop(ev); this.menu.without(elm).each(this.hide.bind(this)); this.show(elm); }, hide : function(elm) { $(elm).up().removeClassName('selected'); helm=$(this.tabID(elm)); if(helm!=null) { helm.removeClassName('active'); } }, show : function(elm) { $(elm).up().addClassName('selected'); helm=$(this.tabID(elm)); if(helm!=null) { helm.addClassName('active'); }else{ //getInitialTab может вызвать переход по реальной ссылке if(!arguments[1]) { window.location=elm.href } } }, tabID : function(elm) { ht=elm.href.match(/#(\w.+)/); if(ht!=null) { return ht[1]; }else{return;} }, getInitialTab : function() { selected=this.element.getElementsBySelector('li.selected'); if(selected[0]!=null){ this.show(selected[0].down(),true); } } } Event.observe(window,'load',function(){ new Fabtabs('mainmenu'); },false);