diff options
author | Arthur <arthur@hoa.ro> | 2015-11-07 16:52:53 +0100 |
---|---|---|
committer | Arthur <arthur@hoa.ro> | 2015-11-07 16:52:53 +0100 |
commit | c536c98ae134191108171d266b73326d6b851f93 (patch) | |
tree | b6f43bc921f1a1f7b08ecfd368fe6aa9e3ffc748 /plugins/qrcode/shaarli-qrcode.js | |
parent | 1b4ea59f93386594a6e6f35e581244b65c2db57f (diff) | |
parent | abb3ff38f5aea6231f981fd2e6d417f09de7a6e6 (diff) | |
download | Shaarli-c536c98ae134191108171d266b73326d6b851f93.tar.gz Shaarli-c536c98ae134191108171d266b73326d6b851f93.tar.zst Shaarli-c536c98ae134191108171d266b73326d6b851f93.zip |
Merge pull request #285 from ArthurHoaro/plugin-qrcode
PLUGIN QRCode
Diffstat (limited to 'plugins/qrcode/shaarli-qrcode.js')
-rw-r--r-- | plugins/qrcode/shaarli-qrcode.js | 56 |
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). | ||
2 | function 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 | ||
49 | function 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 | ||