X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tpl%2Flinklist.html;h=d5bfadf8669eb5b898d78925a0b5588443e354b7;hb=refs%2Fpull%2F93%2Fhead;hp=42a75a1af7be4059caf58c701e1ec4135f6b6fb9;hpb=a2d5ef2127881561bf359390fac2d8d336a37335;p=github%2Fshaarli%2FShaarli.git
diff --git a/tpl/linklist.html b/tpl/linklist.html
index 42a75a1a..d5bfadf8 100644
--- a/tpl/linklist.html
+++ b/tpl/linklist.html
@@ -52,7 +52,7 @@
archive -
{/if}
-
+ onclick="return showQrCode(this);" class="qrcode" data-permalink="{$scripturl}?{$value.linkdate|smallHash}"> -
{$value.url|htmlspecialchars}
{if="$value.tags"}
@@ -79,12 +79,20 @@ function remove_qrcode()
return false;
}
+function isCanvasSupported(){
+ var elem = document.createElement('canvas');
+ return !!(elem.getContext && elem.getContext('2d'));
+}
+
// Show the QR-Code of a permalink (when the QR-Code icon is clicked).
-function showQrCode(caller,loading=false)
+function showQrCode(caller,loading)
{
+ if( !isCanvasSupported() ) return true;
+
// Dynamic javascript lib loading: We only load qr.js if the QR code icon is clicked:
if (typeof(qr)=='undefined') // Load qr.js only if not present.
{
+ loading = typeof loading !== 'undefined' ? loading : false;
if (!loading) // If javascript lib is still loading, do not append script to body.
{
var element = document.createElement("script");
@@ -101,12 +109,12 @@ function showQrCode(caller,loading=false)
// Build the div which contains the QR-Code:
var element = document.createElement('div');
element.id="permalinkQrcode";
- // Make QR-Code div commit sepuku when clicked:
- if ( element.attachEvent ){ element.attachEvent('onclick', 'this.parentNode.removeChild(this);' ); } // Damn IE
- else { element.setAttribute('onclick', 'this.parentNode.removeChild(this);' ); }
+
+ // Make QR-Code div commit sepuku when clicked:
+ element.addEventListener('click', remove_qrcode ); // Works on every canvas supported browser
// Build the QR-Code:
- var image = qr.image({size: 8,value: caller.dataset.permalink});
+ var image = qr.image({size: 8,value: caller.getAttribute('data-permalink')});
if (image)
{
element.appendChild(image);