aboutsummaryrefslogtreecommitdiffstats
path: root/src/services.js
diff options
context:
space:
mode:
authorMisko Hevery2010-04-01 14:10:28 -0700
committerMisko Hevery2010-04-01 14:10:28 -0700
commit85f13d602e31424b2e2d18172872f14a24c31135 (patch)
tree8389ab1a0dfd6b8717a1f0dc70a738deaca146c2 /src/services.js
parent11a6431f8926c557f3c58408dacc98466e76cde1 (diff)
downloadangular.js-85f13d602e31424b2e2d18172872f14a24c31135.tar.bz2
work on $location and autobind
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;
});