Guest User

Untitled

a guest
Jun 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. /* Stop writing the same damn code over and over again to handle swapping input
  2. text on focus/blur. Store the original using jQuery.data(), and have this
  3. be as agnostic as possible. ;P
  4. */
  5.  
  6. var page = {
  7. inputs: {
  8. checkAndStore: function() {
  9. var val = $(this).val(),
  10. stored = $.data($(this)[0], "original_text");
  11.  
  12. /* Store the original value on the first pass through */
  13. if(typeof stored === "undefined") {
  14. $.data($(this)[0], "original_text", val);
  15. stored = val;
  16. }
  17.  
  18. if(val === stored) $(this).val("");
  19. },
  20.  
  21. checkAndReset: function() {
  22. if($(this).val() === "")
  23. $(this).val($.data($(this)[0], "original_text"));
  24. }
  25. }
  26. };
  27.  
  28. /* Super simple focus/blur text handling */
  29. $(".myElements").focus(page.inputs.checkAndStore).blur(page.inputs.checkAndReset);
Add Comment
Please, Sign In to add comment