PageSourceSearch

http://verticalurbanism.org/wp-content/themes/mds-multiple-theme/assets/js/company-table.js?ver=1.0

js verticalurbanism.org collected 2026-09-25 03:55:37 UTC 10,655 bytes, 303 lines download raw bytes

1jQuery(function ($) {
2  // State
3  let currentOrderBy = '';   
4  let currentOrder = 'ASC';
5
6  // || build pagination
7  // function buildPagination(totalPages, current, $container) {
8  //   let html = '';
9  //   if (totalPages <= 1) { $container.html(''); return; }
10
11  //   if (current > 3) html += `<a href="#" class="page-link first" data-page="1">&laquo;</a> `;
12  //   if (current > 1) html += `<a href="#" class="page-link prev" data-page="${current - 1}">&lt;</a> `;
13
14  //   const start = Math.max(1, current - 2);
15  //   const end = Math.min(totalPages, current + 2);
16  //   for (let i = start; i <= end; i++) {
17  //     html += (i === current)
18  //       ? `<span class="current-page">${i}</span> `
19  //       : `<a href="#" class="page-link" data-page="${i}">${i}</a> `;
20  //   }
21
22  //   if (current < totalPages) html += `<a href="#" class="page-link next" data-page="${current + 1}">&gt;</a> `;
23  //   if (current < totalPages - 2) html += `<a href="#" class="page-link last" data-page="${totalPages}">&raquo;</a>`;
24
25  //   $container.html(html);
26  // }
27  // || 
28  function buildPagination(totalPages, current, $container, padding = 2) {
29  if (totalPages <= 1) { 
30    $container.html(''); 
31    return; 
32  }
33
34  let pages = [];
35
36  // Always show first
37  pages.push({
38    label: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
39              <path d="M5.82843 11.9928L12.8284 4.99283L11.4142 3.57861L3 11.9928L11.4142 20.407L12.8284 18.9928L5.82843 11.9928Z" fill="#737373"/>
40              <path d="M13.8284 11.9928L20.8284 4.99283L19.4142 3.57861L11 11.9928L19.4142 20.407L20.8284 18.9928L13.8284 11.9928Z" fill="#737373"/>
41            </svg>`, 
42    page: 1, 
43    type: 'chevron'
44  });
45
46  // Previous
47  if (current > 1) {
48    pages.push({
49      label: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
50                <path d="M9.41436 11.9928L16.4144 4.99283L15.0001 3.57861L6.58594 11.9928L15.0002 20.407L16.4144 18.9928L9.41436 11.9928Z" fill="#737373"/>
51              </svg>`,
52      page: current - 1,
53      type: 'chevron'
54    });
55  }
56
57  // Left ellipsis
58  if (current > padding + 2) {
59    pages.push({ label: '…', page: null });
60  }
61
62  // Middle range
63  let start, end;
64  if (current <= padding + 1) {
65    start = 1;
66    end = Math.min(totalPages, padding * 2 + 1);
67  } else if (current >= totalPages - padding) {
68    start = Math.max(1, totalPages - padding * 2);
69    end = totalPages;
70  } else {
71    start = current - padding;
72    end = current + padding;
73  }
74
75  for (let i = start; i <= end; i++) {
76    pages.push({ label: i, page: i });
77  }
78
79  // Right ellipsis
80  if (current < totalPages - padding - 1) {
81    pages.push({ label: '…', page: null });
82  }
83
84  // Next
85  if (current < totalPages) {
86    pages.push({
87      label: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
88                <path d="M9.00015 3.57861L7.58594 4.99283L14.5859 11.9928L7.58594 18.9928L9.00015 20.407L17.4144 11.9928L9.00015 3.57861Z" fill="#FCFCFC"/>
89              </svg>`,
90      page: current + 1,
91      type: 'chevron'
92    });
93  }
94
95  // Always show last
96  pages.push({
97    label: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
98              <path d="M17.9997 11.993L10.9997 18.993L12.4139 20.4072L20.8281 11.993L12.4139 3.5788L10.9997 4.99301L17.9997 11.993Z" fill="#FCFCFC"/>
99              <path d="M9.9997 11.993L2.9997 18.993L4.41391 20.4072L12.8281 11.993L4.41391 3.5788L2.9997 4.99301L9.9997 11.993Z" fill="#FCFCFC"/>
100            </svg>`,
101    page: totalPages,
102    type: 'chevron'
103  });
104
105  // Render HTML
106  let html = '<div class="custom-pagination">';
107  pages.forEach(p => {
108    if (p.page === null) {
109      html += `<span class="ellipsis">${p.label}</span>`;
110    } else {
111      html += `<button 
112                 class="page-btn ${p.type === 'chevron' ? 'chevron' : ''} ${p.page === current ? 'active' : ''}" 
113                 data-page="${p.page}">
114                 ${p.label}
115               </button>`;
116    }
117  });
118  html += '</div>';
119
120  $container.html(html);
121
122  // Click handlers
123  $container.find('.page-btn').on('click', function() {
124    const targetPage = Number($(this).data('page'));
125    buildPagination(totalPages, targetPage, $container, padding);
126    // trigger your data load function here for page "targetPage"
127  });
128}
129
130
131  // ========== Load Companies ==========
132  function loadCompanies(page = 1) {
133    const levels = $('.level-checkbox:checked')
134      .map(function(){ return $(this).val(); })
135      .get();
136
137      const expertise = $('.expertise-checkbox:checked')
138      .map(function(){ return $(this).val(); })
139      .get();
140
141    $('.companies-table').show(); $('.experts-table').hide(); $('.members-table').hide();
142    $('.companies-pagination').show(); $('.experts-pagination').hide(); $('.members-pagination').hide();
143    $('#companies-filters').show(); $('#experts-filters').hide(); $('#individuals-filters').hide();
144
145    $.ajax({
146      url: ajax_object.ajax_url,
147      method: 'POST',
148      data: {
149        action: 'load_companies',
150        page: page,
151        orderby: currentOrderBy,
152        order: currentOrder,
153        levels: levels,
154        expertise: expertise
155      },
156      success: function(response) {
157        if (response.success && response.data && response.data.html) {
158            // Figure out which table is active
159            let activeTable;
160    
161            if (document.querySelector('.companies-table').style.display !== "none") {
162                activeTable = document.querySelector('.companies-table');
163            } else if (document.querySelector('.experts-table').style.display !== "none") {
164                activeTable = document.querySelector('.experts-table');
165            } else if (document.querySelector('.members-table').style.display !== "none") {
166                activeTable = document.querySelector('.members-table');
167            }
168    
169            if (activeTable) {
170                // Remove old rows except the header
171                activeTable.querySelectorAll('.table-row:not(.table-row-head)').forEach(el => el.remove());
172    
173                // Insert new rows after header
174              activeTable.insertAdjacentHTML('beforeend', response.data.html);
175            } else {
176                console.error("No active table found");
177            }
178        } else {
179            console.error("Unexpected response format:", response);
180        }
181    }
182    
183    });
184  }
185
186
187  // ========== Load Experts ==========
188  function loadExperts(page = 1) {
189    $('.experts-table').show(); $('.companies-table').hide(); $('.members-table').hide();
190    $('.experts-pagination').show(); $('.companies-pagination').hide(); $('.members-pagination').hide();
191    $('#companies-filters').hide(); $('#experts-filters').show(); $('#individuals-filters').hide();
192
193    $.ajax({
194      url: ajax_object.ajax_url,
195      method: 'POST',
196      data: {
197        action: 'load_experts',
198        page: page,
199        orderby: currentOrderBy,
200        order: currentOrder,
201      },
202      success: function (response) {
203        if (response.success) {
204          const $table = $('.experts-table');
205          $table.find('.table-row:not(.table-row-head)').remove();
206          $table.append(response.data.html);
207          buildPagination(response.data.total_pages, response.data.current_page, $('.experts-pagination'));
208        }
209      }
210    });
211  }
212
213  // ========== Load Individual Members ==========
214  function loadIndividuals(page = 1) {
215    $('.members-table').show(); $('.experts-table').hide(); $('.companies-table').hide();
216    $('.members-pagination').show(); $('.experts-pagination').hide(); $('.companies-pagination').hide();
217    $('#companies-filters').hide(); $('#experts-filters').hide(); $('#individuals-filters').show();
218
219    $.ajax({
220      url: ajax_object.ajax_url,
221      method: 'POST',
222      data: {
223        action: 'load_individual',
224        page: page,
225        orderby: currentOrderBy,
226        order: currentOrder,
227      },
228      success: function (response) {
229        if (response.success) {
230          const $table = $('.members-table');
231          $table.find('.table-row:not(.table-row-head)').remove();
232          $table.append(response.data.html);
233          buildPagination(response.data.total_pages, response.data.current_page, $('.members-pagination'));
234        }
235      }
236    });
237  }
238
239  // ===== Tab click handlers =====
240  $('#companies-tab').on('click', function(){ 
241    currentOrderBy = ''; currentOrder = 'ASC';
242    $('.filter__chip-container').height("0px");
243    loadCompanies(1); 
244  });
245  $('#experts-tab').on('click', function(){ 
246    currentOrderBy = ''; currentOrder = 'ASC';
247    $('.filter__chip-container').height("0px");
248    loadExperts(1); 
249  });
250  $('#members-tab').on('click', function(){ 
251    currentOrderBy = ''; currentOrder = 'ASC';
252    $('.filter__chip-container').height("0px");
253    loadIndividuals(1); 
254  });
255
256  // ===== Pagination click handler =====
257  $(document).on('click', '.pagination .page-link', function(e){
258    e.preventDefault();
259    const page = parseInt($(this).data('page'), 10) || 1;
260    const $pagination = $(this).closest('.pagination');
261
262    if ($pagination.hasClass('companies-pagination')) loadCompanies(
262page);
263    else if ($pagination.hasClass('experts-pagination')) loadExperts(page);
264    else if ($pagination.hasClass('members-pagination')) loadIndividuals(page);
265  });
266
267  // ===== Sort handler =====
268  $(document).on('click', '.table-row.table-row-head .table-cell.sortable', function() {
269    const $cell = $(this);
270    const sortField = $cell.data('sort');
271    if (!sortField) return;
272
273    if (currentOrderBy === sortField) {
274      currentOrder = currentOrder === 'ASC' ? 'DESC' : 'ASC';
275    } else {
276      currentOrderBy = sortField;
277      currentOrder = 'ASC';
278    }
279
280    $('.table-row.table-row-head .table-cell.sortable').removeClass('sort-asc sort-desc');
281    $cell.addClass(currentOrder === 'ASC' ? 'sort-asc' : 'sort-desc');
282
283    if ($('.companies-table').is(':visible')) loadCompanies(1);
284    else if ($('.experts-table').is(':visible')) loadExperts(1);
285    else if ($('.members-table').is(':visible')) loadIndividuals(1);
286  });
287
288
289  $(document).on('change', '.level-checkbox, .expertise-checkbox', function() {
290    // Determine which table is visible
291    if ($('.companies-table').is(':visible')) {
292        loadCompanies(1);
293    } else if ($('.experts-table').is(':visible')) {
294        loadExperts(1);
295    } else if ($('.members-table').is(':visible')) {
296        loadIndividuals(1);
297    }
298});
299
300
301  // ===== Initial load =====
302  loadCompanies(1);
303});

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.