(function ($) { $.fn.thumbPopup = function (options) { settings = jQuery.extend({ popupId: "thumbPopup", popupCSS: { 'background': '#FFFFFF' }, imgSmallFlag: "", imgLargeFlag: "", cursorTopOffset: 15, cursorLeftOffset: 15, loadingHtml: "" }, options); popup = $("
").css(settings.popupCSS).attr("id", settings.popupId).css("position", "absolute").appendTo("body").hide(); $(this).hover(setPopup).mousemove(updatePopupPosition).mouseout(hidePopup); function setPopup(event) { var fullImgURL = $(this).attr("src"); $(this).data("hovered", true); $("").bind("load", { thumbImage: this }, function (event) { if ($(event.data.thumbImage).data("hovered") == true) { $(popup).empty().append(this); updatePopupPosition(event); $(popup).show(); } $(event.data.thumbImage).data("cached", true); }).attr("src", fullImgURL).attr("height", "175").attr("border", "0"); if ($(this).data("cached") != true) { $(popup).append($(settings.loadingHtml)); $(popup).show(); } updatePopupPosition(event); } function updatePopupPosition(event) { var windowSize = getWindowSize(); var popupSize = getPopupSize(); if (windowSize.width + windowSize.scrollLeft < event.pageX + popupSize.width + settings.cursorLeftOffset) { $(popup).css("left", event.pageX - popupSize.width - settings.cursorLeftOffset); } else { $(popup).css("left", event.pageX + settings.cursorLeftOffset); } if (windowSize.height + windowSize.scrollTop < event.pageY + popupSize.height + settings.cursorTopOffset) { $(popup).css("top", event.pageY - popupSize.height - settings.cursorTopOffset); } else { $(popup).css("top", event.pageY + settings.cursorTopOffset); } } function hidePopup(event) { $(this).data("hovered", false); $(popup).empty().hide(); } function getWindowSize() { return { scrollLeft: $(window).scrollLeft(), scrollTop: $(window).scrollTop(), width: $(window).width(), height: $(window).height() }; } function getPopupSize() { return { width: $(popup).width(), height: $(popup).height() }; } return this; }; })(jQuery);