Skip to content

Commit

Permalink
Bump version number, namespace events
Browse files Browse the repository at this point in the history
  • Loading branch information
dangrossman committed Mar 6, 2014
1 parent 15bd859 commit 26d32cd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ $(document).ready(function() {

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 range label chosen (if any), as parameters. It will not fire if the picker is closed without any change
to the selected dates.
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(
Expand All @@ -50,7 +50,7 @@ $('input[name="daterange"]').daterangepicker(
startDate: '2013-01-01',
endDate: '2013-12-31'
},
function(start, end) {
function(start, end, label) {
alert('A date range was chosen: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));
}
);
Expand Down Expand Up @@ -106,17 +106,28 @@ Several functions are provided for updating the picker's option and state after

`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`: Triggered when the picker is shown
`show.daterangepicker`: Triggered when the picker is shown

`hide`: Triggered when the picker is hidden
`hide.daterangepicker`: Triggered when the picker is hidden

`apply`: Triggered when the apply button is clicked
`apply.daterangepicker`: Triggered when the apply button is clicked

`cancel`: Triggered when the cancel 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:

Expand All @@ -125,7 +136,7 @@ $('#daterange').daterangepicker({
locale: { cancelLabel: 'Clear' }
});
$('#daterange').on('cancel', function(ev, picker) {
$('#daterange').on('cancel.daterangepicker', function(ev, picker) {
//do something, like clearing an input
$('#daterange').val('');
});
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap-daterangepicker",
"version": "1.3.2",
"version": "1.3.3",
"main": "daterangepicker.js",
"ignore": [
"**/.*",
Expand Down
12 changes: 6 additions & 6 deletions daterangepicker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @version: 1.3.2
* @version: 1.3.3
* @author: Dan Grossman http://www.dangrossman.info/
* @date: 2014-01-22
* @copyright: Copyright (c) 2012-2014 Dan Grossman. All rights reserved.
Expand Down Expand Up @@ -500,7 +500,7 @@
}

$(document).on('mousedown', $.proxy(this.hide, this));
this.element.trigger('show', this);
this.element.trigger('show.daterangepicker', this);
},

hide: function (e) {
Expand All @@ -514,7 +514,7 @@
this.oldEndDate = this.endDate.clone();

$(document).off('mousedown', this.hide);
this.element.trigger('hide', this);
this.element.trigger('hide.daterangepicker', this);
},

enterRange: function (e) {
Expand Down Expand Up @@ -567,7 +567,7 @@

this.container.find('.calendar').hide();
this.hide();
this.element.trigger('apply', this);
this.element.trigger('apply.daterangepicker', this);
}
},

Expand Down Expand Up @@ -662,7 +662,7 @@
clickApply: function (e) {
this.updateInputText();
this.hide();
this.element.trigger('apply', this);
this.element.trigger('apply.daterangepicker', this);
},

clickCancel: function (e) {
Expand All @@ -672,7 +672,7 @@
this.updateView();
this.updateCalendars();
this.hide();
this.element.trigger('cancel', this);
this.element.trigger('cancel.daterangepicker', this);
},

updateMonthYear: function (e) {
Expand Down
12 changes: 6 additions & 6 deletions examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ <h4>Options Usage</h4>
<script type="text/javascript">
$(document).ready(function() {

var cb = function(start, end) {
var cb = function(start, end, label) {
$('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
alert("Callback has fired: [" + start.format('MMMM D, YYYY') + " to " + end.format('MMMM D, YYYY') + "]");
alert("Callback has fired: [" + start.format('MMMM D, YYYY') + " to " + end.format('MMMM D, YYYY') + ", label = " + label + "]");
}

var optionSet1 = {
Expand Down Expand Up @@ -173,16 +173,16 @@ <h4>Options Usage</h4>

$('#reportrange').daterangepicker(optionSet1, cb);

$('#reportrange').on('show', function() { console.log("show event fired"); });
$('#reportrange').on('hide', function() { console.log("hide event fired"); });
$('#reportrange').on('apply', function(ev, picker) {
$('#reportrange').on('show.daterangepicker', function() { console.log("show event fired"); });
$('#reportrange').on('hide.daterangepicker', function() { console.log("hide event fired"); });
$('#reportrange').on('apply.daterangepicker', function(ev, picker) {
console.log("apply event fired, start/end dates are "
+ picker.startDate.format('MMMM D, YYYY')
+ " to "
+ picker.endDate.format('MMMM D, YYYY')
);
});
$('#reportrange').on('cancel', function(ev, picker) { console.log("cancel event fired"); });
$('#reportrange').on('cancel.daterangepicker', function(ev, picker) { console.log("cancel event fired"); });

$('#options1').click(function() {
$('#reportrange').data('daterangepicker').setOptions(optionSet1, cb);
Expand Down

0 comments on commit 26d32cd

Please sign in to comment.