diff --git a/scp/js/tips.js b/scp/js/tips.js index 4d623eb165224df19caf4fb06a51593d0f907540..93f4f14c75d49d1c151e27ffc787e1abb42f3078 100644 --- a/scp/js/tips.js +++ b/scp/js/tips.js @@ -10,8 +10,16 @@ jQuery(function() { var tip_shadow = $('<div>').addClass('tip_shadow'); var tip_content = $('<div>').addClass('tip_content').load(url, function() { tip_content.prepend('<a href="#" class="tip_close"><i class="icon-remove-circle"></i></a>').append(tip_arrow); - if ($(window).width() < tip_content.outerWidth() + the_tip.position().left) { - console.log(x_pos, tip_content.outerWidth(), elem.width()); + var width = $(window).width(), + rtl = $('html').hasClass('rtl'), + size = tip_content.outerWidth(), + left = the_tip.position().left, + left_room = left - size, + right_room = width - size - left, + flip = rtl + ? (left_room > 0 && left_room > right_room) + : (right_room < 0 && left_room > right_room); + if (flip) { the_tip.css({'left':x_pos-tip_content.outerWidth()-elem.width()-32+'px'}); tip_box.addClass('right'); tip_arrow.addClass('flip-x'); @@ -105,7 +113,16 @@ jQuery(function() { tip_timer = setTimeout(function() { $('.tip_box').remove(); $('body').append(the_tip.hide().fadeIn()); - if ($(window).width() < tip_content.outerWidth() + the_tip.position().left) { + var width = $(window).width(), + rtl = $('html').hasClass('rtl'), + size = tip_content.outerWidth(), + left = the_tip.position().left, + left_room = left - size, + right_room = width - size - left, + flip = rtl + ? (left_room > 0 && left_room > right_room) + : (right_room < 0 && left_room > right_room); + if (flip) { the_tip.css({'left':x_pos-tip_content.outerWidth()-40+'px'}); tip_box.addClass('right'); tip_arrow.addClass('flip-x');