Changeset 3975

Show
Ignore:
Timestamp:
03/20/10 07:57:06 (7 days ago)
Author:
joern.zaefferer
Message:

autocomplete: pass through mouse and key events to menu methods in order to differentiate between key and mouse events in autocomplete

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ui/jquery.ui.autocomplete.js

    r3942 r3975  
    103103                                        var item = ui.item.data( "item.autocomplete" ); 
    104104                                        if ( false !== self._trigger( "focus", null, { item: item } ) ) { 
    105                                                 // use value to match what will end up in the input 
    106                                                 self.element.val( item.value ); 
     105                                                // use value to match what will end up in the input, if it was a key event 
     106                                                if ( /^key/.test(event.originalEvent.type) ) { 
     107                                                        self.element.val( item.value ); 
     108                                                } 
    107109                                        } 
    108110                                }, 
     
    287289                        return; 
    288290                } 
    289                 this.menu[ direction ](); 
     291                this.menu[ direction ]( event ); 
    290292        }, 
    291293 
     
    351353                        .attr("tabindex", -1) 
    352354                        // mouseenter doesn't work with event delegation 
    353                         .mouseenter(function() { 
    354                                 self.activate($(this).parent()); 
     355                        .mouseenter(function( event ) { 
     356                                self.activate( event, $(this).parent() ); 
    355357                        }) 
    356358                        .mouseleave(function() { 
     
    359361        }, 
    360362 
    361         activate: function(item) { 
     363        activate: function( event, item ) { 
    362364                this.deactivate(); 
    363365                if (this.hasScroll()) { 
     
    376378                                .attr("id", "ui-active-menuitem") 
    377379                        .end(); 
    378                 this._trigger("focus", null, { item: item }); 
     380                this._trigger("focus", event, { item: item }); 
    379381        }, 
    380382 
     
    389391        }, 
    390392 
    391         next: function() { 
    392                 this.move("next", "li:first"); 
    393         }, 
    394  
    395         previous: function() { 
    396                 this.move("prev", "li:last"); 
     393        next: function(event) { 
     394                this.move("next", "li:first", event); 
     395        }, 
     396 
     397        previous: function(event) { 
     398                this.move("prev", "li:last", event); 
    397399        }, 
    398400 
     
    405407        }, 
    406408 
    407         move: function(direction, edge) { 
     409        move: function(direction, edge, event) { 
    408410                if (!this.active) { 
    409                         this.activate(this.element.children(edge)); 
     411                        this.activate(event, this.element.children(edge)); 
    410412                        return; 
    411413                } 
    412414                var next = this.active[direction](); 
    413415                if (next.length) { 
    414                         this.activate(next); 
     416                        this.activate(event, next); 
    415417                } else { 
    416                         this.activate(this.element.children(edge)); 
     418                        this.activate(event, this.element.children(edge)); 
    417419                } 
    418420        }, 
    419421 
    420422        // TODO merge with previousPage 
    421         nextPage: function() { 
     423        nextPage: function(event) { 
    422424                if (this.hasScroll()) { 
    423425                        // TODO merge with no-scroll-else 
    424426                        if (!this.active || this.last()) { 
    425                                 this.activate(this.element.children(":first")); 
     427                                this.activate(event, this.element.children(":first")); 
    426428                                return; 
    427429                        } 
     
    438440                                result = this.element.children(":last"); 
    439441                        } 
    440                         this.activate(result); 
     442                        this.activate(event, result); 
    441443                } else { 
    442                         this.activate(this.element.children(!this.active || this.last() ? ":first" : ":last")); 
     444                        this.activate(event, this.element.children(!this.active || this.last() ? ":first" : ":last")); 
    443445                } 
    444446        }, 
    445447 
    446448        // TODO merge with nextPage 
    447         previousPage: function() { 
     449        previousPage: function(event) { 
    448450                if (this.hasScroll()) { 
    449451                        // TODO merge with no-scroll-else 
    450452                        if (!this.active || this.first()) { 
    451                                 this.activate(this.element.children(":last")); 
     453                                this.activate(event, this.element.children(":last")); 
    452454                                return; 
    453455                        } 
     
    465467                                result = this.element.children(":first"); 
    466468                        } 
    467                         this.activate(result); 
     469                        this.activate(event, result); 
    468470                } else { 
    469                         this.activate(this.element.children(!this.active || this.first() ? ":last" : ":first")); 
     471                        this.activate(event, this.element.children(!this.active || this.first() ? ":last" : ":first")); 
    470472                } 
    471473        },