1
0

indexedDB feature test for autocache in editors.

References 
This commit is contained in:
Matthias Mees
2014-06-17 11:31:38 +02:00
parent f06da2f6ac
commit 6bd322e195
3 changed files with 63 additions and 57 deletions

@ -95,7 +95,7 @@ function errorHandlerCreateDOM(htmlStr) {
case 'backend_save':
case 'backend_publish':
echo '<script>$(document).ready(function() { serendipity.eraseEntryEditorCache(); });</script>';
echo '<script>$(document).ready(function() { if(Modernizr.indexeddb) { serendipity.eraseEntryEditorCache(); } });</script>';
return true;
break;

@ -661,64 +661,66 @@
}
}
serendipity.startEntryEditorCache = function() {
if ($('textarea[name="serendipity[body]"]').val() == "") {
serendipity.getCached("serendipity[body]", function(res) {
if (res && res != null && res != "null") {
$('textarea[name="serendipity[body]"]').text(res);
}
});
serendipity.getCached("serendipity[extended]", function(res) {
if (res && res != null && res != "null") {
if ($('textarea[name="serendipity[extended]"]').val() == "") {
$('textarea[name="serendipity[extended]"]').text(res);
if (! $('textarea[name="serendipity[extended]"]').is(':visible')) {
serendipity.toggle_extended();
if(Modernizr.indexeddb) {
serendipity.startEntryEditorCache = function() {
if ($('textarea[name="serendipity[body]"]').val() == "") {
serendipity.getCached("serendipity[body]", function(res) {
if (res && res != null && res != "null") {
$('textarea[name="serendipity[body]"]').text(res);
}
});
serendipity.getCached("serendipity[extended]", function(res) {
if (res && res != null && res != "null") {
if ($('textarea[name="serendipity[extended]"]').val() == "") {
$('textarea[name="serendipity[extended]"]').text(res);
if (! $('textarea[name="serendipity[extended]"]').is(':visible')) {
serendipity.toggle_extended();
}
}
}
}
});
}
$('textarea[name="serendipity[body]"]').one('keyup', function() {
setInterval(function() {
serendipity.cache("serendipity[body]", $('textarea[name="serendipity[body]"]').val())
}, 5000);
});
$('textarea[name="serendipity[extended]"]').one('keyup', function() {
setInterval(function() {
serendipity.cache("serendipity[extended]", $('textarea[name="serendipity[extended]"]').val());
}, 5000);
});
}
$('textarea[name="serendipity[body]"]').one('keyup', function() {
setInterval(function() {
serendipity.cache("serendipity[body]", $('textarea[name="serendipity[body]"]').val())
}, 5000);
});
$('textarea[name="serendipity[extended]"]').one('keyup', function() {
setInterval(function() {
serendipity.cache("serendipity[extended]", $('textarea[name="serendipity[extended]"]').val());
}, 5000);
});
}
serendipity.eraseEntryEditorCache = function() {
serendipity.cache("serendipity[body]", null);
serendipity.cache("serendipity[extended]", null);;
}
serendipity.eraseEntryEditorCache = function() {
serendipity.cache("serendipity[body]", null);
serendipity.cache("serendipity[extended]", null);;
}
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
serendipity.cache = function (id, data) {
var request = indexedDB.open("cache", 1);
request.onupgradeneeded = function (event) {
event.target.result.createObjectStore("cache");
};
request.onsuccess = function(event) {
event.target.result.transaction(["cache"], 'readwrite').objectStore("cache").put(data, id);
};
}
serendipity.getCached = function(id, success) {
var request = indexedDB.open("cache", 1);
request.onupgradeneeded = function (event) {
event.target.result.createObjectStore("cache");
};
request.onsuccess = function(event) {
event.target.result.transaction(["cache"], 'readwrite').objectStore("cache").get(id).onsuccess = function (event) {
success(event.target.result);
serendipity.cache = function (id, data) {
var request = indexedDB.open("cache", 1);
request.onupgradeneeded = function (event) {
event.target.result.createObjectStore("cache");
};
};
request.onsuccess = function(event) {
event.target.result.transaction(["cache"], 'readwrite').objectStore("cache").put(data, id);
};
}
serendipity.getCached = function(id, success) {
var request = indexedDB.open("cache", 1);
request.onupgradeneeded = function (event) {
event.target.result.createObjectStore("cache");
};
request.onsuccess = function(event) {
event.target.result.transaction(["cache"], 'readwrite').objectStore("cache").get(id).onsuccess = function (event) {
success(event.target.result);
};
};
}
}
serendipity.toggle_collapsible = function(toggler, target, stateClass, stateIcon, stateOpen, stateClosed) {
@ -1006,7 +1008,9 @@ $(function() {
if(!Modernizr.inputtypes.date) {
$('#serendipityNewTimestamp').val($('#serendipityNewTimestamp').val().replace("T", " "));
}
serendipity.startEntryEditorCache();
if(Modernizr.indexeddb) {
serendipity.startEntryEditorCache();
}
}
// Set entry timestamp

@ -48,11 +48,13 @@
on: {
instanceReady: function( evt ) {
CKEDITOR.instances["{$item}"].document.once('keyup', function() {
setInterval(function() {
serendipity.cache("{$item}", CKEDITOR.instances["{$item}"].getData());
}, 5000)
});
if(Modernizr.indexeddb) {
CKEDITOR.instances["{$item}"].document.once('keyup', function() {
setInterval(function() {
serendipity.cache("{$item}", CKEDITOR.instances["{$item}"].getData());
}, 5000)
});
}
}
},