Copyright © 2023 MIT License. | Design and development by Yury Uvarov.
💢 Usage example

biletiki.store — a website example for searching for flight tickets and hotels using vanilla-calendar.

Main

Creating an Instance

new VanillaCalendar() creates an instance of VanillaCalendar, which encapsulates the calendar, its settings, and methods.

A simple function call (without using the new operator) will return a string, not a VanillaCalendar object.

If you've included VanillaCalendar using a <script> tag, the object is available as a global variable window.VanillaCalendar.

The VanillaCalendar instance takes two parameters. The first one is mandatory and can be either a CSS selector or an HTML element.

The CSS selector or HTML element can represent a container for the calendar, where the calendar will be initialized, or an «Input».

A calendar container is a <div> element inside which the calendar itself will be initialized.

Initialization within a calendar container:

html
<div id="calendar"></div>
html
<div id="calendar"></div>
js
new VanillaCalendar('#calendar');
// or
const calendarEl = document.querySelector('#calendar');
new VanillaCalendar(calendarEl);
js
new VanillaCalendar('#calendar');
// or
const calendarEl = document.querySelector('#calendar');
new VanillaCalendar(calendarEl);

An «Input», in the context of this calendar, does not necessarily mean an <input> element; it can be any HTML element, such as a <div>.

Clicking on the «Input» will open a popup with the calendar.

Initialization within an «Input»:

html
<input type="text" id="input">
<!-- or -->
<div id="input"></div>
html
<input type="text" id="input">
<!-- or -->
<div id="input"></div>
js
new VanillaCalendar('#input', { input: true });
// or
const calendarInput = document.querySelector('#input');
new VanillaCalendar(calendarInput, {
  input: true,
});
js
new VanillaCalendar('#input', { input: true });
// or
const calendarInput = document.querySelector('#input');
new VanillaCalendar(calendarInput, {
  input: true,
});

The second optional parameter is an object that defines the calendar's settings and methods.

js
new VanillaCalendar('#calendar', {
  // Settings
});
js
new VanillaCalendar('#calendar', {
  // Settings
});