Fix non-react version positioning

master
Vitaliy Filippov 2018-11-04 15:13:59 +03:00
parent 439a672aab
commit 95af62423c
1 changed files with 28 additions and 29 deletions

View File

@ -4,7 +4,7 @@
* *
* Original: http://www.openjs.com/scripts/ui/calendar/ * Original: http://www.openjs.com/scripts/ui/calendar/
* Modified: http://yourcmc.ru/git/vitalif-js/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 * License: MIT-like, http://www.openjs.com/license.php
* *
* Example: * Example:
@ -42,15 +42,33 @@ export class Calendar
Calendar.box.innerHTML = html; Calendar.box.innerHTML = html;
if (this.position) if (this.position)
{ {
// Position the div in the correct location... this.calcPosition();
var div = Calendar.box; }
var xy = getOffset(this.input); }
var height = this.input.clientHeight||this.input.offsetHeight;
calcPosition()
{
// Position the div in the correct location...
var input = this.input;
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"; div.style.left = (xy.left-1)+"px";
if (this.position == 'top') if (div.offsetHeight + xy.top+height-1 >= (document.documentElement.clientHeight||document.body.clientHeight) &&
div.style.top = (xy.top-div.offsetHeight)+'px'; xy.top-div.offsetHeight >= 0)
else {
div.style.top = (xy.top+height-1)+"px"; 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()); this.makeCalendar(this.selected.getFullYear(), this.selected.getMonth());
// Position the div in the correct location... // Position the div in the correct location...
var div = Calendar.box; this.calcPosition();
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";
}
}; };
/// Hides the currently show calendar. /// Hides the currently show calendar.