timeline_setter 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/Rakefile +11 -2
  2. data/config/assets.yml +9 -0
  3. data/doc/doc.markdown +65 -17
  4. data/doc/templates.html +3 -0
  5. data/doc/timeline-setter.html +327 -238
  6. data/doc/timeline-setter.min.html +3 -0
  7. data/documentation/TimelineSetter/CLI.html +77 -52
  8. data/documentation/TimelineSetter/Parser.html +40 -39
  9. data/documentation/TimelineSetter/Timeline.html +132 -83
  10. data/documentation/TimelineSetter.html +27 -12
  11. data/documentation/_index.html +23 -12
  12. data/documentation/class_list.html +20 -9
  13. data/documentation/css/style.css +7 -5
  14. data/documentation/file.README.html +33 -23
  15. data/documentation/file_list.html +20 -9
  16. data/documentation/frames.html +1 -1
  17. data/documentation/index.html +33 -23
  18. data/documentation/js/app.js +16 -14
  19. data/documentation/js/full_list.js +7 -6
  20. data/documentation/js/jquery.js +3 -3
  21. data/documentation/method_list.html +42 -23
  22. data/documentation/top-level-namespace.html +26 -11
  23. data/index.html +100 -19
  24. data/lib/timeline_setter/cli.rb +2 -0
  25. data/lib/timeline_setter/timeline.rb +6 -3
  26. data/lib/timeline_setter/version.rb +1 -1
  27. data/lib/timeline_setter.rb +0 -7
  28. data/public/javascripts/templates/card.jst +21 -0
  29. data/public/javascripts/templates/notch.jst +1 -0
  30. data/public/javascripts/templates/series_legend.jst +3 -0
  31. data/public/javascripts/templates/timeline.jst +20 -0
  32. data/public/javascripts/templates/year_notch.jst +3 -0
  33. data/public/javascripts/templates.js +1 -0
  34. data/public/javascripts/timeline-setter.js +303 -167
  35. data/public/javascripts/timeline-setter.min.js +1 -0
  36. data/public/stylesheets/timeline-setter.css +5 -5
  37. data/spec/timeline_setter_spec.rb +2 -2
  38. data/templates/timeline-markup.erb +5 -59
  39. data/timeline_setter.gemspec +15 -5
  40. metadata +15 -5
data/Rakefile CHANGED
@@ -5,6 +5,16 @@ require 'rake/rdoctask'
5
5
  require 'rspec/core/rake_task'
6
6
  require './lib/timeline_setter'
7
7
 
8
+ desc "generate templates and minified JS. Stash them in public/javascripts"
9
+ task :jammit do
10
+ %x{
11
+ cd #{TimelineSetter::ROOT} &&
12
+ jammit &&
13
+ mv public/assets/templates.js public/javascripts/templates.js &&
14
+ mv public/assets/main.js public/javascripts/timeline-setter.min.js
15
+ rm -rf public/assets
16
+ }
17
+ end
8
18
 
9
19
  desc "build docs"
10
20
  task :docs do
@@ -24,7 +34,6 @@ task :gh_pages do
24
34
  `rake docs`
25
35
  `rake yard`
26
36
  `rake docco`
27
- `rake sample`
28
37
 
29
38
  `git branch` =~ /^\* (.+)?\n/
30
39
  current_branch = $1
@@ -58,7 +67,7 @@ begin
58
67
  gem.add_dependency "json"
59
68
  gem.add_dependency "table_fu"
60
69
  gem.add_dependency "kompress", ">= 0.0.2"
61
- gem.add_dependency "closure-compiler"
70
+ gem.add_dependency "jammit"
62
71
  gem.add_development_dependency "rspec", ">= 2.0.0"
63
72
  gem.version = TimelineSetter::VERSION
64
73
  end
data/config/assets.yml ADDED
@@ -0,0 +1,9 @@
1
+ embed_assets :on
2
+ template_function: _.template
3
+
4
+ javascripts:
5
+ main:
6
+ - public/javascripts/timeline-setter.js
7
+ - public/javascripts/templates/*.jst
8
+ templates:
9
+ - public/javascripts/templates/*.jst
data/doc/doc.markdown CHANGED
@@ -158,6 +158,24 @@ The timeline is made up of non-clickable *interval notches* used to denote
158
158
  periods of time, and *event notches*, which, when clicked, reveal their
159
159
  associated *event cards*.
160
160
 
161
+ <a id="configuring"></a>
162
+ ## Configuring the Timeline JavaScript Embed
163
+
164
+ Although the `timeline-setter` command generates a JavaScript embed that prepopulates your data, you can also create this yourself by calling `TimelineSetter.timeline.boot` with an array of card objects, and a config object.
165
+
166
+ var myTimeline = TimelineSetter.Timeline.boot([{card}...], {config})
167
+
168
+ The config object looks for `interval`, `container`, and `formatter` options.
169
+
170
+ The `interval` option takes an [interval](#interval_notch_options) in the form of a JavaScript date getter. The `container` option allows you to inject the entire timeline into an element with the given selector. (By default this is `#timeline`). Finally, `formatter` is a way to format dates on the timeline's interval notches. Write a formatter like so:
171
+
172
+ formatter : function(d, defaults) {
173
+ defaults.months = ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'];
174
+ return defaults;
175
+ }
176
+
177
+
178
+
161
179
  <a name="styling"></a>
162
180
  ## Styling Your Timeline
163
181
 
@@ -169,17 +187,14 @@ replace it completely. Here's a guide to do that.
169
187
  <a id="styling-container"></a>
170
188
  ### Overview and Styling the Container and Top Matter
171
189
 
172
- All TimelineSetter CSS is scoped within a namespace starting with `TS.` The
173
- outermost container is `#timeline_setter.`
190
+ All TimelineSetter CSS is scoped within a namespace starting with `TS` except for the outermost container (by default `#timeline`.) The container is configurable with the `container` argument in the TimelineSetter boot function's config object.
174
191
 
175
192
  Upon first glance, it may not seem like there is much markup at all. That's
176
193
  because we make extensive use of JavaScript (ERB-style) templating via
177
- [Underscore.js](http://documentcloud.github.com/underscore/#template) -- so
178
- templates for each part of the timeline reside in the DOM. The controls (zoom
179
- in/out, previous/next buttons) are available within `#TS-top_matter_container .TS-controls`.
194
+ [Underscore.js](http://documentcloud.github.com/underscore/#template) --
195
+ templates for each part of the timeline reside in a JST object at the end of timeline-setter.js.
180
196
 
181
- Series checkboxes are injected into `.TS-series_nav_container` and templated
182
- via `script#TS-notch_tmpl`. Currently, series colors are hard coded in the
197
+ Currently, series colors are hard coded in the
183
198
  JavaScript. We support a maximum of nine series colors (assigned in this order:
184
199
  ``#065718, #EDC047, #91ADD1, #929E5E, #9E5E23, #C44846, #465363, #EDD4A5, #CECECE``,
185
200
  they can be overridden in the "color priority" section of `timeline-setter.css`). Technically
@@ -189,10 +204,7 @@ to the default charcoal notch color.
189
204
  <a id="styling-bar"></a>
190
205
  ### Styling the bar, notches and cards
191
206
 
192
- Interval notches are templated within `script#TS-year_notch_tmpl`. Their
193
- position is based on the interval of time between events as automatically
194
- determined by the JavaScript. Here's a sampling of what you might see in
195
- interval notches:
207
+ The position of interval notches is based on the interval of time between events as automatically determined by the JavaScript. Here's a sampling of what you might see in interval notches:
196
208
 
197
209
  year => 2001
198
210
  month => June, 2004
@@ -213,12 +225,41 @@ The interval notches date spans themselves can be customized by using the `-i` f
213
225
  Minutes
214
226
  Seconds
215
227
 
216
- Event notches are templated through `#TS-card-tmpl` and contain individual
217
- classes corresponding to spreadsheet columns. `.TS-item-label` corresponds to
218
- `description`, `.TS-item_html` corresponds to `html`,
219
- `.TS-read_btn` is linked to `link` and `.TS-item_year` corresponds to
220
- `display_date` falling through to `date`. Finally, `TS-permalink`
221
- is a fragment link which will show the active card on page load if used.
228
+ <a id="js_api"></a>
229
+ ## The JavaScript API
230
+
231
+ As of version 0.3.0, TimelineSetter has a JavaScript API that allows programmatic access to certain events, and the ability to activate cards. To use the API, assign the `TimelineSetter.Timeline.boot()` function to a variable, and then use methods in the `api` object like so:
232
+
233
+ var currentTimeline = TimelineSetter.Timeline.boot(options);
234
+ currentTimeline.api.onLoad(function() {
235
+ console.log("I'm ready")
236
+ });
237
+
238
+ Here are the API methods:
239
+
240
+ ### onLoad
241
+
242
+ Register a callback for when the timeline is loaded.
243
+
244
+ ### onCardAdd
245
+
246
+ Register a callback for when a card is added to the timeline. This method has access to the event name and the card object.
247
+
248
+ currentTimeline.api.onCardAdd(function(evtName, obj) {
249
+ console.log(obj);
250
+ });
251
+
252
+ ### onCardActivate
253
+
254
+ Register a callback for when a card is activated (i.e. shown). This method has access to the event name and the card object.
255
+
256
+ ### onBarMove
257
+
258
+ Register a callback for when the bar is moved or zoomed. Be careful with this one: Bar move events can be fast and furious, especially with scroll wheels in Safari.
259
+
260
+ ### activateCard
261
+
262
+ Show the card matching a given timestamp. Right now, timelines only support one card per timestamp.
222
263
 
223
264
  <a id="roadmap"></a>
224
265
  ## Roadmap
@@ -258,6 +299,13 @@ questions should go to <a href="mailto:opensource@propublica.org">opensource@pro
258
299
  <a id="changelog"></a>
259
300
  ## Change Log
260
301
 
302
+ <a id="release-030"></a>
303
+ ### 0.3.0
304
+
305
+ * Add JavaScript API
306
+ * Scope timeline to a given element to support multiple timelines on a page
307
+ * Add date formatter config option. _Thanks [@omega](https://github.com/propublica/timeline-setter/pull/26)_
308
+
261
309
  <a id="release-020"></a>
262
310
  ### 0.2.0
263
311
 
@@ -0,0 +1,3 @@
1
+ <!DOCTYPE html> <html> <head> <title>templates.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <div id="jump_to"> Jump To &hellip; <div id="jump_wrapper"> <div id="jump_page"> <a class="source" href="templates.html"> templates.js </a> <a class="source" href="timeline-setter.html"> timeline-setter.js </a> <a class="source" href="timeline-setter.min.html"> timeline-setter.min.js </a> </div> </div> </div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> templates.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="p">(</span><span class="kd">function</span><span class="p">(){</span><span class="nb">window</span><span class="p">.</span><span class="nx">JST</span><span class="o">=</span><span class="nb">window</span><span class="p">.</span><span class="nx">JST</span><span class="o">||</span><span class="p">{};</span><span class="kd">var</span> <span class="nx">a</span><span class="o">=</span><span class="kd">function</span><span class="p">(</span><span class="nx">c</span><span class="p">){</span><span class="kd">var</span> <span class="nx">b</span><span class="o">=</span><span class="k">new</span> <span class="nb">Function</span><span class="p">(</span><span class="s2">&quot;obj&quot;</span><span class="p">,</span><span class="s2">&quot;var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push(&#39;&quot;</span><span class="o">+</span><span class="nx">c</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\\/g</span><span class="p">,</span><span class="s2">&quot;\\\\&quot;</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&#39;/g</span><span class="p">,</span><span class="s2">&quot;\\&#39;&quot;</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&lt;%=([\s\S]+?)%&gt;/g</span><span class="p">,</span><span class="kd">function</span><span class="p">(</span><span class="nx">d</span><span class="p">,</span><span class="nx">e</span><span class="p">){</span><span class="k">return</span><span class="s2">&quot;&#39;,&quot;</span><span class="o">+</span><span class="nx">e</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\\&#39;/g</span><span class="p">,</span><span class="s2">&quot;&#39;&quot;</span><span class="p">)</span><span class="o">+</span><span class="s2">&quot;,&#39;&quot;</span><span class="p">}).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&lt;%([\s\S]+?)%&gt;/g</span><span class="p">,</span><span class="kd">function</span><span class="p">(</span><span class="nx">d</span><span class="p">,</span><span class="nx">e</span><span class="p">){</span><span class="k">return</span><span class="s2">&quot;&#39;);&quot;</span><span class="o">+</span><span class="nx">e</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\\&#39;/g</span><span class="p">,</span><span class="s2">&quot;&#39;&quot;</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/[\r\n\t]/g</span><span class="p">,</span><span class="s2">&quot; &quot;</span><span class="p">)</span><span class="o">+</span><span class="s2">&quot;__p.push(&#39;&quot;</span><span class="p">}).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\r/g</span><span class="p">,</span><span class="s2">&quot;\\r&quot;</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\n/g</span><span class="p">,</span><span class="s2">&quot;\\n&quot;</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\t/g</span><span class="p">,</span><span class="s2">&quot;\\t&quot;</span><span class="p">)</span><span class="o">+</span><span class="s2">&quot;&#39;);}return __p.join(&#39;&#39;);&quot;</span><span class="p">);</span><span class="k">return</span> <span class="nx">b</span><span class="p">};</span><span class="nb">window</span><span class="p">.</span><span class="nx">JST</span><span class="p">.</span><span class="nx">card</span><span class="o">=</span><span class="nx">a</span><span class="p">(</span><span class="s1">&#39;&lt;div class=&quot;TS-card_container TS-card_container_&lt;%= (card.get(&quot;series&quot;) || &quot;&quot;).replace(/W/g, &quot;&quot;) %&gt;&quot;&gt;\n&lt;div class=&quot;TS-css_arrow TS-css_arrow_up TS-css_arrow_color_&lt;%= card.get(&quot;topcolor&quot;) %&gt;&quot;&gt;&lt;/div&gt;\n &lt;div class=&quot;TS-item TS-item_color_&lt;%= card.get(&quot;topcolor&quot;) %&gt;&quot; data-timestamp=&quot;&lt;%= card.get(&quot;timestamp&quot;) %&gt;&quot;&gt;\n &lt;div class=&quot;TS-item_label&quot;&gt;\n &lt;% if (!_.isEmpty(card.get(&quot;html&quot;))){ %&gt;\n &lt;div class=&quot;TS-item_user_html&quot;&gt;\n &lt;%= card.get(&quot;html&quot;) %&gt;\n &lt;/div&gt;\n &lt;% } %&gt;\n &lt;%= card.get(&quot;description&quot;) %&gt;\n &lt;/div&gt;\n &lt;% if (!_.isEmpty(card.get(&quot;link&quot;))){ %&gt;\n &lt;a class=&quot;TS-read_btn&quot; target=&quot;_blank&quot; href=&quot;&lt;%= card.get(&quot;link&quot;) %&gt;&quot;&gt;Read More&lt;/a&gt;\n &lt;% } %&gt;\n\n &lt;div class=&quot;TS-item_year&quot;&gt;\n &lt;span class=&quot;TS-item_year_text&quot;&gt;&lt;%= (card.get(&quot;display_date&quot;) || &quot;&quot;).length &gt; 0 ? card.get(&quot;display_date&quot;) : card.get(&quot;date&quot;) %&gt;&lt;/span&gt;\n &lt;div class=&quot;TS-permalink&quot;&gt;&amp;#8734;&lt;/div&gt;\n &lt;/div&gt;\n &lt;/div&gt;\n&lt;/div&gt;&#39;</span><span class="p">);</span><span class="nb">window</span><span class="p">.</span><span class="nx">JST</span><span class="p">.</span><span class="nx">notch</span><span class="o">=</span><span class="nx">a</span><span class="p">(</span><span class="s1">&#39;&lt;div class=&quot;TS-notch TS-notch_&lt;%= timestamp %&gt; TS-notch_&lt;%= series.replace(/W/g, &quot;&quot;) %&gt; TS-notch_color_&lt;%= topcolor %&gt;&quot;&gt;&lt;/div&gt;\n&#39;</span><span class="p">);</span><span class="nb">window</span><span class="p">.</span><span class="nx">JST</span><span class="p">.</span><span class="nx">series_legend</span><span class="o">=</span><span class="nx">a</span><span class="p">(</span><span class="s1">&#39;&lt;div class=&quot;TS-series_legend_item TS-series_legend_item_&lt;%= name.replace(/W/g, &quot;&quot;) %&gt;&quot;&gt;\n &lt;span class=&quot;TS-series_legend_swatch TS-series_legend_swatch_&lt;%= color %&gt;&quot;&gt;&amp;nbsp;&lt;/span&gt; &lt;span class=&quot;TS-series_legend_text&quot;&gt;&lt;%= name %&gt;&lt;/span&gt;\n&lt;/div&gt;\n&#39;</span><span class="p">);</span><span class="nb">window</span><span class="p">.</span><span class="nx">JST</span><span class="p">.</span><span class="nx">timeline</span><span class="o">=</span><span class="nx">a</span><span class="p">(</span><span class="s1">&#39;&lt;div class=&quot;timeline_setter&quot;&gt;\n &lt;div class=&quot;TS-top_matter_container&quot;&gt;\n &lt;div class=&quot;TS-controls&quot;&gt;\n &lt;a href=&quot;#&quot; class=&quot;TS-zoom TS-zoom_in&quot;&gt;&lt;span class=&quot;TS-controls_inner_text TS-zoom_inner_text&quot;&gt;+&lt;/span&gt;&lt;/a&gt; \n &lt;a href=&quot;#&quot; class=&quot;TS-zoom TS-zoom_out&quot;&gt;&lt;span class=&quot;TS-controls_inner_text TS-zoom_inner_text&quot;&gt;-&lt;/span&gt;&lt;/a&gt; \n &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; \n &lt;a href=&quot;#&quot; class=&quot;TS-choose TS-choose_prev&quot;&gt;&amp;laquo;&amp;nbsp;&lt;span class=&quot;TS-controls_inner_text&quot;&gt;Previous&lt;/span&gt;&lt;/a&gt; \n &lt;a href=&quot;#&quot; class=&quot;TS-choose TS-choose_next&quot;&gt;&lt;span class=&quot;TS-controls_inner_text&quot;&gt;Next&lt;/span&gt;&amp;nbsp;&amp;raquo;&lt;/a&gt;\n &lt;/div&gt;\n &lt;div class=&quot;TS-series_nav_container&quot;&gt;&lt;/div&gt;\n &lt;/div&gt;\n\n &lt;div class=&quot;TS-notchbar_container&quot;&gt;\n &lt;div class=&quot;TS-notchbar&quot;&gt;&lt;/div&gt;\n &lt;/div&gt;\n &lt;div class=&quot;TS-card_scroller&quot;&gt;\n &lt;div class=&quot;TS-card_scroller_inner&quot;&gt;\n &lt;/div&gt;\n &lt;/div&gt;\n&lt;/div&gt;&#39;</span><span class="p">);</span><span class="nb">window</span><span class="p">.</span><span class="nx">JST</span><span class="p">.</span><span class="nx">year_notch</span><span class="o">=</span><span class="nx">a</span><span class="p">(</span><span class="s1">&#39;&lt;div class=&quot;TS-year_notch TS-year_notch_&lt;%= timestamp %&gt;&quot;&gt;\n &lt;span class=&quot;TS-year_notch_year_text&quot;&gt;&lt;%= human %&gt;&lt;/span&gt;\n&lt;/div&gt;\n&#39;</span><span class="p">)})();</span>
2
+
3
+ </pre></div> </td> </tr> </tbody> </table> </div> </body> </html>