main.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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"]').not('#create-switch').not('#events-switch').bootstrapSwitch();
  26. $('[data-get]').on("click", function() {
  27. var type = $(this).data('get');
  28. alert($('#switch-' + type).bootstrapSwitch(type));
  29. });
  30. $('[data-set]').on('click', function() {
  31. var type = $(this).data('set');
  32. $('#switch-' + type).bootstrapSwitch(type, $(this).data('value'));
  33. });
  34. $('[data-toggle]').on('click', function() {
  35. var type = $(this).data('toggle');
  36. $('#switch-' + type).bootstrapSwitch('toggle' + type.charAt(0).toUpperCase() + type.slice(1));
  37. });
  38. $('[data-set-text]').on('change', function(event) {
  39. event.preventDefault();
  40. var type = $(this).data('set-text');
  41. var value = $.trim($(this).val());
  42. if ( ! value) {
  43. return;
  44. }
  45. $('#switch-' + type).bootstrapSwitch(type, value);
  46. });
  47. });