From 0701e6ea9660876a91bb013f424750a98bdc8601 Mon Sep 17 00:00:00 2001 From: Adrien Peisl Date: Mon, 19 Jan 2015 09:55:45 +0100 Subject: [PATCH 1/2] Function to disable an element added --- js/jquery.multi-select.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/js/jquery.multi-select.js b/js/jquery.multi-select.js index 697d15b..a44e541 100644 --- a/js/jquery.multi-select.js +++ b/js/jquery.multi-select.js @@ -473,6 +473,20 @@ } }, + // to disable an element + 'disable': function (value) { + if (typeof value === 'string') { value = [value]; } + var that = this, + ms = this.$element, + msIds = $.map(value, function (val) { return (that.sanitize(val)); }), + selectables = this.$selectableUl.find('#' + msIds.join('-selectable, #') + '-selectable'), + selections = this.$selectionUl.find('#' + msIds.join('-selection, #') + '-selection').filter('.ms-selected').filter(':not(.' + that.options.disabledClass + ')'), + options = ms.find('option').filter(function () { return ($.inArray(this.value, value) > -1); }); + + selectables.addClass(that.options.disabledClass); + selectables.addClass(that.options.disabledClass); + }, + sanitize: function(value){ var hash = 0, i, character; if (value.length == 0) return hash; From 988a1f1a8f78faaa2dad4f0fdf53b17ca2daaef6 Mon Sep 17 00:00:00 2001 From: Peisl Adrien Date: Mon, 19 Jan 2015 10:19:21 +0100 Subject: [PATCH 2/2] Duplicate line removed in created function --- js/jquery.multi-select.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/jquery.multi-select.js b/js/jquery.multi-select.js index a44e541..4124c55 100644 --- a/js/jquery.multi-select.js +++ b/js/jquery.multi-select.js @@ -484,7 +484,6 @@ options = ms.find('option').filter(function () { return ($.inArray(this.value, value) > -1); }); selectables.addClass(that.options.disabledClass); - selectables.addClass(that.options.disabledClass); }, sanitize: function(value){