From f24bc0fb1f63e7f5e38014d7191a4fe69d4179f0 Mon Sep 17 00:00:00 2001 From: Scott González Date: Thu, 15 Jul 2010 10:26:00 -0400 Subject: Widget: Deep extend options when creating a new plugin. Fixes #5830 - Widget: Using inheritance overwrites the base classes options. --- ui/jquery.ui.widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index 1014c607a..265489866 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -57,7 +57,7 @@ $.widget = function( name, base, prototype ) { // basePrototype[ key ] = $.extend( {}, val ); // } // }); - basePrototype.options = $.extend( {}, basePrototype.options ); + basePrototype.options = $.extend( true, {}, basePrototype.options ); $[ namespace ][ name ].prototype = $.extend( true, basePrototype, { namespace: namespace, widgetName: name, -- cgit v1.2.3 From 4ad7154beeaf4d299c4d879c88cbc235b65dceef Mon Sep 17 00:00:00 2001 From: Scott González Date: Fri, 16 Jul 2010 08:54:50 -0400 Subject: Dialog: Fixed whitespace. --- ui/jquery.ui.dialog.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index dc2559e9d..df896e7ea 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -59,6 +59,7 @@ $.widget("ui.dialog", { width: 300, zIndex: 1000 }, + _create: function() { this.originalTitle = this.element.attr('title'); // #5742 - .attr() might return a DOMElement @@ -177,6 +178,7 @@ $.widget("ui.dialog", { uiDialog.bgiframe(); } }, + _init: function() { if ( this.options.autoOpen ) { this.open(); @@ -203,7 +205,7 @@ $.widget("ui.dialog", { return self; }, - + widget: function() { return this.uiDialog; }, @@ -258,12 +260,12 @@ $.widget("ui.dialog", { var self = this, options = self.options, saveScroll; - + if ((options.modal && !force) || (!options.stack && !options.modal)) { return self._trigger('focus', event); } - + if (options.zIndex > $.ui.dialog.maxZ) { $.ui.dialog.maxZ = options.zIndex; } @@ -305,11 +307,11 @@ $.widget("ui.dialog", { if (event.keyCode !== $.ui.keyCode.TAB) { return; } - + var tabbables = $(':tabbable', this), first = tabbables.filter(':first'), last = tabbables.filter(':last'); - + if (event.target === last[0] && !event.shiftKey) { first.focus(1); return false; @@ -461,7 +463,6 @@ $.widget("ui.dialog", { } }, - _position: function(position) { var myAt = [], offset = [0, 0], @@ -484,14 +485,14 @@ $.widget("ui.dialog", { myAt[i] = offsetPosition; } }); - + position = { my: myAt.join(" "), at: myAt.join(" "), offset: offset.join(" ") }; } - + position = $.extend({}, $.ui.dialog.prototype.options.position, position); } else { position = $.ui.dialog.prototype.options.position; @@ -516,7 +517,7 @@ $.widget("ui.dialog", { uiDialog = self.uiDialog, isResizable = uiDialog.is(':data(resizable)'), resize = false; - + switch (key) { //handling of deprecated beforeclose (vs beforeClose) option //Ticket #4669 http://dev.jqueryui.com/ticket/4669 -- cgit v1.2.3 From 141748788b034e97337ee7d9d137153c445097fd Mon Sep 17 00:00:00 2001 From: kobrigo Date: Wed, 16 Jun 2010 04:38:19 -0700 Subject: Fixed argument shifting for effects. Fixes #5731 - hide and show called with ommiting the options in parameters does not call the callback. --- ui/jquery.effects.core.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ui') diff --git a/ui/jquery.effects.core.js b/ui/jquery.effects.core.js index f4fca9f93..801b57e4c 100644 --- a/ui/jquery.effects.core.js +++ b/ui/jquery.effects.core.js @@ -418,15 +418,15 @@ function _normalizeArguments(effect, options, speed, callback) { speed = null; options = {}; } - if ($.isFunction(speed)) { - callback = speed; - speed = null; - } - if (typeof options == 'number' || $.fx.speeds[options]) { + if (typeof options == 'number' || $.fx.speeds[options]) { callback = speed; speed = options; options = {}; } + if ($.isFunction(speed)) { + callback = speed; + speed = null; + } options = options || {}; -- cgit v1.2.3 From 70481d9febd1b904577d2d5f4345e5a0e79a59f7 Mon Sep 17 00:00:00 2001 From: Scott González Date: Fri, 16 Jul 2010 11:48:40 -0400 Subject: Button: Restrict DOM querying to labels. Fixes #5810 - Buttonset and applet error. --- ui/jquery.ui.button.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/jquery.ui.button.js b/ui/jquery.ui.button.js index db8c8b27b..b2fab4d24 100644 --- a/ui/jquery.ui.button.js +++ b/ui/jquery.ui.button.js @@ -196,7 +196,7 @@ $.widget( "ui.button", { // we don't search against the document in case the element // is disconnected from the DOM this.buttonElement = this.element.parents().last() - .find( "[for=" + this.element.attr("id") + "]" ); + .find( "label[for=" + this.element.attr("id") + "]" ); this.element.addClass( "ui-helper-hidden-accessible" ); var checked = this.element.is( ":checked" ); -- cgit v1.2.3 From fde8c64fd37d6700e174ccf5ea1574e418db2c1e Mon Sep 17 00:00:00 2001 From: Tiago Freire Date: Fri, 16 Jul 2010 13:37:54 -0300 Subject: Tabs: Added ability to reference tabs by href. Fixes #3171 - have option to remove tab by href content, not just by index. --- ui/jquery.ui.tabs.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 2d258d1d2..27754e539 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -413,6 +413,20 @@ $.widget("ui.tabs", { }, + _getIndex: function(index) { + // meta-function to give users option to provide a href string instead of a numerical index. + // also sanitizes numerical indexes to valid values. + if (typeof(index) == 'string') { + index = this.anchors.index(this.anchors.filter('[href$=' + index + ']')); + index = (index ==-1?NaN:index); + }else if (typeof(index) != 'number') { + index = NaN; + }else if (index > this.anchors.length) { + index = this.anchors.length; + } + return index; + }, + destroy: function() { var o = this.options; @@ -512,6 +526,7 @@ $.widget("ui.tabs", { }, remove: function(index) { + index = this._getIndex(index); var o = this.options, $li = this.lis.eq(index).remove(), $panel = this.panels.eq(index).remove(); @@ -532,6 +547,7 @@ $.widget("ui.tabs", { }, enable: function(index) { + index = this._getIndex(index); var o = this.options; if ($.inArray(index, o.disabled) == -1) { return; @@ -546,6 +562,7 @@ $.widget("ui.tabs", { }, disable: function(index) { + index = this._getIndex(index); var self = this, o = this.options; if (index != o.selected) { // cannot disable already selected tab this.lis.eq(index).addClass('ui-state-disabled'); @@ -561,9 +578,7 @@ $.widget("ui.tabs", { }, select: function(index) { - if (typeof index == 'string') { - index = this.anchors.index(this.anchors.filter('[href$=' + index + ']')); - } + index = this._getIndex(index); else if (index === null) { // usage of null is deprecated, TODO remove in next release index = -1; } @@ -576,6 +591,7 @@ $.widget("ui.tabs", { }, load: function(index) { + index = this._getIndex(index); var self = this, o = this.options, a = this.anchors.eq(index)[0], url = $.data(a, 'load.tabs'); this.abort(); -- cgit v1.2.3 From f448c79c01ef192fd71dce6ac5279e7795a8e417 Mon Sep 17 00:00:00 2001 From: Scott González Date: Fri, 16 Jul 2010 13:40:11 -0400 Subject: Accordion: Use .addClass() instead of .toggleClass() during init so the classes can be added by the user. --- ui/jquery.ui.accordion.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ui') diff --git a/ui/jquery.ui.accordion.js b/ui/jquery.ui.accordion.js index fd6331026..1d13e9566 100644 --- a/ui/jquery.ui.accordion.js +++ b/ui/jquery.ui.accordion.js @@ -79,7 +79,9 @@ $.widget("ui.accordion", { } } - this.active = this._findActive(this.active || o.active).toggleClass("ui-state-default").toggleClass("ui-state-active").toggleClass("ui-corner-all").toggleClass("ui-corner-top"); + this.active = this._findActive(this.active || o.active) + .addClass("ui-state-default ui-state-active") + .toggleClass("ui-corner-all ui-corner-top"); this.active.next().addClass('ui-accordion-content-active'); //Append icon elements -- cgit v1.2.3 From ba749ba6836d4889f18166a1207d5eeccddf7083 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 10 Jun 2010 12:01:56 -0300 Subject: Datepicker: Fixed pt-BR translation. Fixes #5363 - Error in datepicker translation for pt-BR. --- ui/i18n/jquery.ui.datepicker-pt-BR.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ui') diff --git a/ui/i18n/jquery.ui.datepicker-pt-BR.js b/ui/i18n/jquery.ui.datepicker-pt-BR.js index 38818637d..3cc8c796c 100644 --- a/ui/i18n/jquery.ui.datepicker-pt-BR.js +++ b/ui/i18n/jquery.ui.datepicker-pt-BR.js @@ -10,9 +10,9 @@ jQuery(function($){ 'Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'], monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun', 'Jul','Ago','Set','Out','Nov','Dez'], - dayNames: ['Domingo','Segunda-feira','Terça-feira','Quarta-feira','Quinta-feira','Sexta-feira','Sabado'], - dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'], - dayNamesMin: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'], + dayNames: ['Domingo','Segunda-feira','Terça-feira','Quarta-feira','Quinta-feira','Sexta-feira','Sábado'], + dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb'], + dayNamesMin: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb'], weekHeader: 'Sm', dateFormat: 'dd/mm/yy', firstDay: 0, -- cgit v1.2.3 From 325a262b14aa41be9bda584d770eedbde47297b6 Mon Sep 17 00:00:00 2001 From: Scott González Date: Fri, 16 Jul 2010 14:12:06 -0400 Subject: Autocomplete: Use .outerWidth() for determining the size of the menu. Fixes #5832 - Autocomplete: menu has incorrect width. --- ui/jquery.ui.autocomplete.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 1a51baa8d..3fa196ecb 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -276,9 +276,13 @@ $.widget( "ui.autocomplete", { collision: "none" }); - menuWidth = ul.width( "" ).width(); - textWidth = this.element.width(); - ul.width( Math.max( menuWidth, textWidth ) ); + menuWidth = ul.width( "" ).outerWidth(); + textWidth = this.element.outerWidth(); + ul.width( Math.max( menuWidth, textWidth ) + - ( parseFloat( ul.css("paddingLeft") ) || 0 ) + - ( parseFloat( ul.css("paddingRight") ) || 0 ) + - ( parseFloat( ul.css("borderLeftWidth") ) || 0 ) + - ( parseFloat( ul.css("borderRightWidth") ) || 0 ) ); }, _renderMenu: function( ul, items ) { -- cgit v1.2.3 From 9d01ab564525f9112c2488ad257637593062b70d Mon Sep 17 00:00:00 2001 From: Holger Rüprich Date: Mon, 5 Jul 2010 06:29:09 +0800 Subject: Sortable: Return an empty URL param for empty sortable lists. Fixed #5794 - sortable("serialize", {key: "foo[]"}) returns an empty string for an empty list --- ui/jquery.ui.sortable.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ui') diff --git a/ui/jquery.ui.sortable.js b/ui/jquery.ui.sortable.js index a51f543c5..6cc2434e8 100644 --- a/ui/jquery.ui.sortable.js +++ b/ui/jquery.ui.sortable.js @@ -409,6 +409,10 @@ $.widget("ui.sortable", $.ui.mouse, { if(res) str.push((o.key || res[1]+'[]')+'='+(o.key && o.expression ? res[1] : res[2])); }); + if(!str.length && o.key) { + str.push(o.key + '='); + } + return str.join('&'); }, -- cgit v1.2.3 From 64d90b4a710d520a44408ccfa8df1100b0b95b4d Mon Sep 17 00:00:00 2001 From: Scott González Date: Fri, 16 Jul 2010 16:57:04 -0400 Subject: Dialog: Adjusted logic for finding the first tabbable element. Fixes #5767 - On open, the first tabbable element inside the dialog was never being focused in favor of the dialog container. --- ui/jquery.ui.dialog.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index df896e7ea..ae96b2d8b 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -324,12 +324,9 @@ $.widget("ui.dialog", { // set focus to the first tabbable element in the content area or the first button // if there are no tabbable elements, set focus on the dialog itself - $([]) - .add(uiDialog.find('.ui-dialog-content :tabbable:first')) - .add(uiDialog.find('.ui-dialog-buttonpane :tabbable:first')) - .add(uiDialog) - .filter(':first') - .focus(); + $(self.element.find(':tabbable').get().concat( + uiDialog.find('.ui-dialog-buttonpane :tabbable').get().concat( + uiDialog.get()))).eq(0).focus(); self._trigger('open'); self._isOpen = true; -- cgit v1.2.3 From eaddfedd668c3397ed3c39d733d57d9c78466633 Mon Sep 17 00:00:00 2001 From: Tiago Freire Date: Fri, 16 Jul 2010 18:10:57 -0300 Subject: Tabs: Fixed a broken commit for #3171. --- ui/jquery.ui.tabs.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 27754e539..2a12cb540 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -579,13 +579,9 @@ $.widget("ui.tabs", { select: function(index) { index = this._getIndex(index); - else if (index === null) { // usage of null is deprecated, TODO remove in next release - index = -1; - } - if (index == -1 && this.options.collapsible) { + if (isNaN(index) && this.options.collapsible) { index = this.options.selected; } - this.anchors.eq(index).trigger(this.options.event + '.tabs'); return this; }, -- cgit v1.2.3 From 7e03d4ea9deee68e928651ef80c6c673c479b88d Mon Sep 17 00:00:00 2001 From: Scott González Date: Fri, 16 Jul 2010 20:20:28 -0400 Subject: Tabs: Updated tests. --- tests/unit/tabs/tabs.html | 3 ++- tests/unit/tabs/tabs_methods.js | 11 +---------- ui/jquery.ui.tabs.js | 10 +++------- 3 files changed, 6 insertions(+), 18 deletions(-) (limited to 'ui') diff --git a/tests/unit/tabs/tabs.html b/tests/unit/tabs/tabs.html index 269f47ed5..211237569 100644 --- a/tests/unit/tabs/tabs.html +++ b/tests/unit/tabs/tabs.html @@ -15,7 +15,8 @@ - + + diff --git a/tests/unit/tabs/tabs_methods.js b/tests/unit/tabs/tabs_methods.js index 3eb627830..3812c3e91 100644 --- a/tests/unit/tabs/tabs_methods.js +++ b/tests/unit/tabs/tabs_methods.js @@ -97,7 +97,7 @@ test('remove', function() { }); test('select', function() { - expect(9); + expect(6); el = $('#tabs1').tabs(); @@ -114,21 +114,12 @@ test('select', function() { el.tabs('select', -1); equals(el.tabs('option', 'selected'), -1, 'should collapse tab passing in -1'); - el.tabs('destroy'); - el.tabs({ collapsible: true }); - el.tabs('select', null); - equals(el.tabs('option', 'selected'), -1, 'should collapse tab passing in null (deprecated)'); - el.tabs('select', null); - equals(el.tabs('option', 'selected'), -1, 'should not select tab passing in null a second time (deprecated)'); - el.tabs('destroy'); el.tabs(); el.tabs('select', 0); equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if collapsible is not set to true'); el.tabs('select', -1); equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if collapsible is not set to true'); - el.tabs('select', null); - equals(el.tabs('option', 'selected'), 0, 'should not collapse tab if collapsible is not set to true'); el.tabs('select', '#fragment-2'); equals(el.tabs('option', 'selected'), 1, 'should select tab by id'); diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 2a12cb540..592f1a866 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -416,14 +416,10 @@ $.widget("ui.tabs", { _getIndex: function(index) { // meta-function to give users option to provide a href string instead of a numerical index. // also sanitizes numerical indexes to valid values. - if (typeof(index) == 'string') { + if (typeof index == 'string') { index = this.anchors.index(this.anchors.filter('[href$=' + index + ']')); - index = (index ==-1?NaN:index); - }else if (typeof(index) != 'number') { - index = NaN; - }else if (index > this.anchors.length) { - index = this.anchors.length; } + return index; }, @@ -579,7 +575,7 @@ $.widget("ui.tabs", { select: function(index) { index = this._getIndex(index); - if (isNaN(index) && this.options.collapsible) { + if (index == -1 && this.options.collapsible) { index = this.options.selected; } this.anchors.eq(index).trigger(this.options.event + '.tabs'); -- cgit v1.2.3 From 5435c50765e89f5cfb1c164dda6642c2149dc4db Mon Sep 17 00:00:00 2001 From: Scott González Date: Sat, 17 Jul 2010 18:50:47 -0400 Subject: Tabs: Fixed select method handling for index of -1. --- ui/jquery.ui.tabs.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 592f1a866..5555b95f5 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -575,8 +575,12 @@ $.widget("ui.tabs", { select: function(index) { index = this._getIndex(index); - if (index == -1 && this.options.collapsible) { - index = this.options.selected; + if (index == -1) { + if (this.options.collapsible && this.options.selected != -1) { + index = this.options.selected; + } else { + return this; + } } this.anchors.eq(index).trigger(this.options.event + '.tabs'); return this; -- cgit v1.2.3 From 612838a1518c8cdc80b5bace5d925f89c1e791a3 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 19 Jul 2010 09:28:04 -0400 Subject: Autocomplete: Added position option. Fixes #5153 - Autocomplete position option. --- tests/unit/autocomplete/autocomplete_defaults.js | 7 ++++++- ui/jquery.ui.autocomplete.js | 17 ++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'ui') diff --git a/tests/unit/autocomplete/autocomplete_defaults.js b/tests/unit/autocomplete/autocomplete_defaults.js index c6017d62c..8dad15e8f 100644 --- a/tests/unit/autocomplete/autocomplete_defaults.js +++ b/tests/unit/autocomplete/autocomplete_defaults.js @@ -6,7 +6,12 @@ var autocomplete_defaults = { delay: 300, disabled: false, minLength: 1, - source: undefined + position: { + my: "left top", + at: "left bottom", + collision: "none" + }, + source: null }; commonWidgetTests('autocomplete', { defaults: autocomplete_defaults }); diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 3fa196ecb..1391643ba 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -16,8 +16,14 @@ $.widget( "ui.autocomplete", { options: { + delay: 300, minLength: 1, - delay: 300 + position: { + my: "left top", + at: "left bottom", + collision: "none" + }, + source: null }, _create: function() { var self = this, @@ -269,12 +275,9 @@ $.widget( "ui.autocomplete", { // TODO refresh should check if the active item is still in the dom, removing the need for a manual deactivate this.menu.deactivate(); this.menu.refresh(); - this.menu.element.show().position({ - my: "left top", - at: "left bottom", - of: this.element, - collision: "none" - }); + this.menu.element.show().position( $.extend({ + of: this.element + }, this.options.position )); menuWidth = ul.width( "" ).outerWidth(); textWidth = this.element.outerWidth(); -- cgit v1.2.3 From 5311fe22f327d275f6f8d885da1ce6bbc2c4a681 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 19 Jul 2010 11:51:05 -0400 Subject: Menu: Only look for .ui-menu-item elements to determine if a menu item is the first or last element in the menu. Fixes #5528 - Autocomplete: Issue when try to navigate using up key by keyboard in IE6. --- ui/jquery.ui.autocomplete.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 1391643ba..3f010c1f4 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -433,11 +433,11 @@ $.widget("ui.menu", { }, first: function() { - return this.active && !this.active.prev().length; + return this.active && !this.active.prevAll(".ui-menu-item").length; }, last: function() { - return this.active && !this.active.next().length; + return this.active && !this.active.nextAll(".ui-menu-item").length; }, move: function(direction, edge, event) { -- cgit v1.2.3 From 53489b502dc51edb7707de80ead77549bd529e3a Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 19 Jul 2010 14:36:40 -0400 Subject: Autocomplete: Don't update the value of the text field until after setting focus. Fixes #5639 - Cursor jumps to beginning on select. --- ui/jquery.ui.autocomplete.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 3f010c1f4..c25a8884f 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -132,9 +132,12 @@ $.widget( "ui.autocomplete", { } }, selected: function( event, ui ) { - var item = ui.item.data( "item.autocomplete" ); + var item = ui.item.data( "item.autocomplete" ), + setValue = false; if ( false !== self._trigger( "select", event, { item: item } ) ) { - self.element.val( item.value ); + // #5639 - if we set the value before setting focus + // the cursor will move to the beginning of the field in IE + setValue = true; } self.close( event ); // only trigger when focus was lost (click on menu) @@ -144,6 +147,9 @@ $.widget( "ui.autocomplete", { self.previous = previous; } self.selectedItem = item; + if ( setValue ) { + self.element.val( item.value ); + } }, blur: function( event, ui ) { if ( self.menu.element.is(":visible") ) { -- cgit v1.2.3 From 1f2cfb942f8ac5549b1fe3172501e3486415530e Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 19 Jul 2010 15:45:30 -0400 Subject: Autocomplete: Render items as text, not HTML. Fixes #5275 - suggestions are not html-encoded. As noted in the ticket, it's probably better to default to unstyled items to prevent problems. Users can still implement their own rendering method as shown in the custom data and display demo. --- demos/autocomplete/combobox.html | 6 ++++++ demos/autocomplete/search.php | 4 ++-- ui/jquery.ui.autocomplete.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'ui') diff --git a/demos/autocomplete/combobox.html b/demos/autocomplete/combobox.html index 10d165392..4cc98d8f9 100644 --- a/demos/autocomplete/combobox.html +++ b/demos/autocomplete/combobox.html @@ -54,6 +54,12 @@ minLength: 0 }) .addClass("ui-widget ui-widget-content ui-corner-left"); + input.data("autocomplete")._renderItem = function( ul, item) { + return $( "
  • " ) + .data( "item.autocomplete", item ) + .append( "" + item.label + "" ) + .appendTo( ul ); + }; $("") .attr("tabIndex", -1) .attr("title", "Show All Items") diff --git a/demos/autocomplete/search.php b/demos/autocomplete/search.php index 01206489a..8fa9d28f8 100644 --- a/demos/autocomplete/search.php +++ b/demos/autocomplete/search.php @@ -3,8 +3,8 @@ $q = strtolower($_GET["term"]); if (!$q) return; $items = array( -"Great Bittern"=>"Botaurus stellaris", -"Little Grebe"=>"Tachybaptus ruficollis", +"Great Bittern"=>"Botaurus stellaris", +"Little Grebe"=>"Tachybaptus ruficollis", "Black-necked Grebe"=>"Podiceps nigricollis", "Little Bittern"=>"Ixobrychus minutus", "Black-crowned Night Heron"=>"Nycticorax nycticorax", diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index c25a8884f..27bfe941c 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -304,7 +304,7 @@ $.widget( "ui.autocomplete", { _renderItem: function( ul, item) { return $( "
  • " ) .data( "item.autocomplete", item ) - .append( "" + item.label + "" ) + .append( $( "" ).text( item.label ) ) .appendTo( ul ); }, -- cgit v1.2.3