mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
create simple url service
This commit is contained in:
parent
8e1492494a
commit
c6492905b0
1 changed files with 44 additions and 0 deletions
44
src/kibana/components/url/url.js
Normal file
44
src/kibana/components/url/url.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
define(function (require) {
|
||||
var location = require('modules').get('kibana/url');
|
||||
|
||||
location.service('kbnUrl', function ($route, $location, $rootScope, globalState) {
|
||||
var reloading = false;
|
||||
|
||||
function KbnUrl() {
|
||||
}
|
||||
|
||||
KbnUrl.prototype.changePath = function (path) {
|
||||
if (path !== $location.path()) {
|
||||
$location.path(globalState.writeToUrl(path));
|
||||
reload();
|
||||
}
|
||||
};
|
||||
|
||||
KbnUrl.prototype.change = function (url) {
|
||||
if (url !== $location.url()) {
|
||||
$location.url(globalState.writeToUrl(url));
|
||||
reload();
|
||||
}
|
||||
};
|
||||
|
||||
KbnUrl.prototype.matches = function (url) {
|
||||
var route = $route.current.$$route;
|
||||
if (!route || !route.regexp) return null;
|
||||
return route.regexp.test(url);
|
||||
};
|
||||
|
||||
$rootScope.$on('$routeUpdate', reloadingComplete);
|
||||
$rootScope.$on('$routeChangeStart', reloadingComplete);
|
||||
|
||||
function reload() {
|
||||
if (!reloading) $route.reload();
|
||||
reloading = true;
|
||||
}
|
||||
|
||||
function reloadingComplete() {
|
||||
reloading = false;
|
||||
}
|
||||
|
||||
return new KbnUrl();
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue