11/**
2- * @lordfriend /nya-bootstrap-select v2.1.9
2+ * @lordfriend /nya-bootstrap-select v2.1.10
33 * Copyright 2014 Nyasoft
44 * Licensed under MIT license
55 */
@@ -1073,6 +1073,19 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
10731073 }
10741074 }
10751075 }
1076+
1077+ function supportsSelector ( selector ) {
1078+ var el = document . createElement ( 'div' ) ;
1079+ el . innerHTML = [ '­' , '<style>' , selector , '{}' , '</style>' ] . join ( '' ) ;
1080+ el = document . body . appendChild ( el ) ;
1081+ var style = el . getElementsByTagName ( 'style' ) [ 0 ] ;
1082+ if ( style && style . sheet && style . sheet . rules && style . sheet . cssRules ) {
1083+ var ret = ! ! ( style . sheet . rules || style . sheet . cssRules ) [ 0 ] ;
1084+ document . body . removeChild ( el ) ;
1085+ return ret ;
1086+ }
1087+ return false ;
1088+ }
10761089
10771090 function findFocus ( fromFirst ) {
10781091 var firstLiElement ;
@@ -1083,10 +1096,18 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
10831096 }
10841097
10851098 // focus on selected element
1086- for ( var i = 0 ; i < dropdownMenu . children ( ) . length ; i ++ ) {
1087- var childElement = dropdownMenu . children ( ) . eq ( i ) ;
1088- if ( ! childElement . hasClass ( 'not-match' ) && childElement . hasClass ( 'selected' ) ) {
1089- return dropdownMenu . children ( ) . eq ( i ) [ 0 ] ;
1099+ if ( supportsSelector ( ".selected:not(.not-match)" ) ) {
1100+ var match = dropdownMenu [ 0 ] . querySelector ( '.selected:not(.not-match)' ) ;
1101+ if ( match )
1102+ return match ;
1103+ }
1104+ else {
1105+ // Fallback for IE8 users
1106+ for ( var i = 0 ; i < dropdownMenu . children ( ) . length ; i ++ ) {
1107+ var childElement = dropdownMenu . children ( ) . eq ( i ) ;
1108+ if ( ! childElement . hasClass ( 'not-match' ) && childElement . hasClass ( 'selected' ) ) {
1109+ return dropdownMenu . children ( ) . eq ( i ) [ 0 ] ;
1110+ }
10901111 }
10911112 }
10921113
0 commit comments