plugins/timepicker/bootstrap-timepicker.js
function() {
      if (this.isInline) {
        return;
      }
      var widgetWidth = this.$widget.outerWidth(), widgetHeight = this.$widget.outerHeight(), visualPadding = 10, windowWidth =
        $(window).width(), windowHeight = $(window).height(), scrollTop = $(window).scrollTop();

      var zIndex = parseInt(this.$element.parents().filter(function() { return $(this).css('z-index') !== 'auto'; }).first().css('z-index'), 10) + 10;
      var offset = this.component ? this.component.parent().offset() : this.$element.offset();
      var height = this.component ? this.component.outerHeight(true) : this.$element.outerHeight(false);
      var width = this.component ? this.component.outerWidth(true) : this.$element.outerWidth(false);
      var left = offset.left, top = offset.top;

      this.$widget.removeClass('timepicker-orient-top timepicker-orient-bottom timepicker-orient-right timepicker-orient-left');

      if (this.orientation.x !== 'auto') {
        this.$widget.addClass('timepicker-orient-' + this.orientation.x);
        if (this.orientation.x === 'right') {
          left -= widgetWidth - width;
        }
      } else{
        // auto x orientation is best-placement: if it crosses a window edge, fudge it sideways
        // Default to left
        this.$widget.addClass('timepicker-orient-left');
        if (offset.left < 0) {
          left -= offset.left - visualPadding;
        } else if (offset.left + widgetWidth > windowWidth) {
          left = windowWidth - widgetWidth - visualPadding;
        }
      }
      // auto y orientation is best-situation: top or bottom, no fudging, decision based on which shows more of the widget
      var yorient = this.orientation.y, topOverflow, bottomOverflow;
      if (yorient === 'auto') {
        topOverflow = -scrollTop + offset.top - widgetHeight;
        bottomOverflow = scrollTop + windowHeight - (offset.top + height + widgetHeight);
        if (Math.max(topOverflow, bottomOverflow) === bottomOverflow) {
          yorient = 'top';
        } else {
          yorient = 'bottom';
        }
      }
      this.$widget.addClass('timepicker-orient-' + yorient);
      if (yorient === 'top'){
        top += height;
      } else{
        top -= widgetHeight + parseInt(this.$widget.css('padding-top'), 10);
      }

      this.$widget.css({
        top : top,
        left : left,
        zIndex : zIndex
      });
    }
function() {
      if (this.isInline) {
        return;
      }
      var widgetWidth = this.$widget.outerWidth(), widgetHeight = this.$widget.outerHeight(), visualPadding = 10, windowWidth =
        $(window).width(), windowHeight = $(window).height(), scrollTop = $(window).scrollTop();

      var zIndex = parseInt(this.$element.parents().filter(function() { return $(this).css('z-index') !== 'auto'; }).first().css('z-index'), 10) + 10;
      var offset = this.component ? this.component.parent().offset() : this.$element.offset();
      var height = this.component ? this.component.outerHeight(true) : this.$element.outerHeight(false);
      var width = this.component ? this.component.outerWidth(true) : this.$element.outerWidth(false);
      var left = offset.left, top = offset.top;

      this.$widget.removeClass('timepicker-orient-top timepicker-orient-bottom timepicker-orient-right timepicker-orient-left');

      if (this.orientation.x !== 'auto') {
        this.$widget.addClass('timepicker-orient-' + this.orientation.x);
        if (this.orientation.x === 'right') {
          left -= widgetWidth - width;
        }
      } else{
        // auto x orientation is best-placement: if it crosses a window edge, fudge it sideways
        // Default to left
        this.$widget.addClass('timepicker-orient-left');
        if (offset.left < 0) {
          left -= offset.left - visualPadding;
        } else if (offset.left + widgetWidth > windowWidth) {
          left = windowWidth - widgetWidth - visualPadding;
        }
      }
      // auto y orientation is best-situation: top or bottom, no fudging, decision based on which shows more of the widget
      var yorient = this.orientation.y, topOverflow, bottomOverflow;
      if (yorient === 'auto') {
        topOverflow = -scrollTop + offset.top - widgetHeight;
        bottomOverflow = scrollTop + windowHeight - (offset.top + height + widgetHeight);
        if (Math.max(topOverflow, bottomOverflow) === bottomOverflow) {
          yorient = 'top';
        } else {
          yorient = 'bottom';
        }
      }
      this.$widget.addClass('timepicker-orient-' + yorient);
      if (yorient === 'top'){
        top += height;
      } else{
        top -= widgetHeight + parseInt(this.$widget.css('padding-top'), 10);
      }

      this.$widget.css({
        top : top,
        left : left,
        zIndex : zIndex
      });
    }
function ( ) { if ( this . isInline ) { return ; } var widgetWidth = this . $widget . outerWidth ( ) , widgetHeight = this . $widget . outerHeight ( ) , visualPadding = 10 , windowWidth = $ ( window ) . width ( ) , windowHeight = $ ( window ) . height ( ) , scrollTop = $ ( window ) . scrollTop ( ) ; var zIndex = parseInt ( this . $element . parents ( ) . filter ( function ( ) { return $ ( this ) . css ( 'z-index' ) !== 'auto' ; } ) . first ( ) . css ( 'z-index' ) , 10 ) + 10 ; var offset = this . component ? this . component . parent ( ) . offset ( ) : this . $element . offset ( ) ; var height = this . component ? this . component . outerHeight ( true ) : this . $element . outerHeight ( false ) ; var width = this . component ? this . component . outerWidth ( true ) : this . $element . outerWidth ( false ) ; var left = offset . left , top = offset . top ; this . $widget . removeClass ( 'timepicker-orient-top timepicker-orient-bottom timepicker-orient-right timepicker-orient-left' ) ; if ( this . orientation . x !== 'auto' ) { this . $widget . addClass ( 'timepicker-orient-' + this . orientation . x ) ; if ( this . orientation . x === 'right' ) { left -= widgetWidth - width ; } } else { // auto x orientation is best-placement: if it crosses a window edge, fudge it sideways // Default to left this . $widget . addClass ( 'timepicker-orient-left' ) ; if ( offset . left < 0 ) { left -= offset . left - visualPadding ; } else if ( offset . left + widgetWidth > windowWidth ) { left = windowWidth - widgetWidth - visualPadding ; } } // auto y orientation is best-situation: top or bottom, no fudging, decision based on which shows more of the widget var yorient = this . orientation . y , topOverflow , bottomOverflow ; if ( yorient === 'auto' ) { topOverflow = - scrollTop + offset . top - widgetHeight ; bottomOverflow = scrollTop + windowHeight - ( offset . top + height + widgetHeight ) ; if ( Math . max ( topOverflow , bottomOverflow ) === bottomOverflow ) { yorient = 'top' ; } else { yorient = 'bottom' ; } } this . $widget . addClass ( 'timepicker-orient-' + yorient ) ; if ( yorient === 'top' ) { top += height ; } else { top -= widgetHeight + parseInt ( this . $widget . css ( 'padding-top' ) , 10 ) ; } this . $widget . css ( { top : top , left : left , zIndex : zIndex } ) ; }
This method was adapted from bootstrap-datepicker.
This method was adapted from bootstrap - datepicker .