mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 08:55:12 +00:00
work on autosave
This commit is contained in:
parent
d5117a62b8
commit
b0396cd646
1 changed files with 30 additions and 15 deletions
|
@ -168,15 +168,6 @@ function handle_comment_form(e) {
|
||||||
$('#' + commentElm).attr('tabindex','9');
|
$('#' + commentElm).attr('tabindex','9');
|
||||||
$('#' + submitElm).attr('tabindex','10');
|
$('#' + submitElm).attr('tabindex','10');
|
||||||
|
|
||||||
if(auto_save_draft) {
|
|
||||||
var commentBody = localStorage.getItem("comment_body");
|
|
||||||
if(commentBody && $('#' + commentElm).val() === '') {
|
|
||||||
$('#' + commentElm).val(commentBody);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
localStorage.removeItem("comment_body");
|
|
||||||
}
|
|
||||||
|
|
||||||
form.find(':not(:visible)').show();
|
form.find(':not(:visible)').show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,24 +190,25 @@ function handle_comment_form(e) {
|
||||||
|
|
||||||
var commentSaveTimer = null;
|
var commentSaveTimer = null;
|
||||||
var emptyCommentElm = form.find('.comment-edit-text').attr('id');
|
var emptyCommentElm = form.find('.comment-edit-text').attr('id');
|
||||||
|
var convId = emptyCommentElm.replace(/comment-edit-text-/,'');
|
||||||
$(document).on('focusout','#' + emptyCommentElm,function(e){
|
$(document).on('focusout','#' + emptyCommentElm,function(e){
|
||||||
if(commentSaveTimer)
|
if(commentSaveTimer)
|
||||||
clearTimeout(commentSaveTimer);
|
clearTimeout(commentSaveTimer);
|
||||||
commentSaveChanges(true);
|
commentSaveChanges(convId,true);
|
||||||
commentSaveTimer = null;
|
commentSaveTimer = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('focusin','#' + emptyCommentElm,function(e){
|
$(document).on('focusin','#' + emptyCommentElm,function(e){
|
||||||
commentSaveTimer = setTimeout(function () {
|
commentSaveTimer = setTimeout(function () {
|
||||||
commentSaveChanges(false);
|
commentSaveChanges(convId,false);
|
||||||
},10000);
|
},10000);
|
||||||
});
|
});
|
||||||
|
|
||||||
function commentSaveChanges(isFinal = false) {
|
function commentSaveChanges(convId,isFinal = false) {
|
||||||
if(auto_save_draft) {
|
if(auto_save_draft) {
|
||||||
localStorage.setItem("comment_body", $('#' + emptyCommentElm).val());
|
localStorage.setItem("comment_body" + convId, $('#' + emptyCommentElm).val());
|
||||||
if( !isFinal) {
|
if( !isFinal) {
|
||||||
commentSaveTimer = setTimeout(commentSaveChanges,10000);
|
commentSaveTimer = setTimeout(commentSaveChanges,10000,convId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -600,8 +592,12 @@ function updateConvItems(mode,data) {
|
||||||
$('.thread-wrapper.toplevel_item',data).each(function() {
|
$('.thread-wrapper.toplevel_item',data).each(function() {
|
||||||
|
|
||||||
var ident = $(this).attr('id');
|
var ident = $(this).attr('id');
|
||||||
|
var convId = ident.replace('thread-wrapper-','');
|
||||||
var commentWrap = $('#'+ident+' .collapsed-comments').attr('id');
|
var commentWrap = $('#'+ident+' .collapsed-comments').attr('id');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var itmId = 0;
|
var itmId = 0;
|
||||||
var isVisible = false;
|
var isVisible = false;
|
||||||
|
|
||||||
|
@ -612,6 +608,9 @@ function updateConvItems(mode,data) {
|
||||||
if($('#collapsed-comments-'+itmId).is(':visible'))
|
if($('#collapsed-comments-'+itmId).is(':visible'))
|
||||||
isVisible = true;
|
isVisible = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// insert the content according to the mode and first_page
|
// insert the content according to the mode and first_page
|
||||||
// and whether or not the content exists already (overwrite it)
|
// and whether or not the content exists already (overwrite it)
|
||||||
|
|
||||||
|
@ -633,6 +632,22 @@ function updateConvItems(mode,data) {
|
||||||
if(isVisible)
|
if(isVisible)
|
||||||
showHideComments(itmId);
|
showHideComments(itmId);
|
||||||
|
|
||||||
|
var commentBody = localStorage.getItem("comment_body" + convId);
|
||||||
|
|
||||||
|
if(commentBody) {
|
||||||
|
var commentElm = $('#comment-edit-text' + convId);
|
||||||
|
if(auto_save_draft) {
|
||||||
|
if(commentBody && $('#' + commentElm).val() === '') {
|
||||||
|
$('#comment-edit-form-' + convId).show();
|
||||||
|
$('#' + commentElm).val(commentBody);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem("comment_body" + convId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// trigger the autotime function on all newly created content
|
// trigger the autotime function on all newly created content
|
||||||
|
|
||||||
$("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago();
|
$("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago();
|
||||||
|
|
Loading…
Reference in a new issue