@@ -1060,10 +1060,10 @@ $.extend(Selectize.prototype, {
10601060 optgroup = '' ;
10611061 }
10621062 if ( ! groups . hasOwnProperty ( optgroup ) ) {
1063- groups [ optgroup ] = [ ] ;
1063+ groups [ optgroup ] = document . createDocumentFragment ( ) ;
10641064 groups_order . push ( optgroup ) ;
10651065 }
1066- groups [ optgroup ] . push ( option_html ) ;
1066+ groups [ optgroup ] . appendChild ( option_html ) ;
10671067 }
10681068 }
10691069
@@ -1077,23 +1077,26 @@ $.extend(Selectize.prototype, {
10771077 }
10781078
10791079 // render optgroup headers & join groups
1080- html = [ ] ;
1080+ html = document . createDocumentFragment ( ) ;
10811081 for ( i = 0 , n = groups_order . length ; i < n ; i ++ ) {
10821082 optgroup = groups_order [ i ] ;
1083- if ( self . optgroups . hasOwnProperty ( optgroup ) && groups [ optgroup ] . length ) {
1083+ if ( self . optgroups . hasOwnProperty ( optgroup ) && groups [ optgroup ] . childNodes . length ) {
10841084 // render the optgroup header and options within it,
10851085 // then pass it to the wrapper template
1086- html_children = self . render ( 'optgroup_header' , self . optgroups [ optgroup ] ) || '' ;
1087- html_children += groups [ optgroup ] . join ( '' ) ;
1088- html . push ( self . render ( 'optgroup' , $ . extend ( { } , self . optgroups [ optgroup ] , {
1089- html : html_children
1086+ html_children = document . createDocumentFragment ( ) ;
1087+ html_children . appendChild ( self . render ( 'optgroup_header' , self . optgroups [ optgroup ] ) ) ;
1088+ html_children . appendChild ( groups [ optgroup ] ) ;
1089+
1090+ html . appendChild ( self . render ( 'optgroup' , $ . extend ( { } , self . optgroups [ optgroup ] , {
1091+ html : domToString ( html_children ) ,
1092+ dom : html_children
10901093 } ) ) ) ;
10911094 } else {
1092- html . push ( groups [ optgroup ] . join ( '' ) ) ;
1095+ html . appendChild ( groups [ optgroup ] ) ;
10931096 }
10941097 }
10951098
1096- $dropdown_content . html ( html . join ( '' ) ) ;
1099+ $dropdown_content . html ( html ) ;
10971100
10981101 // highlight matching terms inline
10991102 if ( self . settings . highlight && results . query . length && results . tokens . length ) {
@@ -2044,26 +2047,26 @@ $.extend(Selectize.prototype, {
20442047 }
20452048
20462049 // render markup
2047- html = self . settings . render [ templateName ] . apply ( this , [ data , escape_html ] ) ;
2050+ html = $ ( self . settings . render [ templateName ] . apply ( this , [ data , escape_html ] ) ) ;
20482051
20492052 // add mandatory attributes
20502053 if ( templateName === 'option' || templateName === 'option_create' ) {
2051- html = html . replace ( regex_tag , '<$1 data-selectable') ;
2054+ html . attr ( ' data-selectable' , ' ') ;
20522055 }
2053- if ( templateName === 'optgroup' ) {
2056+ else if ( templateName === 'optgroup' ) {
20542057 id = data [ self . settings . optgroupValueField ] || '' ;
2055- html = html . replace ( regex_tag , '<$1 data-group="' + escape_replace ( escape_html ( id ) ) + '"' ) ;
2058+ html . attr ( ' data-group' , id ) ;
20562059 }
20572060 if ( templateName === 'option' || templateName === 'item' ) {
2058- html = html . replace ( regex_tag , '<$1 data-value="' + escape_replace ( escape_html ( value || '' ) ) + '" ') ;
2061+ html . attr ( ' data-value' , value || '' ) ;
20592062 }
20602063
20612064 // update cache
20622065 if ( cache ) {
2063- self . renderCache [ templateName ] [ value ] = html ;
2066+ self . renderCache [ templateName ] [ value ] = html [ 0 ] ;
20642067 }
20652068
2066- return html ;
2069+ return html [ 0 ] ;
20672070 } ,
20682071
20692072 /**
0 commit comments