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__TimeSelectInput.js
/*** module: node_modules/absol-acomp/js/TimeSelectInput.js ***/
"use strict";

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

require("../css/timeselectinput.css");

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

var _AElement = _interopRequireDefault(require("absol/src/HTML5/AElement"));

var _datetime = require("absol/src/Time/datetime");

var _TimeInput = _interopRequireDefault(require("./TimeInput"));

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

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

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


var _ = _ACore.default._;
var $ = _ACore.default.$;
/***
 * @extends AElement
 * @constructor
 */

function TimeSelectInput() {
  /***
   *
   * @type {SelectListBox}
   */
  this.$selectlistBox = _({
    tag: 'selectlistbox',
    props: {
      anchor: [1, 6, 2, 5]
    },
    on: {
      preupdateposition: this.eventHandler.preUpdateListPosition
    }
  });
  this.$text = $('.as-time-select-input-text', this).on('change', this.eventHandler.textChange).on('keyup', this.eventHandler.textKeyUp).on('keydown', this.eventHandler.textKeyDown);
  this.$toggleBtn = $('absol-selectmenu-btn', this);
  this.$selectlistBox.on('pressitem', this.eventHandler.selectListBoxPressItem);
  this.$selectlistBox.followTarget = this;
  this.$selectlistBox.sponsorElement = this;

  this._makeTimeList(0, _datetime.MILLIS_PER_DAY, _datetime.MILLIS_PER_MINUTE * 15);

  this._hour = 0;
  this._minute = 0;
  this._lastDayOffset = 0;
  this.dayOffset = 0;
  this.on('click', this.eventHandler.click);
}

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

TimeSelectInput.render = function () {
  return _({
    class: 'as-time-select-input',
    extendEvent: 'change',
    attr: {
      tabindex: 0
    },
    child: [{
      tag: 'input',
      class: 'as-time-select-input-text',
      attr: {
        type: 'text'
      }
    }, {
      tag: 'button',
      class: 'absol-selectmenu-btn',
      child: ['dropdown-ico']
    }]
  });
};

TimeSelectInput.prototype._makeTimeList = function (start, end, step) {
  var items = [];

  for (var t = 0; t < end; t += step) {
    items.push({
      text: this._mil2Text(t),
      value: t
    });
  }

  this.$selectlistBox.items = items;
  this.addStyle('--list-min-width', this.$selectlistBox._estimateWidth / 14 + 'em');
};

TimeSelectInput.prototype.textRegx = /^((1[0-2])|[1-9]):([0-5][0-9]) (AM|PM)$/;

TimeSelectInput.prototype._mil2Text = function (mil) {
  if (mil < 0) {
    mil = mil + Math.ceil(-mil / _datetime.MILLIS_PER_DAY) * _datetime.MILLIS_PER_DAY;
  }

  var min = Math.floor(mil / _datetime.MILLIS_PER_MINUTE);
  var hour = Math.floor(min / 60) % 24;
  min = min % 60;
  return (hour % 12 == 0 ? 12 : hour % 12) + ':' + (min < 10 ? '0' : '') + min + ' ' + (hour < 12 ? 'AM' : 'PM');
};
/***
 *
 * @param {string} s
 * @private
 */


TimeSelectInput.prototype._text2mil = function (s) {
  s = s.toLowerCase();
  var nums = s.match(/[0-9]+/g) || [0, 0];

  while (nums.length < 2) {
    nums.push(0);
  }

  var h = (0, _utils.positiveIntMod)(parseInt(nums[0]), 24);
  var m = (0, _utils.positiveIntMod)(parseInt(nums[1]), 60);
  var pm = s.indexOf('pm') > 0 || h > 12;

  if (pm) {
    if (h < 12) h += 12;
  } else {
    if (h == 12) h = 0;
  }

  return h * _datetime.MILLIS_PER_HOUR + m * _datetime.MILLIS_PER_MINUTE;
};

TimeSelectInput.prototype.isActive = function () {
  return document.activeElement == this || _AElement.default.prototype.isDescendantOf.call(document.activeElement, this) || _AElement.default.prototype.isDescendantOf.call(document.activeElement, this.$selectlistBox);
};

TimeSelectInput.prototype._updateValueText = function () {
  this.$text.value = this._mil2Text(this.dayOffset);
};

TimeSelectInput.prototype.notifyCanBeChange = function () {
  var dayOffset = this.dayOffset;

  if (this._lastDayOffset !== dayOffset) {
    this.emit('change', {
      type: 'change',
      lastDayOffset: this._lastDayOffset,
      dayOffset: dayOffset,
      target: this
    }, this);
    this._lastDayOffset = dayOffset;
  }
};

TimeSelectInput.property = {};
TimeSelectInput.property.isFocus = {
  get: function () {
    return this.hasClass('as-focus');
  },
  set: function (value) {
    value = !!value;
    if (value && (this.disabled || this.readOnly)) return;
    if (this.isFocus == value) return;

    if (value) {
      this.addClass('as-focus');
    } else {
      this.removeClass('as-focus');
    }

    var thisI = this;

    if (value) {
      this.$selectlistBox.addTo(document.body);
      var bound = this.getBoundingClientRect();
      this.$selectlistBox.addStyle('min-width', bound.width + 'px');
      this.$selectlistBox.refollow();
      this.$selectlistBox.updatePosition();
      setTimeout(function () {
        if (thisI.enableSearch) {
          thisI.$selectlistBox.$searchInput.focus();
        }

        $(document.body).on('click', thisI.eventHandler.bodyClick);
      }, 1);
      this.$selectlistBox.viewListAtFirstSelected();
    } else {
      $(document.body).off('click', thisI.eventHandler.bodyClick);
      this.$selectlistBox.selfRemove();
      this.$selectlistBox.unfollow();
      this.$selectlistBox.resetSearchState();
    }
  }
};
TimeSelectInput.property.hour = {
  set: function (value) {
    this._hour = (0, _utils.positiveIntMod)(value, 24);
    this._lastDayOffset = this.dayOffset;

    this._updateValueText();
  },
  get: function () {
    return this._hour;
  }
};
TimeSelectInput.property.minute = {
  set: function (value) {
    this._minute = (0, _utils.positiveIntMod)(value, 60);
    this._lastDayOffset = this.dayOffset;

    this._updateValueText();
  },
  get: function () {
    return this._minute;
  }
};
TimeSelectInput.property.dayOffset = _TimeInput.default.property.dayOffset;
TimeSelectInput.property.disabled = {
  set: function (value) {
    this.$text.disabled = !!value;

    if (value) {
      this.addClass('as-disabled');
    } else {
      this.removeClass('as-disabled');
    }
  },
  get: function () {
    return this.hasClass('as-disabled');
  }
};
/***
 *
 * @type {{}|TimeSelectInput}
 */

TimeSelectInput.eventHandler = {};

TimeSelectInput.eventHandler.selectListBoxPressItem = function (event) {
  var lastValue = this._lastDayOffset;
  var value = event.value;

  var text = this._mil2Text(value);

  this.dayOffset = value;
  this.$selectlistBox.values = [value];
  this.focus();
  setTimeout(function () {
    this.isFocus = false;
  }.bind(this), 100);
  this._lastDayOffset = lastValue; // restore last value after set dayOffset

  this.notifyCanBeChange();
};

TimeSelectInput.eventHandler.preUpdateListPosition = function () {
  var bound = this.getBoundingClientRect();
  var screenSize = (0, _Dom.getScreenSize)();
  var availableTop = bound.top - 5;
  var availableBot = screenSize.height - 5 - bound.bottom;
  this.$selectlistBox.addStyle('--max-height', Math.max(availableBot, availableTop) + 'px');
  var outBound = (0, _Dom.traceOutBoundingClientRect)(this);

  if (bound.bottom < outBound.top || bound.top > outBound.bottom || bound.right < outBound.left || bound.left > outBound.right) {
    this.isFocus = false;
  }
};

TimeSelectInput.eventHandler.textChange = function () {
  setTimeout(function () {
    if (!this.textRegx.test(this.$text.value)) {
      this.$text.value = this._mil2Text(this.dayOffset);
    }
  }.bind(this), 10);
};
/***
 *
 * @param {KeyboardEvent} event
 */


TimeSelectInput.eventHandler.textKeyDown = function (event) {
  if (event.key == 'Enter') {
    this.isFocus = false;
    this.$text.blur();
    this.notifyCanBeChange();
  }
};

TimeSelectInput.eventHandler.textKeyUp = function (event) {
  var s = this.$text.value;

  var mil = this._text2mil(s);

  this._hour = Math.floor(mil / _datetime.MILLIS_PER_HOUR);
  this._minute = Math.floor(mil / _datetime.MILLIS_PER_MINUTE) % 60;
  this.$selectlistBox.values = [mil];
  this.$selectlistBox.viewListAtFirstSelected();
};

TimeSelectInput.eventHandler.click = function (event) {
  if (!_EventEmitter.default.hitElement(this.$text, event)) {
    this.isFocus = !this.isFocus;
    setTimeout(function () {
      if (this.isFocus && this.$text != document.activeElement) {
        this.$text.select();
      }
    }.bind(this), 1);
  } else {
    if (!this.isFocus) this.isFocus = true;
  }
};

TimeSelectInput.eventHandler.bodyClick = function (event) {
  if (_EventEmitter.default.hitElement(this, event) || _EventEmitter.default.hitElement(this.$selectlistBox, event)) return;
  this.isFocus = false;
};

_ACore.default.install(TimeSelectInput);

var _default = TimeSelectInput;
exports.default = _default;

VaKeR 2022