Annotation of loncom/html/adm/spellcheck/js/jquery.spellchecker.min.js, revision 1.1

1.1     ! foxr        1: /*
        !             2:  * jquery.spellchecker.js - a simple jQuery Spell Checker
        !             3:  * Copyright (c) 2009 Richard Willis
        !             4:  * MIT license  : http://www.opensource.org/licenses/mit-license.php
        !             5:  * Project      : http://jquery-spellchecker.googlecode.com
        !             6:  * Contact      : willis.rh@gmail.com
        !             7:  */
        !             8: (function(b){b.Z.extend({ga:function(a,c){return this.k(function(){if(b(this).data("spellchecker")&&b(this).data("spellchecker")[a])b(this).data("spellchecker")[a](c);else{b(this).data("spellchecker",new h(this,a&&a.constructor===Object&&a||null));a&&a.constructor==String&&b(this).data("spellchecker")[a](c)}})}});function h(a,c){this.options=b.extend({url:"checkspelling.php",lang:"en",o:"pspell",n:false,B:{action:"after",element:a},w:"below",p:false},c||{});this.b=b(a);this.elements={};this.P()}h.prototype= {P:function(){this.J();this.b.m("spellcheck-container")},I:function(a){var c=this,d=this.b.$(0).nodeName;if(d=="TEXTAREA"||d=="INPUT"){this.type="textarea";d=b.z(this.b.A().replace(new RegExp("<[^>]+>","g"),"").replace(new RegExp("^[^a-zA-Z\\u00A1-\\uFFFF]|[^a-zA-Z\\u00A1-\\uFFFF]+[^a-zA-Z\\u00A1-\\uFFFF]|[^a-zA-Z\\u00A1-\\uFFFF]$|\\n|\\t|\\s{2,}","g")," "))}else{this.type="html";d=b.z(this.b.text().replace(new RegExp("^[^a-zA-Z\\u00A1-\\uFFFF]|[^a-zA-Z\\u00A1-\\uFFFF]+[^a-zA-Z\\u00A1-\\uFFFF]|[^a-zA-Z\\u00A1-\\uFFFF]$|\\n|\\t|\\s{2,}", "g")," "))}this.q(this.options.url,{text:encodeURIComponent(d).replace(/%20/g,"+")},function(e){c.type=="html"&&c.options.p?c.N(e,a):c.G(e,a)})},N:function(a,c){if(a.length){var d=this,e=this.b.h();b.k(a,function(f,g){e=e.replace(new RegExp("([^a-zA-Z\\u00A1-\\uFFFF])("+g+")([^a-zA-Z\\u00A1-\\uFFFF])","g"),'$1<span class="spellcheck-word-highlight">$2</span>$3')});this.b.h(e).find(".spellcheck-word-highlight").click(function(){d.r(this)});c&&c()}else c(true)},G:function(a,c){if(a.length){var d=this, e=[];if(b("#spellcheck-badwords").length)this.elements.d=b("#spellcheck-badwords");else b(this.options.B.element)[this.options.B.action](this.elements.d);this.elements.d.empty();b.k(a,function(f,g){if(b.ba(g,e)===-1){b('<span class="spellcheck-word-highlight">'+g+"</span>").click(function(){d.r(this)}).V(d.elements.d).j('<span class="spellcheck-sep">,</span> ');e.push(g)}});b(".spellcheck-sep:last",d.elements.d).m("spellcheck-sep-last");c&&c()}else c(true)},r:function(a){var c=this;a=b(a);var d=a.da(); this.a=a;if(this.options.p){this.elements.c=this.elements.e.find("#spellcheck-suggestbox");this.elements.f=this.elements.e.find("#spellcheck-suggestbox-words");this.elements.i=this.elements.e.find("#spellcheck-suggestbox-foot")}this.elements.i.M();this.elements.c.stop().M().K({opacity:1,width:"auto",left:d.left+"px",top:this.options.w=="above"?d.top-(a.outerHeight()+10)+"px":d.top+a.outerHeight()+"px"}).X(200);this.elements.g.focus();this.elements.f.h("<em>Loading..</em>");this.q(this.options.url, {r:encodeURIComponent(b.z(a.text()))},function(e){c.H(e,d)})},H:function(a,c){var d=this,e=this.a;this.elements.f.empty();for(var f=0;f<(a.length<5?a.length:5);f++)this.elements.f.append(b('<a href="#">'+a[f]+"</a>").m(!f?"first":"").ca(function(g){g.preventDefault();d.replace(this.innerHTML);d.elements.g.s("blur")}));!f&&this.elements.f.append("<em>(no suggestions)</em>");a=window.innerHeight?window.innerHeight:b(window).height();this.elements.i.show();d.elements.c.K({top:this.options.w=="above"|| c.top+e.outerHeight()+this.elements.c.outerHeight()>a+10?c.top-(this.elements.c.height()+5)+"px":c.top+e.outerHeight()+"px",width:"auto",left:this.elements.c.outerWidth()+c.left>b("body").width()?c.left-this.elements.c.width()+e.outerWidth()+"px":c.left+"px"})},t:function(a){this.elements.c.Y(250,function(){a&&a()})},replace:function(a){switch(this.type){case "textarea":this.S(a);break;case "html":this.R(a);break}},v:function(a,c){return a.replace(new RegExp("([^a-zA-Z\\u00A1-\\uFFFF])("+this.a.text()+ ")([^a-zA-Z\\u00A1-\\uFFFF])","g"),"$1"+c+"$3").replace(new RegExp("^("+this.a.text()+")([^a-zA-Z\\u00A1-\\uFFFF])","g"),c+"$2").replace(new RegExp("([^a-zA-Z\\u00A1-\\uFFFF])("+this.a.text()+")$","g"),"$1"+c)},S:function(a){this.l(this.a);this.b.A(this.v(this.b.A(),a))},R:function(a){var c=this.b.find(".spellcheck-word-highlight:contains("+this.a.text()+")");if(c.length)c.j(a).remove();else{b(this.b).h(this.v(b(this.b).h(),a));this.l(this.a)}},O:function(){this.type=="textarea"?this.l(this.a):this.a.j(this.a.h()).remove()}, u:function(){var a=this;this.type=="textarea"?this.l(this.a):b(".spellcheck-word-highlight",this.b).k(function(){(new RegExp(a.a.text(),"i")).test(this.innerHTML)&&b(this).j(this.innerHTML).remove()})},l:function(a){a.next().aa("spellcheck-sep")&&a.next().remove();a.remove();b(".spellcheck-sep",this.elements.d).length?b(".spellcheck-sep:last",this.elements.d).m("spellcheck-sep-last"):this.remove()},n:function(){var a=this;this.t(function(){confirm('Are you sure you want to add the word "'+a.a.text()+ '" to the dictionary?')&&a.q(a.options.url,{T:a.a.text()},function(){a.u();a.I()})})},remove:function(a){a=a||true;this.elements.e.find(".spellcheck-word-highlight").k(function(){b(this).j(this.innerHTML).remove()});this.elements.e.find("#spellcheck-badwords, #spellcheck-suggestbox-words, #spellcheck-suggestbox-foot, #spellcheck-suggestbox, #spellcheck-focus-helper").remove();b(this.L).fa("spellcheck-container");a&&b(this.L).data("spellchecker",null)},q:function(a,c,d){return b.U({type:"POST",url:a, data:b.extend(c,{o:this.options.o,lang:this.options.lang}),dataType:"json",W:false,error:function(){alert("Sorry, there was an error processing the request.")},ha:function(e){d&&d(e)}})},J:function(){var a=this;this.elements.e=this.options.p?this.b.ea().filter("html:first").find("body"):b("body");this.remove(false);this.elements.g=b('<input type="text" id="spellcheck-focus-helper" />').blur(function(){a.t()}).Q(this.elements.e);this.elements.f=b('<div id ="spellcheck-suggestbox-words"></div>');this.elements.D= b('<a href="#">Ignore Word</a>').click(function(c){c.preventDefault();a.O();a.elements.g.s("blur")});this.elements.C=b('<a href="#">Ignore all</a>').click(function(c){c.preventDefault();a.u();a.elements.g.s("blur")});this.elements.F=b('<a href="#" title="ignore word forever (add to dictionary)">Ignore forever</a>').click(function(c){c.preventDefault();a.n();a.elements.g.s("blur")});this.elements.i=b('<div id="spellcheck-suggestbox-foot"></div>').append(this.elements.D).append(this.elements.C).append(this.options.o== "pspell"&&a.options.n?this.elements.F:false);this.elements.d=b('<div id="spellcheck-badwords"></div>');this.elements.c=b('<div id="spellcheck-suggestbox"></div>').append(this.elements.f).append(this.elements.i).Q(this.elements.e)}}})(jQuery);

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>