Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add qr encode preview #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions css/index.css
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
* {
-webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */
-webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */
-webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */
-webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */
-webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */
}

body {
Expand Down
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Barcode Scanner Demo</title>
</head>
<body>
<body class="platform-ios platform-cordova platform-webview">
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
<p><a href="#" class="topcoat-button" id="scan">SCAN</a></p>
<p><a href="#" class="topcoat-button" id="encode">ENCODE</a></p>
<div id="qr_encoder">
<p><a href="#" class="topcoat-button" id="encode">ENCODE</a></p>
<textarea rows ="8" cols="30" id="textToEncode">Enter text to encode to qr code!</textarea>
</div>
<p id="info"></p>
<h2>OPENING LINKS:</h2>
<p><a href="#" class="topcoat-button" onclick="window.open('http://www.nhl.com', '_blank', 'location=yes');">InAppBrowser</a></p>
Expand Down
30 changes: 24 additions & 6 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
this.bindEvents();
},
// Bind Event Listeners
//
Expand Down Expand Up @@ -82,14 +82,32 @@ var app = {

encode: function() {
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
var textToEncode = document.getElementById("textToEncode").value;
var qr_encode_div = document.getElementById("qr_encoder");
var qrImgTag = "qrcode";

scanner.encode(scanner.Encode.TEXT_TYPE, "http://www.nhl.com", function(success) {
alert("encode success: " + success);
scanner.encode(scanner.Encode.TEXT_TYPE, textToEncode, function(success) {
var img = document.getElementById("qrcode");

if(img != null){
img.src = success.file + "?lastmod=" + (Date.now() / 1000 | 0);
}
else{
img = document.createElement("img");
img.setAttribute("id", qrImgTag);
img.setAttribute("height", "250");
img.setAttribute("width", "250");
img.src = success.file + "?lastmod=" + (Date.now() / 1000 | 0);
qr_encode_div.appendChild(img);
}

}, function(fail) {
alert("encoding failed: " + fail);
var qrImg = document.getElementById(qrImgTag);
if(qrImg != null)
qr_encode_div.removeChild(qrImg);
alert("encoding failed: " + fail);

}
);

}

};