Sha256: 419d783d0db9f474f9776d80c1f61e9da7ee738de49bfa82751e4c51fc5a50b6

Contents?: true

Size: 1013 Bytes

Versions: 23

Compression:

Stored size: 1013 Bytes

Contents

Discerner.Url = function (url) {
  this.url = url;
};

Discerner.Url.prototype = {
  sub: function (params) {
    var url = this.url,
        newUrl = this.url,
        queryString = [],
        encodedArg = undefined,
        encodeParam = undefined,
        param = undefined;

    for (param in params) {
      if (params.hasOwnProperty(param)) {
        encodedParam = encodeURIComponent(param);
        encodedArg = encodeURIComponent(params[param]);
        newUrl = url.replace(':' + param, encodedArg);
        if (url == newUrl) {
          queryString.push(encodedParam + '=' + encodedArg);
        }
        url = newUrl;
      }
    }

    if (queryString.length > 0) {
      if (url.indexOf('?') > 0) {
        return url + queryString.join('&');
      } else {
        return url + '?' + queryString.join('&');
      }
    } else {
      return url;
    }
  },

  parameters: function () {
    return $.map(this.url.match(/:\w+/g) || [], function (o, i) {
      return o.substring(1);
    });
  }
};

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
discerner-2.0.16 app/assets/javascripts/discerner/url.js
discerner-2.0.15 app/assets/javascripts/discerner/url.js
discerner-2.0.14 app/assets/javascripts/discerner/url.js
discerner-2.0.13 app/assets/javascripts/discerner/url.js
discerner-1.2.2 app/assets/javascripts/discerner/url.js
discerner-2.0.12 app/assets/javascripts/discerner/url.js
discerner-1.2.1 app/assets/javascripts/discerner/url.js
discerner-2.0.11 app/assets/javascripts/discerner/url.js
discerner-2.0.10 app/assets/javascripts/discerner/url.js
discerner-1.2.0 app/assets/javascripts/discerner/url.js
discerner-2.0.9 app/assets/javascripts/discerner/url.js
discerner-2.0.8 app/assets/javascripts/discerner/url.js
discerner-2.0.7 app/assets/javascripts/discerner/url.js
discerner-2.0.6 app/assets/javascripts/discerner/url.js
discerner-2.0.5 app/assets/javascripts/discerner/url.js
discerner-2.0.4 app/assets/javascripts/discerner/url.js
discerner-2.0.3 app/assets/javascripts/discerner/url.js
discerner-2.0.2 app/assets/javascripts/discerner/url.js
discerner-2.0.1 app/assets/javascripts/discerner/url.js
discerner-2.0.0 app/assets/javascripts/discerner/url.js