From 37c4bfbaffae6b71e62b61e783ec2c4f8554d136 Mon Sep 17 00:00:00 2001 From: Dan Turkenkopf Date: Wed, 17 Sep 2014 16:39:20 -0400 Subject: [PATCH] Write all item fields as data-? attributes on element If the dataAttributes config option = 'all' then write every field as data-? attributes on the element. --- lib/timeline/component/item/Item.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/timeline/component/item/Item.js b/lib/timeline/component/item/Item.js index dfb9abb3..598d19d4 100644 --- a/lib/timeline/component/item/Item.js +++ b/lib/timeline/component/item/Item.js @@ -201,8 +201,20 @@ Item.prototype._updateTitle = function (element) { */ Item.prototype._updateDataAttributes = function(element) { if (this.options.dataAttributes && this.options.dataAttributes.length > 0) { - for (var i = 0; i < this.options.dataAttributes.length; i++) { - var name = this.options.dataAttributes[i]; + var attributes = []; + + if (Array.isArray(this.options.dataAttributes)) { + attributes = this.options.dataAttributes; + } + else if (this.options.dataAttributes == 'all') { + attributes = Object.keys(this.data); + } + else { + return; + } + + for (var i = 0; i < attributes.length; i++) { + var name = attributes[i]; var value = this.data[name]; if (value != null) {