jQuery(function($){
'use strict';
var select=window.iwjmbSelect={
selectAllNone: function($input){
var $element=$input.find('select');
$input.on('click', '.iwjmb-select-all-none a', function(e){
e.preventDefault();
if('all'==$(this).data('type')){
var selected=[];
$element.find('option').each(function(i, e){
var $value=$(e).attr('value');
if($value!=''){
selected.push($value);
}});
$element.val(selected).trigger('change');
}else{
$element.val('');
}});
},
bindEvents: function($el){
var $input=$el.closest('.iwjmb-input'),
$clone=$input.find('.iwjmb-clone');
if($clone.length){
$clone.each(function (){
select.selectAllNone($(this));
});
}else{
select.selectAllNone($input);
}}
};
function update(){
select.bindEvents($(this));
}
$(':input.iwjmb-select').each(update);
$('.iwjmb-input').on('clone', ':input.iwjmb-select', update);
});