aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/demos/plaintextspellchecker.html
blob: 21ec0498c129196c5e90a41ed9c78cac78922b49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<title>Plain Text Spell Checker</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../base.js"></script>
<script type="text/javascript">
  goog.require('goog.ui.PlainTextSpellChecker');
</script>
<style type="text/css">

.goog-spellcheck-invalidword {
  background: yellow;
}

.goog-spellcheck-correctedword {
  background: green;
}

textarea, .goog-spellcheck-correctionpane {
  font: menu;
  font-size: 0.8em;
  border: 1px solid black;
  padding: 2px;
  margin: 0px;
  overflow: auto;
  line-height: 1.25em;
}

.goog-menu {
  position: absolute;
  color: #000;
  border: 1px solid #B5B6B5;
  background-color: #F3F3F7;
  cursor: default;
  font: normal small arial, helvetica, sans-serif;
  width: 25ex;
  outline: 0;
}

.goog-menuitem {
  padding: 2px 5px;
  position: relative;
}

.goog-menuitem-highlight {
  background-color: #4279A5;
  color: #FFF;
}

.goog-menuitem-disabled {
  background-color: #F3F3F7;
  color: #999;
}

.goog-menu hr {
  background-color: #999;
  height: 1px;
  border: 0px;
  margin: 0px;
}
</style>
</head>
<body>
<h1>Plain Text Spell Checker</h1>
<p>

  <textarea id="t0" style="width: 50ex; height: 15em;"></textarea>


</p>

<button onclick="s.check();">check</button>
<button onclick="s.resume();">resume</button>

<script type="text/javascript">

  function localSpellCheckingFunction(words, spellChecker, callback) {
    var len = words.length;
    var results = [];
    for (var i = 0; i < len; i++) {
      var word = words[i];
      if (word == 'test' || word == 'words' || word == 'a' || word == 'few') {
        results.push([word, goog.spell.SpellCheck.WordStatus.VALID]);
      } else {
        results.push([word, goog.spell.SpellCheck.WordStatus.INVALID,
            ['foo', 'bar', 'test']]);
      }
    }
    callback.call(spellChecker, results);
  }

  var handler = new goog.spell.SpellCheck(localSpellCheckingFunction);
  var s = new goog.ui.PlainTextSpellChecker(handler);
  s.markCorrected = true;
  s.decorate(document.getElementById('t0'));
</script>
</body>
</html>