bugfix
[redakcja.git] / redakcja / static / js / wiki / view_editor_wysiwyg.js
index 080b5a7..a3f4278 100644 (file)
     function addSymbol() {
         if($('div.html-editarea textarea')[0]) {
             var specialCharsContainer = $("<div id='specialCharsContainer'><a href='#' id='specialCharsClose'>Zamknij</a><table id='tableSpecialChars' style='width: 600px;'></table></div>");
     function addSymbol() {
         if($('div.html-editarea textarea')[0]) {
             var specialCharsContainer = $("<div id='specialCharsContainer'><a href='#' id='specialCharsClose'>Zamknij</a><table id='tableSpecialChars' style='width: 600px;'></table></div>");
+                        
             var specialChars = ['Ą','ą','Ć','ć','Ę','ę','Ł','ł','Ń','ń','Ó','ó','Ś','ś','Ż','ż','Ź','ź','Á','á','À','à',
             'Â','â','Ä','ä','Å','å','Ā','ā','Ă','ă','Ã','ã',
             'Æ','æ','Ç','ç','Č','č','Ċ','ċ','Ď','ď','É','é','È','è',
             var specialChars = ['Ą','ą','Ć','ć','Ę','ę','Ł','ł','Ń','ń','Ó','ó','Ś','ś','Ż','ż','Ź','ź','Á','á','À','à',
             'Â','â','Ä','ä','Å','å','Ā','ā','Ă','ă','Ã','ã',
             'Æ','æ','Ç','ç','Č','č','Ċ','ċ','Ď','ď','É','é','È','è',
             'Τ','τ','Υ','υ','Φ','φ','Χ','χ','Ψ','ψ','Ω','ω','–',
             '—','¡','¿','$','¢','£','€','©','®','°','¹','²','³',
             '¼','½','¾','†','§','‰','•','←','↑','→','↓',
             'Τ','τ','Υ','υ','Φ','φ','Χ','χ','Ψ','ψ','Ω','ω','–',
             '—','¡','¿','$','¢','£','€','©','®','°','¹','²','³',
             '¼','½','¾','†','§','‰','•','←','↑','→','↓',
-            '„','”','„”','«','»','«»','’','[',']','~','|','−','·',
+            '„','”','„”','«','»','«»','»«','’','[',']','~','|','−','·',
             '×','÷','≈','≠','±','≤','≥','∈'];
             var tableContent = "<tr>";
             
             '×','÷','≈','≠','±','≤','≥','∈'];
             var tableContent = "<tr>";
             
             
             tableContent += "</tr>";                                   
             $("#content").append(specialCharsContainer);
             
             tableContent += "</tr>";                                   
             $("#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 += "<td><input type='button' class='specialBtn recentSymbol' value='"+recentArray[i]+"'/></td>";              
+                     }
+                     recentRow = "<tr>" + recentRow + "</tr>";                              
+                 }
+             }            
+            $("#tableSpecialChars").append(recentRow);
             $("#tableSpecialChars").append(tableContent);
             
             /* events */
             $("#tableSpecialChars").append(tableContent);
             
             /* events */
                 // if we want to surround text with quotes
                 // not sure if just check if value has length == 2
                 
                 // if we want to surround text with quotes
                 // not sure if just check if value has length == 2
                 
-                if(insertVal == '„”' || insertVal == '«»'){
+                if (insertVal.length == 2) {
                     var startTag = insertVal[0];
                     var endTag = insertVal[1];
                                var textAreaOpened = editArea;                                                  
                     var startTag = insertVal[0];
                     var endTag = insertVal[1];
                                var textAreaOpened = editArea;                                                  
                     insertAtCaret(editArea, insertVal);
                 }
                 
                     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(){
                 $(specialCharsContainer).remove();
             });         
             $('#specialCharsClose').click(function(){
                         }
                     })
                     
                         }
                     })
                     
-                    var msg = $("<div class='saveNotify'><p>Twoje zmiany zostały naniesione na tekst źródłowy. Pamiętaj, że aby zmiany zostały utrwalone <span>należy je zapisać</span>!</p><p class='notifyTip'>Ta wiadomość zostanie automatycznie zamknięta za 6 sekund.</p></div>");
+                    var msg = $("<div class='saveNotify'><p>Pamiętaj, żeby zapisać swoje zmiany.</p></div>");
                     $("#base").prepend(msg);
                     $("#base").prepend(msg);
-                    $("#save-button").css({border: '2px solid #801000', backgroundColor: '#E1C1C1'});
-                    $('#base .saveNotify').fadeOut(7000, function(){
+                    $('#base .saveNotify').fadeOut(3000, function(){
                         $(this).remove(); 
                         $(this).remove(); 
-                        $("#save-button").css({border: '1px solid black'});
                     });
                 }
 
                     });
                 }