Last active
August 29, 2015 14:00
-
-
Save haribote/11136198 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* _.parseUrlQuery.js | |
* - Urlクエリーを解析してlocationオブジェクトを拡張する | |
* - Underscore.js が必要 | |
*/ | |
;(function(window, undefined) { | |
location.query = {}; | |
var queryString = location.search.substring(1); | |
if (queryString.length > 0) { | |
_.extend(location.query, _.chain(queryString.split('&')) | |
.map(function(prop) { | |
var keyVal = prop.split('='); | |
return [keyVal[0], decodeURIComponent(keyVal[1])]; | |
}) | |
.object() | |
.value() | |
); | |
} | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment