variar / grav-plugin-unitegallery

Grav plugin to create image galleries with unitegallery js library
MIT License
19 stars 5 forks source link

unitegallery is not a function #4

Closed citrik closed 7 years ago

citrik commented 7 years ago

I'm getting an error with my Grav install using Unite Gallery.

Uncaught TypeError: jQuery(...).unitegallery is not a function
    at HTMLDocument.<anonymous> ((index):93)
    at i (jquery-2.x.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-2.x.min.js:2)
    at Function.ready (jquery-2.x.min.js:2)
    at HTMLDocument.J (jquery-2.x.min.js:2)

Line 93 of my index.html is where the gallery is being called (Starting from line 91)

<script type="text/javascript">
              jQuery(document).ready(function(){
                jQuery("#unite-gallery").unitegallery({"gallery_theme":"tiles"});
              });
        </script>

Looking in the earlier stages of the index.html I can see jQuery is being sourced, but I don't see that for the unitegallery.min.js (Starting from line 22)

    <script src="/grav/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" ></script>
<script src="/grav/user/themes/deliver/js/modernizr.custom.71422.js" type="text/javascript" ></script>
<script src="/grav/user/plugins/cookiesnotice/assets/js/jquery.cookie.js" type="text/javascript" ></script>
<script src="/grav/user/plugins/cookiesnotice/assets/js/cookiesnotice.js" type="text/javascript" ></script>
<script src="/grav/user/themes/deliver/js/deliver.js" type="text/javascript" ></script>
<script src="/grav/user/themes/deliver/js/slidebars.min.js" type="text/javascript" ></script>
<script src="/grav/user/themes/deliver/js/jquery.slideme2.js" type="text/javascript" ></script>

Looking at unitegallery_extension.php it seems like it might be an issue around line 63 / 80 / 85 which is where the unitegallery.min.js should be added to the grav['assets'] but nothing is standing out to me as an issue. Could this be caused by me having an incorrect configuration of the plugin? I'd appreciate any advice as the gallery looks really nice and It'd be great to get it up and running with Grav. -Thanks!-

variar commented 7 years ago

Hi, Could you try to disable twig caching for the page with the gallery. Adding never_cache_twig: true to the frontmatter should do the trick.

There is currently an issue with assets added by my twig function not ending up in cache. I'm looking for solution.

citrik commented 7 years ago

So the full content of my gallery.md file is

---
never_cache_twig: true
---

And the full content of my gallery.html.twig file is

<div class="modular-row gallery-container {{ page.header.class }}">
    {{ unite_gallery(page.media.images) }}
</div>

Is that correct? Do I need to add the "never_cache_twig: true" somewhere else? Thanks!

variar commented 7 years ago

This looks ok if gallery.md is part of modular page. You may add cache_enabled: false to disable all caching for that page just to check if that works.

variar commented 7 years ago

Looked through shrotcodes core plugin and got an idea how assets can be added even with enabled caching using page content metadata. Will try to implement it tomorrow.

carriersim commented 7 years ago

I had the same problem, the assets were not loading. I solved the problem by installing the Assets plugin.

variar commented 7 years ago

The functionality provided by this Assets plugin is definitely not required by Unitegallery plugin. However, processing that Assets plugin does for each page might trigger something that helps to load assets. I'll look into its code.

variar commented 7 years ago

I've implemented new way to add js and css assets with caching enabled. @citrik could you please check if it works for you?