| @@ -1,14 +1,47 @@ | ||
| 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 | + | |
| 7 | 28 | $('#settings-button').click(function() { |
| 8 | 29 | $('#settings-form').submit(); |
| 9 | 30 | }); |
| 10 | 31 | |
| 32 | + // this portion captures if the settings have changed so that tabs can handle that information. | |
| 33 | + var viz_settings_have_changed = false; | |
| 34 | + | |
| 35 | + window.vizHaveSettingsChanged = function(){ | |
| 36 | + return viz_settings_have_changed; | |
| 37 | + }; | |
| 38 | + | |
| 39 | + window.vizSettingsHaveChanged = function(value){ | |
| 40 | + viz_settings_have_changed = value; | |
| 41 | + }; | |
| 42 | + // this portion captures if the settings have changed so that tabs can handle that information. | |
| 43 | + | |
| 11 | 44 | function updateChart() { |
| 12 | 45 | clearTimeout(timeout); |
| 13 | 46 | timeout = setTimeout(function() { |
| 14 | 47 | var settings = $('#settings-form').serializeObject(); |
| @@ -16,9 +49,10 @@ | ||
| 16 | 49 | delete settings['width']; |
| 17 | 50 | delete settings['height']; |
| 18 | 51 | |
| 19 | 52 | v.charts.canvas.settings = settings; |
| 20 | - v.render(); | |
| 53 | + $('body').trigger('visualizer:render:currentchart:update', {visualizer: v}); | |
| 54 | + vizSettingsHaveChanged(true); | |
| 21 | 55 | }, 1000); |
| 22 | 56 | } |
| 23 | 57 | |
| 24 | 58 | function validateJSON() { |
| @@ -30,9 +64,9 @@ | ||
| 30 | 64 | } |
| 31 | 65 | } |
| 32 | 66 | |
| 33 | 67 | $('.control-text').change(updateChart).keyup(updateChart); |
| 34 | - $('.control-select, .control-checkbox').change(updateChart); | |
| 68 | + $('.control-select, .control-checkbox, .control-check').change(updateChart); | |
| 35 | 69 | $('.color-picker-hex').wpColorPicker({ |
| 36 | 70 | change: updateChart, |
| 37 | 71 | clear: updateChart |
| 38 | 72 | }); |