]>
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 element
= document
.createElement("script");
38 element
.src
= "plugins/qrcode/qr-1.1.3.min.js";
39 document
.body
.appendChild(element
);
41 setTimeout(function() { showQrCode(caller
,true);}, 200); // Retry in 200 milliseconds.
45 // Remove previous qrcode if present.
48 // Build the div which contains the QR-Code:
49 var element
= document
.createElement('div');
50 element
.id
= 'permalinkQrcode';
52 // Make QR-Code div commit sepuku when clicked:
53 if ( element
.attachEvent
){
54 element
.attachEvent('onclick', 'this.parentNode.removeChild(this);' );
58 element
.setAttribute('onclick', 'this.parentNode.removeChild(this);' );
62 var image
= qr
.image({size: 8,value: caller
.dataset
.permalink
});
65 element
.appendChild(image
);
66 element
.innerHTML
+= "<br>Click to close";
67 caller
.parentNode
.appendChild(element
);
70 qrcodeImage
= document
.getElementById('permalinkQrcode');
71 // Workaround to deal with newly created element lag for transition.
72 window
.getComputedStyle(qrcodeImage
).opacity
;
73 qrcodeImage
.className
= 'show';
77 element
.innerHTML
= "Your browser does not seem to be HTML5 compatible.";
82 // Remove any displayed QR-Code
83 function removeQrcode()
85 var elem
= document
.getElementById('permalinkQrcode');
87 elem
.parentNode
.removeChild(elem
);