| 815 | } |
| 816 | |
| 817 | var Selectpicker = function (element, options) { |
| 818 | var that = this; |
| 819 | |
| 820 | // bootstrap-select has been initialized - revert valHooks.select.set back to its original function |
| 821 | if (!valHooks.useDefault) { |
| 822 | $.valHooks.select.set = valHooks._set; |
| 823 | valHooks.useDefault = true; |
| 824 | } |
| 825 | |
| 826 | this.$element = $(element); |
| 827 | this.$newElement = null; |
| 828 | this.$button = null; |
| 829 | this.$menu = null; |
| 830 | this.options = options; |
| 831 | this.selectpicker = { |
| 832 | main: {}, |
| 833 | search: {}, |
| 834 | current: {}, // current changes if a search is in progress |
| 835 | view: {}, |
| 836 | isSearching: false, |
| 837 | keydown: { |
| 838 | keyHistory: '', |
| 839 | resetKeyHistory: { |
| 840 | start: function () { |
| 841 | return setTimeout(function () { |
| 842 | that.selectpicker.keydown.keyHistory = ''; |
| 843 | }, 800); |
| 844 | } |
| 845 | } |
| 846 | } |
| 847 | }; |
| 848 | |
| 849 | this.sizeInfo = {}; |
| 850 | |
| 851 | // If we have no title yet, try to pull it from the html title attribute (jQuery doesnt' pick it up as it's not a |
| 852 | // data-attribute) |
| 853 | if (this.options.title === null) { |
| 854 | this.options.title = this.$element.attr('title'); |
| 855 | } |
| 856 | |
| 857 | // Format window padding |
| 858 | var winPad = this.options.windowPadding; |
| 859 | if (typeof winPad === 'number') { |
| 860 | this.options.windowPadding = [winPad, winPad, winPad, winPad]; |
| 861 | } |
| 862 | |
| 863 | // Expose public methods |
| 864 | this.val = Selectpicker.prototype.val; |
| 865 | this.render = Selectpicker.prototype.render; |
| 866 | this.refresh = Selectpicker.prototype.refresh; |
| 867 | this.setStyle = Selectpicker.prototype.setStyle; |
| 868 | this.selectAll = Selectpicker.prototype.selectAll; |
| 869 | this.deselectAll = Selectpicker.prototype.deselectAll; |
| 870 | this.destroy = Selectpicker.prototype.destroy; |
| 871 | this.remove = Selectpicker.prototype.remove; |
| 872 | this.show = Selectpicker.prototype.show; |
| 873 | this.hide = Selectpicker.prototype.hide; |
| 874 | |