Created
November 5, 2015 16:46
-
-
Save reinaldomendes/c9d355ab11fcf4732b79 to your computer and use it in GitHub Desktop.
Scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var Multiselect = { | |
move: function (from, to) { | |
while (from.selectedIndex > -1) { | |
var option = from.options[from.selectedIndex]; | |
to.appendChild(option); | |
} | |
}, | |
moveAll: function (from, to) { | |
while (from.options.length > 0) { | |
var option = from.options[0]; | |
to.appendChild(option) | |
} | |
} | |
} | |
var $component = $('[data-component="multiselect"]'); | |
var $form = $component.parents('form').first(); | |
$form.bind('submit', function (evt) { | |
//evt.preventDefault(); | |
var $right = $component.find('[data-element="right"]'); | |
$right.find('option').prop('selected', true); | |
/*setTimeout(function(){ | |
$form[0].submit(); | |
},5000)*/ | |
}); | |
$component.on('click', '[data-element="multiselect-actions"]', function (evt) { | |
var from = null; | |
var to = null; | |
switch ($(this).data('direction')) { | |
case 'left': | |
from = $component.find('[data-element="right"]') | |
to = $component.find('[data-element="left"]') | |
break; | |
case 'right': | |
from = $component.find('[data-element="left"]') | |
to = $component.find('[data-element="right"]'); | |
break; | |
} | |
var fnMove = $(this).data('action'); | |
Multiselect[fnMove](from[0], to[0]); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment