diff options
| author | Misko Hevery | 2010-03-31 17:56:16 -0700 |
|---|---|---|
| committer | Misko Hevery | 2010-03-31 18:18:10 -0700 |
| commit | 11a6431f8926c557f3c58408dacc98466e76cde1 (patch) | |
| tree | ab36304fd373d0947ca36c577e25ca87a1c894af /src/services.js | |
| parent | 35a91085004e31f786df1e0011bc26ed0142ab4d (diff) | |
| download | angular.js-11a6431f8926c557f3c58408dacc98466e76cde1.tar.bz2 | |
started to add services
Diffstat (limited to 'src/services.js')
| -rw-r--r-- | src/services.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/services.js b/src/services.js new file mode 100644 index 00000000..14c71363 --- /dev/null +++ b/src/services.js @@ -0,0 +1,34 @@ +angularService("$window", bind(window, identity, window)); + +angularService("$anchor", function(){ + var scope = this; + function anchor(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 params = []; + foreach(anchor.param, function(value, key){ + params.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)); + }); + return (anchor.path ? anchor.path : '') + (params.length ? '?' + params.join('&') : ''); + }; + this.$config.location.watch(function(url){ + anchor(url); + }); + this.$onEval(PRIORITY_LAST, function(){ + scope.$config.location.set(anchor()); + }); + return anchor; +}); |
