Cleanup, shorten and document the onClick event handler
This commit is contained in:
parent
0dc5a12565
commit
62dd827ce2
|
@ -189,6 +189,10 @@
|
||||||
var href = $a.attr('href');
|
var href = $a.attr('href');
|
||||||
var $li;
|
var $li;
|
||||||
var targetId;
|
var targetId;
|
||||||
|
var isMenuLink = $a.closest('#menu').length > 0;
|
||||||
|
|
||||||
|
// TODO: Let remote links pass through. Right now they only work
|
||||||
|
// combined with target="_blank"
|
||||||
if ($a.attr('target') === '_blank') {
|
if ($a.attr('target') === '_blank') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -197,30 +201,46 @@
|
||||||
|
|
||||||
// If link is hash tag...
|
// If link is hash tag...
|
||||||
if (href === '#') {
|
if (href === '#') {
|
||||||
if ($a.closest('#menu')) {
|
// ...it may be a menu section without a dedicated link:
|
||||||
|
if (isMenuLink) {
|
||||||
$li = $a.closest('li');
|
$li = $a.closest('li');
|
||||||
$('#menu .active').removeClass('active');
|
$('#menu .active').removeClass('active');
|
||||||
$li.addClass('active');
|
$li.addClass('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop here for all hash tags
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If everything else fails, our target is the first column...
|
||||||
var $target = $('#col1');
|
var $target = $('#col1');
|
||||||
|
|
||||||
|
// ...but usually we will use our own container...
|
||||||
var $container = $a.closest('.container');
|
var $container = $a.closest('.container');
|
||||||
if ($container.length) {
|
if ($container.length) {
|
||||||
$target = $container;
|
$target = $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ...the only exception are class="action" tables...
|
||||||
if ($a.closest('table.action').length) {
|
if ($a.closest('table.action').length) {
|
||||||
$target = $('#col2');
|
$target = $('#col2');
|
||||||
icinga.events.layout2col();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ...and you can of course override the default behaviour...
|
||||||
if ($a.closest('[data-base-target]').length) {
|
if ($a.closest('[data-base-target]').length) {
|
||||||
targetId = $a.closest('[data-base-target]').data('baseTarget');
|
targetId = $a.closest('[data-base-target]').data('baseTarget');
|
||||||
$target = $('#' + targetId);
|
|
||||||
if (targetId === 'col2') {
|
// Simulate _next to prepare migration to dynamic column layout
|
||||||
icinga.events.layout2col();
|
if (targetId === '_next') {
|
||||||
|
targetId = 'col2';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$target = $('#' + targetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tree handler
|
||||||
|
// TODO: We should move this somewhere else and "register" such
|
||||||
|
// handlers
|
||||||
if ($a.closest('.tree').length) {
|
if ($a.closest('.tree').length) {
|
||||||
$li = $a.closest('li');
|
$li = $a.closest('li');
|
||||||
if ($li.find('li').length) {
|
if ($li.find('li').length) {
|
||||||
|
@ -233,30 +253,22 @@
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
$target = $('#col2');
|
$target = $('#col2');
|
||||||
icinga.events.layout2col();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load link URL
|
||||||
icinga.loader.loadUrl(href, $target);
|
icinga.loader.loadUrl(href, $target);
|
||||||
event.stopPropagation();
|
|
||||||
event.preventDefault();
|
|
||||||
|
|
||||||
if ($a.closest('#menu').length) {
|
// Menu links should remove all but the first layout column
|
||||||
|
if (isMenuLink) {
|
||||||
icinga.events.layout1col();
|
icinga.events.layout1col();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($a.closest('table.action').length) {
|
// Hardcoded layout switch unless columns are dynamic
|
||||||
if ($('#layout').hasClass('twocols')) {
|
if ($target.attr('id') === 'col2') {
|
||||||
if ($target.attr('id') === 'col2') {
|
icinga.events.layout2col();
|
||||||
return;
|
|
||||||
}
|
|
||||||
icinga.events.layout1col();
|
|
||||||
} else {
|
|
||||||
icinga.events.layout2col();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue