@@ -228,17 +228,60 @@ document.addEventListener('alpine:init', () => {
228228 } ) ) ;
229229} ) ;
230230
231+ // Add new name server input
232+ const addNsButton = document . querySelector ( '.js-add-ns' ) ;
233+ if ( addNsButton ) {
234+ addNsButton . addEventListener ( 'click' , ( ) => {
235+ const currentNsInputs = document . querySelectorAll ( 'input[name^=v_ns]' ) ;
236+ const inputCount = currentNsInputs . length ;
237+
238+ if ( inputCount < 8 ) {
239+ const template = currentNsInputs [ 0 ] . parentElement . cloneNode ( true ) ;
240+ const templateNsInput = template . querySelector ( 'input' ) ;
241+
242+ templateNsInput . removeAttribute ( 'value' ) ;
243+ templateNsInput . name = `v_ns${ inputCount + 1 } ` ;
244+ addNsButton . insertAdjacentElement ( 'beforebegin' , template ) ;
245+ }
246+
247+ if ( inputCount === 7 ) {
248+ addNsButton . classList . add ( 'u-hidden' ) ;
249+ }
250+ } ) ;
251+ }
252+
253+ // Remove name server input
254+ document . querySelectorAll ( '.js-remove-ns' ) . forEach ( ( removeNsButton ) => {
255+ removeNsButton . addEventListener ( 'click' , ( ) => {
256+ removeNsButton . parentElement . remove ( ) ;
257+ const currentNsInputs = document . querySelectorAll ( 'input[name^=v_ns]' ) ;
258+ currentNsInputs . forEach ( ( input , index ) => ( input . name = `v_ns${ index + 1 } ` ) ) ;
259+ document . querySelector ( '.js-add-ns' ) . classList . remove ( 'u-hidden' ) ;
260+ } ) ;
261+ } ) ;
262+
231263// Intercept clicks on .js-confirm-action links and display dialog
232- document . addEventListener ( 'click' , ( evt ) => {
233- const triggerLink = evt . target . closest ( '.js-confirm-action' ) ;
234- if ( ! triggerLink ) {
235- return ;
236- }
237- evt . preventDefault ( ) ;
264+ document . querySelectorAll ( '.js-confirm-action' ) . forEach ( ( triggerLink ) => {
265+ triggerLink . addEventListener ( 'click' , ( evt ) => {
266+ evt . preventDefault ( ) ;
267+
268+ const title = triggerLink . dataset . confirmTitle ;
269+ const message = triggerLink . dataset . confirmMessage ;
270+ const targetUrl = triggerLink . getAttribute ( 'href' ) ;
238271
239- const title = triggerLink . getAttribute ( 'data-confirm-title' ) ;
240- const message = triggerLink . getAttribute ( 'data-confirm-message' ) ;
241- const targetUrl = triggerLink . getAttribute ( 'href' ) ;
272+ VE . helpers . createConfirmationDialog ( { title, message, targetUrl } ) ;
273+ } ) ;
274+ } ) ;
275+
276+ // Listen for changes to password inputs and update the password strength
277+ document . querySelectorAll ( '.js-password-input' ) . forEach ( ( passwordInput ) => {
278+ const updateTimeout = ( evt ) => {
279+ clearTimeout ( window . frp_usr_tmt ) ;
280+ window . frp_usr_tmt = setTimeout ( ( ) => {
281+ VE . helpers . recalculatePasswordStrength ( evt . target ) ;
282+ } , 100 ) ;
283+ } ;
242284
243- VE . helpers . createConfirmationDialog ( { title, message, targetUrl } ) ;
285+ passwordInput . addEventListener ( 'keypress' , updateTimeout ) ;
286+ passwordInput . addEventListener ( 'input' , updateTimeout ) ;
244287} ) ;
0 commit comments