From 20ab14e1b8d0f5872bd70ec25d3975c5d9900bf4 Mon Sep 17 00:00:00 2001 From: Nathaniel Palmer Date: Sat, 12 Oct 2013 00:38:57 -0400 Subject: [PATCH] prevent share-view being clipped at viewport bounds --- .../javascripts/discourse/views/share_view.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/views/share_view.js b/app/assets/javascripts/discourse/views/share_view.js index 3c4f0f3ce19..4ca94bdf033 100644 --- a/app/assets/javascripts/discourse/views/share_view.js +++ b/app/assets/javascripts/discourse/views/share_view.js @@ -60,14 +60,24 @@ Discourse.ShareView = Discourse.View.extend({ url = window.location.protocol + "//" + window.location.host + url; } - var x = e.pageX - 150; + var shareLinkWidth = $('#share-link').width(); + var x = e.pageX - (shareLinkWidth / 2); if (x < 25) { x = 25; } + if (x + shareLinkWidth > $(window).width()) { + x -= shareLinkWidth / 2; + } + + var header = $('.d-header'); + var y = e.pageY - ($('#share-link').height() + 20); + if (y < header.offset().top + header.height()) { + y = e.pageY + 10; + } $('#share-link').css({ left: "" + x + "px", - top: "" + (e.pageY - 100) + "px" + top: "" + y + "px" }); shareView.set('controller.link', url); shareView.set('controller.postNumber', postNumber);