1
- /* global Behaviour, dialog, FormChecker, findElementsBySelector, findAncestor */
1
+ /* global Behaviour, dialog, FormChecker, findElementsBySelector */
2
2
3
3
function matrixAuthEscapeHtml ( html ) {
4
4
return html . replace ( / ' / g, "'" ) . replace ( / " / g, """ ) . replace ( / & / g, "&" ) . replace ( / < / g, "<" ) . replace ( / > / g, ">" ) ;
@@ -64,7 +64,7 @@ Behaviour.specify(".matrix-auth-add-button", "GlobalMatrixAuthorizationStrategy"
64
64
}
65
65
} ) ;
66
66
table . appendChild ( copy ) ;
67
- Behaviour . applySubtree ( findAncestor ( table , "TABLE" ) , true ) ;
67
+ Behaviour . applySubtree ( table . closest ( "TABLE" ) , true ) ;
68
68
} ,
69
69
( ) => { } ,
70
70
) ;
@@ -78,9 +78,9 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.remove"
78
78
e . onclick = function ( ) {
79
79
// Run ambiguity warning removal code: If all ambiguous rows are deleted, the warning needs to go as well
80
80
// Order of operations: Find table ancestor, remove row, iterate over leftover rows
81
- const table = findAncestor ( this , "TABLE" ) ;
81
+ const table = this . closest ( "TABLE" ) ;
82
82
83
- const tr = findAncestor ( this , "TR" ) ;
83
+ const tr = this . closest ( "TR" ) ;
84
84
tr . parentNode . removeChild ( tr ) ;
85
85
86
86
const tableRows = table . getElementsByTagName ( "tr" ) ;
@@ -110,14 +110,14 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.remove"
110
110
*/
111
111
Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.selectall" , "GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
112
112
e . onclick = function ( ) {
113
- const tr = findAncestor ( this , "TR" ) ;
113
+ const tr = this . closest ( "TR" ) ;
114
114
const inputs = tr . getElementsByTagName ( "INPUT" ) ;
115
115
for ( let i = 0 ; i < inputs . length ; i ++ ) {
116
116
if ( inputs [ i ] . type === "checkbox" ) {
117
117
inputs [ i ] . checked = true ;
118
118
}
119
119
}
120
- Behaviour . applySubtree ( findAncestor ( this , "TABLE" ) , true ) ;
120
+ Behaviour . applySubtree ( this . closest ( "TABLE" ) , true ) ;
121
121
return false ;
122
122
} ;
123
123
} ) ;
@@ -127,14 +127,14 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.selecta
127
127
*/
128
128
Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.unselectall" , "GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
129
129
e . onclick = function ( ) {
130
- const tr = findAncestor ( this , "TR" ) ;
130
+ const tr = this . closest ( "TR" ) ;
131
131
const inputs = tr . getElementsByTagName ( "INPUT" ) ;
132
132
for ( let i = 0 ; i < inputs . length ; i ++ ) {
133
133
if ( inputs [ i ] . type === "checkbox" ) {
134
134
inputs [ i ] . checked = false ;
135
135
}
136
136
}
137
- Behaviour . applySubtree ( findAncestor ( this , "TABLE" ) , true ) ;
137
+ Behaviour . applySubtree ( this . closest ( "TABLE" ) , true ) ;
138
138
return false ;
139
139
} ;
140
140
} ) ;
@@ -144,15 +144,15 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.unselec
144
144
*/
145
145
Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.migrate" , "GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
146
146
e . onclick = function ( ) {
147
- const tr = findAncestor ( this , "TR" ) ;
147
+ const tr = this . closest ( "TR" ) ;
148
148
const name = tr . getAttribute ( "name" ) ;
149
149
150
150
let newName = name . replace ( "[EITHER:" , "[USER:" ) ; // migrate_user behavior
151
151
if ( this . classList . contains ( "migrate_group" ) ) {
152
152
newName = name . replace ( "[EITHER:" , "[GROUP:" ) ;
153
153
}
154
154
155
- const table = findAncestor ( this , "TABLE" ) ;
155
+ const table = this . closest ( "TABLE" ) ;
156
156
const tableRows = table . getElementsByTagName ( "tr" ) ;
157
157
let newNameElement = null ;
158
158
for ( let i = 0 ; i < tableRows . length ; i ++ ) {
@@ -171,7 +171,7 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
171
171
tr . removeAttribute ( "data-checked" ) ;
172
172
173
173
// remove migration buttons from updated row
174
- const buttonContainer = findAncestor ( this , "DIV" ) ;
174
+ const buttonContainer = this . closest ( "DIV" ) ;
175
175
const migrateButtons = buttonContainer . getElementsByClassName ( "migrate" ) ;
176
176
for ( let i = migrateButtons . length - 1 ; i >= 0 ; i -- ) {
177
177
buttonContainer . removeChild ( migrateButtons [ i ] ) ;
@@ -218,19 +218,19 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
218
218
* Whenever permission assignments change, this ensures that implied permissions get their checkboxes disabled.
219
219
*/
220
220
Behaviour . specify ( ".global-matrix-authorization-strategy-table td input" , "GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
221
- const table = findAncestor ( e , "TABLE" ) ;
221
+ const table = e . closest ( "TABLE" ) ;
222
222
if ( table . classList . contains ( "read-only" ) ) {
223
223
// if this is a read-only UI (ExtendedRead / SystemRead), do not enable checkboxes
224
224
return ;
225
225
}
226
226
227
227
const tooltipAttributeName = "data-html-tooltip" ;
228
228
229
- const impliedByString = findAncestor ( e , "TD" ) . getAttribute ( "data-implied-by-list" ) ;
229
+ const impliedByString = e . closest ( "TD" ) . getAttribute ( "data-implied-by-list" ) ;
230
230
const impliedByList = impliedByString . split ( " " ) ;
231
- const tr = findAncestor ( e , "TR" ) ;
231
+ const tr = e . closest ( "TR" ) ;
232
232
e . disabled = false ;
233
- let tooltip = matrixAuthEscapeHtml ( findAncestor ( e , "TD" ) . getAttribute ( "data-tooltip-enabled" ) ) ;
233
+ let tooltip = matrixAuthEscapeHtml ( e . closest ( "TD" ) . getAttribute ( "data-tooltip-enabled" ) ) ;
234
234
e . nextSibling . setAttribute ( tooltipAttributeName , tooltip ) ;
235
235
236
236
for ( let i = 0 ; i < impliedByList . length ; i ++ ) {
@@ -239,14 +239,14 @@ Behaviour.specify(".global-matrix-authorization-strategy-table td input", "Globa
239
239
if ( reference !== null ) {
240
240
if ( reference . checked ) {
241
241
e . disabled = true ;
242
- let tooltip = matrixAuthEscapeHtml ( findAncestor ( e , "TD" ) . getAttribute ( "data-tooltip-disabled" ) ) ;
242
+ let tooltip = matrixAuthEscapeHtml ( e . closest ( "TD" ) . getAttribute ( "data-tooltip-disabled" ) ) ;
243
243
e . nextSibling . setAttribute ( tooltipAttributeName , tooltip ) ;
244
244
}
245
245
}
246
246
}
247
247
248
248
e . onchange = function ( ) {
249
- Behaviour . applySubtree ( findAncestor ( this , "TABLE" ) , true ) ;
249
+ Behaviour . applySubtree ( this . closest ( "TABLE" ) , true ) ;
250
250
return true ;
251
251
} ;
252
252
} ) ;
0 commit comments