mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-04 01:34:27 +00:00 
			
		
		
		
	Forbid jQuery .prop and fix related issues (#29832)
				
					
				
			The issue checkbox code received a few more cleanups and I specifically tested it. The other changes are trivial. Also, I checked the cases for how many elements match the jQuery selection to determine querySelector vs. querySelectorAll. --------- Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
			
		||||
import $ from 'jquery';
 | 
			
		||||
import {updateIssuesMeta} from './repo-issue.js';
 | 
			
		||||
import {toggleElem, hideElem} from '../utils/dom.js';
 | 
			
		||||
import {toggleElem, hideElem, isElemHidden} from '../utils/dom.js';
 | 
			
		||||
import {htmlEscape} from 'escape-goat';
 | 
			
		||||
import {confirmModal} from './comp/ConfirmModal.js';
 | 
			
		||||
import {showErrorToast} from '../modules/toast.js';
 | 
			
		||||
@@ -8,32 +8,42 @@ import {createSortable} from '../modules/sortable.js';
 | 
			
		||||
import {DELETE, POST} from '../modules/fetch.js';
 | 
			
		||||
 | 
			
		||||
function initRepoIssueListCheckboxes() {
 | 
			
		||||
  const $issueSelectAll = $('.issue-checkbox-all');
 | 
			
		||||
  const $issueCheckboxes = $('.issue-checkbox');
 | 
			
		||||
  const issueSelectAll = document.querySelector('.issue-checkbox-all');
 | 
			
		||||
  const issueCheckboxes = document.querySelectorAll('.issue-checkbox');
 | 
			
		||||
 | 
			
		||||
  const syncIssueSelectionState = () => {
 | 
			
		||||
    const $checked = $issueCheckboxes.filter(':checked');
 | 
			
		||||
    const anyChecked = $checked.length !== 0;
 | 
			
		||||
    const allChecked = anyChecked && $checked.length === $issueCheckboxes.length;
 | 
			
		||||
    const checkedCheckboxes = Array.from(issueCheckboxes).filter((el) => el.checked);
 | 
			
		||||
    const anyChecked = Boolean(checkedCheckboxes.length);
 | 
			
		||||
    const allChecked = anyChecked && checkedCheckboxes.length === issueCheckboxes.length;
 | 
			
		||||
 | 
			
		||||
    if (allChecked) {
 | 
			
		||||
      $issueSelectAll.prop({'checked': true, 'indeterminate': false});
 | 
			
		||||
      issueSelectAll.checked = true;
 | 
			
		||||
      issueSelectAll.indeterminate = false;
 | 
			
		||||
    } else if (anyChecked) {
 | 
			
		||||
      $issueSelectAll.prop({'checked': false, 'indeterminate': true});
 | 
			
		||||
      issueSelectAll.checked = false;
 | 
			
		||||
      issueSelectAll.indeterminate = true;
 | 
			
		||||
    } else {
 | 
			
		||||
      $issueSelectAll.prop({'checked': false, 'indeterminate': false});
 | 
			
		||||
      issueSelectAll.checked = false;
 | 
			
		||||
      issueSelectAll.indeterminate = false;
 | 
			
		||||
    }
 | 
			
		||||
    // if any issue is selected, show the action panel, otherwise show the filter panel
 | 
			
		||||
    toggleElem($('#issue-filters'), !anyChecked);
 | 
			
		||||
    toggleElem($('#issue-actions'), anyChecked);
 | 
			
		||||
    // there are two panels but only one select-all checkbox, so move the checkbox to the visible panel
 | 
			
		||||
    $('#issue-filters, #issue-actions').filter(':visible').find('.issue-list-toolbar-left').prepend($issueSelectAll);
 | 
			
		||||
    const panels = document.querySelectorAll('#issue-filters, #issue-actions');
 | 
			
		||||
    const visiblePanel = Array.from(panels).find((el) => !isElemHidden(el));
 | 
			
		||||
    const toolbarLeft = visiblePanel.querySelector('.issue-list-toolbar-left');
 | 
			
		||||
    toolbarLeft.prepend(issueSelectAll);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  $issueCheckboxes.on('change', syncIssueSelectionState);
 | 
			
		||||
  for (const el of issueCheckboxes) {
 | 
			
		||||
    el.addEventListener('change', syncIssueSelectionState);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  $issueSelectAll.on('change', () => {
 | 
			
		||||
    $issueCheckboxes.prop('checked', $issueSelectAll.is(':checked'));
 | 
			
		||||
  issueSelectAll.addEventListener('change', () => {
 | 
			
		||||
    for (const el of issueCheckboxes) {
 | 
			
		||||
      el.checked = issueSelectAll.checked;
 | 
			
		||||
    }
 | 
			
		||||
    syncIssueSelectionState();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user