forked from gitea/gitea
Merge pull request #326 from nuss-justin/feature/keep-text
Save comment/issue drafts in sessionStorage.
This commit is contained in:
commit
5ed5912ef5
|
@ -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.
|
// Preview for images.
|
||||||
(function() {
|
(function() {
|
||||||
var $hoverElement = $("<div></div>");
|
var $hoverElement = $("<div></div>");
|
||||||
|
@ -661,6 +705,20 @@ function initIssue() {
|
||||||
return;
|
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;
|
window.location.href = response.data;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue