• Resolved siriusly

    (@siriusly)


    I’ve set up modal to display a disclaimer statement when a user clicks an email icon. User then must click either an “Accept” button in the modal, which takes them to “mailto:[email protected],” opening thir email client, or they choose to just close the modal.

    I would like only the modal window to close when the user clicks “Accept,” so if/when they return to the browser window, the modal is no longer visible (but browser window remains open).

    Suggestions would be most welcomed! Thank you!
    ==========
    Here is code I’m using for calling modal:

    <img class="eModal-6" title="Email Firstname Lastname" src="https://mysite.net/wp-content/uploads/glyphicons_010_envelope.png" alt="Email Firstname Lastname" />

    Here is the “Accept” button code:
    [flat_button text="Accept" title="Accept terms and continue" url="mailto:[email protected]" padding="10px 20px" bg_color="#73C700" border_color="#73C700" border_width="1px" text_color="#FFFFFF" text_size="14px" align="center" target="_self"]

    https://www.ads-software.com/plugins/easy-modal/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Daniel Iser

    (@danieliser)

    You need to add something like this. Can be added to your themes js, added to the footer via hooks, or added to the modals content using the <script></script>

    <script>
        jQuery('#eModal-6 button').click(function(e){
            jQuery('#eModal-6').emodal('close');
        });
    </script>
    Thread Starter siriusly

    (@siriusly)

    Thank you so much! Since I need to do the same thing with 7 different modals, it sounds like it would make the most sense to add it to the modals content…. I’m not very familiar with jquery — could you tell me where in the content to add it? Thank you!

    Plugin Author Daniel Iser

    (@danieliser)

    If they are all identical content you could do one script and place it in your themes footer.php below <?php wp_footer(); ?>

    <script>
    jQuery(document).ready(function () {
        jQuery('#eModal-1, #eModal-2, #eModal-3, #eModal-4, #eModal-5, #eModal-6').find('button, .button').click(function (e) {
            jQuery(this).parents('.emodal').emodal('close');
        });
    });
    </script>

    Of course adjust the ids as needed, and if you have any other buttons in the modal they will trigger it as well unless we target them more specifically in the .find(”) parameter. There you can specify a css class .find('.myclass'), ids .find('#mybutton'), elements.find(‘div’)or even combinations to specify say a button with a certain class.find(‘button.myclass’)`

    There are way more selectors possible but it depends on your modals content and the buttons html. You can learn more here

    Thread Starter siriusly

    (@siriusly)

    UPDATE:
    I figured out that I needed to add the correct selector name at .find('button, .button')
    so it is now
    .find('button, .button, .my_button')
    and it is working!!

    Thanks again!!!
    =====================

    So, I’m trying to use this in the child theme’s footer.php… don’t seem to have it working yet… here’s the last part of the footer.php file.

    <?php   wp_footer(); ?>
    
    <!-- Close eModal window with Accept button click |SJ_20140830| -->
    <script>
    jQuery(document).ready(function () {
        jQuery('#eModal-1, #eModal-2, #eModal-3, #eModal-4, #eModal-5, #eModal-6, #eModal-7, #eModal-8, #eModal-9').find('button, .button').click(function (e) {
            jQuery(this).parents('.emodal').emodal('close');
        });
    });
    </script>
    
    <?php
        if( $udesign_options['enable_cufon'] ) : ?>
    	<script type="text/javascript"> Cufon.now(); </script>
    <?php
        endif; ?>
    <?php udesign_body_bottom(); ?>
    
    </body>
    </html>

    What might I be doing wrong?

    Plugin Author Daniel Iser

    (@danieliser)

    Hey siriusly, welcome to the wonderful world of jQuery and Javascript :).

    In reality you can shorten your find to simply .find('.my_button'). You can be as broad or as specific as you need to be with jQuery selectors. For example i can select all images, all images with class .image, every other image with the class .image, or just the 5th one inside main content.

    Thread Starter siriusly

    (@siriusly)

    Awesome. Thanks! Wasn’t sure if the other selectors were important, so I left them in. ?? Been digging into the tutorials, and I have to say, it’s great to begin getting a handle on something that has been lurking in the background as “mysterious” until now. Thanks again for a great plugin, and for the great support! BTW… here’s the page https://bit.ly/1B8XGIF

    Plugin Author Daniel Iser

    (@danieliser)

    Hey, just tried your test page. the button isnt working. You need to change your footer script to match the output of your button.

    Your button has a class of flat-custom-button

    So your .find() needs to be .find('.flat-custom-button')

    Replace your script with this and you should be 100% fine for future as well.

    <script>
    jQuery(document).ready(function () {
        jQuery('#eModal-1, #eModal-2, #eModal-3, #eModal-4, #eModal-5, #eModal-6, #eModal-7, #eModal-8, #eModal-9').find('.flat-custom-button').click(function (e) {
            e.preventDefault();
            jQuery(this).parents('.emodal').emodal('close');
        });
    });
    </script>
    Thread Starter siriusly

    (@siriusly)

    Oops! Thanks!!!!

    Plugin Author Daniel Iser

    (@danieliser)

    NP. Please take a moment to rate and review the plugin and or support. https://www.ads-software.com/support/view/plugin-reviews/easy-modal

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Close Modal when opening email app’ is closed to new replies.