SharePoint Server 脚本隐藏连接与导出功能键

一、 说明

在SharePoint页面中存在连接与导出功能按钮,如下图所示,由于权限管理限制不足以满足连接与导出功能按键显示与隐藏,需要通过脚本的形式添加页面的webpart中,让页面刷新时自动隐藏功能按钮。
SharePoint Server 脚本隐藏连接与导出功能键_第1张图片

二、 操作

编辑页面
SharePoint Server 脚本隐藏连接与导出功能键_第2张图片
添加web部件-内容编辑器
SharePoint Server 脚本隐藏连接与导出功能键_第3张图片
光标停留内容编辑器编辑框,在页面左上角点击设置文字格式,编辑源
SharePoint Server 脚本隐藏连接与导出功能键_第4张图片
编辑源框黏贴脚本代码,点击确定
SharePoint Server 脚本隐藏连接与导出功能键_第5张图片
脚本如下

<script><span id="ms-rterangecursor-start"></span><span id="ms-rterangecursor-end"></span>
(function(){
	if (typeof(_spBodyOnLoadFunctions) === 'undefined' || _spBodyOnLoadFunctions === null) {
		return;
	}
	_spBodyOnLoadFunctions.push(function() {

		if (typeof(SPClientTemplates) === 'undefined' || SPClientTemplates === null || (typeof(APD_InAssetPicker) === 'function' && APD_InAssetPicker())) {
			return;
		}
					
		var registerOverrideToHideSocialActions = function(id) {
			var socialactionsOverridePostRenderCtx = {};
			socialactionsOverridePostRenderCtx.BaseViewID = 'Callout';
			socialactionsOverridePostRenderCtx.ListTemplateType = id;
			socialactionsOverridePostRenderCtx.Templates = {};
			socialactionsOverridePostRenderCtx.Templates.Footer = function(renderCtx) {
				var  renderECB;
				if (typeof(isSharedWithMeView) === 'undefined' || isSharedWithMeView === null) {
					renderECB = true;
				} else {
					var viewCtx = getViewCtxFromCalloutCtx(renderCtx);
					renderECB = !isSharedWithMeView(viewCtx);
				}
				// By setting a null value as 2nd parameter, we do not specify additional callout actions.
				return CalloutRenderCustomFooterTemplate(renderCtx, null, renderECB);
			};
			SPClientTemplates.TemplateManager.RegisterTemplateOverrides(socialactionsOverridePostRenderCtx);
		}
		// Hide actions for default Document Libraries
		registerOverrideToHideSocialActions (101);
		// Hide actions for the document library on your My Site
		registerOverrideToHideSocialActions (700);
		
		function CalloutRenderCustomFooterTemplate(renderCtx, calloutActionMenuPopulator, renderECB) {
			if (typeof calloutActionMenuPopulator === 'undefined' || calloutActionMenuPopulator === null) {
				calloutActionMenuPopulator = CalloutOnPostRenderCustomTemplate;
			}
			if (typeof renderECB === 'undefined' || renderECB === null) {
				renderECB = true;
			}
			var calloutID = GetCalloutElementIDFromRenderCtx(renderCtx);
		
			AddPostRenderCallback(renderCtx, function() {
				var calloutActionMenu = new CalloutActionMenu(calloutID + '-actions');
		
				calloutActionMenuPopulator(renderCtx, calloutActionMenu);
				calloutActionMenu.render();
			});
			var ecbMarkup = [];
		
			if (renderECB) {
				ecbMarkup.push(') + ' class="js-callout-actions js-callout-ecbActionDownArrow">');
				ecbMarkup.push(RenderECBinline(renderCtx, renderCtx.CurrentItem, renderCtx.CurrentFieldSchema));
				ecbMarkup.push('');
			}
			return Callout.GenerateDefaultFooter(calloutID, ecbMarkup.join(''));
		}
		
		function CalloutOnPostRenderCustomTemplate(renderCtx, calloutActionMenu) {
			var listItem = renderCtx.CurrentItem;
			var openText = GetCallOutOpenText(listItem, renderCtx);
		
			calloutActionMenu.addAction(new CalloutAction({
				text: openText,
				onClickCallback: function(calloutActionClickEvent, calloutAction) {
					CalloutAction_Open_OnClick(calloutActionClickEvent, calloutAction, renderCtx);
				}
			}));
		}
	});
})();
function renderHeaderTemplateForDocuments(renderCtx, fRenderHeaderColumnNames){
    var viewData = eval(renderCtx.ListSchema.ViewSelectorPivotMenuOptions);
    ClientPivotControl.prototype.SurfacedPivotCount = 3;   
    return RenderHeaderTemplate(renderCtx, fRenderHeaderColumnNames); //render default Header template
}

SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
  Templates: {
    Header: renderHeaderTemplateForDocuments
  }
});
</script><style>
#Ribbon\.Documents\.Copies-LargeMedium-0{display:none;}
li[text="Download a Copy"] {
display:none;
}
li[id="Ribbon.Library.Actions"] {
display:none;
}
#Ribbon\.Library\.Actions\.OpenWithExplorer-Medium{display:none;}
#WPQ2_ListTitleViewSelectorMenu_Container_overflow{display:none;}
#Ribbon\.Library\.CustomViews{display:none;}
</style>

停止编辑
SharePoint Server 脚本隐藏连接与导出功能键_第6张图片
查看效果,发现连接和导出功能按钮隐藏不再显示了。
SharePoint Server 脚本隐藏连接与导出功能键_第7张图片
以上为个人整理总结的知识,如有遗漏或错误欢迎留言指出、点评,如要引用,请写联系通知,未经允许谢绝转载。

你可能感兴趣的:(SharePoint,SharePoint)