Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Increases performance when you have many items in the dropdown, by st…

…oring the selectedItem index in a local variable rather than looking it up everytime in the matchIndex method. Before this fix the performance decreases exponentially the higher the selectedIndex is.


With 500+ items in a dropdown performance is increased by 10-15 seconds(!)
  • Loading branch information...
commit 7b79040e774260cb353a65ee16795be6c48294de 1 parent c82cbf0
@hartvig hartvig authored
Showing with 15 additions and 11 deletions.
  1. +15 −11 msdropdown/js/uncompressed.jquery.dd.js
View
26 msdropdown/js/uncompressed.jquery.dd.js
@@ -57,7 +57,8 @@
var isClosing = false;
var cacheElement = {};
var inputText = "";
-
+ var selectedItem;
+
var getElement = function(ele) {
if(typeof(cacheElement[ele])=="undefined") {
cacheElement[ele] = document.getElementById(ele);
@@ -73,16 +74,19 @@
return (typeof styles=="undefined") ? "" : styles.cssText;
};
var matchIndex = function (index) {
- var selectedIndex = $("#"+elementid+" option:selected");
- if(selectedIndex.length>1) {
- for(var i=0;i<selectedIndex.length;i++) {
- if(index == selectedIndex[i].index) {
- return true;
- };
- };
- } else if(selectedIndex.length==1) {
- if(selectedIndex[0].index==index) {
- return true;
+ // For performance, store last selected item once in a local variable rather than looking it up
+ // everytime matchIndex is called
+ if (typeof this.selectedItem === 'undefined')
+ this.selectedItem = $("#" + elementid + " option:selected");
+ if (this.selectedItem.length > 1) {
+ for (var i = 0; i < this.selectedItem.length; i++) {
+ if (index == this.selectedItem[i].index) {
+ return true;
+ };
+ };
+ } else if (this.selectedItem.length == 1) {
+ if (this.selectedItem[0].index == index) {
+ return true;
};
};
return false;
Please sign in to comment.
Something went wrong with that request. Please try again.