Skip to content

Commit 933c0d4

Browse files
committed
add support for drops: 'auto'
1 parent 3d57f7b commit 933c0d4

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

daterangepicker.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,9 @@
10231023

10241024
move: function() {
10251025
var parentOffset = { top: 0, left: 0 },
1026-
containerTop;
1026+
containerTop,
1027+
drops = this.drops;
1028+
10271029
var parentRightEdge = $(window).width();
10281030
if (!this.parentEl.is('body')) {
10291031
parentOffset = {
@@ -1033,10 +1035,21 @@
10331035
parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left;
10341036
}
10351037

1036-
if (this.drops == 'up')
1038+
switch (drops) {
1039+
case 'auto':
1040+
containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;
1041+
if (containerTop + this.container.outerHeight() >= this.parentEl[0].scrollHeight) {
1042+
containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;
1043+
drops = 'up';
1044+
}
1045+
break;
1046+
case 'up':
10371047
containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;
1038-
else
1048+
break;
1049+
default:
10391050
containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;
1051+
break;
1052+
}
10401053

10411054
// Force the container to it's actual width
10421055
this.container.css({
@@ -1046,7 +1059,7 @@
10461059
});
10471060
var containerWidth = this.container.outerWidth();
10481061

1049-
this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('drop-up');
1062+
this.container.toggleClass('drop-up', drops == 'up');
10501063

10511064
if (this.opens == 'left') {
10521065
var containerRight = parentRightEdge - this.element.offset().left - this.element.outerWidth();

website/index.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ <h2><a data-toggle="nothing" href="#example4">Predefined Date Ranges</a></h2>
263263
}, cb);
264264

265265
cb(start, end);
266-
266+
267267
});
268268
</script>
269269

@@ -282,7 +282,7 @@ <h2><a data-toggle="nothing" href="#example5">Input Initially Empty</a></h2>
282282
<div class="col-4">
283283
<label>Produces:</label>
284284
<input type="text" name="datefilter" class="form-control pull-right" value="" />
285-
285+
286286
<script type="text/javascript">
287287
$(function() {
288288

@@ -367,7 +367,7 @@ <h1 style="margin-top: 30px"><a id="options" href="#options">Options</a></h1>
367367
<code>opens</code>: ('left'/'right'/'center') Whether the picker appears aligned to the left, to the right, or centered under the HTML element it's attached to.
368368
</li>
369369
<li>
370-
<code>drops</code>: ('down'/'up') Whether the picker appears below (default) or above the HTML element it's attached to.
370+
<code>drops</code>: ('down'/'up'/'auto') Whether the picker appears below (default) or above the HTML element it's attached to.
371371
</li>
372372
<li>
373373
<code>buttonClasses</code>: (string) CSS class names that will be added to both the apply and cancel buttons.
@@ -416,14 +416,14 @@ <h1 style="margin-top: 30px"><a id="methods" href="#methods">Methods</a></h1>
416416
<p>
417417
You can programmatically update the <code>startDate</code> and <code>endDate</code>
418418
in the picker using the <code>setStartDate</code> and <code>setEndDate</code> methods.
419-
You can access the Date Range Picker object and its functions and properties through
419+
You can access the Date Range Picker object and its functions and properties through
420420
data properties of the element you attached it to.
421421
</p>
422422

423423
<script src="https://gist.github.com/dangrossman/8ff9b1220c9b5682e8bd.js"></script>
424424

425425
<br/>
426-
426+
427427
<ul class="nobullets">
428428
<li>
429429
<code>setStartDate(Date or string)</code>: Sets the date range picker's currently selected start date to the provided date
@@ -482,7 +482,7 @@ <h1 style="margin-top: 30px"><a id="events" href="#events">Events</a></h1>
482482
<h1 style="margin-top: 30px"><a id="config" href="#config">Configuration Generator</a></h1>
483483

484484
<div class="well configurator">
485-
485+
486486
<form>
487487
<div class="row">
488488

@@ -527,6 +527,7 @@ <h1 style="margin-top: 30px"><a id="config" href="#config">Configuration Generat
527527
<select id="drops" class="form-control">
528528
<option value="down" selected>down</option>
529529
<option value="up">up</option>
530+
<option value="auto">auto</option>
530531
</select>
531532
</div>
532533

@@ -737,7 +738,7 @@ <h1 style="margin-top: 30px"><a id="config" href="#comments">Comments</a></h1>
737738
</script>
738739

739740
<div id="footer">
740-
Copyright &copy; 2012-2018 <a href="http://www.dangrossman.info/">Dan Grossman</a>.
741+
Copyright &copy; 2012-2018 <a href="http://www.dangrossman.info/">Dan Grossman</a>.
741742
</div>
742743

743744
</body>

0 commit comments

Comments
 (0)