| @@ -1,95 +1,32 @@ | ||
| 1 | 1 | /* global visualizer */ |
| 2 | -/* global console */ | |
| 3 | -/* global vizSettingsHaveChanged */ | |
| 4 | -/* global vizHaveSettingsChanged */ | |
| 5 | - | |
| 6 | 2 | (function($, v) { |
| 7 | 3 | var timeout; |
| 8 | 4 | |
| 9 | 5 | $(document).ready(function() { |
| 10 | - // when data is impported using csv/url, update the hidden data and the advanced settings sidebar. | |
| 11 | - // editor and sidebar are both JSON objects | |
| 12 | - window.vizUpdateHTML = function( editor, sidebar ) { | |
| 13 | - $('.viz-simple-editor').remove(); | |
| 14 | - $('#content').append(editor.html); | |
| 15 | - $('#settings-form .viz-group').remove(); | |
| 16 | - $('#settings-form').append(sidebar.html); | |
| 17 | - | |
| 18 | - $('#settings-form .control-text').change(updateChart).keyup(updateChart); | |
| 19 | - $('#settings-form .control-select, #settings-form .control-checkbox, #settings-form .control-check').change(updateChart); | |
| 20 | - $('#settings-form .color-picker-hex').wpColorPicker({ | |
| 21 | - change: updateChart, | |
| 22 | - clear: updateChart | |
| 23 | - }); | |
| 24 | - $('#settings-form textarea[name="manual"]').change(validateJSON).keyup(validateJSON); | |
| 25 | - vizSettingsHaveChanged(false); | |
| 26 | - }; | |
| 27 | - | |
| 28 | - // Update google chart filter control. | |
| 29 | - window.vizUpdateFilterControl = function() { | |
| 30 | - $( '#control_wrapper_canvas' ).removeClass( 'no-filter' ); | |
| 31 | - var controlsOpt = $( '.vz-controls-opt' ).map( | |
| 32 | - function() { | |
| 33 | - var val = $(this).val(); | |
| 34 | - return '' !== val && 'false' !== val ? val : false ; | |
| 35 | - } | |
| 36 | - ).get(); | |
| 37 | - controlsOpt = controlsOpt.filter( function(el) { return el; } ); | |
| 38 | - if ( controlsOpt.length === 0 ) { | |
| 39 | - $( '#control_wrapper_canvas' ).addClass( 'no-filter' ).html(''); | |
| 40 | - } | |
| 41 | - } | |
| 42 | - | |
| 43 | 6 | $('#settings-button').click(function() { |
| 44 | 7 | $('#settings-form').submit(); |
| 45 | 8 | }); |
| 46 | 9 | |
| 47 | - // this portion captures if the settings have changed so that tabs can handle that information. | |
| 48 | - var viz_settings_have_changed = false; | |
| 49 | - | |
| 50 | - window.vizHaveSettingsChanged = function(){ | |
| 51 | - return viz_settings_have_changed; | |
| 52 | - }; | |
| 53 | - | |
| 54 | - window.vizSettingsHaveChanged = function(value){ | |
| 55 | - viz_settings_have_changed = value; | |
| 56 | - }; | |
| 57 | - // this portion captures if the settings have changed so that tabs can handle that information. | |
| 58 | - | |
| 59 | 10 | function updateChart() { |
| 60 | - vizUpdateFilterControl(); | |
| 61 | 11 | clearTimeout(timeout); |
| 62 | 12 | timeout = setTimeout(function() { |
| 63 | 13 | var settings = $('#settings-form').serializeObject(); |
| 64 | - settings = JSON.stringify( settings ).replace( /<\/?[^>]+(>|$)/g, '' ); | |
| 65 | - settings = JSON.parse( settings ); | |
| 14 | + | |
| 66 | 15 | delete settings['width']; |
| 67 | 16 | delete settings['height']; |
| 68 | 17 | |
| 69 | 18 | v.charts.canvas.settings = settings; |
| 70 | - $('body').trigger('visualizer:render:currentchart:update', {visualizer: v}); | |
| 71 | - vizSettingsHaveChanged(true); | |
| 72 | - }, 1500); | |
| 19 | + v.render(); | |
| 20 | + }, 1000); | |
| 73 | 21 | } |
| 74 | 22 | |
| 75 | - function validateJSON() { | |
| 76 | - $('#visualizer-error-manual').remove(); | |
| 77 | - try{ | |
| 78 | - var options = JSON.parse($(this).val()); | |
| 79 | - }catch(error){ | |
| 80 | - $('<div class="visualizer-error" id="visualizer-error-manual">Invalid JSON: ' + error + '</div>').insertAfter($(this)); | |
| 81 | - } | |
| 82 | - } | |
| 83 | - | |
| 84 | 23 | $('.control-text').change(updateChart).keyup(updateChart); |
| 85 | - $('.control-select, .control-checkbox, .control-check').change(updateChart); | |
| 24 | + $('.control-select, .control-checkbox').change(updateChart); | |
| 86 | 25 | $('.color-picker-hex').wpColorPicker({ |
| 87 | 26 | change: updateChart, |
| 88 | 27 | clear: updateChart |
| 89 | 28 | }); |
| 90 | - $('textarea[name="manual"]').change(validateJSON).keyup(validateJSON); | |
| 91 | - | |
| 92 | 29 | }); |
| 93 | 30 | })(jQuery, visualizer); |
| 94 | 31 | |
| 95 | 32 | (function($) { |