kiran-jejurkar / jquery-stream

Automatically exported from code.google.com/p/jquery-stream
0 stars 0 forks source link

Extra url parameters on initialization #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
New feature-request

The idea is to be able to apply extra parameters to the initialization GET 
request. If these are static they could just be put into the given URL, but if 
they need to be updated (fx. on re-initialization) they need to be variable.

The default options object is extended with a default empty "openData" object.

The prepareURL function is then extended to run through the openData object and 
analyze it's property each property is added to the initialization URL. If a 
property is a function the value of the property will be the result of calling 
the function.

I havent checked out the code from the repository, so I'm not able to make a 
patch. I'll just copy the rewritten prepareURL function in here:

    function prepareURL(url, options) {
        var rts = /([?&]_=)[^&]*/;

        var params = {};
        for(var i in options) {
            if (jQuery.isFunction(options[i])) {
                params[i] = options[i].call(this);
            } else {
                params[i] = options[i];
            }
        }
        // Attaches a time stamp
        return (rts.test(url) ? url : (url + (/\?/.test(url) ? "&" : "?") + "_="))
        .replace(rts, "$1" + new Date().getTime())+"&"+jQuery.param(params);
    }

Then each call to this function need an extra paramter:
prepareURL(this.url, this.options.openData);

Original issue reported on code.google.com by renemark...@gmail.com on 30 Jun 2011 at 8:21

GoogleCodeExporter commented 9 years ago
Thanks for idea.

revision 99 differs from your idea in that the timestamp parameter for 
anti-caching (_) is added into openData object.

Original comment by flowersi...@gmail.com on 1 Jul 2011 at 5:35

GoogleCodeExporter commented 9 years ago
I found that if a value is function, jQuery.param executes it and uses its 
result when performing.

http://jsfiddle.net/xKN5g/

Original comment by flowersi...@gmail.com on 3 Jul 2011 at 7:14