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/ciruiteditor/diagrameditor/controller/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-form/js/ciruiteditor/diagrameditor/controller/NodeSelectController.js
/***
 *
 * @param {CircuitDiagramEditor}  editor
 * @constructor
 */
function NodeSelectController(editor) {
    this.editor = editor;
    for (var i in this) {
        if (i.startsWith('ev_')) {
            this[i] = this[i].bind(this);
        }
    }
    this.$selectedNodes = [];
}

NodeSelectController.prototype.select = function (nodeElt, append) {
    var idx;
    if (nodeElt) {
        idx = this.$selectedNodes.indexOf(nodeElt);
        if (append) {
            if (idx < 0) {
                this.blur();
                nodeElt.addClass('as-focus')
                    .addClass('as-selected');
                this.$selectedNodes.push(nodeElt);
            } else {
                if (idx + 1 < this.$selectedNodes.length) {
                    this.blur();
                    this.$selectedNodes.splice(idx, 1);
                    this.$selectedNodes.push(nodeElt);
                    nodeElt.addClass('as-focus');
                }
            }
        } else {
            if (idx >= 0) {
                if (idx + 1 < this.$selectedNodes.length) {
                    this.blur();
                    this.$selectedNodes.splice(idx, 1);
                    this.unSelectAll();
                    this.$selectedNodes.push(nodeElt);
                    nodeElt.addClass('as-focus');
                } else {
                    this.$selectedNodes.pop();
                    this.unSelectAll();
                    this.$selectedNodes.push(nodeElt);
                }
            } else {
                this.unSelectAll();
                this.$selectedNodes.push(nodeElt);
                nodeElt.addClass('as-focus')
                    .addClass('as-selected');
            }
        }
    } else {
        this.blur();
        this.unSelectAll();
    }
};

NodeSelectController.prototype.unSelectNode = function (node) {
    if (!node) return;
    var idx = this.$selectedNodes.indexOf(node);
    if (idx < 0) return;
    var refocus = node.containsClass('as-focus');
    node.removeClass('as-selected');
    if (refocus) {
        this.blur();
    }
    this.$selectedNodes.splice(idx, 1);
    if (refocus) {
        if (this.$selectedNodes.length > 0) {
            this.$selectedNodes[this.$selectedNodes.length - 1].addClass('as-focus');
        }
    }
};

NodeSelectController.prototype.toggleSelect = function (node, append) {
    if (node.containsClass('as-selected')) {
        if (append) this.unSelectNode(node);
        else {
            this.select(node, false);
        }
    } else {
        this.select(node, append);
    }
};

NodeSelectController.prototype.blur = function () {
    if (this.$selectedNodes.length > 0) {
        if (this.$selectedNodes[this.$selectedNodes.length - 1].containsClass('as-focus')) {
            this.$selectedNodes[this.$selectedNodes.length - 1].removeClass('as-focus');
        }
    }
};

NodeSelectController.prototype.unSelectAll = function () {
    this.blur();
    this.$selectedNodes.splice(0, this.$selectedNodes.length).forEach(function (elt) {
        elt.removeClass('as-selected');
    });
};


export default NodeSelectController;

VaKeR 2022