File tree Expand file tree Collapse file tree 10 files changed +89
-23
lines changed Expand file tree Collapse file tree 10 files changed +89
-23
lines changed Original file line number Diff line number Diff line change
1
+ import { getElements } from '../util' ;
2
+
3
+ /**
4
+ * Conditionally add and remove a class that will float the button group
5
+ * based on whether or not items in the list are checked
6
+ */
7
+ function toggleFloat ( ) : void {
8
+ const checkedCheckboxes = document . querySelector < HTMLInputElement > (
9
+ 'input[type="checkbox"][name="pk"]:checked' ,
10
+ ) ;
11
+ const buttonGroup = document . querySelector < HTMLDivElement > (
12
+ 'div.form.form-horizontal div.btn-list' ,
13
+ ) ;
14
+ if ( ! buttonGroup ) {
15
+ return ;
16
+ }
17
+ const isFloating = buttonGroup . classList . contains ( 'btn-float-group-left' ) ;
18
+ if ( checkedCheckboxes !== null && ! isFloating ) {
19
+ buttonGroup . classList . add ( 'btn-float-group-left' ) ;
20
+ } else if ( checkedCheckboxes === null && isFloating ) {
21
+ buttonGroup . classList . remove ( 'btn-float-group-left' ) ;
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Initialize floating bulk buttons.
27
+ */
28
+ export function initFloatBulk ( ) : void {
29
+ for ( const element of getElements < HTMLInputElement > ( 'input[type="checkbox"][name="pk"]' ) ) {
30
+ element . addEventListener ( 'change' , ( ) => {
31
+ toggleFloat ( ) ;
32
+ } ) ;
33
+ }
34
+ // Handle the select-all checkbox
35
+ for ( const element of getElements < HTMLInputElement > (
36
+ 'table tr th > input[type="checkbox"].toggle' ,
37
+ ) ) {
38
+ element . addEventListener ( 'change' , ( ) => {
39
+ toggleFloat ( ) ;
40
+ } ) ;
41
+ }
42
+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { initDepthToggle } from './depthToggle';
3
3
import { initMoveButtons } from './moveOptions' ;
4
4
import { initReslug } from './reslug' ;
5
5
import { initSelectAll } from './selectAll' ;
6
+ import { initFloatBulk } from './floatBulk' ;
6
7
import { initSelectMultiple } from './selectMultiple' ;
7
8
import { initMarkdownPreviews } from './markdownPreview' ;
8
9
import { initSecretToggle } from './secretToggle' ;
@@ -14,6 +15,7 @@ export function initButtons(): void {
14
15
initReslug ,
15
16
initSelectAll ,
16
17
initSelectMultiple ,
18
+ initFloatBulk ,
17
19
initMoveButtons ,
18
20
initMarkdownPreviews ,
19
21
initSecretToggle ,
Original file line number Diff line number Diff line change @@ -34,6 +34,28 @@ span.color-label {
34
34
letter-spacing : .15rem ;
35
35
}
36
36
37
+ // A floating div for form buttons
38
+ .btn-float-group {
39
+ position : sticky ;
40
+ bottom : 10px ;
41
+ z-index : 2 ;
42
+ }
43
+
44
+ .btn-float-group-left {
45
+ @extend .btn-float-group ;
46
+ float : left ;
47
+ }
48
+
49
+ .btn-float-group-right {
50
+ @extend .btn-float-group ;
51
+ float : right ;
52
+ }
53
+
54
+ // Override a transparent background
55
+ .btn-float {
56
+ --tblr-btn-bg : var (--#{$prefix}bg-surface-tertiary ) !important ;
57
+ }
58
+
37
59
.logo {
38
60
height : 80px ;
39
61
}
Original file line number Diff line number Diff line change @@ -102,8 +102,8 @@ <h2 class="col-9 offset-3">{% trans "Comments" %}</h2>
102
102
103
103
{% endif %}
104
104
105
- < div class ="text-end ">
106
- < a href ="{{ return_url }} " class ="btn btn-outline-secondary "> {% trans "Cancel" %}</ a >
105
+ < div class ="btn-float-group-right ">
106
+ < a href ="{{ return_url }} " class ="btn btn-outline-secondary btn-float "> {% trans "Cancel" %}</ a >
107
107
< button type ="submit " name ="_apply " class ="btn btn-primary "> {% trans "Apply" %}</ button >
108
108
</ div >
109
109
Original file line number Diff line number Diff line change 67
67
{% endblock form %}
68
68
</ div >
69
69
70
- < div class ="text-end my-3 ">
70
+ < div class ="btn-float-group-right ">
71
71
{% block buttons %}
72
- < a href ="{{ return_url }} " class ="btn btn-outline-secondary "> {% trans "Cancel" %}</ a >
72
+ < a href ="{{ return_url }} " class ="btn btn-outline-secondary btn-float "> {% trans "Cancel" %}</ a >
73
73
{% if object.pk %}
74
74
< button type ="submit " name ="_update " class ="btn btn-primary ">
75
75
{% trans "Save" %}
79
79
< button type ="submit " name ="_create " class ="btn btn-primary ">
80
80
{% trans "Create" %}
81
81
</ button >
82
- < button type ="submit " name ="_addanother " class ="btn btn-outline-primary ">
82
+ < button type ="submit " name ="_addanother " class ="btn btn-outline-primary btn-float ">
83
83
{% trans "Create & Add Another" %}
84
84
</ button >
85
85
</ div >
Original file line number Diff line number Diff line change 121
121
{# /Objects table #}
122
122
123
123
{# Form buttons #}
124
- < div class ="btn-list d-print-none mt-2 ">
124
+ < div class ="btn-list d-print-none ">
125
125
{% block bulk_buttons %}
126
126
< div class ="bulk-action-buttons ">
127
127
{% if 'bulk_edit' in actions %}
Original file line number Diff line number Diff line change 37
37
</ div >
38
38
{% endif %}
39
39
</ div >
40
- < div class =" card-footer text-end d-print-none border-0 " >
41
- < button type =" button " class ="btn btn-outline-danger m -1 " data-reset-select >
42
- < i class ="mdi mdi-backspace " > </ i > {% trans "Reset" %}
43
- </ button >
44
- < button type =" submit " class =" btn btn-primary m-1 " >
45
- < i class ="mdi mdi-magnify " > </ i > {% trans "Search" %}
46
- </ button >
47
- </ div >
40
+ </ div >
41
+ < div class ="btn-float-group-right me -1 ">
42
+ < button type =" button " class ="btn btn-outline-danger btn-float " data-reset-select >
43
+ < i class =" mdi mdi-backspace " > </ i > {% trans "Reset" %}
44
+ </ button >
45
+ < button type =" submit " class ="btn btn-primary " >
46
+ < i class =" mdi mdi-magnify " > </ i > {% trans "Search" %}
47
+ </ button >
48
48
</ div >
49
49
</ form >
You can’t perform that action at this time.
0 commit comments