@@ -520,6 +520,50 @@ function initIssue() {
520
520
} ) ;
521
521
} ( ) ) ;
522
522
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 ( / \/ i s s u e s \/ \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
+
523
567
// Preview for images.
524
568
( function ( ) {
525
569
var $hoverElement = $ ( "<div></div>" ) ;
@@ -659,8 +703,22 @@ function initIssue() {
659
703
$button . text ( "An error encoured!" )
660
704
661
705
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 ( / \/ i s s u e s \/ \d + $ / . test ( location . pathname ) ) {
716
+ key = key + path [ 4 ] ;
717
+ } else {
718
+ key = key + "new" ;
719
+ }
663
720
721
+ sessionStorage . removeItem ( key ) ;
664
722
window . location . href = response . data ;
665
723
} ) ;
666
724
0 commit comments