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-full/dist/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-full/dist/js/mdls__absol-acomp__js__QuickMenu.js
/*** module: node_modules/absol-acomp/js/QuickMenu.js ***/
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.QuickMenuInstance = QuickMenuInstance;
exports.default = void 0;

var _ACore = _interopRequireWildcard(require("../ACore"));

var _Dom = _interopRequireWildcard(require("absol/src/HTML5/Dom"));

var _BrowserDetector = _interopRequireDefault(require("absol/src/Detector/BrowserDetector"));

require("./Menu");

var _utils = require("./utils");

var _Follower = _interopRequireDefault(require("./Follower"));

var _EventEmitter = require("absol/src/HTML5/EventEmitter");

var _safeThrow = _interopRequireDefault(require("absol/src/Code/safeThrow"));

var _noop = _interopRequireDefault(require("absol/src/Code/noop"));




var isMobile = _BrowserDetector.default.isMobile;
var _ = _ACore.default._;
var $ = _ACore.default.$;

function QuickMenu() {
  //like context menu without right-click
  this._contextMenuSync = Promise.resolve();
}

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

QuickMenu.render = function () {
  return _({
    tag: 'vmenu',
    extendEvent: 'requestcontextmenu',
    class: ['as-quick-menu', 'as-bscroller'],
    style: {
      'overflow-y': 'auto',
      'box-sizing': 'border-box'
    }
  });
};

_ACore.default.install(QuickMenu);
/***
 *
 * @param {AElement} elt
 * @param opt
 * @constructor
 */


function QuickMenuInstance(elt, opt) {
  this.id = (Math.random() * 10000 >> 0) + '' + new Date().getTime();
  /***
   *
   * @type {"OPEN"|"CLOSE"}
   */

  this.state = 'CLOSE';
  this._willAddClickOut = -1;
  this.elt = elt;
  this.opt = opt;

  for (var key in this) {
    if (key.startsWith('_on')) {
      this[key] = this[key].bind(this);
    }
  }

  this._init();
}

QuickMenuInstance.prototype._init = function () {
  this.elt.classList.add('as-quick-menu-trigger');
  if (this.opt.triggerEvent === 'mousedown') $(this.elt).on('contextmenu', function (event) {
    event.preventDefault();
  }).attr('oncontextmenu', "return false;");

  if (this.opt.triggerEvent) {
    this.elt.addEventListener(this.opt.triggerEvent, this._onClick, true);
  } else this.elt.addEventListener('click', this._onClick, true);

  if (!this.elt.revokeResource) {
    this.elt.revokeResource = () => {
      this.elt.revokeResource = _noop.default;
      this.remove();
    };
  }
};

QuickMenuInstance.prototype._deinit = function () {
  if (this.state === "OPEN") this.close();
  this.elt.classList.remove('as-quick-menu-trigger');

  if (this.opt.triggerEvent) {
    this.elt.removeEventListener(this.opt.triggerEvent, this._onClick, true);
  } else {
    this.elt.removeEventListener('click', this._onClick, true);
  }

  this.elt = null;
  this.opt = null;

  for (var key in this) {
    if (key.startsWith('_on')) {
      this[key] = _noop.default;
    }
  }
};

QuickMenuInstance.prototype.getMenuProps = function () {
  var props;

  if (this.opt.getMenuProps) {
    props = this.opt.getMenuProps();
  } else {
    props = this.opt.menuProps;
  }

  props = props || {};
  return Object.assign({
    extendClasses: [],
    extendStyle: {}
  }, props);
};

QuickMenuInstance.prototype.remove = function () {
  this._deinit();
};

QuickMenuInstance.prototype._onClick = function (event) {
  if (this.opt.triggerEvent === 'mousedown') {
    event.preventDefault();
  }

  var event = (0, _EventEmitter.copyEvent)(event, {
    canceled: false,
    cancel: function () {
      this.canceled = true;
    }
  });

  if (this.opt.onClick) {
    this.opt.onClick.call(this, event);
  }

  if (!event.canceled) this.toggle();
};

QuickMenuInstance.prototype._onClickOut = function (event) {
  if ((0, _EventEmitter.hitElement)(this.elt, event) || (0, _EventEmitter.hitElement)(QuickMenu.$elt, event)) return;
  this.close();
};

QuickMenuInstance.prototype.onSelect = function (item) {
  item = item.__originalItem__ || item;
  if (item.items && item.items.length > 0) return;
  if (this.opt.onSelect) this.opt.onSelect(item);
  this.close();
};

QuickMenuInstance.prototype.open = function () {
  if (QuickMenu.runningInstance === this) return;
  if (this.state !== "CLOSE") return;
  if (QuickMenu.runningInstance) QuickMenu.runningInstance.close();
  QuickMenu.runningInstance = this;
  this.state = 'OPEN';
  this.elt.classList.add('as-quick-menu-attached');
  this._willAddClickOut = setTimeout(() => {
    this._willAddClickOut = -1;
    document.addEventListener('click', this._onClickOut, false);
    followerElt.updatePosition();
    menuElt.addStyle('visibility', 'visible');
  }, isMobile ? 33 : 2);
  var anchor = this.getAnchor();
  var followerElt = QuickMenu.$follower;
  var menuElt = QuickMenu.$elt;
  this.originProps = this.getMenuProps();
  this.copyProps = Object.assign({}, this.originProps);
  this.copyProps.items = this.originProps.items || [];
  this.copyProps.items = this.copyProps.items.map(function visit(item) {
    var cpyItem = item;
    if (typeof item === "string") cpyItem = item;else if (item && typeof item.text === "string") {
      cpyItem = Object.assign({
        __originalItem__: item
      }, item);
      if (cpyItem.items && cpyItem.items.map) cpyItem.items = cpyItem.items.map(visit);
    }
    return cpyItem;
  });
  Object.assign(menuElt, this.copyProps);
  followerElt.addClass('absol-active');

  if (anchor === 'modal') {
    followerElt.addClass('as-anchor-modal');
    followerElt.anchor = [];
  } else {
    followerElt.removeClass('as-anchor-modal');
    followerElt.anchor = anchor;
  }

  this._onSizeNeedUpdate();

  QuickMenu.$follower.on('preupdateposition', this._onSizeNeedUpdate);
  followerElt.followTarget = this.elt;
  followerElt.sponsorElement = this.elt;
  menuElt.addStyle('visibility', 'hidden');
  followerElt.addTo(document.body);
  followerElt.addClass('absol-active');

  if (this.opt.onOpen) {
    try {
      this.opt.onOpen.call(this);
    } catch (err) {
      (0, _safeThrow.default)(err);
    }
  }
};

QuickMenuInstance.prototype.close = function () {
  if (QuickMenu.runningInstance !== this) return;
  if (this.state !== "OPEN") return;

  if (this.opt.onClose) {
    try {
      this.opt.onClose.call(this);
    } catch (err) {
      (0, _safeThrow.default)(err);
    }
  }

  this.state = 'CLOSE';
  this.elt.classList.remove('as-quick-menu-attached');
  QuickMenu.$elt.removeStyle('--available-height');
  var followerElt = QuickMenu.$follower;
  followerElt.addClass('absol-active');
  followerElt.remove();
  QuickMenu.$follower.off('preupdateposition', this._onSizeNeedUpdate);

  if (this._willAddClickOut >= 0) {
    clearTimeout(this._willAddClickOut);
  } else {
    document.removeEventListener('click', this._onClickOut, false);
  }

  QuickMenu.runningInstance = null;
};

QuickMenuInstance.prototype._onSizeNeedUpdate = function () {
  (0, _ACore.$$)('VMenuItem'.toLowerCase(), QuickMenu.$elt).forEach(e => {
    if (e.autoFixParentSize) e.autoFixParentSize();
  });
  var screenSize = (0, _Dom.getScreenSize)();
  var eltBound = this.elt.getBoundingClientRect();
  var outRect = (0, _Dom.traceOutBoundingClientRect)(this.elt);
  var isOut = false;
  if (eltBound.left > outRect.right || eltBound.right < outRect.left || eltBound.top > outRect.bottom || eltBound.bottom < outRect.top) isOut = true;

  if (isOut || !eltBound.width && !eltBound.height) {
    setTimeout(() => {
      this.close();
    }, 0);
  }

  var aTop = eltBound.bottom;
  var aBottom = screenSize.height - eltBound.top;
  QuickMenu.$elt.addStyle('--available-height', Math.max(aTop, aBottom) - 10 + 'px');
};

QuickMenuInstance.prototype.toggle = function () {
  if (this.state === "OPEN") {
    this.close();
  } else if (this.state === 'CLOSE') {
    this.open();
  }
};

QuickMenuInstance.prototype.getAnchor = function () {
  var menuAnchors;
  var anchor = this.opt.getAnchor ? this.opt.getAnchor() : this.opt.anchor;

  if (typeof anchor == 'number') {
    menuAnchors = [anchor];
  } else if (anchor instanceof Array) {
    menuAnchors = anchor;
  } else if (anchor === 'modal') {
    menuAnchors = 'modal';
  } else {
    menuAnchors = QuickMenu.PRIORITY_ANCHORS;
  }

  return menuAnchors;
};

QuickMenu.PRIORITY_ANCHORS = [0, 3, 7, 4, 1, 2, 6, 5];
QuickMenu.$elt = _('quickmenu');
/***
 *
 * @type {Follower}
 */

QuickMenu.$follower = _({
  tag: _Follower.default.tag,
  class: 'absol-context-menu-anchor',
  child: QuickMenu.$elt,
  on: {
    preupdateposition: function () {
      var bound = this.getBoundingClientRect();
      var outBound = (0, _Dom.traceOutBoundingClientRect)(this);

      if (bound.bottom < outBound.top || bound.top > outBound.bottom || bound.right < outBound.left || bound.left > outBound.right) {
        QuickMenu.close(QuickMenu._session);
      }
    }
  }
});
QuickMenu.$follower.cancelWaiting();
/***
 *
 * @type {null|QuickMenuInstance}
 */

QuickMenu.runningInstance = null;
QuickMenu._session = Math.random() * 10000000000 >> 0;
QuickMenu._menuListener = undefined;
QuickMenu.$elt.on('press', function (event) {
  if (QuickMenu.runningInstance) QuickMenu.runningInstance.onSelect((0, _utils.cleanMenuItemProperty)(event.menuItem));
  if (QuickMenu._menuListener) QuickMenu._menuListener((0, _utils.cleanMenuItemProperty)(event.menuItem));
});

QuickMenu.show = function (element, menuProps, anchor, menuListener, darkTheme) {
  var instance = new QuickMenuInstance(element, {
    menuProps: menuProps,
    anchor: anchor,
    onSelect: menuListener,
    darkTheme: darkTheme
  });
  instance.open();
};

QuickMenu.close = function (session) {
  if (QuickMenu.runningInstance && QuickMenu.runningInstance.id === session) QuickMenu.runningInstance.close();
};

QuickMenu.showWhenClick = function (element, menuProps, anchor, menuListener, darkTheme) {
  return new QuickMenuInstance(element, {
    menuProps: menuProps,
    anchor: anchor,
    onSelect: menuListener,
    darkTheme: darkTheme
  });
};
/**
 * @typedef {Object} QuickMenuAdaptor
 * @property {Function} getFlowedElement default is trigger
 * @property {Function} getMenuProps define menuProps if un-change
 * @property {Function} getAnchor default is 'auto', define anchor if un-change
 * @property {Function} onClose callback
 * @property {Function} onOpen callback
 * @property {Function} onSelect calback
 * @property {Function} isDarkTheme default is false, define darkThem if un-change
 *
 *
 * @typedef {Object} QuickMenuDataHolder
 * @property {Function} remove
 *
 * @param {Element} trigger
 * @param {QuickMenuAdaptor} adaptor
 * @returns {QuickMenuDataHolder}
 */


QuickMenu.toggleWhenClick = function (trigger, adaptor) {
  return new QuickMenuInstance(trigger, adaptor);
};

var _default = QuickMenu;
exports.default = _default;

VaKeR 2022