Skip to content

Form debugger storage #9967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
{% endif %}

<script>
function Toggler() {
function Toggler(togglerStorage) {
"use strict";

var expand = function (button) {
Expand All @@ -210,6 +210,8 @@
throw "Toggle target " + targetId + " does not exist";
}

togglerStorage.store(targetId, 'visible');

Sfjs.removeClass(button, 'closed');
Sfjs.removeClass(target, 'hidden');
},
Expand All @@ -222,6 +224,8 @@
throw "Toggle target " + targetId + " does not exist";
}

togglerStorage.store(targetId, 'hidden');

Sfjs.addClass(button, 'closed');
Sfjs.addClass(target, 'hidden');
},
Expand Down Expand Up @@ -271,6 +275,63 @@
};
}

function TogglerStorage(key) {
var key = 'sf_' + (key || 'toggle_data'),
store = function (id, state) {
var toggleData = sessionStorage.getItem(key);
if (!toggleData) {
toggleData = [];
} else {
toggleData = toggleData.split('|');
}

if ('visible' == state) {
toggleData.push(id);
} else {
var index = toggleData.indexOf(id);
if (-1 < index) {
toggleData.splice(index, 1);
}
}

sessionStorage.setItem(key, toggleData.join('|'));
},

initStorage = function (buttonsSelector) {
var toggleData = sessionStorage.getItem(key);

if (!toggleData) {
return;
}
toggleData = toggleData.split('|');

var buttons = document.getElementsByClassName(buttonsSelector || 'toggle-button');
for (i in toggleData) {
var element = document.getElementById(toggleData[i]);
if (!element) {
continue;
}

if (Sfjs.hasClass(element, 'hidden')) {
for (var i = -1; button = buttons[++i]; ) {
if (button.dataset.toggleTargetId && button.dataset.toggleTargetId == element.getAttribute('id')) {
break;
}
}

Sfjs.removeClass(element, 'hidden');
Sfjs.removeClass(button, 'closed');
}
}
};

return {
store: store,

initStorage: initStorage
};
}

function TabView() {
"use strict";

Expand Down Expand Up @@ -335,10 +396,12 @@
}

var tabTarget = new TabView(),
toggler = new Toggler();
storage = new TogglerStorage(),
toggler = new Toggler(storage);

tabTarget.initTabs(document.querySelectorAll('.tree .tree-inner'));
toggler.initButtons(document.querySelectorAll('a.toggle-button'));
storage.initStorage();
</script>
{% endblock %}

Expand Down