fix auto save
This commit is contained in:
@@ -48,9 +48,9 @@
|
|||||||
oSaveTimer = setTimeout(function(){save(true);}, 500);
|
oSaveTimer = setTimeout(function(){save(true);}, 500);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.tmp('saving', true);
|
|
||||||
var sContent = oEditor.getContent();
|
var sContent = oEditor.getContent();
|
||||||
if(!oEditor.isEmpty() || oEditor.id != 0) {
|
if(!oEditor.isEmpty() || oEditor.id != 0) {
|
||||||
|
self.tmp('saving', true);
|
||||||
oMyThoughts.onFeedback('info', 'Saving...');
|
oMyThoughts.onFeedback('info', 'Saving...');
|
||||||
getInfo(
|
getInfo(
|
||||||
'update',
|
'update',
|
||||||
|
|||||||
@@ -290,13 +290,18 @@ function MyThoughts(asGlobals)
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class ThoughtDate extends Quill.import('blots/inline') {
|
//Date format
|
||||||
|
const Inline = Quill.import('blots/inline');
|
||||||
|
class ThoughtDate extends Inline {
|
||||||
static create(value) {
|
static create(value) {
|
||||||
let node = super.create();
|
let node = super.create();
|
||||||
node.setAttribute('class', 'edi_header');
|
node.setAttribute('class', 'edi_header');
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ThoughtDate.blotName = 'thought_date';
|
||||||
|
ThoughtDate.tagName = 'div';
|
||||||
|
Quill.register(ThoughtDate);
|
||||||
|
|
||||||
class Editor {
|
class Editor {
|
||||||
constructor(sContainerId, bReadOnly) {
|
constructor(sContainerId, bReadOnly) {
|
||||||
@@ -305,6 +310,7 @@ class Editor {
|
|||||||
this.keystrokes = 0;
|
this.keystrokes = 0;
|
||||||
this.line = false;
|
this.line = false;
|
||||||
this.readOnly = bReadOnly || false;
|
this.readOnly = bReadOnly || false;
|
||||||
|
this.sCursorPos = '';
|
||||||
|
|
||||||
//DOM Elements
|
//DOM Elements
|
||||||
var sEditorId = 'edi'+Math.floor(Math.random() * 1000);
|
var sEditorId = 'edi'+Math.floor(Math.random() * 1000);
|
||||||
@@ -317,11 +323,6 @@ class Editor {
|
|||||||
|
|
||||||
this.onKeyStroke = function(e){};
|
this.onKeyStroke = function(e){};
|
||||||
|
|
||||||
//Date format
|
|
||||||
ThoughtDate.blotName = 'thought_date';
|
|
||||||
ThoughtDate.tagName = 'div';
|
|
||||||
Quill.register(ThoughtDate);
|
|
||||||
|
|
||||||
this.oQuill = new Quill('#'+sEditorId, {
|
this.oQuill = new Quill('#'+sEditorId, {
|
||||||
theme: 'bubble',
|
theme: 'bubble',
|
||||||
placeholder: 'What\'s on your mind?',
|
placeholder: 'What\'s on your mind?',
|
||||||
@@ -331,7 +332,12 @@ class Editor {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//Key strokes & mouse Events
|
this._initEvents();
|
||||||
|
this._postInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
_initEvents() {
|
||||||
|
//Key strokes
|
||||||
this.$Editor.keydown((e) => {
|
this.$Editor.keydown((e) => {
|
||||||
if($.inArray(e.which, [13, 37, 38, 39, 40]) != -1) this._onChange('', '', 'user', e);
|
if($.inArray(e.which, [13, 37, 38, 39, 40]) != -1) this._onChange('', '', 'user', e);
|
||||||
else if(e.which==33) this.$PrevBtn.click();
|
else if(e.which==33) this.$PrevBtn.click();
|
||||||
@@ -339,8 +345,10 @@ class Editor {
|
|||||||
else this.onKeyStroke(e);
|
else this.onKeyStroke(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//On text modification
|
||||||
this.oQuill.on('text-change', (delta, oldDelta, sSource) => {this._onChange(delta, oldDelta, sSource);});
|
this.oQuill.on('text-change', (delta, oldDelta, sSource) => {this._onChange(delta, oldDelta, sSource);});
|
||||||
|
|
||||||
|
//Mouse wheel events
|
||||||
$(window).mousewheel((turn, iDelta) => {
|
$(window).mousewheel((turn, iDelta) => {
|
||||||
var iNewPage = this.page + ((iDelta > 0)?-1:1);
|
var iNewPage = this.page + ((iDelta > 0)?-1:1);
|
||||||
this.moveToPage(iNewPage);
|
this.moveToPage(iNewPage);
|
||||||
@@ -350,8 +358,13 @@ class Editor {
|
|||||||
//Page buttons
|
//Page buttons
|
||||||
this.$PrevBtn.click(() => {this.moveToPage(this.page - 1);});
|
this.$PrevBtn.click(() => {this.moveToPage(this.page - 1);});
|
||||||
this.$NextBtn.click(() => {this.moveToPage(this.page + 1);});
|
this.$NextBtn.click(() => {this.moveToPage(this.page + 1);});
|
||||||
|
}
|
||||||
|
|
||||||
this._postInit();
|
_postInit(iPage) {
|
||||||
|
iPage = iPage || 0;
|
||||||
|
this._setPageHeight();
|
||||||
|
this.moveToPage(iPage);
|
||||||
|
if(!this.readOnly) this.oQuill.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
setHeader(sHeader) {
|
setHeader(sHeader) {
|
||||||
@@ -385,20 +398,12 @@ class Editor {
|
|||||||
this.pageHeight = iMaxHeight;
|
this.pageHeight = iMaxHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
_postInit(iPage) {
|
|
||||||
iPage = iPage || 0;
|
|
||||||
this._setPageHeight();
|
|
||||||
this.moveToPage(iPage);
|
|
||||||
if(!this.readOnly) this.oQuill.focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
_onChange(delta, oldDelta, sSource, e) {
|
_onChange(delta, oldDelta, sSource, e) {
|
||||||
if(sSource == 'user')
|
if(sSource == 'user')
|
||||||
{
|
{
|
||||||
var range = this.oQuill.getSelection();
|
var range = this.oQuill.getSelection();
|
||||||
if(range)
|
if(range)
|
||||||
{
|
{
|
||||||
//sCursorPos = '';
|
|
||||||
var bSelection = (typeof e != 'undefined')?e.shiftKey:false;
|
var bSelection = (typeof e != 'undefined')?e.shiftKey:false;
|
||||||
var oSelBound = this.oQuill.getBounds(range.index, range.length);
|
var oSelBound = this.oQuill.getBounds(range.index, range.length);
|
||||||
|
|
||||||
@@ -425,8 +430,8 @@ class Editor {
|
|||||||
case 13: //Enter
|
case 13: //Enter
|
||||||
case 40: //Down
|
case 40: //Down
|
||||||
if(bSelection) {
|
if(bSelection) {
|
||||||
if(bReset) sCursorPos = 'last';
|
if(bReset) this.sCursorPos = 'last';
|
||||||
if(sCursorPos == 'last') { //Downwards selection, expanding
|
if(this.sCursorPos == 'last') { //Downwards selection, expanding
|
||||||
oSelBound.bottom += this.lineHeight;
|
oSelBound.bottom += this.lineHeight;
|
||||||
}
|
}
|
||||||
else { //Upwards selection, reducing
|
else { //Upwards selection, reducing
|
||||||
@@ -437,8 +442,8 @@ class Editor {
|
|||||||
break;
|
break;
|
||||||
case 38: //Up
|
case 38: //Up
|
||||||
if(bSelection) {
|
if(bSelection) {
|
||||||
if(bReset) sCursorPos = 'first';
|
if(bReset) this.sCursorPos = 'first';
|
||||||
if(sCursorPos == 'last') { //Downwards selection, reducing
|
if(this.sCursorPos == 'last') { //Downwards selection, reducing
|
||||||
oSelBound.bottom -= this.lineHeight;
|
oSelBound.bottom -= this.lineHeight;
|
||||||
}
|
}
|
||||||
else { //Upwards selection, expanding
|
else { //Upwards selection, expanding
|
||||||
@@ -448,11 +453,11 @@ class Editor {
|
|||||||
else oSelBound.top = Math.max(0, oSelBound.top - this.lineHeight);
|
else oSelBound.top = Math.max(0, oSelBound.top - this.lineHeight);
|
||||||
break;
|
break;
|
||||||
case 37: //Left
|
case 37: //Left
|
||||||
if(bReset && bSelection) sCursorPos = 'first';
|
if(bReset && bSelection) this.sCursorPos = 'first';
|
||||||
oSelBound = this.oQuill.getBounds(Math.max(0, range.index - 1), range.length);
|
oSelBound = this.oQuill.getBounds(Math.max(0, range.index - 1), range.length);
|
||||||
break;
|
break;
|
||||||
case 39: //Right
|
case 39: //Right
|
||||||
if(bReset && bSelection) sCursorPos = 'last';
|
if(bReset && bSelection) this.sCursorPos = 'last';
|
||||||
oSelBound = this.oQuill.getBounds(range.index + 1, range.length);
|
oSelBound = this.oQuill.getBounds(range.index + 1, range.length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -462,12 +467,12 @@ class Editor {
|
|||||||
//console.log('oSelBound: top='+oSelBound.top+' bottom='+oSelBound.bottom);
|
//console.log('oSelBound: top='+oSelBound.top+' bottom='+oSelBound.bottom);
|
||||||
|
|
||||||
var sNewPage = this.page;
|
var sNewPage = this.page;
|
||||||
if( oSelBound.top < oEditorCurBound.top && (!bSelection || sCursorPos == 'first') ||
|
if( oSelBound.top < oEditorCurBound.top && (!bSelection || this.sCursorPos == 'first') ||
|
||||||
oSelBound.bottom < oEditorCurBound.top && (!bSelection || sCursorPos == 'last')) {
|
oSelBound.bottom < oEditorCurBound.top && (!bSelection || this.sCursorPos == 'last')) {
|
||||||
sNewPage--;
|
sNewPage--;
|
||||||
}
|
}
|
||||||
else if(oSelBound.bottom > oEditorCurBound.bottom && (!bSelection || sCursorPos == 'last') ||
|
else if(oSelBound.bottom > oEditorCurBound.bottom && (!bSelection || this.sCursorPos == 'last') ||
|
||||||
oSelBound.top > oEditorCurBound.bottom && (!bSelection || sCursorPos == 'first')) {
|
oSelBound.top > oEditorCurBound.bottom && (!bSelection || this.sCursorPos == 'first')) {
|
||||||
sNewPage++;
|
sNewPage++;
|
||||||
}
|
}
|
||||||
this.moveToPage(sNewPage);
|
this.moveToPage(sNewPage);
|
||||||
|
|||||||
Reference in New Issue
Block a user