Skip to content

Instantly share code, notes, and snippets.

View takahirohonda's full-sized avatar

Takahiro Honda takahirohonda

View GitHub Profile
@takahirohonda
takahirohonda / replacing-local-storage-with-indexeddb-3-initialiseDb.ts
Last active November 9, 2019 12:06
replacing-local-storage-with-indexeddb-3-initialiseDb.ts
let db: any
export const checkIndexDbBrowserSupport = (): boolean => {
return 'indexedDB' in window
}
export const initialiseDb = (data: any, key: string[]) => {
const request = indexedDB.open('mtd', 1)
return new Promise((resolve, reject) => {
request.onupgradeneeded = (e: any) => {
@takahirohonda
takahirohonda / replacing-local-storage-with-indexeddb-2.js
Last active November 9, 2019 12:02
replacing-local-storage-with-indexeddb-2.js
const exampleData = [
{data: [{categoryName: 'To do', listName: 'Personal'},
{categoryName: 'To do', listName: 'Work'}]},
{data: [{listName: 'Personal'}, {listName: 'Work'}]}
]
const key = ['category', 'list']
let db
let request = indexedDB.open('mtd', 1);
@takahirohonda
takahirohonda / replacing-local-storage-with-indexeddb-1.js
Created November 9, 2019 12:00
replacing-local-storage-with-indexeddb-1.js
// Get JSON from local storage with key mtdListData
const listData = JSON.parse(localStorage.getItem('mtdListData')
// Inserting listData into LocalStorage.
localStorage.mtdListData = JSON.stringify(listData)
@takahirohonda
takahirohonda / karma-unit-test-input-eventlistener-4.ts
Created October 13, 2019 04:46
karma-unit-test-input-eventlistener-4.ts
import FormEventHandler from '../FormEventHandler';
describe('FormEventHandler.spec.ts', () => {
beforeEach(() => {
const fixture = `<form id="fixture">
<div role="radiogroup">
<h3>Radio buttons</h3>
<div role="radio" class="radio-input-ac"
value="option1" id="option1">
Option 1
@takahirohonda
takahirohonda / karma-unit-test-input-eventlistener-4.ts
Created October 13, 2019 04:46
karma-unit-test-input-eventlistener-4.ts
import FormEventHandler from '../FormEventHandler';
describe('FormEventHandler.spec.ts', () => {
beforeEach(() => {
const fixture = `<form id="fixture">
<div role="radiogroup">
<h3>Radio buttons</h3>
<div role="radio" class="radio-input-ac"
value="option1" id="option1">
Option 1
@takahirohonda
takahirohonda / karma-unit-test-input-eventlistener-3.ts
Last active October 13, 2019 04:43
karma-unit-test-input-eventlistener-3.ts
class FormEventHandler implements IEventHandler {
private formElement: HTMLElement;
constructor(formElement: HTMLElement) {
this.formElement = formElement;
}
public init(): void {
this.radioInputHandler();
@takahirohonda
takahirohonda / karma-unit-test-input-eventlistener-2.ts
Created October 13, 2019 04:32
karma-unit-test-input-eventlistener-2.ts
import SelectEventHandler from '../SelectEventHandler';
describe('SelectEventHandler.spec.ts', () => {
beforeEach(() => {
const fixture = `<div id="fixture">
<form id="mock-form">
<select id="first-select">
<option value="" class="default">Select option</option>
<option value="Dr" class="option">Dr</option>
@takahirohonda
takahirohonda / karma-unit-test-input-eventlistener-1.ts
Created October 13, 2019 04:28
karma-unit-test-input-eventlistener-1.ts
import { IEventHandler } from './types/interfaces';
class SelectEventHandler implements IEventHandler {
private formElement: HTMLElement;
private selectElements: any;
constructor(formElement: HTMLElement) {
this.formElement = formElement;
this.selectElements = this.formElement
@takahirohonda
takahirohonda / accessibility-form-tips-4-aria-required.html
Created October 12, 2019 05:10
accessibility-form-tips-4-aria-required.html
<!-- aria-checked is not required -->
<input type="radio"
class="radio-input"
id="adelaide"
name="venue"
value="adelaide"
aria-checked="false" />
<!-- remove aria-checked -->
<input type="radio"
@takahirohonda
takahirohonda / accessibility-form-tips-4-checkbox.html
Created October 12, 2019 04:34
accessibility-form-tips-4-checkbox.html
<fieldset class="input-field" tabindex=0>
<legend class="checkbox-title">
Subscribe to our news letter
</legend>
<div class="checkbox-group">
<input type="checkbox" class="checkbox-input"
id="subscribe" name="subscribe" tabindex=0/>
<label class="radio-label" for="subscribe">
Subscribe
</label>