Guest User

Untitled

a guest
Jun 20th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. (function($) {
  2. /**
  3. * .searchText()
  4. * add some helper text to search input field
  5. */
  6. $.fn.searchText = function(options) {
  7. var defaults = {
  8. helperText : 'Search',
  9. inputId : '#s',
  10. forceReset : false
  11. };
  12. var opts = $.extend({},defaults, options);
  13. return this.each(function() {
  14. // write helper text inside input field
  15. $(opts.inputId).bind('blur', {msg: opts.helperText}, function(event){
  16. // $.log(event.type + " : " + event.target.id + " : " + event.data.msg);
  17. var _self = $(this);
  18. if (_self.val() === '') {
  19. _self.val(event.data.msg);
  20. }
  21. return false;
  22. }).bind('focus', {msg: opts.helperText}, function(event){
  23. var _self = $(this);
  24. if (opts.forceReset || _self.val() === event.data.msg) {
  25. // clear search input form
  26. _self.val('');
  27. }
  28. return false;
  29. }).trigger('blur');
  30. });
  31. };
  32. })(jQuery);
  33.  
  34. // Use the plugin in your document ready block
  35. // Use plugin when WordPress search form id is present
  36. // - $('#searchform').searchText();
  37. // Call plugin with option to force reseting the text on focus
  38. $('#searchform').searchText({
  39. helperText : 'Search',
  40. inputId : '#s',
  41. forceReset : true
  42. });
Add Comment
Please, Sign In to add comment