Skip to content

Make url available as a public attribute #2631

Closed
wants to merge 1 commit into from

4 participants

@antpaw
antpaw commented Jul 9, 2014

This is particularly useful if the real GET url is not unknown because additional parameters are appended via send({param: 1}). With this change you can assign the right url to pushState.

var request = new Request.HTML({
onSuccess: function(){
    window.history.pushState({ turbolinks: true, url: request.url }, '', request.url);
}
}).send({param: 1});
@antpaw antpaw Make url available as a public attribute
This is particularly useful if the real GET url is not unknown because additional parameters are appended via `send({param: 1})`. With this change you can assign the right url to `pushState`. 

```javascript
var request = new Request.bhf({
onSuccess: function(request){
	window.history.pushState({ turbolinks: true, url: request.url }, '', request.url);
}
}).send({param: 1});
```
86306f7
@ibolmo ibolmo added the enhancement label Jul 9, 2014
@ibolmo ibolmo added this to the 1.6.0 milestone Jul 9, 2014
@olvlvl
olvlvl commented Sep 11, 2014

I don't think this is necessary. It seams to me that the problem is with the logic of your application.

@antpaw
antpaw commented Sep 11, 2014

Yes it's a logic problem, i could solve it by:
1. implementing the logic you are doing in send() myself (appending '&' or '?' to url ect. ect. very annoying stuff). This leads to duplicated code (same code in framework and my app) and very low level code which i'm trying to escape by using mootools.
2. you could refactor the GET url string build part of send() into a public function and i'm going to use it.
3. as suggested in the first post, making the url string available in the as a public attribute.

Thanks

@ibolmo ibolmo closed this Sep 11, 2014
@olvlvl
olvlvl commented Sep 11, 2014

@antpaw If you don't define the url parameter, the request is sent to the current pathname with the parameters you provide. Your new location should then be created from the current pathname and the params, just like a regular URL would be used to access your resource. Also, I advise you to use your params as stateObj, so that you can easily retrieve the previous state:

var params = { param: 1 }

new Request.HTML({
    onSuccess: function(){
        window.history.pushState(params, '', window.location.pathname + "?" + params.toQueryString())
    }
}).get(params)

What do you think ?

@antpaw
antpaw commented Sep 11, 2014

Thanks for helping me!
I need the hole url that already exists, I already have some GET params which I don't want to lose.
If I use the hole url I need to find out whether i need '?' or '&'.
I need to write low level code, that mootool already has. Can you extract this code in to a helper or provide the url variable as a public attribute?
It will also look nicer, now send() is doing some nasty string appending and data encoding, which you wouldn't expect in a send function.

@olvlvl
olvlvl commented Sep 11, 2014

window.location.search provides you with the current parameters. If you want to preserve those parameters you need to extract them and merge them with your new parameters:

var params = Object.merge(window.location.search.substring(1).parseQueryString(), { param: 1 })

… or a similar code.

@anutron
MooTools member
anutron commented Sep 11, 2014

You might also check out the URI class in Mootools More. It provides a ton of functionality for managing stuff like this.

@antpaw
antpaw commented Sep 12, 2014

okay i see, i'm going to use m-more for this, but shouldn't the basic functions of URI go into m-core because send() and maybe something else is using it anyways?

@anutron
MooTools member
anutron commented Sep 12, 2014

The URI class is just more overhead than Request needs. Including it just to use Request isn't necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.