github github
  • Home
  • Pricing and Signup
  • Training
  • Gist
  • Blog
  • Login

jquery / jquery-ui

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 920
    • 212
  • Source
  • Commits
  • Network (212)
  • Graphs
  • Tree: 74e0d4f

click here to add a description

click here to add a homepage

  • Switch Branches (8)
    • bind
    • devpreview
    • formcontrols
    • master
    • menu
    • panel
    • tooltip
    • widget-super
  • Switch Tags (21)
    • 1.9m2
    • 1.9m1
    • 1.8rc3
    • 1.8rc2
    • 1.8rc1
    • 1.8b1
    • 1.8a2
    • 1.8a1
    • 1.8.4
    • 1.8.3
    • 1.8.2
    • 1.8.1
    • 1.8
    • 1.7
    • 1.6rc6
    • 1.6rc5
    • 1.6rc3
    • 1.6rc2
    • 1.6
    • 1.5.2
    • 1.5.1
  • Comments
  • Contributors
Sending Request…

The official jQuery user interface library. — Read more

  Cancel

http://jqueryui.com/

  Cancel
  • HTTP
  • Git Read-Only

This URL has Read+Write access

Autocomplete: Added appendTo option. Fixes #5836 - Autocomplete: add appendTo option.
scottgonzalez (author)
Wed Jul 21 11:54:20 -0700 2010
commit  74e0d4f47301ff854ec7
tree    4e1f72f466b488f39648
parent  245b93293335e916771a
M tests/unit/autocomplete/autocomplete.html 4 ••••
M tests/unit/autocomplete/autocomplete_defaults.js 1 •
M tests/unit/autocomplete/autocomplete_options.js 30 •••••
M ui/jquery.ui.autocomplete.js 8 ••••
Txt tests/unit/autocomplete/autocomplete.html
  • View file @ 74e0d4f
... ...
@@ -36,8 +36,8 @@
36 36
 
37 37
 <div id="main" style="position: absolute; top: -10000px; left: -10000px;">
38 38
 
39  
-  <div><input id="autocomplete" class="foo" /></div>
40  
-
  39
+  <div id="ac-wrap1" class="ac-wrap"></div>
  40
+  <div id="ac-wrap2" class="ac-wrap"><input id="autocomplete" class="foo" /></div>
41 41
 </div>
42 42
 
43 43
 </body>
Txt tests/unit/autocomplete/autocomplete_defaults.js
  • View file @ 74e0d4f
... ...
@@ -3,6 +3,7 @@
3 3
  */
4 4
 
5 5
 var autocomplete_defaults = {
  6
+  appendTo: "body",
6 7
   delay: 300,
7 8
   disabled: false,
8 9
   minLength: 1,
Txt tests/unit/autocomplete/autocomplete_options.js
  • View file @ 74e0d4f
... ...
@@ -68,6 +68,36 @@ test("cache: false", function() {
68 68
 
69 69
 var data = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl"];
70 70
 
  71
+test( "appendTo", function() {
  72
+  var ac = $( "#autocomplete" ).autocomplete();
  73
+  same( ac.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" );
  74
+  ac.autocomplete( "destroy" );
  75
+
  76
+  ac.autocomplete({
  77
+    appendTo: "#ac-wrap2"
  78
+  });
  79
+  same( ac.autocomplete( "widget" ).parent()[0], $( "#ac-wrap2" )[0], "id" );
  80
+  ac.autocomplete( "destroy" );
  81
+
  82
+  ac.autocomplete({
  83
+    appendTo: ".ac-wrap"
  84
+  });
  85
+  same( ac.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "class" );
  86
+  same( $( "#ac-wrap2 .ui-autocomplete").length, 0, "class - only appends to one element")
  87
+  ac.autocomplete( "destroy" );
  88
+
  89
+  ac.autocomplete({
  90
+    appendTo: null
  91
+  });
  92
+  same( ac.autocomplete( "widget" ).parent()[0], document.body, "null" );
  93
+  ac.autocomplete( "destroy" );
  94
+  
  95
+  ac.autocomplete().autocomplete( "option", "appendTo", "#ac-wrap1" );
  96
+  same( ac.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "modified after init" );
  97
+  ac.autocomplete( "destroy" );
  98
+});
  99
+
  100
+
71 101
 test("delay", function() {
72 102
   var ac = $("#autocomplete").autocomplete({
73 103
     source: data,
Txt ui/jquery.ui.autocomplete.js
  • View file @ 74e0d4f
... ...
@@ -16,6 +16,7 @@
16 16
 
17 17
 $.widget( "ui.autocomplete", {
18 18
   options: {
  19
+    appendTo: "body",
19 20
     delay: 300,
20 21
     minLength: 1,
21 22
     position: {
... ...
@@ -104,7 +105,7 @@ $.widget( "ui.autocomplete", {
104 105
     };
105 106
     this.menu = $( "<ul></ul>" )
106 107
       .addClass( "ui-autocomplete" )
107  
-      .appendTo( "body", doc )
  108
+      .appendTo( $( this.options.appendTo || "body", doc )[0] )
108 109
       // prevent the close-on-blur in case of a "slow" click on the menu (long mousedown)
109 110
       .mousedown(function() {
110 111
         // use another timeout to make sure the blur-event-handler on the input was already triggered
... ...
@@ -166,11 +167,14 @@ $.widget( "ui.autocomplete", {
166 167
     $.Widget.prototype.destroy.call( this );
167 168
   },
168 169
 
169  
-  _setOption: function( key ) {
  170
+  _setOption: function( key, value ) {
170 171
     $.Widget.prototype._setOption.apply( this, arguments );
171 172
     if ( key === "source" ) {
172 173
       this._initSource();
173 174
     }
  175
+    if ( key === "appendTo" ) {
  176
+      this.menu.element.appendTo( $( value || "body", this.element.ownerDocument )[0] )
  177
+    }
174 178
   },
175 179
 
176 180
   _initSource: function() {

0 notes on commit 74e0d4f

Please log in to comment.
Dedicated Server Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
  • Blog
  • Support
  • Training
  • Job Board
  • Shop
  • Contact
  • API
  • Status
  • © 2010 GitHub Inc. All rights reserved.
  • Terms of Service
  • Privacy
  • Security
  • English
  • Deutsch
  • Français
  • 日本語
  • Português (BR)
  • 中文
  • See all available languages

Your current locale selection: English. Choose another?

  • English
  • Afrikaans
  • Català
  • Čeština
  • Deutsch
  • Español
  • Français
  • Hrvatski
  • Indonesia
  • Italiano
  • 日本語
  • Nederlands
  • Norsk
  • Polski
  • Português (BR)
  • Српски
  • Svenska
  • 中文