All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.primefaces-extensions.orgchart.0-jquery.orgchart.js Maven / Gradle / Ivy

There is a newer version: 14.0.7.1
Show newest version
/*
 * jQuery OrgChart Plugin 2.2.0
 * https://github.com/dabeng/OrgChart
 *
 * Copyright 2016, dabeng
 * https://github.com/dabeng
 *
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/MIT
 */
'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) {
  var OrgChart = function (elem, opts) {
    this.$chartContainer = $(elem);
    this.opts = opts;
    this.defaultOptions = {
      'nodeTitle': 'name',
      'nodeId': 'id',
      'toggleSiblingsResp': false,
      'visibleLevel': 999,
      'chartClass': '',
      'exportButton': false,
      'exportButtonName': 'Export',
      'exportFilename': 'OrgChart',
      'exportFileextension': 'png',
      'parentNodeSymbol': 'oci-leader',
      'draggable': false,
      'direction': 't2b',
      'pan': false,
      'zoom': false,
      'zoominLimit': 7,
      'zoomoutLimit': 0.5
    };
  };
  //
  OrgChart.prototype = {
    //
    init: function (opts) {
      var that = this;
      this.options = $.extend({}, this.defaultOptions, this.opts, opts);
      // build the org-chart
      var $chartContainer = this.$chartContainer;
      if (this.$chart) {
        this.$chart.remove();
      }
      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 : ''), 'click': function(event) { if (!$(event.target).closest('.node').length) { $chart.find('.node.focused').removeClass('focused'); } } }); if (typeof MutationObserver !== 'undefined') { this.triggerInitEvent(); } if ($.type(data) === 'object') { if (data instanceof $) { // ul datasource this.buildHierarchy($chart, this.buildJsonDS(data.children()), 0, this.options); } else { // local json datasource this.buildHierarchy($chart, this.options.ajaxURL ? data : this.attachRel(data, '00')); } } else { $chart.append(''); $.ajax({ 'url': data, 'dataType': 'json' }) .done(function(data, textStatus, jqXHR) { that.buildHierarchy($chart, that.options.ajaxURL ? data : that.attachRel(data, '00'), 0, that.options); }) .fail(function(jqXHR, textStatus, errorThrown) { console.log(errorThrown); }) .always(function() { $chart.children('.spinner').remove(); }); } $chartContainer.append($chart); // append the export button if (this.options.exportButton && !$chartContainer.find('.oc-export-btn').length) { this.attachExportButton(); } if (this.options.pan) { this.bindPan(); } if (this.options.zoom) { this.bindZoom(); } return this; }, // triggerInitEvent: function () { var that = this; var mo = new MutationObserver(function (mutations) { mo.disconnect(); initTime: for (var i = 0; i < mutations.length; i++) { for (var j = 0; j < mutations[i].addedNodes.length; j++) { if (mutations[i].addedNodes[j].classList.contains('orgchart')) { if (that.options.initCompleted && typeof that.options.initCompleted === 'function') { that.options.initCompleted(that.$chart); } var initEvent = $.Event('init.orgchart'); that.$chart.trigger(initEvent); break initTime; } } } }); mo.observe(this.$chartContainer[0], { childList: true }); }, triggerLoadEvent: function ($target, rel) { var initEvent = $.Event('load-' + rel +'.orgchart'); $target.trigger(initEvent); }, triggerShowEvent: function ($target, rel) { var initEvent = $.Event('show-' + rel + '.orgchart'); $target.trigger(initEvent); }, triggerHideEvent: function ($target, rel) { var initEvent = $.Event('hide-' + rel + '.orgchart'); $target.trigger(initEvent); }, // attachExportButton: function () { var that = this; var $exportBtn = $('