|
|
@ -32,6 +32,7 @@ function Item (data, conversion, options) { |
|
|
|
*/ |
|
|
|
Item.prototype.select = function() { |
|
|
|
this.selected = true; |
|
|
|
this.dirty = true; |
|
|
|
if (this.displayed) this.redraw(); |
|
|
|
}; |
|
|
|
|
|
|
@ -40,6 +41,18 @@ Item.prototype.select = function() { |
|
|
|
*/ |
|
|
|
Item.prototype.unselect = function() { |
|
|
|
this.selected = false; |
|
|
|
this.dirty = true; |
|
|
|
if (this.displayed) this.redraw(); |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Set data for the item. Existing data will be updated. The id should not |
|
|
|
* be changed. When the item is displayed, it will be redrawn immediately. |
|
|
|
* @param {Object} data |
|
|
|
*/ |
|
|
|
Item.prototype.setData = function(data) { |
|
|
|
this.data = data; |
|
|
|
this.dirty = true; |
|
|
|
if (this.displayed) this.redraw(); |
|
|
|
}; |
|
|
|
|
|
|
@ -140,24 +153,57 @@ Item.prototype._repaintDeleteButton = function (anchor) { |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Set HTML contents for the item |
|
|
|
* @param {Element} element HTML element to fill with the contents |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Item.prototype._updateContents = function (element) { |
|
|
|
if (this.data.content instanceof Element) { |
|
|
|
element.innerHTML = ''; |
|
|
|
element.appendChild(this.data.content); |
|
|
|
} |
|
|
|
else if (this.data.content != undefined) { |
|
|
|
element.innerHTML = this.data.content; |
|
|
|
} |
|
|
|
else { |
|
|
|
throw new Error('Property "content" missing in item ' + this.data.id); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Set HTML contents for the item |
|
|
|
* @param {Element} element HTML element to fill with the contents |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Item.prototype._updateTitle = function (element) { |
|
|
|
if (this.data.title != null) { |
|
|
|
element.title = this.data.title || ''; |
|
|
|
} |
|
|
|
else { |
|
|
|
element.removeAttribute('title'); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
/** |
|
|
|
* Process dataAttributes timeline option and set as data- attributes on dom.content |
|
|
|
* @param {Element} element HTML element to which the attributes will be attached |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
Item.prototype._attachDataAttributes = function() { |
|
|
|
|
|
|
|
Item.prototype._updateDataAttributes = function(element) { |
|
|
|
if (this.options.dataAttributes && this.options.dataAttributes.length > 0) { |
|
|
|
|
|
|
|
var auxiliaryData = Object.keys(this.data); |
|
|
|
for (var i = 0; i < this.options.dataAttributes.length; i++) { |
|
|
|
var name = this.options.dataAttributes[i]; |
|
|
|
var value = this.data[name]; |
|
|
|
|
|
|
|
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]); |
|
|
|
if (value != null) { |
|
|
|
element.setAttribute('data-' + name, value); |
|
|
|
} |
|
|
|
else { |
|
|
|
element.removeAttribute('data-' + name); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = Item; |