Fork me on GitHub
#hoplon
<
2016-11-29
>
laforge4913:11:22

How to do spaces? I pass " baker" to an element and the space vanishes and all I get is "baker". But if I pass "&nbsp;baker" I get "&nbsp;baker". @micha? @flyboarder?

micha13:11:47

(div :html "&nbsp;baker")

micha13:11:37

but almost always though you really want to use css for margins not spaces

laforge4913:11:20

@micha what is that :html?

laforge4913:11:16

It works great.

laforge4913:11:11

I searched the hoplon repository and could not find any documentation. But in any case, thanks for the extra bit of magic.

micha13:11:49

it's defined in the same namespace as the other attributes

micha13:11:58

hoplon.jquery

micha13:11:09

note that you will need to html escape any <, >, and & characters

micha13:11:24

very likely that you don't want to do anything involving &nbsp; in a hoplon application

micha13:11:59

you want to use css to make padding or margin to the left of text

micha13:11:12

not spaces

laforge4914:11:45

I'm creating a console display. All lines are converted into the same type of element so that I can use for-tpl and have elements reused. So I'll convert those reserved characters as I build the dom elements, but as data rather than bringing in dom elements unique to a given line of output.

micha14:11:48

you can use CSS to have an element preserve whitespace

micha14:11:13

and there is the pre element, the code element, etc

laforge4914:11:26

Very nice. Thanks @micha!

jumblerg15:11:14

@onetom: try building with https://github.com/jumblerg/hoplon/tree/optimizations when you get a chance. vflatten has shaved a couple hundred ms from my ui tests.

jumblerg15:11:54

we really need to get some xbrowser unit tests set up on sauce labs or some such similar service that will give us good benchmarks to optimize against.

laforge4919:11:14

@flyboarder @micha I seem to keep coming back to the same thing. I add an element to the output and this time I need to call scrollIntoView. I'm locating the element by id, only at the time I make the call, the dom has not been updated. So is there any way to know when that dom has been updated? Can I wait for it??

laforge4919:11:02

--normally I hate to wait, but in this case I am processing a user request and want to do the scroll to make it visible.

laforge4919:11:11

Hmm. I could just repeatedly check to see if the last item to be displayed is visible and if not then scroll. I.E. polling. 😞

micha20:11:54

seems like there is probably a better way to accomplish what you want to do

micha20:11:02

which is why you keep coming back to the same thing

micha20:11:18

fishing around in the dom for ids is almost never the way to do it

laforge4920:11:50

Is there some way to have a div scroll to the bottom whenever an element is added to it?

laforge4920:11:21

Mind, I still want the user to be able to manually scroll when no elements are actively being added.

micha20:11:14

no, you want to scroll the thing when you add an element

laforge4920:11:16

I really feel like I'm fighting hoplon. Which is a new experience for me.

laforge4920:11:23

yes. only then.

micha20:11:30

you are adding the element though

micha20:11:40

so wherever you do that you can also perform the scorolling

laforge4920:11:12

but when I add the element, it does not exist. How can I scroll to something before it exists in the dom itself?

micha20:11:03

use a timeout of 0

micha20:11:11

it will exist in the dom then

laforge4920:11:49

This is a wonderful general solution. Thanks @micha!

micha20:11:23

however you probably should be using one of the *-tpl things instead of fishing around in the dom for an element by id and then calling appendChild on it

micha20:11:29

however you probably should be using one of the *-tpl things instead of fishing around in the dom for an element by id and then calling appendChild on it

micha20:11:46

then it would be clear how to do the scrolling

laforge4920:11:40

I'm using for-tpl already. only, I need the element itself to call the scrollIntoView method, yes?

micha20:11:13

there is the :scroll-to attribute

micha20:11:31

they're all in that namespace

micha20:11:40

there are a number of handy attributes

laforge4920:11:05

Clearly I need that wiki page.

micha20:11:48

the cljs source is there, it's not a lot of code

laforge4920:11:58

So in the for-tpl, I put :scroll-to on every element, with the value true when it is the last element, eh?

micha20:11:31

(div :scroll-to some-cell "hello")

micha20:11:57

whenever some-cell changes from false to true the page will scroll such that that div is at the top

laforge4920:11:45

top? then the added element will be the only one visible?

micha20:11:21

you can make your own :scroll-to-bottom or whatever if you want

micha20:11:33

using the one in hoplon as an example

micha20:11:17

oh actually what i said above is slightly wrong

micha20:11:02

:scroll-to will scroll the page when the value in some-cell changes and the new value is not nil or false

laforge4920:11:33

with-timeout 0 is working nicely for me. I looked at the other, but it pulls me into places I'm less comfortable with.

laforge4920:11:20

I use a vector where 0 is the id and 1 is the text. I may extend this later if I need to add clickables to the display.

laforge4920:11:39

Only, it feels like using a cell for :id is overkill, since it does not change.

laforge4920:11:33

Ah. Destructuring is the answer.