Skip to content

Commit

Permalink
Release v3.3.15
Browse files Browse the repository at this point in the history
  • Loading branch information
lindell committed Jul 19, 2016
1 parent be6dabb commit 3b0faef
Show file tree
Hide file tree
Showing 30 changed files with 2,668 additions and 2,483 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ Download or get the CDN link to the script:

| Name | Supported barcodes | Size (gzip) | CDN / Download |
|------|--------------------|:-----------:|---------------:|
| *All* | *All the barcodes!* | *7 kB* | *[JsBarcode.all.min.js][1]* |
| CODE128 | CODE128 (auto and force mode) | 4.6 kB | [JsBarcode.code128.min.js][2] |
| CODE39 | CODE39 | 3.7 kB | [JsBarcode.code39.min.js][3] |
| EAN / UPC | EAN-13, EAN-8, EAN-5, EAN-2, UPC (A) | 4.2 kB | [JsBarcode.ean-upc.min.js][4] |
| ITF-14 | ITF-14 | 3.4 kB | [JsBarcode.itf-14.min.js][5] |
| ITF | ITF | 3.4 kB | [JsBarcode.itf.min.js][6] |
| MSI | MSI, MSI10, MSI11, MSI1010, MSI1110 | 3.8 kB | [JsBarcode.msi.min.js][7] |
| Pharmacode | Pharmacode | 3.3 kB | [JsBarcode.pharmacode.min.js][8] |
| *All* | *All the barcodes!* | *7.3 kB* | *[JsBarcode.all.min.js][1]* |
| CODE128 | CODE128 (auto and force mode) | 5 kB | [JsBarcode.code128.min.js][2] |
| CODE39 | CODE39 | 4.1 kB | [JsBarcode.code39.min.js][3] |
| EAN / UPC | EAN-13, EAN-8, EAN-5, EAN-2, UPC (A) | 4.6 kB | [JsBarcode.ean-upc.min.js][4] |
| ITF-14 | ITF-14 | 3.8 kB | [JsBarcode.itf-14.min.js][5] |
| ITF | ITF | 3.7 kB | [JsBarcode.itf.min.js][6] |
| MSI | MSI, MSI10, MSI11, MSI1010, MSI1110 | 4.2 kB | [JsBarcode.msi.min.js][7] |
| Pharmacode | Pharmacode | 3.6 kB | [JsBarcode.pharmacode.min.js][8] |

### Step 2:
Include the script in your code:
Expand Down
140 changes: 26 additions & 114 deletions bin/JsBarcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ var _barcodes = require('./barcodes/');

var _barcodes2 = _interopRequireDefault(_barcodes);

var _renderers = require('./renderers/');

var _renderers2 = _interopRequireDefault(_renderers);

var _merge = require('./help/merge.js');

var _merge2 = _interopRequireDefault(_merge);
Expand All @@ -20,25 +16,29 @@ var _fixOptions = require('./help/fixOptions.js');

var _fixOptions2 = _interopRequireDefault(_fixOptions);

var _getOptionsFromElement = require('./help/getOptionsFromElement.js');
var _getRenderProperties = require('./help/getRenderProperties.js');

var _getOptionsFromElement2 = _interopRequireDefault(_getOptionsFromElement);
var _getRenderProperties2 = _interopRequireDefault(_getRenderProperties);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _defaults = require('./defaults/defaults.js');

// The protype of the object returned from the JsBarcode() call
var _defaults2 = _interopRequireDefault(_defaults);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// Help functions
// The protype of the object returned from the JsBarcode() call
// Import all the barcodes
var API = function API() {};

// The first call of the library API
// Will return an object with all barcodes calls and the information needed
// when the rendering function is called and options the barcodes might need
// Will return an object with all barcodes calls and the data that is used
// by the renderers


// Default values


// Import the renderers
// Help functions
var JsBarcode = function JsBarcode(element, text, options) {
var api = new API();

Expand All @@ -47,11 +47,11 @@ var JsBarcode = function JsBarcode(element, text, options) {
}

// Variables that will be pased through the API calls
api._renderProperties = getRenderProperies(element);
api._renderProperties = (0, _getRenderProperties2.default)(element);
api._encodings = [];
api._options = defaults;
api._options = _defaults2.default;

// If text is set, use simple syntax
// If text is set, use the simple syntax (render the barcode directly)
if (typeof text !== "undefined") {
options = options || {};

Expand Down Expand Up @@ -90,6 +90,7 @@ function registerBarcode(barcodes, name) {
};
}

// encode() handles the Encoder call and builds the binary string to be rendered
function encode(text, Encoder, options) {
// Ensure that text is a string
text = "" + text;
Expand All @@ -99,13 +100,14 @@ function encode(text, Encoder, options) {
// If the input is not valid for the encoder, throw error.
// If the valid callback option is set, call it instead of throwing error
if (!encoder.valid()) {
if (options.valid === defaults.valid) {
throw new Error('"' + text + '" is not a valid input for ' + name);
if (options.valid === _defaults2.default.valid) {
throw new Error('"' + text + '" is not a valid input.');
} else {
options.valid(false);
}
}

// Make a request for the binary data (and other infromation) that should be rendered
var encoded = encoder.encode();

// Encodings can be nestled like [[1-1, 1-2], 2, [3-1, 3-2]
Expand Down Expand Up @@ -144,8 +146,9 @@ API.prototype.blank = function (size) {
return this;
};

// Initialize JsBarcode on all HTML elements defined.
API.prototype.init = function () {
// this._renderProperties can be
// Make sure renderProperies is an array
if (!Array.isArray(this._renderProperties)) {
this._renderProperties = [this._renderProperties];
}
Expand Down Expand Up @@ -186,8 +189,6 @@ API.prototype.render = function () {

// Prepares the encodings and calls the renderer
function render(renderProperties, encodings, options) {
var renderer = _renderers2.default[renderProperties.renderer];

encodings = (0, _linearizeEncodings2.default)(encodings);

for (var i = 0; i < encodings.length; i++) {
Expand All @@ -197,7 +198,9 @@ function render(renderProperties, encodings, options) {

(0, _fixOptions2.default)(options);

renderer(renderProperties.element, encodings, options);
var Renderer = renderProperties.renderer;
var renderer = new Renderer(renderProperties.element, encodings, options);
renderer.render();

if (renderProperties.afterRender) {
renderProperties.afterRender();
Expand All @@ -210,6 +213,7 @@ if (typeof window !== "undefined") {
}

// Export to jQuery
/*global jQuery */
if (typeof jQuery !== 'undefined') {
jQuery.fn.JsBarcode = function (content, options) {
var elementArray = [];
Expand All @@ -221,96 +225,4 @@ if (typeof jQuery !== 'undefined') {
}

// Export to commonJS
module.exports = JsBarcode;

// Takes an element and returns an object with information about how
// it should be rendered
// This could also return an array with these objects
// {
// element: The element that the renderer should draw on
// renderer: The name of the renderer
// afterRender (optional): If something has to done after the renderer
// completed, calls afterRender (function)
// options (optional): Options that can be defined in the element
// }
function getRenderProperies(element) {
// If the element is a string, query select call again
if (typeof element === "string") {
var selector = document.querySelectorAll(element);
if (selector.length === 0) {
throw new Error("No element found");
} else {
var returnArray = [];
for (var i = 0; i < selector.length; i++) {
returnArray.push(getRenderProperies(selector[i]));
}
return returnArray;
}
}
// If element is array. Recursivly call with every object in the array
else if (Array.isArray(element)) {
var returnArray = [];
for (var i = 0; i < element.length; i++) {
returnArray.push(getRenderProperies(element[i]));
}
return returnArray;
}
// If element, render on canvas and set the uri as src
else if (typeof HTMLCanvasElement !== 'undefined' && element instanceof HTMLImageElement) {
var canvas = document.createElement('canvas');
return {
element: canvas,
options: (0, _getOptionsFromElement2.default)(element, defaults),
renderer: "canvas",
afterRender: function afterRender() {
element.setAttribute("src", canvas.toDataURL());
}
};
}
// If SVG
else if (typeof SVGElement !== 'undefined' && element instanceof SVGElement) {
return {
element: element,
options: (0, _getOptionsFromElement2.default)(element, defaults),
renderer: "svg"
};
}
// If canvas (in browser)
else if (typeof HTMLCanvasElement !== 'undefined' && element instanceof HTMLCanvasElement) {
return {
element: element,
options: (0, _getOptionsFromElement2.default)(element, defaults),
renderer: "canvas"
};
}
// If canvas (in node)
else if (element.getContext) {
return {
element: element,
renderer: "canvas"
};
} else {
throw new Error("Not supported type to render on.");
}
}

var defaults = {
width: 2,
height: 100,
format: "auto",
displayValue: true,
fontOptions: "",
font: "monospace",
textAlign: "center",
textPosition: "bottom",
textMargin: 2,
fontSize: 20,
background: "#ffffff",
lineColor: "#000000",
margin: 10,
marginTop: undefined,
marginBottom: undefined,
marginLeft: undefined,
marginRight: undefined,
valid: function valid(_valid) {}
};
module.exports = JsBarcode;
3 changes: 0 additions & 3 deletions bin/barcodes/CODE128/CODE128_AUTO.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ var CODE128AUTO = function (_CODE) {
_classCallCheck(this, CODE128AUTO);

// ASCII value ranges 0-127, 200-211

var _this = _possibleConstructorReturn(this, _CODE.call(this, string));

if (string.search(/^[\x00-\x7F\xC8-\xD3]+$/) !== -1) {
var _this = _possibleConstructorReturn(this, _CODE.call(this, autoSelectModes(string)));
} else {
Expand Down
4 changes: 2 additions & 2 deletions bin/barcodes/CODE39/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ var CODE39 = function () {
// Calculate mod43 checksum if enabled
if (this.mod43Enabled) {
var checksum = 0;
for (var i = 0; i < this.string.length; i++) {
checksum += this.characterValue(this.string[i]);
for (var _i = 0; _i < this.string.length; _i++) {
checksum += this.characterValue(this.string[_i]);
}

checksum = checksum % 43;
Expand Down
2 changes: 1 addition & 1 deletion bin/barcodes/ITF14/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var ITF14 = function () {
result += parseInt(this.string[i]) * (3 - i % 2 * 2);
}

return 10 - result % 10;
return Math.ceil(result / 10) * 10 - result;
};

return ITF14;
Expand Down
18 changes: 9 additions & 9 deletions bin/barcodes/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
value: true
});

var _CODE = require('./CODE39/');
Expand All @@ -21,12 +21,12 @@ var _pharmacode = require('./pharmacode/');
var _GenericBarcode = require('./GenericBarcode/');

exports.default = {
CODE39: _CODE.CODE39,
CODE128: _CODE2.CODE128, CODE128A: _CODE2.CODE128A, CODE128B: _CODE2.CODE128B, CODE128C: _CODE2.CODE128C,
EAN13: _EAN_UPC.EAN13, EAN8: _EAN_UPC.EAN8, EAN5: _EAN_UPC.EAN5, EAN2: _EAN_UPC.EAN2, UPC: _EAN_UPC.UPC,
ITF14: _ITF.ITF14,
ITF: _ITF2.ITF,
MSI: _MSI.MSI, MSI10: _MSI.MSI10, MSI11: _MSI.MSI11, MSI1010: _MSI.MSI1010, MSI1110: _MSI.MSI1110,
pharmacode: _pharmacode.pharmacode,
GenericBarcode: _GenericBarcode.GenericBarcode
CODE39: _CODE.CODE39,
CODE128: _CODE2.CODE128, CODE128A: _CODE2.CODE128A, CODE128B: _CODE2.CODE128B, CODE128C: _CODE2.CODE128C,
EAN13: _EAN_UPC.EAN13, EAN8: _EAN_UPC.EAN8, EAN5: _EAN_UPC.EAN5, EAN2: _EAN_UPC.EAN2, UPC: _EAN_UPC.UPC,
ITF14: _ITF.ITF14,
ITF: _ITF2.ITF,
MSI: _MSI.MSI, MSI10: _MSI.MSI10, MSI11: _MSI.MSI11, MSI1010: _MSI.MSI1010, MSI1110: _MSI.MSI1110,
pharmacode: _pharmacode.pharmacode,
GenericBarcode: _GenericBarcode.GenericBarcode
};
18 changes: 9 additions & 9 deletions bin/barcodes/index.tmp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
value: true
});

var _CODE = require('./CODE39/');
Expand All @@ -21,12 +21,12 @@ var _pharmacode = require('./pharmacode/');
var _GenericBarcode = require('./GenericBarcode/');

exports.default = {
CODE39: _CODE.CODE39,
CODE128: _CODE2.CODE128, CODE128A: _CODE2.CODE128A, CODE128B: _CODE2.CODE128B, CODE128C: _CODE2.CODE128C,
EAN13: _EAN_UPC.EAN13, EAN8: _EAN_UPC.EAN8, EAN5: _EAN_UPC.EAN5, EAN2: _EAN_UPC.EAN2, UPC: _EAN_UPC.UPC,
ITF14: _ITF.ITF14,
ITF: _ITF2.ITF,
MSI: _MSI.MSI, MSI10: _MSI.MSI10, MSI11: _MSI.MSI11, MSI1010: _MSI.MSI1010, MSI1110: _MSI.MSI1110,
pharmacode: _pharmacode.pharmacode,
GenericBarcode: _GenericBarcode.GenericBarcode
CODE39: _CODE.CODE39,
CODE128: _CODE2.CODE128, CODE128A: _CODE2.CODE128A, CODE128B: _CODE2.CODE128B, CODE128C: _CODE2.CODE128C,
EAN13: _EAN_UPC.EAN13, EAN8: _EAN_UPC.EAN8, EAN5: _EAN_UPC.EAN5, EAN2: _EAN_UPC.EAN2, UPC: _EAN_UPC.UPC,
ITF14: _ITF.ITF14,
ITF: _ITF2.ITF,
MSI: _MSI.MSI, MSI10: _MSI.MSI10, MSI11: _MSI.MSI11, MSI1010: _MSI.MSI1010, MSI1110: _MSI.MSI1110,
pharmacode: _pharmacode.pharmacode,
GenericBarcode: _GenericBarcode.GenericBarcode
};
Loading

0 comments on commit 3b0faef

Please sign in to comment.