Sha256: 2cb6f206b263493b0defc3ffbb4352273bc7c4858f25950980d5b1b68a457c5b

Contents?: true

Size: 1.47 KB

Versions: 11

Compression:

Stored size: 1.47 KB

Contents

global.FuturizeComponent = {    
  init: function (css_selector) {
    var obj = document.querySelectorAll(css_selector);
    for (var i in obj) {
      if (obj.hasOwnProperty(i)) {
        //console.log(obj[i].getAttribute('data-futurize-component'));
        this.load_component(obj[i])
      }
    }
  },

  reload: function(css_selector) {
    document.querySelectorAll(css_selector).forEach(function(o) {
      o.innerHTML = ""
    })
  },

  load_component: function (obj) {
    var component_name = obj.getAttribute('data-futurize-component'),
        component_params = obj.getAttribute('data-futurize-params');

    if (obj.innerHTML.trim().length <= 0) {
      obj.innerHTML = 'Loading....';
    }

    var AUTH_TOKEN = document.querySelector('meta[name=csrf-token]').getAttribute('content');
    fetch('/home/loadComponent', {
      mode: 'same-origin',
      method: 'POST',
      dataType: 'json',
      body : JSON.stringify({ component_to_load: component_name, component_params: component_params }),
      headers:  {
        'Content-Type': 'application/json',
        'X-CSRF-Token' : AUTH_TOKEN,
      },
    })
    .then(response => response.json())
    .then(data => {
      obj.innerHTML = data.html
      obj.querySelectorAll("script").forEach(function(o) {
        eval(o.innerHTML)
      })
    }).catch((error) => {
      console.error('Error:', error);
    });
  }
}
document.addEventListener('DOMContentLoaded', function () {
  FuturizeComponent.init('[data-futurize-component]');
})

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
async_futurize-0.1.14 vendor/assets/javascripts/futurize.js
async_futurize-0.1.12 app/javascript/packs/futurize.js
async_futurize-0.1.11 app/javascript/packs/futurize.js
async_futurize-0.1.10 app/javascript/packs/futurize.js
async_futurize-0.1.9 app/javascript/packs/futurize.js
async_futurize-0.1.8 app/javascript/packs/futurize.js
async_futurize-0.1.7 app/javascript/packs/futurize.js
async_futurize-0.1.6 app/javascript/packs/futurize.js
async_futurize-0.1.5 app/assets/javascript/futurize.js
async_futurize-0.1.4 app/assets/javascript/futurize.js
async_futurize-0.1.3 app/assets/javascript/futurize.js