jquery.extendQuery

View the Project on GitHub jondkoon/jquery.extendQuery

What is extendQuery?

extendQuery is a utility function that leverages Steven Levithan's parseUri and jQuery to allow you to merge an object of parameters into a url as query parameters while keeping intact nonconflicting query parameters already in the url, overriding the values of the parameters if they are already present, and adding those not present.

How do I use it?

For example:

var new_url = $.extendQuery("http://hello.com", {param: "abc", param2: 123});
equal(new_url, "http://hello.com?param=abc&param2=123")

Take a look at the unit tests for more examples.

Thanks to parseUri, extendQuery can handle just about any type of url you hand it and produce what you expect.

Is that it?

One caveat of parseUri.join is that it usese protocol, authority, path, query, and anchor to join the object and nothing else. View the parseUri demo for more information.

Why did you write this?

I needed a general way to update links in my one page app with the current state of the application. It was originally intended for download links that are not loaded via ajax, but I am now considering using it to update anchors to provide "open in new tab" ability to my one page app.

Special Thanks

Initial development was sponsored by Aaron's as a part of a Proven Method professional services project.

License

(The MIT License)

Copyright © 2012-now Jon Koon

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.