Skip to content

Instantly share code, notes, and snippets.

@iCodeForBananas
Created February 13, 2017 17:53
Show Gist options
  • Save iCodeForBananas/139667de4924b72e132d95a9cfff7b01 to your computer and use it in GitHub Desktop.
Save iCodeForBananas/139667de4924b72e132d95a9cfff7b01 to your computer and use it in GitHub Desktop.
//
//
// Ladybug House custom scripts
//
//
(function ($) {
$(function () {
//Give Today Popup:
injectPopup();
openPopup();
closePopup();
//Media items filters
mediaItemsTagsToClasses();
mediaItemsClassesToFilters();
mediaFilters();
//Fix on Media page Read more link
readMoreLinkFix();
//Move Twitter Button to Top of block
moveTwitterFollowBtn();
//Layout 50% halves to sidebar + content
halfToSidebar()
//The Team page
theTeamPage();
//Navigation on the same page on Our Story page
OurStoryNavigation();
//Splash page image fix
//splashPage();
});
var injectPopup = function () {
var href = window.location.href;
var thisPage = href.split('/').pop();
var tarr = href.split('/'); //
var thisPageWithSlash = tarr[tarr.length-2];
if (thisPage == "give" || thisPageWithSlash == "give"){
$("body").prepend("<div class='overlay'></div><div id='donate-popup'><div class='close-popup'>X</div><iframe src='https://entry.donorsnap.com/forms/oForms.aspx?id=NTI3YjQwOWYtZWYyNi00NTVmLWJiNWMtYzY1ZGI0MWEzZGI3'></iframe</div>");
}
}
var openPopup = function ()
{
jQuery("a[href='#donate-popup']").on("click",function(e){
e.preventDefault();
$(".overlay, #donate-popup").fadeIn();
});
};
var closePopup = function ()
{
jQuery("#donate-popup .close-popup").on("click",function(){
$(".overlay, #donate-popup").fadeOut();
});
};
var mediaItemsTagsToClasses = function ()
{
if( $("main").hasClass("media-page") ){
var mediaContainer = $(".summary-item-list-container");
mediaContainer.find(".summary-item").each(function(){
var tag = $(this).find(".summary-metadata-container--above-title .summary-metadata--secondary .summary-metadata-item--tags > a").text();
tagLower = tag.toLowerCase();
$(this).addClass("tag-"+tagLower);
$(this).addClass("mix");
$(this).attr("data-tag",tagLower);
tag = "";
});
}
}
var mediaItemsClassesToFilters = function ()
{
if( $("main").hasClass("media-page") ){
var mediaContainer = $(".summary-item-list-container");
var filters = [];
mediaContainer.find(".summary-item").each(function(){
var tag = $(this).data("tag");
filters.push(tag);
});
uniqueFilters = $.unique(filters);
mediaContainer.before("<div id='filter-tags'><span>Filter by: </span><ul><li class='filter active' data-filter='all'>VIEW ALL</li></ul></div>")
$.each(uniqueFilters, function( index, value ) {
$("#filter-tags > ul").append("<li class='filter' data-filter='.tag-"+value+"'>"+value+"</li>")
});
}
}
var mediaFilters = function()
{
if( $("main").hasClass("media-page") ){
var mediaContainer = $(".summary-item-list-container > div");
mediaContainer.mixItUp();
}
}
var readMoreLinkFix = function ()
{
if( $("main").hasClass("media-page") ){
$(".summary-item").each(function(){
var titleLink = $(this).find(".summary-title-link").attr("href");
$(this).find(".summary-read-more-link").attr("href", titleLink);
});
}
}
var moveTwitterFollowBtn = function()
{
followBtn = $(".twitter-block").find(".squarespace-follow-button");
followBtnClone = followBtn.clone();
followBtn.remove();
$(".twitter-block").prepend(followBtnClone);
}
var halfToSidebar = function(){
if($("main").hasClass("half-to-sidebar")){
$(".row").children(".span-6:first-child").removeClass("sqs-col-6 span-6").addClass("sqs-col-3 span-3");
$(".row").children(".span-6:last-child").removeClass("sqs-col-6 span-6").addClass("sqs-col-9 span-9");
}
}
var theTeamPage = function () {
var href = window.location.href;
var thisPage = href.split('/').pop();
var tarr = href.split('/'); //
var thisPageWithSlash = tarr[tarr.length-2];
if (thisPage.indexOf("ladybug-team") >= 0 || thisPageWithSlash.indexOf("ladybug-team") >= 0 ){
$("body").addClass("the-team");
}
$(".the-team .summary-item-list").children(".summary-item").each(function(){
// Name and Role
var nameAndRole = $(this).find(".summary-title").text();
$(this).find(".summary-title").remove();
var tarr = nameAndRole.split('|');
var role = tarr[tarr.length-1];
var name = tarr[tarr.length-2];
var thumbnail = $(this).find(".summary-thumbnail-container");
$("<h3 class='member-name'>"+name+"</h3><h4 class='member-role'>"+role+"</h4>").insertAfter(thumbnail);
// Information popup
var content = $(this).find(".summary-excerpt");
$(this).hover(
function () {
content.fadeIn("fast");
},
function () {
content.fadeOut("fast");
}
);
});
}
var OurStoryNavigation = function(){
var href = window.location.href;
var thisPage = href.split('/').pop();
var tarr = href.split('/'); //
var thisPageWithSlash = tarr[tarr.length-2];
if (thisPage.indexOf("our-story") >= 0 || thisPageWithSlash.indexOf("our-story") >= 0 ){
var navigation = "<ul class='our-story-nav'>";
var indexTitle = 0;
$(".main-content h2").each(function(){
anchor = indexTitle++;
$(this).attr("data-title", anchor )
var titleText = $(this).text();
navigation += "<li data-goto='"+anchor+"'>"+titleText+"</li>";
});
navigation += "</ul>";
$(".main-content").prepend(navigation);
$(".our-story-nav").on("click","li",function(){
var goTo = $(this).data("goto");
$('html, body').animate({
scrollTop: $("h2[data-title='"+goTo+"']").offset().top-20
}, 1000);
});
}
}
var splashPage = function(){
var image = $(".collection-layout-splash #thumbnail img");
var imageWidth = parseInt(image.css("width"));
var calculateCenter;
$(window).resize(function(){
calculateCenter = imageWidth / 2;
image.css("left","50%");
image.css("margin-left", "-"+calculateCenter+"px")
//console.log( image + " and "+ calculateCenter);
});
//Temporary Give Today link:
$("a[href='/give/'], a[href*='entry.donorsnap']").attr("href","https://givebig.seattlefoundation.org/npo/ladybug-house");
// Remember to change back the URL of the popup button to #donate-popup
$(".givebig-overlay,.givebig-popup").fadeIn("fast");
$(".givebig-overlay, .givebig-close").on("click",function(){
$(".givebig-overlay").fadeOut("fast");
$(".givebig-popup").fadeOut("fast");
});
}
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment