1

I have a patternlab implementation (edition-node-gulp). I'm trying to add selectize.js to it (https://github.com/selectize/selectize.js). When I add the indicated jquery function to the foot.mustache file, and check out the result, console indicates reference error: can't find variable $ (i.e. not recognizing jquery). When I add jquery.min.js to the head.mustache, above my selectize.js script tag, some of pattern lab's functionality stops working, some of it STARTS working, and I start getting different error messages (i.e. it now recognizes jquery). TypeError: $('#select-beast').selectize is not a function.

Here's head.mustache:

<!DOCTYPE html>
<html class="{{ htmlClass }}">
  <head>
    <title>{{ title }}</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width" />

    <link rel="stylesheet" href="../../css/style.css?{{ cacheBuster }}" media="all" />
    <link rel="stylesheet" href="../../css/pattern-scaffolding.css?{{ cacheBuster }}" media="all" />
    <!-- Begin Pattern Lab (Required for Pattern Lab to run properly) -->
    {{{ patternLabHead }}}
    <!-- End Pattern Lab -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
    <script src="../js/selectize.js"></script>
  </head>
  <body class="{{ bodyClass }} prg">

And here is foot.mustache:

  <!--DO NOT REMOVE-->
  {{{ patternLabFoot }}}

  <!--selectize -->

<script type="text/javascript" src="selectize.js"></script>
<link rel="stylesheet" type="text/css" href="selectize.css" />
<script>
  $(function() {
      $('select').selectize(options);
  });
</script>
<!-- end selectize -->

  </body>
</html>
Mike Earley
  • 1,223
  • 4
  • 20
  • 47

2 Answers2

0

Maintainer of Pattern Lab Node here.

In my opinion, your problem is your path.

<script src="../js/selectize.js"></script>

Change it to

<script src="../../js/selectize.js"></script>

Because the way Pattern Lab outputs patterns, the base public/ directory is always two levels up. You'll notice the other files in that head pattern are going two levels up too.

enter image description here

public/

  • patterns/
    • pattern-name/file
  • js/
Brian Muenzenmeyer
  • 1,026
  • 1
  • 7
  • 17
  • Should I be declaring jquery? It seems like it's already included in Pattern Lab, if I recall, but I noticed that if I do not include it, I'm getting errors indicating $ isn't a variable. – Mike Earley Feb 16 '18 at 17:19
  • once I included Jquery and jquery UI stuff started to work. The documentation (for selectize) doesn't state you need jquery UI, just jquery. – Mike Earley Mar 26 '18 at 20:34
0

I guess it will be better to include JS or CSS Libraries by CDN, here you can find selectize.js CDN (https://cdnjs.com/libraries/selectize.js/)

Example:

<script src="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.4/js/standalone/selectize.min.js"></script>