Logo downloadtip

by jarnesjo

HTML

<link rel="logo" type="image/svg" src="/logo.svg" data-title="Vector file (.svg)" />
<link rel="logo" type="image/png" src="/logo.png" data-title="Bitmap file (.png) 600px x 1000px" />
<img id="logo" src="http://dummyimage.com/125x125/000/fff" alt="Logo" />

CSS

#logo { margin: 200px; }
#downloadtip {
    border: 1px solid rgba(0, 0, 0, 0.2);
    display: none;
    padding: 1px;
    position: absolute;
    min-width: 160px;
    -moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
    -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
    -moz-border-radius: 6px;
    -webkit-border-radius: 6px;
    border-radius: 6px;
}
#downloadtip h3 {
    background: #f7f7f7;
    border-bottom: 1px solid #ebebeb;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 18px;
    padding: 8px 14px;
}
#downloadtip a { color: #555; display: block; text-decoration: none; }
#downloadtip .content {
    color: #333;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 13px;
    line-height: 20px;
    padding: 9px 14px;
}
#downloadtip .arrow,
#downloadtip .arrow:after { 
    position: absolute;
    display: block;
    width: 0;
    height: 0;
    border-color: transparent;
    border-style: solid;
}
#downloadtip .arrow {
    border-width: 11px;
}
#downloadtip .arrow:after {
    border-width: 10px;
    content: ""; 
}
#downloadtip .arrow{
    top: 50%;
    left: -11px;
    margin-top: -11px;
    border-right-color: #999;
    border-right-color: rgba(0, 0, 0, 0.25); 
    border-left-width: 0;
}
#downloadtip .arrow:after { 
    bottom: -10px;
    left: 1px;
    border-right-color: #ffffff;
    border-left-width: 0;
}

JavaScript

$(document).on("contextmenu", "#logo", function(e){
    if($('#downloadtip').length != 0) { return false; }
    
    $(this).css('position', 'relative');
    
    var container = $("<div/>", {
        "id": "downloadtip",
        "css": { "left": $("#logo").offset().left + $("#logo").width() + 12 }
    });
    var header = $("<h3/>", { "text": "Download logo?" });
    var content = $("<div/>", { "class": "content" }); 
    var arrow = $("<div/>", { "class": "arrow" }); 
    // Get the logos
    $('link[rel="logo"]').each(function(){
        var title = $(this).data('title');
        var href = $(this).attr('src');
        var logo = $("<a/>", { "text": title, "href": href });
        content.append(logo);
    });

    // Append to DOM
    container.append(header)
             .append(arrow)
             .append(content)
             .insertAfter('#logo');
    
    // Position top
    $('#downloadtip').css({
        'top': $('#logo').offset().top + ($('#logo').height() / 2 - $('#downloadtip').height() / 2)
    }).fadeIn();
    
    // Remove downloadtip
    $(document).click(function(e){ 
        // Fade it out then remove it
        $('#downloadtip').fadeOut(400, function(){ 
            $(this).remove();
        });
    });

    // Stop removing of downloadtip if you click the div
    $('#downloadtip').click(function(e) { 
        e.stopPropagation(); 
    });
    
   return false;
});