Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Insert code

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #242719
    Bigg
    Participant

    Hello!

    Mission: when you click X in the popup window – it will fire the cookie code.

    Please help me to insert correctly part of cookie code! From this:
    <script type=”text/javascript”>
    $(window).load(function() {
    var hideTheModal = $.cookie(‘hideTheModal’);
    if(hideTheModal == null){
    setTimeout(function(){
    $(‘#opn-win’).modal();
    $(‘.close-modal’).click(function(){ // Button X. Link to .close-modal class
    // add cookie
    $.cookie(‘hideTheModal’, { expires: 30, path: ‘/’ });
    });
    }, 7000);
    }
    });</script>

    To this:
    <script type=”text/javascript”>
    jQuery(document).ready(function() {
    jQuery(‘#myModal’).reveal();
    });</script>

    #242721
    rkieru
    Participant

    Markdown will help you format that in a much more readable fashion. Based on the code you’ve provided, can I assume correctly that you are relying on Foundation to power your modal?

    If so, I assume this solution would work.

    jQuery(document).ready(function() {
        jQuery('#myModal').reveal({ "closed": function () { 
            $.cookie('hideTheModal', { expires: 30, path: '/' }); 
        });
    });
    
    #242730
    Bigg
    Participant

    rkieru, ye, Foundation!
    If you don’t mind, can you tell me please hot to insert options of this modal to your code?

    http://codepen.io/Krok/pen/aZdaWe

    #242732
    rkieru
    Participant

    I would suggest adding this into your code:

    closed: function () { 
            $.cookie('hideTheModal', { expires: 30, path: '/' }
    }
    

    It’s really nothing more than adding another option to the list of options you have present, but I cannot test it as I have no real practice with Foundation.

    #242752
    Bigg
    Participant

    Ok, thanx! But is it possible to insert options in code?

    #242825
    rkieru
    Participant

    I don’t fully understand your question. The code I presented above as needing to be added into your script IS an option: closed is an option for Foundation’s “Reveal” feature.

    $('#myModal').reveal({
        animation: 'fadeAndPop',                   
        animationspeed: 300,                       
        closeonbackgroundclick: true,             
        dismissmodalclass: 'close-reveal-modal',    //the class of a button or element that will close an open modal
        closed: function () { 
            $.cookie('hideTheModal', { expires: 30, path: '/') }
        }
    });
    
Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.