diff --git a/examples/timeline/other/usingReact.html b/examples/timeline/other/usingReact.html
new file mode 100644
index 00000000..f6d1e1f7
--- /dev/null
+++ b/examples/timeline/other/usingReact.html
@@ -0,0 +1,123 @@
+
+
+
+
+ React Components in templates
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lib/timeline/component/Group.js b/lib/timeline/component/Group.js
index f522fd82..691d24b1 100644
--- a/lib/timeline/component/Group.js
+++ b/lib/timeline/component/Group.js
@@ -87,10 +87,12 @@ Group.prototype._create = function() {
Group.prototype.setData = function(data) {
// update contents
var content;
+ var templateFunction;
+
if (this.itemSet.options && this.itemSet.options.groupTemplate) {
- content = this.itemSet.options.groupTemplate(data, this.dom.inner);
- }
- else {
+ templateFunction = this.itemSet.options.groupTemplate.bind(this);
+ content = templateFunction(data, this.dom.inner);
+ } else {
content = data && data.content;
}
@@ -100,11 +102,11 @@ Group.prototype.setData = function(data) {
this.dom.inner.removeChild(this.dom.inner.firstChild);
}
this.dom.inner.appendChild(content);
- }
- else if (content !== undefined && content !== null) {
+ } else if (content instanceof Object) {
+ templateFunction(data, this.dom.inner);
+ } else if (content !== undefined && content !== null) {
this.dom.inner.innerHTML = content;
- }
- else {
+ } else {
this.dom.inner.innerHTML = this.groupId || ''; // groupId can be null
}
diff --git a/lib/timeline/component/item/Item.js b/lib/timeline/component/item/Item.js
index e50918a8..c70cc0a4 100644
--- a/lib/timeline/component/item/Item.js
+++ b/lib/timeline/component/item/Item.js
@@ -187,31 +187,37 @@ Item.prototype._repaintDeleteButton = function (anchor) {
*/
Item.prototype._updateContents = function (element) {
var content;
+ var templateFunction;
+
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, element);
- }
- else {
+ templateFunction = this.options.template.bind(this);
+ content = templateFunction(itemData, element);
+ } else {
content = this.data.content;
}
- var changed = this._contentToString(this.content) !== this._contentToString(content);
- if (changed) {
- // only replace the content when changed
- if (content instanceof Element) {
- element.innerHTML = '';
- element.appendChild(content);
- }
- else if (content != undefined) {
- element.innerHTML = content;
- }
- else {
- if (!(this.data.type == 'background' && this.data.content === undefined)) {
- throw new Error('Property "content" missing in item ' + this.id);
+ if (content instanceof Object) {
+ templateFunction(itemData, element)
+ } else {
+ var changed = this._contentToString(this.content) !== this._contentToString(content);
+ if (changed) {
+ // only replace the content when changed
+ if (content instanceof Element) {
+ element.innerHTML = '';
+ element.appendChild(content);
+ }
+ else if (content != undefined) {
+ element.innerHTML = content;
+ }
+ else {
+ if (!(this.data.type == 'background' && this.data.content === undefined)) {
+ throw new Error('Property "content" missing in item ' + this.id);
+ }
}
- }
- this.content = content;
+ this.content = content;
+ }
}
};