Browse Source

Merge pull request #327 from dturkenk/all_data_attributes

Write all item fields as data- attributes
v3_develop
Jos de Jong 10 years ago
parent
commit
7b0b101820
6 changed files with 64 additions and 7 deletions
  1. +3
    -2
      docs/timeline.html
  2. +43
    -0
      examples/timeline/24_all_data_attributes.html
  3. +0
    -0
      examples/timeline/25_background_areas.html
  4. +0
    -0
      examples/timeline/27_templates.html
  5. +4
    -3
      examples/timeline/index.html
  6. +14
    -2
      lib/timeline/component/item/Item.js

+ 3
- 2
docs/timeline.html View File

@ -385,9 +385,10 @@ var options = {
<tr>
<td>dataAttributes</td>
<td>Array[String]</td>
<td>Array[String] | 'all'</td>
<td>false</td>
<td>An array of fields optionally defined on the timeline items that will be appended as <code>data-</code> attributes to the DOM element of the items.</td>
<td>An array of fields optionally defined on the timeline items that will be appended as <code>data-</code> attributes to the DOM element of the items.<br>
If value is <code>'all'</code> then each field defined on the timeline item will become a <code>data-</code> attribute.</td>
</tr>

+ 43
- 0
examples/timeline/24_all_data_attributes.html View File

@ -0,0 +1,43 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Timeline | Basic demo</title>
<style type="text/css">
body, html {
font-family: sans-serif;
}
</style>
<script src="../../dist/vis.js"></script>
<link href="../../dist/vis.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p>
In this example all items get HTML attributes attached: each item gets <code>data-?</code> attributes for each field defined on the JS object.
</p>
<div id="visualization"></div>
<script type="text/javascript">
// DOM element where the Timeline will be attached
var container = document.getElementById('visualization');
// Create a DataSet (allows two way data-binding)
var items = new vis.DataSet([
{id: 1, content: 'item 1', start: '2014-04-20', tooltip: 'This is item 1'},
{id: 2, content: 'item 2', start: '2014-04-14'},
{id: 3, content: 'item 3', start: '2014-04-18'},
{id: 4, content: 'item 4', start: '2014-04-16', end: '2014-04-19'},
{id: 5, content: 'item 5', start: '2014-04-25'},
{id: 6, content: 'item 6', start: '2014-04-27', type: 'point', tooltip: 'This is item 6'}
]);
// Configuration for the Timeline
var options = {dataAttributes: 'all'};
// Create a Timeline
var timeline = new vis.Timeline(container, items, options);
</script>
</body>
</html>

examples/timeline/24_background_areas.html → examples/timeline/25_background_areas.html View File


examples/timeline/25_templates.html → examples/timeline/27_templates.html View File


+ 4
- 3
examples/timeline/index.html View File

@ -35,9 +35,10 @@
<p><a href="21_set_selection.html">21_set_selection.html</a></p>
<p><a href="22_window_adjustment.html">22_window_adjustment.html</a></p>
<p><a href="23_data_attributes.html">23_data_attributes.html</a></p>
<p><a href="24_background_areas.html">24_background_areas.html</a></p>
<p><a href="25_templates.html">25_templates.html</a></p>
<p><a href="26_external_data.html">26_external_data.html</a></p>
<p><a href="24_all_data_attributes.html">24_all_data_attributes.html</a></p>
<p><a href="25_background_areas.html">25_background_areas.html</a></p>
<p><a href="26_templates.html">26_templates.html</a></p>
<p><a href="27_external_data.html">27_external_data.html</a></p>
<p><a href="requirejs/requirejs_example.html">requirejs_example.html</a></p>

+ 14
- 2
lib/timeline/component/item/Item.js View File

@ -205,8 +205,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) {

Loading…
Cancel
Save