PageSourceSearch

https://www.stanleyworks.pl/modules/custom/sbd_language_switch/js/language-switch.js?tm46jx

js stanleyworks.pl collected 2026-09-30 09:26:25 UTC 11,045 bytes, 223 lines download raw bytes

1/**
2 * @file
3 * Attaches language switcher if there is English only.
4 */
5
6 (function ($, Drupal, drupalSettings) {
7
8    'use strict';
9
10    Drupal.behaviors.sbd_language_switch = {
11      attach: function (context, settings) {
12        var country_default = drupalSettings.sbd_language_switch.default_country.toUpperCase();
13        var lang_default = drupalSettings.sbd_language_switch.default_lang.toUpperCase();
14        var all_location_page_link = drupalSettings.sbd_language_switch.all_location_page_option;
15        var isCoreMds2024 = drupalSettings.isCoreMds2024;
16        if (drupalSettings.sbd_language_switch.is_in_language_enabled != undefined) {
17          var is_in_language_enabled = drupalSettings.sbd_language_switch.is_in_language_enabled;
18          var in_language_support_text = drupalSettings.sbd_language_switch.in_language_support_text;
19          var in_language_support_target = drupalSettings.sbd_language_switch.in_language_support_target;
20          var in_language_support_link = drupalSettings.sbd_language_switch.in_language_support_link;
21          var in_language_support_icon = drupalSettings.sbd_language_switch.in_language_support_icon;
22        } else {
23          var is_in_language_enabled = 0;
24        }
25        if (is_in_language_enabled == 0) {
26          if(!$('div#block-languageswitcher').length) {
27              var htmlx = '<div class="language-switcher-language-url settings-tray-editable" id="block-languageswitcher" data-drupal-settingstray="editable">';
28              if (isCoreMds2024) {
29                htmlx += '<nav id="langnav" role="navigation" aria-label="Language menu">';
30              }
31              else {
32                htmlx += '<nav id="lnav" role="navigation" aria-label="Language menu">';
33              }
34              htmlx += '<ul class="lang-nav">';
35              if (!isCoreMds2024) {
36                if (all_location_page_link) {
37                  var firstChar = all_location_page_link.substr(0, 1);
38                  if (firstChar == '/') {
39                    htmlx += '<li><a href="' + all_location_page_link + '"><span> ' + country_default + ' | ' + lang_default + ' </span></a></li>';
40                  }
41                  else {
42                    htmlx += '<li><a href="/' + all_location_page_link + '"><span> ' + country_default + ' | ' + lang_default + ' </span></a></li>';
43                  }
44                }
45                else {
46                  htmlx += '<li><span> ' + country_default + ' | ' + lang_default + ' </span></li>';
47                }
48              }
49              else {
50                htmlx += '<li class="single-lang"><div><a href="' + all_location_page_link + '"><span class="globe-icon"></span><span class="mobile">' + country_default + ' | ' + lang_default + '</span></a></div></li>';
51              }
52              htmlx += '</ul></nav></div>';
53              $( ".language-switcher div.coh-block" ).append( '' );
54              $( ".language-switcher div.coh-block" ).append( htmlx );
55          }
56        } else {
57          if (!$('div#block-languageswitcher').length) {
58            var htmlx = '<div class="language-switcher-language-url settings-tray-editable" id="block-languageswitcher" data-drupal-settingstray="editable">';
59            if (isCoreMds2024) {
60              htmlx += '<nav id="langnav" role="navigation" aria-label="Language menu">';
61            }
62            else {
63              htmlx += '<nav id="lnav" role="navigation" aria-label="Language menu">';
64            }
65            if (!isCoreMds2024) {
66              htmlx += '<ul class="lang-nav"><li>';
67            } else {
68              htmlx += '<ul class="lang-nav">';
69            }
70            if (!isCoreMds2024) {
71              if (all_location_page_link) {
72                var firstChar = all_location_page_link.substr(0, 1);
73                if (firstChar == '/') {
74                  htmlx += '<a href="' + all_location_page_link + '"><span> ' + country_default + ' | ' + lang_default + ' </span></a>';
75                  htmlx += '<button id="lang-nav-dropdown-button" class="coh-menu-item-button js-coh-menu-item-button mobile-submenu-toggle" type="button" aria-label="Open language switcher" aria-haspopup="true" aria-expanded="false"></button>';
76                }
77                else {
78                  htmlx += '<a href="/' + all_location_page_link + '"><span> ' + country_default + ' | ' + lang_default + ' </span></a>';
79                  htmlx += '<button id="lang-nav-dropdown-button" class="coh-menu-item-button js-coh-menu-item-button mobile-submenu-toggle" type="button" aria-label="Open language switcher" aria-haspopup="true" aria-expanded="false"></button>';
80                }
81              }
82              else {
83                htmlx += '<span> ' + country_default + ' | ' + lang_default + ' </span>';
84                htmlx += '<button id="lang-nav-dropdown-button" class="coh-menu-item-button js-coh-menu-item-button mobile-submenu-toggle" type="button" aria-label="Open language switcher" aria-haspopup="true" aria-expanded="false"></button>';
85              }
86              // htmlx += '<a href="' + all_location_page_link + '"><span class="globe-icon"></span><span class="mobile">' + country_default + ' | ' + lang_default + '</span></a>';
87            }
88            else {
89              htmlx += '<li class="single-lang"><div style="display:flex;"><a href="' + all_location_page_link + '"><span class="globe-icon"></span><span class="mobile">' + country_default + ' | ' + lang_default + '</span></a>';
90            }
91            if(isCoreMds2024) {
92              if (all_location_page_link || in_language_support_link) {
93                htmlx += '<button class="language-dropdown-trigger" aria-label="Toggle language switcher"></button></div>'
94              } else {
95                htmlx += '</div>'
96              }
97            }
98            
99            htmlx += '<ul>';
100            if (all_location_page_link) {
101              htmlx += '<li class="all-location"><a href="' + all_location_page_link + '"><span class="">' + Drupal.t('View all Locations') + '</span></a></li>';
102            }
103            htmlx += '<li class="in-language-menu"><a href="' + in_language_support_link + '" ' + in_language_support_target + '><span class="mobile">' + Drupal.t(in_language_support_text) + '</span><i class="material-symbols-outlined" aria-hidden="true"> ' + in_language_support_icon + ' </i></a></li></ul>';
104            if (!isCoreMds2024) {
105              htmlx += '</li></ul></li></ul></nav></div>';
106            } else {
107              htmlx += '</li></ul></nav></div>';
108            }
109            
110            $(".language-switcher div.coh-block").append('');
111            $(".language-switcher div.coh-block").append(htmlx);
112          }
113        }
114
115        //language selector
116        $('#lnav', context).once('lnav-init').each(function () {
117          var $this = $(this);
118          
119            function handleLangNavToggle() {
120              var touchHandled = false;
121              var windowWidth = $(window).width();
122              
123              if (windowWidth <= 1024) {
124                $this.removeClass('open').find('ul ul').css('visibility', 'hidden');
125
126                $('#lang-nav-dropdown-button').on('click touchstart', function(e) {
127                  e.preventDefault();
128                  e.stopPropagation();
129                  
130                  // Toggle open class on the #lnav when #lang-nav-dropdown-button is clicked/tapped
131                  if (!$this.hasClass('open')) {
132                    $this.addClass('open').find('ul').css('visibility', 'visible');
133                  } else {
134                    $this.removeClass('open').find('ul ul').css('visibility', 'hidden');
135                  }
136          
137                  // Prevent multiple event triggers after the touchstart or click
138                  touchHandled = true;
139                });
140          
141                // Prevent click event from triggering if touchstart was already handled
142                $('#lang-nav-dropdown-button').on('click', function(e) {
143                  if (touchHandled) {
144                    e.preventDefault();
145                    touchHandled = false;
146                  }
147                });
148              } else {
149                // Remove any event listeners if window width is greater than 1024px
150                $('#lang-nav-dropdown-button').off('click touchstart');
151              }
152            }
153          
154            // Call the function on page load
155            if (!isCoreMds2024) {
156              handleLangNavToggle();
157            }
158          
159            // Listen for window resize events and call the function again
160            let resizeTimeout;
161
162            $(window).resize(function() {
163              if (!isCoreMds2024) {
164                clearTimeout(resizeTimeout);
165                resizeTimeout = setTimeout(function() {
166                  handleLangNavToggle();
167                }, 200);
168              }
169            });
170
171          // Desktop-specific functionality (width >= 1024px)
172          $(this).on('mouseenter mouseleave focusin focusout', function (e) {
173            var windowWidth = $(window).width();
174
175            if (windowWidth >= 1024) {
176              $this.removeClass('open').find('ul ul').css('visibility', 'hidden');
177
178              if ((!$this.hasClass('open') && e.type === 'mouseenter') || (!$this.hasClass('open') && e.type === 'focusin')) {
179                $this
180                  .addClass('open')
181                  .find('ul').css('visibility', 'visible');;
182              } else {
183                if (e.type === 'mouseleave') {
184                  $this
185                    .removeClass('open')
186                    .find('ul ul').css('visibility', 'hidden');;
187                }
188
189                if (e.type === 'focusout' && !$this.find(e.relatedTarget).length) {
190                  $this
191                    .removeClass('open')
192                    .find('ul ul').css('visibility', 'hidden');;
193                }
194              }
195            }
196          });
197        });
198
199        $("[id ^= 'edit-duplo-language-permission']").click(function(){
200          if ($(this).attr('value') == 'authenticated' && $(this).is(':checked')) {
201            $(this).parent().siblings().find('input:checkbox').not("input:not([value='anonymous']").prop('checked', true);
202          } else if ($(this).attr('value') == 'authenticated' && (!$(this).is(':checked'))) {
203            $(this).parent().siblings().find('input:checkbox').not("input:not([value='anonymous']").prop('checked', false);
204          }
205        });
206
207        // Clear time value if date is blank value.
208        $("#edit-publish-on-0-value-date").change(function(){
209          var pickDate = $(this).val();
210          if(!pickDate) {
211            $("#edit-publish-on-0-value-time").val('');
212          }
213        });
214
215        $("#edit-unpublish-on-0-value-date").change(function(){
216          var pickDate = $(this).val();
217          if(!pickDate) {
218            $("#edit-unpublish-on-0-value-time").val('');
219          }
220        });
221      }
222    }
223  })(jQuery, Drupal, drupalSettings);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.