From 0baaf07bacb772effff2e932a0b608faa4a9a82f Mon Sep 17 00:00:00 2001 From: hotoo Date: Sun, 28 Sep 2014 20:33:00 +0800 Subject: [PATCH] Update Timeline(element, data) API --- examples/timeline.md | 35 +++++++++++++++++++++-------------- markline.js | 14 +++++++------- package.json | 2 +- timeline.js | 12 ++++++------ 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/examples/timeline.md b/examples/timeline.md index e3ed5bd..c3059f2 100644 --- a/examples/timeline.md +++ b/examples/timeline.md @@ -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(); }); diff --git a/markline.js b/markline.js index c78a1d4..678d3c2 100644 --- a/markline.js +++ b/markline.js @@ -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 @@ -79,7 +79,7 @@ function parse(markdown){ var data = { title: "", meta: {}, - data: {} + body: {} }; var re_title = /^#\s+(.*)$/; @@ -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; } @@ -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]; @@ -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; diff --git a/package.json b/package.json index f3da82d..b55600f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/timeline.js b/timeline.js index 2540cd7..b5c6ced 100644 --- a/timeline.js +++ b/timeline.js @@ -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){ @@ -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"]; @@ -105,7 +105,7 @@ Markline.prototype.render = function(){ var body_events = ['
']; var current_line_offset_left = 0; - this._process(this._data, { + this._process(this.body, { "group:start": function(group_name){ body_events.push( '
',