2013-06-06 08:13:31 +03:00
|
|
|
"use strict";
|
|
|
|
define(['app'], function () {
|
|
|
|
|
|
|
|
//This module will automatically route all links through backbone router rather than
|
|
|
|
//causing links to reload pages.
|
|
|
|
|
|
|
|
var routeBinder = {
|
|
|
|
|
|
|
|
bind: function () {
|
|
|
|
$(document).on('click', 'a[href]', this._handleClick);
|
|
|
|
},
|
|
|
|
|
2013-06-07 03:17:57 +03:00
|
|
|
_isInTab: function (element) {
|
|
|
|
return;
|
|
|
|
},
|
|
|
|
|
2013-06-06 08:13:31 +03:00
|
|
|
_handleClick: function (event) {
|
|
|
|
var $target = $(event.target);
|
|
|
|
|
2013-06-07 03:17:57 +03:00
|
|
|
//check if tab nav
|
|
|
|
if ($target.parents('.nav-tabs').length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-06 08:13:31 +03:00
|
|
|
if ($target.hasClass('no-router')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('click');
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
var href = event.target.getAttribute('href');
|
|
|
|
|
|
|
|
if (!href && $target.parent('a') && $target.parent('a')[0]) {
|
|
|
|
|
|
|
|
var linkElement = $target.parent('a')[0];
|
|
|
|
|
|
|
|
href = linkElement.getAttribute('href');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!href) {
|
|
|
|
throw 'couldnt find route target';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!href.startsWith('http')) {
|
|
|
|
NzbDrone.Router.navigate(href, { trigger: true });
|
|
|
|
}
|
2013-06-07 18:42:49 +03:00
|
|
|
|
|
|
|
else {
|
|
|
|
//Open in new tab
|
|
|
|
window.open(href, '_blank');
|
|
|
|
}
|
2013-06-06 08:13:31 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return routeBinder;
|
|
|
|
});
|