5

I am currently trying to write javascript within a script editor to hide the 'View Properties' and 'Edit Properties' items in the ECB.

I have found many solutions that edit the core.js file. However, that is not preferable for me as there are multiple sites adn this is not for every site and every library. Eventually this will be applied to a certain library but right now I would just like this to work in general before I worry about that.

I have tried removing the item when the menu is loaded using the below javascript. Where #mp6_0_3 is the id of the 'Edit Properties' menu item.

<script type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script> 

<script language="javascript" type="text/javascript"> 
$(document).ready(function() {
    $('.ms-core-menu-list').live('mouseover', function() {
        $('#mp6_0_3').parent().hide();
        $('#mp6_0_3').remove();       
    });
});
</script>
  • Did you check if this function is firing correctly? – Aanchal Sep 10 '14 at 6:57
7

What you could do, is to override the function in Core.js on the current page instead. If its a library the actions are added in the AddDocLibMenuItems. And the View/Edit Properties are added from the AddShareNamespaceMenuItems function. So you could add this function to your page, just make sure its loaded after Core.js:

function AddDocLibMenuItems(m, ctxt) {
    if (typeof window.Custom_AddDocLibMenuItems != "undefined") {
        if (window.Custom_AddDocLibMenuItems(m, ctxt))
            return;
    }
    var RootFolder = GetRootFolder(ctxt);
    var menuOption;
    var strDisplayText;
    var strAction;
    var strImagePath;

    //AddSharedNamespaceMenuItems(m, ctxt);
    var currentItemEscapedFileUrl;

    if (currentItemFileUrl != null)
        currentItemEscapedFileUrl = escapeProperly(unescapeProperly(currentItemFileUrl));
    var serverFileRedirect = itemTable.getAttribute("SRed");
    var systemCheckout = currentItemCheckedOutUserId == String(SYSTEM_ACCOUNT_ID) && ctxt.CurrentUserId != String(SYSTEM_ACCOUNT_ID);

    if (HasRights(0x0, 0x4) && HasRights(0x10, 0x0) && !systemCheckout && (serverFileRedirect == null || serverFileRedirect == "" || HasRights(0x0, 0x20))) {
        if (ctxt.isWebEditorPreview == 0 && ctxt.listBaseType == 1) {
            if (ctxt.listTemplate != 119) {
                setDocType();
                if (currentItemAppName != "" && currentItemOpenControl != "") {
                    if (!(ctxt.IsAppWeb && currentItemProgId == SPDesignerProgID)) {
                        strDisplayText = "";
                        if (currentItemAppName != " ")
                            strDisplayText = StBuildParam(Strings.STS.L_EditIn_Text, currentItemAppName);
                        else {
                            var objEditor = StsOpenEnsureEx2(currentItemOpenControl + ".3");

                            if (objEditor != null)
                                strDisplayText = Strings.STS.L_EditInApplication_Text;
                        }
                        if (strDisplayText != "") {
                            strAction = "editDocumentWithProgID2('" + currentItemFileUrl + "', '" + currentItemProgId + "', '" + currentItemOpenControl + "', '" + String(bIsCheckout) + "', '" + ctxt.HttpRoot + "', '" + currentItemCheckedoutToLocal + "', '" + currentItemOpenApp + "')";
                            strImagePath = ctxt.imagesPath + currentItemIcon;
                            menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, String(260));
                            menuOption.id = "ID_EditIn_" + currentItemAppName;
                            menuOption.style.cssText = "display:none";
                            CUIInfo(menuOption, "EditDocument", ["EditDocument"]);
                        }
                    }
                }
            }
        }
    }
    CAMSep(m);
    if (HasRights(0x0, 0x4)) {
        if (currentItemFSObjType != "1") {
            if (ctxt.listBaseType == 1) {
                AddCheckinCheckoutMenuItem(m, ctxt, currentItemEscapedFileUrl);
            }
        }
    }
    if ((ctxt.verEnabled == 1 || ctxt.isModerated) && currentItemFSObjType != "1") {
        AddVersionsMenuItem(m, ctxt, currentItemEscapedFileUrl);
    }
    if (HasRights(0x0, 0x4)) {
        if (ctxt.isModerated == true && HasRights(0x0, 0x10) && ((currentItemModerationStatus == String(2) || !ctxt.EnableMinorVersions) && currentItemCheckedOutUserId == "" || currentItemFSObjType == "1")) {
            strDisplayText = Strings.STS.L_ModerateItem_Text;
            strAction = "NavigateToApproveRejectAspx(event, '" + ctxt.HttpRoot + "/_layouts/15/approve.aspx?List=" + ctxt.listName + "&ID=" + currentItemID;
            strAction = AddSourceToUrl(strAction) + GetRootFolder(ctxt) + "')";
            strImagePath = ctxt.imagesPath + "apprj.gif";
            menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, String(850));
            CUIInfo(menuOption, "Moderate", ["Moderate"]);
            menuOption.id = "ID_ModerateItem";
        }
    }
    CAMSep(m);
    AddWorkflowsMenuItem(m, ctxt);
    if (currentItemFSObjType != "1") {
        if (ctxt.PortalUrl != null) {
            strDisplayText = Strings.STS.L_AddToMyLinks_Text;
            strAction = "Portal_Tasks('PinToMyPage')";
            ;
            strImagePath = "";
            menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, String(1000));
            CUIInfo(menuOption, "AddToMyLinks", ["AddToMyLinks"]);
            menuOption.id = "ID_AddToMyLinks";
            menuOption.style.display = "none";
        }
    }
    else if (ctxt.listBaseType == 1 && HasRights(0x10, 0x0)) {
        AddWorkOfflineMenuItem(m, ctxt, currentItemFileUrl);
    }
    if (HasRights(0x80, 0x0) && typeof _spPageContextInfo != 'undefined' && _spPageContextInfo != null && typeof _spPageContextInfo.alertsEnabled == 'boolean' && _spPageContextInfo.alertsEnabled) {
        strDisplayText = Strings.STS.L_Subscribe_Text;
        strAction = "NavigateToSubNewAspxV4(event, '" + ctxt.HttpRoot + "', 'List=" + ctxt.listName + "&ID=" + currentItemID + "')";
        strImagePath = "";
        menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, String(1100));
        CUIInfo(menuOption, "Subscribe", ["Subscribe"]);
        menuOption.id = "ID_Subscribe";
        menuOption.style.display = "none";
    }
    if (currentItemFSObjType != "1") {
        AddSendSubMenu(m, ctxt);
        AddGotoSourceItemMenuItem(m, ctxt, itemTable, currentItemFSObjType);
        AddDocTransformSubMenu(m, ctxt);
    }
    CAMSep(m);
    AddManagePermsMenuItem(m, ctxt, ctxt.listName, currentItemID);
    if (HasRights(0x0, 0x8) && !systemCheckout) {
        strDisplayText = Strings.STS.L_DeleteDocItem_Text;
        var isCopy = "false";

        if (typeof itemTable.getAttribute("CSrc") != "undefined" && itemTable.getAttribute("CSrc") != null && itemTable.getAttribute("CSrc") != "") {
            isCopy = "true";
        }
        strAction = "DeleteDocLibItem('" + ctxt.HttpPath + "&Cmd=Delete&List=" + ctxt.listName + "&ID=" + currentItemID + "&owsfileref=" + currentItemEscapedFileUrl + "&NextUsing=" + GetSource() + "'," + isCopy + ")";
        strImagePath = ctxt.imagesPath + "delitem.gif";
        menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, String(1190));
        menuOption.id = "ID_DeleteDocItem";
        CUIInfo(menuOption, "Delete", ["Delete"]);
    }
    if (HasRights(0x0, 0x4) && currentItemFSObjType == "1" && ctxt.ContentTypesEnabled && ctxt.listTemplate != 108) {
        strDisplayText = Strings.STS.L_CustomizeNewButton_Text;
        strAction = "STSNavigate('" + ctxt.HttpRoot + "/_layouts/15/ChangeContentTypeOrder.aspx?List=" + ctxt.listName + "&RootFolder=" + currentItemEscapedFileUrl;
        strAction = AddSourceToUrl(strAction) + "')";
        strImagePath = "";
        menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, String(1170));
        CUIInfo(menuOption, "ChangeNewButton", ["ChangeNewButton"]);
        menuOption.id = "ID_CustomizeNewButton";
    }
}

I have only commented out the AddSharedNamespaceMenuItems function.

3

If you simply want to hide, use the following CSS:

li.ms-core-menu-item[text="View Properties"], li.ms-core-menu-item[text="Edit Properties"] {
    display: none !important;
}

Add a content/script editor to the page and embed the css. If you want to hide it in the entire site collection/site, add the CSS to your master page.

3

Here is the working solution -

Step 1 - Edit the Library Page and Add Script Editor Web Part .

Step 2 - Paste the Below Code in web part for hiding the required button from ECB Menu Item using the Button ID (Replace ID value after # ).

<style type="text/css">

li.ms-core-menu-item #ID_DeleteDocItem, .ms-core-menu-separator hr {

display:none;

}
</style>

Note -Button Id can be found by Opening Core.js file (use ctrl+F to find the required ID) using the name of Menu Item . For eg if you want to hide Delete option , paste Delete in ctrl+F and get the reqiured ID .

Path for Core.js file - C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS

Screen Shot : Hided CheckOut, Download & Delete option .

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.