Debian Codegraph @

docs/example-parsers-duration.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>jQuery tablesorter - Duration &amp; countdown parsers</title>
6
7 <!-- jQuery -->
8 <script src="js/jquery-latest.min.js"></script>
9
10 <!-- Demo stuff -->
11 <link class="ui-theme" rel="stylesheet" href="css/jquery-ui.min.css">
12 <script src="js/jquery-ui.min.js"></script>
13 <link rel="stylesheet" href="css/jq.css">
14 <link href="css/prettify.css" rel="stylesheet">
15 <script src="js/prettify.js"></script>
16 <script src="js/docs.js"></script>
17 <style>
18 th { width: 20%; }
19 span.valx { float: right; }
20 </style>
21
22 <link href="../css/theme.blue.css" rel="stylesheet">
23 <script src="../js/jquery.tablesorter.js"></script>
24
25 <!-- load duration parsers -->
26 <script src="../js/parsers/parser-duration.js"></script>
27
28 <script id="js">$(function() {
29
30 // call the tablesorter plugin
31 $("table").tablesorter({
32 theme : 'blue',
33 sortList : [[1,0]],
34 widgets : ["zebra"],
35
36 // Change max length of values
37 // if any time value is > 9999 & < 100,000 then change this option to 5
38 // values > 99,999 and < 100,000 then change the option to 6, etc
39 durationLength : 4,
40 // Modify the labels used in your table
41 // labels can be of any length; multiple labels must be separated by a comma
42 // 'y,d,h,m,s'
43 durationLabels : '(?:years|year|y),(?:days|day|d),(?:hours|hour|h),(?:minutes|minute|min|m),(?:seconds|second|sec|s)'
44 });
45
46 });</script>
47 </head>
48 <body>
49 <div id="banner">
50 <h1>table<em>sorter</em></h1>
51 <h2>Duration &amp; countdown parsers</h2>
52 <h3>Flexible client-side table sorting</h3>
53 <a href="index.html">Back to documentation</a>
54 </div>
55 <div id="main">
56 <p></p>
57 <br>
58
59 <div id="root" class="accordion">
60 <h3><a href="#">Notes</a></h3>
61 <div>
62 <ul>
63 <li>Both the duration &amp; countdown parsers are contained in the <code>parser-duration.js</code> file.</li>
64 <li>Neither parser checks for valid time settings, all it does is parse the values to make them sortable.</li>
65 </ul>
66 </div>
67 <h3><a href="#">Duration Parser</a></h3>
68 <div>
69 <ul>
70 <li>The duration parser will convert a duration time "<code>####</code><span class="label label-info">y</span> <code>####</code><span class="label label-info">d</span> <code>####</code><span class="label label-info">h</span> <code>####</code><span class="label label-info">m</span> <code>####</code><span class="label label-info">s</span>" into a sortable value.</li>
71 <li>It is not designed to convert <code>365</code> days into <code>1</code> year, nor perform any other conversions.</li>
72 <li>Options:
73 <ul>
74 <li><code>durationLabels</code>
75 <ul>
76 <li>Default: <code>'(?:years|year|y),(?:days|day|d),(?:hours|hour|h),(?:minutes|minute|min|m),(?:seconds|second|sec|s)'</code></li>
77 <li>Add more or change the duration labels by modifying this option; separate the labels with a comma.</li>
78 <li>The label doesn't need to include regex. If you are only using one letter, change the label to <code>'y,d,h,m,s'</code></li>
79 </ul>
80 </li>
81 <li><code>durationLength</code>
82 <ul>
83 <li>Default: <code>4</code></li>
84 <li>Modify this value so that the <em>max length</em> of values is included.</li>
85 <li>The default value of <code>4</code> will include values up to <code>9,999</code></li>
86 <li>Values less than or equal to <code>99,999</code> will require this option to be set to <code>5</code></li>
87 <li>Values less than or equal to <code>999,999</code> need this value set to <code>6</code>, etc.</li>
88 </ul>
89 </li>
90 </ul>
91 </li>
92 </ul>
93 </div>
94 <h3><a href="#">Countdown Parser</a></h3>
95 <div>
96 <ul>
97 <li>The countdown parser will convert a countdown time "<code>####</code><span class="label label-info">:</span><code>####</code><span class="label label-info">:</span><code>####</code>" into a sortable value.</li>
98 <li>It is not designed to deal with invalid times like <code>65:99</code> (65 minutes &amp; 99 seconds).</li>
99 <li>This parser also uses the <code>durantionLength</code> value to set the maximum length of each value used in the countdown.
100 <ul>
101 <li>Default: <code>4</code></li>
102 <li>Modify this value so that the <em>max length</em> of values is included.</li>
103 <li>The default value of <code>4</code> will include values up to <code>9,999</code></li>
104 <li>Values less than or equal to <code>99,999</code> will require this option to be set to <code>5</code></li>
105 <li>Values less than or equal to <code>999,999</code> need this value set to <code>6</code>, etc.</li>
106 </ul>
107 </li>
108 </ul>
109 </div>
110 </div>
111
112 <h1>Demo</h1>
113
114 <button type="button" class="toggleparsedvalue">toggle</button> parsed values within the column
115
116 <div id="demo"><table class="tablesorter">
117 <thead>
118 <tr>
119 <th>Name</th>
120 <th class="sorter-duration">Duration</th>
121 <th class="sorter-countdown">Countdown</th>
122 </tr>
123 </thead>
124 <tbody>
125 <tr><td>Frank</td><td>1y 23d 12h 44m 9s</td><td>2:21:16</td></tr>
126 <tr><td>Fred</td><td>12d 12h 14m 20s</td><td>44:25</td></tr>
127 <tr><td>Albert</td><td>12h 14m 3s</td><td>1:9:2</td></tr>
128 <tr><td>Aaron</td><td>3d 11h 13m 22s</td><td>1:5:5</td></tr>
129 <tr><td>Oliver</td><td>3d 11h 14s</td><td>4:33:33</td></tr>
130 <tr><td>Xavier</td><td>11m 41s</td><td>59:59</td></tr>
131 <tr><td>Henry</td><td>12m</td><td>10:22:32</td></tr>
132 <tr><td>Lucy</td><td>23d 12h 44m 10s</td><td>2:43:52</td></tr>
133 <tr><td>Marsha</td><td>1y 1h 1m 1s</td><td>3:12:18</td></tr>
134 <tr><td>Pat</td><td>12 days 12hours 44minutes 50 seconds</td><td>22:51</td></tr>
135 <tr><td>George</td><td>33s</td><td>1:53:21</td></tr>
136 <tr><td>Oscar</td><td>24d 12h 11m 11s</td><td>51:12</td></tr>
137 </tbody>
138 </table></div>
139
140 <h1>Script</h1>
141 <div id="javascript">
142 <pre class="prettyprint lang-js"></pre>
143 </div>
144
145 <h1>HTML</h1>
146 <div id="html">
147 <pre class="prettyprint lang-html"></pre>
148 </div>
149
150 <script>
151 $(function() {
152 var $table = $('table'),
153 len = $table[0].config.durationLength,
154 regex = new RegExp('(\\d{' + len + '})', 'g');
155 // add parsed values to order & value column
156 addParsedValues( $table, [1,2], function(v) {
157 var t = v.replace(regex, '$1|');
158 return t.substring(0, t.length - 1);
159 });
160 });
161 </script>
162
163 </div>
164 </body>
165 </html>