Giter Site home page Giter Site logo

Comments (7)

kylestetz avatar kylestetz commented on May 4, 2024

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.

DaAwesomeP avatar DaAwesomeP commented on May 4, 2024

@kylestetz, I understand. It works now! Thanks!

from clndr.

DaAwesomeP avatar DaAwesomeP commented on May 4, 2024

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">&lsaquo;</div><div class="month"><%= month %> <%= year %></div><div class="clndr-next-button">&rsaquo;</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.

kylestetz avatar kylestetz commented on May 4, 2024

That template is working fine for me with the events array you posted earlier. What is the problem exactly?

from clndr.

DaAwesomeP avatar DaAwesomeP commented on May 4, 2024

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.

kylestetz avatar kylestetz commented on May 4, 2024

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">&lsaquo;</div><div class="month"><%= month %> <%= year %></div><div class="clndr-next-button">&rsaquo;</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.

DaAwesomeP avatar DaAwesomeP commented on May 4, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.