From aedc9ca1411566e7c4aa7f4a683ff808a337ed74 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Mon, 2 Jul 2012 15:00:34 +0200 Subject: [PATCH 01/12] updates version to 0.3-pre. --- README.md | 5 +++++ build.properties | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 24c2038..c2a987d 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,11 @@ Uses [QR Code Generator](http://www.d-project.com/qrcode/index.html) (MIT). Kudo ## Changelog +### v0.3 - *2012-??-??* + +* + + ### v0.2 - *2012-07-02* * now encodes up to ~2900 characters (8-bit) diff --git a/build.properties b/build.properties index a2a746a..49b80eb 100644 --- a/build.properties +++ b/build.properties @@ -1,7 +1,7 @@ # project project.name = jquery.qrcode -project.version = 0.2 +project.version = 0.3-pre # src src.dir = src From a4eab68927c7a214e374d0fdc3407586493e5ca3 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Tue, 3 Jul 2012 00:47:46 +0200 Subject: [PATCH 02/12] Adds check for canvas and fallback to div. --- src/jquery.qrcode.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index 764d820..b14eb7a 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -6,10 +6,17 @@ (function ($) { 'use strict'; + // Check if canvas is available in the browser (as Modernizr does) + var canvasAvailable = (function () { + + var elem = document.createElement('canvas'); + return !!(elem.getContext && elem.getContext('2d')); + }()), + // Wrapper for the original QR code generator. - var createQr = function (typeNumber, correctLevel, text) { + createQr = function (typeNumber, correctLevel, text) { - // qrcode is the single public function that will be defined by the `QR Code Generator` + // `qrcode` is the single public function that will be defined by the `QR Code Generator` // at the end of the file. var qr = qrcode(typeNumber, correctLevel); qr.addData(text); @@ -117,6 +124,13 @@ return $div; }, + createHTML = function (options) { + + var settings = $.extend({}, defaults, options); + + return canvasAvailable && settings.render === 'canvas' ? createCanvas(settings) : createDiv(settings); + }, + // Plugin // ====== @@ -145,11 +159,9 @@ // ------------------- $.fn.qrcode = function(options) { - var settings = $.extend({}, defaults, options); - return this.each(function () { - $(this).append(settings.render === 'canvas' ? createCanvas(settings) : createDiv(settings)); + $(this).append(createHTML(options)); }); }; From 6fa3d100fb2ae4a87222972775ba62defc980027 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Tue, 3 Jul 2012 16:57:03 +0200 Subject: [PATCH 03/12] Cleans .gitignore. --- .gitignore | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 4cbedb2..2ccdd29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,8 @@ -# Build files and folders to ignore build release -# Local -local.makefile +# local files build.local.xml *.sublime-* -.ant-targets* - -# Numerous always-ignore extensions -*.ant-targets-build.xml -*.diff -*.err -*.orig -*.log -*.rej -*.swo -*.swp -*.vi -*~ -*.sass-cache +.ant-targets-* From 86534b8083bc2947c2c746fe2006a2eea9a32974 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sat, 25 Aug 2012 22:01:07 +0200 Subject: [PATCH 04/12] Changes build process. --- .gitignore | 6 +- build.properties | 16 ----- build.xml | 115 ----------------------------------- jshint.json | 21 ------- makefile.js | 152 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 156 deletions(-) delete mode 100644 build.properties delete mode 100644 build.xml delete mode 100644 jshint.json create mode 100644 makefile.js diff --git a/.gitignore b/.gitignore index 2ccdd29..efec224 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ build -release +local +*.sublime-* -# local files build.local.xml -*.sublime-* -.ant-targets-* diff --git a/build.properties b/build.properties deleted file mode 100644 index 49b80eb..0000000 --- a/build.properties +++ /dev/null @@ -1,16 +0,0 @@ - -# project -project.name = jquery.qrcode -project.version = 0.3-pre - -# src -src.dir = src - -# build -build.dir = build -release.dir = release - -# tools -tool.wepp = wepp -tool.docco = docco -tool.jshint = jshint diff --git a/build.xml b/build.xml deleted file mode 100644 index 92f324b..0000000 --- a/build.xml +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - Build: ${build.label} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/jshint.json b/jshint.json deleted file mode 100644 index 8adb47f..0000000 --- a/jshint.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - // Enforcing Options - "bitwise": true, - "curly": true, - "eqeqeq": true, - "forin": true, - "latedef": true, - "newcap": true, - "noempty": true, - "plusplus": true, - "trailing": true, - "undef": true, - - // Environments - "browser": true, - - // Globals - "predef": [ - "jQuery", "qrcode" - ] -} \ No newline at end of file diff --git a/makefile.js b/makefile.js new file mode 100644 index 0000000..7b776b6 --- /dev/null +++ b/makefile.js @@ -0,0 +1,152 @@ +/*jshint node: true */ +'use strict'; + + +var path = require('path'), + child_process = require('child_process'); + + +var version = '0.3-dev', + + root = path.resolve(__dirname), + src = path.resolve(root, 'src'), + build = path.resolve(root, 'build'), + + jshint = { + // Enforcing Options + bitwise: true, + curly: true, + eqeqeq: true, + forin: true, + latedef: true, + newcap: true, + noempty: true, + plusplus: true, + trailing: true, + undef: true, + + // Environments + browser: true, + + // Globals + predef: [ + "jQuery", "qrcode" + ] + }, + + mapperRoot = function (blob) { + + return blob.source.replace(root, build); + }; + + +module.exports = function (make) { + + var Event = make.Event, + $ = make.fQuery, + moment = make.moment, + stamp, replacements; + + + make.defaults('release'); + + + make.before(function () { + + stamp = moment(); + + replacements = { + version: version, + stamp: stamp.format('YYYY-MM-DD HH:mm:ss') + }; + + Event.info({ method: 'before', message: version + ' ' + replacements.stamp }); + }); + + + make.target('git-hash', [], 'get git hash tag') + .async(function (done, fail) { + + if (!/-dev$/.test(version)) { + done(); + return; + } + + var hash = '', + cmd = 'git', + args = ['rev-parse', '--short', 'HEAD'], + options = {}, + proc = child_process.spawn(cmd, args, options); + + proc.stdout.on('data', function (data) { + hash += ('' + data).replace(/\s*/g, ''); + }); + proc.on('exit', function (code) { + if (code) { + Event.error({ method: 'git-hash', message: cmd + ' exit code ' + code }); + fail(); + } else { + version += '-' + hash; + replacements.version = version; + Event.ok({ method: 'git-hash', message: 'version is now ' + version }); + done(); + } + }); + }); + + + make.target('clean', [], 'delete build folder') + .sync(function () { + + $.rmfr($.I_AM_SURE, build); + }); + + + make.target('lint', [], 'lint all JavaScript files with JSHint') + .sync(function () { + + $(src + ': jquery.qrcode.js') + .jshint(jshint); + }); + + + make.target('build', ['git-hash'], 'build all updated files') + .sync(function () { + + $(src + ': jquery.qrcode.js') + .includify() + .handlebars(replacements) + .write($.OVERWRITE, path.join(build, 'jquery.qrcode-' + version + '.js')) + .uglifyjs() + .write($.OVERWRITE, path.join(build, 'jquery.qrcode-' + version + '.min.js')); + + $(root + ': README*, LICENSE*') + .write($.OVERWRITE, mapperRoot); + }); + + + make.target('release', ['clean', 'build'], 'create a zipball') + .async(function (done, fail) { + + var target = path.join(build, 'jquery.qrcode-' + version + '.zip'), + cmd = 'zip', + args = ['-ro', target, '.'], + options = { cwd: build }, + proc = child_process.spawn(cmd, args, options); + + Event.info({ method: 'exec', message: cmd + ' ' + args.join(' ') }); + + proc.stderr.on('data', function (data) { + process.stderr.write(data); + }); + proc.on('exit', function (code) { + if (code) { + Event.error({ method: 'exec', message: cmd + ' exit code ' + code }); + fail(); + } else { + Event.ok({ method: 'exec', message: 'created zipball ' + target }); + done(); + } + }); + }); +}; From 4f966bac342fbfef2e1abea3dd1cc8316f9be69f Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sat, 25 Aug 2012 23:00:17 +0200 Subject: [PATCH 05/12] Minor changes. --- makefile.js | 23 ++++++++++++----------- package.json | 5 +++++ src/jquery.qrcode.js | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 package.json diff --git a/makefile.js b/makefile.js index 7b776b6..9f5a496 100644 --- a/makefile.js +++ b/makefile.js @@ -6,7 +6,7 @@ var path = require('path'), child_process = require('child_process'); -var version = '0.3-dev', +var pkg = require('./package.json'), root = path.resolve(__dirname), src = path.resolve(root, 'src'), @@ -56,18 +56,18 @@ module.exports = function (make) { stamp = moment(); replacements = { - version: version, + pkg: pkg, stamp: stamp.format('YYYY-MM-DD HH:mm:ss') }; - Event.info({ method: 'before', message: version + ' ' + replacements.stamp }); + Event.info({ method: 'before', message: pkg.version + ' ' + replacements.stamp }); }); make.target('git-hash', [], 'get git hash tag') .async(function (done, fail) { - if (!/-dev$/.test(version)) { + if (!/-dev$/.test(pkg.version)) { done(); return; } @@ -86,9 +86,8 @@ module.exports = function (make) { Event.error({ method: 'git-hash', message: cmd + ' exit code ' + code }); fail(); } else { - version += '-' + hash; - replacements.version = version; - Event.ok({ method: 'git-hash', message: 'version is now ' + version }); + pkg.version += '-' + hash; + Event.ok({ method: 'git-hash', message: 'version is now ' + pkg.version }); done(); } }); @@ -113,12 +112,14 @@ module.exports = function (make) { make.target('build', ['git-hash'], 'build all updated files') .sync(function () { - $(src + ': jquery.qrcode.js') + var scriptName = pkg.name; + + $(src + ': ' + scriptName + '.js') .includify() .handlebars(replacements) - .write($.OVERWRITE, path.join(build, 'jquery.qrcode-' + version + '.js')) + .write($.OVERWRITE, path.join(build, scriptName + '-' + pkg.version + '.js')) .uglifyjs() - .write($.OVERWRITE, path.join(build, 'jquery.qrcode-' + version + '.min.js')); + .write($.OVERWRITE, path.join(build, scriptName + '-' + pkg.version + '.min.js')); $(root + ': README*, LICENSE*') .write($.OVERWRITE, mapperRoot); @@ -128,7 +129,7 @@ module.exports = function (make) { make.target('release', ['clean', 'build'], 'create a zipball') .async(function (done, fail) { - var target = path.join(build, 'jquery.qrcode-' + version + '.zip'), + var target = path.join(build, pkg.name + '-' + pkg.version + '.zip'), cmd = 'zip', args = ['-ro', target, '.'], options = { cwd: build }, diff --git a/package.json b/package.json new file mode 100644 index 0000000..56c6ae0 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "name": "jquery.qrcode", + "displayName": "jQuery.qrcode", + "version": "0.3-dev" +} \ No newline at end of file diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index b14eb7a..3d09771 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -1,4 +1,4 @@ -/*! jQuery.qrcode %BUILD_VERSION% - //larsjung.de/qrcode - MIT License */ +/*! {{pkg.displayName}} {{pkg.version}} - //larsjung.de/qrcode - MIT License */ // Uses [QR Code Generator](http://www.d-project.com/qrcode/index.html) (MIT), appended to the end of this file. // Kudos to [jquery.qrcode.js](http://github.com/jeromeetienne/jquery-qrcode) (MIT). From 38afc056e00c731640faf61dc7388860ad68a75b Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Fri, 31 May 2013 22:23:51 +0200 Subject: [PATCH 06/12] Updates build process. --- makefile.js | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/makefile.js b/makefile.js index 9f5a496..98d3458 100644 --- a/makefile.js +++ b/makefile.js @@ -64,34 +64,23 @@ module.exports = function (make) { }); - make.target('git-hash', [], 'get git hash tag') - .async(function (done, fail) { + make.target('check-version', [], 'add git info to dev builds').async(function (done, fail) { - if (!/-dev$/.test(pkg.version)) { - done(); - return; - } + if (!/-dev$/.test(pkg.version)) { + done(); + return; + } - var hash = '', - cmd = 'git', - args = ['rev-parse', '--short', 'HEAD'], - options = {}, - proc = child_process.spawn(cmd, args, options); + $.git(root, function (err, result) { - proc.stdout.on('data', function (data) { - hash += ('' + data).replace(/\s*/g, ''); - }); - proc.on('exit', function (code) { - if (code) { - Event.error({ method: 'git-hash', message: cmd + ' exit code ' + code }); - fail(); - } else { - pkg.version += '-' + hash; - Event.ok({ method: 'git-hash', message: 'version is now ' + pkg.version }); - done(); - } + pkg.version += '-' + result.revListOriginMasterHead.length + '-' + result.revParseHead.slice(0, 7); + Event.info({ + method: 'check-version', + message: 'version set to ' + pkg.version }); + done(); }); + }); make.target('clean', [], 'delete build folder') @@ -109,7 +98,7 @@ module.exports = function (make) { }); - make.target('build', ['git-hash'], 'build all updated files') + make.target('build', ['check-version'], 'build all updated files') .sync(function () { var scriptName = pkg.name; From 1993ffba1d82acdee1e7159489c9634b520ccf11 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Fri, 31 May 2013 22:25:57 +0200 Subject: [PATCH 07/12] Updates build process. --- makefile.js | 1 + 1 file changed, 1 insertion(+) diff --git a/makefile.js b/makefile.js index 98d3458..00d857e 100644 --- a/makefile.js +++ b/makefile.js @@ -48,6 +48,7 @@ module.exports = function (make) { stamp, replacements; + make.version('>=0.8.1'); make.defaults('release'); From f50454d8f08055682379143263cb722d332671ba Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sat, 1 Jun 2013 00:08:44 +0200 Subject: [PATCH 08/12] Updates license year. --- LICENSE.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.txt b/LICENSE.txt index bab9d95..35363c3 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2012 Lars Jung, http://larsjung.de +Copyright (c) 2013 Lars Jung, http://larsjung.de Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in From 3c96998eba340745ae106e3c0893e995597dec59 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sat, 1 Jun 2013 14:02:47 +0200 Subject: [PATCH 09/12] Cleans git ignores. --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index efec224..97b30e7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,3 @@ build local *.sublime-* - -build.local.xml From 6908a2bc146e7c04201ac19078573c402870474c Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sat, 1 Jun 2013 14:47:45 +0200 Subject: [PATCH 10/12] Adds option to draw on existing canvas. Improves compression. --- src/jquery.qrcode.js | 79 +++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index 3d09771..10e8636 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -38,63 +38,88 @@ return null; }, - // Returns a `canvas` element representing the QR code for the given settings. - createCanvas = function (settings) { - - var qr = createBestQr(settings.text), - $canvas = $('').attr('width', settings.width).attr('height', settings.height), + // Draws QR code to the given `canvas` and returns it. + drawOnCanvas = function (canvas, settings) { + + // some shortcuts to improve compression + var settings_text = settings.text, + settings_left = settings.left, + settings_top = settings.top, + settings_width = settings.width, + settings_height = settings.height, + settings_color = settings.color, + settings_bgColor = settings.bgColor, + + qr = createBestQr(settings_text), + $canvas = $(canvas), ctx = $canvas[0].getContext('2d'); - if (settings.bgColor) { - ctx.fillStyle = settings.bgColor; - ctx.fillRect(0, 0, settings.width, settings.height); + if (settings_bgColor) { + ctx.fillStyle = settings_bgColor; + ctx.fillRect(settings_left, settings_top, settings_width, settings_height); } if (qr) { var moduleCount = qr.getModuleCount(), - moduleWidth = settings.width / moduleCount, - moduleHeight = settings.height / moduleCount, + moduleWidth = settings_width / moduleCount, + moduleHeight = settings_height / moduleCount, row, col; ctx.beginPath(); for (row = 0; row < moduleCount; row += 1) { for (col = 0; col < moduleCount; col += 1) { if (qr.isDark(row, col)) { - ctx.rect(col * moduleWidth, row * moduleHeight, moduleWidth, moduleHeight); + ctx.rect(settings_left + col * moduleWidth, settings_top + row * moduleHeight, moduleWidth, moduleHeight); } } } - ctx.fillStyle = settings.color; + ctx.fillStyle = settings_color; ctx.fill(); } return $canvas; }, + // Returns a `canvas` element representing the QR code for the given settings. + createCanvas = function (settings) { + + var $canvas = $('').attr('width', settings.width).attr('height', settings.height); + + return drawOnCanvas($canvas, settings); + }, + // Returns a `div` element representing the QR code for the given settings. createDiv = function (settings) { - var qr = createBestQr(settings.text), + // some shortcuts to improve compression + var settings_text = settings.text, + settings_width = settings.width, + settings_height = settings.height, + settings_color = settings.color, + settings_bgColor = settings.bgColor, + math_floor = Math.floor, + + qr = createBestQr(settings_text), $div = $('
').css({ position: 'relative', left: 0, top: 0, padding: 0, margin: 0, - width: settings.width, - height: settings.height + width: settings_width, + height: settings_height }); - if (settings.bgColor) { - $div.css('background-color', settings.bgColor); + if (settings_bgColor) { + $div.css('background-color', settings_bgColor); } if (qr) { var moduleCount = qr.getModuleCount(), - moduleWidth = Math.floor(settings.width / moduleCount), - moduleHeight = Math.floor(settings.height / moduleCount), - offsetLeft = Math.floor(0.5 * (settings.width - moduleWidth * moduleCount)), - offsetTop = Math.floor(0.5 * (settings.height - moduleHeight * moduleCount)), + moduleWidth = math_floor(settings_width / moduleCount), + moduleHeight = math_floor(settings_height / moduleCount), + offsetLeft = math_floor(0.5 * (settings_width - moduleWidth * moduleCount)), + offsetTop = math_floor(0.5 * (settings_height - moduleHeight * moduleCount)), row, col; for (row = 0; row < moduleCount; row += 1) { @@ -117,7 +142,7 @@ margin: 0, width: moduleWidth, height: moduleHeight, - 'background-color': settings.color + 'background-color': settings_color }); } @@ -141,6 +166,10 @@ // render method: `'canvas'` or `'div'` render: 'canvas', + // left and top in pixel if rendering on existing canvas + left: 0, + top: 0, + // width and height in pixel width: 256, height: 256, @@ -161,7 +190,11 @@ return this.each(function () { - $(this).append(createHTML(options)); + if (this.nodeName.toLowerCase() === 'canvas') { + drawOnCanvas(this, options); + } else { + $(this).append(createHTML(options)); + } }); }; From 8cc72e0f4ac3444bdad36e9120b84610c1cf686f Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sat, 1 Jun 2013 15:39:32 +0200 Subject: [PATCH 11/12] Minor changes. --- src/jquery.qrcode.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.qrcode.js b/src/jquery.qrcode.js index 10e8636..3440aa9 100644 --- a/src/jquery.qrcode.js +++ b/src/jquery.qrcode.js @@ -166,7 +166,7 @@ // render method: `'canvas'` or `'div'` render: 'canvas', - // left and top in pixel if rendering on existing canvas + // left and top in pixel if drawn onto existing canvas left: 0, top: 0, From fc9cc2c03efb2c91ea89c9a1b06917afc12e2715 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sat, 1 Jun 2013 15:49:07 +0200 Subject: [PATCH 12/12] Prepares release. --- README.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c2a987d..bbd1f84 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ Uses [QR Code Generator](http://www.d-project.com/qrcode/index.html) (MIT). Kudo ## Changelog -### v0.3 - *2012-??-??* +### v0.3 - *2012-06-01* -* +* adds option to draw on existing canvas ### v0.2 - *2012-07-02* diff --git a/package.json b/package.json index 56c6ae0..0e7d76b 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name": "jquery.qrcode", "displayName": "jQuery.qrcode", - "version": "0.3-dev" + "version": "0.3" } \ No newline at end of file