wiselinks
wiselinks copied to clipboard
How to get the whole response/response data in `page:done` event
I want to do some custom update
Such as handling id
and class
attributes update on html
(I use these for styling and stuff like Modernizr
)
I see that the event page:done
is triggered here
And the arguments are from here
So there are some handling about assets, title and the content
But I want to add some custom handling (in my case it would be replacing some tags in head, modify classes, etc.)
I am not sure how to do it with only response.content()
instead of response
.
Any advise?
@igor-alexandrov
@aishek Any comment?
@PikachuEXE please use last argument of the 'page:done' event – it contains one of two possible values: full document (in case of http caching) or wiselinks content only (is case of server response)
The event is triggered in _done
, and the data
is response.content()
.
And that calls _extract_content
which to my understanding only contain the target DOM.
(It's is used by $target.html(response.content())
so it should never be the complete document)
@PikachuEXE not understand %)
Before #62
The content to be insert could be the target DOM, or the whole html
DOM (due to 304)
That should be inserted by wiselinks
, but I want that DOM in the page:done
event
After #62, response.content()
is passed in for replacing the content, instead of data
It fixes the bug, but it's also thrown into the page:done
event, which is NOT what I want, since I no longer be able to access the full document version
@PikachuEXE If you want custom processing logic, you may patch some handlers like:
window._Wiselinks.RequestManager::_html_loaded = ($target, data, status, xhr) ->
response = new window._Wiselinks.Response(data, xhr, $target)
url = @_normalize(response.url())
assets_digest = response.assets_digest()
if @_assets_changed(assets_digest)
window.location.reload(true)
else
state = History.getState()
if url? && (url != @_normalize(state.url))
@_redirect_to(url, $target, state, xhr)
content = response.content()
# modify content here
$target.html(content).promise().done(
=>
@_title(response.title())
@_done($target, status, state, content)
)
I know I can always patch it But it won't be supported officially
Also in readme:
page:done ($target, status, url, data)
Event is triggered if the request succeeds.
$target – jQuery object that was updated with the request;
status – a string describing the status;
url – url of the request;
data – content of the request;
So it should be really the content of the request, not just the target DOM
@PikachuEXE please, wait a minute, for now request.content()
always returns the same – fragment of html to insert into DOM, so there is no conflict with README
content of the request
= html
from server or cache or fragment
from server
fragment of html to insert into DOM
= Extracted from content of the request