index.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8'>
  5. <title>Datepair.js &ndash; Demos and Documentation</title>
  6. <meta name="description" content="A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar." />
  7. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  8. <script src="https://jonthornton.github.io/jquery-timepicker/jquery.timepicker.js"></script>
  9. <link rel="stylesheet" type="text/css" href="https://jonthornton.github.io/jquery-timepicker/jquery.timepicker.css" />
  10. <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>
  11. <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.standalone.css" />
  12. <script src="lib/pikaday.js"></script>
  13. <link rel="stylesheet" type="text/css" href="lib/pikaday.css" />
  14. <script src="lib/jquery.ptTimeSelect.js"></script>
  15. <link rel="stylesheet" type="text/css" href="lib/jquery.ptTimeSelect.css" />
  16. <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css" type="text/css" media="all" />
  17. <script src="lib/moment.min.js"></script>
  18. <script src="lib/site.js"></script>
  19. <link rel="stylesheet" type="text/css" href="lib/site.css" />
  20. <script src="dist/datepair.js"></script>
  21. <script src="dist/jquery.datepair.js"></script>
  22. </head>
  23. <body>
  24. <header>
  25. <h1><a href="https://github.com/jonthornton/jquery-datepair">Datepair.js</a></h1>
  26. <p>
  27. A javascript plugin for intelligently selecting date and time ranges<br />
  28. inspired by Google Calendar. <br />
  29. </p>
  30. <ul id="header-links">
  31. <li><a href="https://github.com/jonthornton/jquery-datepair#datepair-plugin-for-jquery">Documentation</a></li>
  32. <li><a href="https://github.com/jonthornton/jquery-datepair">Source code on GitHub</a></li>
  33. <li><a href="https://github.com/jonthornton/jquery-datepair/zipball/master">Download (zip)</a></li>
  34. <li><a href="https://github.com/jonthornton/jquery-datepair/issues?state=open">Help</a></li>
  35. </ul>
  36. </header>
  37. <section>
  38. <p>Use this plugin to link date and time inputs when you need to select ranges. <br />No dependencies, with optional support for jQuery/Zepto.</p>
  39. </section>
  40. <section id="examples">
  41. <article>
  42. <div class="demo">
  43. <h2>Basic Example</h2>
  44. <p>Datepair.js doesn't include any date or time picker widgets, but it's preconfigured to work with <a href="https://github.com/jonthornton/jquery-timepicker">jquery-timepicker</a> and <a href="https://github.com/eternicode/bootstrap-datepicker">Bootstrap Datepicker</a>. Include input widgets as you normally would, and then use Datepair.js to link them.</p>
  45. <p id="basicExample">
  46. <input type="text" class="date start" />
  47. <input type="text" class="time start" /> to
  48. <input type="text" class="time end" />
  49. <input type="text" class="date end" />
  50. </p>
  51. </div>
  52. <pre class="code" data-language="javascript">
  53. &lt;p id="basicExample"&gt;
  54. &lt;input type="text" class="date start" /&gt;
  55. &lt;input type="text" class="time start" /&gt; to
  56. &lt;input type="text" class="time end" /&gt;
  57. &lt;input type="text" class="date end" /&gt;
  58. &lt;/p&gt;
  59. &lt;!-- include input widgets; this is independent of Datepair.js --&gt;
  60. &lt;link rel="styleshee" type="text/css" href="jquery.timepicker.css" /&gt;
  61. &lt;link rel="stylesheet" type="text/css" href="bootstrap-datepicker.css" /&gt;
  62. &lt;script type="text/javascript" src="bootstrap-datepicker.js"&gt;&lt;/script&gt;
  63. &lt;script type="text/javascript" src="jquery.timepicker.js"&gt;&lt;/script&gt;
  64. &lt;script type="text/javascript" src="datepair.js"&gt;&lt;/script&gt;
  65. &lt;script&gt;
  66. // initialize input widgets first
  67. $('#basicExample .time').timepicker({
  68. 'showDuration': true,
  69. 'timeFormat': 'g:ia'
  70. });
  71. $('#basicExample .date').datepicker({
  72. 'format': 'm/d/yyyy',
  73. 'autoclose': true
  74. });
  75. // initialize datepair
  76. var basicExampleEl = document.getElementById('basicExample');
  77. var datepair = new Datepair(basicExampleEl);
  78. &lt;/script&gt;
  79. </pre>
  80. <script>
  81. $('#basicExample .time').timepicker({
  82. 'showDuration': true,
  83. 'timeFormat': 'g:ia'
  84. });
  85. $('#basicExample .date').datepicker({
  86. 'format': 'm/d/yyyy',
  87. 'autoclose': true
  88. });
  89. var basicExampleEl = document.getElementById('basicExample');
  90. var datepair = new Datepair(basicExampleEl);
  91. </script>
  92. </article>
  93. <article>
  94. <div class="demo">
  95. <h2>jQuery Example</h2>
  96. <p>Include the optional jquery.datepicker.js file to interact with Datepair.js with a jQuery interface.</p>
  97. <p id="jqueryExample">
  98. <input type="text" class="date start" />
  99. <input type="text" class="time start" /> to
  100. <input type="text" class="time end" />
  101. <input type="text" class="date end" />
  102. </p>
  103. </div>
  104. <pre class="code" data-language="javascript">
  105. &lt;p id="jqueryExample"&gt;
  106. &lt;input type="text" class="date start" /&gt;
  107. &lt;input type="text" class="time start" /&gt; to
  108. &lt;input type="text" class="time end" /&gt;
  109. &lt;input type="text" class="date end" /&gt;
  110. &lt;/p&gt;
  111. &lt;script type="text/javascript" src="datepair.js"&gt;&lt;/script&gt;
  112. &lt;script type="text/javascript" src="jquery.datepair.js"&gt;&lt;/script&gt;
  113. &lt;script&gt;
  114. // initialize input widgets first
  115. $('#jqueryExample .time').timepicker({
  116. 'showDuration': true,
  117. 'timeFormat': 'g:ia'
  118. });
  119. $('#jqueryExample .date').datepicker({
  120. 'format': 'm/d/yyyy',
  121. 'autoclose': true
  122. });
  123. // initialize datepair
  124. $('#jqueryExample').datepair();
  125. &lt;/script&gt;
  126. </pre>
  127. <script>
  128. $('#jqueryExample .time').timepicker({
  129. 'showDuration': true,
  130. 'timeFormat': 'g:ia'
  131. });
  132. $('#jqueryExample .date').datepicker({
  133. 'format': 'm/d/yyyy',
  134. 'autoclose': true
  135. });
  136. $('#jqueryExample').datepair();
  137. </script>
  138. </article>
  139. <article>
  140. <div class="demo">
  141. <h2>Date-only Example</h2>
  142. <p>You can use datepair with just dates, or just times.</p>
  143. <p id="dateOnlyExample">
  144. <input type="text" class="date start" /> to
  145. <input type="text" class="date end" />
  146. </p>
  147. <p id="timeOnlyExample">
  148. <input type="text" class="time start" /> to
  149. <input type="text" class="time end" />
  150. </p>
  151. </div>
  152. <pre class="code" data-language="javascript">
  153. // HTML not shown for brevity
  154. $('#timeOnlyExample .time').timepicker({
  155. 'showDuration': true,
  156. 'timeFormat': 'g:ia'
  157. });
  158. var timeOnlyExampleEl = document.getElementById('timeOnlyExample');
  159. var timeOnlyDatepair = new Datepair(timeOnlyExampleEl);
  160. $('#dateOnlyExample .date').datepicker({
  161. 'format': 'yyyy-m-d',
  162. 'autoclose': true
  163. });
  164. var dateOnlyExampleEl = document.getElementById('dateOnlyExample');
  165. var dateOnlyDatepair = new Datepair(dateOnlyExampleEl);
  166. </pre>
  167. <script>
  168. $('#timeOnlyExample .time').timepicker({
  169. 'showDuration': true,
  170. 'timeFormat': 'g:ia'
  171. });
  172. var timeOnlyExampleEl = document.getElementById('timeOnlyExample');
  173. var timeOnlyDatepair = new Datepair(timeOnlyExampleEl);
  174. $('#dateOnlyExample .date').datepicker({
  175. 'format': 'yyyy-m-d',
  176. 'autoclose': true
  177. });
  178. var dateOnlyExampleEl = document.getElementById('dateOnlyExample');
  179. var dateOnlyDatepair = new Datepair(dateOnlyExampleEl);
  180. </script>
  181. </article>
  182. <article>
  183. <div class="demo">
  184. <h2>Default Delta Example</h2>
  185. <p>Datepair can automatically set the other input when a first value is selected.</p>
  186. <p id="defaultDeltaExample">
  187. <input type="text" class="date start" />
  188. <input type="text" class="time start" /> to
  189. <input type="text" class="time end" />
  190. <input type="text" class="date end" />
  191. </p>
  192. </div>
  193. <pre class="code" data-language="javascript">
  194. // HTML not shown for brevity
  195. var defaultDeltaExampleEl = document.getElementById('defaultDeltaExample');
  196. var defaultDeltaDatepair = new Datepair(defaultDeltaExampleEl, {
  197. 'defaultDateDelta': 1, // days
  198. 'defaultTimeDelta': 7200000 // milliseconds
  199. });
  200. </pre>
  201. <script>
  202. $('#defaultDeltaExample .time').timepicker({
  203. 'showDuration': true,
  204. 'timeFormat': 'g:ia'
  205. });
  206. $('#defaultDeltaExample .date').datepicker({
  207. 'format': 'm/d/yyyy',
  208. 'autoclose': true
  209. });
  210. var defaultDeltaExampleEl = document.getElementById('defaultDeltaExample');
  211. var defaultDeltaDatepair = new Datepair(defaultDeltaExampleEl, {
  212. 'defaultDateDelta': 1,
  213. 'defaultTimeDelta': 7200000
  214. });
  215. </script>
  216. </article>
  217. <article>
  218. <div class="demo">
  219. <h2>Alternate UI Widgets Example</h2>
  220. <p>jquery-datepair is widget agnostic and can work with any date and time pickers. Here's an example with <a href="http://pttimeselect.sourceforge.net/example/index.html">jQuery.ptTimeSelect</a> and <a href="https://github.com/dbushell/Pikaday">Pikaday</a>.</p>
  221. <p id="alternateUiWidgetsExample">
  222. <input type="text" class="date start" />
  223. <input type="text" class="time start" /> to<br />
  224. <input type="text" class="date end" />
  225. <input type="text" class="time end" />
  226. </p>
  227. </div>
  228. <pre class="code" data-language="javascript">
  229. &lt;p id="alternateUiWidgetsExample"&gt;
  230. &lt;input type="text" class="date start" /&gt;
  231. &lt;input type="text" class="time start" /&gt; to&lt;br /&gt;
  232. &lt;input type="text" class="date end" /&gt;
  233. &lt;input type="text" class="time end" /&gt;
  234. &lt;/p>
  235. &lt;script type="text/javascript" src="pikaday.js"&gt;&lt;/script&gt;
  236. &lt;script type="text/javascript" src="jquery.ptTimeSelect.js"&gt;&lt;/script&gt;
  237. &lt;script type="text/javascript" src="moment.js"&gt;&lt;/script&gt;
  238. &lt;script&gt;
  239. // initialize input widgets
  240. // ptTimeSelect doesn't trigger change event by default
  241. $('#alternateUiWidgetsExample .time').ptTimeSelect({
  242. 'onClose': function($self) {
  243. $self.trigger('change');
  244. }
  245. });
  246. $('#alternateUiWidgetsExample .date').pikaday();
  247. var TIMEFORMAT = 'h:mm a';
  248. var alternateUiWidgetsExampleEl = document.getElementById('alternateUiWidgetsExample');
  249. var alternateWidgetsDatepair = new Datepair(alternateUiWidgetsExampleEl, {
  250. parseTime: function(input){
  251. // use moment.js to parse time
  252. var m = moment(input.value, TIMEFORMAT);
  253. return m.toDate();
  254. },
  255. updateTime: function(input, dateObj){
  256. var m = moment(dateObj);
  257. input.value = m.format(TIMEFORMAT);
  258. },
  259. parseDate: function(input){
  260. var picker = $(input).data('pikaday');
  261. return picker.getDate();
  262. },
  263. updateDate: function(input, dateObj){
  264. var picker = $(input).data('pikaday');
  265. return picker.setDate(dateObj);
  266. }
  267. });
  268. &lt;/script&gt;
  269. </pre>
  270. <script>
  271. // initialize input widgets
  272. // ptTimeSelect doesn't trigger change event by default
  273. $('#alternateUiWidgetsExample .time').ptTimeSelect({
  274. 'onClose': function($self) {
  275. $self.trigger('change');
  276. }
  277. });
  278. $('#alternateUiWidgetsExample .date').pikaday();
  279. var TIMEFORMAT = 'h:mm a';
  280. var alternateUiWidgetsExampleEl = document.getElementById('alternateUiWidgetsExample');
  281. var alternateWidgetsDatepair = new Datepair(alternateUiWidgetsExampleEl, {
  282. parseTime: function(input){
  283. // use moment.js to parse time
  284. var m = moment(input.value, TIMEFORMAT);
  285. return m.toDate();
  286. },
  287. updateTime: function(input, dateObj){
  288. var m = moment(dateObj);
  289. input.value = m.format(TIMEFORMAT);
  290. },
  291. parseDate: function(input){
  292. var picker = $(input).data('pikaday');
  293. return picker.getDate();
  294. },
  295. updateDate: function(input, dateObj){
  296. var picker = $(input).data('pikaday');
  297. return picker.setDate(dateObj);
  298. }
  299. });
  300. </script>
  301. </article>
  302. <article>
  303. <div class="demo">
  304. <h2>Events Example</h2>
  305. <p>Datepair fires several events to indicate the status of the inputs.</p>
  306. <p id="eventsExample">
  307. <input type="text" class="date start" />
  308. <input type="text" class="time start" /> to
  309. <input type="text" class="time end" />
  310. <input type="text" class="date end" />
  311. </p>
  312. <p id="eventsExampleStatus"></p>
  313. </div>
  314. <pre class="code" data-language="javascript">
  315. // HTML not shown for brevity
  316. // initialize input widgets first
  317. $('#eventsExample .time').timepicker({
  318. 'showDuration': true,
  319. 'timeFormat': 'g:ia'
  320. });
  321. $('#eventsExample .date').datepicker({
  322. 'format': 'm/d/yyyy',
  323. 'autoclose': true
  324. });
  325. var eventsExampleEl = document.getElementById('eventsExample');
  326. var eventsExampleDatepair = new Datepair(eventsExampleEl);
  327. // some sample handlers
  328. $('#eventsExample').on('rangeSelected', function(){
  329. $('#eventsExampleStatus').text('Valid range selected');
  330. }).on('rangeIncomplete', function(){
  331. $('#eventsExampleStatus').text('Incomplete range');
  332. }).on('rangeError', function(){
  333. $('#eventsExampleStatus').text('Invalid range');
  334. });
  335. </pre>
  336. <script>
  337. $('#eventsExample .time').timepicker({
  338. 'showDuration': true,
  339. 'timeFormat': 'g:ia'
  340. });
  341. $('#eventsExample .date').datepicker({
  342. 'format': 'm/d/yyyy',
  343. 'autoclose': true
  344. });
  345. var eventsExampleEl = document.getElementById('eventsExample');
  346. var eventsExampleDatepair = new Datepair(eventsExampleEl);
  347. $('#eventsExample').on('rangeSelected', function(){
  348. $('#eventsExampleStatus').text('Valid range selected');
  349. }).on('rangeIncomplete', function(){
  350. $('#eventsExampleStatus').text('Incomplete range');
  351. }).on('rangeError', function(){
  352. $('#eventsExampleStatus').text('Invalid range');
  353. });
  354. </script>
  355. </article>
  356. <article>
  357. <div class="demo">
  358. <h2>Anchor Example</h2>
  359. <p>Datepair defaults to move the end time/date based on changes to the start time/date. This can be changed to the end inputs, or disabled completely.</p>
  360. <p>Anchor:
  361. <select id="anchorSelect">
  362. <option value="start">Start</option>
  363. <option value="end">End</option>
  364. <option value="">Null</option>
  365. </select>
  366. </p>
  367. <p id="anchorExample">
  368. <input type="text" class="date start" />
  369. <input type="text" class="time start" /> to
  370. <input type="text" class="time end" />
  371. <input type="text" class="date end" />
  372. </p>
  373. </div>
  374. <pre class="code" data-language="javascript">
  375. var anchorExampleEl = document.getElementById('anchorExample');
  376. var anchorDatepair = new Datepair(anchorExampleEl, {
  377. anchor: $('#anchorSelect').val()
  378. });
  379. $('#anchorSelect').on('change', function(){
  380. anchorDatepair.option('anchor', $('#anchorSelect').val());
  381. });
  382. </pre>
  383. <script>
  384. $('#anchorExample .time').timepicker({
  385. 'showDuration': true,
  386. 'timeFormat': 'g:ia'
  387. });
  388. $('#anchorExample .date').datepicker({
  389. 'format': 'm/d/yyyy',
  390. 'autoclose': true
  391. });
  392. var anchorExampleEl = document.getElementById('anchorExample');
  393. var anchorDatepair = new Datepair(anchorExampleEl, {
  394. anchor: $('#anchorSelect').val()
  395. });
  396. $('#anchorSelect').on('change', function(){
  397. anchorDatepair.option('anchor', $('#anchorSelect').val());
  398. });
  399. </script>
  400. </article>
  401. </section>
  402. <section>
  403. <h2>Need Help?</h2>
  404. <p>Check <a href="https://github.com/jonthornton/jquery-datepair#datepair-plugin-for-jquery">the documenation</a> or <a href="https://github.com/jonthornton/jquery-datepair/issues?state=open">submit an issue</a> on GitHub.</p>
  405. </section>
  406. <footer>
  407. <p>&copy; 2014 <a href="http://jonthornton.com">Jon Thornton</a></p>
  408. </footer>
  409. <script>
  410. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  411. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  412. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  413. })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  414. ga('create', 'UA-15605525-4', 'auto');
  415. ga('send', 'pageview');
  416. </script>
  417. </body>
  418. </html>