Unverified Commit b3b81185 authored by osman's avatar osman

Fix [#2960488]

Cleanup the code.
parent b9b683e1
......@@ -15,21 +15,67 @@ and **inline-iframes**.
You can still use this module tandem with it, though that is not a requirement.
## Requirements
* **[Libraries API][4]** module
* **bLazy v1.8.2** script as a library item:
[Download bLazy][3] from https://github.com/dinbror/blazy
1) Extract the downloaded file,
2) rename *blazy-master* directory to *blazy*,
3) copy the folder into one of the following places that *Libraries API*
module supports, `sites/all/libraries` (or site-specific libraries folder):
i.e.: `sites/all/libraries/blazy/blazy.min.js`
* **bLazy v1.8.2** script as a library item
## Installing Manually
- [Download bLazy][3] from https://github.com/dinbror/blazy
- Extract the downloaded file,
- rename *blazy-master* directory to *blazy*,
- copy the folder into the `/libraries` folder: i.e.: `libraries/blazy/blazy.min.js`
## Installing via Composer
- Run `composer require --prefer-dist composer/installers` to ensure that you have the `composer/installers` package installed. This package facilitates the installation of packages into directories other than `/vendor` (e.g. `/libraries`) using Composer.
- If your `composer.json` doesn't already have a definition for the `libraries` path, define one similar to the one below, depending on your setup:
``` json
"extra": {
"installer-paths": {
"web/libraries/{$name}": ["type:drupal-library"]
}
}
```
## Installation
- Add following to the "repositories" section of `composer.json`:
``` json
"repositories": [
{
"type": "package",
"package": {
"name": "dinbror/blazy",
"version": "1.8.2",
"type": "drupal-library",
"extra": {
"installer-name": "blazy"
},
"source": {
"type": "git",
"url": "https://github.com/dinbror/blazy",
"reference": "1.8.2"
}
}
},
]
```
- Install the required _Blazy_ library:
``` sh
composer require 'dinbror/blazy:1.8.2'
```
- Install this module:
``` sh
composer require 'drupal/lazy:^1.0'
```
Install the module as usual. More information can be found at
https://www.drupal.org/docs/7/extend/installing-modules
## Usage
......@@ -38,12 +84,12 @@ This modules makes a new text filter available for the text-formats: *Lazy-load*
Enable the *Lazy-load* filter for the desired text-formats. i.e. *Full HTML* or
*Filtered HTML*
Check out the module configuration at `admin/config/content/lazy`. The default
settings should work for most developers. Incase they are not, change the
settings to suit your needs and submit the form.
Check out the configuration at `admin/config/content/lazy`.
Configure which elements should be lazy-loaded in the **global settings** area.
**Blazy configuration** options come with the Blazy defaults. Refer to [Blazy plugin documentation][5] for each setting.
This configuration is used globally for all the text-formats having *Lazy-load*
filter enabled.
## Use Case
......@@ -65,3 +111,4 @@ cached, there should not be any changes in performance.
[2]: https://www.drupal.org/project/blazy
[3]: https://github.com/dinbror/blazy/archive/master.zip
[4]: https://www.drupal.org/project/libraries
[5]: http://dinbror.dk/blog/blazy/
{
"name": "drupal/lazy",
"type": "drupal-module",
"description": "Lazy-loading images",
"description": "Lazy-loading images and iframes",
"keywords": ["Drupal", "bLazy", "Lazy-load"],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/lazy",
......@@ -15,26 +15,5 @@
"support": {
"issues": "https://www.drupal.org/project/issues/lazy",
"source": "http://cgit.drupalcode.org/lazy"
},
"require": {
"dinbror/blazy": "1.8.2"
},
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "package",
"package": {
"name": "dinbror/blazy",
"version": "1.8.2",
"type": "drupal-library",
"dist": {
"url": "https://github.com/dinbror/blazy/archive/1.8.2.zip",
"type": "zip"
}
}
}
]
}
}
......@@ -73,9 +73,11 @@ function lazy_page_attachments(array &$attachments) {
*/
function lazy_is_enabled() {
$status = [];
$filters = db_query('SELECT c.name, c.data FROM {config} c WHERE c.name LIKE :format', [
$connection = \Drupal::database();
$query = $connection->query('SELECT c.name, c.data FROM {config} c WHERE c.name LIKE :format', [
':format' => 'filter.format.%',
])->fetchAllKeyed();
]);
$filters = $query->fetchAllKeyed();
foreach ($filters as $key => $filter) {
$filter = unserialize($filter);
if (
......
......@@ -41,7 +41,7 @@ class LazyForm extends ConfigFormBase {
&& !boolval($config->get('alter_tag')['iframe'])
&& !boolval($config->get('image_fields'))
) {
drupal_set_message($this->t('buildForm: Lazy-load is currently disabled. Update configuration in global settings to enable it.'), 'warning');
drupal_set_message($this->t('Lazy-load is currently disabled. Update configuration in global settings to enable it.'), 'warning');
}
$form['settings'] = [
......
......@@ -11,8 +11,8 @@ use Drupal\filter\Plugin\FilterBase;
*
* @Filter(
* id = "lazy_filter",
* title = @Translation("Lazyload images"),
* description = @Translation("Lazy load images via bLazy"),
* title = @Translation("Lazy-load images and IFRAMEs via bLazy"),
* description = @Translation("<a href=':url'>Configure options</a>", arguments = {":url" = "/admin/config/content/lazy"}),
* type = Drupal\filter\Plugin\FilterInterface::TYPE_TRANSFORM_REVERSIBLE,
* weight = 20
* )
......@@ -68,15 +68,16 @@ class LazyFilter extends FilterBase {
$tags = \Drupal::config('lazy.blazy')->get('alter_tag');
$tags = implode(' ', $tags);
$tags = trim(str_replace(['0'], '', $tags));
$options = ['%img' => '<img>', '%iframe' => '<iframe>'];
switch ($tags) {
case 'img iframe':
return t('Both %img and %iframe elements are lazy-loaded.', ['%img' => '<img>', '%iframe' => '<iframe>']);
return t('Both %img and %iframe elements are lazy-loaded.', $options);
case 'img':
return t('%img elements are lazy-loaded.', ['%img' => '<img>', '%iframe' => '<iframe>']);
return t('%img elements are lazy-loaded.', $options);
case 'iframe':
return t('%iframe elements are lazy-loaded.', ['%img' => '<img>', '%iframe' => '<iframe>']);
return t('%iframe elements are lazy-loaded.', $options);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment