src/nsPopover.js
function move(popover, placement, align, rect, triangle) {
            var containerRect;
            var popoverRect = getBoundingClientRect(popover[0]);
            var popoverRight;
            var top, left;

            var positionX = function() {
              if (align === 'center') {
                return Math.round(rect.left + rect.width/2 - popoverRect.width/2);
              } else if(align === 'right') {
                return rect.right - popoverRect.width;
              }
              return rect.left;
            };

            var positionY = function() {
              if (align === 'center') {
                return Math.round(rect.top + rect.height/2 - popoverRect.height/2);
              } else if(align === 'bottom') {
                return rect.bottom - popoverRect.height;
              }
              return rect.top;
            };

            if (placement === 'top') {
              top = rect.top - popoverRect.height;
              left = positionX();
            } else if (placement === 'right') {
              top = positionY();
              left = rect.right;
            } else if (placement === 'bottom') {
              top = rect.bottom;
              left = positionX();
            } else if (placement === 'left') {
              top = positionY();
              left = rect.left - popoverRect.width;
            }

            // Rescrict the popover to the bounds of the container
            if (true === options.restrictBounds) {
              containerRect = getBoundingClientRect($container[0]);

              // The left should be below the left of the container.
              left = Math.max(containerRect.left, left);

              // Prevent the left from causing the right to go outside
              // the conatiner.
              popoverRight = left + popoverRect.width;
              if (popoverRight > containerRect.width) {
                left = left - (popoverRight - containerRect.width);
              }
            }

            popover
              .css('top', top.toString() + 'px')
              .css('left', left.toString() + 'px');

            if (triangle && triangle.length) {
              if (placement === 'top' || placement === 'bottom') {
                left = rect.left + rect.width / 2 - left;
                triangle.css('left', left.toString() + 'px');
              } else {
                top = rect.top + rect.height / 2 - top;
                triangle.css('top', top.toString()  + 'px');
              }
            }
          }
function move(popover, placement, align, rect, triangle) {
            var containerRect;
            var popoverRect = getBoundingClientRect(popover[0]);
            var popoverRight;
            var top, left;

            var positionX = function() {
              if (align === 'center') {
                return Math.round(rect.left + rect.width/2 - popoverRect.width/2);
              } else if(align === 'right') {
                return rect.right - popoverRect.width;
              }
              return rect.left;
            };

            var positionY = function() {
              if (align === 'center') {
                return Math.round(rect.top + rect.height/2 - popoverRect.height/2);
              } else if(align === 'bottom') {
                return rect.bottom - popoverRect.height;
              }
              return rect.top;
            };

            if (placement === 'top') {
              top = rect.top - popoverRect.height;
              left = positionX();
            } else if (placement === 'right') {
              top = positionY();
              left = rect.right;
            } else if (placement === 'bottom') {
              top = rect.bottom;
              left = positionX();
            } else if (placement === 'left') {
              top = positionY();
              left = rect.left - popoverRect.width;
            }

            // Rescrict the popover to the bounds of the container
            if (true === options.restrictBounds) {
              containerRect = getBoundingClientRect($container[0]);

              // The left should be below the left of the container.
              left = Math.max(containerRect.left, left);

              // Prevent the left from causing the right to go outside
              // the conatiner.
              popoverRight = left + popoverRect.width;
              if (popoverRight > containerRect.width) {
                left = left - (popoverRight - containerRect.width);
              }
            }

            popover
              .css('top', top.toString() + 'px')
              .css('left', left.toString() + 'px');

            if (triangle && triangle.length) {
              if (placement === 'top' || placement === 'bottom') {
                left = rect.left + rect.width / 2 - left;
                triangle.css('left', left.toString() + 'px');
              } else {
                top = rect.top + rect.height / 2 - top;
                triangle.css('top', top.toString()  + 'px');
              }
            }
          }
function move ( popover , placement , align , rect , triangle ) { var containerRect ; var popoverRect = getBoundingClientRect ( popover [ 0 ] ) ; var popoverRight ; var top , left ; var positionX = function ( ) { if ( align === 'center' ) { return Math . round ( rect . left + rect . width / 2 - popoverRect . width / 2 ) ; } else if ( align === 'right' ) { return rect . right - popoverRect . width ; } return rect . left ; } ; var positionY = function ( ) { if ( align === 'center' ) { return Math . round ( rect . top + rect . height / 2 - popoverRect . height / 2 ) ; } else if ( align === 'bottom' ) { return rect . bottom - popoverRect . height ; } return rect . top ; } ; if ( placement === 'top' ) { top = rect . top - popoverRect . height ; left = positionX ( ) ; } else if ( placement === 'right' ) { top = positionY ( ) ; left = rect . right ; } else if ( placement === 'bottom' ) { top = rect . bottom ; left = positionX ( ) ; } else if ( placement === 'left' ) { top = positionY ( ) ; left = rect . left - popoverRect . width ; } // Rescrict the popover to the bounds of the container
 if ( true === options . restrictBounds ) { containerRect = getBoundingClientRect ( $container [ 0 ] ) ; // The left should be below the left of the container.
 left = Math . max ( containerRect . left , left ) ; // Prevent the left from causing the right to go outside
 // the conatiner.
 popoverRight = left + popoverRect . width ; if ( popoverRight > containerRect . width ) { left = left - ( popoverRight - containerRect . width ) ; } } popover . css ( 'top' , top . toString ( ) + 'px' ) . css ( 'left' , left . toString ( ) + 'px' ) ; if ( triangle && triangle . length ) { if ( placement === 'top' || placement === 'bottom' ) { left = rect . left + rect . width / 2 - left ; triangle . css ( 'left' , left . toString ( ) + 'px' ) ; } else { top = rect . top + rect . height / 2 - top ; triangle . css ( 'top' , top . toString ( ) + 'px' ) ; } } }
Move the popover to the |placement| position of the object located on the |rect|.

@param popover {Object} The popover object to be moved.
@param placement {String} The relative position to move the popover - top | bottom | left | right.
@param align {String} The way the popover should be aligned - center | left | right.
@param rect {ClientRect} The ClientRect of the object to move the popover around.
@param triangle {Object} The element that contains the popover's triangle. This can be null.
Move the popover to the |placement| position of the object located on the |rect| .