orgchart 3.1.1 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -471,6 +471,15 @@
471
471
  }
472
472
  return { 'exist': false, 'visible': false };
473
473
  },
474
+ getParent: function ($node) {
475
+ return this.getRelatedNodes($node, 'parent');
476
+ },
477
+ getChildren: function ($node) {
478
+ return this.getRelatedNodes($node, 'children');
479
+ },
480
+ getSiblings: function ($node) {
481
+ return this.getRelatedNodes($node, 'siblings');
482
+ },
474
483
  // find the related nodes
475
484
  getRelatedNodes: function ($node, relation) {
476
485
  if (!$node || !($node instanceof $) || !$node.is('.node')) {
@@ -1041,7 +1050,7 @@
1041
1050
  event.originalEvent.dataTransfer.dropEffect = 'none';
1042
1051
  } else {
1043
1052
  // default action for drag-and-drop of div is not to drop, so preventing default action for nodes which have allowedDrop class
1044
- //to fix drag and drop on IE and Edge
1053
+ //to fix drag and drop on IE and Edge
1045
1054
  event.preventDefault();
1046
1055
  }
1047
1056
  },
@@ -1059,7 +1068,7 @@
1059
1068
  this.$chart.triggerHandler({ 'type': 'otherdropped.orgchart', 'draggedItem': $dragged, 'dropZone': $dropZone });
1060
1069
  return;
1061
1070
  }
1062
-
1071
+
1063
1072
  if (!$dropZone.hasClass('allowedDrop')) {
1064
1073
  // We are trying to drop a node into a node which isn't allowed
1065
1074
  // IE/Edge have a habit of allowing this, so we need our own double-check
@@ -184,7 +184,8 @@ describe('orgchart -- unit tests', function () {
184
184
 
185
185
  it('getRelatedNodes()', function () {
186
186
  oc.getRelatedNodes().should.deep.equal($());
187
- oc.getRelatedNodes($('td:first'), 'children').should.deep.equal($());
187
+ oc.getRelatedNodes({}, 'children').should.deep.equal($());
188
+ oc.getRelatedNodes($('.hierarchy:first'), 'children').should.deep.equal($());
188
189
  oc.getRelatedNodes($('.node:first'), 'child').should.deep.equal($());
189
190
 
190
191
  oc.getRelatedNodes($laolao, 'parent').should.deep.equal($());
@@ -196,6 +197,37 @@ describe('orgchart -- unit tests', function () {
196
197
  oc.getRelatedNodes($bomiao, 'siblings').toArray().should.members([$sumiao[0], $hongmiao[0]]);
197
198
  });
198
199
 
200
+ it('getParent()', function () {
201
+ oc.getParent().should.deep.equal($());
202
+ oc.getParent({}).should.deep.equal($());
203
+ oc.getParent($('.hierarchy:first')).should.deep.equal($());
204
+
205
+ oc.getParent($laolao).should.deep.equal($());
206
+ oc.getParent($bomiao).should.deep.equal($laolao);
207
+ oc.getParent($sandan).should.deep.equal($pangpang);
208
+ });
209
+
210
+ it('getSiblings()', function () {
211
+ oc.getSiblings().should.deep.equal($());
212
+ oc.getSiblings({}).should.deep.equal($());
213
+ oc.getSiblings($('.hierarchy:first')).should.deep.equal($());
214
+
215
+ oc.getSiblings($laolao).should.deep.equal($());
216
+ oc.getSiblings($bomiao).toArray().should.members([$sumiao[0], $hongmiao[0]]);
217
+ oc.getSiblings($sandan).should.deep.equal($());
218
+ });
219
+
220
+ it('getChildren()', function () {
221
+ oc.getChildren().should.deep.equal($());
222
+ oc.getChildren({}).should.deep.equal($());
223
+ oc.getChildren($('.hierarchy:first')).should.deep.equal($());
224
+
225
+ oc.getChildren($laolao).toArray().should.members([$bomiao[0], $sumiao[0], $hongmiao[0]]);
226
+ oc.getChildren($bomiao).should.deep.equal($());
227
+ oc.getChildren($sumiao).toArray().should.members([$tiehua[0], $heihei[0], $pangpang[0]]);
228
+ oc.getChildren($sandan).should.deep.equal($());
229
+ });
230
+
199
231
  it('hideParent()', function () {
200
232
  var spy = sinon.spy(oc, 'hideParent');
201
233
  var spy2 = sinon.spy(oc, 'hideSiblings');