add support for bookmarking the expanded/collapsed state of the whole…
… sidebar
- Loading branch information
- +10 −3 R/dashboardSidebar.R
- +54 −3 inst/shinydashboard.js
- +1 −1 inst/shinydashboard.js.map
- +1 −1 inst/shinydashboard.min.js
- +1 −1 inst/shinydashboard.min.js.map
- +40 −0 srcjs/input_binding_sidebarCollapsed.js
- +10 −3 srcjs/sidebar.js
- +2 −0 tools/Gruntfile.js
| @@ -0,0 +1,40 @@ | ||
| /* global Shiny */ | ||
|
|
||
| // sidebarCollapsedInputBinding | ||
| // ------------------------------------------------------------------ | ||
| // This keeps tracks of whether the sidebar is expanded (default) | ||
| // or collapsed | ||
| var sidebarCollapsedInputBinding = new Shiny.InputBinding(); | ||
| $.extend(sidebarCollapsedInputBinding, { | ||
| find: function(scope) { | ||
| return $(scope).find('.main-sidebar').first(); | ||
| }, | ||
| getId: function(el) { | ||
| return "sidebarCollapsed"; | ||
| }, | ||
| getValue: function(el) { | ||
| return $(el).attr("data-collapsed"); | ||
| }, | ||
| setValue: function(el, value) { | ||
| $(el).attr("data-collapsed", value); | ||
| }, | ||
| toggleValue: function(el) { | ||
| var current = this.getValue(el); | ||
| var newVal = (current === "true") ? "false" : "true"; | ||
| this.setValue(el, newVal); | ||
| }, | ||
| receiveMessage: function(el, data) { | ||
| if (data.hasOwnProperty('value')) | ||
| this.setValue(el, data.value); | ||
| }, | ||
| subscribe: function(el, callback) { | ||
| $(el).on('change.sidebarCollapsedInputBinding', function() { | ||
| callback(); | ||
| }); | ||
| }, | ||
| unsubscribe: function(el) { | ||
| $(el).off('.sidebarCollapsedInputBinding'); | ||
| } | ||
| }); | ||
| Shiny.inputBindings.register(sidebarCollapsedInputBinding, | ||
| 'shinydashboard.sidebarCollapsedInputBinding'); |