Skip to content

Commit 119f4fe

Browse files
committed
Merge pull request designmodo#110 from Asakeron/master
Replace DOMNodeInserted with Mutation Observers when supported.
2 parents 3194be1 + f91ae1b commit 119f4fe

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

js/bootstrap-select.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,28 @@
8686
getSize();
8787
$(window).resize(getSize);
8888
$(window).scroll(getSize);
89-
this.$element.bind('DOMNodeInserted', getSize);
89+
if (window.MutationObserver) {
90+
new MutationObserver(getSize).observe(this.$element.get(0), {
91+
childList: true
92+
});
93+
} else {
94+
this.$element.bind('DOMNodeInserted', getSize);
95+
}
9096
} else if (this.options.size && this.options.size != 'auto' && menu.find('li').length > this.options.size) {
9197
var optIndex = menu.find("li > *").filter(':not(.divider)').slice(0,this.options.size).last().parent().index();
9298
var divLength = menu.find("li").slice(0,optIndex + 1).find('.divider').length;
9399
menuHeight = liHeight*this.options.size + divLength*divHeight + menuPadding;
94100
menu.css({'max-height' : menuHeight + 'px', 'overflow-y' : 'scroll'});
95101
}
96102

97-
//Listen for updates to the DOM and re render...
98-
this.$element.bind('DOMNodeInserted', $.proxy(this.reloadLi, this));
103+
// Listen for updates to the DOM and re render... (Use Mutation Observer when availiable)
104+
if (window.MutationObserver) {
105+
new MutationObserver($.proxy(this.reloadLi, this)).observe(this.$element.get(0), {
106+
childList: true
107+
});
108+
} else {
109+
this.$element.bind('DOMNodeInserted', $.proxy(this.reloadLi, this));
110+
}
99111

100112
this.render();
101113
},

0 commit comments

Comments
 (0)