-
Notifications
You must be signed in to change notification settings - Fork 1
/
barcode-min.js
1 lines (1 loc) · 7.51 KB
/
barcode-min.js
1
!function(){this.barcodeToCanvas=function(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y;for(g=95,n=null!=(t=null!=c?c.lineWidth:void 0)?t:3,m=null!=(u=null!=c?c.lineHeight:void 0)?u:70*n,j=10*n,i=null!=(v=null!=c?c.font:void 0)?v:"monospace",e=null!=(w=null!=c?c.black:void 0)?w:"black",o=m+j/2,h=b.getContext("2d"),h.textBaseline="bottom",h.font=j+"px "+i,h.setTransform(1,0,0,1,0,0),h.clearRect(0,0,b.width,b.height),h.textAlign="right",h.fillStyle=e,h.fillText(a.canonical[0],j,m+j),h.textAlign="start",h.translate(j+3*n,0),x=a.toBinary(),p=0,r=x.length;r>p;p++)for(f=x[p],l=f.digit?!1:!0,k=l?o:m,l||(h.fillStyle=e,h.fillText(f.digit,0,m+j)),y=f.bits,q=0,s=y.length;s>q;q++)d=y[q],h.fillStyle="1"===d?e:"rgba(255, 255, 255, 0)",h.fillRect(0,0,n,k),h.translate(n,0);return h.fillStyle=e,h.fillText(">",2*n,m+j)}}.call(this),function(){var a;a=function(){function a(a){this.callbacks=[],this.set(a)}return a.prototype.set=function(a){var b,c,d,e,f,g;if(this.newValue=a,c=this.value,this.value=this.newValue,this.value!==c){if(this.valid=/^[0-9]{12,13}$/.test(this.value),this.empty=""===this.value,this.valid)for(this.canonical=this.value;this.canonical.length<13;)this.canonical="0"+this.canonical;else this.canonical="";for(f=this.callbacks,g=[],d=0,e=f.length;e>d;d++)b=f[d],g.push(b(this.value));return g}},a.prototype.onChange=function(a){return this.callbacks.push(a)},a.prototype.country=function(){var a;return a=parseInt(this.canonical.slice(0,3),10),a>=0&&19>=a?"U.S. and Canada":a>=20&&29>=a?"Restricted distribution (MO defined)":a>=30&&39>=a?"U.S. drugs (see U.S. National Drug Code)":a>=40&&49>=a?"Restricted distribution (MO defined)":a>=50&&59>=a?"Coupons":a>=60&&139>=a?"U.S. and Canada":a>=200&&299>=a?"Restricted distribution (MO defined)":a>=300&&379>=a?"France and Monaco":380===a?"Bulgaria":383===a?"Slovenia":385===a?"Croatia":387===a?"Bosnia and Herzegovina":389===a?"Montenegro":a>=400&&440>=a?"Germany":a>=450&&459>=a?"Japan":a>=460&&469>=a?"Russia":470===a?"Kyrgyzstan":471===a?"Taiwan":474===a?"Estonia":475===a?"Latvia":476===a?"Azerbaijan":477===a?"Lithuania":478===a?"Uzbekistan":479===a?"Sri Lanka":480===a?"Philippines":481===a?"Belarus":482===a?"Ukraine":484===a?"Moldova":485===a?"Armenia":486===a?"Georgia":487===a?"Kazakhstan":488===a?"Tajikistan":489===a?"Hong Kong SAR":a>=490&&499>=a?"Japan":a>=500&&509>=a?"United Kingdom":a>=520&&521>=a?"Greece":528===a?"Lebanon":529===a?"Cyprus":530===a?"Albania":531===a?"Macedonia":535===a?"Malta":539===a?"Ireland":a>=540&&549>=a?"Belgium and Luxembourg":560===a?"Portugal":569===a?"Iceland":a>=570&&579>=a?"Denmark, Faroe Islands and Greenland":590===a?"Poland":594===a?"Romania":599===a?"Hungary":a>=600&&601>=a?"South Africa":603===a?"Ghana":604===a?"Senegal":608===a?"Bahrain":609===a?"Mauritius":611===a?"Morocco":613===a?"Algeria":615===a?"Nigeria":616===a?"Kenya":618===a?"Côte d'Ivoire":619===a?"Tunisia":621===a?"Syria":622===a?"Egypt":624===a?"Libya":625===a?"Jordan":626===a?"Iran":627===a?"Kuwait":628===a?"Saudi Arabia":629===a?"United Arab Emirates":a>=640&&649>=a?"Finland":a>=690&&695>=a?"China, The People's Republic":a>=700&&709>=a?"Norway":729===a?"Israel":a>=730&&739>=a?"Sweden : EAN/GS1 Sweden":740===a?"Guatemala":741===a?"El Salvador":742===a?"Honduras":743===a?"Nicaragua":744===a?"Costa Rica":745===a?"Panama":746===a?"Dominican Republic":750===a?"Mexico":a>=754&&755>=a?"Canada":759===a?"Venezuela":a>=760&&769>=a?"Switzerland and Liechtenstein":a>=770&&771>=a?"Colombia":773===a?"Uruguay":775===a?"Peru":777===a?"Bolivia":779===a?"Argentina":780===a?"Chile":784===a?"Paraguay":785===a?"Peru":786===a?"Ecuador":a>=789&&790>=a?"Brazil":a>=800&&839>=a?"Italy, San Marino and Vatican City":a>=840&&849>=a?"Spain and Andorra":850===a?"Cuba":858===a?"Slovakia":859===a?"Czech Republic":860===a?"Serbia":865===a?"Mongolia":867===a?"North Korea":a>=868&&869>=a?"Turkey":a>=870&&879>=a?"Netherlands":880===a?"South Korea":884===a?"Cambodia":885===a?"Thailand":888===a?"Singapore":890===a?"India":893===a?"Vietnam":896===a?"Pakistan":899===a?"Indonesia":a>=900&&919>=a?"Austria":a>=930&&939>=a?"Australia":a>=940&&949>=a?"New Zealand":950===a?"GS1 Global Office: Special applications":951===a?"EPCglobal: Special applications":955===a?"Malaysia":958===a?"Macau":a>=960&&969>=a?"GS1 Global Office: GTIN-8 allocations":977===a?"Serial publications (ISSN)":a>=978&&979>=a?"Bookland (ISBN)":980===a?"Refund receipts":a>=981&&983>=a?"Common Currency Coupons":a>=990&&999>=a?"Coupons":"Unknown country"},a.prototype.isChecksumValid=function(){return this.validChecksum()===this.checksum()},a.prototype.checksum=function(){return parseInt(this.canonical[12])},a.prototype.validChecksum=function(){var a,b,c,d;for(a=0,b=c=1;11>=c;b=c+=2)a+=3*parseInt(this.canonical[b]);for(b=d=0;11>=d;b=d+=2)a+=parseInt(this.canonical[b]);return(10-a%10)%10},a.prototype.withValidChecksum=function(){return this.value.slice(0,-1)+this.validChecksum()},a.prototype.group1map=["000000","001011","001101","001110","010011","011001","011100","010101","010110","011010"],a.prototype.codes=[["0001101","0100111","1110010"],["0011001","0110011","1100110"],["0010011","0011011","1101100"],["0111101","0100001","1000010"],["0100011","0011101","1011100"],["0110001","0111001","1001110"],["0101111","0000101","1010000"],["0111011","0010001","1000100"],["0110111","0001001","1001000"],["0001011","0010111","1110100"]],a.prototype.toBinary=function(){var a,b,c,d,e;return e=this.group1map[this.canonical[0]],b=function(){var b,c,f,g;for(f=this.canonical.slice(1,7),g=[],d=b=0,c=f.length;c>b;d=++b)a=f[d],g.push({bits:this.codes[a][e[d]],digit:a});return g}.call(this),c=function(){var b,c,d,e;for(d=this.canonical.slice(7,13),e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push({bits:this.codes[a][2],digit:a});return e}.call(this),[{bits:"101"}].concat(b).concat([{bits:"01010"}]).concat(c).concat([{bits:"101"}])},a}(),window.Barcode=a}.call(this),function(){var a,b,c,d;d=null,a=new Barcode(""),a.onChange(function(a){return document.getElementById("barcode").value!==a?document.getElementById("barcode").value=a:void 0}),a.onChange(function(b){var c,d,e;return a.valid?(document.getElementById("main").classList.add("barcode-shown"),document.getElementById("error").style.display="none",d=document.getElementById("canvas"),e={},a.isChecksumValid()||(e.black="rgb(180, 102, 96)"),barcodeToCanvas(a,d,e),document.getElementById("image").src=d.toDataURL(),document.getElementById("results").style.display="block",c=document.getElementById("checksum"),a.isChecksumValid()?c.style.display="none":(c.textContent="fix checksum",c.href="#"+a.withValidChecksum(),c.style.display=""),document.getElementById("country").textContent=a.country(),b===a.canonical?document.getElementById("show-ean-link").style.display="none":(document.getElementById("show-ean-link").textContent="show EAN",document.getElementById("show-ean-link").href="#"+a.canonical,document.getElementById("show-ean-link").style.display="")):(document.getElementById("main").classList.remove("barcode-shown"),document.getElementById("results").style.display="none",document.getElementById("error").style.display=a.empty?"none":"block")}),a.onChange(function(b){var c;return null!=d&&clearTimeout(d),c=b,a.valid||a.empty?d=setTimeout(function(){return window.location.hash=b},300):void 0}),b=function(){return null!=d&&clearTimeout(d),a.set(document.getElementById("barcode").value)},c=function(b){var c;return null!=d&&clearTimeout(d),c=b?b.split("#")[1]:"",a.set(c)},document.getElementById("barcode").addEventListener("input",b),window.onhashchange=function(){return c(window.location.hash)},c(window.location.hash),document.body.classList.remove("preload")}.call(this);