@@ -193,7 +193,7 @@ define('select2/results',[
193193 var $option = $ ( this ) ;
194194 var item = $option . data ( 'data' ) ;
195195
196- if ( selectedIds . indexOf ( item . id . toString ( ) ) > - 1 ) {
196+ if ( item . id != null && selectedIds . indexOf ( item . id . toString ( ) ) > - 1 ) {
197197 $option . addClass ( 'selected' ) ;
198198 }
199199 } ) ;
@@ -205,7 +205,7 @@ define('select2/results',[
205205 '<li class="option highlightable selectable"></li>'
206206 ) ;
207207
208- if ( data . children && data . children . length > 0 ) {
208+ if ( data . children ) {
209209 $option . addClass ( 'group' ) . removeClass ( 'highlightable selectable' ) ;
210210
211211 var $label = $ ( '<strong class="group-label"></strong>' ) ;
@@ -235,6 +235,10 @@ define('select2/results',[
235235 $option . removeClass ( 'selectable highlightable' ) . addClass ( 'disabled' ) ;
236236 }
237237
238+ if ( data . id == null ) {
239+ $option . removeClass ( 'selectable highlightable' ) ;
240+ }
241+
238242 $option . data ( 'data' , data ) ;
239243
240244 return $option ;
@@ -292,28 +296,6 @@ define('select2/results',[
292296 return Results ;
293297} ) ;
294298
295- define ( 'select2/dropdown' , [
296- './utils'
297- ] , function ( Utils ) {
298- function Dropdown ( $element , options ) {
299- this . $element = $element ;
300- }
301-
302- Utils . Extend ( Dropdown , Utils . Observable ) ;
303-
304- Dropdown . prototype . render = function ( ) {
305- var $dropdown = $ (
306- '<span class="dropdown">' +
307- '<span class="results"></span>' +
308- '</span>'
309- ) ;
310-
311- return $dropdown ;
312- } ;
313-
314- return Dropdown ;
315- } ) ;
316-
317299define ( 'select2/selection/single' , [
318300 '../utils'
319301] , function ( Utils ) {
@@ -605,7 +587,6 @@ define('select2/data/select',[
605587 } ;
606588 } else if ( $option . is ( 'optgroup' ) ) {
607589 data = {
608- id : - 1 ,
609590 text : $option . attr ( 'label' ) ,
610591 children : [ ]
611592 } ;
@@ -654,7 +635,7 @@ define('select2/data/select',[
654635 return match ;
655636 }
656637
657- if ( data . text . indexOf ( params . term ) > - 1 ) {
638+ if ( data . text . toUpperCase ( ) . indexOf ( params . term . toUpperCase ( ) ) > - 1 ) {
658639 return match ;
659640 }
660641
@@ -769,19 +750,83 @@ define('select2/data/ajax',[
769750 return AjaxAdapter ;
770751} ) ;
771752
753+ define ( 'select2/dropdown' , [
754+ './utils'
755+ ] , function ( Utils ) {
756+ function Dropdown ( $element , options ) {
757+ this . $element = $element ;
758+ }
759+
760+ Utils . Extend ( Dropdown , Utils . Observable ) ;
761+
762+ Dropdown . prototype . render = function ( ) {
763+ var $dropdown = $ (
764+ '<span class="dropdown">' +
765+ '<span class="results"></span>' +
766+ '</span>'
767+ ) ;
768+
769+ return $dropdown ;
770+ } ;
771+
772+ Dropdown . prototype . bind = function ( container , $container ) {
773+ // Can be implemented in subclasses
774+ } ;
775+
776+ return Dropdown ;
777+ } ) ;
778+
779+ define ( 'select2/dropdown/search' , [
780+
781+ ] , function ( ) {
782+ function Search ( ) { }
783+
784+ Search . prototype . render = function ( decorated ) {
785+ var $rendered = decorated . call ( this ) ;
786+
787+ var $search = $ (
788+ '<span class="search">' +
789+ '<input type="search" name="search" />' +
790+ '</span>'
791+ ) ;
792+
793+ this . $search = $search . find ( 'input' ) ;
794+
795+ $rendered . prepend ( $search ) ;
796+
797+ return $rendered ;
798+ } ;
799+
800+ Search . prototype . bind = function ( decorated , container , $container ) {
801+ decorated . call ( this , container , $container ) ;
802+
803+ this . $search . on ( 'keyup' , function ( ) {
804+ container . trigger ( 'query' , {
805+ term : $ ( this ) . val ( )
806+ } ) ;
807+ } ) ;
808+ } ;
809+
810+ return Search ;
811+ } ) ;
812+
772813define ( 'select2/options' , [
773814 './results' ,
774815
775- './dropdown' ,
776-
777816 './selection/single' ,
778817 './selection/multiple' ,
779818
819+ './utils' ,
820+
780821 './data/select' ,
781822 './data/array' ,
782- './data/ajax'
783- ] , function ( ResultsList , Dropdown , SingleSelection , MultipleSelection ,
784- SelectData , ArrayData , AjaxData ) {
823+ './data/ajax' ,
824+
825+ './dropdown' ,
826+ './dropdown/search'
827+ ] , function ( ResultsList , SingleSelection , MultipleSelection , Utils ,
828+ SelectData , ArrayData , AjaxData ,
829+ Dropdown , Search ) {
785830 function Options ( options ) {
786831 this . options = options ;
787832
@@ -793,8 +838,10 @@ define('select2/options',[
793838 this . dataAdapter = this . dataAdapter || SelectData ;
794839 }
795840
841+ var SearchableDropdown = Utils . Decorate ( Dropdown , Search ) ;
842+
796843 this . resultsAdapter = ResultsList ;
797- this . dropdownAdapter = options . dropdownAdapter || Dropdown ;
844+ this . dropdownAdapter = options . dropdownAdapter || SearchableDropdown ;
798845 this . selectionAdapter = options . selectionAdapter ;
799846
800847 if ( this . selectionAdapter == null ) {
@@ -864,6 +911,8 @@ define('select2/core',[
864911
865912 this . data . bind ( this , $container ) ;
866913 this . selection . bind ( this , $container ) ;
914+
915+ this . dropdown . bind ( this , $container ) ;
867916 this . results . bind ( this , $container ) ;
868917
869918 this . $element . on ( 'change' , function ( ) {
@@ -906,10 +955,14 @@ define('select2/core',[
906955 } ) ;
907956 } ) ;
908957
909- this . data . query ( { } , function ( data ) {
910- self . results . trigger ( 'results:all' , data ) ;
958+ this . on ( 'query' , function ( params ) {
959+ this . data . query ( params , function ( data ) {
960+ self . results . trigger ( 'results:all' , data ) ;
961+ } ) ;
911962 } ) ;
912963
964+ this . trigger ( 'query' , { } ) ;
965+
913966 // Hide the original select
914967
915968 $element . hide ( ) ;
0 commit comments