main.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. // initialize all the inputs
  16. $('input[type="checkbox"], input[type="radio"]')
  17. .not("[data-switch-no-init]")
  18. .bootstrapSwitch();
  19. $('[data-switch-get]').on("click", function() {
  20. var type = $(this).data('switch-get');
  21. alert($('#switch-' + type).bootstrapSwitch(type));
  22. });
  23. $('[data-switch-set]').on('click', function() {
  24. var type = $(this).data('switch-set');
  25. $('#switch-' + type).bootstrapSwitch(type, $(this).data('switch-value'));
  26. });
  27. $('[data-switch-toggle]').on('click', function() {
  28. var type = $(this).data('switch-toggle');
  29. $('#switch-' + type).bootstrapSwitch('toggle' + type.charAt(0).toUpperCase() + type.slice(1));
  30. });
  31. $('[data-switch-set-value]').on('input', function(event) {
  32. event.preventDefault();
  33. var type = $(this).data('switch-set-value');
  34. var value = $.trim($(this).val());
  35. if ($(this).data('value') == value) {
  36. return;
  37. }
  38. $('#switch-' + type).bootstrapSwitch(type, value);
  39. });
  40. $('[data-switch-create-destroy]').on('click', function() {
  41. var isSwitch = $createDestroy.data('bootstrap-switch');
  42. $createDestroy.bootstrapSwitch(isSwitch ? 'destroy' : null);
  43. $(this).button(isSwitch ? 'reset' : 'destroy');
  44. });
  45. });