[LON-CAPA-cvs] cvs: loncom /html/adm/spellcheck/css demo.css spellchecker.css /html/adm/spellcheck/dictionary en.pws /html/adm/spellcheck/img spellcheck.png spellchecker_bg.gif spellchecker_shadow.png /html/adm/spellcheck/js jquery.spellchecker.js jquery.spellchecker.min.js

foxr foxr at source.lon-capa.org
Tue Aug 28 06:18:45 EDT 2012


foxr		Tue Aug 28 10:18:45 2012 EDT

  Added files:                 
    /loncom/html/adm/spellcheck/css	demo.css spellchecker.css 
    /loncom/html/adm/spellcheck/dictionary	en.pws 
    /loncom/html/adm/spellcheck/img	spellcheck.png spellchecker_bg.gif 
                                   	spellchecker_shadow.png 
    /loncom/html/adm/spellcheck/js	jquery.spellchecker.js 
                                  	jquery.spellchecker.min.js 
  Log:
  Add jquery-spellchecker to the repository.
  
  
-------------- next part --------------

Index: loncom/html/adm/spellcheck/css/demo.css
+++ loncom/html/adm/spellcheck/css/demo.css
td,th,tr,thead,tfoot,tbody,caption,table,legend,label,form,fieldset,li,ul,ol,dd,dt,dl,var,tt,sup,sub,strong,strike,small,samp,s,q,kbd,ins,img,font,em,dfn,del,code,cite,big,address,acronym,abbr,pre,blockquote,p,h6,h5,h4,h3,h2,h1,iframe,object,applet,span,div,body,html{font:100% inherit inherit inherit;vertical-align:baseline}td,th,tr,thead,tfoot,tbody,caption,table,legend,label,form,fieldset,li,ul,ol,dd,dt,dl,var,tt,sup,sub,strong,strike,small,samp,s,q,kbd,ins,img,font,em,dfn,del,code,cite,big,address,acronym,abbr,pre,blockquote,p,h6,h5,h4,h3,h2,h1,iframe,object,applet,span,div,body,html,h2,h1,#nav,#footer p{margin:0}td,th,tr,thead,tfoot,tbody,caption,table,legend,label,form,fieldset,li,ul,ol,dd,dt,dl,var,tt,sup,sub,strong,strike,small,samp,s,q,kbd,ins,img,font,em,dfn,del,code,cite,big,address,acronym,abbr,pre,blockquote,p,h6,h5,h4,h3,h2,h1,iframe,object,applet,span,div,body,html,form,#header,#body h2,#footer{padding:0}td,th,tr,thead,tfoot,tbody,caption,table,legend,label,for!
 m,fieldset,li,ul,ol,dd,dt,dl,var,tt,sup,sub,strong,strike,small,samp,s,q,kbd,ins,img,font,em,dfn,del,code,cite,big,address,acronym,abbr,pre,blockquote,p,h6,h5,h4,h3,h2,h1,iframe,object,applet,span,div,body,html,a img,fieldset,#header,#body,#tabs{border:0}td,th,tr,thead,tfoot,tbody,caption,table,legend,label,form,fieldset,li,ul,ol,dd,dt,dl,var,tt,sup,sub,strong,strike,small,samp,s,q,kbd,ins,img,font,em,dfn,del,code,cite,big,address,acronym,abbr,pre,blockquote,p,h6,h5,h4,h3,h2,h1,iframe,object,applet,span,div,body,html,:focus,:active{outline:0}html,body,#wrapper{height:100%}body{font:13px 'lucida grande',helvetica,verdana,arial,sans-serif /1.3;color:#333}h2,h1{font-family:'trebuchet ms',verdana,arial;padding:10px}h1,h2,#header h1{font-size:large}h2,#sidebar a:hover,#body a:hover{color:#800}h2{padding-left:0}h2,#footer,a.ui-button:hover{font-weight:normal}h2 a:visited,h2 a{color:#800 !important;text-decoration:none !important}h2 a:hover{color:red}form{background:#fefefe url(..!
 /img/form_bg.gif) repeat-x 0 0;border:1px solid #ddd;margin-bottom:1.2
em}fieldset{margin:15px}label,#logo,.clearfix:after,* .clearfix{display:block}label{margin-top:2px;margin-bottom:2px}textarea,select,input,#content,#text-content,.ui-selectmenu-service,.ui-selectmenu-menu-dropdown,.ui-button{font-size:0.8em}textarea,a.ui-button:hover{border:1px solid #999}textarea{width:99%;height:16em;font-family:inherit}th,td{vertical-align:middle;padding:0.35em;overflow:hidden;height:1em}th,strong,#header h1,#body h3{font-weight:bold}td{font-size:94%}tr.even{background:#f6f6f6}table{text-align:left}table,#footer{width:100%}ul{margin-bottom:18px}li{margin-bottom:0.6em;margin-left:2.2em}p{margin:0 0 1em 0}small{font-size:86%}em{font-style:italic}pre{background:#eee;border-color:#ddd;border-style:solid;border-width:1px 1px 1px 5px;font-size:small;overflow-x:auto;padding:15px;margin-bottom:1em}#wrapper,#header,.ui-button{position:relative}#header,#footer{text-align:center}#header h1{background:#06b;padding:20px;color:white;background:url(../img/bg.gif) repeat!
 -x;text-shadow:1px 1px 2px #444}#header h1 a,.ui-button{text-decoration:none}#header h1 a{text-shadow:#000 1px 1px 2px}#logo{background:transparent url(../img/jq.png) repeat scroll 0 0;height:31px;margin-right:10px;margin-top:15px;width:110px}#logo,.col-r,.right{float:right}#nav{line-height:1;-moz-border-radius:0;-webkit-border-radius:0;border-radius:0;font-size:1.1em}#nav a{padding:0.3em 1em;font-size:88%}#body{padding:1.6em 2em}#body h1{padding:15px 10px 5px 0}#body h2,#body h3{margin-bottom:14px}#body h3{font-size:120%}#body h2 a{text-decoration:underline}#body .padd{padding:0.5em}#footer,.ui-button span.ui-icon{position:absolute}#footer{bottom:0;font-size:90%;height:22px;line-height:18px}#footer p{padding:0.2em}#body button{font-size:0.9em;padding:0.28em 0.6em 0.3em 0.1em;margin-right:0.3em}#content,#text-content{background:url(../img/form_bg.gif) repeat-x 0 0;border:1px solid #888;border-right:1px solid #ccc;border-bottom:1px solid #ccc;margin-bottom:10px}#content{-moz!
 -border-radius:4px;-webkit-border-radius:4px;padding:0.8em 0.9em 0 0.9
em}#text-content{padding:2px}.ui-selectmenu-service,.ui-selectmenu-language,.ui-icon,.ui-dialog-buttonpane .loading,.col-l,.left{float:left}.ui-selectmenu-language{margin-right:0.5em}.ui-widget-content{font-size:1em}.ui-selectmenu-menu-dropdown,.ui-widget a.ui-selectmenu{font-size:0.7em}.ui-tabs .ui-tabs-panel{padding:1em 0;font-size:118%}.ui-button{padding:0.4em 1em}.ui-button span.ui-icon{left:0.2em;margin:-8px 5px 0 0;top:50%}a.ui-button:hover{background:#dadada url(http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/smoothness/images/ui-bg_glass_75_dadada_1x400.png) 50% 50% repeat-x;color:#212121;outline:none}.ui-dialog-buttonpane .loading{background:0 center;padding:0.7em 0 0.7em 22px}.col-r{width:55%}.col-l{padding-top:2px;width:42%}.hidden{display:none}.strike{text-decoration:line-through}.loading{background:url(../img/ajax-loader.gif) no-repeat center center;padding:0.5em 8px}.clear{clear:left}.clearfix:after{content:".";height:0;clear:both;visibility:hidden}.!
 clearfix{display:inline-block}* html .clearfix{height:1%}

Index: loncom/html/adm/spellcheck/css/spellchecker.css
+++ loncom/html/adm/spellcheck/css/spellchecker.css
spellcheck-suggestbox {
	position: absolute;
	display: none;
	z-index: 9999;
	overflow: none;
	padding: 0px 9px 9px 0px;
	background: transparent url(../img/spellchecker_shadow.png) no-repeat scroll right bottom;
	font: normal 13px arial;
}
spellcheck-suggestbox em {
	border-top: 1px solid #ccc;
	border-left: 1px solid #bbb;
	border-right: 1px solid #bbb;
	padding: 3px 6px 3px 6px;
	display: block;
	margin: 0px;
	text-decoration: none;
	color: #333;
	font-style: italic;
}
spellcheck-suggestbox a, .spellcheck-suggestbox a:visited {
	border-left: 1px solid #bbb;
	border-right: 1px solid #bbb;
	padding: 3px 6px 3px 6px;
	display: block;
	margin: 0px;
	text-decoration: none;
	color: #333;
	outline: none;
}
spellcheck-suggestbox a.first, .spellcheck-suggestbox a.first:visited {
	border-top: 1px solid #ccc;
}
spellcheck-suggestbox a:hover {
	color: #000;
	background: #ddd;
}
spellcheck-suggestbox-words {
	background: #fff;
}
spellcheck-suggestbox-foot {
	border-top: 1px solid #ddd;
	background: #fff;
}
spellcheck-suggestbox-foot a, .spellcheck-suggestbox-foot a:visited {
	outline: none;
} 
pellcheck-focus-helper {
	position: absolute;
	top: -2000px;
	z-index: 0;
}
spellcheck-word-highlight {
	color: #d70303;
	text-decoration: none;
	background: url(../img/spellchecker_bg.gif) repeat-x 100% 100%;
	cursor: pointer;
}
spellcheck-badwords {
	margin-bottom: 2em;
	margin-top: -0.5em;
	font-size: 12px;
	border: 1px solid #bbb;
	padding: 4px 6px;
}
spellcheck-sep {
	padding-right: 0.5em;
}
spellcheck-sep-last {
	display: none;
}

Index: loncom/html/adm/spellcheck/dictionary/en.pws
+++ loncom/html/adm/spellcheck/dictionary/en.pws

Index: loncom/html/adm/spellcheck/js/jquery.spellchecker.js
+++ loncom/html/adm/spellcheck/js/jquery.spellchecker.js
/*
 * jquery.spellchecker.js - a simple jQuery Spell Checker
 * Copyright (c) 2009 Richard Willis
 * MIT license  : http://www.opensource.org/licenses/mit-license.php
 * Project      : http://jquery-spellchecker.googlecode.com
 * Contact      : willis.rh at gmail.com
 */

