comparison static/bootstrap/js/bootstrap-typeahead.js @ 88:a5a3d454eac9

Updated Bootstrap.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 05 Apr 2013 08:08:12 -0700
parents 130eccd396d8
children
comparison
equal deleted inserted replaced
87:c0cf67362fb1 88:a5a3d454eac9
1 /* ============================================================= 1 /* =============================================================
2 * bootstrap-typeahead.js v2.2.2 2 * bootstrap-typeahead.js v2.3.1
3 * http://twitter.github.com/bootstrap/javascript.html#typeahead 3 * http://twitter.github.com/bootstrap/javascript.html#typeahead
4 * ============================================================= 4 * =============================================================
5 * Copyright 2012 Twitter, Inc. 5 * Copyright 2012 Twitter, Inc.
6 * 6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * Licensed under the Apache License, Version 2.0 (the "License");
170 prev.addClass('active') 170 prev.addClass('active')
171 } 171 }
172 172
173 , listen: function () { 173 , listen: function () {
174 this.$element 174 this.$element
175 .on('focus', $.proxy(this.focus, this))
175 .on('blur', $.proxy(this.blur, this)) 176 .on('blur', $.proxy(this.blur, this))
176 .on('keypress', $.proxy(this.keypress, this)) 177 .on('keypress', $.proxy(this.keypress, this))
177 .on('keyup', $.proxy(this.keyup, this)) 178 .on('keyup', $.proxy(this.keyup, this))
178 179
179 if (this.eventSupported('keydown')) { 180 if (this.eventSupported('keydown')) {
181 } 182 }
182 183
183 this.$menu 184 this.$menu
184 .on('click', $.proxy(this.click, this)) 185 .on('click', $.proxy(this.click, this))
185 .on('mouseenter', 'li', $.proxy(this.mouseenter, this)) 186 .on('mouseenter', 'li', $.proxy(this.mouseenter, this))
187 .on('mouseleave', 'li', $.proxy(this.mouseleave, this))
186 } 188 }
187 189
188 , eventSupported: function(eventName) { 190 , eventSupported: function(eventName) {
189 var isSupported = eventName in this.$element 191 var isSupported = eventName in this.$element
190 if (!isSupported) { 192 if (!isSupported) {
254 256
255 e.stopPropagation() 257 e.stopPropagation()
256 e.preventDefault() 258 e.preventDefault()
257 } 259 }
258 260
261 , focus: function (e) {
262 this.focused = true
263 }
264
259 , blur: function (e) { 265 , blur: function (e) {
260 var that = this 266 this.focused = false
261 setTimeout(function () { that.hide() }, 150) 267 if (!this.mousedover && this.shown) this.hide()
262 } 268 }
263 269
264 , click: function (e) { 270 , click: function (e) {
265 e.stopPropagation() 271 e.stopPropagation()
266 e.preventDefault() 272 e.preventDefault()
267 this.select() 273 this.select()
274 this.$element.focus()
268 } 275 }
269 276
270 , mouseenter: function (e) { 277 , mouseenter: function (e) {
278 this.mousedover = true
271 this.$menu.find('.active').removeClass('active') 279 this.$menu.find('.active').removeClass('active')
272 $(e.currentTarget).addClass('active') 280 $(e.currentTarget).addClass('active')
281 }
282
283 , mouseleave: function (e) {
284 this.mousedover = false
285 if (!this.focused && this.shown) this.hide()
273 } 286 }
274 287
275 } 288 }
276 289
277 290
314 * ================== */ 327 * ================== */
315 328
316 $(document).on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) { 329 $(document).on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) {
317 var $this = $(this) 330 var $this = $(this)
318 if ($this.data('typeahead')) return 331 if ($this.data('typeahead')) return
319 e.preventDefault()
320 $this.typeahead($this.data()) 332 $this.typeahead($this.data())
321 }) 333 })
322 334
323 }(window.jQuery); 335 }(window.jQuery);