| @@ -1,9 +1,8 @@ | ||
| 1 | 1 | /* global visualizer */ |
| 2 | 2 | /* global console */ |
| 3 | 3 | /* global vizSettingsHaveChanged */ |
| 4 | 4 | /* global vizHaveSettingsChanged */ |
| 5 | -/* global wp */ | |
| 6 | 5 | |
| 7 | 6 | (function($, v) { |
| 8 | 7 | var timeout; |
| 9 | 8 | |
| @@ -22,9 +21,8 @@ | ||
| 22 | 21 | change: updateChart, |
| 23 | 22 | clear: updateChart |
| 24 | 23 | }); |
| 25 | 24 | $('#settings-form textarea[name="manual"]').change(validateJSON).keyup(validateJSON); |
| 26 | - initManualConfigEditor(); | |
| 27 | 25 | vizSettingsHaveChanged(false); |
| 28 | 26 | }; |
| 29 | 27 | |
| 30 | 28 | // Update google chart filter control. |
| @@ -174,44 +172,14 @@ | ||
| 174 | 172 | |
| 175 | 173 | function validateJSON() { |
| 176 | 174 | $('#visualizer-error-manual').remove(); |
| 177 | 175 | try{ |
| 178 | - JSON.parse($(this).val()); | |
| 176 | + var options = JSON.parse($(this).val()); | |
| 179 | 177 | }catch(error){ |
| 180 | - var $after = $(this).next('.CodeMirror').length ? $(this).next('.CodeMirror') : $(this); | |
| 181 | - $('<div class="visualizer-error" id="visualizer-error-manual">Invalid JSON: ' + error + '</div>').insertAfter($after); | |
| 178 | + $('<div class="visualizer-error" id="visualizer-error-manual">Invalid JSON: ' + error + '</div>').insertAfter($(this)); | |
| 182 | 179 | } |
| 183 | 180 | } |
| 184 | 181 | |
| 185 | - function initManualConfigEditor() { | |
| 186 | - var $textarea = $('textarea[name="manual"]'); | |
| 187 | - if (!$textarea.length || $textarea.data('cm-initialized')) return; | |
| 188 | - | |
| 189 | - var CodeMirrorLib = (typeof wp !== 'undefined' && wp.CodeMirror) ? wp.CodeMirror : null; | |
| 190 | - if (!CodeMirrorLib) return; | |
| 191 | - | |
| 192 | - $textarea.data('cm-initialized', true); | |
| 193 | - | |
| 194 | - var cm = CodeMirrorLib.fromTextArea($textarea.get(0), { | |
| 195 | - mode: 'application/json', | |
| 196 | - lineNumbers: true, | |
| 197 | - lineWrapping: true, | |
| 198 | - matchBrackets: true, | |
| 199 | - autoCloseBrackets: true | |
| 200 | - }); | |
| 201 | - | |
| 202 | - // Refresh when any sidebar group is expanded so line numbers render correctly | |
| 203 | - // (CodeMirror can't measure gutter width while the container is hidden). | |
| 204 | - $(document).on('click.vizManualConfig', '.viz-group-title', function() { | |
| 205 | - setTimeout(function() { cm.refresh(); }, 50); | |
| 206 | - }); | |
| 207 | - | |
| 208 | - cm.on('change', function() { | |
| 209 | - cm.save(); | |
| 210 | - $textarea.trigger('change'); | |
| 211 | - }); | |
| 212 | - } | |
| 213 | - | |
| 214 | 182 | $('.control-text').change(updateChart).keyup(updateChart); |
| 215 | 183 | $('.control-select, .control-checkbox, .control-check').change(updateChart); |
| 216 | 184 | $('.color-picker-hex').wpColorPicker({ |
| 217 | 185 | change: updateChart, |
| @@ -217,13 +185,8 @@ | ||
| 217 | 185 | change: updateChart, |
| 218 | 186 | clear: updateChart |
| 219 | 187 | }); |
| 220 | 188 | $('textarea[name="manual"]').change(validateJSON).keyup(validateJSON); |
| 221 | - initManualConfigEditor(); | |
| 222 | - | |
| 223 | - $(document).on('change', 'input[name="paging_bool"], input[name="pagination"]', function() { | |
| 224 | - $('.viz-pagination-options').toggle($(this).is(':checked')); | |
| 225 | - }); | |
| 226 | 189 | |
| 227 | 190 | }); |
| 228 | 191 | })(jQuery, visualizer); |
| 229 | 192 | |