Sha256: 4a481e231d680aa478686b555b1085a1148f8c59c914d864af9563f3374d7aeb

Contents?: true

Size: 1.81 KB

Versions: 11

Compression:

Stored size: 1.81 KB

Contents

Spree.ready(function() {
  if (!document.querySelector(".solidus-admin--nav")) {
    if (window.screen.width <= 1024 && !document.cookie.includes("admin_nav_hidden")) {
      // Set default nav to collapse on small screens - but don't override user preference
      document.body.classList.add("admin-nav-hidden");
      document.cookie = "admin_nav_hidden=true; expires=Fri, 31 Dec 9999 23:59:59 GMT";
    }

    var adminNavToggle = document.querySelector("#admin-nav-toggle");

    if (adminNavToggle) {
      adminNavToggle.addEventListener("click", function(e) {
        e.preventDefault();
        document.body.classList.toggle("admin-nav-hidden");
        $(document.body).trigger("sticky_kit:recalc");
        adminNavToggle.classList.toggle("fa-chevron-circle-left");
        adminNavToggle.classList.toggle("fa-chevron-circle-right");
        document.cookie = "admin_nav_hidden=" + document.body.classList.contains("admin-nav-hidden") + "; expires=Fri, 31 Dec 9999 23:59:59 GMT";
      });
    }

    if (document.body.classList.contains('admin-nav-hidden')) {
      $(adminNavToggle).removeClass('fa-chevron-circle-left').addClass('fa-chevron-circle-right');
    }
  }

  let solidusAdminSwitch = document.querySelector("#solidus-admin-switch");

  if (solidusAdminSwitch) {
    let cookies = new Map(document.cookie.split(';').map((cookie) => cookie.trim().split('=')))
    let label = document.querySelector("#solidus-admin-switch-label");

    solidusAdminSwitch.checked = cookies.get("solidus_admin") === 'false'
    label.textContent = solidusAdminSwitch.checked ? label.dataset.adminLabel : label.dataset.legacyLabel

    solidusAdminSwitch.addEventListener("change", function(e) {
      let value = !solidusAdminSwitch.checked;

      document.cookie = `solidus_admin=${value}; Path=/ `;

      location.reload();
    });
  }
});

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
solidus_backend-4.4.2 app/assets/javascripts/spree/backend/components/admin_nav.js
solidus_backend-4.4.1 app/assets/javascripts/spree/backend/components/admin_nav.js
solidus_backend-4.4.0 app/assets/javascripts/spree/backend/components/admin_nav.js
solidus_backend-4.3.4 app/assets/javascripts/spree/backend/components/admin_nav.js
solidus_backend-4.2.4 app/assets/javascripts/spree/backend/components/admin_nav.js
solidus_backend-4.3.3 app/assets/javascripts/spree/backend/components/admin_nav.js
solidus_backend-4.3.2 app/assets/javascripts/spree/backend/components/admin_nav.js
solidus_backend-4.3.1 app/assets/javascripts/spree/backend/components/admin_nav.js
solidus_backend-4.3.0 app/assets/javascripts/spree/backend/components/admin_nav.js
solidus_backend-4.2.3 app/assets/javascripts/spree/backend/components/admin_nav.js
solidus_backend-4.2.2 app/assets/javascripts/spree/backend/components/admin_nav.js