integration/mediapart/article_files/probe-13.js
author Anthony Ly <anthonyly.com@gmail.com>
Tue, 09 Oct 2012 16:31:25 +0200
changeset 4 b00fdbef41d4
permissions -rw-r--r--
ajout du header sur pages articles

/*!Version: 13.3*/
var radar={};function cdxProbing(){this.maxMeasurementsByCountry={FR:1};this.cancelled=false;this.providers=[];this.currentProvider=null;this.currentProbeIdx=0}cdxProbing.defaultMaxMeasurements=4;cdxProbing.ResultCodes={SUCCESS:{name:"SUCCESS",code:0},HTTP_TIMEOUT:{name:"HTTP_TIMEOUT",code:1},HTTP_INVALID_FILE:{name:"HTTP_INVALID_FILE",code:4}};cdxProbing.prototype.go=function(c){var a=cdxFeatures,b;b=a.reqs[c];if(b){this.downloadProbeDefinitions(b)}};cdxProbing.prototype.notifyCancelled=function(){var a=cdxFeatures,b;for(b in a.reqs){if(a.reqs.hasOwnProperty(b)){a.reqs[b].notify("Sampling Cancelled")}}};cdxProbing.prototype.cancel=function(){this.cancelled=true;if(!this.currentProvider){this.notifyCancelled()}else{if(this.currentProbeIdx<this.currentProvider.probes.length){this.currentProvider.probes[this.currentProbeIdx].cancelled=true}}};cdxProbing.prototype.getProbeDefinitionsPath=function(b){var a=cdxFeatures,c;c="//"+((location.protocol==="https:")?a.secureProbePath:a.probePath)+b.zid+"-"+b.cid+"-probes10.js";return c};cdxProbing.prototype.downloadProbeDefinitions=function(c){var a=document.createElement("script");a.type="text/javascript";a.src=this.getProbeDefinitionsPath(c);document.getElementById("radar_downloads").appendChild(a)};cdxProbing.prototype.startMeasurements=function(){var a=this.providers;if(0<a.length){this.currentProvider=a.shift();this.currentProbeIdx=0;this.beginProbe()}};cdxProbing.prototype.registerProviders=function(b){var a=this;this.providers=this.providers.concat(b);if(!this.measureTimeoutId){this.measureTimeoutId=setTimeout(function(){a.startMeasurements()})}};cdxProbing.prototype.onProbeDataReceived=function(f){var a=cdxFeatures,e,d,b,c;if(f&&f.privateProviders&&f.privateProviders[0]){e=f.privateProviders[0];d=cdxCore.getRequestorKey(e.providerZoneId,e.providerCustomerId);b=a.reqs[d];if(b){c=cdxProbing.parseConfiguration(b,f);c=b.notify("Samples Selected",c);this.registerProviders(c)}}};cdxProbing.isLargeObject=function(a){return a.probeType.indexOf("_KBPS")>-1};cdxProbing.prototype.beginProbe=function(){var e=this,c=document.getElementById("radar_downloads"),b,d,a;b=this.currentProvider.probes[this.currentProbeIdx];d=this.currentProvider.requestor;switch(b.tag){case"img":a=this.beginSampleImage();break;case"script":a=this.beginSampleScript();break;case"iframe":a=this.beginSampleIFrame();break;default:console.info("Invalid probe definition");return}this.currentTag=a;radar.stoppedAt=null;c.appendChild(a);this.scriptTimeoutId=setTimeout(function(){e.onScriptTimeout()},b.timeout);this.startedAt=new Date()};cdxProbing.prototype.beginSampleScript=function(){var c=this,b=this.currentProvider.probes[this.currentProbeIdx],a=document.createElement("script");a.type="text/javascript";a.src=cdxProbing.makeAssetUrl(b,this.currentProvider);a.onload=(function(d){return function(){if(!d.cancelled){if(radar.stoppedAt){c.sampleComplete(radar.stoppedAt)}else{c.sampleComplete(new Date(),cdxProbing.ResultCodes.HTTP_INVALID_FILE)}}}}(b));a.onreadystatechange=function(){if(("loaded"===a.readyState)||("complete"===a.readyState)){if(!radar.stoppedAt){c.sampleComplete(new Date(),cdxProbing.ResultCodes.HTTP_INVALID_FILE)}else{c.sampleComplete(radar.stoppedAt)}}};a.onerror=function(){c.sampleComplete(new Date(),cdxProbing.ResultCodes.HTTP_INVALID_FILE)};return a};cdxProbing.prototype.beginSampleImage=function(){var c=this,b=this.currentProvider.probes[this.currentProbeIdx],a=document.createElement("img");a.src=cdxProbing.makeAssetUrl(b,this.currentProvider);a.style.display="none";a.onload=function(){c.onSampleComplete()};a.onerror=function(){c.sampleComplete(new Date(),cdxProbing.ResultCodes.HTTP_INVALID_FILE)};return a};cdxProbing.prototype.beginSampleIFrame=function(){var c=this,b=this.currentProvider.probes[this.currentProbeIdx],a=document.createElement("iframe");a.src=cdxProbing.makeAssetUrl(b,this.currentProvider);a.style.display="none";if(a.addEventListener){a.addEventListener("load",function(){c.onSampleComplete()},false)}else{if(a.attachEvent){a.attachEvent("onload",function(){c.onSampleComplete()})}}return a};cdxProbing.prototype.onSampleComplete=function(){this.sampleComplete(new Date())};cdxProbing.makeAssetUrl=function(a,e){var d,c="",b=a.url;if(0!==b.indexOf("http")){b="//"+b}if(!e.omitQueryStrings){d=Math.round(10000000000*Math.random());if(e.addProbeId){c="&pb="+e.requestor.zid+"-"+e.requestor.cid+"-"+e.zid+"-"+e.cid+"-"+e.pid}if(0>b.indexOf("?",0)){b+="?rnd="+d}else{b+="&rnd="+d}b+=c}return b};cdxProbing.prototype.calculateMeasurement=function(e,d,c){var g=/-(\d+)kb\.js$/i,b=e-d,f,a;if(0>c.probeType.indexOf("_KBPS")){return b}f=g.exec(c.url);if(!f||(2>f.length)){return 0}a=parseInt(f[1],10);return Math.floor(8*1000*a/b)};cdxProbing.prototype.onScriptTimeout=function(){this.scriptTimeoutId=null;this.sampleComplete(new Date(),cdxProbing.ResultCodes.HTTP_TIMEOUT)};cdxProbing.prototype.sampleComplete=function(f,d){var c=cdxFeatures,g,a,b,e;if(this.cancelled){this.notifyCancelled();return}g=this.currentProvider;a=g.probes[this.currentProbeIdx];if(!a){return}this.callComplete();b=this.calculateMeasurement(f.getTime(),this.startedAt.getTime(),a);d=d||cdxProbing.ResultCodes.SUCCESS;e=g.zid+"/"+g.cid+"/"+g.pid+"/"+cdxCore.getProbeTypeCode(a.probeType)+"/"+d.code+"/"+(d.code===0?b.toString(10):"0");c.addReport("f1",g.requestor,e);g.requestor.notify("Probe Completed",{providerZoneId:g.zid,providerCustomerId:g.cid,providerId:g.pid,probeType:cdxCore.getProbeTypeCode(a.probeType),elapsed:b,resultCode:d.code});if((0!==d.code)&&cdxCore.isColdProbeType(a.probeType)){c.submitReportBatch(this.postSubmitReportBatch())}else{if(this.currentProbeIdx<(this.currentProvider.probes.length-1)){this.currentProbeIdx++;this.beginProbe()}else{c.submitReportBatch(this.postSubmitReportBatch())}}};cdxProbing.prototype.callComplete=function(){if(this.scriptTimeoutId){clearTimeout(this.scriptTimeoutId);this.scriptTimeoutId=null}this.currentTag.onload=this.currentTag.onerror=this.currentTag.onreadystatechange=null};cdxProbing.filter=function(b){var c,d,a=[];for(c=0;c<b.length;c++){d=b[c];if(true!==d.selected){a.push(d)}}return a};cdxProbing.chooseRandomProvider=function(e){var d,c,b,a;a=cdxProbing.filter(e);d=cdxCore.getSum(a,function(f){return f.weight});b=cdxCore.getRandomInt(0,d-1);d=0;for(c=0;c<a.length;c++){d+=a[c].weight;if(b<d){a[c].selected=true;return a[c]}}return null};cdxProbing.getSample=function(a){return{providerZoneId:a.providerZoneId,providerCustomerId:a.providerCustomerId,provider:cdxProbing.chooseRandomProvider(a.providers)}};cdxProbing.gatherProbes=function(f){var a=f.probes,d,c,b,e=[];for(d=0;d<a.length;d++){b=a[d];for(c=0;c<b.types.length;c++){e.push({tag:b.tag,timeout:b.timeout,probeType:b.types[c],url:b.url})}}return e};cdxProbing.parseConfiguration=function(m,d){var g=cdxFeatures,y,q,p,a,b,v,u,s,r,e,t,f,h,o,n,c=[],x,w;y=m.getPrivateProviders(d);q=m.getPublicProviders(d);p=cdxProbing.filterProviderGroups(m,y);a=cdxProbing.filterProviderGroups(m,q);b=[p,a];for(v=0;v<b.length;v++){for(u=0;u<b[v].length;u++){e=b[v][u];t=e.providers;f=g.unlimitedMeasurements?t.length:Math.min(e.maxMeasurements,t.length);o=e.maxThroughputMeasurements||0;h=0;for(s=0;s<f;s++){w=cdxProbing.getSample(e);x={requestor:m,zid:w.providerZoneId,cid:w.providerCustomerId,pid:w.provider.providerId,addProbeId:w.provider.addProbeId,omitQueryStrings:w.provider.omitQueryStrings};x.probes=[];n=cdxProbing.gatherProbes(w.provider);for(r=0;r<n.length;r++){if(cdxProbing.isLargeObject(n[r])){if(g.unlimitedMeasurements||(h<o)){x.probes.push(n[r])}h++}else{x.probes.push(n[r])}}c.push(x);m.notify("Provider Configured",x)}}}return c};cdxProbing.filterProviderGroups=function(b,c){var e=[],a,d;for(a in c){if(c.hasOwnProperty(a)){d=cdxProbing.filterGroup(b,c[a]);if(d){e.push(d)}}}return e};cdxProbing.getMaxMeasurements=function(b,a,g){var d=cdxFeatures,c=d.probing,f=c.maxMeasurementsByCountry,e;if("public"===g){for(e in f){if(f.hasOwnProperty(e)){if(d.countryCode===e){return Math.min(b,f[e])}}}}switch(typeof b){case"number":return b;case"string":return parseInt(b,10);default:return a}};cdxProbing.filterGroup=function(c,e){var b,f,d,a=false;d={groupName:e.groupName,providerZoneId:e.providerZoneId,providerCustomerId:e.providerCustomerId,maxMeasurements:cdxProbing.getMaxMeasurements(e.maxMeasurements,cdxProbing.defaultMaxMeasurements,e.groupName),maxThroughputMeasurements:e.maxThroughputMeasurements,activationPct:100,providers:[]};if(typeof e.activationPct!=="undefined"){d.activationPct=e.activationPct}if(cdxCore.checkPercentage(d.activationPct)){for(b in e.providers){if(e.providers.hasOwnProperty(b)){f=cdxProbing.filterProvider(c,e.providers[b]);if(f){d.providers.push(f);a=true}}}}return a?d:null};cdxProbing.getWeight=function(b,a){if(a.hasOwnProperty(cdxFeatures.countryCode)){return a[cdxFeatures.countryCode]}else{if(a.hasOwnProperty("default")){if(b.useDefaultProviderWeighting){return b.defaultProviderWeight}return a["default"]}}return a};cdxProbing.filterProvider=function(f,h){var c,e,d,g=false,b,a;b={providerId:h.providerId,weight:cdxProbing.getWeight(f,h.weight),addProbeId:h.hasOwnProperty("addProbeId")?h.addProbeId:false,omitQueryStrings:h.hasOwnProperty("omitQueryStrings")?h.omitQueryStrings:false,probes:[]};if(0<b.weight){for(e in h.probes){if(h.probes.hasOwnProperty(e)){c=h.probes[e];a={tag:c.tag,timeout:c.timeout,types:c.types,url:c.url};if(location.protocol==="https:"){a.types=[];for(d in c.types){if(c.types.hasOwnProperty(d)){if(/^SSL_/.test(c.types[d])){a.types.push(c.types[d])}}}}if(0<a.types.length){b.probes.push(a);g=true}}}}return g?b:null};cdxProbing.prototype.postSubmitReportBatch=function(){var a=this;return function(){var b=a.currentProvider.requestor;if(!a.lastRequestor||(a.lastRequestor!==b)){if(a.lastRequestor){a.lastRequestor.notify("Sampling Completed")}a.lastRequestor=b}if(a.cancelled){b.notify("Sampling Cancelled")}else{if(0<a.providers.length){a.currentProvider=a.providers.shift();a.currentProbeIdx=0;a.beginProbe()}else{a.currentProvider=null;a.measureTimeoutId=null;b.notify("Sampling Completed")}}}};(function(){var a=cdxFeatures;if(a&&!a.probing){a.probing=new cdxProbing()}}());