Skip to content

Commit 1849833

Browse files
committed
Vendor2
1 parent f30ecb5 commit 1849833

File tree

2 files changed

+293
-0
lines changed

2 files changed

+293
-0
lines changed

index-vendor2.html

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!DOCTYPE html>
2+
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
3+
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
4+
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
5+
<!--[if gt IE 8]><!-->
6+
<html class="no-js"><!--<![endif]-->
7+
<head>
8+
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
9+
<meta charset="utf-8">
10+
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
11+
<title>Script.js not load lib js to pass tool speed</title>
12+
<meta name="description" content="">
13+
<meta name="viewport" content="width=device-width">
14+
<link rel="stylesheet" href="css/slick.css">
15+
<link rel="stylesheet" href="css/slick-theme.css">
16+
<script id="jsvendor" src="js/vendor2.js"
17+
data-jquery="js/jquery.js"
18+
data-slick="js/slick.js"
19+
>
20+
</script>
21+
<script type="text/javascript">
22+
(function(){
23+
var vendor = document.querySelector('#jsvendor'),
24+
vendorSrc = vendor.dataset;
25+
// load jquery and plugin at the same time. name it 'bundle'
26+
// $script([vendorSrc.jquery, vendorSrc.slick], 'bundle');
27+
28+
var dependencyList = {
29+
jquery: vendorSrc.jquery,
30+
bar: vendorSrc.slick,
31+
slider: [vendorSrc.jquery, vendorSrc.slick]
32+
}
33+
34+
$script.ready(['slider'], function () {
35+
console.log('xxx');
36+
$(document).ready(function() {
37+
var carousel = $('.js-carousel');
38+
var carouselSlick = carousel.slick(carousel.data());
39+
});
40+
}, function(depsNotFound) {
41+
depsNotFound.forEach(function(dep) {
42+
$script(dependencyList[dep], dep)
43+
})
44+
});
45+
46+
})();
47+
</script>
48+
<style>img{width:100%}</style>
49+
</head>
50+
<body>
51+
<div class="container">
52+
<ul class="slider js-carousel"
53+
data-infinite="true"
54+
data-speed="300"
55+
data-slides-To-Show="8",
56+
data-slides-To-Scroll="1",
57+
data-space="15"
58+
data-responsive= '[{"breakpoint": "1024", "settings": {"slidesToShow": "6"}}, {"breakpoint": "800", "settings": {"slidesToShow": "3"}}, {"breakpoint": "600", "settings": {"slidesToShow": "2"}}, {"breakpoint": "460", "settings": {"slidesToShow": "1"}}]'
59+
>
60+
<li><img src="http://www.starplugins.com/sites/starplugins/images/jetzoom/large/image1.jpg"/></li>
61+
<li><img src="http://www.starplugins.com/sites/starplugins/images/jetzoom/large/image2.jpg"/></li>
62+
<li><img src="http://www.starplugins.com/sites/starplugins/images/jetzoom/large/image3.jpg"/></li>
63+
<li><img src="http://www.starplugins.com/sites/starplugins/images/jetzoom/large/image4.jpg"/></li>
64+
<li><img src="http://www.starplugins.com/sites/starplugins/images/jetzoom/large/image5.jpg"/></li>
65+
<li><img src="http://www.starplugins.com/sites/starplugins/images/jetzoom/large/image6.jpg"/></li>
66+
<li><img src="http://www.starplugins.com/sites/starplugins/images/jetzoom/large/image7.jpg"/></li>
67+
<li><img src="http://www.starplugins.com/sites/starplugins/images/jetzoom/large/image8.jpg"/></li>
68+
<li><img src="http://www.starplugins.com/sites/starplugins/images/jetzoom/large/image9.jpg"/></li>
69+
<li><img src="http://www.starplugins.com/sites/starplugins/images/jetzoom/large/image10.jpg"/></li>
70+
<li><img src="http://www.starplugins.com/sites/starplugins/images/jetzoom/large/image11.jpg"/></li>
71+
</ul>
72+
</div>
73+
</body>
74+
</html>

