main.js 2.0 KB

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