Skip to content

Commit 7a04275

Browse files
committed
Merge branch 'feature-onload'
* feature-onload: bump version move callback into onload function loaded state triggered by event from element, not position in viewport, when possible typo fire event on image load
2 parents 63a9c0a + b5df372 commit 7a04275

5 files changed

+45
-15
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "laziestloader",
3-
"version": "0.3.0",
3+
"version": "0.5.1",
44
"homepage": "https://github.com/sjwilliams/laziestloader",
55
"authors": [
66
"Josh Williams <contact@joshwilliams.com>"

index.html

+9-4
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ <h1>LaziestLoader</h1>
283283
</section>
284284

285285
<section class="installation">
286-
<h2>Download v0.5.0</h2>
286+
<h2>Download v0.5.1</h2>
287287
<ol>
288-
<li><a href="https://raw.githubusercontent.com/sjwilliams/laziestloader/v0.5.0/jquery.laziestloader.js">Development Version</a></li>
289-
<li><a href="https://raw.githubusercontent.com/sjwilliams/laziestloader/v0.5.0/jquery.laziestloader.min.js">Production Version</a></li>
288+
<li><a href="https://raw.githubusercontent.com/sjwilliams/laziestloader/v0.5.1/jquery.laziestloader.js">Development Version</a></li>
289+
<li><a href="https://raw.githubusercontent.com/sjwilliams/laziestloader/v0.5.1/jquery.laziestloader.min.js">Production Version</a></li>
290290
<li><span class="code">$ npm install laziestloader</span></li>
291291
<li><span class="code">$ bower install laziestloader</span></li>
292292
</ol>
@@ -622,6 +622,11 @@ <h2>Trigger</h2>
622622

623623
<section id="releasehistory">
624624
<h2>Release History</h2>
625+
<h4>0.5.1</h4>
626+
<ul>
627+
<li>Loaded state fired, if possible, when media actually loads, not simply triggered by viewport position. See <a href="https://github.com/sjwilliams/laziestloader/issues/8">Issue 8</a>.</li>
628+
</ul>
629+
625630
<h4>0.5.0</h4>
626631
<ul>
627632
<li>Classes added to element to reflect state. See <a href="https://github.com/sjwilliams/laziestloader/issues/8">Issue 8</a>.</li>
@@ -681,7 +686,7 @@ <h4>0.0.1</h4>
681686

682687
<section>
683688
<h2>Credits</h2>
684-
<p>LaziestLoader is by <a href="http://joshwilliams.com">Josh Williams</a>. Early versions were based heavily on Luís Almeida's <a href="http://luis-almeida.github.com/unveil/">unveil</a></p>
689+
<p>LaziestLoader is by <a href="http://joshwilliams.com">Josh Williams</a>. Inspried by Luís Almeida's <a href="http://luis-almeida.github.com/unveil/">unveil</a></p>
685690
</section>
686691

687692
<section>

jquery.laziestloader.js

+32-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @preserve LaziestLoader - v0.5.0 - 2014-06-19
2+
* @preserve LaziestLoader - v0.5.1 - 2014-06-19
33
* A responsive lazy loader for jQuery.
44
* http://sjwilliams.github.io/laziestloader/
55
* Copyright (c) 2014 Josh Williams; Licensed MIT
@@ -96,6 +96,21 @@
9696
return source;
9797
}
9898

99+
/**
100+
* Reflect loaded state in class names
101+
* and fire event.
102+
*
103+
* @param {jQuery Object} $el
104+
*/
105+
function onLoad($el) {
106+
$el.addClass('ll-loaded').removeClass('ll-notloaded');
107+
$el.trigger('loaded');
108+
109+
if (typeof callback === 'function') {
110+
callback.call($el);
111+
}
112+
}
113+
99114
/**
100115
* Attach event handler that sets correct
101116
* media source for the elements' width, or
@@ -118,14 +133,24 @@
118133
source = options.getSource($el);
119134
if (source && this.getAttribute('src') !== source) {
120135
this.setAttribute('src', source);
121-
if (typeof callback === 'function') callback.call(this);
122136
}
123-
} else {
124-
if (typeof callback === 'function') callback.call(this);
125137
}
126138

127-
// reflect current state in classes
128-
$el.addClass('ll-loaded').removeClass('ll-notloaded');
139+
// Determine when to fire `loaded` event. Wait until
140+
// media is truly loaded if possible, otherwise immediately
141+
if (options.setSourceMode && (this.nodeName === 'IMG' || this.nodeName === 'VIDEO' || this.nodeName === 'AUDIO') ) {
142+
if (this.nodeName === 'IMG') {
143+
this.onload = function() {
144+
onLoad($el);
145+
}
146+
} else {
147+
this.onloadstart = function() {
148+
onLoad($el);
149+
}
150+
}
151+
} else {
152+
onLoad($el);
153+
}
129154
});
130155
}
131156

@@ -203,7 +228,7 @@
203228
}
204229
}
205230

206-
// add inital state classes, ahd check if
231+
// add inital state classes, and check if
207232
// element dimensions need to be set.
208233
$elements.addClass('ll-init ll-notloaded').each(setHeight);
209234

jquery.laziestloader.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "laziestloader",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"author": "Josh Williams <contact@joshwilliams.com>",
55
"description": "A responsive-aware jQuery plugin to smartly lazy load images and other elements.",
66
"repository": {

0 commit comments

Comments
 (0)