From 92085afca29e09d99f16ff9a6fef78d665c80488 Mon Sep 17 00:00:00 2001 From: PeuX Date: Fri, 7 Jul 2017 14:22:02 +0200 Subject: [PATCH] Adding lazy loading added lazy loading for multiselect. you have to use option enableLazyLoad : true to lazyload this multiselect. --- dist/js/bootstrap-multiselect.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/dist/js/bootstrap-multiselect.js b/dist/js/bootstrap-multiselect.js index 9a50a18a..bd717d5a 100644 --- a/dist/js/bootstrap-multiselect.js +++ b/dist/js/bootstrap-multiselect.js @@ -204,9 +204,11 @@ this.buildContainer(); this.buildButton(); this.buildDropdown(); - this.buildSelectAll(); - this.buildDropdownOptions(); - this.buildFilter(); + if(!this.options.enableLazyLoad){ + this.buildSelectAll(); + this.buildDropdownOptions(); + this.buildFilter(); + } this.updateButtonText(); this.updateSelectAll(true); @@ -421,6 +423,7 @@ numberDisplayed: 3, disableIfEmpty: false, disabledText: '', + enableLazyLoad:false, delimiterText: ', ', templates: { button: '', @@ -440,12 +443,27 @@ */ buildContainer: function() { this.$container = $(this.options.buttonContainer); + if(this.options.enableLazyLoad) this.$container.on('show.bs.dropdown', $.proxy( this.lazyLoad, this )); this.$container.on('show.bs.dropdown', this.options.onDropdownShow); this.$container.on('hide.bs.dropdown', this.options.onDropdownHide); this.$container.on('shown.bs.dropdown', this.options.onDropdownShown); this.$container.on('hidden.bs.dropdown', this.options.onDropdownHidden); }, + /** + * Triggered when the dropdown is shown. + * + * @param {jQuery} event + */ + lazyLoad: function(event) { + if(this.firstLazy){ + this.buildSelectAll(); + this.buildDropdownOptions(); + this.buildFilter(); + this.firstLazy = false; + } + }, + firstLazy: true, /** * Builds the button of the multiselect. */