Created
May 14, 2018 20:34
-
-
Save StabbyMcDuck/e8d4d99b74dbfe6ad75f009656d11023 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
<script type="text/javascript"> | |
// Call the function once page is loaded | |
SP.SOD.executeFunc('sp.js','SP.ClientContext',runWhenLoaded); | |
//Shared Global Variables | |
var clientContext; | |
var oWeb; | |
var oList; | |
var obj = []; | |
var linkLine; | |
var offset = -1/60 * (new Date().getTimezoneOffset()); | |
console.log(offset); // This prints to the inspector console, can change to alert if you want | |
function runWhenLoaded() { | |
// Create context, get the rootweb, then get the list | |
clientContext = SP.ClientContext.get_current(); | |
oWeb = clientContext.get_web(); | |
oList = oWeb.get_lists().getByTitle("Navigation"); | |
clientContext.load(oList); | |
// Execute the queued context commands (passes back to the global vars) | |
clientContext.executeQueryAsync(runOnSuccess,function() { alert("Error"); } ); | |
} | |
// Callback function for async success | |
function runOnSuccess() { | |
// Get all list items via CAML | |
var camlQuery = SP.CamlQuery.createAllItemsQuery(); | |
var allItems = oList.getItems(camlQuery); | |
clientContext.load(allItems, 'Include(Title, NAVControlID, NAVLink, NAVTimeZoneOffset)'); | |
clientContext.executeQueryAsync(function(){ | |
var listEnum = allItems.getEnumerator(); | |
while (listEnum.moveNext()) { | |
var currentItem = listEnum.get_current(); | |
obj.push({ page: currentItem.get_item('Title'), navControlID: currentItem.get_item('NAVControlID'), navLink: currentItem.get_item('NAVLink'), navTimeZoneOffset: currentItem.get_item('NAVTimeZoneOffset') }); | |
} | |
concatenateURL(); // call after the list items get called | |
} | |
,function() { alert('List get failed'); } ); | |
} | |
/* Regina's Code */ | |
function concatenateURL(linkLine) { | |
var parsedLinkLine = parseInt(linkLine); | |
if (obj[parsedLinkLine].NAVTimeZoneOffset === true) { | |
var offsetURL = obj[linkLine].pcxLink.replace("~xx~", offset); | |
setAttribute("href", offsetURL); | |
} | |
} | |
</script> | |
.... | |
<li><span class="glyphicon glyphicon-menu-right" aria-hidden="true"></span><a onclick="concatenateURL('0')"> Program Card</a></li> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment