lib/har/viewer/scripts/tabs/previewTab.js

Summary

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

define("tabs/previewTab",["domplate/domplate","domplate/tabView","core/lib","i18n!nls/previewTab","domplate/toolbar","tabs/pageTimeline","tabs/harStats","preview/pageList","core/cookies","preview/validationError","downloadify/js/swfobject","downloadify/src/downloadify"],function(Domplate,TabView,Lib,Strings,Toolbar,Timeline,Stats,PageList,Cookies,ValidationError){with(Domplate){function PreviewTab(e){this.model=e,this.toolbar=new Toolbar,this.timeline=new Timeline,this.stats=new Stats(e,this.timeline),this.toolbar.addButtons(this.getToolbarButtons()),ValidationError.addListener(this)}return PreviewTab.prototype=Lib.extend(TabView.Tab.prototype,{id:"Preview",label:Strings.previewTabLabel,tabBodyTag:DIV({"class":"tab$tab.id\\Body tabBody",_repObject:"$tab"},DIV({"class":"previewToolbar"}),DIV({"class":"previewTimeline"}),DIV({"class":"previewStats"}),DIV({"class":"previewList"})),onUpdateBody:function(e,t){this.toolbar.render(Lib.$(t,"previewToolbar")),this.stats.render(Lib.$(t,"previewStats")),this.timeline.render(Lib.$(t,"previewTimeline"));var n=this.model.input;n&&Cookies.getCookie("timeline")=="true"&&this.onTimeline(!1),n&&Cookies.getCookie("stats")=="true"&&this.onStats(!1),this.updateDownloadifyButton()},updateDownloadifyButton:function(){var e=this.model;$(".harDownloadButton").downloadify({filename:function(){return"netData.har"},data:function(){return e?e.toJSON():""},onComplete:function(){},onCancel:function(){},onError:function(){alert(Strings.downloadError)},swf:"scripts/downloadify/media/downloadify.swf",downloadImage:"css/images/download-sprites.png",width:16,height:16,transparent:!0,append:!1})},getToolbarButtons:function(){var e=[{id:"showTimeline",label:Strings.showTimelineButton,tooltiptext:Strings.showTimelineTooltip,command:Lib.bindFixed(this.onTimeline,this,!0)},{id:"showStats",label:Strings.showStatsButton,tooltiptext:Strings.showStatsTooltip,command:Lib.bindFixed(this.onStats,this,!0)},{id:"clear",label:Strings.clearButton,tooltiptext:Strings.clearTooltip,command:Lib.bindFixed(this.onClear,this)}];return e.push({id:"download",tooltiptext:Strings.downloadTooltip,className:"harDownloadButton"}),e},onTimeline:function(e){var t=this.toolbar.getButton("showTimeline");if(!t)return;this.timeline.toggle(e);var n=this.timeline.isVisible();t.label=Strings[n?"hideTimelineButton":"showTimelineButton"],this.toolbar.render(),this.updateDownloadifyButton(),Cookies.setCookie("timeline",n)},onStats:function(e){var t=this.toolbar.getButton("showStats");if(!t)return;this.stats.toggle(e);var n=this.stats.isVisible();t.label=Strings[n?"hideStatsButton":"showStatsButton"],this.toolbar.render(),this.updateDownloadifyButton(),Cookies.setCookie("stats",n)},onClear:function(){var e=document.location.href,t=e.indexOf("?");document.location=e.substr(0,t)},showStats:function(e){Cookies.setCookie("stats",e)},showTimeline:function(e){Cookies.setCookie("timeline",e)},append:function(e){var t=new PageList(e);t.append(Lib.$(this._body,"previewList")),this.timeline.append(e),t.addListener(this)},appendError:function(e){ValidationError.appendError(e,Lib.$(this._body,"previewList"))},addPageTiming:function(e){PageList.prototype.pageTimings.push(e)},getMenuItems:function(e,t,n){if(!n)return;e.push("-"),e.push({label:Strings.menuShowHARSource,command:Lib.bind(this.showHARSource,this,t,n)})},showHARSource:function(e,t,n){var r=this.tabView.getTab("DOM");if(!r)return;r.select("DOM"),r.highlightFile(t,n)}}),PreviewTab}});