Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. (function($){
  2. $.fn.extend({
  3. entry: function (options) {
  4. // entry adds default text to an element and removes it if selected
  5. var defaults = {
  6. expand: false,
  7. submit: false,
  8. };
  9. var options = $.extend(defaults, options);
  10.  
  11. return this.each(function () {
  12. $(this).click(function() {
  13. // the title attribute contains the default text for the input/textarea upon creation
  14. // if this value exists in the input field, it is recognised as untouched
  15. if($(this).val() == $(this)[0].title) {
  16. // text contents are cleared for user entry
  17. $(this).val("");
  18. // the previously lighter text is replaced with darker
  19. $(this).css('color', '#333');
  20. // the input field will also increase in padding for aesthetics, but only if expand is enabled
  21. if(options.expand)
  22. $(this).css('padding-bottom', '10px');
  23. if(options.submit)
  24. $(this).next().show();
  25. }
  26. });
  27. $(this).blur(function() {
  28. if($(this).val() == "") {
  29. $(this).val($(this)[0].title); // reset text contents to default
  30. $(this).css('color', '#999');
  31. $(this).css('padding-bottom', '0px');
  32. if(options.submit)
  33. $(this).next().hide();
  34. }
  35. });
  36. return false;
  37. });
  38. }
  39. });
  40. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement