0

I would like to run avgrund plugin if current user is a visitor else I'd like tor run a different piece of code.

My code looks like this so far:

<html>
    <head>
        <link rel="stylesheet" href="http://labs.voronianski.com/jquery.avgrund.js/avgrund.css">
        <link rel="stylesheet" href="http://labs.voronianski.com/jquery.avgrund.js/style.css">
    </head>
    <body>

        <a href="#" id="reply1" class="replyButton">
            <span>reply</span>
        </a>
        <script src="https://code.jquery.com/jquery-3.2.1.min.js"> </script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.avgrund/1.3.3/jquery.avgrund.js"></script>
        <script>
         $(function() {

             var username = "Visitor";

             $(".replyButton").on('click', function(e) {

                 if (typeof username !== 'undefined') {

                     if (username !== 'Visitor') {
                         console.log("Do some stuff");
                     }
                     else {

                         var selectedButton = $(this).attr('id');
                         selectedButton = '#' + selectedButton;
                         $(selectedButton).avgrund();
                     }
                 }

             });


         });

        </script>

    </body>
</html>

But the problem is popup opens after two clicks. How should I make the code run on first click.

Here is the js fiddle demo:

https://jsfiddle.net/sv1mmn6q

Update:

I tried this method which seems to work fine for this small example.

$(document).avgrund({
   openOnEvent: true
 });

Updated jsfiddle demo:

https://jsfiddle.net/sv1mmn6q/1/

But in fact makes avgrund plugin to activate on click events. For example if you click home page it activates avgrund plugin. Which is the unintended behavior.

1 Answers1

0

After setting these options it seems to work fine.

setEvent: 'click',
openOnEvent: false,