@@ -1710,8 +1710,68 @@ var DateRangePicker;
1710
1710
}
1711
1711
delete this . container ;
1712
1712
delete this . element . dataset ;
1713
- }
1713
+ } ,
1714
+
1715
+ updateRanges : function ( newRanges ) {
1716
+ if ( typeof newRanges === 'object' ) {
1717
+ jq . off ( this . container . querySelector ( '.ranges' ) , 'click' , 'li' , this . clickRangeProxy ) ;
1718
+ this . ranges = [ ] ;
1719
+ let rangesKeys = Object . keys ( newRanges ) ;
1720
+ for ( let i = 0 ; i < rangesKeys . length ; ++ i ) {
1721
+ let range = rangesKeys [ i ] ;
1722
+
1723
+ if ( typeof newRanges [ range ] [ 0 ] === 'string' )
1724
+ start = moment ( newRanges [ range ] [ 0 ] , this . locale . format ) ;
1725
+ else
1726
+ start = moment ( newRanges [ range ] [ 0 ] ) ;
1727
+
1728
+ if ( typeof newRanges [ range ] [ 1 ] === 'string' )
1729
+ end = moment ( newRanges [ range ] [ 1 ] , this . locale . format ) ;
1730
+ else
1731
+ end = moment ( newRanges [ range ] [ 1 ] ) ;
1732
+
1733
+ // If the start or end date exceed those allowed by the minDate or maxSpan
1734
+ // options, shorten the range to the allowable period.
1735
+ if ( this . minDate && start . isBefore ( this . minDate ) )
1736
+ start = this . minDate . clone ( ) ;
1737
+
1738
+ var maxDate = this . maxDate ;
1739
+ if ( this . maxSpan && maxDate && start . clone ( ) . add ( this . maxSpan ) . isAfter ( maxDate ) )
1740
+ maxDate = start . clone ( ) . add ( this . maxSpan ) ;
1741
+ if ( maxDate && end . isAfter ( maxDate ) )
1742
+ end = maxDate . clone ( ) ;
1743
+
1744
+ // If the end of the range is before the minimum or the start of the range is
1745
+ // after the maximum, don't display this range option at all.
1746
+ if ( ( this . minDate && end . isBefore ( this . minDate , this . timepicker ? 'minute' : 'day' ) )
1747
+ || ( maxDate && start . isAfter ( maxDate , this . timepicker ? 'minute' : 'day' ) ) )
1748
+ continue ;
1749
+
1750
+ //Support unicode chars in the range names.
1751
+ var elem = document . createElement ( 'textarea' ) ;
1752
+ elem . innerHTML = range ;
1753
+ var rangeHtml = elem . value ;
1754
+
1755
+ this . ranges [ rangeHtml ] = [ start , end ] ;
1756
+ }
1757
+
1758
+ var list = '<ul>' ;
1759
+ for ( range in this . ranges ) {
1760
+ list += '<li data-range-key="' + range + '">' + range + '</li>' ;
1761
+ }
1762
+ if ( this . showCustomRangeLabel ) {
1763
+ list += '<li data-range-key="' + this . locale . customRangeLabel + '">' + this . locale . customRangeLabel + '</li>' ;
1764
+ }
1765
+ list += '</ul>' ;
1766
+ let rangeNode = this . container . querySelector ( '.ranges' ) ;
1767
+ rangeNode . removeChild ( rangeNode . firstChild ) ;
1768
+ rangeNode . insertAdjacentHTML ( 'afterbegin' , list ) ;
1769
+ }
1714
1770
1771
+ this . clickRangeProxy = function ( e ) { this . clickRange ( e ) ; } . bind ( this ) ;
1772
+ jq . on ( this . container . querySelector ( '.ranges' ) , 'click' , 'li' , this . clickRangeProxy ) ;
1773
+ }
1774
+
1715
1775
} ;
1716
1776
1717
1777
// alternate jquery function (subset)
@@ -1826,4 +1886,4 @@ var DateRangePicker;
1826
1886
}
1827
1887
} ,
1828
1888
} ;
1829
- } ) ( ) ;
1889
+ } ) ( ) ;
0 commit comments