From 7734d248c5f42e31882d6e475c0a3519179a1b52 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 22 Feb 2019 17:35:03 +0100 Subject: [PATCH] Handle app-tiles click events in a more elegant way ;) --- portal/assets/js/global.js | 43 ++++++++++++++++++-------------------- portal/info.html | 2 +- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/portal/assets/js/global.js b/portal/assets/js/global.js index a5b4a65..74dd839 100644 --- a/portal/assets/js/global.js +++ b/portal/assets/js/global.js @@ -1,26 +1,3 @@ - -// handle app links so they work both in plain info page and in the info iframe called from ynhpanel.js -// FIXME : the appClick thing should be added with a selector on relevant items after the DOM loaded, not hardcoded in the .ms templates ? -function appClick (evnt, url) { - - // if asked to open in new tab - if ( - evnt.ctrlKey || - evnt.shiftKey || - evnt.metaKey || - (evnt.button && evnt.button == 1) - ) return - - // if asked in current tab - else { - evnt.preventDefault(); - parent.location.href= url; - return false; - }; - -} - - // FIXME : this stuff is really weird given that global.js // is ran on all pages, even if you are not logged in ... // Maybe add a check. I noticed that if the user is logged in, @@ -62,6 +39,26 @@ document.addEventListener('DOMContentLoaded', function() { addMaildrop.parentNode.insertBefore(inputDropClone, addMaildrop); }); + // handle app links so they work both in plain info page and in the info iframe called from ynhpanel.js + var app_tiles = document.getElementsByClassName("app-tile"); + if (app_tiles) { + for (var i = 0; i < app_tiles.length; i++) { + app_tiles[i].addEventListener('click', function(event) { + // if asked to open in new tab + if (event.ctrlKey || event.shiftKey || event.metaKey + || (event.button && event.button == 1)) { + return + } + // if asked in current tab + else { + event.preventDefault(); + parent.location.href=this.href; + return false; + }; + }, false); + } + } + // FIXME - I don't understand what this do ... // This looks kinda hackish :| if(window.location != window.parent.location) { diff --git a/portal/info.html b/portal/info.html index 223dcaa..ead4c56 100644 --- a/portal/info.html +++ b/portal/info.html @@ -14,7 +14,7 @@