# quadmenu/1.8.8/lib/redux/rgba/field_rgba.js

QuadMenu – Mega Menu, version 1.8.8. 146 lines.

- Page: https://pluginprobe.com/plugins/quadmenu/1.8.8/code/lib/redux/rgba/field_rgba.js
- Raw: https://pluginprobe.com/plugins/quadmenu/1.8.8/raw/lib/redux/rgba/field_rgba.js
- Modified: 2018-11-10T15:50:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/quadmenu/1.8.8/code/lib/redux/rgba/field_rgba.js#L10-L20`.

```javascript
/*
 Field Color (color)
 */

/*global jQuery, document, redux_change, redux*/

(function ($) {
  'use strict';

  redux.field_objects = redux.field_objects || {};
  redux.field_objects.rgba = redux.field_objects.rgba || {};

  $(document).ready(
          function () {

          }
  );

  redux.field_objects.rgba.init = function (selector) {

    if (!selector) {
      selector = $(document).find(".redux-group-tab:visible").find('.redux-container-rgba:visible');
    }

    $(selector).each(
            function () {

              var el = $(this);
              var parent = el;

              if (!el.hasClass('redux-field-container')) {
                parent = el.parents('.redux-field-container:first');
              }
              if (parent.is(":hidden")) { // Skip hidden fields
                return;
              }
              if (parent.hasClass('redux-field-init')) {
                parent.removeClass('redux-field-init');
              } else {
                return;
              }

              el.find('.redux-rgba-init').wpColorPicker(
                      {
                        change: function (e, ui) {
                          $(this).val(ui.color.toString());
                          redux_change($(this));
                          el.find('#' + e.target.getAttribute('data-id') + '-transparency').removeAttr('checked');
                        },
                        clear: function (e, ui) {
                          $(this).val('');
                          redux_change($(this).parent().find('.redux-rgba-init'));
                        }
                      }
              );

              el.find('.redux-color').on(
                      'focus', function () {
                        $(this).data('oldcolor', $(this).val());
                      }
              );

              el.find('.redux-color').on(
                      'keyup', function () {
                        var value = $(this).val();
                        var color = colorValidate(this);
                        var id = '#' + $(this).attr('id');

                        if (value === "transparent") {
                          $(this).parent().parent().find('.wp-color-result').css(
                                  'background-color', 'transparent'
                                  );

                          el.find(id + '-transparency').attr('checked', 'checked');
                        } else {
                          el.find(id + '-transparency').removeAttr('checked');

                          if (color && color !== $(this).val()) {
                            $(this).val(color);
                          }
                        }
                      }
              );

              // Replace and validate field on blur
              el.find('.redux-rgba').on(
                      'blur', function () {
                        var value = $(this).val();
                        var id = '#' + $(this).attr('id');

                        if (value === "transparent") {
                          $(this).parent().parent().find('.wp-color-result').css(
                                  'background-color', 'transparent'
                                  );

                          el.find(id + '-transparency').attr('checked', 'checked');
                        } else {
                          if (colorValidate(this) === value) {
                            if (value.indexOf("#") !== 0) {
                              $(this).val($(this).data('oldcolor'));
                            }
                          }

                          el.find(id + '-transparency').removeAttr('checked');
                        }
                      }
              );

              // Store the old valid color on keydown
              el.find('.redux-color').on(
                      'keydown', function () {
                        $(this).data('oldkeypress', $(this).val());
                      }
              );

              // When transparency checkbox is clicked
              el.find('.color-transparency').on(
                      'click', function () {
                        if ($(this).is(":checked")) {
                          el.find('.redux-saved-color').val($('#' + $(this).data('id')).val());
                          el.find('#' + $(this).data('id')).val('transparent');
                          el.find('#' + $(this).data('id')).parent().parent().find('.wp-color-result').css(
                                  'background-color', 'transparent'
                                  );
                        } else {
                          if (el.find('#' + $(this).data('id')).val() === 'transparent') {
                            var prevColor = $('.redux-saved-color').val();

                            if (prevColor === '') {
                              prevColor = $('#' + $(this).data('id')).data('default-color');
                            }

                            el.find('#' + $(this).data('id')).parent().parent().find('.wp-color-result').css(
                                    'background-color', prevColor
                                    );

                            el.find('#' + $(this).data('id')).val(prevColor);
                          }
                        }
                        redux_change($(this));
                      }
              );
            }
    );
  };
})(jQuery);
```
