PageSourceSearch

https://nadiesolo.org/wp-content/themes/twentytwentyone-child/boo/js/blog.js?ver=7.0.3.1791415070

js nadiesolo.org collected 2026-10-10 00:46:01 UTC 3,555 bytes, 110 lines download raw bytes

1(function ($) {
2  $(function () {
3    var $tabs        = $('ul.menu-tabs');
4    var $form        = $('form.form-buscador');
5    var $input       = $form.find('input[name="s"]');
6    var $hiddenTag   = $('#filter-tag');
7    var $dropdown    = $('#tag-dropdown');
8    var $resultsWrap = $('.blog-search-results');
9
10    function doSearch(page = 1) {
11      const currentTab = $tabs.find('li.active').data('id');
12      const rawS       = ($input.val() || '').trim();
13      const tagSlug    = (($hiddenTag.val() || '') + '').trim();
14
15      // Si hay tag => buscamos en "todos"
16      const tabToSend  = tagSlug ? 'todos' : currentTab;
17      const sToSend    = tagSlug ? '' : rawS;
18
19      $.ajax({
20        url:  BlogSearchAjax.ajax_url,
21        type: 'POST',
22        data: {
23          action:      'blog_search',
24          _ajax_nonce: BlogSearchAjax.nonce,
25          tab:         tabToSend,
26          s:           sToSend,
27          tag:         tagSlug,
28          paged:       page
29        },
30        beforeSend() { $resultsWrap.addClass('loading'); },
31        success(html) {
32          $resultsWrap.removeClass('loading').html(html);
33          const noResults = $resultsWrap.find('[data-noresults="1"]').length > 0;
34          const $msg = $('.post-search .no-results-message');
35          $msg.toggle(noResults);
36        }
37      });
38    }
39
40    // Tabs
41    $tabs.on('click', 'li', function (e) {
42      e.preventDefault();
43      $input.val('');
44      $hiddenTag.val('');
45      $dropdown.find('.tag-dropdown__item.active').removeClass('active');
46      $tabs.find('li').removeClass('active');
47      $(this).addClass('active');
48      doSearch(1);
49    });
50
51    // Submit
52    $form.on('submit', function (e) {
53      e.preventDefault();
54      doSearch(1);
55    });
56
57    // Paginación (delegada)
58    $(document).on('click', '.post-search-pagination a', function (e) {
59      e.preventDefault();
60      e.stopImmediatePropagation();
61      const href = $(this).attr('href');
62      const url  = new URL(href, window.location.origin);
63      const page = parseInt(url.searchParams.get('paged') || '1', 10);
64      doSearch(page);
65    });
66
67    // Dropdown tags
68    $input.on('focus', function () { $dropdown.show(); });
69    $(document).on('click', function (e) {
70      if (!$input.is(e.target) && $input.has(e.target).length === 0 &&
71          !$dropdown.is(e.target) && $dropdown.has(e.target).length === 0) {
72        $dropdown.hide();
73      }
74    });
75    $(document).on('keydown', function (e) {
76      if (e.key === 'Escape') $dropdown.hide();
77    });
78
79    // Click en tag: activar "todos" y buscar por tag global
80    $dropdown.on('click', '.tag-dropdown__item', function () {
81      const slug  = (($(this).data('tag') || '') + '').trim();
82      const label = (($(this).text() || '').replace(/\s+/g, ' ')).trim();
83
84      $dropdown.find('.tag-dropdown__item.active').removeClass('active');
85      $(this).addClass('active');
86
87      // set tag + texto en input
88      $hiddenTag.val(slug);
89      $input.val(label);
90
91      // activar pestaña "todos" en UI
92      $tabs.find('li').removeClass('active');
93      $tabs.find('li[data-id="todos"]').addClass('active');
94
95      doSearch(1);
96    });
97
98    // Restablecer
99    $('.post-search__title').css('cursor', 'pointer').on('click', function () {
100      $input.val('');
101      $hiddenTag.val('');
102      $dropdown.find('.tag-dropdown__item.active').removeClass('active');
103      $tabs.find('li').removeClass('active');
104      $tabs.find('li[data-id="todos"]').addClass('active');
105      doSearch(1);
106    });
107
108    doSearch(1);
109  });
110})(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.