-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
73 lines (61 loc) · 3.3 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<!DOCTYPE html>
<html>
<head>
<title>Require Bundle Test</title>
<script type="text/javascript" src="dist/require-bundle.min.js"></script>
<script type="text/javascript">
var log = function( message ) {
var debugContainer = document.querySelector( '.debug-container' );
if ( debugContainer ) {
var newMessage = document.createElement( 'p' );
newMessage.innerText = message;
debugContainer.appendChild( newMessage );
}
}
var registerBundle = function( bundleName, resources, autoLoadSelector, callbackFn ) {
RequireBundle.register( bundleName, resources, autoLoadSelector, callbackFn );
log( 'Registered bundle: `' + bundleName + '`' );
}
var deregisterBundle = function() {
bundleName = 'smooth-parallax';
RequireBundle.deregister( bundleName );
log( 'De-registered bundle: `' + bundleName + '`' );
log( 'Has bundle "' + bundleName + '": `' + RequireBundle.hasBundle( bundleName ) + '`' );
}
var registerBundles = function() {
// Register
registerBundle( 'smooth-parallax', [ 'https://raw.githubusercontent.com/diegoversiani/smooth-parallax/master/dist/smooth-parallax.min.js' ] );
registerBundle( 'hamburger-menu', [ 'https://raw.githubusercontent.com/center-key/hamburger-menu/master/dist/hamburger-menu.min.js', 'https://raw.githubusercontent.com/center-key/hamburger-menu/master/dist/hamburger-menu.min.css' ] );
// Register with auto-load
registerBundle( 'slider', [ 'https://raw.githubusercontent.com/thomaslanciaux/Slider/master/slider.js' ], '.slider-wrapper', function(){ log( 'Auto-loaded bundle: `slider`' ); } );
}
var requireBundlesViaScript = function() {
RequireBundle.require( 'smooth-parallax', function() { log( 'Loaded bundle: `smooth-parallax`' ); } );
RequireBundle.require( 'hamburger-menu', function() { log( 'Loaded bundle: `hamburger-menu`' ); } );
}
window.addEventListener( "DOMContentLoaded", function () { log( 'DOM Content loaded' ); } );
window.addEventListener( "DOMContentLoaded", function () { if ( window.RequireBundle ) { log( 'Require Bundle loaded' ); } } );
window.addEventListener( "DOMContentLoaded", function () { if ( window.RequireBundle ) { registerBundles(); } } );
window.addEventListener( "DOMContentLoaded", function () { if ( window.RequireBundle ) { deregisterBundle(); } } );
window.addEventListener( "load", function () { log( 'Page loaded' ); } );
window.addEventListener( "load", function () { if ( window.RequireBundle ) { requireBundlesViaScript(); } } );
</script>
</head>
<body>
<div class="instructions">
Notes:
<ul>
<li>All bundles are registered as early as possible (on page load in this test)</li>
<li>Bundles <code>smooth-parallax</code> and <code>hamburger-menu</code> are loaded via a function executed on page load</li>
<li>Bundle <code>slider</code> is auto-loaded when an element with class <code>.slider-wrapper</code> is present on the page (temporarily remove the element to test the auto-load feature)</li>
</ul>
</div>
<hr/>
<div class="slider-wrapper">
slider-wrapper present
</div>
<hr/>
<div class="debug-container">
</div>
</body>
</html>