thybag / PJAX-Standalone

A standalone implementation of Pushstate AJAX, for non-jquery webpages.
203 stars 42 forks source link

Execute JavaScript scripts loaded via PJAX standalone #17

Closed ab192130 closed 10 years ago

ab192130 commented 10 years ago

Hi thybag, I can't run javascripts insde the response. Is that a bug or behaviour? How can we fix that?

ghost commented 10 years ago

Hello,

Both kind of, its a feature I've planned to look at, but one I've yet to get around to.

Is this raw <script> var = new my_code(){ return "here";}</script> kinda stuff, or references to external files <script src="script_here"></script> that you're attempting to get working?

Thanks, Carl

ab192130 commented 10 years ago

Hi Carl, thanks for attention... it,s simply kinda the first one <script>alert('test'); </script>

ps. sorry i don't know how to highlight codes in github comments, so i wrote them with spaces -- (I did it, thanksss)

thybag commented 10 years ago

Hello,

Evaling inline js should be fairly straight forward, so I'll try and have a look at that as soon as i get a chance.

Github wise, to get a code box either indent the code with a tab (or 4 spaces) or surround it with ` for inline code

indented 4 chars

and this is surrounded by the `'s

ab192130 commented 10 years ago

OK. I'll wait for your response, Carl. Hope it wont take long, cause I need that so much. BTW, Thank you for helping me

thybag commented 10 years ago

Hello,

I've just pushed a branch ( https://github.com/thybag/PJAX-Standalone/tree/feature/js_handling ) containing an initial implementation for handing JS on pages returned via PJAX. The feature is disabled by default, although can be enabled by adding parseJS: true to your PJAX configuration options.

For example:

pjax.connect({
    'container': 'content',
    'parseJS': true
});
ab192130 commented 10 years ago

Thank you for support, Carl, but it's the same thing :(

Here It's my ajax response: http://jsfiddle.net/S7pTn/

Is there anything wrong?

ab192130 commented 10 years ago

Yahooooooo.......!!!!! it was my bad. I've fixed it and it works like a charmm... thank you very much Caaaaaarl.. You are best!!!!

PS. bootstrap tooltips and popovers still dont work.. what could be the reason? can i run these in response content ?

Update. Carl,, i've added $('*[data-toggle="tooltip"]').tooltip(); $('*[data-toggle="popover"]').popover(); to pjax.success event and it worked.

thybag commented 10 years ago

Hello,

Just rolled this fix in to the master branch.

Re: tooltips, I think the call to the bootstrap tooltip/popover method in the success is probably the best option (in order to get the newly loaded elements set up to work with it). Only suggestion would be to maybe just apply it to tooltips in the PJAX loaded container (to avoid re adding it to existing elements), something along the lines of $('#mycontainer *[data-toggle="tooltip"]').tooltip();.

ab192130 commented 10 years ago

Thank You

bilogic commented 6 years ago

Hi, if I use pjax go forward a few pages (containing javascripts that pull dynamic data), these javascripts are not executed again when clicking on the browser's back button (and forward button), is there a way to make them execute? Thank you.