Emanuele 8 rokov pred
rodič
commit
a1f4b4dd13
2 zmenil súbory, kde vykonal 58 pridanie a 50 odobranie
  1. 0 50
      src/docs/coffee/main.coffee
  2. 58 0
      src/docs/js/main.js

+ 0 - 50
src/docs/coffee/main.coffee

@@ -1,50 +0,0 @@
-$confirm = null
-
-$ ->
-  $window = $(window)
-  sectionTop = $(".top").outerHeight() + 20
-  $createDestroy = $("#switch-create-destroy")
-
-  # initialize highlight.js
-  hljs.initHighlightingOnLoad()
-
-  # navigation
-  $("a[href*=\"#\"]").on "click", (event) ->
-    event.preventDefault()
-    $target = $($(this).attr("href").slice("#"))
-    $window.scrollTop $target.offset().top - sectionTop  if $target.length
-
-
-  # initialize all the inputs
-  $("input[type=\"checkbox\"], input[type=\"radio\"]").not("[data-switch-no-init]").bootstrapSwitch()
-  $("[data-switch-get]").on "click", ->
-    type = $(this).data("switch-get")
-    alert $("#switch-" + type).bootstrapSwitch(type)
-
-  $("[data-switch-set]").on "click", ->
-    type = $(this).data("switch-set")
-    $("#switch-" + type).bootstrapSwitch type, $(this).data("switch-value")
-
-  $("[data-switch-toggle]").on "click", ->
-    type = $(this).data("switch-toggle")
-    $("#switch-" + type).bootstrapSwitch "toggle" + type.charAt(0).toUpperCase() + type.slice(1)
-
-  $("[data-switch-set-value]").on "input", (event) ->
-    event.preventDefault()
-    type = $(this).data("switch-set-value")
-    value = $.trim($(this).val())
-
-    return  if $(this).data("value") is value
-    $("#switch-" + type).bootstrapSwitch type, value
-
-  $("[data-switch-create-destroy]").on "click", ->
-    isSwitch = $createDestroy.data("bootstrap-switch")
-
-    $createDestroy.bootstrapSwitch (if isSwitch then "destroy" else null)
-    $(this).button (if isSwitch then "reset" else "destroy")
-
-  $confirm = $("#confirm").bootstrapSwitch
-    size: "large"
-    onSwitchChange: (event, state) ->
-      event.preventDefault()
-      console.log state, event.isDefaultPrevented()

+ 58 - 0
src/docs/js/main.js

@@ -0,0 +1,58 @@
+const $ = window.Jquery
+
+const $window = $(window)
+const sectionTop = $('.top').outerHeight() + 20
+const $createDestroy = $('#switch-create-destroy')
+
+function capitalize (string) {
+  return string.charAt(0).toUpperCase() + string.slice(1)
+}
+
+window.hljs.initHighlightingOnLoad()
+$('a[href*=\'#\']').on('click', function (event) {
+  event.preventDefault()
+  const $target = $($(this).attr('href').slice('#'))
+  if ($target.length) {
+    $window.scrollTop($target.offset().top - sectionTop)
+  }
+})
+$('input[type="checkbox"], input[type="radio"]')
+  .not('[data-switch-no-init]')
+  .bootstrapSwitch()
+
+$('[data-switch-get]').on('click', function () {
+  const type = $(this).data('switch-get')
+  window.alert($(`#switch-${type}`).bootstrapSwitch(type))
+})
+$('[data-switch-set]').on('click', function () {
+  var type
+  type = $(this).data('switch-set')
+  $(`#switch-${type}`).bootstrapSwitch(type, $(this).data('switch-value'))
+})
+$('[data-switch-toggle]').on('click', function () {
+  const type = $(this).data('switch-toggle')
+  $(`#switch-${type}`).bootstrapSwitch(`toggle${capitalize(type)}`)
+})
+$('[data-switch-set-value]').on('input', function (event) {
+  var type, value
+  event.preventDefault()
+  type = $(this).data('switch-set-value')
+  value = $.trim($(this).val())
+  if ($(this).data('value') === value) {
+    return
+  }
+  $(`#switch-${type}`).bootstrapSwitch(type, value)
+})
+$('[data-switch-create-destroy]').on('click', function () {
+  var isSwitch
+  isSwitch = $createDestroy.data('bootstrap-switch')
+  $createDestroy.bootstrapSwitch((isSwitch ? 'destroy' : null))
+  $(this).button((isSwitch ? 'reset' : 'destroy'))
+})
+$('#confirm').bootstrapSwitch({
+  size: 'large',
+  onSwitchChange: function (event, state) {
+    event.preventDefault()
+    return console.log(state, event.isDefaultPrevented())
+  }
+})