Permalink
Browse files

Form debugger storage

  • Loading branch information...
1 parent 8cd8ec0 commit 744da7f29c70cf394792b0f4bbcede4efb872be1 @wouterj wouterj committed with fabpot Dec 30, 2013
Showing with 65 additions and 2 deletions.
  1. +65 −2 src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/form.html.twig
@@ -199,7 +199,7 @@
{% endif %}
<script>
- function Toggler() {
+ function Toggler(togglerStorage) {
"use strict";
var expand = function (button) {
@@ -210,6 +210,8 @@
throw "Toggle target " + targetId + " does not exist";
}
+ togglerStorage.store(targetId, 'visible');
+
Sfjs.removeClass(button, 'closed');
Sfjs.removeClass(target, 'hidden');
},
@@ -222,6 +224,8 @@
throw "Toggle target " + targetId + " does not exist";
}
+ togglerStorage.store(targetId, 'hidden');
+
Sfjs.addClass(button, 'closed');
Sfjs.addClass(target, 'hidden');
},
@@ -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";
@@ -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 %}

0 comments on commit 744da7f

Please sign in to comment.