datepicker: improve table popup positioning - jscancer - Javascript crap (relatively small)
 (HTM) git clone git://git.codemadness.org/jscancer
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit a7942f7578eae5031a1baa6867ee20631ac2226a
 (DIR) parent 39836e1d998366312bca5fe1f77400923fffd868
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Tue, 30 May 2017 19:38:23 +0200
       
       datepicker: improve table popup positioning
       
       Diffstat:
         M datepicker/datepicker.js            |      14 ++++++++++----
       
       1 file changed, 10 insertions(+), 4 deletions(-)
       ---
 (DIR) diff --git a/datepicker/datepicker.js b/datepicker/datepicker.js
       @@ -77,12 +77,18 @@ function datepicker_init(input) {
                        table.hidden = false;
                        table.style.display = "table";
                        table.style.position = "absolute";
       -                var left = 0;
       +                var left = 0, top = 0;
                        for (var c = input; c; c = c.offsetParent) {
       -                        if (["absolute", "fixed"].indexOf(c.style.position) == -1)
       -                                left += c.offsetLeft;
       +                        left += c.offsetLeft;
       +                        top += c.offsetTop;
       +                        if (c.style.position == "fixed") {
       +                                left += window.pageXOffset;
       +                                top += window.pageYOffset;
       +                                break;
       +                        }
                        }
                        table.style.left = String(left) + "px";
       +                table.style.top = String(top + input.offsetHeight) + "px";
                        // scroll if outside window.
                        input.scrollIntoView();
                };
       @@ -194,7 +200,7 @@ function datepicker_init(input) {
        
                datepicker_render();
                datepicker_hide();
       -        input.parentNode.insertBefore(table, input.nextSibling);
       +        document.body.appendChild(table);
        }
        
        // has native HTML5 date input type support? type is "text" if it isn't.