parent
9536c6c1bb
commit
47d924cff3
@ -1,55 +1,59 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
define(['backbone'],function (Backbone) {
|
define(
|
||||||
//This module will automatically route all relative links through backbone router rather than
|
[
|
||||||
//causing links to reload pages.
|
'backbone',
|
||||||
|
'jquery'
|
||||||
|
], function (Backbone,$) {
|
||||||
|
//This module will automatically route all relative links through backbone router rather than
|
||||||
|
//causing links to reload pages.
|
||||||
|
|
||||||
var routeBinder = {
|
var routeBinder = {
|
||||||
|
|
||||||
bind: function () {
|
bind: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
$(document).on('click', 'a[href]', function (event) {
|
$(document).on('click', 'a[href]', function (event) {
|
||||||
self._handleClick(event);
|
self._handleClick(event);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_handleClick: function (event) {
|
_handleClick: function (event) {
|
||||||
var $target = $(event.target);
|
var $target = $(event.target);
|
||||||
|
|
||||||
//check if tab nav
|
//check if tab nav
|
||||||
if ($target.parents('.nav-tabs').length) {
|
if ($target.parents('.nav-tabs').length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($target.hasClass('no-router')) {
|
if ($target.hasClass('no-router')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
var href = event.target.getAttribute('href');
|
var href = event.target.getAttribute('href');
|
||||||
|
|
||||||
if (!href && $target.parent('a') && $target.parent('a')[0]) {
|
if (!href && $target.parent('a') && $target.parent('a')[0]) {
|
||||||
|
|
||||||
var linkElement = $target.parent('a')[0];
|
var linkElement = $target.parent('a')[0];
|
||||||
|
|
||||||
href = linkElement.getAttribute('href');
|
href = linkElement.getAttribute('href');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!href) {
|
if (!href) {
|
||||||
throw 'couldn\'t find route target';
|
throw 'couldn\'t find route target';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!href.startsWith('http')) {
|
if (!href.startsWith('http')) {
|
||||||
Backbone.history.navigate(href, { trigger: true });
|
Backbone.history.navigate(href, { trigger: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
//Open in new tab
|
//Open in new tab
|
||||||
window.open(href, '_blank');
|
window.open(href, '_blank');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
};
|
|
||||||
|
|
||||||
return routeBinder;
|
return routeBinder;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in new issue