Debian Codegraph @

docs/example-widget-lazyload.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter 2.0 - Lazyload widget</title>
6
7 <!-- Demo stuff -->
8 <link rel="stylesheet" href="css/jq.css">
9 <link rel="stylesheet" href="css/jquery-ui.min.css">
10 <link href="css/prettify.css" rel="stylesheet">
11 <script src="js/prettify.js"></script>
12 <!-- jQuery -->
13 <script src="js/jquery-latest.min.js"></script>
14 <script src="js/jquery-ui.min.js"></script>
15 <script src="js/docs.js"></script>
16
17 <!-- Tablesorter: required -->
18 <link rel="stylesheet" href="../css/theme.blue.css">
19 <script src="../js/jquery.tablesorter.js"></script>
20 <script src="../js/widgets/widget-filter.js"></script>
21 <script src="../js/widgets/widget-lazyload.js"></script>
22
23 <script id="js">$(function() {
24 $("table").tablesorter({
25 theme : 'blue',
26 widgets : [ 'lazyload', 'filter', 'zebra' ],
27 widgetOptions : {
28 // widget options
29 lazyload_imageClass : 'lazy',
30 // scrollStop option (https://github.com/ssorallen/jquery-scrollstop)
31 lazyload_latency : 250,
32 // lazyload options (see http://www.appelsiini.net/projects/lazyload)
33 lazyload_threshold : 0,
34 lazyload_failure_limit : 0,
35 lazyload_event : 'scrollstop',
36 lazyload_effect : 'show',
37 lazyload_container : window,
38 lazyload_data_attribute : 'original',
39 lazyload_skip_invisible : true,
40 lazyload_appear : function( elements_left, settings ) {
41 // callback fired when image is in view, but before it is loaded
42 $(this).addClass( 'tablesorter-processing' );
43 },
44 lazyload_load : function( elements_left, settings ) {
45 // callback fired after image has loaded
46 $(this).removeClass( 'tablesorter-processing' );
47 },
48 lazyload_placeholder : 'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='
49 }
50 });
51 });</script>
52 </head>
53 <body>
54
55 <div id="banner">
56 <h1>table<em>sorter</em></h1>
57 <h2>Lazyload widget</h2>
58 <h3>Flexible client-side table sorting</h3>
59 <a href="index.html">Back to documentation</a>
60 </div>
61 <div id="main">
62
63 <p></p>
64 <br>
65
66 <div id="root" class="accordion">
67
68 <h3><a href="#">Notes</a></h3>
69 <div>
70 <p>
71 <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.
72 </p>
73 <ul>
74 <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>
75 <li>This widget will only work if:
76 <ul>
77 <li>The image class, set by the <code>lazyload_imageClass</code> option is included.</li>
78 <li>The image <code>width</code> &amp; <code>height</code> attributes are set.</li>
79 <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>
80 </ul>
81 <pre class="prettyprint lang-html">&lt;img class="lazy" data-original="images/logo.png" width="300" height="300"&gt;</pre>
82 </li>
83 <li>The images will load only if:
84 <ul>
85 <li>The image is inside the viewport.</li>
86 <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>
87 </ul>
88 </li>
89 <li>In this demo, scroll down the page to see the lazyload plugin in action.</li>
90 <li>This widget will not work with the original tablesorter plugin (v2.0.5).</li>
91 </ul>
92 </div>
93
94 <h3><a href="#">Options</a></h3>
95 <div>
96 <h4>Lazyload widget default options (added inside of tablesorter <code>widgetOptions</code>)</h4>
97 <div class="tip">
98 <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.
99 </div>
100 <table class="tablesorter-blue options">
101 <thead>
102 <tr><th>Option</th><th>Default</th><th class="sorter-false">Description</th></tr>
103 </thead>
104
105 <tbody class="tablesorter-infoOnly">
106 <tr><th colspan="3">Lazyload widget options</th></tr>
107 </tbody>
108
109 <tbody>
110 <tr id="lazyload_imageclass">
111 <td><a href="#" class="permalink">lazyload_imageClass</a></td>
112 <td><code>'lazy'</code></td>
113 <td>
114 This option contains the image class name targeted by the lazyload widget.
115 <div class="collapsible">
116 <br>
117 This option is set up to add a period to the beginning of this option, to make a jQuery class name selector.
118 </div>
119 </td>
120 </tr>
121 <tr id="lazyload_update">
122 <td><a href="#" class="permalink">lazyload_update</a></td>
123 <td><code>'lazyloadUpdate'</code></td>
124 <td>
125 This option sets the event name that can be triggered to update the lazy load on newly loaded images.
126 <div class="collapsible">
127 <br>
128 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.
129 </div>
130 </td>
131 </tr>
132 </tbody>
133
134 <tbody class="tablesorter-infoOnly">
135 <tr><th colspan="3">jQuery scrollstop plugin option</th></tr>
136 </tbody>
137
138 <tbody>
139 <tr id="lazyload_latency">
140 <td><a href="#" class="permalink">lazyload_latency</a></td>
141 <td><code>250</code></td>
142 <td>
143 Latency is the minimum time (in milliseconds) between the last scroll event and when the scrollstop event fires.
144 <div class="collapsible">
145 <br>
146 For more details, see the <a class="external" href="https://github.com/ssorallen/jquery-scrollstop">main plugin page</a>.
147 </div>
148 </td>
149 </tr>
150 </tbody>
151
152 <tbody class="tablesorter-infoOnly">
153 <tr><th colspan="3">jQuery lazyload plugin options</th></tr>
154 </tbody>
155
156 <tbody>
157 <tr id="lazyload_threshold">
158 <td><a href="#" class="permalink">lazyload_threshold</a></td>
159 <td><code>0</code></td>
160 <td>
161 By default images are loaded when they appear on the screen.
162 <div class="collapsible">
163 <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>
164 For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#setting-threshold">main documentation</a>.
165 </div>
166 </td>
167 </tr>
168 <tr id="lazyload_failure_limit">
169 <td><a href="#" class="permalink">lazyload_failure_limit</a></td>
170 <td><code>0</code></td>
171 <td>
172 Setting failure_limit to 10 causes plugin to stop searching for images to load after finding 10 images below the fold.
173 <div class="collapsible">
174 <p>If you have a funky layout set this number to something high. Worst case being the actual number of images.</p>
175 For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#when-images-are-not-sequential">main documentation</a>.
176 </div>
177 </td>
178 </tr>
179 <tr id="lazyload_event">
180 <td><a href="#" class="permalink">lazyload_event</a></td>
181 <td><code>'scrollstop'</code></td>
182 <td>
183 Event to trigger image loading.
184 <div class="collapsible">
185 <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>
186 <p>Alternative settings include <code>'click'</code> (user clicks on image to load it) or <code>'mouseover'</code>.</p>
187 <p>If this option is not set to <code>'scrollstop'</code>, then the scrollstop plugin will not be initialized.</p>
188 <p><span class="label warning">Warning</span> If the option is set to <code>'scroll'</code>, the plugin may cause excessive lag.</p>
189 For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#event-to-trigger-loading">main documentation</a>.
190 </div>
191 </td>
192 </tr>
193 <tr id="lazyload_effect">
194 <td><a href="#" class="permalink">lazyload_effect</a></td>
195 <td><code>'show'</code></td>
196 <td>
197 By default plugin waits for image to fully load and calls <code>show()</code>.
198 <div class="collapsible">
199 <p>You can use any effect you want, e.g. <code>'fadeIn'</code> effect.</p>
200 For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#using-effects">main documentation</a>.
201 </div>
202 </td>
203 </tr>
204 <tr id="lazyload_container">
205 <td><a href="#" class="permalink">lazyload_container</a></td>
206 <td><code>window</code></td>
207 <td>
208 You can also use plugin for images inside scrolling container, such as div with scrollbar.
209 <div class="collapsible">
210 <p>Just pass the container as jQuery object.</p>
211 For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#images-inside-container">main documentation</a>.
212 </div>
213 </td>
214 </tr>
215 <tr id="lazyload_data_attribute">
216 <td><a href="#" class="permalink">lazyload_data_attribute</a></td>
217 <td><code>'original'</code></td>
218 <td>
219 You must alter your image tags. Address of the image must be put into <code>data-original</code> attribute.
220 <div class="collapsible">
221 <p>Use this option to set a different attribute.</p>
222 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:
223 <pre class="prettyprint lang-js">$(function() {
224 $( 'table' ).tablesorter({
225 theme : 'blue',
226 widgets : [ 'lazyload' ],
227 widgetOptions : {
228 lazyload_appear : function( elements_left, settings ) {
229 // elements_left = number of images left to load
230 // settings = lazyload plugin settings; not the widgetOptions setting which don't matter at this point
231 settings.data_attribute = window.devicePixelRatio > 1 && $( this ).attr( 'retina' ) ?
232 // use "data-retina" for higher resolution images
233 'retina' :
234 // fallback to "data-original" for non-retina displays
235 'original';
236 }
237 }
238 });
239 });</pre>
240 For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#how-to-use">main documentation</a>.
241 </div>
242 </td>
243 </tr>
244 <tr id="lazyload_skip_invisible">
245 <td><a href="#" class="permalink">lazyload_skip_invisible</a></td>
246 <td><code>true</code></td>
247 <td>
248 There are cases when you have images which are in viewport but not <code>:visible</code> (<span class="version updated">v2.25.6</span>).
249 <div class="collapsible">
250 <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>
251 <p>To improve performance you can ignore <code>.not(":visible")</code> images by setting this option to <code>true</code>.</p>
252 For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#dealing-with-invisible-images">main documentation</a>.
253 </div>
254 </td>
255 </tr>
256 <tr id="lazyload_appear">
257 <td><a href="#" class="permalink">lazyload_appear</a></td>
258 <td><code>null</code></td>
259 <td>
260 This function is called when image appears in the viewport, but before it is loaded.
261 <div class="collapsible">
262 <p>Use this callback function as follows:</p>
263 <pre class="prettyprint lang-js">$(function() {
264 $( 'table' ).tablesorter({
265 theme : 'blue',
266 widgets : [ 'lazyload' ],
267 widgetOptions : {
268 lazyload_appear : function( elements_left, settings ) {
269 // elements_left = number of images left to load
270 // settings = plugin settings; not the widgetOptions
271 $( this ).parent().addClass( 'loading' );
272 }
273 }
274 });
275 });</pre>
276 There doesn't appear to be any documentation for this callback in the main documentation.
277 </div>
278 </td>
279 </tr>
280 <tr id="lazyload_load">
281 <td><a href="#" class="permalink">lazyload_load</a></td>
282 <td><code>null</code></td>
283 <td>
284 This function is called after the image has completed loading.
285 <div class="collapsible">
286 <p>Use this callback function as follows:</p>
287 <pre class="prettyprint lang-js">$(function() {
288 $( 'table' ).tablesorter({
289 theme : 'blue',
290 widgets : [ 'lazyload' ],
291 widgetOptions : {
292 lazyload_load : function( elements_left, settings ) {
293 // elements_left = number of images left to load
294 // settings = plugin settings; not the widgetOptions
295 $( this ).parent().removeClass( 'loading' );
296 }
297 }
298 });
299 });</pre>
300 There doesn't appear to be any documentation for this callback in the main documentation.
301 </div>
302 </td>
303 </tr>
304 <tr id="lazyload_placeholder">
305 <td><a href="#" class="permalink">lazyload_placeholder</a></td>
306 <td>See description</td>
307 <td>
308 This placeholder replaces the image until it gets loaded.
309 <div class="collapsible">
310 <p>By default, this setting is an encoded gif of a 1x1 transparent pixel.</p>
311 <p>Default: <code>'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=='</code></p>
312 For more details, see the <a class="external" href="http://www.appelsiini.net/projects/lazyload#fallback-for-non-javascript-browsers">main documentation</a>.
313 </div>
314 </td>
315 </tr>
316 </tbody>
317 </table>
318 </div>
319
320 <h3><a href="#">Method</a></h3>
321 <div>
322 <h3>Force lazyload widget update</h3>
323 If you need to programmically force the lazyload widget to update, trigger a <code>'lazyloadUpdate'</code> event on the table:
324 <pre class="prettyprint lang-js">$( 'table' ).trigger( 'lazyloadUpdate' );</pre>
325 You can change this event name by setting the <code>lazyload_update</code> option.
326 </div>
327
328 </div>
329
330 <p></p>
331
332 <h1>Demo</h1>
333 <div id="demo"><table class="tablesorter">
334 <thead>
335 <tr>
336 <th>First Name</th>
337 <th>Last Name</th>
338 <th>Image</th>
339 </tr>
340 </thead>
341 <tbody>
342 <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>
343 <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>
344 <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>
345 <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>
346 <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>
347 <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>
348 <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>
349 <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>
350 <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>
351 </tbody>
352 </table></div>
353
354 <h1>Javascript</h1>
355 <div id="javascript">
356 <pre class="prettyprint lang-javascript"></pre>
357 </div>
358 <h1>HTML</h1>
359 <div id="html">
360 <pre class="prettyprint lang-html"></pre>
361 </div>
362
363 </div>
364
365 </body>
366 </html>