Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions instantclick.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/* InstantClick 3.0.1 | (C) 2014 Alexandre Dieulot | http://instantclick.io/license */
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['InstantClick'], factory(root.document, root.location));
} else if (typeof exports === 'object') {
module.exports = factory(root.document, root.location);
} else {
root.InstantClick = factory(root.document, root.location);
}
}(window || this, function(document, location) {

var InstantClick = function(document, location) {
// Internal variables
var $ua = navigator.userAgent,
$isChromeForIOS = $ua.indexOf(' CriOS/') > -1,
Expand Down Expand Up @@ -687,4 +695,4 @@ var InstantClick = function(document, location) {
on: on
}

}(document, location);
}));
110 changes: 66 additions & 44 deletions tests/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
}
}

$use_amd = isset($_GET['amd']) && $_GET['amd'];

$nocache = '&nocache=' . microtime(true) * 10000;
if ($preload_on == 'hover') {
$append = $nocache;
Expand All @@ -35,6 +37,10 @@
$append = '&on=' . $preload_on . $nocache;
}

if ($use_amd) {
$append .= '&amd=' . $use_amd;
}

if (isset($_GET['wait'])) {
usleep((int)$_GET['wait'] * 1000);
}
Expand Down Expand Up @@ -71,6 +77,7 @@
<a data-no-instant href="?<?php echo $nocache ?>" class="<?php if ($preload_on == 'hover') echo 'selected' ?>">↻ On hover</a>
<a data-no-instant href="?on=100<?php echo $nocache ?>" class="<?php if ($preload_on === (int)$preload_on) echo 'selected' ?>">↻ On hover + 100 ms delay</a>
<a data-no-instant href="?on=mousedown<?php echo $nocache ?>" class="<?php if ($preload_on == 'mousedown') echo 'selected' ?>">↻ On mousedown</a>
<a data-no-instant href="?amd=1<?php echo $nocache ?>" class="<?php if ($amd) echo 'selected' ?>">↻ Using Require.js</a>
</div>

<hr>
Expand Down Expand Up @@ -100,26 +107,6 @@

<div id="divDebug"></div>



<script src="instantclick.js.php?<?php echo $nocache ?>" data-no-instant></script>


<?php if ($page == 'nprogress'): ?>
<script data-no-instant>
InstantClick.on('wait', function() {
NProgress.start()
})

InstantClick.on('change', function(isInitialLoad) {
if (isInitialLoad) {
addDebugMessage('NProgress on')
}
NProgress.done(!isInitialLoad)
})
</script>
<?php endif ?>

<script data-no-instant>
var $debugMessages = ''

Expand All @@ -132,29 +119,64 @@ function addDebugMessage(message) {
divDebug.innerHTML = $debugMessages
}

InstantClick.on('fetch', function() {
addDebugMessage('<small><small>Event: fetch</small></small>')
})

InstantClick.on('receive', function() {
addDebugMessage('<small><small>Event: receive</small></small>')
})

InstantClick.on('wait', function() {
addDebugMessage('Event: wait')
})

InstantClick.on('change', function(isInitialLoad) {
addDebugMessage('Event: change' + (isInitialLoad ? ' (initial load)' : ''))
})

InstantClick.init(<?php
if ($preload_on == 'mousedown') {
echo "'mousedown'";
}
elseif ((int)$preload_on != 0) {
echo $preload_on;
function testEvents(InstantClick) {
<?php if ($page == 'nprogress'): ?>
InstantClick.on('wait', function() {
NProgress.start()
})

InstantClick.on('change', function(isInitialLoad) {
if (isInitialLoad) {
addDebugMessage('NProgress on')
}
NProgress.done(!isInitialLoad)
})
<?php endif ?>

InstantClick.on('fetch', function() {
addDebugMessage('<small><small>Event: fetch</small></small>')
})

InstantClick.on('receive', function() {
addDebugMessage('<small><small>Event: receive</small></small>')
})

InstantClick.on('wait', function() {
addDebugMessage('Event: wait')
})

InstantClick.on('change', function(isInitialLoad) {
addDebugMessage('Event: change' + (isInitialLoad ? ' (initial load)' : ''))
})

InstantClick.init(<?php
if ($preload_on == 'mousedown') {
echo "'mousedown'";
}
elseif ((int)$preload_on != 0) {
echo $preload_on;
}
?>);
}
</script>

<?php if ($use_amd): ?>
<script src="vendors/requirejs/requirejs-2.1.15.js" data-no-instant></script>
<script>
require.config({
baseUrl: '/'
});

require(['InstantClick'], function(InstantClick) {
addDebugMessage('Loaded with: Require.js AMD')
testEvents(InstantClick)
});
</script>

?>);
</script>
<?php else: ?>
<script src="instantclick.js.php?<?php echo $nocache ?>" data-no-instant></script>
<script>
addDebugMessage('Loaded with: script tag')
testEvents(window.InstantClick)
</script>
<?php endif ?>
Loading