plain-css.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>Vanilla JS Datepicker Demo</title>
  7. <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bulma-tooltip@3.0.2/dist/css/bulma-tooltip.min.css">
  8. <link rel="stylesheet" type="text/css" href="../dist/css/datepicker.css">
  9. <script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
  10. <style type="text/css">
  11. pre {
  12. background-color: #f5f5f5;
  13. padding: 1rem;
  14. overflow-x: auto;
  15. }
  16. .section {
  17. padding: 1.5rem;
  18. }
  19. .field {
  20. margin-bottom: 1em;
  21. }
  22. .has-addons {
  23. display: flex;
  24. }
  25. .has-addons .control a {
  26. padding-left: 0.5rem;
  27. padding-right: 0.5rem;
  28. }
  29. .label {
  30. font-weight: 600;
  31. }
  32. aside {
  33. position: fixed;
  34. top: 0;
  35. bottom: 0;
  36. right: -300px;
  37. width: 300px;
  38. overflow: auto;
  39. background-color: #fff;
  40. box-shadow: inset 1px 1px rgba(0, 0, 0, 10%);
  41. transition: right 0.3s;
  42. }
  43. .open aside {
  44. right: 0;
  45. }
  46. aside hr {
  47. margin-top: 0.5rem;
  48. }
  49. .code-wrap {
  50. position: relative;
  51. }
  52. .code-wrap pre:not(.is-active) {
  53. height: 0;
  54. overflow: hidden;
  55. opacity: 0.5;
  56. }
  57. .code-wrap .collapse-button {
  58. position: absolute;
  59. top: 0;
  60. right: 0;
  61. left: auto;
  62. cursor: pointer;
  63. padding: 0.125rem 0.25rem;
  64. font-size: 0.75rem;
  65. }
  66. label.checkbox {
  67. display: inline-block;
  68. }
  69. .help {
  70. margin: 0;
  71. }
  72. .help.is-danger {
  73. color: #f14668;
  74. }
  75. .toggle-btn {
  76. position: fixed;
  77. top: 0.75rem;
  78. right: 0.75rem;
  79. width: 1.5rem;
  80. background-color: #fff;
  81. line-height: 1.5rem;
  82. border: 1px solid rgba(0, 0, 0, 10%);
  83. border-radius: 2px;
  84. box-shadow: 1px 1px rgba(0, 0, 0, 10%);
  85. cursor: pointer;
  86. }
  87. .toggle-btn::before {
  88. content: '\25c0';
  89. padding-left: 0.25rem;
  90. }
  91. .open .toggle-btn::before {
  92. content: '\25b6';
  93. }
  94. .has-background-info {
  95. background-color: cyan;
  96. }
  97. .has-text-success {
  98. color: green;
  99. }
  100. @media (min-width: 481px) {
  101. main {
  102. margin-right: 38.1966%;
  103. }
  104. aside {
  105. right: 0;
  106. width: 38.1966%;
  107. }
  108. .toggle-btn {
  109. display: none;
  110. }
  111. }
  112. </style>
  113. </head>
  114. <body>
  115. <main>
  116. <section class="section container is-fluid">
  117. <div class="columns">
  118. <div class="column">
  119. <p>Vanilla JS Datepicker</p>
  120. <h1 class="title">Demo</h1>
  121. <div id="sandbox"></div>
  122. </div>
  123. </div>
  124. <div class="columns">
  125. <div class="column">
  126. <p><small>Style: <a href="index.html">Bulma</a> | <a href="bs4.html">Bootstrap</a> | <a href="foundation.html">Foundation</a> | <em>Plain CSS</em></small></p>
  127. <p><small>* This page uses <a href="https://wikiki.github.io/elements/tooltip/" target="_blank">bulma-tooltip</a> for tooltips.</small></p>
  128. </div>
  129. </div>
  130. </section>
  131. </main>
  132. <aside>
  133. <section class="section">
  134. <div class="tile is-parent is-vertical">
  135. <div class="tile is-child">
  136. <h4 class="subtitle">Type</h4>
  137. <form id="types">
  138. <div class="field">
  139. <div class="control">
  140. <label class="radio">
  141. <input type="radio" name="type" value="input" checked>
  142. Input
  143. </label>
  144. <label class="radio">
  145. <input type="radio" name="type" value="inline">
  146. Inline
  147. </label>
  148. <label class="radio">
  149. <input type="radio" name="type" value="range">
  150. Range
  151. </label>
  152. </div>
  153. </div>
  154. </form>
  155. </div>
  156. <hr>
  157. <div class="tile is-child">
  158. <h4 class="subtitle">Options</h4>
  159. <form id="options">
  160. <div class="field">
  161. <div class="control tooltip" data-tooltip="Only effective in range picker">
  162. <label class="label checkbox">
  163. <input type="checkbox" name="allowOneSidedRange" value="true">
  164. allowOneSidedRange
  165. </label>
  166. </div>
  167. </div>
  168. <div class="field">
  169. <div class="control">
  170. <label class="label checkbox">
  171. <input type="checkbox" name="autohide" value="true">
  172. autohide
  173. </label>
  174. </div>
  175. </div>
  176. <div class="field">
  177. <div class="control">
  178. <label class="label checkbox">
  179. <input type="checkbox" name="beforeShowDay" value="true">
  180. beforeShowDay
  181. </label>
  182. </div>
  183. <div class="code-wrap">
  184. <pre id="code-beforeShowDay"></pre>
  185. <div class="collapse-button" data-target="code-beforeShowDay">show/hide</div>
  186. </div>
  187. </div>
  188. <div class="field">
  189. <div class="control">
  190. <label class="label checkbox">
  191. <input type="checkbox" name="beforeShowMonth" value="true">
  192. beforeShowMonth
  193. </label>
  194. </div>
  195. <div class="code-wrap">
  196. <pre id="code-beforeShowMonth"></pre>
  197. <div class="collapse-button" data-target="code-beforeShowMonth">show/hide</div>
  198. </div>
  199. </div>
  200. <div class="field">
  201. <div class="control">
  202. <label class="label checkbox">
  203. <input type="checkbox" name="beforeShowYear" value="true">
  204. beforeShowYear
  205. </label>
  206. </div>
  207. <div class="code-wrap">
  208. <pre id="code-beforeShowYear"></pre>
  209. <div class="collapse-button" data-target="code-beforeShowYear">show/hide</div>
  210. </div>
  211. </div>
  212. <div class="field">
  213. <div class="control">
  214. <label class="label checkbox">
  215. <input type="checkbox" name="beforeShowDecade" value="true">
  216. beforeShowDecade
  217. </label>
  218. </div>
  219. <div class="code-wrap">
  220. <pre id="code-beforeShowDecade"></pre>
  221. <div class="collapse-button" data-target="code-beforeShowDecade">show/hide</div>
  222. </div>
  223. </div>
  224. <div class="field">
  225. <div class="control">
  226. <label class="label checkbox">
  227. <input type="checkbox" name="calendarWeeks" value="true">
  228. calendarWeeks
  229. </label>
  230. </div>
  231. </div>
  232. <div class="field">
  233. <div class="control">
  234. <label class="label checkbox">
  235. <input type="checkbox" name="clearBtn" value="true">
  236. clearBtn
  237. </label>
  238. </div>
  239. </div>
  240. <div class="field">
  241. <label class="label">dateDelimiter</label>
  242. <div class="control">
  243. <input type="text" class="input" name="dateDelimiter" placeholder=",">
  244. </div>
  245. </div>
  246. <div class="field">
  247. <label class="label">datesDisabled</label>
  248. <div class="control tooltip" data-tooltip="enter in JSON format">
  249. <textarea class="input" name="datesDisabled" placeholder="[]"></textarea>
  250. </div>
  251. </div>
  252. <div class="field">
  253. <label class="label">daysOfWeekDisabled</label>
  254. <div class="control">
  255. <label class="checkbox">
  256. <input type="checkbox" name="daysOfWeekDisabled" value="0"> 0
  257. </label>&nbsp;
  258. <label class="checkbox">
  259. <input type="checkbox" name="daysOfWeekDisabled" value="1"> 1
  260. </label>&nbsp;
  261. <label class="checkbox">
  262. <input type="checkbox" name="daysOfWeekDisabled" value="2"> 2
  263. </label>&nbsp;
  264. <label class="checkbox">
  265. <input type="checkbox" name="daysOfWeekDisabled" value="3"> 3
  266. </label>&nbsp;
  267. <label class="checkbox">
  268. <input type="checkbox" name="daysOfWeekDisabled" value="4"> 4
  269. </label>&nbsp;
  270. <label class="checkbox">
  271. <input type="checkbox" name="daysOfWeekDisabled" value="5"> 5
  272. </label>&nbsp;
  273. <label class="checkbox">
  274. <input type="checkbox" name="daysOfWeekDisabled" value="6"> 6
  275. </label>&nbsp;
  276. </div>
  277. </div>
  278. <div class="field">
  279. <label class="label">daysOfWeekHighlighted</label>
  280. <div class="control">
  281. <label class="checkbox">
  282. <input type="checkbox" name="daysOfWeekHighlighted" value="0"> 0
  283. </label>&nbsp;
  284. <label class="checkbox">
  285. <input type="checkbox" name="daysOfWeekHighlighted" value="1"> 1
  286. </label>&nbsp;
  287. <label class="checkbox">
  288. <input type="checkbox" name="daysOfWeekHighlighted" value="2"> 2
  289. </label>&nbsp;
  290. <label class="checkbox">
  291. <input type="checkbox" name="daysOfWeekHighlighted" value="3"> 3
  292. </label>&nbsp;
  293. <label class="checkbox">
  294. <input type="checkbox" name="daysOfWeekHighlighted" value="4"> 4
  295. </label>&nbsp;
  296. <label class="checkbox">
  297. <input type="checkbox" name="daysOfWeekHighlighted" value="5"> 5
  298. </label>&nbsp;
  299. <label class="checkbox">
  300. <input type="checkbox" name="daysOfWeekHighlighted" value="6"> 6
  301. </label>&nbsp;
  302. </div>
  303. </div>
  304. <div class="field">
  305. <label class="label">defaultViewDate</label>
  306. <div class="control">
  307. <input type="text" class="input" name="defaultViewDate" placeholder="today">
  308. </div>
  309. </div>
  310. <div class="field">
  311. <div class="control">
  312. <label class="label checkbox">
  313. <input type="checkbox" name="disableTouchKeyboard" value="true">
  314. disableTouchKeyboard
  315. </label>
  316. </div>
  317. </div>
  318. <div class="field">
  319. <label class="label">format</label>
  320. <div class="control">
  321. <input type="text" class="input" name="format" placeholder="mm/dd/yyyy">
  322. </div>
  323. </div>
  324. <div class="field">
  325. <label class="label">language</label>
  326. <div class="control">
  327. <div class="select">
  328. <select name="language" >
  329. <option value="en">en – English (US)</option>
  330. </select>
  331. </div>
  332. </div>
  333. </div>
  334. <div class="field">
  335. <label class="label">maxDate</label>
  336. <div class="control">
  337. <input type="text" class="input" name="maxDate" placeholder="null">
  338. </div>
  339. </div>
  340. <div class="field">
  341. <label class="label">maxNumberOfDates</label>
  342. <div class="control tooltip" data-tooltip="Not effective in range picker">
  343. <input type="text" class="input" name="maxNumberOfDates" placeholder="1">
  344. </div>
  345. </div>
  346. <div class="field">
  347. <label class="label">maxView</label>
  348. <div class="control">
  349. <div class="select">
  350. <select name="maxView">
  351. <option value="0">0 – days</option>
  352. <option value="1">1 – months</option>
  353. <option value="2">2 – years</option>
  354. <option value="3" selected>3 – decades</option>
  355. </select>
  356. </div>
  357. </div>
  358. </div>
  359. <div class="field">
  360. <label class="label">minDate</label>
  361. <div class="control">
  362. <input type="text" class="input" name="minDate" placeholder="null">
  363. </div>
  364. </div>
  365. <div class="field">
  366. <label class="label">nextArrow</label>
  367. <div class="control">
  368. <textarea class="input" name="nextArrow" placeholder="»"></textarea>
  369. </div>
  370. </div>
  371. <div class="field">
  372. <label class="label">orientation</label>
  373. <div class="control">
  374. <div class="select">
  375. <select name="orientation" >
  376. <option value="auto">auto</option>
  377. <option value="top auto">top auto</option>
  378. <option value="bottom auto">bottom auto</option>
  379. <option value="auto left">auto left</option>
  380. <option value="top left">top left</option>
  381. <option value="bottom left">bottom left</option>
  382. <option value="auto right">auto right</option>
  383. <option value="top right">top right</option>
  384. <option value="bottom right">bottom right</option>
  385. </select>
  386. </div>
  387. </div>
  388. </div>
  389. <div class="field">
  390. <label class="label">pickLevel</label>
  391. <div class="control">
  392. <div class="select">
  393. <select name="pickLevel">
  394. <option value="0">0 – date</option>
  395. <option value="1">1 – month</option>
  396. <option value="2">2 – year</option>
  397. </select>
  398. </div>
  399. </div>
  400. </div>
  401. <div class="field">
  402. <label class="label">prevArrow</label>
  403. <div class="control">
  404. <textarea class="input" name="prevArrow" placeholder="«"></textarea>
  405. </div>
  406. </div>
  407. <div class="field">
  408. <div class="control">
  409. <label class="label checkbox">
  410. <input type="checkbox" name="showDaysOfWeek" value="true" checked>
  411. showDaysOfWeek
  412. </label>
  413. </div>
  414. </div>
  415. <div class="field">
  416. <div class="control">
  417. <label class="label checkbox">
  418. <input type="checkbox" name="showOnClick" value="true" checked>
  419. showOnClick
  420. </label>
  421. </div>
  422. </div>
  423. <div class="field">
  424. <div class="control">
  425. <label class="label checkbox">
  426. <input type="checkbox" name="showOnFocus" value="true" checked>
  427. showOnFocus
  428. </label>
  429. </div>
  430. </div>
  431. <div class="field">
  432. <label class="label">startView</label>
  433. <div class="control">
  434. <div class="select">
  435. <select name="startView">
  436. <option value="0">0 – days</option>
  437. <option value="1">1 – months</option>
  438. <option value="2">2 – years</option>
  439. <option value="3">3 – decades</option>
  440. </select>
  441. </div>
  442. </div>
  443. </div>
  444. <div class="field">
  445. <label class="label">title</label>
  446. <div class="control">
  447. <input type="text" class="input" name="title">
  448. </div>
  449. </div>
  450. <div class="field">
  451. <div class="control">
  452. <label class="label checkbox">
  453. <input type="checkbox" name="todayBtn" value="true">
  454. todayBtn
  455. </label>
  456. </div>
  457. </div>
  458. <div class="field">
  459. <label class="label">todayBtnMode</label>
  460. <div class="control">
  461. <div class="select">
  462. <select name="todayBtnMode">
  463. <option value="0">0 – focus</option>
  464. <option value="1">1 – select</option>
  465. </select>
  466. </div>
  467. </div>
  468. </div>
  469. <div class="field">
  470. <div class="control">
  471. <label class="label checkbox">
  472. <input type="checkbox" name="todayHighlight" value="true">
  473. todayHighlight
  474. </label>
  475. </div>
  476. </div>
  477. <div class="field">
  478. <div class="control">
  479. <label class="label checkbox">
  480. <input type="checkbox" name="updateOnBlur" value="true" checked>
  481. updateOnBlur
  482. </label>
  483. </div>
  484. </div>
  485. <div class="field">
  486. <label class="label">weekStart</label>
  487. <div class="control">
  488. <input type="text" class="input" name="weekStart" placeholder="0">
  489. </div>
  490. </div>
  491. </form>
  492. </div>
  493. <hr>
  494. <div class="tile is-child">
  495. <h4 class="subtitle">Text direction</h4>
  496. <form id="direction">
  497. <div class="field">
  498. <div class="control">
  499. <label class="radio">
  500. <input type="radio" name="direction" value="ltr" checked>
  501. LTR
  502. </label>
  503. <label class="radio">
  504. <input type="radio" name="direction" value="rtl">
  505. RTL
  506. </label>
  507. </div>
  508. </div>
  509. </form>
  510. </div>
  511. </div>
  512. </section>
  513. </aside>
  514. <div class="toggle-btn"></div>
  515. <script src="../dist/js/datepicker-full.js"></script>
  516. <script src="./live-demo.js"></script>
  517. <script>
  518. /*global initialize onChangeType onChnageDirection onChangeInputOption onChangeInputOption onChangeTextareaOption onClickCheckboxOptions switchPicker */
  519. initialize();
  520. document.getElementById('types').querySelectorAll('input').forEach((el) => {
  521. el.addEventListener('change', onChangeType);
  522. });
  523. document.getElementById('direction').querySelectorAll('input').forEach((el) => {
  524. el.addEventListener('change', onChnageDirection);
  525. });
  526. const optsForm = document.getElementById('options');
  527. optsForm.querySelectorAll('input[type=text], input[type=radio], select').forEach((el) => {
  528. el.addEventListener('change', onChangeInputOption);
  529. });
  530. optsForm.querySelectorAll('textarea').forEach((el) => {
  531. el.addEventListener('change', onChangeTextareaOption);
  532. });
  533. optsForm.querySelectorAll('.checkbox').forEach((el) => {
  534. el.addEventListener('click', onClickCheckboxOptions);
  535. });
  536. switchPicker('input');
  537. </script>
  538. </body>
  539. </html>