Changeset 35902


Ignore:
Timestamp:
2022-01-07T16:42:07+13:00 (2 years ago)
Author:
cstephen
Message:

Save preferences to localStorage and introduce localStorage polyfill

Location:
main/trunk/model-interfaces-dev/atea/macron-restoration/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/macron-restoration/src/components/DirectInput.vue

    r35901 r35902  
    1212    data() {
    1313        return {
    14             preserveExistingMacrons: true,
    15             showMacronisedWords: false,
    1614            macroniseWaitTimeout: null,
    1715            waitingToMacronise: false,
    18             errorState: false,
    19             normaliseLinebreaks: false
     16            errorState: false
    2017        }
    2118    },
    2219    computed: {
     20        preserveExistingMacrons: {
     21            get() {
     22                const value = localStorage.getItem("preserveExistingMacrons");
     23                return value ?? true;
     24            },
     25            set(newValue) {
     26                localStorage.setItem("preserveExistingMacrons", newValue);
     27            }
     28        },
     29        enableSpellcheck: {
     30            get() {
     31                return localStorage.getItem("enableSpellcheck");
     32            },
     33            set(newValue) {
     34                localStorage.setItem("enableSpellcheck", newValue);
     35            }
     36        },
     37        showMacronisedWords: {
     38            get() {
     39                const value = localStorage.getItem("showMacronisedWords");
     40                return value ?? true;
     41            },
     42            set(newValue) {
     43                localStorage.setItem("showMacronisedWords", newValue);
     44            }
     45        },
     46        normaliseLinebreaks: {
     47            get() {
     48                return localStorage.getItem("normaliseLinebreaks");
     49            },
     50            set(newValue) {
     51                localStorage.setItem("normaliseLinebreaks", newValue);
     52            }
     53        },
    2354        canDownload() {
    2455            return this.restored.length > 0 && !this.waitingToMacronise;
     
    160191<div class="root">
    161192    <textarea class="text-input input-area" @input="onTextInput" autocomplete="off"
    162         v-model="input" :placeholder="translations.get('DirectInput_InputPlaceholder')" />
     193        v-model="input" :placeholder="translations.get('DirectInput_InputPlaceholder')"
     194        :spellcheck="enableSpellcheck ? 'yes' : 'no'" />
    163195
    164196    <div class="text-container">
     
    179211    </div>
    180212
    181     <div class="flex right-column">
     213    <div class="flex">
     214        <input type="checkbox" id="i-enable-spellcheck" v-model="enableSpellcheck" />
     215        <label for="i-enable-spellcheck">{{ translations.get('DirectInput_EnableSpellcheck') }}</label>
     216    </div>
     217
     218    <div class="flex">
    182219        <input type="checkbox" id="i-show-macronised-words" v-model="normaliseLinebreaks" :disabled="restored.length === 0" />
    183220        <label for="i-show-macronised-words">{{ translations.get('DirectInput_NormaliseLinebreaks') }}</label>
     
    216253}
    217254
     255.left-column {
     256    grid-column: 1;
     257}
     258
    218259.right-column {
    219260    grid-column: 2;
  • main/trunk/model-interfaces-dev/atea/macron-restoration/src/main.js

    r35741 r35902  
    44import App from "./App.vue";
    55import ToggleButton from "./components/ToggleButton.vue"
     6
     7// Polyfill localstorage with an in-memory solution for old browsers.
     8// Adapted from https://gist.github.com/juliocesar/926500#gistcomment-1620487
     9try {
     10    window.localStorage.setItem("test_localstorage_available", "1");
     11    window.localStorage.removeItem("test_localstorage_available");
     12}
     13catch (error) {
     14    window.localStorage = {
     15        _data: {},
     16        setItem: function (id, val) {
     17            this._data[id] = String(val);
     18        },
     19        getItem: function (id) {
     20            return Object.prototype.hasOwnProperty.call(this._data, id) ? this._data[id] : undefined;
     21        },
     22        removeItem: function (id) {
     23            return delete this._data[id];
     24        },
     25        clear: function () {
     26            this._data = {};
     27        }
     28    };
     29}
    630
    731const store = createStore({
Note: See TracChangeset for help on using the changeset viewer.