Code Monkey home page Code Monkey logo

html-calendar.js's Introduction

๐Ÿ—“๏ธ HTML-Calendar.js

Generate calendars using HTML tables

  • Lightweight
  • No dependencies
  • Pretty

Take a look at index.html to see a sample usage.

Features

  1. Add the calendar for any given month
  2. Add the calendar for a range of months
  3. (Optional) Colour specific dates in the calendar

How to use

<script src="./html-calendar.js"></script>

<div class="html-calendar" id="2022-08"></div>

<script>
  autoAddCalendarToDOM()
</script>
  1. Add the script to your webpage.
  2. Create a div element with the html-calendar class and give it an ID in the YYYY-MM format.
  3. Run the autoAddCalendarToDOM() function and a calendar will automatically be added to the div

How to add colour

Each td element in the generated calendar table has the date in YYYY-MM-DD format as a class. Using this the built-in colorDates function is able to add colour to specific dates.

You can call the function by passing the table element as the first parameter and an array with specifications as the second parameter. The specification array looks like this โ€“

specification = [
  // [startDate, endDate, bgColour, textColour], 
  [1, 5, "red", "white"],
  [6, 6, "green", "white"],
   ...
]

There are three built-in colour options โ€“ red, green and yellow. Or you can specify the hex code directly.

Change the look of the table

The final generated table has the following CSS classes: table and table-bordered. These are the Bootstrap classes for tables. If you use some other CSS framework or want to specify your own styles, simply modify line 88 in the script.

If you do use Bootstrap 5, you can pass an optional boolean parameter called compactCal to autoAddCalendarToDOM() for generating a slimmer table output. By default it is set to false, but if you set it to true, the generated tables will have table-sm and m-0 classes added in addition to the default.

License

This code is licensed under the GNU GPL v3 license.

html-calendar.js's People

Contributors

gsidhu avatar

Watchers

 avatar

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.