Created
October 7, 2012 03:54
-
-
Save ntotten/3847038 to your computer and use it in GitHub Desktop.
Building Super Fast Web Apps with PJAX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('a.pjax').pjax('#main') | |
| $('#main') | |
| .on('pjax:start', function() { $('#loading').show() }) | |
| .on('pjax:end', function() { $('#loading').hide() }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <a href='/explore' data-pjax='#main'>Explore</a> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('a[data-pjax]').pjax() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = function() { | |
| return function(req, res, next) { | |
| if (req.header('X-PJAX')) { | |
| req.pjax = true; | |
| } | |
| res.renderPjax = function(view, options, fn) { | |
| if (req.pjax) { | |
| if (options) { | |
| options.layout = false; | |
| } else { | |
| options = {}; | |
| options.layout = false; | |
| } | |
| } | |
| res.render(view, options, fn); | |
| }; | |
| next(); | |
| }; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module.exports = function(app) { | |
| app.get('/', function(req, res) { | |
| res.renderPjax('home/index', { title: 'SocialDrawing' }); | |
| }); | |
| app.get('/about', function(req, res) { | |
| res.renderPjax('home/about', { title: 'About' }); | |
| }); | |
| app.get('/contact', function(req, res) { | |
| res.renderPjax('home/contact', { title: 'Contact' }); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment