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-acomp/out/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-acomp/out/ContextMenu.js.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: ContextMenu.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: ContextMenu.js</h1>

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>import '../css/contextmenu.css';
import ACore from "../ACore";
import EventEmitter from "absol/src/HTML5/EventEmitter";
import Dom from "absol/src/HTML5/Dom";
import Vec2 from 'absol/src/Math/Vec2';
import './Menu';
import AElement from "absol/src/HTML5/AElement";
import BoardTable from "./BoardTable";
import { getSelectionText } from "./utils";
import BrowserDetector from "absol/src/Detector/BrowserDetector";

var _ = ACore._;
var $ = ACore.$;

var supportContextEvent = false;
var isMobile = BrowserDetector.isMobile;


/**
 * @extends AElement
 * @constructor
 */
export function ContextCaptor() {
    this.attachedElt = null;
    this.$textarea = $('textarea', this)
        .attr('readonly', 'true')
        .on('contextmenu', this.eventHandler.contextmenu, true);
    this._ss = 0;
    this._isTouch = false;
    /**
     this._target = null;
     * @type {Vec2}
     */
    this._posStart = null;
    /**
     * @type {Vec2}
     */
    this._posCurrent = null;
    this._touchId = -100;
    this._longPressTimeout = -1;
    this._removeTimeout = -1;
    this._fireContextMenuTimeout = -1;
    this.$target = null;
    this._pointerSession = 0;
    this._lastContextSession = 0;

    this.mousedownEvent = null;
    this.sync = Promise.resolve();
};

ContextCaptor.prototype.attachTo = function (elt) {
    if (this.attachedElt) {
        this.attachedElt.removeEventListener('mousedown', this.eventHandler.mousedown);
        this.attachedElt.removeEventListener('touchstart', this.eventHandler.mousedown);
        this.attachedElt = null;
    }
    this.attachedElt = elt;
    if (this.attachedElt) {
        this.attachedElt.addEventListener('mousedown', this.eventHandler.mousedown);
        this.attachedElt.addEventListener('touchstart', this.eventHandler.mousedown);
    }
    return this;
};

ContextCaptor.tag = 'ContextCaptor'.toLowerCase();

ContextCaptor.render = function () {
    return _({
        class: ['absol-context-menu-anchor'],
        extendEvent: 'requestcontextmenu',
        child: [
            'textarea'
        ]
    });
};

ContextCaptor.prototype.showContextMenu = function (x, y, props, onSelectItem) {
    var self = this;
    var anchor = _('.as-context-menu-ctn.absol-context-menu-anchor' + (isMobile ? '.as-anchor-modal' : '')).addTo(document.body);
    var finish = function (event) {
        document.removeEventListener('click', finish);
        document.removeEventListener('touchcancel', finish);
        document.removeEventListener('touchend', finish);
        document.removeEventListener('contextmenu', finish);
        anchor.off('click', touchModal);


        self.off('requestcontextmenu', finish);
        setTimeout(function () {
            anchor.selfRemove();//
        }, 10);
    };

    function touchModal(event) {
        if (event.target.classList &amp;&amp; event.target.classList.contains('as-anchor-modal')) {
            finish(event);
        }
    }

    var vmenu = _({
        tag: 'vmenu',
        props: props,
        on: {
            press: onSelectItem || function () {
            }
        }
    }).addTo(anchor);


    setTimeout(function () {
        if (!isMobile) {
            var screenSize = Dom.getScreenSize();
            var menuBound = vmenu.getBoundingClientRect();
            if (x + menuBound.width > screenSize.width - 17) {
                x -= menuBound.width;
            }
            if (y + menuBound.height > screenSize.height - 17) {
                y -= menuBound.height;
            }

            anchor.addStyle({
                left: x + 'px',
                top: y + 'px'
            });
        }
        anchor.addClass('absol-active');
    }, 30);


    setTimeout(function () {
        document.addEventListener('click', finish)
        document.addEventListener('contextmenu', finish);
        self.on('requestcontextmenu', finish);
        anchor.on('click', touchModal);
    }, 10)
};

ContextCaptor.prototype._checkNeedHandle = function (target) {
    var current = target;
    var needHandle = false;
    while (current &amp;&amp; !needHandle &amp;&amp; !current.classList.contains('as-system-context-menu')) {
        if (current.isSupportedEvent &amp;&amp; current.isSupportedEvent('contextmenu'))
            needHandle = true;
        current = current.parentElement;
    }
    return needHandle;
};


ContextCaptor.prototype._fireContextMenuEvent = function () {
    if (this._lastContextSession >= this._pointerSession) return false;// prevent fire multi-times in a pointer session
    var showed = false;
    this._lastContextSession = this._pointerSession;
    var baseEventData = {
        clientX: this._posCurrent.x,
        clientY: this._posCurrent.y,
        target: this.$target
    };
    this.emit('requestcontextmenu', baseEventData, this);
    var self = this;

    var propagation = true;
    var localEvent = Object.assign({
        clientX: this._posCurrent.x, clientY: this._posCurrent.y,
        target: this.$target,
        showContextMenu: function (props, onSelectItem) {
            showed = true;
            self.sync = self.sync.then(function () {
                return new Promise(function (rs) {
                    setTimeout(function () {
                        self.showContextMenu(self._posCurrent.x, self._posCurrent.y, props, onSelectItem);
                        rs();
                    }, 30)
                });
            })
        },
        stopPropagation: function () {
            propagation = false;
        }
    }, baseEventData);

    Object.defineProperty(localEvent, 'selectedText', {
        get: function () {
            return getSelectionText();
        }
    });

    var current = this.$target;
    while (current &amp;&amp; propagation) {
        if (current.isSupportedEvent &amp;&amp; current.isSupportedEvent('contextmenu')) {
            current.emit('contextmenu', localEvent, current, this);
        }
        current = current.parentElement;
    }
    return showed;
};

/**
 * @type {ContextCaptor}
 */
ContextCaptor.eventHandler = {};

ContextCaptor.eventHandler.mousedown = function (event) {
    if (this._touchId != -100) return;
    this._pointerSession++;
    var target;
    var isTouch;
    var touchId;
    var posCurrent;
    var pointer;
    if (event.type == 'touchstart') {
        isTouch = true;
        pointer = event.changedTouches[0];
        touchId = pointer.identifier;
    }
    else {
        isTouch = false;
        touchId = -1;
        pointer = event;
    }
    target = pointer.target;

    posCurrent = new Vec2(pointer.clientX, pointer.clientY);

    if (isTouch) {
        var dragzone = BoardTable.prototype._findDragZone(target);
        if (dragzone) return;
        var thisCT = this;
        this._longPressTimeout = setTimeout(function () {
            if (!thisCT._checkNeedHandle(target)) return;
            if (thisCT._removeTimeout > 0) {
                clearTimeout(thisCT._removeTimeout);
                thisCT._removeTimeout = -1;
            }

            thisCT._ss++;
            thisCT.moveTo(thisCT._posCurrent);
            thisCT.active(true);
            thisCT._longPressTimeout = -1;
            if (thisCT._fireContextMenuTimeout >= 0) {
                clearTimeout(thisCT._fireContextMenuTimeout);
            }
            // show if device not support contextmenu event (after 700ms)
            thisCT._fireContextMenuTimeout = setTimeout(function () {
                if (!supportContextEvent) {
                    thisCT._fireContextMenuEvent();
                }
            }, 300);
        }, 400);
        this.$target = target;
        this._isTouch = isTouch;
        this._touchId = touchId;
        this._posCurrent = posCurrent;
        this._posStart = posCurrent;
        document.addEventListener('touchmove', thisCT.eventHandler.mousemove);
        document.addEventListener('touchend', thisCT.eventHandler.mousefinish);
        document.addEventListener('touchcancel', thisCT.eventHandler.mousefinish);

    }
    else {
        if (EventEmitter.isMouseRight(event) &amp;&amp; this._checkNeedHandle(target)) {
            if (this._removeTimeout > 0) {
                clearTimeout(this._removeTimeout);
                this._removeTimeout = -1;
            }
            this.$target = target;
            this._isTouch = isTouch;
            this._posCurrent = posCurrent;
            this._posStart = posCurrent;
            this._touchId = touchId;
            this._ss++;
            this.moveTo(this._posCurrent);
            this.active(true);

            document.addEventListener('mousemove', this.eventHandler.mousemove);
            document.addEventListener('mouseup', this.eventHandler.mousefinish);
            document.addEventListener('mouseleave', this.eventHandler.mousefinish);
        }
    }
};

/**
 * @param {Vec2} pos
 */
ContextCaptor.prototype.moveTo = function (pos) {
    this.addStyle({
        left: pos.x - 80 + 'px',
        top: pos.y - 80 + 'px'
    });
};

ContextCaptor.prototype.active = function (flag) {
    if (flag)
        this.addClass('absol-active');
    else
        this.removeClass('absol-active');
};

