VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/libs/absol-form/js/anchors/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-form/js/anchors/LinearAnchor.js
import FCore from "../core/FCore";
import FViewable from "../core/FViewable";
import '../../css/linearanchor.css';
import inheritComponentClass from "../core/inheritComponentClass";
import makeMapStyleHandler from "./makeMapStyleHandler";
import { parseMeasureValue } from "../core/utils";

var _ = FCore._;
var $ = FCore.$;

/**
 * AnchorBox only has one child node
 * @extends FViewable
 */
function LinearAnchor() {
    FViewable.call(this);
    this.style.left = 0;
    this.style.right = 0;
    this.style.top = 0;
    this.style.bottom = 0;
    this.width = 0;
    this.height = 0;
    this.childNode = null;

    //for quick binding render
    this.viewBinding = {};

    this.onCreate();
    this.domElt = this.render();
    this.onCreated();
}

inheritComponentClass(LinearAnchor, FViewable);

LinearAnchor.prototype.TOP_CLASS_NAME = 'as-linear-anchor-box';


LinearAnchor.prototype.onCreate = function () {/* NOOP */
}

LinearAnchor.prototype.onCreated = function () {
    for (var key in this.viewBinding) {
        this[key] = $(this.viewBinding[key], this.view);
    }
};


LinearAnchor.prototype.compStyleHandlers = {};

LinearAnchor.prototype.compStyleHandlers.height = {
    /***
     * @this BaseComponent
     * @param value
     * @returns {string}
     */
    set: function (value) {
        var ref = arguments[arguments.length - 1];
        var currentValue = ref.get();
        var unit = arguments.length > 2 ? arguments[1] : undefined;
        var current = parseMeasureValue(currentValue) || { value: 'auto', unit: null };
        value = this.implicitMeasureSizeValue(value, unit, "height", current.unit);

        if (value === 'auto') {
            this.anchor.domElt.addClass('as-height-auto');
        }
        else {
            this.anchor.domElt.removeClass('as-height-auto');
        }
        var styleValue = value >= 0 ? value + 'px' : value;
        if (styleValue === 'match_parent') styleValue = '100%';
        this.anchor.domElt.addStyle('height', styleValue);
        this.domElt.removeStyle('height');
        return value;

    },
    /***
     * @this BaseComponent
     *
     * */
    get: function () {
        var ref = arguments[arguments.length - 1];
        var value = ref.get();
        var unit = arguments.length > 1 ? arguments[0] : undefined;
        return this.explicitMeasureSizeValue(value, unit, 'height');
    },
    descriptor: {
        type: 'measureSize',
        sign: 'LinearHeight',
        independence: true
    }
};

LinearAnchor.prototype.compStyleHandlers.width = {
    /***
     * @this BaseComponent
     * @param value
     * @returns {*}
     */
    set: function (value) {
        var ref = arguments[arguments.length - 1];
        var unit = arguments.length > 2 ? arguments[1] : undefined;
        var currentValue = ref.get();
        var current = parseMeasureValue(currentValue) || { value: 'auto', unit: null };
        value = this.implicitMeasureSizeValue(value, unit, 'width', current.unit);
        if (value === 'auto') {
            this.anchor.domElt.addClass('as-width-auto');
        }
        else {
            this.anchor.domElt.removeClass('as-width-auto');
        }
        var styleValue = value >= 0 ? value + 'px' : value;
        if (styleValue === 'match_parent') styleValue = '100%';
        this.anchor.domElt.addStyle('width', styleValue);
        this.domElt.removeStyle('width');
        return value;
    },
    get: function () {
        var unit = arguments.length > 1 ? arguments[0] : undefined;
        var ref = arguments[arguments.length - 1];
        var value = ref.get();
        var bound, parentBound;
        if (unit === 'px') {
            if (value !== 'number') {
                bound = this.domElt.getBoundingClientRect();
                return bound.width;
            }
            else {
                return value;
            }
        }
        else if (unit === '%') {
            if (typeof value === 'string' && value.match(/%$/))
                return parseFloat(value.replace('%', ''));
            else {
                bound = this.domElt.getBoundingClientRect();
                parentBound = this.parent.domElt.getBoundingClientRect();
                return bound.width * 100 / parentBound.width;
            }
        }
        else
            return value;
    },
    descriptor: {
        type: 'measureSize',
        sign: 'LinearWidth',
        independence: true
    }
};

