| @@ -7,12 +7,11 @@ | ||
| 7 | 7 | /* global vizHaveSettingsChanged */ |
| 8 | 8 | |
| 9 | 9 | (function ($) { |
| 10 | 10 | $(window).on('load', function(){ |
| 11 | - let chart_select = $('#chart-select'); | |
| 12 | - if(chart_select.length > 0){ | |
| 13 | - // scroll to the selected chart type. | |
| 14 | - $('#chart-select')[0].scrollIntoView(); | |
| 11 | + // scroll to the selected chart type. | |
| 12 | + if($('label.type-label.type-label-selected').length > 0) { | |
| 13 | + $('label.type-label.type-label-selected')[0].scrollIntoView(); | |
| 15 | 14 | } |
| 16 | 15 | }); |
| 17 | 16 | |
| 18 | 17 | $(document).ready(function () { |
| @@ -35,9 +34,8 @@ | ||
| 35 | 34 | }); |
| 36 | 35 | } |
| 37 | 36 | |
| 38 | 37 | function onReady() { |
| 39 | - initAccessibility(); | |
| 40 | 38 | initTabs(); |
| 41 | 39 | |
| 42 | 40 | // open the correct source tab/sub-tab. |
| 43 | 41 | var source = $('#visualizer-chart-id').attr('data-chart-source'); |
| @@ -73,9 +71,8 @@ | ||
| 73 | 71 | |
| 74 | 72 | $('.type-radio').change(function () { |
| 75 | 73 | $('.type-label-selected').removeClass('type-label-selected'); |
| 76 | 74 | $(this).parent().addClass('type-label-selected'); |
| 77 | - updateTypeAriaChecked(); | |
| 78 | 75 | }); |
| 79 | 76 | |
| 80 | 77 | // collapse other open sections of this group |
| 81 | 78 | $(document).on('click', '.viz-group-title', function () { |
| @@ -96,18 +93,15 @@ | ||
| 96 | 93 | * and then show the chart as it was |
| 97 | 94 | * let's close the LHS window and show the chart that is hidden |
| 98 | 95 | */ |
| 99 | 96 | $('body').trigger('visualizer:change:action'); |
| 100 | - updateGroupAriaState($(this)); | |
| 101 | 97 | }); |
| 102 | 98 | |
| 103 | 99 | // collapse other open subsections of this section |
| 104 | 100 | $(document).on('click', '.viz-section-title', function () { |
| 105 | 101 | var grandparent = $(this).parent().parent(); |
| 106 | - grandparent.find('.viz-section-title.open').not(this).each(function () { | |
| 107 | - $(this).removeClass('open').siblings('.viz-section-items').hide(); | |
| 108 | - }); | |
| 109 | - updateSectionAriaState($(this)); | |
| 102 | + grandparent.find('.viz-section-title.open ~ .viz-section-items').hide(); | |
| 103 | + grandparent.find('.viz-section-title.open').removeClass('open'); | |
| 110 | 104 | }); |
| 111 | 105 | |
| 112 | 106 | $('#view-remote-file').click(function () { |
| 113 | 107 | var url = $(this).parent().find('#vz-schedule-url').val(); |
| @@ -150,9 +144,9 @@ | ||
| 150 | 144 | $('#cancel-button').click(function () { |
| 151 | 145 | $('#cancel-form').submit(); |
| 152 | 146 | }); |
| 153 | 147 | |
| 154 | - init_available_chart_list(); | |
| 148 | + init_type_vs_library(); | |
| 155 | 149 | |
| 156 | 150 | $('.viz-abort').on('click', function(e){ |
| 157 | 151 | e.preventDefault(); |
| 158 | 152 | window.parent.postMessage('visualizer:mediaframe:close', '*'); |
| @@ -159,216 +153,27 @@ | ||
| 159 | 153 | }); |
| 160 | 154 | |
| 161 | 155 | } |
| 162 | 156 | |
| 163 | - function initAccessibility(){ | |
| 164 | - // Chart type picker: treat tiles as radios with keyboard support. | |
| 165 | - var $typePicker = $('#type-picker'); | |
| 166 | - if($typePicker.length){ | |
| 167 | - $typePicker.attr('role', 'radiogroup'); | |
| 168 | - $('.type-label').each(function(){ | |
| 169 | - var $label = $(this); | |
| 170 | - var $input = $label.find('input[type="radio"]'); | |
| 171 | - $label.attr('tabindex', '0').attr('role', 'radio'); | |
| 172 | - if($input.length){ | |
| 173 | - $label.attr('aria-checked', $input.is(':checked') ? 'true' : 'false'); | |
| 174 | - }else{ | |
| 175 | - $label.attr('aria-disabled', 'true'); | |
| 176 | - } | |
| 177 | - }); | |
| 178 | - $(document).on('keydown', '.type-label', function(e){ | |
| 179 | - if(e.key === 'Enter' || e.key === ' '){ | |
| 180 | - e.preventDefault(); | |
| 181 | - var $label = $(this); | |
| 182 | - var $input = $label.find('input[type="radio"]'); | |
| 183 | - if($input.length){ | |
| 184 | - $input.prop('checked', true).trigger('change'); | |
| 185 | - } | |
| 186 | - } | |
| 187 | - }); | |
| 188 | - } | |
| 189 | - | |
| 190 | - // Collapsible groups: add button roles + keyboard activation. | |
| 191 | - $('.viz-group-title').each(function(index){ | |
| 192 | - var $title = $(this); | |
| 193 | - $title.attr('role', 'button').attr('tabindex', '0'); | |
| 194 | - var $content = $title.siblings('.viz-group-content'); | |
| 195 | - if($content.length){ | |
| 196 | - if(!$content.attr('id')){ | |
| 197 | - $content.attr('id', 'viz-group-content-' + index); | |
| 198 | - } | |
| 199 | - $title.attr('aria-controls', $content.attr('id')); | |
| 200 | - updateGroupAriaState($title); | |
| 201 | - } | |
| 202 | - }); | |
| 203 | - $(document).on('keydown', '.viz-group-title', function(e){ | |
| 204 | - if(e.key === 'Enter' || e.key === ' '){ | |
| 205 | - e.preventDefault(); | |
| 206 | - $(this).trigger('click'); | |
| 207 | - } | |
| 208 | - }); | |
| 209 | - | |
| 210 | - // Subsections in source panel. | |
| 211 | - $('.viz-section-title').each(function(index){ | |
| 212 | - var $title = $(this); | |
| 213 | - $title.attr('role', 'button').attr('tabindex', '0'); | |
| 214 | - var $items = $title.siblings('.viz-section-items'); | |
| 215 | - if($items.length){ | |
| 216 | - if(!$items.attr('id')){ | |
| 217 | - $items.attr('id', 'viz-section-items-' + index); | |
| 218 | - } | |
| 219 | - $title.attr('aria-controls', $items.attr('id')); | |
| 220 | - updateSectionAriaState($title); | |
| 221 | - } | |
| 222 | - }); | |
| 223 | - $(document).on('keydown', '.viz-section-title', function(e){ | |
| 224 | - if(e.key === 'Enter' || e.key === ' '){ | |
| 225 | - e.preventDefault(); | |
| 226 | - $(this).trigger('click'); | |
| 227 | - } | |
| 228 | - }); | |
| 229 | - } | |
| 230 | - | |
| 231 | - function updateTypeAriaChecked(){ | |
| 232 | - $('.type-label').each(function(){ | |
| 233 | - var $label = $(this); | |
| 234 | - var $input = $label.find('input[type="radio"]'); | |
| 235 | - if($input.length){ | |
| 236 | - $label.attr('aria-checked', $input.is(':checked') ? 'true' : 'false'); | |
| 237 | - } | |
| 238 | - }); | |
| 239 | - } | |
| 240 | - | |
| 241 | - function updateGroupAriaState($title){ | |
| 242 | - if(!$title || $title.length === 0){ | |
| 157 | + function init_type_vs_library() { | |
| 158 | + var $data = $('select.viz-select-library').attr('data-type-vs-library'); | |
| 159 | + if(typeof $data === 'undefined' || $data.length === 0){ | |
| 243 | 160 | return; |
| 244 | 161 | } |
| 245 | - var isOpen = $title.parent().hasClass('open'); | |
| 246 | - $title.attr('aria-expanded', isOpen ? 'true' : 'false'); | |
| 247 | - } | |
| 248 | - | |
| 249 | - function updateSectionAriaState($title){ | |
| 250 | - if(!$title || $title.length === 0){ | |
| 251 | - return; | |
| 252 | - } | |
| 253 | - var isOpen = $title.hasClass('open'); | |
| 254 | - $title.attr('aria-expanded', isOpen ? 'true' : 'false'); | |
| 255 | - } | |
| 256 | - | |
| 257 | - /** | |
| 258 | - * Initialize/Update the available chart list based on their supported renderer libraries. | |
| 259 | - * | |
| 260 | - * @returns {void} | |
| 261 | - */ | |
| 262 | - function init_available_chart_list() { | |
| 263 | - const rendererSelect = document.querySelector('select.viz-select-library'); | |
| 264 | - if ( ! rendererSelect ) { | |
| 265 | - return; | |
| 266 | - } | |
| 267 | - | |
| 268 | - const rendererTypesMappingData = rendererSelect?.getAttribute('data-type-vs-library'); | |
| 269 | - if( ! rendererTypesMappingData ) { | |
| 270 | - return; | |
| 271 | - } | |
| 272 | - | |
| 273 | - /** @type {Record<string, ('GoogleCharts' | 'ChartJS' | 'DataTable')[]>} */ | |
| 274 | - const rendererTypesMapping = JSON.parse( rendererTypesMappingData ); | |
| 275 | - | |
| 276 | - document.querySelectorAll('input.type-radio').forEach( chartTypeRadio => { | |
| 277 | - | |
| 278 | - // Init the lib based on the default selected chart type. | |
| 279 | - if ( chartTypeRadio.checked ) { | |
| 280 | - const chartType = chartTypeRadio.value; | |
| 281 | - if ( ! chartType ) { | |
| 282 | - return; | |
| 283 | - } | |
| 284 | - | |
| 285 | - const selectedRenderer = rendererSelect.value; | |
| 286 | - if ( ! rendererTypesMapping[chartType]?.includes( selectedRenderer ) ) { | |
| 287 | - disable_renderer_select_placeholder(); | |
| 288 | - rendererSelect.value = rendererTypesMapping[chartType][0] | |
| 289 | - } | |
| 290 | - } | |
| 291 | - | |
| 292 | - chartTypeRadio.addEventListener('click', (event) => { | |
| 293 | - // Check if the chart type is supported by the selected renderer. If not, select the first supported renderer. | |
| 294 | - const chartType = event.target.value; | |
| 295 | - if ( ! chartType ) { | |
| 296 | - return; | |
| 297 | - } | |
| 298 | - | |
| 299 | - const selectedRenderer = rendererSelect.value; | |
| 300 | - if ( ! rendererTypesMapping[chartType]?.includes( selectedRenderer ) ) { | |
| 301 | - disable_renderer_select_placeholder(); | |
| 302 | - rendererSelect.value = rendererTypesMapping[chartType][0] | |
| 303 | - } | |
| 304 | - }); | |
| 162 | + var $typeVsLibrary = JSON.parse( $('select.viz-select-library').attr('data-type-vs-library') ); | |
| 163 | + // disable all unsupported libraries for the chart type. | |
| 164 | + $('input.type-radio').on('click', function(){ | |
| 165 | + enable_libraries_for($(this).val(), $typeVsLibrary); | |
| 305 | 166 | }); |
| 306 | 167 | |
| 307 | - // Update the chart list on user interaction. | |
| 308 | - rendererSelect.addEventListener('change', (event) => { | |
| 309 | - disable_renderer_select_placeholder(); | |
| 310 | - toggle_renderer_type( event.target.value ); | |
| 311 | - toggle_chart_types_by_render( event.target.value ); | |
| 312 | - }); | |
| 313 | - | |
| 314 | - } | |
| 315 | - | |
| 316 | - /** | |
| 317 | - * Disable the placeholder option in the renderer select. | |
| 318 | - */ | |
| 319 | - function disable_renderer_select_placeholder() { | |
| 320 | - const placeholderOption = document.querySelector('#library-select-placeholder'); | |
| 321 | - if ( placeholderOption && placeholderOption.disabled === false ) { | |
| 322 | - placeholderOption.disabled = true; | |
| 323 | - } | |
| 324 | - } | |
| 325 | - | |
| 326 | - /** | |
| 327 | - * Toggle the renderer type class based on the given renderer type. | |
| 328 | - * | |
| 329 | - * The class is used to style the chart type picker based on the given renderer library. | |
| 330 | - * | |
| 331 | - * @param {('GoogleCharts' | 'ChartJS' | 'DataTable')} rendererType The renderer type to toggle the class. | |
| 332 | - */ | |
| 333 | - function toggle_renderer_type( rendererType ) { | |
| 334 | - const typePicker = document.querySelector('#type-picker'); | |
| 335 | - if ( ! typePicker ) { | |
| 336 | - return; | |
| 337 | - } | |
| 338 | - | |
| 339 | - typePicker.classList.remove('lib-GoogleCharts', 'lib-ChartJS', 'lib-DataTable'); | |
| 340 | - typePicker.classList.add(`lib-${rendererType}`); | |
| 341 | - } | |
| 342 | - | |
| 343 | - /** | |
| 344 | - * Toggle chart types based on the given renderer type. | |
| 345 | - * | |
| 346 | - * @param {('GoogleCharts' | 'ChartJS' | 'DataTable')} rendererType The renderer type to filter the chart types. | |
| 347 | - */ | |
| 348 | - function toggle_chart_types_by_render( rendererType ) { | |
| 349 | - document.querySelectorAll('.type-box').forEach( typeBox => { | |
| 350 | - const hasLib = typeBox.classList.contains(`type-lib-${rendererType}`); | |
| 351 | - typeBox.classList.toggle('viz-hidden', ! hasLib ); | |
| 352 | - | |
| 353 | - // Reset unavailable chart type selection. | |
| 354 | - const chartOption = typeBox.querySelector('input[type="radio"]'); | |
| 355 | - if ( ! hasLib && chartOption?.checked ) { | |
| 356 | - chartOption.checked = false; | |
| 357 | - } | |
| 358 | - }); | |
| 359 | - | |
| 360 | 168 | enable_libraries_for($('input.type-radio:checked').val(), $typeVsLibrary); |
| 361 | 169 | } |
| 362 | 170 | |
| 363 | 171 | function enable_libraries_for($type, $typeVsLibrary) { |
| 364 | 172 | $('select.viz-select-library option').addClass('disabled').attr('disabled', 'disabled'); |
| 365 | - $('select.viz-select-library option .premium-label').remove(); | |
| 366 | - $('select.viz-select-library option').append('<span class="premium-label"> (PREMIUM)</span>'); | |
| 367 | 173 | var $libs = $typeVsLibrary[$type]; |
| 368 | 174 | $.each($libs, function( i, $lib ) { |
| 369 | 175 | $('select.viz-select-library option[value="' + $lib + '"]').removeClass('disabled').removeAttr('disabled'); |
| 370 | - $('select.viz-select-library option[value="' + $lib + '"] .premium-label').remove(); | |
| 371 | 176 | }); |
| 372 | 177 | $('select.viz-select-library').val( $('select.viz-select-library option:not(.disabled)').val() ); |
| 373 | 178 | } |
| 374 | 179 | |
| @@ -376,9 +181,9 @@ | ||
| 376 | 181 | $('.visualizer-permission').chosen({ |
| 377 | 182 | width : '50%', |
| 378 | 183 | search_contains : true |
| 379 | 184 | }); |
| 380 | - | |
| 185 | + | |
| 381 | 186 | $('.visualizer-permission-type').each(function(x, y){ |
| 382 | 187 | var type = $(y).attr('data-visualizer-permission-type'); |
| 383 | 188 | var child = $('.visualizer-permission-' + type + '-specific'); |
| 384 | 189 | if($(y).val() === 'all'){ |
| @@ -385,9 +190,9 @@ | ||
| 385 | 190 | child.next('div.chosen-container').hide(); |
| 386 | 191 | return; |
| 387 | 192 | } |
| 388 | 193 | }); |
| 389 | - | |
| 194 | + | |
| 390 | 195 | $('.visualizer-permission-type').on('change', function(evt, params) { |
| 391 | 196 | var type = $(this).attr('data-visualizer-permission-type'); |
| 392 | 197 | var child = $('.visualizer-permission-' + type + '-specific'); |
| 393 | 198 | child.empty(); |
| @@ -430,9 +235,9 @@ | ||
| 430 | 235 | lineWrapping: true, |
| 431 | 236 | dragDrop: false, |
| 432 | 237 | matchBrackets: true, |
| 433 | 238 | autoCloseBrackets: true, |
| 434 | - extraKeys: {"Shift-Space": "autocomplete"}, | |
| 239 | + extraKeys: {"Ctrl-Space": "autocomplete"}, | |
| 435 | 240 | hintOptions: { tables: table_columns } |
| 436 | 241 | }); |
| 437 | 242 | |
| 438 | 243 | // force refresh so that the query shows on first time load. Otherwise you have to click on the editor for it to show. |
| @@ -440,9 +245,9 @@ | ||
| 440 | 245 | cm.refresh(); |
| 441 | 246 | }); |
| 442 | 247 | |
| 443 | 248 | cm.focus(); |
| 444 | - | |
| 249 | + | |
| 445 | 250 | // update text area. |
| 446 | 251 | cm.on('inputRead', function(x, y){ |
| 447 | 252 | cm.save(); |
| 448 | 253 | }); |
| @@ -451,9 +256,9 @@ | ||
| 451 | 256 | // from the editor. Let's force this. |
| 452 | 257 | $('body').on('visualizer:db:query:update', function(event, data){ |
| 453 | 258 | cm.save(); |
| 454 | 259 | }); |
| 455 | - | |
| 260 | + | |
| 456 | 261 | // clear the editor. |
| 457 | 262 | $('body').on('visualizer:db:query:setvalue', function(event, data){ |
| 458 | 263 | cm.setValue(data.value); |
| 459 | 264 | cm.clearHistory(); |
| @@ -468,10 +273,8 @@ | ||
| 468 | 273 | |
| 469 | 274 | function init_filter_import() { |
| 470 | 275 | $( '#db-filter-save-button' ).on( 'click', function(){ |
| 471 | 276 | $('#vz-filter-wizard').submit(); |
| 472 | - $( '#vz-wp-sync-options' ).hide(); | |
| 473 | - $( '#vz-wp-sync-btn' ).attr( 'aria-expanded', false ); | |
| 474 | 277 | }); |
| 475 | 278 | } |
| 476 | 279 | |
| 477 | 280 | function init_db_import(){ |
| @@ -478,36 +281,8 @@ | ||
| 478 | 281 | $( '#visualizer-db-query' ).css("z-index", "-1").hide(); |
| 479 | 282 | |
| 480 | 283 | init_db_import_component(); |
| 481 | 284 | |
| 482 | - var settings_button = document.querySelector( '#settings-button' ); | |
| 483 | - if ( settings_button ) { | |
| 484 | - settings_button.addEventListener( 'click', function( event ){ | |
| 485 | - $('body').trigger('visualizer:db:query:update', {}); | |
| 486 | - if( $( '#db-chart-button' ).attr( 'data-current' ) !== 'filter' || $( '.visualizer-db-query' ).val().length === 0 ){ | |
| 487 | - return; | |
| 488 | - } | |
| 489 | - | |
| 490 | - event.preventDefault(); | |
| 491 | - event.stopImmediatePropagation(); | |
| 492 | - | |
| 493 | - var query_saved = false; | |
| 494 | - var resume_save = function(){ | |
| 495 | - query_saved = true; | |
| 496 | - settings_button.click(); | |
| 497 | - }; | |
| 498 | - | |
| 499 | - $('body').one( 'visualizer:render:currentchart:update', resume_save ); | |
| 500 | - $( '#thehole' ).one( 'load', function(){ | |
| 501 | - $('body').off( 'visualizer:render:currentchart:update', resume_save ); | |
| 502 | - if ( ! query_saved ) { | |
| 503 | - $( '#db-chart-button' ).trigger( 'click' ); | |
| 504 | - } | |
| 505 | - } ); | |
| 506 | - $( '#db-chart-button' ).trigger( 'click' ); | |
| 507 | - }, true ); | |
| 508 | - } | |
| 509 | - | |
| 510 | 285 | $('#visualizer-query-fetch').on('click', function(e){ |
| 511 | 286 | |
| 512 | 287 | $('body').trigger('visualizer:db:query:update', {}); |
| 513 | 288 | if($('.visualizer-db-query').val() === ''){ |
| @@ -512,9 +287,9 @@ | ||
| 512 | 287 | $('body').trigger('visualizer:db:query:update', {}); |
| 513 | 288 | if($('.visualizer-db-query').val() === ''){ |
| 514 | 289 | return; |
| 515 | 290 | } |
| 516 | - | |
| 291 | + | |
| 517 | 292 | start_ajax($('#visualizer-db-query')); |
| 518 | 293 | $('.db-wizard-results').empty(); |
| 519 | 294 | $('.db-wizard-error').empty(); |
| 520 | 295 | $.ajax({ |
| @@ -551,9 +326,9 @@ | ||
| 551 | 326 | filter_button.attr( 'data-current', 'chart' ); |
| 552 | 327 | $( '#canvas' ).css("z-index", "1").show(); |
| 553 | 328 | }); |
| 554 | 329 | |
| 555 | - $('#content').css('width', 'calc(100% - 350px)'); | |
| 330 | + $('#content').css('width', 'calc(100% - 300px)'); | |
| 556 | 331 | if( $(this).attr( 'data-current' ) === 'chart'){ |
| 557 | 332 | $(this).val( $(this).attr( 'data-t-filter' ) ); |
| 558 | 333 | $(this).html( $(this).attr( 'data-t-filter' ) ); |
| 559 | 334 | $(this).attr( 'data-current', 'filter' ); |
| @@ -572,29 +347,13 @@ | ||
| 572 | 347 | $( '#db-chart-save-button' ).trigger('click'); |
| 573 | 348 | } |
| 574 | 349 | } ); |
| 575 | 350 | |
| 576 | - $( document ).on( 'click', '#vz-db-sync-btn', function(){ | |
| 577 | - var $options = $( '#vz-db-sync-options' ); | |
| 578 | - var isOpen = $options.is( ':visible' ); | |
| 579 | - $options.toggle(); | |
| 580 | - $( this ).attr( 'aria-expanded', ! isOpen ); | |
| 581 | - } ); | |
| 582 | - | |
| 583 | - $( document ).on( 'click', '#vz-wp-sync-btn', function(){ | |
| 584 | - var $options = $( '#vz-wp-sync-options' ); | |
| 585 | - var isOpen = $options.is( ':visible' ); | |
| 586 | - $options.toggle(); | |
| 587 | - $( this ).attr( 'aria-expanded', ! isOpen ); | |
| 588 | - } ); | |
| 589 | - | |
| 590 | 351 | $( '#db-chart-save-button' ).on( 'click', function(){ |
| 591 | 352 | // submit only if a query has been provided. |
| 592 | 353 | if($('#db-query-form .visualizer-db-query').val().length > 0){ |
| 593 | 354 | $('#viz-db-wizard-params').val($('#db-query-form').serialize()); |
| 594 | 355 | $('#vz-db-wizard').submit(); |
| 595 | - $( '#vz-db-sync-options' ).hide(); | |
| 596 | - $( '#vz-db-sync-btn' ).attr( 'aria-expanded', false ); | |
| 597 | 356 | }else{ |
| 598 | 357 | $('#canvas').unlock(); |
| 599 | 358 | } |
| 600 | 359 | }); |
| @@ -616,9 +375,9 @@ | ||
| 616 | 375 | heightStyle: 'content', |
| 617 | 376 | active: false, |
| 618 | 377 | collapsible: true |
| 619 | 378 | }); |
| 620 | - | |
| 379 | + | |
| 621 | 380 | // open the accordions by default if they are indicated with the 'open' class. |
| 622 | 381 | $('.visualizer-json-subform .viz-substep.open').each(function(i, e){ |
| 623 | 382 | $('.visualizer-json-subform').accordion( "option", "active", i ); |
| 624 | 383 | }); |
| @@ -837,9 +596,9 @@ | ||
| 837 | 596 | }; |
| 838 | 597 | |
| 839 | 598 | // show column visibility button only when more than 6 columns are found (including the Label column) |
| 840 | 599 | if($(element + ' table.viz-editor-table thead tr th').length > 6){ |
| 841 | - $.extend( settings, { | |
| 600 | + $.extend( settings, { | |
| 842 | 601 | dom: 'Bt', |
| 843 | 602 | buttons: [ |
| 844 | 603 | { |
| 845 | 604 | extend: 'colvis', |
| @@ -920,107 +679,5 @@ | ||
| 920 | 679 | }); |
| 921 | 680 | |
| 922 | 681 | return $(this); |
| 923 | 682 | }; |
| 924 | - | |
| 925 | - // Telemetry | |
| 926 | - function getChartID() { | |
| 927 | - const urlParams = new URLSearchParams(window.location.search); | |
| 928 | - return urlParams.get('chart') ?? ''; | |
| 929 | - } | |
| 930 | - | |
| 931 | - const groupId = getChartID(); | |
| 932 | - | |
| 933 | - const chartTypes = document.querySelector('#viz-types-form') | |
| 934 | - if( chartTypes ) { | |
| 935 | - document.querySelector('.push-right[type=submit]')?.addEventListener('click', async function (event) { | |
| 936 | - if ( typeof window.tiTrk !== 'undefined' ) { | |
| 937 | - event.preventDefault(); | |
| 938 | - try { | |
| 939 | - const formData = new FormData(document.querySelector('#viz-types-form')); | |
| 940 | - const savedData = Object.fromEntries(formData); | |
| 941 | - | |
| 942 | - tiTrk?.with('visualizer')?.add({ | |
| 943 | - feature: 'chart-create', | |
| 944 | - featureComponent: 'saved-data', | |
| 945 | - featureData: { | |
| 946 | - type: savedData?.['type'], | |
| 947 | - library: savedData?.['chart-library'] | |
| 948 | - }, | |
| 949 | - groupId | |
| 950 | - }); | |
| 951 | - | |
| 952 | - // Do not make the user to wait too long for the event to be uploaded. | |
| 953 | - const timer = new Promise((resolve) => setTimeout(resolve, 500)); | |
| 954 | - await Promise.race([timer, tiTrk?.uploadEvents()]); | |
| 955 | - } catch (e) { | |
| 956 | - console.warn(e); | |
| 957 | - } | |
| 958 | - $('#viz-types-form').submit(); | |
| 959 | - } | |
| 960 | - }); | |
| 961 | - } | |
| 962 | - | |
| 963 | - [ | |
| 964 | - { | |
| 965 | - selector: '#editor-button', | |
| 966 | - featureComponent: 'source-manual-data' | |
| 967 | - }, | |
| 968 | - { | |
| 969 | - selector: '#vz-import-file', | |
| 970 | - featureComponent: 'source-import-csv-file' | |
| 971 | - }, | |
| 972 | - { | |
| 973 | - selector: '#vz-save-schedule', | |
| 974 | - featureComponent: 'source-import-csv-remote' | |
| 975 | - }, | |
| 976 | - { | |
| 977 | - selector: '#visualizer-json-fetch', | |
| 978 | - featureComponent: 'source-import-json-remote' | |
| 979 | - }, | |
| 980 | - { | |
| 981 | - selector: '#existing-chart', | |
| 982 | - featureComponent: 'source-import-chart' | |
| 983 | - }, | |
| 984 | - { | |
| 985 | - selector: '#filter-chart-button', | |
| 986 | - featureComponent: 'source-import-wordpress', | |
| 987 | - }, | |
| 988 | - { | |
| 989 | - selector: '#woo-chart-button', | |
| 990 | - featureComponent: 'source-import-woocommerce' | |
| 991 | - }, | |
| 992 | - { | |
| 993 | - selector: '#db-chart-button', | |
| 994 | - featureComponent: 'source-import-database' | |
| 995 | - } | |
| 996 | - ].forEach(({ selector, featureComponent }) => { | |
| 997 | - document.querySelector(selector)?.addEventListener('click', function () { | |
| 998 | - window?.tiTrk?.with('visualizer')?.set('used-source',{ | |
| 999 | - feature: 'chart-edit-used-source', | |
| 1000 | - featureComponent, | |
| 1001 | - groupId | |
| 1002 | - }); | |
| 1003 | - }); | |
| 1004 | - }); | |
| 1005 | -})(jQuery); | |
| 1006 | - | |
| 1007 | - | |
| 1008 | -document.querySelector('#viz-copy-shortcode')?.addEventListener('click', function() { | |
| 1009 | - var copyText = document.querySelector('#viz-shortcode')?.value; | |
| 1010 | - if ( !copyText ) { | |
| 1011 | - return; | |
| 1012 | - } | |
| 1013 | - | |
| 1014 | - navigator.clipboard.writeText(copyText); | |
| 1015 | - alert(visualizer.l10n.copied); | |
| 1016 | -}); | |
| 1017 | - | |
| 1018 | -// Connect Chart Backend Title Info Panel with the field from the settings form. | |
| 1019 | -const interactiveBackendTitleField = document.querySelector( '#viz-backend-name' ); | |
| 1020 | -const backendTitleSave = document.querySelector( '#settings-form input[name="backend-title"]' ); | |
| 1021 | - | |
| 1022 | -if ( interactiveBackendTitleField && backendTitleSave ) { | |
| 1023 | - interactiveBackendTitleField.addEventListener('input', function() { | |
| 1024 | - backendTitleSave.value = this.value; | |
| 1025 | - }); | |
| 1026 | -} | |
| 683 | +})(jQuery); | |