Skip to content

Commit

Permalink
Merge pull request #149 from martijnlentink/patch-1
Browse files Browse the repository at this point in the history
Extremely improve the initial load of dropdown
  • Loading branch information
lordfriend authored Nov 11, 2016
2 parents 5b70c12 + 53a66ae commit ad350ee
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/nya-bs-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,19 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
}
}
}

function supportsSelector(selector) {
var el = document.createElement('div');
el.innerHTML = ['&shy;', '<style>', selector, '{}', '</style>'].join('');
el = document.body.appendChild(el);
var style = el.getElementsByTagName('style')[0];
if (style && style.sheet && style.sheet.rules && style.sheet.cssRules) {
var ret = !!(style.sheet.rules || style.sheet.cssRules)[0];
document.body.removeChild(el);
return ret;
}
return false;
}

function findFocus(fromFirst) {
var firstLiElement;
Expand All @@ -673,10 +686,18 @@ nyaBsSelect.directive('nyaBsSelect', ['$parse', '$document', '$timeout', '$compi
}

// focus on selected element
for(var i = 0; i < dropdownMenu.children().length; i++) {
var childElement = dropdownMenu.children().eq(i);
if (!childElement.hasClass('not-match') && childElement.hasClass('selected')) {
return dropdownMenu.children().eq(i)[0];
if (supportsSelector(".selected:not(.not-match)")) {
var match = dropdownMenu[0].querySelector('.selected:not(.not-match)');
if (match)
return match;
}
else {
// Fallback for IE8 users
for(var i = 0; i < dropdownMenu.children().length; i++) {
var childElement = dropdownMenu.children().eq(i);
if (!childElement.hasClass('not-match') && childElement.hasClass('selected')) {
return dropdownMenu.children().eq(i)[0];
}
}
}

Expand Down

0 comments on commit ad350ee

Please sign in to comment.