scripts.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. $(function() {
  2. // Toggle visibility of navigation
  3. $('.toggle-sidebar').on('click', function() {
  4. $('body').toggleClass('sidebar-open');
  5. return false;
  6. });
  7. // Hack to get error styles right for Bootstrap
  8. $('.field_with_errors').parents('.form-group').addClass('has-error');
  9. // Setup datepicker (jQuery UI)
  10. $('.datepicker').datepicker({ dateFormat: 'yy-mm-dd' });
  11. // If having problems with multiple `.datepicker` or `.datetimepicker` elements on a single page,
  12. // be sure that each input element has a unique id. This can be done by namespacing each `form_for`
  13. // Example: `form_for(record, namespace: record.id)`
  14. // Setup datetimepicker (extends datepicker)
  15. $('.datetimepicker').datetimepicker({
  16. dateFormat: 'yy-mm-dd',
  17. timeFormat: 'h:mmtt', // e.g. "9:40am" This must *exactly* match format of datetime field output,
  18. // but DO NOT COPY/PASTE from or into Ruby, as Ruby & JS use different
  19. // syntax for datetime string formatting!
  20. oneLine: true // Try to render time selects (hour, minute) on a single line
  21. });
  22. // Select the appropriate tab on page load
  23. var hash = window.location.hash;
  24. if (hash) {
  25. $('a[href="'+ hash +'"]').tab('show');
  26. } else {
  27. // Select the first tab in the group
  28. $('.nav-tabs').find('li:first a').tab('show');
  29. // Select a tab with errors inside, if it exists
  30. $('[href="#' + $('.tab-pane:has(.field_with_errors)').attr('id') + '"]').tab('show');
  31. }
  32. //
  33. // Use 'Chosen' jQuery plugin to give extra functionality to selects
  34. //
  35. function initChosen() {
  36. $(".chosen-select").each(function() {
  37. var item = $(this);
  38. item.chosen({
  39. allow_single_deselect: true,
  40. disable_search_threshold: 0, // on single select, disables search if fewer than X options in select
  41. no_results_text: 'No options match', // displayed (with "<current_string>" appended) when no options match
  42. placeholder_text_single: 'Select from list',
  43. placeholder_text_multiple: 'Select one or more options',
  44. search_contains: true, // matches any substring, instead of matching only from beginning of word(s)
  45. width: '100%',
  46. max_selected_options: parseInt(item.attr('data-max-selected-options'))
  47. });
  48. });
  49. };
  50. $(document).ready(function(){
  51. initChosen();
  52. });
  53. $(document).ajaxComplete(function(){
  54. initChosen();
  55. });
  56. //
  57. // AJAX forms
  58. //
  59. $(document).on('submit', '[data-remote="true"]', function() {
  60. $('.processing').slideDown(200);
  61. })
  62. $('.processing').hide();
  63. //
  64. //// Search Form Advanced Options
  65. //
  66. $('.advanced-toggle').click(function() {
  67. $(this).closest('form.search').toggleClass('advanced-active');
  68. });
  69. });
  70. $(document).ready(function(){
  71. $(".color-picker").colorPicker({
  72. colors: ['#4C97B1','#3169D1','#271F90','#5C259A','#842959','#BB1907','#BE3D0F','#C16F1C','#C48922','#F2D435','#D0C837','#829B40'],
  73. rowitem: 4,
  74. onSelect: function(ui, color){
  75. ui.closest(".color-picker").val(color).css('background-color', color).css('color', color);
  76. }
  77. });
  78. });