Handle app-tiles click events in a more elegant way ;)

This commit is contained in:
Alexandre Aubin 2019-02-22 17:35:03 +01:00
parent 63846817c0
commit 7734d248c5
2 changed files with 21 additions and 24 deletions

View file

@ -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) {

View file

@ -14,7 +14,7 @@
<div id="apps" class="wrapper apps">
<ul class="listing-apps">
{{#app}}
<li><a class="app_logo" href="https://{{url}}" onclick="appClick(event, 'https://{{url}}')"><span class="first-letter"></span><span class="name">{{name}}</span></a></li>
<li><a class="app-tile" href="https://{{url}}"><span class="first-letter"></span><span class="name">{{name}}</span></a></li>
{{/app}}
</ul>
</div>