Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Support for node webkit #2

Merged
merged 2 commits into from

2 participants

@pose

The following commits add support to use with node-webkit together with an example of how to use it.

@vicapow vicapow merged commit 13b0dc7 into from
@vicapow
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 9, 2014
  1. @pose
  2. @pose

    Adding node-webkit example.

    pose authored
This page is out of date. Refresh to see the latest.
View
3  examples/node-webkit/README.md
@@ -0,0 +1,3 @@
+### Running the example
+
+Just execute `nw .` on this directory.
View
40 examples/node-webkit/index.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title></title>
+ <style>
+ body, html {
+ padding: 0;
+ margin: 0;
+ width: 100%;
+ height: 100%;
+ }
+
+ #holder {
+ border: 10px dashed #ccc;
+ width: 100%;
+ height: 100%;
+ margin: 0;
+ -webkit-box-sizing:border-box;
+ text-align: center;
+ font-size: 48pt;
+ font-family: Helvetica;
+ padding: 30px;
+ color: black;
+ }
+
+ #holder.shake {
+ border-color: red;
+ color: red;
+ }
+
+ #holder.hover {
+ border: 10px dashed #333;
+ }
+ </style>
+ </head>
+ <body>
+ <div id="holder"></div>
+ <script src="index.js"></script>
+ </body>
+</html>
View
37 examples/node-webkit/index.js
@@ -0,0 +1,37 @@
+var qrcode = require('../../src/qrcode')();
+
+// prevent default behavior from changing page on dropped file
+window.ondragover = function(e) {
+ e.preventDefault();
+ return false;
+};
+window.ondrop = function(e) {
+ e.preventDefault();
+ return false;
+};
+
+var holder = document.getElementById('holder');
+holder.ondragover = function () { this.className = 'hover'; return false; };
+holder.ondragend = function () { this.className = ''; return false; };
+holder.ondrop = function (e) {
+ e.preventDefault();
+ holder.innerText = '';
+ var fileName = e.dataTransfer.files[0].path;
+
+ var image = new Image();
+
+ image.onload = function () {
+ var result;
+ try{
+ result = qrcode.decode(image);
+ alert('result of qr code: ' + result);
+ } catch(e) {
+ console.log('unable to read qr code' + e.stack);
+ }
+ };
+
+ image.src = fileName;
+
+ return false;
+};
+
View
11 examples/node-webkit/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "jsqrcode-node-webkit-example",
+ "version": "0.0.1",
+ "main": "index.html",
+ "window": {
+ "toolbar": false,
+ "width": 612,
+ "height": 310
+ }
+}
+
View
0  examples/qrcode.png → examples/node/qrcode.png
File renamed without changes
View
0  examples/test.js → examples/node/test.js
File renamed without changes
View
7 src/QRCode.js
@@ -24,6 +24,11 @@ module.exports = function(Canvas){
var Image = null, isCanvas = null, createCanvas = null;
if(typeof window!='undefined') {
+ // XXX Fix for node-webkit not finding HTMLCanvasElement and document
+ // outside window.
+ HTMLCanvasElement = window.HTMLCanvasElement;
+ document = window.document;
+
// we're in the browser
if(typeof HTMLCanvasElement !== 'undefined' ){
createCanvas = function(width,height){
@@ -246,4 +251,4 @@ module.exports = function(Canvas){
return (number >> bits) + (2 << ~bits);
}
return qrcode;
-}
+}
Something went wrong with that request. Please try again.