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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
|
<!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> & <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> & <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"><img class="lazy" data-original="images/logo.png" width="300" height="300"></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>
|