final Console console = Y.newConsole(ConsoleConfig.create() );
console.render();
final HistoryBase history = Y.newHistoryHash();
final TabView tb = Y.newTabView(TabViewConfig.create(new TabConfig[]{
TabConfig.create().label("tab1").content("<p>11111111111 foo content</p>"),
TabConfig.create().label("tab2").content("<p>2222222222222222<b>Hello</b>foo <i>content</i></p>"),
TabConfig.create().label("tab3").content("<p>3333333333333<b>ben parker</b>foo <i>holla dooba do</i></p>"),
}));
tb.render(parent);
tb.after("selectionChange", new EventCallback<TabViewEvent>() {
@Override
public void call(TabViewEvent e) {
/* note e.newVal is the selected child widget - we cast directly.
* @see http://yuilibrary.com/yui/docs/api/classes/WidgetParent.html#attr_selection
*/
Widget selChild = e.newValObj().cast();
int newTabIndex = selChild.getInt("index");
console.log("tabview selectionChange: "+newTabIndex);
history.addValue("tab", newTabIndex==0 ? null : newTabIndex+"");
}
});
tb.selectChild(parseInt(history.get("tab"), 0));
Y.on("history:change", new EventCallback<HistoryEvent>() {
@Override
public void call(HistoryEvent e) {
// Ignore changes we make ourselves, since we don't need
// to update the selection state for those. We're only
// interested in outside changes, such as the ones generated
// when the user clicks the browser's back or forward buttons.
if(e.src().equals(Y.HistoryHash().SRC_HASH())) {
if(e.changed().objGetObj("tab")!=null) {
//e.changed.tab.newVal is a string containing the tab index
int i = parseInt(e.changed().objGetObj("tab").objGetString("newVal"), 0);
tb.selectChild(i);
}
else if(e.removed().objGetString("tab")!=null) {
// The tab selection was removed in the new state, so
// select the first tab by default.
tb.selectChild(0);
}
else {
}
}
}