lib/har/viewer/scripts/domplate/tabView.js

Summary

Maintainability
A
0 mins
Test Coverage
/* See license.txt for terms of usage */

define("domplate/tabView",["domplate/domplate","core/lib","core/trace"],function(Domplate,Lib,Trace){with(Domplate){var TabViewTempl=domplate({tag:TABLE({"class":"tabView",cellpadding:0,cellspacing:0,_repObject:"$tabView"},TBODY(TR({"class":"tabViewRow"},TD({"class":"tabViewCol",valign:"top"},TAG("$tabList",{tabView:"$tabView"}))))),tabList:DIV({"class":"tabViewBody",onclick:"$onClickTab"},DIV({"class":"$tabView.id\\Bar tabBar"}),DIV({"class":"$tabView.id\\Bodies tabBodies"})),tabHeaderTag:A({"class":"$tab.id\\Tab tab",view:"$tab.id",_repObject:"$tab"},"$tab.label"),tabBodyTag:DIV({"class":"tab$tab.id\\Body tabBody",_repObject:"$tab"}),hideTab:function(e){return!1},onClickTab:function(e){var t=Lib.fixEvent(e),n=this.getTabView(t.target);n.onClickTab(t)},getTabView:function(e){var t=Lib.getAncestorByClass(e,"tabView");return t.repObject}});function TabView(e){this.id=e,this.tabs=[],this.listeners=[],this.tabBarVisibility=!0}return TabView.prototype={appendTab:function(e){return this.tabs.push(e),e.tabView=this,e},removeTab:function(e){for(var t in this.tabs){var n=this.tabs[t];if(n.id==e){this.tabs.splice(t,1);break}}},getTab:function(e){for(var t in this.tabs){var n=this.tabs[t];if(n.id==e)return n}},selectTabByName:function(e){var t=Lib.getElementByClass(this.element,e+"Tab");t&&this.selectTab(t)},showTabBar:function(e){this.element?e?this.element.removeAttribute("hideTabBar"):this.element.setAttribute("hideTabBar","true"):this.tabBarVisibility=e},addListener:function(e){this.listeners.push(e)},removeListener:function(e){Lib.remove(this.listeners,e)},onClickTab:function(e){var t=Lib.getAncestorByClass(e.target,"tab");t&&this.selectTab(t)},selectTab:function(e){if(!Lib.hasClass(e,"tab"))return;if(Lib.hasClass(e,"selected")&&e._updated)return;var t=e.getAttribute("view");if(!t)return;var n=Lib.getAncestorByClass(e,"tabViewBody");n.selectedTab&&(n.selectedTab.removeAttribute("selected"),n.selectedBody.removeAttribute("selected"),Lib.removeClass(n.selectedTab,"selected"),Lib.removeClass(n.selectedBody,"selected"));var r=Lib.getElementByClass(n,"tab"+t+"Body");r||Trace.error("TabView.selectTab; Missing tab body",e),n.selectedTab=e,n.selectedBody=r,n.selectedTab.setAttribute("selected","true"),n.selectedBody.setAttribute("selected","true"),Lib.setClass(n.selectedBody,"selected"),Lib.setClass(n.selectedTab,"selected"),this.updateTabBody(n,t)},updateTabBody:function(e,t){var n=e.selectedTab.repObject;if(n._body._updated)return;n._body._updated=!0,n.bodyTag&&n.bodyTag.replace({tab:n},n._body),n&&n.onUpdateBody&&n.onUpdateBody(this,n._body);for(var r=0;r<this.listeners.length;r++){var i=this.listeners[r];i.onUpdateBody&&i.onUpdateBody(this,n._body)}},render:function(e){this.element=TabViewTempl.tag.replace({tabView:this},e,TabViewTempl),Lib.setClass(this.element,this.id),this.showTabBar(this.tabBarVisibility);for(var t in this.tabs){var n=this.tabs[t],r=n.tabHeaderTag?n.tabHeaderTag:TabViewTempl.tabHeaderTag,i=n.tabBodyTag?n.tabBodyTag:TabViewTempl.tabBodyTag;try{n._header=r.append({tab:n},Lib.$(e,"tabBar")),n._body=i.append({tab:n},Lib.$(e,"tabBodies"))}catch(s){Trace.exception("TabView.appendTab; Exception ",s)}}return this.element}},TabView.Tab=function(){},TabView.Tab.prototype={invalidate:function(){this._updated=!1},select:function(){this.tabView.selectTabByName(this.id)}},TabView}});