From 89a0bfd36a833579f4e0f05bf1e153f584753cd4 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sun, 16 Oct 2016 11:54:01 +0300 Subject: [PATCH 01/12] Add element to templates options --- lib/timeline/component/Group.js | 2 +- lib/timeline/component/item/Item.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/timeline/component/Group.js b/lib/timeline/component/Group.js index 512fac58..4927e034 100644 --- a/lib/timeline/component/Group.js +++ b/lib/timeline/component/Group.js @@ -88,7 +88,7 @@ Group.prototype.setData = function(data) { // update contents var content; if (this.itemSet.options && this.itemSet.options.groupTemplate) { - content = this.itemSet.options.groupTemplate(data); + content = this.itemSet.options.groupTemplate(data, this.dom.inner); } else { content = data && data.content; diff --git a/lib/timeline/component/item/Item.js b/lib/timeline/component/item/Item.js index ea5c7cbb..743e5944 100644 --- a/lib/timeline/component/item/Item.js +++ b/lib/timeline/component/item/Item.js @@ -190,7 +190,7 @@ Item.prototype._updateContents = function (element) { var content; if (this.options.template) { var itemData = this.parent.itemSet.itemsData.get(this.id); // get a clone of the data from the dataset - content = this.options.template(itemData); + content = this.options.template(itemData, element); } else { content = this.data.content; From b32f9428ff7725bc14e4e11ef5f8dc16336516a1 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sun, 16 Oct 2016 12:20:49 +0300 Subject: [PATCH 02/12] Fix comment typo --- lib/timeline/component/item/RangeItem.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/timeline/component/item/RangeItem.js b/lib/timeline/component/item/RangeItem.js index 98614607..01c94ed2 100644 --- a/lib/timeline/component/item/RangeItem.js +++ b/lib/timeline/component/item/RangeItem.js @@ -45,11 +45,11 @@ RangeItem.prototype.isVisible = function(range) { // determine visibility var isVisible = // determine horizontal visibillity - (this.data.start < range.end) && - (this.data.end > range.start) && -// determine verticaltal visibillity - (this.parent.top < range.body.domProps.centerContainer.height - range.body.domProps.scrollTop) && - (this.parent.top + this.parent.height > - range.body.domProps.scrollTop) +(this.data.start < range.end) && +(this.data.end > range.start) && +// determine vertical visibillity +(this.parent.top < range.body.domProps.centerContainer.height - range.body.domProps.scrollTop) && +(this.parent.top + this.parent.height > - range.body.domProps.scrollTop) return isVisible;}; /** From 092186857b8a35388f50911152d1cd373e9ae578 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sun, 16 Oct 2016 12:33:42 +0300 Subject: [PATCH 03/12] Add documentation for react mounting --- docs/timeline/index.html | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/timeline/index.html b/docs/timeline/index.html index f11d1c89..4ca5975e 100644 --- a/docs/timeline/index.html +++ b/docs/timeline/index.html @@ -640,7 +640,7 @@ function (option, path) { groupTemplate function none - A template function used to generate the contents of the groups. The function is called by the Timeline with a groups data as argument, and must return HTML code as result. When the option groupTemplate is specified, the groups do not need to have a field content. See section Templates for a detailed explanation. + A template function used to generate the contents of the groups. The function is called by the Timeline with a groups data as the first argument and the group element as the second, and must return HTML code as result. When the option groupTemplate is specified, the groups do not need to have a field content. See section Templates for a detailed explanation. @@ -970,7 +970,7 @@ function (option, path) { template function none - A template function used to generate the contents of the items. The function is called by the Timeline with an items data as argument, and must return HTML code as result. When the option template is specified, the items do not need to have a field content. See section Templates for a detailed explanation. + A template function used to generate the contents of the items. The function is called by the Timeline with an items data as the first argument and the item element as the second, and must return HTML code as result. When the option template is specified, the items do not need to have a field content. See section Templates for a detailed explanation. @@ -1629,6 +1629,17 @@ var template = Handlebars.compile(source); }; +

React templates

+ +You can use a React component for the templates by rendering them to the templates' element directly: + +
+  template: function (item, element) {
+    return ReactDOM.render(<b>{item.content}</b>, element);
+  },
+
+ +

Multiple templates

In order to support multiple templates, the template handler can be extended to switch between different templates, depending on a specific item property: From 06c264e5b627c320f2d7474b251b1ccaa285e04c Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sat, 22 Oct 2016 13:07:29 +0300 Subject: [PATCH 04/12] add react example --- examples/timeline/other/usingReact.html | 131 ++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 examples/timeline/other/usingReact.html diff --git a/examples/timeline/other/usingReact.html b/examples/timeline/other/usingReact.html new file mode 100644 index 00000000..2e59d418 --- /dev/null +++ b/examples/timeline/other/usingReact.html @@ -0,0 +1,131 @@ + + + + + React Hello World + + + +
+ + + + + + + + + + + + + \ No newline at end of file From 17c48c7967d2a5c3995133ae61d19173458dfeab Mon Sep 17 00:00:00 2001 From: yotamberk Date: Sat, 22 Oct 2016 13:13:04 +0300 Subject: [PATCH 05/12] Fix typo --- examples/timeline/other/usingReact.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/timeline/other/usingReact.html b/examples/timeline/other/usingReact.html index 2e59d418..dea32d95 100644 --- a/examples/timeline/other/usingReact.html +++ b/examples/timeline/other/usingReact.html @@ -113,7 +113,7 @@ render: function() { return

Vis timline with React

-

Using react components for items ang group templates

+

Using react components for items and group templates

@@ -128,4 +128,4 @@ ReactDOM.render(, document.getElementById('root')); - \ No newline at end of file + From 42c054ff540b15db8f91d01c7824b3f73b7c4208 Mon Sep 17 00:00:00 2001 From: yotamberk Date: Sat, 22 Oct 2016 13:37:57 +0300 Subject: [PATCH 06/12] fix title --- examples/timeline/other/usingReact.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/timeline/other/usingReact.html b/examples/timeline/other/usingReact.html index dea32d95..4f7c2470 100644 --- a/examples/timeline/other/usingReact.html +++ b/examples/timeline/other/usingReact.html @@ -2,7 +2,7 @@ - React Hello World + React Components in templates From 342091d180ff6badfe2a1631adf809c3d326cb22 Mon Sep 17 00:00:00 2001 From: Yotam Berkowitz Date: Sat, 22 Oct 2016 17:51:52 +0300 Subject: [PATCH 07/12] Fix review comments --- examples/timeline/other/usingReact.html | 50 +++++++++++-------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/examples/timeline/other/usingReact.html b/examples/timeline/other/usingReact.html index 2e59d418..1d276499 100644 --- a/examples/timeline/other/usingReact.html +++ b/examples/timeline/other/usingReact.html @@ -2,7 +2,7 @@ - React Hello World + React Components in templates @@ -17,8 +17,8 @@ to compile JSX into JavaScript. Also, check out: http://facebook.github.io/react/docs/tooling-integration.html --> - - + + @@ -30,7 +30,7 @@ -->