Skip to content

Commit

Permalink
prevent browser error when localstorage is full fixes #67
Browse files Browse the repository at this point in the history
  • Loading branch information
w8tcha committed Dec 24, 2016
1 parent 88cf289 commit a618964
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 11 deletions.
1 change: 1 addition & 0 deletions autosave/lang/ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.plugins.setLang('autosave', 'ca', {
loadSavedContent: 'S\'ha trobat una versió auto-desada d\'aquest contingut de "{0}". Voleu comparar les versions del contingut i escollir quina carregar?',
title: 'Compareu el contingut auto-desat amb el contingut carregat del lloc web',
loadedContent: 'Contingut carregat',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: 'Contingut auto-desat de: \'',
ok: 'Sí, carrega el contingut auto-desat',
no: 'No',
Expand Down
1 change: 1 addition & 0 deletions autosave/lang/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.plugins.setLang('autosave', 'cs', {
loadSavedContent: 'byla nalezena automaticky uložená verze obsahu ze dne "{0}". Chcete porovnat obsah a zvolit si s kterým obsahem chete pracovat?',
title: 'Porovnejre automaticky uložený obsah s obsahem nahraným z webové stránky',
loadedContent: 'Nahraný obsah',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: 'Automaticky uložený obsah z: \'',
ok: 'Ano, zvolit automaticky uložený obsah',
no: 'Ne',
Expand Down
1 change: 1 addition & 0 deletions autosave/lang/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.plugins.setLang('autosave', 'de', {
loadSavedContent: 'Es wurde ein autom. Gespeicherter Inhalt gefunden (vom "{0}"). Wollen Sie den Inhalt vergleichen, um dann entscheiden zu können ob der Inhalt geladen werden soll?',
title: 'Temp. Gespeichert Inhalt vergleichen',
loadedContent: 'Geladener Inhalt',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: 'Autom. Gespeicherten Inhalt (vom: \'',
ok: 'Ja, Lade Autom. Gespeicherten Inhalt',
no: 'Nein',
Expand Down
3 changes: 2 additions & 1 deletion autosave/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ CKEDITOR.plugins.setLang('autosave', 'en', {
autoSaveMessage: 'Auto Saved',
loadSavedContent: 'An auto-saved version of this content from "{0}" has been found. Would you like to compare content versions and choose which one to load? Clicking Cancel will remove previously auto-saved content.',
title: 'Compare auto-saved content with that loaded from the website',
loadedContent: 'Loaded content',
loadedContent: 'Loaded content',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: 'Auto-saved content from: \'',
ok: 'Yes, load auto-saved content',
no: 'No',
Expand Down
1 change: 1 addition & 0 deletions autosave/lang/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.plugins.setLang('autosave', 'es', {
loadSavedContent: 'Se ha encontrado una versión auto-guardada de este contenido de "{0}". Queréis comparar el contenido de las versiones y elegir cual cargar?',
title: 'Compara el contenido auto-guardado con el cargado del sitio web',
loadedContent: 'Contenido cargado',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: 'Contenido auto-guardado de: \'',
ok: 'Si, carga el contenido auto-guardado',
no: 'No',
Expand Down
1 change: 1 addition & 0 deletions autosave/lang/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.plugins.setLang('autosave', 'fr', {
loadSavedContent: 'Une précédente version a été sauvegardée le "{0}". Voulez-vous l\'afficher et la comparer avec le document en cours ?',
title: 'Comparaison du document en cours et du document sauvegardé',
loadedContent: 'Document en cours',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: 'Document sauvegardé le : \'',
ok: 'Oui, charger le document sauvegardé',
no: 'Non, continuer avec le document en cours',
Expand Down
1 change: 1 addition & 0 deletions autosave/lang/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.plugins.setLang('autosave', 'ja', {
loadSavedContent: '投稿途中だった内容があります({0})。現在保存されている投稿と比較しますか?',
title: 'Compare auto-saved content with that loaded from the website',
loadedContent: '現在保存されている投稿',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: '投稿途中だった内容: \'',
ok: '投稿途中だった内容(緑)を使う',
no: 'いいえ',
Expand Down
1 change: 1 addition & 0 deletions autosave/lang/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.plugins.setLang('autosave', 'nl', {
loadSavedContent: 'Een automatisch opgeslagen versie van deze inhoud van "{0}" is gevonden. Wilt u de inhoud van deze versies vergelijken en kiezen welke te laden?',
title: 'Vergelijk automatisch opgeslagen inhoud met die geladen van de website',
loadedContent: 'Geladen inhoud',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: 'Automatisch opgeslagen inhoud van: \'',
ok: 'Ja, laadt automatisch opgeslagen inhoud',
no: 'Nee',
Expand Down
1 change: 1 addition & 0 deletions autosave/lang/pl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.plugins.setLang('autosave', 'pl', {
loadSavedContent: 'Istnieje automatycznie zapisana wersja zawartości (z "{0}"). Otworzyć okno porównawcze, w którym można zadecydować o wczytaniu automatycznie zapisanej zawartości?',
title: 'Porównanie tymczasowo zapisanej zawartości z zawartością wczytaną w witrynie',
loadedContent: 'Zawartość wczytania',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: 'Zawartość zapisana automatycznie (z: \'',
ok: 'Tak, wczytaj automatycznie zapisaną treść',
no: 'Nie',
Expand Down
1 change: 1 addition & 0 deletions autosave/lang/pt-br.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.plugins.setLang('autosave', 'pt-br', {
loadSavedContent: 'An auto-saved version of this content from "{0}" has been found. Would you like to compare content versions and choose which one to load?',
title: 'Compare auto-saved content with that loaded from the website',
loadedContent: 'Loaded content',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: 'Auto-saved content from: \'',
ok: 'Yes, load auto-saved content',
no: 'No',
Expand Down
1 change: 1 addition & 0 deletions autosave/lang/sk.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.plugins.setLang('autosave', 'sk', {
loadSavedContent: 'Bola nájdená automaticky uložená verzia z "{0}". Chcete porovnať obsah a vybrať verziu, ktorú chcete použiť?',
title: 'Porovnanie automaticky uloženého obsahu s obsahom nahraným z webu',
loadedContent: 'Nahraný obsah z webu',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: 'Automaticky uložený obsah z: \'',
ok: 'Použiť automaticky uložený obsah',
no: 'Použiť obsah z webu',
Expand Down
4 changes: 3 additions & 1 deletion autosave/lang/sv.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
*/
CKEDITOR.plugins.setLang('autosave', 'sv', {
dateFormat: 'LLL',
autoSaveMessage: 'Autosparat',
autoSaveMessage: 'Auto Saved',
loadSavedContent: 'There is a auto-saved version of this content (From "{0}") found. Do you want to open the Compare Dialog, where you can decide to load the auto saved Content?',
loadSavedContent: 'En auto-sparad version av det här innehållet (från "{0}") hittades. Vill du öppna en dialogruta för att jämföra, där du även kan välja att läsa in det auto sparade innehållet?',
title: 'Jämför Temporärt sparat innehåll med det inladdade innehållet från sidan',
loadedContent: 'Inladdat innehåll',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: 'Autosparat innehåll (från: \'',
ok: 'Läs in Autosparat innehåll',
no: 'Nej tack',
Expand Down
1 change: 1 addition & 0 deletions autosave/lang/zh-cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.plugins.setLang('autosave', 'zh-cn', {
loadSavedContent: '已经存在这个内容之前保存的版本 "{0}". 你希望比较两个不同的版本并从中选择你想要加载的那个么?',
title: '比较自动保存的版本',
loadedContent: '已经加载的内容',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: '自动保存的内容: \'',
ok: '我确认,加载自动保存的内容',
no: '取消',
Expand Down
1 change: 1 addition & 0 deletions autosave/lang/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CKEDITOR.plugins.setLang('autosave', 'zh', {
loadSavedContent: 'An auto-saved version of this content from "{0}" has been found. Would you like to compare content versions and choose which one to load?',
title: 'Compare auto-saved content with that loaded from the website',
loadedContent: 'Loaded content',
localStorageFull: 'Browser localStorage is full, clear your storage or Increase database size',
autoSavedContent: 'Auto-saved content from: \'',
ok: 'Yes, load auto-saved content',
no: 'No',
Expand Down
56 changes: 47 additions & 9 deletions autosave/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,27 +243,42 @@

function SaveData(autoSaveKey, editorInstance, config) {
var compressedJSON = LZString.compressToUTF16(JSON.stringify({ data: editorInstance.getData(), saveTime: new Date() }));
localStorage.setItem(autoSaveKey, compressedJSON);

var messageType = config.messageType != null ? config.messageType : "notification";
var quotaExceeded = false;

if (editorInstance.plugins.textselection && messageType == "statusbar") {
messageType = "notification";
try {
localStorage.setItem(autoSaveKey, compressedJSON);
} catch (e) {
quotaExceeded = isQuotaExceeded(e);
if (quotaExceeded) {
console.log(editorInstance.lang.autosave.localStorageFull);
}
}

if (messageType == "statusbar") {
if (quotaExceeded) {
var notificationError = new CKEDITOR.plugins.notification(editorInstance, { message: editorInstance.lang.autosave.localStorageFull, type: 'warning' });
notificationError.show();
} else {
var messageType = config.messageType != null ? config.messageType : "notification";

if (editorInstance.plugins.textselection && messageType == "statusbar") {
messageType = "notification";
}

if (messageType == "statusbar") {
var autoSaveMessage = document.getElementById(autoSaveMessageId(editorInstance));

if (autoSaveMessage) {
autoSaveMessage.className = "show";

setTimeout(function() {
setTimeout(function () {
autoSaveMessage.className = "hidden";
}, 2000);
}
} else if (messageType == "notification") {
var notification = new CKEDITOR.plugins.notification(editorInstance, { message: editorInstance.lang.autosave.autoSaveMessage, type: 'success' });
notification.show();
} else if (messageType == "notification") {
var notification = new CKEDITOR.plugins.notification(editorInstance, { message: editorInstance.lang.autosave.autoSaveMessage, type: 'success' });
notification.show();
}
}
}

Expand Down Expand Up @@ -293,4 +308,27 @@
viewType: dialog.getContentElement('general', 'diffType').getValue() == "inline" ? 1 : 0
}).outerHTML + '</div>');
}

function isQuotaExceeded(e) {
var quotaExceeded = false;
if (e) {
if (e.code) {
switch (e.code) {
case 22:
quotaExceeded = true;
break;
case 1014:
// Firefox
if (e.name === 'NS_ERROR_DOM_QUOTA_REACHED') {
quotaExceeded = true;
}
break;
}
} else if (e.number === -2147024882) {
// Internet Explorer 8
quotaExceeded = true;
}
}
return quotaExceeded;
}
})();

0 comments on commit a618964

Please sign in to comment.