aboutsummaryrefslogtreecommitdiffstats
path: root/src/services.js
blob: 5d235b324d6b2243b0694b4599f5d0f90d82f4e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
angularService("$window", bind(window, identity, window));

var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.]+)(:([0-9]+))?([^\?#]+)?(\?([^#]*))((#([^\?]*))(\?([^\?]*))?)$/;
angularService("$location", function(){
  var scope = this;
  function location(url){
    if (isDefined(url)) {
      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(location.param, function(value, key){
      params.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
    });
    return (location.path ? location.path : '') + (params.length ? '?' + params.join('&') : '');
  };
  this.$config.location.watch(function(url){
    location(url);
  });
  this.$onEval(PRIORITY_LAST, function(){
    scope.$config.location.set(location());
  });
  return location;
});