-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.backbone.hijax.js
44 lines (40 loc) · 1.12 KB
/
jquery.backbone.hijax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
(function ($, plugin) {
if ($) { // Global jQuery
plugin.fn = (plugin.isStatic ? $ : $.fn)[plugin.name] = plugin.factory($);
}
if (typeof exports !== 'undefined' && plugin.fn) { // CommonJS
if (typeof module !== 'undefined' && module.exports) {
module.exports = plugin.fn;
}
exports[plugin.name] = plugin.fn;
} else if (typeof define === 'function' && define.amd) { // AMD
define(['jquery'], function ($) {
var fn = (plugin.isStatic ? $ : $.fn)[plugin.name] = plugin.factory($);
return fn;
});
} else if (!$) {
/*
jQuery isn't defined and user is
trying to use plugin directly without
CommonJS or AMD support
*/
throw 'jQuery not defined.';
}
})(window.$, {
'name' : 'backboneHijax',
'isStatic' : true,
'factory' : function ($) {
return function (router) {
return $(document).on('click', 'a[href]:not([data-bypass])', function (e) {
var href = $(this).attr('href'),
url = href.replace(/^\//,'').replace('\#\!\/','');
if (href.charAt(0) === '/') {
router.navigate(url, {'trigger' : true});
e.preventDefault();
return false;
}
});
};
}
});