data.js 2.35 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
1
/*!
XhmikosR's avatar
XhmikosR committed
2
  * Bootstrap data.js v5.0.0-alpha3 (https://getbootstrap.com/)
XhmikosR's avatar
XhmikosR committed
3
  * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
XhmikosR's avatar
XhmikosR committed
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
XhmikosR's avatar
XhmikosR committed
5
6
7
8
  */
(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  typeof define === 'function' && define.amd ? define(factory) :
XhmikosR's avatar
XhmikosR committed
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Data = factory());
XhmikosR's avatar
XhmikosR committed
10
}(this, (function () { 'use strict';
XhmikosR's avatar
XhmikosR committed
11
12
13

  /**
   * --------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
14
   * Bootstrap (v5.0.0-alpha3): dom/data.js
XhmikosR's avatar
XhmikosR committed
15
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
XhmikosR's avatar
XhmikosR committed
16
17
18
19
20
21
22
23
24
25
26
27
28
   * --------------------------------------------------------------------------
   */

  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */
  var mapData = function () {
    var storeData = {};
    var id = 1;
    return {
      set: function set(element, key, data) {
XhmikosR's avatar
XhmikosR committed
29
30
        if (typeof element.bsKey === 'undefined') {
          element.bsKey = {
XhmikosR's avatar
XhmikosR committed
31
32
33
34
35
36
            key: key,
            id: id
          };
          id++;
        }

XhmikosR's avatar
XhmikosR committed
37
        storeData[element.bsKey.id] = data;
XhmikosR's avatar
XhmikosR committed
38
39
      },
      get: function get(element, key) {
XhmikosR's avatar
XhmikosR committed
40
        if (!element || typeof element.bsKey === 'undefined') {
XhmikosR's avatar
XhmikosR committed
41
42
43
          return null;
        }

XhmikosR's avatar
XhmikosR committed
44
        var keyProperties = element.bsKey;
XhmikosR's avatar
XhmikosR committed
45
46
47
48
49
50
51
52

        if (keyProperties.key === key) {
          return storeData[keyProperties.id];
        }

        return null;
      },
      delete: function _delete(element, key) {
XhmikosR's avatar
XhmikosR committed
53
        if (typeof element.bsKey === 'undefined') {
XhmikosR's avatar
XhmikosR committed
54
55
56
          return;
        }

XhmikosR's avatar
XhmikosR committed
57
        var keyProperties = element.bsKey;
XhmikosR's avatar
XhmikosR committed
58
59
60

        if (keyProperties.key === key) {
          delete storeData[keyProperties.id];
XhmikosR's avatar
XhmikosR committed
61
          delete element.bsKey;
XhmikosR's avatar
XhmikosR committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        }
      }
    };
  }();

  var Data = {
    setData: function setData(instance, key, data) {
      mapData.set(instance, key, data);
    },
    getData: function getData(instance, key) {
      return mapData.get(instance, key);
    },
    removeData: function removeData(instance, key) {
      mapData.delete(instance, key);
    }
  };

  return Data;

XhmikosR's avatar
XhmikosR committed
81
})));
XhmikosR's avatar
XhmikosR committed
82
//# sourceMappingURL=data.js.map