Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

98 строки
2.7 KiB

  1. /**
  2. * --------------------------------------------------------------------------
  3. * Bootstrap (v5.1.3): dom/selector-engine.js
  4. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  5. * --------------------------------------------------------------------------
  6. */
  7. define([
  8. "../util/index"
  9. ], function(Util) {
  10. 'use strict';
  11. const isDisabled = Util.isDisabled;
  12. const isVisible = Util.isVisible;
  13. /**
  14. * ------------------------------------------------------------------------
  15. * Constants
  16. * ------------------------------------------------------------------------
  17. */
  18. const NODE_TEXT = 3
  19. return {
  20. find: function(selector, element = document.documentElement) {
  21. return [].concat(...Element.prototype.querySelectorAll.call(element, selector))
  22. },
  23. findOne: function(selector, element = document.documentElement) {
  24. return Element.prototype.querySelector.call(element, selector)
  25. },
  26. children: function(element, selector) {
  27. return [].concat(...element.children)
  28. .filter(child => child.matches(selector))
  29. },
  30. parents: function(element, selector) {
  31. const parents = []
  32. let ancestor = element.parentNode
  33. while (ancestor && ancestor.nodeType === Node.ELEMENT_NODE && ancestor.nodeType !== NODE_TEXT) {
  34. if (ancestor.matches(selector)) {
  35. parents.push(ancestor)
  36. }
  37. ancestor = ancestor.parentNode
  38. }
  39. return parents
  40. },
  41. prev: function(element, selector) {
  42. let previous = element.previousElementSibling
  43. while (previous) {
  44. if (previous.matches(selector)) {
  45. return [previous]
  46. }
  47. previous = previous.previousElementSibling
  48. }
  49. return []
  50. },
  51. next: function(element, selector) {
  52. let next = element.nextElementSibling
  53. while (next) {
  54. if (next.matches(selector)) {
  55. return [next]
  56. }
  57. next = next.nextElementSibling
  58. }
  59. return []
  60. },
  61. focusableChildren: function(element) {
  62. const focusables = [
  63. 'a',
  64. 'button',
  65. 'input',
  66. 'textarea',
  67. 'select',
  68. 'details',
  69. '[tabindex]',
  70. '[contenteditable="true"]'
  71. ].map(selector => `${selector}:not([tabindex^="-"])`).join(', ')
  72. return this.find(focusables, element).filter(el => !isDisabled(el) && isVisible(el))
  73. }
  74. }
  75. });