Skip to content

Instantly share code, notes, and snippets.

@janvanderhaegen
Created March 22, 2013 15:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janvanderhaegen/5222145 to your computer and use it in GitHub Desktop.
Save janvanderhaegen/5222145 to your computer and use it in GitHub Desktop.
JavaScript snippet to turn a "custom control" into a JQuery search box (and move it to the command bar)
(function ($) {
$.widget("switchtory.lightswitchsearchbox", {
_create: function () {
},
_init: function () {
},
destroy: function () {
},
bindTo: function (contentItem) {
this.contentItem = contentItem;
},
render: function () {
var that = this;
$('.msls-footer').append($('<input type="search" />'));
setTimeout( //Give JQueryMobile a moment to process controls.
function () {
//Find the resulting controls
var processedFooter = $('.msls-footer');
var searchBox = $('div', processedFooter).first();
//Tweak appearance for command bar
searchBox.addClass('msls-vauto');
searchBox.addClass('msls-buttons-row');
//Set up the bindings
var searchControl = $('input', searchBox);
that.contentItem.dataBind('value', function (newValue) {
searchControl.val(newValue);
});
searchControl.change(function () {
that.contentItem.value = searchControl.val();
});
});
},
});
}(jQuery));
@Msender
Copy link

Msender commented Jan 23, 2015

Hi

Can you please explain me how to add it to my project.

Thanks

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