source: Dev/trunk/src/client/dojox/editor/plugins/_SpellCheckParser.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 1.6 KB
Line 
1define([
2        "dojo",
3        "dojox",
4        "dojo/_base/connect",
5        "dojo/_base/declare"
6], function(dojo, dojox) {
7
8var SpellCheckParser = dojo.declare("dojox.editor.plugins._SpellCheckParser", null, {
9        lang: "english",
10       
11        parseIntoWords: function(/*String*/ text){
12                // summary:
13                //              Parse the text into words
14                // text:
15                //              Plain text without html tags
16                // tags:
17                //              public
18                // returns:
19                //              Array holding all the words
20                function isCharExt(c){
21                        var ch = c.charCodeAt(0);
22                        return 48 <= ch && ch <= 57 || 65 <= ch && ch <= 90 || 97 <= ch && ch <= 122;
23                }
24                var words = this.words = [],
25                        indices = this.indices = [],
26                        index = 0,
27                        length = text && text.length,
28                        start = 0;
29               
30                while(index < length){
31                        var ch;
32                        // Skip the white character and need to treat HTML entity respectively
33                        while(index < length && !isCharExt(ch = text.charAt(index)) && ch != "&"){ index++; }
34                        if(ch == "&"){ // An HTML entity, skip it
35                                while(++index < length && (ch = text.charAt(index)) != ";" && isCharExt(ch)){}
36                        }else{ // A word
37                                start = index;
38                                while(++index < length && isCharExt(text.charAt(index))){}
39                                if(start < length){
40                                        words.push(text.substring(start, index));
41                                        indices.push(start);
42                                }
43                        }
44                }
45               
46                return words;
47        },
48       
49        getIndices: function(){
50                // summary:
51                //              Get the indices of the words. They are in one-to-one correspondence
52                // tags:
53                //              public
54                // returns:
55                //              Index array
56                return this.indices;
57        }
58});
59
60// Register this parser in the SpellCheck plugin.
61dojo.subscribe(dijit._scopeName + ".Editor.plugin.SpellCheck.getParser", null, function(sp){
62        if(sp.parser){ return; }
63        sp.parser = new SpellCheckParser();
64});
65
66return SpellCheckParser;
67
68});
Note: See TracBrowser for help on using the repository browser.