1- /* global Behaviour, dialog, FormChecker, findElementsBySelector, findAncestor */
1+ /* global Behaviour, dialog, FormChecker, findElementsBySelector */
22
33function matrixAuthEscapeHtml ( html ) {
44 return html . replace ( / ' / g, "'" ) . replace ( / " / g, """ ) . replace ( / & / g, "&" ) . replace ( / < / g, "<" ) . replace ( / > / g, ">" ) ;
@@ -64,7 +64,7 @@ Behaviour.specify(".matrix-auth-add-button", "GlobalMatrixAuthorizationStrategy"
6464 }
6565 } ) ;
6666 table . appendChild ( copy ) ;
67- Behaviour . applySubtree ( findAncestor ( table , "TABLE" ) , true ) ;
67+ Behaviour . applySubtree ( table . closest ( "TABLE" ) , true ) ;
6868 } ,
6969 ( ) => { } ,
7070 ) ;
@@ -78,9 +78,9 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.remove"
7878 e . onclick = function ( ) {
7979 // Run ambiguity warning removal code: If all ambiguous rows are deleted, the warning needs to go as well
8080 // Order of operations: Find table ancestor, remove row, iterate over leftover rows
81- const table = findAncestor ( this , "TABLE" ) ;
81+ const table = this . closest ( "TABLE" ) ;
8282
83- const tr = findAncestor ( this , "TR" ) ;
83+ const tr = this . closest ( "TR" ) ;
8484 tr . parentNode . removeChild ( tr ) ;
8585
8686 const tableRows = table . getElementsByTagName ( "tr" ) ;
@@ -110,14 +110,14 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.remove"
110110 */
111111Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.selectall" , "GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
112112 e . onclick = function ( ) {
113- const tr = findAncestor ( this , "TR" ) ;
113+ const tr = this . closest ( "TR" ) ;
114114 const inputs = tr . getElementsByTagName ( "INPUT" ) ;
115115 for ( let i = 0 ; i < inputs . length ; i ++ ) {
116116 if ( inputs [ i ] . type === "checkbox" ) {
117117 inputs [ i ] . checked = true ;
118118 }
119119 }
120- Behaviour . applySubtree ( findAncestor ( this , "TABLE" ) , true ) ;
120+ Behaviour . applySubtree ( this . closest ( "TABLE" ) , true ) ;
121121 return false ;
122122 } ;
123123} ) ;
@@ -127,14 +127,14 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.selecta
127127 */
128128Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.unselectall" , "GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
129129 e . onclick = function ( ) {
130- const tr = findAncestor ( this , "TR" ) ;
130+ const tr = this . closest ( "TR" ) ;
131131 const inputs = tr . getElementsByTagName ( "INPUT" ) ;
132132 for ( let i = 0 ; i < inputs . length ; i ++ ) {
133133 if ( inputs [ i ] . type === "checkbox" ) {
134134 inputs [ i ] . checked = false ;
135135 }
136136 }
137- Behaviour . applySubtree ( findAncestor ( this , "TABLE" ) , true ) ;
137+ Behaviour . applySubtree ( this . closest ( "TABLE" ) , true ) ;
138138 return false ;
139139 } ;
140140} ) ;
@@ -144,15 +144,15 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.unselec
144144 */
145145Behaviour . specify ( ".global-matrix-authorization-strategy-table TD.stop A.migrate" , "GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
146146 e . onclick = function ( ) {
147- const tr = findAncestor ( this , "TR" ) ;
147+ const tr = this . closest ( "TR" ) ;
148148 const name = tr . getAttribute ( "name" ) ;
149149
150150 let newName = name . replace ( "[EITHER:" , "[USER:" ) ; // migrate_user behavior
151151 if ( this . classList . contains ( "migrate_group" ) ) {
152152 newName = name . replace ( "[EITHER:" , "[GROUP:" ) ;
153153 }
154154
155- const table = findAncestor ( this , "TABLE" ) ;
155+ const table = this . closest ( "TABLE" ) ;
156156 const tableRows = table . getElementsByTagName ( "tr" ) ;
157157 let newNameElement = null ;
158158 for ( let i = 0 ; i < tableRows . length ; i ++ ) {
@@ -171,7 +171,7 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
171171 tr . removeAttribute ( "data-checked" ) ;
172172
173173 // remove migration buttons from updated row
174- const buttonContainer = findAncestor ( this , "DIV" ) ;
174+ const buttonContainer = this . closest ( "DIV" ) ;
175175 const migrateButtons = buttonContainer . getElementsByClassName ( "migrate" ) ;
176176 for ( let i = migrateButtons . length - 1 ; i >= 0 ; i -- ) {
177177 buttonContainer . removeChild ( migrateButtons [ i ] ) ;
@@ -218,19 +218,19 @@ Behaviour.specify(".global-matrix-authorization-strategy-table TD.stop A.migrate
218218 * Whenever permission assignments change, this ensures that implied permissions get their checkboxes disabled.
219219 */
220220Behaviour . specify ( ".global-matrix-authorization-strategy-table td input" , "GlobalMatrixAuthorizationStrategy" , 0 , function ( e ) {
221- const table = findAncestor ( e , "TABLE" ) ;
221+ const table = e . closest ( "TABLE" ) ;
222222 if ( table . classList . contains ( "read-only" ) ) {
223223 // if this is a read-only UI (ExtendedRead / SystemRead), do not enable checkboxes
224224 return ;
225225 }
226226
227227 const tooltipAttributeName = "data-html-tooltip" ;
228228
229- const impliedByString = findAncestor ( e , "TD" ) . getAttribute ( "data-implied-by-list" ) ;
229+ const impliedByString = e . closest ( "TD" ) . getAttribute ( "data-implied-by-list" ) ;
230230 const impliedByList = impliedByString . split ( " " ) ;
231- const tr = findAncestor ( e , "TR" ) ;
231+ const tr = e . closest ( "TR" ) ;
232232 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" ) ) ;
234234 e . nextSibling . setAttribute ( tooltipAttributeName , tooltip ) ;
235235
236236 for ( let i = 0 ; i < impliedByList . length ; i ++ ) {
@@ -239,14 +239,14 @@ Behaviour.specify(".global-matrix-authorization-strategy-table td input", "Globa
239239 if ( reference !== null ) {
240240 if ( reference . checked ) {
241241 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" ) ) ;
243243 e . nextSibling . setAttribute ( tooltipAttributeName , tooltip ) ;
244244 }
245245 }
246246 }
247247
248248 e . onchange = function ( ) {
249- Behaviour . applySubtree ( findAncestor ( this , "TABLE" ) , true ) ;
249+ Behaviour . applySubtree ( this . closest ( "TABLE" ) , true ) ;
250250 return true ;
251251 } ;
252252} ) ;
0 commit comments