main.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. $(function() {
  2. var $window = $(window);
  3. var sectionTop = $('.top').outerHeight() + 20;
  4. // initialize highlight.js
  5. hljs.initHighlightingOnLoad();
  6. // navigation
  7. $('a[href*="#"]').on('click', function(event) {
  8. event.preventDefault();
  9. var $target = $($(this).attr('href').slice('#'));
  10. if ($target.length) {
  11. $window.scrollTop($target.offset().top - sectionTop);
  12. }
  13. });
  14. // download switch
  15. $('input[name="download-version"]').on({
  16. 'init.bootstrapSwitch': function() {
  17. $('#download-' + ($(this).is(':checked') ? '2' : '3')).hide();
  18. },
  19. 'switchChange.bootstrapSwitch': function(event, state) {
  20. $('#download-3')[state ? 'show' : 'hide']();
  21. $('#download-2')[state ? 'hide' : 'show']();
  22. }
  23. });
  24. // initialize all the inputs
  25. $('input[type="checkbox"],[type="radio"]')
  26. .not('#create-switch')
  27. .not('#events-switch')
  28. .not('#switch-modal')
  29. .bootstrapSwitch();
  30. $('[data-get]').on("click", function() {
  31. var type = $(this).data('get');
  32. alert($('#switch-' + type).bootstrapSwitch(type));
  33. });
  34. $('[data-set]').on('click', function() {
  35. var type = $(this).data('set');
  36. $('#switch-' + type).bootstrapSwitch(type, $(this).data('value'));
  37. });
  38. $('[data-toggle]').on('click', function() {
  39. var type = $(this).data('toggle');
  40. $('#switch-' + type).bootstrapSwitch('toggle' + type.charAt(0).toUpperCase() + type.slice(1));
  41. });
  42. $('[data-set-value]').on('input', function(event) {
  43. event.preventDefault();
  44. var type = $(this).data('set-value');
  45. var value = $.trim($(this).val());
  46. if ($(this).data('value') == value) {
  47. return;
  48. }
  49. $('#switch-' + type).bootstrapSwitch(type, value);
  50. });
  51. $('#modal-switch')
  52. .on("shown.bs.modal", function() {
  53. $('#switch-modal').bootstrapSwitch();
  54. })
  55. .on("hidden.bs.modal", function() {
  56. $('#switch-modal').bootstrapSwitch('destroy');
  57. });
  58. });