mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-07 23:03:00 +03:00
Converted toggle switch into a blade/jquery template
This commit is contained in:
@@ -4,36 +4,6 @@ import markdown from "marked";
|
||||
|
||||
export default function (ngApp, events) {
|
||||
|
||||
/**
|
||||
* Toggle Switches
|
||||
* Has basic on/off functionality.
|
||||
* Use string values of 'true' & 'false' to dictate the current state.
|
||||
*/
|
||||
ngApp.directive('toggleSwitch', function () {
|
||||
return {
|
||||
restrict: 'A',
|
||||
template: `
|
||||
<div class="toggle-switch" ng-click="switch()" ng-class="{'active': isActive}">
|
||||
<input type="hidden" ng-attr-name="{{name}}" ng-attr-value="{{value}}"/>
|
||||
<div class="switch-handle"></div>
|
||||
</div>
|
||||
`,
|
||||
scope: true,
|
||||
link: function (scope, element, attrs) {
|
||||
scope.name = attrs.name;
|
||||
scope.value = attrs.value;
|
||||
scope.isActive = scope.value == true && scope.value != 'false';
|
||||
scope.value = (scope.value == true && scope.value != 'false') ? 'true' : 'false';
|
||||
|
||||
scope.switch = function () {
|
||||
scope.isActive = !scope.isActive;
|
||||
scope.value = scope.isActive ? 'true' : 'false';
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
/**
|
||||
* Common tab controls using simple jQuery functions.
|
||||
*/
|
||||
|
@@ -149,6 +149,18 @@ $(function () {
|
||||
window.open($(this).attr('href'));
|
||||
});
|
||||
|
||||
// Toggle Switches
|
||||
let $switches = $('[toggle-switch]');
|
||||
if ($switches.length > 0) {
|
||||
$switches.click(event => {
|
||||
let $switch = $(event.target);
|
||||
let input = $switch.find('input').first()[0];
|
||||
let checked = input.value !== 'true';
|
||||
input.value = checked ? 'true' : 'false';
|
||||
$switch.toggleClass('active', checked);
|
||||
});
|
||||
}
|
||||
|
||||
// Detect IE for css
|
||||
if(navigator.userAgent.indexOf('MSIE')!==-1
|
||||
|| navigator.appVersion.indexOf('Trident/') > 0
|
||||
|
Reference in New Issue
Block a user