luyadev / luya

LUYA is a scalable web framework and content management system with the goal to please developers, clients and users alike.
https://luya.io
MIT License
812 stars 207 forks source link

LazyLoad widget don't work in another widget #1830

Closed cheerymagicsoftware closed 6 years ago

cheerymagicsoftware commented 6 years ago

What steps will reproduce the problem?

Using widget LazyLoad in another widgets (For example ListView). I add this widget in 'itemView' partial view of ListView widget.

What is the expected result?

lazyload.js must load.

What do you get instead? (A Screenshot can help us a lot!)

Don`t load lazyload.js lib.

LUYA Check ouput (run this script and post the result: luyacheck.php)


Additional infos

It's happend because static::$counter of class Widget already has counted +1 in ListView widget. In my case, I extended LazyLoad class and add local counter:

<?php
...
class LazyLoadExt extends Widget
{
    ...
    public static $localCounter = 0;
    ...
    public function init()
    {
         ...
         static::$localCounter++;
         static::$counter++;

         if (static::$localCounter== 1) {
             LazyLoadAsset::register($this->view);
             $this->view->registerJs("$('.lazy-image').lazyLoad();", View::POS_READY);
             $this->view->registerCss(".lazy-image { display: none; }");
         }
     }
     ...
}
?>
Q A
LUYA Version 1.0.7
PHP Version 7.1
Platform XAMPP
Operating system Windows
nadar commented 6 years ago

Maybe there is also another (better) way to check whether an asset is already registered or not (instead if the counter).

cheerymagicsoftware commented 6 years ago

Maybe... :)

nadar commented 6 years ago

Thanks for the report, will fix it asap