From a6a7ee232e6aac2e7ef78b351a345177a61a77fe Mon Sep 17 00:00:00 2001 From: Ben Morton Date: Sat, 18 Mar 2017 20:49:51 +0000 Subject: [PATCH] Allow nested groups to be removed by nulling the nestedGroups content. (#2852) Don't update the showNested property if nothing has been set in the data object, unless it is undefined. Verify group object exists during `onGroupClick` --- lib/timeline/component/Group.js | 25 +++++++++++++++++++------ lib/timeline/component/ItemSet.js | 2 +- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/timeline/component/Group.js b/lib/timeline/component/Group.js index 883d8580..42c2eddb 100644 --- a/lib/timeline/component/Group.js +++ b/lib/timeline/component/Group.js @@ -133,21 +133,34 @@ Group.prototype.setData = function(data) { } if (data && data.nestedGroups) { - if (data.showNested == false) { - this.showNested = false; - } else { - this.showNested = true; + if (!this.nestedGroups || this.nestedGroups != data.nestedGroups) { + this.nestedGroups = data.nestedGroups; + } + + if (data.showNested !== undefined || this.showNested === undefined) { + if (data.showNested == false) { + this.showNested = false; + } else { + this.showNested = true; + } } util.addClassName(this.dom.label, 'vis-nesting-group'); + var collapsedDirClassName = this.itemSet.options.rtl ? 'collapsed-rtl' : 'collapsed' if (this.showNested) { - util.removeClassName(this.dom.label, 'collapsed'); + util.removeClassName(this.dom.label, collapsedDirClassName); util.addClassName(this.dom.label, 'expanded'); } else { util.removeClassName(this.dom.label, 'expanded'); - var collapsedDirClassName = this.itemSet.options.rtl ? 'collapsed-rtl' : 'collapsed' util.addClassName(this.dom.label, collapsedDirClassName); } + } else if (this.nestedGroups) { + this.nestedGroups = null; + + var collapsedDirClassName = this.itemSet.options.rtl ? 'collapsed-rtl' : 'collapsed' + util.removeClassName(this.dom.label, collapsedDirClassName); + util.removeClassName(this.dom.label, 'expanded'); + util.removeClassName(this.dom.label, 'vis-nesting-group'); } if (data && data.nestedInGroup) { diff --git a/lib/timeline/component/ItemSet.js b/lib/timeline/component/ItemSet.js index d3f670fe..46129a6a 100644 --- a/lib/timeline/component/ItemSet.js +++ b/lib/timeline/component/ItemSet.js @@ -1644,7 +1644,7 @@ ItemSet.prototype._onDragEnd = function (event) { ItemSet.prototype._onGroupClick = function (event) { var group = this.groupFromTarget(event); - if (!group.nestedGroups) return; + if (!group || !group.nestedGroups) return; var groupsData = this.groupsData; if (this.groupsData instanceof DataView) {