Last active
August 29, 2015 13:55
-
-
Save nnarhinen/8782434 to your computer and use it in GitHub Desktop.
Datepicker using Bacon.js and CLNDR.js (with Foundation5 styles)
This file contains 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
var Bacon = require('baconjs').Bacon, | |
_ = require('underscore'), | |
moment = require('moment'), | |
Handlebars = require("hbsfy/runtime"); | |
Handlebars.registerHelper('ifDatePickerIsDateSelected', function(a, b, options) { | |
if (a.format('YYYY-MM-DD') === b.format('YYYY-MM-DD')) { | |
return options.fn(this); | |
} | |
return options.inverse(this); | |
}); | |
var tmpl = require('./datepicker.hbs'); | |
module.exports = function(elem, initialDate) { | |
var bus = new Bacon.Bus(); | |
var selectedDate = initialDate || moment(); | |
elem.clndr({ | |
weekOffset: 1, | |
render: function(data) { | |
return tmpl(_.extend({}, data, {selectedDate: selectedDate})); | |
}, | |
clickEvents: { | |
click: function(target) { | |
bus.push(target.date); | |
selectedDate = target.date; | |
this.render(); | |
}, | |
} | |
}); | |
return bus; | |
}; |
This file contains 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
.clndr-grid | |
.day,.header-day | |
text-align: center | |
padding-bottom: 5px | |
padding-top: 5px | |
-moz-box-sizing: border-box | |
box-sizing: border-box | |
padding-left: 0px | |
padding-right: 0px | |
width: 14.28% | |
.selected | |
background-color: #008CBA | |
color: white | |
.today | |
font-weight: bold |
This file contains 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
var datepicker = require('./datepicker'), | |
moment = require('moment'), | |
$ = require('jquery'); | |
var initialStartDate = moment().add('months', -1).date(1), | |
initialEndDate = moment().date(0), | |
start = datepicker($('.period-start'), initialStartDate).toProperty(initialStartDate); | |
stop = datepicker($('.period-end'), initialEndDate).toProperty(initialEndDate); | |
start.map('.format', 'DD.MM.YYYY').assign($('.period-start-txt'), 'text'); | |
stop.map('.format', 'DD.MM.YYYY').assign($('.period-end-txt'), 'text'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment