Permalink
Browse files

Added :select option for JavaScriptMacroHelper#auto_complete_field th…

…at makes it easier to only use part of the auto-complete suggestion as the value for insertion [Thomas Fuchs]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3348 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent d4e02f7 commit cfb0babec348a5543ae4c4a8c2c5e4438644429e @dhh dhh committed Dec 24, 2005
@@ -221,13 +221,14 @@ Autocompleter.Base.prototype = {
this.options.updateElement(selectedElement);
return;
}
+
var value = '';
if (this.options.select) {
var nodes = document.getElementsByClassName(this.options.select, selectedElement) || [];
if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
} else
value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
-
+
var lastTokenPos = this.findLastToken();
if (lastTokenPos != -1) {
var newValue = this.element.value.substr(0, lastTokenPos + 1);
@@ -22,7 +22,7 @@ String.prototype.parseColor = function() {
}
}
return(color.length==7 ? color : (arguments[0] || this));
-}
+}
Element.collectTextNodes = function(element) {
return $A($(element).childNodes).collect( function(node) {
@@ -39,6 +39,7 @@ Element.collectTextNodesIgnoreClass = function(element, className) {
}).flatten().join('');
}
+
Element.setStyle = function(element, style) {
element = $(element);
for(k in style) element.style[k.camelize()] = style[k];
@@ -222,7 +222,13 @@ Autocompleter.Base.prototype = {
return;
}
- var value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
+ var value = '';
+ if (this.options.select) {
+ var nodes = document.getElementsByClassName(this.options.select, selectedElement) || [];
+ if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
+ } else
+ value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
+
var lastTokenPos = this.findLastToken();
if (lastTokenPos != -1) {
var newValue = this.element.value.substr(0, lastTokenPos + 1);
@@ -24,23 +24,22 @@ String.prototype.parseColor = function() {
return(color.length==7 ? color : (arguments[0] || this));
}
-Element.collectTextNodesIgnoreClass = function(element, ignoreclass) {
- var children = $(element).childNodes;
- var text = '';
- var classtest = new RegExp('^([^ ]+ )*' + ignoreclass+ '( [^ ]+)*$','i');
-
- for (var i = 0; i < children.length; i++) {
- if(children[i].nodeType==3) {
- text+=children[i].nodeValue;
- } else {
- if((!children[i].className.match(classtest)) && children[i].hasChildNodes())
- text += Element.collectTextNodesIgnoreClass(children[i], ignoreclass);
- }
- }
-
- return text;
+Element.collectTextNodes = function(element) {
+ return $A($(element).childNodes).collect( function(node) {
+ return (node.nodeType==3 ? node.nodeValue :
+ (node.hasChildNodes() ? Element.collectTextNodes(node) : ''));
+ }).flatten().join('');
}
+Element.collectTextNodesIgnoreClass = function(element, className) {
+ return $A($(element).childNodes).collect( function(node) {
+ return (node.nodeType==3 ? node.nodeValue :
+ ((node.hasChildNodes() && !Element.hasClassName(node,className)) ?
+ Element.collectTextNodes(node) : ''));
+ }).flatten().join('');
+}
+
+
Element.setStyle = function(element, style) {
element = $(element);
for(k in style) element.style[k.camelize()] = style[k];

0 comments on commit cfb0bab

Please sign in to comment.