Skip to content

Instantly share code, notes, and snippets.

@liammcinroy
Created May 25, 2014 18:45
Show Gist options
  • Save liammcinroy/5a293d17980915c15e53 to your computer and use it in GitHub Desktop.
Save liammcinroy/5a293d17980915c15e53 to your computer and use it in GitHub Desktop.
Hide messages
javascript:var popUp = function(a,e,f,b){ b || $(".popup").remove(); b={}; a-=$(window).scrollLeft(); e-=$(window).scrollTop(); a < $(window).width() / 2 ? b.left= a : b.right = $(window).width() - a; e < $(window).height() / 2 ? b.top = e : b.bottom = $(window).height() - e; var c = div("popup").css(b).hide(); $("<div class='btn-close'>X</div>").click(function(){ $(this).closest(".popup").fadeOut(200,function(){ $(this).remove() }) }).prependTo(c); c.appendTo( f || $("body") ).fadeIn(200); if( f !== undefined && f.hasClass("message") ){ var hideMessage = document.createElement("div"); var message; if( f[0].getAttribute("data-remove-message") == null){ message = "Click to hide this message"; }else{ message = "Click to restore this message"; } hideMessage.innerHTML = message; $(hideMessage).css("cursor","pointer"); hideMessage.onclick=function(e){ shutter(e,c) }; c.append(hideMessage); } c.close = function(){ c.fadeOut( 200, function(){c.remove()} ) }; return c }; function shutter(evnt,caller){ var tar = evnt.target; var element = $(tar).closest('.message')[0]; var message; var remove; if( element.getAttribute("data-remove-message") == null){ message = "remove message?"; remove = true; }else{ message = "restore message?"; remove = false; } if( remove ){ element.setAttribute("data-remove-message","restore"); element.setAttribute("data-previous-height",$(element).height()); $(element).find('.content').fadeTo("fast",0.01); $(element).css('overflow','hidden'); $(element).animate({height:'1.5em'}, "medium", function(){ $(element).find('.content').css("position","absolute"); $(element).find('.content').css('z-index','-1'); }); $(element).css("background-color","grey"); }else{ element.removeAttribute("data-remove-message"); var h = element.getAttribute("data-previous-height") + "px"; element.removeAttribute("data-previous-height"); $(element).css("background-color",""); $(element).animate({height:h}, "medium", function(){ $(element).find('.content').css("position",""); $(element).css("height",""); $(element).css('overflow',''); }); $(element).find('.content').css("z-index",""); $(element).find('.content').fadeTo("fast",1); } caller.fadeOut( 200, function(){caller.remove()} ) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment