Skip to content

Instantly share code, notes, and snippets.

@jumika
Forked from mudassir0909/clear_selection.js
Last active August 29, 2015 14:14
Show Gist options
  • Save jumika/abe412f1aa2b24ea86e6 to your computer and use it in GitHub Desktop.
Save jumika/abe412f1aa2b24ea86e6 to your computer and use it in GitHub Desktop.
Updated to support changing the title. Also adds a .clear-selection class to the dropdown header for css manipulation.
Selectize.define( 'clear_selection', function ( options ) {
var self = this;
var settings = $.extend({
title: 'Clear selection'
}, options);
//Overriding because, ideally you wouldn't use header & clear_selection simultaneously
self.plugins.settings.dropdown_header = {
title: settings.title
};
this.require( 'dropdown_header' );
self.setup = (function () {
var original = self.setup;
return function () {
original.apply( this, arguments );
this.$dropdown.find('.selectize-dropdown-header').addClass('clear-selection').on('mousedown', function ( e ) {
self.setValue( '' );
self.close();
self.blur();
return false;
});
}
})();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment