From 43e5de7f830a098582b519706f9c5da6eecd2c3e Mon Sep 17 00:00:00 2001 From: Justin Nuß Date: Thu, 24 Jul 2014 13:50:03 +0200 Subject: Show attachments in issues/comments and add preview for images --- public/js/app.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'public/js/app.js') diff --git a/public/js/app.js b/public/js/app.js index 16d1d5da..3d4ed623 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -520,6 +520,61 @@ function initIssue() { }); }()); + // Preview for images. + (function() { + var $hoverElement = $("
"); + var $hoverImage = $(""); + + $hoverElement.addClass("attachment-preview"); + $hoverElement.hide(); + + $hoverImage.addClass("attachment-preview-img"); + + $hoverElement.append($hoverImage); + $(document.body).append($hoverElement); + + var over = function() { + var $this = $(this); + + if ($this.text().match(/\.(png|jpg|jpeg|gif)$/) == false) { + return; + } + + if ($hoverImage.attr("src") != $this.attr("href")) { + $hoverImage.attr("src", $this.attr("href")); + $hoverImage.load(function() { + var height = this.height; + var width = this.width; + + if (height > 300) { + var factor = 300 / height; + + height = factor * height; + width = factor * width; + } + + $hoverImage.css({"height": height, "width": width}); + + var offset = $this.offset(); + var left = offset.left, top = offset.top + $this.height() + 5; + + $hoverElement.css({"top": top + "px", "left": left + "px"}); + $hoverElement.css({"height": height + 16, "width": width + 16}); + $hoverElement.show(); + }); + } else { + $hoverElement.show(); + } + }; + + var out = function() { + $hoverElement.hide(); + }; + + $(".issue-main .attachments .attachment").hover(over, out); + }()); + + // Upload. (function() { var $attached = $("#attached"); var $attachments = $("input[name=attachments]"); -- cgit v1.2.3