Skip to content

Commit

Permalink
append data attribute for restoring initiation options
Browse files Browse the repository at this point in the history
  • Loading branch information
dabeng committed Mar 6, 2016
1 parent 2e40ee8 commit aed6758
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions examples/js/jquery.orgchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
};

var opts = $.extend(defaultOptions, options);
this.data('orgchart', { 'options' : opts });

switch (options) {
case 'buildNode':
Expand Down Expand Up @@ -374,19 +375,20 @@
// create node
function createNode(nodeData, opts) {
// construct the content of node
var $nodeDiv = $('<div>', {'id': nodeData[opts.nodeId]})
var $nodeDiv = $('<div>', { 'id': nodeData[opts.nodeId] })
.addClass('node')
.append('<div class="title">' + nodeData[opts.nodeTitle] + '</div>')
.append(typeof opts.nodeContent !== 'undefined' ? '<div class="content">' + nodeData[opts.nodeContent] + '</div>' : '');
// append 4 directions arrows
if (Number(nodeData[opts.nodeRelationship].substr(0,1))) {
var flags = nodeData[opts.nodeRelationship];
if (Number(flags.substr(0,1))) {
$nodeDiv.append('<i class="edge verticalEdge topEdge fa"></i>');
}
if(Number(nodeData[opts.nodeRelationship].substr(1,1))) {
if(Number(flags.substr(1,1))) {
$nodeDiv.append('<i class="edge horizontalEdge rightEdge fa"></i>' +
'<i class="edge horizontalEdge leftEdge fa"></i>');
}
if(Number(nodeData[opts.nodeRelationship].substr(2,1))) {
if(Number(flags.substr(2,1))) {
$nodeDiv.find('.title').prepend('<i class="fa '+ opts.parentNodeSymbol + ' symbol"></i>')
$nodeDiv.append('<i class="edge verticalEdge bottomEdge fa"></i>');
}
Expand Down Expand Up @@ -859,7 +861,7 @@
// Construct the node
var $nodeRow = $("<tr/>").addClass("node-cells");
var $nodeCell = $("<td/>").addClass("node-cell").attr("colspan", 2);
var $nodeDiv = createNode(nodeData, opts);
var $nodeDiv = createNode(nodeData, opts ? opts : this.data('orgchart').options);
$nodeCell.append($nodeDiv);
$nodeRow.append($nodeCell);
$tbody.append($nodeRow);
Expand Down
12 changes: 7 additions & 5 deletions jquery.orgchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
};

var opts = $.extend(defaultOptions, options);
this.data('orgchart', { 'options' : opts });

switch (options) {
case 'buildNode':
Expand Down Expand Up @@ -374,19 +375,20 @@
// create node
function createNode(nodeData, opts) {
// construct the content of node
var $nodeDiv = $('<div>', {'id': nodeData[opts.nodeId]})
var $nodeDiv = $('<div>', { 'id': nodeData[opts.nodeId] })
.addClass('node')
.append('<div class="title">' + nodeData[opts.nodeTitle] + '</div>')
.append(typeof opts.nodeContent !== 'undefined' ? '<div class="content">' + nodeData[opts.nodeContent] + '</div>' : '');
// append 4 directions arrows
if (Number(nodeData[opts.nodeRelationship].substr(0,1))) {
var flags = nodeData[opts.nodeRelationship];
if (Number(flags.substr(0,1))) {
$nodeDiv.append('<i class="edge verticalEdge topEdge fa"></i>');
}
if(Number(nodeData[opts.nodeRelationship].substr(1,1))) {
if(Number(flags.substr(1,1))) {
$nodeDiv.append('<i class="edge horizontalEdge rightEdge fa"></i>' +
'<i class="edge horizontalEdge leftEdge fa"></i>');
}
if(Number(nodeData[opts.nodeRelationship].substr(2,1))) {
if(Number(flags.substr(2,1))) {
$nodeDiv.find('.title').prepend('<i class="fa '+ opts.parentNodeSymbol + ' symbol"></i>')
$nodeDiv.append('<i class="edge verticalEdge bottomEdge fa"></i>');
}
Expand Down Expand Up @@ -859,7 +861,7 @@
// Construct the node
var $nodeRow = $("<tr/>").addClass("node-cells");
var $nodeCell = $("<td/>").addClass("node-cell").attr("colspan", 2);
var $nodeDiv = createNode(nodeData, opts);
var $nodeDiv = createNode(nodeData, opts ? opts : this.data('orgchart').options);
$nodeCell.append($nodeDiv);
$nodeRow.append($nodeCell);
$tbody.append($nodeRow);
Expand Down

0 comments on commit aed6758

Please sign in to comment.