Forked from bkosborne/gist:56ee6a6559ac66d64490
Last active
December 13, 2015 11:25
-
-
Save antitoxic/9156ae5a4531fce46ad1 to your computer and use it in GitHub Desktop.
Selectize `no_results` plugin
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('no_results', function( options ) { | |
var KEY_LEFT = 37; | |
var KEY_UP = 38; | |
var KEY_RIGHT = 39; | |
var KEY_DOWN = 40; | |
var ignoreKeys = [KEY_LEFT, KEY_UP, KEY_RIGHT, KEY_DOWN] | |
var self = this; | |
options = $.extend({ | |
message: 'No results found.', | |
html: function(data) { | |
return '<div class="dropdown-empty-message">' + data.message + '</div>'; | |
} | |
}, options ); | |
self.on('type', function(str) { | |
if (!self.hasOptions) { | |
self.$empty_results_container.show(); | |
} else { | |
self.$empty_results_container.hide(); | |
} | |
}); | |
self.onKeyUp = (function() { | |
var original = self.onKeyUp; | |
return function ( e ) { | |
if (ignoreKeys.indexOf(e.keyCode) > -1) return; | |
self.isOpen = false; | |
original.apply( self, arguments ); | |
} | |
})(); | |
self.onBlur = (function () { | |
var original = self.onBlur; | |
return function () { | |
original.apply( self, arguments ); | |
self.$empty_results_container.hide(); | |
}; | |
})(); | |
self.setup = (function() { | |
var original = self.setup; | |
return function() { | |
original.apply( self, arguments); | |
self.$empty_results_container = $( | |
options.html($.extend({ | |
classNames: self.$input.attr( 'class' ) | |
}, options)) | |
); | |
self.$empty_results_container.hide(); | |
self.$dropdown.append(self.$empty_results_container); | |
}; | |
})(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I can't make it work.
Am I supposed to do something else besides loading this .js and adding
plugins: ['no_results']
to my Selectize?