swatch_container.js 1.2 KB

123456789101112131415161718192021222324252627282930
  1. /**
  2. * DevExtreme (ui/widget/swatch_container.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var $ = require("../../core/renderer");
  11. var viewPortUtils = require("../../core/utils/view_port");
  12. var SWATCH_CONTAINER_CLASS_PREFIX = "dx-swatch-";
  13. var getSwatchContainer = function(element) {
  14. var $element = $(element);
  15. var swatchContainer = $element.closest('[class^="'.concat(SWATCH_CONTAINER_CLASS_PREFIX, '"], [class*=" ').concat(SWATCH_CONTAINER_CLASS_PREFIX, '"]'));
  16. var viewport = viewPortUtils.value();
  17. if (!swatchContainer.length) {
  18. return viewport
  19. }
  20. var swatchClassRegex = new RegExp("(\\s|^)(".concat(SWATCH_CONTAINER_CLASS_PREFIX, ".*?)(\\s|$)"));
  21. var swatchClass = swatchContainer[0].className.match(swatchClassRegex)[2];
  22. var viewportSwatchContainer = viewport.children("." + swatchClass);
  23. if (!viewportSwatchContainer.length) {
  24. viewportSwatchContainer = $("<div>").addClass(swatchClass).appendTo(viewport)
  25. }
  26. return viewportSwatchContainer
  27. };
  28. module.exports = {
  29. getSwatchContainer: getSwatchContainer
  30. };