@@ -9782,10 +9782,17 @@ define('select2/data/select',[
97829782 } ;
97839783
97849784 SelectAdapter . prototype . item = function ( $option ) {
9785- var data = {
9786- id : $option . val ( ) ,
9787- text : $option . html ( )
9788- } ;
9785+ var data = $option . data ( "data" ) ;
9786+
9787+ // If the data has already be generated, use it
9788+ if ( data == null ) {
9789+ data = {
9790+ id : $option . val ( ) ,
9791+ text : $option . html ( )
9792+ } ;
9793+
9794+ $option . data ( "data" , data ) ;
9795+ }
97899796
97909797 return data ;
97919798 } ;
@@ -9893,7 +9900,7 @@ define('select2/results',[
98939900 self . setClasses ( ) ;
98949901 } )
98959902
9896- this . $results . on ( "click " , ".option" , function ( evt ) {
9903+ this . $results . on ( "mouseup " , ".option" , function ( evt ) {
98979904 var $this = $ ( this ) ;
98989905
98999906 var data = $this . data ( "data" ) ;
@@ -9978,7 +9985,7 @@ define('select2/selection/single',[
99789985 SingleSelection . prototype . bind = function ( container , $container ) {
99799986 var self = this ;
99809987
9981- this . $selection . on ( 'click ' , function ( evt ) {
9988+ this . $selection . on ( 'mousedown ' , function ( evt ) {
99829989 self . trigger ( "toggle" , {
99839990 originalEvent : evt
99849991 } ) ;
@@ -10098,7 +10105,7 @@ define('select2/options',[
1009810105 function Options ( options ) {
1009910106 this . options = options ;
1010010107
10101- this . dataAdapter = SelectData ;
10108+ this . dataAdapter = options . dataAdapter || SelectData ;
1010210109 this . resultsAdapter = ResultsList ;
1010310110 this . dropdownAdapter = options . dropdownAdapter || Dropdown ;
1010410111 this . selectionAdapter = options . selectionAdapter ;
@@ -10197,12 +10204,18 @@ define('select2/core',[
1019710204 // Set the initial state
1019810205
1019910206 this . data . current ( function ( initialData ) {
10200- self . selection . update ( initialData ) ;
10207+ self . trigger ( "selection:update" , {
10208+ data : initialData
10209+ } ) ;
1020110210 } ) ;
1020210211
1020310212 this . data . query ( { } , function ( data ) {
1020410213 self . results . trigger ( "results:all" , data ) ;
1020510214 } ) ;
10215+
10216+ // Hide the original select
10217+
10218+ $element . hide ( ) ;
1020610219 } ;
1020710220
1020810221 Utils . Extend ( Select2 , Utils . Observable ) ;
0 commit comments