Skip to content

Instantly share code, notes, and snippets.

@minas7111
Forked from mudassir0909/clear_selection.js
Last active March 15, 2016 15:43
Show Gist options
  • Save minas7111/dcccb9cf771320cf85a5 to your computer and use it in GitHub Desktop.
Save minas7111/dcccb9cf771320cf85a5 to your computer and use it in GitHub Desktop.
Selectize plugin which gives an option to clear selection
Selectize.define( 'clear_selection', function ( options ) {
var self = this;
//Overriding because, ideally you wouldn't use header & clear_selection simultaneously
self.plugins.settings.dropdown_header = $.extend({
title: 'Clear selection'
}, options);
this.require( 'dropdown_header' );
self.setup = (function () {
var original = self.setup;
return function () {
original.apply( this, arguments );
this.$dropdown.on( 'mousedown', '.selectize-dropdown-header', function ( e ) {
self.setValue( '' );
self.close();
self.blur();
return false;
});
}
})();
});
@minas7111
Copy link
Author

Adding the possibility to pass the title through plugin options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment