Skip to content

Instantly share code, notes, and snippets.

@ABM-Dan
Created January 14, 2016 15:49
Show Gist options
  • Save ABM-Dan/70316682296df8e044fb to your computer and use it in GitHub Desktop.
Save ABM-Dan/70316682296df8e044fb to your computer and use it in GitHub Desktop.
var selectricOptions = {
disableOnMobile: false,
onInit: function () {
var label, selectedClass, selectricWrapper;
selectricWrapper = $(this).parents('.selectric-wrapper');
selectedClass = selectricWrapper.find('option:selected').attr('class');
label = selectricWrapper.find('.label');
label.addClass(selectedClass);
if ($(this).data('placeholder')) {
return label.text($(this).data('placeholder'));
}
},
onBeforeOpen: function () {
var options;
options = $(this).find('option');
return $(this).parent().siblings('.selectric-items').find('li').each(function (index, el) {
var currentClass;
currentClass = options.eq(index).attr('class');
return $(el).addClass(currentClass).data('class', currentClass);
});
},
onChange: function() {
var pickedClass;
pickedClass = $(this).parent().siblings('.selectric-items').find('li.selected').data('class');
return $(this).parents('.selectric-wrapper').find('.label').attr('class', 'label ' + pickedClass + ' changed');
}
};
selectricOptions.onRefresh = selectricOptions.onChange;
$('select.selectric').selectric(selectricOptions);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment