Maintenance. Add utf-8 support.

pull/22/head v0.12.0
Lars Jung 10 years ago
parent e8f252f6e1
commit 4b4f1181d0

@ -0,0 +1,147 @@
{
"disallowDanglingUnderscores": {
"allExcept": ["_exception", "_obj" , "_private"]
},
"disallowEmptyBlocks": true,
"disallowImplicitTypeConversion": [
"binary",
"boolean",
"numeric",
"string"
],
"disallowKeywords": [
"with"
],
"disallowKeywordsOnNewLine": [
"else"
],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineStrings": true,
"disallowMultipleSpaces": true,
"disallowMultipleVarDecl": true,
"disallowNewlineBeforeBlockStatements": true,
"disallowQuotedKeysInObjects": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": [
"++",
"--",
"+",
"-",
"~",
"!"
],
"disallowSpaceBeforePostfixUnaryOperators": [
"++",
"--"
],
"disallowSpacesInCallExpression": true,
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowTrailingComma": true,
"disallowTrailingWhitespace": true,
"disallowYodaConditions": true,
"requireCapitalizedConstructors": true,
"requireCommaBeforeLineBreak": true,
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch",
"case",
"default"
],
"requireDollarBeforejQueryAssignment": true,
"requireDotNotation": true,
"requireLineBreakAfterVariableAssignment": true,
"requireLineFeedAtFileEnd": true,
"requireOperatorBeforeLineBreak": [
"?",
"=",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"requireParenthesesAroundIIFE": true,
"requireSemicolons": true,
"requireSpaceAfterBinaryOperators": [
"=",
",",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!=="
],
"requireSpaceAfterKeywords": [
"do",
"for",
"if",
"else",
"switch",
"case",
"try",
"catch",
"void",
"while",
"with",
"return",
"typeof",
"function"
],
"requireSpaceAfterLineComment": true,
"requireSpaceBeforeBinaryOperators": [
"=",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!=="
],
"requireSpaceBeforeBlockStatements": true,
"requireSpaceBeforeKeywords": [
"else",
"while",
"catch"
],
"requireSpaceBeforeObjectValues": true,
"requireSpaceBetweenArguments": true,
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"requireSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
},
"requireSpacesInForStatement": true,
"validateIndentation": 4,
"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
},
"validateLineBreaks": "LF",
"validateParameterSeparator": ", ",
"validateQuoteMarks": "'"
}

@ -0,0 +1,27 @@
{
"bitwise": true,
"curly": true,
"eqeqeq": true,
"forin": true,
"freeze": true,
"futurehostile": true,
"latedef": true,
"maxdepth": 3,
"noarg": true,
"nocomma": true,
"nonbsp": true,
"nonew": true,
"plusplus": true,
"strict": false,
"supernew": true,
"trailing": true,
"undef": true,
"unused": true,
"browser": true,
"globals": {
"jQuery": false,
"qrcode": false
}
}

@ -8,7 +8,7 @@ jQuery plugin to dynamically generate QR codes. Uses [QR Code Generator][qrcode]
## License ## License
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2014 Lars Jung (http://larsjung.de) Copyright (c) 2015 Lars Jung (http://larsjung.de)
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
@ -32,9 +32,9 @@ THE SOFTWARE.
[web]: http://larsjung.de/qrcode/ [web]: http://larsjung.de/qrcode/
[github]: https://github.com/lrsjng/jquery-qrcode [github]: https://github.com/lrsjng/jquery-qrcode
[license-img]: http://img.shields.io/badge/license-MIT-a0a060.svg?style=flat-square [license-img]: https://img.shields.io/badge/license-MIT-a0a060.svg?style=flat-square
[web-img]: http://img.shields.io/badge/web-larsjung.de/qrcode-a0a060.svg?style=flat-square [web-img]: https://img.shields.io/badge/web-larsjung.de/qrcode-a0a060.svg?style=flat-square
[github-img]: http://img.shields.io/badge/github-lrsjng/jquery--qrcode-a0a060.svg?style=flat-square [github-img]: https://img.shields.io/badge/github-lrsjng/jquery--qrcode-a0a060.svg?style=flat-square
[bower-img]: http://img.shields.io/badge/bower-lrsjng/jquery--qrcode-a0a060.svg?style=flat-square [bower-img]: https://img.shields.io/badge/bower-lrsjng/jquery--qrcode-a0a060.svg?style=flat-square
[qrcode]: https://github.com/kazuhikoarase/qrcode-generator [qrcode]: https://github.com/kazuhikoarase/qrcode-generator

@ -1,6 +1,6 @@
{ {
"name": "jquery-qrcode", "name": "jquery-qrcode",
"version": "0.11.0", "version": "0.12.0",
"description": "generate QR codes dynamically", "description": "generate QR codes dynamically",
"homepage": "http://larsjung.de/jquery-qrcode/", "homepage": "http://larsjung.de/jquery-qrcode/",
"authors": [ "authors": [

@ -1,5 +1,5 @@
/* jQuery.qrcode 0.11.0 - http://larsjung.de/jquery-qrcode/ - uses //github.com/kazuhikoarase/qrcode-generator (MIT) */ /* jQuery.qrcode 0.12.0 - http://larsjung.de/jquery-qrcode/ - uses //github.com/kazuhikoarase/qrcode-generator (MIT) */
(function () { (function (qrcode) {
'use strict'; 'use strict';
var $ = jQuery; var $ = jQuery;
@ -7,8 +7,6 @@ var $ = jQuery;
// Wrapper for the original QR code generator. // Wrapper for the original QR code generator.
function QRCode(text, level, version, quiet) { function QRCode(text, level, version, quiet) {
// `qrcode` is the single public function that will be defined by the `QR Code Generator`
// at the end of the file.
var qr = qrcode(version, level); var qr = qrcode(version, level);
qr.addData(text); qr.addData(text);
qr.make(); qr.make();
@ -58,7 +56,7 @@ function QRCode(text, level, version, quiet) {
var hasCanvas = (function () { var hasCanvas = (function () {
var elem = document.createElement('canvas'); var elem = document.createElement('canvas');
return !!(elem.getContext && elem.getContext('2d')); return Boolean(elem.getContext && elem.getContext('2d'));
}()); }());
var hasArcTo = Object.prototype.toString.call(window.opera) !== '[object Opera]'; var hasArcTo = Object.prototype.toString.call(window.opera) !== '[object Opera]';
@ -78,8 +76,8 @@ function createQRCode(text, level, minVersion, maxVersion, quiet) {
function drawBackgroundLabel(qr, context, settings) { function drawBackgroundLabel(qr, context, settings) {
var size = settings.size; var size = settings.size;
var font = "bold " + (settings.mSize * size) + "px " + settings.fontname; var font = 'bold ' + (settings.mSize * size) + 'px ' + settings.fontname;
var ctx = $('<canvas/>')[0].getContext("2d"); var ctx = $('<canvas/>')[0].getContext('2d');
ctx.font = font; ctx.font = font;
@ -253,7 +251,8 @@ function drawModules(qr, context, settings) {
var moduleCount = qr.moduleCount; var moduleCount = qr.moduleCount;
var moduleSize = settings.size / moduleCount; var moduleSize = settings.size / moduleCount;
var fn = drawModuleDefault; var fn = drawModuleDefault;
var row, col; var row;
var col;
if (hasArcTo && settings.radius > 0 && settings.radius <= 0.5) { if (hasArcTo && settings.radius > 0 && settings.radius <= 0.5) {
fn = drawModuleRounded; fn = drawModuleRounded;
@ -263,9 +262,9 @@ function drawModules(qr, context, settings) {
for (row = 0; row < moduleCount; row += 1) { for (row = 0; row < moduleCount; row += 1) {
for (col = 0; col < moduleCount; col += 1) { for (col = 0; col < moduleCount; col += 1) {
var l = settings.left + col * moduleSize, var l = settings.left + col * moduleSize;
t = settings.top + row * moduleSize, var t = settings.top + row * moduleSize;
w = moduleSize; var w = moduleSize;
fn(qr, context, settings, l, t, w, row, col); fn(qr, context, settings, l, t, w, row, col);
} }
@ -275,7 +274,7 @@ function drawModules(qr, context, settings) {
context.lineWidth = 2; context.lineWidth = 2;
context.stroke(); context.stroke();
var prev = context.globalCompositeOperation; var prev = context.globalCompositeOperation;
context.globalCompositeOperation = "destination-out"; context.globalCompositeOperation = 'destination-out';
context.fill(); context.fill();
context.globalCompositeOperation = prev; context.globalCompositeOperation = prev;
@ -335,7 +334,8 @@ function createDiv(settings) {
var moduleSize = math_floor(settings_size / moduleCount); var moduleSize = math_floor(settings_size / moduleCount);
var offset = math_floor(0.5 * (settings_size - moduleSize * moduleCount)); var offset = math_floor(0.5 * (settings_size - moduleSize * moduleCount));
var row, col; var row;
var col;
var containerCSS = { var containerCSS = {
position: 'relative', position: 'relative',
@ -462,12 +462,9 @@ $.fn.qrcode = function(options) {
} }
}); });
}; };
}(function () {
// jQuery.qrcode plug in code ends here // `qrcode` is the single public function defined by the `QR Code Generator`
// QR Code Generator
// =================
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// //
// QR Code Generator for JavaScript // QR Code Generator for JavaScript
@ -493,7 +490,7 @@ var qrcode = function() {
/** /**
* qrcode * qrcode
* @param typeNumber 1 to 10 * @param typeNumber 1 to 40
* @param errorCorrectLevel 'L','M','Q','H' * @param errorCorrectLevel 'L','M','Q','H'
*/ */
var qrcode = function(typeNumber, errorCorrectLevel) { var qrcode = function(typeNumber, errorCorrectLevel) {
@ -766,7 +763,7 @@ var qrcode = function() {
ecdata[r] = new Array(rsPoly.getLength() - 1); ecdata[r] = new Array(rsPoly.getLength() - 1);
for (var i = 0; i < ecdata[r].length; i += 1) { for (var i = 0; i < ecdata[r].length; i += 1) {
var modIndex = i + modPoly.getLength() - ecdata[r].length; var modIndex = i + modPoly.getLength() - ecdata[r].length;
ecdata[r][i] = (modIndex >= 0)? modPoly.get(modIndex) : 0; ecdata[r][i] = (modIndex >= 0)? modPoly.getAt(modIndex) : 0;
} }
} }
@ -1402,7 +1399,7 @@ var qrcode = function() {
var _this = {}; var _this = {};
_this.get = function(index) { _this.getAt = function(index) {
return _num[index]; return _num[index];
}; };
@ -1416,7 +1413,7 @@ var qrcode = function() {
for (var i = 0; i < _this.getLength(); i += 1) { for (var i = 0; i < _this.getLength(); i += 1) {
for (var j = 0; j < e.getLength(); j += 1) { for (var j = 0; j < e.getLength(); j += 1) {
num[i + j] ^= QRMath.gexp(QRMath.glog(_this.get(i) ) + QRMath.glog(e.get(j) ) ); num[i + j] ^= QRMath.gexp(QRMath.glog(_this.getAt(i) ) + QRMath.glog(e.getAt(j) ) );
} }
} }
@ -1429,15 +1426,15 @@ var qrcode = function() {
return _this; return _this;
} }
var ratio = QRMath.glog(_this.get(0) ) - QRMath.glog(e.get(0) ); var ratio = QRMath.glog(_this.getAt(0) ) - QRMath.glog(e.getAt(0) );
var num = new Array(_this.getLength() ); var num = new Array(_this.getLength() );
for (var i = 0; i < _this.getLength(); i += 1) { for (var i = 0; i < _this.getLength(); i += 1) {
num[i] = _this.get(i); num[i] = _this.getAt(i);
} }
for (var i = 0; i < e.getLength(); i += 1) { for (var i = 0; i < e.getLength(); i += 1) {
num[i] ^= QRMath.gexp(QRMath.glog(e.get(i) ) + ratio); num[i] ^= QRMath.gexp(QRMath.glog(e.getAt(i) ) + ratio);
} }
// recursive call // recursive call
@ -1548,7 +1545,7 @@ var qrcode = function() {
[5, 109, 87, 1, 110, 88], [5, 109, 87, 1, 110, 88],
[5, 65, 41, 5, 66, 42], [5, 65, 41, 5, 66, 42],
[5, 54, 24, 7, 55, 25], [5, 54, 24, 7, 55, 25],
[11, 36, 12], [11, 36, 12, 7, 37, 13],
// 16 // 16
[5, 122, 98, 1, 123, 99], [5, 122, 98, 1, 123, 99],
@ -1771,7 +1768,7 @@ var qrcode = function() {
return _buffer; return _buffer;
}; };
_this.get = function(index) { _this.getAt = function(index) {
var bufIndex = Math.floor(index / 8); var bufIndex = Math.floor(index / 8);
return ( (_buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1; return ( (_buffer[bufIndex] >>> (7 - index % 8) ) & 1) == 1;
}; };
@ -2283,5 +2280,74 @@ var qrcode = function() {
return qrcode; return qrcode;
}(); }();
(function (factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof exports === 'object') {
module.exports = factory();
}
}(function () {
return qrcode;
}));
//---------------------------------------------------------------------
//
// QR Code Generator for JavaScript UTF8 Support (optional)
//
// Copyright (c) 2011 Kazuhiko Arase
//
// URL: http://www.d-project.com/
//
// Licensed under the MIT license:
// http://www.opensource.org/licenses/mit-license.php
//
// The word 'QR Code' is registered trademark of
// DENSO WAVE INCORPORATED
// http://www.denso-wave.com/qrcode/faqpatent-e.html
//
//---------------------------------------------------------------------
!function(qrcode) {
}()); //---------------------------------------------------------------------
// overwrite qrcode.stringToBytes
//---------------------------------------------------------------------
qrcode.stringToBytes = function(s) {
// http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
function toUTF8Array(str) {
var utf8 = [];
for (var i=0; i < str.length; i++) {
var charcode = str.charCodeAt(i);
if (charcode < 0x80) utf8.push(charcode);
else if (charcode < 0x800) {
utf8.push(0xc0 | (charcode >> 6),
0x80 | (charcode & 0x3f));
}
else if (charcode < 0xd800 || charcode >= 0xe000) {
utf8.push(0xe0 | (charcode >> 12),
0x80 | ((charcode>>6) & 0x3f),
0x80 | (charcode & 0x3f));
}
// surrogate pair
else {
i++;
// UTF-16 encodes 0x10000-0x10FFFF by
// subtracting 0x10000 and splitting the
// 20 bits of 0x0-0xFFFFF into two halves
charcode = 0x10000 + (((charcode & 0x3ff)<<10)
| (str.charCodeAt(i) & 0x3ff));
utf8.push(0xf0 | (charcode >>18),
0x80 | ((charcode>>12) & 0x3f),
0x80 | ((charcode>>6) & 0x3f),
0x80 | (charcode & 0x3f));
}
}
return utf8;
}
return toUTF8Array(s);
};
}(qrcode);
return qrcode;
}()));

File diff suppressed because one or more lines are too long

@ -1,10 +1,8 @@
/*jshint node: true */ /*jshint node: true */
'use strict'; 'use strict';
module.exports = function (suite) { module.exports = function (suite) {
var path = require('path'); var path = require('path');
var root = path.resolve(__dirname); var root = path.resolve(__dirname);
var src = path.join(root, 'src'); var src = path.join(root, 'src');
@ -12,50 +10,28 @@ module.exports = function (suite) {
var build = path.join(root, 'build'); var build = path.join(root, 'build');
var $ = require('fquery'); var $ = require('fquery');
$.plugin('fquery-handlebars');
$.plugin('fquery-includeit'); $.plugin('fquery-includeit');
$.plugin('fquery-jade');
$.plugin('fquery-jshint'); $.plugin('fquery-jshint');
$.plugin('fquery-jszip'); $.plugin('fquery-jszip');
$.plugin('fquery-uglifyjs'); $.plugin('fquery-uglifyjs');
suite.defaults('release'); suite.defaults('release');
suite.target('clean', [], 'delete build folder').task(function () { suite.target('clean', [], 'delete build folder').task(function () {
$([build, dist], {dirs: true}).delete(); $([build, dist], {dirs: true}).delete();
}); });
suite.target('lint', [], 'lint all JavaScript files with JSHint').task(function () { suite.target('lint', [], 'lint all JavaScript files with JSHint').task(function () {
var options = { var fs = require('fs');
// Enforcing Options var jshint = JSON.parse(fs.readFileSync('.jshintrc', 'utf-8'));
bitwise: true,
curly: true,
eqeqeq: true,
forin: true,
latedef: true,
newcap: true,
noempty: true,
plusplus: true,
trailing: true,
undef: true,
// Environments
browser: true
};
var global = {
'jQuery': true,
'qrcode': true
};
$(src + ': jquery.qrcode.js, demo/scripts.js') $(src + ': jquery.qrcode.js, demo/scripts.js')
.jshint(options, global); .jshint(jshint, jshint.globals);
}); });
suite.target('release', ['clean', 'lint'], 'build all files and create a zipball').task(function () { suite.target('release', ['clean', 'lint'], 'build all files and create a zipball').task(function () {
var pkg = require('./package.json'); var pkg = require('./package.json');
@ -73,15 +49,18 @@ module.exports = function (suite) {
.write($.map.p(src, dist).s('.js', '.min.js'), true) .write($.map.p(src, dist).s('.js', '.min.js'), true)
.write($.map.p(src, build).s('.js', '-' + pkg.version + '.min.js'), true); .write($.map.p(src, build).s('.js', '-' + pkg.version + '.min.js'), true);
$(src + ': **, ! *.js') $(src + ': **/*.jade')
.handlebars(env) .jade(env)
.write($.map.p(src, build).s('.jade', ''), true);
$(src + ': **, ! *.js, ! **/*.jade, ! lib/**')
.write($.map.p(src, build), true); .write($.map.p(src, build), true);
$(root + ': *.md') $(root + ': *.md')
.write($.map.p(root, build), true); .write($.map.p(root, build), true);
$(build + ': **') $(build + ': **')
.jszip({dir: build}) .jszip({dir: build, level: 9})
.write(target, true); .write(target, true);
}); });
}; };

@ -1,7 +1,7 @@
{ {
"name": "jquery-qrcode", "name": "jquery-qrcode",
"displayName": "jQuery.qrcode", "displayName": "jQuery.qrcode",
"version": "0.11.0", "version": "0.12.0",
"description": "generate QR codes dynamically", "description": "generate QR codes dynamically",
"homepage": "http://larsjung.de/jquery-qrcode/", "homepage": "http://larsjung.de/jquery-qrcode/",
"bugs": "https://github.com/lrsjng/jquery-qrcode/issues", "bugs": "https://github.com/lrsjng/jquery-qrcode/issues",
@ -12,12 +12,16 @@
"url": "https://github.com/lrsjng/jquery-qrcode.git" "url": "https://github.com/lrsjng/jquery-qrcode.git"
}, },
"devDependencies": { "devDependencies": {
"fquery": "~0.16.2", "fquery": "~0.16.4",
"fquery-handlebars": "~0.2.0", "fquery-includeit": "~0.3.0",
"fquery-includeit": "~0.2.0", "fquery-jade": "~0.5.0",
"fquery-jshint": "~0.2.0", "fquery-jshint": "~0.3.0",
"fquery-jszip": "~0.4.0", "fquery-jszip": "~0.5.1",
"fquery-uglifyjs": "~0.2.1", "fquery-uglifyjs": "~0.3.0",
"mkr": "~0.6.1" "mkr": "~0.8.5"
},
"engines": {
"node": ">=0.10",
"iojs": ">=1.0.0"
} }
} }

@ -1,294 +0,0 @@
/*
html5slider - a JS implementation of <input type=range> for Firefox 16 and up
https://github.com/fryn/html5slider
Copyright (c) 2010-2013 Frank Yan, <http://frankyan.com>
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 the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
(function() {
// test for native support
var test = document.createElement('input');
try {
test.type = 'range';
if (test.type == 'range')
return;
} catch (e) {
return;
}
// test for required property support
test.style.background = 'linear-gradient(red, red)';
if (!test.style.backgroundImage || !('MozAppearance' in test.style))
return;
var scale;
var isMac = navigator.platform == 'MacIntel';
var thumb = {
radius: isMac ? 9 : 6,
width: isMac ? 22 : 12,
height: isMac ? 16 : 20
};
var track = 'linear-gradient(transparent ' + (isMac ?
'6px, #999 6px, #999 7px, #ccc 8px, #bbb 9px, #bbb 10px, transparent 10px' :
'9px, #999 9px, #bbb 10px, #fff 11px, transparent 11px') +
', transparent)';
var styles = {
'min-width': thumb.width + 'px',
'min-height': thumb.height + 'px',
'max-height': thumb.height + 'px',
padding: '0 0 ' + (isMac ? '2px' : '1px'),
border: 0,
'border-radius': 0,
cursor: 'default',
'text-indent': '-999999px' // -moz-user-select: none; breaks mouse capture
};
var options = {
attributes: true,
attributeFilter: ['min', 'max', 'step', 'value']
};
var onInput = document.createEvent('HTMLEvents');
onInput.initEvent('input', true, false);
var onChange = document.createEvent('HTMLEvents');
onChange.initEvent('change', true, false);
if (document.readyState == 'loading')
document.addEventListener('DOMContentLoaded', initialize, true);
else
initialize();
addEventListener('pageshow', recreate, true);
function initialize() {
// create initial sliders
recreate();
// create sliders on-the-fly
new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes)
Array.forEach(mutation.addedNodes, function(node) {
if (!(node instanceof Element))
;
else if (node.childElementCount)
Array.forEach(node.querySelectorAll('input[type=range]'), check);
else if (node.mozMatchesSelector('input[type=range]'))
check(node);
});
});
}).observe(document, { childList: true, subtree: true });
}
function recreate() {
Array.forEach(document.querySelectorAll('input[type=range]'), check);
}
function check(input) {
if (input.type != 'range')
transform(input);
}
function transform(slider) {
var isValueSet, areAttrsSet, isUI, isClick, prevValue, rawValue, prevX;
var min, max, step, range, value = slider.value;
// lazily create shared slider affordance
if (!scale) {
scale = document.body.appendChild(document.createElement('hr'));
style(scale, {
'-moz-appearance': isMac ? 'scale-horizontal' : 'scalethumb-horizontal',
display: 'block',
visibility: 'visible',
opacity: 1,
position: 'fixed',
top: '-999999px'
});
document.mozSetImageElement('__sliderthumb__', scale);
}
// reimplement value and type properties
var getValue = function() { return '' + value; };
var setValue = function setValue(val) {
value = '' + val;
isValueSet = true;
draw();
delete slider.value;
slider.value = value;
slider.__defineGetter__('value', getValue);
slider.__defineSetter__('value', setValue);
};
slider.__defineGetter__('value', getValue);
slider.__defineSetter__('value', setValue);
Object.defineProperty(slider, 'type', {
get: function() { return 'range'; }
});
// sync properties with attributes
['min', 'max', 'step'].forEach(function(name) {
if (slider.hasAttribute(name))
areAttrsSet = true;
Object.defineProperty(slider, name, {
get: function() {
return this.hasAttribute(name) ? this.getAttribute(name) : '';
},
set: function(val) {
val === null ?
this.removeAttribute(name) :
this.setAttribute(name, val);
}
});
});
// initialize slider
slider.readOnly = true;
style(slider, styles);
update();
new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName != 'value') {
update();
areAttrsSet = true;
}
// note that value attribute only sets initial value
else if (!isValueSet) {
value = slider.getAttribute('value');
draw();
}
});
}).observe(slider, options);
slider.addEventListener('mousedown', onDragStart, true);
slider.addEventListener('keydown', onKeyDown, true);
slider.addEventListener('focus', onFocus, true);
slider.addEventListener('blur', onBlur, true);
function onDragStart(e) {
isClick = true;
setTimeout(function() { isClick = false; }, 0);
if (e.button || !range)
return;
var width = parseFloat(getComputedStyle(this).width);
var multiplier = (width - thumb.width) / range;
if (!multiplier)
return;
// distance between click and center of thumb
var dev = e.clientX - this.getBoundingClientRect().left - thumb.width / 2 -
(value - min) * multiplier;
// if click was not on thumb, move thumb to click location
if (Math.abs(dev) > thumb.radius) {
isUI = true;
this.value -= -dev / multiplier;
}
rawValue = value;
prevX = e.clientX;
this.addEventListener('mousemove', onDrag, true);
this.addEventListener('mouseup', onDragEnd, true);
}
function onDrag(e) {
var width = parseFloat(getComputedStyle(this).width);
var multiplier = (width - thumb.width) / range;
if (!multiplier)
return;
rawValue += (e.clientX - prevX) / multiplier;
prevX = e.clientX;
isUI = true;
this.value = rawValue;
}
function onDragEnd() {
this.removeEventListener('mousemove', onDrag, true);
this.removeEventListener('mouseup', onDragEnd, true);
slider.dispatchEvent(onInput);
slider.dispatchEvent(onChange);
}
function onKeyDown(e) {
if (e.keyCode > 36 && e.keyCode < 41) { // 37-40: left, up, right, down
onFocus.call(this);
isUI = true;
this.value = value + (e.keyCode == 38 || e.keyCode == 39 ? step : -step);
}
}
function onFocus() {
if (!isClick)
this.style.boxShadow = !isMac ? '0 0 0 2px #fb0' :
'inset 0 0 20px rgba(0,127,255,.1), 0 0 1px rgba(0,127,255,.4)';
}
function onBlur() {
this.style.boxShadow = '';
}
// determines whether value is valid number in attribute form
function isAttrNum(value) {
return !isNaN(value) && +value == parseFloat(value);
}
// validates min, max, and step attributes and redraws
function update() {
min = isAttrNum(slider.min) ? +slider.min : 0;
max = isAttrNum(slider.max) ? +slider.max : 100;
if (max < min)
max = min > 100 ? min : 100;
step = isAttrNum(slider.step) && slider.step > 0 ? +slider.step : 1;
range = max - min;
draw(true);
}
// recalculates value property
function calc() {
if (!isValueSet && !areAttrsSet)
value = slider.getAttribute('value');
if (!isAttrNum(value))
value = (min + max) / 2;;
// snap to step intervals (WebKit sometimes does not - bug?)
value = Math.round((value - min) / step) * step + min;
if (value < min)
value = min;
else if (value > max)
value = min + ~~(range / step) * step;
}
// renders slider using CSS background ;)
function draw(attrsModified) {
calc();
var wasUI = isUI;
isUI = false;
if (wasUI && value != prevValue)
slider.dispatchEvent(onInput);
if (!attrsModified && value == prevValue)
return;
prevValue = value;
var position = range ? (value - min) / range * 100 : 0;
var bg = '-moz-element(#__sliderthumb__) ' + position + '% no-repeat, ';
style(slider, { background: bg + track });
}
}
function style(element, styles) {
for (var prop in styles)
element.style.setProperty(prop, styles[prop], 'important');
}
})();

@ -1,90 +0,0 @@
<!DOCTYPE html>
<html class="no-js no-browser" lang="en">
<head>
<meta charset="utf-8">
<title>{{pkg.displayName}} {{pkg.version}} · Demo</title>
<meta name="description" content="demo for the jQuery plug in jQuery.qrcode (http://larsjung.de/qrcode/)">
<meta name="author" content="Lars Jung">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="author" href="http://plus.google.com/106403733398479106535">
<link rel="shortcut icon" href="dummy.png" type="image/png">
<link rel="apple-touch-icon" href="dummy.png" type="image/png">
<link href='http://fonts.googleapis.com/css?family=Ubuntu:400,700' rel='stylesheet'>
<link href='styles.css' rel='stylesheet'>
<script src="jquery-1.10.2.js"></script>
<script src="../jquery.qrcode-{{pkg.version}}.js"></script>
<script src="ff-range.js"></script>
<script src="scripts.js"></script>
</head>
<body>
<div id="container"></div>
<div class="control left">
<a id="banner" href="http://larsjung.de/qrcode/">{{pkg.displayName}} {{pkg.version}}</a>
<hr/>
<label for="render">RENDER MODE</label>
<select id="render">
<option value="canvas" selected="selected">Canvas</option>
<option value="image">Image</option>
<option value="div">DIV</option>
</select>
<hr/>
<label for="size">SIZE:</label>
<input id="size" type="range" value="400" min="100" max="1000" step="50" />
<label for="fill">FILL</label>
<input id="fill" type="color" value="#333333" />
<label for="background">BACKGROUND</label>
<input id="background" type="color" value="#ffffff" />
<label for="text">CONTENT</label>
<textarea id="text">http://larsjung.de/qrcode/</textarea>
<hr/>
<label for="minversion">MIN VERSION:</label>
<input id="minversion" type="range" value="6" min="1" max="10" step="1" />
<label for="eclevel">ERROR CORRECTION LEVEL</label>
<select id="eclevel">
<option value="L">L - Low (7%)</option>
<option value="M">M - Medium (15%)</option>
<option value="Q">Q - Quartile (25%)</option>
<option value="H" selected="selected">H - High (30%)</option>
</select>
<label for="quiet">QUIET ZONE:</label>
<input id="quiet" type="range" value="1" min="0" max="4" step="1" />
<label for="radius">CORNER RADIUS (not in Opera):</label>
<input id="radius" type="range" value="50" min="0" max="50" step="10" />
</div>
<div class="control right">
<label for="mode">MODE</label>
<select id="mode">
<option value="0">0 - Normal</option>
<option value="1">1 - Label-Strip</option>
<option value="2" selected="selected">2 - Label-Box</option>
<option value="3">3 - Image-Strip</option>
<option value="4">4 - Image-Box</option>
</select>
<hr/>
<label for="msize">SIZE:</label>
<input id="msize" type="range" value="11" min="0" max="40" step="1" />
<label for="mposx">POS X:</label>
<input id="mposx" type="range" value="50" min="0" max="100" step="1" />
<label for="mposy">POS Y:</label>
<input id="mposy" type="range" value="50" min="0" max="100" step="1" />
<hr/>
<label for="label">LABEL</label>
<input id="label" type="text" value="jQuery.qrcode" />
<label for="font">FONT NAME</label>
<input id="font" type="text" value="Ubuntu" />
<label for="fontcolor">FONT COLOR:</label>
<input id="fontcolor" type="color" value="#ff9818" />
<hr/>
<label for="image">IMAGE</label>
<input id="image" type="file" />
</div>
<img id="img-buffer" src="dummy.png" />
</body>
</html>

@ -0,0 +1,83 @@
doctype html
html(lang='en')
head
meta(charset='utf-8')
meta(http-equiv='x-ua-compatible', content='ie=edge')
title #{pkg.displayName} #{pkg.version} · Demo
meta(name='description', content='demo for #{pkg.displayName} (#{pkg.homepage})')
meta(name='viewport', content='width=device-width, initial-scale=1')
link(rel='shortcut icon', type='image/png', href='dummy.png')
link(rel='apple-touch-icon-precomposed', type='image/png', href='dummy.png')
link(href='//fonts.googleapis.com/css?family=Ubuntu:300,400,700', rel='stylesheet')
link(href='styles.css', rel='stylesheet')
script(src='jquery-1.11.3.min.js')
script(src='../jquery.qrcode-#{pkg.version}.js')
script(src='scripts.js')
body
div#container
div.control.left
a#banner(href='#{pkg.homepage}') #{pkg.displayName} #{pkg.version}
hr
label(for='render') RENDER MODE
select#render
option(value='canvas', selected='selected') canvas
option(value='image') image
option(value='div') div
hr
label(for='size') SIZE:
input#size(type='range', value='400', min='100', max='1000', step='50')
label(for='fill') FILL
input#fill(type='color', value='#333333')
label(for='background') BACKGROUND
input#background(type='color', value='#ffffff')
label(for='text') CONTENT
textarea#text #{pkg.homepage}
hr
label(for='minversion') MIN VERSION:
input#minversion(type='range', value='6', min='1', max='10', step='1')
label(for='eclevel') ERROR CORRECTION LEVEL
select#eclevel
option(value='L') L - Low (7%)
option(value='M') M - Medium (15%)
option(value='Q') Q - Quartile (25%)
option(value='H', selected='selected') H - High (30%)
label(for='quiet') QUIET ZONE:
input#quiet(type='range', value='1', min='0', max='4', step='1')
label(for='radius') CORNER RADIUS:
input#radius(type='range', value='50', min='0', max='50', step='10')
div.control.right
label(for='mode') MODE
select#mode
option(value='0') 0 - Normal
option(value='1') 1 - Label-Strip
option(value='2', selected='selected') 2 - Label-Box
option(value='3') 3 - Image-Strip
option(value='4') 4 - Image-Box
hr
label(for='msize') SIZE:
input#msize(type='range', value='11', min='0', max='40', step='1')
label(for='mposx') POS X:
input#mposx(type='range', value='50', min='0', max='100', step='1')
label(for='mposy') POS Y:
input#mposy(type='range', value='50', min='0', max='100', step='1')
hr
label(for='label') LABEL
input#label(type='text', value='#{pkg.displayName}')
label(for='font') FONT NAME
input#font(type='text', value='Ubuntu')
label(for='fontcolor') FONT COLOR
input#fontcolor(type='color', value='#ff9818')
hr
label(for='image') IMAGE
input#image(type='file')
img#img-buffer(src='dummy.png')

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

@ -2,101 +2,88 @@
'use strict'; 'use strict';
var $ = jQuery; var $ = jQuery;
var guiValuePairs = [
var isOpera = Object.prototype.toString.call(window.opera) === '[object Opera]', ['size', 'px'],
['minversion', ''],
guiValuePairs = [ ['quiet', ' modules'],
["size", "px"], ['radius', '%'],
["minversion", ""], ['msize', '%'],
["quiet", " modules"], ['mposx', '%'],
["radius", "%"], ['mposy', '%']
["msize", "%"], ];
["mposx", "%"],
["mposy", "%"] function updateGui() {
],
updateGui = function () {
$.each(guiValuePairs, function (idx, pair) { $.each(guiValuePairs, function (idx, pair) {
var $label = $('label[for="' + pair[0] + '"]'); var $label = $('label[for="' + pair[0] + '"]');
$label.text($label.text().replace(/:.*/, ': ' + $('#' + pair[0]).val() + pair[1])); $label.text($label.text().replace(/:.*/, ': ' + $('#' + pair[0]).val() + pair[1]));
}); });
}, }
updateQrCode = function () { function updateQrCode() {
var options = { var options = {
render: $("#render").val(), render: $('#render').val(),
ecLevel: $("#eclevel").val(), ecLevel: $('#eclevel').val(),
minVersion: parseInt($("#minversion").val(), 10), minVersion: parseInt($('#minversion').val(), 10),
fill: $("#fill").val(), fill: $('#fill').val(),
background: $("#background").val(), background: $('#background').val(),
// fill: $("#img-buffer")[0], // fill: $('#img-buffer')[0],
text: $("#text").val(), text: $('#text').val(),
size: parseInt($("#size").val(), 10), size: parseInt($('#size').val(), 10),
radius: parseInt($("#radius").val(), 10) * 0.01, radius: parseInt($('#radius').val(), 10) * 0.01,
quiet: parseInt($("#quiet").val(), 10), quiet: parseInt($('#quiet').val(), 10),
mode: parseInt($("#mode").val(), 10), mode: parseInt($('#mode').val(), 10),
mSize: parseInt($("#msize").val(), 10) * 0.01, mSize: parseInt($('#msize').val(), 10) * 0.01,
mPosX: parseInt($("#mposx").val(), 10) * 0.01, mPosX: parseInt($('#mposx').val(), 10) * 0.01,
mPosY: parseInt($("#mposy").val(), 10) * 0.01, mPosY: parseInt($('#mposy').val(), 10) * 0.01,
label: $("#label").val(), label: $('#label').val(),
fontname: $("#font").val(), fontname: $('#font').val(),
fontcolor: $("#fontcolor").val(), fontcolor: $('#fontcolor').val(),
image: $("#img-buffer")[0] image: $('#img-buffer')[0]
}; };
$("#container").empty().qrcode(options); $('#container').empty().qrcode(options);
}, }
update = function () { function update() {
updateGui(); updateGui();
updateQrCode(); updateQrCode();
}, }
onImageInput = function () {
var input = $("#image")[0]; function onImageInput() {
var input = $('#image')[0];
if (input.files && input.files[0]) { if (input.files && input.files[0]) {
var reader = new FileReader(); var reader = new FileReader();
reader.onload = function (event) { reader.onload = function (event) {
$("#img-buffer").attr("src", event.target.result); $('#img-buffer').attr('src', event.target.result);
$("#mode").val("4"); $('#mode').val('4');
setTimeout(update, 250); setTimeout(update, 250);
}; };
reader.readAsDataURL(input.files[0]); reader.readAsDataURL(input.files[0]);
} }
}, }
download = function (event) { function download() {
var data = $("#container canvas")[0].toDataURL('image/png'); $('#download').attr('href', $('#container canvas')[0].toDataURL('image/png'));
$("#download").attr("href", data); }
};
$(function () { $(function () {
if (isOpera) { $('#download').on('click', download);
$('html').addClass('opera'); $('#image').on('change', onImageInput);
$('#radius').prop('disabled', true); $('input, textarea, select').on('input change', update);
}
$("#download").on("click", download);
$("#image").on('change', onImageInput);
$("input, textarea, select").on("input change", update);
$(window).load(update); $(window).load(update);
update(); update();
}); });

@ -1,9 +1,9 @@
body { body {
font-family: Ubuntu; font-family: 'Ubuntu', 'Arial', 'sans';
margin: 0; margin: 0;
padding: 0; padding: 0;
text-align: center; text-align: center;
background: repeat url("back.png"); background: repeat url('back.png');
} }
#banner { #banner {
@ -56,14 +56,10 @@ hr {
label { label {
font-size: 10px; font-size: 10px;
color: #bbb; color: #aaa;
padding: 12px 4px 0 4px; padding: 12px 4px 0 4px;
} }
html.opera label[for="radius"] {
color: #e55;
}
#download { #download {
text-align: center; text-align: center;
font-weight: bold; font-weight: bold;
@ -78,7 +74,7 @@ html.opera label[for="radius"] {
} }
input, textarea, select { input, textarea, select {
font-family: Ubuntu; font-family: 'Ubuntu', 'Arial', 'sans';
display: block; display: block;
background-color: #fff; background-color: #fff;
margin: 2px; margin: 2px;
@ -96,12 +92,11 @@ input, textarea, select {
display: none; display: none;
} }
input[type='range'] {
input[type="range"] {
-webkit-appearance: none; -webkit-appearance: none;
cursor: pointer; cursor: pointer;
} }
input::-webkit-slider-thumb { input::-webkit-slider-thumb {
-webkit-appearance: none; -webkit-appearance: none;
width: 16px; width: 16px;

@ -1,4 +1,4 @@
(function () { (function (qrcode) {
'use strict'; 'use strict';
var $ = jQuery; var $ = jQuery;
@ -6,8 +6,6 @@ var $ = jQuery;
// Wrapper for the original QR code generator. // Wrapper for the original QR code generator.
function QRCode(text, level, version, quiet) { function QRCode(text, level, version, quiet) {
// `qrcode` is the single public function that will be defined by the `QR Code Generator`
// at the end of the file.
var qr = qrcode(version, level); var qr = qrcode(version, level);
qr.addData(text); qr.addData(text);
qr.make(); qr.make();
@ -57,7 +55,7 @@ function QRCode(text, level, version, quiet) {
var hasCanvas = (function () { var hasCanvas = (function () {
var elem = document.createElement('canvas'); var elem = document.createElement('canvas');
return !!(elem.getContext && elem.getContext('2d')); return Boolean(elem.getContext && elem.getContext('2d'));
}()); }());
var hasArcTo = Object.prototype.toString.call(window.opera) !== '[object Opera]'; var hasArcTo = Object.prototype.toString.call(window.opera) !== '[object Opera]';
@ -77,8 +75,8 @@ function createQRCode(text, level, minVersion, maxVersion, quiet) {
function drawBackgroundLabel(qr, context, settings) { function drawBackgroundLabel(qr, context, settings) {
var size = settings.size; var size = settings.size;
var font = "bold " + (settings.mSize * size) + "px " + settings.fontname; var font = 'bold ' + (settings.mSize * size) + 'px ' + settings.fontname;
var ctx = $('<canvas/>')[0].getContext("2d"); var ctx = $('<canvas/>')[0].getContext('2d');
ctx.font = font; ctx.font = font;
@ -252,7 +250,8 @@ function drawModules(qr, context, settings) {
var moduleCount = qr.moduleCount; var moduleCount = qr.moduleCount;
var moduleSize = settings.size / moduleCount; var moduleSize = settings.size / moduleCount;
var fn = drawModuleDefault; var fn = drawModuleDefault;
var row, col; var row;
var col;
if (hasArcTo && settings.radius > 0 && settings.radius <= 0.5) { if (hasArcTo && settings.radius > 0 && settings.radius <= 0.5) {
fn = drawModuleRounded; fn = drawModuleRounded;
@ -262,9 +261,9 @@ function drawModules(qr, context, settings) {
for (row = 0; row < moduleCount; row += 1) { for (row = 0; row < moduleCount; row += 1) {
for (col = 0; col < moduleCount; col += 1) { for (col = 0; col < moduleCount; col += 1) {
var l = settings.left + col * moduleSize, var l = settings.left + col * moduleSize;
t = settings.top + row * moduleSize, var t = settings.top + row * moduleSize;
w = moduleSize; var w = moduleSize;
fn(qr, context, settings, l, t, w, row, col); fn(qr, context, settings, l, t, w, row, col);
} }
@ -274,7 +273,7 @@ function drawModules(qr, context, settings) {
context.lineWidth = 2; context.lineWidth = 2;
context.stroke(); context.stroke();
var prev = context.globalCompositeOperation; var prev = context.globalCompositeOperation;
context.globalCompositeOperation = "destination-out"; context.globalCompositeOperation = 'destination-out';
context.fill(); context.fill();
context.globalCompositeOperation = prev; context.globalCompositeOperation = prev;
@ -334,7 +333,8 @@ function createDiv(settings) {
var moduleSize = math_floor(settings_size / moduleCount); var moduleSize = math_floor(settings_size / moduleCount);
var offset = math_floor(0.5 * (settings_size - moduleSize * moduleCount)); var offset = math_floor(0.5 * (settings_size - moduleSize * moduleCount));
var row, col; var row;
var col;
var containerCSS = { var containerCSS = {
position: 'relative', position: 'relative',
@ -461,12 +461,10 @@ $.fn.qrcode = function(options) {
} }
}); });
}; };
}(function () {
// jQuery.qrcode plug in code ends here // `qrcode` is the single public function defined by the `QR Code Generator`
// @include "lib/qrcode.js"
// @include "lib/qrcode_UTF8.js"
// QR Code Generator return qrcode;
// ================= }()));
// @include "qrcode.js"
}());

File diff suppressed because it is too large Load Diff

@ -0,0 +1,59 @@
//---------------------------------------------------------------------
//
// QR Code Generator for JavaScript UTF8 Support (optional)
//
// Copyright (c) 2011 Kazuhiko Arase
//
// URL: http://www.d-project.com/
//
// Licensed under the MIT license:
// http://www.opensource.org/licenses/mit-license.php
//
// The word 'QR Code' is registered trademark of
// DENSO WAVE INCORPORATED
// http://www.denso-wave.com/qrcode/faqpatent-e.html
//
//---------------------------------------------------------------------
!function(qrcode) {
//---------------------------------------------------------------------
// overwrite qrcode.stringToBytes
//---------------------------------------------------------------------
qrcode.stringToBytes = function(s) {
// http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
function toUTF8Array(str) {
var utf8 = [];
for (var i=0; i < str.length; i++) {
var charcode = str.charCodeAt(i);
if (charcode < 0x80) utf8.push(charcode);
else if (charcode < 0x800) {
utf8.push(0xc0 | (charcode >> 6),
0x80 | (charcode & 0x3f));
}
else if (charcode < 0xd800 || charcode >= 0xe000) {
utf8.push(0xe0 | (charcode >> 12),
0x80 | ((charcode>>6) & 0x3f),
0x80 | (charcode & 0x3f));
}
// surrogate pair
else {
i++;
// UTF-16 encodes 0x10000-0x10FFFF by
// subtracting 0x10000 and splitting the
// 20 bits of 0x0-0xFFFFF into two halves
charcode = 0x10000 + (((charcode & 0x3ff)<<10)
| (str.charCodeAt(i) & 0x3ff));
utf8.push(0xf0 | (charcode >>18),
0x80 | ((charcode>>12) & 0x3f),
0x80 | ((charcode>>6) & 0x3f),
0x80 | (charcode & 0x3f));
}
}
return utf8;
}
return toUTF8Array(s);
};
}(qrcode);

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save