Browse Source

`select` event now returns the original type of the id, not the stringfied ids

css_transitions
josdejong 10 years ago
parent
commit
5e6717f7df
2 changed files with 72 additions and 66 deletions
  1. +3
    -2
      examples/timeline/06_event_listeners.html
  2. +69
    -64
      src/timeline/component/ItemSet.js

+ 3
- 2
examples/timeline/06_event_listeners.html View File

@ -20,7 +20,7 @@
<script type="text/javascript"> <script type="text/javascript">
var container = document.getElementById('visualization'); var container = document.getElementById('visualization');
var items = [ var items = [
{id: 1, content: 'item 1', start: '2013-04-20'},
{ida: 1, content: 'item 1', start: '2013-04-20'},
{id: 2, content: 'item 2', start: '2013-04-14'}, {id: 2, content: 'item 2', start: '2013-04-14'},
{id: 3, content: 'item 3', start: '2013-04-18'}, {id: 3, content: 'item 3', start: '2013-04-18'},
{id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'}, {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
@ -43,7 +43,8 @@
function logEvent(event, properties) { function logEvent(event, properties) {
var log = document.getElementById('log'); var log = document.getElementById('log');
var msg = document.createElement('div'); var msg = document.createElement('div');
msg.innerHTML = 'event=' + event + ', properties=' + JSON.stringify(properties);
msg.innerHTML = 'event=' + JSON.stringify(event) + ', ' +
'properties=' + JSON.stringify(properties);
log.firstChild ? log.insertBefore(msg, log.firstChild) : log.appendChild(msg); log.firstChild ? log.insertBefore(msg, log.firstChild) : log.appendChild(msg);
} }

+ 69
- 64
src/timeline/component/ItemSet.js View File

@ -262,80 +262,82 @@ ItemSet.prototype.repaint = function repaint() {
}; };
// show/hide added/changed/removed items // show/hide added/changed/removed items
Object.keys(queue).forEach(function (id) {
//var entry = queue[id];
var action = queue[id];
var item = items[id];
//var item = entry.item;
//noinspection FallthroughInSwitchStatementJS
switch (action) {
case 'add':
case 'update':
var itemData = itemsData && itemsData.get(id, dataOptions);
if (itemData) {
var type = itemData.type ||
(itemData.start && itemData.end && 'range') ||
options.type ||
'box';
var constructor = ItemSet.types[type];
// TODO: how to handle items with invalid data? hide them and give a warning? or throw an error?
if (item) {
// update item
if (!constructor || !(item instanceof constructor)) {
// item type has changed, hide and delete the item
changed += item.hide();
item = null;
}
else {
item.data = itemData; // TODO: create a method item.setData ?
changed++;
for (var id in queue) {
if (queue.hasOwnProperty(id)) {
var entry = queue[id],
item = items[id],
action = entry.action;
//noinspection FallthroughInSwitchStatementJS
switch (action) {
case 'add':
case 'update':
var itemData = itemsData && itemsData.get(id, dataOptions);
if (itemData) {
var type = itemData.type ||
(itemData.start && itemData.end && 'range') ||
options.type ||
'box';
var constructor = ItemSet.types[type];
// TODO: how to handle items with invalid data? hide them and give a warning? or throw an error?
if (item) {
// update item
if (!constructor || !(item instanceof constructor)) {
// item type has changed, hide and delete the item
changed += item.hide();
item = null;
}
else {
item.data = itemData; // TODO: create a method item.setData ?
changed++;
}
} }
}
if (!item) {
// create item
if (constructor) {
item = new constructor(me, itemData, options, defaultOptions);
item.id = id;
changed++;
}
else {
throw new TypeError('Unknown item type "' + type + '"');
if (!item) {
// create item
if (constructor) {
item = new constructor(me, itemData, options, defaultOptions);
item.id = entry.id; // we take entry.id, as id itself is stringified
changed++;
}
else {
throw new TypeError('Unknown item type "' + type + '"');
}
} }
}
// force a repaint (not only a reposition)
item.repaint();
// force a repaint (not only a reposition)
item.repaint();
items[id] = item;
}
items[id] = item;
}
// update queue
delete queue[id];
break;
// update queue
delete queue[id];
break;
case 'remove':
if (item) {
// remove the item from the set selected items
if (item.selected) {
me._deselect(id);
}
case 'remove':
if (item) {
// remove the item from the set selected items
if (item.selected) {
me._deselect(id);
}
// remove DOM of the item
changed += item.hide();
}
// remove DOM of the item
changed += item.hide();
}
// update lists
delete items[id];
delete queue[id];
break;
// update lists
delete items[id];
delete queue[id];
break;
default:
console.log('Error: unknown action "' + action + '"');
default:
console.log('Error: unknown action "' + action + '"');
}
} }
});
}
// reposition all items. Show items only when in the visible area // reposition all items. Show items only when in the visible area
util.forEach(this.items, function (item) { util.forEach(this.items, function (item) {
@ -546,7 +548,10 @@ ItemSet.prototype._onRemove = function _onRemove(ids) {
ItemSet.prototype._toQueue = function _toQueue(action, ids) { ItemSet.prototype._toQueue = function _toQueue(action, ids) {
var queue = this.queue; var queue = this.queue;
ids.forEach(function (id) { ids.forEach(function (id) {
queue[id] = action;
queue[id] = {
id: id,
action: action
};
}); });
if (this.controller) { if (this.controller) {

Loading…
Cancel
Save