Skip to content
This repository has been archived by the owner on Mar 5, 2018. It is now read-only.

Commit

Permalink
Merge pull request #3 from rrthomas/master
Browse files Browse the repository at this point in the history
Generalize toggles to work with arbitrary elements
  • Loading branch information
Radagaisus committed May 29, 2012
2 parents 0b90dfa + 2dffa1e commit ad56cf8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
19 changes: 14 additions & 5 deletions index.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -246,12 +246,21 @@ <h2>Number Selection</h2>
<div class='desc'> <div class='desc'>
<h2>Toggle</h2> <h2>Toggle</h2>
<div class='example'> <div class='example'>
<blockquote>Theodore Robert "Ted" Bundy was an American <span class='toggle' id='ted1'>serial killer</span>, <span id='ted2' class='toggle' >rapist</span>, <span id='ted3' class='toggle' >kidnapper</span>, and <span id='ted4' class='toggle' >necrophile</span> who assaulted and murdered numerous young women during the 1970s, and possibly earlier. </blockquote> <blockquote>Theodore Robert "Ted" Bundy was an American <span class='toggle' id='ted1'><span>serial killer</span><span>serial entrepreneur</span></span> and <span id='ted2' class='toggle' ><span>rapist</span><span>rapper</span><span>flapper</span></span> who assaulted and murdered numerous young women during the 1970s, and possibly earlier. </blockquote>
<pre class='sh_javascript_dom'> <pre class='sh_javascript_dom'>
$("#ted1").toggle_select(['serial killer', 'serial entrepreneur']); &lt;span class='toggle' id='ted1'&gt;
$("#ted2").toggle_select(['rapist', 'rapper', 'flapper']); &lt;span&gt;serial killer&lt;/span&gt;
$("#ted3").toggle_select(['kidnapper', 'babysitter']); &lt;span&gt;serial entrepreneur&lt;/span&gt;
$("#ted4").toggle_select(['necrophile', 'overall, a very decent man']);</pre> &lt;/span&gt;

&lt;span id='ted2' class='toggle' &gt;
&lt;span&gt;rapist&lt;/span&gt;
&lt;span&gt;rapper&lt;/span&gt;
&lt;span&gt;flapper&lt;/span&gt;
&lt;/span&gt;

$("#ted1").toggle_select();
$("#ted2").toggle_select();</pre>
</div> </div>
</div> </div>


Expand Down
17 changes: 11 additions & 6 deletions verdict.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,17 +70,22 @@
list of alternative contents list of alternative contents
### ###
(($) -> (($) ->
$.fn.toggle_select = (o) -> $.fn.toggle_select = () ->


# Add the event handlers # Add the event handlers
toggle = (elem) -> toggle = (elem) ->
children = elem.children()
for i in [1...children.length]
children[i].style.display = "none"
elem.click (e) -> elem.click (e) ->
children = elem.children()
n = 0 n = 0
for n in [0..o.length - 1] for i in [0...children.length]
if o[n] == elem.text() if children[i].style.display != "none"
elem.text(o[(n + 1) % o.length]) n = (i + 1) % children.length
break children[i].style.display = "none"
elem.trigger('verdict_change', elem.text()) children[n].style.removeProperty("display")
elem.trigger('verdict_change', elem)


@each -> @each ->
toggle $(@), toggle $(@),
Expand Down
21 changes: 14 additions & 7 deletions verdict.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ad56cf8

Please sign in to comment.