(function (Drupal, $, once) {
  Drupal.behaviors.cdcnpin_global = {
    attach: function (context) {
      $(once('cdc-global', 'body', context))
        .each(function () {
					console.log("Loaded.");
          jQuery(document).ready(function ($) {
            setTimeout(function () {
              $(window).resize();
            }, 500);

            //*Back to top button*/
            $(window).scroll(function () {
              if ($(this).scrollTop() > 500) {
                $(".back-to-top").slideDown();
              } else {
                $(".back-to-top").slideUp();
              }
            });

            ///scroll effect
            $(".back-to-top").click(function (event) {
              event.preventDefault(); //keep the href from jumping to top
              $("html, body").animate(
                {
                  scrollTop: 0,
                },
                300
              );
            }); //click

            // Store the main menu bar.
            var menu_bar = $("#menu-bar");

            /**
             * Responsive specific JavaScript.
             */

            // Less than 1023px.
            if (matchMedia("only screen and (max-width: 1024px)").matches) {
              // Organization services.
              adjust_organization_services();

              adjust_mobile_links();
            }

            if (matchMedia("only screen and (max-width:979px)").matches) {
              // Adjust elements.
              adjust_elements();

              // Move menu.
              move_menu();
            }

            // Tablet portrait on Load.
            //if ((matchMedia('only screen and (min-width:481px) and (max-width:768px)').matches) || (matchMedia("(orientation:portrait)").matches)) {
            if (
              matchMedia(
                "only screen and (min-width:481px) and (max-width:768px)"
              ).matches
            ) {
              // Adjust elements.
              adjust_elements();
              // Move menu.
              move_menu();
            }

            // Tablet on resize.
            $(window).resize(function () {
              if ($(window).width() > 979) {
                $("div.nav-collapse.always-show").css("width", "auto");
              }
              // Mobile portrait.
              if ($(".responsive-object").css("font-size") == "9px") {
                // Debug.
                console.log("smartphone landscape");

                // Adjust elements.
                adjust_elements();
              }
              // Tablet portrait.
              else if ($(".responsive-object").css("font-size") == "10px") {
                // Debug.
                console.log("tablet portrait");

                // Get the menu bar.
                menu_bar = $("#menu-bar");

                // Adjust elements.
                adjust_elements();

                // Move menu.
                move_menu();
              }
              // Tablet landscape.
              else if ($(".responsive-object").css("font-size") == "11px") {
                // Debug.
                console.log("tablet landscape");

                // Get the menu bar.
                menu_bar = $("#menu-bar");

                // Adjust elements.
                adjust_elements();

                // Move menu.
                move_menu();

                adjust_mobile_links();
                // Adjust the utility section and move main menu and move it to the utility menu section.
                /*
					$('.nav-collapse.collapse.always-show').removeAttr('style');
					$('#utility #menu-bar .search-form-mobile').remove();
					$('#utility p').find('div').contents().unwrap().end();
					$('#menu-bar').detach().appendTo('.header-color-row-two .container');
					*/
              }

              // Desktop
              else if ($(".responsive-object").css("font-size") == "12px") {
                // Adjust elements.
                adjust_elements();

                // Adjust the utility section and move main menu and move it to the utility menu section.
                $(".nav-collapse.collapse.always-show").removeAttr("style");
                $("#utility #menu-bar .search-form-mobile").remove();
                $("#utility p").find("div").contents().unwrap().end();
                $("#menu-bar")
                  .detach()
                  .appendTo(".header-color-row-two .container");
              }
            });

            // Smalltouch general
            if (matchMedia("only screen and (max-width:480px)").matches) {
              // Adjust elements.
              adjust_elements();

              // Move menu.
              move_menu();

              // Add a facet filter.
              facet_filter();
            }

            /**
             * Polishing.
             */

            /* Re-calling menu button script for Org pages with map issue*/
            $(".node-type-organization .tb-megamenu-button").click(function () {
              if (
                parseInt($(this).parent().children(".nav-collapse").height())
              ) {
                $(this).parent().children(".nav-collapse").css({
                  height: 0,
                  overflow: "hidden",
                });
              } else {
                $(this).parent().children(".nav-collapse").css({
                  height: "auto",
                  overflow: "visible",
                });
              }
            });

            // Create navigation sub menu columns
            $(
              "#menu-bar.nav .tb-megamenu li.tb-megamenu-item .tb-megamenu-row"
            ).each(function () {
              var $this = $(this);

              if ($this.children(".tb-megamenu-column").length > 1) {
                $this
                  .children(".tb-megamenu-column:nth-child(1)")
                  .find("ul.menu li.leaf:gt(5)")
                  .remove();
                $this
                  .children(".tb-megamenu-column:nth-child(2)")
                  .find("ul.menu li.leaf:lt(6)")
                  .remove();
              }
            });

            // Supress user profile link for unauthenticated users.
            jQuery('.not-logged-in .message a[href*="/users/"]')
              .contents()
              .unwrap();

            // Hide all empty fields.
            //$('.page-node .field-items .field-item:empty').closest('section').hide();
            //$('.page-node div.field-items:empty').closest('section').hide();
            $(".page-node #main-content:empty").closest("section").hide();

            $(".page-node div.field a:empty").closest("div.field").hide();
            $(".block-title:empty").remove();
            //$('label.element-invisible').remove();
            $("h2.element-invisible").remove();
            $("h1.element-invisible").remove();

            // Fix SERP highlighting.
            $(".page-search .pane-apachesolr-result h3")
              .find("span")
              .contents()
              .unwrap()
              .end();
            // Fix Organization SERP pages.
            $(".page-search-organization .organization-services span")
              .find("span")
              .contents()
              .unwrap()
              .end();
            $("input#edit-search-block-form--3").val(
              $("input#edit-apachesolr-panels-search-form--2").val()
            );
            // Adds alt text to big search button.
            $("#edit-submit").attr("alt", "Search Button");
            // Removes reset filter help text that is visible when css is disabled.
            $(".current-search-item-active").find("span").remove();
            // Add title to external link icon and wrapped it with anchor tag. Link can be defined here.
            var extlinkurl =
              '<a href="/pages/policies-and-disclaimers#links" class="ext-link"></a>';
            $("span.ext")
              .attr("title", "External Web Site Policy")
              .wrap(extlinkurl);

            //NPIN COMMUNITY FIXES

            $(
              ".not-logged-in .cdcnpin-group-list .views-field-title"
            ).wrapInner("<h2></h2>");

            $(
              '.page-node-add #edit-field-document-file label:contains("Add a new file")'
            ).attr("for", "edit-field-document-file-und-0-upload");
            $(
              '<label class="element-invisible" for="edit-field-document-file-und-0-upload-button">Upload</label>'
            ).insertBefore(
              $(
                ".page-node-add #edit-field-document-file #edit-field-document-file-und-0-upload-button"
              )
            );
            $(
              '.page-node-add #external-bookmark-node-form label:contains("External URL")'
            ).replaceWith(
              '<p class="label-replacement">External URL <span title="This field is required." class="form-required">*</span></p>'
            );

            //Filter select drop downs Limit To and Sort By
            var follownum = 0;
            var sortnum = 0;

            $("#edit-following-wrapper label").each(function () {
              $(this).attr("for", "edit-following" + follownum);
              $(this)
                .next()
                .find("#edit-following")
                .attr("id", "edit-following" + follownum);
              follownum++;
            });

            $(".form-item-sort-by label").each(function () {
              $(this).attr("for", "edit-sort-by" + sortnum);
              $(this)
                .next()
                .find("#edit-sort-by")
                .attr("id", "edit-sort-by" + sortnum);
              sortnum++;
            });

            //Missing checkbox and input labels

            $(".facetapi-facetapi-checkbox-links input:checkbox").each(
              function () {
                var checkbxid = $(this).attr("id");
                var checkbxtext = $(this)
                  .next("a")
                  .find("span.element-invisible")
                  .text();
                if (!$(this).prev().is("label")) {
                  $('<label class="element-invisible"></label>').insertBefore(
                    $(this)
                  );
                  $(this).prev("label").attr("for", checkbxid);
                  $(this).prev("label").append(checkbxtext);
                }
              }
            );

            //Messages table
            var idnum = 0;
            $("#privatemsg-list th.select-all input:checkbox").each(
              function () {
                $(this).attr("id", "select-list-all" + idnum++);
              }
            );

            $("#privatemsg-list input:checkbox").each(function () {
              var inputid = $(this).attr("id");
              if (!$(this).prev().is("label")) {
                $('<label class="element-invisible"></label>').insertBefore(
                  $(this)
                );
                $(this).prev("label").attr("for", inputid);
                $(this).prev("label").append("Select message");
              }
            });

            $("#privatemsg-list select").each(function () {
              var selectid = $(this).attr("id");
              if (!$(this).prev().is("label")) {
                $('<label class="element-invisible"></label>').insertBefore(
                  $(this)
                );
                $(this).prev("label").attr("for", selectid);
                $(this).prev("label").append("Actions...");
              }
            });

            // Orphan form labels changed to paragraph tags
            $(
              '#edit-profile-user-profile-form label:contains("Expertise")'
            ).replaceWith(
              '<p class="label-replacement">Expertise/Skills <span title="This field is required." class="form-required">*</span></p>'
            );
            $(
              '#edit-profile-user-profile-form label:contains("Experience with the Following Populations")'
            ).replaceWith(
              '<p class="label-replacement">Experience with the Following Populations <span title="This field is required." class="form-required">*</span></p>'
            );
            $(
              '#edit-profile-user-profile-form label:contains("Experience in the Following Settings")'
            ).replaceWith(
              '<p class="label-replacement">Experience in the Following Settings  <span title="This field is required." class="form-required">*</span></p>'
            );
            $('#user-profile-form label:contains("Status ")').replaceWith(
              '<p class="label-replacement">Status</p>'
            );
            $('#user-profile-form label:contains("Roles ")').replaceWith(
              '<p class="label-replacement">Roles</p>'
            );
            $(
              '#user-profile-form label:contains("Or simply select an icon")'
            ).replaceWith(
              '<p class="label-replacement">Or simply select an icon </p>'
            );
            $('#user-register-form label:contains("Expertise")').replaceWith(
              '<p class="label-replacement">Expertise/Skills <span title="This field is required." class="form-required">*</span></p>'
            );
            $(
              '#user-register-form label:contains("Experience with the Following Populations")'
            ).replaceWith(
              '<p class="label-replacement">Experience with the Following Populations <span title="This field is required." class="form-required">*</span></p>'
            );
            $(
              '#user-register-form label:contains("Experience in the Following Settings")'
            ).replaceWith(
              '<p class="label-replacement">Experience in the Following Settings  <span title="This field is required." class="form-required">*</span></p>'
            );
            $(
              '#user-register-form label:contains("Select an avatar ")'
            ).replaceWith(
              '<p class="label-replacement">Select an avatar <span title="This field is required." class="form-required">*</span> </p>'
            );
            //$('.views-exposed-form label:contains("Sort by ")').replaceWith('<span>Sort by </span>');
            //$('.views-exposed-form label:contains("Limited to ")').replaceWith('<span>Limited to </span>');
            $('.poll label.element-invisible:contains("Choices")').remove();

            //Profile
            $("#edit-profile-user-profile-form").each(function () {
              $(this)
                .find("#field-twitter-url-add-more-wrapper label")
                .attr("for", "edit-field-twitter-url-und-0-url--2");
              $(this)
                .find("#field-linkedin-url-add-more-wrapper label")
                .attr("for", "edit-field-linkedin-url-und-0-url--2");
              $(this)
                .find("#field-facebook-url-add-more-wrapper label")
                .attr("for", "edit-field-facebook-url-und-0-url--2");
              $(this)
                .find('label:contains("Other groups")')
                .attr("for", "edit-og-user-node-und-0-admin-0-target-id--2");
              $(this).find("label.element-invisible").remove();
            });

            // Notification Settings
            var noteidnum = 0;
            $(
              "#commons-follow-ui-notification-settings-form input:checkbox"
            ).each(function () {
              $(this).attr("id", "send-email-check" + noteidnum++);
            });
            $(
              "#commons-follow-ui-notification-settings-form input:checkbox"
            ).each(function () {
              var inputid = $(this).attr("id");
              if (!$(this).prev().is("label")) {
                $('<label class="element-invisible"></label>').insertBefore(
                  $(this)
                );
                $(this).prev("label").attr("for", inputid);
                $(this).prev("label").append("Check to send email");
              }
            });
            $(
              '#commons-follow-ui-notification-settings-form label:contains("Send email notifications by default")'
            ).replaceWith(
              '<span class="label-replacement">Send email notifications by default.</span>'
            );

            //Feed icon alt text
            if(!$(".feed-icon").attr("title")){
              $(".feed-icon").attr("title", "Subscribe to all groups");
              $(".feed-icon img").attr("alt", "Subscribe to all groups");
            }

            //Contributors alt text
            //alert($(this).attr('title'));
            var t = $(this).attr("title");
            $(".view-commons-contributors-group img").each(function () {
              if ($(this).next().is("span")) {
                var contributorname = $(this).next("span").html();
                $(this).attr("alt", "View " + contributorname + "'s Profile");
              } else {
                //$(this).attr('alt', 'View ' + ($(this).attr('title').replace('picture', '')) +' Profile');
                $(this).attr(
                  "alt",
                  "View " + t.replace("picture", "") + " Profile"
                );
              }
            });

            // Community default logo
            if (
              $(
                ".node-type-group #node_group_full_group_header .field-name-field-group-logo"
              ).length == 0
            ) {
              var group_name = $("#page-title").html();
              var group_logo_replacement =
                '<div class="field field-name-field-group-logo field-type-image field-label-hidden view-mode-full"><h1>' +
                group_name +
                "</h1></div>";
              var group_description_height =
                $(".node-type-group .field-type-text-with-summary p").height() -
                10;
              $(
                ".node-type-group #node_group_full_group_header .field-type-text-with-summary"
              ).before(group_logo_replacement);
              $(
                ".node-type-group #node_group_full_group_header .field-name-field-group-logo"
              )
                .css("height", group_description_height)
                .css("display", "table");
              $(
                ".node-type-group #node_group_full_group_header .field-name-field-group-logo h1"
              )
                .css("display", "table-cell")
                .css("vertical-align", "middle");
            }

            // Add an ID to the comment form block.
            $(".pane-node-comment-form.block").attr("id", "comment-form");

            if ($('#comment-form label:contains("Your name")').next().is("a")) {
              $('#comment-form label:contains("Your name")').replaceWith(
                "<p class='label-replacement'>Your Name</p>"
              );
            }

            // Start a conversation node add pages.
            $("#edit-topics-wrapper--3").removeClass("collapsed");
            // Member search facet
            $(
              ".pane-facetapi-agtgryafivlwfkl4rsmngfggc0xh4ron .facetapi-facetapi-checkbox-links li.leaf:gt(4)"
            ).css("display", "none");
            $(
              ".pane-facetapi-8gxvprwidzjengioul30qmdwtkhuorvp .facetapi-facetapi-checkbox-links li.leaf:gt(4)"
            ).css("display", "none");
            // $('.region.region-three-25-50-25-second').css('width', '75%');
            // $('.region.region-three-25-50-25-third').hide();
            $(".user-picture").css("width", "50px").css("height", "50px");

            $(".page-node-add .ckeditor_links").hide();
            $(".page-node-add .field-edit-link").hide();
            $(".page-node-edit .ckeditor_links").hide();
            $(".page-node-edit .field-edit-link").hide();

            //SERP PAGES
            //SEARCH 508 FIXES
            $('#search-block-form input[type="submit"]').each(function () {
              var submitid = $(this).attr("id");
              if (!$(this).prev().is("label")) {
                $('<label class="element-invisible"></label>').insertBefore(
                  $(this)
                );
                $(this).prev("label").attr("for", submitid);
                $(this).prev("label").append("Search");
              } else {
                $(this).prev("label").attr("for", submitid);
              }
            });

            //custom date form funding
            $("#cdcnpin-funding-solr-date-range-form input:text").each(
              function () {
                var dateinputid = $(this).attr("id");
                if ($(this).parent().parent().prev().is("label")) {
                  $(this)
                    .parent()
                    .parent()
                    .prev("label")
                    .attr("for", dateinputid);
                }
              }
            );

            //custom date form news
            $("#cdcnpin-news-solr-date-range-form input:text").each(
              function () {
                var dateinputid = $(this).attr("id");
                if ($(this).parent().parent().prev().is("label")) {
                  $(this)
                    .parent()
                    .parent()
                    .prev("label")
                    .attr("for", dateinputid);
                }
              }
            );

            $(
              "#cdcnpin-funding-solr-date-range-form label.element-invisible"
            ).remove();
            $(
              "#cdcnpin-news-solr-date-range-form label.element-invisible"
            ).remove();

            $(".page-search-organization span.label").wrap("<h2></h2>");

            $(".page-node .label-above").wrapInner("<h2></h2>");
            $(".pane-node-content .fieldset-legend").wrapInner("<h2></h2>");

            // Make slider pager keyboard accessible
            var slidePagerLink = $(
              ".pane-bundle-cdcnpin-slideshow-fpp .flex-control-paging li a"
            );
            $(slidePagerLink).attr("href", "#");
            $(slidePagerLink).click(function (event) {
              event.preventDefault();
            }); //click
            $(slidePagerLink)
              .focus(function () {
                // $(this).addClass('pager-hover');
                $(this).css("border", "2px solid #2f7545");
              })
              .blur(function () {
                //$(this).removeClass('pager-hover');
                $(this).css("border", "0px");
              });

            // Add "Did You Know Slide" to DYK slide links for when css is disabled*/
            $(slidePagerLink).each(function () {
              if (!$(this).hasClass("slidePage")) {
                //prevent any looping from ajax
                $(this).prepend("Featured Slide ");
              }
              $(this).addClass("slidePage");
            });

            // Remove hidden headings from home page{
            $(
              ".pane-fieldable-panels-pane .flexslider h2.element-invisible"
            ).remove();

            // Make AddThis Pinterest button accessible
            $(".addthis_button_pinterest_pinit").attr({
              href: "#",
              title: "Pin It",
            });

            /**
             * Featured Partner
             */
            // Banner Alt Text
            $(".node-featured-partner img").each(function () {
              if ($(this).attr("src").indexOf("banner") > -1) {
                $(this).attr("alt", "Featured Partner Banner");
              }
            });

            //Overview Heading
            $(
              ".field-name-featured-partner-overview-title .field-items .field-item"
            ).wrapInner("<h2></h2>");

            //Program Highlight Heading
            //$('.node-featured-partner .label-above').wrapInner( "<h2></h2>");

            /**
             * Adjust menu and hero text.
             */
            function adjust_elements() {
              // Set the width of the tb menu to match the width of the window.
              var window_width = $(window).width();
              $("#block-tb-megamenu-main-menu .nav-collapse.collapse")
                .width(window_width)
                .css("left", -1 * (window_width - 41))
                .css("top", "35px");

              // // Get the height of the hero image to match the height of the blue cover
              // // minus the 30px padding and 35% of the width.
              // var img_height = $('.flexslider .slides img').height();
              // var img_width = $('.flexslider .slides img').width();

              // // Set the cooresponding size to the base background.
              // $('.pane-fieldable-panels-pane .flexslider .fieldset-outer-wrapper').height(img_height - 30).width(img_width * .35);
            }

            /**
             * Move menus.
             */
            function move_menu() {
              // Grab the main menu and move it to the utility menu section.
              $("#menu-bar").detach().appendTo("#utility");

              // First, remove the search form mobile.
              $(
                "#menu-bar.nav ul.tb-megamenu-nav .search-form-mobile"
              ).remove();

              // Move the search.
              var _search_form = $("#block-search-form").html();
              $("#menu-bar.nav ul.tb-megamenu-nav").prepend(
                '<li class="tb-megamenu-item level-1 mega mega-align-left search-form-mobile">' +
                  _search_form +
                  "</li>"
              );

              // Add the Utility Navigation to the main menu.
              var _utility_menu_links = $("#utility p").find("a");
              if (
                !$("#menu-bar.nav ul.tb-megamenu-nav li:last-child").hasClass(
                  "utility"
                )
              ) {
                $.each(_utility_menu_links, function (i, val) {
                  _utility_menu_element = $(val).wrap("<div>").parent().html();
                  $("#menu-bar.nav ul.tb-megamenu-nav").append(
                    '<li class="tb-megamenu-item level-1 mega mega-align-left utility">' +
                      _utility_menu_element +
                      "</li>"
                  );
                });
              }
            }

            /**
             * Enable a toggle facet filter for mobile screens.
             */
            function facet_filter() {
              // Create a toggle button.
              $(".page-search .first-column .filter-toggle").prepend(
                '<div class="filter-results"><a>Filter result ▼</a></div>'
              );

              // Add a collapsible element for the facets.
              $(
                ".page-search .first-column .filter-toggle .region-inner .pane-block"
              ).hide();

              $(
                ".page-search .first-column .filter-toggle .filter-results a"
              ).live("click", function () {
                $(
                  ".page-search .first-column .filter-toggle .region-inner .pane-block"
                ).toggle();
              });
            }

            /**
             * Update organization services.
             */
            function adjust_organization_services() {
              $(".menu-name-menu-service-tabs ul.menu").each(function () {
                var list = $(this),
                  select = $(document.createElement("select")).insertBefore(
                    $(this).hide()
                  );
                $(">li a", this).each(function () {
                  var target = $(this).attr("target"),
                    option = $(document.createElement("option"))
                      .appendTo(select)
                      .val(this.href)
                      .html($(this).html());
                  if (window.location.href == this.href)
                    $(select).val(this.href);
                });

                list.remove();
                select.change(function () {
                  window.location.href = $(this).val();
                });
              });
            }

            //check if modal exists on page
            if ($("#cdc-modal").length) {
              //disable chrome autocomplete from changing password field after modal appears
              $("#edit-pass").attr({ autocomplete: "new-password" });

              var xBtn = document.createElement("span");
              $(xBtn)
                .attr({
                  style:
                    "float:right; color:rgba(50, 50, 50,.7); cursor: pointer;",
                })
                .html("<span>✖</span>")
                .on("click", function () {
                  $("#cdc-modal").css("display", "none");
                });
              var buttonsDiv = document.createElement("div");
              $(buttonsDiv).attr({
                id: "buttonsDiv",
              });

              //create sign in button in modal
              var modalBtn = document.createElement("input");
              $(modalBtn)
                .attr({
                  //not a type="submit" because it doesn't always work on IE, and submit() is below
                  type: "button",
                  id: "accept",
                  form: "user-login-form",
                  value: "I accept",
                  class: "form-submit close",
                  alt: "Sign in button",
                  style: "background-color:#28a745; border-color: #28a745",
                })
                .on("click", function () {
                  $("#cdc-modal").css("display", "none");
                  $("#user-login-form").submit();
                });

              var modalCloseBtn = document.createElement("input");
              $(modalCloseBtn)
                .attr({
                  type: "button",
                  id: "reject",
                  value: "I do not accept",
                  class: "form-submit close",
                  alt: "Close modal button",
                  style:
                    "margin-left:30px; background-color:#dc3545; border-color: #dc3545;",
                })
                .on("click", function () {
                  $("#cdc-modal").css("display", "none");
                });

              var acceptIcon = document.createElement("i");
              $(acceptIcon)
                .attr({ class: "fa fa-check-circle", style: "cursor: pointer" })
                .on("click", function () {
                  $("#cdc-modal").css("display", "none");
                  $("#user-login-form").submit();
                });

              var rejectIcon = document.createElement("i");
              $(rejectIcon)
                .attr({ class: "fa fa-times-circle", style: "cursor: pointer" })
                .on("click", function () {
                  $("#cdc-modal").css("display", "none");
                });

              //add to modal
              $("#cdc-warning-banner").prepend(xBtn);
              $("#cdc-warning-banner").append(buttonsDiv);
              $("#buttonsDiv").append(modalBtn, modalCloseBtn);
              $(acceptIcon).insertAfter("#accept");
              $(rejectIcon).insertAfter("#reject");

              //hide modal without submitting form if clicked outside
              $(window).on("click", function (event) {
                if ($(event.target).is($("#cdc-modal"))) {
                  $("#cdc-modal").css("display", "none");
                }
              });

              //prevent user hitting enter until both fields are filled
              $("#user-login-form").keydown(function (event) {
                if (event.keyCode == 13) {
                  event.preventDefault();
                  if (
                    $("#edit-name").val() == "" ||
                    $("#edit-pass").val() == ""
                  ) {
                    return;
                  } else {
                    $("#edit-submit").click();
                  }
                }
              });
            }
            if ($(".page-dashboard-my-groups")) {
              for (
                var i = 0;
                i < $("div.group-accordion").children().length;
                i++
              ) {
                $("div.group-accordion .accordion-row")
                  .attr("tabindex", 0)
                  .keydown(function (e) {
                    if (e.which === 13) {
                      $(this).find("h2").click();
                    }
                  });
              }
            }

            //deactivate current sign in button
            $("#user-login-form input.form-submit")
              .prop("type", "button")
              .on("click", function () {
                $("#cdc-modal").css("display", "block");
                $(modalBtn).focus();
              });

            /**Prevent double tapping on mobile devices.
             * Called only in mobile sizes
             * Prevent external links opening in current window
             * Ignore back to top link
             */

            function adjust_mobile_links() {
              $("a").on("click touchend", function (e) {
                if (
                  !$(this).is(".back-to-top") &&
                  !$(this).is(".facetapi-limit-link")
                ) {
                  e.preventDefault();
                  var el = $(this);
                  var link = el.attr("href");
                  if (!el.is(".ext")) {
                    window.location = link;
                  } else if (el.is(".ext")) {
                    window.open(link);
                  }
                }
              });
            }
          });
        });
    },
  };
})(Drupal, jQuery, once);