mock.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ;(function(){
  2. window.patch_date = function patch(f){
  3. var NativeDate = window.Date;
  4. var date = function date(y,m,d,h,i,s,j){
  5. switch(arguments.length){
  6. case 0: return date.now ? new NativeDate(date.now) : new NativeDate();
  7. case 1: return new NativeDate(y);
  8. case 2: return new NativeDate(y,m);
  9. case 3: return new NativeDate(y,m,d);
  10. case 4: return new NativeDate(y,m,d,h);
  11. case 5: return new NativeDate(y,m,d,h,i);
  12. case 6: return new NativeDate(y,m,d,h,i,s);
  13. case 7: return new NativeDate(y,y,m,d,h,i,s,j);
  14. }
  15. };
  16. date.UTC = NativeDate.UTC;
  17. return function(){
  18. Array.prototype.push.call(arguments, date);
  19. window.Date = date;
  20. f.apply(this, arguments);
  21. window.Date = NativeDate;
  22. };
  23. };
  24. window.patch_show_hide = function patch(f){
  25. var oldShow = $.fn.show,
  26. newShow = function () {
  27. $(this).removeClass('foo');
  28. return oldShow.apply(this, arguments);
  29. };
  30. var oldHide = $.fn.hide,
  31. newHide = function () {
  32. $(this).addClass('foo');
  33. return oldHide.apply(this, arguments);
  34. };
  35. return function(){
  36. $.fn.show = newShow;
  37. $.fn.hide = newHide;
  38. f.apply(this, arguments);
  39. $.fn.show = oldShow;
  40. $.fn.hide = oldHide;
  41. };
  42. };
  43. }());