Giter VIP home page Giter VIP logo

jquery-spellchecker's Introduction

jQuery Spellchecker

THIS PROJECT IS OLD AND IS NOT MAINTAINED

The jQuery Spellchecker is a free Javascript spellchecker in the form of a lightweight jQuery plugin that can be used to check the spelling of text within a form field or within a DOM tree. This is a complete rewrite of the initial spellchecker plugin I wrote.

The current version of the plugin is v0.2.4 Beta.

Features

  • Unicode support (works with most languages)
  • HTML parsing (for using the spellchecker within WSYIWYG editors)
  • Text parsing (for using the spellchecker on form fields)
  • Multiple fields
  • Multiple PHP back-end drivers (Enchant, PSpell, Google)
  • Friendly API
  • Event based
  • MIT licensed
  • Actively developed

Browser support

The plugin has been tested and works with the following browsers:

  • IE6+ and latest Chrome, Firefox, Safari and Opera

Requirements

  • jQuery
  • PHP5.3+ to use the default webservice

Download

Documentation

Examples

You can find simple usage examples in the downloadable package.

Issues

Testing is much appreciated. Please post any issue you find in the issue tracker.

Contributing

Thanks

This project would not be possible without the findAndReplaceDOMText function written by James Padolsey.

License

Licensed under the MIT license.

jquery-spellchecker's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-spellchecker's Issues

Redactor demo IE7/IE8

Hi,

I've just been looking at the redactor demo in IE7 and IE8 and have noticed that the response from calling SpellChecker.php always comes back empty - with no word suggestions.

Any thoughts as to why this might be happening? the text parameter is sent as text[] - is IE <9 unable to pass this correctly perhaps?

this.editor.commands is undefined

I'm not sure if this is an issue or something that I am doing wrong since I am a newbie at using CKEditor and Jquery spell checker. However, If someone knows and obvious answer to this question I would appreciate the help.

When I click on the spell check button, Firebug returns the errors below. How is commands initialized? It is always undefined.

TypeError: this.editor.commands is undefined
..rPaste');},0);},null,null,1000);y.on('pasteDialog',function(A){setTimeout(functi...

TypeError: this.editor.commands is undefined
this.editor.commands.jqueryspellchecker.toggleState();

Ignores the wrong words written in captial letters

What is the expected output? What do you see instead?
its works gd only with words that is written in small letters. if the wrong word is written in caps , it simply ignores that words and show the alert box there is no incorrect spelt words. it should work with all words either written in caps or small letters.

What version of the product are you using? On what operating system?
this issue is coming in all versions.

Multiple fields

I need to make some changes to the plugin to support multiple textareas. Currently it relies on using a selector for appending the incorrect words list and this approach won't work for multiple textareas. I also need to create an example (and possible a demo) showing how to do this.

Options:

  • Allow a callback function to be used to append the incorrect words list

Shell script to build and bump versions

I need to create a shell script to replace the version numbers in all the relevant files:

  • package.json
  • jquery.spellchecker.json
  • src/js/jquery.spellchecker.js
  • src/css/jquery.spellchecker.css
  • src/examples/english/ckeditor/plugins/jqueryspellchecker/plugin.js
  • src/examples/english/tinymce/plugins/jqueryspellchecker/editor_plugin.js

The build script should execute in the following order:

  • Run PHP tests
  • Run Javascript tests
  • Bump version numbers
  • Run grunt tasks
  • Git commit
  • Git tag

apostrophe is marked as a misspell

In the fancy demo > textarea:

If you type in a misspelling like "worldz" and change it to the suggested word "world's" and check the spelling again, it marks the "world's" as wrong with "world/'s"

The spell checker is not working with a contentEditable div.

"just use a

with contentEditable property (which is pretty well supported: http://caniuse.com/contenteditable)." - badsyntax

I've tried this method to no avail. The text that loads initially in the div can be read just fine, but even with an event that fires on blur, some words typed after page load will never be checked and some will be fine.

function typer() {
  $('#spellCheck').off('blur', speller).on('blur', speller);
}

// Bind spellchecker handler functions
spellchecker.on('check.success', function() {
  alert('There are no incorrectly spelled words!');
});

function speller()
{
  // Check the spelling when user clicks on button
  $("#check-spelling-button").off('click').on('click', function(e){
    spellchecker.check();
  });
}

When spellchecking with IE8, extra paragraphs are created occasionally

To reproduce: (use native IE8, not IE9 in IE8 mode)

Go to http://jquery-spellchecker.badsyntax.co/ckeditor.html

Place the cursor between "great explorer" and "of the truth" in the paragraph. Hit enter.

Press spellchecker (ABC-button on the top of the editor).

Spellcheck the second paragraph (starting with 'of the truth'... Correct Noo, consequencses's and painful.

At either "consequencses's" or "painful", the normalize function will create an extra paragraph when normalizing the p-element.

Created a pull request at padolsey/findAndReplaceDOMText#9
that will fix this problem, hopefully.

Pre-defined words to ignore when using google?

Just wondering if there's a way to create a word-list to ignore by default so that when using google we can skip some hassle for our users having to ignore the same acronyms and capitalizations that get flagged every time. Great plugin!

CKEditor Issue...blank button and error onclick.

Hello. Issue is the image button is blank and upon clicking I get the attached error. I did find the plugin.js file and created a folder in the CKEditor's plugin section called "jqueryspellchecker" and put it in there. Please help...thank you very much.

I'm using vb.net, VS2010 and my project is using a masterpage. I put the following on my masterpage's head section:

<link href="../Styles/jquery.spellchecker.css" rel="stylesheet" />

<script src="../Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="../Scripts/jquery.spellchecker.js" type="text/javascript"></script>
<script src="../ckeditor/ckeditor.js" type="text/javascript"></script>

<style type="text/css">
    .cke_button__spellchecker_icon {background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAACXklEQVQ4y22RzU4rRxCFv+oeM+32jOSFDRIrlA3SABJiiaNIyYK7uq9h3UR5kzwBvEF2+VkgiGSzzgNYVnIH4QULhBhAMOMZ8FBZXNsySRYldZ86p3SqjkwmE1qtFlEUAVAUBQBxHBMEAa+vrzw9PVFVFWEYEkURjUaDqqp4fHyE29tbVBVAAVXVd/8FVlXVf/AsyzDee0REVbVS1UpEFODw8JBVbG1t7R1PVas8zwmstSRJAtAG2N/fnwLUdb3E9vb2pgC7u7tLDGA6nRKICNZagBLAGLPoIyJTvuxQAVRVxfPzc3lzc8NsNsNaixER5qUioosBeZ6vrhACvL290Ww2ieMY7z1BEGDquibLsiU5yzIAyrJc2G1vbm4CYK3FWsv6+jobGxs0m024u7ubu1Snqq7RaKiq0u12V1MoVZXJZPLnagr39/dwdXWFqpZpmi7f82jLlXLABxEpe72eHh8fD1S1vL6+xry8vCwv670HaMdxvLQPtEXkmzAMf+n1emGr1Rr0+/2fgXZRFF+OmKZpGccx3W4XEfnROffdPJVSRL4Ow/DXg4MDF0XR8Ozs7C/gZDwel6pKYIzBWksYhojIB+/9T8aYQkQ+AhJF0W87OzvOOTc4PT39G/hhPB6rtRZjDMEinqIoUFWOjo6GDw8P315eXv4OsLW11XTODQeDwWfg+1WxiGDmEZDnOcAf5+fnl865YafT8Z1Ox3vvhxcXF5+BT/8WA0iapixc1HXN9va2AU6SJPkKYDQapUD//8TvBqgqdV0zm81IksQAJ3NOfzQavQVBgLX2nRjgHzGrYAquuDikAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDEyLTEwLTI1VDEyOjQ4OjExKzAyOjAwAaJEMgAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxMi0xMC0yNVQxMjo0ODoxMSswMjowMHD//I4AAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAAElFTkSuQmCC) !important;}
</style>

Here's my config.js:

// Extra plugins
config.extraPlugins = 'jqueryspellchecker';

//CAPs Comm Tool's Custom Toolbars
CKEDITOR.config.toolbar_CT =
[
{ name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] },
//{ name: 'editing', items: ['Find', 'Replace', '-', 'SelectAll', '-', 'SpellChecker', 'Scayt'] },
    { name: 'spellcheck', items: ['jQuerySpellChecker'] },
'/',
{ name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'] },
{ name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] },
{ name: 'links', items: ['Link', 'Unlink'] },
{ name: 'colors', items: ['TextColor', 'BGColor'] },
//    { name: 'insert', items: ['Image', 'Table', 'HorizontalRule', 'SpecialChar'] },
    {name: 'insert', items: ['Table', 'HorizontalRule', 'SpecialChar'] },
{ name: 'tools', items: ['Maximize'] }
];

contentsCss: '../Styles/jquery.spellchecker.css'

CKEDITOR.config.toolbar = 'CT';

Suggestion for support of filtering nodes in findAndReplaceDOMText

We have some static content that can be pasted into a CKEditor that we do not want to spellcheck. In other words, we simply just want certain nodes and their children to be ignored. Did the following to add some simple support to help our cause.

function findAndReplaceDOMText(regex, node, replacementNode, captureGroup, filter) {

    filter = filter || function() { return true; };
    var m, matches = [], text = _getText(node, filter);
    var replaceFn = _genReplacer(replacementNode, node);

    if (!text) { return; }

    if (regex.global) {
        while (!!(m = regex.exec(text))) {
            matches.push(_getMatchIndexes(m, captureGroup));
        }
    } else {
        m = text.match(regex);
        matches.push(_getMatchIndexes(m, captureGroup));
    }

    if (matches.length) {
        _stepThroughMatches(node, matches, replaceFn);
    }
}

function _getText(node, filter) {

    if (node.nodeType === 3) {
        return node.data;
    }

    var txt = '';

    if (!!(node = node.firstChild)) do {
        if (filter(node)) {
            txt += _getText(node, filter);
        }
    } while (!!(node = node.nextSibling));

    return txt;

}

EDIT: Was a bit quick here and forgot to add the filter callback in the recursive call.

Position no results text

It would be useful if we could position the no results text. At the moment, the fixed default behaviour is for the default no results text to be shown, followed by "[ENTERED TEXT]"

One potential workaround is to use CSS to reposition the span, but as the quotes are outside of the span they will remain at the end of the no results string.

Would be great if the quotes were put inside the span.

It can be done by removing the quotes from line 937 and adding them to the html call in 938.

Regular expression for replace fails with special characters

This is a verified issue, copied from: http://code.google.com/p/jquery-spellchecker/issues/detail?id=35#makechanges

What steps will reproduce the problem?

  1. Type "color(yellow)" into text area
  2. Run spellcheck through pspell

What is the expected output? What do you see instead?

JavaScript throws an error:
Uncaught SyntaxError: Invalid regular expression: /([^a-zA-Z\u00A1-\uFFFF])(colored(yellow)([^a-zA-Z\u00A1-\uFFFF])/: Unterminated group

on line 97.

What version of the product are you using? On what operating system?

Ubuntu Linux x64 - Chrome version Version 22.0.1229.94

Please provide any additional information below.

To resolve this issue the variable replaceWord needs to be escaped properly for the regular expression.

I added this line to 96:

replaceWord = (replaceWord+'').replace(/([.?*+^$[](){}|-])/g, "$1");

Delete comment

Calling SpellChecker.php remotely

Hi,

Have almost managed to integrate the spellchecker into a Redactor set-up.

I do though have one remaining issues, and I'm hoping you can offer some pointers.

I need to run the text editor with spellchecker on a page that is not PHP, sitting on a different server to where I have got spellchecker and the SpellChecker.php service installed. The spellcheck seems to work, but each time the check spelling button is pressed I can see that two AJAX calls are made:

The first one is a POST which returns the JSON object of mis-spelled words. This also returns a 301 moved permanently response.

A second request, this time a GET is then fired, which never completes - just sitting in the background waiting for a response.

On the server running the text editor, I am tunnelling the request throgh a proxy script to avoid cross-site scripting issues - posting directly to SpellChecker.php on the remote server.

Do you have any thoughts what might be causing the double firing of AJAX requests, or any pointers to how I could directly call SpellChecker.php from a remote server?

Is the "clean" function necessary?

Hello Richard,

I noticed the "clean" function here, and I was wondering if it is essential?
https://github.com/badsyntax/jquery-spellchecker/blob/master/src/js/jquery.spellchecker.js

The reason I am asking is because I am building a grammar checker here http://proofreadbot.com, and I need every punctuation etc. intact because I am matching stuff like "and , sue has running." not just single words.
So, I plan to comment out the clean function most likely, but I am unsure of the repercussions.

So far, I have used afterthedeadline js code, but yours is so much better. :)

word does not check properly

Go to the demo here: http://jquery-spellchecker.badsyntax.co/ckeditor.html

All of the issues can be seen by looking at the misspelt word "consequencse's"

Turn on spell checking mode and then:

Click on the word and try ignoring it, notice that it won't let you.

Next try selecting the first suggested correction. The word will change now turn off and turn back on spell check. Notice the word is still shown as being misspelt.

Note this was tested on chrome Version 25.0.1364.152 m

Suggested words

I have noticed that the spell checker only offers 5 options. It would be useful to have an option with "more suggestions" after "ignore word" since in my mother tongue (Hungarian) these options are not always enough due to our accents. Thanks, the HUN

Ignore word

I've tested out the demo of this spellchecker in CKEditor and I clicked ignore word on the word consequencse's. Nothing happened. The red text and underline should've been gone.

spell checker doesnt play well with multiple tiny_mce instances on the same page

spelling

I have been successfully using the jquery spellchecker plugin in several other areas of a site. However when I loaded several of them onto a page things quickly went bonkers. If you check the spelling in more than one box at a time the checker quickly gets confused and will freeze or unfreeze the pane on both boxes instead of the one you are working with.

I would guess that the issue at hand is somewhere in the top level jquery.spellchecker.js include that is watching for activity.

Full unicode support

We need to support Unicode character sets. Unfortunately Javascript doesn't make it easy to work with Unicode character sets, so we should consider using http://xregexp.com/.

After some initial testing, it appears the xRegExp library fits the job, but there are certain decisions we need to make before properly integrating it.

The spellchecker plugin currently relies on sending a string of words to the back-end service/s. This means we need to strip punctuation from the string of text. Determining what is punctuation is the difficult part.

The RegExp library gives us the \p{P} (unicode punctuation regexp category) but we don't want to strip punctuation that forms part of a word, eg "Here's". I can't even being to decide on how to handle this for languages other than English.

I suggest we have a look at existing spellcheckers to determine how others handle this to come to a decision. The solution has to be generic for all languages.

I'm making changes related to Unicode support the unicode-support branch.

Any advice or suggestions would be greatly appreciated.

Legacy Version for PHP 5.2

Is there a legacy version of the webservices available for PHP 5.2? Due to some other software we run on our server I cannot upgrade to 5.3+ until a serious patch/upgrade is issued later this year.

CKEditor issues

I tried integrating this with CKEditor and found a lot of issues. So much so that I couldn't use it. I was switching from Redactor over to CKeditor.

  • Once the content becomes greater than the size of the editor, the suggest box positioning is wrong.
  • Once the content becomes greater than the size of the editor, the selected word is wrong (big one).

I had implemented a .Net backend for this which worked with Redactor, but since it doesn't work with CKEditor I am forced to used another provider.

JS in textarea executes

No biggy, as I'd only be XSS'ing myself (wouldn't I?) but seems to execute before the clean method is called.

Screen shot 2013-04-05 at 16 50 24

Happy to fix, should pull requests me made against the develop branch?

hangs on loading when null returned.

Clicking on a miss spelt word that has no suggestion is returning null, this is generating a TypeError : word is null @ line 305 in jquery.spellchecker.js

(function() {

var toggle = (function() {
var fields = $('input:text,textarea');
var spellchecker = null;

function showPopover() {
$('.popover').hide().find('.popover-content').each(function(){
if ($(this).find('a').length) {
$(this).parents('.popover').show();
return false;
}
});
}

function create() {

spellchecker = new $.SpellChecker(fields, {
lang: 'en_GB',
parser: 'text',
webservice: {
path: 'webservices/php/SpellChecker.php',
driver: 'enchant'
},
local: {
    requestError: 'There was an error processing the request.',
    ignoreWord: 'Ignore word',
    ignoreAll: 'Ignore all',
    loading: 'Loading...',
    noSuggestions: '(No suggestions)'
},
suggestBox: {
position: 'below'
},
incorrectWords: {
position: function(container) {
this.after(container);
}
}
});

spellchecker.on('check.success', function() {
alert('There are no incorrectly spelt words.');
});

spellchecker.on('check.fail', function() {

fields.each(function() {
var field = $(this);

if (field.data('popover')) {
return;
}
field.popover({
trigger: 'manual',
placement: 'bottom',
title: '<i class="icon-info-sign"></i> Spelling errors'
})
.popover('show')
.data('popover')
.$tip
.find('.popover-content')
.append(field.next());
});
showPopover();
});

spellchecker.on('replace.word', function(incorrectWords) {
showPopover();
});

spellchecker.check();
}

function destroy() {
spellchecker.destroy();
spellchecker = null;
fields.popover('destroy');
}

function toggle() {
(!spellchecker) ? create() : destroy();
}
return toggle;
})();

// Check the spelling
$("#spellcheck").click(toggle);
})();
</script>

Ampersands in Google's XML

Not a problem with the plugin, but seems there is still an issue with ampersands in the XML from Google.

See here:

http://code.google.com/p/google-api-spelling-java/issues/detail?id=1

Might be worth patching with something like this while Google sort themselves out ๐Ÿ˜‰

// Line 75 spellchecker/driver/google.php
$google_xml_response = curl_exec($ch);  

$clean_xml = str_replace('&', '&#038;', $google_xml_response);
$xml = simplexml_load_string($clean_xml);

defaultConfig is rewritten upon creating a spellchecker

In the constructor for Spellchecker, the following code can be found

this.config = $.extend(true, defaultConfig, config);

This rewrites the defaultConfig with the values of config. It is solved by creating a copy first to extend from;

    var defaultConfigCopy = $.extend(true, {}, defaultConfig);
    this.config = $.extend(true, defaultConfigCopy, config);

EDIT: Missed true parameter for deep copy

Apostrophe's aren't handled correctly

If you use the online demo, and enter a valid word that has an apostrophe, like "It's", it will be flagged as a misspelled word. It appears to be an escaping problem (i tried this on chrome)...

Spellchecking will not work in Native IE7 in CKEditor

When turning spellchecking on it will result in "Invalid argument" for IE7. This is because the findAndReplaceDOMText creates replacements nodes within the top document and tries to insert that into the iframe of editor. To solve this problem, you simply have to use owning document where the node will be placed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.