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