Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Remove delete (or others) options in toolbar for includes resources

diegom88598729
Level 1
Level 1

What do you think about this code to remove delete options in toolbar from children components embeed using data-sly-resource.

or you could remove this part of code : find('[data-type="Editable"]') and remove the delete option in the component

(function($) {

    "use strict";

   

     // title of parent component

    var removeDeleteOptFromChildrensArr = ['TitleXXX', 'TitleYYY'];

    $(window).on('load', function() {

        if (Granite.author.ContentFrame) {

            var removeDeleteOptionInToolbar = function () {

                $.each(removeDeleteOptFromChildrensArr, function (i, value) {

                    $('[title="' + value + '"]').find('[data-type="Editable"]').off('click').on('click', function () {

                        var dataPath = $(this).attr('data-path');

                        setTimeout(function () {

                            $('button[title="Delete"][data-path="' + dataPath + '"]').hide();

                        }, dataPath);

                    });

                });

            };

            var createMutationObserver = function () {

                var targetNode = $('div.cq-Overlay--placeholder[data-type="Editable"][title="Layout Container [Root]"]');

                var config = { attributes: true, childList: true, subtree: true };

                var callback = function(mutationsList, observer) {

                    for (var mutation of mutationsList) {

                        if (mutation.type === 'attributes' && mutation.attributeName === 'style') {

removeDeleteOptionInToolbar();

                        }

                    }

                };

                var observer = new MutationObserver(callback);

                observer.observe(targetNode.get(0), config);

            }

            Granite.author.loadPageInfo().then(function () {

                setTimeout(function () {

                    createMutationObserver();

                }, 500);

                removeDeleteOptionInToolbar();

            });

        }

    });

})($);

0 Replies