|
(function ($) { |
|
|
|
// JSCookies |
|
var JSCookies = { |
|
|
|
defaults: { |
|
expiryDays: 1 |
|
}, |
|
|
|
createCookie: function (name, value, hours) { |
|
if (!hours) { |
|
days = this.defaults.expiryDays; |
|
} else { |
|
days = hours / 24; |
|
} |
|
|
|
date = new Date(); |
|
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); |
|
expires = "; expires=" + date.toGMTString(); |
|
|
|
document.cookie = name + "=" + value + expires + "; path=/"; |
|
|
|
return { "name": name, "value": value }; |
|
}, |
|
|
|
readCookie: function (name) { |
|
nameEQ = name + "="; |
|
ca = document.cookie.split(";"); |
|
for (i = 0; i < ca.length; i++) { |
|
c = ca[i]; |
|
while (c.charAt(0) == " ") { |
|
c = c.substring(1, c.length); |
|
} |
|
if (c.indexOf(nameEQ) == 0) { |
|
return c.substring(nameEQ.length, c.length); |
|
} else { } |
|
} |
|
return ""; |
|
}, |
|
|
|
eraseCookie: function (name) { |
|
this.createCookie(name, "", -1); |
|
return { "name": name, "value": null }; |
|
} |
|
}; |
|
|
|
// read cookie |
|
var TopNotificationCookie = JSCookies.readCookie("top_notification"); |
|
// var TopNotificationCookieLife = 1 / 360; // 1 / 360 = 10 sec, 24 = 1 day |
|
var TopNotificationCookieLife = 24; // 1 / 360 = 10 sec, 24 = 1 day |
|
|
|
console.log(TopNotificationCookie); |
|
|
|
if(TopNotificationCookie != 'Shown'){ |
|
|
|
// styles |
|
var styles = '<style>' + |
|
'#TopNotification { position: relative; z-index: 10; height: 40px; overflow: hidden; }' + |
|
'#TopNotification:before, #TopNotification:after { content: " "; display: block; width: 50%; height: 40px; background: #d5a00f; border-top: 1px solid #f9bf1d; position: absolute; z-index: -1; right: 50%; top: 0; }' + |
|
'#TopNotification:after { right: auto; left: 50%; background: #eeb311; }' + |
|
'#TopNotification .inner { display: block; width: 1080px; height: 40px; background: url(path/to/sprite.png) scroll no-repeat 0 -1px; position: absolute; z-index: 5; left: 50%; margin-left: -540px; top: 1px; font-size: 1px; text-align: left; text-indent: -99999px; text-decoration: none; }' + |
|
'#TopNotification .close { display: block; width: 40px; height: 40px; background: url(path/to/sprite.png) scroll no-repeat -990px -40px; position: absolute; z-index: 15; left: 50%; margin-left: 449px; top: -1px; font-size: 1px; text-align: left; text-indent: -99999px; text-decoration: none; }' + |
|
'#TopNotification .close:hover { background-position: -1030px -40px; }' + |
|
'</style>'; |
|
$(styles).appendTo('head'); |
|
|
|
// dom |
|
var $h = $('#Header'); |
|
var tn = '<div id="TopNotification">' + |
|
'<a class="inner" href="#" class="close" target="_blank">' + |
|
'Top Notification Alt Text' + |
|
'</a>' + |
|
'<a href="javascript:void(0);" class="close">' + |
|
'Close' + |
|
'</a>' + |
|
'</div>'; |
|
$(tn).insertBefore($h); |
|
|
|
var $tn = $('#TopNotification'); |
|
var $close = $('.close', $tn); |
|
|
|
// var $bgImg = $('<img />'); |
|
// $bgImg.bind('load', function() { |
|
// setTimeout(function(){ |
|
// $tn.slideDown(300); |
|
// }, 250); |
|
// }); |
|
// $bgImg.attr('src', '/path/to/image.png'); |
|
|
|
$close.click(function(){ |
|
if(!$close.is('clicked')){ |
|
$close.addClass('clicked'); |
|
$tn.slideUp(300); |
|
JSCookies.createCookie("top_notification", "Shown", TopNotificationCookieLife); |
|
} |
|
}); |
|
} |
|
|
|
})(jQuery); |