commit
4083ec4d12
@ -0,0 +1,23 @@
|
||||
|
||||
# Build files and folders to ignore
|
||||
build
|
||||
release
|
||||
|
||||
# Local
|
||||
local.makefile
|
||||
build.local.xml
|
||||
*.sublime-*
|
||||
.ant-targets*
|
||||
|
||||
# Numerous always-ignore extensions
|
||||
*.ant-targets-build.xml
|
||||
*.diff
|
||||
*.err
|
||||
*.orig
|
||||
*.log
|
||||
*.rej
|
||||
*.swo
|
||||
*.swp
|
||||
*.vi
|
||||
*~
|
||||
*.sass-cache
|
@ -0,0 +1,19 @@
|
||||
Copyright (c) 2012 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
|
||||
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.
|
@ -0,0 +1,14 @@
|
||||
# jQuery.qrcode
|
||||
|
||||
* Website with download, docs and demo: <http://larsjung.de/qrcode>
|
||||
* Sources: <http://github.com/lrsjng/jQuery.qrcode>
|
||||
|
||||
jQuery.qrcode is provided under the terms of the [MIT License](http://github.com/lrsjng/jQuery.qrcode/blob/master/LICENSE.txt).
|
||||
|
||||
Uses [QR Code Generator](http://www.d-project.com/qrcode/index.html) (MIT). Kudos to [jquery.qrcode.js](http://github.com/jeromeetienne/jquery-qrcode) (MIT).
|
||||
|
||||
## Changelog
|
||||
|
||||
### v0.1 - *2012-07-01*
|
||||
|
||||
* Initial release
|
@ -0,0 +1,16 @@
|
||||
|
||||
# project
|
||||
project.name = jquery.qrcode
|
||||
project.version = 0.1
|
||||
|
||||
# src
|
||||
src.dir = src
|
||||
|
||||
# build
|
||||
build.dir = build
|
||||
release.dir = release
|
||||
|
||||
# tools
|
||||
tool.wepp = wepp
|
||||
tool.docco = docco
|
||||
tool.jshint = jshint
|
@ -0,0 +1,115 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project
|
||||
name="jQuery.qrcode"
|
||||
basedir="."
|
||||
default="release"
|
||||
>
|
||||
|
||||
<target name="init">
|
||||
<property file="build.properties" />
|
||||
<tstamp><format property="build.stamp" pattern="yyyy-MM-dd-HHmmss" /></tstamp>
|
||||
<property name="build.label" value="${project.name} ${project.version} b${build.stamp}" />
|
||||
<echo>Build: ${build.label}</echo>
|
||||
</target>
|
||||
|
||||
<target name="clean" depends="init">
|
||||
<delete dir="${build.dir}" />
|
||||
<delete dir="${release.dir}" />
|
||||
</target>
|
||||
|
||||
<target name="build" depends="clean">
|
||||
<mkdir dir="${build.dir}" />
|
||||
<copy todir="${build.dir}">
|
||||
<fileset dir="${src.dir}" />
|
||||
<fileset file="LICENSE.txt" />
|
||||
<fileset file="README.md" />
|
||||
</copy>
|
||||
<replace dir="${build.dir}">
|
||||
<replacefilter token="%BUILD%" value="${build.label}" />
|
||||
<replacefilter token="%BUILD_NAME%" value="${project.name}" />
|
||||
<replacefilter token="%BUILD_VERSION%" value="${project.version}" />
|
||||
<replacefilter token="%BUILD_STAMP%" value="${build.stamp}" />
|
||||
</replace>
|
||||
|
||||
<!-- qrcode -->
|
||||
<wepp file="${build.dir}/jquery.qrcode.js" tofile="${build.dir}/jquery.qrcode-${project.version}.js" />
|
||||
<wepp-min file="${build.dir}/jquery.qrcode.js" tofile="${build.dir}/jquery.qrcode-${project.version}.min.js" />
|
||||
<delete file="${build.dir}/qrcode.js" />
|
||||
<delete file="${build.dir}/jquery.qrcode.js" />
|
||||
|
||||
<!-- docs -->
|
||||
<docco dir="${build.dir}" files="jquery.qrcode-${project.version}.js" />
|
||||
</target>
|
||||
|
||||
<target name="release" depends="build">
|
||||
<mkdir dir="${release.dir}" />
|
||||
<zip destfile="${release.dir}/${project.name}-${project.version}.zip" basedir="${build.dir}" />
|
||||
</target>
|
||||
|
||||
<target name="jshint" depends="init">
|
||||
<exec executable="${tool.jshint}">
|
||||
<arg line="${src.dir}/jquery.qrcode.js" />
|
||||
<arg line="--config jshint.json" />
|
||||
<arg line="--show-non-errors" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
|
||||
<macrodef name="wepp-args">
|
||||
<attribute name="args" default="" />
|
||||
<sequential>
|
||||
<exec executable="${tool.wepp}" failonerror="true">
|
||||
<arg line="@{args}" />
|
||||
</exec>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<macrodef name="wepp">
|
||||
<attribute name="file" />
|
||||
<attribute name="tofile" />
|
||||
<sequential>
|
||||
<wepp-args args="--nc --inFile '@{file}' --outFile '@{toFile}'" />
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<macrodef name="wepp-min">
|
||||
<attribute name="file" />
|
||||
<attribute name="tofile" />
|
||||
<sequential>
|
||||
<wepp-args args="--zs --inFile '@{file}' --outFile '@{toFile}'" />
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<macrodef name="wepp-dir">
|
||||
<attribute name="dir" />
|
||||
<attribute name="todir" />
|
||||
<sequential>
|
||||
<wepp-args args="--nc --inDir '@{dir}' --outDir '@{todir}'" />
|
||||
<delete dir="@{todir}/inc" >
|
||||
<fileset dir="." includes="@{todir}/**/*.less" />
|
||||
</delete>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<macrodef name="wepp-dir-min">
|
||||
<attribute name="dir" />
|
||||
<attribute name="todir" />
|
||||
<sequential>
|
||||
<wepp-args args="--inDir '@{dir}' --outDir '@{todir}'" />
|
||||
<delete dir="@{todir}/inc" >
|
||||
<fileset dir="." includes="@{todir}/**/*.less" />
|
||||
</delete>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
<macrodef name="docco">
|
||||
<attribute name="dir" />
|
||||
<attribute name="files" />
|
||||
<sequential>
|
||||
<exec executable="${tool.docco}" dir="@{dir}" failonerror="true">
|
||||
<arg line="@{files}" />
|
||||
</exec>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
|
||||
</project>
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
// 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"
|
||||
]
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
/*! jQuery.qrcode %BUILD_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).
|
||||
|
||||
(function ($) {
|
||||
'use strict';
|
||||
|
||||
// Wrapper for the original QR code generator.
|
||||
var createQr = function (typeNumber, correctLevel, text) {
|
||||
|
||||
// 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);
|
||||
qr.make();
|
||||
|
||||
return qr;
|
||||
},
|
||||
|
||||
// Returns a minimal QR code for the given text. Returns `null` if `text`
|
||||
// is to long to be encoded. At the moment it should work with up to 271 characters.
|
||||
createBestQr = function (text) {
|
||||
|
||||
for (var type = 2; type <= 10; type += 1) {
|
||||
try {
|
||||
return createQr(type, 'L', text);
|
||||
} catch (err) {}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
// Returns a `canvas` element representing the QR code for the given settings.
|
||||
createCanvas = function (settings) {
|
||||
|
||||
var qr = createBestQr(settings.text),
|
||||
$canvas = $('<canvas/>').attr('width', settings.width).attr('height', settings.height),
|
||||
ctx = $canvas[0].getContext('2d');
|
||||
|
||||
if (settings.bgColor) {
|
||||
ctx.fillStyle = settings.bgColor;
|
||||
ctx.fillRect(0, 0, settings.width, settings.height);
|
||||
}
|
||||
|
||||
if (qr) {
|
||||
var moduleCount = qr.getModuleCount(),
|
||||
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.fillStyle = settings.color;
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
return $canvas;
|
||||
},
|
||||
|
||||
// Returns a `div` element representing the QR code for the given settings.
|
||||
createDiv = function (settings) {
|
||||
|
||||
var qr = createBestQr(settings.text),
|
||||
$div = $('<div/>').css({
|
||||
position: 'relative',
|
||||
left: 0,
|
||||
top: 0,
|
||||
padding: 0,
|
||||
margin: 0,
|
||||
width: settings.width,
|
||||
height: settings.height
|
||||
});
|
||||
|
||||
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)),
|
||||
row, col;
|
||||
|
||||
for (row = 0; row < moduleCount; row += 1) {
|
||||
for (col = 0; col < moduleCount; col += 1) {
|
||||
if (qr.isDark(row, col)) {
|
||||
$('<div/>')
|
||||
.css({
|
||||
left: offsetLeft + col * moduleWidth,
|
||||
top: offsetTop + row * moduleHeight
|
||||
})
|
||||
.appendTo($div);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$div.children()
|
||||
.css({
|
||||
position: 'absolute',
|
||||
padding: 0,
|
||||
margin: 0,
|
||||
width: moduleWidth,
|
||||
height: moduleHeight,
|
||||
'background-color': settings.color
|
||||
});
|
||||
}
|
||||
|
||||
return $div;
|
||||
},
|
||||
|
||||
// Plugin
|
||||
// ======
|
||||
|
||||
// Default settings
|
||||
// ----------------
|
||||
defaults = {
|
||||
|
||||
// render method: `'canvas'` or `'div'`
|
||||
render: 'canvas',
|
||||
|
||||
// width and height in pixel
|
||||
width: 256,
|
||||
height: 256,
|
||||
|
||||
// code color
|
||||
color: '#000',
|
||||
|
||||
// background color, `null` for transparent background
|
||||
bgColor: null,
|
||||
|
||||
// the encoded text
|
||||
text: 'no text'
|
||||
};
|
||||
|
||||
// Register the plugin
|
||||
// -------------------
|
||||
$.fn.qrcode = function(options) {
|
||||
|
||||
var settings = $.extend({}, defaults, options);
|
||||
|
||||
return this.each(function () {
|
||||
|
||||
$(this).append(settings.render === 'canvas' ? createCanvas(settings) : createDiv(settings));
|
||||
});
|
||||
};
|
||||
|
||||
// jQuery.qrcode plug in code ends here
|
||||
|
||||
// QR Code Generator
|
||||
// =================
|
||||
// @include "qrcode.js"
|
||||
|
||||
}(jQuery));
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue