HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/globfdxw/public_html/wp-content/plugins/sermone/src/favorite.js
/**
 * Sermone favorite 
 * 
 * @package sermone
 */

import NoticeBox from './notice-box'

; ( ( w, $ ) => {
  'use strict'

  let N = new NoticeBox()

  const FavoriteHandle = () => {
    
    const sendData = async ( ID ) => {
      return await $.ajax( {
        type: 'POST',
        url: PHP_DATA.ajax_url,
        data: {
          action: 'sermone_ajax_add_to_favorite',
          id: ID
        },
        error ( err ) {
          console.log( err )
          alert( 'Internal error: Please reload page and try again!' )
        }
      } )
    }

    $( document.body ).on( {
      async 'sermone:addToFavorite' ( e, ID ) {
        const Result = await sendData( ID )
        
        N.setContent( Result.data.message )
        N.show()

        if( Result.data.fav.includes( ID ) ) {
          $( `[data-sermone-fav=${ ID }]` ).addClass( '__in-fav' )
        } else {
          $( `[data-sermone-fav=${ ID }]` ).removeClass( '__in-fav' )
        }
      } 
    } )

    $( 'body' ).on( 'click', '[data-sermone-fav]', function( e ) {
      e.preventDefault();
      let ID = $( this ).data( 'sermone-fav' )

      $( document.body ).trigger( 'sermone:addToFavorite', [ parseInt( ID ) ] )
    } )
  }  

  $( FavoriteHandle )

} )( window, jQuery )

module.exports = {}