PageSourceSearch

https://amcham.co.za/themes/EventBank/js/custom.js?tkgx89

js amcham.co.za collected 2026-09-28 10:07:14 UTC 69,821 bytes, 1,433 lines download raw bytes

1(function ($, Drupal) {
2    function isValidEmailAddress(emailAddress) {
3        // var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
4        var pattern = new RegExp("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$");
5        return pattern.test(emailAddress);
6    };
7
8    /*
9    * Skip to main content — explicitly move focus to #main-content on activation.
10    * tabindex="-1" on <main> makes it programmatically focusable but some browsers
11    * don't reliably move focus via hash links alone.
12    */
13    Drupal.behaviors.skipLink = {
14        attach: function (context, settings) {
15            once('skip-link', '.skip-link', context).forEach(function (link) {
16                link.addEventListener('click', function (e) {
17                    var target = document.getElementById('main-content');
18                    if (target) {
19                        e.preventDefault();
20                        target.focus();
21                    }
22                });
23            });
24        }
25    };
26
27    /*
28    * Check all <a> link to login EB
29    */
30    Drupal.behaviors.checkForEventBankRedirect = {
31        attach: function (context, settings) {
32            if($('a').length) {
33                $(once('glueup-links', 'a[href*="glueup."]:not([href*="-website.glueup."])', context)).click(function (e) {
34                    var link_href = encodeURIComponent($(this).attr("href"));
35                    var url = '/redirect-eventbank';
36                    window.open(url + '?redirect=' + link_href, '_blank');
37                    return false;
38                });
39            }
40        }
41    };
42
43    /*
44    * News page
45    */
46    Drupal.behaviors.membershipDirectory = {
47        attach: function (context, settings) {
48            if($('.page-node-type-news').length) {
49                $('.field--name-field-source a').attr("target", "_blank");
50            }
51        }
52    };
53
54    /*
55    * Hide Ads when empty
56    */
57    Drupal.behaviors.adsManage = {
58        attach: function (context, settings) {
59            if($('[class*="block-views-blockblock-ads"]').length) {
60                $('[class*="block-views-blockblock-ads"]').each(function(i,ele) {
61                    var block_html = $(this).find('.view-block-ads-horizontal').html();
62                    if(typeof block_html != 'undefined'){
63                        if(block_html.indexOf('img') == -1){
64                            $(this).css('display', 'none');
65                        } else {
66                            var field_html = $(this).find('.views-field-nothing').find('.field-content').html();
67                            if(field_html.indexOf('img') == -1){
68                                $(this).css('display', 'none');
69                            }
70                        }
71                    }
72                });
73            }
74        }
75    };
76
77    /*
78    * Document Listing
79    */
80    Drupal.behaviors.documentListing = {
81        attach: function (context, settings) {
82            if($('.view-document').length) {
83                var curHeight, curPadTop, curPadBot, totalHeight, animatedHeight;
84                $('.view-document .views-row').on({
85                    mouseenter: function () {
86                        $(this).find('.document-overlay').css('height', '100%');
87                        $(this).find('.views-field-field-document-file').show();
88                        $(this).find('.views-field-field-document-file-1').show();
89
90                        /* old system not working because of the calculation of the auto height when moving the mouse too fast */
91                        // curHeight = $(this).find('.document-overlay').height();
92                        // curPadTop = parseInt($(this).find('.document-overlay').css('padding-top'));
93                        // curPadBot = parseInt($(this).find('.document-overlay').css('padding-bottom'));
94                        // totalHeight = curHeight + curPadTop + curPadBot;
95                        //
96                        // $(this).find('.document-overlay').animate(
97                        //     { 'height': '100%' },
98                        // )
99                        // .promise()
100                        // .done(function() {
101                        //     $(this).find('.views-field-field-document-file').fadeIn('fast');
102                        //     $(this).find('.views-field-field-document-file-1').fadeIn('fast');
103                        // } );
104                    },
105                    mouseleave: function() {
106                        $(this).find('.document-overlay').css('height', 'auto');
107                        $(this).find('.views-field-field-document-file').hide();
108                        $(this).find('.views-field-field-document-file-1').hide();
109
110                        /* old system not working because of the calculation of the auto height when moving the mouse too fast */
111                        // $(this).find('.views-field-field-document-file').fadeOut('fast');
112                        // $(this).find('.views-field-field-document-file-1').fadeOut('fast');
113                        // $(this).find('.document-overlay').animate(
114                        //     { 'height': totalHeight },
115                        // )
116                        // .promise()
117                        // .done(function() {
118                        //     $(this).find('.views-field-field-document-file').hide();
119                        //     $(this).find('.views-field-field-document-file-1').hide();
120                        // } );
121                    }
122                });
123            }
124        }
125    };
126
127    /*
128    * Modal Popup
129    */
130    Drupal.behaviors.popupModal = {
131        attach: function (context, settings) {
132            if($('.popup-modal').length){
133
134                //get modal function
135                function popupModal(url, email){
136                    var get_modal = '.modal-ajax';
137
138                    //check for custom modal from url
139                    var custom_class_position = url.indexOf('#');
140                    if (custom_class_position >= 0) {
141                        get_modal = '.' + url.substr(custom_class_position + 1)
142                    }
143
144                    $.ajax({
145                        type: 'POST',
146                        url: url,
147                        data: { email: email }
148                    }).done(function(data, textStatus, jqXHR) {
149                        var content_html = $(data).find(get_modal).html();
150
151                        //get region class to keep style when possible
152                        var region_classes = $(data).find('.region-content').attr('class');
153                        var region_class_array = region_classes.split(' ');
154                        var region_class = '';
155
156
157                        if (!String.prototype.startsWith) {
158                            String.prototype.startsWith = function(searchString, position){
159                              return this.substr(position || 0, searchString.length) === searchString;
160                          };
161                        }
162
163                        $.each( region_class_array, function( i, l ){
164                            if(l.startsWith("class-region-")){
165                                region_class = l;
166                            }
167                        });
168
169                        $('.path-membership-directory').css('height', '100%');
170                        $('.path-membership-directory').css('overflow', 'hidden');
171
172                        $('.ajax-overlay').before('<div class="ajax-overlay-end"><div class="ajax-content '+region_class+'"><span class="ajax-close f-icon close-icon" role="button" tabindex="0" aria-label="Close"></span>'+content_html+'</div><div class="overlay-all-white"></div></div>');
173
174                        // Re-run Drupal behaviors (including spamspan) on the newly injected modal content.
175                        Drupal.attachBehaviors($('.ajax-content')[0]);
176
177                        // Move keyboard focus into the modal after it is painted.
178                        setTimeout(function() {
179                            var focusableSelectors = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not
179([tabindex="-1"])';
180                            var $first = $('.ajax-content').find(focusableSelectors).first();
181                            if ($first.length) {
182                                $first.focus();
183                            } else {
184                                $('.ajax-content').attr('tabindex', '-1').focus();
185                            }
186                        }, 50);
187                    }).fail(function(jqXHR, textStatus, errorThrown) {
188                        alert(jqXHR.responseText);
189                    });
190                }
191
192                //popup modal click button
193                $(once('.body-class', '.popup-modal', context)).click(function (e) {
194                    e.preventDefault();
195                    //get button url
196                    var url = $(this).attr('href');
197
198                    var input_error = 0;
199                    var email = '';
200
201                    //check if custom form & get custom data
202                    if($(this).hasClass('newsletters-signup')){
203                        //get form container
204                        var form_container = $(this).parents('.form-container');
205
206                        // get email
207                        email = form_container.find('.email-input').val();
208
209                        //check email value if needed
210                        if(email !== '' && isValidEmailAddress(email)){
211                            form_container.find('.email-value').removeClass('error');
212                            form_container.find('.email-not-valid').hide();
213
214                            input_error = 0;
215                        } else {
216                            //show error message
217                            form_container.find('.newsletters-email').focus();
218                            form_container.find('.newsletters-email').addClass('error');
219                            form_container.find('.email-not-valid').show();
220
221                            input_error = 1;
222                        }
223                    }
224
225                    //if no error call popup function
226                    if(input_error == 0){
227                        $('body').data('last-popup-trigger', this); // Store trigger for focus return on close.
228                        $('.ajax-content').remove();
229                        popupModal(url, email);
230                    }
231                });
232
233                // Allow pressing Enter in the email field to trigger the signup button.
234                $(once('newsletter-enter', '.newsletters-email', context)).on('keydown', function(e) {
235                    if (e.key === 'Enter') {
236                        e.preventDefault();
237                        $(this).closest('.form-container').find('.newsletters-signup').trigger('click');
238                    }
239                });
240
241                //open newsletter modal on homepage load
242                if($('.open-on-load').length){
243                    var cookie_value = $.cookie('open_on_load')
244                    var pathname = window.location.pathname;
245                    if(cookie_value != 'true' && pathname == '/'){
246                        $.cookie('open_on_load', 'true');
247                        $('a.open-on-load').click();
248                    }
249                }
250
251                $(once('newsletter-link-submit', 'body')).on('click', '.newsletters-subscription-form .newsletter-link-submit', function(e){
252                    e.preventDefault();
253                    
254                    var renderValue = null;
255
256                    $('script[src*="recaptcha/api.js"]').each(function () {
257                        var src = $(this).attr('src');
258                        var urlParams = new URLSearchParams(src.split('?')[1]);
259                        renderValue = urlParams.get('render');
260                    });
261                    
262                    grecaptcha.ready(function() {
263                    grecaptcha.execute(renderValue, {action: 'submit'}).then(function(token) {
264                        // Send the token to the server using AJAX
265                        
266                        var url_verify = window.location.origin + '/verify-recaptcha';
267                        
268                        $.ajax({
269                            url: url_verify,
270                            type: 'POST',
271                            data: {
272                              token: token
273                            },
274                            // success: function(response) {
275                            }).done(function(data, textStatus, jqXHR) {
276                                if (data.results.success && data.results.score >= 0.5) {
277                                    var url = window.location.origin + '/newsletter-thank-you';
278                
279                                    var form_container = $('.newsletters-subscription-form .eventbank-newsletter-form');
280                
281                                    var email_error = 0;
282                                    var lastname_error = 0;
283                                    var firstname_error = 0;
284                
285                                    // get values
286                                    var form_email = form_container.find("input[name='email']");
287                                    var email = form_email.val();
288                                    //check email value
289                                    if(email !== '' && isValidEmailAddress(email)){
290                                        form_email.removeClass('error');
291                                        form_container.find('.email-not-valid').css('display', 'none');
292                
293                                        email_error = 0;
294                                    } else {
295                                        //show error message
296                                        form_email.addClass('error');
297                                        form_container.find('.email-not-valid').css('display', 'block');
298                
299                                        email_error = 1;
300                                    }
301                
302                                    var form_lastname = form_container.find('#edit-lastname');
303                                    var last_name = form_lastname.val();
304                                    //check last name value
305                                    if(last_name !== ''){
306                                        form_lastname.removeClass('error');
307                                        form_container.find('.lastname-not-valid').css('display', 'none');
308                
309                                        lastname_error = 0;
310                                    } else {
311                                        //show error message
312                                        form_lastname.addClass('error');
313                                        form_container.find('.lastname-not-valid').css('display', 'block');
314                
315                                        lastname_error = 1;
316                                    }
317                
318                                    var form_firstname = form_container.find('#edit-firstname');
319                                    var first_name = form_firstname.val();
320                                    //check first name value
321                                    if(first_name !== ''){
322                                        form_firstname.removeClass('error');
323                                        form_container.find('.firstname-not-valid').css('display', 'none');
324                
325                                        firstname_error = 0;
326                                    } else {
327                                        //show error message
328                                        form_firstname.addClass('error');
329                                        form_container.find('.firstname-not-valid').css('display', 'block');
330                
331                                        firstname_error = 1;
332                                    }
333                
334                                    var subscriptions = {};
335                                    $('.newsletters-subscription-form .form-checkbox').each(function(){
336                                        if($(this).is(':checked')){
337                                            subscriptions[$(this).val()] = $(this).val();
338                                        } else {
339                                            subscriptions[$(this).val()] = 0;
340                                        }
341                                    });
342                
343                                    if(email_error == 0 && lastname_error == 0 && firstname_error == 0){
344                                        $.ajax({
345                                            type: 'POST',
346                                            url: url,
347                                            data: { last_name: last_name, first_name:first_name, email: email, subscriptions: subscriptions }
348                                        }).done(function(data, textStatus, jqXHR) {
349                                            $('.ajax-content').remove();
350                                            var content_html = $(data).find('.modal
350-ajax').html();
351                
352                                            $('.ajax-overlay').before('<div class="ajax-overlay-end"><div class="ajax-content"><span class="ajax-close f-icon close-icon"></span>'+content_html+'</div><div class="overlay-all-white"></div></div>');
353                                        }).fail(function(jqXHR, textStatus, errorThrown) {
354                                            alert(jqXHR.responseText);
355                                        });
356                                    }
357                                } else {
358                                  $('.ajax-overlay').before('<div class="ajax-overlay-end"><div class="ajax-content"><span class="ajax-close f-icon close-icon"></span><p>Recaptcha detect you as a bot - try again or contact us.</p></div><div class="overlay-all-white"></div></div>');
359                                }
360                        }).fail(function(jqXHR, textStatus, errorThrown) {
361                            $('.ajax-overlay').before('<div class="ajax-overlay-end"><div class="ajax-content"><span class="ajax-close f-icon close-icon"></span><p><p>Recaptcha detect you as a bot. - try again or contact us.</p></div><div class="overlay-all-white"></div></div>');
362                        });
363                    });
364                    });
365                });
366            }
367        }
368    };
369
370    /*
371    * Rework select on view
372    */
373    Drupal.behaviors.listingCommon = {
374        attach: function (context, settings) {
375            if($('.view').length){
376
377                //for each form select, user select2MultiCheckboxes
378                $('.view .view-filters .form-select').each(function(index, value){
379                    var $placehoder = ($(this).attr('data-placeholder') != null) ? $(this).attr('data-placeholder') : 'Select';
380                    $(this).select2({
381                        placeholder: "Select a topic",
382                        templateSelection: function (data) {
383                              return $placehoder;
384                          }
385                    });
386                });
387            }
388        }
389    };
390
391    /*
392    * Event Listing filter
393    */
394    Drupal.behaviors.eventListingUpdate = {
395        attach: function (context, settings) {
396            if($('.context-events, .block-event-block').length){
397                var url = window.location.href;
398
399                $('#edit-date-range').datetimepicker({
400                    viewMode: 'years',
401                    format: 'MMM YYYY',
402                    showClear: true,
403                    icons: {
404                        previous: 'glyphicon glyphicon-arrow date-arrow-left',
405                        next: 'glyphicon glyphicon-arrow date-arrow-right',
406                        clear: 'glyphicon glyphicon-close date-clear',
407                    }
408                });
409
410                function formatCustom (state) {
411                    if (!state.id) { return state.text; }
412                    var $state = $(
413                        '<span><span class="select2-icon-span f-icon ' + state.element.value.toLowerCase() + '-icon"></span> ' + state.text + '</span>'
414                    );
415                    return $state;
416                };
417
418                function formatNonCustom (state) {
419                    if (!state.id) { return state.text; }
420                    var $state = $(
421                        '<span><span class="select2-icon-span f-icon checkbox-checked-icon"></span>' + state.text + '</span>'
422                    );
423                    return $state;
424                };
425
426                //add select2 to filter
427                $('.non-custom-filter-form .form-select').select2({
428                  minimumResultsForSearch: Infinity,
429                  templateResult: formatNonCustom,
430                });
431                $('.custom-filter-form .form-select').select2({
432                  minimumResultsForSearch: Infinity,
433                  templateSelection: formatCustom,
434                  templateResult: formatCustom,
435                });
436
437                var option_type = 0;
438
439                // Use once() to prevent duplicate event handlers on re-attach.
440                $(once('event-listing-handlers', '.events-listing', context)).each(function() {
441                    var $listing = $(this);
442
443                    $listing.on('click', '#resetDatePicker', function(e) {
444                        $('#edit-date-range').data('DateTimePicker').clear();
445                    });
446
447                    $listing.on('dp.update', '#edit-date-range', function (e) {
448                        //only when month M is selected
449                        if(e.change == 'M'){
450                            option_type = 1;
451                            $('.event-filter-form .events-search-ajax').trigger( 'click' );
452                        }
453                    });
454
455                    $listing.on('change', '.events-filter-ajax:not
455(.events-filter-ajax-date)', function(e){
456                        $('#edit-search-name').val('').trigger('change');
457                        option_type = 2;
458                        $('.event-filter-form .events-search-ajax').trigger( 'click' );
459                    });
460
461                    //force stop propagation
462                    $listing.on('input', '#edit-search-name', function(e){
463                        option_type = 3;
464                    });
465
466                    //search only work if value is not empty
467                    $listing.on('click', '.form-item-search-name', function(){
468                        if($('#edit-search-name').val() != ''){
469                            $('.event-filter-form .events-search-ajax').trigger( 'click' );
470                        }
471                    });
472
473                    //trigger on search or when change the other filters above
474                    $listing.on('click', '.events-search-ajax', function(event){
475                        event.preventDefault();
476                        eventAjax(url, 'filter');
477                        return false;
478                    });
479
480                    //trigger on reset
481                    $listing.on('click keydown', '.form-reset', function(event){
482                        if (event.type === 'keydown' && event.key !== 'Enter' && event.key !== ' ') { return; }
483                        event.preventDefault();
484                        eventAjax(url, 'filter', 'reset');
485                        return false;
486                    });
487
488                    //trigger on show more
489                    $listing.on('click', '.show-more-button', function(event){
490                        eventAjax(url, 'show-more');
491                        return false;
492                    });
493                });
494
495
496                function eventAjax(url, type, reset){
497                    if(reset == 'reset'){
498                        var timeline = 3;
499                        var range_date = 0;
500                        var search_keyword = '';
501                        var registration = '';
502                        var tags = '';
503                        var location = '';
504                        var location_val = '';
505                    } else {
506                        //default value to not fire filter on timeline or date range
507                        var timeline = 3;
508                        var range_date = 0;
509                        var search_keyword = '';
510
511                        timeline = $('.event-filter-form #edit-timeline').val();
512
513                        if(option_type == 2){
514                            timeline = $('.event-filter-form #edit-timeline').val();
515                        } else if(option_type == 1){
516                            var timeline = 1;
517                            range_date = $('#edit-date-range').val();
518                        } else if(option_type == 3) {
519                            search_keyword = $('#edit-search-name').val();
520                        }
521
522                        var registration = $('.event-filter-form #edit-registration').val();
523                        var tags = $('.event-filter-form #edit-tags').val();
524                        var location = $('.event-filter-form #edit-location option:selected').text();
525                        var location_val = $('.event-filter-form #edit-location option:selected').val();
526
527                    }
528
529                    if(type == 'show-more'){
530                        var more_value = $('.show-more-button').attr('value');
531                        var ajax_type = 2;
532                    } else {
533                        var ajax_type = 1;
534                        var more_value = '';
535                    }
536                    
537                    $.ajax({
538                        type: 'POST',
539                        url: url,
540                        data: { more_value: more_value, timeline: timeline, registration: registration, tags: tags, location: location, location_val: location_val, range_date: range_date, search_keyword: search_keyword, ajax_call: ajax_type }
541                        }).done(function(data, textStatus, jqXHR) {
542                            var content_html = $(data).find('.events-listing').html();
543                            if(type == 'filter'){
544                                $('.events-listing-ajax').replaceWith(content_html);
545
546                                //add select2 to filter
547                                $('.non-custom-filter-form .form-select').select2({
548                                  minimumResultsForSearch: Infinity,
549                                  templateResult: formatNonCustom,
550                                });
551                                $('.custom-filter-form .form-select').select2({
552                                  minimumResultsForSearch: Infinity,
553                                  templateSelection: formatCustom,
554                                  templateResult: formatCustom,
555                                });
556
557                                $('#edit-date-range').datetimepicker({
558                                    viewMode: 'years',
559                                    format: 'MMM YYYY',
560                                    showClear: true,
561                                    icons: {
562                                        previous: 'glyphicon glyphicon-arrow date-arrow-left',
563                                        next: 'glyphicon glyphicon-arrow date-arrow-right',
564                                        clear: 'glyphicon glyphicon-close date-clear',
565                                    }
566                                });
567
568                                // Re-render AddToAny share buttons on the newly injected event
569                                // cards — this flow intentionally skips Drupal.attachBehaviors(),
570                                // so Drupal.behaviors.addToAny (which would normally call this)
571                                // never runs.
572                                if (window.a2a) {
573                                    a2a.init_all();
574                                }
575                            } else {
576                                $('.events-more-ajax').replaceWith(content_html);
577                                // Drupal.attachBehaviors(); //do not add this to filter
578
579                                // Re-render AddToAny share buttons on the newly injected event
580                                // cards (see comment in the filter branch above).
581                                if (window.a2a) {
582                                    a2a.init_all();
583                                }
584                            }
585                        }).fail(function(jqXHR, textStatus, errorThrown) {
586                        alert(jqXHR.responseText);
587                    });
588                }
589            }
590        }
591    };
592
593    /*
594    * Membership Listing Page
595    */
596    Drupal.behaviors.membershipListingUpdate = {
597        attach: function (context, settings) {
598            // if($('.membership-listing-content').length){
599            if($('.membership-listing').length){
600                var url = window.location.href;
601
602                function formatCustom (state) {
603                    if (!state.id) { return state.text; }
604                    var $state = $(
605                        '<span><span class="select2-icon-span f-icon ' + state.element.value.toLowerCase() + '-icon"></span> ' + state.text + '</span>'
606                    );
607                    return $state;
608                };
609
610                function formatNonCustom (state) {
611                    if (!state.id) { return state.text; }
612                    var $state = $(
613                        '<span><span class="select2-icon-span f-icon checkbox-checked-icon"></span> ' + state.text + '</span>'
614                    );
615                    return $state;
616                };
617
618                //add select2 to filter
619                $('.non-custom-filter-form .form-select').select2MultiCheckboxes({
620                  minimumResultsForSearch: Infinity,
621                  templateResult: formatNonCustom,
622                  templateSelection: function(selected, total) {
623                    return "Selected " + selected.length + " of " + total;
624                  },
625                });
626                $('.custom-filter-form .form-select').select2MultiCheckboxes({
627                  minimumResultsForSearch: Infinity,
628                  templateSelection: formatCustom,
629                  templateResult: formatCustom,
630                });
631
632                var option_type = 0;
633                
634                $('.region-eventbank-api-membership-listing, .region-eventbank-api-membership-listing-default, .path-membership-directory', context).on('click', '.membership-clear-ajax',function(event){
635                    event.stopImmediatePropagation();
636                    $('.non-custom-filter-form .form-select').val(null).trigger('change');
637                    $('.custom-filter-form .form-select').val(null).trigger('change');
638                    $('.form-container-search input[type="text"]').val('');
639                    // location.reload();
640                    
641                    return false;
642                });
643
644                $('.region-eventbank-api-membership-listing, .region-eventbank-api-membership-listing-default, .path-membership-directory', context).on('click', '.membership-search-ajax',function(event){
645                    event.stopImmediatePropagation();
646                    var order = $('.membership-filter-form #edit-order').val();
647                    var industry = [];
648                    
649                    $('.membership-filter-form .membership-filter-ajax').each(function(){
650                        if ($(this).val() != '' && $(this).val() != 0) {
651                           industry.push($(this).val());
652                            // return false;
653                        }
654                    });
655                    var filter_tag = $("input[name=filter_tag]").val();
656                    var type = $('.membership-filter-form #edit-type').val();
657                    var search_keyword_value = '';
658                    var search_keyword = '';
659                    
660                    $('.membership-filter-form .membership-search-ajax-input', context).each(function(){
661                        if ($(this).val() != '' && $(this).val() != 0) {
662                            var search_keyword_name = $(this).attr('name');
663                            search_keyword_name = search_keyword_name.substr(7); //Cut from 'search-'
664                            search_keyword_value =  $(this).val();
665                            search_keyword =  search_keyword_value + '##FilterKey##' + search_keyword_name;
666                            return false;
667                        }
668                    });
669
670                    $('.membership-filter-form .membership-search-ajax-input', context).onclick = function () {
671                        if (search_keyword_value === '') {
672                            return  false;
673                        }
674                    }
675
676                    $.ajax({
677                        type: 'POST',
678                        url: url,
679                        data: { order: order, industry: industry, filter_tag: filter_tag, type: type, search_keyword: search_keyword, ajax_call: 1 }
680                        }).done(function(data, textStatus, jqXHR) {
681                            var content_html = $(data).find('.membership-listing').html();
682                            $('.membership-listing-ajax').replaceWith(content_html);
683
684                            //add select2 to filter
685                            $('.non-custom-filter-form .form-select').select2({
686                              minimumResultsForSearch: Infinity,
687                              templateResult: formatNonCustom,
688                            });
689                            $('.custom-filter-form .form-select').select2({
690                              minimumResultsForSearch: Infinity,
691                              templateSelection: formatCustom,
692                              templateResult: formatCustom,
693                            });
694                             $('.letter-filter.active').removeClass('underline');
695                            Drupal.attachBehaviors();
696                        }).fail(function(jqXHR, textStatus, errorThrown) {
697                        alert(jqXHR.responseText);
698                    });
699                    return false;
700                });
701
702                $('.membership-listing', context).on('click keydown', '.form-reset', function(event){
703                    if (event.type === 'keydown' && event.key !== 'Enter' && event.key !== ' ') { return; }
704                    event.stopImmediatePropagation();
705                    var order = '';
706                    var industry = '';
707                    var filter_tag = '';
708                    var type = '';
709                    var search_keyword = '';
710
711                    $.ajax({
712                        type: 'POST',
713                        url: url,
714                        data: { order: order, industry: industry, filter_tag: filter_tag, type: type, search_keyword: search_keyword, ajax_call: 0 }
715                        }).done(function(data, textStatus, jqXHR) {
716                            var content_html = $(data).find('.membership-listing').html();
717                            $('.membership-listing-ajax').replaceWith(content_html);
718
719                            //add select2 to filter
720                            $('.non-custom-filter-form .form-select').select2({
721                              minimumResultsForSearch: Infinity,
722                              templateResult: formatNonCustom,
723                            });
724                            $('.custom-filter-form .form-select').select2({
725                              minimumResultsForSearch: Infinity,
726                              templateSelection: formatCustom,
727                              templateResult: formatCustom,
728                            });
729                            Drupal.attachBehaviors();
730                        }).fail(function(jqXHR, textStatus, errorThrown) {
731                        alert(jqXHR.responseText);
732                    });
733                    return false;
734                });
735
736                $('.membership-listing', context).on('click', '.show-more-button', function(event){
737                    event.stopImmediatePropagation();
738                    var more_value = $('.show-more-button').attr('value');
739                    var order = $('.membership-filter-form #edit-order').val();
740                    var industry = '';
741                    $('.membership-filter-form .membership-filter-ajax').each(function(){
742                        if ($(this).val() != '' && $(this).val() != 0) {
743                            industry =  $(this).val();
744                        }
745                    });
746
747                    var filter_tag = $("input[name=filter_tag]").val();
748                    var type = $('.membership-filter-form #edit-type').val();
749                    var search_keyword = '';
750                    $('.membership-filter-form .membership-search-ajax-input').each(function(){
751                        if ($(this).val() != '' && $(this).val() != 0) {
752                            var search_keyword_name = $(this).attr('name');
753                            search_keyword_name = search_keyword_name.substr(7); //Cut from 'search-'
754                            search_keyword =  $(this).val();
755                            search_keyword =  search_keyword + '##FilterKey##' + search_keyword_name;
756                        }
757                    });
758
759                    $.ajax({
760                        type: 'POST',
761                        url: url,
762                        data: { more_value: more_value, order: order, industry: industry, filter_tag: filter_tag, type: type, search_keyword: search_keyword, ajax_call: 2 }
763                        }).done(function(data, textStatus, jqXHR) {
764                            var content_html = $(data).find('.membership-listing').html();
765                            $('.membership-more-ajax').replaceWith(content_html);
766                            Drupal.attachBehaviors();
767                        }).fail(function(jqXHR, textStatus, errorThrown) {
768                        alert(jqXHR.responseText);
769                    });
770                    return false;
771                });
772            }
773        }
774    };
775
776
777    /*
778    * Cascading filter: when a level-1 cascading dropdown changes, restrict
779    * the level-2 dropdown to only show the children of the selected parent(s).
780    * Works with the data-cascade-child / data-cascade-parent / data-cascade-map /
781    * data-all-options attributes set by membershipFilter::buildForm().
782    */
783    Drupal.behaviors.membershipCascadingFilter = {
784        attach: function (context, settings) {
785            once('cascading-filter', '[data-cascade-child]', context).forEach(function (parentEl) {
786                var cascadeMap = {};
787                try {
788                    cascadeMap = JSON.parse(parentEl.getAttribute('data-cascade-map') || '{}');
789                } catch (e) {}
790
791                // preserveChildValue: true on initial attach (keep existing child selection if
792                // still valid), false on user-driven change (clear child selection).
793                function updateChild(preserveChildValue) {
794                    var parentName = parentEl.name.replace('[]', '');
795                    var $child = $('[data-cascade-parent]').filter(function () {
796                        return $(this).attr('data-cascade-parent') === parentName;
797                    });
798                    if (!$child.length) { return; }
799
800                    var $childWrapper = $child.closest('.non-custom-filter-form');
801                    var allOptions = [];
802                    try {
803                        allOptions = JSON.parse($child.attr('data-all-options') || '[]');
804                    } catch (e) {}
805
806                    var previousVals = $child.val() || [];
807                    var selected = $(parentEl).val() || [];
808                    var parentCodes = selected.map(function (v) {
809                        return v.split('##FilterKey##')[0];
810                    });
811
812                    // Collect allowed child codes (union of all selected parents' children).
813                    var allowedCodes = [];
814                    parentCodes.forEach(function (pCode) {
815                        if (cascadeMap[pCode]) {
816                            allowedCodes = allowedCodes.concat(cascadeMap[pCode]);
817                        }
818                    });
819
820                    // Rebuild child options: only matching children when parent selected.
821                    $child.empty();
822                    var matchCount = 0;
823                    allOptions.forEach(function (opt) {
824                        var optCode = opt.v.split('##FilterKey##')[0];
825                        if (allowedCodes.length === 0 || allowedCodes.indexOf(optCode) !== -1) {
826                            $child.append(new Option(opt.t, opt.v));
827                            if (allowedCodes.length > 0) { matchCount++; }
828                        }
829                    });
830
831                    // Show child only when parent has a selection AND children exist for it.
832                    if (allowedCodes.length > 0 && matchCount > 0) {
833                        $childWrapper.show();
834                        // Re-initialize select2 on the child now that it is visible.
835                        if ($child.data('select2')) { $child.select2('destroy'); }
836                        $child.select2MultiCheckboxes({
837                            minimumResultsForSearch: Infinity,
838                            templateResult: function (state) {
839                                if (!state.id) { return state.text; }
840                                return $('<span><span class="select2-icon-span f-icon checkbox-checked-icon"></span> ' + state.text + '</span>');
841                            },
842                            templateSelection: function (selected, total) {
843                                return 'Selected ' + selected.length + ' of ' + total;
844                            },
845                        });
846                        if (preserveChildValue) {
847                            // Restore previously selected values that are still in the filtered list.
848                            var stillValid = previousVals.filter(function (v) {
849                                return $child.find('option[value="' + v + '"]').length > 0;
850                            });
851                            $child.val(stillValid.length > 0 ? stillValid : null).trigger('change');
852                        } else {
853                            $child.val(null).trigger('change');
854                        }
855                    } else {
856                        $child.val(null).trigger('change');
857                        $childWrapper.hide();
858                    }
859                }
860
861                // User changes parent: clear child selection and update visibility.
862                $(parentEl).on('change.cascade', function () { updateChild(false); });
863
864                // Initial attach: if parent already has a value (e.g. after AJAX re-render),
865                // filter child options and preserve any still-valid child selection.
866                if ($(parentEl).val() && $(parentEl).val().length > 0) {
867                    updateChild(true);
868                }
869            });
870        }
871    };
872
873    /*
874    * Common Page View
875    */
876    Drupal.behaviors.commonPageView = {
877        attach: function (context, settings) {
878            if($('.common-page-view').length){
879                $('.views-exposed-form .form-item-title').on('click', '.control-label', function(){
880                    $('.views-exposed-form .form-actions .form-submit').trigger( 'click' );
881                });
882            }
883        }
884    };
885
886
887    /*
888    * Weixin QR code
889    */
890    Drupal.behaviors.weixinQrCode = {
891        attach: function (context, settings) {
892            if($('.weixin-qr-code').length){
893                $('.weixin-icon').on('click', function(){
894                    $(this).next('.weixin-qr-code').toggle();
895                    $(this).parent('.button-social-media').toggleClass('active');
896                });
897                $('.line-icon').on('click', function(){
898                    $(this).next('.weixin-qr-code').toggle();
899                    $(this).parent('.button-social-media').toggleClass('active');
900                });
901            }
902        }
903    };
904
905
906    /*
907    * Mobile menu
908    */
909    Drupal.behaviors.mobileMenu = {
910        attach: function (context, settings) {
911            if($('.mobile-header-menu').length){
912                $(once('.mobile-header-menu', '.mobile-header-menu-link', context)).click(function () {
913                    if($('.mobile-header-menu .mobile-block-menu').hasClass('mobile-block-menu-open')){
914                        $('.mobile-header-menu .mobile-block-menu').hide();
915                        $('.mobile-header-menu .mobile-block-menu #block-mainnavigation-2').hide();
916                        $('.mobile-header-menu .mobile-block-menu').removeClass('mobile-block-menu-open');
917                    } else {
918                        $('.mobile-header-menu .mobile-block-menu').show();
919                        $('.mobile-header-menu .mobile-block-menu').addClass('mobile-block-menu-open');
920                        $('.mobile-header-menu .mobile-block-menu').addClass('testing');
921                        $('.mobile-header-menu .mobile-block-menu #block-mainnavigation-2').show();
922                        $('#block-mainnavigation-2 #superfish-main--2-accordion').removeClass('sf-hidden');
923                        $('#block-mainnavigation-2 #superfish-main--2-accordion').addClass('sf-expanded');
924                        $('#block-mainnavigation-2 #superfish-main--2-accordion').css('display', 'block');
925                    }
926                });
927                $('.mobile-header-menu').on('click', '.close-icon', function(){
928                    $('.mobile-header-menu .mobile-block-menu').hide();
929                    $('.mobile-header-menu .mobile-block-menu').removeClass('mobile-block-menu-open');
930                });
931                // $('.mobile-block-menu').on('click', 'li.menuparent', function(){
932
933                //     $('.mobile-block-menu li.menuparent ul').css('position', 'absolute');
934
935                //     if($(this).hasClass('li-open')){
936                //         $('.mobile-block-menu li.menuparent').removeClass('li-open');
937                //         var sub_menu = $(this).find('ul');
938                //         sub_menu.css('display', 'none');
939                //     } else {
940                //         $('.mobile-block-menu li.menuparent').removeClass('li-open');
941                //         $(this).addClass('li-open');
942                //         var sub_menu = $(this).find('ul');
943                //         sub_menu.css('position', 'relative');
944                //         sub_menu.css('top', '10px');
945                //     }
946                // });
947            }
948        }
949    };
950
951
952    /*
953    * Global
954    */
955    /*
956    * Keyboard accessibility: make non-link nav parent items Tab-focusable.
957    *
958    * Superfish renders menu items with no URL as <span class="nolink"> which are
959    * not natively focusable. Adding tabindex="0" puts them in the Tab order so
960    * the CSS :focus-within rule on the parent <li> can show their submenu.
961    * Enter/Space toggle the submenu for keyboard users who expect that behaviour.
962    */
963    Drupal.behaviors.navKeyboard = {
964        attach: function (context, settings) {
965            once('nav-nolink-focusable', '.sf-menu span.nolink.menuparent', context).forEach(function (span) {
966                span.setAttribute('tabindex', '0');
967                $(span).on('keydown', function (e) {
968                    if (e.key === 'Enter' || e.key === ' ') {
969                        e.preventDefault();
970                        var $li = $(span).closest('li');
971                        var isOpen = $li.hasClass('sfHover');
972                        // Close all other open items first.
973                        $('.sf-menu li.sfHover').not($li).removeClass('sfHover');
974                        $li.toggleClass('sfHover', !isOpen);
975                    }
976                    // Arrow-Down moves focus to the first submenu item.
977                    if (e.key === 'ArrowDown') {
978                        e.preventDefault();
979                        var $first = $(span).closest('li').find('ul a').first();
980                        if ($first.length) { $first.focus(); }
981                    }
982                });
983            });
984        }
985    };
986
987    Drupal.behaviors.global = {
988        attach: function (context, settings) {
989            // Shared helper so click, keyboard, and Escape all use the same close logic.
990            function closeAjaxModal() {
991                var $trigger = $('body').data('last-popup-trigger');
992                $('.ajax-overlay').hide();
993                $('.ajax-overlay-end').remove();
994                $('.overlay-all-white').remove();
995                $('.ajax-content').remove();
996                $('body').css('height', 'auto');
997                $('body').css('overflow', 'visible');
998                // Return focus to the element that opened the modal.
999                if ($trigger) { $($trigger).focus(); }
1000            }
1001
1002            $('html').on('click', '.ajax-overlay-end .ajax-content .ajax-close, .overlay-all-white', function(){
1003                closeAjaxModal();
1004            });
1005
1006            // Allow keyboard users to close the modal with Enter/Space on the close button.
1007            $('html').on('keydown', '.ajax-overlay-end .ajax-content .ajax-close', function(e){
1008                if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); closeAjaxModal(); }
1009            });
1010
1011            // Close on Escape key — required by WCAG 2.1 SC 2.1.2.
1012            // Focus trap: keep Tab/Shift+Tab cycling inside the modal while it is open.
1013            $(document).off('keydown.ajax-modal').on('keydown.ajax-modal', function(e) {
1014                if (e.key === 'Escape' && $('.ajax-overlay-end').length) { closeAjaxModal(); return; }
1015
1016                if (e.key === 'Tab' && $('.ajax-overlay-end').length) {
1017                    e.preventDefault();
1018                    var focusableSelectors = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
1019                    var $modal    = $('.ajax-content');
1020                    var $focusable = $modal.find(focusableSelectors).filter(':visible');
1021                    if (!$focusable.length) { $modal.attr('tabindex', '-1').focus(); return; }
1022                    var $first = $focusable.first();
1023                    var $last  = $focusable.last();
1024                    // If focus is outside the modal, bring it in.
1025                    if (!$.contains($modal[0], document.activeElement)) {
1026                        (e.shiftKey ? $last : $first).focus();
1027                        return;
1028                    }
1029                    // Wrap at boundaries.
1030                    if (e.shiftKey && $(document.activeElement).is($first)) {
1031                        $last.focus();
1032                    } else if (!e.shiftKey && $(document.activeElement).is($last)) {
1033                        $first.focus();
1034                    } else {
1035                        // Move naturally to the next/previous focusable element within the modal.
1036                        var index = $focusable.index(document.activeElement);
1037                        $focusable.eq(e.shiftKey ? index - 1 : index + 1).focus();
1038                    }
1039                }
1040            });
1041
1042            // Use once() to prevent duplicate ajaxStart/ajaxStop handlers on re-attach.
1043            once('global-ajax-handlers', 'html').forEach(function () {
1044                var $overlay = $('.ajax-overlay').hide();
1045                var $overlay_end = $('.ajax-overlay-end').hide();
1046                var $overlay_all_white = $('.overlay-all-white').hide();
1047                var $loading = $('#loading').hide();
1048                $(document)
1049                    .ajaxStart(function () {
1050                        $overlay.show();
1051                        $loading.show();
1052                        $overlay_end.remove();
1053                        $overlay_all_white.remove();
1054                    })
1055                    .ajaxStop(function () {
1056                        $overlay.hide();
1057                        $loading.hide();
1058                    });
1059            });
1060
1061
1062            /*
1063            * Replace Anchor scroll to a smooth scroll
1064            */
1065            $("a[href*='#']:not([href='#'])").click(function() {
1066                if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
1067                  var target = $(this.hash);
1068                  target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
1069                  if (target.length) {
1070                    var scroll = target.offset().top;
1071                    if($('.mobile')){
1072                        scroll = scroll - 130;
1073                    } else {
1074                        scroll = scroll - 110;
1075                    }
1076
1077                    $('html,body', context).animate({
1078                      scrollTop: scroll
1079                    }, 1000);
1080                    return false;
1081                  }
1082                }
1083            });
1084        }
1085    };
1086
1087    /*
1088    * Node Modal
1089    */
1090    Drupal.behaviors.nodeModal = {
1091        attach: function (context, settings) {
1092            if($('.node-modal').length){
1093                //get modal function
1094                function nodeModal(url){
1095                    var get_modal = '.node--view-mode-full';
1096                    var node_class = 'body';
1097
1098                    //check for custom modal from url
1099                    var custom_class_position = url.indexOf('#');
1100                    if (custom_class_position >= 0) {
1101                        get_modal = '.' + url.substr(custom_class_position + 1)
1102                    }
1103
1104                    $.ajax({
1105                        type: 'POST',
1106                        url: url,
1107                    }).done(function(data, textStatus, jqXHR) {
1108                        var content_html = $(data).find(get_modal).html();
1109
1110                        //get region class to keep style when possible
1111                        var parser = new DOMParser();
1112                        doc = parser.parseFromString(data, "text/html");
1113                        var docClass = doc.body.getAttribute('class');
1114                        parser = doc = null;
1115
1116                        if (!String.prototype.startsWith) {
1117                            String.prototype.startsWith = function(searchString, position){
1118                              return this.substr(position || 0, searchString.length) === searchString;
1119                          };
1120                        }
1121
1122                        $('.ajax-overlay').before('<div class="ajax-overlay-end"><div class="ajax-content '+docClass+'"><span class="ajax-close f-icon close-icon"></span>'+content_html+'</div><div class="overlay-all-white"></div></div>');
1123                    }).fail(function(jqXHR, textStatus, errorThrown) {
1124                        alert(jqXHR.responseText);
1125                    });
1126                }
1127
1128                //node modal click button
1129                $(once('.body-class', '.node-modal', context)).click(function (e) {
1130                // $('.node-modal').once().each(function(){
1131                    // $(this).one('click', function(e){
1132                        e.preventDefault();
1133                        var url = $(this).attr('href');
1134
1135                        $('.ajax-content').remove();
1136                        nodeModal(url);
1137                    // });
1138                });
1139            }
1140        }
1141    };
1142
1143    /*
1144    * Full List: having the letter filter fixed on top of the page after scrolling down
1145    */
1146    Drupal.behaviors.alphabetNavPositionFixed = {
1147        attach: function (context, settings) {
1148            if ($('.letters-filter-fixednav').length) {
1149              var alphabetNav = $(".letters-filter-fixednav");
1150              var win = $(window);
1151              var top_offset = $('.letters-filter-fixednav').offset().top;
1152
1153              var sc = $(document);
1154              win.scroll(function () {
1155                  if (sc.scrollTop() >= top_offset) {
1156                      alphabetNav.addClass("fixednav");
1157                  } else {
1158                      alphabetNav.removeClass("fixednav");
1159                  }
1160              })
1161            }
1162        }
1163    };
1164
1165    /*
1166    * Get the height of membership info description so as to append shandow
1167    */
1168    Drupal.behaviors.appendShandowForMembershipDescription = {
1169        attach: function (context, settings) {
1170            if ($('#block-membershippaymentdetails .membership-details-content').length) {
1171                $( "#block-membershippaymentdetails .membership-details-content .views-row .field-content-description" ).each(function() {
1172                    if (($(this).height() > 190) && (!$(this).parent().contents('.membership-info-contents-hide').length)) {
1173                        $(this).after('<span class="membership-info-contents-hide"></span>');
1174                        $(this).addClass("field-content-description-scroll");
1175                    }
1176                });
1177            }
1178        }
1179    };
1180
1181    Drupal.behaviors.appendShandowForMembershipV2Description = {
1182        attach: function (context, settings) {
1183            if ($('.block-membership-payment-corporate-individual .membership-details-content').length) {
1184                $( ".block-membership-payment-corporate-individual .membership-details-content .views-row .field-content-description" ).each(function() {
1185                    if (($(this).height() > 190) && (!$(this).parent().contents('.membership-info-contents-hide').length)) {
1186                        $(this).after('<span class="membership-info-contents-hide"></span>');
1187                        $(this).addClass("field-content-description-scroll");
1188                    }
1189                });
1190            }
1191        }
1192    };
1193
1194
1195    /*
1196    * Display none the button when the CTA link is empty
1197    */
1198    Drupal.behaviors.displayNoneForCTALink = {
1199        attach: function (context, settings) {
1200            // Home banner buttons
1201            if ($('.block-views-blockhomepage-block-1 .banner-buttons').length) {
1202                var banner_left_link_html = $('.block-views-blockhomepage-block-1 .banner-buttons .views-field-field-left-link .field-content').html();
1203                var banner_right_link_html = $('.block-views-blockhomepage-block-1 .banner-buttons .views-field-field-right-link .field-content').html();
1204                if (banner_left_link_html.length == 0) {
1205                    $('.block-views-blockhomepage-block-1 .banner-buttons .views-field-field-left-link').css('display', 'none');
1206                    $('.block-views-blockhomepage-block-1 .banner-buttons .views-field-field-left-link').css('margin-right', 'auto');
1207                }
1208                if (banner_right_link_html.length == 0) {
1209                    $('.block-views-blockhomepage-block-1 .banner-buttons .views-field-field-right-link').css('display', 'none');
1210                }
1211            }
1212        }
1213    };
1214
1215    /*
1216    * Hide job contact when page load
1217    */
1218    // Drupal.behaviors.toggleContactFormForWebformContactPage = {
1219    //     attach: function (context, settings) {
1220    //         if ($('#webform-submission-jobs-add-form').length) {
1221    //             if ($("webform-submission-volunteer-opportunity-add-form input[name='job_contact']:checked").val() == 'email') {
1222    //                 $('.form-item-contact-email').css('display', 'block');
1223    //                 $('.form-item-contact-url').css('display', 'none');
1224    //             } else if ($("webform-submission-volunteer-opportunity-add-form input[name='job_contact']:checked").val() == 'link_url') {
1225    //                 $('.form-item-contact-url').css('display', 'block');
1226    //                 $('.form-item-contact-email').css('display', 'none');
1227    //             } else {
1228    //                 $('.form-item-contact-url').css('display', 'none');
1229    //                 $('.form-item-contact-email').css('display', 'none');
1230    //             }
1231
1232    //             $('html').on('click', '#edit-job-contact-email', function(){
1233    //                 $('.form-item-contact-email').css('display', 'block');
1234    //                 $('.form-item-contact-url').css('display', 'none');
1235    //                 $('#edit-job-contact-link-url').val("");
1236    //             });
1237
1238    //             $('html').on('click', '#edit-job-contact-link-url', function(){
1239    //                 $('.form-item-contact-url').css('display', 'block');
1240    //                 $('.form-item-contact-email').css('display', 'none');
1241    //                 $('#edit-job-contact-email').val("");
1242    //             });
1243    //         }
1244    //     }
1245    // };
1246
1247    /*
1248    * Home page banner slick
1249    */
1250    Drupal.behaviors.homeBannerSlick = {
1251        attach: function (context, settings) {
1252            once('homeBannerSlick', '#block-views-block-homepage-block-1', document).forEach(function (el) {
1253                $(el).find('.views-field-field-image .field-content').slick({
1254                    arrows: false,
1255                    slidesToShow: 1,
1256                    slidesToScroll: 1,
1257                    autoplay: true,
1258                    autoplaySpeed: 5000,
1259                    speed: 300,
1260                    infinite: true,
1261                    fade: true,
1262                    cssEase: 'ease',
1263                    pauseOnHover: false,
1264                    pauseOnFocus: false
1265                });
1266            });
1267        }
1268    };
1269
1270    /*
1271    * Facebook feed responsive
1272    */
1273    Drupal.behaviors.FacebookFeedResponsive = {
1274        attach: function (context, settings) {
1275            if ($('.feeds-contents-social').length || $('.feeds-contents-social-front').length) {
1276                $(window).on('resize', function() {
1277                    setTimeout(function(){facebookFeedResponsive()}, 500);
1278                });
1279
1280                $(window).on('load', function() {
1281                    setTimeout(function(){facebookFeedResponsive()}, 1500);
1282                });
1283
1284                var facebookFeedResponsive = function () {
1285                    //getting parent box width
1286                    var container_width = Number($('.block-feeds-block').width()).toFixed(0) - 40;
1287                    var container_height = Number($('.block-feeds-block').height()).toFixed(0) - 40;
1288                    if (!isNaN(container_width)) {
1289                        $(".fb-page").attr("data-width", container_width).attr("data-height", container_height);
1290                    }
1291                    if (typeof FB !== 'undefined' ) {
1292                        FB.XFBML.parse();
1293                    }
1294                }
1295            }
1296        }
1297    };
1298
1299    /*
1300    * Glueup profile menu
1301    */
1302    Drupal.behaviors.GlueupProfileMenu = {
1303        attach: function (context, settings) {
1304            if($('.header-profile').length){
1305                once('GlueupProfileMenu', 'html').forEach(function (element) {
1306                    $('.header-profile').on('click', function(e){
1307                        $(this).find('.profile-menu').toggle();
1308                        $(this).find('.glueup-profile').toggleClass('active');
1309                    });
1310
1311                    $(document).on('click', function(event) {
1312                        if (!$(event.target).closest('.header-profile').length) {
1313                            //This code will run when the click is outside '.header-profile'
1314                            $('.profile-menu').hide();
1315                            $('.glueup-profile').removeClass('active');
1316                        }
1317                    });
1318                    
1319                    $('#profile-menu-main li a').click(function() {
1320                        $('.profile-menu').toggle();
1321                        $('.glueup-profile').toggleClass('active');
1322                    });
1323                });
1324            }
1325        }
1326    };
1327
1328    /*
1329    * Calendar Link
1330    */
1331    Drupal.behaviors.CalendarLink = {
1332        attach: function (context, settings) {
1333            function openCalendar($widget) {
1334                $('.event-add-calendar .calendar-text-icon').hide();
1335                $('.event-add-calendar .calendar-image a').attr('aria-expanded', 'false');
1336                var $panel = $widget.find('.calendar-text-icon');
1337                var isOpen = $panel.is(':visible');
1338                $panel.toggle();
1339                $widget.find('.calendar-image a').attr('aria-expanded', isOpen ? 'false' : 'true');
1340                if (!isOpen) {
1341                    // Move focus into the panel for keyboard users.
1342                    $panel.find('a').first().focus();
1343                }
1344            }
1345            function closeCalendar($widget) {
1346                $widget.find('.calendar-text-icon').hide();
1347                var $trigger = $widget.find('.calendar-image a');
1348                $trigger.attr('aria-expanded', 'false').focus();
1349            }
1350
1351            $(once('calendar-link-handlers', 'body')).each(function () {
1352                $(document).on('click keydown', '.event-add-calendar .calendar-image a', function(e){
1353                    if (e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ') { return; }
1354                    e.preventDefault();
1355                    openCalendar($(this).closest('.event-add-calendar'));
1356                });
1357
1358                $(document).on('click', function(event) {
1359                    if (!$(event.target).closest('.event-add-calendar').length) {
1360                        $('.event-add-calendar .calendar-text-icon').hide();
1361                        $('.event-add-calendar .calendar-image a').attr('aria-expanded', 'false');
1362                    }
1363                });
1364
1365                $(document).on('click keydown', '.event-add-calendar .close-icon', function(e){
1366                    if (e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ') { return; }
1367                    e.preventDefault();
1368                    closeCalendar($(this).closest('.event-add-calendar'));
1369                });
1370
1371                $(document).on('keydown.calendar-panel', function(e) {
1372                    if (e.key === 'Escape' && $('.event-add-calendar .calendar-text-icon:visible').length) {
1373                        e.stopPropagation();
1374                        closeCalendar($('.event-add-calendar .calendar-text-icon:visible').closest('.event-add-calendar'));
1375                    }
1376                });
1377            });
1378        }
1379    };
1380
1381    /*
1382    * Event share
1383    */
1384    Drupal.behaviors.EventShare = {
1385        attach: function (context, settings) {
1386            function openShare($widget) {
1387                $('.event-share .share-text-icon').hide();
1388                $('.event-share .share-image a').attr('aria-expanded', 'false');
1389                var $panel = $widget.find('.share-text-icon');
1390                var isOpen = $panel.is(':visible');
1391                $panel.toggle();
1392                $widget.find('.share-image a').attr('aria-expanded', isOpen ? 'false' : 'true');
1393                if (!isOpen) {
1394                    $panel.find('a').first().focus();
1395                }
1396            }
1397            function closeShare($widget) {
1398                $widget.find('.share-text-icon').hide();
1399                var $trigger = $widget.find('.share-image a');
1400                $trigger.attr('aria-expanded', 'false').focus();
1401            }
1402
1403            $(once('event-share-handlers', 'body')).each(function () {
1404                $(document).on('click keydown', '.event-share .share-image a', function(e){
1405                    if (e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ') { return; }
1406                    e.preventDefault();
1407                    openShare($(this).closest('.event-share'));
1408                });
1409
1410                $(document).on('click', function(event) {
1411                    if (!$(event.target).closest('.event-share').length) {
1412                        $('.event-share .share-text-icon').hide();
1413                        $('.event-share .share-image a').attr('aria-expanded', 'false');
1414                    }
1415                });
1416
1417                $(document).on('click keydown', '.event-share .close-icon', function(e){
1418                    if (e.type === 'keydown' && e.key !== 'Enter' && e.key !== ' ') { return; }
1419                    e.preventDefault();
1420                    closeShare($(this).closest('.event-share'));
1421                });
1422
1423                $(document).on('keydown.share-panel', function(e) {
1424                    if (e.key === 'Escape' && $('.event-share .share-text-icon:visible').length) {
1425                        e.stopPropagation();
1426                        closeShare($('.event-share .share-text-icon:visible').closest('.event-share'));
1427                    }
1428                });
1429            });
1430        }
1431    };
1432
1433})(jQuery, Drupal);

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.