From 95af62423cfdb79dc2b89f2cf3ddeb75f90b2eca Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 4 Nov 2018 15:13:59 +0300 Subject: [PATCH] Fix non-react version positioning --- calendar.js | 57 ++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/calendar.js b/calendar.js index ccd04d0..c3cb8ab 100644 --- a/calendar.js +++ b/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: @@ -42,15 +42,33 @@ export class Calendar Calendar.box.innerHTML = html; if (this.position) { - // Position the div in the correct location... - var div = Calendar.box; - var xy = getOffset(this.input); - var height = this.input.clientHeight||this.input.offsetHeight; + this.calcPosition(); + } + } + + 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"; - if (this.position == 'top') - div.style.top = (xy.top-div.offsetHeight)+'px'; - else - div.style.top = (xy.top+height-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.