LinearAnchor.prototype.compStyleHandlers.hidden = {
    set: function (value) {
        value = !!value;
        if (value)
            this.anchor.domElt.addClass('as-display-hidden');
        else
            this.anchor.domElt.removeClass('as-display-hidden');
        this.domElt.removeClass('as-display-hidden');
        return value;
    },
    descriptor: {type: 'bool'}
};


['left', 'right', 'top', 'bottom', 'width', 'height', 'hidden'].forEach(function (name) {
    LinearAnchor.prototype.styleHandlers[name] = makeMapStyleHandler(name);
});

['left', 'right', 'top', 'bottom'].forEach(function (name) {
    LinearAnchor.prototype.compStyleHandlers[name] = {
        /***
         * @this BaseComponent
         * @param value
         * @returns {string|number}
         */
        set: function (value) {
            var ref = arguments[arguments.length - 1];
            var unit = arguments.length > 2 ? arguments[1] : undefined;
            var currentValue = ref.get();
            var current =  parseMeasureValue(currentValue) || { value: 'auto', unit: null };
            value = this.implicitMeasureSizeValue(value, unit, "width", current.unit);
            var styleValue = (typeof value === "number") ? value + 'px' : value;
            this.anchor.domElt.addStyle('margin-' + name, styleValue);
            return value;
        },
        /**
         * @this BaseComponent
         * @returns {number|*}
         */
        get: function () {
            var unit = arguments.length > 1 ? arguments[0] : undefined;
            var ref = arguments[arguments.length - 1];
            var value = ref.get();
            return this.explicitMeasureSizeValue(value, unit, "width");
        },
        export: function (ref) {
            var value = ref.get();
            if (value === 0 || value === '0%') return undefined;
            return value;
        },
        descriptor: {
            type: 'measurePosition',
            min: -Infinity,
            max: Infinity,
            dependency: ['width'],
            sign: 'Linear' + name.substr(0, 1).toUpperCase() + name.substr(1),
            independence: true
        }
    };
});


LinearAnchor.prototype.render = function () {
    var layout = {
        class: [this.TOP_CLASS_NAME]
    };
    return _(layout);
};


/**
 * @param {BaseComponent} child
 */
LinearAnchor.prototype.attachChild = function (child) {
    if (this.childNode) {
        this.childNode.view.remove();
        this.childNode = null;
        this.childNode.anchor = null;
    }

    if (child.anchor) throw new Error("Detach anchorBox first");
    this.childNode = child;
    child.anchor = this;
    this.childNode.style.width = this.childNode.style.width || 0;
    this.childNode.style.height = this.childNode.style.height || 0;
    this.childNode.style.left = this.childNode.style.left || 0;
    this.childNode.style.right = this.childNode.style.right || 0;
    this.childNode.style.top = this.childNode.style.top || 0;
    this.childNode.style.bottom = this.childNode.style.bottom || 0;
    this.style.left = this.childNode.style.left;
    this.style.right = this.childNode.style.right;
    this.style.top = this.childNode.style.top;
    this.style.bottom = this.childNode.style.bottom;

    this.domElt.addChild(child.view);
    this.style.loadAttributeHandlers(this.styleHandlers);
    child.style.loadAttributeHandlers(Object.assign({}, child.styleHandlers, this.compStyleHandlers));
    child.onAnchorAttached();
};

LinearAnchor.prototype.detachChild = function () {
    if (this.childNode) {
        this.childNode.view.remove();
        this.childNode.onAnchorDetached();
        this.childNode.anchor = null;
        this.childNode = null;
    } else
        throw new Error("Nothing to detach");
};


Object.defineProperty(LinearAnchor.prototype, 'view', {
    get: function () {
        return this.domElt;
    }
});


export default LinearAnchor;

VaKeR 2022