Debian Codegraph @

docs/example-widget-align-character.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter 2.0 - Align Character Widget</title>
6
7 <!-- jQuery -->
8 <script src="js/jquery-latest.min.js"></script>
9
10 <!-- Demo stuff -->
11 <link rel="stylesheet" href="css/jq.css">
12 <link href="css/prettify.css" rel="stylesheet">
13 <link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css">
14 <script src="js/jquery-ui.min.js"></script>
15 <script src="js/prettify.js"></script>
16 <script src="js/docs.js"></script>
17
18 <!-- Tablesorter: required -->
19 <link rel="stylesheet" href="../css/theme.blue.css">
20 <script src="../js/jquery.tablesorter.js"></script>
21 <script src="../js/jquery.tablesorter.widgets.js"></script>
22
23 <script src="../js/widgets/widget-alignChar.js"></script>
24
25 <style>
26 /* demo stuff */
27 .accordion th:nth-child(2) {
28 width: 140px;
29 }
30 #demo th {
31 width: 25%;
32 }
33 </style>
34
35 <style id="css">/* CSS needed for this widget */
36 .ts-align-wrap {
37 display: block;
38 white-space: nowrap; /* optional */
39 width: 100%;
40 overflow: hidden;
41 }
42 .ts-align-wrap, .ts-align-left, .ts-align-right {
43 -moz-box-sizing: border-box;
44 -webkit-box-sizing: border-box;
45 box-sizing: border-box;
46 }
47 .ts-align-left {
48 display: inline-block;
49 text-align:right;
50 }
51 .ts-align-right {
52 display: inline-block;
53 text-align:left;
54 }
55 /* optional - colorize alignment character in Animals column */
56 td:nth-child(3) .ts-align-right i {
57 color: red;
58 }</style>
59
60 <script id="js">$(function() {
61
62 $("table").tablesorter({
63 theme: 'blue',
64 widgets: ['zebra', 'alignChar'],
65 widgetOptions : {
66 alignChar_wrap : '<i/>',
67 alignChar_charAttrib : 'data-align-char',
68 alignChar_indexAttrib : 'data-align-index',
69 alignChar_adjustAttrib : 'data-align-adjust' // percentage width adjustments
70 }
71 });
72
73 });
74 </script>
75 </head>
76 <body id="align">
77
78 <div id="banner">
79 <h1>table<em>sorter</em></h1>
80 <h2>Align Character Widget</h2>
81 <h3>Flexible client-side table sorting</h3>
82 <a href="index.html">Back to documentation</a>
83 </div>
84
85 <div id="main">
86
87 <p></p>
88 <br>
89
90 <div class="accordion">
91
92 <h3><a href="#">Notes</a></h3>
93 <div>
94 <ul>
95 <li>In <span class="version">v2.31.3</span>, tweaked the css to prevent change in vertical height. See <a href="https://github.com/Mottie/tablesorter/issues/1713">issue #1713</a>.</li>
96 <li>In <span class="version">v2.19.0</span>, if there is nothing to the right of the set align character, then the align character will not be added; this prevents hanging decimals like <code>3000.</code>.<p></p></li>
97 <li>This widget will <strong>only work</strong> in tablesorter version 2.8+ and jQuery version 1.7+.</li>
98 <li>Make sure to include the CSS shown below to maintain the alignment.</li>
99 <li><span class="label warning">*NOTE*</span> if the table cell becomes too narrow, the alignment <strong>will not</strong> be maintained &amp; some content may overflow into the next/previous cell (the widget css does include <code>overflow:hidden</code> on the wrapper, so some content will be hidden instead of overflowing).</li>
100 <li>Until the day that <code>text-align: '.' center;</code> becomes standard in CSS4 (<a href="https://www.w3.org/TR/css-text-4/#character-alignment">ref</a>), if ever, this widget might prove useful.</li>
101 </ul>
102 </div>
103
104 <h3><a href="#">Options</a></h3>
105 <div>
106 <h3>Align Character (alignChar) widget default options (added inside of tablesorter <code>widgetOptions</code>)</h3>
107 <div>
108 <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.
109 </div>
110 <table class="tablesorter-blue">
111 <colgroup><col style="width:135px"></colgroup>
112 <thead>
113 <tr><th>Option</th><th>Default</th><th class="sorter-false">Description</th></tr>
114 </thead>
115 <tbody>
116 <tr>
117 <td><a href="#" class="permalink">alignChar_wrap</a></td>
118 <td><code>''</code></td>
119 <td>
120 This option allows you to wrap the alignment character in any HTML:
121 <div class="collapsible">
122 <br>
123 When the widget completes the alignment, it is basically splitting the content of the table cell into two halves, and wrapping it in a span element. Below is an example of a modified cell showing all contents; it's from the "Animals" column (the cell that contains "Ox = stinky")
124 <pre class="prettyprint lang-html">&lt;td&gt;
125 &lt;span class=&quot;ts-align-wrap&quot;&gt;
126 &lt;span class=&quot;ts-align-left&quot; style=&quot;min-width:37%&quot;&gt;Ox&amp;nbsp;&lt;/span&gt;
127 &lt;span class=&quot;ts-align-right&quot; style=&quot;min-width:63%&quot;&gt;=&amp;nbsp;stinky&lt;/span&gt;
128 &lt;/span&gt;
129 &lt;/td&gt;</pre>
130 When this option is set with some HTML:
131 <br><pre class="prettyprint lang-js">alignChar_wrap : '&lt;i/&gt;'</pre>
132 it results in this layout:
133 <pre class="prettyprint lang-html">&lt;td&gt;
134 &lt;span class=&quot;ts-align-wrap&quot;&gt;
135 &lt;span class=&quot;ts-align-left&quot; style=&quot;min-width:37%&quot;&gt;Ox&amp;nbsp;&lt;/span&gt;
136 &lt;span class=&quot;ts-align-right&quot; style=&quot;min-width:63%&quot;&gt;
137 &lt;i&gt;=&lt;/i&gt;&amp;nbsp;stinky
138 &lt;/span&gt;
139 &lt;/span&gt;
140 &lt;/td&gt;</pre>
141 </div>
142 </td>
143 </tr>
144 <tr>
145 <td><a href="#" class="permalink">alignChar_charAttrib</a></td>
146 <td><code>'data-align-char'</code></td>
147 <td>
148 This option points to the header data-attribute which contains the desired alignment character.
149 <div class="collapsible">
150 <br>
151 Add it to the header as follows:
152 <pre class="prettyprint lang-html">&lt;th data-align-char="."&gt;Numeric&lt;/th&gt;</pre>
153 The <code>data-align-char</code> data-attribute contains the actual character to align. There is no default alignment character, so if this data-attribute is undefined, the column will be ignored.<br>
154 <br>
155 <span class="label warning">*NOTE*</span> if wanting to align the content on a space (see the "AlphaNumeric" column), use <code>&amp;nbsp;</code> instead of a regular space because all spaces within the content are replaced by non-breaking spaces.
156 <pre class="prettyprint lang-html">&lt;th data-align-char="&amp;nbsp;"&gt;AlphaNumeric&lt;/th&gt;</pre>
157 </div>
158 </td>
159 </tr>
160 <tr>
161 <td><a href="#" class="permalink">alignChar_indexAttrib</a></td>
162 <td><code>'data-align-index'</code></td>
163 <td>This option points to the header data-attribute which contains the desired alignment character index (<strong>one-based index</strong>).
164 <div class="collapsible">
165 <ul>
166 <li>What that means is if your data has multiple periods, like in the URLs of the sites column below, you can tell the widget which period to line-up on.</li>
167 <li>The alignment may seem to act incorrectly, if your data doesn't have enough periods to line up on, but it's doing the best it can! For example, in the sites column below, a table cell contains <code>"rental.nytimes.com/index.html"</code>. This URL has three periods, while all other cells in that column only contain two. When the <code>data-align-index</code> is set to <code>"3"</code>, the widget aligns the content on that third period. All of the other columns only have two, so they all align on their last period. Does that make it clear?</li>
168 <li>Try adjusting the sliders in this demo to change the <code>data-align-index</code> of the "Animals" and "Sites" columns to see how this works.</li>
169 </ul>
170 Add this attribute to the header as follows:
171 <pre class="prettyprint lang-html">&lt;th data-align-char="=" data-align-index="1"&gt;Animals&lt;/th&gt;</pre>
172 The <code>data-align-index</code> data-attribute contains the actual character index. The index defaults to "1" if this data-attribute is undefined.
173 </div>
174 </td>
175 </tr>
176 <tr>
177 <td><a href="#" class="permalink">alignChar_adjustAttrib</a></td>
178 <td><code>'data-align-adjust'</code></td>
179 <td>This option allows you to tweak the horizontal position of the aligned cell content.
180 <div class="collapsible">
181 <ul>
182 <li>Here is an example of a modified cell showing its contents; it's from the "Numeric" column (the cell that contains "87.20000"):
183 <pre class="prettyprint lang-html">&lt;td&gt;
184 &lt;span class=&quot;ts-align-wrap&quot;&gt;
185 &lt;span class=&quot;ts-align-left&quot; style=&quot;min-width:36%&quot;&gt;87&lt;/span&gt;
186 &lt;span class=&quot;ts-align-right&quot; style=&quot;min-width:64%&quot;&gt;.20000&lt;/span&gt;
187 &lt;/span&gt;
188 &lt;/td&gt;</pre>As you can see, the "87" (integer-part) is in a "ts-align-left" span, set with a <code>text-align: right;</code> (it's on the left, but right aligned)<br>
189 The ".20000" (fractional-part) is in a "ts-align-right" span, set with a <code>text-align: left;</code> (opposite of the other one)!<br>
190 </li>
191 <li>So in the above example, the left side is set to a width of "36%" and the right to "64%" (adding up to 100%), which "sort-of" centers the aligned character.</li>
192 <li>If you don't want to move the position of the aligned character, you can set the <code>data-align-adjust</code> data-attribute with a percentage change. This value (positive or negative) will be added to the "ts-align-left" span, and subtracted from the "ts-align-right" span.</li>
193 <li>Try adjusting the sliders in this demo to change the <code>data-align-adjust</code> of the "Sites" column to see how this works.</li>
194 </ul>
195 Add this attribute to the header as follows:
196 <pre class="prettyprint lang-html">&lt;th data-align-char="." data-align-adjust="10"&gt;Numeric&lt;/th&gt;</pre>
197 The <code>data-align-adjust</code> data-attribute contains a percentage value (without the percent sign). The adjustment defaults to "0" if this data-attribute is undefined.
198 </div>
199 </td>
200 </tr>
201 </tbody>
202 </table>
203 </div>
204
205 <h3><a href="#">CSS</a></h3>
206 <div>
207 The following is *required* css. Without it, the alignment will be all wrong.
208 <div id="css">
209 <pre class="prettyprint lang-css"></pre>
210 </div>
211 </div>
212
213 </div>
214
215 <p></p>
216
217 <h1>Demo</h1>
218
219 <span class="demo-label">Animals align index:</span> <div id="slider0"></div> <span class="bright">1</span> (only indexes of 1 or 2 will work)<br>
220 <span class="demo-label">Sites align index:</span> <div id="slider1"></div> <span class="bright">1</span> (only indexes of 1 - 3 will work<br>
221 <span class="demo-label">Sites adjust value:</span> <div id="slider2"></div> <span class="bright">0</span>
222
223 <div id="demo"><table class="tablesorter">
224 <thead>
225 <tr>
226 <th data-align-char="&nbsp;">AlphaNumeric</th>
227 <th data-align-char="." data-align-adjust="0">Numeric</th>
228 <th data-align-char="=" data-align-index="1">Animals</th>
229 <th data-align-char="." data-align-index="1">Sites</th>
230 </tr>
231 </thead>
232 <tbody>
233 <tr>
234 <td>abc 123</td>
235 <td>.423475</td>
236 <td>Koala = cute = cudley</td>
237 <td>search.google.com</td>
238 </tr>
239 <tr>
240 <td>abc 1</td>
241 <td>23.4</td>
242 <td>Ox = stinky</td>
243 <td>mail.yahoo.com</td>
244 </tr>
245 <tr>
246 <td>abc 9</td>
247 <td>1.0</td>
248 <td>Girafee = tall</td>
249 <td>http://www.facebook.com</td>
250 </tr>
251 <tr>
252 <td>zyx 24</td>
253 <td>7.67</td>
254 <td>Bison = burger</td>
255 <td>http://internship.whitehouse.gov/</td>
256 </tr>
257 <tr>
258 <td>abc 11</td>
259 <td>3000</td>
260 <td>Chimp = banana lover</td>
261 <td>about.ucla.edu/</td>
262 </tr>
263 <tr>
264 <td>abc 2</td>
265 <td>56.5</td>
266 <td>Elephant = unforgetable</td>
267 <td>http://www.wikipedia.org/</td>
268 </tr>
269 <tr>
270 <td>abc 9</td>
271 <td>15.5</td>
272 <td>Lion = rawr</td>
273 <td>rental.nytimes.com/index.html</td>
274 </tr>
275 <tr>
276 <td>ABC 10</td>
277 <td>87.20000</td>
278 <td>Zebra = stripey</td>
279 <td>http://android.google.com</td>
280 </tr>
281 <tr>
282 <td>zyx 1</td>
283 <td>999.1</td>
284 <td>Koala = cute, again!</td>
285 <td>http://irsmrt.mit.edu/</td>
286 </tr>
287 <tr>
288 <td>zyx 12</td>
289 <td>.2</td>
290 <td>Llama = llove it</td>
291 <td>http://aliens.nasa.gov/</td>
292 </tr>
293 </tbody>
294 </table></div>
295
296 <h1>Page Header</h1>
297 <div>
298 <pre class="prettyprint lang-html">&lt;!-- Tablesorter: required --&gt;
299 &lt;link href=&quot;../css/theme.blue.css&quot; rel=&quot;stylesheet&quot;&gt;
300 &lt;script src=&quot;../js/jquery.tablesorter.js&quot;&gt;&lt;/script&gt;
301 &lt;script src=&quot;../js/jquery.tablesorter.widgets.js&quot;&gt;&lt;/script&gt;
302
303 &lt;!-- Align Character widget --&gt;
304 &lt;script src=&quot;../js/widgets/widget-alignChar.js&quot;&gt;&lt;/script&gt;</pre>
305 </div>
306
307 <h1>Script</h1>
308 <div id="javascript">
309 <pre class="prettyprint lang-js"></pre>
310 </div>
311
312 <h1>CSS</h1>
313 <div id="css">
314 <pre class="prettyprint lang-css"></pre>
315 </div>
316
317 <h1>HTML</h1>
318 <div>
319 <pre class="prettyprint lang-html">&lt;table class=&quot;tablesorter&quot;&gt;
320 &lt;thead&gt;
321 &lt;tr&gt;
322 &lt;th data-align-char=&quot;&amp;nbsp;&quot;&gt;AlphaNumeric&lt;/th&gt;
323 &lt;th data-align-char=&quot;.&quot; data-align-adjust=&quot;0&quot;&gt;Numeric&lt;/th&gt;
324 &lt;th data-align-char=&quot;=&quot; data-align-index=&quot;1&quot;&gt;Animals&lt;/th&gt;
325 &lt;th data-align-char=&quot;.&quot; data-align-index=&quot;1&quot;&gt;Sites&lt;/th&gt;
326 &lt;/tr&gt;
327 &lt;/thead&gt;
328 &lt;tbody&gt;
329 &lt;tr&gt;
330 &lt;td&gt;abc 123&lt;/td&gt;
331 &lt;td&gt;.423475&lt;/td&gt;
332 &lt;td&gt;Koala = cute = cudley&lt;/td&gt;
333 &lt;td&gt;search.google.com&lt;/td&gt;
334 &lt;/tr&gt;
335 &lt;tr&gt;
336 &lt;td&gt;abc 1&lt;/td&gt;
337 &lt;td&gt;23.4&lt;/td&gt;
338 &lt;td&gt;Ox = stinky&lt;/td&gt;
339 &lt;td&gt;mail.yahoo.com&lt;/td&gt;
340 &lt;/tr&gt;
341 &lt;tr&gt;
342 &lt;td&gt;abc 9&lt;/td&gt;
343 &lt;td&gt;1.0&lt;/td&gt;
344 &lt;td&gt;Girafee = tall&lt;/td&gt;
345 &lt;td&gt;http://www.facebook.com&lt;/td&gt;
346 &lt;/tr&gt;
347 &lt;tr&gt;
348 &lt;td&gt;zyx 24&lt;/td&gt;
349 &lt;td&gt;7.67&lt;/td&gt;
350 &lt;td&gt;Bison = burger&lt;/td&gt;
351 &lt;td&gt;http://internship.whitehouse.gov/&lt;/td&gt;
352 &lt;/tr&gt;
353 &lt;tr&gt;
354 &lt;td&gt;abc 11&lt;/td&gt;
355 &lt;td&gt;3000&lt;/td&gt;
356 &lt;td&gt;Chimp = banana lover&lt;/td&gt;
357 &lt;td&gt;about.ucla.edu/&lt;/td&gt;
358 &lt;/tr&gt;
359 &lt;tr&gt;
360 &lt;td&gt;abc 2&lt;/td&gt;
361 &lt;td&gt;56.5&lt;/td&gt;
362 &lt;td&gt;Elephant = unforgetable&lt;/td&gt;
363 &lt;td&gt;http://www.wikipedia.org/&lt;/td&gt;
364 &lt;/tr&gt;
365 &lt;tr&gt;
366 &lt;td&gt;abc 9&lt;/td&gt;
367 &lt;td&gt;15.5&lt;/td&gt;
368 &lt;td&gt;Lion = rawr&lt;/td&gt;
369 &lt;td&gt;rental.nytimes.com/index.html&lt;/td&gt;
370 &lt;/tr&gt;
371 &lt;tr&gt;
372 &lt;td&gt;ABC 10&lt;/td&gt;
373 &lt;td&gt;87.20000&lt;/td&gt;
374 &lt;td&gt;Zebra = stripey&lt;/td&gt;
375 &lt;td&gt;http://android.google.com&lt;/td&gt;
376 &lt;/tr&gt;
377 &lt;tr&gt;
378 &lt;td&gt;zyx 1&lt;/td&gt;
379 &lt;td&gt;999.1&lt;/td&gt;
380 &lt;td&gt;Koala = cute, again!&lt;/td&gt;
381 &lt;td&gt;http://irsmrt.mit.edu/&lt;/td&gt;
382 &lt;/tr&gt;
383 &lt;tr&gt;
384 &lt;td&gt;zyx 12&lt;/td&gt;
385 &lt;td&gt;0.2&lt;/td&gt;
386 &lt;td&gt;Llama = llove it&lt;/td&gt;
387 &lt;td&gt;http://aliens.nasa.gov/&lt;/td&gt;
388 &lt;/tr&gt;
389 &lt;/tbody&gt;
390 &lt;/table&gt;</pre>
391 </div>
392
393 </div>
394
395 <script>
396 /* DEMO ONLY CODE */
397 $(function() {
398 var $table = $('#demo table'),
399 c = $table[0].config,
400 $animals = c.$headers.eq(2),
401 $sites = c.$headers.eq(3);
402 $animals.find('.tablesorter-header-inner')[0].innerHTML += ' ( "data-align-index" : <span></span> )';
403 $sites.find('.tablesorter-header-inner')[0].innerHTML += ' ( "data-align-index" : <span></span>, "data-align-adjust" : <span></span> )';
404 $( "#slider0" ).slider({
405 value: 1,
406 min: 0,
407 max: 3,
408 step: 1,
409 create: function() {
410 $animals.find('span').html( $animals.attr('data-align-index') );
411 },
412 slide: function( event, ui ) {
413 $animals
414 .attr('data-align-index', ui.value)
415 .find('span').html( ui.value );
416 $('.bright:eq(0)').html( ui.value );
417 $table.trigger('refreshAlign');
418 }
419 });
420 $( "#slider1" ).slider({
421 value: 1,
422 min: 0,
423 max: 4,
424 step: 1,
425 create: function() {
426 $sites.find('span').html( $sites.attr('data-align-index') );
427 },
428 slide: function( event, ui ) {
429 $sites
430 .attr('data-align-index', ui.value)
431 .find('span:eq(0)').html( ui.value );
432 $('.bright:eq(1)').html( ui.value );
433 $table.trigger('refreshAlign');
434 }
435 });
436 $( "#slider2" ).slider({
437 value: 0,
438 min: -30,
439 max: 30,
440 step: 5,
441 create: function() {
442 $sites.find('span').html( $sites.attr('data-align-index') );
443 },
444 slide: function( event, ui ) {
445 $sites
446 .attr('data-align-adjust', ui.value)
447 .find('span:eq(1)').html( ui.value );
448 $('.bright:eq(2)').html( ui.value );
449 $table.trigger('refreshAlign');
450 }
451 });
452
453 });
454 </script>
455
456 </body>
457 </html>