It is annoying when we are typing a huge text in the text editor, and suddenly when we send the message the internet drops or the message does not send. This code ensures that the message is temporarily saved so that you can recycle it.
Create a new JavaScript (The Placement: All Pages):
Create a new JavaScript (The Placement: All Pages):
- Code:
/*
* Application: Last auto-save
* Date: 10/04/2018
* Version: 1.310042018
* Copyright (c) 2018 Daemon <help.forumotion.com>
* This work is free. You can redistribute it and/or modify it
*/
$(document).on("ready", function() {
if (!$.sceditor) return;
var lang = {
dialogTitle: "Recycling notice",
dialogContent: "A message has been saved. Do you want to recycle it?",
dialogConfirm: "Yes",
dialogCancel: "No",
savingNotice: "Last auto-save at"
};
var config = {
modal: $("<div>",{
id: "myModal",
class: "modal"
}).html(
'<div class="modal-content"></div>'
),
dialog: $("<div>",{
id: "myDialog",
class: "dialog"
}).html(
'<div class="dialog-titlebar">' +
' <span class="dialog-title">' + lang.dialogTitle + '</span>' +
'</div>' +
'<div class="dialog-content">' + lang.dialogContent + '</div>' +
'<div class="dialog-buttonpane">' +
' <div class="dialog-buttonset">' +
' <button type="button" class="dialog-button confirm">' + lang.dialogConfirm + '</button>' +
' <button type="button" class="dialog-button cancel">' + lang.dialogCancel + '</button>' +
' </div>' +
'</div>'
),
myCSS: '<style type="text/css">' +
'.modal {' +
' display: none;' +
' position: fixed;' +
' z-index: 99999;' +
' right: 30px;' +
' bottom: 30px;' +
' overflow: auto;' +
'}' +
'.modal-content {' +
' position: relative;' +
' font-family: Verdana, Arial, Helvetica, sans-serif;' +
' background-color: #c3e0ff;' +
' margin: auto;' +
' padding: 13px;' +
' text-align: center;' +
' border: 1px solid #608eaf;' +
' color: #608eaf;' +
' width: 250px;' +
' border-radius: 3px;' +
' -moz-border-radius: 3px;' +
' -webkit-border-radius: 3px;' +
' box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);' +
'}' +
'.dialog {' +
' display: none;' +
' position: fixed;' +
' z-index: 99999;' +
' right: 30px;' +
' bottom: 30px;' +
' overflow: auto;' +
' width: 335px' +
' height: auto;' +
' font-family: Verdana, Arial, Helvetica, sans-serif;' +
' border: 1px solid #a6c9e2;' +
' background: #fcfdfd url(https://i.imgur.com/zSvngeq.png) 50% bottom repeat-x;' +
' color: #222222;' +
'}' +
'.dialog-titlebar {' +
' border: 1px solid #4297d7;' +
' background: #5c9ccc url(https://i.imgur.com/VKAHB77.png) 50% 50% repeat-x;' +
' color: #ffffff;' +
' font-weight: bold;' +
'}' +
'.dialog, .dialog-titlebar {' +
' -moz-border-radius: 5px;' +
' -webkit-border-radius: 5px;' +
' -khtml-border-radius: 5px;' +
' border-radius: 5px;' +
'}' +
'.dialog, .dialog-titlebar, .dialog-content {' +
' padding: 8px;' +
'}' +
'.dialog-buttonpane {' +
' border: 1px solid #a6c9e2;' +
' background: #fcfdfd url(https://i.imgur.com/44EUC3C.png) 50% bottom repeat-x;' +
' color: #222222;' +
'}' +
'.dialog-buttonpane {' +
' text-align: center;' +
'}' +
'.dialog-button {' +
' cursor: pointer;' +
' outline: none;' +
' border: 1px solid #c5dbec;' +
' background: #dfeffc url(https://i.imgur.com/p3HHEiR.png) 50% 50% repeat-x;' +
' font-weight: bold;' +
' color: #2e6e9e;' +
' margin: 8px;' +
' padding: 8px 15px;' +
'}' +
'.dialog-button:hover {' +
' border: 1px solid #79b7e7;' +
' background: #dfeffc url(https://i.imgur.com/jrnDbA8.png) 50% 50% repeat-x;' +
' font-weight: bold;' +
' color: #1d5987;' +
'}' +
'</style>',
scrollSpeed: 750, // Page scrolling speed up to the editor
typingInterval: 5000, // 5 seconds to save the message
closingInterval: 5000, // 5 seconds to close the modal
content: $.cookie("editor_sm"),
expireTime: 10, // Time to expire the message (set 10 days as standard)
editor: $("#text_editor_textarea").sceditor("instance")
};
// Inserting CSS before page body
$(config.myCSS).insertBefore("body");
// Inserting element modal append to page body
$(config.modal).appendTo("body");
// Check for recycled message
if(config.content) {
// Inserting element dialog append to page body
$(config.dialog).appendTo("body");
config.dialog.show("fast");
$.cookie("editor_sm", null);
}
// Declaring the variables
var typingTimer = null,
date = null,
time = "",
editorVal = null;
// Whyle typing in the editor
config.editor.keyUp(function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(savingMessage, config.typingInterval);
}).keyDown(function() {
clearTimeout(typingTimer);
});
// Recycle function
config.dialog.on("click", ".confirm", function() {
config.editor.val(config.content);
$("body, html").stop().animate({
scrollTop: $("#quick_reply").offset().top;
}, config.scrollSpeed);
config.dialog.hide();
});
// Cancel function
config.dialog.on("click", ".cancel", function() {
config.dialog.hide("slow");
});
// Saving function
function savingMessage() {
date = new Date();
time = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
editorVal = config.editor.val();
if(editorVal != "") {
$.cookie("editor_sm", editorVal, { expires : config.expireTime });
config.modal.show("fast", function() {
config.modal.find(".modal-content").html(lang.savingNotice + ": " + time);
config.modal.delay(config.closingInterval).hide("slow");
});
}
}
});
Last edited by Daemon on Wed 11 Apr - 15:40; edited 6 times in total