Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you target elements with JQuery Minicolors? #243

Open
RailsCod3rFuture opened this issue Feb 10, 2018 · 0 comments
Open

How do you target elements with JQuery Minicolors? #243

RailsCod3rFuture opened this issue Feb 10, 2018 · 0 comments
Labels

Comments

@RailsCod3rFuture
Copy link

RailsCod3rFuture commented Feb 10, 2018

I can't seem to figure out how to change the swatch color and manipulate separately targeted class elements. I'm using rails btw.

<div class="col-md-4">
     <%= f.simple_fields_for :profile_color do |c| %>
       <label>Avatar Background Color</label>
       <%= c.input :border_background_color, as: :minicolors, class: 'form-control profile-border-bg-color', label: false %>
       <label>Body Background Color</label>
       <%= c.input :body_background_color, as: :minicolors, class: 'form-control profile-body-bg-color', label: false %>
       <label>Header Label Background Color</label>
       <%= c.input :header_label_background_color, as: :minicolors, class: 'form-control profile-header-label-bg-color', label: false %>
       <label>Information Box Color</label>
       <%= c.input :information_box_color, as: :minicolors, class: 'form-control profile-info-color', label: false %>
       <label>About Me Background Color</label>
       <%= c.input :about_me_background_box_color, as: :minicolors, class: 'form-control profile-about-me-color', label: false %>
     <% end %>
   </div>
<div class="col-md-4">
      <div class="preview-container">
        <div class="preview-header">
          <h6>Color Preview</h6>
        </div>
        <div class="preview-border">
          <div class="preview-container-avatar">

          </div>
        </div>
        <div class="preview-container-about-me">

        </div>
        <div class="preview-header-block">

        </div>
        <div class="preview-info-block">

        </div>
      </div>
<script type="text/javascript">
    $(document).on('turbolinks:load', function () {
 
        $('#profile_color_attributes_border_background_color, #profile_color_attributes_body_background_color, #profile_color_attributes_header_label_background_color, #profile_color_attributes_information_box_color, #profile_color_attributes_about_me_background_box_color').minicolors({
            theme: 'bootstrap',
            animationSpeed: 50,
            animationEasing: 'swing',
            change: function (hex, opacity) {
                var color = $(this).minicolors('rgbaString');
                var parent = $(self);
                if (parent.hasClass("profile-border-bg-color")) {
                    $("preview-border").css("background-color", color);
                } else if (parent.hasClass("profile-body-bg-color")) {
                    $("preview-container").css("background-color", color);
                } else if (parent.hasClass("profile-header-label-bg-color")) {
                    $("preview-header-block").css("background-color", color);
                } else if (parent.hasClass("profile-info-color")) {
                    $("preview-info-block").css("background-color", color);
                } else if (parent.hasClass("rf-profile-about-me-color")) {
                    $("preview-container-about-me").css("background-color", color);
                }
            }

        });
    });
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants