2021-01-26 18:46:30 +08:00
|
|
|
|
import 'External/ko';
|
|
|
|
|
import ko from 'ko';
|
2020-09-17 06:02:35 +08:00
|
|
|
|
import { SaveSettingsStep } from 'Common/Enums';
|
|
|
|
|
|
|
|
|
|
ko.bindingHandlers.saveTrigger = {
|
|
|
|
|
init: (element) => {
|
|
|
|
|
element.saveTriggerType = element.matches('input[type=text],input[type=email],input[type=password],select,textarea')
|
|
|
|
|
? 'input' : 'custom';
|
|
|
|
|
|
|
|
|
|
if ('custom' === element.saveTriggerType) {
|
|
|
|
|
element.append(
|
2020-09-28 15:50:31 +08:00
|
|
|
|
' ',
|
2021-02-05 00:52:46 +08:00
|
|
|
|
Element.fromHTML('<i class="icon-spinner"></i>'),
|
|
|
|
|
Element.fromHTML('<i class="fontastic error">✖</i>'),
|
2020-09-17 06:02:35 +08:00
|
|
|
|
Element.fromHTML('<i class="icon-ok success"></i>')
|
|
|
|
|
);
|
|
|
|
|
element.classList.add('settings-saved-trigger');
|
|
|
|
|
} else {
|
|
|
|
|
element.classList.add('settings-saved-trigger-input');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
update: (element, fValueAccessor) => {
|
|
|
|
|
const value = parseInt(ko.unwrap(fValueAccessor()),10);
|
|
|
|
|
if ('custom' === element.saveTriggerType) {
|
2021-02-05 05:47:38 +08:00
|
|
|
|
element.querySelector('.icon-spinner').hidden = value !== SaveSettingsStep.Animate;
|
2020-09-17 06:02:35 +08:00
|
|
|
|
element.querySelector('.success').hidden = value !== SaveSettingsStep.TrueResult;
|
|
|
|
|
element.querySelector('.error').hidden = value !== SaveSettingsStep.FalseResult;
|
|
|
|
|
} else if (value !== SaveSettingsStep.Animate) {
|
|
|
|
|
element.classList.toggle('success', value === SaveSettingsStep.TrueResult);
|
|
|
|
|
element.classList.toggle('error', value === SaveSettingsStep.FalseResult);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ko.extenders.idleTrigger = (target) => {
|
|
|
|
|
target.trigger = ko.observable(SaveSettingsStep.Idle);
|
|
|
|
|
return target;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// functions
|
|
|
|
|
|
|
|
|
|
ko.observable.fn.idleTrigger = function() {
|
|
|
|
|
return this.extend({ 'idleTrigger': true });
|
|
|
|
|
};
|