code: function( popup, left, top ) // left+top relative to container
          {
              // Test parents, el.getBoundingClientRect() does not work within 'position:fixed'
              var node = node_container,
                  popup_parent = node.offsetParent;
              while( node )
              {
                  var node_style = getComputedStyle( node );
                  if( node_style['position'] != 'static' )
                      break;
                  left += node.offsetLeft;
                  top += node.offsetTop;
                  popup_parent = node;
                  node = node.offsetParent;
              }
              // Move popup as high as possible in the DOM tree
              popup_parent.appendChild( popup );
              // Trim to viewport
              var rect = popup_parent.getBoundingClientRect();
              var documentElement = document.documentElement;
              var viewport_width = Math.min( window.innerWidth, Math.max(documentElement.offsetWidth, documentElement.scrollWidth) );
              var viewport_height = window.innerHeight;
              var popup_width = popup.offsetWidth;    // accurate to integer
              var popup_height = popup.offsetHeight;
              if( rect.left + left < 1 )
                  left = 1 - rect.left;
              else if( rect.left + left + popup_width > viewport_width - 1 )
                  left = Math.max( 1 - rect.left, viewport_width - 1 - rect.left - popup_width );
              if( rect.top + top < 1 )
                  top = 1 - rect.top;
              else if( rect.top + top + popup_height > viewport_height - 1 )
                  top = Math.max( 1 - rect.top, viewport_height - 1 - rect.top - popup_height );
              // Set offset
              popup.style.left = parseInt(left) + 'px';
              popup.style.top = parseInt(top) + 'px';
          }
docs: open popup and apply position