1.2.2 • Published 10 months ago

agjcalendar v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

agjCalendar

MIT License Current Release Tested by QUnit Coveralls Coverage Issues npm Downloads Patreon

Description

agjCalendar is a plugin for the jQuery Javascript library to deal with calendars, dates and date ranges.

Patreon - Become a Patron

agjCalendar is an agjjQuery.org plugin.

Examples

// The most basic agjCalendar integration
$('#text-input').agjCalendar();

// An alternative way of doing the same thing
$.agjCalendar({
  dateSelector: '#text-input'
});

// A more complex agjCalendar integration
$.agjCalendar({
  dateFormat:          'M j, Y',
  calendarCount:       3,
  inputType:           'text',
  dateSelector:        '#start-date',
  expanderSelector:    '#start-date-icon',
  minimumDate:         '2023-01-01',
  maximumDate:         '2023-12-31',
  defaultDate:         '2023-07-09',
  defaultEndDate:      '2023-07-10',
  allowRange:          true,
  minimumRange:        1,
  maximumRange:        7,
  defaultRange:        2,
  endDateSelector:     '#end-date',
  endExpanderSelector: '#end-date-icon'
});

There are other examples included in the GitHub repository and on agjCalendar.agjjQuery.org.

Options

When intializing an agjCalendar integration you can set its configuration options by passing a JSON object of values.

// A basic agjCalendar integration that will render a calendar that uses Monday to start the week
$.agjCalendar({
  dateSelector:      '#text-input',
  startWeekOnMonday: true
});

// Alternatively you can use the $.fn.agjCalendar() function for the same result
$('#text-input').agjCalendar({
  startWeekOnMonday: true
});

A complete list of all options, their default values, valid values and notes is available below.

keytypedefaultvaluesnotes
allowBlankDatesbooleanfalsetruefalseIf set to true blank dates will be permitted
allowRangebooleanfalsetruefalseIf set to true a second date can be entered with the endDateSelector option or the endMonthSelector and endDaySelector options
autoBlurbooleantrue if calendarDisplay is set to 'modal' or 'full' otherwise falsetruefalseIf set to true automatically lose focus (blur) immediately after a text field is focused (only used when inputType is set to 'text')
autoSetEndDatestring'dates''blanks''dates''always''never'This option controls whether or not the end date will automatically change when the start date changes;'blanks' will only trigger when the end date is blank,'dates' will only trigger when the end date is a date,'always' will trigger for both and'never' will trigger for neither (only used when allowRange is set to true)
calendarCountinteger1123Defines whether the date picker uses a single, double or triple calendar (only used when calendarDisplay is set to 'inline' or 'modal')
calendarDisplaystring'inline''inline''modal''full'Toggles whether the date picker is displayed as 'inline', 'modal' or 'full'
calendarSizestring'small''small''medium''large'Defines whether the date picker displays as small, medium or large (only used when calendarDisplay is set to 'inline' or 'modal')
dateFormatstring'm/d/Y'A string using our Date Format OptionsDetermines which date format is used for text inputs (only used when inputType is set to 'text')See Date Format Options for details
dateFormatDatestring'j'A string using our Date Format OptionsDetermines which date format is used for dates on the date pickerSee Date Format Options for details
dateFormatDateTooltipstring'F j, Y' for English'j F Y' for non-EnglishA string using our Date Format OptionsDetermines which date format is used for date tooltips on the date pickerSee Date Format Options for details
dateFormatDayInputstring'j'A string using our Date Format OptionsDetermines which date format is used for day dropdown inputs (only used when inputType is set to 'dropdown' and calendarDisplay is set to 'inline' or 'modal')See Date Format Options for details
dateFormatDayOfWeekTooltipstring'l'A string using our Date Format OptionsDetermines which date format is used for day of week tooltips on the date pickerSee Date Format Options for details
dateFormatMonthDropdownstring'M Y'A string using our Date Format OptionsDetermines which date format is used for the month dropdown on the date pickerSee Date Format Options for details
dateFormatMonthInputstring'M Y'A string using our Date Format OptionsDetermines which date format is used for month dropdown inputs (only used when inputType is set to 'dropdown' and calendarDisplay is set to 'inline' or 'modal')See Date Format Options for details
dateFormatMonthLabelstring'F Y'A string using our Date Format OptionsDetermines which date format is used for month labels on the date picker (only used when calendarCount is set to 2 or 3)See Date Format Options for details
dateSelectorstringnullAccepts a string value for your target text element such as '#text-input' (only used when inputType is set to 'text')
dayNameEllipsisbooleantruetruefalseDetermines whether longer day names will be cut-off with an ellipsis
dayNameFormatstring'short''short''abbreviated''full'Determines which day format is used for days of the week on the date picker'short' = first letter, e.g. F'abbreviated' = partial name, e.g. Fri'full' = full name, e.g. Friday
daySelectorstringnullAccepts a string value for your target day dropdown element such as '#day-select' (only used when inputType is set to 'dropdown')
defaultDateDate|stringToday’s dateA Date object, a string formatted as YYYY-MM-DD or 'blank'The default date to prefill
defaultEndDateDate|stringToday’s date plus the defaultRangeA Date object, a string formatted as YYYY-MM-DD or 'blank'The default end date to prefill (only used when allowRange is set to true)
defaultRangeinteger0 if the minimumDate and maximumDate options are set to the same date otherwise 1Any non-negative integerThe default date range (only used when allowRange is set to true)
endDateSelectorstringnullThe same as dateSelector but for the end date (only used when allowRange is set to true and inputType is set to 'text')
endDaySelectorstringnullThe same as daySelector but for the end date (only used when allowRange is set to true and inputType is set to 'dropdown')
endExpanderSelectorstringnullThe same as expanderSelector but for the end date (only used when allowRange is set to true)
endMonthSelectorstringnullThe same as monthSelector but for the end date (only used when allowRange is set to true and inputType is set to 'dropdown')
excludeDatesarray[]An array of Date objects and/or strings formatted as YYYY-MM-DDIndividual dates that will be excluded from the date picker
expanderSelectorstringnullAccepts a string value for an additional target element to expand the calendar such as '#calendar-icon'
forceMaxZIndexbooleanfalsetruefalseForce the maximum z-index value (2147483647) on the date picker instead of calculating based on an integration’s elements’ z-index values (only used when calendarDisplay is set to 'inline')
inputTypestring'text''text''dropdown'If set to 'text' will use the dateSelector option to store the date or if set to 'dropdown' will use the monthSelector and daySelector options to store the date
languagestring'en''en''ar''bn''de''es''fr''he''hi''it''ja''ko''mr''pa''pt''ru''te''tr''ur''vi''zh'The language for the text elements on the date picker'en' = English'ar' = اَلْعَرَبِيَّةُ (Arabic)'bn' = বাংলা (Bengali)'de' = Deutsch (German)'es' = Español (Spanish)'fr' = Français (French)'he' = עִבְרִית (Hebrew)'hi' = आधुनिक मानक हिन्दी (Hindi)'it' = Italiano (Italian)'ja' = 日本語 (Japanese)'ko' = 한국어 (Korean)'mr' = मराठी (Marathi)'pa' = پنجابی (Punjabi)'pt' = Português (Portuguese)'ru' = русский язык (Russian)'te' = తెలుగు (Telugu)'tr' = Türkçe (Turkish)'ur' = اردو (Urdu)'vi' = Tiếng Việt (Vietnamese)'zh' = 官话 (Chinese Mandarin)Our online documentation has more details on the translations page
maximumDateDate|stringToday’s date plus one yearA Date object or a string formatted as YYYY-MM-DDThe maximum date that can be picked
maximumRangeintegerThe number of days between the minimumDate and maximumDate optionsAny non-negative integerThe maximum date range (only used when allowRange is set to true)
minimumDateDate|stringToday’s dateA Date object or a string formatted as YYYY-MM-DDThe minimum date that can be picked
minimumRangeinteger0 if the minimumDate and maximumDate options are set to the same date otherwise 1Any non-negative integerThe minimum date range (only used when allowRange is set to true)
monthSelectorstringnullAccepts a string value for your target month dropdown element such as '#month-select' (only used when inputType is set to 'dropdown')
overwriteDayOptionsbooleantruetruefalseIf set to true the options on the daySelector and endDaySelector dropdown elements will dynamically update (only used when inputType is set to 'dropdown')
overwriteMonthOptionsbooleantruetruefalseIf set to true the options on the monthSelector and endMonthSelector dropdown elements will dynamically update (only used when inputType is set to 'dropdown')
startWeekOnMondaybooleanfalsetruefalseIf set to true the weeks on the calendar will start on Monday instead of Sunday
themestringnull'red''orange''yellow''green''cyan''blue''purple''pink''custom-*'A string of one of the eight included themes or a custom theme that must begin with custom- (our online documentation has more details on the themes page)
translationsobject[]An object of translationsThe translations option will always take precedence over the language optionOur online documentation has more details on the translations page

Date Format Options

The plugin uses common date formating for the dateFormat, dateFormatDate, dateFormatDateTooltip, dateFormatDayInput, dateFormatDayOfWeekTooltip, dateFormatMonthDropdown, dateFormatMonthInput and dateFormatMonthLabel options. You can choose any combination of the below characters to format dates for users. The characters are based on PHP’s DateTime::format function which is in turn based on C Standard Library’s strftime function.

Warning: This plugin does not support timezones, all dates and times are treated timezone agnostically

characterdescriptionexample(s)
Day------
dDay of the month, 2 digits with leading zeros01
DA textual representation of a day, three lettersSun
jDay of the month without leading zeros1
l (lowercase ‘L’)A full textual representation of the day of the weekSunday
NISO 8601 numeric representation of the day of the week1 (for Monday) through 7 (for Sunday)
SEnglish ordinal suffix for the day of the month, 2 charactersst, nd, rd or th
wNumeric representation of the day of the week0 (for Sunday) through 6 (for Saturday)
zThe day of the year (starting from 0)0 through 365
Week------
WISO 8601 week number of year, weeks starting on Monday42 (the 42nd week in the year)
Month------
FA full textual representation of a month, such as January or MarchJanuary
mNumeric representation of a month, with leading zeros01
MA short textual representation of a month, three lettersJan
nNumeric representation of a month, without leading zeros1
tNumber of days in the given month28
Time------
aLowercase Ante meridiem and Post meridiemam or pm
AUppercase Ante meridiem and Post meridiemAM or PM
g12-hour format of an hour without leading zeros1 through 12
G24-hour format of an hour without leading zeros0 through 23
h12-hour format of an hour with leading zeros01 through 12
H24-hour format of an hour with leading zeros00 through 23
iMinutes with leading zeros00 to 59
sSeconds with leading zeros00 through 59
uMicroseconds. Note that date() will always generate 000000 since it takes an int parameter, whereas DateTime::format() does support microseconds if DateTime was created with microseconds.Example: 654321
vMilliseconds. Same note applies as for u.Example: 654
Year------
LWhether it’s a leap year1 if it is a leap year, 0 otherwise
oISO 8601 week-numbering year. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.2000
xAn expanded full numeric representation if required, or a standard full numeral representation if possible (like Y). At least four digits. Years BCE are prefixed with a -. Years beyond (and including) 10000 are prefixed by a +.Examples: -0055, 0787, 1999, +10191
XAn expanded full numeric representation of a year, at least 4 digits, with - for years BCE, and + for years CEExamples: -0055, +0787, +1999, +10191
yA two digit representation of a year00
YA full numeric representation of a year, at least 4 digits, with - for years BCE2000
Full Date------
cISO 8601 date2000-01-01T00:00:00
rRFC 2822/RFC 5322 formatted dateWarning: This plugin does not support timezones so this formatted date will always end in +0000Thu, 21 Dec 2000 10:01:07 +0000
USeconds since the Unix Epoch (January 1 1970 00:00:00 GMT)946706400

Javascript Functions

The majority of the functionality for the agjCalendar plugin is self-contained but there are some functions that are added to extend jQuery that can be accessed by any of your Javascript code. We use the dollar sign alias ($) instead of the jQuery global for documentation but either can be referenced.

$.agjCalendar(options)

var integration = $.agjCalendar({
  dateSelector: '#text-input'
});
if (integration !== -1) {
  alert('The integration was a success!');
} else {
  alert('The integration failed; check your Javascript console for details.');
}

The $.agjCalendar() function accepts an options JSON object of values to initialize a new agjCalendar integration. Returns true if the integration was successful or false if it was not.

$.fn.agjCalendar(options)

var integration;
$('#text-input').agjCalendar({
  dateFormat: 'Y-m-d'
}, function(returnValue) {
  integration = returnValue;
});
if (integration !== -1) {
  alert('The integration was a success!');
} else {
  alert('The integration failed; check your Javascript console for details.');
}

The $.fn.agjCalendar() function works similar to the $.agjCalendar() function but does not require the dateSelector option as you would be selecting the element and calling this function directly off of it. Returns the element to allow for chaining. This function also has an optional callback parameter that will be executed on completion of the integration attempt and will pass the integration attempt outcome into the callback’s first and only parameter.

$.agjCalendar.addRegexTextPattern(regexTextPattern)

$.agjCalendar.addRegexTextPattern('\u3040-\u30FF');

The $.agjCalendar.addRegexTextPattern() function will add a regular expression pattern to the plugin’s text checks. This function should be used if custom unicode characters are being used in custom translations. Our online documentation has more details on the translations page.

$.agjCalendar.dateToString(date, dateFormat, translations)

var formattedDate = $.agjCalendar.dateToString(new Date(), 'j F Y');

The $.agjCalendar.dateToString() function will accept a date & date format and return a formatted string. It also accepts an optional translations parameters which is an object of translations (including day and month names) which will be used in the string, if no translations are passed the included English translations will be used. Read more about date format options and custom translations.

$.agjCalendar.deactivate()

$.agjCalendar.deactivate();

The $.agjCalendar.deactivate() function will deactivate any active date pickers.

$.agjCalendar.disable(position)

var integration = $.agjCalendar({
  dateSelector: '#text-input'
});
if (integration !== -1) {
  $.agjCalendar.disable(integration);
}

The $.agjCalendar.disable() function will disable an agjCalendar integration after it has been initialized.

$.agjCalendar.disableEmojiSupport()

$.agjCalendar.disableEmojiSupport();

The $.agjCalendar.disableEmojiSupport() function will disable emoji support for custom translations.

Warning: Emoji support will have issues with older versions of Microsoft Internet Explorer specifically 6, 7, 8, 9, 10 and 11 as they don’t support ECMAScript 2018. To support older browsers we recommend using $.agjCalendar.addRegexTextPattern() and passing each emoji character you want to use.

$.agjCalendar.enableEmojiSupport()

$.agjCalendar.enableEmojiSupport();

The $.agjCalendar.enableEmojiSupport() function will enable emoji support for custom translations.

Warning: Emoji support will have issues with older versions of Microsoft Internet Explorer specifically 6, 7, 8, 9, 10 and 11 as they don’t support ECMAScript 2018. To support older browsers we recommend using $.agjCalendar.addRegexTextPattern() and passing each emoji character you want to use.

$.agjCalendar.getIncludedTranslations(language)

var dateInFrench = $.agjCalendar.dateToString(
  new Date(),
  'j F Y',
  $.agjCalendar.getIncludedTranslations('fr')
);

The $.agjCalendar.getIncludedTranslations() function will return an object of translations for one of the plugin’s included translations.

$.agjCalendar.isActive()

if ($.agjCalendar.isActive()) {
  alert('There is a date picker currently active!');
} else {
  alert('There are no date pickers currently active.');
}

The $.agjCalendar.isActive() function will determine whether or not any date pickers are active. Returns true if a date picker is active or false if none are.

$.agjCalendar.stringToDate(string, dateFormat, translations)

var extractedDate = $.agjCalendar.stringToDate('1 January 2000', 'j F Y');
if (extractedDate !== -1) {
  alert('Date successfully extracted: ' + extractedDate);
} else {
  alert('The date extraction failed.');
}

The $.agjCalendar.stringToDate() function will accept a string & date format and return a date object. It also accepts an optional translations parameters which is an object of translations (including day and month names) which will be used in parsing the string, if no translations are passed the included English translations will be used. Read more about date format options and custom translations.

Usage/Installation

You will need an HTML reference to jQuery in order for the plugin to function.

<!-- Reference to the jQuery Javascript library -->
<script type="text/javascript" src="//code.jquery.com/jquery-3.7.1.min.js"></script>

With npm or Yarn

This plugin offers support for the npm and Yarn dependency managers. You can find the agjCalendar package online on npmjs.com.

Install using npm

Run this command to install the plugin using npm:

npm install agjcalendar

Install using Yarn

Run this command to install the plugin using Yarn:

yarn add agjcalendar

Once installed you can start using agjCalendar within your project by adding HTML references to the plugin’s Javascript and CSS stylesheet files.

<!-- Reference to the agjCalendar jQuery plugin -->
<script type="text/javascript" src="./node_modules/agjcalendar/source/agjCalendar/jquery.agjCalendar.js"></script>

<!-- Reference to the agjCalendar CSS stylesheet -->
<style type="text/css">@import './node_modules/agjcalendar/source/agjCalendar/jquery.agjCalendar.css';</style>

With Bower

This plugin also offers support for the now-deprecated Bower dependency manager.

Install using Bower

Run this command to install the plugin using Bower:

bower install andrewgjohnson/agjCalendar --save

Once installed you can start using agjCalendar within your project by adding HTML references to the plugin’s Javascript and CSS stylesheet files.

<!-- Reference to the agjCalendar jQuery plugin -->
<script type="text/javascript" src="./bower_components/agjCalendar/source/agjCalendar/jquery.agjCalendar.js"></script>

<!-- Reference to the agjCalendar CSS stylesheet -->
<style type="text/css">@import './bower_components/agjCalendar/source/agjCalendar/jquery.agjCalendar.css';</style>

Without npm, Yarn or Bower

To use without npm, Yarn or Bower add HTML references to the Javascript source and the CSS source which you will need to download and host. Run these commands to download them via the terminal:

curl -o jquery.agjCalendar.min.css 'https://agjCalendar.agjjQuery.org/source/agjCalendar/jquery.agjCalendar.min.css'
curl -o jquery.agjCalendar.min.js 'https://agjCalendar.agjjQuery.org/source/agjCalendar/jquery.agjCalendar.min.js'

Once downloaded, you must reference the files in your HTML:

<!-- Reference to the agjCalendar jQuery plugin -->
<script type="text/javascript" src="jquery.agjCalendar.min.js"></script>

<!-- Reference to the agjCalendar CSS stylesheet -->
<style type="text/css">@import 'jquery.agjCalendar.min.css';</style>

Backwards Compatibility

The plugin strives to keep backwards compatibiltiy with all past releases. New features should be off by default with few exceptions. Changes to existing features should continue to support past options/values/configurations so older integrations of agjCalendar will continue to function without any need for change if their core plugin is updated.

List of Backward Compatibility Changes

versiondeprecated featurebackwards support
v1.0.0$.ctcCalendar() functionThe plugin was renamed from ctcCalendar to agjCalendarThe $.ctcCalendar() function is now an alias of $.agjCalendar()
v1.0.0autoSetEndDate options true and falseautoSetEndDate deprecated boolean values in favour of four possible strings ('always', 'never', 'blanks' and 'dates')true is now an alias of 'always' and false is now an alias of 'never' for the autoSetEndDate option
v1.2.0dayNameFormat option 'medium'dayNameFormat deprecated 'medium' in favour of 'abbreviated''medium' is now an alias of 'abbreviated' for the dayNameFormat option
v1.2.0dateFormat options 1, 2, 3, 4 and 5dateFormat was refactored to allow for custom formats1 is now an alias of 'm/d/Y', 2 is now an alias of 'M j, Y', 3 is now an alias of 'd/m/Y', 4 is now an alias of 'Y-m-d' and 5 is now an alias of 'j F Y' for the dateFormat and dateFormatDateTooltip options
v1.2.0$.agjCalendar returns -1 instead of false on failureSuccessful integrations function in the same manner but failures will now return -1 instead of false
v1.2.0The z-index CSS values of the calendar and modal background elements now change dynamically based upon the integration elements when calendarDisplay is set to 'inline'Previously the z-index CSS value was always set to the maximum for the calendar element and maximum minus one for the modal background element when calendarDisplay was set to 'inline' which will still happen if the integration sets the forceMaxZIndex option to true (which is set to false by default)
v1.2.0The autoBlur option will be automatically set to true when the calendarDisplay option is set to 'modal' or 'full'Previously all integrations of agjCalendar had the false behaviour which is still the case for integrations with the calendarDisplay set to 'inline' and can still happen if the autoBlur option is set to false

Older Versions of jQuery

The plugin is designed to work with the newest version of jQuery (3.7.1) but will also work with older versions of jQuery 3.x as well as jQuery 2.x (tested up to 2.2.4) and jQuery 1.x (tested up to 1.12.4). We recommend using the newest version of jQuery.

Unit Testing

The plugin uses jQuery’s QUnit framework for unit testing. All units tests are located in the qunit.js file. The unit tests can be run online in-browser at agjCalendar.agjjQuery.org/tests/index.html. We strive to cover all public facing functions and API’s to ensure all permutations of parameters, options, fail scenarios, success scenarios, etc. are covered. Many novel scenarios are included in the unit tests to achieve high code coverage.

Help Requests

Please post any questions in the discussions area on GitHub if you need help.

If you discover a bug please enter an issue on GitHub. When submitting an issue please use our issue templates.

Contributing

Please read our contributing guidelines if you want to contribute.

You can contribute financially by becoming a patron at patreon.com/agjopensource to support agjCalendar and other agjjQuery.org plugins.

Patreon - Become a Patron

Acknowledgements

This plugin was started by Andrew G. Johnson (@andrewgjohnson).

Full list of contributors:

Our security policies and procedures comes via the atomist/samples project. Our issue templates comes via the tensorflow/tensorflow project. Our pull request template comes via the stevemao/github-issue-templates project. The forest photo comes via Radek Homola.

Changelog

You can find all notable changes in the changelog.

1.2.2

10 months ago

1.2.0

1 year ago

1.2.1

1 year ago

1.1.0

1 year ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.9.5

2 years ago

0.9.4

2 years ago