Участник:IKhitron/checktab.js

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
// The file is frozen for user:stjn, the work continues in other file

(function() {
	let accmode; // null as regular mode, true as accebility mode, help as help mode
	let first, last;
	
	function haspu() {
		return $('.popup-window').length > 0;
	}
	
	function startmode() {
		first = $('.popup-window li:first-child a');
		last = $('.popup-window li:last-child a');
		$('.popup-window li a')
			.on('focus', function () {
				$(this).closest('li').trigger('mouseenter');
			})
			.on('blur', function() {
				$(this).closest('li').trigger('mouseleave');
			});
		accmode = true;
	}
	
	$(document).on('keydown', function (event) {
		switch (event.which) {
			case 9:
				if (haspu() && ! event.shiftKey) {
					if (! accmode) {
						startmode();
						first.focus();
						event.preventDefault();
					} else if (last.is(":focus")) {
						first.focus();
						event.preventDefault();
					}
				} else if (haspu()) {
					if (! accmode) {
						startmode();
						last.focus();
						event.preventDefault();
					} else if (first.is(":focus")) {
						last.focus();
						event.preventDefault();
					}
				}
				break;
			default:
		}
	});
})();