Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #27 from jmeas/v1.0.0
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
jamesplease committed Feb 25, 2015
2 parents a0bf1a4 + 0a4138a commit 7272c09
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,13 @@
### [1.0.0](https://github.com/jmeas/backbone.radio/releases/tag/v1.0.0)

- **Enhancement**: Adds support for multiple query parameters of the same name. They
are returned as an array.

### [0.5.0](https://github.com/jmeas/backbone.radio/releases/tag/v0.5.0)

- Updated Backbone dependency
- Tests against multiple versions of Backbone/Underscore

### [0.4.1](https://github.com/jmeas/backbone.radio/releases/tag/v0.4.1)

- **Bug fix**: Uses the constructor on the Router's prototype
Expand Down
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "backbone.base-router",
"version": "0.5.0",
"version": "1.0.0",
"homepage": "https://github.com/jmeas/backbone.base-router",
"authors": [
"Jmeas <jellyes2@gmail.com>"
Expand Down
51 changes: 33 additions & 18 deletions dist/backbone.base-router.js
@@ -1,4 +1,4 @@
// Backbone.BaseRouter v0.5.0
// Backbone.BaseRouter v1.0.0
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['backbone', 'underscore'], function(Backbone, _) {
Expand All @@ -20,8 +20,10 @@
// Backbone.BaseRouter
//

// Copied over from Backbone, because it doesn't expose them.
var namedParam = /(\(\?)?:\w+/g;
// This is copied over from Backbone, because it doesn't expose it
var NAMED_PARAM = /(\(\?)?:\w+/g;
// Find plus symbols
var PLUS_SYMBOL = /\+/g;

Backbone.BaseRouter = Backbone.Router.extend({
constructor: function() {
Expand Down Expand Up @@ -81,7 +83,7 @@
_extractRouteParams: function(route) {
var namedParams = [];

route.replace(namedParam, function(match, optional) {
route.replace(NAMED_PARAM, function(match, optional) {
namedParams.push(match.substr(1));
});

Expand All @@ -94,20 +96,33 @@
_getQueryParameters: function(queryString) {
if (!queryString) { return {}; }

var match;
var search = /([^&=]+)=?([^&]*)/g;
var urlParams = {};

while (match = search.exec(queryString)) {
urlParams[this._decodeParams(match[1])] = this._decodeParams(match[2]);
}

return urlParams;
},

_decodeParams: function (queryString) {
// Replace addition symbol with a space
return decodeURIComponent(queryString.replace(/\+/g, ' '));
return _.reduce(queryString.split('&'), function(memo, param) {
var parts = param.replace(PLUS_SYMBOL, ' ').split('=');
var key = parts[0];
var val = parts[1];

key = decodeURIComponent(key);
val = val === undefined ? null : decodeURIComponent(val);

// If we don't have the value, then we set it.
if (!memo[key]) {
memo[key] = val;
}

// Otherwise, if we have the value, and it's an array,
// then we push to it.
else if (_.isArray(memo[key])) {
memo[key].push(val);
}

// Otherwise, we have a value that is not yet an array,
// so we convert it to an array, adding the newest value.
else {
memo[key] = [memo[key], val];
}

return memo;
}, {});
},

// Returns the named parameters of the route
Expand Down
4 changes: 2 additions & 2 deletions dist/backbone.base-router.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/backbone.base-router.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "backbone.base-router",
"version": "0.5.0",
"version": "1.0.0",
"description": "A better starting point for a new Backbone Router.",
"main": "dist/backbone.base-router.js",
"directories": {
Expand Down

0 comments on commit 7272c09

Please sign in to comment.