if (typeof content_manager !== 'undefined') {

    var beforeShopCMSPagedataInit = pagedataInit;

    pagedataInit = function (dom_scope) {
        'use strict';
        if (typeof dom_scope === 'undefined' || dom_scope === false || dom_scope === "" || dom_scope === 0) {
            dom_scope = 'ul.pagedata-list';
        }
        beforeShopCMSPagedataInit.apply(this, arguments);
        $(dom_scope).find(".shopCmsPagedataPluginSelect").each(function (index, element) {
            var clear_button = $('<span class="clearCoordinates fa fa-close"></span>'),
                toggle_clear_button = function () {
                    if (parseInt($(element).val(), 10) == 0) {
                        clear_button.hide();
                    } else {
                        clear_button.show();
                    }
                };
            $(element).parent().append(clear_button);
            clear_button.on('click', function () {
                $(element).val(0);
                clear_button.hide();
            });

            toggle_clear_button();
            $(element).change(toggle_clear_button);
            $(element).on('click', function (event) {
                cmsPreventDefault(event);
                window.open(
                    '/shop/admin/products/manage.products.mini.php?field=pagedata\[' + $(this).attr("data-list-item-data-id") + '\]\[value\]',
                    'productselector',
                    'status=yes,scrollbars=yes,resizable=yes,width=600,height=600'
                );
            });
        });
    }
}
