-
-
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.
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
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