]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - plugins/qrcode/shaarli-qrcode.js
1 /** @licstart The following is the entire license notice for the
2 * JavaScript code in this page.
4 * Copyright: (c) 2011-2015 Sébastien SAUVAGE <sebsauvage@sebsauvage.net>
5 * (c) 2011-2017 The Shaarli Community, see AUTHORS
7 * This software is provided 'as-is', without any express or implied warranty.
8 * In no event will the authors be held liable for any damages arising from
9 * the use of this software.
11 * Permission is granted to anyone to use this software for any purpose,
12 * including commercial applications, and to alter it and redistribute it
13 * freely, subject to the following restrictions:
15 * 1. The origin of this software must not be misrepresented; you must not
16 * claim that you wrote the original software. If you use this software
17 * in a product, an acknowledgment in the product documentation would
18 * be appreciated but is not required.
20 * 2. Altered source versions must be plainly marked as such, and must
21 * not be misrepresented as being the original software.
23 * 3. This notice may not be removed or altered from any source distribution.
25 * @licend The above is the entire license notice
26 * for the JavaScript code in this page.
29 // Show the QR-Code of a permalink (when the QR-Code icon is clicked).
30 function showQrCode(caller
,loading
)
32 // Dynamic javascript lib loading: We only load qr.js if the QR code icon is clicked:
33 if (typeof(qr
) == 'undefined') // Load qr.js only if not present.
35 if (!loading
) // If javascript lib is still loading, do not append script to body.
37 var basePath
= document
.querySelector('input[name="js_base_path"]').value
;
38 var element
= document
.createElement("script");
39 element
.src
= basePath
+ "/plugins/qrcode/qr-1.1.3.min.js";
40 document
.body
.appendChild(element
);
42 setTimeout(function() { showQrCode(caller
,true);}, 200); // Retry in 200 milliseconds.
46 // Remove previous qrcode if present.
49 // Build the div which contains the QR-Code:
50 var element
= document
.createElement('div');
51 element
.id
= 'permalinkQrcode';
53 // Make QR-Code div commit sepuku when clicked:
54 if ( element
.attachEvent
){
55 element
.attachEvent('onclick', 'this.parentNode.removeChild(this);' );
59 element
.setAttribute('onclick', 'this.parentNode.removeChild(this);' );
63 var image
= qr
.image({size: 8,value: caller
.dataset
.permalink
});
66 element
.appendChild(image
);
67 element
.innerHTML
+= "<br>Click to close";
68 caller
.parentNode
.appendChild(element
);
71 qrcodeImage
= document
.getElementById('permalinkQrcode');
72 // Workaround to deal with newly created element lag for transition.
73 window
.getComputedStyle(qrcodeImage
).opacity
;
74 qrcodeImage
.className
= 'show';
78 element
.innerHTML
= "Your browser does not seem to be HTML5 compatible.";
83 // Remove any displayed QR-Code
84 function removeQrcode()
86 var elem
= document
.getElementById('permalinkQrcode');
88 elem
.parentNode
.removeChild(elem
);