js/vendor2.js

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
/*!
2+
* $script.js JS loader & dependency manager
3+
* https://github.com/ded/script.js
4+
* (c) Dustin Diaz 2014 | License MIT
5+
*/
6+
7+
(function (name, definition) {
8+
if (typeof module != 'undefined' && module.exports) module.exports = definition()
9+
else if (typeof define == 'function' && define.amd) define(definition)
10+
else this[name] = definition()
11+
})('$script', function () {
12+
var doc = document
13+
, head = doc.getElementsByTagName('head')[0]
14+
, s = 'string'
15+
, f = false
16+
, push = 'push'
17+
, readyState = 'readyState'
18+
, onreadystatechange = 'onreadystatechange'
19+
, list = {}
20+
, ids = {}
21+
, delay = {}
22+
, scripts = {}
23+
, scriptpath
24+
, urlArgs
25+
26+
function every(ar, fn) {
27+
for (var i = 0, j = ar.length; i < j; ++i) if (!fn(ar[i])) return f
28+
return 1
29+
}
30+
function each(ar, fn) {
31+
every(ar, function (el) {
32+
fn(el)
33+
return 1
34+
})
35+
}
36+
37+
function $script(paths, idOrDone, optDone) {
38+
paths = paths[push] ? paths : [paths]
39+
var idOrDoneIsDone = idOrDone && idOrDone.call
40+
, done = idOrDoneIsDone ? idOrDone : optDone
41+
, id = idOrDoneIsDone ? paths.join('') : idOrDone
42+
, queue = paths.length
43+
function loopFn(item) {
44+
return item.call ? item() : list[item]
45+
}
46+
function callback() {
47+
if (!--queue) {
48+
list[id] = 1
49+
done && done()
50+
for (var dset in delay) {
51+
every(dset.split('|'), loopFn) && !each(delay[dset], loopFn) && (delay[dset] = [])
52+
}
53+
}
54+
}
55+
setTimeout(function () {
56+
each(paths, function loading(path, force) {
57+
if (path === null) return callback()
58+
59+
if (!force && !/^https?:\/\//.test(path) && scriptpath) {
60+
path = (path.indexOf('.js') === -1) ? scriptpath + path + '.js' : scriptpath + path;
61+
}
62+
63+
if (scripts[path]) {
64+
if (id) ids[id] = 1
65+
return (scripts[path] == 2) ? callback() : setTimeout(function () { loading(path, true) }, 0)
66+
}
67+
68+
scripts[path] = 1
69+
if (id) ids[id] = 1
70+
create(path, callback)
71+
})
72+
}, 0)
73+
return $script
74+
}
75+
76+
function create(path, fn) {
77+
var el = doc.createElement('script'), loaded
78+
el.onload = el.onerror = el[onreadystatechange] = function () {
79+
if ((el[readyState] && !(/^c|loade/.test(el[readyState]))) || loaded) return;
80+
el.onload = el[onreadystatechange] = null
81+
loaded = 1
82+
scripts[path] = 2
83+
fn()
84+
}
85+
el.async = 1
86+
el.src = urlArgs ? path + (path.indexOf('?') === -1 ? '?' : '&') + urlArgs : path;
87+
head.insertBefore(el, head.lastChild)
88+
}
89+
90+
$script.get = create
91+
92+
$script.order = function (scripts, id, done) {
93+
(function callback(s) {
94+
s = scripts.shift()
95+
!scripts.length ? $script(s, id, done) : $script(s, callback)
96+
}())
97+
}
98+
99+
$script.path = function (p) {
100+
scriptpath = p
101+
}
102+
$script.urlArgs = function (str) {
103+
urlArgs = str;
104+
}
105+
$script.ready = function (deps, ready, req) {
106+
deps = deps[push] ? deps : [deps]
107+
var missing = [];
108+
!each(deps, function (dep) {
109+
list[dep] || missing[push](dep);
110+
}) && every(deps, function (dep) {return list[dep]}) ?
111+
ready() : !function (key) {
112+
delay[key] = delay[key] || []
113+
delay[key][push](ready)
114+
req && req(missing)
115+
}(deps.join('|'))
116+
return $script
117+
}
118+
119+
$script.done = function (idOrDone) {
120+
$script([null], idOrDone)
121+
}
122+
123+
return $script
124+
});
125+
126+
class VendorJs {
127+
constructor() {
128+
this.init();
129+
}
130+
init (){
131+
document.addEventListener("DOMContentLoaded", function() {
132+
if( navigator.userAgent.indexOf("Chrome-Lighthouse") != -1
133+
|| navigator.userAgent.indexOf("GTmetrix") != -1
134+
|| navigator.userAgent.indexOf("PingdomPageSpeed") != -1 ) {
135+
document.documentElement.classList.add('no-js page-speed');
136+
return false;
137+
}
138+
var $body = document.body,
139+
jsvendor = document.querySelector('#jsvendor'),
140+
dataSrc = jsvendor.dataset;
141+
$script([dataSrc.jquery], function () {
142+
$script([dataSrc.sc, dataSrc.lazysizes], 'load_basic');
143+
});
144+
$script.ready('load_basic', function() {
145+
var require = [
146+
dataSrc.cookie,
147+
dataSrc.currencies,
148+
dataSrc.magnific,
149+
dataSrc.countdown,
150+
dataSrc.accordion
151+
];
152+
$script(require, 'load_page');
153+
});
154+
$script.ready('load_page', function() {
155+
var require = [dataSrc.shopify];
156+
/* load dependency in home page */
157+
if($body.classList.contains('home')){
158+
/* require.push("home-sj"); */
159+
}
160+
/* load dependency in category page */
161+
else if($body.classList.contains('template-collection') || $body.classList.contains('template-search')){
162+
require.push(dataSrc.stickybar);
163+
require.push(dataSrc.collection);
164+
}
165+
/* load dependency in product page */
166+
else if($body.classList.contains('template-product')){
167+
require.push(dataSrc.zoom);
168+
require.push(dataSrc.stickybar);
169+
require.push(dataSrc.product);
170+
}
171+
$script(require , 'load_main');
172+
});
173+
$script.ready('load_main', function() {
174+
$script([dataSrc.theme]);
175+
$script([dataSrc.custom]);
176+
});
177+
document.addEventListener("PriceSliderAssets", function() {
178+
if(jsvendor.classList.contains('PriceSliderAssets')) return;
179+
$script([dataSrc.nouislider], function(){
180+
var style = document.createElement('link');
181+
style.rel = 'stylesheet';
182+
style.type = 'text/css';
183+
style.href = dataSrc.nouisliderStyle;
184+
document.head.appendChild(style);
185+
jsvendor.classList.add('PriceSliderAssets');
186+
});
187+
});
188+
document.addEventListener("VenoboxAssets", function() {
189+
if(jsvendor.classList.contains('VenoboxAssets')){
190+
document.dispatchEvent(new Event('VenoboxAssetsReady'));
191+
return;
192+
}
193+
$script([dataSrc.venobox], function(){
194+
var style = document.createElement('link');
195+
style.rel = 'stylesheet';
196+
style.type = 'text/css';
197+
style.href = dataSrc.venoboxStyle;
198+
document.head.appendChild(style);
199+
jsvendor.classList.add('VenoboxAssets');
200+
document.dispatchEvent(new Event('VenoboxAssetsReady'));
201+
});
202+
});
203+
document.addEventListener("ColllectionLoadJs", function() {
204+
if(jsvendor.classList.contains('ColllectionLoadJs')) return;
205+
$script([dataSrc.global, dataSrc.stickybar, dataSrc.collection], function(){
206+
jsvendor.classList.add('ColllectionLoadJs');
207+
});
208+
});
209+
document.addEventListener("MainProductLoadJs", function() {
210+
if(jsvendor.classList.contains('MainProductLoadJs')) return;
211+
$script([dataSrc.global, dataSrc.product, dataSrc.productModel], function(){
212+
jsvendor.classList.add('MainProductLoadJs');
213+
});
214+
});
215+
});
216+
}
217+
}
218+
219+
new VendorJs();

0 commit comments

Comments
 (0)