Guest User

Untitled

a guest
May 26th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. // jQuery plugin to easily implement autosave
  2. //
  3. //
  4. //
  5. //
  6. ;(function($) {
  7. $.fn.typed = function(settings) {
  8.  
  9. var config = {
  10. 'callback': function(){},
  11. wait : 750
  12. };
  13. if (settings) $.extend(config, settings);
  14.  
  15. this.each(function(){
  16. $(this).attr('old-val', $(this).val());
  17. var that = this
  18. function save(){
  19. var val = $(that).val()
  20. var old_val = $(that).attr('old-val');
  21. if (val != old_val) {
  22. config.callback.call(that)
  23. $(that).attr('old-val', val )
  24. }
  25. }
  26. var t;
  27. $(this).keydown(function(){
  28. clearTimeout(t)
  29. })
  30. $(this).keyup(function(){
  31. clearTimeout(t)
  32. t = setTimeout(save, config.wait);
  33. })
  34. })
  35. return this;
  36. };
  37. })(jQuery);
  38.  
  39. //example usage
  40. // $('.datepicker').typed({callback : change_form});
Add Comment
Please, Sign In to add comment