summaryrefslogtreecommitdiffstats
path: root/public/js
diff options
context:
space:
mode:
authorJustin Nuß <nuss.justin@gmail.com>2014-07-25 20:56:17 +0200
committerJustin Nuß <nuss.justin@gmail.com>2014-07-25 20:56:17 +0200
commit09cb8c67cb59a331490fa28cc3b608bfd99c3aad (patch)
treec6619353098e66c7cea4ed161c652f1a3aa29114 /public/js
parentaad91d4b21b2aae438162e10f698e81abb4e63ee (diff)
downloadgitea-09cb8c67cb59a331490fa28cc3b608bfd99c3aad.tar.gz
gitea-09cb8c67cb59a331490fa28cc3b608bfd99c3aad.zip
Save comment/issue drafts in sessionStorage.
Diffstat (limited to 'public/js')
-rw-r--r--public/js/app.js60
1 files changed, 59 insertions, 1 deletions
diff --git a/public/js/app.js b/public/js/app.js
index d7208119b3..ef54aaf811 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -520,6 +520,50 @@ function initIssue() {
});
}());
+ // store unsend text in session storage.
+ (function() {
+ var $textArea = $("#issue-content,#issue-reply-content");
+ var current = "";
+
+ if ($textArea == null || !('sessionStorage' in window)) {
+ return;
+ }
+
+ var path = location.pathname.split("/");
+ var key = "issue-" + path[1] + "-" + path[2] + "-";
+
+ if (/\/issues\/\d+$/.test(location.pathname)) {
+ key = key + path[4];
+ } else {
+ key = key + "new";
+ }
+
+ if ($textArea.val() !== undefined && $textArea.val() !== "") {
+ sessionStorage.setItem(key, $textArea.val());
+ } else {
+ $textArea.val(sessionStorage.getItem(key) || "");
+
+ if ($textArea.attr("id") == "issue-reply-content") {
+ var $closeBtn = $('#issue-close-btn');
+ var $openBtn = $('#issue-open-btn');
+
+ if ($textArea.val().length) {
+ $closeBtn.val($closeBtn.data("text"));
+ $openBtn.val($openBtn.data("text"));
+ } else {
+ $closeBtn.val($closeBtn.data("origin"));
+ $openBtn.val($openBtn.data("origin"));
+ }
+ }
+ }
+
+ $textArea.on("keyup", function() {
+ if ($textArea.val() !== current) {
+ sessionStorage.setItem(key, current = $textArea.val());
+ }
+ });
+ }());
+
// Preview for images.
(function() {
var $hoverElement = $("<div></div>");
@@ -659,8 +703,22 @@ function initIssue() {
$button.text("An error encoured!")
return;
- }
+ }
+
+ if (!('sessionStorage' in window)) {
+ return;
+ }
+
+ var path = location.pathname.split("/");
+ var key = "issue-" + path[1] + "-" + path[2] + "-";
+
+ if (/\/issues\/\d+$/.test(location.pathname)) {
+ key = key + path[4];
+ } else {
+ key = key + "new";
+ }
+ sessionStorage.removeItem(key);
window.location.href = response.data;
});