fl-builder-admin-usage.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. (function( $ ) {
  2. /**
  3. * Enable/Disable usage stats helper.
  4. *
  5. * @since 2.1
  6. */
  7. var FLBuilderUsage = {
  8. init: function() {
  9. FLBuilderUsage._fadeToggle()
  10. FLBuilderUsage._enableClick()
  11. FLBuilderUsage._disableClick()
  12. },
  13. _fadeToggle: function() {
  14. $( 'a.stats-info' ).click( function( e ) {
  15. e.preventDefault();
  16. $( '.stats-info-data' ).fadeToggle()
  17. })
  18. },
  19. _enableClick: function() {
  20. $( '.buttons span.enable-stats' ).click( function( e ) {
  21. nonce = $(this).closest('.buttons').find('#_wpnonce').val()
  22. data = {
  23. 'action' : 'fl_usage_toggle',
  24. 'enable' : 1,
  25. '_wpnonce': nonce
  26. }
  27. FLBuilderUsage._doAjax( data )
  28. })
  29. },
  30. _disableClick: function() {
  31. $( '.buttons span.disable-stats' ).click( function( e ) {
  32. nonce = $(this).closest('.buttons').find('#_wpnonce').val()
  33. data = {
  34. 'action' : 'fl_usage_toggle',
  35. 'enable' : 0,
  36. '_wpnonce': nonce
  37. }
  38. FLBuilderUsage._doAjax( data )
  39. })
  40. },
  41. _doAjax: function( data ) {
  42. $.post(ajaxurl, data, function(response) {
  43. FLBuilderUsage._close()
  44. });
  45. },
  46. _close: function() {
  47. $( '.fl-usage').closest('.notice').fadeToggle()
  48. }
  49. };
  50. $( function() {
  51. FLBuilderUsage.init();
  52. });
  53. })( jQuery );