11jQuery ( document ) . ready ( function ( $ ) {
2+ var __ = wp . i18n . __ ;
3+ var _e = wp . i18n . _e ;
4+ var sprintf = wp . i18n . sprintf ;
25 var saveBtn = jQuery ( "#disableCommentSaveSettings button.button.button__success" ) ;
36 var deleteBtn = jQuery ( "#deleteCommentSettings button.button.button__delete" ) ;
47
5-
68 if ( jQuery ( '.sites_list_wrapper' ) . length ) {
79 var addSite = function ( $sites_list , site , type ) {
810 var id = "sites__option__" + type + "__" + site . site_id ;
@@ -271,13 +273,14 @@ jQuery(document).ready(function ($) {
271273 type : "post" ,
272274 data : data ,
273275 beforeSend : function ( ) {
276+ var btnText = __ ( "Saving Settings.." , "disable-comments" ) ;
274277 saveBtn . html (
275- '<svg id="eael-spinner" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 48 48"><circle cx="24" cy="4" r="4" fill="#fff"/><circle cx="12.19" cy="7.86" r="3.7" fill="#fffbf2"/><circle cx="5.02" cy="17.68" r="3.4" fill="#fef7e4"/><circle cx="5.02" cy="30.32" r="3.1" fill="#fef3d7"/><circle cx="12.19" cy="40.14" r="2.8" fill="#feefc9"/><circle cx="24" cy="44" r="2.5" fill="#feebbc"/><circle cx="35.81" cy="40.14" r="2.2" fill="#fde7af"/><circle cx="42.98" cy="30.32" r="1.9" fill="#fde3a1"/><circle cx="42.98" cy="17.68" r="1.6" fill="#fddf94"/><circle cx="35.81" cy="7.86" r="1.3" fill="#fcdb86"/></svg><span>Saving Settings.. </span>'
278+ '<svg id="eael-spinner" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 48 48"><circle cx="24" cy="4" r="4" fill="#fff"/><circle cx="12.19" cy="7.86" r="3.7" fill="#fffbf2"/><circle cx="5.02" cy="17.68" r="3.4" fill="#fef7e4"/><circle cx="5.02" cy="30.32" r="3.1" fill="#fef3d7"/><circle cx="12.19" cy="40.14" r="2.8" fill="#feefc9"/><circle cx="24" cy="44" r="2.5" fill="#feebbc"/><circle cx="35.81" cy="40.14" r="2.2" fill="#fde7af"/><circle cx="42.98" cy="30.32" r="1.9" fill="#fde3a1"/><circle cx="42.98" cy="17.68" r="1.6" fill="#fddf94"/><circle cx="35.81" cy="7.86" r="1.3" fill="#fcdb86"/></svg><span>' + btnText + ' </span>'
276279 ) ;
277280 } ,
278281 success : function ( response ) {
279282 if ( response . success ) {
280- saveBtn . html ( "Save Settings" ) ;
283+ saveBtn . html ( __ ( "Save Settings" , "disable-comments" ) ) ;
281284 Swal . fire ( {
282285 icon : "success" ,
283286 title : response . data . message ,
@@ -291,8 +294,8 @@ jQuery(document).ready(function ($) {
291294 saveBtn . html ( "Save Settings" ) ;
292295 Swal . fire ( {
293296 type : "error" ,
294- title : "Oops..." ,
295- text : "Something went wrong!" ,
297+ title : __ ( "Oops..." , "disable-comments" ) ,
298+ text : __ ( "Something went wrong!" , "disable-comments" ) ,
296299 } ) ;
297300 } ,
298301 } ) ;
@@ -302,12 +305,12 @@ jQuery(document).ready(function ($) {
302305 var $form = jQuery ( this ) ;
303306 Swal . fire ( {
304307 icon : "error" ,
305- title : "Are you sure?" ,
306- text : "You won't be able to revert this!" ,
308+ title : __ ( "Are you sure?" , "disable-comments" ) ,
309+ text : __ ( "You won't be able to revert this!" , "disable-comments" ) ,
307310 showConfirmButton : true ,
308311 showCancelButton : true ,
309- confirmButtonText : 'Yes, Delete It' ,
310- cancelButtonText : 'No, Cancel' ,
312+ confirmButtonText : __ ( 'Yes, Delete It' , "disable-comments" ) ,
313+ cancelButtonText : __ ( 'No, Cancel' , "disable-comments" ) ,
311314 customClass : {
312315 confirmButton : 'confirmButton' ,
313316 cancelButton : 'cancelButton'
@@ -327,22 +330,22 @@ jQuery(document).ready(function ($) {
327330 data : $form . serialize ( ) ,
328331 } ;
329332 deleteBtn . html (
330- '<svg id="eael-spinner" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 48 48"><circle cx="24" cy="4" r="4" fill="#fff"/><circle cx="12.19" cy="7.86" r="3.7" fill="#fffbf2"/><circle cx="5.02" cy="17.68" r="3.4" fill="#fef7e4"/><circle cx="5.02" cy="30.32" r="3.1" fill="#fef3d7"/><circle cx="12.19" cy="40.14" r="2.8" fill="#feefc9"/><circle cx="24" cy="44" r="2.5" fill="#feebbc"/><circle cx="35.81" cy="40.14" r="2.2" fill="#fde7af"/><circle cx="42.98" cy="30.32" r="1.9" fill="#fde3a1"/><circle cx="42.98" cy="17.68" r="1.6" fill="#fddf94"/><circle cx="35.81" cy="7.86" r="1.3" fill="#fcdb86"/></svg><span>Deleting Comments..</span>'
333+ '<svg id="eael-spinner" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 48 48"><circle cx="24" cy="4" r="4" fill="#fff"/><circle cx="12.19" cy="7.86" r="3.7" fill="#fffbf2"/><circle cx="5.02" cy="17.68" r="3.4" fill="#fef7e4"/><circle cx="5.02" cy="30.32" r="3.1" fill="#fef3d7"/><circle cx="12.19" cy="40.14" r="2.8" fill="#feefc9"/><circle cx="24" cy="44" r="2.5" fill="#feebbc"/><circle cx="35.81" cy="40.14" r="2.2" fill="#fde7af"/><circle cx="42.98" cy="30.32" r="1.9" fill="#fde3a1"/><circle cx="42.98" cy="17.68" r="1.6" fill="#fddf94"/><circle cx="35.81" cy="7.86" r="1.3" fill="#fcdb86"/></svg><span>' + __ ( " Deleting Comments.." , "disable-comments" ) + ' </span>'
331334 ) ;
332335 jQuery . post ( ajaxurl , data , function ( response ) {
333- deleteBtn . html ( "Delete Comments" ) ;
336+ deleteBtn . html ( __ ( "Delete Comments" , "disable-comments" ) ) ;
334337 if ( response . success ) {
335338 Swal . fire ( {
336339 icon : "success" ,
337- title : "Deleted" ,
340+ title : __ ( "Deleted" , "disable-comments" ) ,
338341 html : response . data . message ,
339342 timer : 3000 ,
340343 showConfirmButton : false ,
341344 } ) ;
342345 } else {
343346 Swal . fire ( {
344347 icon : "error" ,
345- title : "Oops..." ,
348+ title : __ ( "Oops..." , "disable-comments" ) ,
346349 html : response . data . message ,
347350 showConfirmButton : true ,
348351 } ) ;
@@ -357,7 +360,7 @@ jQuery(document).ready(function ($) {
357360 saveBtn . addClass ( 'form-dirty' ) ;
358361 } ) ;
359362
360- jQuery ( document ) . ready ( function ( ) {
363+ ( function ( ) {
361364 var excludeByRoleWrapper = jQuery ( '#exclude_by_role_wrapper' ) ;
362365 if ( ! excludeByRoleWrapper . length ) return ;
363366 var excludeByRoleSelectWrapper = excludeByRoleWrapper . find ( '#exclude_by_role_select_wrapper' ) ;
@@ -368,35 +371,41 @@ jQuery(document).ready(function ($) {
368371 var includedRoles = excludeByRoleWrapper . find ( '.included-roles' ) ;
369372 var selectOnChange = function ( ) {
370373 var selectedOptions = excludeByRoleSelect . select2 ( 'data' ) ;
374+ console . log ( selectedOptions ) ;
371375 excludeByRoleSelectWrapper . show ( ) ;
372376 if ( selectedOptions . length ) {
373377 includedRoles . show ( ) ;
374378 excludedRoles . show ( ) ;
375- selectedOptions = selectedOptions . map ( function ( val , index ) {
376- return val . text ;
379+ var hasLoggedOutUsers = selectedOptions . find ( function ( val , index ) {
380+ return val . id == 'logged-out-users' ;
377381 } ) ;
378382 if ( options . length == selectedOptions . length ) {
379- excludedRoles . text ( "Comments are visible to everyone." ) ;
383+ excludedRoles . text ( __ ( "Comments are visible to everyone." , "disable-comments" ) ) ;
380384 includedRoles . hide ( ) ;
381385 }
382- else if ( selectedOptions . includes ( 'Logged out users' ) ) {
386+ else if ( hasLoggedOutUsers ) {
383387 if ( selectedOptions . length == 1 ) {
384- excludedRoles . text ( "Users who are logged out will see comments." ) ;
385- includedRoles . text ( "No comments will be visible to other roles." ) ;
388+ excludedRoles . text ( __ ( "Users who are logged out will see comments." , "disable-comments" ) ) ;
389+ includedRoles . text ( __ ( "No comments will be visible to other roles." , "disable-comments" ) ) ;
386390 }
387391 else {
388392 var _selectedOptions = selectedOptions . filter ( function ( val ) {
389- return val !== 'Logged out users' ;
390- } )
393+ return val . id !== 'logged-out-users' ;
394+ } ) . map ( function ( val , index ) {
395+ return val . id ;
396+ } ) ;
391397 var text = "<b>" + _selectedOptions . join ( "</b>, <b>" ) + "</b>" ;
392- excludedRoles . html ( "Comments are visible to " + text + " and <b>Logged out users</b>.") ;
393- includedRoles . text ( "No comments will be visible to other roles." ) ;
398+ excludedRoles . html ( sprintf ( __ ( "Comments are visible to %s and <b>Logged out users</b>." , "disable-comments" ) , text ) ) ;
399+ includedRoles . text ( __ ( "No comments will be visible to other roles." , "disable-comments" ) ) ;
394400 }
395401 }
396402 else {
397- var text = "<b>" + selectedOptions . join ( "</b>, <b>" ) + "</b>" ;
398- excludedRoles . html ( "Comments are visible to " + text + "." ) ;
399- includedRoles . text ( "Other roles and logged out users won't see any comments." ) ;
403+ var selectedOptionsLabels = selectedOptions . map ( function ( val , index ) {
404+ return val . text ;
405+ } ) ;
406+ var text = "<b>" + selectedOptionsLabels . join ( "</b>, <b>" ) + "</b>" ;
407+ excludedRoles . html ( sprintf ( __ ( "Comments are visible to %s." , "disable-comments" ) , text ) ) ;
408+ includedRoles . text ( __ ( "Other roles and logged out users won't see any comments." , "disable-comments" ) ) ;
400409 }
401410 }
402411 else {
@@ -407,7 +416,7 @@ jQuery(document).ready(function ($) {
407416 excludeByRoleSelect . select2 ( {
408417 multiple : true ,
409418 data : options ,
410- placeholder : "Select User Roles" ,
419+ placeholder : __ ( "Select User Roles" , "disable-comments" ) ,
411420 } ) ;
412421 excludeByRoleSelect . on ( 'change' , selectOnChange ) ;
413422 selectOnChange ( ) ;
@@ -420,6 +429,6 @@ jQuery(document).ready(function ($) {
420429 }
421430 } ) ;
422431 jQuery ( '#enable_exclude_by_role' ) . trigger ( 'change' ) ;
423- } ) ;
432+ } ) ( ) ;
424433
425434} ) ;
0 commit comments