Advertisement
Guest User

Untitled

a guest
Apr 16th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. /*
  2. * jQuery placeholder Plugin
  3. * version: 0.1
  4. * @requires: jQuery v1.4.1 or later, Modernizr, and jquery livequery plugin
  5. *
  6. * http://docs.jquery.com/Plugins/livequery
  7. *
  8. * To use: When you write your input tags, include a title and placeholder attribute as
  9. * well as a placeholder class. Also include styling for the hasPlaceholder class.
  10. *
  11. * E.g.:
  12. * CSS:
  13. * .hasPlaceholder { color: #ddd; font-style: italic; }
  14. *
  15. * <input type="text" class="placeholder" title="Username" placeholder="Username" name="username">
  16. */
  17. if (!Modernizr.input.placeholder) {
  18. $(function() {
  19.  
  20. var blurInputs = function (selector) {
  21. selector.each(function () {
  22. var trimmedTitle = $.trim(this.title), trimmedValue = $.trim(this.value);
  23. if (trimmedTitle !== '' && (trimmedValue === '' || trimmedValue == trimmedTitle)) {
  24. this.value = this.title;
  25. $(this).addClass('hasPlaceholder');
  26. }
  27. });
  28. };
  29.  
  30. $(':text.placeholder')
  31. .livequery(function () {
  32. blurInputs($(this));
  33. })
  34. .live('focus', function () {
  35. if ($.trim(this.title) !== '' && $.trim(this.value) === $.trim(this.title)) {
  36. this.value = '';
  37. $(this).removeClass('hasPlaceholder');
  38. }
  39. })
  40. .live('blur', function () {
  41. blurInputs($(this));
  42. });
  43.  
  44. $("form").live("submit", function () {
  45. $(this).find(':text.hasPlaceholder').val('');
  46. });
  47. });
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement