Comments (5)
Thanks for elaborating on your confusion, I definitely see the ambiguity there.
These options are indeed only related to the labels for the days and not for turning the days on and off in the template. I wrote the note about using moment.js because daysOfTheWeek
and weekOffset
are a little finicky and I'm hoping people avoid using them altogether. The problem is caused by the fact that moment and clndr can both offset the start of the week, which will obviously cause errors.
You're right that this is a matter of writing a template that ignores weekends, and luckily that's not too difficult. I'll give you a start here... There are no back/forward controls, though they are very simple to add:
<script type="text/template" id="full-clndr-template">
<div class="clndr-grid">
<div class="days-of-the-week">
<% _.each(['M', 'T', 'W', 'T', 'F'], function(day) { %>
<div class="header-day"><%= day %></div>
<% }); %>
</div>
<div class="days">
<% _.each(days, function(day) { %>
<% if(day.date.weekday() !== 0 && day.date.weekday() !== 6){ %>
<div class="<%= day.classes %>"><span class="day-number"><%= day.day %></span></div>
<% } %>
<% }); %>
</div>
</div>
</script>
Two things of note:
- The
_.each(['M', 'T', 'W', 'T', 'F'] ... )
call allows us to make five header columns. Normally thedaysOfTheWeek
variable would go here, but that doesn't suit your needs. - We've got an
if
statement inside of thedays
loop, which taps into theday.date
moment object. We can call any moment function here, so I chose to check whether the weekday is equal to 0 or 6, which would denote a weekend.
index.html
in the clndr Github Pages site (https://github.com/kylestetz/CLNDR/blob/gh-pages/index.html) has three different templates you can use as a starting point to learn more about this, and I am happy to answer any other questions you have!
from clndr.
How could this be done in a logic-less templating engine such as handlebars?
<% if(day.date.weekday() !== 0 && day.date.weekday() !== 6){ %>
<div class="<%= day.classes %>"><span class="day-number"><%= day.day %></span></div>
<% } %>
from clndr.
Handlebars has {{#if}}
blocks, so you should be able to write a simple if statement like the one you posted.
I'm not well-versed in handlebars so I will defer to a tutorial of partials and helpers:
http://blog.teamtreehouse.com/handlebars-js-part-2-partials-and-helpers
Let me know if that's helpful!
from clndr.
Thanks, that was helpful indeed! :)
However I'm noticing that if I don't render "Sundays" in my calendar, for some reason it renders a full row of days belonging to next month under the calendar. Am I doing something wrong? Here is a link:
http://sandbox.saeidmohadjer.com/calendar_handlebars.html
from clndr.
This is happening because the Sunday that you are excluding would be the left-most grid element on the bottom row, so it is rendering the entire row. The simple way to get around this would be to pass the option showAdjacentMonths: false
into your clndr configuration.
Since you're using the render
function, you could dig into that data object and remove the last row if the last day of the current month is a Sunday. That would be the hard option.
from clndr.
Related Issues (20)
- 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
- Initialization intervalEnd error with more than one month
- CLNDR2 released
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.