Git Product home page Git Product logo

jscalendar's Introduction

jsCalendar is a lightweight date picker for desktop and mobile browsers.

Features

  • small file size
  • designed for webkit mobile, mainly iOS and Android
  • support for desktop browsers
  • works with jQuery as well as Zepto.js
  • range of days selection mode
  • single date selection mode
  • 3D calendar turn over css3 animation, supported by Safari only
  • multilingual support
  • flexible first day of the week
  • multiple calendars on one page possible
  • selecting past dates is prevented

Requirements

Usage

On document ready, the calendar attaches itself to HTML elements with the class name "jsCalendar". Manual initialization is not necessary. This element should have an attribute data-localized_date with a JSON string as value containing the localized names of months and weekdays like this one:

{"days":{"names":{"min":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}},"months":{"names":{"long":["January","February","March","April","May","June","July","August","September","October","November","December"]}}}

It is possible to select a range of days between start and end date as well as selecting a single date. Range selection is default. To switch to single date selection, add the class name jsSingleDate to the jsCalendar HTML element before document ready.

You are notified when the user changes the selection by the custom events startDateChanged and endDateChanged on the jsCalender HTML element. So the currently selected dates can be retrieved like this:

$(".jsCalendar").bind("startDateChanged", function() {
    $(this).data("startdate");
}).bind("endDateChanged", function() {
    $(this).data("enddate");
});

If you are using the single date selection mode, startDateChanged is the only triggered event.

To initialize the calendar with start and end date, specify the attributes data-startdate and data-enddate at the jsCalender HTML element with the string representation of a JavaScript Date object.

To set dates programatically, call $(".jsCalendar").calendar().setDates(start, end), where start and end are Date objects representing the dates you want to set. If you pass null as parameter, the corresponding date selection is removed.

To reset the selection programatically (e.g. with an extra button), you could trigger a resetSelection event on the jsCalender HTML element.

From the user's perspective, range selection works like this: the first click is the start date, second click the end date, a third click resets the selection. If the selected end date is before the start date, they are automatically exchanged. It is possible to deselect a start or end date by clicking it without resetting the whole selection. You can implement your own date selection algorithm by rewriting the dateSelected method.

To set the first day of the week (e.g: Sunday, Monday, ...) specify the attribute data-firstdayofweek at the jsCalender HTML element with a value between 0 and 6.

It is possible to display a specific month by calling $(".jsCalendar").calendar().showMonth(date), where date is a Date object representing the desired month.

Right now, it is not possible to select a date in the past and there is no maximum selection date for the far future.

After initialization, the JavaScript Date object will be extended with a subset of instance methods from datejs: clone, isLeapYear, getDaysInMonth, moveToFirstDayOfMonth, moveToLastDayOfMonth, addMilliseconds, addDays, addMonths and clearTime.

The $ function is extended with a slice method to select a range from a set of elements like this $("a").slice(3, 7), using the native slice implementation for arrays. Another extension is the calendar method, returning the Calendar object belonging to the first matched HTML element, if available.

Example

See index.html

Supported Platforms

  • tested with Zepto.js:
    • Android
    • iOS
    • Safari
    • Chrome
  • tested with jQuery
    • Android
    • iOS
    • Safari
    • Chrome
    • Firefox
    • Internet Explorer 7

License

jsCalendar is licensed under the terms of the MIT License.

jscalendar's People

Contributors

michaelkamphausen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.