@@ -235,6 +235,7 @@ mod_document_code_server <- function(id, glob) {
235235 glob $ doc_selector <- input $ doc_selector
236236 loc $ codes_menu_observer <- loc $ codes_menu_observer + 1 # must run first
237237 loc $ text_observer <- loc $ text_observer + 1
238+ removeUI(" #code_extra_div" ) # remove code extra div so values can recalculate
238239 })
239240
240241 # # Observe refresh ----
@@ -460,6 +461,8 @@ mod_document_code_server <- function(id, glob) {
460461 observeEvent(input $ quickcode , {
461462 if (isTruthy(input $ quickcode )) {
462463 removeUI(" #code_extra_div" )
464+ # Backlight reset
465+ loc $ backlight_code_id <- NULL
463466 non_matched_codes <- loc $ codebook %> %
464467 dplyr :: filter(
465468 ! stringr :: str_detect(code_name , paste0(" (?i)" , input $ quickcode ))
@@ -522,11 +525,15 @@ mod_document_code_server <- function(id, glob) {
522525 observeEvent(req(input $ selected_code_extra ), {
523526 req(glob $ doc_selector )
524527 removeUI(" #code_extra_div" )
525- sel <- paste0(" #" , ns(paste0(" more-" , input $ selected_code_extra )))
526- generate_code_extra_LF(sel )
528+ loc $ code_extra_sel <- paste0(
529+ " #" ,
530+ ns(paste0(" more-" , input $ selected_code_extra ))
531+ )
532+ generate_code_extra_LF()
527533 })
528534 observeEvent(req(input $ close_code_extra_div ), {
529535 removeUI(" #code_extra_div" )
536+ loc $ backlight_code_id <- NULL
530537 })
531538
532539 # Segment removal ----------
@@ -637,6 +644,70 @@ mod_document_code_server <- function(id, glob) {
637644 as.character(reported_range )
638645 })
639646
647+ # Backlight ------
648+ observeEvent(
649+ c(
650+ input $ code_extra_backlight ,
651+ glob $ segments_observer
652+ ),
653+ {
654+ if (button_is_on(req(input $ code_extra_backlight ))) {
655+ if (! isTruthy(loc $ backlight_code_id )) {
656+ loc $ backlight_observer <- 1
657+ } else {
658+ loc $ backlight_observer <- loc $ backlight_observer + 1
659+ }
660+ loc $ backlight_code_id <- paste0(" code_id_" , input $ js_backlight_value )
661+ } else {
662+ loc $ backlight_code_id <- NULL
663+ }
664+ }
665+ )
666+
667+ observeEvent(c(loc $ backlight_observer , loc $ backlight_code_id ), {
668+ if (isTruthy(loc $ backlight_code_id )) {
669+ # Add frontlight class to all docpar elements
670+ shinyjs :: addClass(
671+ class = " code_extra_frontlight" ,
672+ selector = " .docpar"
673+ )
674+
675+ # Add frontlight class to all code elements except the targeted one
676+ shinyjs :: addClass(
677+ class = " code_extra_frontlight" ,
678+ selector = paste0(" .code:not(." , loc $ backlight_code_id , " )" )
679+ )
680+
681+ # Remove backlight class from all non-targeted code elements
682+ shinyjs :: removeClass(
683+ class = " code_extra_backlight" ,
684+ selector = paste0(" .code:not(." , loc $ backlight_code_id , " )" )
685+ )
686+
687+ # Add backlight class to the targeted code element
688+ shinyjs :: addClass(
689+ class = " code_extra_backlight" ,
690+ selector = paste0(" ." , loc $ backlight_code_id )
691+ )
692+ } else {
693+ # Remove backlight class from all code elements
694+ shinyjs :: removeClass(
695+ class = " code_extra_backlight" ,
696+ selector = " .code"
697+ )
698+ # Remove frontlight class from all code elements
699+ shinyjs :: removeClass(
700+ class = " code_extra_frontlight" ,
701+ selector = " .code"
702+ )
703+ # Remove frontlight class from all docpar elements
704+ shinyjs :: removeClass(
705+ class = " code_extra_frontlight" ,
706+ selector = " .docpar"
707+ )
708+ }
709+ })
710+
640711 # Local functions -------------------
641712 # # toggle_style_LF -------------------
642713
@@ -758,7 +829,7 @@ mod_document_code_server <- function(id, glob) {
758829 }
759830
760831 # # generate_code_extra_LF -------------------
761- generate_code_extra_LF <- function (sel ) {
832+ generate_code_extra_LF <- function () {
762833 doc_group <- NULL
763834 selected_code_extra <- as.integer(input $ selected_code_extra )
764835 active_project <- as.integer(glob $ active_project )
@@ -776,7 +847,7 @@ mod_document_code_server <- function(id, glob) {
776847 total_freq = dplyr :: n()
777848 )
778849 insertUI(
779- selector = sel ,
850+ selector = loc $ code_extra_sel ,
780851 where = " afterEnd" ,
781852 ui = tags $ div(
782853 id = " code_extra_div" ,
@@ -798,7 +869,19 @@ mod_document_code_server <- function(id, glob) {
798869 br(),
799870 " Total frequency:" ,
800871 tags $ b(segments_count $ total_freq ),
801- br()
872+ br(),
873+ actionButton(
874+ ns(" code_extra_backlight" ),
875+ label = NULL ,
876+ icon = icon(" glasses" ),
877+ `data-code_id` = selected_code_extra ,
878+ onclick = paste0(
879+ " Shiny.setInputValue('" ,
880+ ns(" js_backlight_value" ),
881+ " ', this.getAttribute('data-code_id'), {priority: 'event'});"
882+ )
883+ ) %> %
884+ tagAppendAttributes(class = " code_extra_btn" )
802885 )
803886 )
804887 }
0 commit comments