From 9ae92ee5e50a442b87bf10c26ad9e85b631bab35 Mon Sep 17 00:00:00 2001 From: Suwon Chae Date: Mon, 18 Jun 2018 14:12:38 +0900 Subject: [PATCH] editor: Try to fix editor draft saving bug, second trial --- public/javascripts/common/yobi.CommentForm.js | 4 ++-- public/javascripts/service/yona.temporarySaveHandler.js | 9 +++++++-- public/javascripts/yona-lib.js | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/public/javascripts/common/yobi.CommentForm.js b/public/javascripts/common/yobi.CommentForm.js index cbde35fa6..99820cf78 100644 --- a/public/javascripts/common/yobi.CommentForm.js +++ b/public/javascripts/common/yobi.CommentForm.js @@ -44,6 +44,8 @@ $(function(){ * @returns {boolean} */ function onSubmitCommentForm(event){ + removeCurrentPageTemprarySavedContent(); + event.preventDefault(); var that = this; @@ -59,8 +61,6 @@ $(function(){ elements.commentForm.data("onsubmit", true); - removeCurrentPageTemprarySavedContent(); - NProgress.start(); setTimeout(function () { diff --git a/public/javascripts/service/yona.temporarySaveHandler.js b/public/javascripts/service/yona.temporarySaveHandler.js index 18304a5be..3092db0e0 100644 --- a/public/javascripts/service/yona.temporarySaveHandler.js +++ b/public/javascripts/service/yona.temporarySaveHandler.js @@ -36,8 +36,13 @@ function temporarySaveHandler($textarea, contentInitialized) { }); if (contentInitialized === undefined || contentInitialized === true) { // default: true - if (localStorage.getItem(location.pathname)) { - $textarea.val(localStorage.getItem(location.pathname)); + var lastTextAreaText = $("textarea.content[data-editor-mode='update-comment-body']").last().val(); + var storedDraftText = localStorage.getItem(location.pathname); + if (storedDraftText && lastTextAreaText + && storedDraftText.trim() === lastTextAreaText.trim()) { + removeCurrentPageTemprarySavedContent(); + } else if (storedDraftText) { + $textarea.val(storedDraftText); } } } diff --git a/public/javascripts/yona-lib.js b/public/javascripts/yona-lib.js index 3481bebc3..21a301962 100644 --- a/public/javascripts/yona-lib.js +++ b/public/javascripts/yona-lib.js @@ -42,5 +42,5 @@ c.welMessage.html($yobi.nl2br(b));c.welDescription.html($yobi.nl2br(a||""));c.we a.waItems.removeClass("active");b.addClass("active")}function f(c){c=c.attr("data-value");var e=a.welContainer.attr("data-name");b.sName=e;b.sValue=c;if("undefined"!==typeof e){var f=a.welContainer.find("input[name='"+e+"']");0===f.length&&(f=$(''),a.welContainer.append(f));f.val(c)}}function h(){"function"==typeof b.fOnChange&&setTimeout(function(){b.fOnChange(e())},0)}function e(){return b.sValue}function c(b){b=a.welContainer.find(b);if(0>=b.length)return!1;b= $(b[0]);l(b);f(b);return!0}var b={sValue:""},a={};(function(d){a.welContainer=$(d.elContainer);a.welSelectedLabel=a.welContainer.find(".d-label");a.welList=a.welContainer.find(".dropdown-menu");a.waItems=a.welList.find("li");a.welList.on("click","li",q);a.welList.on("mousewheel",p);b.fOnChange=d.fOnChange;c("li[data-selected=true]")})(g);return{getValue:e,onChange:function(a){b.fOnChange=a;return!0},selectByValue:function(a){return c("li[data-value='"+a+"']")},selectItem:c}}})("yobi.ui.Dropdown");$(document).ready(function(){function g(g,f){var h;f=$("#"+g).find("li > a");(h=localStorage.getItem("yobitab-"+g))&&f[h]&&(h=$(f[h]))&&h.data(!1)&&h.tab("show")}var n,p,q;$(".nav-tabs[id]").each(function(l,f){p=$(f);q=p.attr("id");"undefined"!=typeof q&&(n=p.find("li"),n.click(function(){localStorage.setItem("yobitab-"+q,$(this).index())}),g(q,n))})});(function(g){g=$yobi.createNamespace(g);g.container[g.name]=function(g,p){function q(c){$(this).remove()}function l(c,b){c.bind("webkitTransitionEnd",function(){c.remove()});setTimeout(function(){c.css("opacity",0)},b)}var f,h,e;(function(c,b){b.sTplToast=b.sTplToast.replace("\n","");f=b.sTplToast||'
';h=$(c); e=$(f)})(g,p||{});return{push:function(c,b){var a=e.clone(),d=a.find(".msg");a.css("opacity","0");a.click(q);d.html($yobi.nl2br(c));h.prepend(a);a.css("opacity","1");b&&0Draft saved'))},5E3)))});(void 0=== -n||!0===n)&&localStorage.getItem(location.pathname)&&g.val(localStorage.getItem(location.pathname))}function removeCurrentPageTemprarySavedContent(){localStorage.removeItem(location.pathname);localStorage.removeItem(location.pathname+"-last-comment-update-draft")}; +e){l.sActionURL=e.sActionURL||"/users";l.rxContentRange=/items\s+([0-9]+)\/([0-9]+)/;l.htData=e.htData||{};try{f=$(g);f.typeahead({minLength:l.htData.minLength||0,items:10});var c=f.data("typeahead")||{};c.items=l.htData.limit||10;c.source=l.htData.source||q;"function"===typeof l.htData.updater&&(c.updater=l.htData.updater);"function"===typeof l.htData.render&&(c.render=l.htData.render);c.minLength=l.htData.minLength||0;f.typeahead(c)}catch(b){"object"==typeof console&&console.log(b)}})(g,p||{})}})("yobi.ui.Typeahead");function temporarySaveHandler(g,n){var p=$(".editor-notice-label"),q;g.on("keyup",function(){g.val()!==localStorage.getItem(location.pathname)&&(clearTimeout(q),""===g.val()?localStorage.removeItem(location.pathname):(p.children().fadeOut(),q=setTimeout(function(){"update-comment-body"===g.data("editorMode")?localStorage.setItem(location.pathname+"-last-comment-update-draft",g.val()):(localStorage.setItem(location.pathname,g.val()),p.html('Draft saved'))},5E3)))});if(void 0=== +n||!0===n){var l=$("textarea.content[data-editor-mode='update-comment-body']").last().val(),f=localStorage.getItem(location.pathname);f&&l&&f.trim()===l.trim()?removeCurrentPageTemprarySavedContent():f&&g.val(f)}}function removeCurrentPageTemprarySavedContent(){localStorage.removeItem(location.pathname);localStorage.removeItem(location.pathname+"-last-comment-update-draft")};