Skip to content

Instantly share code, notes, and snippets.

@StabbyMcDuck
Last active May 31, 2018 19:34
Show Gist options
  • Save StabbyMcDuck/af10f0be99ffaeb76eb9c38419cf5708 to your computer and use it in GitHub Desktop.
Save StabbyMcDuck/af10f0be99ffaeb76eb9c38419cf5708 to your computer and use it in GitHub Desktop.
Line 34 and Line 70
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.set(currentItem.get_item('NAVControlID'), { page: currentItem.get_item('Title'), navLink: currentItem.get_item('NAVLink'), navTimeZoneOffset: currentItem.get_item('NAVTimeZoneOffset') })
//obj.push({ page: currentItem.get_item('Title'), navControlID: currentItem.get_item('NAVControlID'), navLink: currentItem.get_item('NAVLink'), navTimeZoneOffset: currentItem.get_item('NAVTimeZoneOffset') });
obj[currentItem.get_item('NAVControlID')] = {
page: currentItem.get_item('Title'),
navLink: currentItem.get_item('NAVLink'),
navTimeZoneOffset: currentItem.get_item('NAVTimeZoneOffset') };
}
insertHREFs(); // call after the list items get called
}
,function() { alert('List get failed'); } );
}
function insertHREFs() {
// get all anchor tags
var navControlLinks = document.querySelectorAll('a[data-nav-control-id]');
for(var i=0; i < navControlLinks.length; i++) {
var element = navControlLinks[i];
var dataNavControlId = element.getAttribute('data-nav-control-id');
var value = obj.get(dataNavControlId);
concatenateURL(element, value);
}
}
function concatenateURL(element, value) {
if (value.navTimeZoneOffset === true) {
var offsetURL = value.navLink.replace("~xx~", offset);
element.setAttribute("href", offsetURL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment