# CONTENTS OF THIS FILE
* [Introduction](#introduction)
* [Requirements](#requirements)
* [Recommended modules](#recommended-modules)
* [Installation](#installation)
* [Configuration](#configuration)
* [Features](#features)
* [Updating](#updating)
* [Troubleshooting](#troubleshooting)
* [FAQ](#faq)
* [Aspect ratio template](#aspect-ratio-template)
* [Contribution](#contribution)
* [Maintainers](#maintainers)
.
***
***
.
# INTRODUCTION
Provides integration with bLazy and or Intersection Observer API to lazy load
and multi-serve images to save bandwidth and server requests. The user will have
faster load times and save data usage if they don't browse the whole page.
.
***
***
.
# REQUIREMENTS
1. bLazy library:
* [Download bLazy](https://github.com/dinbror/blazy)
* Extract it as is, rename **blazy-master** to **blazy**, so the assets are:
+ **/sites/../libraries/blazy/blazy.min.js**
2. PHP 5.6+ (let us know if Blazy can go lower?)
3. Any of autoloader modules:
* [registry_autoload](https://www.drupal.org/project/registry_autoload)
* [psr0](https://www.drupal.org/project/psr0)
* [xautoload](https://www.drupal.org/project/xautoload)
* [autoload](https://www.drupal.org/project/autoload)
* Others?
Skip if you already one have, I meant, have one. If you have others, please
create a feature to include it in the module `hook_requirements()`. The order
implies the recommendation priority.
.
***
***
.
# INSTALLATION
[Installing Drupal 7 module](http://drupal.org/documentation/install/modules-themes/modules-7)
### Two steps below are crucial, otherwise Blazy complains missing dependencies:
1. Visit **/admin/modules** and install one of autoloader as mentioned above.
Save! Do not install Blazy, yet, since Blazy has no hard dependency on any.
The order above indicates priority. The first found will be locked.
You can install another, and uninstall the other which suits you better.
2. Install Blazy. Once an autoloader is installed, it will be locked for
Blazy usage later to avoid accidental removal.
As long as you stick to these 2 steps, it should be just fine like regular
modules with hard dependencies.
### Known issues:
* **autoload**: must run `drush aur` and `drush cc` on Blazy activation, or
fatal. The same procedure applies whenever blazy-related modules are
activated, or adding new classes. Especially during DEV, Alpha, Beta,
before RC. If not using drush, consider the other two:
**registry_autoload**, **xautoload**.
If any issue with other autoloaders, kindly let us know. Blazy doesn't have a
hard dependency on any, it is on your own discretion.
**At any rate, solution is available:**
* Before any update, open `/admin/config/development/performance`, so to clear
cache easily before running into issues.
* Know how to run `drush cc all` or clear cache.
* Only **at worst** case, clear registry, or if you don't drush, install and
know how to use registry_rebuild.module safely.
This particular issue never happens at D8, please bear with D7, and current
Blazy limitation and development process.
### WTF FTW?
Blazy uses classes as a direct backport of 8.x.
.
***
***
.
# FEATURES
* Supports core Image.
* Supports Picture.
* Supports Colorbox/ Photobox/ PhotoSwipe, etc, also multimedia lightboxes.
* Multi-serving lazyloaded images, including multi-breakpoint CSS backgrounds.
* Lazyload video iframe urls via custom coded, or Media.
* Supports inline images and iframes with lightboxes, and grid or CSS3 Masonry
via Blazy Filter. Enable Blazy filter at **/admin/config/content/formats**,
and check out instruction at **/filter/tips**.
* Blazy Grid formatter for Image, Media and Text with multi-value.
* Delay loading for below-fold images until 100px (configurable) before they are
visible at viewport.
* A simple effortless CSS loading indicator.
* It doesn't take over all images, so it can be enabled as needed via Blazy
formatters, or its supporting modules.
## OPTIONAL FEATURES
* Views fields for File Entity and Media integration, see Slick Browser.
* Views style plugin Blazy Grid for Grid Foundation or CSS3 Masonry.
* Field formatters: Blazy with Media integration.
.
***
***
.
# CONFIGURATION
Be sure to enable Blazy UI which can be uninstalled at production later.
* Go to Manage display page, e.g.:
[Admin page displays](/admin/structure/types/manage/page/display)
* Find **Blazy** formatter under **Manage display**.
* Go to [Blazy UI](/admin/config/media/blazy) to manage few global options,
including enabling support to bring Picture into blazy-related formatters.
### USAGES: BLAZY FOR MULTIMEDIA GALLERY VIA VIEWS UI
1. Add a Views style **Blazy Grid** for entities containing Media or Image.
2. Add a Blazy formatter for the Media or Image field.
3. Add any lightbox under **Media switcher** option.
4. Limit the values to 1 under **Multiple field settings** > **Display**.
5. Be sure to leave **Use field template** under **Style settings** unchecked.
If checked, the gallery is locked to a single entity, that is no Views
gallery, but gallery per field.
Check out the relevant sub-module docs for details.
.
***
***
.
# RECOMMENDED MODULES
* [Markdown](https://www.drupal.org/project/markdown)
To make reading this README a breeze at [Blazy help](/admin/help/blazy_ui)
## MODULES THAT INTEGRATE WITH OR REQUIRE BLAZY
* [Ajaxin](https://www.drupal.org/project/ajaxin)
* [Intersection Observer](https://www.drupal.org/project/io)
* [Blazy PhotoSwipe](https://www.drupal.org/project/blazy_photoswipe)
* [GridStack](https://www.drupal.org/project/gridstack)
* [Outlayer](https://www.drupal.org/project/outlayer)
* [Intense](https://www.drupal.org/project/intense)
* [Mason](https://www.drupal.org/project/mason)
* [Slick](https://www.drupal.org/project/slick)
* [Slick Lightbox](https://www.drupal.org/project/slick_lightbox)
* [Slick Views](https://www.drupal.org/project/slick_views)
* [Slick Paragraphs](https://www.drupal.org/project/slick_paragraphs)
* [Jumper](https://www.drupal.org/project/jumper)
* [Zooming](https://www.drupal.org/project/zooming)
* [ElevateZoom Plus](https://www.drupal.org/project/elevatezoomplus)
Most duplication efforts from the above modules will be merged into
\Drupal\blazy\Dejavu or anywhere else namespace.
**What dups?**
The most obvious is the removal of formatters from Intense, Zooming,
Slick Lightbox, Blazy PhotoSwipe, and other (quasi-)lightboxes. Any lightbox
supported by Blazy can use Blazy, or Slick formatters if applicable instead.
We do not have separate formatters when its prime functionality is embedding
a lightbox, or superceded by Blazy.
Blazy provides a versatile and reusable formatter for a few known lightboxes
with extra advantages:
lazyloading, grid, multi-serving images, Responsive image,
CSS background, captioning, etc.
Including making those lightboxes available for free at Views Field for
File entity, Media and Blazy Filter for inline images.
If you are developing lightboxes and using Blazy, I would humbly invite you
to give Blazy a try, and consider joining forces with Blazy, and help improve it
for the above-mentioned advantages. We are also continuously improving and
solidifying the API to make advanced usages a lot easier, and DX friendly.
Currently, of course, not perfect, but have been proven to play nice with at
least 7 lightboxes, and likely more.
## SIMILAR MODULES
[Lazyloader](https://www.drupal.org/project/lazyloader)
.
***
***
.
# MAINTAINERS/CREDITS
* [Gaus Surahman](https://www.drupal.org/user/159062)
* [Contributors](https://www.drupal.org/node/2663268/committers)
* CHANGELOG.txt for helpful souls with their patches, suggestions and reports.
## READ MORE
See the project page on drupal.org:
[Blazy module](http://drupal.org/project/blazy)
See the bLazy docs at:
* [Blazy library](https://github.com/dinbror/blazy)
* [Blazy website](http://dinbror.dk/blazy/)
.
***
***
.
# FAQ
## CURRENT DEVELOPMENT STATUS
A full release should be reasonable after proper feedback from the community,
some code cleanup, and optimization where needed. Patches are very much welcome.
## PROGRAMATICALLY
[blazy.api.php](https://git.drupalcode.org/project/blazy/blob/7.x-1.x/blazy.api.php)
## BLAZY VS. B-LAZY
`blazy` is the module namespace. `b-lazy` is the default CSS class to lazy load.
* The `blazy` class is applied to the **top level container**, e,g.. `.field`,
`.view`, `.item-list`, etc., those which normally contain item collection.
In this container, you can feed any `bLazy` script options into `[data-blazy]`
attribute to override existing behaviors per particular page, only if needed.
* The `b-lazy` class is applied to the **target item** to lazy load, normally
the children of `.blazy`, but not always. This can be IMG, VIDEO, DIV, etc.
## WHAT `BLAZY` CSS CLASS IS FOR?
Aside from the fact that a module must reserve its namespace including for CSS
classes, the `blazy` is actually used to limit the scope to scan document.
Rather than scanning the entire DOM, you limit your work to a particular
`.blazy` container, and these can be many, no problem. This also allows each
`.blazy` container to have unique features, such as ones with multi-breakpoint
images, others with regular images; ones with a lightbox, others with
image to iframe; ones with CSS background, others with regular images; etc.
right on the same page. This is only possible and efficient within the `.blazy`
scope.
## WHY NOT `BLAZY__LAZY` FOR `B-LAZY`?
`b-lazy` is the default CSS class reserved by JS script. Rather than recreating
a new one, respecting the defaults is better. Following BEM standard is not
crucial for most JS generated CSS classes. Uniqueness matters.
## NATIVE LAZY LOADING
Native lazy loading is supported by Chrome 76+ as of 01/2019. Blazy or IO will
be used as fallback for other browsers instead. Currently the offset/ threshold
before loading is hard-coded to [800px at Chrome](https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/frame/settings.json5?l=971-1003&rcl=e8f3cf0bbe085fee0d1b468e84395aad3ebb2cad), so it
might only be good for super tall pages for now, be aware.
[Read more](https://web.dev/native-lazy-loading/)
## ANIMATE.CSS INTEGRATION
Blazy container (`.media`) can be animated using
[animate.css](https://github.com/daneden/animate.css). The container is chosen
to be the animated element so to support various use cases:
CSS background, picture, image, or rich media contents.
### Requirements:
* The `animate.css` library included in your theme, or via `animate_css` module.
* Data attributes: `data-animation`, with optional: `data-animation-duration`,
`data-animation-delay` and `data-animation-iteration-count`, as seen below.
```
function MYTHEME_preprocess_blazy(&$variables) {
$settings = &$variables['settings'];
$attributes = &$variables['attributes'];
// Be sure to limit the scope, only animate for particular conditions.
if ($settings['entity_id'] == 123
&& $settings['field_name'] == 'field_media_animated') {
$attributes['data-animation'] = 'wobble';
$attributes['data-animation-duration'] = '3s';
$attributes['data-animation-delay'] = '.3s';
// Iteration can be any number, or infinite.
$attributes['data-animation-iteration-count'] = 'infinite';
}
}
```
## PERFORMANCE TIPS:
* If breakpoints provided with tons of images, using image styles with ANY crop
is recommended to avoid image dimension calculation with individual images.
The image dimensions will be set once, and inherited by all images as long as
they contain word crop. If using scaled image styles, regular calculation
applies.
.
.
***
***
.
# UPDATE SOP
Visit any of the following URLs when updating Blazy, or its related modules.
Please ignore any documentation if already aware of Drupal site building. This
is for the sake of completed documentation for those who may need it.
1. [Performance](/admin/config/development/performance)
Unless an update is required, clearing cache should fix most issues.
* Hit **Clear all caches** button once the new Blazy in place.
* Regenerate CSS and JS as the latest fixes may contain changes to the assets.
Ignore below if you are aware, and found no asset changes from commits.
Normally clearing cache suffices when no asset changes are found.
* Uncheck CSS and JS aggregation options under Bandwidth optimization.
* Save.
* [Ignorable] See one of Blazy related pages if display is expected.
* [Ignorable] Only clear cache if needed.
* Check both options again.
* Save again.
* [Ignorable] Press F5, or CMD/ CTRL + R to refresh browser cache if
needed.
2. [Admin status](/admin/reports/status)
Check for any pending update, and run /update.php from browser address bar.
3. If `theme_blazy()` is customized, compare against the latest.
4. Always test updates at DEV or STAGING environments like a pro so nothing
breaks your PRODUCTION site till everything is thoroughly reviewed.
5. Read more the [TROUBLESHOOTING](#troubleshooting) section for common trouble
solutions.
## BROKEN MODULES
Alpha, Beta, DEV releases are for developers only. Beware of possible breakage.
However if it is broken, unless an update is provided, running `drush cc` during
DEV releases should fix most issues as we add new services, or change things.
If you don't drush, before any module update:
1. Always open a separate tab:
[Performance](/admin/config/development/performance)
2. And so you are ready to hit **Clear all caches** button if any issue. Do not
reload this page.
3. Instead view other browser tabs, and simply hit the button if any
issue.
4. Run `/update.php` as required.
5. Only at worst case, know how to run
[Registry Rebuild](https://www.drupal.org/project/registry_rebuild) safely.
.
***
***
.
# TROUBLESHOOTING
* Blazy and its sub-modules -- Slick, GridStack, etc. are tightly coupled.
Be sure to have the latest release date or matching versions in the least.
DEV for DEV, Beta for Beta, etc. Mismatched versions may lead to errors
especially before having RCs. Mismatched branches will surely be errors.
* Resizing is not supported. Just reload the page.
* Images are gone, only eternal blue loader is flipping like a drunk butterfly.
Solution: ensures that blazy library is loaded. And temporarily switch to
stock Bartik themes.
* Press F12 at any browser, and see the errors at the browser console. Any JS
error will prevent Blazy from working identified by eternal blue loaders.
* Images are collapsed. Solution: choose one of the Aspect ratio.
* Images or videos aren't responsive. Solution: choose one of the Aspect ratio.
* Images are distorted. Solution: choose the correct Aspect ratio. If unsure,
choose "fluid" to let the module calculate aspect ratio automatically.
[Check out few aspect ratio samples](https://cgit.drupalcode.org/blazy/tree/docs/ASPECT_RATIO.md)
### 1. VIEWS INTEGRATION
Blazy provides a simple Views field for File Entity, and Media.
When using Blazy formatter within Views, check **Use field template** under
**Style settings**, if trouble with Blazy Formatter as a stand alone Views
output.
On the contrary, uncheck **Use field template**, when Blazy formatter
is embedded inside another module such as Slick so to pass the renderable
array to work with accordingly.
This is a Views common gotcha with field formatter, so be aware of it.
If confusing, just toggle **Use field template**, and see the output. You'll
know which works.
### 2. BLAZY GRID WITH SINGLE VALUE FIELD (D7 ONLY)
This is no issue at D8. Blazy Grid formatter is designed for multi-value fields.
Unfortunately no handy way to disable formatters for single value at D7. So
the formatter is available even for single value, but not actually
functioning. Please ignore it till we can get rid of it at D7, if possible,
without extra legs.
### 3. MIN-WIDTH
If the images appear to be shrink within a **floating** container, add
some expected width or min-width to the parent container via CSS accordingly.
Non-floating image parent containers aren't affected.
### 4. MIN-HEIGHT
Add a min-height CSS to individual element to avoid layout reflow if not using
**Aspect ratio** or when **Aspect ratio** is not supported such as with
Responsive image. Otherwise some collapsed image containers will defeat the
purpose of lazyloading. When using CSS background, the container may also be
collapsed.
### 5. SOLUTIONS
Both layout reflow and lazyloading delay issues are actually taken care of
if **Aspect ratio** option is enabled in the first place.
Adjust, and override blazy CSS/ JS files accordingly.
### 6. BLAZY FILTER
Blazy Filter must run after **Align/ Caption filters** as otherwise the required
CSS class `b-lazy` will be moved into `