Permalink
Browse files

Merge pull request #3 from rrthomas/master

Generalize toggles to work with arbitrary elements
  • Loading branch information...
2 parents 0b90dfa + 2dffa1e commit ad56cf8821164c4735d53b287596197d7306ce0a @Radagaisus committed May 29, 2012
Showing with 39 additions and 18 deletions.
  1. +14 −5 index.html
  2. +11 −6 verdict.coffee
  3. +14 −7 verdict.js
View
@@ -246,12 +246,21 @@
<div class='desc'>
<h2>Toggle</h2>
<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'>
-$("#ted1").toggle_select(['serial killer', 'serial entrepreneur']);
-$("#ted2").toggle_select(['rapist', 'rapper', 'flapper']);
-$("#ted3").toggle_select(['kidnapper', 'babysitter']);
-$("#ted4").toggle_select(['necrophile', 'overall, a very decent man']);</pre>
+&lt;span class='toggle' id='ted1'&gt;
+ &lt;span&gt;serial killer&lt;/span&gt;
+ &lt;span&gt;serial entrepreneur&lt;/span&gt;
+&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>
View
@@ -70,17 +70,22 @@
list of alternative contents
###
(($) ->
- $.fn.toggle_select = (o) ->
+ $.fn.toggle_select = () ->
# Add the event handlers
toggle = (elem) ->
+ children = elem.children()
+ for i in [1...children.length]
+ children[i].style.display = "none"
elem.click (e) ->
+ children = elem.children()
n = 0
- for n in [0..o.length - 1]
- if o[n] == elem.text()
- elem.text(o[(n + 1) % o.length])
- break
- elem.trigger('verdict_change', elem.text())
+ for i in [0...children.length]
+ if children[i].style.display != "none"
+ n = (i + 1) % children.length
+ children[i].style.display = "none"
+ children[n].style.removeProperty("display")
+ elem.trigger('verdict_change', elem)
@each ->
toggle $(@),
View
Oops, something went wrong.

0 comments on commit ad56cf8

Please sign in to comment.