build: Fix vars-on-top and one-var rules

Change-Id: I70612df6e936229f95bce96b3abff508c74a8a03
This commit is contained in:
James D. Forrester 2019-04-06 17:11:41 -07:00
parent f3c558e148
commit 7aabb5450d
2 changed files with 25 additions and 21 deletions

View file

@ -10,8 +10,6 @@
},
"rules": {
"max-len": 0,
"no-undef": 0,
"one-var": 0,
"vars-on-top": 0
"no-undef": 0
}
}

View file

@ -1,5 +1,7 @@
( function ( $ ) {
$.fn.qrcode = function ( options ) {
var createCanvas, createTable;
// if options is string,
if ( typeof options === 'string' ) {
options = { text: options };
@ -17,28 +19,30 @@
foreground: '#000000'
}, options );
var createCanvas = function () {
createCanvas = function () {
var qrcode, canvas, ctx, tileW, tileH, row, col, w, h;
// create the qrcode itself
var qrcode = new QRCode( options.typeNumber, options.correctLevel );
qrcode = new QRCode( options.typeNumber, options.correctLevel );
qrcode.addData( options.text );
qrcode.make();
// create canvas element
var canvas = document.createElement( 'canvas' );
canvas = document.createElement( 'canvas' );
canvas.width = options.width;
canvas.height = options.height;
var ctx = canvas.getContext( '2d' );
ctx = canvas.getContext( '2d' );
// compute tileW/tileH based on options.width/options.height
var tileW = options.width / qrcode.getModuleCount();
var tileH = options.height / qrcode.getModuleCount();
tileW = options.width / qrcode.getModuleCount();
tileH = options.height / qrcode.getModuleCount();
// draw in the canvas
for ( var row = 0; row < qrcode.getModuleCount(); row++ ) {
for ( var col = 0; col < qrcode.getModuleCount(); col++ ) {
for ( row = 0; row < qrcode.getModuleCount(); row++ ) {
for ( col = 0; col < qrcode.getModuleCount(); col++ ) {
ctx.fillStyle = qrcode.isDark( row, col ) ? options.foreground : options.background;
var w = ( Math.ceil( ( col + 1 ) * tileW ) - Math.floor( col * tileW ) );
var h = ( Math.ceil( ( row + 1 ) * tileW ) - Math.floor( row * tileW ) );
w = ( Math.ceil( ( col + 1 ) * tileW ) - Math.floor( col * tileW ) );
h = ( Math.ceil( ( row + 1 ) * tileW ) - Math.floor( row * tileW ) );
ctx.fillRect( Math.round( col * tileW ), Math.round( row * tileH ), w, h );
}
}
@ -47,14 +51,16 @@
};
// from Jon-Carlos Rivera (https://github.com/imbcmdth)
var createTable = function () {
createTable = function () {
var qrcode, $table, tileW, tileH, row, col, $row;
// create the qrcode itself
var qrcode = new QRCode( options.typeNumber, options.correctLevel );
qrcode = new QRCode( options.typeNumber, options.correctLevel );
qrcode.addData( options.text );
qrcode.make();
// create table element
var $table = $( '<table></table>' )
$table = $( '<table></table>' )
.css( 'width', options.width + 'px' )
.css( 'height', options.height + 'px' )
.css( 'border', '0px' )
@ -62,14 +68,14 @@
.css( 'background-color', options.background );
// compute tileS percentage
var tileW = options.width / qrcode.getModuleCount();
var tileH = options.height / qrcode.getModuleCount();
tileW = options.width / qrcode.getModuleCount();
tileH = options.height / qrcode.getModuleCount();
// draw in the table
for ( var row = 0; row < qrcode.getModuleCount(); row++ ) {
var $row = $( '<tr></tr>' ).css( 'height', tileH + 'px' ).appendTo( $table );
for ( row = 0; row < qrcode.getModuleCount(); row++ ) {
$row = $( '<tr></tr>' ).css( 'height', tileH + 'px' ).appendTo( $table );
for ( var col = 0; col < qrcode.getModuleCount(); col++ ) {
for ( col = 0; col < qrcode.getModuleCount(); col++ ) {
$( '<td></td>' )
.css( 'width', tileW + 'px' )
.css( 'background-color', qrcode.isDark( row, col ) ? options.foreground : options.background )