Last active
December 26, 2015 01:19
-
-
Save KurtWM/7070727 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*properties | |
addClass, after, ajaxComplete, appendTo, attr, children, css, filter, find, | |
first, prev, remove, removeAttr, removeClass, test, url | |
*/ | |
var customButtonsCreated = false, | |
// Douglas Crockford's short method for determining object types. | |
typeOf = function (value) { | |
"use strict"; | |
var s = typeof value; | |
if (s === 'object') { | |
if (value) { | |
if (value instanceof Array) { | |
s = 'array'; | |
} | |
} else { | |
s = 'null'; | |
} | |
} | |
return s; | |
}, | |
addInfoLinkAfter = function (obj, url, txt, cls, icon) { | |
"use strict"; | |
console.log("addInfoLinkAfter() has fired for: " + cls); | |
icon = icon || null; | |
cls = cls || null; | |
$(obj).after("<a href='" + url + "' target='_blank'" + (typeOf(cls) === 'null' ? "" : "class='" + cls + "'") + ">" + (typeOf(icon) === 'null' ? "" : "<i class='" + icon + "'></i> ") + txt + "</a>"); | |
}, | |
addInfoLinks = function () { | |
"use strict"; | |
var $prayerAnchor; | |
// Change the prayer request button section into three informational buttons. | |
$(".live-prayer p").remove(); | |
$prayerAnchor = $(".live-prayer button").filter(":first-child"); | |
//$prayerAnchor.addClass("btn-prayer"); | |
addInfoLinkAfter( | |
$prayerAnchor, | |
"http://www.johnsonferry.org/prayerrequest/", | |
"Prayer", | |
"btn-prayer button blue", | |
"icon-comment-alt" | |
); | |
addInfoLinkAfter( | |
$prayerAnchor, | |
"http://www.johnsonferry.org/aboutus.aspx", | |
"About Us", | |
"btn-aboutus button blue", | |
"icon-info-sign" | |
); | |
addInfoLinkAfter( | |
$prayerAnchor, | |
"http://jfaccess.johnsonferry.org/default.aspx?page=3996", | |
"Next Steps", | |
"btn-nextsteps button blue", | |
"icon-hand-right" | |
); | |
// Remove original button (does not match new buttons). | |
$prayerAnchor.remove(); | |
// The .live-prayer element may be hidden by having its size set to 0px. | |
// Now that we have finished altering it, we may set its height to 100%. | |
$(".live-prayer").css("height", "100%"); | |
}, | |
relocateLoginButton = function () { | |
"use strict"; | |
// Make variable of the list item containing the Log In button. | |
var $loginBtn = $( | |
".top-bar-section ul li:has( a[data-behavior='signin_account'] )" | |
); | |
// Remove any "divider" element that may be in front of the list item. | |
$loginBtn.prev(".divider").remove(); | |
// Remove list item from the header links list and place it into the footer links list. | |
$loginBtn | |
.appendTo($(".footer-links")) // Move item | |
.removeAttr("class") // Remove class attribute | |
.children("a").first() // Select item's anchor tag | |
.removeClass("blue button") // Remove current classes from anchor | |
.addClass("login") // Optionally add class to anchor | |
.css("border-left", "0"); // Remove default left border | |
// Make the top-bar-section visible. | |
$(".top-bar-section .right").css("display", "block"); | |
}, | |
moveListItems = function (from, to) { | |
"use strict"; | |
var $fromListItems, | |
$toListItem; | |
from = from || $(".top-bar-section .left .links .dropdown"); | |
to = to || $(".top-bar-section .right"); | |
$fromListItems = $(from).find("li"); | |
$toListItem = $(to).find("li").first(); | |
$fromListItems.removeClass().addClass($toListItem.attr("class")); | |
$fromListItems.children().removeClass().addClass($toListItem.children() | |
.first() | |
.attr("class")); | |
$fromListItems.appendTo($(to)); | |
$(".top-bar-section .left .links").remove(); | |
}; | |
$(document).ajaxComplete(function (event, xhr, settings) { | |
"use strict"; | |
console.log("document.ajaxComplete has fired: " + event + "; " + xhr + "; " + settings.url) | |
// If the main XMLHttpRequest has completed, update the window. | |
// As of this writing, the main XMLHttpRequest URL is: | |
// '/api/v1/events/current?expand=event_slides%2Cevent_videos' | |
// We look for the main part of the URL using a Regular Expression. | |
if (/\/api\/v1\/channels\/identity/.test(settings.url)) { | |
console.log("Running functions after XMLHttpRequest has completed.") | |
if (!customButtonsCreated) { | |
addInfoLinks(); | |
customButtonsCreated = true; | |
} | |
} | |
if (/\/api\/v1\/events\/current/.test(settings.url)) { | |
console.log("Running functions after XMLHttpRequest has completed.") | |
relocateLoginButton(); | |
moveListItems(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment