]> BookStack Code Mirror - bookstack/blobdiff - resources/views/components/toggle-switch.blade.php
Finished migration of last angular code
[bookstack] / resources / views / components / toggle-switch.blade.php
index b20b74d5ec90d17a8462610894a8db1013c78b72..ad54d5ab1f965eef8f435e66098c3abab5684f68 100644 (file)
@@ -1,4 +1,15 @@
-<div toggle-switch class="toggle-switch @if($value) active @endif">
+<div toggle-switch="{{$name}}" class="toggle-switch @if($value) active @endif">
     <input type="hidden" name="{{$name}}" value="{{$value?'true':'false'}}"/>
     <div class="switch-handle"></div>
-</div>
\ No newline at end of file
+</div>
+<script>
+    (function() {
+       var toggle = document.querySelector('[toggle-switch="{{$name}}"]');
+       var toggleInput = toggle.querySelector('input');
+       toggle.onclick = function(event) {
+           var checked = toggleInput.value !== 'true';
+           toggleInput.value = checked ? 'true' : 'false';
+           checked ? toggle.classList.add('active') : toggle.classList.remove('active');
+       };
+    })()
+</script>
\ No newline at end of file