index.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8'>
  5. <title>Timepicker for jQuery &ndash; Demos and Documentation</title>
  6. <meta name="description" content="A lightweight, customizable jQuery timepicker plugin inspired by Google Calendar. Add a user-friendly javascript timepicker dropdown to your app in minutes." />
  7. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  8. <script type="text/javascript" src="jquery.timepicker.js"></script>
  9. <link rel="stylesheet" type="text/css" href="jquery.timepicker.css" />
  10. <script type="text/javascript" src="lib/bootstrap-datepicker.js"></script>
  11. <link rel="stylesheet" type="text/css" href="lib/bootstrap-datepicker.css" />
  12. <script type="text/javascript" src="lib/site.js"></script>
  13. <link rel="stylesheet" type="text/css" href="lib/site.css" />
  14. </head>
  15. <body>
  16. <header>
  17. <h1><a href="https://github.com/jonthornton/jquery-timepicker">jquery.timepicker</a></h1>
  18. <p class="body-text">
  19. A lightweight, customizable javascript timepicker plugin for jQuery inspired by Google Calendar.
  20. </p>
  21. <ul id="header-links">
  22. <li><a href="https://github.com/jonthornton/jquery-timepicker#timepicker-plugin-for-jquery">Documentation</a></li>
  23. <li><a href="https://github.com/jonthornton/jquery-timepicker">Source code on GitHub</a></li>
  24. <li><a href="https://github.com/jonthornton/jquery-timepicker/zipball/master">Download (zip)</a></li>
  25. <li><a href="https://github.com/jonthornton/jquery-timepicker/issues?state=open">Help</a></li>
  26. </ul>
  27. </header>
  28. <section>
  29. <p class="body-text">Use this plugin to unobtrusively add a timepicker dropdown to your forms. It's lightweight (2.7kb minified and gzipped) and easy to customize.</p>
  30. </section>
  31. <section id="examples">
  32. <article>
  33. <div class="demo">
  34. <h2>Basic Example</h2>
  35. <p>
  36. <input id="basicExample" type="text" class="time" />
  37. </p>
  38. </div>
  39. <script>
  40. $(function() {
  41. $('#basicExample').timepicker();
  42. });
  43. </script>
  44. <pre class="code" data-language="javascript">$('#basicExample').timepicker();</pre>
  45. </article>
  46. <article>
  47. <div class="demo">
  48. <h2>Scroll Default Example</h2>
  49. <p>Set the scroll position to local time if no value selected.</p>
  50. <p>
  51. <input id="scrollDefaultExample" type="text" class="time" />
  52. </p>
  53. </div>
  54. <script>
  55. $(function() {
  56. $('#scrollDefaultExample').timepicker({ 'scrollDefault': 'now' });
  57. });
  58. </script>
  59. <pre class="code" data-language="javascript">$('#scrollDefaultExample').timepicker({ 'scrollDefault': 'now' });</pre>
  60. </article>
  61. <article>
  62. <div class="demo">
  63. <h2>Set Time Example</h2>
  64. <p>Dynamically set the time using a Javascript Date object.</p>
  65. <p>
  66. <input id="setTimeExample" type="text" class="time" />
  67. <button id="setTimeButton">Set current time</button>
  68. </p>
  69. </div>
  70. <script>
  71. $(function() {
  72. $('#setTimeExample').timepicker();
  73. $('#setTimeButton').on('click', function() {
  74. $('#setTimeExample').timepicker('setTime', new Date());
  75. });
  76. });
  77. </script>
  78. <pre class="code" data-language="javascript">$('#setTimeExample').timepicker();
  79. $('#setTimeButton').on('click', function (){
  80. $('#setTimeExample').timepicker('setTime', new Date());
  81. });</pre>
  82. </article>
  83. <article>
  84. <div class="demo">
  85. <h2>Duration Example</h2>
  86. <p>Set a starting time and see duration from that starting time. You can optionally set an maxTime as well.</p>
  87. <p>
  88. <input id="durationExample" type="text" class="time" />
  89. </p>
  90. </div>
  91. <script>
  92. $(function() {
  93. $('#durationExample').timepicker({
  94. 'minTime': '2:00pm',
  95. 'maxTime': '11:30pm',
  96. 'showDuration': true
  97. });
  98. });
  99. </script>
  100. <pre class="code" data-language="javascript">$('#durationExample').timepicker({
  101. 'minTime': '2:00pm',
  102. 'maxTime': '11:30pm',
  103. 'showDuration': true
  104. });</pre>
  105. </article>
  106. <article>
  107. <div class="demo">
  108. <h2>Event Example</h2>
  109. <p>Trigger an event after selecting a value. Fires before the input onchange event.</p>
  110. <p>
  111. <input id="onselectExample" type="text" class="time" />
  112. <span id="onselectTarget" style="margin-left: 30px;"></span>
  113. </p>
  114. </div>
  115. <script>
  116. $(function() {
  117. $('#onselectExample').timepicker();
  118. $('#onselectExample').on('changeTime', function() {
  119. $('#onselectTarget').text($(this).val());
  120. });
  121. });
  122. </script>
  123. <pre class="code" data-language="javascript">$('#onselectExample').timepicker();
  124. $('#onselectExample').on('changeTime', function() {
  125. $('#onselectTarget').text($(this).val());
  126. });</pre>
  127. </article>
  128. <article>
  129. <div class="demo">
  130. <h2>DisableTimeRanges Example</h2>
  131. <p>Prevent selection of certain time values.</p>
  132. <p>
  133. <input id="disableTimeRangesExample" type="text" class="time" />
  134. </p>
  135. </div>
  136. <script>
  137. $(function() {
  138. $('#disableTimeRangesExample').timepicker({ 'disableTimeRanges': [
  139. ['1am', '2am'],
  140. ['3am', '4:01am']
  141. ] });
  142. });
  143. </script>
  144. <pre class="code" data-language="javascript">$('#disableTimeRangesExample').timepicker({
  145. 'disableTimeRanges': [
  146. ['1am', '2am'],
  147. ['3am', '4:01am']
  148. ]
  149. });</pre>
  150. </article>
  151. <article>
  152. <div class="demo">
  153. <h2>noneOption Example</h2>
  154. <p>Custom options can be added to the dropdown menu.</p>
  155. <p>
  156. <input id="noneOptionExample" type="text" class="time" />
  157. </p>
  158. </div>
  159. <script>
  160. $(function() {
  161. $('#noneOptionExample').timepicker({
  162. 'noneOption': [{
  163. 'label': 'Foobar',
  164. 'className': 'shibby',
  165. 'value': '42'
  166. },
  167. 'Foobar2'
  168. ]
  169. });
  170. });
  171. </script>
  172. <pre class="code" data-language="javascript">
  173. $('#noneOptionExample').timepicker({
  174. 'noneOption': [
  175. {
  176. 'label': 'Foobar',
  177. 'className': 'shibby',
  178. 'value': '42'
  179. },
  180. 'Foobar2'
  181. ]
  182. });
  183. </pre>
  184. </article>
  185. <article>
  186. <div class="demo">
  187. <h2>timeFormat Example</h2>
  188. <p>timepicker.jquery uses the time portion of <a href="http://php.net/manual/en/function.date.php">PHP's date formatting commands</a>.</p>
  189. <p>
  190. <input id="timeformatExample1" type="text" class="time" />
  191. <input id="timeformatExample2" type="text" class="time" />
  192. </p>
  193. </div>
  194. <script>
  195. $(function() {
  196. $('#timeformatExample1').timepicker({ 'timeFormat': 'H:i:s' });
  197. $('#timeformatExample2').timepicker({ 'timeFormat': 'h:i A' });
  198. });
  199. </script>
  200. <pre class="code" data-language="javascript">$('#timeformatExample1').timepicker({ 'timeFormat': 'H:i:s' });
  201. $('#timeformatExample2').timepicker({ 'timeFormat': 'h:i A' });</pre>
  202. </article>
  203. <article>
  204. <div class="demo">
  205. <h2>Step Example</h2>
  206. <p>Generate drop-down options with varying levels of precision.</p>
  207. <p>
  208. <input id="stepExample1" type="text" class="time" />
  209. <input id="stepExample2" type="text" class="time" />
  210. </p>
  211. </div>
  212. <script>
  213. $(function() {
  214. $('#stepExample1').timepicker({ 'step': 15 });
  215. $('#stepExample2').timepicker({
  216. 'step': function(i) {
  217. return (i % 2) ? 15 : 45;
  218. }
  219. });
  220. });
  221. </script>
  222. <pre class="code" data-language="javascript">$('#stepExample1').timepicker({ 'step': 15 });
  223. $('#stepExample2').timepicker({
  224. 'step': function(i) {
  225. return (i%2) ? 15 : 45;
  226. }
  227. });</pre>
  228. </article>
  229. <article>
  230. <div class="demo">
  231. <h2>forceRoundTime Example</h2>
  232. <p>jquery-timepicker allows entering times via the keyboard. Setting forceRoundTime to true will round the entered time to the nearest option on the dropdown list.</p>
  233. <p>
  234. <input id="roundTimeExample" type="text" class="time" /> </p>
  235. </div>
  236. <script>
  237. $(function() {
  238. $('#roundTimeExample').timepicker({ 'forceRoundTime': true });
  239. });
  240. </script>
  241. <pre class="code" data-language="javascript">$('#roundTimeExample').timepicker({ 'forceRoundTime': true });</pre>
  242. </article>
  243. <article>
  244. <div class="demo">
  245. <h2>Select Example</h2>
  246. <p>jquery-timepicker can render itself as a select element too.</p>
  247. <p>
  248. <input id="selectExample" class="time" name="foo" />
  249. <button id="selectButton">Toggle</button>
  250. </p>
  251. </div>
  252. <script>
  253. $(function() {
  254. $('#selectExample').timepicker();
  255. $('#selectButton').click(function(e) {
  256. $('#selectExample').timepicker('option', { useSelect: true });
  257. $(this).hide();
  258. });
  259. });
  260. </script>
  261. <pre class="code" data-language="javascript">$('#selectExample').timepicker();
  262. $('#selectButton').click(function(e) {
  263. $('#selectExample').timepicker('option', { useSelect: true });
  264. $(this).hide();
  265. });</pre>
  266. </article>
  267. <article>
  268. <div class="demo">
  269. <h2>Non-input Example</h2>
  270. <p>jquery-timepicker can be bound to any visibile DOM element, such as spans or divs.</p>
  271. <p><span id="spanExample" style="background:#f00; padding:0 10px; margin-right:100px;"></span>
  272. <button id="openSpanExample">Pick Time</button>
  273. </p>
  274. </div>
  275. <script>
  276. $(function() {
  277. $('#spanExample').timepicker();
  278. $('#openSpanExample').on('click', function() {
  279. $('#spanExample').timepicker('show');
  280. });
  281. });
  282. </script>
  283. <pre class="code" data-language="javascript">$('#spanExample').timepicker();
  284. $('#openSpanExample').on('click', function(){
  285. $('#spanExample').timepicker('show');
  286. });</pre>
  287. </article>
  288. <article>
  289. <div class="demo">
  290. <h2>Datepair Plugin Example</h2>
  291. <p>jquery-timepicker is designed to work with the <a href="http://jonthornton.github.com/Datepair.js">jquery-datepair plugin</a>.
  292. <p id="datepairExample">
  293. <input type="text" class="date start" />
  294. <input type="text" class="time start" /> to
  295. <input type="text" class="time end" />
  296. <input type="text" class="date end" />
  297. </p>
  298. </div>
  299. <script src="http://jonthornton.github.io/Datepair.js/dist/datepair.js"></script>
  300. <script src="http://jonthornton.github.io/Datepair.js/dist/jquery.datepair.js"></script>
  301. <script>
  302. $('#datepairExample .time').timepicker({
  303. 'showDuration': true,
  304. 'timeFormat': 'g:ia'
  305. });
  306. $('#datepairExample .date').datepicker({
  307. 'format': 'm/d/yyyy',
  308. 'autoclose': true
  309. });
  310. $('#datepairExample').datepair();
  311. </script>
  312. <pre class="code" data-language="javascript">
  313. &lt;p id="datepairExample"&gt;
  314. &lt;input type="text" class="date start" /&gt;
  315. &lt;input type="text" class="time start" /&gt; to
  316. &lt;input type="text" class="time end" /&gt;
  317. &lt;input type="text" class="date end" /&gt;
  318. &lt;/p&gt;
  319. &lt;script type="text/javascript" src="datepair.js"&gt;&lt;/script&gt;
  320. &lt;script type="text/javascript" src="jquery.datepair.js"&gt;&lt;/script&gt;
  321. &lt;script&gt;
  322. // initialize input widgets first
  323. $('#datepairExample .time').timepicker({
  324. 'showDuration': true,
  325. 'timeFormat': 'g:ia'
  326. });
  327. $('#datepairExample .date').datepicker({
  328. 'format': 'yyyy-m-d',
  329. 'autoclose': true
  330. });
  331. // initialize datepair
  332. $('#datepairExample').datepair();
  333. &lt;/script&gt;</pre>
  334. </article>
  335. </section>
  336. <section>
  337. <h2>Need Help?</h2>
  338. <p>Check <a href="https://github.com/jonthornton/jquery-timepicker#timepicker-plugin-for-jquery">the documentation</a> or <a href="https://github.com/jonthornton/jquery-timepicker/issues?state=open">submit an issue</a> on GitHub.</p>
  339. </section>
  340. <footer>
  341. <p>&copy; 2014 <a href="http://jonthornton.com">Jon Thornton</a></p>
  342. </footer>
  343. <script>
  344. (function(i, s, o, g, r, a, m) {
  345. i['GoogleAnalyticsObject'] = r;
  346. i[r] = i[r] || function() {
  347. (i[r].q = i[r].q || []).push(arguments)
  348. }, i[r].l = 1 * new Date();
  349. a = s.createElement(o),
  350. m = s.getElementsByTagName(o)[0];
  351. a.async = 1;
  352. a.src = g;
  353. m.parentNode.insertBefore(a, m)
  354. })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
  355. ga('create', 'UA-15605525-4', 'auto');
  356. ga('send', 'pageview');
  357. </script>
  358. </div>
  359. </body>
  360. </html>