Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/magento/module-page-builder/view/adminhtml/web/ts/js/binding/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/corals/old/vendor/magento/module-page-builder/view/adminhtml/web/ts/js/binding/style.ts
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

import ko from "knockout";
import utils from "mageUtils";
import _ from "underscore";
import Config from "../config";
import {generateCssBlock, pbStyleAttribute, styleDataAttribute} from "../content-type/style-registry";

const originalStyle: KnockoutBindingHandler = ko.bindingHandlers.style;
const bodyId: string = Config.getConfig("bodyId");

function isPageBuilderContext(context: {[key: string]: any}): boolean {
    return !!(context.stage && context.stage.pageBuilder);
}

ko.bindingHandlers.style = {
    init: (element, valueAccessor, allBindings, viewModel, bindingContext) => {
        if (isPageBuilderContext(bindingContext)) {
            element.setAttribute(pbStyleAttribute, utils.uniqueid());
        }
    },
    update: (element: HTMLElement, valueAccessor, allBindings, viewModel, bindingContext) => {
        if (isPageBuilderContext(bindingContext)) {
            const value = ko.utils.unwrapObservable(valueAccessor() || {});
            const styles: { [key: string]: any; } = {};
            const styleId = element.getAttribute(pbStyleAttribute);
            const existedStyleBlock = document.querySelector(`style[${styleDataAttribute}="${styleId}"]`);

            ko.utils.objectForEach(value, (styleName, styleValue) => {
                styleValue = ko.utils.unwrapObservable(styleValue);

                if (styleValue === null || styleValue === undefined || styleValue === false) {
                    styleValue = "";
                }
                if (styleValue) {
                    styles[styleName] = styleValue;
                }
            });

            if (existedStyleBlock) {
                existedStyleBlock.remove();
            }
            if (!_.isEmpty(styles)) {
                const styleElement: HTMLStyleElement = document.createElement("style");

                styleElement.setAttribute(styleDataAttribute, styleId);
                styleElement.innerHTML = generateCssBlock(`#${bodyId} [${pbStyleAttribute}="${styleId}"]`, styles);
                element.parentElement.append(styleElement);
            }
        } else {
            originalStyle.update(element, valueAccessor, allBindings, viewModel, bindingContext);
        }
    },
};

Spamworldpro Mini