diff --git a/README.md b/README.md index 7983c4cc..2f772d0d 100644 --- a/README.md +++ b/README.md @@ -6,169 +6,13 @@ This date range picker component for Bootstrap creates a dropdown menu from whic select a range of dates. I created it while building the UI for [Improvely](http://www.improvely.com), which needed a way to select date ranges for reports. -If invoked with no options, it will present two calendars to choose a start -and end date from. Optionally, you can provide a list of date ranges the user can select from instead -of choosing dates from the calendars. If attached to a text input, the selected dates will be inserted -into the text box. Otherwise, you can provide a custom callback function to receive the selection. +Features include limiting the selectable date range, localizable strings and date formats, +a single date picker mode, optional time picker (for e.g. making appointments or reservations), +and styles that match the default Bootstrap 3 theme. -The component can also be used as a single date picker by setting the `singleDatePicker` option to `true`. +## [Documentation and Live Usage Examples](http://www.daterangepicker.com) -**[View some examples](http://www.daterangepicker.com/)** or **[Try it in a live application](https://awio.iljmp.com/5/drpdemogh)** - -## Usage - -This component relies on [Bootstrap](http://getbootstrap.com), -[Moment.js](http://momentjs.com/) and [jQuery](http://jquery.com/). - -Separate stylesheets are included for use with Bootstrap 2 or Bootstrap 3. - -Basic usage: - -``` - - - - - - - -``` - -The constructor also takes an optional options object and callback function. The function will be called whenever -the selected date range has been changed by the user, and is passed the start and end dates (moment date objects) -and the predefined range label chosen (if any), as parameters. It will not fire if the picker is closed without -any change to the selected dates. - -```` -$('input[name="daterange"]').daterangepicker( - { - format: 'YYYY-MM-DD', - startDate: '2013-01-01', - endDate: '2013-12-31' - }, - function(start, end, label) { - alert('A date range was chosen: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD')); - } -); -```` - -Options may also be set using HTML5 data attributes. For example, timePicker="true" would be set with: - -``` - -``` - -## Options - -`startDate`: (Date object, moment object or string) The start of the initially selected date range - -`endDate`: (Date object, moment object or string) The end of the initially selected date range - -`minDate`: (Date object, moment object or string) The earliest date a user may select - -`maxDate`: (Date object, moment object or string) The latest date a user may select - -`dateLimit`: (object) The maximum span between the selected start and end dates. Can have any property you can add to a moment object (i.e. days, months) - -`timeZone`: (string or number) The timezone that will be used to display the startDate and endDate in the calendar. This may be a string such as "08:00" or an offset in minutes from Greenwich Mean Time. Uses Moment.js #utcOffset, [see the docs here](http://momentjs.com/docs/#/manipulating/utc-offset/) for more information. If the timeZone option is not set, the calendar will use the time zone set on the startDate that has been passed in through the options, if it has one. Defaults to the local time zone - -`showDropdowns`: (boolean) Show year and month select boxes above calendars to jump to a specific month and year - -`showWeekNumbers`: (boolean) Show week numbers at the start of each week on the calendars - -`timePicker`: (boolean) Allow selection of dates with times, not just dates - -`timePickerIncrement`: (number) Increment of the minutes selection list for times (i.e. 30 to allow only selection of times ending in 0 or 30) - -`timePicker12Hour`: (boolean) Use 12-hour instead of 24-hour times, adding an AM/PM select box - -`timePickerSeconds`: (boolean) Show seconds in the timePicker - -`ranges`: (object) Set predefined date ranges the user can select from. Each key is the label for the range, and its value an array with two dates representing the bounds of the range - -`opens`: (string: 'left'/'right'/'center') Whether the picker appears aligned to the left, to the right, or centered under the HTML element it's attached to - -`drops`: (string: 'down' or 'up') Whether the picker opens below (default) or above the element it's attached to - -`buttonClasses`: (array) CSS class names that will be added to all buttons in the picker - -`applyClass`: (string) CSS class string that will be added to the apply button - -`cancelClass`: (string) CSS class string that will be added to the cancel button - -`format`: (string) Date/time format string used by moment when parsing or displaying the selected dates - -`separator`: (string) Separator string to display between the start and end date when populating a text input the picker is attached to - -`locale`: (object) Allows you to provide localized strings for buttons and labels, and the first day of week for the calendars - -`singleDatePicker`: (boolean) Show only a single calendar to choose one date, instead of a range picker with two calendars; the start and end dates provided to your callback will be the same single date chosen - -`parentEl`: (string) jQuery selector of the parent element that the date range picker will be added to, if not provided this will be `'body'` - -## Functions - -Several functions are provided for updating the picker's option and state after initialization: - -`setOptions(object, function)`: This function has the same signature and purpose as the date range picker's constructor: it sets the picker's options to their defaults, overrides them with any values in an options object you provide, and sets the callback for selection changes to whatever function you provide - -`setStartDate(Date/moment/string)`: Sets the date range picker's currently selected start date to the provided date - -`setEndDate(Date/moment/string)`: Sets the date range picker's currently selected end date to the provided date - -Example usage: - -```` -//create a new date range picker -$('#daterange').daterangepicker({ startDate: '2014-03-05', endDate: '2014-03-06' }); - -//change the selected date range of that picker -$('#daterange').data('daterangepicker').setStartDate('2014-03-01'); -$('#daterange').data('daterangepicker').setEndDate('2014-03-31'); -```` - -## Events - -Several events are triggered on the element you attach the picker to, which you can listen for: - -`show.daterangepicker`: Triggered when the picker is shown - -`hide.daterangepicker`: Triggered when the picker is hidden - -`showCalendar.daterangepicker`: Triggered when the calendar is shown - -`hideCalendar.daterangepicker`: Triggered when the calendar is hidden - -`apply.daterangepicker`: Triggered when the apply button is clicked - -`cancel.daterangepicker`: Triggered when the cancel button is clicked - -Some applications need a "clear" instead of a "cancel" functionality, which can be achieved by changing the button label and watching for the cancel event: - -```` -$('#daterange').daterangepicker({ - locale: { cancelLabel: 'Clear' } -}); - -$('#daterange').on('cancel.daterangepicker', function(ev, picker) { - //do something, like clearing an input - $('#daterange').val(''); -}); -```` - -While passing in a callback to the constructor is the easiest way to listen for changes in the selected date range, you can also do something every time the apply button is clicked even if the selection hasn't changed: - -```` -$('#daterange').daterangepicker(); -$('#daterange').on('apply.daterangepicker', function(ev, picker) { - console.log(picker.startDate.format('YYYY-MM-DD')); - console.log(picker.endDate.format('YYYY-MM-DD')); -}); -```` +## [See It In a Live Application](https://awio.iljmp.com/5/drpdemogh) ## License diff --git a/bower.json b/bower.json index fff6f78f..a02303c3 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "name": "bootstrap-daterangepicker", "main": [ "daterangepicker.js", - "daterangepicker-bs3.css" + "daterangepicker.css" ], "ignore": [ "**/.*", diff --git a/daterangepicker.js b/daterangepicker.js index 1b8666a3..92b70b25 100644 --- a/daterangepicker.js +++ b/daterangepicker.js @@ -98,7 +98,7 @@ '
' + '
' + '' + - '' + + '' + '
' + '
' + '' + @@ -109,7 +109,7 @@ '
' + '
' + '' + - '' + + '' + '
' + '
' + '' + diff --git a/demo.html b/demo.html index 3a4001e7..09e66bd1 100644 --- a/demo.html +++ b/demo.html @@ -147,6 +147,7 @@

Configuration Builder

+
diff --git a/drp.png b/drp.png new file mode 100644 index 00000000..f29eacde Binary files /dev/null and b/drp.png differ diff --git a/package.js b/package.js index 588d67b4..6f6ad103 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ name: 'dangrossman:bootstrap-daterangepicker', - version: '1.3.22', + version: '2.0.0', summary: 'Date range picker component for Bootstrap', git: 'https://github.com/dangrossman/bootstrap-daterangepicker', documentation: 'README.md' @@ -14,5 +14,5 @@ Package.onUse(function(api) { api.use('jquery@1.11.3_2', ["client"]); api.addFiles('daterangepicker.js', ["client"]); - api.addFiles('daterangepicker-bs3.css', ["client"]); + api.addFiles('daterangepicker.css', ["client"]); }); diff --git a/package.json b/package.json index ccd3d913..c8a3332d 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "bootstrap-daterangepicker", - "version": "1.3.22", + "version": "2.0.0", "description": "Date range picker component for Bootstrap", "main": "daterangepicker.js", - "style": "daterangepicker-bs3.css", + "style": "daterangepicker.css", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/website.html b/website.html new file mode 100644 index 00000000..b22cf6a2 --- /dev/null +++ b/website.html @@ -0,0 +1,922 @@ + + + + + Date Range Picker for Bootstrap + + + + + + + + + + + + + + + +
+
+
+
+ +

Date Range Picker

+

+ A JavaScript dropdown for choosing date ranges. +
+ Designed to work with the Bootstrap CSS framework. +

+ +
+
+ + View on GitHub + +   + + Download ZIP + +

+ + + + + + + +
+
+
+
+ +
+
+ +
+ +
+ +

+ Originally built for reporting at Improvely, + the Date Range Picker can be attached to any webpage element to pop up two calendars + for selecting dates, times, or from predefined ranges like "Last 30 Days". +

+ + + +
+ +
+ +

Usage

+ +

+ Date Range Picker relies on Bootstrap, jQuery and Moment.js. + + Include the required scripts and stylesheet in your page: +

+ + + +

Then attach the picker to the element you want to trigger it:

+ + + +
+ +

+ You can customize Date Range Picker with options, and + get notified when the user chooses new dates by providing a callback function. +

+ + + +
+ +
+ +

Examples

+ +
+ +

Date Range Picker

+ +

+ The Date Range Picker is attached to a text input. It will use the current + value of the input to initialize, and update the input if new dates are chosen. +

+ +
+
+ +
+
+

Demo:

+ +
+
+ + + +
+ +
+ +

Date and Time

+ +

+ The Date Range Picker can also be used to select times. Hour, minute and (optional) + second dropdowns are added below the calendars. An option exists to set the increment + count of the minutes dropdown to e.g. offer only 15-minute or 30-minute increments. +

+ +
+
+ +
+
+

Demo:

+ +
+
+ + + +
+ +
+ +

Single Date Picker

+ +

+ The Date Range Picker can be turned into a single date picker widget with only + one calendar. In this example, dropdowns to select a month and year have also + been enabled at the top of the calendar to quickly jump to different months. +

+ +
+
+ +
+
+

Demo:

+ +
+
+ + + +
+ +
+ +

Predefined Ranges

+ +

+ This example shows the option to predefine date ranges that + the user can choose from a list. +

+ +
+
+ +
+
+

Demo:

+
+   + +
+
+
+ +
+ + + +
+ +
+ +

Configuration Generator

+ +
+ +
+
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+ +
+ +
+ +
+

Configuration

+ +
+ +
+ +
+
+

Your Date Range Picker

+ + +
+ +
+ +
+ +
+ +

Options

+ +
    +
  • + startDate (Date object, moment object or string) The start of the initially selected date range +
  • +
  • + endDate: (Date object, moment object or string) The end of the initially selected date range +
  • +
  • + minDate: (Date object, moment object or string) The earliest date a user may select +
  • +
  • + maxDate: (Date object, moment object or string) The latest date a user may select +
  • +
  • + dateLimit: (object) The maximum span between the selected start and end dates. Can have any property you can add to a moment object (i.e. days, months) +
  • +
  • + timeZone: (string or number) The timezone that will be used to display the startDate and endDate in the calendar. This may be a string such as "08:00" or an offset in minutes from Greenwich Mean Time. Uses Moment.js #utcOffset, see the docs here for more information. If the timeZone option is not set, the calendar will use the time zone set on the startDate that has been passed in through the options, if it has one. Defaults to the local time zone +
  • +
  • + showDropdowns: (boolean) Show year and month select boxes above calendars to jump to a specific month and year +
  • +
  • + showWeekNumbers: (boolean) Show week numbers at the start of each week on the calendars +
  • +
  • + timePicker: (boolean) Allow selection of dates with times, not just dates +
  • +
  • + timePickerIncrement: (number) Increment of the minutes selection list for times (i.e. 30 to allow only selection of times ending in 0 or 30) +
  • +
  • + timePicker24Hour: (boolean) Use 24-hour instead of 12-hour times, removing the AM/PM selection +
  • +
  • + timePickerSeconds: (boolean) Show seconds in the timePicker +
  • +
  • + ranges: (object) Set predefined date ranges the user can select from. Each key is the label for the range, and its value an array with two dates representing the bounds of the range +
  • +
  • + opens: (string: 'left'/'right'/'center') Whether the picker appears aligned to the left, to the right, or centered under the HTML element it's attached to +
  • +
  • + drops: (string: 'down' or 'up') Whether the picker appears below (default) or above the HTML element it's attached to +
  • +
  • + buttonClasses: (array) CSS class names that will be added to all buttons in the picker +
  • +
  • + applyClass: (string) CSS class string that will be added to the apply button +
  • +
  • + cancelClass: (string) CSS class string that will be added to the cancel button +
  • +
  • + locale: (object) Allows you to provide localized strings for buttons and labels, customize the date display format, and change the first day of week for the calendars +
  • +
  • + singleDatePicker: (boolean) Show only a single calendar to choose one date, instead of a range picker with two calendars; the start and end dates provided to your callback will be the same single date chosen +
  • +
  • + parentEl: (string) jQuery selector of the parent element that the date range picker will be added to, if not provided this will be 'body' +
  • +
+ +
+ +
+ +

Methods Reference

+ +

+ You can programmatically update the startDate and endDate + in the picker using the setStartDate and setEndDate methods. + You can access the Date Range Picker object and its functions and properties through + data properties of the element you attached it to. +

+ + + +
+ +
    +
  • + setStartDate(Date/moment/string): Sets the date range picker's currently selected start date to the provided date +
  • +
  • + setEndDate(Date/moment/string): Sets the date range picker's currently selected end date to the provided date +
  • +
+ +

Example usage:

+ + + +
+ +
+ +

Events Reference

+ +

+ Several events are triggered on the element you attach the picker to, which you can listen for. +

+ +
    +
  • + show.daterangepicker: Triggered when the picker is shown +
  • +
  • + hide.daterangepicker: Triggered when the picker is hidden +
  • +
  • + showCalendar.daterangepicker: Triggered when the calendar(s) are shown +
  • +
  • + hideCalendar.daterangepicker: Triggered when the calendar(s) are hidden +
  • +
  • + apply.daterangepicker: Triggered when the apply button is clicked, + or when a predefined range is clicked +
  • +
  • + cancel.daterangepicker: Triggered when the cancel button is clicked +
  • +
+ +

+ Some applications need a "clear" instead of a "cancel" functionality, which can be achieved by changing the button label and watching for the cancel event: +

+ + + +
+ +

+ While passing in a callback to the constructor is the easiest way to listen for changes in the selected date range, you can also do something every time the apply button is clicked even if the selection hasn't changed: +

+ + + +
+ +
+ +

License

+ +

The MIT License (MIT)

+ +

Copyright (c) 2012-2015 Dan Grossman

+ +

+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +

+ +

+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +

+ +

+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +

+ +
+ +
+ +

Comments

+ +
+ + + +
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + +