diff --git a/caniuse-embed.min.js b/caniuse-embed.min.js index b5affdd..1d7c664 100644 --- a/caniuse-embed.min.js +++ b/caniuse-embed.min.js @@ -1 +1 @@ -(function(){for(var e=document.getElementsByClassName("ciu_embed"),t=0;t';s.innerHTML=o}else s.innerHTML="A feature was not included. Go to http://caniuse.bitsofco.de/#how-to-use to generate an embed."}var i=window.addEventListener?"addEventListener":"attachEvent",d=window[i],l="attachEvent"==i?"onmessage":"message";d(l,function(t){var s=t.data;if("string"==typeof s&&s.indexOf("ciu_embed")>-1)for(var n=s.split(":")[1],r=s.split(":")[2],a=0;a';a.innerHTML=o}else a.innerHTML="A feature was not included. Go to http://caniuse.bitsofco.de/#how-to-use to generate an embed."}var i=window.addEventListener?"addEventListener":"attachEvent",d=window[i],l="attachEvent"==i?"onmessage":"message";d(l,function(t){var a=t.data;if("string"==typeof a&&a.indexOf("ciu_embed")>-1)for(var r=a.split(":")[1],s=a.split(":")[2],n=0;n'; diff --git a/embed/script.js b/embed/script.js index 84a7d64..b71b8d3 100644 --- a/embed/script.js +++ b/embed/script.js @@ -1 +1 @@ -function getShortenedBrowserVersion(e){return e&&e.indexOf("-")>-1&&(e=e.split("-")[1]),e}function loadJSON(e,t,s){var n=new XMLHttpRequest;n.onreadystatechange=function(){n.readyState===XMLHttpRequest.DONE&&(200===n.status?t&&t(JSON.parse(n.responseText)):s&&s(n))},n.open("GET",e,!0),n.send()}var caniuseDataUrl="https://raw.githubusercontent.com/Fyrd/caniuse/master/fulldata-json/data-2.0.json",featureID=location.href.split("?feat=")[1],featureID=featureID?featureID.split("&periods=")[0]:null,periods=location.href.split("&periods=")[1],periods=periods?periods.split(","):null,browsers=["ie","edge","firefox","chrome","safari","opera","ios_saf","op_mini","android","and_chr"];featureID&&periods?document.getElementById("defaultMessage").innerHTML='Can I Use '+featureID+"? Data on support for the "+featureID+" feature across the major browsers from caniuse.com. (Embed Loading)":document.getElementById("defaultMessage").innerHTML="Error: Feature and/or Periods not Specified";for(var i=periods.length-1;i>-1;i--){var tableCells='',row=document.createElement("tr");row.className="statistics "+periods[i],row.innerHTML=tableCells,document.getElementById("tableBody").appendChild(row)}loadJSON(caniuseDataUrl,function(e){var t=e.data[featureID];if(t){var s=t.usage_perc_y,r=t.usage_perc_a,a=s+r,a=a.toFixed(2),o=t.description;o=o.replace(//g,">"),document.getElementById("featureTitle").innerHTML=t.title,document.getElementById("featureDescription").innerHTML=o,document.getElementById("featureLink").href="http://caniuse.com/#feat="+featureID,document.getElementById("note").innerHTML='Global: '+s+'% + '+r+"% = "+a+"%";for(var i={},d=0;d-1?(n=parseInt(p.split("_")[1]),i[u][p]=e.agents[u].version_list[l-n]?e.agents[u].version_list[l-n].version:null):p.indexOf("future")>-1&&(n=parseInt(p.split("_")[1]),i[u][p]=e.agents[u].version_list[l+n]?e.agents[u].version_list[l+n].version:null)}}for(var g={},d=0;d-1&&(b=w[B]);void 0!=v[u][p]?b.className+=" "+v[u][p]:!1;var _=getShortenedBrowserVersion(i[u][p]),M=""+_+''+g[u][p]+"%";void 0!=i[u][p]?b.innerHTML=M:b.innerHTML="",void 0!=v[u][p]&&v[u][p].indexOf("x")>-1&&(y=!0),void 0!=v[u][p]&&v[u][p].indexOf("u")>-1&&(I=!0)}y?document.getElementById("legendX").style.display="inline-block":document.getElementById("legendX").style.display="none",I?document.getElementById("legendU").style.display="inline-block":document.getElementById("legendU").style.display="none"}else document.getElementById("featureTitle").innerHTML="Uh Oh!",document.getElementById("featureDescription").innerHTML="The feature '"+featureID+"' was not recognized. ",document.getElementById("featureMain").innerHTML="";document.getElementById("defaultMessage").style.display="none",document.getElementsByClassName("feature")[0].style.display="block";var D=document.getElementsByClassName("feature")[0].scrollHeight,L="ciu_embed:"+featureID+":"+D;parent.postMessage(L,"*"),window.onresize=function(e){D=document.getElementsByClassName("feature")[0].scrollHeight;var t="ciu_embed:"+featureID+":"+D;parent.postMessage(t,"*")}},function(e){document.getElementById("defaultMessage").innerHTML="Error Getting JSON File: "+e.response,console.error(e)}); \ No newline at end of file +function getShortenedBrowserVersion(e){return e&&e.indexOf("-")>-1&&(e=e.split("-")[1]),e}function loadJSON(e,t,s){var r=new XMLHttpRequest;r.onreadystatechange=function(){r.readyState===XMLHttpRequest.DONE&&(200===r.status?t&&t(JSON.parse(r.responseText)):s&&s(r))},r.open("GET",e,!0),r.send()}var caniuseDataUrl="https://raw.githubusercontent.com/Fyrd/caniuse/master/fulldata-json/data-2.0.json",featureID=location.href.split("?feat=")[1],featureID=featureID?featureID.split("&periods=")[0]:null,periods=location.href.split("&periods=")[1],periods=periods?periods.split(","):null,browsers=["ie","edge","firefox","chrome","safari","opera","ios_saf","op_mini","android","and_chr"];featureID&&periods?document.getElementById("defaultMessage").innerHTML='Can I Use '+featureID+"? Data on support for the "+featureID+" feature across the major browsers from caniuse.com. (Embed Loading)":document.getElementById("defaultMessage").innerHTML="Error: Feature and/or Periods not Specified";for(var i=periods.length-1;i>-1;i--){var tableCells='',row=document.createElement("tr");row.className="statistics "+periods[i],row.innerHTML=tableCells,document.getElementById("tableBody").appendChild(row)}loadJSON(caniuseDataUrl,function(e){var t=e.data[featureID];if(t){var s=t.usage_perc_y,r=t.usage_perc_a,a=s+r,a=a.toFixed(2),o=t.description;o=o.replace(//g,">"),document.getElementById("featureTitle").innerHTML=t.title,document.getElementById("featureDescription").innerHTML=o,document.getElementById("featureLink").href="http://caniuse.com/#feat="+featureID,document.getElementById("note").innerHTML='Global: '+s+'% + '+r+"% = "+a+"%";for(var i={},d=0;d-1?(n=parseInt(p.split("_")[1]),i[u][p]=e.agents[u].version_list[l-n]?e.agents[u].version_list[l-n].version:null):p.indexOf("future")>-1&&(n=parseInt(p.split("_")[1]),i[u][p]=e.agents[u].version_list[l+n]?e.agents[u].version_list[l+n].version:null)}}for(var g={},d=0;d-1&&(I=w[_]);void 0!=v[u][p]?I.className+=" "+v[u][p]:!1;var B=getShortenedBrowserVersion(i[u][p]),M=""+B+''+g[u][p]+"%";void 0!=i[u][p]?I.innerHTML=M:I.innerHTML="",void 0!=v[u][p]&&v[u][p].indexOf("x")>-1&&(y=!0),void 0!=v[u][p]&&v[u][p].indexOf("u")>-1&&(b=!0)}y?document.getElementById("legendX").style.display="inline-block":document.getElementById("legendX").style.display="none",b?document.getElementById("legendU").style.display="inline-block":document.getElementById("legendU").style.display="none"}else document.getElementById("featureTitle").innerHTML="Uh Oh!",document.getElementById("featureDescription").innerHTML="The feature '"+featureID+"' was not recognized. ",document.getElementById("featureMain").innerHTML="";document.getElementById("defaultMessage").style.display="none",document.getElementsByClassName("feature")[0].style.display="block";var L=document.getElementsByClassName("feature")[0].scrollHeight,T="ciu_embed:"+featureID+":"+L;parent.postMessage(T,"*"),window.onresize=function(e){L=document.getElementsByClassName("feature")[0].scrollHeight;var t="ciu_embed:"+featureID+":"+L;parent.postMessage(t,"*")}},function(e){document.getElementById("defaultMessage").innerHTML="Error Getting JSON File: "+e.response,console.error(e)}); \ No newline at end of file