3 * Provides admin utilities.
6 (function ($, Drupal) {
11 * Blazy admin utility functions.
14 * The index of the current element.
15 * @param {HTMLElement} form
16 * The Blazy form wrapper HTML element.
18 function blazyForm(i, form) {
21 $('.details-legend-prefix', t).removeClass('element-invisible');
23 t[$('.form-checkbox--vanilla', t).prop('checked') ? 'addClass' : 'removeClass']('form--vanilla-on');
25 t.on('click', '.form-checkbox', function () {
27 $input[$input.prop('checked') ? 'addClass' : 'removeClass']('on');
29 if ($input.hasClass('form-checkbox--vanilla')) {
30 t[$input.prop('checked') ? 'addClass' : 'removeClass']('form--vanilla-on');
34 $('select[name$="[style]"]', t).on('change', function () {
35 var $select = $(this);
37 t.removeClass(function (index, css) {
38 return (css.match(/(^|\s)form--style-\S+/g) || []).join(' ');
41 if ($select.val() === '') {
42 t.addClass('form--style-off');
45 t.addClass('form--style-on form--style-' + $select.val());
49 $('select[name$="[responsive_image_style]"]', t).on('change', function () {
50 var $select = $(this);
51 t[$select.val() === '' ? 'removeClass' : 'addClass']('form--responsive-image-on');
54 $('select[name$="[media_switch]"]', t).on('change', function () {
55 var $select = $(this);
57 t.removeClass(function (index, css) {
58 return (css.match(/(^|\s)form--media-switch-\S+/g) || []).join(' ');
61 t[$select.val() === '' ? 'removeClass' : 'addClass']('form--media-switch-' + $select.val());
64 t.on('mouseenter touchstart', '.hint', function () {
65 $(this).closest('.form-item').addClass('is-hovered');
68 t.on('mouseleave touchend', '.hint', function () {
69 $(this).closest('.form-item').removeClass('is-hovered');
72 t.on('click', '.hint', function () {
73 $('.form-item.is-selected', t).removeClass('is-selected');
74 $(this).parent().toggleClass('is-selected');
77 t.on('click', '.description', function () {
78 $(this).closest('.is-selected').removeClass('is-selected');
81 t.on('focus', '.js-expandable', function () {
82 $(this).parent().addClass('is-focused');
85 t.on('blur', '.js-expandable', function () {
86 $(this).parent().removeClass('is-focused');
91 * Blazy admin tooltip function.
94 * The index of the current element.
95 * @param {HTMLElement} elm
96 * The Blazy form item description HTML element.
98 function blazyTooltip(i, elm) {
101 if (!$tip.siblings('.hint').length) {
102 $tip.closest('.form-item').append('<span class="hint">?</span>');
107 * Attaches Blazy form behavior to HTML element.
109 * @type {Drupal~behavior}
111 Drupal.behaviors.blazyAdmin = {
112 attach: function (context) {
113 var $form = $('.form--slick', context);
115 $('.description', $form).once('blazy-tooltip').each(blazyTooltip);
117 $form.once('blazy-admin').each(blazyForm);