summaryrefslogtreecommitdiff
path: root/_includes/extensions/geopattern.html
blob: 3931533e8d1496c19584f79f39c3449cc23f366f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{% if include.selector %}
  {% assign selector = include.selector %}
{% endif %}

{% if include.seed %}
  {% assign seed = include.seed %}
{% endif %}

<script src="https://cdnjs.cloudflare.com/ajax/libs/geopattern/1.2.3/js/geopattern.min.js"></script>
<script>
  function setRandomBgImage(selector, seed) {
    var pattern = GeoPattern.generate(seed);
    var element = document.querySelector(selector)
    if (element) {
      element.style.backgroundImage = pattern.toDataUrl();
    }
  }

  setRandomBgImage('{{ selector }}', '{{ seed }}');
</script>