Created
August 25, 2011 14:58
-
-
Save mpezzi/1170858 to your computer and use it in GitHub Desktop.
jQuery Query Plugin
This file contains hidden or 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
/** | |
* jQuery Query Plugin by M. Pezzi | |
* Version: 1.0 (08/25/11) | |
* https://gist.github.com/1170858 | |
* Dual licensed under the MIT and GPL licences: | |
* http://www.opensource.org/licenses/mit-license.php | |
* http://www.gnu.org/licenses/gpl.html | |
* Requires: jQuery v1.4.2 or later | |
*/ | |
(function($){ | |
$.query = function(key, value) { | |
var e, a = /\+/g, r = /([^&=]+)=?([^&]*)/g, | |
d = function (s) { return decodeURIComponent(s.replace(a, " ")); }, | |
q = window.location.search.substring(1), | |
urlParams = {}; | |
while ( e = r.exec(q) ) | |
urlParams[d(e[1])] = d(e[2]); | |
if ( typeof key !== 'undefined' && typeof value == 'undefined' ) { | |
return urlParams[key]; | |
} else if ( typeof key !== 'undefined' && typeof value !== 'undefined' ) { | |
return ( urlParams[key] == value ); | |
} else { | |
return urlParams; | |
} | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment