notices.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * Customizer controls toggles
  3. *
  4. * @package Astra
  5. */
  6. ( function( $ ) {
  7. /**
  8. * Helper class for the main Customizer interface.
  9. *
  10. * @since 1.0.0
  11. * @class ASTCustomizer
  12. */
  13. AstraNotices = {
  14. /**
  15. * Initializes our custom logic for the Customizer.
  16. *
  17. * @since 1.0.0
  18. * @method init
  19. */
  20. init: function()
  21. {
  22. this._bind();
  23. },
  24. /**
  25. * Binds events for the Astra Portfolio.
  26. *
  27. * @since 1.0.0
  28. * @access private
  29. * @method _bind
  30. */
  31. _bind: function()
  32. {
  33. $( document ).on('click', '.astra-notice-close', AstraNotices._dismissNoticeNew );
  34. $( document ).on('click', '.astra-notice .notice-dismiss', AstraNotices._dismissNotice );
  35. },
  36. _dismissNotice: function( event ) {
  37. event.preventDefault();
  38. var repeat_notice_after = $( this ).parents('.astra-notice').data( 'repeat-notice-after' ) || '';
  39. var notice_id = $( this ).parents('.astra-notice').attr( 'id' ) || '';
  40. AstraNotices._ajax( notice_id, repeat_notice_after );
  41. },
  42. _dismissNoticeNew: function( event ) {
  43. event.preventDefault();
  44. var repeat_notice_after = $( this ).attr( 'data-repeat-notice-after' ) || '';
  45. var notice_id = $( this ).parents('.astra-notice').attr( 'id' ) || '';
  46. var $el = $( this ).parents('.astra-notice');
  47. $el.fadeTo( 100, 0, function() {
  48. $el.slideUp( 100, function() {
  49. $el.remove();
  50. });
  51. });
  52. AstraNotices._ajax( notice_id, repeat_notice_after );
  53. var link = $( this ).attr( 'href' ) || '';
  54. var target = $( this ).attr( 'target' ) || '';
  55. if( '' !== link && '_blank' === target ) {
  56. window.open(link , '_blank');
  57. }
  58. },
  59. _ajax: function( notice_id, repeat_notice_after ) {
  60. if( '' === notice_id ) {
  61. return;
  62. }
  63. $.ajax({
  64. url: ajaxurl,
  65. type: 'POST',
  66. data: {
  67. action : 'astra-notice-dismiss',
  68. nonce : astraNotices._notice_nonce,
  69. notice_id : notice_id,
  70. repeat_notice_after : parseInt( repeat_notice_after ),
  71. },
  72. });
  73. }
  74. };
  75. $( function() {
  76. AstraNotices.init();
  77. } );
  78. } )( jQuery );