Fix non-react version positioning
parent
439a672aab
commit
95af62423c
51
calendar.js
51
calendar.js
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* Original: http://www.openjs.com/scripts/ui/calendar/
|
||||
* Modified: http://yourcmc.ru/git/vitalif-js/calendar
|
||||
* Version: 2018-10-23
|
||||
* Version: 2018-11-04
|
||||
* License: MIT-like, http://www.openjs.com/license.php
|
||||
*
|
||||
* Example:
|
||||
|
@ -41,15 +41,33 @@ export class Calendar
|
|||
html += "<a class='calendar-cancel' onclick='Calendar.instance.hideCalendar()'>"+this.close_label+"</a>";
|
||||
Calendar.box.innerHTML = html;
|
||||
if (this.position)
|
||||
{
|
||||
this.calcPosition();
|
||||
}
|
||||
}
|
||||
|
||||
calcPosition()
|
||||
{
|
||||
// Position the div in the correct location...
|
||||
var input = this.input;
|
||||
var div = Calendar.box;
|
||||
var xy = getOffset(this.input);
|
||||
var height = this.input.clientHeight||this.input.offsetHeight;
|
||||
div.style.left = (xy.left-1)+"px";
|
||||
if (this.position == 'top')
|
||||
div.style.top = (xy.top-div.offsetHeight)+'px';
|
||||
var xy = getOffset(input);
|
||||
var height = input.clientHeight||input.offsetHeight;
|
||||
var ww = document.documentElement.clientWidth||document.body.clientWidth;
|
||||
div.style.display = "block";
|
||||
if (div.offsetWidth + xy.left-1 > ww)
|
||||
div.style.left = (ww-div.offsetWidth-1)+"px";
|
||||
else
|
||||
div.style.left = (xy.left-1)+"px";
|
||||
if (div.offsetHeight + xy.top+height-1 >= (document.documentElement.clientHeight||document.body.clientHeight) &&
|
||||
xy.top-div.offsetHeight >= 0)
|
||||
{
|
||||
this.position = 'top';
|
||||
div.style.top = (xy.top-div.offsetHeight)+'px';
|
||||
}
|
||||
else
|
||||
{
|
||||
this.position = 'bottom';
|
||||
div.style.top = (xy.top+height-1)+"px";
|
||||
}
|
||||
}
|
||||
|
@ -289,26 +307,7 @@ export class Calendar
|
|||
this.makeCalendar(this.selected.getFullYear(), this.selected.getMonth());
|
||||
|
||||
// Position the div in the correct location...
|
||||
var div = Calendar.box;
|
||||
var xy = getOffset(input);
|
||||
var height = input.clientHeight||input.offsetHeight;
|
||||
var ww = document.documentElement.clientWidth||document.body.clientWidth;
|
||||
div.style.display = "block";
|
||||
if (div.offsetWidth + xy.left-1 > ww)
|
||||
div.style.left = (ww-div.offsetWidth-1)+"px";
|
||||
else
|
||||
div.style.left = (xy.left-1)+"px";
|
||||
if (div.offsetHeight + xy.top+height-1 >= (document.documentElement.clientHeight||document.body.clientHeight) &&
|
||||
xy.top-div.offsetHeight >= 0)
|
||||
{
|
||||
this.position = 'top';
|
||||
div.style.top = (xy.top-div.offsetHeight)+'px';
|
||||
}
|
||||
else
|
||||
{
|
||||
this.position = 'bottom';
|
||||
div.style.top = (xy.top+height-1)+"px";
|
||||
}
|
||||
this.calcPosition();
|
||||
};
|
||||
|
||||
/// Hides the currently show calendar.
|
||||
|
|
Loading…
Reference in New Issue