From 44982eca07a0c5e71267c4f920290263a525aa21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Li=C3=A9geois?= Date: Tue, 25 Jul 2017 20:55:46 +0200 Subject: [PATCH 1/3] Fix for Issues with Internet Explorer - Concerning Issue #243 - Fix for an error thrown in the console when using orgchart in IE 11 --- dist/js/jquery.orgchart.js | 82 +++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/dist/js/jquery.orgchart.js b/dist/js/jquery.orgchart.js index 1cb773b6..947a476e 100644 --- a/dist/js/jquery.orgchart.js +++ b/dist/js/jquery.orgchart.js @@ -182,7 +182,7 @@ return this; }, // - setOptions (opts, val) { + setOptions: function (opts, val) { if (typeof opts === 'string') { if (opts === 'pan') { if (val) { @@ -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); @@ -291,32 +291,32 @@ }); }, // - 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); @@ -324,14 +324,14 @@ 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); @@ -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 = ''; @@ -385,7 +385,7 @@ } }, // - buildJsonDS ($li) { + buildJsonDS: function ($li) { var that = this; var subObj = { 'name': $li.contents().eq(0).text().trim(), @@ -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) { @@ -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 }; @@ -423,7 +423,7 @@ 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!'; @@ -431,7 +431,7 @@ 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'); @@ -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') { @@ -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); @@ -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'); @@ -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) { @@ -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; @@ -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) { @@ -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 = $(); @@ -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; @@ -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(); @@ -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(); @@ -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; @@ -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 @@ -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; @@ -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 = $(''); nodeData.relationship = nodeData.relationship || '001'; @@ -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) { @@ -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 += ''; @@ -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; @@ -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); @@ -1227,7 +1227,7 @@ }); }, // - removeNodes ($node) { + removeNodes: function ($node) { var $parent = $node.closest('table').parent(); var $sibs = $parent.parent().siblings(); if ($parent.is('td')) { From 834931b977e000e059ee082ed820cf0a70dc2347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Li=C3=A9geois?= Date: Tue, 25 Jul 2017 22:32:43 +0200 Subject: [PATCH 2/3] New option: collapsable Adds a new option "collapsable" with the default value true in order to work as expected. When set to false the class "noncollapsable" is added as is suggested in a tip on https://github.com/dabeng/OrgChart#tips --- dist/js/jquery.orgchart.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dist/js/jquery.orgchart.js b/dist/js/jquery.orgchart.js index 947a476e..493c6398 100644 --- a/dist/js/jquery.orgchart.js +++ b/dist/js/jquery.orgchart.js @@ -30,6 +30,7 @@ 'toggleSiblingsResp': false, 'depth': 999, 'chartClass': '', + 'collapsable': true, 'exportButton': false, 'exportFilename': 'OrgChart', 'exportFileextension': 'png', @@ -56,7 +57,7 @@ var data = this.options.data; var $chart = this.$chart = $('
', { 'data': { 'options': this.options }, - 'class': 'orgchart' + (this.options.chartClass !== '' ? ' ' + this.options.chartClass : '') + (this.options.direction !== 't2b' ? ' ' + this.options.direction : ''), + 'class': 'orgchart' + (this.options.chartClass !== '' ? ' ' + this.options.chartClass : '') + (this.options.direction !== 't2b' ? ' ' + this.options.direction : '') + (this.options.collapsable === false ? ' noncollapsable' : ''), 'click': function(event) { if (!$(event.target).closest('.node').length) { $chart.find('.node.focused').removeClass('focused'); From d11e646da0fdfe8180f6a4492fb0545e55c06392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Li=C3=A9geois?= Date: Tue, 25 Jul 2017 22:37:02 +0200 Subject: [PATCH 3/3] Reverted new option "collapsable" --- dist/js/jquery.orgchart.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dist/js/jquery.orgchart.js b/dist/js/jquery.orgchart.js index 493c6398..d9d05931 100644 --- a/dist/js/jquery.orgchart.js +++ b/dist/js/jquery.orgchart.js @@ -30,7 +30,6 @@ 'toggleSiblingsResp': false, 'depth': 999, 'chartClass': '', - 'collapsable': true, 'exportButton': false, 'exportFilename': 'OrgChart', 'exportFileextension': 'png', @@ -57,7 +56,7 @@ var data = this.options.data; var $chart = this.$chart = $('
', { 'data': { 'options': this.options }, - 'class': 'orgchart' + (this.options.chartClass !== '' ? ' ' + this.options.chartClass : '') + (this.options.direction !== 't2b' ? ' ' + this.options.direction : '') + (this.options.collapsable === false ? ' noncollapsable' : ''), + 'class': 'orgchart' + (this.options.chartClass !== '' ? ' ' + this.options.chartClass : '') + (this.options.direction !== 't2b' ? ' ' + this.options.direction : ''), 'click': function(event) { if (!$(event.target).closest('.node').length) { $chart.find('.node.focused').removeClass('focused'); @@ -1251,4 +1250,4 @@ return new OrgChart(this, opts).init(); }; -})); +})); \ No newline at end of file