lib/har/viewer/scripts/preview/requestBody.js in har-0.0.9 vs lib/har/viewer/scripts/preview/requestBody.js in har-0.1.0

- old
+ new

@@ -1,11 +2 @@ -require.def("preview/requestBody",["domplate/domplate","i18n!nls/requestBody","core/lib","domplate/tabView","syntax-highlighter/shCore"],function(h,e,d,i,o){with(h){h=function(){};h.prototype=domplate({render:function(a,b){var c=new i("requestBody");c.appendTab(new g(b));b.request.queryString&&b.request.queryString.length&&c.appendTab(new j(b));b.request.postData&&c.appendTab(new k(b,b.request.method));b.response.content.size>0&&c.appendTab(new l(b));this.showCache(b)&&c.appendTab(new m(b));this.showHtml(b)&& -c.appendTab(new n(b));a=c.render(a);c.selectTabByName("Headers");return a},showCache:function(a){if(!a.cache)return false;if(!a.cache.afterRequest)return false;if(a.category=="image")return false;return true},showHtml:function(a){return a.response.content.mimeType=="text/html"||a.mimeType=="application/xhtml+xml"}});var g=function(a){this.file=a};g.prototype=domplate(i.Tab.prototype,{id:"Headers",label:e.Headers,bodyTag:TABLE({"class":"netInfoHeadersText netInfoText netInfoHeadersTable",cellpadding:0, -cellspacing:0},TBODY(TR({"class":"netInfoResponseHeadersTitle"},TD({colspan:2},DIV({"class":"netInfoHeadersGroup"},e.ResponseHeaders))),TR({"class":"netInfoRequestHeadersTitle"},TD({colspan:2},DIV({"class":"netInfoHeadersGroup"},e.RequestHeaders))))),headerDataTag:FOR("param","$headers",TR(TD({"class":"netInfoParamName"},"$param.name"),TD({"class":"netInfoParamValue"},PRE("$param|getParamValue")))),getParamValue:function(a){return d.wrapText(a.value,true)},onUpdateBody:function(a,b){this.file.response.headers&& -this.insertHeaderRows(b,this.file.response.headers,"Headers","ResponseHeaders");this.file.request.headers&&this.insertHeaderRows(b,this.file.request.headers,"Headers","RequestHeaders")},insertHeaderRows:function(a,b,c,f){c=d.getElementByClass(a,"netInfo"+c+"Table");f=d.getElementByClass(c,"netInfo"+f+"Title");if(b.length){this.headerDataTag.insertRows({headers:b},f?f:a);d.removeClass(f,"collapsed")}else d.setClass(f,"collapsed")}});var l=function(a){this.file=a};l.prototype=domplate(i.Tab.prototype, -{id:"Response",label:e.Response,bodyTag:DIV({"class":"netInfoResponseText netInfoText"},PRE({"class":"javascript:nocontrols:nogutter:",name:"code"})),onUpdateBody:function(a,b){a=d.getElementByClass(b,"netInfoResponseText");if(this.file.category=="image"){d.clearNode(a);b=b.ownerDocument.createElement("img");b.src=this.file.href;a.appendChild(b,a)}else{d.clearNode(a.firstChild);b=this.file.response.content.text;var c=this.file.response.content.mimeType;if(c=="application/javascript"||c=="text/javascript"|| -c=="application/x-javascript"||c=="text/ecmascript"||c=="application/ecmascript"){a.firstChild.innerHTML=b;o.SyntaxHighlighter.HighlightAll(a.firstChild)}else d.insertWrappedText(b,a.firstChild)}}});var j=function(a){this.file=a};j.prototype=domplate(g.prototype,{id:"Params",label:e.URLParameters,bodyTag:TABLE({"class":"netInfoParamsText netInfoText netInfoParamsTable",cellpadding:0,cellspacing:0},TBODY()),onUpdateBody:function(a,b){this.file.request.queryString&&this.insertHeaderRows(d.getElementByClass(b, -"netInfoParamsText"),this.file.request.queryString,"Params")}});var k=function(a,b){b=b.charAt(0).toUpperCase()+b.slice(1).toLowerCase();this.file=a;this.id=b;this.label=e[b]};k.prototype=domplate(g.prototype,{bodyTag:DIV({"class":"netInfo$tab.id\\Text netInfoText"},TABLE({"class":"netInfo$tab.id\\Table",cellpadding:0,cellspacing:0},TBODY())),onUpdateBody:function(a,b){if(a=this.file.request.postData){b=d.getElementByClass(b,"netInfo"+this.id+"Text");a.mimeType=="application/x-www-form-urlencoded"? -this.insertHeaderRows(b,a.params,this.id):d.insertWrappedText(a.text,b)}}});(function(a){this.file=a}).prototype=domplate(g.prototype,{id:"Cookies",label:e.Cookies,bodyTag:DIV({"class":"netInfoCookiesText netInfoText"},TABLE({"class":"netInfoCookiesTable",cellpadding:0,cellspacing:0},TBODY(TR({"class":"netInfoResponseCookiesTitle"},TD({colspan:2},DIV({"class":"netInfoCookiesGroup"},e.ResponseCookies))),TR({"class":"netInfoRequestCookiesTitle"},TD({colspan:2},DIV({"class":"netInfoCookiesGroup"},e.RequestCookies)))))), -onUpdateBody:function(a,b){if(file.response.cookies){a=d.getElementByClass(b,"netInfoParamsText");this.insertHeaderRows(a,file.response.cookies,"Cookies","ResponseCookies")}if(file.request.cookies){a=d.getElementByClass(b,"netInfoParamsText");this.insertHeaderRows(a,file.request.cookies,"Cookies","RequestCookies")}}});var m=function(a){this.file=a};m.prototype=domplate(g.prototype,{id:"Cache",label:e.Cache,bodyTag:DIV({"class":"netInfoCacheText netInfoText"},TABLE({"class":"netInfoCacheTable",cellpadding:0, -cellspacing:0},TBODY())),onUpdateBody:function(a,b){if(this.file.cache&&this.file.cache.afterRequest){a=this.file.cache.afterRequest;var c=[];for(var f in a)c.push({name:f,value:a[f]});this.insertHeaderRows(b,c,"Cache")}}});var n=function(a){this.file=a};n.prototype=domplate(g.prototype,{id:"HTML",label:e.HTML,bodyTag:DIV({"class":"netInfoHtmlText netInfoText"},IFRAME({"class":"netInfoHtmlPreview"})),onUpdateBody:function(a,b){d.getElementByClass(b,"netInfoHtmlPreview").contentWindow.document.body.innerHTML= -this.file.response.content.text}});return h}}); +require.def("preview/requestBody",["domplate/domplate","i18n!nls/requestBody","core/lib","core/cookies","domplate/tabView","core/dragdrop","syntax-highlighter/shCore"],function(Domplate,Strings,Lib,Cookies,TabView,DragDrop,dp){with(Domplate){function RequestBody(){}RequestBody.prototype=domplate({render:function(a,b){var c=new TabView("requestBody");b.response.headers.length>0&&c.appendTab(new HeadersTab(b)),b.request.queryString&&b.request.queryString.length&&c.appendTab(new ParamsTab(b)),b.request.postData&&c.appendTab(new SentDataTab(b,b.request.method)),b.response.content.text&&b.response.content.text.length>0&&c.appendTab(new ResponseTab(b)),this.showCache(b)&&c.appendTab(new CacheTab(b)),this.showHtml(b)&&c.appendTab(new HtmlTab(b)),this.showDataURL(b)&&c.appendTab(new DataURLTab(b));var d=c.render(a);c.tabs.length>0&&c.selectTabByName(c.tabs[0].id);return d},showCache:function(a){if(!a.cache)return!1;if(!a.cache.afterRequest)return!1;if(a.category=="image")return!1;return!0},showHtml:function(a){return a.response.content.mimeType=="text/html"||a.mimeType=="application/xhtml+xml"},showDataURL:function(a){return a.request.url.indexOf("data:")==0}});function HeadersTab(a){this.file=a}HeadersTab.prototype=domplate(TabView.Tab.prototype,{id:"Headers",label:Strings.Headers,bodyTag:TABLE({"class":"netInfoHeadersText netInfoText netInfoHeadersTable",cellpadding:0,cellspacing:0},TBODY(TR({"class":"netInfoResponseHeadersTitle"},TD({colspan:2},DIV({"class":"netInfoHeadersGroup"},Strings.ResponseHeaders))),TR({"class":"netInfoRequestHeadersTitle"},TD({colspan:2},DIV({"class":"netInfoHeadersGroup"},Strings.RequestHeaders))))),headerDataTag:FOR("param","$headers",TR(TD({"class":"netInfoParamName"},"$param.name"),TD({"class":"netInfoParamValue"},PRE("$param|getParamValue")))),getParamValue:function(a){return Lib.wrapText(a.value,!0)},onUpdateBody:function(a,b){this.file.response.headers&&this.insertHeaderRows(b,this.file.response.headers,"Headers","ResponseHeaders"),this.file.request.headers&&this.insertHeaderRows(b,this.file.request.headers,"Headers","RequestHeaders")},insertHeaderRows:function(a,b,c,d){var e=Lib.getElementByClass(a,"netInfo"+c+"Table"),f=Lib.getElementByClass(e,"netInfo"+d+"Title");b.length?(this.headerDataTag.insertRows({headers:b},f?f:a),Lib.removeClass(f,"collapsed")):Lib.setClass(f,"collapsed")}});function ResponseTab(a){this.file=a}ResponseTab.prototype=domplate(TabView.Tab.prototype,{id:"Response",label:Strings.Response,bodyTag:DIV({"class":"netInfoResponseText netInfoText"},PRE({"class":"javascript:nocontrols:nogutter:",name:"code"})),onUpdateBody:function(a,b){var c=Lib.getElementByClass(b,"netInfoResponseText");if(this.file.category=="image"){Lib.clearNode(c);var d=b.ownerDocument.createElement("img");d.src=this.file.href,c.appendChild(d,c)}else{Lib.clearNode(c.firstChild);var e=this.file.response.content.text,f=this.file.response.content.mimeType;f=="application/javascript"||f=="text/javascript"||f=="application/x-javascript"||f=="text/ecmascript"||f=="application/ecmascript"?(c.firstChild.innerHTML=e,dp.SyntaxHighlighter.HighlightAll(c.firstChild)):Lib.insertWrappedText(e,c.firstChild)}}});function ParamsTab(a){this.file=a}ParamsTab.prototype=domplate(HeadersTab.prototype,{id:"Params",label:Strings.URLParameters,bodyTag:TABLE({"class":"netInfoParamsText netInfoText netInfoParamsTable",cellpadding:0,cellspacing:0},TBODY()),onUpdateBody:function(a,b){if(this.file.request.queryString){var c=Lib.getElementByClass(b,"netInfoParamsText");this.insertHeaderRows(c,this.file.request.queryString,"Params")}}});function SentDataTab(a,b){b=b.charAt(0).toUpperCase()+b.slice(1).toLowerCase(),this.file=a,this.id=b,this.label=Strings[b]}SentDataTab.prototype=domplate(HeadersTab.prototype,{bodyTag:DIV({"class":"netInfo$tab.id\\Text netInfoText"},TABLE({"class":"netInfo$tab.id\\Table",cellpadding:0,cellspacing:0},TBODY())),onUpdateBody:function(a,b){var c=this.file.request.postData;if(c){var d=Lib.getElementByClass(b,"netInfo"+this.id+"Text");c.mimeType=="application/x-www-form-urlencoded"?this.insertHeaderRows(d,c.params,this.id):Lib.insertWrappedText(c.text,d)}}});function CookiesTab(a){this.file=a}CookiesTab.prototype=domplate(HeadersTab.prototype,{id:"Cookies",label:Strings.Cookies,bodyTag:DIV({"class":"netInfoCookiesText netInfoText"},TABLE({"class":"netInfoCookiesTable",cellpadding:0,cellspacing:0},TBODY(TR({"class":"netInfoResponseCookiesTitle"},TD({colspan:2},DIV({"class":"netInfoCookiesGroup"},Strings.ResponseCookies))),TR({"class":"netInfoRequestCookiesTitle"},TD({colspan:2},DIV({"class":"netInfoCookiesGroup"},Strings.RequestCookies)))))),onUpdateBody:function(a,b){if(file.response.cookies){var c=Lib.getElementByClass(b,"netInfoParamsText");this.insertHeaderRows(c,file.response.cookies,"Cookies","ResponseCookies")}if(file.request.cookies){var c=Lib.getElementByClass(b,"netInfoParamsText");this.insertHeaderRows(c,file.request.cookies,"Cookies","RequestCookies")}}});function CacheTab(a){this.file=a}CacheTab.prototype=domplate(HeadersTab.prototype,{id:"Cache",label:Strings.Cache,bodyTag:DIV({"class":"netInfoCacheText netInfoText"},TABLE({"class":"netInfoCacheTable",cellpadding:0,cellspacing:0},TBODY())),onUpdateBody:function(a,b){if(this.file.cache&&this.file.cache.afterRequest){var c=this.file.cache.afterRequest,d=[];for(var e in c)d.push({name:e,value:c[e]});this.insertHeaderRows(b,d,"Cache")}}});function HtmlTab(a){this.file=a}HtmlTab.prototype=domplate(HeadersTab.prototype,{id:"HTML",label:Strings.HTML,bodyTag:DIV({"class":"netInfoHtmlText netInfoText"},IFRAME({"class":"netInfoHtmlPreview",onload:"$onLoad"}),DIV({"class":"htmlPreviewResizer"})),onUpdateBody:function(a,b){this.preview=Lib.getElementByClass(b,"netInfoHtmlPreview");var c=parseInt(Cookies.getCookie("htmlPreviewHeight"));isNaN(c)||(this.preview.style.height=c+"px");var d=Lib.getElementByClass(b,"htmlPreviewResizer");this.resizer=new DragDrop.Tracker(d,{onDragStart:Lib.bind(this.onDragStart,this),onDragOver:Lib.bind(this.onDragOver,this),onDrop:Lib.bind(this.onDrop,this)})},onLoad:function(a){var b=Lib.fixEvent(a),c=Lib.getAncestorByClass(b.target,"tabHTMLBody").repObject;c.preview.contentWindow.document.body.innerHTML=c.file.response.content.text},onDragStart:function(a){var b=Lib.getBody(this.preview.ownerDocument);b.setAttribute("hResizing","true"),this.startHeight=this.preview.clientHeight},onDragOver:function(a,b){var c=this.startHeight+a.y;this.preview.style.height=c+"px",Cookies.setCookie("htmlPreviewHeight",c)},onDrop:function(a){var b=Lib.getBody(this.preview.ownerDocument);b.removeAttribute("hResizing")}});function DataURLTab(a){this.file=a}DataURLTab.prototype=domplate(HeadersTab.prototype,{id:"DataURL",label:Strings.DataURL,bodyTag:DIV({"class":"netInfoDataURLText netInfoText"}),onUpdateBody:function(a,b){var c=Lib.getElementByClass(b,"netInfoDataURLText"),d=this.file.request.url;if(d.indexOf("data:image")==0){var e=b.ownerDocument.createElement("img");e.src=d,c.appendChild(e)}else Lib.insertWrappedText(unescape(d),c)}});return RequestBody}}) \ No newline at end of file