From: Lukasz Anwajler Date: Mon, 29 Nov 2010 22:13:23 +0000 (-0600) Subject: Ticket #957: using localStorage for recently used symbols X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/ddb13727d82986ce526a5a62481ed1f808307a96 Ticket #957: using localStorage for recently used symbols --- diff --git a/redakcja/static/css/html.css b/redakcja/static/css/html.css index ffed30e0..9eb4089d 100644 --- a/redakcja/static/css/html.css +++ b/redakcja/static/css/html.css @@ -651,8 +651,15 @@ div[x-node] > .uwaga { color: white; font-weight: bold; } + #tableSpecialChars td input { background-color: transparent; border:0; color: white; } + +#tableSpecialChars td input.recentSymbol { + background-color: white; + border:0; + color: black; +} diff --git a/redakcja/static/js/wiki/view_editor_wysiwyg.js b/redakcja/static/js/wiki/view_editor_wysiwyg.js index 080b5a74..a4dc874c 100644 --- a/redakcja/static/js/wiki/view_editor_wysiwyg.js +++ b/redakcja/static/js/wiki/view_editor_wysiwyg.js @@ -196,6 +196,7 @@ function addSymbol() { if($('div.html-editarea textarea')[0]) { var specialCharsContainer = $("
Zamknij
"); + var specialChars = ['Ą','ą','Ć','ć','Ę','ę','Ł','ł','Ń','ń','Ó','ó','Ś','ś','Ż','ż','Ź','ź','Á','á','À','à', 'Â','â','Ä','ä','Å','å','Ā','ā','Ă','ă','Ã','ã', 'Æ','æ','Ç','ç','Č','č','Ċ','ċ','Ď','ď','É','é','È','è', @@ -230,6 +231,21 @@ tableContent += ""; $("#content").append(specialCharsContainer); + + + // localStorage for recently used characters - reading + if (typeof(localStorage) != 'undefined') { + if (localStorage.getItem("recentSymbols")) { + var recent = localStorage.getItem("recentSymbols"); + var recentArray = recent.split(";"); + var recentRow = ""; + for(var i in recentArray.reverse()) { + recentRow += ""; + } + recentRow = "" + recentRow + ""; + } + } + $("#tableSpecialChars").append(recentRow); $("#tableSpecialChars").append(tableContent); /* events */ @@ -263,6 +279,34 @@ insertAtCaret(editArea, insertVal); } + // localStorage for recently used characters - saving + if (typeof(localStorage) != 'undefined') { + if (localStorage.getItem("recentSymbols")) { + var recent = localStorage.getItem("recentSymbols"); + var recentArray = recent.split(";"); + var valIndex = $.inArray(insertVal, recentArray); + //alert(valIndex); + if(valIndex == -1) { + // value not present in array yet + if(recentArray.length > 13){ + recentArray.shift(); + recentArray.push(insertVal); + } else { + recentArray.push(insertVal); + } + } else { + // value already in the array + for(var i = valIndex; i < recentArray.length; i++){ + recentArray[i] = recentArray[i+1]; + } + recentArray[recentArray.length-1] = insertVal; + } + localStorage.setItem("recentSymbols", recentArray.join(";")); + } else { + localStorage.setItem("recentSymbols", insertVal); + } + } + $(specialCharsContainer).remove(); }); $('#specialCharsClose').click(function(){