fix autosave

This commit is contained in:
2018-06-17 22:18:07 +02:00
parent 6ee27fda3d
commit d09f0fd49f
11 changed files with 203 additions and 211 deletions

View File

@@ -6,6 +6,7 @@
<link href="style/mythoughts.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="scripts/jquery.mousewheel.min.js"></script>
<script type="text/javascript" src="scripts/quill.min.js"></script>
<script type="text/javascript" src="scripts/functions.js"></script>
<script type="text/javascript" src="scripts/mythoughts.js"></script>

View File

@@ -1,15 +1,15 @@
<div id="write">
<div id="write_feedback"></div>
<div id="nav">
<a class="fal fa-prev"></a>
<span class="page_nb">1</span>
<A class="fal fa-next"></a>
</div>
<div id="editor_container">
<div id="editor_content">
<div id="editor" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></div>
</div>
</div>
<div id="nav">
<div class="nav-elem"><a class="fal fa-fw fa-prev"></a></div>
<div class="nav-elem"><span class="page_nb"></span></div>
<div class="nav-elem"><a class="fal fa-fw fa-next"></a></div>
</div>
</div>
<script type="text/javascript">
oMyThoughts.pageInit = function(asHash, bFirstPage)
@@ -18,6 +18,7 @@
self.vars('default_text', "\n");
self.vars('page', 0);
self.vars('keystrokes', 0);
self.vars('saving', false);
//DOM
self.vars('editor', $('#editor_content'));
@@ -30,32 +31,23 @@
toolbar: [['bold', 'italic', 'underline'], [{ 'list': 'ordered'}, { 'list': 'bullet' }], ['clean']]
}
});
/*oQuill.setContents([
{insert: "So, I'm there, wondering about myself and my future - such a luxury by the way - when suddenly, someone approaches. mid-40s i'd say, elegant cold women, the kind you've learned not to talk to, to eventually avoid feeling repressed, or bad for yourself, or both."},
{insert: '\n'},
{insert: "Anyhow, it would seem that in this particular situation, the choice wasn't given to me to decide whether or not to talk to that precise women. She seats down next to me and engage a conversation. 'How is it you're here today?' I'm already regretting not having gone away when i still had the chance."},
{insert: '\n'},
{insert: "'Hello to you too' I say, still willing to show some manhood, even though I already know this women crushes manhood by pairs as a breakfast ritual."},
{insert: '\n'},
{insert: "In-extremist, I manage to babble some excuses about a rigorous lunch break time and leave the premises."},
{insert: '\n'},
{insert: "So, I'm there, wondering about myself and my future - such a luxury by the way - when suddenly, someone approaches. mid-40s i'd say, elegant cold women, the kind you've learned not to talk to, to eventually avoid feeling repressed, or bad for yourself, or both."},
{insert: '\n'},
{insert: "Anyhow, it would seem that in this particular situation, the choice wasn't given to me to decide whether or not to talk to that precise women. She seats down next to me and engage a conversation. 'How is it you're here today?' I'm already regretting not having gone away when i still had the chance."},
{insert: '\n'},
{insert: "'Hello to you too' I say, still willing to show some manhood, even though I already know this women crushes manhood by pairs as a breakfast ritual."},
{insert: '\n'},
{insert: "In-extremist, I manage to babble some excuses about a rigorous lunch break time and leave the premises."}
]);*/
setLastContent();
setPageHeight();
//Add last thought
setLastContent(oQuill, function(){
setPageHeight();
moveToPage(self.vars('page'));
});
//Key strokes Events
//Key strokes & mouse Events
$('#editor').keydown(function(e){
if($.inArray(e.which, [13, 37, 38, 39, 40]) != -1) onChange('', '', 'user', e);
});
oQuill.on('text-change', onChange);
$(window).mousewheel(function(turn, iDelta) {
var iNewPage = self.vars('page') + ((iDelta > 0)?-1:1);
moveToPage(iNewPage);
return false;
});
//Page buttons
$('.fa-prev').click(function(){moveToPage(self.vars('page')-1);});
@@ -63,7 +55,6 @@
//Init
oQuill.focus();
moveToPage(self.vars('page'));
};
oMyThoughts.onFeedback = function(sType, sMsg)
@@ -87,16 +78,18 @@
function setPageHeight()
{
var $Page = $('#editor_container').css('height', 'calc(100% - 4em)');
var $Page = $('#editor_container');
var iHeight = $Page.height();
var iLineHeight = parseInt($('#editor_container p').css('line-height'));
var iMaxHeight = Math.floor(iHeight / iLineHeight) * iLineHeight;
$Page.height(iMaxHeight);
$Page.height(iMaxHeight+'px');
self.vars('line-height', iLineHeight);
self.vars('page_height', iMaxHeight);
self.vars('page-height', iMaxHeight);
}
function setLastContent(oQuill)
function setLastContent(oQuill, fCallback)
{
getInfo
(
@@ -104,8 +97,8 @@
function(sDesc, asData)
{
self.vars('id', asData.id);
oQuill.setContents(asData.ops);
if(typeof fCallback == 'function') fCallback();
},
{id: 'last'}
);
@@ -119,8 +112,8 @@
if(range)
{
var oSelBound = oQuill.getBounds(range.index, range.length);
var oEditorCurBound = { top: self.vars('page_height') * self.vars('page'),
bottom: self.vars('page_height') * (self.vars('page') + 1)};
var oEditorCurBound = { top: self.vars('page-height') * self.vars('page'),
bottom: self.vars('page-height') * (self.vars('page') + 1)};
//Anticipating arrows
if(e)
@@ -161,25 +154,30 @@
function moveToPage(iNewPage)
{
if(iNewPage!=self.vars('page'))
var iContentHeight = self.vars('editor').height();
var iLastPage = Math.floor(iContentHeight / self.vars('page-height'));
//console.log(iNewPage);
if(iNewPage >= 0 && iNewPage <= iLastPage)
{
var iOldPage = self.vars('page');
self.vars('page', iNewPage);
if(iNewPage!=self.vars('page'))
{
var iOldPage = self.vars('page');
self.vars('page', iNewPage);
//Page Position
var iOffset = self.vars('page') * self.vars('page-height') * -1;
self.vars('editor').css('top', iOffset);
}
//Page Number
$('.page_nb').text(self.vars('page') + 1);
//Page Position
var iOffset = self.vars('page') * self.vars('page_height') * -1;
self.vars('editor').css('top', iOffset);
//Detect First/Last Page
$('.fa-prev').toggle(self.vars('page')!=0);
$('.fa-next').toggle(self.vars('page')!=iLastPage);
}
//Detect First Page
$('.fa-prev').fadeTo('fast', (self.vars('page')==0)?0:1);
//Detect last page
var bLastPage = (self.vars('editor').height() < self.vars('page_height') * (self.vars('page') + 1));
$('.fa-next').fadeTo('fast', bLastPage?0:1);
}
function incKeyStrokes()
@@ -190,28 +188,40 @@
function save()
{
var sContent = oQuill.getContents().ops;
if(sContent[0] != self.vars('default_text'))
{
oMyThoughts.onFeedback('info', 'Saving...');
getInfo
(
'update',
function(sDesc, asData)
{
self.vars('id', asData.id);
oMyThoughts.onFeedback('notice', 'Saved ('+asData.led.substr(11, 5)+')');
},
{
id: self.vars('id'),
content: sContent
},
function(sError)
{
oMyThoughts.onFeedback('error', 'Not saved! An error occured: '+sError);
},
'POST'
);
if(typeof oSaveTimer != 'undefined') clearTimeout(oSaveTimer);
if(!self.vars('saving') && self.vars('keystrokes') != self.vars('lastKeystrokes')) {
self.vars('saving', true);
var iCurrentKeystrokes = self.vars('keystrokes');
var sContent = oQuill.getContents().ops;
if(sContent[0] != self.vars('default_text'))
{
oMyThoughts.onFeedback('info', 'Saving...');
getInfo
(
'update',
function(sDesc, asData)
{
self.vars('id', asData.id);
oMyThoughts.feedback('notice', 'Saved ('+asData.led.substr(11, 5)+')');
self.vars('saving', false);
self.vars('lastKeystrokes', iCurrentKeystrokes);
oSaveTimer = setTimeout(save, 1000*10);
},
{
id: self.vars('id'),
content: sContent
},
function(sError)
{
oMyThoughts.feedback('error', 'Not saved! An error occured: '+sError);
self.vars('saving', false);
oSaveTimer = setTimeout(save, 1000);
},
'POST'
);
}
}
}
</script>

8
scripts/jquery.mousewheel.min.js vendored Normal file
View File

@@ -0,0 +1,8 @@
/*!
* jQuery Mousewheel 3.1.13
*
* Copyright 2015 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a:a(jQuery)}(function(a){function b(b){var g=b||window.event,h=i.call(arguments,1),j=0,l=0,m=0,n=0,o=0,p=0;if(b=a.event.fix(g),b.type="mousewheel","detail"in g&&(m=-1*g.detail),"wheelDelta"in g&&(m=g.wheelDelta),"wheelDeltaY"in g&&(m=g.wheelDeltaY),"wheelDeltaX"in g&&(l=-1*g.wheelDeltaX),"axis"in g&&g.axis===g.HORIZONTAL_AXIS&&(l=-1*m,m=0),j=0===m?l:m,"deltaY"in g&&(m=-1*g.deltaY,j=m),"deltaX"in g&&(l=g.deltaX,0===m&&(j=-1*l)),0!==m||0!==l){if(1===g.deltaMode){var q=a.data(this,"mousewheel-line-height");j*=q,m*=q,l*=q}else if(2===g.deltaMode){var r=a.data(this,"mousewheel-page-height");j*=r,m*=r,l*=r}if(n=Math.max(Math.abs(m),Math.abs(l)),(!f||f>n)&&(f=n,d(g,n)&&(f/=40)),d(g,n)&&(j/=40,l/=40,m/=40),j=Math[j>=1?"floor":"ceil"](j/f),l=Math[l>=1?"floor":"ceil"](l/f),m=Math[m>=1?"floor":"ceil"](m/f),k.settings.normalizeOffset&&this.getBoundingClientRect){var s=this.getBoundingClientRect();o=b.clientX-s.left,p=b.clientY-s.top}return b.deltaX=l,b.deltaY=m,b.deltaFactor=f,b.offsetX=o,b.offsetY=p,b.deltaMode=0,h.unshift(b,j,l,m),e&&clearTimeout(e),e=setTimeout(c,200),(a.event.dispatch||a.event.handle).apply(this,h)}}function c(){f=null}function d(a,b){return k.settings.adjustOldDeltas&&"mousewheel"===a.type&&b%120===0}var e,f,g=["wheel","mousewheel","DOMMouseScroll","MozMousePixelScroll"],h="onwheel"in document||document.documentMode>=9?["wheel"]:["mousewheel","DomMouseScroll","MozMousePixelScroll"],i=Array.prototype.slice;if(a.event.fixHooks)for(var j=g.length;j;)a.event.fixHooks[g[--j]]=a.event.mouseHooks;var k=a.event.special.mousewheel={version:"3.1.12",setup:function(){if(this.addEventListener)for(var c=h.length;c;)this.addEventListener(h[--c],b,!1);else this.onmousewheel=b;a.data(this,"mousewheel-line-height",k.getLineHeight(this)),a.data(this,"mousewheel-page-height",k.getPageHeight(this))},teardown:function(){if(this.removeEventListener)for(var c=h.length;c;)this.removeEventListener(h[--c],b,!1);else this.onmousewheel=null;a.removeData(this,"mousewheel-line-height"),a.removeData(this,"mousewheel-page-height")},getLineHeight:function(b){var c=a(b),d=c["offsetParent"in a.fn?"offsetParent":"parent"]();return d.length||(d=a("body")),parseInt(d.css("fontSize"),10)||parseInt(c.css("fontSize"),10)||16},getPageHeight:function(b){return a(b).height()},settings:{adjustOldDeltas:!0,normalizeOffset:!0}};a.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}})});

View File

@@ -80,6 +80,10 @@ function MyThoughts(asGlobals)
self.onFeedback = function(sType, sMsg){Tools.feedback(sType, sMsg, self.elem.$Container);};
};
this.feedback = function(sType, sMsg) {
self.onFeedback(sType, sMsg);
};
/* Hash Handling */
this.getHash = function()
@@ -130,9 +134,6 @@ function MyThoughts(asGlobals)
/* Page Switching */
this.loadHome = function(asData) {
console.log(asData);
self.vars('log_in', asData.log_in);
self.vars('id', asData.id);
@@ -218,10 +219,9 @@ function MyThoughts(asGlobals)
//Page Bootstrap
self.elem.$Main.removeClass('no_frame');
self.pageInit(asHash, bFirstPage);
//Show main
$FadeInElem.fadeTo('fast', 1, function(){});
$FadeInElem.fadeTo('fast', 1, function(){self.pageInit(asHash, bFirstPage);});
};
/* Variables Handling */

View File

@@ -2,15 +2,15 @@ $gray-100: lighten($col_main_1, 80%); //
$gray-200: lighten($col_main_1, 65%); //
$gray-300: lighten($col_main_1, 50%); //
$gray-400: lighten($col_main_1, 35%); //#c09b71
$gray-500: lighten($col_main_1, 20%); //
$gray-500: lighten($col_main_1, 20%); //#9f7546
$gray-600: lighten($col_main_1, 10%); //
$gray-700: $col_main_1;
$gray-800: darken($col_main_1, 10%); //
$gray-900: darken($col_main_1, 20%); //
$theme-colors: (
"primary": $col_main_1, //Irish Coffee
"secondary": #355078,
"primary": $col_main_1,
"secondary": $col_main_2,
"grey-400": $gray-400
);

View File

@@ -6,13 +6,13 @@ body {
font-size:1em;
background-color:#e2ccb2;
margin:0;
color:#584127;
color:$col_main_1;
}
/* Typography */
a:visited, a {
color:#584127;
color:$col_main_1;
text-decoration: none;
font-weight: bold;
}
@@ -57,7 +57,7 @@ a.button {
font-size: 1.1em;
text-align:center;
background: url("../images/minicloud.png") 0 0 no-repeat;
color: $col_main_2;
color: $gray-600;
}
a.button:hover {
color:white;
@@ -116,14 +116,14 @@ a.button:active {
margin-top:1em;
position: absolute;
top:203px;
bottom:2em;
bottom: 2rem;
right:0;
left:0;
border-radius: 0.5em;
padding: 1em;
&:not(.no_frame) {
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
@extend .shadow;
}
}
@@ -229,13 +229,19 @@ fieldset p {
footer {
position: absolute;
bottom: 0;
text-align:center;
text-align: center;
color: $gray-400;
font-size:0.9em;
width:100%;
height:2em;
}
font-size: 0.9em;
width: 100%;
height: 2rem;
footer a {
color: $gray-500;
span {
transform: translateY(-50%);
position: relative;
top: 50%;
a {
color: $gray-500;
}
}
}

View File

@@ -7,9 +7,7 @@ blue lines : #2DCDFF
red lines : #EC3B45
*/
$col_main_1: #584127;
$col_main_2: #735533;
$col_main_3: #ede0d0;
$col_main_4: #f7f2eb;
$col_main_1: #584127; //Primary
$col_main_2: #355078; //Complementary to Primary
$font_para: 'Quicksand';

View File

@@ -1,10 +1,12 @@
#write {
position: relative;
height:100%;
#editor_container {
/* Write - Editor */
height: calc(100% - 4em);
#editor_container {
height: calc(100% - 2em);
overflow: hidden;
position: relative;
@@ -14,100 +16,67 @@
position: relative;
.ql-container {
font-family: 'Indie Flower', cursive;
font-size: 16px;
font-family: $font_para;
font-size: 14px;
padding:0;
.ql-editor {
padding:0;
}
}
}
.shade {
position: absolute;
width: 100%;
background:red;
#editor {
div {
margin:0;
}
&.top {
top:0;
}
&.bottom {
bottom:0;
}
&.bottomplus {
top:100%;
height:2em;
p {
text-indent: 1.5em;
margin: 0;
padding: 0;
text-align: justify;
line-height: 1.5em;
}
}
}
}
}
/* Write - Editor */
#write #editor div {
margin:0;
}
#write #editor p {
text-indent: 1.5em;
margin: 0;
padding: 0;
text-align: justify;
line-height: 1.5em;
}
/* Write - Toolbar */
#write #nav {
position:absolute;
bottom:0;
right:0;
left:0;
text-align: center;
}
#write .fa-prev, #write .page_nb, #write .fa-next {
color:#997E60;
font-size:1.5em;
margin:0 0 0.5em 0;
cursor:pointer;
}
#write .page_nb {
font-size: 1em;
vertical-align:0.25em;
cursor: default;
padding-left:0.5em;
padding-right:0.5em;
}
#write .fa-prev:hover, #write .fa-next:hover {
color:#584127;
}
#write .fa-prev.disabled, #write .fa-next.disabled,
#write .fa-prev.disabled:hover, #write .fa-next.disabled:hover {
color:#EDE0D0;
}
/* Write - Placeholder */
#write .jqte_placeholder_text {
top:1em;
left:0;
text-indent: 1.5em;
}
#write .jqte_focused .jqte_placeholder_text {
display:none;
}
/* Write - Feedback */
#write_feedback {
position:absolute;
top: -1.5em;
right:0.5em;
/* Write - Navbar */
#nav {
position:absolute;
bottom:0;
right:0;
left:0;
text-align: center;
.nav-elem {
color: $gray-500;
width: 1.25em;
display: inline-block;
text-align: center;
}
.fa-prev, .fa-next {
cursor: pointer;
display: none;
&:hover {
color: $gray-700;
}
}
}
/* Write - Feedback */
#write_feedback {
position:absolute;
top: -2.5rem;
right: -1rem;
font-size: 0.8em;
.notice {
color: $gray-400;
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -5,7 +5,7 @@
/* Fonts */
@import 'font-awesome';
@import url('https://fonts.googleapis.com/css?family=Nunito|Quicksand|Fira+Sans');
@import url('https://fonts.googleapis.com/css?family=Nunito|Quicksand|Fira+Sans|Montserrat');
/* Plugins */