'use strict'; (function(factory) { if (typeof module === 'object' && typeof module.exports === 'object') { factory(require('jquery'), window, document); } else { factory(jQuery, window, document); } }(function($, window, document, undefined) { $.fn.orgchart = function(options) { var defaultOptions = { 'nodeTitle': 'name', 'nodeId': 'id', 'nodeChildren': 'children', 'toggleSiblingsResp': false, 'depth': 999, 'chartClass': '', 'exportButton': false, 'exportFilename': 'OrgChart', 'parentNodeSymbol': 'fa-users', 'draggable': false, 'direction': 't2b', 'pan': false, 'zoom': false }; switch (options) { case 'buildHierarchy': return buildHierarchy.apply(this, Array.prototype.splice.call(arguments, 1)); case 'addChildren': return addChildren.apply(this, Array.prototype.splice.call(arguments, 1)); case 'addParent': return addParent.apply(this, Array.prototype.splice.call(arguments, 1)); case 'addSiblings': return addSiblings.apply(this, Array.prototype.splice.call(arguments, 1)); case 'removeNodes': return removeNodes.apply(this, Array.prototype.splice.call(arguments, 1)); case 'getHierarchy': return getHierarchy.apply(this, Array.prototype.splice.call(arguments, 1)); default: // initiation time var opts = $.extend(defaultOptions, options); } // build the org-chart var $chartContainer = this; var data = opts.data; var $chart = $('
', { 'data': { 'options': opts }, 'class': 'orgchart' + (opts.chartClass !== '' ? ' ' + opts.chartClass : '') + (opts.direction !== 't2b' ? ' ' + opts.direction : ''), 'click': function(event) { if (!$(event.target).closest('.node').length) { $chart.find('.node.focused').removeClass('focused'); } } }); if ($.type(data) === 'object') { if (data instanceof $) { // ul datasource buildHierarchy($chart, buildJsonDS(data.children()), 0, opts); } else { // local json datasource buildHierarchy($chart, opts.ajaxURL ? data : attachRel(data, '00'), 0, opts); } } else { $.ajax({ 'url': data, 'dataType': 'json', 'beforeSend': function () { $chart.append(''); } }) .done(function(data, textStatus, jqXHR) { buildHierarchy($chart, opts.ajaxURL ? data : attachRel(data, '00'), 0, opts); }) .fail(function(jqXHR, textStatus, errorThrown) { console.log(errorThrown); }) .always(function() { $chart.children('.spinner').remove(); }); } $chartContainer.append($chart); // append the export button if (opts.exportButton && !$chartContainer.find('.oc-export-btn').length) { var $exportBtn = $('