Comments (25)
This is my init code:
new Pjax({
elements: "a.js-pjax"
, selectors: ["title", "[name=analytics_page_name]", ".content", ".pjax-custom-js", ".pjax-mixpanel-track"]
});
new Pjax({
elements: ".sct a"
, selectors: ["title", "[name=analytics_page_name]", ".hero", "main", ".pjax-custom-js", ".pjax-mixpanel-track"]
});
(note that I have two different pjax implementations, not sure if this would cause the issue.)
from pjax.
You can just execute this code for every page, links that already get a event listener will be ignored (so everything will work "as expected".
I should update the readme with this example:
// edit: code removed because of the stupidity of the anwser
from pjax.
Ah, okay, good to know. I was unsure if calling pjax on the same element groups would effectively double the attached events. Thanks!
from pjax.
Hum reopening to let people know that trick while is not documented
from pjax.
Note that I believe the docs say explicitly not to do this :p
from pjax.
Also IMO this is probably something that should be done by the library by default. I can hack at it later when time permits :)
from pjax.
Haha my bad. I am stupid. The library should do that by default
Lines 467 to 469 in a17a6b9
So you should not do what I put in the example above indeed. I'll edit the comment to remove this snippet.
from pjax.
Take a look here how I'm doing on my website https://github.com/MoOx/moox.github.io/blob/40e2146b8483a7d05fd578c5a99cd136b24a65a9/src/assets/_scripts/vanilla.js
from pjax.
So this should work by default is selector are ok. It should already reapply to all the selector (& skip the elements already affected)
from pjax.
Are you using 0.1.4 ?
from pjax.
I am. I did some testing, it appears it works fine if both of my pjax calls use the same selectors
, but as soon as i define different selectors
per init, it seems to cause issues. I will continue to investigate.
You can see what I mean if you go to http://guidebook.com; clicking around the sub-nav works fine, clicking a main-nav link works fine, but if you click on a main-nav link and then return to the index and then use the sub-nav, it will cause a full reload. Not sure why.
from pjax.
Also, just tested that re-init'ing pjax on pjax:complete does in fact cause the links in question to work again, but the pjax events are bound/fired multiple times, so that doesn't work as a solution.
from pjax.
I think I get it. For now only one instance is reparsing DOM for its own selectors, not for other pjax instances. So maybe you should use a pjax event to for reparsing for other part. I did do anything special to handle this case. Maybe we should create a pjax.refresh() method to force reload.
It seems like an edge case to use 2 instances that can update same part of the page :/
from pjax.
@MoOx cool, thanks for looking into it. I can take a stab at writing that method if I have time today.
from pjax.
@MoOx I'm going to take a crack at this. Whats the best way to get this repo up and running locally so I can hack at it? Do you just browserify the index.js file? Let me know what your setup looks like. Thanks!
from pjax.
According to the package.json scripts section, you should just use npm test
command (after npm install
).
The current repo state is kind of broken (some tests aren't good because last time I work on this repo I didn't finish what I was working).
I started a refactoring (one big file to many files with tests) that I didn't finish.
What should be cool is to work with low level tests. You will probably need to extract some part of the code into new files (because I didn't finish the entire refactoring).
Take a look to this PR #33 that did that kind of stuff.
Tell me if that's enough for you to start.
from pjax.
@MoOx thanks. After playing around with it today I'm not sure the repo is in a working enough state for me to just go in and fix this issue. It seems like its kind of in a broken state, unfortunately :(
I might want to modify the existing version which is hosted on npm and update that to fix this issue. Is that possible?
from pjax.
You can do that too. Just find a way to share the fix so I can bring it back in there :)
from pjax.
@MoOx pretty simple: pklada/pjax@MoOx:master...master
Just added a simple exposed refresh method which would refresh the document based on the elements in the options. Also added some logic so that calling this wouldnt double-bind pjax events. In the code on my side I just call this on pjax:complete.
var mainPjax = new Pjax({
elements: "a.js-pjax"
, selectors: ["title", "[name=analytics_page_name]", ".content", ".pjax-custom-js", ".pjax-mixpanel-track"]
});
var sctPjax = new Pjax({
elements: ".sct a"
, selectors: ["title", "[name=analytics_page_name]", ".hero", "main", ".pjax-custom-js", ".pjax-mixpanel-track"]
});
$(document).on('pjax:complete', function(){
mainPjax.refresh();
sctPjax.refresh();
});
Maybe not the most elegant solution, but it works.
from pjax.
Good to know. Thanks for sharing I'll handle that next time I'll continue the refactoring.
from pjax.
@MoOx what are the plans w/ the refactor? Honestly I might move the current master to a new branch since its in a sort of unfinished state, maybe a refactor branch, and then roll back the current branch to .1.4. I can help in my free time as well as this library was really helpful to me, Id just like to keep the npm package, etc, up to date.
from pjax.
The current master should work in a Commonjs env. If not, it should not be a big deal to fix since I mainly just move some code (split the big file into smaller tested pieces).
I were working on a branch but was not going forward enough so I decide to break things to move fast.
I understand your arguments but think we should iterate on the current master.
Sorry to not be in a hurry, I'm really busy with bigger OS projects for now (like cssnext or stylelint) but totally want to keep this repo up since I'm using it for my website (I plan to refactor it soon, so I'll end up to use an up to date version of this lib as well).
Note: I recently give write access to @igierard yesterday since he is interested to & have made a nice PR: #33.
Maybe we should just add more minimal tests to ensure the current master works (note that the broken test for now has been made on purpose, as a reminder to finish the refactoring) so we can release new version (reminder we are still under v1.0.0, so we can totally break things ^^).
from pjax.
^ okay, that's fair. I updated my project w/ my forked version for now. (guidebook.com if you want to check it out working) Thanks.
from pjax.
If you are interested to contribute to the project, just make a nice PR as a start & we will see what happen :)
from pjax.
Closing as my fixes got added to master.
from pjax.
Related Issues (20)
- Make X-PJAX headers optional HOT 1
- Fix testing(example) folder JS paths
- what meaning of analytics options ? HOT 1
- Not working with React event handlers HOT 1
- different script for different pages? HOT 2
- adding title to selectors results in full page loading HOT 2
- Pjax doesn't work with links loaded with another children ajax elements after DOM
- The hash value of url change to 'undefined' when click the browser prev or next page
- Some events are added repeatedly HOT 1
- How to cancel Pjax triggers if in the url # HOT 1
- "Before Send" Event? HOT 1
- How to find out whether PJax is property configured?
- Drop down menu
- unable to use pjax with express
- I want you to optimize your coding experience HOT 1
- Support for formaction attribute?
- Pjax can work incorrectly when manually calling functions in History HOT 1
- Is there a way for the page to uninstall PJAX?
- Can I still use pjax if I break and change some requests by ServiceWorker?
- constantly request 404 page when local develop my blog with Hexo+butterfly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pjax.