main.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. requirejs.config({
  2. "paths": {
  3. "jquery": "https://code.jquery.com/jquery-1.11.3.min",
  4. "moment": "../../moment",
  5. "daterangepicker": "../../daterangepicker"
  6. }
  7. });
  8. requirejs(['jquery', 'moment', 'daterangepicker'] , function ($, moment) {
  9. $(document).ready(function() {
  10. $('#config-text').keyup(function() {
  11. eval($(this).val());
  12. });
  13. $('.configurator input, .configurator select').change(function() {
  14. updateConfig();
  15. });
  16. $('.demo i').click(function() {
  17. $(this).parent().find('input').click();
  18. });
  19. $('#startDate').daterangepicker({
  20. singleDatePicker: true,
  21. startDate: moment().subtract(6, 'days')
  22. });
  23. $('#endDate').daterangepicker({
  24. singleDatePicker: true,
  25. startDate: moment()
  26. });
  27. updateConfig();
  28. function updateConfig() {
  29. var options = {};
  30. if ($('#singleDatePicker').is(':checked'))
  31. options.singleDatePicker = true;
  32. if ($('#showDropdowns').is(':checked'))
  33. options.showDropdowns = true;
  34. if ($('#showWeekNumbers').is(':checked'))
  35. options.showWeekNumbers = true;
  36. if ($('#showISOWeekNumbers').is(':checked'))
  37. options.showISOWeekNumbers = true;
  38. if ($('#timePicker').is(':checked'))
  39. options.timePicker = true;
  40. if ($('#timePicker24Hour').is(':checked'))
  41. options.timePicker24Hour = true;
  42. if ($('#timePickerIncrement').val().length && $('#timePickerIncrement').val() != 1)
  43. options.timePickerIncrement = parseInt($('#timePickerIncrement').val(), 10);
  44. if ($('#timePickerSeconds').is(':checked'))
  45. options.timePickerSeconds = true;
  46. if ($('#autoApply').is(':checked'))
  47. options.autoApply = true;
  48. if ($('#dateLimit').is(':checked'))
  49. options.dateLimit = { days: 7 };
  50. if ($('#ranges').is(':checked')) {
  51. options.ranges = {
  52. 'Today': [moment(), moment()],
  53. 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  54. 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
  55. 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
  56. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  57. 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  58. };
  59. }
  60. if ($('#locale').is(':checked')) {
  61. options.locale = {
  62. format: 'MM/DD/YYYY HH:mm',
  63. separator: ' - ',
  64. applyLabel: 'Apply',
  65. cancelLabel: 'Cancel',
  66. fromLabel: 'From',
  67. toLabel: 'To',
  68. customRangeLabel: 'Custom',
  69. daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr','Sa'],
  70. monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  71. firstDay: 1
  72. };
  73. }
  74. if (!$('#linkedCalendars').is(':checked'))
  75. options.linkedCalendars = false;
  76. if (!$('#autoUpdateInput').is(':checked'))
  77. options.autoUpdateInput = false;
  78. if ($('#alwaysShowCalendars').is(':checked'))
  79. options.alwaysShowCalendars = true;
  80. if ($('#parentEl').val().length)
  81. options.parentEl = $('#parentEl').val();
  82. if ($('#startDate').val().length)
  83. options.startDate = $('#startDate').val();
  84. if ($('#endDate').val().length)
  85. options.endDate = $('#endDate').val();
  86. if ($('#minDate').val().length)
  87. options.minDate = $('#minDate').val();
  88. if ($('#maxDate').val().length)
  89. options.maxDate = $('#maxDate').val();
  90. if ($('#opens').val().length && $('#opens').val() != 'right')
  91. options.opens = $('#opens').val();
  92. if ($('#drops').val().length && $('#drops').val() != 'down')
  93. options.drops = $('#drops').val();
  94. if ($('#buttonClasses').val().length && $('#buttonClasses').val() != 'btn btn-sm')
  95. options.buttonClasses = $('#buttonClasses').val();
  96. if ($('#applyClass').val().length && $('#applyClass').val() != 'btn-success')
  97. options.applyClass = $('#applyClass').val();
  98. if ($('#cancelClass').val().length && $('#cancelClass').val() != 'btn-default')
  99. options.cancelClass = $('#cancelClass').val();
  100. $('#config-text').val("$('#demo').daterangepicker(" + JSON.stringify(options, null, ' ') + ", function(start, end, label) {\n console.log(\"New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')\");\n});");
  101. $('#config-demo').daterangepicker(options, function(start, end, label) { console.log('New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')'); });
  102. }
  103. });
  104. });