473,396 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Complex spellchk .JS function won't do what I want it to do :(

Dear newsgroup:

I've got this long function, which works good overall to spell check
words from a dictionary and I am not in a position to replace it. Can
someone please see where or how it might be chopping up words like:
don't. It brings them back as: 't, chopping off the "don" before the
apostrophe. I've looked over the whole situation and ran many $string
tests....and it appears to be narrowed it down to this. I may be wrong
and not very good with Javascript so I am hoping someone can help me
and tell me if something is going on here :))

Sincerest regards,
~Julie

BTW, this code seems to be ignoring special characters like #dont,
storing/interperting it as dont minus the #.... but I would rather it
not do that and take the string verbatum as is.
/*

function addEvent(obj, evType, fn){
if (obj.addEventListener){
obj.addEventListener(evType, fn, true);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent("on"+evType, fn);
return r;
} else {
return false;
}
}

function removeEvent(elm, evType, fn)
{
if (elm.removeEventListener){
elm.removeEventListener(evType, fn, true);
return true;
} else if (elm.detachEvent){
var r = elm.detachEvent("on"+evType, fn);
return r;
} else {
return false;
}
}

function isRightClick(e)
{
var rightclick;
// Tests if an event is a right-click - see
http://www.xs4all.nl/~ppk/js/events_properties.html
if (!e) var e = window.event;
if (e.which) rightclick = (e.which == 3);
else if (e.button) rightclick = (e.button == 2);
return rightclick;
}

function getTarget(e)
{
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
// Nasty mozilla specific code - IE returns a span but Moz sometimes
returns the text node
if (targ.nodeType == 3) {
targ = targ.parentNode;
}
return targ;
}

function getMousePosition(e)
{
var pos = {x: 0, y: 0};
if (!e) var e = window.event;
if (e.pageX || e.pageY)
{
pos.x = e.pageX;
pos.y = e.pageY;
}
else if (e.clientX || e.clientY)
{
pos.x = e.clientX + document.body.scrollLeft;
pos.y = e.clientY + document.body.scrollTop;
}
return pos;
}

globalspan = null;

function makeMenu(word, suggestions, pos) {
var words = new Array();
words = suggestions.split(', ');
menu = document.createElement('div');
menu.setAttribute('style', 'position: absolute; left: '+(pos.x -
10)+'px; top:'+(pos.y - 10)+'px;');
menu.className = 'spelingMenu';
// Make sure this item has at least one suggestion
if (words[0] == '') {
// Add "None available" notice
var none = document.createElement('div');
none.appendChild(document.createTextNode('None available'));
menu.appendChild(none);
}
for (var i = 0; i < words.length; i++) {
var item = document.createElement('a');
item.href = 'javascript:void(0);';
var newword = words[i];
var text = document.createTextNode(newword);
item.word = newword;
item.appendChild(text);
menu.appendChild(item);
// Add event - at the moment this works on the textarea with
id="speling"
var textarea = document.getElementById('speling');
addEvent(item, 'click', function(e) {
var re = new RegExp('(\\W|^)'+word+'(\\W|$)', 'gim');;
textarea.value = textarea.value.replace(re,
'$1'+getTarget(e).word+'$2');
// Change the span to have the correct text as well
globalspan.firstChild.nodeValue = getTarget(e).word;
globalspan.className = '';
// Now close the menu

document.getElementsByTagName('body')[0].removeChild(spelingMenu);
spelingMenu = null;
});
}
// Add "cancel" button
var cancel = document.createElement('div');
cancel.className = 'cancel';
cancel.appendChild(document.createTextNode('cancel '));
addEvent(cancel, 'click', function(e) {

document.getElementsByTagName('body')[0].removeChild(spelingMenu);
spelingMenu = null;
});
menu.appendChild(cancel);
return menu;
}

var spelingMenu = null;

function setupSpeling() {
// Loop through span tags adding magic right menu to them
spans = document.getElementsByTagName('span');
for (var i = 0; i < spans.length; i++) {
var span = spans[i];
if (span.className == 'speling') {
// Attach magic events
span.suggestions = span.title;
span.title = 'Click to correct spelling';
addEvent(span, 'click', function(e) {
var pos = getMousePosition(e);
var target = getTarget(e);
var suggestions = target.suggestions;
var word = target.firstChild.nodeValue;
// alert('Word: '+word+' Suggestions: '+suggestions);
// alert('X: '+pos.x+' Y: '+pos.y+' Corrections:
'+targ.title);
// Destroy menu if it already exists
if (spelingMenu != null) {

document.getElementsByTagName('body')[0].removeChild(spelingMenu);
spelingMenu = null;
}
globalspan = this;
var menu = makeMenu(word, suggestions, pos);

document.getElementsByTagName('body')[0].appendChild(menu);
spelingMenu = menu;
});
}
}
}

addEvent(window, "load", setupSpeling);

Dec 2 '06 #1
4 1435
ha********@gmail.com wrote:
Dear newsgroup:

I've got this long function, which works good overall to spell check
words from a dictionary and I am not in a position to replace it.
Remove it then. Firefox v2 has spellchecking on textboxes.
Dec 2 '06 #2
On Dec 2, 1:07 pm, TheBagbournes <n...@noway.comwrote:
Remove it then. Firefox v2 has spellchecking on textboxes.
Yep, but IE6, IE7, FF1.5, Opera & Safari don't.

Dec 2 '06 #3
I wish I could do that, but this has IE users, so this is definately
not an easy situation for me and giving me heart palipations!! :(

Dec 2 '06 #4

ha********@gmail.com wrote:
I wish I could do that, but this has IE users, so this is definately
not an easy situation for me and giving me heart palipations!! :(
I beleive I can help (although not with the heart palpitations) - and
this would actually be really useful to me too, can you tell me where
you got this function please?

Will try to figure out what's wrong while I wait for your reply.

Jim

Dec 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ken in Melbourne Australia | last post by:
If I use the curly bracket syntax (referred to as the complex syntax) within a string, how do I get to call a function within it? The php manual says that the first (or previous) character for...
3
by: Peter Olsen | last post by:
I want to define a class "point" as a subclass of complex. When I create an instance sample = point(<arglist>) I want "sample" to "be" a complex number, but with its real and imaginary...
34
by: Pmb | last post by:
I've been working on creating a Complex class for my own learning purpose (learn through doing etc.). I'm once again puzzled about something. I can't figure out how to overload the assignment...
17
by: Chris Travers | last post by:
Hi all; I just made an interesting discovery. Not sure if it is a good thing or not, and using it certainly breakes first normal form.... Not even sure if it really works. However, as I am...
116
by: Mike MacSween | last post by:
S**t for brains strikes again! Why did I do that? When I met the clients and at some point they vaguely asked whether eventually would it be possible to have some people who could read the data...
1
by: Laertes | last post by:
Hi, I want to use the expression builder in a query to define a field. I know how to do it for simple fields, like the one below : orderdate: IIf((IsNull() And =False) Or (<>"N/A" And...
3
by: Kevin Rollo | last post by:
I'm playing with a generic routine to export data, the concept is to have a list of data driven templates defining what fields to output. Evaluating a simple variable field name in the function...
8
by: Steve Jorgensen | last post by:
Mailing List management is a good example of a case where my conundrum arises. Say there is a m-m relationship between parties and groups - anyone can be a member of any combintation of groups. ...
3
by: Dennis M | last post by:
Hey everyone, I am curious what the performance impact of a custom control would be if it had a significant hierarchy of children. For example, 40 child controls, 5 levels deep, each control on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.