1/* global visualizer2 */ 2/* global Handsontable */ 3(function($, v) { 4 5 $(document).ready(function(){ 6 initAll(); 7 }); 8 9 function visualizer_perform_action(e){ 10 if(e.origin !== window.location.protocol + '//' + window.location.host){ 11 return; 12 } 13 14 switch(e.data.type){ 15 case 'edit': 16 var hot = null; 17 var chart_id = e.data.chart; 18 var id = 'visualizer-editor-' + chart_id; 19 var buttons = '<button class="visualizer-editor-save" data-visualizer-chart="' + chart_id + '">' + v.i10n['save'] + '</button>' + '<button class="visualizer-editor-cancel">' + v.i10n['cancel'] + '</button>'; 20 $('body').append($('<a id="' + id + '-anchor" href="#' + id + '-popup" ></a><div class="visualizer-editor-front-container mfp-hide" id="' + id + '-popup"><div class="visualizer-editor-front" id="' + id + '"></div><div class="visualizer-editor-front-actions">' + buttons + '</div></div></div>')); 21 $('#' + id + '-anchor').magnificPopup({ 22 type: 'inline', 23 modal: true 24 }); 25 $('.visualizer-editor-cancel').on('click', function(e){ 26 e.preventDefault(); 27 $.magnificPopup.close(); 28 deleteItems(id); 29 }); 30 $('.visualizer-editor-save').on('click', function(e){ 31 e.preventDefault(); 32 $.ajax({ 33 url : v.rest_url.replace('#id#', chart_id).replace('#type#', 'save'), 34 method : 'post', 35 data : { 36 data : JSON.stringify(hot.getData()), 37 }, 38 success: function(){ 39 $.magnificPopup.close(); 40 deleteItems(id); 41 window.location.reload(); 42 } 43 }); 44 }); 45 $('#' + id + '-anchor').trigger('click'); 46 hot = loadEditor(id, chart_id, e.data.data); 47 break; 48 } 49 } 50 51 function deleteItems(id){ 52 $('#' + id).remove(); 53 $('#' + id + '-popup').remove(); 54 } 55 56 function loadEditor(id, chart, data){ 57 var container = $( '#' + id ).get(0); 58 var hot = new Handsontable( 59 container, 60 { 61 language: v.locale, 62 minRows: 30, 63 minCols: 26, 64 rowHeaders: true, 65 colHeaders: true, 66 allowInvalid: false, 67 cells: function (row, col, prop) { 68 var cellProperties; 69 if (row === 1) { 70 cellProperties = { 71 type: 'autocomplete', 72 source: v.types, 73 strict: true 74 }; 75 } 76 if ( row > 1 && data.date_formats ) { 77 data.date_formats.map(function(i, index){ 78 if(i.index === col){ 79 cellProperties = { 80 type: 'date', 81 dateFormat: i.format, 82 correctFormat: true, 83 }; 84 } 85 }); 86 } 87 return cellProperties; 88 }, 89 afterLoad: function (){ 90 $( '#editor-chart-button' ).removeAttr("disabled"); 91 } 92 } 93 ); 94 95 loadDataInTable(data.series, data.data, hot); 96 return hot; 97 } 98 99 function loadDataInTable(cols, d, hot){ 100 var data = []; 101 var heading = []; 102 var type = []; 103 var i; 104 for( i = 0; i < cols.length; i++){ 105 heading[heading.length] = cols[i].label; 106 type[type.length] = cols[i].type; 107 } 108 109 data[data.length] = heading; 110 data[data.length] = type; 111 112 for( i = 0; i < d.length; i++){ 113 data[data.length] = d[i]; 114 } 115 116 hot.loadData(data); 117 } 118 119 function initAll(){ 120 window.addEventListener("message", visualizer_perform_action, false); 121 } 122 123})(jQuery, visualizer2); 124 125function visualizer_perform_action(type, chart, data){ 126 window.postMessage({'type': type, 'chart': chart, 'data': data}, window.location.protocol + '//' + window.location.host); 127}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.