Skip to content

Instantly share code, notes, and snippets.

@AFaust
Last active December 22, 2015 07:49
Show Gist options
  • Select an option

  • Save AFaust/6440958 to your computer and use it in GitHub Desktop.

Select an option

Save AFaust/6440958 to your computer and use it in GitHub Desktop.
This script removes some Share header items in a share-header.get.js customization. Currently there does not appear to be a utility to remove widgets from the new JS widget model, so this is what got the job done for me...
var widget, widgetsToRemove = [ "HEADER_SHARED_FILES", "HEADER_MY_FILES", "HEADER_PEOPLE", "HEADER_TASKS", "HEADER_REPOSITORY",
"HEADER_SEARCH" ], idx, max;
for (idx = 0, max = widgetsToRemove.length; idx < max; idx++)
{
findAndRemoveIn(model.jsonModel.widgets, null, null, widgetsToRemove[idx]);
}
function findAndRemoveIn(obj, arrContext, arrIdx, id)
{
var idx, max, key, removed = false;
if (obj !== undefined && obj !== null)
{
if (Object.prototype.toString().apply(obj) === "[object Object]")
{
if (obj.hasOwnProperty("id") && obj.id === id)
{
if (arrContext !== null && arrIdx !== null)
{
arrContext.splice(arrIdx, 1);
removed = true;
}
else
{
logger.debug("Unexpected match outside of array structure: " + jsonUtils.toJSONString(obj));
}
}
else
{
for (key in obj)
{
if (obj.hasOwnProperty(key))
{
removed = findAndRemoveIn(obj[key], null, null, id);
if(removed)
{
break;
}
}
}
}
}
else if (Object.prototype.toString().apply(obj) === "[object Array]")
{
for (idx = 0, max = obj.length; idx < max; idx++)
{
removed = findAndRemoveIn(obj[idx], obj, idx, id);
if(removed)
{
break;
}
}
}
}
return removed;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment