| @@ -1,25 +1,76 @@ | ||
| 1 | 1 | /* global visualizer */ |
| 2 | 2 | /* global console */ |
| 3 | +/* global vizSettingsHaveChanged */ | |
| 4 | +/* global vizHaveSettingsChanged */ | |
| 5 | + | |
| 3 | 6 | (function($, v) { |
| 4 | 7 | var timeout; |
| 5 | 8 | |
| 6 | 9 | $(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 | + | |
| 7 | 43 | $('#settings-button').click(function() { |
| 8 | 44 | $('#settings-form').submit(); |
| 9 | 45 | }); |
| 10 | 46 | |
| 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 | + | |
| 11 | 59 | function updateChart() { |
| 60 | + vizUpdateFilterControl(); | |
| 12 | 61 | clearTimeout(timeout); |
| 13 | 62 | timeout = setTimeout(function() { |
| 14 | 63 | var settings = $('#settings-form').serializeObject(); |
| 15 | - | |
| 64 | + settings = JSON.stringify( settings ).replace( /<\/?[^>]+(>|$)/g, '' ); | |
| 65 | + settings = JSON.parse( settings ); | |
| 16 | 66 | delete settings['width']; |
| 17 | 67 | delete settings['height']; |
| 18 | 68 | |
| 19 | 69 | v.charts.canvas.settings = settings; |
| 20 | - v.update(); | |
| 21 | - }, 1000); | |
| 70 | + $('body').trigger('visualizer:render:currentchart:update', {visualizer: v}); | |
| 71 | + vizSettingsHaveChanged(true); | |
| 72 | + }, 1500); | |
| 22 | 73 | } |
| 23 | 74 | |
| 24 | 75 | function validateJSON() { |
| 25 | 76 | $('#visualizer-error-manual').remove(); |