@@ -714,6 +714,23 @@ S2.define('select2/utils',[
714714 } ) ;
715715 } ;
716716
717+ // Append an array of jQuery nodes to a given element.
718+ Utils . appendMany = function ( $element , $nodes ) {
719+ // jQuery 1.7.x does not support $.fn.append() with an array
720+ // Fall back to a jQuery object collection using $.fn.add()
721+ if ( $ . fn . jquery . substr ( 0 , 3 ) === '1.7' ) {
722+ var $jqNodes = $ ( ) ;
723+
724+ $ . map ( $nodes , function ( node ) {
725+ $jqNodes = $jqNodes . add ( node ) ;
726+ } ) ;
727+
728+ $nodes = $jqNodes ;
729+ }
730+
731+ $element . append ( $nodes ) ;
732+ } ;
733+
717734 return Utils ;
718735} ) ;
719736
@@ -1565,7 +1582,7 @@ S2.define('select2/selection/multiple',[
15651582 return ;
15661583 }
15671584
1568- var $selections = $ ( ) ;
1585+ var $selections = [ ] ;
15691586
15701587 for ( var d = 0 ; d < data . length ; d ++ ) {
15711588 var selection = data [ d ] ;
@@ -1578,10 +1595,12 @@ S2.define('select2/selection/multiple',[
15781595
15791596 $selection . data ( 'data' , selection ) ;
15801597
1581- $selections = $selections . add ( $selection ) ;
1598+ $selections . push ( $selection ) ;
15821599 }
15831600
1584- this . $selection . find ( '.select2-selection__rendered' ) . append ( $selections ) ;
1601+ var $rendered = this . $selection . find ( '.select2-selection__rendered' ) ;
1602+
1603+ Utils . appendMany ( $rendered , $selections ) ;
15851604 } ;
15861605
15871606 return MultipleSelection ;
@@ -3015,7 +3034,7 @@ S2.define('select2/data/select',[
30153034 } ;
30163035
30173036 SelectAdapter . prototype . addOptions = function ( $options ) {
3018- this . $element . append ( $options ) ;
3037+ Utils . appendMany ( this . $element , $options ) ;
30193038 } ;
30203039
30213040 SelectAdapter . prototype . option = function ( data ) {
@@ -3185,7 +3204,7 @@ S2.define('select2/data/array',[
31853204 return self . item ( $ ( this ) ) . id ;
31863205 } ) . get ( ) ;
31873206
3188- var $options = $ ( ) ;
3207+ var $options = [ ] ;
31893208
31903209 // Filter out all items except for the one passed in the argument
31913210 function onlyItem ( item ) {
@@ -3216,10 +3235,10 @@ S2.define('select2/data/array',[
32163235 if ( item . children ) {
32173236 var $children = this . convertToOptions ( item . children ) ;
32183237
3219- $option . append ( $children ) ;
3238+ Utils . appendMany ( $option , $children ) ;
32203239 }
32213240
3222- $options = $options . add ( $option ) ;
3241+ $options . push ( $option ) ;
32233242 }
32243243
32253244 return $options ;
@@ -3403,7 +3422,7 @@ S2.define('select2/data/tags',[
34033422 var $option = self . option ( tag ) ;
34043423 $option . attr ( 'data-select2-tag' , true ) ;
34053424
3406- self . addOptions ( $option ) ;
3425+ self . addOptions ( [ $option ] ) ;
34073426
34083427 self . insertTag ( data , tag ) ;
34093428 }
@@ -5468,8 +5487,8 @@ S2.define('select2/compat/inputData',[
54685487 } ;
54695488
54705489 InputData . prototype . addOptions = function ( _ , $options ) {
5471- var options = $ . map ( $options , function ( option ) {
5472- return $ . data ( option , 'data' ) ;
5490+ var options = $ . map ( $options , function ( $ option) {
5491+ return $ . data ( $ option[ 0 ] , 'data' ) ;
54735492 } ) ;
54745493
54755494 this . _currentData . push . apply ( this . _currentData , options ) ;
0 commit comments