lib/har/viewer/scripts/preview/harModel.js in har-0.0.9 vs lib/har/viewer/scripts/preview/harModel.js in har-0.1.0
- old
+ new
@@ -1,7 +2 @@
-require.def("preview/harModel",["core/lib","preview/jsonSchema","preview/ref","preview/harSchema","core/cookies","core/trace","jquery-plugins/jquery.json"],function(i,m,n,o,j,k){function f(){this.input=null}function p(){var a={};for(var c in this)if(c!="toJSON")a[c]=this[c];if(!this.text)return a;a.text=Array.map(this.text,function(b){var d=b.charCodeAt(0);if(d>=32&&d<127||d==10||d==13)return b.charAt(0);for(b=d.toString(16).toUpperCase();b.length<4;)b="0"+b;return"\\u"+b}).join("");return a}f.prototype=
-{append:function(a){if(a){if(this.input)if(a.log.pages)for(var c=0;c<a.log.pages.length;c++)this.importPage(a.log.pages[c],a.log.entries);else{k.error("Import of additional data without a page is not yet supported.");return null}else this.input=a;return this.input}else k.error("HarModel.append; Trying to append null input!")},getPages:function(){if(!this.input)return[];return this.input.log.pages?this.input.log.pages:[]},getFirstPage:function(){var a=this.getPages();return a.length>0?a[0]:null},getPageEntries:function(a){return f.getPageEntries(this.input,
-a)},getAllEntries:function(){return this.input?this.input.log.entries:[]},getParentPage:function(a){return f.getParentPage(this.input,a)},importPage:function(a,c){var b=this.getUniquePageID(a.id),d=a.id;a.id=b;this.input.log.pages.push(a);for(a=0;a<c.length;a++){var e=c[a];if(e.pageref==d){e.pageref=b;this.input.log.entries.push(e)}}},getUniquePageID:function(a){for(var c=this.input.log.pages,b={},d=0;d<c.length;d++)b[c[d].id]=true;if(!b[a])return a;for(c=1;;){d=a+c;if(!b[d])return d;c++}},toJSON:function(a){if(!a)a=
-this.input;if(!a)return"";a=this.input.log.entries;for(var c=0;c<a.length;c++){var b=a[c];if(b.response.content.text)b.response.content.toJSON=p}return $.jSONToString(this.input,null,"\t").replace(/\\\\u/g,"\\u")},getSize:function(a){if(!a)a=this.input;if(!a)return 0;return dojo.toJson(a,true).length}};f.parse=function(a,c){var b=a;try{if(typeof a==="string")b=jQuery.toJSON(a)}catch(d){console.exception("HarModel.parse; EXCEPTION",d);throw{errors:[{message:"Failed to parse JSON",property:"JSON evaluation"}]};
-}if(!c)return b;a=n.resolveJson(o);a=m.validate(b,a.logType);if(a.valid)return b;throw a;};f.getPageEntries=function(a,c){var b=[];a=a.log.entries;if(!a)return b;for(var d=0;d<a.length;d++){var e=a[d];!e.pageref&&!c&&b.push(e);c&&e.pageref==c.id&&b.push(e)}return b};f.getParentPage=function(a,c){a=a.log.pages;if(!a)return null;for(var b=0;b<a.length;b++)if(a[b].id==c.pageref)return a[b];return null};f.Loader={run:function(a,c){var b=i.getURLParameter("baseUrl");if(b&&b[b.length-1]!="/")b+="/";var d=
-i.getURLParameters("path"),e=i.getURLParameter("callback"),h=i.getURLParameter("inputUrl"),g=[];for(var l in d)g.push(b?b+d[l]:d[l]);h&&g.push(h);if((b||h)&&g.length>0)return this.loadRemoteArchive(g,e,a,c);if(b=i.getURLParameter("path"))return this.loadLocalArchive(b,a,c)},loadExample:function(a){var c=document.location.href,b=c.indexOf("?");document.location=c.substr(0,b)+"?path="+a;j.setCookie("timeline",true);j.setCookie("stats",true)},loadLocalArchive:function(a,c,b){$.ajax({url:a,context:this,
-success:function(d){c(d)},error:function(d,e){b(d,e)}});return true},loadRemoteArchive:function(a,c,b,d){if(!a.length)return false;var e=a.shift();c||(c="onInputData");$.ajax({url:e,context:this,dataType:"jsonp",jsonp:"callback",jsonpCallback:c,success:function(h){b(h);if(a.length){var g=this;setTimeout(function(){g.loadRemoteArchive(a,c,b,d)},300)}},error:function(h,g){d(h,g)}});return true}};return f});
+require.def("preview/harModel",["core/lib","preview/jsonSchema","preview/ref","preview/harSchema","core/cookies","core/trace","i18n!nls/harModel","jquery-plugins/jquery.json"],function(a,b,c,d,e,f,g){function i(){var a={};for(var b in this)b!="toJSON"&&(a[b]=this[b]);if(!this.text)return a;a.text=Array.map(this.text,function(a){var b=a.charCodeAt(0);if(b>=32&&b<127||b==10||b==13)return a.charAt(0);var c=b.toString(16).toUpperCase();while(c.length<4)c="0"+c;return"\\u"+c}).join("");return a}function h(){this.input=null}h.prototype={append:function(b){{if(b){b.log.entries.sort(function(b,c){var d=a.parseISO8601(b.startedDateTime),e=a.parseISO8601(c.startedDateTime);if(d<e)return-1;if(d>e)return 1;return 0});if(this.input){if(!b.log.pages){f.error("Import of additional data without a page is not yet supported.");return null}for(var c=0;c<b.log.pages.length;c++)this.importPage(b.log.pages[c],b.log.entries)}else this.input=a.cloneJSON(b);return this.input}f.error("HarModel.append; Trying to append null input!")}},getPages:function(){if(!this.input)return[];return this.input.log.pages?this.input.log.pages:[]},getFirstPage:function(){var a=this.getPages();return a.length>0?a[0]:null},getPageEntries:function(a){return h.getPageEntries(this.input,a)},getAllEntries:function(a){return this.input?this.input.log.entries:[]},getParentPage:function(a){return h.getParentPage(this.input,a)},importPage:function(a,b){var c=this.getUniquePageID(a.id),d=a.id;a.id=c,this.input.log.pages.push(a);for(var e=0;e<b.length;e++){var f=b[e];f.pageref==d&&(f.pageref=c,this.input.log.entries.push(f))}},getUniquePageID:function(a){var b=this.input.log.pages,c={};for(var d=0;d<b.length;d++)c[b[d].id]=!0;if(!c[a])return a;var e=1;while(!0){var f=a+e;if(!c[f])return f;e++}},toJSON:function(a){a||(a=this.input);if(!a)return"";var b=this.input.log.entries;for(var c=0;c<b.length;c++){var d=b[c];d.response.content.text&&(d.response.content.toJSON=i)}var e=$.jSONToString(this.input,null,"\t"),f=e.replace(/\\\\u/g,"\\u");return f},getSize:function(a){a||(a=this.input);if(!a)return 0;var b=dojo.toJson(a,!0);return b.length}},h.parse=function(a,e){var f=a;try{typeof a==="string"&&(f=jQuery.parseJSON(a))}catch(g){console.exception("HarModel.parse; EXCEPTION",g);throw{errors:[{message:"Failed to parse JSON",property:"JSON evaluation"}]}}if(!e)return f;var h=c.resolveJson(d),i=b.validate(f,h.logType);if(i.valid){this.validateRequestTimings(f);return f}throw i},h.getPageEntries=function(a,b){var c=[],d=a.log.entries;if(!d)return c;for(var e=0;e<d.length;e++){var f=d[e];!f.pageref&&!b&&c.push(f),b&&f.pageref==b.id&&c.push(f)}return c},h.getParentPage=function(a,b){var c=a.log.pages;if(!c)return null;for(var d=0;d<c.length;d++)if(c[d].id==b.pageref)return c[d];return null},h.validateRequestTimings=function(b){var c=[],d=b.log.entries;for(var e=0;e<d.length;e++){var f=d[e],h=f.timings;if(h.blocked<-1||h.connect<-1||h.dns<-1||h.receive<-1||h.send<-1||h.wait<-1){var i=a.formatString(g.validationNegativeTimeError,f.request.url,e,f.pageref);c.push({input:b,file:f,message:i,property:g.validationType})}}if(c.length)throw{errors:c,input:b}},h.Loader={run:function(b,c){var d=a.getURLParameter("baseUrl");d&&d[d.length-1]!="/"&&(d+="/");var e=a.getURLParameters("path"),f=a.getURLParameter("callback"),g=a.getURLParameters("inputUrl"),h=[];for(var i in e)h.push(d?d+e[i]:e[i]);for(var i in g)h.push(g[i]);if((d||g.length>0)&&h.length>0)return this.loadRemoteArchive(h,f,b,c);var j=a.getURLParameter("path");if(j)return this.loadLocalArchive(j,b,c)},loadExample:function(a,b){var c=document.location.href,d=c.indexOf("?");document.location=c.substr(0,d)+"?path="+a,e.setCookie("timeline",!0),e.setCookie("stats",!0)},loadLocalArchive:function(a,b,c){$.ajax({url:a,context:this,success:function(a){b(a)},error:function(a,b){c(a,b)}});return!0},loadRemoteArchive:function(a,b,c,d){if(!a.length)return!1;var e=a.shift();b||(b="onInputData"),$.ajax({url:e,context:this,dataType:"jsonp",jsonp:"callback",jsonpCallback:b,success:function(e){c&&c(e);if(a.length){var f=this;setTimeout(function(){f.loadRemoteArchive(a,b,c,d)},300)}},error:function(a,b){d&&d(a,b)}});return!0},load:function(a,b,c,d,e,f){function h(b,c){a.onLoadError&&a.onLoadError(b,c),f&&f.call(a,b,c)}function g(b){a.appendPreview&&a.appendPreview(b),e&&e.call(a,b)}return c?this.loadRemoteArchive([b],d,g,h):this.loadLocalArchive(b,g,h)}};return h})
\ No newline at end of file