diff options
author | Unknwon <joe2010xtmf@163.com> | 2014-07-24 12:49:43 -0400 |
---|---|---|
committer | Unknwon <joe2010xtmf@163.com> | 2014-07-24 12:49:43 -0400 |
commit | c20f5dc2ea1b27e80c28e00831278c7451ba6cce (patch) | |
tree | 85d1f32c36f962ad6338ec75e3a7a8ff8baf1905 /public/js/app.js | |
parent | a41a1fe60da5b02891640dd5f99758015b78bcc9 (diff) | |
parent | da0240aacd5646bd73b2e22d92d88578dbafd64b (diff) |
Merge branch 'dev' of github.com:gogits/gogs into dev
Diffstat (limited to 'public/js/app.js')
-rw-r--r-- | public/js/app.js | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/public/js/app.js b/public/js/app.js index 7d4e7839..7ffcbd4a 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -520,6 +520,90 @@ function initIssue() { }); }()); + // Preview for images. + (function() { + var $hoverElement = $("<div></div>"); + var $hoverImage = $("<img />"); + + $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)$/i) == 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 $attachedList = $("#attached-list"); + var $addButton = $("#attachments-button"); + + var fileInput = $("#attachments-input")[0]; + + fileInput.addEventListener("change", function(event) { + $attachedList.empty(); + $attachedList.append("<b>Attachments:</b> "); + + for (var index = 0; index < fileInput.files.length; index++) { + var file = fileInput.files[index]; + + var $span = $("<span></span>"); + + $span.addClass("label"); + $span.addClass("label-default"); + + $span.append(file.name.toLowerCase()); + $attachedList.append($span); + } + }); + + $addButton.on("click", function() { + fileInput.click(); + return false; + }); + }()); + // issue edit mode (function () { $("#issue-edit-btn").on("click", function () { |