You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
12 years ago
|
"use strict";
|
||
12 years ago
|
define(function () {
|
||
12 years ago
|
//This module will automatically route all links through backbone router rather than
|
||
|
//causing links to reload pages.
|
||
|
|
||
|
var routeBinder = {
|
||
|
|
||
12 years ago
|
bind: function (router) {
|
||
12 years ago
|
var self = this;
|
||
|
$(document).on('click', 'a[href]', function (event) {
|
||
|
self._handleClick(event, router);
|
||
|
});
|
||
12 years ago
|
},
|
||
|
|
||
12 years ago
|
_handleClick: function (event, router) {
|
||
12 years ago
|
var $target = $(event.target);
|
||
|
|
||
12 years ago
|
//check if tab nav
|
||
|
if ($target.parents('.nav-tabs').length) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
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')) {
|
||
12 years ago
|
router.navigate(href, { trigger: true });
|
||
12 years ago
|
}
|
||
12 years ago
|
|
||
|
else {
|
||
|
//Open in new tab
|
||
|
window.open(href, '_blank');
|
||
|
}
|
||
12 years ago
|
}
|
||
|
};
|
||
|
|
||
|
return routeBinder;
|
||
|
});
|