-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscancode.html
114 lines (98 loc) · 2.67 KB
/
scancode.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<link rel="import" href="lib/polymer.html">
<script type="text/javascript" src="lib/jquery.min.js"></script>
<script type="text/javascript" src="lib/jquery-barcode.min.js"></script>
<script type="text/javascript" src="lib/qrcode.js"></script>
<polymer-element name="scan-code">
<dom-module id="scan-code">
<template>
<div id='scancode' style="text-align:center;"></div>
</template>
</dom-module>
<script>
Polymer({
is: "scan-code",
properties: {
data: { type: String, observer: 'dataChanged'},
type: { type: String, observer: 'typeChanged'},
format: { type: String, observer: 'formatChanged'},
height: { type: String, observer: 'heightChanged'},
width: { type: String, observer: 'widthChanged'},
colordark: { type: String, observer: 'colorDarkChanged'},
colorlight: { type: String, observer: 'colorLightChanged'}
},
ready: function(){
this.generate();
},
dataChanged: function () {
this.generate();
},
typeChanged: function () {
this.generate();
},
formatChanged: function () {
this.generate();
},
heightChanged: function () {
this.generate();
},
widthChanged: function () {
this.generate();
console.log("changed");
},
colorDarkChanged: function () {
console.log("changed");
this.generate();
},
colorLightChanged: function () {
console.log("changed");
this.generate();
},
generate : function(){
//console.dir(this.type);
try{
if (this.type === 'barcode') {
this.generateBarcode();
}
else if (this.type === 'qrcode'){
this.generateQRcode()
}
else{
console.log("Not Rendering scancode");
var el = this.$.scancode;
el.innerHTML = "";
}
}
catch(err) {
console.dir(err);
}
},
generateQRcode: function(){
var el = this.$.scancode;
el.innerHTML = "";
//console.log(this.colorDark);
var qrcode = new QRCode(el, {
text: this.data,
width: this.width,
height: this.height,
colorDark : this.colordark || "#000000",
colorLight : this.colorlight || "#ffffff",
correctLevel : QRCode.CorrectLevel.H
});
},
generateBarcode: function(){
var el = this.$.scancode;
$(el).barcode(
{
code: this.data,
crc:false
},
this.format || "codabar",
{
barWidth:this.width,
barHeight:this.height
}
);
}
});
</script>
</polymer-element>