silverstripe-framework/client/dist/js/router.js

66 lines
1.8 KiB
JavaScript
Raw Normal View History

(function (global, factory) {
2016-04-05 07:07:52 +02:00
if (typeof define === "function" && define.amd) {
define('ss.router', ['exports', 'page.js', 'url'], factory);
2016-04-05 07:07:52 +02:00
} else if (typeof exports !== "undefined") {
factory(exports, require('page.js'), require('url'));
2016-04-05 07:07:52 +02:00
} else {
var mod = {
exports: {}
};
factory(mod.exports, global.page, global.url);
2016-04-05 07:07:52 +02:00
global.ssRouter = mod.exports;
}
})(this, function (exports, _page, _url) {
2016-04-05 07:07:52 +02:00
'use strict';
2016-04-05 07:07:52 +02:00
Object.defineProperty(exports, "__esModule", {
value: true
});
2016-04-05 07:07:52 +02:00
var _page2 = _interopRequireDefault(_page);
var _url2 = _interopRequireDefault(_url);
2016-04-05 07:07:52 +02:00
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function resolveURLToBase(path) {
var absoluteBase = this.getAbsoluteBase();
var absolutePath = _url2.default.resolve(absoluteBase, path);
if (absolutePath.indexOf(absoluteBase) !== 0) {
return absolutePath;
}
return absolutePath.substring(absoluteBase.length - 1);
}
2016-04-05 07:07:52 +02:00
function show(pageShow) {
return function (path, state, dispatch, push) {
return pageShow(_page2.default.resolveURLToBase(path), state, dispatch, push);
2016-04-05 07:07:52 +02:00
};
}
2016-04-12 00:25:02 +02:00
function routeAppliesToCurrentLocation(route) {
var r = new _page2.default.Route(route);
return r.match(_page2.default.current, {});
}
function getAbsoluteBase() {
var baseTags = window.document.getElementsByTagName('base');
if (baseTags && baseTags[0]) {
return baseTags[0].href;
}
return null;
}
_page2.default.getAbsoluteBase = getAbsoluteBase.bind(_page2.default);
_page2.default.resolveURLToBase = resolveURLToBase.bind(_page2.default);
2016-04-05 07:07:52 +02:00
_page2.default.show = show(_page2.default.show);
2016-04-12 00:25:02 +02:00
_page2.default.routeAppliesToCurrentLocation = routeAppliesToCurrentLocation;
2016-04-05 07:07:52 +02:00
exports.default = _page2.default;
});