PageSourceSearch

https://freelance.ru/assets/ab5772f9/task_form.js?v=1790795476

js freelance.ru collected 2026-10-01 08:35:51 UTC 5,318 bytes, 127 lines download raw bytes

1$(function () {
2    var STORAGE_KEY = 'taskFeedFilters';
3    var $form       = $('#taskFeedForm');
4    var $resetBtn   = $('#task-filter-reset');
5    var $applyBtn   = $form.find('.task-filter-apply');
6    var $rail       = $form.find('.task-filter-rail');
7
8    if (!$form.length) { return; }
9
10    // ── chip-toggle classes ──────────────────────────────────────────
11    $form.find('.task-chip-toggle input[type=checkbox]').on('change', function () {
12        var $lbl = $(this).closest('.task-chip-toggle');
13        if ($lbl.attr('id') === 'chip-premium') {
14            $lbl.toggleClass('task-chip-toggle--premium', this.checked);
15        } else {
16            $lbl.toggleClass('task-chip-toggle--on', this.checked);
17        }
18    });
19
20    // ── reset-button visibility + active count ───────────────────────
21    var $filterCount = $('#task-filter-reset-count');
22
23    function updateFilterCount() {
24        var count = $form.find('input[type=checkbox]:checked').length;
25        $filterCount.text(count > 0 ? count : '');
26    }
27
28    function updateResetVisibility() {
29        var count = $form.find('input[type=checkbox]:checked').length;
30        $resetBtn.toggle(count > 0);
31        $filterCount.text(count > 0 ? count : '');
32    }
33
34    // ── apply-button pending state ───────────────────────────────────
35    function setApplyPending() {
36        $applyBtn.addClass('task-filter-apply--pending');
37    }
38
39    $form.find('input[type=checkbox]').on('change', function () {
40        updateResetVisibility();
41        setApplyPending();
42    });
43
44    updateFilterCount(); // счётчик для фильтров, пришедших из URL (кнопку не трогаем — PHP уже выставил)
45
46    // ── filter rail: sticky ↔ static ────────────────────────────────
47    function updateRailPosition() {
48        if (!$rail.length) { return; }
49        $rail.css('position', $rail.outerHeight(true) > $(window).height() ? 'static' : '');
50    }
51
52    updateRailPosition();
53    $(window).on('resize', updateRailPosition);
54
55    // ── localStorage helpers ─────────────────────────────────────────
56    function serializeFilters() {
57        var state = {};
58        $form.find('input[type=checkbox]').each(function () {
59            var name = $(this).attr('name');
60            if (!this.checked) { return; }
61            if (name.indexOf('[]') !== -1) {
62                if (!state[name]) { state[name] = []; }
63                state[name].push($(this).val());
64            } else {
65                state[name] = $(this).val();
66            }
67        });
68        return state;
69    }
70
71    function applyFilters(state) {
72        $form.find('input[type=checkbox]').each(function () {
73            var name    = $(this).attr('name');
74            var val     = $(this).val();
75            var checked = name.indexOf('[]') !== -1
76                ? (state[name] || []).indexOf(val) !== -1
77                : state.hasOwnProperty(name);
78            this.checked = checked;
79            $(this).trigger('change'); // sync chip-toggle classes + reset btn
80        });
81    }
82
83    function hasUrlFilters() {
84        var search = window.location.search;
85        if (!search || search === '?') { return false; }
86        var found = false;
87        $form.find('input[type=checkbox]').each(function () {
88            var baseName = $(this).attr('name').replace(/\[\]$/, '');
89            if (search.indexOf(baseName) !== -1) { found = true; return false; }
90        });
91        return found;
92    }
93
94    // ── save on submit ───────────────────────────────────────────────
95    $form.on('submit', function () {
96        try {
97            var state = serializeFilters();
98            if (Object.keys(state).length > 0) {
99                localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
100            } else {
101                localStorage.removeItem(STORAGE_KEY);
102            }
103        } catch (e) {}
104    });
105
106    // ── clear on reset ───────────────────────────────────────────────
107    $resetBtn.on('click', function () {
108        try { localStorage.removeItem(STORAGE_KEY); } catch (e) {}
109    });
110
111    // ── restore on clean load ────────────────────────────────────────
112    if (!hasUrlFilters()) {
113        try {
114            var saved = localStorage.getItem(STORAGE_KEY);
115            if (saved) {
116                var state = JSON.parse(saved);
117                if (Object.keys(state).length > 0) {
118                    applyFilters(state);
119                    setApplyPending(); // кнопка активна, пользователь сам нажмёт
120                }
121            }
122        } catch (e) {
123            try { localStorage.removeItem(STORAGE_KEY); } catch (e2) {}
124        }
125    }
126
127});

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.