aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins/qrcode/shaarli-qrcode.js
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/qrcode/shaarli-qrcode.js')
-rw-r--r--plugins/qrcode/shaarli-qrcode.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/plugins/qrcode/shaarli-qrcode.js b/plugins/qrcode/shaarli-qrcode.js
new file mode 100644
index 00000000..0a8de21d
--- /dev/null
+++ b/plugins/qrcode/shaarli-qrcode.js
@@ -0,0 +1,56 @@
1// Show the QR-Code of a permalink (when the QR-Code icon is clicked).
2function showQrCode(caller,loading)
3{
4 // Dynamic javascript lib loading: We only load qr.js if the QR code icon is clicked:
5 if (typeof(qr) == 'undefined') // Load qr.js only if not present.
6 {
7 if (!loading) // If javascript lib is still loading, do not append script to body.
8 {
9 var element = document.createElement("script");
10 element.src = "plugins/qrcode/qr-1.1.3.min.js";
11 document.body.appendChild(element);
12 }
13 setTimeout(function() { showQrCode(caller,true);}, 200); // Retry in 200 milliseconds.
14 return false;
15 }
16
17 // Remove previous qrcode if present.
18 removeQrcode();
19
20 // Build the div which contains the QR-Code:
21 var element = document.createElement('div');
22 element.id="permalinkQrcode";
23
24 // Make QR-Code div commit sepuku when clicked:
25 if ( element.attachEvent ){
26 element.attachEvent('onclick', 'this.parentNode.removeChild(this);' );
27
28 } else {
29 // Damn IE
30 element.setAttribute('onclick', 'this.parentNode.removeChild(this);' );
31 }
32
33 // Build the QR-Code:
34 var image = qr.image({size: 8,value: caller.dataset.permalink});
35 if (image)
36 {
37 element.appendChild(image);
38 element.innerHTML += "<br>Click to close";
39 caller.parentNode.appendChild(element);
40 }
41 else
42 {
43 element.innerHTML = "Your browser does not seem to be HTML5 compatible.";
44 }
45 return false;
46}
47
48// Remove any displayed QR-Code
49function removeQrcode()
50{
51 var elem = document.getElementById("permalinkQrcode");
52 if (elem) {
53 elem.parentNode.removeChild(elem);
54 }
55 return false;
56} \ No newline at end of file