Sounds like you’re making progress. As a certain Jedi master once
said, “You’ve taken your first step into a larger world”.
On Mar 1, 2010, at 5:14 AM, jeff wrote:
On 10 Feb 2010, 2:56 am, waltd wrote:
That’s just one example. The key to being able to use a technique
like this is going to be structure. You’re going to need to have a
deliberate and predictable nesting strategy so that the structure
of the elements determines what happens after a click.
If you wanted to have a click on a top-level header cause the next
two levels to spill open, then you’d need to nest them within each
other something like this:
I’ve started looking at the code for this website outside Freeway.
You can see the current example here:
http://www.message-design.co.uk/eecf4/
It’s a little more complex than your example (though similarly
nested), in terms of having extra div wrappers (some of which I
think are needed for the Scriptaculous).
Will the javascript still work do you think?
Mine is more like this (though even this leaves out some of the
divs!):
Click me
<div>
<div>
<p>Second level content here</p>
<div>
<div>
<p>Third level content here</p>
</div>
</div>
</div>
</div>
What kind of thing can the javascript target? Can you listen for
clicks on
and then slide open the div directly below?
JavaScript can target anything, really. You can say “when I click
this, the third DIV from the bottom will open”, without knowing how
many elements are in the container. But much more certainly, you can
say “the element with this ID will do something when I click over
here”. That relies on the native construction getElementById(), which
is aliased and extended in Prototype as the “dollar” function:
$('someDivIdHere') //=> returns a reference to that DIV,
// and extends it with all the Prototype methods
Whenever you draw a DIV in Freeway, it gets an ID. If you want to act
on more than one thing at a time, you can add a classname to each
element in your group, and then act on the class all at once. That’s
what the “double-dollar” function is for in Prototype, and underneath
it, the native JS construction getElementsByTagName().
$$('div.foo') //=> returns an array of all DIVs on the page
//with the classname 'foo', or an empty array
I guess I need to get rid of all the div wrappers around my head
tags. I put them in so that I can easily put extra divs within them
and make their whole width (not just the words) clickable. But if I
make the head tags display:block
will this make their whole width
clickable?
Yes, although head tags are display:block already. You may be thinking
that you need to add a link to the head in order to make it a click
target. If you do that, then you have to make the link display block
to get the effect you want. But that’s not necessary either.
Freeway doesn’t make it possible to add an ID to an H tag. So you have
to get a little bit creative. You do have an ID on the DIV that holds
the H tag, so you can address that head by DOM traversal. Ideally, you
would write a single function that can apply to many different heads
rather than writing a separate function for each head, but if you
wanted to address one particular head, you could do this:
$('parentDivId').down('h2') ...
or
$$('#parentDivId > h2').first() ...
Can I then nest other divs inside the head tags?
You can, but not easily within Freeway. (Actually, I haven’t tried
that, it might work, but I have to ask a big WHY?) A head is a
semantic element as well as a structural and styling element. If you
nest a DIV inside it, you are removing any hierarchical clues from
whatever is inside that DIV, and shifting everything up to the level
of a head. Imagine a PowerPoint where everything was written at the
same ginormous font size, no variety. That’s more or less what you’re
doing to the browser or any other state machine that tries to make
sense of the content. You might want to try making a cut-down example
of what you’re intending and run it through the W3 validator to see
what it makes of it.
Also, can the structure in the html be used by the CSS to target the
styles, instead of using classes, as I have? So that if some text is
a child of a div with a certain id (at some given level of nesting)
it gets a certain style?
Sure, that’s very simple.
div#divId ul li ul li //=> targets only the second level list elements
// in the div with the ID 'divId'
And would this whole thing be better structured as a list? Can you
still put
etc tags inside a list, or would that just be making
extra work for little reward?
You can put nearly any sort of tag inside a list item tag. (As a side
note, I hope you only ever have one H1 tag on any given page. You can
have as many H2-6 as you like.) A list would offer quite a bit of
semantic structure to the page, although it’s debatable whether it
would be a significant difference from a normal inline layout for this
particular construction.
Walter
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options