PageSourceSearch

https://tribunalconstitucional.ao/scripts/excel-bootstrap-table-filter-bundle.js

js tribunalconstitucional.ao collected 2026-10-02 11:31:07 UTC 14,968 bytes, 357 lines download raw bytes

1(function ($$1) {
2'use strict';
3
4$$1 = 'default' in $$1 ? $$1['default'] : $$1;
5
6var FilterMenu = function () {
7    function FilterMenu(target, th, column, index, options) {
8        this.options = options;
9        this.th = th;
10        this.column = column;
11        this.index = index;
12        this.tds = target.find('tbody tr td:nth-child(' + (this.column + 1) + ')').toArray();
13    }
14    FilterMenu.prototype.initialize = function () {
15        this.menu = this.dropdownFilterDropdown();
16        this.th.appendChild(this.menu);
17        var $trigger = $(this.menu.children[0]);
18        var $content = $(this.menu.children[1]);
19        var $menu = $(this.menu);
20        $trigger.click(function () {
21            return $content.toggle();
22        });
23        $(document).click(function (el) {
24            if (!$menu.is(el.target) && $menu.has(el.target).length === 0) {
25                $content.hide();
26            }
27        });
28    };
29    FilterMenu.prototype.searchToggle = function (value) {
30        if (this.selectAllCheckbox instanceof HTMLInputElement) this.selectAllCheckbox.checked = false;
31        if (value.length === 0) {
32            this.toggleAll(true);
33            if (this.selectAllCheckbox instanceof HTMLInputElement) this.selectAllCheckbox.checked = true;
34            return;
35        }
36        this.toggleAll(false);
37        this.inputs.filter(function (input) {
38            return input.value.toLowerCase().indexOf(value.toLowerCase()) > -1;
39        }
39).forEach(function (input) {
40            input.checked = true;
41        });
42    };
43    FilterMenu.prototype.updateSelectAll = function () {
44        if (this.selectAllCheckbox instanceof HTMLInputElement) {
45            $(this.searchFilter).val('');
46            this.selectAllCheckbox.checked = this.inputs.length === this.inputs.filter(function (input) {
47                return input.checked;
48            }).length;
49        }
50    };
51    FilterMenu.prototype.selectAllUpdate = function (checked) {
52        $(this.searchFilter).val('');
53        this.toggleAll(checked);
54    };
55    FilterMenu.prototype.toggleAll = function (checked) {
56        for (var i = 0; i < this.inputs.length; i++) {
57            var input = this.inputs[i];
58            if (input instanceof HTMLInputElement) input.checked = checked;
59        }
60    };
61    FilterMenu.prototype.dropdownFilterItem = function (td, self) {
62        var value = td.innerText;
63        var dropdownFilterItem = document.createElement('div');
64        dropdownFilterItem.className = 'dropdown-filter-item';
65        var input = document.createElement('input');
66        input.type = 'checkbox';
67        input.value = value.trim().replace(/ +(?= )/g, '');
68        input.setAttribute('checked', 'checked');
69        input.className = 'dropdown-filter-menu-item item';
70        input.setAttribute('data-column', self.column.toString());
71        input.setAttribute('data-index', self.index.toString());
72        dropdownFilterItem.appendChild(input);
73        dropdownFilterItem.innerHTML = dropdownFilterItem.innerHTML.trim() + ' ' + value;
74        return dropdownFilterItem;
75    };
76    FilterMenu.prototype.dropdownFilterItemSelectAll = function () {
77        var value = this.options.captions.select_all;
78        var dropdownFilterItemSelectAll = document.createElement('div');
79        dropdownFilterItemSelectAll.className = 'dropdown-filter-item';
80        var input = document.createElement('input');
81        input.type = 'checkbox';
82        input.value = this.options.captions.select_all;
83        input.setAttribute('checked', 'checked');
84        input.className = 'dropdown-filter-menu-item select-all';
85        input.setAttribute('data-column', this.column.toString());
86        input.setAttribute('data-index', this.index.toString());
87        dropdownFilterItemSelectAll.appendChild(input);
88        dropdownFilterItemSelectAll.innerHTML = dropdownFilterItemSelectAll.innerHTML + ' ' + value;
89        return dropdownFilterItemSelectAll;
90    };
91    FilterMenu.prototype.dropdownFilterSearch = function () {
92        var dropdownFilterItem = document.createElement('div');
93        dropdownFilterItem.className = 'dropdown-filter-search';
94        var input = document.createElement('input');
95        input.type = 'text';
96        input.className = 'dropdown-filter-menu-search form-control';
97        input.setAttribute('data-column', this.column.toString());
98        input.setAttribute('data-index', this.index.toString());
99        input.setAttribute('placeholder', this.options.captions.search);
100        dropdownFilterItem.appendChild(input);
101        return dropdownFilterItem;
102    };
103    FilterMenu.prototype.dropdownFilterSort = function (direction) {
104        var dropdownFilterItem = document.createElement('div');
105        dropdownFilterItem.className = 'dropdown-filter-sort';
106        var span = document.createElement('span');
107        span.className = direction.toLowerCase().split(' ').join('-');
108        span.setAttribute('data-column', this.column.toString());
109        span.setAttribute('data-index', this.index.toString());
110        span.innerText = direction;
111        dropdownFilterItem.appendChild(span);
112        return dropdownFilterItem;
113    };
114    FilterMenu.prototype.dropdownFilterContent = function () {
115        var _this = this;
116        var self = this;
117        var dropdownFilterContent = document.createElement('div');
118        dropdownFilterContent.className = 'dropdown-filter-content';
119        var innerDivs = this.tds.reduce(function (arr, el) {
120            var values = arr.map(function (el) {
121                return el.innerText.trim();
122            });
123            if (values.indexOf(el.innerText.trim()) < 0) arr.push(el);
124            return arr;
125        }, []).sort(function (a, b) {
126            var A = a.innerText.toLowerCase();
127            var B = b.innerText.toLowerCase();
128            if (!isNaN(Number(A)) && !isNaN(Number(B))) {
129                if (Number(A) < Number(B)) return -1;
130                if (Number(A) > Number(B)) return 1;
131            } else {
132                if (A < B) return -1;
133                if (A > B) return 1;
134            }
135            return 0;
136        }).map(function (td) {
137            return _this.dropdownFilterItem(td, self);
138        });
139        this.inputs = innerDivs.map(function (div) {
140            return div.firstElementChild;
141        });
142        var selectAllCheckboxDiv = this.dropdownFilterItemSelectAll();
143        this.selectAllCheckbox = selectAllCheckboxDiv.firstElementChild;
144        innerDivs.unshift(selectAllCheckboxDiv);
145        var searchFilterDiv = this.dropdownFilterSearch();
146        this.searchFilter = searchFilterDiv.firstElementChild;
147        var outerDiv = innerDivs.reduce(function (outerDiv, innerDiv) {
148            outerDiv.appendChild(innerDiv);
149            return outerDiv;
150        }, document.createElement('div'));
151        outerDiv.className = 'checkbox-container';
152        var elements = [];
153        if (this.options.sort) elements = elements.concat([this.dropdownFilterSort(this.options.captions.a_to_z), this.dropdownFilterSort(this.options.captions.z_to_a)]);
154        if (this.options.search) elements.push(searchFilterDiv);
155        return elements.concat(outerDiv).reduce(function (html, el) {
156            html.appendChild(el);
157            return html;
158        }, dropdownFilterContent);
159    };
160    FilterMenu.prototype.dropdownFilterDropdown = function () {
161        var dropdownFilterDropdown = document.createElement('div');
162        dropdownFilterDropdown.className = 'dropdown-filter-dropdown';
163        var arrow = document.createElement('span');
164        arrow.className = '';
165        var icon = document.createElement('i');
166        icon.className = 'fa fa-filter';
167        arrow.appendChild(icon);
168        dropdownFilterDropdown.appendChild(arrow);
169        dropdownFilterDropdown.appendChild(this.dropdownFilterContent());
170        if ($(this.th).hasClass('no-sort')) {
171            $(dropdownFilterDropdown).find('.dropdown-filter-sort').remove();
172        }
173        if ($(this.th).hasClass('no-filter')) {
174            $(dropdownFilterDropdown).find('.checkbox-container').remove();
175        }
176        if ($(this.th).hasClass('no-search')) {
177            $(dropdownFilterDropdown).find('.dropdown-filter-search').remove();
178        }
179        return dropdownFilterDropdown;
180    };
181    return FilterMenu;
182}();
183
184var FilterCollection = function () {
185    function FilterCollection(target, options) {
186        this.target = target;
187        this.options = options;
188        this.ths = target.find('th' + options.columnSelector).toArray();
189        this.filterMenus = this.ths.map(function (th, index) {
190            var column = $(th).index();
191            return new FilterMenu(target, th, column, index, options);
192        });
193        this.rows = target.find('tbody').find('tr').toArray();
194        this.table = target.get(0);
195    }
196    FilterCollection.prototype.initialize = function () {
197        this.filterMenus.forEach(function (filterMenu) {
198            filterMenu.initialize();
199        });
200        this.bindCheckboxes();
201        this.bindSelectAllCheckboxes();
202        this.bindSort();
203        this.bindSearch();
204    };
205    FilterCollection.prototype.bindCheckboxes = function () {
206        var filterMenus = this.filterMenus;
207        var rows = this.rows;
208        var ths = this.ths;
209        var updateRowVisibility = this.updateRowVisibility;
210        this.target.find('.dropdown-filter-menu-item.item').change(function () {
211            var index = $(this).data('index');
212            var value = $(this).val();
213            filterMenus[index].updateSelectAll();
214            updateRowVisibility(filterMenus, rows, ths);
215        });
216    };
217    FilterCollection.prototype.bindSelectAllCheckboxes = function () {
218        var filterMenus = this.filterMenus;
219        var rows = this.rows;
220        var ths = this.ths;
221        var updateRowVisibility = this.updateRowVisibility;
222        this.target.find('.dropdown-filter-menu-item.select-all').change(function () {
223            var index = $(this).data('index');
224            var value = this.checked;
225            filterMenus[index].selectAllUpdate(value);
226            updateRowVisibility(filterMenus, rows, ths);
227        });
228    };
229    FilterCollection.prototype.bindSort = function () {
230        var filterMenus = this.filterMenus;
231        var rows = this.rows;
232        var ths = this.ths;
233        var sort = this.sort;
234        var table = this.table;
235        var options = this.options;
236        var updateRowVisibility = this.updateRowVisibility;
237        this.target.find('.dropdown-filter-sort').click(function () {
238            var $sortElement = $(this).find('span');
239            var column = $sortElement.data('column');
240            var order = $sortElement.attr('class');
241            sort(column, order, table, options);
242            updateRowVisibility(filterMenus, rows, ths);
243        });
244    };
245    FilterCollection.prototype.bindSearch = function () {
246        var filterMenus = this.filterMenus;
247        var rows = this.rows;
248        var ths = this.ths;
249        var updateRowVisibility = this.updateRowVisibility;
250        this.target.find('.dropdown-filter-search').keyup(function () {
251            var $input = $(this).find('input');
252            var index = $input.data('index');
253            var value = $input.val();
254            filterMenus[index].searchToggle(value);
255            updateRowVisibility(filterMenus, rows, ths);
256        });
257    };
258    FilterCollection.prototype.updateRowVisibility = function (filterMenus, rows, ths) {
259        var showRows = rows;
260        var hideRows = [];
261        var selectedLists = filterMenus.map(function (filterMenu) {
262            return {
263                column: filterMenu.column,
264                selected: filterMenu.inputs.filter(function (input) {
265                    return input.checked;
266                }).map(function (input) {
267                    return input.value.trim().replace(/ +(?= )/g, '');
268                })
269            };
270        });
271        for (var i = 0; i < rows.length; i++) {
272            var tds = rows[i].children;
273            for (var j = 0; j < selectedLists.length; j++) {
274                var content = tds[selectedLists[j].column].innerText.trim().replace(/ +(?= )/g, '');
275                if (selectedLists[j].selected.indexOf(content) === -1) {
276                    $(rows[i]).hide();
277                    break;
278                }
279                $(rows[i]).show();
280            }
281        }
282    };
283    FilterCollection.prototype.sort = function (column, order, table, options) {
284        var flip = 1;
285        if (order === options.captions.z_to_a.toLowerCase().split(' ').join('-')) flip = -1;
286        var tbody = $(table).find('tbody').get(0);
287        var rows = $(tbody).find('tr').get();
288        rows.sort(function (a, b) {
289            var A = a.children[column].innerText.toUpperCase();
290            var B = b.children[column].innerText.toUpperCase();
291            if (!isNaN(Number(A)) && !isNaN(Number(B))) {
292                if (Number(A) < Number(B)) return -1 * flip;
293                if (Number(A) > Number(B)) return 1 * flip;
294            } else {
295                if (A < B) return -1 * flip;
296                if (A > B) return 1 * flip;
297            }
298            return 0;
299        });
300        for (var i = 0; i < rows.length; i++) {
301            tbody.appendChild(rows[i]);
302        }
303    };
304    return FilterCollection;
305}();
306
307$$1.fn.excelTableFilter = function (options) {
308    
309    var currentUrl = document.URL;
310    
311    var languageValidator = currentUrl.includes("/en");
312    
313    var sa_to_z="";
314    
315    var sz_to_a="";
316    
317    var ssearch="";
318    
319    var sSelectAll="";
320    
321    if(languageValidator){
322        sa_to_z="A to Z";
323        
324        sz_to_a="Z to A";
325        
326        ssearch="Search";
327        
328        sSelectAll="Select all";
329    }
330    else{
331        sa_to_z="A para Z";
332        
333        sz_to_a="Z para A";
334        
335        ssearch="Pesquisar";
336        
337        sSelectAll="Selecionar tudo";
338    }
339    
340    var target = this;
341    options = $$1.extend({}, $$1.fn.excelTableFilter.options, options);
342    if (typeof options.columnSelector === 'undefined') options.columnSelector = '';
343    if (typeof options.sort === 'undefined') options.sort = true;
344    if (typeof options.search === 'undefined') options.search = true;
345    if (typeof options.captions === 'undefined') options.captions = {
346        a_to_z: sa_to_z,
347        z_to_a: sz_to_a,
348        search: ssearch,
349        select_all: sSelectAll
350    };
351    var filterCollection = new FilterCollection(target, options);
352    filterCollection.initialize();
353    return target;
354};
355$$1.fn.excelTableFilter.options = {};
356
357}(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.