Last active
August 29, 2015 14:01
-
-
Save Robdel12/024ad9845aaa7bf07775 to your computer and use it in GitHub Desktop.
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
$("#search_select").dropkick({ | |
mobile: true, | |
initialize: function() { | |
var $input, | |
dk = this; | |
$( '.dk-selected', dk.data.elem ).after([ | |
'<div class="dk-search">', | |
'<input type="text" class="dk-search-input" placeholder="Search">', | |
'</div>', | |
].join("")); | |
$input = $( ".dk-search-input", dk.data.elem ); | |
$input.on( "click", function ( event ) { | |
event.stopPropagation(); | |
}).on( "keypress keyup", function ( event ) { | |
var found = dk.search( this.value, dk.data.settings.search ); | |
event.stopPropagation(); | |
$( '.dk-option', dk.data.elem ).remove(); | |
if ( found.length ) { | |
$( found ).appendTo( dk.data.elem.lastChild ); | |
dk.selectOne( found[0] ); | |
} else { | |
$( "<li></li>" ).addClass( "dk-option dk-option-disabled" ).text( "Not Found" ).appendTo( dk.data.elem.lastChild ); | |
} | |
found.length && dk.selectOne( found[0] ); | |
}); | |
}, | |
open: function() { | |
$( '.dk-search-input', this.data.elem ).focus(); | |
}, | |
close: function() { | |
$( '.dk-search-input', this.data.elem ).val("").blur(); | |
$( '.dk-option', this.data.elem ).remove(); | |
$( this.options ).appendTo( this.data.elem.lastChild ); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment