mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-14 17:13:49 -07:00
all links are automatically handled through backbone router.
no more page reload.
This commit is contained in:
parent
5ea794939c
commit
50918ae65f
6 changed files with 55 additions and 41 deletions
44
UI/RouteBinder.js
Normal file
44
UI/RouteBinder.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
"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);
|
||||
},
|
||||
|
||||
_handleClick: function (event) {
|
||||
var $target = $(event.target);
|
||||
|
||||
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 });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return routeBinder;
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue