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.
- data/Rakefile +11 -2
- data/config/assets.yml +9 -0
- data/doc/doc.markdown +65 -17
- data/doc/templates.html +3 -0
- data/doc/timeline-setter.html +327 -238
- data/doc/timeline-setter.min.html +3 -0
- data/documentation/TimelineSetter/CLI.html +77 -52
- data/documentation/TimelineSetter/Parser.html +40 -39
- data/documentation/TimelineSetter/Timeline.html +132 -83
- data/documentation/TimelineSetter.html +27 -12
- data/documentation/_index.html +23 -12
- data/documentation/class_list.html +20 -9
- data/documentation/css/style.css +7 -5
- data/documentation/file.README.html +33 -23
- data/documentation/file_list.html +20 -9
- data/documentation/frames.html +1 -1
- data/documentation/index.html +33 -23
- data/documentation/js/app.js +16 -14
- data/documentation/js/full_list.js +7 -6
- data/documentation/js/jquery.js +3 -3
- data/documentation/method_list.html +42 -23
- data/documentation/top-level-namespace.html +26 -11
- data/index.html +100 -19
- data/lib/timeline_setter/cli.rb +2 -0
- data/lib/timeline_setter/timeline.rb +6 -3
- data/lib/timeline_setter/version.rb +1 -1
- data/lib/timeline_setter.rb +0 -7
- data/public/javascripts/templates/card.jst +21 -0
- data/public/javascripts/templates/notch.jst +1 -0
- data/public/javascripts/templates/series_legend.jst +3 -0
- data/public/javascripts/templates/timeline.jst +20 -0
- data/public/javascripts/templates/year_notch.jst +3 -0
- data/public/javascripts/templates.js +1 -0
- data/public/javascripts/timeline-setter.js +303 -167
- data/public/javascripts/timeline-setter.min.js +1 -0
- data/public/stylesheets/timeline-setter.css +5 -5
- data/spec/timeline_setter_spec.rb +2 -2
- data/templates/timeline-markup.erb +5 -59
- data/timeline_setter.gemspec +15 -5
- 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 "
|
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
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
|
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) --
|
178
|
-
templates for each part of the timeline reside in the
|
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
|
-
|
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
|
-
|
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
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
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
|
|
data/doc/templates.html
ADDED
@@ -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 … <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">¶</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">"obj"</span><span class="p">,</span><span class="s2">"var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"</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">"\\\\"</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">"\\'"</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/<%=([\s\S]+?)%>/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">"',"</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">/\\'/g</span><span class="p">,</span><span class="s2">"'"</span><span class="p">)</span><span class="o">+</span><span class="s2">",'"</span><span class="p">}).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/<%([\s\S]+?)%>/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">"');"</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">/\\'/g</span><span class="p">,</span><span class="s2">"'"</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">" "</span><span class="p">)</span><span class="o">+</span><span class="s2">"__p.push('"</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">"\\r"</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">"\\n"</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">"\\t"</span><span class="p">)</span><span class="o">+</span><span class="s2">"');}return __p.join('');"</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">'<div class="TS-card_container TS-card_container_<%= (card.get("series") || "").replace(/W/g, "") %>">\n<div class="TS-css_arrow TS-css_arrow_up TS-css_arrow_color_<%= card.get("topcolor") %>"></div>\n <div class="TS-item TS-item_color_<%= card.get("topcolor") %>" data-timestamp="<%= card.get("timestamp") %>">\n <div class="TS-item_label">\n <% if (!_.isEmpty(card.get("html"))){ %>\n <div class="TS-item_user_html">\n <%= card.get("html") %>\n </div>\n <% } %>\n <%= card.get("description") %>\n </div>\n <% if (!_.isEmpty(card.get("link"))){ %>\n <a class="TS-read_btn" target="_blank" href="<%= card.get("link") %>">Read More</a>\n <% } %>\n\n <div class="TS-item_year">\n <span class="TS-item_year_text"><%= (card.get("display_date") || "").length > 0 ? card.get("display_date") : card.get("date") %></span>\n <div class="TS-permalink">&#8734;</div>\n </div>\n </div>\n</div>'</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">'<div class="TS-notch TS-notch_<%= timestamp %> TS-notch_<%= series.replace(/W/g, "") %> TS-notch_color_<%= topcolor %>"></div>\n'</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">'<div class="TS-series_legend_item TS-series_legend_item_<%= name.replace(/W/g, "") %>">\n <span class="TS-series_legend_swatch TS-series_legend_swatch_<%= color %>">&nbsp;</span> <span class="TS-series_legend_text"><%= name %></span>\n</div>\n'</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">'<div class="timeline_setter">\n <div class="TS-top_matter_container">\n <div class="TS-controls">\n <a href="#" class="TS-zoom TS-zoom_in"><span class="TS-controls_inner_text TS-zoom_inner_text">+</span></a> \n <a href="#" class="TS-zoom TS-zoom_out"><span class="TS-controls_inner_text TS-zoom_inner_text">-</span></a> \n &nbsp;&nbsp;&nbsp;&nbsp; \n <a href="#" class="TS-choose TS-choose_prev">&laquo;&nbsp;<span class="TS-controls_inner_text">Previous</span></a> \n <a href="#" class="TS-choose TS-choose_next"><span class="TS-controls_inner_text">Next</span>&nbsp;&raquo;</a>\n </div>\n <div class="TS-series_nav_container"></div>\n </div>\n\n <div class="TS-notchbar_container">\n <div class="TS-notchbar"></div>\n </div>\n <div class="TS-card_scroller">\n <div class="TS-card_scroller_inner">\n </div>\n </div>\n</div>'</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">'<div class="TS-year_notch TS-year_notch_<%= timestamp %>">\n <span class="TS-year_notch_year_text"><%= human %></span>\n</div>\n'</span><span class="p">)})();</span>
|
2
|
+
|
3
|
+
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|