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__src__Code__FlagManager.js
/*** module: node_modules/absol/src/Code/FlagManager.js ***/
"use strict";

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

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

var _OOP = _interopRequireDefault(require("../HTML5/OOP"));


/***
 * @extends EventEmitter
 * @constructor
 */
function FlagManager() {
  _EventEmitter.default.call(this);

  this.flag = {};
  this.readSetting();
}

_OOP.default.mixClass(FlagManager, _EventEmitter.default);

FlagManager.prototype.STORE_KEY = "ABSOL_FLAG";

FlagManager.prototype.readSetting = function () {
  var flagText = localStorage.getItem(this.STORE_KEY) || '{}';
  var newFlag = {};

  try {
    newFlag = JSON.parse(flagText);
  } catch (err) {}

  this.applyFlag(newFlag);
};

FlagManager.prototype.applyFlag = function (newFlag, save) {
  var changed = [];
  Object.keys(Object.assign({}, this.flag, newFlag)).forEach(function (key) {
    if (key in window) {
      if (key in newFlag) {
        if (window[key] !== newFlag[key]) {
          window[key] = newFlag[key];
          changed.push(key);
        }
      } else {
        changed.push(key);
        delete window[key];
      }
    } else {
      if (key in newFlag) {
        if (window[key] !== newFlag[key]) {
          window[key] = newFlag[key];
          changed.push(key);
        }
      }
    }
  });
  this.flag = newFlag;
  if (save) this.saveSetting();

  if (changed.length > 0) {
    this.emit('change', {
      type: 'change',
      target: this,
      keys: changed
    });
  }
};

FlagManager.prototype.saveSetting = function () {
  localStorage.setItem(this.STORE_KEY, JSON.stringify(this.flag));
};
/***
 *
 * @param {string} key
 * @param {boolean=} value
 */


FlagManager.prototype.add = function (key, value) {
  if (!key || typeof key != 'string') return;
  if (key in this.flag) return;

  if (typeof value != "boolean") {
    value = !!window[key];
  }

  this.flag[key] = value;
  window[key] = value;
  this.saveSetting();
  this.emit('change', {
    type: 'change',
    target: this,
    keys: [key]
  });
};

FlagManager.prototype.set = function (key, value) {
  if (!key || typeof key != 'string') return;

  if (typeof value != "boolean") {
    value = !!window[key];
  }

  var changed = false;
  this.flag[key] = value;

  if (window[key] !== value) {
    changed = true;
  }

  this.saveSetting();

  if (changed) {
    this.emit('change', {
      type: 'change',
      target: this,
      keys: [key]
    });
  }
};

FlagManager.prototype.remove = function (key) {
  if (key in this.flag) {
    delete window[key];
    delete this.flag[key];
    this.emit('change', {
      type: 'change',
      target: this,
      keys: [key]
    });
  }
};

var _default = new FlagManager();

exports.default = _default;

VaKeR 2022