"use strict";!function(e){"object"==typeof module&&"object"==typeof module.exports?e(require("jquery"),window,document):e(jQuery,window,document)}(function(p,u,f,d){function t(e,t){this.$chartContainer=p(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;this.options=p.extend({},this.defaultOptions,this.opts,e);var t=this.$chartContainer;this.$chart&&this.$chart.remove();var i=this.options.data,s=this.$chart=p("
",{data:{options:this.options},class:"orgchart"+(""!==this.options.chartClass?" "+this.options.chartClass:"")+("t2b"!==this.options.direction?" "+this.options.direction:""),click:function(e){p(e.target).closest(".node").length||s.find(".node.focused").removeClass("focused")}});"undefined"!=typeof MutationObserver&&this.triggerInitEvent();var o=s.append(p('
')).find(".hierarchy");return"object"===p.type(i)?i instanceof p?this.buildHierarchy(o,this.buildJsonDS(i.children()),0,this.options):this.buildHierarchy(o,this.options.ajaxURL?i:this.attachRel(i,"00")):(s.append('
'),p.ajax({url:i,dataType:"json"}).done(function(e,t,i){n.buildHierarchy(o,n.options.ajaxURL?e:n.attachRel(e,"00"),0,n.options)}).fail(function(e,t,i){console.log(i)}).always(function(){s.children(".spinner").remove()})),t.append(s),this.options.exportButton&&!p(".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 o=p(e.delegateTarget);if(p(e.target).closest(".node").length||e.touches&&1i.zoomoutLimit&&oi.zoomoutLimit&&o').children().not(".spinner").css("opacity",.2),t.data("inAjax",!0),p(".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),p(".oc-export-btn").prop("disabled",!1)},isInAction:function(e){return-1').after('').siblings(".nodes").append(i.find(".horizontalEdge").remove().end().closest(".hierarchy")),t.children(".title").length&&t.children(".title").prepend('');1===n.siblings(".nodes").children(".hierarchy").length?n.siblings(".nodes").children(".hierarchy").find(".node:first").find(".horizontalEdge").remove():0===n.siblings(".nodes").children(".hierarchy").length&&n.find(".bottomEdge, .symbol").remove().end().siblings(".nodes").remove()}}}else this.$chart.triggerHandler({type:"otherdropped.orgchart",draggedItem:i,dropZone:t})},touchstartHandler:function(e){this.touchHandled||e.touches&&1").addClass("node "+(i.className||"")+(e>n.visibleLevel?" slide-up":""));n.nodeTemplate?t.append(n.nodeTemplate(i)):t.append(''+i[n.nodeTitle]+"
").append(void 0!==n.nodeContent?''+(i[n.nodeContent]||"")+"
":"");var s=p.extend({},i);delete s.children,t.data("nodeData",s);var o=i.relationship||"";return n.verticalLevel&&e>=n.verticalLevel?e+1>n.verticalLevel&&Number(o.substr(2,1))&&t.append('').children(".title").prepend(''):(Number(o.substr(0,1))&&t.append(''),Number(o.substr(1,1))&&t.append(''),Number(o.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=this,n=this.options,s=0;if(s=t.level?t.level:t.level=e.parentsUntil(".orgchart",".nodes").length,2n.visibleLevel||t.collapsed!==d&&t.collapsed;n.verticalLevel&&s+1>=n.verticalLevel?(a=p(''),r&&s+1>=n.verticalLevel&&a.addClass("hidden"),s+1===n.verticalLevel?e.addClass("hybrid").append(a.addClass("vertical")):e.append(a)):(a=p(''),2===Object.keys(t).length||r&&e.addClass("isChildrenCollapsed"),e.append(a)),p.each(t.children,function(){var e=p('- ');a.append(e),this.level=s+1,i.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";var i=p('').find(".hierarchy").append(this.createNode(t)).end();this.$chart.prepend(i).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=p.isArray(t)?t.length:t.children.length,n=e.parent().is(".nodes")?e.siblings().length+1:1,s=n+i,o=1
')).children(".hierarchy:first"),t),e.prevAll(".hierarchy").children(".nodes").children().eq(o).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){p(t).addClass("allowedDrop")}),this.$chart.data("dragged",p(e))},processExternalDrop:function(e,t){t&&this.$chart.data("dragged",p(t)),e.closest(".node").triggerHandler({type:"drop"})},exportPDF:function(e,t){var i={},n=Math.floor(e.width),s=Math.floor(e.height);u.jsPDF||(u.jsPDF=u.jspdf.jsPDF),(i=s'),o.find(a).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,p(this).children(".spinner").length)return!1;var s=this.$chartContainer,e=s.find(".mask");e.length?e.removeClass("hidden"):s.append('
');var o=s.addClass("canvasContainer").find('.orgchart:not(".hidden")').get(0),a="l2r"===n.options.direction||"r2l"===n.options.direction;html2canvas(o,{width:a?o.clientHeight:o.clientWidth,height:a?o.clientWidth:o.clientHeight,onclone:function(e){p(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")})}},p.fn.orgchart=function(e){return new t(this,e).init()}});
//# sourceMappingURL=jquery.orgchart.min.js.map