]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - plugins/qrcode/shaarli-qrcode.js
1 // Show the QR-Code of a permalink (when the QR-Code icon is clicked).
2 function showQrCode(caller
,loading
)
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.
7 if (!loading
) // If javascript lib is still loading, do not append script to body.
9 var element
= document
.createElement("script");
10 element
.src
= "plugins/qrcode/qr-1.1.3.min.js";
11 document
.body
.appendChild(element
);
13 setTimeout(function() { showQrCode(caller
,true);}, 200); // Retry in 200 milliseconds.
17 // Remove previous qrcode if present.
20 // Build the div which contains the QR-Code:
21 var element
= document
.createElement('div');
22 element
.id
= 'permalinkQrcode';
24 // Make QR-Code div commit sepuku when clicked:
25 if ( element
.attachEvent
){
26 element
.attachEvent('onclick', 'this.parentNode.removeChild(this);' );
30 element
.setAttribute('onclick', 'this.parentNode.removeChild(this);' );
34 var image
= qr
.image({size: 8,value: caller
.dataset
.permalink
});
37 element
.appendChild(image
);
38 element
.innerHTML
+= "<br>Click to close";
39 caller
.parentNode
.appendChild(element
);
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';
49 element
.innerHTML
= "Your browser does not seem to be HTML5 compatible.";
54 // Remove any displayed QR-Code
55 function removeQrcode()
57 var elem
= document
.getElementById('permalinkQrcode');
59 elem
.parentNode
.removeChild(elem
);