UNPKG

call-me-aishmael

Version:
64 lines (56 loc) 1.86 kB
/* * (C) Copyright IBM Corp. 2017. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ var state = require('../../state'); var utils = require('../../utils'); function enableInput() { var current = state.get(); var disableInput = (current.disableInput) ? (current.disableInput - 1) :0; state.set({ disableInput: disableInput }); if (!disableInput) current.input.removeAttribute('disabled'); } function disableInput() { var current = state.get(); var disableInput = (current.disableInput) ? (current.disableInput + 1) : 1; state.set({ disableInput: disableInput }); current.input.setAttribute('disabled', 'disabled'); } function enableLoadingInput() { var current = state.get(); var loading = (current.loading) ? (current.loading + 1) : 1; state.set({ loading: loading }); utils.spinner.show(current.loader); } function disableLoadingInput() { var current = state.get(); var loading = (current.loading) ? (current.loading - 1) : 0; state.set({ loading: loading }); if (loading === 0) utils.spinner.hide(current.loader); } function focusInput() { var current = state.get(); current.input.focus(); } module.exports = { enableInput: enableInput, disableInput: disableInput, enableLoadingInput: enableLoadingInput, disableLoadingInput: disableLoadingInput, focusInput: focusInput };