• Trying to get javascript callback working : favorites_after_button_submit, so that I can pop up login modal if user not logged in when they favourite.

    Website says to add simple-locator script as dependency. Do you mean simple-favorites? Neither seems to work. Can you please share more complete example?

    Callback Functions
    To use the callback functions in your theme’s scripts, the simple locator script handle must be added as a dependency when enqueueing your script. The Simple Locator script handle is simple-locator. See the WordPress Codex for more information about properly enqueuing scripts.

    https://wordpress.org/plugins/favorites/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @river-clement ,

    since I went through it myself I can explain how to approach this.

    In order to let something happen after the button has been pressed (= post has been added to favorites, NOT removed), you best use JavaScript to e.g. show a div with a message as in my case. For the script not to fail because a crucial resource from the plugin itself hasn’t loaded, you add simple-locator as a dependency for your JavaScript to load. The WordPress Codex helps you understand how you best include a script and/or CSS files into your theme, and then you enqueue your script like this:

    wp_enqueue_script('script', get_stylesheet_directory_uri() . '/js/script.js', 'simple-locator', '1.0.0', true);

    , and inside your script.js you could do something like this:

    function favorites_after_button_submit(favorites){
    	jQuery('.simplefavorite-button.active').after('<div class="fav_success"><i class="fa fa-info-circle"></i>Contract successfully added to your clipboard.</div>');
    	jQuery('.fav_success').fadeIn(1500).delay(5000).fadeOut(1500);
    }

    – does that help you out? It is working in my case (showing a message after user added fav, disappears again after 5 seconds).

    Best

    physalis

    PS: Of course, you have to style the div, foremost to not appear on loading for it to fadeIn if this is your desire :).

    PS: the correct handle is “simple-favorite” not “simple-locator”

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Javascript callbacks clarification’ is closed to new replies.