PageSourceSearch

https://menarights.org/themes/ak_theme/js/ak_select.js?tm6le8

js menarights.org collected 2026-10-02 06:20:48 UTC 14,196 bytes, 274 lines download raw bytes

1/**
2 * @file
3 * Custom theme behaviors: select‑picker styling and site‑wide enhancements.
4 */
5(function (Drupal, once, $) {
6  'use strict';
7
8  /**
9   * Applies bootstrap-select styling to specific Views forms.
10   */
11  Drupal.behaviors.akSelectStyles = {
12    attach: function (context, settings) {
13      // 1) Reports form.
14      once('ak-select-reports', '#views-exposed-form-ak-reports-reports', context)
15        .forEach(function (formEl) {
16          $('select', formEl).addClass('selectpicker');
17        });
18
19      // 2) Latest‑home articles form.
20      once('ak-select-articles', '#views-exposed-form-ak-articles-latest-home', context)
21        .forEach(function (formEl) {
22          $('select', formEl).addClass('selectpicker');
23        });
24    }
25  };
26
27  /**
28   * All the rest of your site‑wide jQuery tweaks run once per page load.
29   */
30  Drupal.behaviors.akSiteEnhancements = {
31    attach: function (context, settings) {
32      once('ak-site-enhancements', 'body', context).forEach(function () {
33        // — Language switcher URLs
34        var currentURL = window.location.href;
35        var arLink, enLink;
36        if (currentURL.includes('/en/')) {
37          arLink = currentURL.replace('/en/', '/ar/');
38          enLink = currentURL;
39        } else {
40          arLink = currentURL;
41          enLink = currentURL.replace('/ar/', '/en/');
42        }
43
44        // — Reports form conditional fields
45        function reportsForm(val) {
46          var $form = $('#views-exposed-form-ak-reports-reports');
47          switch (val) {
48            case '7':
49              $form.find('.form-item-body, .form-item-country').show();
50              break;
51            case '40':
52              $form.find('.form-item-body select').val('All').end()
53                   .find('.form-item-body').hide()
54                   .end().find('.form-item-country').show();
55              break;
56            case '39':
57              $form.find('.form-item-body select').val('All').end()
58                   .find('.form-item-body').hide()
59                   .end().find('.form-item-country select').val('All').end()
60                   .find('.form-item-country').hide();
61              break;
62            default:
63              if ($form.find('.form-item-body select').val() === 'All') {
64                $form.find('.form-item-body').hide();
65              }
66              if ($form.find('.form-item-country select').val() === 'All') {
67                $form.find('.form-item-country').hide();
68              }
69              break;
70          }
71        }
72
73        // Initialize on load
74        var initVal = $('#views-exposed-form-ak-reports-reports .form-item-type select').val();
75        reportsForm(initVal);
76
77        // Attach change handler once
78        once('ak-select-doc-type', '#views-exposed-form-ak-reports-reports .form-item-type select', context)
79          .forEach(function (el) {
80            $(el).on('change', function (e) {
81              reportsForm(e.target.value);
82            });
83          });
84
85        // — Gallery thumbnail logic
86        var gallercount = $('.field-gallery-thumbs > a').length;
87        if (gallercount === 1) {
88          $('.case-slider .field-gallery .field-gallery-thumbs')
89            .css('display', 'none')
90            .find('a:first').css('display', 'none');
91        }
92
93        // — Hide empty “more country” block
94        if (!$.trim($('.view-more-country-for-article-landing-page').html())) {
95          $('.block-views-blockmore-country-for-article-landing-page-block-1').hide();
96        }
97
98        // — Append “Latest Update” to region headings
99        ['.latest_gulf', '.latest_Mashreq', '.latest_Maghreb'].forEach(function (sel) {
100          var $h3 = $(sel + ' .view-content .item-list h3');
101          $h3.text($h3.text() + ' Latest Update');
102        });
103
104        // — Reposition home cases view
105        $('.view-latest-home-cases')
106          .insertBefore('.field--name-dynamic-block-fieldtaxonomy-term-articles-per-country');
107
108        // — Page header & inserts
109        $('.path-reports .region-header .page-header').text('Latest reports');
110        $('.taxonomy-term--type-ak-country .view-latest-home-cases')
111          .before('<div class="countreport">Latest Cases</div>');
112        $('.view-id-ak_reports .view-filters')
113          .before('<div class="searchreport">Search reports</div>');
114        $('#views-exposed-form-ak-reports-reports .form-item-type .filter-option.pull-left')
115          .text('Type of Report');
116
117        // — Show report menu on /reports or /contact
118        if ($('body').hasClass('path-reports') || $('body').hasClass('path-contact')) {
119          $('.report_menu').show();
120        }
121
122        // — Hide AK Events & Campaigns content regions
123        if ($('#block-views-block-ak-events-block-1').length ||
124            $('#block-views-block-campaigns-block-1').length) {
125          $('.region-content .page, .middle_cntent').hide();
126        }
127
128        // — Always hide French switcher
129        $('#block-languageswitcher-3 .fr').hide();
130
131        // — Country block‑title replacement
132        var countryText = $('.field--name-field-ak-countries .field--item').text();
133        $('.block-views-blockmore-country-for-article-landing-page-block-1 h2.block-title')
134          .text(function () {
135            return $(this).text().replace('Country', countryText);
136          });
137        $('html[lang=ar] .block-views-blockmore-country-for-article-landing-page-block-1 h2.block-title')
138          .text(function () {
139            return $(this).text()
140              .replace('Country', countryText)
141              .replace('More on', 'المزيد عن');
142          });
143
144        // — Arabic‑specific tweaks
145        if ($('.logo.pull-left').attr('href') === '/ar') {
146          $('.block-views-blockhome-page-report-block-1 .block-title').css('margin-right', '96px');
147          $('.region-sidebar-report .block-twitter-block .block-title').css('padding-right', '35px');
148          $('.report_section').addClass('arbic');
149          $('body').addClass('arbic');
150          $('.path-reports .region-header .page-header').replaceWith('آخر التقارير');
151          $('.countreport').replaceWith("<div class='countreport'>أحدث الحالات</div>");
152          $(".field--name-dynamic-block-fieldtaxonomy-term-articles-per-country .field--label")
153            .replaceWith("<div class='field--label'>أحدث الأخبار</div>");
154          $("#main-menu-link-contentab9f3aa1-87b8-4543-9208-56a59ca71335 a").text("الحالات");
155          $(".contact-message-need-help-form #group-applicant-information .panel-title")
156            .text("بيانات مقدم الطلب");
157          $(".contact-message-need-help-form .panel-body .help-block")
158            .text("إذا تعرضت أنت أو أحد معارفك لانتهاك حقوقك الإنسانية، أو إذا كنت محاميا لأحد ضحايا انتهاك حقوق الإنسان، الرجاء الإجابة على الأسئلة التالية لمساعدتنا على تقييم ما إذا كان في وسعنا مساعدتك");
159          $(".contact-message-need-help-form #bootstrap-panel--2 .panel-title").text("هوية الضحية");
160          $(".contact-message-need-help-form #bootstrap-panel--3 .panel-title").text("طبيعة الانتهاك");
161          $(".contact-message-need-help-form .field--type-string .form-item-field-i-0-value .control-label")
162            .text("إذا كان آخر ، يرجى تقديم التفاصيل");
163          $('.maintop.en').hide();
164          $('.maintop.ar').show();
165          setTimeout(function () {
166            $(".form-search.form-control")
167              .attr("placeholder", "أدخل العبارات التي تريد البحث عنها.");
168            $('#views-exposed-form-ak-reports-reports .form-type-select .dropdown-menu li:first')
169              .text('- أي -');
170          }, 2000);
171          $('#edit-field-country-target-id option[value="All"]').text('- أي -');
172          $('.path-reports .view-ak-reports .searchreport')
173            .replaceWith("<div class='searchreport'>
173تقارير البحث</div>");
174          $('.path-reports #block-mainnavigationarabic').hide();
175
176          // — Month name translation
177          var month = $('.article-main .date .month').html().trim();
178          var monthMap = {
179            'January': 'كانون الثاني',    'February': 'شهر فبراير',
180            'March':   'مارس',            'April':   'أبريل',
181            'May':     'قد',              'June':    'يونيو',
182            'July':    'يوليو',           'August':  'أغسطس',
183            'September':'سبتمبر',         'October': 'شهر اكتوبر',
184            'November':'نوفمبر',         'December':'ديسمبر'
185          };
186          var monthval = monthMap[month] || 'ديسمبر';
187          var day  = $('.article-main .date .dat').html();
188          var year = $('.article-main .date .year').html();
189          $(".article-main .date.arbic")
190            .html("<span class='month'>" + monthval + "</span>&nbsp;<span class='dat'>" + day + "</span>&nbsp;<span class='year'>" + year + "</span>");
191          $('.article-main .date.eng').hide();
192        }
193
194        // — Donation button text
195        $('.comment-comment-form .form-submit').text('Click to Donate');
196
197        // — Add class for latest news view
198        if ($('.view-latest-news').hasClass('view-id-latest_news')) {
199          $('body').addClass('case_body');
200        }
201
202        // — Ensure Font Awesome is loaded
203        if (!$('head link[href*="font-awesome"]').length) {
204          $('head').append(
205            '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" type="text/css" />'
206          );
207        }
208
209        // — Social & date wraps on document pages
210        $('.page-node-type-ak-document .se-block, .page-node-type-ak-document .field--name-field-ak-file')
211          .wrapAll('<div class="document_social"></div>');
212        $('.page-node-type-ak-document .field--name-field-ak-pub-date, .page-node-type-ak-document .page-header')
213          .wrapAll('<div class="date_title"></div>');
214        $('.date_title').detach().appendTo('.page-node-type-ak-document .field--name-field-image');
215        $('.page-node-type-ak-document .date_title .field--name-field-ak-pub-date')
216          .detach().insertBefore('.page-node-type-ak-document .date_title .page-header');
217
218        // — Wrap taxonomy term regions
219        $('.taxonomy-term--type-ak-country .bs-region--middle, .taxonomy-term--type-ak-country .bs-region--bottom')
220          .wrapAll('<div class="child_merge"></div>');
221        $('.taxonomy-term--type-ak-country .bs-region--top-left, .taxonomy-term--type-ak-country .bs-region--top-right')
222          .wrapAll('<div class="child_merge_top"></div>');
223        $('.taxonomy-term--type-ak-topics .field--name-description')
224          .wrapAll('<div class="topic_child"></div>');
225        $('.taxonomy-term--type-ak-topics .field--name-dynamic-block-fieldtaxonomy-term-by-region-by-topic')
226          .wrapAll('<div class="topic_child_top"></div>');
227
228        // — Newsletter + map side by side
229        $('#block-newsletter,#block-ak-map').wrapAll('<div class="newsletter-half"></div>');
230
231        // — Wrap bootstrap panels
232        $('#bootstrap-panel .panel-heading, #bootstrap-panel .panel-body').wrapAll('<div class="human-inner"></div>');
233        $('#bootstrap-panel--2 .panel-heading, #bootstrap-panel--2 .panel-body').wrapAll('<div class="human-inner"></div>');
234        $('#bootstrap-panel--3 .panel-heading, #bootstrap-panel--3 .panel-body').wrapAll('<div class="human-inner"></div>');
235        $('#bootstrap-panel--4 .panel-heading, #bootstrap-panel--4 .panel-body').wrapAll('<div class="human-inner"></div>');
236        $('#bootstrap-panel--5 .panel-heading, #bootstrap-panel--5 .panel-body').wrapAll('<div class="human-inner"></div>');
237
238        // — Wrap country email block
239        $('.col-sm-3.bs-region.bs-region--top-right .field--type-email')
240          .wrapAll('<div class="country_right_inner_b"></div>');
241
242        // — Move footer logo before newsletter block
243        $('#block-footerlogo').detach().insertBefore('#block-newsletter');
244
245        // — Sort country dropdowns alphabetically
246        $('#edit-field-country-target-id').append(
247          $('#edit-field-country-target-id option').remove().sort(function (a, b) {
248            return $(a).text() > $(b).text() ? 1 : -1;
249          })
250        );
251        $('#edit-field-country-target-id option[value="All"]').prop('selected', true);
252
253        $('#edit-field-ak-country-target-id').append(
254          $('#edit-field-ak-country-target-id option').remove().sort(function (a, b) {
255            return $(a).text() > $(b).text() ? 1 : -1;
256          })
257        );
258        $('#edit-field-ak-country-target-id option[value="All"]').prop('selected', true);
259
260        // — Translate “All” in Arabic
261        $('html[lang=ar] option[value="All"]').html('- أي -');
262
263        // — Translate contact/need_help form panels
264        $('html[lang="ar"] #trans-applicant-information .panel-title')
265          .text('معلومات مقدم الطلب');
266        $('html[lang="ar"] #trans-applicant-information--description')
267          .text('إذا كنت أنت أو قريبك ضحية لانتهاك حقوق الإنسان ، أو إذا كنت محاميًا لضحية انتهاك حقوق الإنسان ، فيرجى الإجابة على الأسئلة التالية لمساعدتنا في تقييم ما إذا كان بإمكاننا تقديم المساعدة لك.');
268        $('html[lang="ar"] #trans-identity-of-the-victim .panel-title').text('هوية الضحية');
269        $('html[lang="ar"] #trans-nature-of-the-violation .panel-title').text('طبيعة الإنتهاك');
270      });
271    }
272  };
273
274})(Drupal, once, jQuery);

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.