Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Highlighter.js (720kb.github.io)
40 points by 720kb on Aug 1, 2015 | hide | past | favorite | 22 comments


I don't get why this requires a special purpose library. Why not create a css class highlighted where the borders of an elements would be in fluorescent green and modify the class of the elements of the DOM one wants to highlight with jquery?


I agree, most of the code in the library is for element navigation. Why not open-source that and let people define their own CSS props.

By the way, I believe it uses the `outline` CSS property as opposed to `border` (border changes layout, outline doesn't).


Yes it's outline, just because it is probably the less used css rule available for the scope. Probably the alternative could be box-shadow. Having to modify borders will probably result in breaking third parties CSS etc.. more troubles guess.

The code is already open-source, feel free to open issues, fork and PR also if you want to add new features, the door is open wide!


Yeah, you also have to account for box sizing by adding borders. What I've done for this in the past is use a css &:after pseudo-element and make it absolutely positioned, and set width and height at 100% and position it at left: 0 and top: 0. You can do things like give it a fill with opacity too, to highlight not with just outline but color overlay too.

.outlined:after { content: ""; position: absolute; top: 0; width: 0; height: 100%; width: 100%; background-color: green; opacity: 0.3; }

.outlined { position: relative; } // this part my be a poor assumption


Hi, yes this is another alternative, probably the best one but it's hard actually to find the real best one because in the end everyone use different styles, different css frameworks, different use cases, in many cases it may break something in many others not, you know :)

Anyway appreciated a lot your example and your tips, let's just wait for some feedback from people who use it and make decisions more clear.

Thank you really :)


This is intended to be used without jQuery :)


yup, normally I'm all for new projects but this just seems like an overkill. You could achieve this with even just a css. I don't think it's worth it at all to be using a specialized library for it.


Sorry i don't understand the point, CSS is not programmatic


you don't need to be programmatic because it's so much lightweight and easier to use CSS + a few lines of javascript. You can absolutely highlight an element by adding a class or even hover property.

This is like a giant box wrapped in fancy wrappers but when you open the box there's not much substance inside, you spend more time dealing with the wrappers.


Thank you for explanation, how do you skip 50 next elements and select the next element with class="oneclass twoclass" in CSS and then return the element infos in JS?

My bet is you are going to need more lines then this https://github.com/720kb/highlighter.js/blob/master/src/js/h... (which is going to be slimmed more)


> how do you skip 50 next elements and select the next element with class="oneclass twoclass" in CSS

Why do you need to do this? That's a solution looking for a problem.


Hi :), sorry you're right, looks like i am going to make it more difficult than it really is. Actually you can also skip elements https://github.com/720kb/highlighter.js#skip-next

Use cases are up to your imagination, just for example, think of a html5 game where you want to highlight but skip elements, or move cursor forward and backward... only a trivial example


I know you are attached with it since it's your creation but I was just looking for what problem it could possibly solve and I failed to see any use cases where javascript + xpath couldn't solve. If you want to skip to the next element, you can absolutely do this with the nextSibling or any iterative function that returns the next DOM element. With xpath you can drill down into the exact element by using the indice like `//a[50]` to select the 50th element directly.

To support older browsers you could use something like xpaths.js but safari, chrome, firefox all support document.evaluate() and manipulating the element is a no brainer just do addClass().

https://github.com/andrejpavlovic/xpathjs

Despite being a jQuery fan (I've used it to build 4k line jquery chrome extension) I find it much easier to just look up the javascript equivalent, more than often, it's worth knowing since it frees you from using library.

But keep at it, I think maybe if you could build something that does a very good job of highlighting dom elements on mouseover/mouseout with some intelligent highlighting (simply attaching event handlers to all elements on the dom page produces a jerky) I could see that being quite useful.

All in all, take my view with a grain of salt, just because I failed to see a use case and think it's more cost effective to know the DOM manipulations with javascript directly, does not mean that somebody out there might justify it's use.

Good stuff!


Thanks for the suggestions, there is no problem, this library was made to be used on another project where we needed some kind of "joystick" for elements of the DOM.

We did not find anything and we thought of writing it directly.

Obviously it's open source so anyone can use it and do and suggest changes, we are curious to see even the possible use cases that others have.

Probably using what you say would be the best is not easy to say so on the spot, it should be seen in any detail.


You could add a tabindex to each element in your filtered set. Then you could have :focus as your highlight selector, and it would give you keyboard accessibility for free.


hi, for the keyboard we would prefer to not touch or change the DOM elements other than the outline css rule.

You could end up having various problems adding tabindex, many people use tabindex attribute.


Neat little tool, and love the size constraint!

I made a little JS bookmarklet a while ago that reveals script, style, and meta tags, and tries to display which tags are used to build the layout: http://www.youtube.com/watch?v=wp2d24t2POI

Are there any plans in the future to make your tool so the highlight follows that I tap on mobile? Keep up the great work!


Hi, thank you a lot for supporting, the aim, actually, is to stay lightweight, but for sure you can bind it for your own pourposes and needs, like tap and select, or click and select, why not :)

This project was meant to easily surf the nodes and maybe highlight them, but it's still at early stage and any help is much appreciated!

Thanks for sharing the video, very interesting :)


zooming in on Android 4.4.4 browser prevents scrolling for me


Hi, thanks for reporting the issue, it's still at early stage we need to improve it.

Here you can check what's wrong and post new issues https://github.com/720kb/highlighter.js/issues

Any help is appreciated!


People were doing this 15 years ago, before all the hipster web designers picked up javascript, opened terminal and called themselves programmers.

I"m sure the old JS programmers moved on to a real programming language, but they put you new guys to complete shame, and they didn't need 18 dependencies and a dependency manager to get it done.

jQuery was a great invention for web development, but everything since then has been total crap. Angular, React, Node, all of it's crap. The only people who like it are those who aren't smart enough to be real programmers.


Whatever you say old man




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: