Skip to content

Instantly share code, notes, and snippets.

@nickfogle
Created May 15, 2014 17:55
Show Gist options
  • Save nickfogle/2879f91af2cce6e40e82 to your computer and use it in GitHub Desktop.
Save nickfogle/2879f91af2cce6e40e82 to your computer and use it in GitHub Desktop.
NetCommunity JavaScript Snippets
/**********************************************
Blackbaud Design Custom JavaScript
***********************************************
Site:
Author:
Created:
BBNC Version:
*********** CHANGE LOG ************************
**********************************************/
/************* global definitions ************/
var bbpage = Sys.WebForms.PageRequestManager.getInstance(); //BBNC
var isEditView = window.location.href.match('edit=');
/************* run page load functions ************/
bbpage.add_pageLoaded(function(){
bbGlobal();
siteGlobal();
if (isEditView) { uiGlobal() } // runs UI functions in postback for edit mode
});
$(window).load(function(){
if (!isEditView) { uiGlobal() }
});
/********** execute functions **********/
// execute default functions - remove or comment out unused functions
function bbGlobal() {
currentYear();
fixPositioning();
hideMenuItem('menu'); // replace 'menu' if you are using a different class for your menu
};
// execute page load (postback) functions
function siteGlobal() {
// your code here
};
// execute UI functions - such as slideshows
function uiGlobal() {
// your code here
};
/************* default functions ************ do not edit */
// replace copyright with current year
// note: this can be deprecated in BBNC 6.45 in favor of the Time merge field
function currentYear() { $("#currentYear").text((new Date).getFullYear()); };
// position fix - do not include on layout
// note: this can be deprecated by using the CSS approach
function fixPositioning() { $('div[id$=_panelPopup]').appendTo('body'); $('div[id$=_panelPopup_DropShadow]').appendTo('body'); };
// hide menu item
// note: this is helpful for linking pages in the menu that shouldn't be visible, such as confirmation pages
function hideMenuItem(menuClass) { $('.'+menuClass+' a[title=hide]').each(function(){ var ul = $(this).parent().parent(); var li = $(this).parent(); var parent = $(this).parent().parent().parent(); var a = ul.prev(); if ($(this).hasClass('selected')) { $(this).removeClass('selected'); a.addClass('selected'); } if (li.siblings().length > 0) { li.remove(); } else { ul.remove(); parent.removeClass('parent'); } }); $('ul.menu').css('visibility','visible'); };
/************* custom functions ************
insert new functions here, but do not execute here
********************************************/
/************* custom functions ************
paste minified plugin code here or include document reference
ex: <script src="document.doc?id=x"></script>
********************************************/
/**********************************************
Blackbaud Design Mobile JavaScript
***********************************************/
/************* global definitions ************/
var bbpage = Sys.WebForms.PageRequestManager.getInstance(); //BBNC
var isEditView = window.location.href.match('edit=');
/************* run page load functions ************/
bbpage.add_pageLoaded(function(){
bbGlobal();
//if ($('.CalendarViewContainer').length > 0) {miniCal();}
//if ($('.DonationFormTable').length > 0) {donationCSC();}
//if ($('.DonationFormTable').length > 0) {radioList();}
});
/********** define plugins and functions **********/
var BBMobi = BBMobi || {
Core: {
_version: 0.1,
_updated: '04/26/2012 12:00 PM',
//isEditView: !!window.location.href.match('pagedesign'),
isEditView: window.location.href.match('edit='),
run: function(){
var thisObj = this;
if(typeof Sys !== 'undefined') {
thisObj.prm = Sys.WebForms.PageRequestManager.getInstance()
} else {
thisObj.prm = {
add_initializeRequest: function(){ }, // console.log('initializeRequest run');
add_beginRequest: function(){ }, // console.log('beginRequest run');
add_pageLoading: function(){ }, // console.log('pageLoading run');
add_pageLoaded: function(fn){
$(document).ready(function(){ fn(); });
}, // console.log('pageLoaded run');
add_endRequest: function(){ } // console.log('endRequest run');
}
}
}
//prm: Sys.WebForms.PageRequestManager.getInstance(),
},
init: function(){
var thisObj = this;
this.Core.run();
if(!thisObj.Core.isEditView){
document.write('<style>.DonationFormTable table[id*="tblAmount"]{display:none;}</style>');
};
this.Core.prm.add_pageLoaded(function(){
if ($('.DonationFormTable').length > 0) {
thisObj.donation.radioList();
};
if ($('.DonationCaptureFormTable').length > 0) {
thisObj.donation.CSC();
}
if ($('.CalendarViewContainer').length > 0) {
thisObj.miniCal();
};
if ($('.BBMembershipFormTable').length > 0) {
thisObj.membership();
};
if ($('.ProfileFormTable').length > 0) {
thisObj.profileUpdate();
}
thisObj.initMenu();
thisObj.callLink();
thisObj.backButton();
thisObj.partFixes();
});
$(document).ready(function(){
});
},
metaHead: function() {
setTimeout(function() { window.scrollTo(0, 1); }, 100);
},
initMenu: function() {
// move 2nd level menu items in horizontal task list
$('ul.mainNav li.selected ul').appendTo('#contentSecondary .gutter');
$('<span class="navArrow"></span>').prependTo('#contentSecondary ul li.parent');
$('#contentSecondary ul ul').hide();
$('#contentSecondary ul li.selected ul').show();
$('#contentSecondary ul li span').click(
function() {
var checkElement = $(this).nextAll('ul');
if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
$('#contentSecondary ul ul:visible').slideUp('normal');
checkElement.parent().removeClass("selected");
}
else if((checkElement.is('ul')) && (checkElement.is(':hidden'))) {
$('#contentSecondary ul ul:visible').slideUp('normal');
$('#contentSecondary ul ul:visible').parent().removeClass("selected");
checkElement.slideDown('normal');
checkElement.parent().addClass("selected");
}
}
);
},
callLink: function() {
// call button
$('#contactButtons .menu li a').each(function(){
var linkContent = $(this).html();
var isNumber = /^[+-]?\d+(\.\d+)?([eE][+-]?\d+)?$/;
if(isNumber.test(linkContent)) {
$(this).attr("href", "tel:+1" + linkContent);
$(this).html('Call');
};
});
},
backButton: function() {
// back button
$('#utilityMenu .menu .menuItem1 a').click(function(){ history.go(-1);});
},
partFixes: function() {
/* add missing class to parent tables on Login Form */
$('.LoginFormTable').parents('table').addClass('LoginFormTable');
/* restructure progress bar on Event Registration Form */
$('table[id$=tblProgress]').attr('cellspacing', '0');
$('table[id$=tblProgress] th').each(function(){
var progLabel = $(this).text().substr(7);
$(this).text(progLabel);
$(this).wrapInner('<span class="progContent" />');
});
/* restructure progress bar on eCard Form */
$('table[id$=tblProgress] td').each(function(){
var divClass = $(this).children('div').attr('class');
var progLabel = $(this).text().substr(7);
$(this).attr('class', divClass);
$(this).text(progLabel);
$(this).wrapInner('<span class="progContent" />');
});
/* restructure elements of eCards for mobile display */
$('.ECardSection div').removeAttr('style');
$('.ECardSection').each(function(){
$(this).find('th').each(function(index){
$(this).parents('table').find('th').eq(index).addClass('ECardSectionHeaderCell' + index);
$(this).parents('table').find('td').eq(index).addClass('ECardSectionCell' + index);
if ($(this).closest('table').find('tr[class*=ECardSectionRow]').length > 0){
var lastIndex = index - 1;
$(this).closest('table').find('tr[class*=ECardSectionRow' + lastIndex + ']').after('<tr class="ECardSectionRow' + index + '" />');
}
else {
$(this).parents('table').prepend('<tr class="ECardSectionRow' + index + '" />');
};
var thContent = $(this).closest('table').find('th[class="ECardSectionHeaderCell' + index + '"]"');
var tdContent = $(this).closest('table').find('td[class="ECardSectionCell' + index + '"]"');
$(this).closest('table').find('tr[class="ECardSectionRow' + index + '"]').prepend(thContent);
$(this).closest('table').find('tr[class="ECardSectionRow' + index + '"]').append(tdContent);
});
if ($(this).find('input[id*=txtEmail]').length > 0){
var thisInput = $(this).find('input[id*=txtEmail]');
$(this).find('.BBFormRequiredFieldMarker').insertAfter(thisInput);
};
$(this).find('tr').slice(-3).remove();
});
$('th[class*=ECardSectionHeaderCell]').wrapInner('<label />');
/* restructure membership form
if ($('.BBMembershipControlCell').siblings('.BBMembershipControlCell').length > 0 ){
};*/
/* remove access spacing from event selection grid */
$('.EventTable').find('td').removeAttr('style');
/* fix colspan issues in Job Board */
$('.PostJobFormTable tr').each(function(){
var numTDs = $(this).children('td').size();
if (numTDs == 1){
$(this).children('td').attr('colspan', '3');
}
else if (numTDs == 2){
$(this).children('td:last-child').attr('colspan', '2');
};
});
},
donation: {
CSC: function(){
/* CSC Link */
$('.BBLinkHelpIcon').removeAttr('href');
$('.BBLinkHelpIcon').contents().replaceWith('What\'s this?');
$("a.BBLinkHelpIcon").click(function(){
alert('The card security code (CSC) is a 3 or 4 digit number that is not part of the credit card number.');
});
},
radioList: function(){
/* Convert Giving Amount Radio Button List to Select List */
$('.DonationFormTable input[type=radio]').closest('table').addClass('radioTbl');
$('.radioTbl').hide();
$('.radioTbl').after('<select class="BBFormSelectList DonationCaptureSelectList DonationRadioSelectList" />');
$('.DonationRadioSelectList').after('<div id="tblOther" style="display: none;" />');
$('table[id$=tblAmount]').siblings('select').addClass('GivingLevelSelectList');
$('table[id$=tblAmount] tr[id$="trOther"] table').appendTo('#tblOther');
//$('.radioTbl').closest('table').siblings('select').append('<option value="">Select</option>');
$('.radioTbl td').each(function(){
var content = $.trim($(this).text());
var radioVal = $('input',this).val();
var givingVal = $(this).siblings('td').find('input').attr('value');
if (content.length > 0 && radioVal === undefined){
$(this).closest('table').siblings('select').append('<option value="' + givingVal + '">' + content + '</option>');
}
else if (content.length > 0 && givingVal === undefined){
$(this).closest('table').siblings('select').append('<option value="' + radioVal + '">' + content + '</option>');
}
else if (content.length > 0 && givingVal != undefined && radioVal != undefined){
$(this).closest('table').siblings('select').append('<option value="' + radioVal + '">' + content + '</option>');
};
});
/* Check Hidden Giving Amount Radio Buttons when Select Options are made */
$('.DonationRadioSelectList').change(function(){
var selectedValue = $(this).children('option:selected').val();
$(this).siblings('table').find('input').each(function(){
if($(this).attr('value') == selectedValue){
$(this).click();
$(this).attr('checked', true);
};
});
});
/* If Radio buttons are selected, reflect this in select lists on DOM refreshes */
/*if ($('.radioTbl input:checked').length > 0){
var rdoVal = $('.radioTbl input:checked').val()
$('.DonationRadioSelectList option[value="'+rdoVal+'"]').attr('selected',true);
} else {
$('.DonationRadioSelectList option:first').attr('selected',true);
$('.DonationRadioSelectList').change();
}*/
$('.radioTbl').each(function(){
if ($('input:checked',this).length == 0){
//$('input:first',this).attr('checked',true);
$('input:first',this).click();
}
});
$('.radioTbl input:checked').each(function(){
var getVal = $(this).attr('value');
$(this).closest('.radioTbl').next('.DonationRadioSelectList').children('option').each(function(){
if($(this).attr('value') == getVal){
$(this).attr('selected', true);
};
});
});
/*$('.DonationRadioSelectList').each(function(){
if ($('option:selected',this).length == 0){
$('option:first',this).attr('selected',true);
$(this).change();
}
});*/
/*$('.radioTbl').find('input').each(function(){
if($(this).is(':checked') === true) {
var getVal = $(this).attr('value');
$(this).next('.DonationRadioSelectList').children('option').each(function(){
if($(this).attr('value') == getVal){
$(this).attr('selected', true);
};
});
};
});*/
/* Display "Other" options on Giving Amounts Table */
$('.GivingLevelSelectList').change(function(){
var selectedValue = $(this).children('option:selected').val();
if(selectedValue == 'rdoOther'){
$('#tblOther').slideDown();
}
else{
$('#tblOther').slideUp();
};
});
/*if ($('.GivingLevelSelectList option:selected').val() == 'rdoOther'){
$('#tblOther').show();
};*/
/* Show/Hide other - adds display none to fix spacing */
$('select[id$="ddlDesignations"]').change(function(){
if($(this).children('option:selected').text() == 'Other'){
$('tr[id$="trDesignationOther"]').slideDown();
}
else{
$('tr[id$="trDesignationOther"]').slideUp();
};
});
$('select[id$="ddlDesignations"]').change();
}
},
miniCal: function(){
/* Add the .hasEvent class to the container <td>*/
$('.CalendarViewEventItemContainer').each(function(){
if ($(this).children().length > 0) {
$(this).parent().addClass('hasEvent');
}
});
/* Abbreviate the days to the first letter */
$('.CalendarViewDayHeader').each(function() {
var firstLetter = $(this).text().charAt(0);
$(this).text(firstLetter);
});
/* Clear the tooltip on events*/
$('.CalendarViewEvent').attr('onmouseover','');
//$('.CalendarViewEvent').attr('onmouseout','');
$('.CalendarViewAllDayEvent').unbind('onmouseover');
//$('.CalendarViewAllDayEvent').unbind('onmouseout');
/* Previous and Next month controls */
$('.CalendarViewTopLeft').append('<div id="prevMonth">Prev</div>');
$('.CalendarViewTopRight').append('<div id="nextMonth">Next</div>');
var currMonth = $('.CalendarViewTopLeft option:selected');
$('#prevMonth').click(function(){
currMonth.prev().attr('selected','selected');
currMonth.parent().change();
});
$('#nextMonth').click(function(){
currMonth.next().attr('selected','selected');
currMonth.parent().change();
});
var EventContents = "";
var EventListingContainerOffset = 0;
var ListingOpen = false;
$('.hasEvent').click(function(){
//$('.CalendarViewEventItemContainer').hide();
//$(this).children('.CalendarViewEventItemContainer').show();
try{UnTip()}catch(x){}
EventContents = $(this).children('.CalendarViewEventItemContainer').html();
$("#EventListingContainer .EventListing").html(EventContents);
if($("#EventListingContainer:visible").length == 0){
$("#EventListingContainer").slideDown();
ListingOpen = false;
}
else{ ListingOpen = true;}
/* If Listing is not visible scroll to Event Listing*/
if(!ListingOpen){
EventListingContainerOffset = $("#EventListingContainer").offset().top;
$('html, body').animate({scrollTop: EventListingContainerOffset}, 1000);
}
});
/* add lightbox container */
$('#printStartCV').append('<div id="EventListingContainer"><div class="closeEventItem">Close</div><div class="EventListing"></div></div>');
/* Add close button to the event container*/
$('.closeEventItem').click(function(e){ $('#EventListingContainer').slideUp();});
},
membership: function(){
$('.BBMembershipCategoryTable tr[id*="tr_MemCatDesc"]').each(function(i){
i=i++;
//$(this).before('<tr><td colspan="4"><table class="addlCatInfo'+i+'"><tbody><tr><td class="first" /></tr></tbody></table></td></tr>');
$(this).before('<tr><td colspan="4"><table class="addlCatInfo catInfo'+i+'"><tbody><tr><td class="content" /></tr></tbody></table></td></tr>');
$(this).prev().prev().find('td.BBMembershipControlCell:not(:first)').each(function(){
$(this).wrapInner('<div />').contents().appendTo('.catInfo'+i+' td.content');
})
});
$('.DonationCaptureFormTable td.DonationCaptureFieldCaption[id*="MembershipGOM"]').each(function(){
if($(this).find('label').length == 0){
$(this).wrapInner('<label />');
}
});
$('.BBMembershipFormTable tr[id*="AddlCards"] table.BBMembershipCategoryTable tr').each(function(){
if ($('td:eq(4)',this).length > 0){
$(this).after('<tr><td colspan="4"><table><tbody><tr><td></td></tr></tbody></table></td></tr>');
$(this).next().find('table td').append($('td:eq(3)',this).nextUntil());
}
})
},
profileUpdate: function(){
$('.ProfileFormPrivateControlCell').each(function(){
cbox = $('span.ProfileFormCheckbox input[type="checkbox"]',this);
$(cbox).after('<div class="privateLock"><span class="pIcon"></span></div>');
if ($(cbox).is(':checked')){
$(cbox).next().addClass('private');
} else {
$(cbox).next().removeClass('private');
}
});
$('.ProfileFormPrivateControlCell .privateLock').click(function(){
$(this).toggleClass('private');
if ($(this).hasClass('private')){
$(this).prev().attr('checked',true);
} else {
$(this).prev().removeAttr('checked');
}
});
$('.ProfileFormTable:first').before('<div class="profileLegend"><div class="privateLock"><span class="pIcon"></span></div><span class="pLabel"> = Public</span> &nbsp;&nbsp; <div class="privateLock private"><span class="pIcon"></span></div> <span class="pLabel"> = Private</span></div>')
}
};
BBMobi.init();
// core design global functions
function bbGlobal() {
function fixPositioning() {
$('div[id$=_panelPopup]').appendTo('body');
$('div[id$=_panelPopup_DropShadow]').appendTo('body');
};
// execute functions
// remove or comment out unused functions
fixPositioning();
};
<!-- Automatically Update Copyright Date -->
<div id="wrapFooter">
<div class="gutter">&copy; <span id="currentYear">2013</span> Blackbaud, Inc.</div>
</div>
<script type="text/javascript" language="javascript">
$("#currentYear").text((new Date).getFullYear());
</script>
<!-- Load Desktop on iPad -->
<script>
var isiPad = navigator.userAgent.match(/iPad/i) != null;
if(isiPad){BLACKBAUD.netcommunity.ViewAsDesktop();}
</script>
<!-- iPad Redirect Scripts -->
<body>
<style type="text/css">
/* Hide site from general tablet layouts */
@media only screen and (device-width: 768px) {
* { display: none; }
}
</style>
<div class="wrapScript">
<!-- BEGIN Redirect -->
<script type="text/javascript">
var iPad = (/ipad/i.test(navigator.userAgent.toLowerCase()));
if (iPad) {
document.location = "javascript:BLACKBAUD.netcommunity.ViewAsDesktop();";
}
</script>
<!-- END Redirect -->
</div>
<!-- END Scripts -->
<!-- BEGIN Your Code Here -->
</body>
<!-- Modify Label Text for New User Registration Form-->
<script>
function defaultPartner()
{
$("label[for='PC9280_NewUserRegistration1_txtUserID']").text("User Name:");
}
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(defaultPartner);
</script>
<!-- Fixed Positioning -->
<script type="text/javascript" language="javascript">
function fixPositioning()
{
var _els = document.getElementsByTagName('div');
for (var _i=0;_i<_els.length;_i++)
{
if (_els[_i].id.match(/_panelPopup$/) || _els[_i].id.match(/_panelPopup_DropShadow$/))
document.getElementsByTagName('body')[0].appendChild(_els[_i]);
}
}
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(fixPositioning);
</script>
<!-- Fixed Positioning #2 -->
<script language="javascript" type="text/javascript">
function fixPositioning()
{
$('div[id *= "_panelPopup"]').appendTo('body');
}
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(fixPositioning);
</script>
<!-- Fixes the issue where you can't click to edit parts* -->
<script language="javascript" type="text/javascript">
function fixPositioning()
{
$('div[id *= "_panelPopup"]').appendTo('body');
$('div[id *= "_designPaneCloak"]').css({"top": "0px","left": "0px"});
$('.DesignPane').css("position", "relative");
}
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(fixPositioning);
</script>
<!-- Quick Search Text Replacement -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Quick Search Text Replacement</title>
<script type="text/javascript" src="../js/jquery.js"></script>
</head>
<body>
<table class="QuickSearchFormTable" border="0">
<tbody>
<tr>
<td>
<label class="BBFieldCaption QuickSearchFieldCaption">Search:</label>
</td>
<td>
<input type="text" maxlength="255" class="QuickSearchTextbox" />
<input type="text" style="display:none; visibility:hidden" />
</td>
<td>
<input type="submit" value="Search" class="BBFormSubmitButton QuickSearchButton" />
</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
/* quick search text replacement */
$(".QuickSearchTextbox").val("Search").click(function(){
if ($(this).val() == "Search") {$(this).val("");}}).blur(function(){
if ($(this).val() == "") {$(this).val("Search");}});
</script>
</body>
</html>
<!-- Swap Table Rows -->
<script type="text/JavaScript">P
$(document).ready(function(){
$(#PC22553_Wizard1_dgEventItems2_dgPriceList_0 .BBListOddRowStyle").append($("#PC22553_Wizard1_dgEventItems2_dgPriceList_0 .BBListEvenRowStyle));
});
</script>
<!-- Force Select Form Option -->
<script>
$(document).ready(function(){
If ($(‘form[action*=”pagedesign”]’).length > 0) {
// run scripts in edit mode
}
Else {
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function() {
$("select.BBFormSelectList.LoginFormSelectList option[selected]").removeAttr("selected");
$("select.BBFormSelectList.LoginFormSelectList option[value='Women of Reform Judaism']").attr("selected", "selected");
});
} //End of the Edit View Check
});
</script>
/**
* FlashObject v1.2.3: Flash detection and embed - http://blog.deconcept.com/flashobject/
*
* FlashObject is (c) 2005 Geoff Stearns and is released under the MIT License:
* http://www.opensource.org/licenses/mit-license.php
*
*/
if(typeof com == "undefined") var com = new Object();
if(typeof com.deconcept == "undefined") com.deconcept = new Object();
if(typeof com.deconcept.util == "undefined") com.deconcept.util = new Object();
if(typeof com.deconcept.FlashObjectUtil == "undefined") com.deconcept.FlashObjectUtil = new Object();
com.deconcept.FlashObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, redirectUrl, detectKey){
this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
this.skipDetect = com.deconcept.util.getRequestParameter(this.DETECT_KEY);
this.params = new Object();
this.variables = new Object();
this.attributes = new Array();
if(swf) this.setAttribute('swf', swf);
if(id) this.setAttribute('id', id);
if(w) this.setAttribute('width', w);
if(h) this.setAttribute('height', h);
if(ver) this.setAttribute('version', new com.deconcept.PlayerVersion(ver.toString().split(".")));
if(c) this.addParam('bgcolor', c);
var q = quality ? quality : 'high';
this.addParam('quality', q);
this.setAttribute('redirectUrl', '');
if(redirectUrl) this.setAttribute('redirectUrl', redirectUrl);
if(useExpressInstall) {
// check to see if we need to do an express install
var expressInstallReqVer = new com.deconcept.PlayerVersion([6,0,65]);
var installedVer = com.deconcept.FlashObjectUtil.getPlayerVersion();
if (installedVer.versionIsValid(expressInstallReqVer) && !installedVer.versionIsValid(this.getAttribute('version'))) {
this.setAttribute('doExpressInstall', true);
}
} else {
this.setAttribute('doExpressInstall', false);
}
}
com.deconcept.FlashObject.prototype.setAttribute = function(name, value){
this.attributes[name] = value;
}
com.deconcept.FlashObject.prototype.getAttribute = function(name){
return this.attributes[name];
}
com.deconcept.FlashObject.prototype.getAttributes = function(){
return this.attributes;
}
com.deconcept.FlashObject.prototype.addParam = function(name, value){
this.params[name] = value;
}
com.deconcept.FlashObject.prototype.getParams = function(){
return this.params;
}
com.deconcept.FlashObject.prototype.getParam = function(name){
return this.params[name];
}
com.deconcept.FlashObject.prototype.addVariable = function(name, value){
this.variables[name] = value;
}
com.deconcept.FlashObject.prototype.getVariable = function(name){
return this.variables[name];
}
com.deconcept.FlashObject.prototype.getVariables = function(){
return this.variables;
}
com.deconcept.FlashObject.prototype.getParamTags = function(){
var paramTags = ""; var key; var params = this.getParams();
for(key in params) {
paramTags += '<param name="' + key + '" value="' + params[key] + '" />';
}
return paramTags;
}
com.deconcept.FlashObject.prototype.getVariablePairs = function(){
var variablePairs = new Array();
var key;
var variables = this.getVariables();
for(key in variables){
variablePairs.push(key +"="+ variables[key]);
}
return variablePairs;
}
com.deconcept.FlashObject.prototype.getHTML = function() {
var flashHTML = "";
if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "PlugIn"); }
flashHTML += '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" id="'+ this.getAttribute('id') + '" name="'+ this.getAttribute('id') +'"';
var params = this.getParams();
for(var key in params){ flashHTML += ' '+ key +'="'+ params[key] +'"'; }
pairs = this.getVariablePairs().join("&");
if (pairs.length > 0){ flashHTML += ' flashvars="'+ pairs +'"'; }
flashHTML += '></embed>';
} else { // PC IE
if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "ActiveX"); }
flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" id="'+ this.getAttribute('id') +'">';
flashHTML += '<param name="movie" value="' + this.getAttribute('swf') + '" />';
var tags = this.getParamTags();
if(tags.length > 0){ flashHTML += tags; }
var pairs = this.getVariablePairs().join("&");
if(pairs.length > 0){ flashHTML += '<param name="flashvars" value="'+ pairs +'" />'; }
flashHTML += '</object>';
}
return flashHTML;
}
com.deconcept.FlashObject.prototype.write = function(elementId){
if(this.skipDetect || this.getAttribute('doExpressInstall') || com.deconcept.FlashObjectUtil.getPlayerVersion().versionIsValid(this.getAttribute('version'))){
if(document.getElementById){
if (this.getAttribute('doExpressInstall')) {
this.addVariable("MMredirectURL", escape(window.location));
document.title = document.title.slice(0, 47) + " - Flash Player Installation";
this.addVariable("MMdoctitle", document.title);
}
document.getElementById(elementId).innerHTML = this.getHTML();
}
}else{
if(this.getAttribute('redirectUrl') != "") {
document.location.replace(this.getAttribute('redirectUrl'));
}
}
}
/* ---- detection functions ---- */
com.deconcept.FlashObjectUtil.getPlayerVersion = function(){
var PlayerVersion = new com.deconcept.PlayerVersion(0,0,0);
if(navigator.plugins && navigator.mimeTypes.length){
var x = navigator.plugins["Shockwave Flash"];
if(x && x.description) {
PlayerVersion = new com.deconcept.PlayerVersion(x.description.replace(/([a-z]|[A-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
}
}else if (window.ActiveXObject){
try {
var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
PlayerVersion = new com.deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
} catch (e) {}
}
return PlayerVersion;
}
com.deconcept.PlayerVersion = function(arrVersion){
this.major = parseInt(arrVersion[0]) || 0;
this.minor = parseInt(arrVersion[1]) || 0;
this.rev = parseInt(arrVersion[2]) || 0;
}
com.deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
if(this.major < fv.major) return false;
if(this.major > fv.major) return true;
if(this.minor < fv.minor) return false;
if(this.minor > fv.minor) return true;
if(this.rev < fv.rev) return false;
return true;
}
/* ---- get value of query string param ---- */
com.deconcept.util.getRequestParameter = function(param){
var q = document.location.search || document.location.href.hash;
if(q){
var startIndex = q.indexOf(param +"=");
var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
if (q.length > 1 && startIndex > -1) {
return q.substring(q.indexOf("=", startIndex)+1, endIndex);
}
}
return "";
}
/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}
/* add some aliases for ease of use / backwards compatibility */
var getQueryParamValue = com.deconcept.util.getRequestParameter;
var FlashObject = com.deconcept.FlashObject;
As the standard NetCommunity functionality does not fully address the needs of most websites, it is necessary to customize or extend some aspects of the site with the use of JavaScript. Implementing the JavaScript can be somewhat complicated and prone to mistakes, so take this careful approach to ensure as smooth of a process as possible.
Getting Started
Step 1: Create Global JavaScript Document
Before adding any JavaScript to the site, begin with the following document. It serves as a consistent starting point for any and all customizations moving forward. It defines some basic variables and functions that will ultimately make implementation of your scripts easier. And it provides useful information for troubleshooting and support.
Download and save the Global JavaScript File in your active project folder.
Add the following information to the top of the document and save again:
Site: (Site Name)
Author: (Your Name)
Created: (Date Created)
BBNC Version: (Current Version of Site)
Step 2: Create Documents Page and Upload JavaScript in NetCommunity
For the purpose of these instructions, we’ll get the document setup on the site first before adding any custom code. However you’re comfortable, you can add all your code first and do some local testing before even loading this into NetCommunity.
In your NetCommunity site, create a new page and name it "Web Admin Documents" using your default internal template.
In the main content area, insert a new Documents part, and also name it "Web Admin Documents" and click Next.
For title, add "Web Admin Documents"
For description, add
The following documents contain functionality that is vital to this site. Do not edit or delete unless you are authorized, as this could disable vital functionality and would not be supported.
Save
Click "Add". This will show the upload option.
Add "Global JavaScript" to the title
Click "Browse" and select your locally saved JavaScript file
Save
It is important to always work from this file when you make future edits. See Step 4.
Step 3: Reference JavaScript file in the Layout
The Global JavaScript file will be referenced on the layout level to provide access to the code for every page based on the layout. It is recommended that every layout use this file unless there are exceptions to its use, such as requiring a different set of JavaScript functions or none at all.
While on the documents page, make note of the document’s numeric ID in the status bar by hovering over "Global JavaScript". It should say http://www.yoursite.org/document.doc?id=#. Remember that number.
In your layout, switch to HTML view and add the following code at the very top (replace # with the numeric ID from the document):
<script type="text/javascript" src="document.doc?id=#"></script>
Save.
Repeat for each layout.
Step 4: Updating the Global JavaScript document
It is important to always work from the file in the Web Admin Documents when making future edits.
If you are working alone:
Make all your changes to the local file and save
When you are ready to apply your changes, click the "Edit" link next to the Global JavaScript file in the documents list.
Click "Browse" and select your locally saved JavaScript file
Save
If you are collaborating with others on the development of the JavaScript, be sure to download the latest version by clicking on the "Global JavaScript" title. This will ensure that you are working on the latest active version of the document.
Modifying the Global JavaScript document
Now that you have set up your master JavaScript file on the NetCommunity site, you can begin adding any additional scripts your site requires. For advanced developers, you can do this step prior to steps 2-4. For these instructions, replace all italicized terms with your own terms.
Note: Execution code differs from the actual function or plugin.
Also include code for click and hover events within these areas, rather than including in a link itself or outside of the siteGlobal function. This is so the entire DOM could load and allow the JavaScript to acknowledge the existence of the object you are manipulating.
siteGlobal()
For any non-UI script that needs to be executed globally throughout the site upon page load or postbacks, add your execution code between the brackets of the following function:
// execute page load (postback) functions
function siteGlobal() {
// your code here
};
uiGlobal()
For any UI script that needs to be executed once all elements on a page have loaded, add your execution code between the brackets of the following function:
// execute UI functions - such as slideshows
function uiGlobal() {
// your code here
};
What’s the difference?
The function siteGlobal() executes code upon initial page load or postback, using the Microsoft Ajax page loaded event in NetCommunity. This means the code will run for every step of a form submission. Even selecting a recurring gift option on a donation form will trigger this event. The function uiGlobal() will only run the first time a page loads, and after all elements have been loaded, including images. This ensures the UI plugins will have all the elements that it needs to properly execute its functions. Since the UI plugins do not typically interact with form elements, it is unnecessary to run them in the postback, which can also cause additional problems.
Embedding Plugins
Once you have loaded your Global JavaScript file on the layout, that provides you with a “hook” in which you can add additional JavaScript to your site, without cluttering the layout. This is especially useful if your site has a more than a few layouts. Instead, you can embed additional JavaScript files within your Global JavaScript file, which would automatically include the files on all layouts at once.
Reference external file
Begin by adding each of the reference documents to the Web Admin Documents as individual documents. Give them each a title that matches the filename. After uploading, note the document ID when you hover of the document link.
In the Global JavaScript file, include the following code below Custom Functions, making the necessary replacements:
// plugin filename here
document.write('<script src="document.doc?id=xxx"></script>');
This simply emulates the process of writing a script reference on your layout. Everything between the single quotes within the parenthesis will be written directly to the layout as the page loads.
Reference external file
In some cases, you will be provided with something called minified code, which is basically the same as the external reference file, but compressed so you can reduce the calls to external documents. You can just place the minified code in this area as well, rather than uploading the document separately.
Updating Script
After saving your changes, reload the JavaScript file in the Web Admin Documents by following Step 4 above.
Preview the page to make sure your function executed properly.
Explanation:
When including third-party, external content such as a Google font, TypeKit package or ShareThis buttons, it’s important to be mindful of how the content is included. Using the vendor’s instructions will usually suffice, except when the same layout/template/theme must support both secure and insecure pages.
In the scenario where we’re including insecure external content (http://) but are viewing from an secure page (https://), many browsers will display a warning or even refuse to load the content. To avoid this warning, we can use a “protocol-relative URL.” All this basically means is using an absolute URL, but leaving off the “http://” or “https://”
If you are interested in understanding how this works, as well as a more in-depth explanation of the caveats, I would give Paul Irish’s protocol-relative URL a read.
Caveats
As the saying goes, “If it’s too good to be true it probably is.” Listed below are the caveats of using this method:
When dealing with a stylesheet, IE7 & IE8 will download the file twice. The same URL must be used for http & https.
Using a protocol-relative URL only deals with external content. When linking to content included on the same domain, simply use a relative URL – either relative from the URL root or relative to the HTML/CSS document.
Examples:
Google Font – Link
<link type="text/css" href="//fonts.googleapis.com/css?family=Lato" rel="stylesheet">
Google Font – Import
@import url(//fonts.googleapis.com/css?family=Lato);
Typekit Package
<script type="text/javascript" src="//use.typekit.net/ppj6gtf.js"></script>
ShareThis Buttons – Insecure *
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
ShareThis Buttons – Secure *
<script type="text/javascript" src="https://ws.sharethis.com/button/buttons.js"></script>
* In the case of ShareThis, where different URL’s are required for secure or insecure content, a protocol-relative URL cannot be used. If there’s any chance the buttons could be included on a secure page, I would default to using the secure (https://ws.sharethis.com) URL. See the ShareThis documentation for more details.
//get RSS feed and format it for use in the Byline
var feedCount = $('.NewsReaderResultsList').children().children('tr').length;
$.jGFeed('http://news.sfppr.org/feed/',
function(feeds){
// Check for errors
if(!feeds){
// there was an error
return false;
}
// do whatever you want with feeds here
for(var i=0; i var entry = feeds.entries[i];
// Entry title
entry.title;
entry.author;
//write the Author to the Byline
$('.NewsReaderResultsList').children().children('tr:eq('+i+')').find('.NewsReaderItemDesc').append('- By: '+entry.author);
}
}, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment