diff --git a/lib/scripts/spellcheck.js b/lib/scripts/spellcheck.js index feeeb0967a79e82b899d6a9f4e1b9ba08ac97b58..06ba49c0ddb60bd65ce88d1c4e774def0975078d 100644 --- a/lib/scripts/spellcheck.js +++ b/lib/scripts/spellcheck.js @@ -80,6 +80,14 @@ function findPosY(object){ return curtop; } //end findPosY function +/** + * quotes single quotes + * + * @author Andreas Gohr <andi@splitbrain.org> + */ +function qquote(str){ + return str.split('\'').join('\\\''); +} /** * AJAX Spellchecker Class @@ -201,11 +209,53 @@ function ajax_spell_class(){ */ this.correct = function (id, word){ var obj = document.getElementById('spell_error'+id); - obj.innerHTML = decodeURI(word); + obj.innerHTML = decodeURIComponent(word); obj.style.color = "#005500"; this.suggestObj.style.display = "none"; } + /** + * Displays the suggestions for a misspelled word + * + * @author Andreas Gohr <andi@splitbrain.org> + * @author Garrison Locke <http://www.broken-notebook.com> + */ + this.suggest = function(){ + var args = this.suggest.arguments; + if(!args[0]) return; + var id = args[0]; + + // set position of the popup + this.suggestObj.style.display = "none"; + var x = findPosX('spell_error'+id); + var y = findPosY('spell_error'+id); + + // handle scrolling + if(is_opera){ + var scrollPos = 0; //FIXME how to do this without browser sniffing? + }else{ + var scrollPos = this.showboxObj.scrollTop; + } + + this.suggestObj.style.left = x+'px'; + this.suggestObj.style.top = (y+16-scrollPos)+'px'; + + // handle suggestions + var text = ''; + if(args.length == 1){ + text += this.txtNoSug; + }else{ + for(var i=1; i<args.length; i++){ + text += '<a href="javascript:ajax_spell.correct('+id+',\''+ + qquote(encodeURIComponent(args[i]))+'\')">'; + text += args[i]; + text += '</a><br>'; + } + } + + this.suggestObj.innerHTML = text; + this.suggestObj.style.display = "block"; + } // --- Callbacks --- @@ -290,47 +340,6 @@ function ajax_spell_class(){ } } - /** - * Displays the suggestions for a misspelled word - * - * @author Andreas Gohr <andi@splitbrain.org> - * @author Garrison Locke <http://www.broken-notebook.com> - */ - this.suggest = function(){ - var args = this.suggest.arguments; - if(!args[0]) return; - var id = args[0]; - - // set position of the popup - this.suggestObj.style.display = "none"; - var x = findPosX('spell_error'+id); - var y = findPosY('spell_error'+id); - - // handle scrolling - if(is_opera){ - var scrollPos = 0; //FIXME how to do this without browser sniffing? - }else{ - var scrollPos = this.showboxObj.scrollTop; - } - - this.suggestObj.style.left = x+'px'; - this.suggestObj.style.top = (y+16-scrollPos)+'px'; - - // handle suggestions - var text = ''; - if(args.length == 1){ - text += this.txtNoSug; - }else{ - for(var i=1; i<args.length; i++){ - text += '<a href="javascript:ajax_spell.correct('+id+',\''+encodeURIComponent(args[i])+'\')">'; - text += args[i]; - text += '</a><br>'; - } - } - - this.suggestObj.innerHTML = text; - this.suggestObj.style.display = "block"; - } } // create the global object