Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yet another approach #2

Open
1 of 2 tasks
bburky opened this issue May 22, 2014 · 3 comments
Open
1 of 2 tasks

Yet another approach #2

bburky opened this issue May 22, 2014 · 3 comments

Comments

@bburky
Copy link
Member

bburky commented May 22, 2014

You could implement this as a contentEditable document and apply regex string replacements to innerHTML to create real HTML <input type=checkbox> checkboxes.

Example:

<body id=t contenteditable=true oninput="localStorage.t=t.innerHTML=t.innerHTML.replace(/\[ ?\]/g,'<input type=checkbox onchange=this.removeAttribute(\'checked\');if(this.checked)this.setAttribute(\'checked\',\'\');localStorage.t=t.innerHTML>')"onload=t.innerHTML=localStorage.t||''>

Issues:

  • You must copy the checked property of each checkbox into its checked attribute so that persistence of the document's innerHTML captures the checkbox states.
  • Modifying innerHTML resets the cursor position. I haven't fixed this, so for the example you must move the cursor to the end every time you enter text.
@subzey
Copy link
Member

subzey commented May 22, 2014

Yeah, the cursor position is painful thing, that was my first approach.

By the way, this repo is a community repo, feel free to and add your implementations and edit existing ones!

@bburky
Copy link
Member Author

bburky commented May 22, 2014

I added it as contenteditable.html. Live demo. Note that this also uses localStorage.t, so it will clobber the stored data from the other one.

@xem
Copy link
Member

xem commented May 22, 2014

I had the same idea as @bburky and started to implement it, but it doesn't work yet.
Although, my version has/had another goal: inserting a checkbox after each line break / carriage return, so that you don't have to type the [ ] manually before each line. Maybe the text-only version could do that too @subzey ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants