1jQuery(document).ready(function() { 2 3 function getStaffId(id) { 4 var sep_char_index = id.lastIndexOf(':'); 5 if (sep_char_index !== -1) { 6 return id.substring(id.length, sep_char_index+1); 7 } 8 return id; 9 } 10 11 function drawChart(rows, container) { 12 var data = new google.visualization.DataTable(); 13 data.addColumn('string', 'Name'); 14 data.addColumn('string', 'Manager'); 15 data.addRows(rows); 16 var chart = new google.visualization.OrgChart(container); 17 chart.draw(data, {allowHtml:true, allowCollapse: true, size: 'medium'}); 18 } 19 20 if (typeof google !== 'undefined') { 21 jQuery('table.orgchart, .wrap_orgchart table').each(function(){ 22 var staff = []; 23 var $orgchart = jQuery(this); 24 var includelinks = $orgchart.hasClass('includelinks'); 25 26 jQuery('tr', $orgchart).not(':first').each(function(i){ 27 var $row = jQuery(this); 28 var id, name, title, manager, photo = ''; 29 var name_detail = {}; 30 31 jQuery('td', $row).each(function(j){ 32 var $this = jQuery(this); 33 var $link = jQuery('a', $this); 34 35 switch(j) { 36 case 0: 37 name = $this.text().trim(); 38 if ($link.length) { 39 if (includelinks) { 40 $link.removeClass('wikilink1'); 41 name = $this.html().trim(); 42 } 43 id = getStaffId($link.attr('title')); 44 } else { 45 id = name.toLowerCase(); 46 } 47 break; 48 case 1: 49 if ($link.length) { 50 manager = getStaffId($link.attr('title')); 51 } else { 52 manager = $this.text().trim().toLowerCase(); 53 } 54 break; 55 case 2: 56 title = $this.text().trim(); 57 break; 58 case 3: 59 photo = $this.html(); 60 break; 61 } 62 63 name_detail.v = id; 64 name_detail.f = ' <strong>' + name + '</strong> '; 65 if (title) { 66 name_detail.f = name_detail.f + title; 67 } 68 if (photo) { 69 name_detail.f = photo + name_detail.f; 70 } 71 }); 72 73 staff[i] = [name_detail, manager]; 74 }); 75 76 google.setOnLoadCallback(function(){ 77 drawChart(staff, $orgchart.parent()[0]); 78 }); 79 }); 80 } 81 82}); 83