Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e231728

Browse files
committedApr 3, 2021
Minimized script and css
1 parent a6c6cc2 commit e231728

File tree

7 files changed

+35
-46
lines changed

7 files changed

+35
-46
lines changed
 

‎assets/helpers.js

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,16 @@
6464
replace(' ' + find + ' ', ' ') + replace).trim();
6565
}
6666

67-
function _lazyload() {
68-
defer.dom(_queryTarget, 0, '', function (node) {
69-
_replaceClass(node, 'defer-loading', 'defer-loaded');
70-
}, _options);
71-
72-
[].slice.call(document.querySelectorAll('style[defer]')).
73-
forEach(function(node) {
74-
node.media = node.getAttribute('data-media') || 'all';
75-
});
76-
}
67+
/*
68+
|--------------------------------------------------------------------------
69+
| Fallback for external libraries
70+
|--------------------------------------------------------------------------
71+
*/
7772

78-
function _copyright(_copyText) {
79-
if (console.log) {
80-
console.log(_copyText || [
81-
'Optimized by defer.php',
82-
'(c) 2021 AppSeeds',
83-
'Github: https://code.shin.company/defer.php'
84-
].join('\n'));
85-
}
86-
}
73+
// Fix missing dataLayer (for Google Analytics)
74+
// See: https://developers.google.com/analytics/devguides/collection/analyticsjs
75+
window.ga = window.ga || function () {(window.ga.q = window.ga.q || []).push(arguments)}; window.ga.l = Number(Date());
76+
window[_dataLayer] = window[_dataLayer] || [];
8777

8878
/*
8979
|--------------------------------------------------------------------------
@@ -102,27 +92,30 @@
10292
return;
10393
}
10494

105-
// Fallback for older versions
106-
window.defer_helper = {'defermedia': _lazyload};
107-
108-
/*
109-
|--------------------------------------------------------------------------
110-
| Fallback for external libraries
111-
|--------------------------------------------------------------------------
112-
*/
113-
114-
// Fix missing dataLayer (for Google Analytics)
115-
// See: https://developers.google.com/analytics/devguides/collection/analyticsjs
116-
window.ga = window.ga || function () {(window.ga.q = window.ga.q || []).push(arguments)}; window.ga.l = Number(Date());
117-
window[_dataLayer] = window[_dataLayer] || [];
118-
11995
/*
12096
|--------------------------------------------------------------------------
12197
| Main
12298
|--------------------------------------------------------------------------
12399
*/
124100

125-
_copyright();
126-
defer(_lazyload, _delay);
101+
// Lazyload all style tags
102+
defer(function() {
103+
[].slice.call(document.querySelectorAll('style[defer]')).
104+
forEach(defer.reveal);
105+
}, _delay);
106+
107+
// Lazyload all media
108+
defer.dom(_queryTarget, _delay, 0, function (node) {
109+
_replaceClass(node, 'defer-loading', 'defer-loaded');
110+
}, _options);
111+
112+
// Copyright
113+
if (console.log) {
114+
console.log([
115+
'Optimized by defer.php',
116+
'(c) 2021 AppSeeds',
117+
'Github: https://code.shin.company/defer.php'
118+
].join('\n'));
119+
}
127120

128121
})(this, document, console);

‎assets/styles.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ embed {
2020
}
2121

2222
.defer-faded [lazied]{
23-
transition: opacity 0.3s;
23+
transition: opacity 0.2s;
2424
}
2525

26-
.defer-faded .defer-loading:not([data-ignore]) {
27-
opacity: 0.1!important;
26+
.defer-faded .defer-loading {
27+
opacity: 0.5!important;
2828
}

‎public/helpers.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎public/styles.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎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/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/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);

0 commit comments

Comments
 (0)
This repository has been archived.