Add section navigation controls

This commit is contained in:
Jeremy Penner 2011-02-15 08:42:27 -08:00
parent 200333b787
commit 6129bbce17
2 changed files with 30 additions and 2 deletions

View file

@ -127,6 +127,8 @@ class Nevgen
nevgen = nevgen.NextI() nevgen = nevgen.NextI()
nevgen nevgen
NextI: () -> NextI: () ->
if @wst.nev.FEndsSection()
return null
if @respo? if @respo?
respoNext = @respo.Next(this) respoNext = @respo.Next(this)
wst = @wst wst = @wst
@ -150,7 +152,13 @@ class Gst
isectionRemove = @rgsection.length - 1 isectionRemove = @rgsection.length - 1
@rgsection.splice(isectionRemove, 1) @rgsection.splice(isectionRemove, 1)
@rgwstInit.splice(isectionRemove, 1) @rgwstInit.splice(isectionRemove, 1)
@Display()
PushSection: (section, wst) ->
@rgsection.push(section)
@rgwstInit.push(wst)
@Display()
SectionCurrent: () -> SectionCurrent: () ->
@rgsection[@rgsection.length - 1] @rgsection[@rgsection.length - 1]
@ -166,6 +174,11 @@ class Gst
dgEnter = () -> $(this).addClass('hover') dgEnter = () -> $(this).addClass('hover')
dgLeave = () -> $(this).removeClass('hover') dgLeave = () -> $(this).removeClass('hover')
# show "previous section" link
if @rgsection.length > 1
@jDiv.append("<div class='iffy-section-nav'>#{@Link("Previous section", () => @GoBackOneSection())}</div>")
# show all nevs in section
@rgwst = null @rgwst = null
@rgwst = @RgwstRun() @rgwst = @RgwstRun()
for wst in @rgwst for wst in @rgwst
@ -175,6 +188,11 @@ class Gst
jDivNev.hover(dgEnter, dgLeave) jDivNev.hover(dgEnter, dgLeave)
@wstLast = wst @wstLast = wst
# show "next section" link
stHtmlNav = @wstLast.nev.StHtmlNextSection(this, @wstLast)
if stHtmlNav?
@jDiv.append("<div class='iffy-section-nav'>#{stHtmlNav}</div>")
for stId_dgOnClick in @mpstId_dgOnClick for stId_dgOnClick in @mpstId_dgOnClick
@jDiv.find("##{stId_dgOnClick[0]}").click(stId_dgOnClick[1]) @jDiv.find("##{stId_dgOnClick[0]}").click(stId_dgOnClick[1])
@ -288,7 +306,12 @@ class Nev
wst = wst.WstPrev() wst = wst.WstPrev()
return false return false
FCanRun: (gst, wst) -> not @FHasRun(wst) FCanRun: (gst, wst) -> not @FHasRun(wst)
FEndsSection: () -> $(@dNev).attr("nextsection")?
RunAction: (gst, wst) -> RunAction: (gst, wst) ->
StHtmlNextSection: (gst, wst) ->
stSectionNext = $(@dNev).attr("nextsection")
if stSectionNext?
gst.Link("Next section", () -> gst.PushSection(gst.story.SectionByName(stSectionNext), wst))
StHtmlDisplay: (gst, wst) -> StHtmlDisplay: (gst, wst) ->
jdivTmp = $("<div/>") jdivTmp = $("<div/>")
for dHTML in $(@dNev).contents() for dHTML in $(@dNev).contents()

View file

@ -31,7 +31,7 @@
</verb> </verb>
</word> </word>
<word name="button"> <word name="button">
<verb name="Push"> <verb name="Push" nextsection="next">
<p>Larry reaches for the button and gives it a push.</p> <p>Larry reaches for the button and gives it a push.</p>
<p>"Nothing happened", says Larry, looking at the [computer].</p> <p>"Nothing happened", says Larry, looking at the [computer].</p>
<p>"I <i>told</i> you you were going to push it," says [Richard].</p> <p>"I <i>told</i> you you were going to push it," says [Richard].</p>
@ -45,4 +45,9 @@
<p>"Never mind," says [Richard].</p> <p>"Never mind," says [Richard].</p>
</pastresponse> </pastresponse>
</section> </section>
<section name="next">
<nev name="start">
Larry is alone with the DeLorean in the lab, for the first time.
</nev>
</section>
</story> </story>