2016-03-29 00:43:45 +02:00
|
|
|
(function (global, factory) {
|
2016-04-05 07:07:52 +02:00
|
|
|
if (typeof define === "function" && define.amd) {
|
2016-04-19 01:55:45 +02:00
|
|
|
define('ss.router', ['exports', 'page.js', 'url'], factory);
|
2016-04-05 07:07:52 +02:00
|
|
|
} else if (typeof exports !== "undefined") {
|
2016-04-19 01:55:45 +02:00
|
|
|
factory(exports, require('page.js'), require('url'));
|
2016-04-05 07:07:52 +02:00
|
|
|
} else {
|
|
|
|
var mod = {
|
|
|
|
exports: {}
|
|
|
|
};
|
2016-04-19 01:55:45 +02:00
|
|
|
factory(mod.exports, global.page, global.url);
|
2016-04-05 07:07:52 +02:00
|
|
|
global.ssRouter = mod.exports;
|
|
|
|
}
|
2016-04-19 01:55:45 +02:00
|
|
|
})(this, function (exports, _page, _url) {
|
2016-04-05 07:07:52 +02:00
|
|
|
'use strict';
|
2016-03-29 00:43:45 +02:00
|
|
|
|
2016-04-05 07:07:52 +02:00
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
|
value: true
|
|
|
|
});
|
2016-03-29 00:43:45 +02:00
|
|
|
|
2016-04-05 07:07:52 +02:00
|
|
|
var _page2 = _interopRequireDefault(_page);
|
2016-03-29 00:43:45 +02:00
|
|
|
|
2016-04-19 01:55:45 +02:00
|
|
|
var _url2 = _interopRequireDefault(_url);
|
|
|
|
|
2016-04-05 07:07:52 +02:00
|
|
|
function _interopRequireDefault(obj) {
|
|
|
|
return obj && obj.__esModule ? obj : {
|
|
|
|
default: obj
|
|
|
|
};
|
|
|
|
}
|
2016-03-29 00:43:45 +02:00
|
|
|
|
2016-04-19 01:55:45 +02:00
|
|
|
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) {
|
2016-04-19 01:55:45 +02:00
|
|
|
return pageShow(_page2.default.resolveURLToBase(path), state, dispatch, push);
|
2016-04-05 07:07:52 +02:00
|
|
|
};
|
|
|
|
}
|
2016-03-29 00:43:45 +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, {});
|
|
|
|
}
|
|
|
|
|
2016-04-19 01:55:45 +02:00
|
|
|
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-03-29 00:43:45 +02:00
|
|
|
|
2016-04-05 07:07:52 +02:00
|
|
|
exports.default = _page2.default;
|
2016-03-29 00:43:45 +02:00
|
|
|
});
|