Calentim is a Date/Time Range Picker plugin, built using jQuery and moment.js libraries. You can use it as a date time range picker, as a date picker, or as a time picker. You can show it inline, or use as a dropdown for any element.
It's a range picker, with time!
You can use default ranges, or define your own!
It can also be used as a single date time picker!
You can modify all the picker's behaviour like hiding some part, disabling some feature etc.
Supports fast month and year navigation!
If you don't like dropdowns, you can convert your input to an inline calendar!
It renders beautifully on mobile devices
Also has a different landscape layout
You can slide between months!
We support them all!
(What moment.js supports :P)
You can re-design completely using SASS.
Yes, it's the automation era.
The main files of this plugin are calentim.min.js
and calentim.min.css
, which are generated by compiling and minifying calentim.js
and calentim.css
. The plugin relies on jQuery and moment.js libraries, also needs to be included before including calentim.min.js
.
The font used on this plugin is Roboto, and the icons are provided by Font Awesome which are included remotely from their CDN's. You can change it anyway you want.
The example configuration which can be found in the base index file is:
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,500,700" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-2.1.4.min.js" type="text/javascript"><\/script>');
</script>
<!-- .calentim includes -->
<link href="build/css/calentim.min.css" rel="stylesheet"/>
<script src="build/js/moment.min.js"></script>
<script src="build/js/calentim.min.js"></script>
<!-- .end calentim includes -->
Then, to attach a Calentim object to an element you desire, use this:
$(".calentim").calentim();
You can customize your plugin with options you provide to the initializing function,
$(".calentim").calentim({inline: true, startOnMonday: true});
or the element's data-plugin-options
property.
<input class="calentim" data-plugin-options='{"calendarCount":1,"showHeader":true,"showFooter":true}'
name="calendar-input" type="text" value="08.08.2017 12:43 - 08.09.2017 13:11"/>
Once initalized, you can access the calentim object like this:
var calentim = $(".calentim:eq(3)").data("calentim");
calentim.config.startDate = new Date();
calentim.reDrawCalendars();
Once you've got the calentim
instance object, you can access these properties:
elem
[DOM node object]: The HTML dom node which the instance is created on.$elem
[jQuery Object]: jQuery object of the dom node. Equals to $(calentim.elem)
Please Note that if you've chosen a different target element, you will be accessing the initiator element by calling
calentim.$elem
. Your actual target element would becalentim.config.target
.
For example,
var calentim = $("#elem1").calentim();
// calentim.elem will be equal to document.getElementById("elem1") or $("#elem1").get(0);
// calentim.$elem will be equal to $("#elem1");
config
[JS Object]: The instance's configuration object. Consists of merging default values and user defined settings. The details of it is explained in the Options section.
These properties are also defined, but not recommended to tinker on.
container
[jQuery Object]: This refers to the outermost container element of the instance dropdown or inline instance and the input itself.header
[jQuery Object]: This refers to the header part of the plugin.footer
[jQuery Object]: This refers to the footer part, - not the mobile buttons part - the ranges part of the plugin.input
[jQuery Object]: This refers to the first child of the container, which contains everything except the input which is calentim instantiated on.These are the options you can set with the javascript plugin initialization object, or with the data-plugin-options
html attribute on the input element, or within the events by directly modifying the calentim.config
object.
startDate
[moment object|javascript Date Object|string]: the selected start date, initially today is selected if not defined inside the input's value, or any of the initialization configuration methods.
endDate
[moment object|javascript Date Object|string]: the selected end date, initially today is selected if not defined inside the input's value, or any of the initialization configuration methods.
format
[string]: the default format for showing in input, defaults to short date format of locale, for all possible inputs, look here: https://momentjs.com/docs/#/displaying/format/ default: 'L LT'
hourFormat
[number]: the format for the time pickers. Can be 12 or 24, if set anything else, will revert to default 24. default '24'
Note: Be careful when setting this option, you might need to pick a suitable format for the format
variable too. For example, you might set 12 hour calendar with L HH:mm format, and then receive 24 hour data on your backend.
dontPrefixHours
[boolean]: If the 12 hour format is selected, you can set this to true to get one digit hours without the "0" prefix. Default: false
minuteSteps
[number]: the minute steps you want to show on your minute picker, for example, if you set 15 as the step, you'll get 0, 15, 30 and 45 in your minute picker. Default: 1
dateSeparator
[string]: if not used as a single date picker, this will be the seperator, default " - ".
calendarCount
[integer]: how many calendars will be shown in the plugin screen, default 2
inline
[boolean]: display as an inline input replacement instead of input dropdown. default: false
minDate
[moment object|javascript Date Object|string|null]: minimum selectable date, default null (no minimum)
maxDate
[moment object|javascript Date Object|string|null]: maximum selectable date, default null (no maximum)
showHeader
[boolean]: visibility of the part which displays the selected start and end dates, default true
showFooter
[boolean]: visibility of the part which contains user defined ranges, default true
showButtons
[boolean]: whether the input should display the apply and cancel buttons in dropdown, default false
startEmpty
[boolean]: whether the input should remain empty until user makes a selection, default false
hideOutOfRange
[boolean]: when used with minDate and/or maxDate, the navigation arrows will be hidden on the available first and last months to prevent further navigation. default false
enableKeyboard
[boolean]: enable this if you want to add keyboard support to the calendar. The keys are:startOnMonday
[boolean]: false, // if you want to start the calendars on Monday, set this to true. Note that if the locale already starts on Monday, this setting will be ignored.
container
[string]: the selector of the dropdowns container, default "body"
oneCalendarWidth
[integer]: the width of one calendar, if two calendars are shown, the input width will be 2 * this setting. default 230
showOn
["bottom"|"top"|"left"|"right"|"center"]: dropdown placement position relative to input element, will be adjusted to the viewport, default "bottom"
arrowOn
["bottom"|"top"|"left"|"right"|"center"]: arrow position relative to dropdown element, will be adjusted to the viewport, default "left"
autoAlign
[boolean]: enables dropdown auto placement change when the dropdown is not fully visible on the viewport. Default "true"
locale
[string]: moment locale setting, for more information: https://momentjs.com/docs/#/i18n/changing-locale/, and for a list of available locales: https://momentjs.com/ (bottom of the page)
singleDate
[boolean]: if you want a single date picker, set this to true, default false
target
: [jquery object] the element to update after selection, if it's null, the element that is instantiated on will be updated. default null
ranges
: [array] predefined ranges range objects array, which each will create a button in the footer, and when the user clicks, it'll automatically will be applied. One range is defined like below:
title
[string]: the label which will appear on the button,startDate
[moment object|javascript Date Object|string]: the first date of the range,endDate
[moment object|javascript Date Object|string]: the last date of the range,
rangeLabel
[string] : The title displayed in the defined ranges list section, default "Ranges: "
cancelLabel
[string]: The cancel button label, default "Cancel"
applyLabel
[string]: The apply button label, default "Apply"
enableMonthSwitcher
[boolean]: Enables the month switcher when clicking on month names. Default: true
monthSwitcherFormat
[boolean]: Changes the month name display format on the month switcher. Default: "MMMM"
enableYearSwitcher
[boolean]: Enables the year switcher when clicking on years. Default: true
numericMonthSwitcher
[boolean]: If set to true, shows month numbers instead of month names in month selector. Default: false
monthSwitcherFormat
[string]: Changes the format of the month name displayed on the month selector. Default: "MMMM" (long month name format)
showWeekNumbers
[string]: Shows week numbers on the left of the calendars. Default: false
autoCloseOnSelect
[boolean]: On instances that are not displayed inline, this setting is used to automatically close the dropdown when a selection is made.
disableDays
[function]: Enables day based disabling filters, input value is the current day to be processed. Example:{
disableDays: function(day){
return day.isSame(moment("17/05/2017")); // will return true on that day and the day will be disabled.
}
}
disabledRanges
[object array]: Enables user to disable specific ranges from selection. Can be used with continuous
option to preserve continuity. Object structure: [{ start: [moment object], end: [moment object]}, ..]
continuous
[boolean]: Adds a check if the selected range continues any disabled days. Reverts the selection to it's original state when the user tries to select a range which contains a disabled date.
limitTimeForDay
[function]: Limits the time selection based on the day parameter, input value is the current day to be processed. Example:{
limitTimeForDay: function (day) {
if (day.isoWeekday() === 6 || day.isoWeekday() === 7) {
return { start: { hour: 8, minute: 15, ampm: null }, end: { hour: 18, minute: 21, ampm: null } };
} else {
return { start: { hour: 9, minute: 30, ampm: null }, end: { hour: 16, minute: 45, ampm: null } };
}
}
}
This limits the time selection to 8:15 and 18:21 if the day is on weekends, if it's not, it limits the selection to 9:30 to 16:45. You can see a working example in the examples section.
rangeOrientation
[string]: Sets the range view to "vertical" or "horizontal" which renders the range part on the right or on the bottom of the calendar. Default: "horizontal"
verticalRangeWidth
[string]: Sets the vertical range view panel width in pixels. Default: 150onbeforeselect
[function]: event which is triggered before selecting the end date ( a range selection is completed). The return value decides whether the selection will happen. Returning false will prevent the input to update.
Prototype:
onbeforeselect: function(calentim, startDate, endDate){
// calentim: calentim object instance
// startDate: moment.js instance
// endDate: moment.js instance
return true; // false prevents update
}
onafterselect
[function]: event which is triggered after selecting the end date ( the input value changed )
Prototype:
onafterselect: function(calentim, startDate, endDate){
// calentim: calentim object instance
// startDate: moment.js instance
// endDate: moment.js instance
}
onbeforeshow
[function]: event which is triggered before showing the dropdown
Prototype:
onbeforeshow: function(calentim){
// calentim: calentim object instance
}
onbeforehide
[function]: event which is triggered before hiding the dropdown
Prototype:
onbeforehide: function(calentim){
// calentim: calentim object instance
}
onaftershow
[function]: event which is triggered after showing the dropdown
Prototype:
onaftershow: function(calentim){
// calentim: calentim object instance
}
onafterhide
[function]: event which is triggered after hiding the dropdown
Prototype:
onafterhide: function(calentim){
// calentim: calentim object instance
}
onfirstselect
[function]: event which is triggered after selecting the first date of ranges
Prototype:
onfirstselect: function(calentim, startDate){
// calentim: calentim object instance
// startDate: moment.js instance
}
onrangeselect
[function]: event which is triggered after selecting a range from the defined range links
Prototype:
onrangeselect: function(calentim, range){
// calentim: calentim object instance
// range: selected range definition
}
onbeforemonthchange
[function]: event which fires before changing the first calendar month of multiple calendars, or the month of a single calendar. The return value decides whether the month switch will take place.
Prototype:
onbeforemonthchange: function(calentim, month, direction){
// calentim: calentim object instance
// month : moment.js object of first day of the month selected on the **first** calendar
// direction: "next" or "prev", shows the month change direction. if `month.month()` is 4,
// and direction is "prev", next month will be 3.
return true; // false disables switching
}
onaftermonthchange
[function]: event which fires after changing the first calendar month of multiple calendars, or the month of a single calendar
Prototype:
onaftermonthchange: function(calentim, month){
// calentim: calentim object instance
// month : moment.js object of first day of the month selected on the first calendar
}
onafteryearchange
[function]: event which fires after changing the first calendar year of multiple calendars, or the year of a single calendar
Prototype:
onafteryearchange: function(calentim, year){
// calentim: calentim object instance
// year : moment.js object of first day of the year selected on the first calendar
}
ondraw
[function]: event which fires after redraws in calendar
Prototype:
onredraw: function(calentim){
// calentim: calentim object instance
}
oninit
[function]: event which fires after instance initialization
Prototype:
oninit: function(calentim){
// calentim: calentim object instance
}
onBeforeInit
[function]: event which fires before instance initialization
Prototype:
onBeforeInit: function(calentim){
// calentim: calentim object instance
}
ondestroy
[function]: event which fires after instance destruction
Prototype:
ondestroy: function(calentim){
// calentim: calentim object instance
}
onBeforeDestroy
[function]: event which fires before instance destruction, if you return false
to this functino, it cancels the destruction.
Prototype:
onBeforeDestroy: function(calentim){
// calentim: calentim object instance
return true;
}
ontimechange
[function]: event which fires after timepicker value changes
Prototype:
ontimechange: function(calentim, startDate, endDate){
// calentim: calentim object instance
// startDate: the start date moment object
// endDate: the end date moment object
}
validateDates
[function]: Validates the startDate, endDate, minDate, maxDate parameters of the instance configuration, by the means of parsability and order, and defaults to today's date for startDate and endDate, and to null for maxDate and minDate.
fetchInputs
[function]: Retrieves the date(s) from the instance holder input and validates them before putting it to it's configuration.
updateInput
[function]: Updates the instance holder input with the instance values and configuration.
drawNextMonth
[function]: Triggers the instance show the next month after the first calendar month as the first calendar.
drawPrevMonth
[function]: Triggers the instance show the previous month before the first calendar month as the first calendar.
reDrawCalendars
[function]: Triggers a complete restructuring of the instance. Drawing the container first, then the header, then the calendars, then the footer.
reDrawCells
[function]: Only modifies the calendar's related parts with the configuration variables. Doesn't entirely build the instance again like reDrawCalendars
method does.
setViewport
[function]: On dropdown instances, if the dropdown falls outside of the viewport (when shown, not scrolled) this function decides and calculates it's new position opposed to its configuration. For example, if the dropdown position is set to bottom
and it falls below the page bottom edge, this method makes it appear as it was set to top
for once.
showDropdown
[function]: On dropdown and mobile instances, if the dropdown is not visible, this method triggers the show method.
hideDropdown
[function]: On dropdown and mobile instances, if the dropdown is visible, this method hides it.
setStart
[function]: Sets the start date and time of the input.
setEnd
[function]: Sets the end date and time of the input.
setMinDate
[function]: Sets the minimum selectable date of the input. Time portion is ignored.
setMaxDate
[function]: Sets the maximum selectable date of the input. Time portion is ignored.
setDisplayDate
[function] : Sets the displayed month and year, day and time are ignored.
var instance = $(".calentim").data("calentim");
// using moment object
instance.setStart(moment());
// using javascript Date object
instance.setStart(new Date());
// using ISO and RFC standardized date strings
instance.setStart("2017-11-27T13:07:04+00:00"); // ISO 8601 and RFC 3339
instance.setStart("Mon, 27 Nov 2017 13:07:04 +0000"); // RFC 822, 1035, 1123, 2822
instance.setStart("Monday, 27-Nov-17 13:07:04 UTC"); // RFC 2822
// using unix timestamp
instance.setStart(1511788024);
// using custom formatted date time string
instance.setStart(moment("16:06 27.11.2017","HH:mm dd.MM.YYYY"));
Preview:
HTML:
<input type="text" id="calentim-ex-1" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-1").calentim();
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-1-1" />
<input type="text" id="calentim-ex-1-2" />
<input type="text" id="calentim-ex-1-3" />
<input type="text" id="calentim-ex-1-4" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-1-1").calentim({showOn:"top",autoAlign:true});
$("#calentim-ex-1-2").calentim({showOn:"left",autoAlign:true});
$("#calentim-ex-1-3").calentim({showOn:"right",autoAlign:true});
$("#calentim-ex-1-4").calentim({showOn:"bottom",autoAlign:true});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-1-5" />
<input type="text" id="calentim-ex-1-6" />
<input type="text" id="calentim-ex-1-7" />
<input type="text" id="calentim-ex-1-8" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-1-5").calentim({showOn:"top",autoAlign:false});
$("#calentim-ex-1-6").calentim({showOn:"left",autoAlign:false});
$("#calentim-ex-1-7").calentim({showOn:"right",autoAlign:false});
$("#calentim-ex-1-8").calentim({showOn:"bottom",autoAlign:false});
</script>
Preview:
HTML:
<style> .vhide{ visibility:hidden; } </style>
<input type="text" class="vhide"><input type="text" id="calentim-ex-t-r" value="06/21/2017" /><input type="text" id="calentim-ex-t-c" value="06/21/2017" /><input type="text" id="calentim-ex-t-l" value="06/21/2017" /><input type="text" class="vhide"><br><br>
<input type="text" id="calentim-ex-l-t" value="06/21/2017" /><input type="text" class="vhide"><input type="text" class="vhide"><input type="text" class="vhide"><input type="text" id="calentim-ex-r-t" value="06/21/2017" /><br><br>
<input type="text" id="calentim-ex-l-c" value="06/21/2017" /><input type="text" class="vhide"><input type="text" id="calentim-ex-c-c" value="06/21/2017" /><input type="text" class="vhide"><input type="text" id="calentim-ex-r-c" value="06/21/2017" /><br><br>
<input type="text" id="calentim-ex-l-b" value="06/21/2017" /><input type="text" class="vhide"><input type="text" class="vhide"><input type="text" class="vhide"><input type="text" id="calentim-ex-r-b" value="06/21/2017" /><br><br>
<input type="text" class="vhide"><input type="text" id="calentim-ex-b-r" value="06/21/2017" /><input type="text" id="calentim-ex-b-c" value="06/21/2017" /><input type="text" id="calentim-ex-b-l" value="06/21/2017" /><input type="text" class="vhide"><br><br>
JavaScript:
<script type="text/javascript">
$("#calentim-ex-t-r").calentim({
showOn: "top",
arrowOn: "right"
});
$("#calentim-ex-t-c").calentim({
showOn: "top",
arrowOn: "center"
});
$("#calentim-ex-t-l").calentim({
showOn: "top",
arrowOn: "left"
});
$("#calentim-ex-l-c").calentim({
showOn: "left",
arrowOn: "center"
});
$("#calentim-ex-l-t").calentim({
showOn: "left",
arrowOn: "top"
});
$("#calentim-ex-l-b").calentim({
showOn: "left",
arrowOn: "bottom"
});
$("#calentim-ex-c-c").calentim({
showOn: "center",
arrowOn: "center"
});
$("#calentim-ex-r-c").calentim({
showOn: "right",
arrowOn: "center"
});
$("#calentim-ex-r-t").calentim({
showOn: "right",
arrowOn: "top"
});
$("#calentim-ex-r-b").calentim({
showOn: "right",
arrowOn: "bottom"
});
$("#calentim-ex-b-r").calentim({
showOn: "bottom",
arrowOn: "right"
});
$("#calentim-ex-b-c").calentim({
showOn: "bottom",
arrowOn: "center"
});
$("#calentim-ex-b-l").calentim({
showOn: "bottom",
arrowOn: "left"
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-2" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-2").calentim({showHeader: false});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-3" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-3").calentim({showFooter: false});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-3-3" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-3-3").calentim({
showCalendars: false,
format: "hh:mm A"
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-3-4" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-3-4").calentim({showTimePickers: false, format: "L"});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-5-1" placeholder="Select a Date" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-5-1").calentim({startEmpty: true});
</script>
This will only work with dropdown desktop view, inline views don't support cancel and apply buttons. Mobile modal view already has them.
Preview:
HTML:
<input type="text" id="calentim-ex-5-3" placeholder="Select a Date" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-5-1").calentim({showButtons: true});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-3-1" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-3-1").calentim({
format: "DD/MM/YYYY HH:mm",
hourFormat: 24
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-3-2" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-3-2").calentim({
minuteSteps: 15
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-3-5" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-3-5").calentim({
reverseTimepickerArrows: true
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-4" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-4").calentim({calendarCount: 3});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-5" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-5").calentim({inline: true});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-5-2" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-5-2").calentim({
inline: true,
showCalendars: false,
format: "hh:mm A"
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-6" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-6").calentim({singleDate: true});
</script>
Preview:
HTML:
<label for='single-calentim-mod'>
<input type='radio' value="single" id='single-calentim-mod' name="calentim-type-selector"
class='calentim-type-selector'>
Single Date
</label>
<label for='multi-calentim-mod'>
<input type='radio' value="multi" id='multi-calentim-mod' name="calentim-type-selector"
class='calentim-type-selector' checked>
Multiple Dates
</label>
<input type="text" id="calentim-ex-6-4" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-6-4").calentim();
$(".calentim-type-selector").click(function(){
$("#calentim-ex-6-4").data("calentim").destroy();
$("#calentim-ex-6-4").calentim({
singleDate: $("input[name='calentim-type-selector']:checked").val() == "single" ? true : false
});
});
</script>
Preview:
HTML:
<div style='display: flex;'>
<div>Start Date: <input type="text" id="calentim-ex-6-5-start" /></div>
<div style='margin-left:20px;'>End Date: <input type="text" id="calentim-ex-6-5-end" /></div>
</div>
JavaScript:
<script type="text/javascript">
var startDate, endDate, startInstance, endInstance;
var fillInputs = function () {
if (startDate) startInstance.$elem.val(startDate.locale(startInstance.config.locale).format(startInstance.config.format));
if (endDate) endInstance.$elem.val(endDate.locale(endInstance.config.locale).format(endInstance.config.format));
};
var beforeShow = function (instance) {
if (startDate) {
startInstance.config.startDate = startDate.clone();
endInstance.config.startDate = startDate.clone();
}
if (endDate) {
startInstance.config.endDate = endDate.clone();
endInstance.config.endDate = endDate.clone();
}
fillInputs();
instance.updateHeader();
instance.reDrawCells();
instance.updateTimePickerDisplay();
};
$("#calentim-ex-6-5-start").calentim({
startEmpty: $("#calentim-ex-6-5-start").val() === "",
startDate: $("#calentim-ex-6-5-start").val(),
endDate: $("#calentim-ex-6-5-end").val(),
enableKeyboard: false,
oninit: function (instance) {
startInstance = instance;
if (!instance.config.startEmpty && instance.config.startDate) {
instance.$elem.val(instance.config.startDate.locale(instance.config.locale).format(instance.config.format));
startDate = instance.config.startDate.clone();
}
},
onaftershow: beforeShow,
ontimechange: function (instance, start, end) {
if(start) startDate = start.clone();
if(end) endDate = end.clone();
fillInputs();
},
onfirstselect: function (instance, start) {
startDate = start.clone();
endDate = null;
startInstance.globals.startSelected = false;
startInstance.hideDropdown();
endInstance.showDropdown();
endInstance.setDisplayDate(start.clone());
endInstance.config.minDate = startDate.clone();
endInstance.config.startDate = startDate.clone();
endInstance.config.endDate = null;
endInstance.globals.startSelected = true;
endInstance.globals.endSelected = false;
endInstance.globals.firstValueSelected = true;
if (endDate && startDate.isAfter(endDate)) {
endInstance.config.endDate = endDate.clone();
}
fillInputs();
endInstance.updateHeader();
endInstance.reDrawCells();
endInstance.updateTimePickerDisplay();
}
});
$("#calentim-ex-6-5-end").calentim({
startEmpty: $("#calentim-ex-6-5-end").val() === "",
startDate: $("#calentim-ex-6-5-start").val(),
endDate: $("#calentim-ex-6-5-end").val(),
enableKeyboard: false,
autoCloseOnSelect: true,
oninit: function (instance) {
endInstance = instance;
if (!instance.config.startEmpty && instance.config.endDate) {
instance.$elem.val(instance.config.endDate.locale(instance.config.locale).format(instance.config.format));
endDate = instance.config.endDate.clone();
}
},
onaftershow: beforeShow,
ontimechange: function (instance, start, end) {
if(start) startDate = start.clone();
if(end) endDate = end.clone();
fillInputs();
},
onafterselect: function (instance, start, end) {
startDate = start.clone();
endDate = end.clone();
endInstance.hideDropdown();
startInstance.config.endDate = endDate.clone();
startInstance.globals.firstValueSelected = true;
fillInputs();
endInstance.globals.startSelected = true;
endInstance.globals.endSelected = false;
}
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-6-2" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-6-2").calentim({
singleDate: true,
calendarCount: 1,
showHeader: false,
showFooter: false,
autoCloseOnSelect: true
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-6-7" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-6-7").calentim({
limitTimeForDay: function (day) {
if (day.isoWeekday() === 6 || day.isoWeekday() === 7) {
return { start: { hour: 8, minute: 15, ampm: null }, end: { hour: 18, minute: 21, ampm: null } };
} else {
return { start: { hour: 9, minute: 30, ampm: null }, end: { hour: 16, minute: 45, ampm: null } };
}
}
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-6-7-1" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-6-7-1").calentim({
limitTimeForDay: function (day) {
if (day.isoWeekday() === 6 || day.isoWeekday() === 7) {
return { start: { hour: 8, minute: 15, ampm: "am" }, end: { hour: 6, minute: 21, ampm: "pm" } };
} else {
return { start: { hour: 9, minute: 30, ampm: "pm" }, end: { hour: 4, minute: 45, ampm: "pm" } };
}
}
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-6-7-2" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-6-7-2").calentim({
hourFormat: 24,
limitTimeForDay: function (day) {
if (day.isoWeekday() === 6 || day.isoWeekday() === 7) {
return { start: { hour: 9, minute: 0, ampm: null }, end: { hour: 12, minute: 30, ampm: null } };
} else {
return [
{ start: { hour: 9, minute: 0, ampm: null }, end: { hour: 12, minute: 30, ampm: null } },
{ start: { hour: 13, minute: 30, ampm: null }, end: { hour: 18, minute: 00, ampm: null } }
];
}
}
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-6-6-1" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-6-6-1").calentim({
rangeOrientation: "vertical"
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-6-6-2" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-6-6-2").calentim({
rangeOrientation: "vertical",
showButtons: true
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-6-6-3" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-6-6-3").calentim({
inline: true,
rangeOrientation: "vertical"
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-6-6-4" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-6-6-4").calentim({
showWeekNumbers: true
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-6-1" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-6-1").calentim({autoCloseOnSelect: true});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-6-3" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-6-3").calentim({
minDate: moment().subtract(1, "weeks").startOf("week"),
maxDate: moment().add(1, "weeks").endOf("week")
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-7" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-7").calentim({ranges: [
{
title: "Next Week",
startDate: moment().add(1,"weeks").startOf("week"),
endDate: moment().add(1,"weeks").endOf("week")
},
{
title: "Today",
startDate: moment(),
endDate: moment()
},
{
title: "Yesterday",
startDate: moment().subtract(1,"days"),
endDate: moment().subtract(1,"days")
},
{
title: "Last 7 days",
startDate: moment().subtract(7,"days"),
endDate: moment().subtract(1,"days")
},
{
title: "Last 30 days",
startDate: moment().subtract(30,"days"),
endDate: moment().subtract(1,"days")
},
{
title: "This month",
startDate: moment().startOf("month"),
endDate: moment().endOf("month")
},
{
title: "Last month",
startDate: moment().subtract(1,"months").startOf("month"),
endDate: moment().subtract(1,"months").endOf("month")
}
]});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-8" />
<div class="calentimlabel"></div>
JavaScript:
<script type="text/javascript">
$("#calentim-ex-8").calentim({
onafterselect: function(calentim, startDate, endDate) {
calentim.$elem.closest(".well").find(".calentimlabel")
.text("You have chosen between " + startDate.format('LLLL') + " and " + endDate.format('LLLL'));
}
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-9-1" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-9-1").calentim({
isHotelBooking: true,
continuous: true,
startEmpty: true,
minSelectedDays: 1,
disabledRanges: [
{
start: moment(),
end: moment().add(2, "days")
}
]
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-9" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-9").calentim({startOnMonday: true});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-10" />
JavaScript:
<script type="text/javascript">
var userLanguage = navigator.language || navigator.userLanguage;
if(userLanguage == "en") userLanguage = "fr";
$("#calentim-ex-10").calentim({locale: userLanguage });
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-10-2" />
JavaScript:
<script type="text/javascript">
var userLanguage = navigator.language || navigator.userLanguage;
if(userLanguage == "en") userLanguage = "fr";
$("#calentim-ex-10-2").calentim({locale: userLanguage, inline: true });
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-10-3" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-10-3").calentim({locale: "ar", inline: true });
</script>
Preview:
HTML:
<div dir="rtl">
<input type="text" id="calentim-ex-10-4" />
</div>
JavaScript:
<script type="text/javascript">
$("#calentim-ex-10-4").calentim({locale: "ar", isRTL: true, arrowOn: "right" });
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-10-1" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-10").calentim({
onfirstselect: function(elem,start){
elem.config.startDate = moment(start).startOf("week");
elem.config.endDate = moment(start).endOf("week");
elem.globals.endSelected = true;
elem.globals.startSelected = false;
elem.globals.hoverDate = null;
elem.container.find( ".calentim-apply" ).removeAttr( "disabled" );
elem.updateInput();
}
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-11-target" />
<button id="calentim-ex-11">Open calentim</button>
JavaScript:
<script type="text/javascript">
$("#calentim-ex-11").calentim({target: $("#calentim-ex-11-target")});
</script>
Note: This task would only fill the input on Wednesdays, because the only valid (selectable) dates are Wednesdays on the calendar. If the start day or end day isn't selectable, the plugin will revert itself to startEmpty
state when initialized.
Preview:
HTML:
<input type="text" id="calentim-ex-13" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-13").calentim({
disableDays: function(day){
return day.day() != 3;
}
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-13-2" value="03/19/2017 12:00 AM - 03/20/2017 12:00 AM" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-13-2").calentim({
disabledRanges: [
{
"start": moment("10/03/2017","DD/MM/YYYY"),
"end": moment("18/03/2017", "DD/MM/YYYY")
},
{
"start": moment("01/04/2017","DD/MM/YYYY"),
"end": moment("05/04/2017", "DD/MM/YYYY")
},
{
"start": moment("11/04/2017","DD/MM/YYYY"),
"end": moment("15/04/2017", "DD/MM/YYYY")
}
]
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-13-3" value="03/19/2017 12:00 AM - 03/20/2017 12:00 AM" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-13-3").calentim({
continuous: true,
disabledRanges: [
{
start: moment("10/03/2017","DD/MM/YYYY"),
end: moment("18/03/2017", "DD/MM/YYYY")
},
{
"start": moment("01/04/2017","DD/MM/YYYY"),
"end": moment("05/04/2017", "DD/MM/YYYY")
},
{
"start": moment("11/04/2017","DD/MM/YYYY"),
"end": moment("15/04/2017", "DD/MM/YYYY")
}
]
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-13-5" value="03/19/2017 - 03/20/2017" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-13-5").calentim({
disableOnlyStart: true,
disabledRanges: [
{
"start": moment("10/03/2017","DD/MM/YYYY"),
"end": moment("18/03/2017", "DD/MM/YYYY")
},
{
"start": moment("01/04/2017","DD/MM/YYYY"),
"end": moment("05/04/2017", "DD/MM/YYYY")
},
{
"start": moment("11/04/2017","DD/MM/YYYY"),
"end": moment("15/04/2017", "DD/MM/YYYY")
}
]
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-13-6" value="03/19/2017 - 03/20/2017" />
JavaScript:
<script type="text/javascript">
$("#calentim-ex-13-6").calentim({
disableOnlyEnd: true,
disabledRanges: [
{
"start": moment("10/03/2017","DD/MM/YYYY"),
"end": moment("18/03/2017", "DD/MM/YYYY")
},
{
"start": moment("01/04/2017","DD/MM/YYYY"),
"end": moment("05/04/2017", "DD/MM/YYYY")
},
{
"start": moment("11/04/2017","DD/MM/YYYY"),
"end": moment("15/04/2017", "DD/MM/YYYY")
}
]
});
</script>
Preview:
HTML:
<input type="text" id="calentim-ex-13-1" />
<button class="calentim-show">Show Instance</button>
<button class="calentim-hide">Hide Instance</button>
JavaScript:
<script type="text/javascript">
$("#calentim-ex-13-1").calentim();
$(".calentim-show").on("click",function(e){
var calentim = $("#calentim-ex-13-1").data("calentim");
calentim.showDropdown(e);
});
$(".calentim-hide").on("click",function(e){
var calentim = $("#calentim-ex-13-1").data("calentim");
calentim.hideDropdown(e);
});
</script>
Preview:
HTML:
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<input type="text" id="calentim-ex-12" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" onclick="$('#myModal').modal('show');" >
Launch demo modal
</button>
JavaScript:
<script type="text/javascript">
$("#calentim-ex-12").calentim();
</script>
There are 4 ready to use themes included in this package. You can include any theme by just switching the css file you've loaded inside your HTML file:
<link href="build/css/calentim.min.css" rel="stylesheet"/>
<link href="build/css/calentim-alt.min.css" rel="stylesheet"/>
<link href="build/css/calentim-dark.min.css" rel="stylesheet"/>
<link href="build/css/calentim-dark-alt.min.css" rel="stylesheet"/>
You can create and use your theme by modifying and building any of the SCSS files included within the package /css
folder. To add your own theme without touching the others, you need to copy 2 files and modify the Grunt configuration file.
calentim-variables-[your theme slug].scss
by copying any one of the calentim-variables-*.scss
files, whichever is more close to your design.calentim-[your theme slug].scss
by copying the calentim.scss
file, and modify the first import to load your calentim-variables-[your theme slug].scss
file.Open Gruntfile.js
at the root of the package, add
'build/css/calentim-[your theme name].min.css': 'css/calentim-[your theme name].scss'
to the sass.dist.files
array to get it built and minified, and add build/css/calentim-[your-theme-name].min.css
file to the postcss.files
array to get it enhanced to be crossbrowser compatible.
After that, when you run grunt min
, you'll get your build/css/calentim-[your theme slug].min.css
file built and ready to use in your applications. When developing the theme, you can use grunt watcher
to get a live reload server running and utilizing single-test.html file, you can live edit your theme variables. Just don't forget to update the linked stylesheet in the single test to your modified one.
I left the calentim object fully accessible to the inner variables, so you can alter the object's config in any event. For example, you can alter the max date of the calendar after first selection like this (limiting the user to select max 7 days of the first selection):
onfirstselect: function(calentim, startDate){
calentim.config.maxDate = startDate.clone().add(7,"days");
},
onafterselect: function(calentim, startDate, endDate){
calentim.config.maxDate = null;
}
or another example, disabling previous date selection:
onfirstselect: function(calentim, startDate){
calentim.config.minDate = startDate.clone();
},
onafterselect: function(calentim, startDate, endDate){
calentim.config.minDate = null;
}
The cloning is very important when adding or subtracting, because they modify the reference element too! As you can see in the above examples, the startDate and the endDate elements are cloned when defining the maxDate and minDate values. If you don't want to modify the startDate or endDate intentionally, use cloning.
Mobile only supports modal like interface. Dropdowns and inline options currently don't work on mobile phones. Added inline support on mobile devices on version 1.1.2.
Only one event can be bound using the initialize config object. Multiple events are not supported.
startEmpty: true
settingshowCalendars
option to disable date selection (only time picker)enableKeyboard
option)calentim-not-in-month
class for the days that don't belong to that month.startOf("day")
to middleOfDay()
extension function to minimize DST change bugs.reverseTimepickerArrows
option to reverse the actions of time picker arrowsdontPrefixHours
variable to prevent 12-hour format hour padding with zero-
Calentim Date/Time Range Picker
Copyright (c) Taha PAKSU http://www.tahapaksu.com
All rights reserved.
Based on jQuery — New Wave JavaScript http://www.jquery.org
Copyright (c) JS Foundation and other contributors, https://js.foundation/
Released under jQuery License
All rights reserved.
Based on Moment.js http://www.momentjs.com
Copyright (c) JS Foundation and other contributors
Moment.js is freely distributable under the terms of the MIT license.
All rights reserved.
Includes hammer.js http://hammerjs.github.io
Copyright (C) 2011-2014 by Jorik Tangelder (Eight Media)
hammer.js is freely distributable under the terms of the MIT license.
All rights reserved.