├── .gitignore
├── .gitmodules
├── Makefile
├── Readme.markdown
├── examples
├── noend.html
├── progressive.html
├── simple.html
└── twix.html
├── files
├── timestack.css
├── timestack.js
└── timestack.min.js
├── package.json
└── src
├── timestack.coffee
└── timestack.less
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | *.sublime-workspace
3 | *#
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "vendor/moment"]
2 | path = vendor/moment
3 | url = git://github.com/moment/moment.git
4 | [submodule "vendor/twix"]
5 | path = vendor/twix
6 | url = git://github.com/icambron/twix.js.git
7 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | build:
2 | @node_modules/coffee-script/bin/coffee -c -o files src/timestack.coffee
3 | @node_modules/uglify-js/bin/uglifyjs files/timestack.js > files/timestack.min.js
4 | @node_modules/less/bin/lessc src/timestack.less > files/timestack.css
5 |
--------------------------------------------------------------------------------
/Readme.markdown:
--------------------------------------------------------------------------------
1 | [Timestack](http://icambron.github.com/timestack)
2 | =================================================
3 |
4 | Timestack is a simple jQuery plugin for generating pretty, clickable timelines for the web.
5 |
6 | ### [Documentation](http://icambron.github.com/timestack)
7 |
8 | ### More info
9 |
10 | Here's a [blog post](http://isaaccambron.com/blog/2012/08/27/introducing-timestack.html) about Timestack.
11 |
12 | ### Building/Contributing
13 |
14 | Timestack is written in [CoffeeScript](http://coffeescript.org/) and [Less](http://lesscss.org/). You can find the source files in `/src`; the output directory is `/files`.
15 |
16 | To get started, fork the repository, clone it, and run:
17 |
18 | ```
19 | npm install
20 | ```
21 |
22 | To build just run
23 |
24 | ```
25 | make
26 | ```
27 |
28 | ### Acknowledgements
29 |
30 | The CSS here is based on work by [Matt Bango](http:///mattbango.com); the original can be found [here](http://mattbango.com/notebook/web-development/pure-css-timeline/). It's distributed here under the MIT license with permission from Matt.
31 |
32 | ### License (MIT)
33 |
34 | Copyright (c) 2012 Isaac Cambron
35 |
36 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
37 |
38 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
39 |
40 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 |
--------------------------------------------------------------------------------
/examples/noend.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
15 |
16 |
46 |
52 |
53 |
54 | Ranges don't have to end
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/examples/progressive.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
14 |
15 |
27 |
28 |
29 |
30 | Progressively enhancing an existing UL.
31 |
42 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/examples/simple.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
15 |
16 |
58 |
64 |
65 |
66 | You can click on events to see more info.
67 |
68 |
69 |
70 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/examples/twix.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
16 |
17 |
62 |
63 |
64 | Similar to the simple example , but notice the more subtle formatting of the time ranges.
65 |
66 |
67 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/files/timestack.css:
--------------------------------------------------------------------------------
1 | /*
2 | Based off CSS code by Matt Bango: http://mattbango.com/notebook/web-development/pure-css-timeline/
3 | Released with permission under the MIT license.
4 | */
5 | ul.timestack-events {
6 | list-style-type: none;
7 | margin: 0;
8 | padding: 0 0 20px 0;
9 | width: 100%;
10 | }
11 | ul.timestack-events li {
12 | box-sizing: border-box;
13 | -moz-box-sizing: border-box;
14 | -webkit-box-sizing: border-box;
15 | margin-bottom: 6px;
16 | position: relative;
17 | text-align: center;
18 | padding-left: 5px;
19 | padding-right: 5px;
20 | color: #707070;
21 | background-color: #eee;
22 | -webkit-border-radius: 11px;
23 | -moz-border-radius: 11px;
24 | border-radius: 11px;
25 | border: 1px solid #ddd;
26 | font-size: 1.2em;
27 | font-weight: bold;
28 | }
29 | ul.timestack-events li em {
30 | font-weight: normal;
31 | font-size: 0.9em;
32 | }
33 | ul.intervals {
34 | list-style-type: none;
35 | padding: 0;
36 | margin: 0;
37 | display: block;
38 | width: 100%;
39 | }
40 | ul.intervals li {
41 | box-sizing: border-box;
42 | -moz-box-sizing: border-box;
43 | -webkit-box-sizing: border-box;
44 | border-right: 1px solid #ccc;
45 | color: #999 !default;
46 | float: left;
47 | font-size: 1.2em;
48 | margin: 0;
49 | padding: 15px 0;
50 | text-align: center;
51 | }
52 | ul.intervals li:first-child {
53 | border-left: 1px solid #ccc;
54 | }
55 | ul.intervals:after {
56 | content: ".";
57 | visibility: hidden;
58 | display: block;
59 | height: 0;
60 | clear: both;
61 | margin-bottom: 8px;
62 | }
63 |
--------------------------------------------------------------------------------
/files/timestack.js:
--------------------------------------------------------------------------------
1 | // Generated by CoffeeScript 1.6.3
2 | /*
3 | Timestack
4 | http://icambron.github.com/timestack
5 | Copyright 2012 Isaac Cambron
6 | Released under the MIT license, license here: https://github.com/icambron/timestack/blob/master/Readme.markdown
7 | */
8 |
9 |
10 | (function() {
11 | (function(jQuery) {
12 | var $;
13 | $ = jQuery;
14 | return $.fn.extend({
15 | timestack: function(options) {
16 | var between, defaults, findEnds, parseDom, useData;
17 | defaults = {
18 | click: function() {},
19 | parse: function(s) {
20 | return moment(s);
21 | },
22 | renderDates: function(item) {
23 | var dateFormat, endFormated, startFormated;
24 | dateFormat = this.dateFormats[options.span];
25 | startFormated = item.start.format(dateFormat);
26 | endFormated = item.tilNow ? '' : item.end.format(dateFormat);
27 | return this.formatRange(startFormated, endFormated);
28 | },
29 | formatRange: function(startStr, endStr) {
30 | return "" + startStr + " - " + endStr;
31 | },
32 | span: 'year',
33 | dateFormats: {
34 | year: 'MMM YYYY',
35 | month: 'MMM DD',
36 | day: 'MMM DD',
37 | hour: 'h:mm a'
38 | },
39 | intervalFormats: {
40 | year: 'YYYY',
41 | month: 'MMM YYYY',
42 | day: 'MMM DD',
43 | hour: 'h:mm a'
44 | }
45 | };
46 | options = $.extend(defaults, options);
47 | if (!(['year', 'month', 'day', 'hour'].indexOf(options.span) > -1)) {
48 | throw "" + options.span + " is not a valid span option";
49 | }
50 | parseDom = function($obj) {
51 | var $ul;
52 | $ul = $obj.children('ul:not(.timestack-events)');
53 | if ($ul.length === 0) {
54 | return [];
55 | }
56 | return [
57 | $ul, $ul.children('li').map(function() {
58 | var $li, i;
59 | $li = $(this);
60 | return i = {
61 | start: $li.attr('data-start'),
62 | end: $li.attr('data-end'),
63 | title: $li.contents().filter(function() {
64 | return this.nodeType === 3;
65 | }).remove().text(),
66 | color: $li.attr('data-color'),
67 | li: $li,
68 | content: $li.children().remove()
69 | };
70 | })
71 | ];
72 | };
73 | useData = function($obj, items) {
74 | var $ul;
75 | $obj.empty();
76 | $ul = $("");
77 | $obj.append($ul);
78 | return [$ul, items];
79 | };
80 | findEnds = function(items) {
81 | var earliest, i, latest, _i, _len;
82 | earliest = null;
83 | latest = null;
84 | for (_i = 0, _len = items.length; _i < _len; _i++) {
85 | i = items[_i];
86 | i.start = options.parse(i.start);
87 | i.tilNow = i.end == null;
88 | i.end = i.tilNow ? moment() : options.parse(i.end);
89 | if (!(i.start <= i.end)) {
90 | throw 'Start times must be before end times';
91 | }
92 | if (!(earliest && earliest < i.start)) {
93 | earliest = i.start.clone();
94 | }
95 | if (!(latest && latest > i.end)) {
96 | latest = i.end.clone();
97 | }
98 | }
99 | return [earliest, latest];
100 | };
101 | between = function(start, end) {
102 | var index, results;
103 | results = [];
104 | index = start.clone().startOf(options.span);
105 | while (index < end) {
106 | results.push(index.clone());
107 | index.add(options.span + 's', 1);
108 | }
109 | return results;
110 | };
111 | return this.each(function() {
112 | var $intervals, $li, $obj, $ul, date, dates, diff, earliest, format, i, items, labelspan, latest, offset, timespan, titlespan, width, _i, _j, _len, _len1, _ref, _ref1, _ref2;
113 | $obj = $(this);
114 | if (options.data) {
115 | _ref = useData($obj, options.data), $ul = _ref[0], items = _ref[1];
116 | } else {
117 | _ref1 = parseDom($obj), $ul = _ref1[0], items = _ref1[1];
118 | }
119 | if (items.length === 0) {
120 | return;
121 | }
122 | if (!$ul) {
123 | throw "Timestack requires either a data object or a UL for progressive enhancement.";
124 | }
125 | $ul.css('width', options.width).addClass('timestack-events');
126 | _ref2 = findEnds(items), earliest = _ref2[0], latest = _ref2[1];
127 | earliest.startOf(options.span);
128 | if (latest.valueOf() !== latest.clone().startOf(options.span).valueOf()) {
129 | latest.endOf(options.span);
130 | }
131 | diff = latest - earliest;
132 | for (_i = 0, _len = items.length; _i < _len; _i++) {
133 | i = items[_i];
134 | $li = i.li;
135 | if (!$li) {
136 | $li = $(" ");
137 | $ul.append($li);
138 | }
139 | i.timeDisplay = options.renderDates(i);
140 | timespan = $("(" + i.timeDisplay + ") ").addClass('timestack-time');
141 | titlespan = $("" + i.title + " ").addClass("timestack-title");
142 | labelspan = $(" ").addClass('timestack-label').append(titlespan).append(timespan);
143 | width = ((i.end - i.start) / diff * 100 - 0.01).toFixed(3);
144 | offset = ((i.start - earliest) / diff * 100 - 0.01).toFixed(3);
145 | $li.prepend(labelspan).css("margin-left", "" + offset + "%").css("width", "" + width + "%").click((function(i) {
146 | return function() {
147 | return options.click(i);
148 | };
149 | })(i));
150 | if (i.color) {
151 | $li.css('background-color', i.color);
152 | }
153 | if (options.click) {
154 | $li.css('cursor', 'pointer');
155 | }
156 | if (i["class"] != null) {
157 | $li.addClass(i["class"]);
158 | }
159 | }
160 | dates = between(earliest, latest);
161 | width = (100 / dates.length - 0.01).toFixed(3) + "%";
162 | format = options.intervalFormats[options.span];
163 | $intervals = $("").addClass("intervals");
164 | for (_j = 0, _len1 = dates.length; _j < _len1; _j++) {
165 | date = dates[_j];
166 | $(" ").text(date.format(format)).css('width', width).appendTo($intervals);
167 | }
168 | return $obj.append($intervals);
169 | });
170 | }
171 | });
172 | })(jQuery);
173 |
174 | }).call(this);
175 |
--------------------------------------------------------------------------------
/files/timestack.min.js:
--------------------------------------------------------------------------------
1 | (function(){(function(jQuery){var $;$=jQuery;return $.fn.extend({timestack:function(options){var between,defaults,findEnds,parseDom,useData;defaults={click:function(){},parse:function(s){return moment(s)},renderDates:function(item){var dateFormat,endFormated,startFormated;dateFormat=this.dateFormats[options.span];startFormated=item.start.format(dateFormat);endFormated=item.tilNow?"":item.end.format(dateFormat);return this.formatRange(startFormated,endFormated)},formatRange:function(startStr,endStr){return""+startStr+" - "+endStr},span:"year",dateFormats:{year:"MMM YYYY",month:"MMM DD",day:"MMM DD",hour:"h:mm a"},intervalFormats:{year:"YYYY",month:"MMM YYYY",day:"MMM DD",hour:"h:mm a"}};options=$.extend(defaults,options);if(!(["year","month","day","hour"].indexOf(options.span)>-1)){throw""+options.span+" is not a valid span option"}parseDom=function($obj){var $ul;$ul=$obj.children("ul:not(.timestack-events)");if($ul.length===0){return[]}return[$ul,$ul.children("li").map(function(){var $li,i;$li=$(this);return i={start:$li.attr("data-start"),end:$li.attr("data-end"),title:$li.contents().filter(function(){return this.nodeType===3}).remove().text(),color:$li.attr("data-color"),li:$li,content:$li.children().remove()}})]};useData=function($obj,items){var $ul;$obj.empty();$ul=$("");$obj.append($ul);return[$ul,items]};findEnds=function(items){var earliest,i,latest,_i,_len;earliest=null;latest=null;for(_i=0,_len=items.length;_i<_len;_i++){i=items[_i];i.start=options.parse(i.start);i.tilNow=i.end==null;i.end=i.tilNow?moment():options.parse(i.end);if(!(i.start<=i.end)){throw"Start times must be before end times"}if(!(earliest&&earliesti.end)){latest=i.end.clone()}}return[earliest,latest]};between=function(start,end){var index,results;results=[];index=start.clone().startOf(options.span);while(index");$ul.append($li)}i.timeDisplay=options.renderDates(i);timespan=$("("+i.timeDisplay+") ").addClass("timestack-time");titlespan=$(""+i.title+" ").addClass("timestack-title");labelspan=$(" ").addClass("timestack-label").append(titlespan).append(timespan);width=((i.end-i.start)/diff*100-.01).toFixed(3);offset=((i.start-earliest)/diff*100-.01).toFixed(3);$li.prepend(labelspan).css("margin-left",""+offset+"%").css("width",""+width+"%").click(function(i){return function(){return options.click(i)}}(i));if(i.color){$li.css("background-color",i.color)}if(options.click){$li.css("cursor","pointer")}if(i["class"]!=null){$li.addClass(i["class"])}}dates=between(earliest,latest);width=(100/dates.length-.01).toFixed(3)+"%";format=options.intervalFormats[options.span];$intervals=$("").addClass("intervals");for(_j=0,_len1=dates.length;_j<_len1;_j++){date=dates[_j];$(" ").text(date.format(format)).css("width",width).appendTo($intervals)}return $obj.append($intervals)})}})})(jQuery)}).call(this);
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "timestack",
3 | "version": "0.0.1",
4 | "author": "Isaac Cambron",
5 | "dependencies": {
6 | },
7 | "devDependencies": {
8 | "uglify-js" : "*",
9 | "less": "*",
10 | "coffee-script": "*"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/timestack.coffee:
--------------------------------------------------------------------------------
1 | ###
2 | Timestack
3 | http://icambron.github.com/timestack
4 | Copyright 2012 Isaac Cambron
5 | Released under the MIT license, license here: https://github.com/icambron/timestack/blob/master/Readme.markdown
6 | ###
7 | do (jQuery) ->
8 | $ = jQuery
9 |
10 | $.fn.extend
11 | timestack: (options) ->
12 | defaults =
13 | click: ->
14 | parse: (s) -> moment(s)
15 | renderDates: (item) ->
16 | dateFormat = @dateFormats[options.span]
17 | startFormated = item.start.format dateFormat
18 | endFormated = if item.tilNow then '' else item.end.format dateFormat
19 | @formatRange startFormated, endFormated
20 | formatRange: (startStr, endStr) -> "#{startStr} - #{endStr}"
21 | span: 'year'
22 | dateFormats:
23 | year: 'MMM YYYY'
24 | month: 'MMM DD'
25 | day: 'MMM DD'
26 | hour: 'h:mm a'
27 | intervalFormats:
28 | year: 'YYYY'
29 | month: 'MMM YYYY'
30 | day: 'MMM DD'
31 | hour: 'h:mm a'
32 |
33 | options = $.extend defaults, options
34 |
35 | throw "#{options.span} is not a valid span option" unless ['year', 'month', 'day', 'hour'].indexOf(options.span) > -1
36 |
37 | parseDom = ($obj) ->
38 | $ul = $obj.children('ul:not(.timestack-events)')
39 |
40 | return [] if $ul.length == 0
41 |
42 | [
43 | $ul
44 | $ul.children('li').map ->
45 | $li = $ @
46 | i = {
47 | start: $li.attr 'data-start'
48 | end: $li.attr 'data-end'
49 | title: $li.contents().filter(-> @nodeType == 3).remove().text()
50 | color: $li.attr('data-color')
51 | li: $li
52 | content: $li.children().remove()
53 | }
54 | ]
55 |
56 | useData = ($obj, items) ->
57 | $obj.empty()
58 | $ul = $("")
59 | $obj.append $ul
60 | [$ul, items]
61 |
62 | findEnds = (items) ->
63 | earliest = null
64 | latest = null
65 |
66 | for i in items
67 |
68 | i.start = options.parse(i.start)
69 | i.tilNow = !i.end?
70 | i.end = if i.tilNow then moment() else options.parse(i.end)
71 |
72 | throw 'Start times must be before end times' unless i.start <= i.end
73 |
74 | earliest = i.start.clone() unless earliest && earliest < i.start
75 | latest = i.end.clone() unless latest && latest > i.end
76 |
77 | [earliest, latest]
78 |
79 | between = (start, end) ->
80 | results = []
81 | index = start.clone().startOf(options.span)
82 | while index < end
83 | results.push index.clone()
84 | index.add(options.span + 's', 1)
85 | results
86 |
87 | @each ->
88 | $obj = $ @
89 |
90 | if options.data
91 | [$ul, items] = useData($obj, options.data)
92 | else
93 | [$ul, items] = parseDom $obj
94 |
95 | return if items.length == 0
96 |
97 | throw "Timestack requires either a data object or a UL for progressive enhancement." unless $ul
98 |
99 | $ul
100 | .css('width', options.width)
101 | .addClass('timestack-events')
102 |
103 | [earliest, latest] = findEnds items
104 |
105 | earliest.startOf options.span
106 | unless latest.valueOf() == latest.clone().startOf(options.span).valueOf()
107 | latest.endOf options.span
108 |
109 | diff = latest - earliest
110 |
111 | for i in items
112 | $li = i.li
113 |
114 | unless $li
115 | $li = $(" ")
116 | $ul.append $li
117 |
118 | i.timeDisplay = options.renderDates i
119 |
120 | timespan = $("(#{i.timeDisplay}) ").addClass('timestack-time')
121 | titlespan = $("#{i.title} ").addClass("timestack-title")
122 |
123 | labelspan = $(" ")
124 | .addClass('timestack-label')
125 | .append(titlespan)
126 | .append(timespan)
127 |
128 | width = ((i.end - i.start)/diff * 100 - 0.01).toFixed(3)
129 | offset = ((i.start - earliest)/diff * 100 - 0.01).toFixed(3)
130 |
131 | $li
132 | .prepend(labelspan)
133 | .css("margin-left", "#{offset}%")
134 | .css("width", "#{width}%")
135 | .click(do (i) -> -> options.click i)
136 |
137 | $li.css('background-color', i.color) if i.color
138 | $li.css('cursor', 'pointer') if options.click
139 |
140 | $li.addClass(i.class) if i.class?
141 |
142 | dates = between earliest, latest
143 | width = (100/dates.length - 0.01).toFixed(3) + "%"
144 | format = options.intervalFormats[options.span]
145 | $intervals = $("").addClass("intervals")
146 | for date in dates
147 | $(" ")
148 | .text(date.format(format))
149 | .css('width', width)
150 | .appendTo($intervals)
151 | $obj.append($intervals)
152 |
--------------------------------------------------------------------------------
/src/timestack.less:
--------------------------------------------------------------------------------
1 | /*
2 | Based off CSS code by Matt Bango: http://mattbango.com/notebook/web-development/pure-css-timeline/
3 | Released with permission under the MIT license.
4 | */
5 | .border-box() {
6 | box-sizing:border-box;
7 | -moz-box-sizing:border-box;
8 | -webkit-box-sizing:border-box
9 | }
10 |
11 | ul.timestack-events {
12 |
13 | list-style-type: none;
14 | margin: 0;
15 | padding: 0 0 20px 0;
16 | width: 100%;
17 |
18 | li {
19 |
20 | .border-box;
21 |
22 | //position
23 | margin-bottom: 6px;
24 | position: relative;
25 | text-align: center;
26 | padding-left: 5px;
27 | padding-right: 5px;
28 |
29 | //color
30 | color: #707070;
31 | background-color: #eee;
32 |
33 | //border
34 | -webkit-border-radius: 11px;
35 | -moz-border-radius: 11px;
36 | border-radius: 11px;
37 | border: 1px solid #ddd;
38 |
39 | //font
40 | font-size: 1.2em;
41 | font-weight: bold;
42 |
43 | em {
44 | font-weight: normal;
45 | font-size: 0.9em;
46 | }
47 | }
48 | }
49 |
50 | ul.intervals {
51 |
52 | list-style-type: none;
53 | padding: 0;
54 | margin: 0;
55 | display: block;
56 | width: 100%;
57 |
58 | li {
59 | .border-box;
60 | border-right: 1px solid #ccc;
61 | color: #999 !default;
62 | float: left;
63 | font-size: 1.2em;
64 | margin: 0;
65 | padding: 15px 0;
66 | text-align: center;
67 | }
68 |
69 | li:first-child {
70 | border-left: 1px solid #ccc;
71 | }
72 | }
73 |
74 | ul.intervals:after {
75 | content: ".";
76 | visibility: hidden;
77 | display: block;
78 | height: 0;
79 | clear: both;
80 | margin-bottom: 8px;
81 | }
82 |
--------------------------------------------------------------------------------