From 0fdf0f40f305388f83742ed11a2ddebd832e3e52 Mon Sep 17 00:00:00 2001 From: dabeng Date: Thu, 2 Feb 2023 00:26:52 +0800 Subject: [PATCH] fix-bug: drag&drop is not working in the hybrid chart --- demo/drag-drop-hybrid-chart.html | 81 ++++++++++++++++++++++++++++++ demo/index.html | 1 + demo/vertical-level.html | 33 ++++++------ dist/js/jquery.orgchart.js | 21 ++++++++ dist/js/jquery.orgchart.min.js | 2 +- dist/js/jquery.orgchart.min.js.map | 2 +- package-lock.json | 11 ++++ package.json | 1 + src/js/jquery.orgchart.js | 21 ++++++++ 9 files changed, 155 insertions(+), 18 deletions(-) create mode 100644 demo/drag-drop-hybrid-chart.html diff --git a/demo/drag-drop-hybrid-chart.html b/demo/drag-drop-hybrid-chart.html new file mode 100644 index 00000000..5f954e67 --- /dev/null +++ b/demo/drag-drop-hybrid-chart.html @@ -0,0 +1,81 @@ + + + + + Organization Chart Plugin + + + + + + +
+ + + + + + + \ No newline at end of file diff --git a/demo/index.html b/demo/index.html index 4a6dda37..79987b75 100755 --- a/demo/index.html +++ b/demo/index.html @@ -143,6 +143,7 @@
  • Highlight related nodes
  • position node in specific level
  • nodes of different widths
  • +
  • drag&drop in hybrid chart
  • diff --git a/demo/vertical-level.html b/demo/vertical-level.html index 0561fba5..da356aee 100755 --- a/demo/vertical-level.html +++ b/demo/vertical-level.html @@ -20,23 +20,24 @@ $(function() { var datascource = { + 'id': '1', 'name': 'Lao Lao', 'title': 'general manager', 'children': [ - { 'name': 'Bo Miao', 'title': 'department manager' }, - { 'name': 'Su Miao', 'title': 'department manager', + { 'id': '2', 'name': 'Bo Miao', 'title': 'department manager' }, + { 'id': '3', 'name': 'Su Miao', 'title': 'department manager', 'children': [ - { 'name': 'Tie Hua', 'title': 'senior engineer' }, - { 'name': 'Hei Hei', 'title': 'senior engineer', + { 'id': '4', 'name': 'Tie Hua', 'title': 'senior engineer' }, + { 'id': '5', 'name': 'Hei Hei', 'title': 'senior engineer', 'children': [ - { 'name': 'Pang Pang', 'title': 'engineer' }, - { 'name': 'Dan Dan', 'title': 'UE engineer' , + { 'id': '6', 'name': 'Pang Pang', 'title': 'engineer' }, + { 'id': '7', 'name': 'Dan Dan', 'title': 'UE engineer' , 'children': [ - { 'name': 'Er Dan', 'title': 'engineer' }, - { 'name': 'San Dan', 'title': 'engineer', + { 'id': '8', 'name': 'Er Dan', 'title': 'engineer' }, + { 'id': '9', 'name': 'San Dan', 'title': 'engineer', 'children': [ - { 'name': 'Si Dan', 'title': 'intern' }, - { 'name': 'Wu Dan', 'title': 'intern' } + { 'id': '10', 'name': 'Si Dan', 'title': 'intern' }, + { 'id': '11', 'name': 'Wu Dan', 'title': 'intern' } ] } ]} @@ -44,14 +45,14 @@ } ] }, - { 'name': 'Hong Miao', 'title': 'department manager' }, - { 'name': 'Chun Miao', 'title': 'department manager', + { 'id': '12', 'name': 'Hong Miao', 'title': 'department manager' }, + { 'id': '13', 'name': 'Chun Miao', 'title': 'department manager', 'children': [ - { 'name': 'Bing Qin', 'title': 'senior engineer' }, - { 'name': 'Yue Yue', 'title': 'senior engineer', + { 'id': '14', 'name': 'Bing Qin', 'title': 'senior engineer' }, + { 'id': '15', 'name': 'Yue Yue', 'title': 'senior engineer', 'children': [ - { 'name': 'Er Yue', 'title': 'engineer' }, - { 'name': 'San Yue', 'title': 'UE engineer' } + { 'id': '16', 'name': 'Er Yue', 'title': 'engineer' }, + { 'id': '17', 'name': 'San Yue', 'title': 'UE engineer' } ] } ] diff --git a/dist/js/jquery.orgchart.js b/dist/js/jquery.orgchart.js index f78010ca..76a0b73c 100644 --- a/dist/js/jquery.orgchart.js +++ b/dist/js/jquery.orgchart.js @@ -1094,6 +1094,7 @@ }, // when user drops the node, it will be removed from original parent node and be added to new parent node dropHandler: function (event) { + var that = this; var $dropZone = $(event.delegateTarget); var $dragged = this.$chart.data('dragged'); @@ -1115,6 +1116,25 @@ if (dropEvent.isDefaultPrevented()) { return; } + // special process for hybrid chart + if (this.$chart.data('options').verticalLevel > 1) { + var datasource = this.$chart.data('options').data; + var digger = new JSONDigger(datasource, this.$chart.data('options').nodeId, 'children'); + digger.findNodeById($dragged.data('nodeData').id).then(function(draggedNode) { + var copy = Object.assign({}, draggedNode) + digger.removeNode(draggedNode.id).then(function() { + digger.findNodeById($dropZone.data('nodeData').id).then(function(dropNode) { + if (dropNode.children) { + dropNode.children.push(copy); + } else { + dropNode.children = [copy]; + } + that.init({ 'data': datasource }); + }); + }); + }); + } else { + // The folowing code snippets are used to process horizontal chart // firstly, deal with the hierarchy of drop zone if (!$dropZone.siblings('.nodes').length) { // if the drop zone is a leaf node $dropZone.append('') @@ -1142,6 +1162,7 @@ $dragZone.find('.bottomEdge, .symbol').remove() .end().siblings('.nodes').remove(); } + } }, // touchstartHandler: function (event) { diff --git a/dist/js/jquery.orgchart.min.js b/dist/js/jquery.orgchart.min.js index 07caa0dd..c3a0637f 100644 --- a/dist/js/jquery.orgchart.min.js +++ b/dist/js/jquery.orgchart.min.js @@ -1,2 +1,2 @@ -"use strict";!function(e){"object"==typeof module&&"object"==typeof module.exports?e(require("jquery"),window,document):e(jQuery,window,document)}(function(l,h,c,r){function t(e,t){this.$chartContainer=l(e),this.opts=t,this.defaultOptions={nodeTitle:"name",nodeId:"id",toggleSiblingsResp:!1,visibleLevel:999,chartClass:"",exportButton:!1,exportButtonName:"Export",exportFilename:"OrgChart",exportFileextension:"png",parentNodeSymbol:"oci-leader",draggable:!1,direction:"t2b",pan:!1,zoom:!1,zoominLimit:7,zoomoutLimit:.5}}t.prototype={init:function(e){var n=this,e=(this.options=l.extend({},this.defaultOptions,this.opts,e),this.$chartContainer),t=(this.$chart&&this.$chart.remove(),this.options.data),i=this.$chart=l("
    ",{data:{options:this.options},class:"orgchart"+(""!==this.options.chartClass?" "+this.options.chartClass:"")+("t2b"!==this.options.direction?" "+this.options.direction:""),click:function(e){l(e.target).closest(".node").length||i.find(".node.focused").removeClass("focused")}}),s=("undefined"!=typeof MutationObserver&&this.triggerInitEvent(),i.append(l('')).find(".hierarchy"));return"object"===l.type(t)?t instanceof l?this.buildHierarchy(s,this.buildJsonDS(t.children()),0,this.options):this.buildHierarchy(s,this.options.ajaxURL?t:this.attachRel(t,"00")):(i.append(''),l.ajax({url:t,dataType:"json"}).done(function(e,t,i){n.buildHierarchy(s,n.options.ajaxURL?e:n.attachRel(e,"00"),0,n.options)}).fail(function(e,t,i){console.log(i)}).always(function(){i.children(".spinner").remove()})),e.append(i),this.options.exportButton&&!l(".oc-export-btn").length&&this.attachExportButton(),this.options.pan&&this.bindPan(),this.options.zoom&&this.bindZoom(),this},triggerInitEvent:function(){var s=this,o=new MutationObserver(function(e){o.disconnect();e:for(var t=0;t",{class:"oc-export-btn",text:this.options.exportButtonName,click:function(e){e.preventDefault(),t.export()}});this.$chartContainer.after(e)},setOptions:function(e,t){return"string"==typeof e&&("pan"===e&&(t?this.bindPan():this.unbindPan()),"zoom"===e)&&(t?this.bindZoom():this.unbindZoom()),"object"==typeof e&&(e.data?this.init(e):(void 0!==e.pan&&(e.pan?this.bindPan():this.unbindPan()),void 0!==e.zoom&&(e.zoom?this.bindZoom():this.unbindZoom()))),this},panStartHandler:function(e){var s=l(e.delegateTarget);if(l(e.target).closest(".node").length||e.touches&&1n.zoomoutLimit&&on.zoomoutLimit&&o').children().not(".spinner").css("opacity",.2),t.data("inAjax",!0),l(".oc-export-btn").prop("disabled",!0),!0)},endLoading:function(e){var t=e.parent();e.removeClass("hidden"),t.find(".spinner").remove(),t.children().removeAttr("style"),this.$chart.data("inAjax",!1),l(".oc-export-btn").prop("disabled",!1)},isInAction:function(e){return-1',s.find(".horizontalEdge").length||s.append(i),e.siblings(".nodes").append(s.closest(".hierarchy")),1===(n=s.closest(".hierarchy").siblings().find(".node:first")).length&&n.append(i)):(e.append('').after('
      ').siblings(".nodes").append(s.find(".horizontalEdge").remove().end().closest(".hierarchy")),e.children(".title").length&&e.children(".title").prepend('')),1===t.siblings(".nodes").children(".hierarchy").length?t.siblings(".nodes").children(".hierarchy").find(".node:first").find(".horizontalEdge").remove():0===t.siblings(".nodes").children(".hierarchy").length&&t.find(".bottomEdge, .symbol").remove().end().siblings(".nodes").remove())):this.$chart.triggerHandler({type:"otherdropped.orgchart",draggedItem:s,dropZone:e})},touchstartHandler:function(e){this.touchHandled||e.touches&&1").addClass("node "+(i.className||"")+(e>n.visibleLevel?" slide-up":""))),s=(n.nodeTemplate?t.append(n.nodeTemplate(i)):t.append('
      '+i[n.nodeTitle]+"
      ").append(void 0!==n.nodeContent?'
      '+(i[n.nodeContent]||"")+"
      ":""),l.extend({},i)),s=(delete s.children,t.data("nodeData",s),i.relationship||"");return n.verticalLevel&&e>=n.verticalLevel?e+1>n.verticalLevel&&Number(s.substr(2,1))&&t.append('').children(".title").prepend(''):(Number(s.substr(0,1))&&t.append(''),Number(s.substr(1,1))&&t.append(''),Number(s.substr(2,1))&&t.append('').children(".title").prepend('')),t.on("mouseenter mouseleave",this.nodeEnterLeaveHandler.bind(this)),t.on("click",this.nodeClickHandler.bind(this)),t.on("click",".topEdge",this.topEdgeClickHandler.bind(this)),t.on("click",".bottomEdge",this.bottomEdgeClickHandler.bind(this)),t.on("click",".leftEdge, .rightEdge",this.hEdgeClickHandler.bind(this)),t.on("click",".toggleBtn",this.toggleVNodes.bind(this)),n.draggable&&(this.bindDragDrop(t),this.touchHandled=!1,this.touchMoved=!1,this.touchTargetNode=null),n.createNode&&n.createNode(t,i),t},buildHierarchy:function(e,t){var i,n,s=this,o=this.options,a=0,a=t.level||(t.level=e.parentsUntil(".orgchart",".nodes").length);2o.visibleLevel||t.collapsed!==r&&t.collapsed,o.verticalLevel&&a+1>=o.verticalLevel?(n=l('
        '),i&&a+1>=o.verticalLevel&&n.addClass("hidden"),a+1===o.verticalLevel?e.addClass("hybrid").append(n.addClass("vertical")):e.append(n)):(n=l('
          '),2!==Object.keys(t).length&&i&&e.addClass("isChildrenCollapsed"),e.append(n)),l.each(t.children,function(){var e=l('
        • ');n.append(e),this.level=a+1,s.buildHierarchy(e,this)}))},buildChildNode:function(e,t){this.buildHierarchy(e,{children:t})},addChildren:function(e,t){this.buildChildNode(e.closest(".hierarchy"),t),e.find(".symbol").length||e.children(".title").prepend(''),e.closest(".nodes.vertical").length?e.children(".toggleBtn").length||e.append(''):e.children(".bottomEdge").length||e.append(''),this.isInAction(e)&&this.switchVerticalArrow(e.children(".bottomEdge"))},buildParentNode:function(e,t){t.relationship=t.relationship||"001";t=l('
          ').find(".hierarchy").append(this.createNode(t)).end();this.$chart.prepend(t).find(".hierarchy:first").append(e.closest("ul").addClass("nodes"))},addParent:function(e,t){this.buildParentNode(e,t),e.children(".topEdge").length||e.children(".title").after(''),this.isInAction(e)&&this.switchVerticalArrow(e.children(".topEdge"))},buildSiblingNode:function(e,t){var i,n=(l.isArray(t)?t:t.children).length,s=e.parent().is(".nodes")?e.siblings().length+1:1,n=s+n,n=1')).children(".hierarchy:first"),t),e.prevAll(".hierarchy").children(".nodes").children().eq(n).after(e))},addSiblings:function(e,t){this.buildSiblingNode(e.closest(".hierarchy"),t),e.closest(".nodes").data("siblingsLoaded",!0),e.children(".leftEdge").length||e.children(".topEdge").after(''),this.isInAction(e)&&(this.switchHorizontalArrow(e),e.children(".topEdge").removeClass("oci-chevron-up").addClass("oci-chevron-down"))},removeNodes:function(e){var t=e.closest(".hierarchy").parent();t.parent().is(".hierarchy")?this.getNodeState(e,"siblings").exist?(e.closest(".hierarchy").remove(),1===t.children().length&&t.find(".node:first .horizontalEdge").remove()):t.siblings(".node").find(".bottomEdge").remove().end().end().remove():t.closest(".orgchart").remove()},hideDropZones:function(){this.$chart.find(".allowedDrop").removeClass("allowedDrop")},showDropZones:function(e){this.$chart.find(".node").each(function(e,t){l(t).addClass("allowedDrop")}),this.$chart.data("dragged",l(e))},processExternalDrop:function(e,t){t&&this.$chart.data("dragged",l(t)),e.closest(".node").triggerHandler({type:"drop"})},exportPDF:function(e,t){var i={},n=Math.floor(e.width),s=Math.floor(e.height);h.jsPDF||(h.jsPDF=h.jspdf.jsPDF),(i=s'),o.find(i).attr("href",e.toDataURL())[0].click())},export:function(t,i){var n=this;if(t=void 0!==t?t:this.options.exportFilename,i=void 0!==i?i:this.options.exportFileextension,l(this).children(".spinner").length)return!1;var s=this.$chartContainer,e=s.find(".mask"),e=(e.length?e.removeClass("hidden"):s.append('
          '),s.addClass("canvasContainer").find('.orgchart:not(".hidden")').get(0)),o="l2r"===n.options.direction||"r2l"===n.options.direction;html2canvas(e,{width:o?e.clientHeight:e.clientWidth,height:o?e.clientWidth:e.clientHeight,onclone:function(e){l(e).find(".canvasContainer").css("overflow","visible").find('.orgchart:not(".hidden"):first').css("transform","")}}).then(function(e){s.find(".mask").addClass("hidden"),"pdf"===i.toLowerCase()?n.exportPDF(e,t):n.exportPNG(e,t),s.removeClass("canvasContainer")},function(){s.removeClass("canvasContainer")})}},l.fn.orgchart=function(e){return new t(this,e).init()}}); +"use strict";!function(e){"object"==typeof module&&"object"==typeof module.exports?e(require("jquery"),window,document):e(jQuery,window,document)}(function(l,h,c,r){function t(e,t){this.$chartContainer=l(e),this.opts=t,this.defaultOptions={nodeTitle:"name",nodeId:"id",toggleSiblingsResp:!1,visibleLevel:999,chartClass:"",exportButton:!1,exportButtonName:"Export",exportFilename:"OrgChart",exportFileextension:"png",parentNodeSymbol:"oci-leader",draggable:!1,direction:"t2b",pan:!1,zoom:!1,zoominLimit:7,zoomoutLimit:.5}}t.prototype={init:function(e){var n=this,e=(this.options=l.extend({},this.defaultOptions,this.opts,e),this.$chartContainer),t=(this.$chart&&this.$chart.remove(),this.options.data),i=this.$chart=l("
          ",{data:{options:this.options},class:"orgchart"+(""!==this.options.chartClass?" "+this.options.chartClass:"")+("t2b"!==this.options.direction?" "+this.options.direction:""),click:function(e){l(e.target).closest(".node").length||i.find(".node.focused").removeClass("focused")}}),s=("undefined"!=typeof MutationObserver&&this.triggerInitEvent(),i.append(l('
          ')).find(".hierarchy"));return"object"===l.type(t)?t instanceof l?this.buildHierarchy(s,this.buildJsonDS(t.children()),0,this.options):this.buildHierarchy(s,this.options.ajaxURL?t:this.attachRel(t,"00")):(i.append(''),l.ajax({url:t,dataType:"json"}).done(function(e,t,i){n.buildHierarchy(s,n.options.ajaxURL?e:n.attachRel(e,"00"),0,n.options)}).fail(function(e,t,i){console.log(i)}).always(function(){i.children(".spinner").remove()})),e.append(i),this.options.exportButton&&!l(".oc-export-btn").length&&this.attachExportButton(),this.options.pan&&this.bindPan(),this.options.zoom&&this.bindZoom(),this},triggerInitEvent:function(){var s=this,o=new MutationObserver(function(e){o.disconnect();e:for(var t=0;t",{class:"oc-export-btn",text:this.options.exportButtonName,click:function(e){e.preventDefault(),t.export()}});this.$chartContainer.after(e)},setOptions:function(e,t){return"string"==typeof e&&("pan"===e&&(t?this.bindPan():this.unbindPan()),"zoom"===e)&&(t?this.bindZoom():this.unbindZoom()),"object"==typeof e&&(e.data?this.init(e):(void 0!==e.pan&&(e.pan?this.bindPan():this.unbindPan()),void 0!==e.zoom&&(e.zoom?this.bindZoom():this.unbindZoom()))),this},panStartHandler:function(e){var s=l(e.delegateTarget);if(l(e.target).closest(".node").length||e.touches&&1n.zoomoutLimit&&on.zoomoutLimit&&o').children().not(".spinner").css("opacity",.2),t.data("inAjax",!0),l(".oc-export-btn").prop("disabled",!0),!0)},endLoading:function(e){var t=e.parent();e.removeClass("hidden"),t.find(".spinner").remove(),t.children().removeAttr("style"),this.$chart.data("inAjax",!1),l(".oc-export-btn").prop("disabled",!1)},isInAction:function(e){return-1',e.find(".horizontalEdge").length||e.append(s),r.siblings(".nodes").append(e.closest(".hierarchy")),1===(o=e.closest(".hierarchy").siblings().find(".node:first")).length&&o.append(s)):(r.append('').after('
            ').siblings(".nodes").append(e.find(".horizontalEdge").remove().end().closest(".hierarchy")),r.children(".title").length&&r.children(".title").prepend('')),1===t.siblings(".nodes").children(".hierarchy").length?t.siblings(".nodes").children(".hierarchy").find(".node:first").find(".horizontalEdge").remove():0===t.siblings(".nodes").children(".hierarchy").length&&t.find(".bottomEdge, .symbol").remove().end().siblings(".nodes").remove()))):this.$chart.triggerHandler({type:"otherdropped.orgchart",draggedItem:e,dropZone:r})},touchstartHandler:function(e){this.touchHandled||e.touches&&1").addClass("node "+(i.className||"")+(e>n.visibleLevel?" slide-up":""))),s=(n.nodeTemplate?t.append(n.nodeTemplate(i)):t.append('
            '+i[n.nodeTitle]+"
            ").append(void 0!==n.nodeContent?'
            '+(i[n.nodeContent]||"")+"
            ":""),l.extend({},i)),s=(delete s.children,t.data("nodeData",s),i.relationship||"");return n.verticalLevel&&e>=n.verticalLevel?e+1>n.verticalLevel&&Number(s.substr(2,1))&&t.append('').children(".title").prepend(''):(Number(s.substr(0,1))&&t.append(''),Number(s.substr(1,1))&&t.append(''),Number(s.substr(2,1))&&t.append('').children(".title").prepend('')),t.on("mouseenter mouseleave",this.nodeEnterLeaveHandler.bind(this)),t.on("click",this.nodeClickHandler.bind(this)),t.on("click",".topEdge",this.topEdgeClickHandler.bind(this)),t.on("click",".bottomEdge",this.bottomEdgeClickHandler.bind(this)),t.on("click",".leftEdge, .rightEdge",this.hEdgeClickHandler.bind(this)),t.on("click",".toggleBtn",this.toggleVNodes.bind(this)),n.draggable&&(this.bindDragDrop(t),this.touchHandled=!1,this.touchMoved=!1,this.touchTargetNode=null),n.createNode&&n.createNode(t,i),t},buildHierarchy:function(e,t){var i,n,s=this,o=this.options,a=0,a=t.level||(t.level=e.parentsUntil(".orgchart",".nodes").length);2o.visibleLevel||t.collapsed!==r&&t.collapsed,o.verticalLevel&&a+1>=o.verticalLevel?(n=l('
              '),i&&a+1>=o.verticalLevel&&n.addClass("hidden"),a+1===o.verticalLevel?e.addClass("hybrid").append(n.addClass("vertical")):e.append(n)):(n=l('
                '),2!==Object.keys(t).length&&i&&e.addClass("isChildrenCollapsed"),e.append(n)),l.each(t.children,function(){var e=l('
              • ');n.append(e),this.level=a+1,s.buildHierarchy(e,this)}))},buildChildNode:function(e,t){this.buildHierarchy(e,{children:t})},addChildren:function(e,t){this.buildChildNode(e.closest(".hierarchy"),t),e.find(".symbol").length||e.children(".title").prepend(''),e.closest(".nodes.vertical").length?e.children(".toggleBtn").length||e.append(''):e.children(".bottomEdge").length||e.append(''),this.isInAction(e)&&this.switchVerticalArrow(e.children(".bottomEdge"))},buildParentNode:function(e,t){t.relationship=t.relationship||"001";t=l('
                ').find(".hierarchy").append(this.createNode(t)).end();this.$chart.prepend(t).find(".hierarchy:first").append(e.closest("ul").addClass("nodes"))},addParent:function(e,t){this.buildParentNode(e,t),e.children(".topEdge").length||e.children(".title").after(''),this.isInAction(e)&&this.switchVerticalArrow(e.children(".topEdge"))},buildSiblingNode:function(e,t){var i,n=(l.isArray(t)?t:t.children).length,s=e.parent().is(".nodes")?e.siblings().length+1:1,n=s+n,n=1')).children(".hierarchy:first"),t),e.prevAll(".hierarchy").children(".nodes").children().eq(n).after(e))},addSiblings:function(e,t){this.buildSiblingNode(e.closest(".hierarchy"),t),e.closest(".nodes").data("siblingsLoaded",!0),e.children(".leftEdge").length||e.children(".topEdge").after(''),this.isInAction(e)&&(this.switchHorizontalArrow(e),e.children(".topEdge").removeClass("oci-chevron-up").addClass("oci-chevron-down"))},removeNodes:function(e){var t=e.closest(".hierarchy").parent();t.parent().is(".hierarchy")?this.getNodeState(e,"siblings").exist?(e.closest(".hierarchy").remove(),1===t.children().length&&t.find(".node:first .horizontalEdge").remove()):t.siblings(".node").find(".bottomEdge").remove().end().end().remove():t.closest(".orgchart").remove()},hideDropZones:function(){this.$chart.find(".allowedDrop").removeClass("allowedDrop")},showDropZones:function(e){this.$chart.find(".node").each(function(e,t){l(t).addClass("allowedDrop")}),this.$chart.data("dragged",l(e))},processExternalDrop:function(e,t){t&&this.$chart.data("dragged",l(t)),e.closest(".node").triggerHandler({type:"drop"})},exportPDF:function(e,t){var i={},n=Math.floor(e.width),s=Math.floor(e.height);h.jsPDF||(h.jsPDF=h.jspdf.jsPDF),(i=s'),o.find(i).attr("href",e.toDataURL())[0].click())},export:function(t,i){var n=this;if(t=void 0!==t?t:this.options.exportFilename,i=void 0!==i?i:this.options.exportFileextension,l(this).children(".spinner").length)return!1;var s=this.$chartContainer,e=s.find(".mask"),e=(e.length?e.removeClass("hidden"):s.append('
                '),s.addClass("canvasContainer").find('.orgchart:not(".hidden")').get(0)),o="l2r"===n.options.direction||"r2l"===n.options.direction;html2canvas(e,{width:o?e.clientHeight:e.clientWidth,height:o?e.clientWidth:e.clientHeight,onclone:function(e){l(e).find(".canvasContainer").css("overflow","visible").find('.orgchart:not(".hidden"):first').css("transform","")}}).then(function(e){s.find(".mask").addClass("hidden"),"pdf"===i.toLowerCase()?n.exportPDF(e,t):n.exportPNG(e,t),s.removeClass("canvasContainer")},function(){s.removeClass("canvasContainer")})}},l.fn.orgchart=function(e){return new t(this,e).init()}}); //# sourceMappingURL=jquery.orgchart.min.js.map diff --git a/dist/js/jquery.orgchart.min.js.map b/dist/js/jquery.orgchart.min.js.map index f4f483eb..556b2840 100644 --- a/dist/js/jquery.orgchart.min.js.map +++ b/dist/js/jquery.orgchart.min.js.map @@ -1 +1 @@ -{"version":3,"file":"jquery.orgchart.min.js","sources":["jquery.orgchart.js"],"sourcesContent":["/*\n * jQuery OrgChart Plugin\n * https://github.com/dabeng/OrgChart\n *\n * Copyright 2016, dabeng\n * https://github.com/dabeng\n *\n * Licensed under the MIT license:\n * http://www.opensource.org/licenses/MIT\n */\n'use strict';\n\n(function (factory) {\n if (typeof module === 'object' && typeof module.exports === 'object') {\n factory(require('jquery'), window, document);\n } else {\n factory(jQuery, window, document);\n }\n}(function ($, window, document, undefined) {\n var OrgChart = function (elem, opts) {\n this.$chartContainer = $(elem);\n this.opts = opts;\n this.defaultOptions = {\n 'nodeTitle': 'name',\n 'nodeId': 'id',\n 'toggleSiblingsResp': false,\n 'visibleLevel': 999,\n 'chartClass': '',\n 'exportButton': false,\n 'exportButtonName': 'Export',\n 'exportFilename': 'OrgChart',\n 'exportFileextension': 'png',\n 'parentNodeSymbol': 'oci-leader',\n 'draggable': false,\n 'direction': 't2b',\n 'pan': false,\n 'zoom': false,\n 'zoominLimit': 7,\n 'zoomoutLimit': 0.5\n };\n };\n //\n OrgChart.prototype = {\n //\n init: function (opts) {\n var that = this;\n this.options = $.extend({}, this.defaultOptions, this.opts, opts);\n // build the org-chart\n var $chartContainer = this.$chartContainer;\n if (this.$chart) {\n this.$chart.remove();\n }\n var data = this.options.data;\n var $chart = this.$chart = $('
                ', {\n 'data': { 'options': this.options },\n 'class': 'orgchart' + (this.options.chartClass !== '' ? ' ' + this.options.chartClass : '') + (this.options.direction !== 't2b' ? ' ' + this.options.direction : ''),\n 'click': function(event) {\n if (!$(event.target).closest('.node').length) {\n $chart.find('.node.focused').removeClass('focused');\n }\n }\n });\n if (typeof MutationObserver !== 'undefined') {\n this.triggerInitEvent();\n }\n var $root = $chart.append($('
                ')).find('.hierarchy');\n if ($.type(data) === 'object') {\n if (data instanceof $) { // ul datasource\n this.buildHierarchy($root, this.buildJsonDS(data.children()), 0, this.options);\n } else { // local json datasource\n this.buildHierarchy($root, this.options.ajaxURL ? data : this.attachRel(data, '00'));\n }\n } else {\n $chart.append('');\n $.ajax({\n 'url': data,\n 'dataType': 'json'\n })\n .done(function(data, textStatus, jqXHR) {\n that.buildHierarchy($root, that.options.ajaxURL ? data : that.attachRel(data, '00'), 0, that.options);\n })\n .fail(function(jqXHR, textStatus, errorThrown) {\n console.log(errorThrown);\n })\n .always(function() {\n $chart.children('.spinner').remove();\n });\n }\n $chartContainer.append($chart);\n\n // append the export button\n if (this.options.exportButton && !$('.oc-export-btn').length) {\n this.attachExportButton();\n }\n\n if (this.options.pan) {\n this.bindPan();\n }\n\n if (this.options.zoom) {\n this.bindZoom();\n }\n\n return this;\n },\n //\n triggerInitEvent: function () {\n var that = this;\n var mo = new MutationObserver(function (mutations) {\n mo.disconnect();\n initTime:\n for (var i = 0; i < mutations.length; i++) {\n for (var j = 0; j < mutations[i].addedNodes.length; j++) {\n if (mutations[i].addedNodes[j].classList.contains('orgchart')) {\n if (that.options.initCompleted && typeof that.options.initCompleted === 'function') {\n that.options.initCompleted(that.$chart);\n }\n var initEvent = $.Event('init.orgchart');\n that.$chart.trigger(initEvent);\n break initTime;\n }\n }\n }\n });\n mo.observe(this.$chartContainer[0], { childList: true });\n },\n triggerLoadEvent: function ($target, rel) {\n var initEvent = $.Event('load-' + rel +'.orgchart');\n $target.trigger(initEvent);\n },\n triggerShowEvent: function ($target, rel) {\n var initEvent = $.Event('show-' + rel + '.orgchart');\n $target.trigger(initEvent);\n },\n triggerHideEvent: function ($target, rel) {\n var initEvent = $.Event('hide-' + rel + '.orgchart');\n $target.trigger(initEvent);\n },\n // add export button for orgchart\n attachExportButton: function () {\n var that = this;\n var $exportBtn = $('