Skip to content

Commit

Permalink
Adding node-webkit example.
Browse files Browse the repository at this point in the history
  • Loading branch information
pose committed Jun 9, 2014
1 parent 0f9f3fb commit 8768fbf
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/node-webkit/README.md
@@ -0,0 +1,3 @@
### Running the example

Just execute `nw .` on this directory.
40 changes: 40 additions & 0 deletions 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>
37 changes: 37 additions & 0 deletions 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;
};

11 changes: 11 additions & 0 deletions 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
}
}

File renamed without changes
File renamed without changes.

0 comments on commit 8768fbf

Please sign in to comment.