diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-24 00:52:14 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-24 00:52:14 +0000 |
commit | 96536bebaefccabcbfb5ce9e689dd40c4fb4e294 (patch) | |
tree | 9000f9de158a5bce0ca7f6571637c1fa20361947 /actionpack/lib/action_view/helpers/javascripts | |
parent | af60120d30157837d92b02953e04131facd1f7de (diff) | |
download | rails-96536bebaefccabcbfb5ce9e689dd40c4fb4e294.tar.gz rails-96536bebaefccabcbfb5ce9e689dd40c4fb4e294.tar.bz2 rails-96536bebaefccabcbfb5ce9e689dd40c4fb4e294.zip |
Added :select option for JavaScriptMacroHelper#auto_complete_field that 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@3344 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascripts')
-rw-r--r-- | actionpack/lib/action_view/helpers/javascripts/controls.js | 9 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/javascripts/effects.js | 30 |
2 files changed, 21 insertions, 18 deletions
diff --git a/actionpack/lib/action_view/helpers/javascripts/controls.js b/actionpack/lib/action_view/helpers/javascripts/controls.js index 9742b69188..f13733d5f0 100644 --- a/actionpack/lib/action_view/helpers/javascripts/controls.js +++ b/actionpack/lib/action_view/helpers/javascripts/controls.js @@ -221,8 +221,13 @@ Autocompleter.Base.prototype = { this.options.updateElement(selectedElement); 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); diff --git a/actionpack/lib/action_view/helpers/javascripts/effects.js b/actionpack/lib/action_view/helpers/javascripts/effects.js index 414398ce47..ebca0c490a 100644 --- a/actionpack/lib/action_view/helpers/javascripts/effects.js +++ b/actionpack/lib/action_view/helpers/javascripts/effects.js @@ -22,23 +22,21 @@ 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) { |