Unable to get enquire.js to work with drupal 8

38 views Asked by At

I would to use this JS library in a Drupal 8 theme. So I have added it with npm in my project then in my theme: libraries.yml

at.enquire:
  remote: https://raw.githubusercontent.com/WickyNilliams/enquire.js
  version: "2.1.6"
  license:
    name: MIT
    url: https://raw.githubusercontent.com/WickyNilliams/enquire.js/master/LICENSE
    gpl-compatible: true
  js:
    https://cdnjs.cloudflare.com/ajax/libs/enquire.js/2.1.6/enquire.min.js: { type: external, minified: true }
  dependencies:
    - core/jquery
    - core/matchmedia

Then loaded vi amy info.yml:

<script src="https://cdnjs.cloudflare.com/ajax/libs/enquire.js/2.1.6/enquire.min.js"></script>

In my js file:

$(document).ready(function () {
enquire.register("screen and (min-width:768px) and (max-width:1024px) and (orientation: landscape) and (min-resolution:1dppx)", {
      deferSetup : true,
        setup : function() {
        $(".acces_rubriques iframe").height('55vh').width('45vw');//Video Gde Taille HP
        },
      match : function() {
        console.log('Enquire.js : BP pour: tabletlandscape');
           //Video sur HP
      $(".acces_rubriques iframe").height('55vh').width('65vw');//Video Gde Taille HP
        },
        unmatch : function() {
            example.unmatch();
        }
    });//enquire.register(tabletlandscape)
  });//Fin document.ready

But nothing happen on my android Tab.

What could be missing ? Thanks

1

There are 1 answers

0
webmaster pf On

I figure it out to adopt jquery v3 bundle on Drupal8. But I need to use this to work:

  jQuery( document ).ready(function() {
//Enquire stuff here
}

and load the npm enquire.js into twig template via:

{{ attach_library('THEMENAME/npm.enquire') }}

and proper JS via THEMENAME.libraries.yml:

npm.enquire:
  version: VERSION
  js:
    #Chargement des JS ajoutées via NPM ou externes
    node_modules/enquire.js/dist/enquire.min.js: {} 

So it work now. :)