2010-04-01 00:56:16 +00:00
|
|
|
angularService("$window", bind(window, identity, window));
|
|
|
|
|
|
2010-04-01 21:10:28 +00:00
|
|
|
var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.]+)(:([0-9]+))?([^\?#]+)?(\?([^#]*))((#([^\?]*))(\?([^\?]*))?)$/;
|
|
|
|
|
angularService("$location", function(){
|
2010-04-01 00:56:16 +00:00
|
|
|
var scope = this;
|
2010-04-01 21:10:28 +00:00
|
|
|
function location(url){
|
2010-04-01 00:56:16 +00:00
|
|
|
if (isDefined(url)) {
|
2010-04-01 21:10:28 +00:00
|
|
|
var match = URL_MATCH.exec(url);
|
|
|
|
|
dump(match);
|
|
|
|
|
location.href = url;
|
|
|
|
|
location.protocol = match[1];
|
|
|
|
|
location.host = match[3];
|
|
|
|
|
location.port = match[5];
|
|
|
|
|
location.path = match[6];
|
|
|
|
|
location.search = parseKeyValue(match[8]);
|
|
|
|
|
location.hash = match[9];
|
|
|
|
|
location.hashPath = match[11];
|
|
|
|
|
location.hashSearch = parseKeyValue(match[13]);
|
|
|
|
|
foreach(location, dump);
|
2010-04-01 00:56:16 +00:00
|
|
|
}
|
|
|
|
|
var params = [];
|
2010-04-01 21:10:28 +00:00
|
|
|
foreach(location.param, function(value, key){
|
2010-04-01 00:56:16 +00:00
|
|
|
params.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
|
|
|
|
|
});
|
2010-04-01 21:10:28 +00:00
|
|
|
return (location.path ? location.path : '') + (params.length ? '?' + params.join('&') : '');
|
2010-04-01 00:56:16 +00:00
|
|
|
};
|
|
|
|
|
this.$config.location.watch(function(url){
|
2010-04-01 21:10:28 +00:00
|
|
|
location(url);
|
2010-04-01 00:56:16 +00:00
|
|
|
});
|
|
|
|
|
this.$onEval(PRIORITY_LAST, function(){
|
2010-04-01 21:10:28 +00:00
|
|
|
scope.$config.location.set(location());
|
2010-04-01 00:56:16 +00:00
|
|
|
});
|
2010-04-01 21:10:28 +00:00
|
|
|
return location;
|
2010-04-01 00:56:16 +00:00
|
|
|
});
|