(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',	// default spellcheck url
			lang: 'en',			// default language 
			engine: 'pspell',		// pspell or google
			addToDictionary: false,		// display option to add word to dictionary (pspell only)
			wordlist: {
				action: 'after',	// which jquery dom insert action
				element: domObj		// which object to apply above method
			},
			suggestBoxPosition: 'below',	// position of suggest box; above or below the highlighted word
			innerDocument: false		// if you want the badwords highlighted in the html then set to true
		}, options || {});
		this.$domObj = $(domObj);
		this.elements = {};
		this.init();
	};

	SpellChecker.prototype = {

		init : function(){
			var self = this;
			this.createElements();
			this.$domObj.addClass('spellcheck-container');
			// hide the suggest box on document click
			$(document).bind('click', function(e){
				(!$(e.target).hasClass('spellcheck-word-highlight') && 
				!$(e.target).parents().filter('.spellcheck-suggestbox').length) &&
				self.hideBox();
			});
		},

		// 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){

			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'), '')	// strip html tags
					.replace(new RegExp(puncExp, 'g'), ' ') // strip punctuation
				);
			} else {
				this.type = 'html';
				var text = $.trim(
					this.$domObj.text()
					.replace(new RegExp(puncExp, 'g'), " ") // strip punctuation
				);
			}
			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 = [];

			// insert badwords list into dom
			$(this.options.wordlist.element)[this.options.wordlist.action](this.elements.$badwords);

			// empty the badwords container
			this.elements.$badwords.empty()

			// append incorrectly spelt words
			$.each(json, function(key, badword) {
				if ($.inArray(badword, words) === -1) {
					self.elements.highlightWords.push(
						$('<span class="spellcheck-word-highlight">'+badword+'</span>')
						.click(function(){ self.suggest(this); })
						.appendTo(self.elements.$badwords)
						.after('<span class="spellcheck-sep">,</span> ')
					);
					words.push(badword);
				}
			});
			$('.spellcheck-sep:last', self.elements.$badwords).addClass('spellcheck-sep-last');
			(callback) && callback();
		},

		// gets a list of suggested words, appends to the suggestbox and shows the suggestbox
		suggest : function(word){

			var self = this, $word = $(word), offset = $word.offset();
			this.$curWord = $word;

			if (this.options.innerDocument) {
				this.elements.$suggestBox = this.elements.$body.find('.spellcheck-suggestbox');
				this.elements.$suggestWords = this.elements.$body.find('.spellcheck-suggestbox-words');
				this.elements.$suggestFoot = this.elements.$body.find('.spellcheck-suggestbox-foot');
			}

			this.elements.$suggestFoot.hide();
			this.elements.$suggestBox
			.stop().hide()
			.css({
				opacity: 1,
				width: "auto",
				left: offset.left + "px",
				top: 
					(this.options.suggestBoxPosition == "above" ?
					(offset.top - ($word.outerHeight() + 10)) + "px" :
					(offset.top + $word.outerHeight()) + "px")
			}).fadeIn(200);
			
			this.elements.$suggestWords.html('<em>Loading..</em>');

			this.postJson(this.options.url, {
				suggest: encodeURIComponent($.trim($word.text()))
			}, function(json){
				self.buildSuggestBox(json, offset);
			});
		},

		buildSuggestBox : function(json, offset){

			var self = this, $word = this.$curWord;

			this.elements.$suggestWords.empty();

			// build suggest word list
			for(var i=0; i < (json.length < 5 ? json.length : 5); i++) {
				this.elements.$suggestWords.append(
					$('<a href="#">'+json[i]+'</a>')
					.addClass((!i?'first':''))
					.click(function(){ return false; })
					.mousedown(function(e){
						e.preventDefault();
						self.replace(this.innerHTML);
						self.hideBox();
					})
				);
			}								

			// no word suggestions
			(!i) && this.elements.$suggestWords.append('<em>(no suggestions)</em>');

			// get browser viewport height
			var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
			
			this.elements.$suggestFoot.show();
						
			// position the suggest box
			self.elements.$suggestBox
			.css({
				top :	(this.options.suggestBoxPosition == 'above') ||
					(offset.top + $word.outerHeight() + this.elements.$suggestBox.outerHeight() > viewportHeight + 10) ?
					(offset.top - (this.elements.$suggestBox.height()+5)) + "px" : 
					(offset.top + $word.outerHeight() + "px"),
				width : 'auto',
				left :	(this.elements.$suggestBox.outerWidth() + offset.left > $('body').width() ? 
					(offset.left - this.elements.$suggestBox.width()) + $word.outerWidth() + 'px' : 
					offset.left + 'px')
			});
			
		},

		// hides the suggest box	
		hideBox : function(callback) {
			this.elements.$suggestBox.fadeOut(250, function(){
				(callback) && callback();
			});				
		},
	
		// replace incorrectly spelt word with suggestion
		replace : function(replace) {
			switch(this.type) {
				case 'textarea': this.replaceTextbox(replace); break;
				case 'html': this.replaceHtml(replace); break;
			}
		},

		// replaces a word string in a chunk of text
		replaceWord : function(text, replace){
			return text
				.replace(
					new RegExp("([^a-zA-Z\\u00A1-\\uFFFF]?)("+this.$curWord.text()+")([^a-zA-Z\\u00A1-\\uFFFF]?)", "g"),
					'$1'+replace+'$3'
				)
				.replace(
					new RegExp("^("+this.$curWord.text()+")([^a-zA-Z\\u00A1-\\uFFFF])", "g"),
					replace+'$2'
				)
				.replace(
					new RegExp("([^a-zA-Z\\u00A1-\\uFFFF])("+this.$curWord.text()+")$", "g"),
					'$1'+replace
				);
		},

		// replace word in a textarea
		replaceTextbox : function(replace){
			this.removeBadword(this.$curWord);
			this.$domObj.val(
				this.replaceWord(this.$domObj.val(), replace)
			);
		},

		// replace word in an HTML container
		replaceHtml : function(replace){
			var words = this.$domObj.find('.spellcheck-word-highlight:contains('+this.$curWord.text()+')')
			if (words.length) {
				words.after(replace).remove();
			} else {
				$(this.$domObj).html(
					this.replaceWord($(this.$domObj).html(), replace)
				);
				this.removeBadword(this.$curWord);
			}
		},
		
		// remove spelling formatting from word to ignore in original element
		ignore : function() {
			if (this.type == 'textarea') {
				this.removeBadword(this.$curWord);
			} else {
				this.$curWord.after(this.$curWord.html()).remove();
			}
		},
		
		// remove spelling formatting from all words to ignore in original element
		ignoreAll : function() {
			var self = this;
			if (this.type == 'textarea') {
				this.removeBadword(this.$curWord);
			} else {
				$('.spellcheck-word-highlight', this.$domObj).each(function(){
					(new RegExp(self.$curWord.text(), 'i').test(this.innerHTML)) && 
					$(this).after(this.innerHTML).remove(); // remove anchor
				});
			}
		},

		removeBadword : function($domObj){
			($domObj.next().hasClass('spellcheck-sep')) && $domObj.next().remove();
			$domObj.remove();
			if (!$('.spellcheck-sep', this.elements.$badwords).length){
				this.elements.$badwords.remove();
			} else {
				$('.spellcheck-sep:last', this.elements.$badwords).addClass('spellcheck-sep-last');
			}
		},
		
		// add word to personal dictionary (pspell only)
		addToDictionary : function() {
			var self= this;
			this.hideBox(function(){
				confirm('Are you sure you want to add the word "'+self.$curWord.text()+'" to the dictionary?') &&
				self.postJson(self.options.url, { addtodictionary: self.$curWord.text() }, function(){
					self.ignoreAll();
					self.check();
				});			
			});
		},
		
		// remove spell check formatting
		remove : function(destroy) {
			destroy = destroy || true;
			$.each(this.elements.highlightWords, function(val){
				this.after(this.innerHTML).remove()
			});
			this.elements.$badwords.remove();
                        this.elements.$suggestBox.remove();
			$(this.domObj).removeClass('spellcheck-container');
			(destroy) && $(this.domObj).data('spellchecker', null);
		},
		
		// sends post request, return JSON object
		postJson : function(url, data, callback){
			var xhr = $.ajax({
				type : 'POST',
				url : url,
				data : $.extend(data, {
					engine: this.options.engine, 
					lang: this.options.lang
				}),
				dataType : 'json',
				cache : false,
				error : function(XHR, status, error) {
					alert('Sorry, there was an error processing the request.');
				},
				success : function(json){
					(callback) && callback(json);
				}
			});
			return xhr;
		},

		// create the spellchecker elements, prepend to body
		createElements : function(){
			var self = this;

			this.elements.$body = this.options.innerDocument ? this.$domObj.parents().filter('html:first').find("body") : $('body');
			this.elements.highlightWords = [];
			this.elements.$suggestWords = this.elements.$suggestWords ||
				$('<div></div>').addClass('spellcheck-suggestbox-words');
			this.elements.$ignoreWord = this.elements.$ignoreWord ||
				$('<a href="#">Ignore Word</a>')
				.click(function(e){
					e.preventDefault();
					self.ignore();
					self.hideBox();
				});
			this.elements.$ignoreAllWords = this.elements.$ignoreAllWords ||
				$('<a href="#">Ignore all</a>')
				.click(function(e){
					e.preventDefault();
					self.ignoreAll();
					self.hideBox();
				});
			this.elements.$ignoreWordsForever = this.elements.$ignoreWordsForever ||
				$('<a href="#" title="ignore word forever (add to dictionary)">Ignore forever</a>')
				.click(function(e){
					e.preventDefault();
					self.addToDictionary();
					self.hideBox();
				});
			this.elements.$suggestFoot = this.elements.$suggestFoot ||
				$('<div></div>').addClass('spellcheck-suggestbox-foot')
				.append(this.elements.$ignoreWord)
				.append(this.elements.$ignoreAllWords)
				.append(this.options.engine == "pspell" && self.options.addToDictionary ? this.elements.$ignoreWordsForever : false);
			this.elements.$badwords = this.elements.$badwords ||
				$('<div></div>').addClass('spellcheck-badwords');
			this.elements.$suggestBox = this.elements.$suggestBox ||
				$('<div></div>').addClass('spellcheck-suggestbox')
				.append(this.elements.$suggestWords)
				.append(this.elements.$suggestFoot)
				.prependTo(this.elements.$body);
		}
	};	

})(jQuery);

Index: loncom/html/adm/spellcheck/js/jquery.spellchecker.min.js
+++ loncom/html/adm/spellcheck/js/jquery.spellchecker.min.js
/*
 * jquery.spellchecker.js - a simple jQuery Spell Checker
 * Copyright (c) 2009 Richard Willis
 * MIT license  : http://www.opensource.org/licenses/mit-license.php
 * Project      : http://jquery-spellchecker.googlecode.com
 * Contact      : willis.rh at gmail.com
 */
(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.elem!
 ents.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(t!
 his.a)}},O:function(){this.type=="textarea"?this.l(this.a):this.a.j(th
is.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:func!
 tion(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-sugge!
 stbox-foot"></div>').append(this.elements.D).append(this.elements.C).a
ppend(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);


More information about the LON-CAPA-cvs mailing list