Search

2/11/2009

YUI tabview : get active index when change

// from cheetsheet
var tab = new YAHOO.widget.TabView('some-tab');
tab.addListener('activeTabChange', function(o){
var index = this.getTabIndex(o.newValue);
console.log(index);
})


var tabInit = function() {
var archiveTab = new YAHOO.widget.TabView('archive-tab');
var match = window.location.href.match(/type=([^&#]*)/);
var type = match ? match[1] : 'blog';

archiveTab.set('activeIndex',
YAHOO.lang.substitute('{' + type + '}', {
'blog':0, 'album':1, 'video':2
})
);

archiveTab.on('activeTabChange', function(o){
window.location.type = o.newValue.getElementsByTagName('a')[0].type;
});

}; // tabInit

沒有留言: