1001}10021003proxy.dimension.height = areaGreatestY - areaSmallestY;1004proxy.dimension.width = areaGreatestX - areaSmallestX;1005proxy.offset.top = mapOffsetTop + areaSmallestY;1006proxy.offset.left = mapOffsetLeft + areaSmallestX;1007} else {1008proxy.dimension.height = map.offsetHeight;1009proxy.dimension.width = map.offsetWidth;1010proxy.offset.top = mapOffsetTop;1011proxy.offset.left = mapOffsetLeft;1012
} } // our function and global vars for positioning our tooltip var currentLeft = 0; var currentLeftMirror = 0; var currentTop = 0; var offsetY = parseInt(self.options.offsetY); var offsetX = parseInt(self.options.offsetX); // this is the arrow position that will eventually be used. It may differ from the position option if the tooltip cannot be displayed in this position practicalPosition = self.options.position; /** * A function to detect if the tooltip is going off the screen horizontally. If so, reposition it! */ function dontGoOffScreenX() { var windowLeft = (window.pageXOffset || body.scrollLeft) - (body.clientLeft || 0); // if the tooltip goes off the left side of the screen, line it up with the left side of the window if (currentLeft - windowLeft < 0) { arrowReposition = currentLeft - windowLeft; currentLeft = windowLeft; } // if the tooltip goes off the right of the screen, line it up with the right side of the window if (currentLeft + tooltipWidth - windowLeft > windowWidth) { arrowReposition = currentLeft - (windowWidth + windowLeft - tooltipWidth); currentLeft = windowWidth + windowLeft - tooltipWidth; } } /** * A function to detect if the tooltip is going off the screen vertically. If so, switch to the opposite! * * @param {string} switchTo - switch to position * @param {string} switchFrom - switch from position */ function dontGoOffScreenY(switchTo, switchFrom) { var windowScrollTop = window.pageYOffset; // if it goes off the top off the page if ( proxy.offset.top - windowScrollTop - tooltipHeight - offsetY - 12 < 0 && switchFrom.indexOf('top') > -1 ) { practicalPosition = switchTo; } // if it goes off the bottom of the page but fits at the top if ( proxy.offset.top + proxy.dimension.height + tooltipHeight + 12 + offsetY > windowScrollTop + window.innerHeight && switchFrom.indexOf('bottom') > -1 && proxy.offset.top - tooltipHeight - offsetY - 12 > 0 ) { practicalPosition = switchTo; currentTop = proxy.offset.top - tooltipHeight - offsetY - 12; } } if (practicalPosition === 'top') { var leftDifference = proxy.offset.left + tooltipWidth - (proxy.offset.left + proxy.dimension.width); currentLeft = proxy.offset.left + offsetX - leftDifference / 2; currentTop = proxy.offset.top - tooltipHeight - offsetY - 12; dontGoOffScreenX(); dontGoOffScreenY('bottom', 'top'); } if (practicalPosition === 'top-left') { currentLeft = proxy.offset.left + offsetX; currentTop = proxy.offset.top - tooltipHeight - offsetY - 12; dontGoOffScreenX(); dontGoOffScreenY('bottom-left', 'top-left'); } if (practicalPosition === 'top-right') { currentLeft = proxy.offset.left + proxy.dimension.width + offsetX - tooltipWidth; currentTop = proxy.offset.top - tooltipHeight - offsetY - 12; dontGoOffScreenX(); dontGoOffScreenY('bottom-right', 'top-right'); } if (practicalPosition === 'bottom') { var leftDifference = proxy.offset.left + tooltipWidth - (proxy.offset.left + proxy.dimension.width); currentLeft = proxy.offset.left - leftDifference / 2 + offsetX; currentTop = proxy.offset.top + proxy.dimension.height + offsetY + 12; dontGoOffScreenX();