News for hackers. Stuff that matters.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by brockwhittaker on Friday February 24, 2017 @07:28PM (#13729233)
You should consider removing all the other functions from the global scope, especially because they have relatively generic names like "generateTree", "toArray", "depth", and "toggleClass".

Consider using an actual class or a closure perhaps?

Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by MaxLeiter on Tuesday February 28, 2017 @03:07PM (#13757361)
Wrapped in a closure, thanks!
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by Cheezmeister on Friday February 24, 2017 @07:18PM (#13729190)
Thanks for sharing! I see your 3.5k and raise (lower?) you 1.6k

https://github.com/cheezmeister/kapok

[I think it does most of what yours does](https://github.com/Cheezmeister/kapok/blob/master/tst/kapok....) (EDIT: Nope, missing URL loading and XSS cleaning!)

Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by MaxLeiter on Saturday February 25, 2017 @01:18AM (#13730344)
Yours is much cleaner code though; this was my first venture in javascript (and really programming) when I wrote it and am planning on refactoring it soon(tm). Great work with Kapok, the demo page is well done.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by kc10 on Friday February 24, 2017 @06:54PM (#13729067)
I didn't realize it's a tree until I clicked it. Changing the buttons to + and - signs might help.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by yestoallthat on Saturday February 25, 2017 @06:22AM (#13731078)
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by tomatsu on Friday February 24, 2017 @07:11PM (#13729157)
I'm using ⊞ and ⊟ for that.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by timfletcher on Friday February 24, 2017 @07:18PM (#13729188)
I was confused too. It looks like an bulleted list in Chrome.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by ibgib on Friday February 24, 2017 @10:10PM (#13729789)
I think its cool, but def the bullets threw me. Maybe an example of the customized styling would be good.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by simcop2387 on Friday February 24, 2017 @09:48PM (#13729713)
firefox also
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by MaxLeiter on Saturday February 25, 2017 @01:17AM (#13730340)
Originally I wanted no custom styling so the developer could decide, but I think I'll add either + - or ^ >
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by edko on Friday February 24, 2017 @07:02PM (#13729114)
I noticed that your json2html function assigns the same id (top) to all non-leaf tree nodes. You might want to fix that.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by ComputerGuru on Friday February 24, 2017 @08:26PM (#13729455)
This doesn't work in Safari on iOS. Values don't show up, no tree.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by foota on Friday February 24, 2017 @09:03PM (#13729546)
I definitely expected this to be like a JSON serialization format for HTMl.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by Lorin on Friday February 24, 2017 @06:22PM (#13728867)
Neat, but generated tree isn't keyboard accessible.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by MaxLeiter on Friday February 24, 2017 @06:42PM (#13728987)
keyboard accessible? are most html trees?
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by simonw on Friday February 24, 2017 @07:15PM (#13729175)
They definitely should be, for accessibility reasons and because it's not that difficult to support.

Here's an example of a tree widget that can be navigated by keyboard: https://www.jstree.com/docs/html/

Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by EdSharkey on Friday February 24, 2017 @07:57PM (#13729364)
I'm not a fan of javascript being used for the clicky handlers, even if the element being clicked is a natural clicky element like an anchor tag.

It's much better to rely on a toggle like input type=checkbox and CSS to visualize tree expand and collapse based on checkbox states than to install click handlers in javascript. I suspect you could make such an arrangement more accessible and keyboard navigable as well (via grouping.)

Javascript should only be used to dynamically load/unload subtrees on click in the case of especially huge or costly trees.

Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by recklessplayer on Sunday February 26, 2017 @03:09AM (#13736224)
As a blind screen reader user, I rely on keyboard accessibility for navigating any type of tree. Now I know not to checkout your project as it would be of no use to me.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by onion2k on Saturday February 25, 2017 @05:49AM (#13731001)
Most aren't. The good ones are.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by kyriakos on Friday February 24, 2017 @08:53PM (#13729520)
The menu on the linked page does not work on mobile because the fork me banner is overlayed on top on it.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by MaxLeiter on Saturday February 25, 2017 @01:16AM (#13730338)
Removed the banner - thanks
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by frik on Saturday February 25, 2017 @02:51AM (#13730559)
Doesn't work on mobile browser.
Re:Show HN: JsonTree, a 3.53kb JavaScript tool for generatin... by WhitneyLand on Friday February 24, 2017 @07:17PM (#13729182)
Doesn't work on mobile? (iOS)