diff --git a/lib/timeline/Core.js b/lib/timeline/Core.js index d816ce38..546b4cb8 100644 --- a/lib/timeline/Core.js +++ b/lib/timeline/Core.js @@ -173,7 +173,7 @@ Core.prototype._create = function (container) { Core.prototype.setOptions = function (options) { if (options) { // copy the known options - var fields = ['width', 'height', 'minHeight', 'maxHeight', 'autoResize', 'start', 'end', 'orientation', 'clickToUse']; + var fields = ['width', 'height', 'minHeight', 'maxHeight', 'autoResize', 'start', 'end', 'orientation', 'clickToUse', 'dataAttributes']; util.selectiveExtend(fields, this.options, options); if ('clickToUse' in options) { diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index d803b097..879b7b04 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -259,7 +259,7 @@ ItemSet.prototype._create = function(){ ItemSet.prototype.setOptions = function(options) { if (options) { // copy all options that we know - var fields = ['type', 'align', 'orientation', 'padding', 'stack', 'selectable', 'groupOrder']; + var fields = ['type', 'align', 'orientation', 'padding', 'stack', 'selectable', 'groupOrder', 'dataAttributes']; util.selectiveExtend(fields, this.options, options); if ('margin' in options) { diff --git a/lib/timeline/component/item/Item.js b/lib/timeline/component/item/Item.js index cfb1aa29..92edb636 100644 --- a/lib/timeline/component/item/Item.js +++ b/lib/timeline/component/item/Item.js @@ -140,4 +140,24 @@ Item.prototype._repaintDeleteButton = function (anchor) { } }; +/** + * Process dataAttributes timeline option and set as data- attributes on dom.content + */ + Item.prototype._attachDataAttributes = function() { + + if (this.options.dataAttributes && this.options.dataAttributes.length > 0) { + + var auxiliaryData = Object.keys(this.data); + + for (var i in this.options.dataAttributes) { + var c = this.options.dataAttributes[i]; + if (auxiliaryData.indexOf(c) >= 0) { + this.dom.content.setAttribute('data-' + c, this.data[c]); + } + } + } + + + }; + module.exports = Item; diff --git a/lib/timeline/component/item/ItemBox.js b/lib/timeline/component/item/ItemBox.js index 282293e1..6bfddfcf 100644 --- a/lib/timeline/component/item/ItemBox.js +++ b/lib/timeline/component/item/ItemBox.js @@ -132,16 +132,8 @@ ItemBox.prototype.redraw = function() { this.dirty = true; } - // set all other fields as data- attributes - var auxiliaryData = Object.keys(this.data); - - for (var i in auxiliaryData) { - var c = auxiliaryData[i]; - if (['start', 'end', 'content', 'title', 'id', 'className', 'group', 'type'].indexOf(c) < 0) { - dom.content.setAttribute('data-' + c, this.data[c]); - } - } + this._attachDataAttributes(); // recalculate size diff --git a/lib/timeline/component/item/ItemPoint.js b/lib/timeline/component/item/ItemPoint.js index 77f6a2a8..c736ed7e 100644 --- a/lib/timeline/component/item/ItemPoint.js +++ b/lib/timeline/component/item/ItemPoint.js @@ -121,15 +121,7 @@ ItemPoint.prototype.redraw = function() { this.dirty = true; } - // set all other fields as data- attributes - var auxiliaryData = Object.keys(this.data); - - for (var i in auxiliaryData) { - var c = auxiliaryData[i]; - if (['start', 'end', 'content', 'title', 'id', 'className', 'group', 'type'].indexOf(c) < 0) { - dom.content.setAttribute('data-' + c, this.data[c]); - } - } + this._attachDataAttributes(); // recalculate size if (this.dirty) { diff --git a/lib/timeline/component/item/ItemRange.js b/lib/timeline/component/item/ItemRange.js index d7068ade..083ce4c4 100644 --- a/lib/timeline/component/item/ItemRange.js +++ b/lib/timeline/component/item/ItemRange.js @@ -115,17 +115,7 @@ ItemRange.prototype.redraw = function() { this.dirty = true; } - - // set all other fields as data- attributes - var auxiliaryData = Object.keys(this.data); - - for (var i in auxiliaryData) { - var c = auxiliaryData[i]; - if (['start', 'end', 'content', 'title', 'id', 'className', 'group', 'type'].indexOf(c) < 0) { - dom.content.setAttribute('data-' + c, this.data[c]); - } - } - + this._attachDataAttributes(); // recalculate size if (this.dirty) {