111 lines
2.7 KiB
HTML
Executable File
111 lines
2.7 KiB
HTML
Executable File
<div id="write">
|
|
<div id="write_feedback"></div>
|
|
<div id="edi_write"></div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
oMyThoughts.pageInit = function(asHash, bFirstPage)
|
|
{
|
|
self.tmp('default_text', "\n");
|
|
self.tmp('keystrokes', 0);
|
|
self.tmp('saving', false);
|
|
|
|
oEditor = new Editor('#edi_write');
|
|
oEditor.onKeyStroke = (e) => {
|
|
if(e.which == 83 && e.ctrlKey) {
|
|
e.preventDefault();
|
|
save(true);
|
|
}
|
|
else save();
|
|
}
|
|
oEditor.moveToPage('last');
|
|
};
|
|
|
|
oMyThoughts.onFeedback = function(sType, sMsg)
|
|
{
|
|
var $Feedback = $('#write_feedback').stop();
|
|
if(sMsg != $Feedback.find('span').text()) {
|
|
$Feedback.fadeOut($Feedback.is(':empty')?0:'fast', function(){
|
|
$(this)
|
|
.empty()
|
|
.append($('<span>', {'class':sType}).text(sMsg))
|
|
.fadeIn('fast');
|
|
});
|
|
}
|
|
};
|
|
|
|
oMyThoughts.onQuitPage = function()
|
|
{
|
|
return save(true);
|
|
};
|
|
|
|
function save(bForce)
|
|
{
|
|
if(typeof oSaveTimer != 'undefined') clearTimeout(oSaveTimer);
|
|
var bSave = (oEditor.keystrokes % 20 == 0 || bForce);
|
|
|
|
if(bSave) {
|
|
if(self.tmp('saving')) {
|
|
oSaveTimer = setTimeout(function(){save(true);}, 500);
|
|
}
|
|
else {
|
|
var sContent = oEditor.getContent();
|
|
if(!oEditor.isEmpty() || oEditor.id != 0) {
|
|
self.tmp('saving', true);
|
|
oMyThoughts.onFeedback('info', 'Saving...');
|
|
getInfo(
|
|
'update',
|
|
function(sDesc, asData) {
|
|
if(oEditor.id == 0) oMyThoughts.updateSideMenu();
|
|
oEditor.id = asData.id;
|
|
oMyThoughts.feedback('notice', 'Thought saved ('+asData.led.substr(11, 5)+')');
|
|
self.tmp('saving', false);
|
|
},
|
|
{
|
|
id: oEditor.id,
|
|
content: sContent
|
|
},
|
|
function(sError) {
|
|
oMyThoughts.feedback('error', 'Not saved! An error occured: '+sError);
|
|
self.tmp('saving', false);
|
|
oSaveTimer = setTimeout(save, 1000);
|
|
},
|
|
'POST'
|
|
);
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
oSaveTimer = setTimeout(function(){save(true);}, 1000*10);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/*function setLastContent(oQuill, fCallback)
|
|
{
|
|
getInfo
|
|
(
|
|
'load',
|
|
function(sDesc, asData)
|
|
{
|
|
if(asData.ops.length != 1 || asData.ops[0].insert != '' && false) {
|
|
var $Date = $('<p>', {'class':'entry_date'}).text(asData.created_f);
|
|
|
|
var $Sep = $('<div>', {'class':'entry_sep'})
|
|
.text('~')
|
|
.click(function(){oQuill.focus();});
|
|
|
|
oQuill.setContents(asData.ops);
|
|
$('#context')
|
|
.append($('#editor .ql-editor').html())
|
|
.append($Date)
|
|
.append($Sep);
|
|
|
|
oQuill.setContents([]);
|
|
}
|
|
else oQuill.focus();
|
|
if(typeof fCallback == 'function') fCallback();
|
|
},
|
|
{id: 'last'}
|
|
);
|
|
}*/
|
|
</script> |