Sinneren Sinneren - 8 days ago 8
Javascript Question

How to detect up or down direction jQuery UI datepicker at his input element?

I can detect input offset position at window:
input.getBoundingClientRect().top
But I must to know where will be my datepicker block(under input or above it) to change it class-name.

Answer
beforeShow: function (input, inst) {
    var instHeight = 0;

    setTimeout(function () {
      instHeight = inst.dpDiv.height();
      if(input.getBoundingClientRect().top < instHeight) {
        inst.dpDiv
          .removeClass('ui-top')
          .addClass('ui-bottom')
          .position({
            my: 'left top+5',
            at: 'left bottom',
            collision: 'none',
            of: input
          })
      } else {
        inst.dpDiv
          .removeClass('ui-bottom')
          .addClass('ui-top')
          .position({
            my: 'left bottom-5',
            at: 'left top',
            collision: 'none',
            of: input
          })
      }
    },0);
  },
Comments