From 5c8ed05f68e0e7dc95e39b48fc4bd0c373936c9a Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Tue, 22 Dec 2020 10:20:31 +0100 Subject: [PATCH] Use dynamic barcode types (references #1133) --- public/viewjs/shoppinglist.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/public/viewjs/shoppinglist.js b/public/viewjs/shoppinglist.js index 6400acb0..f273cb4f 100644 --- a/public/viewjs/shoppinglist.js +++ b/public/viewjs/shoppinglist.js @@ -536,10 +536,21 @@ var dummyCanvas = document.createElement("canvas"); $("img.barcode").each(function() { var img = $(this); + var barcode = img.attr("data-barcode").replace(/\D/g, ""); + + var barcodeType = "code128"; + if (barcode.length == 8) + { + barcodeType = "ean8"; + } + else if (barcode.length == 13) + { + barcodeType = "ean13"; + } bwipjs.toCanvas(dummyCanvas, { - bcid: "ean8", - text: img.attr("data-barcode"), + bcid: barcodeType, + text: barcode, height: 5, includetext: false });