[Pro] Javascript for Search Field, Safari problems

Walter,

I finalized my CSS and JS for my cookie application. No Protaculous2/Prototype or jQuery external libraries required.

The cookie is used only to remember the last time a DIV overlay was displayed, and when the cookie expires (I set it to 30 days), then the overlay will display again and a new cookie will be set when the user clicks anywhere on-screen to close the overlay. By using the cookie, the overlay is not bothersome (not displayed on every page load) to repeat visitors.

For the sake of others who wish to do something similar, here’s the code…

Put this CSS in "before in Freeway’s HTML Markup dialog:

<style type="text/css">
/* DIV overlay is named "legaleze" */
#legaleze{
   display:none;
   top: 0;
   left: 0;
   right: 0;
   bottom:0;
   background-color: white;
   opacity: 0.9;
   filter: alpha(opacity=90);
}
/* Close box is named "box" */
#box:hover {
  background-color: red;
  cursor: pointer;
}
</style>

Put this JS in “before ” in Freeway’s HTML markup dialog:

<script type="text/javascript">
function setCookie(cname,cvalue,exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    document.cookie = cname + "=" + cvalue + ";" + "expires=" + d.toGMTString() + ";path=/";
}
function getCookie(cname) {
    var name = cname + "=";
    var ca = decodeURIComponent(document.cookie).split(';');
    for(var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}
document.addEventListener('DOMContentLoaded', function(){
    var cook=getCookie("kiramek_patent_notice");
    if (cook === "Show every 30 days") { //do nothing
    } else { //close the overlay on click and set cookie
    document.getElementById("legaleze").style.display = 'block';
    document.getElementById('legaleze').onclick = function(){ 
        document.getElementById("legaleze").style.display = 'none'; 
        setCookie("kiramek_patent_notice", "Show every 30 days", 30);
        }
    }
});
</script

NOTE: Add the closing greater-than symbol to the end of /script above. I tried to add it, but it totally messes up the line breaks here on FreewayTalk when I do that, even though it’s situated within “[code]” tags.

–James Wages


dynamo mailing list
email@hidden
Update your subscriptions at: