// Custom jQuery Easing jQuery.easing['jswing'] = jQuery.easing['swing']; jQuery.extend( jQuery.easing, { easeOutBounce: function (x, t, b, c, d) { if ((t/=d) < (1/2.75)) { return c*(7.5625*t*t) + b; } else if (t < (2/2.75)) { return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; } else if (t < (2.5/2.75)) { return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; } else { return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; } } }); // remap jQuery to $ (function($){ $.fn.attentionGrabber = function(options) { var defaults = { duration : 500, position : 'top', closeable : true, showAfter : 0, keepHidden : false, borderSize : 3, height : 40, easing : "swing" }, settings = $.extend({}, defaults, options); settings.totalHeight = parseInt( settings.height, 10) + parseInt( settings.borderSize, 10); settings.duration = parseInt( settings.duration, 10); settings.showAfter = parseInt(settings.showAfter, 10)*1000; // Main elements var wrap = $(this), grabber = wrap.find("#attentionGrabber"), link = grabber.find(".link"), closeBtn = grabber.find("#closeAttentionGrabber"), openBtn = wrap.find("#openAttentionGrabber"), animationParam = {}, animationProperty = "", buttonAnimationParam = {}, buttonAnimationProperty = "", showOpenButton = function(){ buttonAnimationParam[buttonAnimationProperty] = settings.totalHeight; openBtn.animate( buttonAnimationParam, (settings.duration/2), settings.easing ); wrap.removeClass("openGrabber"); }, hideOpenButton = function(){ buttonAnimationParam[buttonAnimationProperty] = - Math.abs(34 - settings.height); openBtn.animate( buttonAnimationParam, (settings.duration/2), function(){ showGrabber(); } ); }, // The show/hide animations showGrabber = function(){ animationParam[animationProperty] = 0; wrap.animate( animationParam , settings.duration, settings.easing ,function(){ wrap.addClass("openGrabber"); } ); }, hideGrabber = function(){ animationParam[animationProperty] = -settings.totalHeight; wrap.animate( animationParam , settings.duration, function(){ showOpenButton(); } ); }, // Get the cookie foundCookie = false; // Initialize the property for the slide animation switch( settings.position ){ case "top" : animationProperty = "marginTop"; buttonAnimationProperty = "top"; break; case "top_fixed" : animationProperty = "top"; buttonAnimationProperty = "top"; break; case "bottom_fixed" : animationProperty = "bottom"; buttonAnimationProperty = "bottom"; break; } // Remove it from the DOM wrap.detach(); // Move it to the right position wrap.prependTo("body").css({ display : "block" }); if( foundCookie && settings.keepHidden && settings.closeable ){ // Show only the open button setTimeout( function(){ showOpenButton(); }, settings.showAfter ); }else { // Show the grabber for the first time setTimeout( function(){ showGrabber(); }, settings.showAfter ); } // Close grabber closeBtn.click(function(){ hideGrabber(); setCookie(); }); // Open grabber openBtn.click(function(){ hideOpenButton(); setCookie(); }); // Set the cookie function setCookie(){ if( settings.keepHidden ){ if( !foundCookie ){ $.ajax({ type : 'post', url : 'http://www.assuranceenligne.org/wp-content/plugins/attentionGrabber/functions/functions.php', data : "setCookie=true", success : function(results){ foundCookie = true; } }); }else{ $.ajax({ type : 'post', url : 'http://www.assuranceenligne.org/wp-content/plugins/attentionGrabber/functions/functions.php', data : "setCookie=false", success : function(results){ foundCookie = false; } }); } } } // Add a click counter link.click(function(){ $.ajax({ type : 'post', url : 'http://www.assuranceenligne.org/wp-content/plugins/attentionGrabber/functions/functions.php', data : "click=true", success : function(results){ } }); return true; }); } })(window.jQuery); jQuery(document).ready(function(){ jQuery("#attentionGrabberWrap").attentionGrabber({ position : 'bottom_fixed', showAfter : 0, keepHidden : true, duration : 300, closeable : true, height : 40, borderSize : 2, easing : 'swing' }); });