main.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. (function() {
  2. var $confirm;
  3. $confirm = null;
  4. $(function() {
  5. var $createDestroy, $window, sectionTop;
  6. $window = $(window);
  7. sectionTop = $(".top").outerHeight() + 20;
  8. $createDestroy = $("#switch-create-destroy");
  9. hljs.initHighlightingOnLoad();
  10. $("a[href*=\"#\"]").on("click", function(event) {
  11. var $target;
  12. event.preventDefault();
  13. $target = $($(this).attr("href").slice("#"));
  14. if ($target.length) {
  15. return $window.scrollTop($target.offset().top - sectionTop);
  16. }
  17. });
  18. $("input[type=\"checkbox\"], input[type=\"radio\"]").not("[data-switch-no-init]").bootstrapSwitch();
  19. $("[data-switch-get]").on("click", function() {
  20. var type;
  21. type = $(this).data("switch-get");
  22. return alert($("#switch-" + type).bootstrapSwitch(type));
  23. });
  24. $("[data-switch-set]").on("click", function() {
  25. var type;
  26. type = $(this).data("switch-set");
  27. return $("#switch-" + type).bootstrapSwitch(type, $(this).data("switch-value"));
  28. });
  29. $("[data-switch-toggle]").on("click", function() {
  30. var type;
  31. type = $(this).data("switch-toggle");
  32. return $("#switch-" + type).bootstrapSwitch("toggle" + type.charAt(0).toUpperCase() + type.slice(1));
  33. });
  34. $("[data-switch-set-value]").on("input", function(event) {
  35. var type, value;
  36. event.preventDefault();
  37. type = $(this).data("switch-set-value");
  38. value = $.trim($(this).val());
  39. if ($(this).data("value") === value) {
  40. return;
  41. }
  42. return $("#switch-" + type).bootstrapSwitch(type, value);
  43. });
  44. $("[data-switch-create-destroy]").on("click", function() {
  45. var isSwitch;
  46. isSwitch = $createDestroy.data("bootstrap-switch");
  47. $createDestroy.bootstrapSwitch((isSwitch ? "destroy" : null));
  48. return $(this).button((isSwitch ? "reset" : "destroy"));
  49. });
  50. return $confirm = $("#confirm").bootstrapSwitch({
  51. size: "large",
  52. onSwitchChange: function(event, state) {
  53. event.preventDefault();
  54. return console.log(state, event.isDefaultPrevented());
  55. }
  56. });
  57. });
  58. }).call(this);