website.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. $(document).ready(function() {
  2. $('#config-text').keyup(function() {
  3. eval($(this).val());
  4. });
  5. $('.configurator input, .configurator select').change(function() {
  6. updateConfig();
  7. });
  8. $('.demo i').click(function() {
  9. $(this).parent().find('input').click();
  10. });
  11. $('#startDate').daterangepicker({
  12. singleDatePicker: true,
  13. startDate: moment().subtract(6, 'days')
  14. });
  15. $('#endDate').daterangepicker({
  16. singleDatePicker: true,
  17. startDate: moment()
  18. });
  19. updateConfig();
  20. function updateConfig() {
  21. var options = {};
  22. if ($('#singleDatePicker').is(':checked'))
  23. options.singleDatePicker = true;
  24. if ($('#showDropdowns').is(':checked'))
  25. options.showDropdowns = true;
  26. if ($('#showWeekNumbers').is(':checked'))
  27. options.showWeekNumbers = true;
  28. if ($('#showISOWeekNumbers').is(':checked'))
  29. options.showISOWeekNumbers = true;
  30. if ($('#timePicker').is(':checked'))
  31. options.timePicker = true;
  32. if ($('#timePicker24Hour').is(':checked'))
  33. options.timePicker24Hour = true;
  34. if ($('#timePickerIncrement').val().length && $('#timePickerIncrement').val() != 1)
  35. options.timePickerIncrement = parseInt($('#timePickerIncrement').val(), 10);
  36. if ($('#timePickerSeconds').is(':checked'))
  37. options.timePickerSeconds = true;
  38. if ($('#autoApply').is(':checked'))
  39. options.autoApply = true;
  40. if ($('#dateLimit').is(':checked'))
  41. options.dateLimit = { days: 7 };
  42. if ($('#ranges').is(':checked')) {
  43. options.ranges = {
  44. 'Today': [moment(), moment()],
  45. 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  46. 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
  47. 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
  48. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  49. 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  50. };
  51. }
  52. if ($('#locale').is(':checked')) {
  53. options.locale = {
  54. format: 'MM/DD/YYYY',
  55. separator: ' - ',
  56. applyLabel: 'Apply',
  57. cancelLabel: 'Cancel',
  58. fromLabel: 'From',
  59. toLabel: 'To',
  60. customRangeLabel: 'Custom',
  61. weekLabel: 'W',
  62. daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr','Sa'],
  63. monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  64. firstDay: 1
  65. };
  66. }
  67. if (!$('#linkedCalendars').is(':checked'))
  68. options.linkedCalendars = false;
  69. if (!$('#autoUpdateInput').is(':checked'))
  70. options.autoUpdateInput = false;
  71. if (!$('#showCustomRangeLabel').is(':checked'))
  72. options.showCustomRangeLabel = false;
  73. if ($('#alwaysShowCalendars').is(':checked'))
  74. options.alwaysShowCalendars = true;
  75. if ($('#parentEl').val().length)
  76. options.parentEl = $('#parentEl').val();
  77. if ($('#startDate').val().length)
  78. options.startDate = $('#startDate').val();
  79. if ($('#endDate').val().length)
  80. options.endDate = $('#endDate').val();
  81. if ($('#minDate').val().length)
  82. options.minDate = $('#minDate').val();
  83. if ($('#maxDate').val().length)
  84. options.maxDate = $('#maxDate').val();
  85. if ($('#opens').val().length && $('#opens').val() != 'right')
  86. options.opens = $('#opens').val();
  87. if ($('#drops').val().length && $('#drops').val() != 'down')
  88. options.drops = $('#drops').val();
  89. if ($('#buttonClasses').val().length && $('#buttonClasses').val() != 'btn btn-sm')
  90. options.buttonClasses = $('#buttonClasses').val();
  91. if ($('#applyClass').val().length && $('#applyClass').val() != 'btn-success')
  92. options.applyClass = $('#applyClass').val();
  93. if ($('#cancelClass').val().length && $('#cancelClass').val() != 'btn-default')
  94. options.cancelClass = $('#cancelClass').val();
  95. $('#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});");
  96. $('#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 + ')'); });
  97. }
  98. if ($(window).width() > 980) {
  99. $('#sidebar').affix({
  100. offset: {
  101. top: 300,
  102. bottom: function () {
  103. return (this.bottom = $('.footer').outerHeight(true))
  104. }
  105. }
  106. });
  107. }
  108. $('body').scrollspy({ target: '#nav-spy', offset: 20 });
  109. });