✏️ 正在编辑: admin.js
路径:
/home/h359620/public_html/wp-content/themes/datis/assets/js/admin.js
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
jQuery(function ($) { if (typeof DatisNoticeAjax === 'undefined') return; const $scope = $('#datis_notice_scope'); const $wrap = $('#datis_notice_user_picker_wrap'); const $search = $('#datis_notice_user_search'); const $results = $('#datis_notice_user_results'); const $selectedList = $('#datis_notice_user_selected_list'); if (!$scope.length) return; let timer = null; function existingIds() { return $selectedList.find('input[name="datis_notice_user_ids[]"]').map(function () { return parseInt(this.value, 10); }).get(); } function showResults(items) { if (!items.length) { $results.html(`<div style="padding:8px;">${DatisNoticeAjax.i18n_no_results}</div>`).show(); return; } const already = new Set(existingIds()); const html = items.map(u => { const disabled = already.has(u.id); return ` <div class="datis-user-item" data-id="${u.id}" data-name="${u.name}" data-login="${u.login}" style="padding:8px; cursor:${disabled ? 'not-allowed' : 'pointer'}; border-bottom:1px solid #eee; opacity:${disabled ? 0.5 : 1};"> ${u.text} ${disabled ? '<small style="opacity:.8;">(added)</small>' : ''} </div> `; }).join(''); $results.html(html).show(); } function searchUsers(term) { $.ajax({ url: DatisNoticeAjax.ajax_url, method: 'GET', dataType: 'json', data: { action: 'datis_notice_user_search', nonce: DatisNoticeAjax.nonce, term: term } }).done(function (res) { if (res && res.success && res.data && res.data.results) { showResults(res.data.results); } else { showResults([]); } }).fail(function () { showResults([]); }); } function addUser(id, name, login) { const ids = existingIds(); if (ids.includes(id)) return; $selectedList.find('small').remove(); const html = ` <div class="datis-selected-user" data-id="${id}" style="display:flex; align-items:center; justify-content:space-between; gap:8px; padding:6px 8px; border:1px solid #eee; margin-bottom:6px; background:#fafafa;"> <span style="flex:1; min-width:0;">${name} <small style="opacity:.8;">(${login}, #${id})</small></span> <button type="button" class="button-link-delete datis-remove-user" aria-label="Remove user">×</button> <input type="hidden" name="datis_notice_user_ids[]" value="${id}"> </div> `; $selectedList.append(html); } function toggle() { const isSelected = $scope.val() === 'selected_users'; $wrap.toggle(isSelected); if (!isSelected) $results.hide(); } $scope.on('change', toggle); $search.on('input', function () { const term = $(this).val().trim(); if (term.length < 2) { $results.hide(); return; } clearTimeout(timer); timer = setTimeout(() => searchUsers(term), 250); }); $results.on('click', '.datis-user-item', function () { const id = parseInt($(this).data('id'), 10); const name = $(this).data('name'); const login = $(this).data('login'); if (existingIds().includes(id)) return; addUser(id, name, login); $results.hide(); $search.val(''); }); $selectedList.on('click', '.datis-remove-user', function () { $(this).closest('.datis-selected-user').remove(); if ($selectedList.find('.datis-selected-user').length === 0) { $selectedList.html(`<small style="opacity:.75;">${DatisNoticeAjax.i18n_no_selected}</small>`); } }); $(document).on('click', function (e) { if (!$(e.target).closest('#datis_notice_user_results, #datis_notice_user_search').length) { $results.hide(); } }); toggle(); });
💾 保存文件
← 返回文件管理器