/layouts/joomla/form/field/color/slider.php

https://github.com/Hackwar/joomla-cms · PHP · 153 lines · 107 code · 10 blank · 36 comment · 14 complexity · e4d17c2dca4f5a49e3b72d2e5e664487 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Site
  4. * @subpackage Layout
  5. *
  6. * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. use Joomla\CMS\Factory;
  10. use Joomla\CMS\Language\Text;
  11. /**
  12. * @var array $displayData Data for this field collected by ColorField
  13. */
  14. extract($displayData);
  15. /**
  16. * Layout variables
  17. * -----------------
  18. * @var string $autocomplete Autocomplete attribute for the field.
  19. * @var boolean $autofocus Is autofocus enabled?
  20. * @var string $class Classes for the input
  21. * @var boolean $disabled Is this field disabled?
  22. * @var string $display Which kind of slider should be displayed?
  23. * @var string $default Default value for this field
  24. * @var string $format Format of color value
  25. * @var string $hint Text for inputs placeholder
  26. * @var string $id ID of field and label
  27. * @var string $name Name of the input field
  28. * @var string $onchange Onchange attribute for the field
  29. * @var string $onclick Onclick attribute for the field
  30. * @var string $position Position of input
  31. * @var boolean $preview Should the selected value be displayed separately?
  32. * @var boolean $readonly Is this field read only?
  33. * @var boolean $required Is this field required?
  34. * @var string $saveFormat Format to save the color
  35. * @var integer $size Size attribute of the input
  36. * @var string $validate Validation rules to apply.
  37. * @var string $dataAttribute Miscellaneous data attributes preprocessed for HTML output
  38. * @var array $dataAttributes Miscellaneous data attributes for eg, data-*.
  39. */
  40. if ($color === 'none' || is_null($color))
  41. {
  42. $color = '';
  43. }
  44. $alpha = $format === 'hsla' || $format === 'rgba' || $format === 'alpha';
  45. $autocomplete = !empty($autocomplete) ? 'autocomplete="' . $autocomplete . '"' : '';
  46. $autofocus = $autofocus ? ' autofocus' : '';
  47. $color = ' data-color="' . $color . '"';
  48. $class = $class ? ' class="' . $class . '"' : '';
  49. $default = $default ? ' data-default="' . $default . '"' : '';
  50. $disabled = $disabled ? ' disabled' : '';
  51. $format = $format ? ' data-format="' . $format . '"' : '';
  52. $hint = strlen($hint) ? ' placeholder="' . $this->escape($hint) . '"' : '';
  53. $onchange = $onchange ? ' onchange="' . $onchange . '"' : '';
  54. $onclick = $onclick ? ' onclick="' . $onclick . '"' : '';
  55. $preview = $preview ? ' data-preview="' . $preview . '"' : '';
  56. $readonly = $readonly ? ' readonly' : '';
  57. $saveFormat = $saveFormat ? ' data-format="' . $saveFormat . '"' : '';
  58. $size = $size ? ' size="' . $size . '"' : '';
  59. $validate = $validate ? ' data-validate="' . $validate . '"' : '';
  60. $displayValues = explode(',', $display);
  61. $allSliders = $display === 'full' || empty($display);
  62. /** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
  63. $wa = Factory::getApplication()->getDocument()->getWebAssetManager();
  64. $wa->useScript('field.color-slider');
  65. Text::script('JFIELD_COLOR_ERROR_CONVERT_HSL');
  66. Text::script('JFIELD_COLOR_ERROR_CONVERT_HUE');
  67. Text::script('JFIELD_COLOR_ERROR_NO_COLOUR');
  68. Text::script('JFIELD_COLOR_ERROR_WRONG_FORMAT');
  69. ?>
  70. <div class="color-slider-wrapper"
  71. <?php echo
  72. $class,
  73. $color,
  74. $default,
  75. $preview,
  76. $size,
  77. $dataAttribute;
  78. ?>
  79. >
  80. <!-- The data to save at the end (label created in form by Joomla) -->
  81. <input type="text" class="form-control color-input" id="<?php echo $id; ?>" name="<?php echo $name; ?>"
  82. <?php echo
  83. $disabled,
  84. $readonly,
  85. $required,
  86. $saveFormat,
  87. $validate;
  88. ?>
  89. >
  90. <!-- Shows value which is allowed to manipulate like 'hue' -->
  91. <label for="slider-input" class="visually-hidden"><?php echo Text::_('JFIELD_COLOR_LABEL_SLIDER_INPUT'); ?></label>
  92. <input type="text" class="form-control" id="slider-input"
  93. <?php echo
  94. $autocomplete,
  95. $disabled,
  96. $hint,
  97. $onchange,
  98. $onclick,
  99. $position,
  100. $readonly,
  101. $required,
  102. $format,
  103. $validate;
  104. ?>
  105. >
  106. <span class="form-control-feedback"></span>
  107. <?php if ($allSliders || in_array('hue', $displayValues)) : ?>
  108. <label for="hue-slider" class="visually-hidden"><?php echo Text::_('JFIELD_COLOR_LABEL_SLIDER_HUE'); ?></label>
  109. <input type="range" min="0" max="360" class="form-control color-slider" id="hue-slider" data-type="hue"
  110. <?php echo
  111. $autofocus,
  112. $disabled
  113. ?>
  114. >
  115. <?php endif ?>
  116. <?php if ($allSliders || in_array('saturation', $displayValues)) : ?>
  117. <label for="saturation-slider" class="visually-hidden"><?php echo Text::_('JFIELD_COLOR_LABEL_SLIDER_SATURATION'); ?></label>
  118. <input type="range" min="0" max="100" class="form-control color-slider" id="saturation-slider" data-type="saturation"
  119. <?php echo
  120. $autofocus,
  121. $disabled
  122. ?>
  123. >
  124. <?php endif ?>
  125. <?php if ($allSliders || in_array('light', $displayValues)) : ?>
  126. <label for="light-slider" class="visually-hidden"><?php echo Text::_('JFIELD_COLOR_LABEL_SLIDER_LIGHT'); ?></label>
  127. <input type="range" min="0" max="100" class="form-control color-slider" id="light-slider" data-type="light"
  128. <?php echo
  129. $autofocus,
  130. $disabled
  131. ?>
  132. >
  133. <?php endif ?>
  134. <?php if ($alpha && ($allSliders || in_array('alpha', $displayValues))) : ?>
  135. <label for="alpha-slider" class="visually-hidden"><?php echo Text::_('JFIELD_COLOR_LABEL_SLIDER_ALPHA'); ?></label>
  136. <input type="range" min="0" max="100" class="form-control color-slider" id="alpha-slider" data-type="alpha"
  137. <?php echo
  138. $autofocus,
  139. $disabled
  140. ?>
  141. >
  142. <?php endif ?>
  143. </div>