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

Commit a6c6cc2

Browse files
committed
Better JS file
1 parent d29436a commit a6c6cc2

File tree

4 files changed

+23
-54
lines changed

4 files changed

+23
-54
lines changed

assets/helpers.js

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,11 @@
3737
|--------------------------------------------------------------------------
3838
*/
3939

40-
// Backup jQuery.ready
41-
var _jqueryReady;
42-
4340
// Common texts
4441
var _dataLayer = 'dataLayer';
45-
var _deferClass = 'deferjs';
46-
var _deferPrefix = 'defer-';
47-
var _lazied = 'lazied';
48-
var _dataPrefix = 'data-';
49-
var _media = 'media';
50-
51-
// Common class names
52-
var _classLazied = _deferPrefix + _lazied;
53-
var _classLoaded = _deferPrefix + 'loaded';
54-
var _classLoading = _deferPrefix + 'loading';
55-
56-
// Common attributes
57-
var _attrClassName = 'className';
58-
var _attrDataIgnore = 'data-ignore';
5942

6043
// Common CSS selectors
61-
var _queryTarget = '.' + _classLoading + ':not([' + _attrDataIgnore + ']):not([lazied])';
44+
var _queryTarget = '.defer-loading:not([data-ignore]):not([lazied])';
6245

6346
/*
6447
|--------------------------------------------------------------------------
@@ -77,18 +60,18 @@
7760
*/
7861

7962
function _replaceClass(node, find, replace) {
80-
node[_attrClassName] = (' ' + node[_attrClassName] + ' ').
81-
replace(' ' + find + ' ', ' ' + replace + ' ').trim();
63+
node.className = ((' ' + node.className + ' ').
64+
replace(' ' + find + ' ', ' ') + replace).trim();
8265
}
8366

8467
function _lazyload() {
85-
defer.dom(_queryTarget, 0, _classLazied, function (node) {
86-
_replaceClass(node, _classLoading, _classLoaded);
68+
defer.dom(_queryTarget, 0, '', function (node) {
69+
_replaceClass(node, 'defer-loading', 'defer-loaded');
8770
}, _options);
8871

8972
[].slice.call(document.querySelectorAll('style[defer]')).
9073
forEach(function(node) {
91-
node[_media] = node.getAttribute(_dataPrefix + _media) || 'all';
74+
node.media = node.getAttribute('data-media') || 'all';
9275
});
9376
}
9477

@@ -102,20 +85,22 @@
10285
}
10386
}
10487

105-
function _boot() {
106-
defer(_lazyload, _delay);
107-
_replaceClass(document.documentElement, 'no-' + _deferClass, _deferClass);
108-
_copyright();
109-
}
110-
11188
/*
11289
|--------------------------------------------------------------------------
11390
| Define helper object
11491
|--------------------------------------------------------------------------
11592
*/
11693

94+
_replaceClass(
95+
document.documentElement,
96+
'no-deferjs',
97+
defer ? 'deferjs' : ''
98+
);
99+
117100
// Check if missing defer feature
118-
if (!defer) {return;}
101+
if (!defer) {
102+
return;
103+
}
119104

120105
// Fallback for older versions
121106
window.defer_helper = {'defermedia': _lazyload};
@@ -131,29 +116,13 @@
131116
window.ga = window.ga || function () {(window.ga.q = window.ga.q || []).push(arguments)}; window.ga.l = Number(Date());
132117
window[_dataLayer] = window[_dataLayer] || [];
133118

134-
// Fake jQuery.ready, if jQuery loaded
135-
defer(function (jquery) {
136-
if (_jqueryReady) {
137-
return;
138-
}
139-
140-
jquery = window.jQuery;
141-
142-
if (jquery && jquery.fn) {
143-
_jqueryReady = jquery.fn.ready;
144-
jquery.fn.ready = function (callback) {
145-
defer(function () {_jqueryReady(callback)}, _delay);
146-
}
147-
}
148-
});
149-
150119
/*
151120
|--------------------------------------------------------------------------
152121
| Main
153122
|--------------------------------------------------------------------------
154123
*/
155124

156-
157-
_boot();
125+
_copyright();
126+
defer(_lazyload, _delay);
158127

159128
})(this, document, console);

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.

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

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)