Skip to content
Browse files

Merging with repo

  • Loading branch information...
2 parents b1c2402 + 2361bba commit d1965ab057b09e2747faf28e68ecd5018fdec3b3 @sergeche committed Jun 22, 2010
Showing with 141 additions and 15 deletions.
  1. +19 −0 .externalToolBuilders/Contewnt assist.launch
  2. +2 −0 .gitignore
  3. +10 −0 .project
  4. +3 −1 README
  5. +23 −0 build.xml
  6. +47 −2 index.html
  7. +37 −12 src/ContentAssistProcessor.js
View
19 .externalToolBuilders/Contewnt assist.launch
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
+<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
+<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
+<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${project}"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/tx-content-assist/build.xml"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
+<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
+<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="tx-content-assist"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/tx-content-assist/build.xml}"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value=""/>
+<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
+</launchConfiguration>
View
2 .gitignore
@@ -0,0 +1,2 @@
+/build
+.DS_Store
View
10 .project
@@ -10,6 +10,16 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
+ <triggers>full,incremental,</triggers>
+ <arguments>
+ <dictionary>
+ <key>LaunchConfigHandle</key>
+ <value>&lt;project&gt;/.externalToolBuilders/Contewnt assist.launch</value>
+ </dictionary>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
View
4 README
@@ -1,3 +1,5 @@
-Content assist support for textarea element. See demo here: http://media.chikuyonok.ru/content-assist/
+Content assist support for textarea element based on Eclipse IDE's concept. See demo here: http://media.chikuyonok.ru/content-assist/
+
+MIT license.
More documentation coming soon.
View
23 build.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="content-assist" basedir="./" default="main">
+ <import file="${webtasks_path}"/>
+
+ <property name="js.dir" value="./build"/>
+ <property name="js-src.dir" value="./src"/>
+
+ <target name="main">
+ <mkdir dir="${js.dir}"/>
+ <compile-js-lib tofile="${js.dir}/content-assist.js">
+ <files>
+ <filelist dir="${js-src.dir}">
+ <file name="tx_utils.js" />
+ <file name="EventDispatcher.js" />
+ <file name="TextViewer.js" />
+ <file name="ContentAssist.js" />
+ <file name="ContentAssistProcessor.js" />
+ <file name="CompletionProposal.js" />
+ <file name="BasicContentAssist.js" />
+ </filelist>
+ </files>
+ </compile-js-lib>
+
View
49 index.html
@@ -1,2 +1,47 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Document</title>
+ <script type="text/javascript" src="./src/tx_utils.js"></script>
+ <script type="text/javascript" src="./src/EventDispatcher.js"></script>
+ <script type="text/javascript" src="./src/TextViewer.js"></script>
+ <script type="text/javascript" src="./src/ContentAssist.js"></script>
+ <script type="text/javascript" src="./src/ContentAssistProcessor.js"></script>
+ <script type="text/javascript" src="./src/CompletionProposal.js"></script>
+ <script type="text/javascript" src="./src/BasicContentAssist.js"></script>
+ <link rel="stylesheet" type="text/css" href="content-assist.css" media="all" />
+ <style type="text/css">
+ #wrap {
+ position:relative;
+ }
+
+ #input {
+ width:90%;
+ height:10em;
+ position:relative;
+ display:block;
+ }
+
+ #str {
+ width:50%;
+ margin-top:2em;
+ }
+ </style>
+ </head>
+ <body>
+ <p>Type a few words starting from "a": for example, "awesome", "amazing".</p>
+ <div id="wrap">
+ <textarea id="input"></textarea>
+ </div>
+
+ <input type="text" id="str" />
+
+ <script type="text/javascript">
+ var words = 'after,any,also,around,another,ask,again,air,away,animal,answer,america,awesome,amazing'.split(',');
+ new BasicContentAssist(document.getElementById('input'), words);
+ new BasicContentAssist(document.getElementById('str'), words);
+ </script>
+
+ </body>
+</html>
View
49 src/ContentAssistProcessor.js
@@ -8,7 +8,8 @@
*
* @include "TextViewer.js"
* @include "CompletitionProposal.js"
- */
+ */
+function ContentAssistProcessor(words) {
if (words)
this.setWords(words);
}
@@ -81,22 +82,41 @@ ContentAssistProcessor.prototype = {
return 'abcdefghijklmnopqrstuvwxyz!@$';
},
+ /**
+ * Check if passed character is allowed for word bounds
+ * @param {String} ch
+ * @return {Boolean}
+ */
isAllowedChar: function(ch) {
ch = String(ch);
if (!ch) return false;
-
- var char_code = ch.charCodeAt(0),
+ var re_ch = /[\s\.,\!\?\#%\^\$\(\)\{\}<>'"«»]/;
+ return !re_ch.test(ch);
-
- return (char_code > 64 && char_code < 91) // uppercase letter
- || (char_code > 96 && char_code < 123) // lowercase letter
- || (char_code > 47 && char_code < 58) // number
+// var char_code = ch.charCodeAt(0),
+// special_chars = ':@!.#-_';
+//
+// return (char_code > 64 && char_code < 91) // uppercase letter
+// || (char_code > 96 && char_code < 123) // lowercase letter
+// || (char_code > 47 && char_code < 58) // number
+// || special_chars.indexOf(ch) != -1; // special character
},
setWords: function(words) {
- setWords: function(words) {
+ // index words by first letter for faster search
+ var _w = {};
+ for (var i = 0, il = words.length; i < il; i++) {
+ var ch = words[i].toString().charAt(0);
+ if (!(ch in _w))
+ _w[ch] = [];
+
+ _w[ch].push(words[i]);
+ }
+
+
+ this.words = _w;
},
/**
@@ -109,10 +129,15 @@ ContentAssistProcessor.prototype = {
var result = [];
if (prefix && this.words) {
- if (prefix && this.words) {
- for (var i = 0, il = this.words.length; i < il; i++) {
- var word = this.words[i].toString();
- if (word.indexOf(prefix) === 0 && word.length > prefix.length)
+ var first_ch = prefix.charAt(0),
+ prefix_len = prefix.length;
+ if (first_ch in this.words) {
+ var words = this.words[first_ch];
+ for (var i = 0, il = words.length; i < il; i++) {
+ var word = words[i].toString();
+ if (word.indexOf(prefix) === 0 && word.length > prefix_len)
+ result.push(word);
+ }
}
}

0 comments on commit d1965ab

Please sign in to comment.
Something went wrong with that request. Please try again.