Forums › Forums › Search & Filter Pro › Ajax messing up Slick js script
Tagged: ajax, jquery conflict
- This topic has 19 replies, 2 voices, and was last updated 5 years, 8 months ago by Trevor.
-
Anonymous(Private) February 25, 2019 at 3:45 pm #203197
Hi !
I set up ajax search on a page which has jquery carousels (I used the Slick carousels). The sorting works fine, but when the results show up, the carousels don’t work (they do one I reload the page).
Here is the page (I have not done any compatibility or responsive yet hopefully it will still show up fine) : http://bsm.connivence-poleweb.fr/projets/
How could I fix this ?
Thanks !
CarolineTrevor(Private) February 25, 2019 at 4:58 pm #203210You might find this or something like it would work if the preceding assumption that I made was that slick was being used inside the Ajax Container:
<script>(function ( $ ) { "use strict"; $(document).on("sf:ajaxfinish", ".searchandfilter", function(){ $('.skills_section').slick('unslick'); /* ONLY remove the classes and handlers added on initialize */ $('.my-slide').remove(); /* Remove current slides elements, in case that you want to show new slides. */ $('.skills_section').slick(getSliderSettings()); /* Initialize the slick again */ }); }(jQuery));</script>
But the classes used above would need to change to match what classes yours uses, so you need to modify this code.
Anonymous(Private) February 26, 2019 at 8:03 am #203257The slider is indeed in the ajax section.
My skills in jQuery are very limited, what are the skills_section / my-slide supposed to match ? Here’s my mark up :
<div class=”contents”>
<section class=”visuels-realisations”> <— This is the slider block targeted by the slick script
<div>Image</div> <— These are the slides
<div>Image</div>
</section><section class=”visuels-realisations”> <— This is the slider block targeted by the slick script
<div>Image</div> <— These are the slides
<div>Image</div>
</section>
</div>Trevor(Private) February 26, 2019 at 9:34 am #203264As you are not wanting to remove slides, that line can probably go. So, maybe this:
<script>(function ( $ ) { "use strict"; $(document).on("sf:ajaxfinish", ".searchandfilter", function(){ $('.visuels-realisations').slick('unslick'); $('.visuels-realisations').slick(getSliderSettings()); }); }(jQuery));</script>
If you don’t know how to add JS to your site, you can use this plugin:
https://wordpress.org/plugins/custom-css-js/
You won’t need the script tags, as that plugin adds them for you.
Anonymous(Private) February 26, 2019 at 10:29 am #203269I’ve installed the plugin and pasted the code but it didn’t change anything. Maybe the synthax is wrong. I also tried as said by the plugin :
jQuery(document).ready(function( $ ){ "use strict"; $(document).on("sf:ajaxfinish", ".searchandfilter", function(){ $('.visuels-realisations').slick('unslick'); $('.visuels-realisations').slick(getSliderSettings()); }); });
But didn’t work either.
Here’s the error from the console :Uncaught TypeError: Cannot read property ‘unslick’ of undefined
at a.fn.init.$.fn.slick (slick.js?ver=1:3005)
at HTMLFormElement.<anonymous> (?_sft_categories-projets=ouvrages-publics:334)
at HTMLDocument.dispatch (jquery.js?ver=1.12.4:3)
at HTMLDocument.r.handle (jquery.js?ver=1.12.4:3)
at Object.trigger (jquery.js?ver=1.12.4:3)
at Object.a.event.trigger (jquery-migrate.min.js?ver=1.4.1:2)
at HTMLFormElement.<anonymous> (jquery.js?ver=1.12.4:3)
at Function.each (jquery.js?ver=1.12.4:2)
at a.fn.init.each (jquery.js?ver=1.12.4:2)
at a.fn.init.trigger (jquery.js?ver=1.12.4:3 -
AuthorPosts