Skip to content

Commit 09cb8c6

Browse files
committed
Save comment/issue drafts in sessionStorage.
1 parent aad91d4 commit 09cb8c6

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

public/js/app.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,50 @@ function initIssue() {
520520
});
521521
}());
522522

523+
// store unsend text in session storage.
524+
(function() {
525+
var $textArea = $("#issue-content,#issue-reply-content");
526+
var current = "";
527+
528+
if ($textArea == null || !('sessionStorage' in window)) {
529+
return;
530+
}
531+
532+
var path = location.pathname.split("/");
533+
var key = "issue-" + path[1] + "-" + path[2] + "-";
534+
535+
if (/\/issues\/\d+$/.test(location.pathname)) {
536+
key = key + path[4];
537+
} else {
538+
key = key + "new";
539+
}
540+
541+
if ($textArea.val() !== undefined && $textArea.val() !== "") {
542+
sessionStorage.setItem(key, $textArea.val());
543+
} else {
544+
$textArea.val(sessionStorage.getItem(key) || "");
545+
546+
if ($textArea.attr("id") == "issue-reply-content") {
547+
var $closeBtn = $('#issue-close-btn');
548+
var $openBtn = $('#issue-open-btn');
549+
550+
if ($textArea.val().length) {
551+
$closeBtn.val($closeBtn.data("text"));
552+
$openBtn.val($openBtn.data("text"));
553+
} else {
554+
$closeBtn.val($closeBtn.data("origin"));
555+
$openBtn.val($openBtn.data("origin"));
556+
}
557+
}
558+
}
559+
560+
$textArea.on("keyup", function() {
561+
if ($textArea.val() !== current) {
562+
sessionStorage.setItem(key, current = $textArea.val());
563+
}
564+
});
565+
}());
566+
523567
// Preview for images.
524568
(function() {
525569
var $hoverElement = $("<div></div>");
@@ -659,8 +703,22 @@ function initIssue() {
659703
$button.text("An error encoured!")
660704

661705
return;
662-
}
706+
}
707+
708+
if (!('sessionStorage' in window)) {
709+
return;
710+
}
711+
712+
var path = location.pathname.split("/");
713+
var key = "issue-" + path[1] + "-" + path[2] + "-";
714+
715+
if (/\/issues\/\d+$/.test(location.pathname)) {
716+
key = key + path[4];
717+
} else {
718+
key = key + "new";
719+
}
663720

721+
sessionStorage.removeItem(key);
664722
window.location.href = response.data;
665723
});
666724

0 commit comments

Comments
 (0)