Comments (7)
Try console.log(target)
in your click handler and check out the developer console. My use of the word target
here is a bit misleading... This is the object you get back when the click event is fired:
target: {
element: DOMElement,
date: moment(),
events: []
}
So you'd want to point your window.location.href
to something like target.events[0].url
, however there's no guarantee that the day a user clicks on even has events in it.
As a suggestion, you might want to try adding a URL to the event in the template instead. Then you don't even need click events. While looping through the days
array you might throw something like this in your template:
<% if(days[i].events.length) { %>
<% _.each(days[i].events, function(event) { %>
<a href="<%= event.url %>"><%= event.title %></a>
<% }) %>
<% } %>
Let me know if that's confusing.
from clndr.
@kylestetz, I understand. It works now! Thanks!
from clndr.
Well, I just realized I should use the alternative solution as you said. I can't get it to work
Here is my template:
<div id="full-clndr" class="clearfix">
<script type="text/template" id="full-clndr-template">
<div class="controls">
<div class="clndr-previous-button">‹</div><div class="month"><%= month %> <%= year %></div><div class="clndr-next-button">›</div>
</div>
<div class="clndr-grid">
<div class="days-of-the-week clearfix">
<% _.each(daysOfTheWeek, function(day) { %>
<div class="header-day"><%= day %></div>
<% }); %>
</div>
<div class="days clearfix">
<% _.each(days, function(day) { %>
<div class="<%= day.classes %>" id="<%= day.id %>"><span class="day-number"><%= day.day %></span></div>
<% }); %>
</div>
</div>
<div class="event-listing">
<div class="event-listing-title">EVENTS THIS MONTH</div>
<% _.each(eventsThisMonth, function(event) { %>
<a href="<%= event.url %>"><div class="event-item">
<div class="event-item-name"><%= event.title %></div>
<div class="event-item-location"><%= event.location %></div>
</div></a>
<% }); %>
</div>
</script>
</div>
from clndr.
That template is working fine for me with the events array you posted earlier. What is the problem exactly?
from clndr.
Where do I insert the code?
<% if(days[i].events.length) { %>
<% _.each(days[i].events, function(event) { %>
<a href="<%= event.url %>"><%= event.title %></a>
<% }) %>
<% } %>
from clndr.
Oh! Sorry, I misunderstood. There are two ways you can do this depending on how you want it to function.
1: The entire day on the calendar is one big link. This poses a problem if you plan to have more than one event on the same day (wouldn't recommend going down this road).
2: Each event is listed inside of the day in which it takes place. That's the code example I was giving you, which would go here (I took out the if statement because it was redundant):
<div id="full-clndr" class="clearfix">
<script type="text/template" id="full-clndr-template">
<div class="controls">
<div class="clndr-previous-button">‹</div><div class="month"><%= month %> <%= year %></div><div class="clndr-next-button">›</div>
</div>
<div class="clndr-grid">
<div class="days-of-the-week clearfix">
<% _.each(daysOfTheWeek, function(day) { %>
<div class="header-day"><%= day %></div>
<% }); %>
</div>
<div class="days clearfix">
<% _.each(days, function(day) { %>
<div class="<%= day.classes %>" id="<%= day.id %>">
<span class="day-number"><%= day.day %></span>
<!-- perhaps here is a good place? -->
<% _.each(day.events, function(event) { %>
<a href="<%= event.url %>"><%= event.title %></a>
<% }) %>
</div>
<% }); %>
</div>
</div>
<div class="event-listing">
<div class="event-listing-title">EVENTS THIS MONTH</div>
<% _.each(eventsThisMonth, function(event) { %>
<a href="<%= event.url %>"><div class="event-item">
<div class="event-item-name"><%= event.title %></div>
<div class="event-item-location"><%= event.location %></div>
</div></a>
<% }); %>
</div>
</script>
</div>
from clndr.
I'm just going to stick with the first option so that I can have the event link fill the entire day.
from clndr.
Related Issues (20)
- This Template is not working? HOT 1
- custom `options.targets.day` is ignored and days which don't have the `day` class loose their `inactive` class HOT 2
- It's possible to move self.options.clickEvents.click.apply(self, [target]); after setting the selected date? HOT 2
- Previous and Next months appear. I just want to show the current month. HOT 5
- how can i translate month into chinese?
- Have multiple classes for an events such as a class for a bank holiday and school holiday class HOT 2
- Feature Request: Multi-day select HOT 1
- set month and year same time HOT 2
- "Na" being displayed instead of previous month's dates HOT 3
- Destroy Clndr In Internet Explorer IE 11 HOT 1
- Generating `daysOfTheWeek` array with only first character HOT 11
- Styling/CSS Not showing HOT 3
- Can I have the mini-calendar without the full calendar?
- Get clicked date in calander
- Drop jQuery dependency HOT 1
- How can I show current month in number?
- how can I stay the same month when returning back to this page HOT 1
- Usage docs should explain how to use eventsThisInterval HOT 1
- hi If I wants to change the calendar start day order from Sunday to Monday how can I change it HOT 2
- Improper translations with the localization features
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 clndr.