Browse Source

Define allowed dataAttributes as Timeline option

Read from an array of allowed dataAttributes at the timeline level and
write them as data- attributes on the item
v3_develop
Dan Turkenkopf 10 years ago
parent
commit
386035180e
6 changed files with 25 additions and 31 deletions
  1. +1
    -1
      lib/timeline/Core.js
  2. +1
    -1
      lib/timeline/component/ItemSet.js
  3. +20
    -0
      lib/timeline/component/item/Item.js
  4. +1
    -9
      lib/timeline/component/item/ItemBox.js
  5. +1
    -9
      lib/timeline/component/item/ItemPoint.js
  6. +1
    -11
      lib/timeline/component/item/ItemRange.js

+ 1
- 1
lib/timeline/Core.js View File

@ -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) {

+ 1
- 1
lib/timeline/component/ItemSet.js View File

@ -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) {

+ 20
- 0
lib/timeline/component/item/Item.js View File

@ -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;

+ 1
- 9
lib/timeline/component/item/ItemBox.js View File

@ -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

+ 1
- 9
lib/timeline/component/item/ItemPoint.js View File

@ -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) {

+ 1
- 11
lib/timeline/component/item/ItemRange.js View File

@ -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) {

Loading…
Cancel
Save