From 115d75cf9b21242134eb70b7e238b9ab6aec4440 Mon Sep 17 00:00:00 2001 From: Konrad Paluszek Date: Sat, 23 Nov 2024 18:31:10 +0100 Subject: [PATCH] Fix balloons position --- resources/jquery-balloon.js | 29 +++++++++++++++++++++++++---- resources/parse-v13.js | 2 +- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/resources/jquery-balloon.js b/resources/jquery-balloon.js index a84a54b..84d7c47 100644 --- a/resources/jquery-balloon.js +++ b/resources/jquery-balloon.js @@ -8,6 +8,12 @@ * @author: Hayato Takenaka (http://urin.take-uma.net) * @version: 0.3.0 - 2012/02/25 **/ + +function isInViewport(el) { + let left = parseFloat(el.style.left); + return left >= 0; +} + ;(function($) { //----------------------------------------------------------------------------- // Private @@ -99,7 +105,22 @@ })(); // Adjust position of balloon body - function makeupBalloon($target, $balloon, options) { + function makeupBalloonWrapper($target, $balloon, options) { + let positions = options.position.split('-'); + console.log('Will try', positions) + for (let position of positions) { + let my_options = {} + Object.assign(my_options, options); + my_options.position = position; + makeupBalloonOriginalImpl($target, $balloon, my_options); + if (isInViewport($balloon[0])) { + console.log('break'); + break; + } + } + } + function makeupBalloonOriginalImpl($target, $balloon, options) { + console.log('try', options) $balloon.stop(true, true); var outerTip, innerTip, initTipStyle = {position: "absolute", height: "0", width: "0", border: "solid 0 transparent"}, @@ -206,7 +227,7 @@ if(options.url) { $balloon.load($.isFunction(options.url) ? options.url(this) : options.url, function(res, sts, xhr) { if(options.ajaxComplete) options.ajaxComplete(res, sts, xhr); - makeupBalloon($target, $balloon, options); + makeupBalloonWrapper($target, $balloon, options); }); } if(isNew) { @@ -216,10 +237,10 @@ .css({visibility: "hidden", position: "absolute"}) .appendTo("body"); $target.data("balloon", $balloon); - makeupBalloon($target, $balloon, options); + makeupBalloonWrapper($target, $balloon, options); $balloon.hide().css("visibility", "visible"); } else { - makeupBalloon($target, $balloon, options); + makeupBalloonWrapper($target, $balloon, options); } $target.data("onTimer", setTimeout(function() { if(options.showAnimation) { diff --git a/resources/parse-v13.js b/resources/parse-v13.js index d890343..bc517ec 100644 --- a/resources/parse-v13.js +++ b/resources/parse-v13.js @@ -633,7 +633,7 @@ function display(node, HTML_title=true, do_topmenu=true) { no++; } if (!is_comment) { - $(a).balloon({position: depth <= 1 ? "bottom" : "left", contents: format_str(node.current_auction.to_table())}); + $(a).balloon({position: 'left-top', contents: format_str(node.current_auction.to_table())}); } content.appendChild(a); }