Skip to content

Commit

Permalink
Update Timeline(element, data) API
Browse files Browse the repository at this point in the history
  • Loading branch information
hotoo committed Sep 28, 2014
1 parent 11f3707 commit 0baaf07
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 28 deletions.
35 changes: 21 additions & 14 deletions examples/timeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,27 @@

````javascript
seajs.use('../timeline', function(Markline) {
var line = new Markline("#demo", "DEMO", {age:"show"}, {
"default": [
{
"name": "text",
"date-start": new Date("1983/08/08"),
"date-end": new Date("2010/08/18"),
"events": [
{
"date": new Date("2014/08/09"),
"name": "event 1"
}
]
}
]
var line = new Markline("#demo", {
title: "DEMO",
meta: {
age: "show"
},
body: {
"default": [
{
"name": "text",
"date-start": new Date("1983/08/08"),
"date-end": new Date("1994/08/18"),
"events": [
{
"date-start": new Date("1984/02/09"),
"date-end": new Date("1985/06/09"),
"name": "event 1"
}
]
}
]
}
});
line.render();
});
Expand Down
14 changes: 7 additions & 7 deletions markline.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Markline(element, markdown){
this.element = element;

var data = parse(markdown);
this.timeline = new Timeline(this.element, data.title, data.meta, data.data);
this.timeline = new Timeline(this.element, data);
}

// @param {String} date
Expand Down Expand Up @@ -79,7 +79,7 @@ function parse(markdown){
var data = {
title: "",
meta: {},
data: {}
body: {}
};

var re_title = /^#\s+(.*)$/;
Expand All @@ -95,11 +95,11 @@ function parse(markdown){
var inmeta = false;

function addGroup(group_name){
while (data.data.hasOwnProperty(group_name)) {
while (data.body.hasOwnProperty(group_name)) {
group_name += " ";
}
current_group = parseMarkdown(group_name);
data.data[current_group] = [];
data.body[current_group] = [];

inline = true;
}
Expand All @@ -124,8 +124,8 @@ function parse(markdown){
} else if (match = text_line.match(re_line)){
// PARSE EVENT LINES.

if (!data.data[current_group]){
data.data[current_group] = [];
if (!data.body[current_group]){
data.body[current_group] = [];
}

var line_start = match[2];
Expand All @@ -138,7 +138,7 @@ function parse(markdown){
"name": parseMarkdown(line_name),
"events": []
};
data.data[current_group].push(data_line);
data.body[current_group].push(data_line);
current_line = data_line;

inline = true;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "markline",
"version": "0.2.2",
"version": "0.3.0",
"description": "Timeline via Markdown",
"keywords": ["Timeline", "Markdown"],
"homepage": "https://github.com/hotoo/markline",
Expand Down
12 changes: 6 additions & 6 deletions timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ var offset_top = 20;

var year_width = 100;

function Markline (element, title, meta, data) {
function Markline (element, data) {
this._element = $(element);
this.title = title || "";
this.meta = meta || {};
this._data = data || {};
this.title = data.title || "";
this.meta = data.meta || {};
this.body = data.body || {};
}

function calcLength(distance){
Expand Down Expand Up @@ -67,7 +67,7 @@ Markline.prototype.render = function(){
var min_date;
var max_date;

this._process(this._data, {
this._process(this.body, {
"line:start": function(line){

var date_start = line["date-start"];
Expand Down Expand Up @@ -105,7 +105,7 @@ Markline.prototype.render = function(){
var body_events = ['<div class="events" id="events">'];
var current_line_offset_left = 0;

this._process(this._data, {
this._process(this.body, {
"group:start": function(group_name){
body_events.push(
'<div class="groups">',
Expand Down

0 comments on commit 0baaf07

Please sign in to comment.