2.1.5 • Published 1 month ago

bookingsync-calendar-widget v2.1.5

Weekly downloads
11
License
MIT
Repository
github
Last release
1 month ago

Calendar Widget CircleCI

TL;DR

Development

  • npm
  • npm start
  • npm run mock-server
  • npm run test-ci

Usage

  • load dist/bookingsync-calendar-widget.js script
  • add <div data-bookingsync-calendar-widget></div> tag to the place you would like to put the widget.

  • Or as global.

const calendar = new BookingSyncCalendarWidget({ el: document.querySelector('.my-widget') });
  • Or as module
import Calendar from 'bookingsync-calendar-widget';

const calendar = new Calendar({ el: document.querySelector('.my-widget') });

@see index.html for more examples.

Setup

Getting started with Development

Additionally you can run json-mock server

  • npm run mock-server it serve maps api for local development. Mocks are in db.json file.

Scripts

  • npm start - starts development server with live-reload and hot module replacement
  • npm run build - produces production version under the dist folder
  • npm run test - runs tests.

Config

OptionDescriptionTypeDefault
elHTMLElement to act as a container (only this one is MANDATORY)HTMLElementnull
apiHostAPI host nameStringhttp://localhost:3000 for development, https://www.bookingsync.com for production
apiNamespaceAPI namespaseString/api/v2/public
apiMapsRouteroute for mapsString/maps.json?rental_id={params} - {params} is replaced with rentalId
rentalURLURL route for mapsFunction
rentalIdparameter to pass in API request for availability mapsString or Numbernull
currencySet currency conversionStringnull
minStayMinimum selectable rangeNumber1
maxStayMaximum selectable rangeNumberInfinity
allowShorterMinStaySelectionForce minimum selection to opts.minStayBooleanfalse
allowShorterMaxStaySelectionForce maximum selection to opts.maxStayBooleanfalse
monthStartCalendar starts months, the left up most, 0 - 11 rangeNumberCurrent month
yearStartCalendar start year, YYYY format (2016)NumberCurrent year
displayMonthsHow many months to renderNumber2
selectableAllow to select rangeBooleanfalse
showRatesShow rates from availability mapBooleanfalse
showMinStayShow minimum stay per single day (be careful to use together with showRates or showMaxStay, can be too munch information)Booleanfalse
showMaxStayShow maximum stay per single day (be careful to use together with showRates or showMinStay, can be too munch information)Booleanfalse
isReverseSelectableUser selects end date firstBooleanfalse
isBackDisabledDisable back button for past monthsBooleantrue
isDropDownAct like drop down, good idea to specify elStartAt and elEndAtBooleanfalse
elStartAtInput field to show start selected, open drop-down on focusHTMLElementnull (will try to find .bookingsyncCalendarWidget__start-at if null)
elEndAtInput field to show end selected, open drop-down on focusHTMLElementnull (will try to find .bookingsyncCalendarWidget__end-at if null)
elSingleInputSingle input field to show start/end selected, open drop-down on focusHTMLElementnull (will try to find .bookingsyncCalendarWidget__single-input if null)
isSingleInputAllow to use the single input, hides start/end inputsBooleannull
elResetAny element on click resets calendar selections and input valuesHTMLElementnull
formatDateOverwrite locale defined date formatString%m/%d/%y (https://github.com/pineapplemachine/strtime-js/blob/HEAD/directives.md)
hiddenElFormatDuplicate start/end inputs with a different date formatStringnull
disableAvailabityMapOverwrite each days to be availableBooleanfalse
enableAllDaysForce past days/months to be selectableBooleanfalse
currentDateCurrent date Date objectDatenew Date()

Callbacks

  • onSelectStart(ISO String, Date)
  • onSelectEnd(ISO String, Date)
  • onSelectionCompleted(ISO String, ISO String)

see index.html for more examples. All options can be passed as data- attributes to HTMLElement calendar placeholders, with dasherized way. e.g.

<div 
  data-bookingsync-calendar-widget
  data-selectable="true"
  data-format-date="%m/%d/%y">
</div>

Events

Calendar implements event Emitter, receiver can subscribe/unsubscribe to events and subscribe one-time.

var cal = new bookingsyncCalendarWidget({
  el: document.querySelector('.calendar-wrapper'),
});

cal.on('selection-end', function(a, b) {
  console.log('selection-end', a, b)
});
cal.on('selection-start', function(a, b) {
  console.log('selection-start', a, b)
});

cal.once('selection-end', function(a, b) {
    console.log('selection-end', a, b)
 });
 
cal.off('selection-end', function(a, b) {
    console.log('selection-end', a, b)
 }); 
EventDescriptionParams
initFinished initializing, data is NOT loaded
maps-loadedAvailability, rates and minimum stay maps are loaded and added to calendar{Object} raw response from the server
maps-errorError when loading maps
loading-showLoading indicator shows
loading-hideLoading indicator hides
selection-startUser selected start date{String} {Date}, ISO format '2016-01-01', Date
selection-endUser selected end date{String} {Date}, ISO format '2016-01-01', Date
selection-resetSelection reset{Array}, {Array}, selection start, selection end (yyyy, m, dd)
selection-completedUser selects end date when start date was already selected{Array}, {Array}, selection start, selection end (yyyy, m, dd)
drop-openCalendar-drop open
drop-closeCalendar-drop close
2.1.5

1 month ago

2.1.4

10 months ago

2.1.3

1 year ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.3

2 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.5.0

3 years ago

1.4.8

3 years ago

1.4.7

3 years ago

1.4.6

4 years ago

1.4.5

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.3

5 years ago

1.3.0

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.0.0

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.1

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.17

7 years ago

0.0.15

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago