#StackBounty: #javascript #jquery Fastest Possible Way in jQuery to Filter "Radios + Select + Checkbox" Together Simultaneously

Bounty: 300

What is the Fastest strategy (in terms of Performance) to filter a combination of different type filters in jQuery?

In this example, I use "Radios + Select + Checkbox" and need them to operate together simultaneously.

JS Bin Link: https://jsbin.com/wegopom/3/edit?js,output

I am targeting markers in a Leaflet map based on the:

  • image’s "src" e.g. img[src$="marker-icon.png"] (ends with file name)
  • image’s "class" e.g. img.variation

Speed on the filter is central as this map will be displaying hundreds and eventually thousands of marker images.


For the Radios, ("variation" class)… I have a change function:

jQuery(document).on("change", ".variation", function() {

For the Select, ("filterbottler" ID)… I have a second change function:

jQuery('#filterbottler').change(function(){

For the Checkbox, ("outages" ID)… I have a third change function:

jQuery('#outages').change(function(){

It was simple to make two of these change functions work in tandem using a bunch of IF statements and adjoined/chained classes (like img.variation.bottler which would be very slow)… but now that I’ve added a third filter, it seems like overload and it has now become very hard for me to wrap my brain around every single filtering scenario.

The JS Bin @ https://jsbin.com/wegopom/3/edit?js,output features each of these three filters working independently…

The goal is to get the first three filters (Variation, Bottler, & Outages) to simultaneously work together in the quickest and most efficient way possible. Can the jQuery experts here please help?


jQuery(document).ready(function($){

    // Filter 1) by Variation
    jQuery(document).on("change", ".variation", function() {
        var bottlerValue = jQuery("#filterbottler").find("option:selected").val();
        var bottlerClass = '.field-ccb-cached__'+bottlerValue;

        // marker groups to be used in exclusionary :not() statements so they aren't affected by the filters... e.g. marker-icon.png & marker-icon-2x.png are "My Location" markers
        var mainMarkers = '[src$="bottler_22px.png"],[src$="marker-icon.png"],[src$="marker-icon-2x.png"]';
        var includeOutageMarkers = '[src$="bottler_22px.png"],[src$="marker-icon.png"],[src$="marker-icon-2x.png"],[src$="cross_22px.png"]';

        if (this.id == "map-filters-show-all") {
            jQuery('.leaflet-marker-pane img:not('+mainMarkers+')').show(500);
        }
        else if (this.id == "map-filters-16oz-cans") {
            jQuery('.leaflet-marker-pane img:not('+includeOutageMarkers+',.field-report-variation__16oz-cans)').hide(500);
            jQuery('.leaflet-marker-pane img.field-report-variation__16oz-cans').show(500);
        } else if (this.id == "map-filters-12oz-cans") {
            jQuery('.leaflet-marker-pane img:not('+includeOutageMarkers+',.field-report-variation__12oz-cans)').hide(500);
            jQuery('.leaflet-marker-pane img.field-report-variation__12oz-cans').show(500);
        } else if (this.id == "map-filters-fountain-surge") {
            jQuery('.leaflet-marker-pane img:not('+includeOutageMarkers+',.field-report-variation__fountain-surge)').hide(500);
            jQuery('.leaflet-marker-pane img.field-report-variation__fountain-surge').show(500);
        } else if (this.id == "map-filters-fountain-surge-red-berry-blast") {
            jQuery('.leaflet-marker-pane img:not('+includeOutageMarkers+',.field-report-variation__fountain-surge-red-berry-blast)').hide(500);
            jQuery('.leaflet-marker-pane img.field-report-variation__fountain-surge-red-berry-blast').show(500);
        }
    });

    // Filter 2) by Bottling Company (select box)
    jQuery('#filterbottler').change(function(){
        var bottlerValue = jQuery("#filterbottler").find("option:selected").val();
        var bottlerClass = '.field-ccb-cached__'+bottlerValue;

        if (bottlerClass != '.field-ccb-cached___none') {
            jQuery('.leaflet-marker-pane img:not([src$="bottler_22px.png"],[src$="marker-icon.png"],[src$="marker-icon-2x.png"],[src$="cross_22px.png"],'+bottlerClass+')').hide(500);
            jQuery('.leaflet-marker-pane img'+bottlerClass).show(500);
        }
        if (bottlerClass === '.field-ccb-cached___none') {
            jQuery('.leaflet-marker-pane img:not([src$="bottler_22px.png"],[src$="marker-icon.png"],[src$="marker-icon-2x.png"])').show(500);
        }

    });

    // Filter 3) Show Outage Reports (checkbox on/off)
    jQuery('#outages').change(function(){
        if(this.checked){
            jQuery('.leaflet-marker-pane img[src$="cross_22px.png"],[src$="exclamation_22px.png"]').fadeToggle(500);
            jQuery.cookie('outagemarkers', true);
        }
        else {
            jQuery('.leaflet-marker-pane img[src$="cross_22px.png"],[src$="exclamation_22px.png"]').fadeToggle(500);
            jQuery.cookie('outagemarkers', false);
        }
    });


Get this bounty!!!

#StackBounty: #jquery Why doesn't my div follow my cursor consistently across all browsers?

Bounty: 50

I have a circle div that follows my cursor and changes size/ color when I hover a link. I’m happy with the way my code works in Chrome, Brave and Opera browsers – it’s smooth, and it remains fixed when the mouse is scrolled. In Safari and Firefox however, it’s not working so well.

In safari, it’s very jerky and the div lags behind the cursor, and in Firefox there is a glitch when the cursor hovers the link. (If the cursor is moved over the link quickly, the circle seems to move away very suddenly and catches up with the cursor).

Can anyone see any obvious errors in my code? I’m very new to jQuery and this is something I’ve pieced together from tutorials, trial & error and the help of kind people on stackoverflow.

Thanking you in advance for any help.

JSFiddle – https://jsfiddle.net/ecapvukw/1/

jQuery(document).ready(function($) {

  var $circle = $('.circle-cursor');
  var half_cWidth = $circle.width() / 2;
  var half_cHeight = $circle.height() / 2;

  $(document).mousemove(function(e) {
    $circle.css({
      transform: 'translate(' + (e.clientX - half_cHeight) + 'px, ' + (e.clientY - half_cWidth) + 'px)'
    });
  });

  $("a").hover(
    function() {
      $("body").addClass("cursor-hover");
    },
    function() {
      $("body").removeClass("cursor-hover");
    }
  );

});
body {
  position: relative;
  height: 1000px;
  width: 100%;
  margin: 0;
}

a {
  float: left;
  padding: 20px;
  background: #efefef;
}

.circle-cursor {
  position: fixed;
  z-index: 99999;
  -webkit-transition: -webkit-transform 0.1s;
  -o-transition: transform 0.1s;
  transition: transform 0.1s;
}

.circle-inner {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  pointer-events: none;
  background-color: rgba(0, 0, 0, 0.05);
  -webkit-transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  -webkit-transition: width .2s, height .2s, opacity 1s, background-color .2s, -webkit-transform .2s;
  -o-transition: transform .2s, width .2s, height .2s, opacity 1s, background-color .2s;
  transition: transform .2s, width .2s, height .2s, opacity 1s, background-color .2s;
}

body.cursor-hover .circle-inner {
  width: 70px;
  height: 70px;
  background-color: rgba(237, 85, 0, 0.5);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="circle-cursor">
    <span class="circle-inner"></span>
</span>
<a href="">This is a link.</a>


Get this bounty!!!

#StackBounty: #jquery #css #reactjs #slick.js #owl-carousel How to create Image Grid Slider with different heights and width of image

Bounty: 50

I wanted to create a grid image slider with different height and width of the image. something looks like the below image.

In the below image we have the first image slider as Squire Image and 2nd slider as two rectangle image than again Squire image and continue …

enter image description here

Can anyone suggest any slider which supports this type of image configuration?


Get this bounty!!!

#StackBounty: #javascript #jquery #django #django-templates #formset Jquery in django : Uncaught TypeError: Cannot read property 'c…

Bounty: 50

For the life of me I can’t figure out what’s wrong with this code. It used to work in an earlier version and after I rearranged the javascript at the bottom of the page it just won’t work properly. It keeps giving me this error:
enter image description here

The row where it throws the error is the following:
$('.formset_row').formset({

And this is the jquery plugin that i used. This used to work perfectly until like yesterday when i probably touched something i shouldnt have.

    <!-- Select2 JS -->
    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>

    <!-- Semantic UI -->
    
   
    
    <script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.6.0/dist/umd/popper.min.js" integrity="sha384-KsvD1yqQ1/1+IA7gi3P0tyJcT3vR+NdBTt13hSJ2lnve8agRGXTTyNaBYmCR/Nwi" crossorigin="anonymous"></script>
    <script src="/static/bootstrap/js/bootstrap.min.js"></script>
    <!-- Select2 JS -->
    <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-beta.1/dist/js/select2.min.js"></script>
    <script src="/static/js/script.js"></script>
    
    
    <script>
        /*$('body').on('focus',".my-date-picker", function(){
            $('.my-date-picker').datetimepicker({
                format: 'DD/MM/YYYY',
                ignoreReadonly: true,
                showTodayButton: true
            });
        });*/
    </script>
    <script src="/static/formset/jquery.formset.js"></script>
    <script type="text/javascript">
        $('.formset_row').formset({
            addText: '<div style="color: #34C6AA;" class="my-2 text-center"><span class="oi oi-plus"></span> Add Education</div>',
            deleteText: '<div style="color: #f4816e; text-decoration: none;" class="my-2 text-center"> <span class="oi oi-x"></span> Remove Education</div> ',
            prefix: 'educations'
        });
    </script>



</body>

EDIT: As requested im sharing the code that uses the class formset

{% extends '_base.html' %}
{% load crispy_forms_tags %}
{% load static %}



{% block content %}
</br>
    <h1 class="display-4 text-responsive">Edit your education information</h1>
<h3 class="display-6 text-muted">This will be visible on your profile</h3>
<p><span style="color: #f4816e;">IMPORTANT:</span></p>
<ul>
    <li>Leave the End Date field empty if you are currently enrolled in your school/university</li>
</ul>
<hr>    
<form method="POST" action=""> 
    {% csrf_token %} 

    {{ formset.management_form }} {# This is necessary when using formsets  #}
        {% for form in formset  %}
            
            {{ form.media }} {# This shit is responsible for showing the datepicker #}
            
            
            <div class="formset_row">
            <div class="row">
                    
                    {% if forloop.first %}
                            {% for hidden in form.hidden_fields %}
                                {{ hidden }}
                            {% endfor %}
                    {% endif %}
                    {% for field in form.visible_fields %}
                        
                            {% if field.name == "start_date" or field.name == 'end_date' %}
                                {% if  field.name == 'end_date' %}
                                    <div class="col-lg-2 col-sm-12 col-md-1">
                                        {{ field.label }} 
                                        {{ field }} </br>
                                        
                                    </div>
                                {% else %}
                                    <div class="col-lg-2 col-sm-12 col-md-1">
                                        {{ field.label }}
                                        {{ field }} </br>
                                    </div>
                                {% endif %}
                            {% elif field.name != 'DELETE' %}
                                <div class="col-lg-4 col-sm-12 col-md-4">
                                    {{ field.label }}
                                    {{ field }} </br>
                                </div>
                            {% else %}
                                {{ field }}
                            {% endif %}
                        
                        
                    {% endfor %}
            </div>
            </div>
        {% endfor %}
    
    <div class="d-block d-sm-none ">
        <input type="submit" name="save_and_next" value="Save and continue to next step" class="btn btn-success btn-block">
        <input type="submit" name="save_and_profile"value="Save and go to profile" class="btn btn-outline-info btn-block">
        <a href="{% url 'recruitment:update_coach_prof_exp' %}" class="btn btn-light btn-block">Skip step</a>
    </div>
    <div class="d-none d-md-block ">
        <input type="submit" name="save_and_next" value="Save and continue to next step" class="btn btn-success">
        <input type="submit" name="save_and_profile"value="Save and go to profile" class="btn btn-outline-info">
        <a href="{% url 'recruitment:update_coach_prof_exp' %}" class="btn btn-light">Skip step</a>
    </div>

    
</form>
<script>
    $('body').on('focus',".my-date-picker", function(){
        $(this).datetimepicker({
            format: 'DD/MM/YYYY',
            ignoreReadonly: true,
            showTodayButton: true
        });
    });
</script>
<script src="{% static 'formset/jquery.formset.js' %}"></script>
<script type="text/javascript">
    $('.formset_row').formset({
        addText: '<div style="color: #34C6AA;" class="my-2 text-center"><span class="oi oi-plus"></span> Add Education</div>',
        deleteText: '<div style="color: #f4816e; text-decoration: none;" class="my-2 text-center"> <span class="oi oi-x"></span> Remove Education</div> ',
        prefix: '{{ formset.prefix }}'
    });
</script>

{% endblock content %}


Get this bounty!!!

#StackBounty: #javascript #jquery #dom Getting checked value after using back button

Bounty: 50

I have the following code on a web page:

<script>
jQuery(function(){ 
    console.log($("[name='type']:checked").val());
})
</script>

<form>
A <input type="radio" name="type" value="A"> &nbsp;&nbsp;
B <input type="radio" name="type" value="B"><br>
<input type="submit" name="submit" value="submit">
</form>

When I load the page, the output in the console is, naturally, ‘undefined’. Let’s say I select the ‘A’ option, click the submit button and then click the browser’s back button. The ‘A’ option is still checked but the console output is also still ‘undefined’. That doesn’t seem right. Obviously I want the output to be ‘A’. What am I doing wrong?


Get this bounty!!!

#StackBounty: #filters #jquery #gallery WP Filter to change the URL of an Anchor wrapping the last gallery image

Bounty: 150

We have a normal WordPress gallery on a development webpage.

enter image description here

The page is custom content through Advanced Custom Fields, and we are wrapping the section above’s content like so:

<?php
  $content = get_sub_field('wysiwyg');
  if ( function_exists('slb_activate') ) {
    $content = slb_activate($content);
  }
  echo $content;
?>

The lightbox functionality is generated by Simple Lightbox, and slb_activate is a function of this plugin, which adds the lightbox functionality to any gallery in the ACF content.

The designer wants the last image in the gallery (the purple one) to link to a different WordPress page while maintaining the lightbox functionality for the rest of the gallery.

I don’t know if we need a WordPress filter (which to me would be complicated by the slb_activate function, or some jQuery, and target .gallery-item:last-of-type, replacing the URL with a new one?

If so, we’d like to take the page slug (bathrooms) from https://herodevelopment.com.au/allbathroomgear/design-build/bathrooms/ and use this slug to generate a new URL of https://herodevelopment.com.au/allbathroomgear/album/bathrooms/

(so going from /design-build/bathrooms/ to /album/bathrooms/ on the final production website).

I’d appreciate any help, as I am unfortunately not a developer.


Get this bounty!!!

#StackBounty: #javascript #jquery #tensorflow #tensorflow.js Order of execution is not behaving sychronously with tensorflow.js and jav…

Bounty: 50

I have a simple tensorflow.js application built with jquery and some basic javascript.

I have button that when clicked, disables itself and toggles a spinner icon to indicate that the model is performing its predictions. When the predictions are finished the default button is restored. However, visually, the UI is not behaving in this way on the browser.

Demo: https://maksimdan.github.io/endpoints/models/pokename.htm

If we substitute predictions with a synchronous sleep function, it behaves as expected.

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

$("#raw-gen-button").click(async function(){
    console.log("Generating new predictions...");

    showButtonId("#generating-button");
    await sleep(750);
    // let predictions = await predict_model(5);
    // addGeneratedNamesToUI(predictions);
    showButtonId("#generate-button");

    console.log("Finished generating new predictions...");
    // console.log(predictions);
});


Get this bounty!!!

#StackBounty: #javascript #jquery #validation #event-handling Submitting form jQuery checkboxlist

Bounty: 50

In my requestForm submit function I have this logic that checks three checkboxes and then displays the label with an error message. Is there better logic? I would be happy for any kind of feedback since this is quite critical a part of my application.

$("#requestForm").submit(function (e) {
            e.stopPropagation();
            e.preventDefault();


        var checked_sourcecheckboxes = $("#sources input[type=checkbox]:checked");
        if (checked_sourcecheckboxes.length == 0) {
            $("#lblSourcesError").show();
            return false;
        }
        else {
            $("#lblSourcesError").hide();
        }
        var checked_academicformatcheckboxes = $("#academicFormatsRow input[type=checkbox]:checked");
        if (checked_academicformatcheckboxes.length == 0) {
            $("#lblacademicFormatError").show();
            return false;
        }
        else {
            $("#lblacademicFormatError").hide();
        }
        var checked_academicmediaformatcheckboxes = $("#academicMediaFormatRow input[type=checkbox]:checked");
        if (checked_academicmediaformatcheckboxes.length == 0) {
            $("#lblacademicmediaFormatError").show();
            return false;
        }
        else {
            $("#lblacademicmediaFormatError").hide();
        }
})


Get this bounty!!!

#StackBounty: #javascript #jquery Submitting form jQuery checkboxlist

Bounty: 50

In my requestForm submit function I have this logic that is check three checkbox and then displaying the label with an error message. Is there better logic. I would be happy for any kind of feedback since this is quite critical a part of my application.

$("#requestForm").submit(function (e) {
            e.stopPropagation();
            e.preventDefault();


        var checked_sourcecheckboxes = $("#sources input[type=checkbox]:checked");
        if (checked_sourcecheckboxes.length == 0) {
            $("#lblSourcesError").show();
            return false;
        }
        else {
            $("#lblSourcesError").hide();
        }
        var checked_academicformatcheckboxes = $("#academicFormatsRow input[type=checkbox]:checked");
        if (checked_academicformatcheckboxes.length == 0) {
            $("#lblacademicFormatError").show();
            return false;
        }
        else {
            $("#lblacademicFormatError").hide();
        }
        var checked_academicmediaformatcheckboxes = $("#academicMediaFormatRow input[type=checkbox]:checked");
        if (checked_academicmediaformatcheckboxes.length == 0) {
            $("#lblacademicmediaFormatError").show();
            return false;
        }
        else {
            $("#lblacademicmediaFormatError").hide();
        }
})


Get this bounty!!!