Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section id="barcodescan">
    <div class="container">
      
      <div class="row">
        <div class="col-lg-12 text-center">
          <h2>Price Calculator</h2>
        <hr class="star-primary">
        <div class="input-field">
          <label for="ean_input">EAN:</label>
          <input id="ean_input" class="ean" type="number" value="0"/>
          <button type="button" class="btn btn-danger fa fa-barcode button scan"> SCAN</button><button type="button" class="btn btn-danger icon-barcode button add_product text-white bg-dark"> Add Product</button>
      </div>
        </div>
      </div>
      <div class="row">
        <div class="col-lg-6">
          <div class="container">

             <div id="table" class="row justify-content-center table-editable" style="width:100%;">
                <div class="col-auto">
                <span class="table-add glyphicon glyphicon-plus hidden"></span>
                <table class="table table-dark table-responsive text-left">
                  <thead>
                  <tr>
                    <th scope="col">Index</th>
                    <th scope="col">Code</th>
                    <th scope="col">Name</th>
                    <th scope="col" class="text-right">Price</th>
                    <th scope="col" data-attr-ignore>Remove</th>
                  </tr>
                </thead>
                <tbody>
                  <!-- This is our clonable table line -->
                  <tr class="hide">
                    <td>-</td>
                    <td></td>
                    <td contenteditable="false">undefined</td>
                    <td contenteditable="true" class="price text-"></td>
                    <td>
                      <span class="table-remove glyphicon glyphicon-remove"></span>
                    </td>
                  </tr>
                </tbody>
                  <tfoot>
                    <tr class="total">
                      <td></td>
                      <td></td>
                      <td></td>
                      <td class="text-right">Total: <span class="total_price">0.00</span></td> 
                      <td></td>
                    </tr>
                </tfoot>
                  
                </table>
              </div>
              </div>
        
      </div>
      
    </div><!-- /.container -->
  </section>
              
            
!

CSS

              
                .hidden {display:none;}
    .total_price {text-align:right;}
    #about, .nav.navbar {display:block;}
    body {
  font-family: system-ui;
  text-align: left;
}
 .hidden {display:none;}
 .glyphicon {color:#fff;}
.total_price {text-align:right;}
#about, .nav.navbar {display:block;}
.hide {display:none;}
input, textarea{
    background-color:#666;
    color: #FFF;
}
table {text-align:left;}
.total td:eq(4) {text-align:right;}
              
            
!

JS

              
                $(document).ready(function(){
  
  $("input.ean").on("change", function(){
    addProduct();
        });
    function addProduct(){
      var eancode = $("input.ean").val();
        $("tr.hide td:eq(0)").text($('tbody tr').length);
        $("tr.hide td:eq(1)").text(eancode);
        $("tr.hide td:eq(2)").html("Product " + ($('tbody tr').length));
        $("tr.hide td:eq(3)").text("1.00").addClass("text-right");
        $(".total_price").text("1.00");
        calc_total();
        $('.table-add').click();
    }
    $(".add_product").on("click", function(){
        addProduct();
      });

      function calc_total(){
        var sum = 0;
        $("tbody tr").each(function(i){
          $("td:eq(0)",this).text(((i)));
        });
        $("tr:not(.hide) .price").each(function(){
        sum += parseFloat($(this).text());
        console.log($(this).text());
      });
      $('.total_price').text((sum).toFixed(2));
    }

    
  // TABLE SCRIPT ----------------------------------
     var $TABLE = $('#table');
var $BTN = $('#export-btn');
var $EXPORT = $('#export');

$('.table-add').click(function() {
  var $clone = $('#table').find('tr.hide').clone(true).removeClass('hide table-line');
  $('#table').find('tbody').append($clone);
  calc_total();
});

$('.table-remove').click(function() {
  $(this).parents('tr').remove();
  calc_total();
}); 

$('.table-up').click(function() {
  var $row = $(this).parents('tr');
  if ($row.index() === 1) return; // Don't go above the header
  $row.prev().before($row.get(0));
});

$('.table-down').click(function() {
  var $row = $(this).parents('tr');
  $row.next().after($row.get(0));
});

// A few jQuery helpers for exporting only
jQuery.fn.pop = [].pop;
jQuery.fn.shift = [].shift;

$BTN.click(function() {
  var $rows = $TABLE.find('tr:not(:hidden)');
  var headers = [];
  var data = [];

  // Get the headers (add special header logic here)
  $($rows.shift()).find('th:not(:empty):not([data-attr-ignore])').each(function() {
    headers.push($(this).text().toLowerCase());
  });

  // Turn all existing rows into a loopable array
  $rows.each(function() {
    var $td = $(this).find('td');
    var h = {};

    // Use the headers from earlier to name our hash keys
    headers.forEach(function(header, i) {
      h[header] = $td.eq(i).text(); // will adapt for inputs if text is empty
    });

    data.push(h);
  });

  // Output the result
  $EXPORT.text(JSON.stringify(data));
});
      //});
  
   var Quagga = window.Quagga;
var App = {
    _scanner: null,
    init: function() {
        this.attachListeners();
    },
    activateScanner: function() {
        var scanner = this.configureScanner('.overlay__content'),
            onDetected = function (result) {
                document.querySelector('input.ean').value = result.codeResult.code;
                stop();
            }.bind(this),
            stop = function() {
                scanner.stop();  // should also clear all event-listeners?
                scanner.removeEventListener('detected', onDetected);
                this.hideOverlay();
                this.attachListeners();
                addProduct();
            }.bind(this);

        this.showOverlay(stop);
        scanner.addEventListener('detected', onDetected).start();
    },
    attachListeners: function() {
        var self = this,
            button = document.querySelector('.input-field input + button.scan');

        button.addEventListener("click", function onClick(e) {
            e.preventDefault();
            button.removeEventListener("click", onClick);
            self.activateScanner();
        });
    },
    showOverlay: function(cancelCb) {
        if (!this._overlay) {
            var content = document.createElement('div'),
                closeButton = document.createElement('div');

            closeButton.appendChild(document.createTextNode('[ X ]'));
            content.className = 'overlay__content';
            closeButton.className = 'overlay__close';
            this._overlay = document.createElement('div');
            this._overlay.className = 'overlay';
            this._overlay.appendChild(content);
            content.appendChild(closeButton);
            closeButton.addEventListener('click', function closeClick() {
                closeButton.removeEventListener('click', closeClick);
                cancelCb();
            });
            document.body.appendChild(this._overlay);
        } else {
            var closeButton = document.querySelector('.overlay__close');
            closeButton.addEventListener('click', function closeClick() {
                closeButton.removeEventListener('click', closeClick);
                cancelCb();
            });
        }
        this._overlay.style.display = "block";
    },
    hideOverlay: function() {
        if (this._overlay) {
            this._overlay.style.display = "none";
            $(".overlay__content").html("<span>Press the close button</span>");
        }
        else {
          closeClick();
          $(".overlay__content").hide();
        }
    },
    configureScanner: function(selector) {
        if (!this._scanner) {
            this._scanner = Quagga
                .decoder({readers: ['ean_reader']})
                .locator({patchSize: 'medium'})
                .fromSource({
                    target: selector,
                    constraints: {
                        width: 800,
                        height: 600,
                        facingMode: "environment"
                    }
                });
        }
        return this._scanner;
    }
};
App.init();
  
});
              
            
!
999px

Console