aboutsummaryrefslogtreecommitdiffstats
path: root/src/services.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/services.js')
-rw-r--r--src/services.js40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/services.js b/src/services.js
index 14c71363..5d235b32 100644
--- a/src/services.js
+++ b/src/services.js
@@ -1,34 +1,34 @@
angularService("$window", bind(window, identity, window));
-angularService("$anchor", function(){
+var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.]+)(:([0-9]+))?([^\?#]+)?(\?([^#]*))((#([^\?]*))(\?([^\?]*))?)$/;
+angularService("$location", function(){
var scope = this;
- function anchor(url){
+ function location(url){
if (isDefined(url)) {
- if (url.charAt(0) == '#') url = url.substr(1);
- var pathQuery = url.split('?');
- anchor.path = decodeURIComponent(pathQuery[0]);
- anchor.param = {};
- foreach((pathQuery[1] || "").split('&'), function(keyValue){
- if (keyValue) {
- var parts = keyValue.split('=');
- var key = decodeURIComponent(parts[0]);
- var value = parts[1];
- if (!value) value = true;
- anchor.param[key] = decodeURIComponent(value);
- }
- });
+ 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);
}
var params = [];
- foreach(anchor.param, function(value, key){
+ foreach(location.param, function(value, key){
params.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
});
- return (anchor.path ? anchor.path : '') + (params.length ? '?' + params.join('&') : '');
+ return (location.path ? location.path : '') + (params.length ? '?' + params.join('&') : '');
};
this.$config.location.watch(function(url){
- anchor(url);
+ location(url);
});
this.$onEval(PRIORITY_LAST, function(){
- scope.$config.location.set(anchor());
+ scope.$config.location.set(location());
});
- return anchor;
+ return location;
});