Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($) {
- /**
- * .searchText()
- * add some helper text to search input field
- */
- $.fn.searchText = function(options) {
- var defaults = {
- helperText : 'Search',
- inputId : '#s',
- forceReset : false
- };
- var opts = $.extend({},defaults, options);
- return this.each(function() {
- // write helper text inside input field
- $(opts.inputId).bind('blur', {msg: opts.helperText}, function(event){
- // $.log(event.type + " : " + event.target.id + " : " + event.data.msg);
- var _self = $(this);
- if (_self.val() === '') {
- _self.val(event.data.msg);
- }
- return false;
- }).bind('focus', {msg: opts.helperText}, function(event){
- var _self = $(this);
- if (opts.forceReset || _self.val() === event.data.msg) {
- // clear search input form
- _self.val('');
- }
- return false;
- }).trigger('blur');
- });
- };
- })(jQuery);
- // Use the plugin in your document ready block
- // Use plugin when WordPress search form id is present
- // - $('#searchform').searchText();
- // Call plugin with option to force reseting the text on focus
- $('#searchform').searchText({
- helperText : 'Search',
- inputId : '#s',
- forceReset : true
- });
Add Comment
Please, Sign In to add comment