|
12 | 12 |
|
13 | 13 | var DEFAULT_SETTINGS = { |
14 | 14 | tableWidth: "fixed", // fixed | full | fluid |
| 15 | + sidebarWidth: "standard", // standard | compact |
15 | 16 | rowDensity: "normal", // compact | normal | comfortable |
16 | 17 | wrapLongText: false, |
17 | 18 | maxColumnWidthPx: null, // number | null |
|
21 | 22 | }; |
22 | 23 |
|
23 | 24 | var allowedTableWidths = { fixed: true, full: true, fluid: true }; |
| 25 | + var allowedSidebarWidths = { standard: true, compact: true }; |
24 | 26 | var allowedRowDensities = { compact: true, normal: true, comfortable: true }; |
25 | 27 | var allowedJsonModes = { raw: true, wrapped: true, pretty: true }; |
26 | 28 | var allowedPageLengths = { 10: true, 25: true, 50: true, 100: true }; |
|
90 | 92 | if (!raw || typeof raw !== "object") return settings; |
91 | 93 |
|
92 | 94 | if (allowedTableWidths[raw.tableWidth]) settings.tableWidth = raw.tableWidth; |
| 95 | + if (allowedSidebarWidths[raw.sidebarWidth]) settings.sidebarWidth = raw.sidebarWidth; |
93 | 96 | if (allowedRowDensities[raw.rowDensity]) settings.rowDensity = raw.rowDensity; |
94 | 97 | if (allowedJsonModes[raw.jsonMode]) settings.jsonMode = raw.jsonMode; |
95 | 98 |
|
|
142 | 145 | } |
143 | 146 | } |
144 | 147 |
|
| 148 | + function setBootstrapSmColumn(el, span) { |
| 149 | + if (!el || !el.length) return; |
| 150 | + if (typeof span !== "number") return; |
| 151 | + if (span < 1) span = 1; |
| 152 | + if (span > 12) span = 12; |
| 153 | + |
| 154 | + var className = el.attr("class") || ""; |
| 155 | + var classes = className.split(/\s+/).filter(Boolean); |
| 156 | + var updated = []; |
| 157 | + for (var i = 0; i < classes.length; i++) { |
| 158 | + if (/^col-sm-\d+$/.test(classes[i])) continue; |
| 159 | + updated.push(classes[i]); |
| 160 | + } |
| 161 | + updated.push("col-sm-" + span); |
| 162 | + el.attr("class", updated.join(" ")); |
| 163 | + } |
| 164 | + |
| 165 | + function applySidebarWidth(settings) { |
| 166 | + var dbCol = $("#addb-db-column"); |
| 167 | + var tableCol = $("#addb-table-column"); |
| 168 | + var dataCol = $("#parent-data-div"); |
| 169 | + if (!dbCol.length || !tableCol.length || !dataCol.length) return; |
| 170 | + |
| 171 | + var isCompact = settings.sidebarWidth === "compact"; |
| 172 | + setBootstrapSmColumn(dbCol, isCompact ? 1 : 2); |
| 173 | + setBootstrapSmColumn(tableCol, isCompact ? 1 : 2); |
| 174 | + setBootstrapSmColumn(dataCol, isCompact ? 10 : 8); |
| 175 | + } |
| 176 | + |
145 | 177 | function applyBodyClasses(settings) { |
146 | 178 | var body = $("body"); |
147 | 179 |
|
|
154 | 186 | body.addClass("addb-json-mode-" + settings.jsonMode); |
155 | 187 |
|
156 | 188 | body.toggleClass("addb-sticky-header", !!settings.stickyHeader); |
| 189 | + |
| 190 | + body.toggleClass("addb-sidebar-compact", settings.sidebarWidth === "compact"); |
157 | 191 | } |
158 | 192 |
|
159 | 193 | function applyMaxColumnWidth(settings) { |
|
423 | 457 | currentSettings = normalizeSettings(settings); |
424 | 458 |
|
425 | 459 | applyContainerWidth(currentSettings); |
| 460 | + applySidebarWidth(currentSettings); |
426 | 461 | applyBodyClasses(currentSettings); |
427 | 462 | applyMaxColumnWidth(currentSettings); |
428 | 463 |
|
|
550 | 585 | var maxWidthRaw = $("#addb-max-column-width").val(); |
551 | 586 | var settings = { |
552 | 587 | tableWidth: $("input[name='addb-table-width']:checked").val(), |
| 588 | + sidebarWidth: $("input[name='addb-sidebar-width']:checked").val(), |
553 | 589 | rowDensity: $("input[name='addb-row-density']:checked").val(), |
554 | 590 | wrapLongText: $("#addb-wrap-long-text").is(":checked"), |
555 | 591 | maxColumnWidthPx: maxWidthRaw === "" ? null : maxWidthRaw, |
|
562 | 598 |
|
563 | 599 | function writeFormFromSettings(settings) { |
564 | 600 | $("input[name='addb-table-width'][value='" + settings.tableWidth + "']").prop("checked", true); |
| 601 | + $("input[name='addb-sidebar-width'][value='" + settings.sidebarWidth + "']").prop("checked", true); |
565 | 602 | $("input[name='addb-row-density'][value='" + settings.rowDensity + "']").prop("checked", true); |
566 | 603 | $("#addb-wrap-long-text").prop("checked", !!settings.wrapLongText); |
567 | 604 | $("#addb-max-column-width").val(settings.maxColumnWidthPx === null ? "" : settings.maxColumnWidthPx); |
|
0 commit comments