Skip to content

Commit

Permalink
Merge pull request #250 from NielsNet/master
Browse files Browse the repository at this point in the history
Fix for Issues with Internet Explorer
  • Loading branch information
dabeng authored Jul 27, 2017
2 parents a4d847a + d11e646 commit 6cb7d83
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions dist/js/jquery.orgchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
return this;
},
//
setOptions (opts, val) {
setOptions: function (opts, val) {
if (typeof opts === 'string') {
if (opts === 'pan') {
if (val) {
Expand Down Expand Up @@ -223,7 +223,7 @@
return this;
},
//
panStartHandler (e) {
panStartHandler: function (e) {
var $chart = $(e.delegateTarget);
if ($(e.target).closest('.node').length || (e.touches && e.touches.length > 1)) {
$chart.data('panning', false);
Expand Down Expand Up @@ -291,47 +291,47 @@
});
},
//
panEndHandler (e) {
panEndHandler: function (e) {
if (e.data.chart.data('panning')) {
e.data.chart.data('panning', false).css('cursor', 'default').off('mousemove');
}
},
//
bindPan () {
bindPan: function () {
this.$chartContainer.css('overflow', 'hidden');
this.$chart.on('mousedown touchstart', this.panStartHandler);
$(document).on('mouseup touchend', { 'chart': this.$chart }, this.panEndHandler);
},
//
unbindPan () {
unbindPan: function () {
this.$chartContainer.css('overflow', 'auto');
this.$chart.off('mousedown touchstart', this.panStartHandler);
$(document).off('mouseup touchend', this.panEndHandler);
},
//
zoomWheelHandler (e) {
zoomWheelHandler: function (e) {
var oc = e.data.oc;
e.preventDefault();
var newScale = 1 + (e.originalEvent.deltaY > 0 ? -0.2 : 0.2);
oc.setChartScale(oc.$chart, newScale);
},
//
zoomStartHandler (e) {
zoomStartHandler: function (e) {
if(e.touches && e.touches.length === 2) {
var oc = e.data.oc;
oc.$chart.data('pinching', true);
var dist = oc.getPinchDist(e);
oc.$chart.data('pinchDistStart', dist);
}
},
zoomingHandler (e) {
zoomingHandler: function (e) {
var oc = e.data.oc;
if(oc.$chart.data('pinching')) {
var dist = oc.getPinchDist(e);
oc.$chart.data('pinchDistEnd', dist);
}
},
zoomEndHandler (e) {
zoomEndHandler: function (e) {
var oc = e.data.oc;
if(oc.$chart.data('pinching')) {
oc.$chart.data('pinching', false);
Expand All @@ -344,25 +344,25 @@
}
},
//
bindZoom () {
bindZoom: function () {
this.$chartContainer.on('wheel', { 'oc': this }, this.zoomWheelHandler);
this.$chartContainer.on('touchstart', { 'oc': this }, this.zoomStartHandler);
$(document).on('touchmove', { 'oc': this }, this.zoomingHandler);
$(document).on('touchend', { 'oc': this }, this.zoomEndHandler);
},
unbindZoom () {
unbindZoom: function () {
this.$chartContainer.off('wheel', this.zoomWheelHandler);
this.$chartContainer.off('touchstart', this.zoomStartHandler);
$(document).off('touchmove', this.zoomingHandler);
$(document).off('touchend', this.zoomEndHandler);
},
//
getPinchDist (e) {
getPinchDist: function (e) {
return Math.sqrt((e.touches[0].clientX - e.touches[1].clientX) * (e.touches[0].clientX - e.touches[1].clientX) +
(e.touches[0].clientY - e.touches[1].clientY) * (e.touches[0].clientY - e.touches[1].clientY));
},
//
setChartScale ($chart, newScale) {
setChartScale: function ($chart, newScale) {
var opts = $chart.data('options');
var lastTf = $chart.css('transform');
var matrix = '';
Expand All @@ -385,7 +385,7 @@
}
},
//
buildJsonDS ($li) {
buildJsonDS: function ($li) {
var that = this;
var subObj = {
'name': $li.contents().eq(0).text().trim(),
Expand All @@ -401,7 +401,7 @@
return subObj;
},
//
attachRel (data, flags) {
attachRel: function (data, flags) {
var that = this;
data.relationship = flags + (data.children && data.children.length > 0 ? 1 : 0);
if (data.children) {
Expand All @@ -412,7 +412,7 @@
return data;
},
//
loopChart ($chart) {
loopChart: function ($chart) {
var that = this;
var $tr = $chart.find('tr:first');
var subObj = { 'id': $tr.find('.node')[0].id };
Expand All @@ -423,15 +423,15 @@
return subObj;
},
//
getHierarchy ($chart) {
getHierarchy: function ($chart) {
var $chart = $chart || this.$chart;
if (!$chart.find('.node:first')[0].id) {
return 'Error: Nodes of orghcart to be exported must have id attribute!';
}
return this.loopChart($chart);
},
// detect the exist/display state of related node
getNodeState ($node, relation) {
getNodeState: function ($node, relation) {
var $target = {};
if (relation === 'parent') {
$target = $node.closest('.nodes').siblings(':first');
Expand All @@ -449,7 +449,7 @@
return { 'exist': false, 'visible': false };
},
// find the related nodes
getRelatedNodes ($node, relation) {
getRelatedNodes: function ($node, relation) {
if (relation === 'parent') {
return $node.closest('.nodes').parent().children(':first').find('.node');
} else if (relation === 'children') {
Expand All @@ -459,7 +459,7 @@
}
},
// recursively hide the ancestor node and sibling nodes of the specified node
hideParent ($node) {
hideParent: function ($node) {
var $temp = $node.closest('table').closest('tr').siblings();
if ($temp.eq(0).find('.spinner').length) {
$node.closest('.orgchart').data('inAjax', false);
Expand Down Expand Up @@ -487,7 +487,7 @@
}
},
// show the parent node of the specified node
showParent ($node) {
showParent: function ($node) {
var that = this;
// just show only one superior level
var $temp = $node.closest('table').closest('tr').siblings().removeClass('hidden');
Expand All @@ -504,7 +504,7 @@
});
},
// recursively hide the descendant nodes of the specified node
hideChildren ($node) {
hideChildren: function ($node) {
var that = this;
var $temp = $node.closest('tr').siblings();
if ($temp.last().find('.spinner').length) {
Expand All @@ -529,7 +529,7 @@
});
},
// show the children nodes of the specified node
showChildren ($node) {
showChildren: function ($node) {
var that = this;
var $levels = $node.closest('tr').siblings();
var isVerticalDesc = $levels.is('.verticalNodes') ? true : false;
Expand All @@ -546,7 +546,7 @@
});
},
// hide the sibling nodes of the specified node
hideSiblings ($node, direction) {
hideSiblings: function ($node, direction) {
var that = this;
var $nodeContainer = $node.closest('table').parent();
if ($nodeContainer.siblings().find('.spinner').length) {
Expand Down Expand Up @@ -580,7 +580,7 @@
});
},
// show the sibling nodes of the specified node
showSiblings ($node, direction) {
showSiblings: function ($node, direction) {
var that = this;
// firstly, show the sibling td tags
var $siblings = $();
Expand Down Expand Up @@ -619,7 +619,7 @@
});
},
// start up loading status for requesting new nodes
startLoading ($arrow, $node, options) {
startLoading: function ($arrow, $node, options) {
var $chart = $node.closest('.orgchart');
if (typeof $chart.data('inAjax') !== 'undefined' && $chart.data('inAjax') === true) {
return false;
Expand All @@ -633,7 +633,7 @@
return true;
},
// terminate loading status for requesting new nodes
endLoading ($arrow, $node, options) {
endLoading: function ($arrow, $node, options) {
var $chart = $node.closest('div.orgchart');
$arrow.removeClass('hidden');
$node.find('.spinner').remove();
Expand All @@ -642,15 +642,15 @@
$('.oc-export-btn' + (options.chartClass !== '' ? '.' + options.chartClass : '')).prop('disabled', false);
},
// whether the cursor is hovering over the node
isInAction ($node) {
isInAction: function ($node) {
return $node.children('.edge').attr('class').indexOf('fa-') > -1 ? true : false;
},
//
switchVerticalArrow ($arrow) {
switchVerticalArrow: function ($arrow) {
$arrow.toggleClass('fa-chevron-up').toggleClass('fa-chevron-down');
},
//
switchHorizontalArrow ($node) {
switchHorizontalArrow: function ($node) {
var opts = $node.closest('.orgchart').data('options');
if (opts.toggleSiblingsResp && (typeof opts.ajaxURL === 'undefined' || $node.closest('.nodes').data('siblingsLoaded'))) {
var $prevSib = $node.closest('table').parent().prev();
Expand All @@ -677,13 +677,13 @@
}
},
//
repaint (node) {
repaint: function (node) {
if (node) {
node.style.offsetWidth = node.offsetWidth;
}
},
// create node
createNode(nodeData, level, opts) {
createNode: function (nodeData, level, opts) {
var that = this;
$.each(nodeData.children, function (index, child) {
child.parentId = nodeData.id;
Expand Down Expand Up @@ -1038,7 +1038,7 @@
return dtd.promise();
},
// recursively build the tree
buildHierarchy ($appendTo, nodeData, level, opts, callback) {
buildHierarchy: function ($appendTo, nodeData, level, opts, callback) {
var that = this;
var $nodeWrapper;
// Construct the node
Expand Down Expand Up @@ -1108,14 +1108,14 @@
}
},
// build the child nodes of specific node
buildChildNode ($appendTo, nodeData, opts, callback) {
buildChildNode: function ($appendTo, nodeData, opts, callback) {
var opts = opts || $appendTo.closest('.orgchart').data('options');
var data = nodeData.children || nodeData.siblings;
$appendTo.find('td:first').attr('colspan', data.length * 2);
this.buildHierarchy($appendTo, { 'children': data }, 0, opts, callback);
},
// exposed method
addChildren ($node, data, opts) {
addChildren: function ($node, data, opts) {
var that = this;
var opts = opts || $node.closest('.orgchart').data('options');
var count = 0;
Expand All @@ -1132,7 +1132,7 @@
});
},
// build the parent node of specific node
buildParentNode ($currentRoot, nodeData, opts, callback) {
buildParentNode: function ($currentRoot, nodeData, opts, callback) {
var that = this;
var $table = $('<table>');
nodeData.relationship = nodeData.relationship || '001';
Expand All @@ -1153,7 +1153,7 @@
});
},
// exposed method
addParent ($currentRoot, data, opts) {
addParent: function ($currentRoot, data, opts) {
var that = this;
this.buildParentNode($currentRoot, data, opts, function() {
if (!$currentRoot.children('.topEdge').length) {
Expand All @@ -1163,7 +1163,7 @@
});
},
// subsequent processing of build sibling nodes
complementLine ($oneSibling, siblingCount, existingSibligCount) {
complementLine: function ($oneSibling, siblingCount, existingSibligCount) {
var lines = '';
for (var i = 0; i < existingSibligCount; i++) {
lines += '<td class="leftLine topLine">&nbsp;</td><td class="rightLine topLine">&nbsp;</td>';
Expand All @@ -1172,7 +1172,7 @@
.end().next().children(':first').after(lines);
},
// build the sibling nodes of specific node
buildSiblingNode ($nodeChart, nodeData, opts, callback) {
buildSiblingNode: function ($nodeChart, nodeData, opts, callback) {
var that = this;
var opts = opts || $nodeChart.closest('.orgchart').data('options');
var newSiblingCount = nodeData.siblings ? nodeData.siblings.length : nodeData.children.length;
Expand Down Expand Up @@ -1216,7 +1216,7 @@
}
},
//
addSiblings ($node, data, opts) {
addSiblings: function ($node, data, opts) {
var that = this;
this.buildSiblingNode($node.closest('table'), data, opts, function() {
$node.closest('.nodes').data('siblingsLoaded', true);
Expand All @@ -1227,7 +1227,7 @@
});
},
//
removeNodes ($node) {
removeNodes: function ($node) {
var $parent = $node.closest('table').parent();
var $sibs = $parent.parent().siblings();
if ($parent.is('td')) {
Expand All @@ -1250,4 +1250,4 @@
return new OrgChart(this, opts).init();
};

}));
}));

0 comments on commit 6cb7d83

Please sign in to comment.