]> git.immae.eu Git - github/shaarli/Shaarli.git/blame_incremental - plugins/qrcode/shaarli-qrcode.js
Markdown: inline code background color
[github/shaarli/Shaarli.git] / plugins / qrcode / shaarli-qrcode.js
... / ...
CommitLineData
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 // Show the QRCode
42 qrcodeImage = document.getElementById('permalinkQrcode');
43 // Workaround to deal with newly created element lag for transition.
44 window.getComputedStyle(qrcodeImage).opacity;
45 qrcodeImage.className = 'show';
46 }
47 else
48 {
49 element.innerHTML = "Your browser does not seem to be HTML5 compatible.";
50 }
51 return false;
52}
53
54// Remove any displayed QR-Code
55function removeQrcode()
56{
57 var elem = document.getElementById('permalinkQrcode');
58 if (elem) {
59 elem.parentNode.removeChild(elem);
60 }
61 return false;
62}