Low Events Ajax Calendar
Do you perhaps have any documentation or code snippets that would help me to implement the events calendar with ajax. In other words, not reload the page when clicking the previous or next buttons ?
Any suggestions or pointers would be greatly appreciated.
Replies
Low 23 Jan 2014 09:41
I don't have any docs or examples on that -- it's front-end implementation, which is up to you. However, here's how I would approach it:
- Make sure the bits that need to be reloaded is in its own template. Usually, that would be the Entries tag (eg. events/_entries)
- Embed this template in the main template where you want to display them (eg. {embed="events/_entries"}
- Generate the prev/next links like you normally would, and make sure everything works without JS.
- Use JS to catch the clicks on the prev/next links, change the href to target the embedded template only, and load that up using Ajax, inserting the result in the DOM.
Celéste Erasmus 23 Jan 2014 09:46
great ! thank you !
Celéste Erasmus 23 Jan 2014 12:46
It's working nicely, but only the first time that you click the next or previous buttons.
On the second click, it redirects to the embed template.
Can you think what mistake I might be making ?
$('#prev').click(function(e){
e.preventDefault();
var prev = $(this).attr("href");
$('#calendar').load(prev);
});
Low 23 Jan 2014 13:26
You'll need to delegate the onclick handler. Something like this:
Celéste Erasmus 23 Jan 2014 13:45
found it - had to adjust my click handler, because the element is loaded dynamically:
$(document).on('click', '#next', function(e){
e.preventDefault();
var next = $(this).attr("href");
$('#calendar').load(next);
});
Celéste Erasmus 23 Jan 2014 13:48
thank you very much for your feedback - appreciate it
Celéste Erasmus 30 Jan 2015 06:02
The Ajax calendar works well, but I now need to limit how far in advance the user can browse. As soon as I add date_to="+365 day" the next_month nav arrow no longer works. I'm struggling to figure out why. Am I using date_to incorrectly ?
Low 30 Jan 2015 08:14
The Calendar tag doesn't have a date_to parameter. Instead, you'd have to use conditionals to show/hide the prev/next links.