Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 899f4ff

Browse files
committed
Improved code logic
1 parent 05bbec7 commit 899f4ff

File tree

8 files changed

+10
-14
lines changed

8 files changed

+10
-14
lines changed

src/Helpers/DeferConstant.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class DeferConstant
152152
// -------------------------------------------------------------------------
153153

154154
// Source files
155-
const SRC_DEFERJS_CDN = 'https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.3.0/dist/defer_plus.min.js';
155+
const SRC_DEFERJS_CDN = 'https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer_plus.min.js';
156156
const SRC_POLYFILL_CDN = 'https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver';
157157
const SRC_DEFERJS_FALLBACK = DEFER_PHP_ROOT . '/public/lib/defer_plus.min.js';
158158
const SCR_DEFERJS_CACHE = DEFER_PHP_ROOT . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;

src/Helpers/DeferMinifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static function minifyCss($input)
4848
// Minify the css code
4949
// See: https://gist.github.com/clipperhouse/1201239/cad48570925a4f5ff0579b654e865db97d73bcc4
5050
$minified = preg_replace('/\s*([,\+\*\/>~;:!}{]{1})\s*/', '$1', $input);
51-
$minified = strtr($minified, [';}' => '}', "\r" => '', "\n" => '', '0.' => '.']);
51+
$minified = strtr($minified, [';}' => '}', "\r" => '', "\n" => '']);
5252

5353
// Strip comments
5454
// See: https://gist.github.com/orangexception/1292778

src/Helpers/DeferOptimizer.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,6 @@ public static function optimizeElement(ElementNode &$node, DeferOptions &$option
238238
$lazied = $resolver->lazyload();
239239

240240
if ($lazied) {
241-
$node->addClass(DeferConstant::CLASS_DEFER_LOADING);
242-
243241
if (!empty($fallback)) {
244242
$fallback->detach();
245243
$node->follow($fallback);

src/Helpers/DeferOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public function getWellKnown3rd($useCache = true)
241241
* 'manually_add_deferjs' => false,
242242
*
243243
* // URL to defer.js javascript file.
244-
* // Default: https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.3.0/dist/defer_plus.min.js
244+
* // Default: https://cdn.jsdelivr.net/npm/@shinsenter/defer.js@2.4.0/dist/defer_plus.min.js
245245
* 'deferjs_src' => \AppSeeds\DeferConstant::SRC_DEFERJS_CDN,
246246
*
247247
* // URL to javascript contains fixes.

src/Resolvers/DeferResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ public function createDataAttr($attr, $placeholder = '')
359359
if ($placeholder != $value) {
360360
$this->node->setAttribute($attr, $placeholder);
361361
$this->node->setAttribute($data_attr, $value);
362+
$this->node->addClass(DeferConstant::CLASS_DEFER_LOADING);
362363
}
363364

364365
return $this;

src/Resolvers/IframeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function normalize()
4848
}
4949

5050
if (empty($this->node->getAttribute('title'))) {
51-
$this->node->setAttribute('title', basename($src ?: ''));
51+
$this->node->setAttribute('title', basename($src ?: 'blank'));
5252
}
5353

5454
// Browser-level image lazy-loading for the web

src/Resolvers/StyleResolver.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ public function lazyload()
119119
// Only defer when it is a CSS node
120120
// and "onload" attribute is not provided
121121
$media = $this->node->getAttribute('media');
122-
123-
if (!empty($media)) {
124-
$this->node->setAttribute('data-media', $media);
125-
}
122+
$this->node->setAttribute('data-media', $media ?: 'all');
126123

127124
// Lazyload the style
128125
$this->node->setAttribute('media', DeferConstant::TEMPLATE_LAZY_MEDIA_ATTR);

tests/v2/test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@
2828
require_once BASE . DS . 'helpers.php';
2929

3030
// Test request arguments
31-
$_REQUEST['nodefer'] = 0;
32-
$_REQUEST['debug'] = 0;
33-
$_REQUEST['debug_time'] = 1;
34-
$_REQUEST['minify_output_html'] = 1;
31+
$_REQUEST['nodefer'] = 0;
32+
$_REQUEST['debug'] = 0;
33+
$_REQUEST['debug_time'] = 1;
3534

3635
// New instance
3736
$defer = new AppSeeds\Defer([
@@ -79,6 +78,7 @@
7978
'.header_top_icon_list img',
8079
'.header_logo img',
8180
'.banner img',
81+
'.logo',
8282
],
8383
]);
8484

0 commit comments

Comments
 (0)