mirror of
https://github.com/YunoHost/SSOwat.git
synced 2024-09-03 20:06:27 +02:00
Use addEvent helper to be consistent accross the JS file
This commit is contained in:
parent
d521d87d23
commit
ad27933f54
1 changed files with 23 additions and 32 deletions
|
@ -91,6 +91,7 @@ Element.toggleClass = function(element, className) {
|
||||||
https://github.com/Darklg/JavaScriptUtilities/blob/master/assets/js/vanilla-js/libs/vanilla-events.js
|
https://github.com/Darklg/JavaScriptUtilities/blob/master/assets/js/vanilla-js/libs/vanilla-events.js
|
||||||
-------------------------- */
|
-------------------------- */
|
||||||
window.addEvent = function(el, eventName, callback, options) {
|
window.addEvent = function(el, eventName, callback, options) {
|
||||||
|
if (el == null) { return; }
|
||||||
if (el.addEventListener) {
|
if (el.addEventListener) {
|
||||||
if (!options || typeof(options) !== "object") {
|
if (!options || typeof(options) !== "object") {
|
||||||
options = {};
|
options = {};
|
||||||
|
@ -197,7 +198,7 @@ function make_element_draggable(id) {
|
||||||
/* ----------------------------------------------------------
|
/* ----------------------------------------------------------
|
||||||
Main
|
Main
|
||||||
---------------------------------------------------------- */
|
---------------------------------------------------------- */
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
window.addEvent(document, 'DOMContentLoaded', function() {
|
||||||
|
|
||||||
// 3 different cases :
|
// 3 different cases :
|
||||||
// - this script is loaded from inside an app
|
// - this script is loaded from inside an app
|
||||||
|
@ -293,37 +294,28 @@ function init_portal_button_and_overlay()
|
||||||
function init_portal()
|
function init_portal()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Variables
|
window.addEvent(document.getElementById('add-mailalias'), "click", function() {
|
||||||
var addMailAlias = document.getElementById('add-mailalias')
|
|
||||||
, addMaildrop = document.getElementById('add-maildrop')
|
|
||||||
;
|
|
||||||
|
|
||||||
addMailAlias && addMailAlias.addEventListener('click', function(){
|
|
||||||
// Clone last input.
|
// Clone last input.
|
||||||
var inputAliasClone = document.querySelector('.mailalias-input').cloneNode(true);
|
var inputAliasClone = document.querySelector('.mailalias-input').cloneNode(true);
|
||||||
// Empty value.
|
// Empty value.
|
||||||
inputAliasClone.value = '';
|
inputAliasClone.value = '';
|
||||||
// Append to form-group.
|
// Append to form-group.
|
||||||
addMailAlias.parentNode.insertBefore(inputAliasClone, addMailAlias);
|
this.parentNode.insertBefore(inputAliasClone, this);
|
||||||
});
|
});
|
||||||
|
|
||||||
addMaildrop && addMaildrop.addEventListener('click', function(){
|
window.addEvent(document.getElementById('add-maildrop'), "click", function() {
|
||||||
// Clone last input.
|
// Clone last input.
|
||||||
var inputDropClone = document.querySelector('.maildrop-input').cloneNode(true);
|
var inputDropClone = document.querySelector('.maildrop-input').cloneNode(true);
|
||||||
// Empty value.
|
// Empty value.
|
||||||
inputDropClone.value = '';
|
inputDropClone.value = '';
|
||||||
// Append to form-group.
|
// Append to form-group.
|
||||||
addMaildrop.parentNode.insertBefore(inputDropClone, addMaildrop);
|
this.parentNode.insertBefore(inputDropClone, this);
|
||||||
});
|
});
|
||||||
|
|
||||||
var app_tiles = document.getElementsByClassName("app-tile");
|
Array.each(document.getElementsByClassName("app-tile"), function(el) {
|
||||||
if (app_tiles) {
|
|
||||||
for (var i = 0; i < app_tiles.length; i++) {
|
|
||||||
|
|
||||||
var el = app_tiles[i];
|
|
||||||
set_app_tile_style(el);
|
set_app_tile_style(el);
|
||||||
// handle app links so they work both in plain info page and in the info iframe called from ynhpanel.js
|
// handle app links so they work both in plain info page and in the info iframe called from ynhpanel.js
|
||||||
el.addEventListener('click', function(event) {
|
window.addEvent(el, 'click', function(event) {
|
||||||
// if asked to open in new tab
|
// if asked to open in new tab
|
||||||
if (event.ctrlKey || event.shiftKey || event.metaKey
|
if (event.ctrlKey || event.shiftKey || event.metaKey
|
||||||
|| (event.button && event.button == 1)) {
|
|| (event.button && event.button == 1)) {
|
||||||
|
@ -335,9 +327,8 @@ function init_portal()
|
||||||
parent.location.href=this.href;
|
parent.location.href=this.href;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
}, false);
|
});
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var app_tile_colors = ['redbg','purpledarkbg','darkbluebg','orangebg','greenbg','darkbluebg','purpledarkbg','yellowbg','lightpinkbg','pinkbg','turquoisebg','yellowbg','lightbluebg','purpledarkbg', 'bluebg'];
|
var app_tile_colors = ['redbg','purpledarkbg','darkbluebg','orangebg','greenbg','darkbluebg','purpledarkbg','yellowbg','lightpinkbg','pinkbg','turquoisebg','yellowbg','lightbluebg','purpledarkbg', 'bluebg'];
|
||||||
|
@ -360,9 +351,9 @@ function tweak_portal_when_in_iframe()
|
||||||
userContainer.setAttribute('href', userContainer
|
userContainer.setAttribute('href', userContainer
|
||||||
.getAttribute('href')
|
.getAttribute('href')
|
||||||
.replace('edit.html', ''));
|
.replace('edit.html', ''));
|
||||||
userContainer.addEventListener('click', function(e) {
|
window.addEvent(userContainer, 'click', function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
window.parent.location.href = userContainer.getAttribute('href');
|
window.parent.location.href = userContainer.getAttribute('href');
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue