wefra/lib/jquery/tablesorter-2.31.1/docs/example-widget-lazyload.html

367 lines
16 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery tablesorter 2.0 - Lazyload widget</title>
<!-- Demo stuff -->
<link rel="stylesheet" href="css/jq.css">
<link rel="stylesheet" href="css/jquery-ui.min.css">
<link href="css/prettify.css" rel="stylesheet">
<script src="js/prettify.js"></script>
<!-- jQuery -->
<script src="js/jquery-latest.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/docs.js"></script>
<!-- Tablesorter: required -->
<link rel="stylesheet" href="../css/theme.blue.css">
<script src="../js/jquery.tablesorter.js"></script>
<script src="../js/widgets/widget-filter.js"></script>
<script src="../js/widgets/widget-lazyload.js"></script>
<script id="js">$(function() {
$("table").tablesorter({
theme : 'blue',
widgets : [ 'lazyload', 'filter', 'zebra' ],
widgetOptions : {
// widget options
lazyload_imageClass : 'lazy',
// scrollStop option (https://github.com/ssorallen/jquery-scrollstop)
lazyload_latency : 250,
// lazyload options (see http://www.appelsiini.net/projects/lazyload)
lazyload_threshold : 0,
lazyload_failure_limit : 0,
lazyload_event : 'scrollstop',
lazyload_effect : 'show',
lazyload_container : window,
lazyload_data_attribute : 'original',
lazyload_skip_invisible : true,
lazyload_appear : function( elements_left, settings ) {
// callback fired when image is in view, but before it is loaded
$(this).addClass( 'tablesorter-processing' );
},
lazyload_load : function( elements_left, settings ) {
// callback fired after image has loaded
$(this).removeClass( 'tablesorter-processing' );
},
lazyload_placeholder : 'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='
}
});
});</script>
</head>
<body>
<div id="banner">
<h1>table<em>sorter</em></h1>
<h2>Lazyload widget</h2>
<h3>Flexible client-side table sorting</h3>
<a href="index.html">Back to documentation</a>
</div>
<div id="main">
<p></p>
<br>
<div id="root" class="accordion">
<h3><a href="#">Notes</a></h3>
<div>
<p>
<span class="label warning">Warning</span> Binding the <a class="intlink" href="#lazyload_event"><code>lazyload_event</code></a> to <code>'scroll'</code> may cause excessive lag.
</p>
<ul>
<li>This widget, added in <span class="version">v2.24.0</span>, integrates the popular <a class="external" href="https://github.com/tuupola/jquery_lazyload">jQuery lazyload plugin</a> &amp; <a class="external" href="https://github.com/ssorallen/jquery-scrollstop">jQuery scrollstop</a>.</li>
<li>This widget will only work if:
<ul>
<li>The image class, set by the <code>lazyload_imageClass</code> option is included.</li>
<li>The image <code>width</code> &amp; <code>height</code> attributes are set.</li>
<li>The url to the image is added to the data-attribute, set by the <code>lazyload_data_attribute</code> option, and not the image <code>src</code> attribute.</li>
</ul>
<pre class="prettyprint lang-html">&lt;img class="lazy" data-original="images/logo.png" width="300" height="300"&gt;</pre>
</li>
<li>The images will load only if:
<ul>
<li>The image is inside the viewport.</li>
<li>When the user has stoped scrolling; this is because the <code>lazyload_event</code> option is set by default to use the "scrollstop" event, which is added by the jQuery scrollstop plugin (see <code>lazyload_event</code> option for more details).</li>
</ul>
</li>
<li>In this demo, scroll down the page to see the lazyload plugin in action.</li>
<li>This widget will not work with the original tablesorter plugin (v2.0.5).</li>
</ul>
</div>
<h3><a href="#">Options</a></h3>
<div>
<h4>Lazyload widget default options (added inside of tablesorter <code>widgetOptions</code>)</h4>
<div class="tip">
<span class="label label-info">TIP!</span> Click on the link in the option column to reveal full details (or <a href="#" class="toggleAll">toggle</a>|<a href="#" class="showAll">show</a>|<a href="#" class="hideAll">hide</a> all) or double click to update the browser location.
</div>
<table class="tablesorter-blue options">
<thead>
<tr><th>Option</th><th>Default</th><th class="sorter-false">Description</th></tr>
</thead>
<tbody class="tablesorter-infoOnly">
<tr><th colspan="3">Lazyload widget options</th></tr>
</tbody>
<tbody>
<tr id="lazyload_imageclass">
<td><a href="#" class="permalink">lazyload_imageClass</a></td>
<td><code>'lazy'</code></td>
<td>
This option contains the image class name targeted by the lazyload widget.
<div class="collapsible">
<br>
This option is set up to add a period to the beginning of this option, to make a jQuery class name selector.
</div>
</td>
</tr>
<tr id="lazyload_update">
<td><a href="#" class="permalink">lazyload_update</a></td>
<td><code>'lazyloadUpdate'</code></td>
<td>
This option sets the event name that can be triggered to update the lazy load on newly loaded images.
<div class="collapsible">
<br>
This widget will work with the pager and columnSelector widget, so you shouldn't need to trigger this event, but you may need to use it if new rows are added or a cell with an image is updated.
</div>
</td>
</tr>
</tbody>
<tbody class="tablesorter-infoOnly">
<tr><th colspan="3">jQuery scrollstop plugin option</th></tr>
</tbody>
<tbody>
<tr id="lazyload_latency">
<td><a href="#" class="permalink">lazyload_latency</a></td>
<td><code>250</code></td>
<td>
Latency is the minimum time (in milliseconds) between the last scroll event and when the scrollstop event fires.
<div class="collapsible">
<br>
For more details, see the <a class="external" href="https://github.com/ssorallen/jquery-scrollstop">main plugin page</a>.
</div>
</td>
</tr>
</tbody>
<tbody class="tablesorter-infoOnly">
<tr><th colspan="3">jQuery lazyload plugin options</th></tr>
</tbody>
<tbody>
<tr id="lazyload_threshold">
<td><a href="#" class="permalink">lazyload_threshold</a></td>
<td><code>0</code></td>
<td>
By default images are loaded when they appear on the screen.
<div class="collapsible">
<p>If you want images to load earlier use threshold parameter. Setting threshold to <code>200</code> causes image to load 200 pixels before it appears on viewport.</p>
For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#setting-threshold">main documentation</a>.
</div>
</td>
</tr>
<tr id="lazyload_failure_limit">
<td><a href="#" class="permalink">lazyload_failure_limit</a></td>
<td><code>0</code></td>
<td>
Setting failure_limit to 10 causes plugin to stop searching for images to load after finding 10 images below the fold.
<div class="collapsible">
<p>If you have a funky layout set this number to something high. Worst case being the actual number of images.</p>
For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#when-images-are-not-sequential">main documentation</a>.
</div>
</td>
</tr>
<tr id="lazyload_event">
<td><a href="#" class="permalink">lazyload_event</a></td>
<td><code>'scrollstop'</code></td>
<td>
Event to trigger image loading.
<div class="collapsible">
<p>In the original plugin, the default for this option is <code>'scroll'</code>. It was changed to <code>'scrollstop'</code> in this widget to only load images after scrolling stops.</p>
<p>Alternative settings include <code>'click'</code> (user clicks on image to load it) or <code>'mouseover'</code>.</p>
<p>If this option is not set to <code>'scrollstop'</code>, then the scrollstop plugin will not be initialized.</p>
<p><span class="label warning">Warning</span> If the option is set to <code>'scroll'</code>, the plugin may cause excessive lag.</p>
For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#event-to-trigger-loading">main documentation</a>.
</div>
</td>
</tr>
<tr id="lazyload_effect">
<td><a href="#" class="permalink">lazyload_effect</a></td>
<td><code>'show'</code></td>
<td>
By default plugin waits for image to fully load and calls <code>show()</code>.
<div class="collapsible">
<p>You can use any effect you want, e.g. <code>'fadeIn'</code> effect.</p>
For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#using-effects">main documentation</a>.
</div>
</td>
</tr>
<tr id="lazyload_container">
<td><a href="#" class="permalink">lazyload_container</a></td>
<td><code>window</code></td>
<td>
You can also use plugin for images inside scrolling container, such as div with scrollbar.
<div class="collapsible">
<p>Just pass the container as jQuery object.</p>
For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#images-inside-container">main documentation</a>.
</div>
</td>
</tr>
<tr id="lazyload_data_attribute">
<td><a href="#" class="permalink">lazyload_data_attribute</a></td>
<td><code>'original'</code></td>
<td>
You must alter your image tags. Address of the image must be put into <code>data-original</code> attribute.
<div class="collapsible">
<p>Use this option to set a different attribute.</p>
If you have a higher quality image that you want to load under certain conditions, use the <code>lazyload_appear</code> callback to change this setting. Here is an example that switches to load retina images:
<pre class="prettyprint lang-js">$(function() {
$( 'table' ).tablesorter({
theme : 'blue',
widgets : [ 'lazyload' ],
widgetOptions : {
lazyload_appear : function( elements_left, settings ) {
// elements_left = number of images left to load
// settings = lazyload plugin settings; not the widgetOptions setting which don't matter at this point
settings.data_attribute = window.devicePixelRatio > 1 && $( this ).attr( 'retina' ) ?
// use "data-retina" for higher resolution images
'retina' :
// fallback to "data-original" for non-retina displays
'original';
}
}
});
});</pre>
For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#how-to-use">main documentation</a>.
</div>
</td>
</tr>
<tr id="lazyload_skip_invisible">
<td><a href="#" class="permalink">lazyload_skip_invisible</a></td>
<td><code>true</code></td>
<td>
There are cases when you have images which are in viewport but not <code>:visible</code> (<span class="version updated">v2.25.6</span>).
<div class="collapsible">
<p>In <span class="version updated">v2.25.6</span>, change this default value to <code>true</code> to better work with the filter widget.</p>
<p>To improve performance you can ignore <code>.not(":visible")</code> images by setting this option to <code>true</code>.</p>
For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#dealing-with-invisible-images">main documentation</a>.
</div>
</td>
</tr>
<tr id="lazyload_appear">
<td><a href="#" class="permalink">lazyload_appear</a></td>
<td><code>null</code></td>
<td>
This function is called when image appears in the viewport, but before it is loaded.
<div class="collapsible">
<p>Use this callback function as follows:</p>
<pre class="prettyprint lang-js">$(function() {
$( 'table' ).tablesorter({
theme : 'blue',
widgets : [ 'lazyload' ],
widgetOptions : {
lazyload_appear : function( elements_left, settings ) {
// elements_left = number of images left to load
// settings = plugin settings; not the widgetOptions
$( this ).parent().addClass( 'loading' );
}
}
});
});</pre>
There doesn't appear to be any documentation for this callback in the main documentation.
</div>
</td>
</tr>
<tr id="lazyload_load">
<td><a href="#" class="permalink">lazyload_load</a></td>
<td><code>null</code></td>
<td>
This function is called after the image has completed loading.
<div class="collapsible">
<p>Use this callback function as follows:</p>
<pre class="prettyprint lang-js">$(function() {
$( 'table' ).tablesorter({
theme : 'blue',
widgets : [ 'lazyload' ],
widgetOptions : {
lazyload_load : function( elements_left, settings ) {
// elements_left = number of images left to load
// settings = plugin settings; not the widgetOptions
$( this ).parent().removeClass( 'loading' );
}
}
});
});</pre>
There doesn't appear to be any documentation for this callback in the main documentation.
</div>
</td>
</tr>
<tr id="lazyload_placeholder">
<td><a href="#" class="permalink">lazyload_placeholder</a></td>
<td>See description</td>
<td>
This placeholder replaces the image until it gets loaded.
<div class="collapsible">
<p>By default, this setting is an encoded gif of a 1x1 transparent pixel.</p>
<p>Default: <code>'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='</code></p>
For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#fallback-for-non-javascript-browsers">main documentation</a>.
</div>
</td>
</tr>
</tbody>
</table>
</div>
<h3><a href="#">Method</a></h3>
<div>
<h3>Force lazyload widget update</h3>
If you need to programmically force the lazyload widget to update, trigger a <code>'lazyloadUpdate'</code> event on the table:
<pre class="prettyprint lang-js">$( 'table' ).trigger( 'lazyloadUpdate' );</pre>
You can change this event name by setting the <code>lazyload_update</code> option.
</div>
</div>
<p></p>
<h1>Demo</h1>
<div id="demo"><table class="tablesorter">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Image</th>
</tr>
</thead>
<tbody>
<tr><td>Bill</td><td>Murray</td><td><img class="lazy" data-original="http://www.fillmurray.com/300/500" width="300" height="500" alt="Murray" /></td></tr>
<tr><td>Joyce</td><td>Young</td><td><img class="lazy" data-original="http://placehold.it/300x500/ff0000/ffffff" width="300" height="500" alt="Red" /></td></tr>
<tr><td>John</td><td>Hood</td><td><img class="lazy" data-original="http://placehold.it/300x500" width="300" height="500" alt="Grey" /></td></tr>
<tr><td>Clark</td><td>Kent</td><td><img class="lazy" data-original="http://placebear.com/300/500" width="300" height="500" alt="Bear" /></td></tr>
<tr><td>Beverly</td><td>Pyle</td><td><img class="lazy" data-original="http://placehold.it/300x500/ff00ff/ffffff" width="300" height="500" alt="Blue" /></td></tr>
<tr><td>Bruce</td><td>Almighty</td><td><img class="lazy" data-original="http://lorempixel.com/300/500" width="300" height="500" alt="Random" /></td></tr>
<tr><td>Billy</td><td>Murray</td><td><img class="lazy" data-original="http://www.fillmurray.com/300/500" width="300" height="500" alt="Murray" /></td></tr>
<tr><td>Frank</td><td>Bedlam</td><td><img class="lazy" data-original="http://placehold.it/300x500/0000ff/ffffff" width="300" height="500" alt="Blue" /></td></tr>
<tr><td>Harry</td><td>Sally</td><td><img class="lazy" data-original="http://placebear.com/300/500" width="300" height="500" alt="Bear" /></td></tr>
</tbody>
</table></div>
<h1>Javascript</h1>
<div id="javascript">
<pre class="prettyprint lang-javascript"></pre>
</div>
<h1>HTML</h1>
<div id="html">
<pre class="prettyprint lang-html"></pre>
</div>
</div>
</body>
</html>