[LON-CAPA-cvs] cvs: loncom /html/adm/spellcheck/js jquery.spellchecker.js jquery.spellchecker.min.js

foxr foxr at source.lon-capa.org
Mon Sep 24 06:31:45 EDT 2012


foxr		Mon Sep 24 10:31:45 2012 EDT

  Modified files:              
    /loncom/html/adm/spellcheck/js	jquery.spellchecker.js 
                                  	jquery.spellchecker.min.js 
  Log:
  Add option setting method
  
Index: loncom/html/adm/spellcheck/js/jquery.spellchecker.js
diff -u loncom/html/adm/spellcheck/js/jquery.spellchecker.js:1.1 loncom/html/adm/spellcheck/js/jquery.spellchecker.js:1.2
--- loncom/html/adm/spellcheck/js/jquery.spellchecker.js:1.1	Tue Aug 28 10:18:44 2012
+++ loncom/html/adm/spellcheck/js/jquery.spellchecker.js	Mon Sep 24 10:31:45 2012
@@ -56,6 +56,12 @@
 				self.hideBox();
 			});
 		},
+		option : function(newopts) {
+		    for (optname in newopts) {
+		        this.options[optname] = newopts[optname];
+		    }
+		    return this;
+	    },
 
 		// checks a chunk of text for bad words, then either shows the words below the original element (if texarea) or highlights the bad words
 		check : function(callback){
Index: loncom/html/adm/spellcheck/js/jquery.spellchecker.min.js
diff -u loncom/html/adm/spellcheck/js/jquery.spellchecker.min.js:1.2 loncom/html/adm/spellcheck/js/jquery.spellchecker.min.js:1.3
--- loncom/html/adm/spellcheck/js/jquery.spellchecker.min.js:1.2	Tue Sep  4 10:44:13 2012
+++ loncom/html/adm/spellcheck/js/jquery.spellchecker.min.js	Mon Sep 24 10:31:45 2012
@@ -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<span class="spellcheck-word-highlight">$2</span>$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()




More information about the LON-CAPA-cvs mailing list