--- loncom/html/adm/spellcheck/js/jquery.spellchecker.min.js 2012/09/04 10:44:13 1.2 +++ loncom/html/adm/spellcheck/js/jquery.spellchecker.min.js 2012/09/24 10:31:45 1.3 @@ -1,5 +1,6 @@ -(function($){$.fn.extend({spellchecker:function(options,callback){return this.each(function(){var obj=$(this).data('spellchecker');if(obj&&String===options.constructor&&obj[options]){obj[options](callback);}else if(obj){obj.init();}else{$(this).data('spellchecker',new SpellChecker(this,(Object===options.constructor?options:null)));(String===options.constructor)&&$(this).data('spellchecker')[options](callback);}});}});var SpellChecker=function(domObj,options){this.options=$.extend({url:'checkspelling.php',lang:'en',engine:'pspell',addToDictionary:false,wordlist:{action:'after',element:domObj},suggestBoxPosition:'below',innerDocument:false},options||{});this.$domObj=$(domObj);this.elements={};this.init();};SpellChecker.prototype={init:function(){var self=this;this.createElements();this.$domObj.addClass('spellcheck-container');$(document).bind('click',function(e){(!$(e.target).hasClass('spellcheck-word-highlight')&&!$(e.target).parents().filter('.spellcheck-suggestbox').length)&&self.hideBox();});},check:function(callback){var self=this,node=this.$domObj.get(0).nodeName,tagExp='<[^>]+>',puncExp='^[^a-zA-Z\\u00A1-\\uFFFF]|[^a-zA-Z\\u00A1-\\uFFFF]+[^a-zA-Z\\u00A1-\\uFFFF]|[^a-zA-Z\\u00A1-\\uFFFF]$|\\n|\\t|\\s{2,}';if(node=='TEXTAREA'||node=='INPUT'){this.type='textarea';var text=$.trim(this.$domObj.val().replace(new RegExp(tagExp,'g'),'').replace(new RegExp(puncExp,'g'),' '));}else{this.type='html';var text=$.trim(this.$domObj.text().replace(new RegExp(puncExp,'g')," "));} +(function($){$.fn.extend({spellchecker:function(options,callback){return this.each(function(){var obj=$(this).data('spellchecker');if(obj&&String===options.constructor&&obj[options]){obj[options](callback);}else if(obj){obj.init();}else{$(this).data('spellchecker',new SpellChecker(this,(Object===options.constructor?options:null)));(String===options.constructor)&&$(this).data('spellchecker')[options](callback);}});}});var SpellChecker=function(domObj,options){this.options=$.extend({url:'checkspelling.php',lang:'en',engine:'pspell',addToDictionary:false,wordlist:{action:'after',element:domObj},suggestBoxPosition:'below',innerDocument:false},options||{});this.$domObj=$(domObj);this.elements={};this.init();};SpellChecker.prototype={init:function(){var self=this;this.createElements();this.$domObj.addClass('spellcheck-container');$(document).bind('click',function(e){(!$(e.target).hasClass('spellcheck-word-highlight')&&!$(e.target).parents().filter('.spellcheck-suggestbox').length)&&self.hideBox();});},option:function(newopts){for(optname in newopts){this.options[optname]=newopts[optname];} +return this;},check:function(callback){var self=this,node=this.$domObj.get(0).nodeName,tagExp='<[^>]+>',puncExp='^[^a-zA-Z\\u00A1-\\uFFFF]|[^a-zA-Z\\u00A1-\\uFFFF]+[^a-zA-Z\\u00A1-\\uFFFF]|[^a-zA-Z\\u00A1-\\uFFFF]$|\\n|\\t|\\s{2,}';if(node=='TEXTAREA'||node=='INPUT'){this.type='textarea';var text=$.trim(this.$domObj.val().replace(new RegExp(tagExp,'g'),'').replace(new RegExp(puncExp,'g'),' '));}else{this.type='html';var text=$.trim(this.$domObj.text().replace(new RegExp(puncExp,'g')," "));} this.postJson(this.options.url,{text:encodeURIComponent(text).replace(/%20/g,'+')},function(json){self.type=='html'&&self.options.innerDocument?self.highlightWords(json,callback):self.buildBadwordsBox(json,callback);});},highlightWords:function(json,callback){if(!json.length){callback.call(this.$domObj,true);return;} var self=this,html=this.$domObj.html();$.each(json,function(key,replaceWord){html=html.replace(new RegExp('([^a-zA-Z\\u00A1-\\uFFFF])('+replaceWord+')([^a-zA-Z\\u00A1-\\uFFFF])','g'),'$1$2$3');});this.$domObj.html(html).find('.spellcheck-word-highlight').each(function(){self.elements.highlightWords.push($(this).click(function(){self.suggest(this);}));});(callback)&&callback();},buildBadwordsBox:function(json,callback){if(!json.length){callback.call(this.$domObj,true);return;} var self=this,words=[];$(this.options.wordlist.element)[this.options.wordlist.action](this.elements.$badwords);this.elements.$badwords.empty()