vendor/assets/javascripts/multi-select.js in multi-select-rails-0.9.3 vs vendor/assets/javascripts/multi-select.js in multi-select-rails-0.9.4
- old
+ new
@@ -1,7 +1,7 @@
/*
-* MultiSelect v0.9.3
+* MultiSelect v0.9.4
* Copyright (c) 2012 Louis Cuny
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
@@ -119,12 +119,17 @@
.hide();
that.$selectionUl.find('.ms-optgroup-label').hide();
if ($(this).prop('disabled') || ms.prop('disabled')){
- selectableLi.prop('disabled', true);
- selectableLi.addClass(that.options.disabledClass);
+ if (this.selected) {
+ selectedLi.prop('disabled', true);
+ selectedLi.addClass(that.options.disabledClass);
+ } else {
+ selectableLi.prop('disabled', true);
+ selectableLi.addClass(that.options.disabledClass);
+ }
}
if (optgroupId){
that.$selectableUl.children('#'+optgroupId+'-selectable').find('ul').first().append(selectableLi);
that.$selectionUl.children('#'+optgroupId+'-selection').find('ul').first().append(selectedLi);
@@ -264,11 +269,11 @@
that.$selectableUl.focusout();
that.$selectionUl.focusin();
} else {
that.$selectableUl.focusin();
that.$selectionUl.focusout();
- }
+ }
}
}
ms.on('keydown', function(e){
if (ms.is(':focus')){
@@ -374,33 +379,44 @@
}
}
},
'select_all' : function(){
- var ms = this.$element;
+ var ms = this.$element,
+ values = ms.val();
ms.find('option').prop('selected', true);
this.$selectableUl.find('.ms-elem-selectable').addClass('ms-selected').hide();
this.$selectionUl.find('.ms-optgroup-label').show();
this.$selectableUl.find('.ms-optgroup-label').hide();
this.$selectionUl.find('.ms-elem-selection').addClass('ms-selected').show();
this.$selectionUl.focusin();
this.$selectableUl.focusout();
ms.trigger('change');
+ if (typeof this.options.afterSelect == 'function') {
+ var selectedValues = $.grep(ms.val(), function(item){
+ return $.inArray(item, values) < 0;
+ });
+ this.options.afterSelect.call(this, selectedValues);
+ }
},
'deselect_all' : function(){
- var ms = this.$element;
+ var ms = this.$element,
+ values = ms.val();
ms.find('option').prop('selected', false);
this.$selectableUl.find('.ms-elem-selectable').removeClass('ms-selected').show();
this.$selectionUl.find('.ms-optgroup-label').hide();
this.$selectableUl.find('.ms-optgroup-label').show();
this.$selectionUl.find('.ms-elem-selection').removeClass('ms-selected').hide();
this.$selectableUl.focusin();
this.$selectionUl.focusout();
ms.trigger('change');
+ if (typeof this.options.afterDeselect == 'function') {
+ this.options.afterDeselect.call(this, values);
+ }
},
isDomNode: function (attr){
return (
attr &&
@@ -419,10 +435,10 @@
* ======================= */
$.fn.multiSelect = function () {
var option = arguments[0],
args = arguments;
-
+
return this.each(function () {
var $this = $(this),
data = $this.data('multiselect'),
options = $.extend({}, $.fn.multiSelect.defaults, $this.data(), typeof option == 'object' && option);
\ No newline at end of file