Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pjax form submit heroku example #489

Open
wants to merge 11 commits into
base: heroku
Choose a base branch
from
6 changes: 6 additions & 0 deletions app/views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
<li><a href="/aliens.html">aliens</a></li>
</ul>

<h1><%= params[:text] %></h1>
<form method="GET">
<input type="text" name="text">
<input type="submit">
</form>

<p>
pjax loads html from your server into the current page
without a full page load. It's ajax with real permalinks,
Expand Down
16 changes: 11 additions & 5 deletions app/views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@
<%# finally, make the page-top bar somewhat respectably toned down too %>
<meta name="apple-mobile-web-app-status-bar-style" content="black">

<script src="jquery.js"></script>
<script src="jquery.cookie.js"></script>
<script src="pages.js"></script>
<!-- <script src="jquery.js"></script> -->
<script src="//code.jquery.com/jquery-1.11.2.js"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 from loading from CDN. You may remove the old vendored jquery.js and references to it.

<!-- <script src="jquery.cookie.js"></script> -->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for removing old cookie plugin especially if it doesn't work anymore.

<!-- <script src="pages.js"></script> -->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was pretty important because it kept the state of the checkbox consistent between page refreshes. I get that it was broken because the cookie plugin was broken. Instead of setting cookies, you can try using sessionStorage to keep the checked state of the checkbox consistent between refreshes.


<script src="jquery.pjax.js"></script>
<script type="text/javascript">
$(function(){
// pjax
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change the invocation? I preferred the shorter form. It works good as a demo.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's legacy API. With the version of jquery I updated, live doesn't seems to work anymore.
https://github.com/defunkt/jquery-pjax#legacy-api

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah OK, got it. The new invocation you wrote looks good.

$('ul a').pjax('#main')
// $('ul a').pjax('#main')
$(document).pjax('ul a', '#main');
// $(document).pjax('form', '#main');
$(document).on('submit', 'form', function(e) {
$.pjax.submit(e, '#main');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for form submit pjax, but we don't use semicolons in pjax code itself, so we don't need to use them in demo code as well.

});
})
</script>

Expand Down Expand Up @@ -51,7 +57,7 @@
## a a .
( '._)
|'-- |
_.\___/_ ___<label><input type="checkbox" name="pjax" />pjax</label>___
_.\___/_ ___<label><input type="checkbox" name="pjax" checked />pjax</label>___
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for making the checked state by default for this demo, but I would prefer if changes unrelated to the form submit pjaxing (the primary topic of your PR) were made as separate commits. It's good git practice in general for any project.

."\> \Y/|<'. '._.-'
/ \ \_\/ / '-' /
| --'\_/|/ | _/
Expand Down
Loading