ContextCaptor.eventHandler.mousemove = function (event) {
    var isTouch = this._isTouch;
    var touchId;
    var pointer;
    var posCurrent;
    if (isTouch) {
        pointer = event.changedTouches[0];
        touchId = pointer.identifier;
    }
    else {
        isTouch = false;
        touchId = -1;
        pointer = event;
    }

    if (touchId != this._touchId) return;
    posCurrent = new Vec2(pointer.clientX, pointer.clientY);
    this._posCurrent = posCurrent;
    if (isTouch) {
        if (this._posStart.sub(posCurrent).abs() > 10) this.eventHandler.mousefinish(event);
    }
    this.moveTo(posCurrent);
};


ContextCaptor.eventHandler.mousefinish = function (event) {

    var isTouch = this._isTouch;
    var touchId;
    var pointer;

    if (isTouch) {
        pointer = event.changedTouches[0];
        touchId = pointer.identifier;
    }
    else {
        isTouch = false;
        touchId = -1;
        pointer = event;

    }
    if (touchId != this._touchId) return;
    if (isTouch) {
        document.removeEventListener('touchmove', this.eventHandler.mousemove);
        document.removeEventListener('touchend', this.eventHandler.mousefinish);
        document.removeEventListener('touchcancel', this.eventHandler.mousefinish);
        if (this._longPressTimeout > 0) {
            clearTimeout(this._longPressTimeout);
            this._longPressTimeout = -1;
        }
    }
    else {
        document.removeEventListener('mousemove', this.eventHandler.mousemove);
        document.removeEventListener('mouseup', this.eventHandler.mousefinish);
        document.removeEventListener('mouseleave', this.eventHandler.mousefinish);
    }

    this._touchId = -100;
    if (this._fireContextMenuTimeout >= 0) {
        clearTimeout(this._fireContextMenuTimeout);
    }
    var thisCT = this;
    this._removeTimeout = setTimeout(function () {
        thisCT.active(false);
        thisCT._removeTimeout = -1;

    }, 1);
};

ContextCaptor.eventHandler.contextmenu = function (event) {
    supportContextEvent = true;
    event.preventDefault();
    this._fireContextMenuEvent();

};


ContextCaptor.auto = function () {
    if (ContextCaptor.$elt) return;
    ContextCaptor.$elt = _('contextcaptor');
    Dom.documentReady.then(function () {
        ContextCaptor.$elt.addTo(document.body);
        ContextCaptor.$elt.attachTo(document.body);
    });
};

ACore.install(ContextCaptor);

export default ContextCaptor;</code></pre>
        </article>
    </section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="CalendarInput.html">CalendarInput</a></li><li><a href="CandyBoxButton.html">CandyBoxButton</a></li><li><a href="ChromeCalendar.html">ChromeCalendar</a></li><li><a href="CircleSectionLabel.html">CircleSectionLabel</a></li><li><a href="Cluster.html">Cluster</a></li><li><a href="ClusterIconInfo.html">ClusterIconInfo</a></li><li><a href="ClusterIconStyle.html">ClusterIconStyle</a></li><li><a href="ContextCaptor.html">ContextCaptor</a></li><li><a href="DateInput.html">DateInput</a></li><li><a href="DateInput2.html">DateInput2</a></li><li><a href="DropPanel.html">DropPanel</a></li><li><a href="DropPanelStack.html">DropPanelStack</a></li><li><a href="FlexiconButton.html">FlexiconButton</a></li><li><a href="MarkerClusterer.html">MarkerClusterer</a></li><li><a href="MarkerClustererOptions.html">MarkerClustererOptions</a></li><li><a href="SearchTextInput.html">SearchTextInput</a></li><li><a href="Sprite.html">Sprite</a></li><li><a href="Time24Input.html">Time24Input</a></li></ul><h3>Events</h3><ul><li><a href="MarkerClusterer.html#event:click">click</a></li><li><a href="MarkerClusterer.html#event:clusteringbegin">clusteringbegin</a></li><li><a href="MarkerClusterer.html#event:clusteringend">clusteringend</a></li><li><a href="MarkerClusterer.html#event:mouseout">mouseout</a></li><li><a href="MarkerClusterer.html#event:mouseover">mouseover</a></li></ul><h3>Global</h3><ul><li><a href="global.html#$windowTitleText">$windowTitleText</a></li><li><a href="global.html#AddIcon">AddIcon</a></li><li><a href="global.html#calcMinHMTime">calcMinHMTime</a></li><li><a href="global.html#cleanMenuItemProperty">cleanMenuItemProperty</a></li><li><a href="global.html#preventNotNumberInput">preventNotNumberInput</a></li><li><a href="global.html#vScrollIntoView">vScrollIntoView</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.0</a> on Wed Jan 04 2023 18:18:58 GMT+0700 (Indochina Time)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>

VaKeR 2022