1jQuery(function ($) { 2 //@Source: https://patdavid.net/2019/02/displaying-a-big-html-table/ 3 $('body').css('cursor','default'); 4 $('table.csvtohtml').show(); 5 6 var default_values; 7 var current_url = my_ajax_object.ajax_url; 8 9 //Removes all spellchecking (mouseclicks makes spellcheck active again in some browsers) 10 $(document).on("focusin", "textarea", function() { 11 $(this).attr("spellcheck", "false"); 12 }); 13 14 15 $.ajax({ 16 url: current_url, 17 method: 'GET', 18 dataType: 'json', 19 data:{ 20 action: 'getdefaults' 21 } 22 }) 23 .done(function( response ) { 24 default_values = response; 25 }) 26 .fail(function(textStatus) { 27 console.log('failed getdefaults'); 28 console.log(textStatus); 29 }); 30 31 32 //Sortable columns (by user) 33 function doSorting(e, ths) { 34 let sort_direction = 'asc'; 35 let sortindex = parseInt($(ths).attr('data-colindex')); 36 37 if ($(ths).hasClass('asc')) { 38 sort_direction = 'desc'; 39 $(ths).removeClass('asc').addClass('desc'); 40 } 41 else { 42 sort_direction = 'asc'; 43 $(ths).removeClass('desc').addClass('asc'); 44 } 45 let colnr = sortindex + 1; 46 47 48 //If headertype is NOT set, then remove an extra parent (there is another scrollwrapper when using headertype) 49 //(This is kind of backward, but I did this because I wanted to identify unique tables and not all) 50 let table_wrapper = $(ths).parent().parent().parent().parent().parent(); 51 if ( $(table_wrapper).find("div.csvtohtml-tablescroll").length == 0 ) { 52 table_wrapper = $(ths).parent().parent().parent().parent(); 53 } 54 55 sortTable(e, table_wrapper, colnr, sort_direction); 56 } 57 58 $('table.csvtohtml-sortable').find('thead th').on('click',function(e) { 59 doSorting(e, $(this)); 60 }); 61 62 63 //Shortcode creation help function 64 window.check_length = function( input_type , element_name ) { 65 var use_val = true; 66 67 var tp = 'input'; 68 if (input_type=='select') { 69 tp = 'select'; 70 } 71 if (input_type=='button') { 72 tp = 'button'; 73 use_val = false; //Use attr instead 74 } 75 var element_nofrm = element_name.substr(4); //Remove four first chars (frm_) 76 77 //Value exists, return value 78 //If no html-object found, just return '' 79 let el_val; 80 if ( use_val === true ) { 81 el_val = $('#dynamic_form').find(tp + '[name="' + element_name + '"]').val(); 82 } 83 else { 84 el_val = $('#shortcode_preview').find(tp + '[name="' + element_name + '"]').attr('value'); 85 } 86 87 if (!el_val) {return '';} 88 89 //Is value for element same as default? 90 //Then skip it 91 if (default_values[element_nofrm] != 'undefined') { 92 93 if (default_values[element_nofrm] == el_val) { 94 return ''; 95 } 96 97 } 98 99 100 if ( el_val.length > 0 ) { 101 return element_nofrm + '="' + el_val + '" '; 102 } 103 104 //return empty string 105 return ''; 106 } 107 108 //Shortcode creation help function 109 window.generate_shortcode = function() { 110 111 var sc_arr = []; 112 113 sc_arr.push('[csvtohtml_create '); 114 115 //Responsive 116 sc_arr.push( check_length('select','frm_responsive') ); 117 sc_arr.push( check_length('input','frm_css_max_width') ); 118 sc_arr.push( check_length('input','frm_css_min_devicewidth') ); 119 sc_arr.push( check_length('input','frm_css_max_devicewidth') ); 120 121 //Html styling 122 sc_arr.push( check_length('select','frm_table_fixedlayout') ); 123 sc_arr.push( check_length('input','frm_html_id') ); 124 sc_arr.push( check_length('input','frm_html_class') ); 125 sc_arr.push( check_length('select','frm_header_type') ); 126 sc_arr.push( check_length('input','frm_header_backgroundcolor') ); 127 sc_arr.push( check_length('input','frm_header_backgroundcolor_left') ); 128 sc_arr.push( check_length('input','frm_header_textcolor') ); 129 sc_arr.push( check_length('input','frm_header_textcolor_left') ); 130 131 sc_arr.push( check_length('input','frm_table_height') ); 132 sc_arr.push( check_length('input','frm_table_width') ); 133 sc_arr.push( check_length('select','frm_fixed_leftcol') ); 134 sc_arr.push( check_length('input','frm_table_offset_header') ); 135 136 //General files/paths/format 137 sc_arr.push( check_length('select','frm_show_onlyloggedin') ); 138 sc_arr.push( check_length('input','frm_path') ); 139 sc_arr.push( check_length('select','frm_source_type') ); 140 sc_arr.push( check_length('select','frm_skip_headerrow') ); 141 sc_arr.push( check_length('select','frm_headerrow_exists') ); 142 sc_arr.push( check_length('select','frm_editable') ); 143 sc_arr.push( check_length('input','frm_source_files') ); 144 sc_arr.push( check_length('input','frm_eol_detection') ); 145 sc_arr.push( check_length('input','frm_title') ); 146 sc_arr.push( check_length('input','frm_csv_delimiter') ); 147 sc_arr.push( check_length('input','frm_float_divider') ); 148 sc_arr.push( check_length('select','frm_fetch_lastheaders') ); 149 sc_arr.push( check_length('select','frm_add_ext_auto') ); 150 sc_arr.push( check_length('select','frm_large_files') ); 151 152 //Encoding 153 sc_arr.push( check_length('select','frm_convert_encoding_from') ); 154 sc_arr.push( check_length('select','frm_convert_encoding_to') ); 155 156 //Sorting 157 sc_arr.push( check_length('input','frm_sort_cols') ); 158 sc_arr.push( check_length('input','frm_sort_cols_order') ); 159 sc_arr.push( check_length('select','frm_sort_cols_userclick') ); 160 sc_arr.push( check_length('select','frm_sort_cols_userclick_arrows') ); 161 162 //Rows and columns 163 sc_arr.push( check_length('input','frm_include_rows') ); 164 sc_arr.push( check_length('input','frm_include_cols') ); 165 sc_arr.push( check_length('input','frm_exclude_cols') ); 166 sc_arr.push( check_length('input','frm_hide_cols') ); 167 sc_arr.push( check_length('input','frm_headerrows_start') ); 168 169 //Filter 170 sc_arr.push( check_length('input','frm_filter_data') ); 171 sc_arr.push( check_length('input','frm_filter_criterias') ); 172 sc_arr.push( check_length('input','frm_filter_removechars') ); 173 sc_arr.push( check_length('select','frm_filter_operator') ); 174 sc_arr.push( check_length('input','frm_filter_col') ); 175 176 //Grouping 177 sc_arr.push( check_length('select','frm_groupby_col') ); 178 sc_arr.push( check_length('select','frm_groupby_col_header') ); 179 180 //Table in columns 181 sc_arr.push( check_length('input','frm_table_in_cell_wrapperclass') ); 182 sc_arr.push( check_length('input','frm_table_in_cell_header') ); 183 sc_arr.push( check_length('input','frm_table_in_cell_cols') ); 184 185 //Pagination 186 sc_arr.push( check_length('select','frm_pagination') ); 187 sc_arr.push( check_length('select','frm_pagination_below_table') ); 188 sc_arr.push( check_length('select','frm_pagination_above_table') ); 189 sc_arr.push( check_length('input','frm_pagination_start') ); 190 sc_arr.push( check_length('input','frm_pagination_text_start') ); 191 sc_arr.push( check_length('input','frm_pagination_text_prev') ); 192 sc_arr.push( check_length('input','frm_pagination_text_next') ); 193 sc_arr.push( check_length('input','frm_pagination_text_last') ); 194 sc_arr.push( check_length('input','frm_pagination_rows') ); 195 sc_arr.push( check_length('input','frm_pagination_links_max') ); 196 197 //Search 198 sc_arr.push( check_length('select','frm_search_functionality') ); 199 sc_arr.push( check_length('select','frm_search_caseinsensitive') ); 200 sc_arr.push( check_length('select','frm_search_exactmatch') ); 201 sc_arr.push( check_length('input','frm_search_cols') ); 202 sc_arr.push( check_length('select','frm_hidetable_load') ); 203 sc_arr.push( check_length('select','frm_hidetable_reset') ); 204 sc_arr.push( check_length('select','frm_search_realtime') ); 205 sc_arr.push( check_length('input','frm_searchbutton_text') ); 206 sc_arr.push( check_length('input','frm_resetbutton_text') ); 207 sc_arr.push( check_length('input','frm_searchinput_placeholder') ); 208 sc_arr.push( check_length('input','frm_notfound_message') ); 209 sc_arr.push( check_length('input','frm_search_requiredchars') ); 210 sc_arr.push( check_length('input','frm_search_requiredchars_message') ); 211 sc_arr.push( check_length('select','frm_search_highlight') ); 212 sc_arr.push( check_length('input','frm_search_highlightcolor') ); 213 sc_arr.push( check_length('select', 'frm_search_excludedrows') ); 214 215 //Totals 216 sc_arr.push( check_length('input','frm_totals_cols_bottom') ); 217 sc_arr.push( check_length('input','frm_totals_cols_bottom_countlines') ); 218 sc_arr.push( check_length('input','frm_totals_cols_bottom_empty') ); 219 sc_arr.push( check_length('input','frm_totals_cols_bottom_title') ); 220 sc_arr.push( check_length('input','frm_totals_cols_bottom_title_col') ); 221 sc_arr.push( check_length('input','frm_totals_cols_prefix') ); 222 sc_arr.push( check_length('input','frm_totals_cols_suffix') ); 223 sc_arr.push( check_length('select','frm_total_percentage_above_table') ); 224 sc_arr.push( check_length('select','frm_total_percentage_below_table') ); 225 sc_arr.push( check_length('input','frm_total_percentage_checkvalue') ); 226 sc_arr.push( check_length('select','frm_total_percentage_col') ); 227 sc_arr.push( check_length('input','frm_total_percentage_text') ); 228 sc_arr.push( check_length('input','frm_total_percentage_decimals') ); 229 230 //Fetching 231 sc_arr.push( check_length('select','frm_fetch_interval') ); 232 sc_arr.push( check_length('select','frm_downloadable') ); 233 sc_arr.push( check_length('input','frm_downloadable_text') ); 234 sc_arr.push( check_length('input','frm_downloadable_filename') ); 235 236 //Communication 237 sc_arr.push( check_length('input','frm_selected_sheets') ); 238 sc_arr.push( check_length('select','frm_api_cdn') ); 239 sc_arr.push( check_length('input','frm_json_startlevel') ); 240 sc_arr.push( check_length('select','frm_design_template') ); 241 242 //Automatic converts 243 sc_arr.push( check_length('input','frm_dateformat') );
244 sc_arr.push ( check_length('select', 'frm_markdown_support')); 245 sc_arr.push ( check_length('select', 'frm_htmltags_autoconvert')); 246 sc_arr.push ( check_length('select', 'frm_htmltags_autoconvert_newwindow')); 247 sc_arr.push ( check_length('input', 'frm_htmltags_autoconvert_imagealt')); 248 sc_arr.push ( check_length('input', 'frm_htmltags_autoconvert_imagewidth')); 249 250 sc_arr.push ( check_length('select', 'frm_grabcontent_col_fromlink')); 251 sc_arr.push ( check_length('select', 'frm_grabcontent_col_tolink')); 252 sc_arr.push ( check_length('select', 'frm_grabcontent_col_tolink_addhttps')); 253 254 sc_arr.push(']'); 255 256 $('#new_shortcode').val( sc_arr.join("") ); 257 258 } 259 260 //If path / files etc has changed, values in form must be updated 261 //regarding to columns, rows etc 262 window.updatevalues_fromshortcode = function() { 263 let selected_value = $('#new_shortcode').val(); 264 265 var current_url = my_ajax_object.ajax_url; 266 267 //Store focus and position of textarea 268 let isFocused = $('#new_shortcode').is(':focus');
269 let cursorPos = $('#new_shortcode')[0].selectionStart; 270 271 $.ajax({ 272 url: current_url, 273 method: 'POST', 274 dataType: 'html', 275 data:{ 276 security: my_ajax_object.security, // Include the nonce 277 action: 'refreshform', 278 doshortcode: 'no', 279 shortcode: selected_value 280 } 281 }) 282 .done(function( response ) { 283 $('#dynamic_form').html( response ); 284 285 //Restore focus and position of textarea after update dynamic form 286 if (isFocused) { 287 $('#new_shortcode').focus(); 288 $('#new_shortcode')[0].setSelectionRange(cursorPos, cursorPos); 289 } 290 291 $("div.csvtohtml-p.admin h2").on( "click", function() { 292 $(this).parent().toggleClass('selectedsection'); 293 294 if ( $(this).parent().hasClass("reflist") ) { 295 $("#csvtohtml-referencelist-csvtohtml-plugin").toggle(); 296 } 297 else { 298 $(this).parent().find('table').toggle(); 299 } 300 }); 301 302 showresult_shortcode(); //Put this in preview div 303 }) 304 .fail(function(textStatus) { 305 $("#update_shortcode").fadeIn(1000); 306 $("#new_shortcode").fadeIn(2000); 307 console.log('failed updatevalues_fromshortcode'); 308 console.log(textStatus); 309 }); 310 } 311 312 //Init preview shortcode 313 if ($('#new_shortcode').length >0) { 314 updatevalues_fromshortcode(); 315 } 316 317 //Show result of generated shortcode in preview-div 318 function showresult_shortcode() { 319 let selected_value = $('#new_shortcode').val(); 320 var current_url = my_ajax_object.ajax_url; 321 322 //Shortcode preview 323 $.ajax({
324 url: current_url, 325 method: 'POST', 326 dataType: 'html', 327 data:{ 328 security: my_ajax_object.security, // Include the nonce 329 action: 'refreshform', 330 doshortcode: 'yes', 331 shortcode: selected_value 332 } 333 }) 334 .done(function( response ) { 335 $('#shortcode_preview').html( response ); 336 $('table.csvtohtml').show(); //Must be here, because invisible from start! 337 $("#update_shortcode").fadeIn(1000); //Preview-button should be available again 338 $("#new_shortcode").fadeIn(2000); 339 $('body').css('cursor','default'); 340 }) 341 .fail(function(textStatus) { 342 console.log('failed showresult_shortcode'); 343 console.log(textStatus); 344 }); 345 } 346 347 $('body').on('click', '#update_shortcode', function() { 348 $(this).fadeOut(1000); 349 $("#new_shortcode").fadeOut(2000); 350 $('body').css('cursor','wait'); 351 updatevalues_fromshortcode(); 352 }); 353 354 //Create short dynamically when user types / changes anything 355 $('body').on('keyup', 'input', function() { 356 generate_shortcode(); 357 }); 358 359 $('body').on('click', '#pathviewer', function(e) { 360 e.preventDefault(); 361 $('#uploadpaths').toggle(); 362 }); 363 364 $('body').on('click', '#fileviewer', function(e) { 365 e.preventDefault(); 366 $('#fileview').toggle(); 367 }); 368 369 $('body').on('click', 'a.filelink', function(e) { 370 e.preventDefault(); 371 let clicked_file = $(this).data('basename'); 372 let current_val = $('input[name="frm_source_files"]').val(); 373 if ( current_val == '*.csv') { 374 current_val = ''; 375 } 376 add_char = ''; 377 if (current_val.length > 0) { 378 add_char = ';'; 379 } 380 381 $('input[name="frm_source_files"]').val( current_val + add_char + clicked_file ) ; 382 generate_shortcode(); 383 }); 384 385 //Debugging events 386 $('body').on('click', '.useguess', function(e) { 387 e.preventDefault(); 388 $('select[name="frm_source_type"]').val('guess'); 389 generate_shortcode(); 390 }); 391 392 $('body').on('click', '#identifydelimiter', function(e) { 393 e.preventDefault(); 394 $('input[name="frm_csv_delimiter"]').val( ',' ); 395 generate_shortcode(); 396 }); 397 398 $('body').on('click', '#removeencodings', function(e) { 399 e.preventDefault(); 400 $('select[name="frm_convert_encoding_from"]').val( '' ); 401 $('select[name="frm_convert_encoding_to"]').val( '' ); 402 generate_shortcode(); 403 }); 404 405 $('body').on('click', '#removefilter', function(e) { 406 e.preventDefault(); 407 $('input[name="frm_filter_data"]').val( '' ); 408 $('select[name="frm_filter_col"]')[0].selectedIndex = 0; 409 generate_shortcode(); 410 }); 411 //End debugging events 412 413 414 //This is used when user might have mispelled a file 415 $('body').on('click', '.changefile', function(e) { 416 e.preventDefault(); 417 let old_file = $('.adjustspelling').data('file'); 418 let new_file = $(this).parent().find('.adjustspelling').html(); 419 420 //Replace file and put replacement in source_files 421 let current_sourcefiles = $('input[name="frm_source_files"]').val(); 422 let cs = current_sourcefiles.replace( old_file, new_file ); 423 $('input[name="frm_source_files"]').val(cs); 424 generate_shortcode(); 425 updatevalues_fromshortcode(); 426 }); 427 428 429 430 431 $('body').on('click', 'a.pathlink', function(e) { 432 e.preventDefault(); 433 let clickedon_folder = $(this).html(); 434 435 //Set input folderpath and also replace/add to baseupload folder for csv-files 436 $('input[name="frm_path"]').val( clickedon_folder ); 437 $('#csvtohtmlsettings-path').html( clickedon_folder ); 438 generate_shortcode(); 439 updatevalues_fromshortcode(); 440 });
441 442 $('body').on('change', 'select', function() { 443 generate_shortcode(); 444 }); 445 446 //Total (bottom of table) 447 $('body').on('click', 'div input[name^="totalcl"]', function() { 448 449 let total_cols_bottom = ''; 450 $('div input[name^="totalcl"]').each(function( index ) { 451 if ( $(this).is(':checked')) { 452 total_cols_bottom += '' + (index+1) + ','; 453 } 454 455 456 }); 457 458 //Remove last char 459 total_cols_bottom = total_cols_bottom.slice(0, -1); 460 $('input[name="frm_totals_cols_bottom"]').val(total_cols_bottom); 461 generate_shortcode(); 462 463 }); 464 465 $('body').on('click', 'div input[name^="sorting"]', function() { 466 doSort(); 467 }); 468 469 $('body').on('change', 'div select[name^="sortiteration_col"]', function() { 470 doSort(); 471 }); 472 473 function doSort() { 474 var str_sort = ''; 475 var str_sort_direction = ''; 476 var row = 1; 477 478 var icol = []; 479 $('div select[name^="sortiteration_col"]').each(function( index ) { 480 481 var this_name = $(this).attr('name'), 482 col_number = this_name.split('[')[1].split(']')[0]; 483 var iteration = $('div select[name="sortiteration_col[' + col_number + ']"'); 484 485 var iteration_nr = null; 486 if (iteration.length>0) { 487 iteration_nr = parseInt(iteration.val()); 488 } 489 icol.push( iteration_nr ); 490 491 }); 492 493 494 495 //Rearrange iteration/sortingorder values for column array 496 var iterationorder_col = []; 497 var sortorder_col = []; 498 var use_col; 499 500 for (var i = 0; i < icol.length; i++) { 501 use_col = icol.indexOf(i) + 1; 502 503 //Iteration order (in which order column(s) are sorted) 504 iterationorder_col[i] = use_col; //+1 to tell which column 505 506 //Sortorder (asc,desc,ignore) 507 var this_obj = $('div input[name="sorting[' + use_col + ']"'); 508 var use_data = ''; 509 this_obj.each(function( index ) { 510 if ($(this).is(':checked')) { 511 use_data = $(this).data('num'); 512 return false; 513 } 514 }); 515 516 sortorder_col.push(use_data); 517 518 } 519 520 //Generate final attribute inclusion of sorting columns 521 //Skip when nosort or col is set to zero 522 for(i=0;i<iterationorder_col.length;i++) { 523 if ( sortorder_col[i] !== 'nosort' && iterationorder_col[i]>0) { 524 str_sort += '' + iterationorder_col[i] + ','; 525 str_sort_direction += sortorder_col[i] + ','; 526 } 527 }; 528 529 //Remove last char 530 str_sort = str_sort.slice(0, -1); 531 str_sort_direction = str_sort_direction.slice(0, -1); 532 533 $('#sort_str').val(str_sort); 534 $('#sort_str_direction').val(str_sort_direction); 535 536 generate_shortcode(); 537 538 }; 539 540 //Change location of (local) files when modifiying path 541 $('body').on('keyup', 'div input[name="frm_path"]', function(){ 542 $('#csvtohtmlsettings-path').html($(this).val()); 543 }); 544 545 //Inclusion of cell table in cells functionality 546 $('body').on('click', 'div input[name^="tableincellsclude"]', function(){ 547 var str_include = ''; 548 var str_exclude = ''; 549 550 var clude_arr = $('div input[name^="tableincellsclude"]'); 551 if (clude_arr.length > 0) { 552 553 str_include = ''; 554 555 //Go through all include/exclude radio buttons 556 clude_arr.each(function( index ) { 557 558 if ($(this).is(':checked')) { 559 var current_data = $(this).data('num'); 560 561 //Get column of checked radiobutton... 562 var this_name = $(this).attr('name'), 563 col_number = this_name.split('[')[1].split(']')[0]; 564 565 //Get values from data-attr for clude[col] 566 if (current_data == 'ignore') { 567 //Remove this columns values from both include and exclude 568 str_include = str_include.replace( col_number + ',', ''); 569 } 570 if (current_data == 'include') { 571 str_include += col_number + ','; 572 } 573 574 } 575 }); 576 577 //Remove last char 578 str_include = str_include.slice(0, -1); 579 str_exclude = str_exclude.slice(0, -1); 580 581 if (str_include == 'include_cols="') { 582 str_include = ''; 583 } 584 585 $('#table_in_cell_cols').val(str_include); 586 587 generate_shortcode(); 588 } 589 590 });
591 592 593 //Filter on columns 594 $('body').on('click', 'div input[name^="filter_includecols"]', function(){ 595 596 var str_include = ''; 597 598 var filtercols_arr = $('div input[name^="filter_includecols"]'); 599 if (filtercols_arr.length > 0) { 600 601 str_include = ''; 602 var nr_cols = 0; 603 604 //Go through all include in search radio buttons 605 filtercols_arr.each(function( index ) { 606 607 if ($(this).is(':checked')) { 608 var current_data = $(this).data('num'); 609 610 //Get column of checked radiobutton... 611 var this_name = $(this).attr('name'), 612 col_number = this_name.split('[')[1].split(']')[0]; 613 614 //Get values from data-attr for clude_search[col] 615 if (current_data == 'ignore') { 616 //Remove this columns values 617 str_include = str_include.replace( col_number + ',', ''); 618 } 619 if (current_data == 'include') { 620 str_include += col_number + ','; 621 } 622 623 } 624 625 nr_cols++; 626 }); 627 628 //Remove last char 629 str_include = str_include.slice(0, -1); 630 631 if (str_include == 'filter_col="') { 632 str_include = ''; 633 } 634 635 } 636 637 $('#include_filtercols_shortcode_str').val(str_include); 638 639 generate_shortcode(); 640 641 }); 642 643 //Search in columns 644 $('body').on('click', 'div input[name^="search_includecols"]', function(){ 645 646 var str_include = ''; 647 648 var searchincols_arr = $('div input[name^="search_includecols"]'); 649 if (searchincols_arr.length > 0) { 650 651 str_include = ''; 652 var nr_cols = 0; 653 654 //Go through all include in search radio buttons 655 searchincols_arr.each(function( index ) { 656 657 if ($(this).is(':checked')) { 658 var current_data = $(this).data('num'); 659 660 //Get column of checked radiobutton... 661 var this_name = $(this).attr('name'), 662 col_number = this_name.split('[')[1].split(']')[0]; 663 664 //Get values from data-attr for clude_search[col] 665 if (current_data == 'ignore') { 666 //Remove this columns values 667 str_include = str_include.replace( col_number + ',', ''); 668 } 669 if (current_data == 'include') { 670 str_include += col_number + ','; 671 } 672 673 } 674 675 nr_cols++; 676 }); 677 678 //Remove last char 679 str_include = str_include.slice(0, -1); 680 681 if (str_include == 'search_cols="') { 682 str_include = ''; 683 } 684 685 } 686 687 $('#include_searchcols_shortcode_str').val(str_include); 688 689 generate_shortcode(); 690 691 }); 692 693 694 //Include/Exclusion of columns 695 $('body').on('click', 'div input[name^="clude"]', function(){ 696 var str_include = ''; 697 var str_exclude = ''; 698 var str_hide = ''; 699 700 var clude_arr = $('div input[name^="clude"]'); 701 if (clude_arr.length > 0) { 702 703 str_include = ''; 704 str_exclude = ''; 705 str_hide = ''; 706 var nr_cols = 0; 707 708 //Go through all include/exclude radio buttons 709 clude_arr.each(function( index ) { 710 711 if ($(this).is(':checked')) { 712 var current_data = $(this).data('num'); 713 714 //Get column of checked radiobutton... 715 var this_name = $(this).attr('name'), 716 col_number = this_name.split('[')[1].split(']')[0]; 717 718 //Get values from data-attr for clude[col] 719 if (current_data == 'ignore') { 720 //Remove this columns values from both include and exclude 721 str_include = str_include.replace( col_number + ',', ''); 722 str_exclude = str_exclude.replace( col_number + ',', ''); 723 str_hide = str_hide.replace( col_number + ',', '' ); 724 } 725 if (current_data == 'include') { 726 str_include += col_number + ','; 727 } 728 if (current_data == 'exclude') { 729 str_exclude += col_number + ','; 730 } 731 if (current_data == 'hide') { 732 str_hide += col_number + ','; 733 } 734 } 735 736 nr_cols++; 737 }); 738 739 //Remove last char 740 str_include = str_include.slice(0, -1); 741 str_exclude = str_exclude.slice(0, -1); 742 str_hide = str_hide.slice(0, -1); 743 744 if (str_include == 'include_cols="') { 745 str_include = ''; 746 } 747 if (str_exclude == 'exclude_cols="') { 748 str_exclude = ''; 749 } 750 if (str_hide == 'hide_cols="') { 751 str_hide = ''; 752 } 753 754 $('#include_shortcode_str').val(str_include); 755 $('#hide_shortcode_str').val(str_hide); 756 let excl_sc = $('#exclude_shortcode_str').val(str_exclude); 757 758 759 //If number of exclusion is set to number of columns 760 if (excl_sc.val().length == nr_cols) { 761 alert('If you exclude everything - nothing is shown!'); 762 } 763 764 } 765 766 generate_shortcode(); 767 768 });
769 770 771 $("div.csvtohtml-p.admin h2").on( "click", function() { 772 $(this).parent().toggleClass('selectedsection'); 773 774 if ( $(this).parent().hasClass("reflist") ) { 775 $("#csvtohtml-referencelist-csvtohtml-plugin").toggle(); 776 } 777 else { 778 $(this).parent().find('table').toggle(); 779 } 780 }); 781 782 783 784 function editable() { 785 786 //If editable is set to yes, this function 787 //is used for the actual saving when changing content in a textinput (with classname savecell) 788 $('.csvtohtml').on('change','.savecell', function(e) { 789 //four levels up are always the same table that user tries to edit in 790 var table_identifier = $(this).parent().parent().parent().parent(); 791 792 //Relevant attributes to use 793 var ds = $(this).data('source'); 794 795 var row_index = $(this).data('filerow'); 796 var csvfile = $(this).data('csvfile'); 797 var delim = $(this).data('delimiter'); 798 var csv_editrow = []; 799 var csv_headers = []; 800 var csv_row = ''; 801 var all_content_file = null; 802 803 //Headers 804 $(table_identifier).find('tr.headers[data-source="' + ds +'"]').each(function(index) { 805 csv_row = ''; 806 $(this).find('.savecell').each(function(inner_index) { 807 csv_row += '' + $(this).val() + delim; 808 }); 809 810 csv_headers.push( csv_row.slice(0,-1) ); //Remove last char in string (delimiter) 811 }); 812 813 //All row content for this specific file 814 var shortcode_attributes = table_identifier.parent().find('form.sc_attributes'); //If using pagination 815 all_content_file = shortcode_attributes.find('.all-rowcontent[data-source="' + ds +'"]').html(); 816 817 //Grab which row is edited for this specific file and add that to a new array with index as row_index 818 var row_content = $(table_identifier).find('tr.rowset[data-source="' + ds +'"]').find('.savecell[data-filerow="' + row_index + '"]'); 819 820 //Create a string of current row 821 csv_row = ''; 822 row_content.each(function(inner_index) { 823 csv_row += $(this).val() + delim; 824 }); 825 826 //Put this string into array with given row (file) index 827 csv_editrow[row_index] = csv_row.slice(0,-1); //Remove last char in string 828 829 830 //Save the actual content 831 //with help / request to server-side 832 var current_url = my_ajax_object.ajax_url; 833 834 $.ajax({
835 url: current_url, 836 method: 'POST', 837 dataType: 'json', 838 data:{ 839 action: 'savecsvfile', 840 security: my_ajax_object.security, // Include the nonce 841 filerow: row_index, 842 csvcontent: csv_editrow, 843 csvheaders: csv_headers, 844 allcontent: all_content_file, 845 csvfile: csvfile, //this value is part of this filename 846 attrs: shortcode_attributes.serialize() 847 } 848 }) 849 .done(function( response ) { 850 //Update all updated values into html content all-rowscontent for saving correctly 851 //several times/values in same file 852 shortcode_attributes.find('.all-rowcontent[data-source="' + ds +'"]').html(response.allcontent); 853 }) 854 .fail(function(textStatus) { 855 alert('failed saving'); 856 console.log(textStatus); 857 }); 858 859 }); 860 } 861 862 editable(); 863 864 var searching = false; 865 866 function checkSearchRealtime() { 867 var timeout; 868 var delay = 1000; // 1 second //Get this value from attributes 869 870 //If user presses enter, handle it as an ordinary search 871 $('.csv-search').on('keypress','.search-text', function(e) { 872 if (e.which == 13 ) { 873 searchTable(e, $(this).parent().find('.search-submit')); 874 return false; 875 } 876 }); 877 878 $('.csv-search').on('keyup','.search-text', function(e) { 879 //If user presesed enter, don't do anything (it's done in keypress above) 880 if (e.which == 13 ) { 881 return false; 882 } 883 884 var ev = e; 885 var t = $(this); 886 887 //Check if realtimesearch is set to yes for this table 888 //and do the search then 889 var attrs = t.parent().parent().parent().find('.sc_attributes'); 890 var srt = attrs.find('input[name="search_realtime"]'); 891 if (srt.length>0) { 892 if (srt.val() == 'yes') { 893 if(timeout) { 894 clearTimeout(timeout); 895 } 896 timeout = setTimeout(function() { 897 searchTable(ev, t); 898 }, delay); 899 } 900 } 901 }); 902 } 903 904 checkSearchRealtime(); 905 906 907 908 909 910 $('.csv-search').on('click','.search-submit', function(e) { 911 searchTable(e, $(this)); 912 }); 913 914 $('.csv-search').on('click','.reset-submit', resetTable); 915 916 917 function sortTable(e, tablewrapper_obj, colnr, sort_direction) { 918 e.preventDefault(); 919 var shortcode_attributes = tablewrapper_obj.find('form.sc_attributes'); 920 921 $('body').css('cursor','wait'); 922 tablewrapper_obj.find('table.csvtohtml').find('thead th').css('cursor','wait'); 923 $('.csv-search').css('cursor', 'wait'); 924 $('.csv-search form').css('cursor', 'wait'); 925 $('.csv-search input').css('cursor', 'wait'); 926 927 var current_url = my_ajax_object.ajax_url; 928 $.ajax({
929 url: current_url, 930 method: 'POST', 931 dataType: 'json', 932 data:{ 933 security: my_ajax_object.security, // Include the nonce 934 action: 'fetchtable', 935 attrs: shortcode_attributes.serialize(), 936 pagination_start: 1, //always start at page 1 when search result is presented 937 dosort: "yes", 938 column: colnr, 939 direction: sort_direction 940 } 941 }) 942 .done(function( response ) { 943 $('body').css('cursor','default'); 944 $('.csv-reset').off('click', '.search-submit'); 945 $('.csv-reset').off('click', '.reset-submit'); 946 $('.csv-search').off('keyup','.search-text'); 947 $('.csvhtml-pagination').off('click', 'a'); 948 $('table.csvtohtml-sortable').find('thead th').off('click'); 949 950 tablewrapper_obj[0].outerHTML = response.tabledata; 951 952 //Reinitiate for click to work after replacing html-content table/pagination 953 $('.csv-search').on('click','.search-submit', function(e) { 954 searchTable(e, $(this)) 955 }); 956 $('.csvhtml-pagination').on('click', 'a', reloadTable); 957 $('.csv-search').on('click','.reset-submit', resetTable); 958 checkSearchRealtime(); 959 960 $('table.csvtohtml-sortable').find('thead th').on('click',function(e) { 961 doSorting(e, $(this)); 962 }); 963 964 tablewrapper_obj.find('table.csvtohtml').find('thead th').css('cursor','default'); 965 $('table.csvtohtml').show(); 966 }) 967 .fail(function(textStatus) { 968 $('body').css('cursor','default'); 969 $('.csv-search').css('cursor', 'default'); 970 $('.csv-search form').css('cursor', 'default'); 971 $('.csv-search input').css('cursor', 'default'); 972 $('.csv-search').off('click', '.search-submit'); 973 $('.csvhtml-pagination').off('click', 'a'); 974 $('.csv-search').off('click', '.reset-submit'); 975 $('.csv-search').off('keyup','.search-text'); 976 $('table.csvtohtml-sortable').find('thead th').off('click'); 977 978 $('.csv-search').on('click','.search-submit', function(e) { 979 searchTable(e, $(this)) 980 }); 981 checkSearchRealtime(); 982 $('.csvhtml-pagination').on('click', 'a', reloadTable); 983 $('.csv-search').on('click','.reset-submit', resetTable); 984 $('table.csvtohtml-sortable').find('thead th').on('click',function(e) { 985 doSorting(e, $(this)); 986 }); 987 tablewrapper_obj.find('table.csvtohtml').find('thead th').css('cursor','default'); 988 console.log('failed resetTable'); 989 console.log(textStatus); 990 }); 991 }; 992 993 function resetTable(e) { 994 e.preventDefault(); 995 var h = $(this).data(); 996 var tablewrapper_obj = $('#wrapper-' + h.htmlid); 997 var shortcode_attributes = tablewrapper_obj.find('form.sc_attributes'); 998 999 $('body').css('cursor','wait'); 1000 $('.csv-search').css('cursor', 'wait'); 1001 $('.csv-search form').css('cursor', 'wait'); 1002 $('.csv-search input').css('cursor', 'wait'); 1003 1004 var current_url = my_ajax_object.ajax_url; 1005 $.ajax({
1006 url: current_url, 1007 method: 'POST', 1008 dataType: 'json', 1009 data:{ 1010 security: my_ajax_object.security, // Include the nonce 1011 action: 'fetchtable', 1012 attrs: shortcode_attributes.serialize(), 1013 pagination_start: 1, //always start at page 1 when search result is presented 1014 reset: 1 1015 } 1016 }) 1017 .done(function( response ) { 1018 $('body').css('cursor','default'); 1019 $('.csv-search').css('cursor', 'default'); 1020 $('.csv-search form').css('cursor', 'default'); 1021 $('.csv-search input').css('cursor', 'default'); 1022 $('.csv-reset').off('click', '.search-submit'); 1023 $('.csv-reset').off('click', '.reset-submit'); 1024 $('.csv-search').off('keyup','.search-text'); 1025 $('.csvhtml-pagination').off('click', 'a'); 1026 $('table.csvtohtml-sortable').find('thead th').off('click'); 1027 tablewrapper_obj[0].outerHTML = response.tabledata; 1028 1029 //Reinitiate for click to work after replacing html-content table/pagination 1030 $('.csv-search').on('click','.search-submit', function(e) { 1031 searchTable(e, $(this)) 1032 }); 1033 $('.csvhtml-pagination').on('click', 'a', reloadTable); 1034 $('.csv-search').on('click','.reset-submit', resetTable); 1035 $('table.csvtohtml-sortable').find('thead th').on('click',function(e) { 1036 doSorting(e, $(this)); 1037 }); 1038 checkSearchRealtime(); 1039 $('table.csvtohtml').show(); 1040 }) 1041 .fail(function(textStatus) { 1042 $('body').css('cursor','default'); 1043 $('.csv-search').css('cursor', 'default'); 1044 $('.csv-search form').css('cursor', 'default'); 1045 $('.csv-search input').css('cursor', 'default'); 1046 $('.csv-search').off('click', '.search-submit'); 1047 $('.csvhtml-pagination').off('click', 'a'); 1048 $('.csv-search').off('click', '.reset-submit'); 1049 $('.csv-search').off('keyup','.search-text'); 1050 $('table.csvtohtml-sortable').find('thead th').off('click'); 1051 1052 $('.csv-search').on('click','.search-submit', function(e) { 1053 searchTable(e, $(this)) 1054 }); 1055 checkSearchRealtime(); 1056 $('.csvhtml-pagination').on('click', 'a', reloadTable); 1057 $('.csv-search').on('click','.reset-submit', resetTable); 1058 $('table.csvtohtml-sortable').find('thead th').on('click',function(e) { 1059 doSorting(e, $(this)); 1060 }); 1061 console.log('failed resetTable'); 1062 console.log(textStatus); 1063 }); 1064 }; 1065 1066 function searchTable(e, ths) { 1067 if ( searching == true ) { 1068 return false; 1069 } 1070 1071 searching = true; 1072 e.preventDefault(); 1073 var search_text = ths.parent().find('.search-text').val(); 1074 var h = ths.data(); 1075 var tablewrapper_obj = $('#wrapper-' + h.htmlid); 1076 var shortcode_attributes = tablewrapper_obj.find('form.sc_attributes'); 1077 1078 $('body').css('cursor','wait'); 1079 $('.csv-search').css('cursor', 'wait'); 1080 $('.csv-search form').css('cursor', 'wait'); 1081 $('.csv-search input').css('cursor', 'wait'); 1082 1083 var current_url = my_ajax_object.ajax_url; 1084 $.ajax({
1085 url: current_url, 1086 method: 'POST', 1087 dataType: 'json', 1088 data:{ 1089 security: my_ajax_object.security, // Include the nonce 1090 action: 'fetchtable', 1091 attrs: shortcode_attributes.serialize(), 1092 pagination_start: 1, //always start at page 1 when search result is presented 1093 search: search_text 1094 } 1095 }) 1096 .done(function( response ) { 1097 $('body').css('cursor','default'); 1098 $('.csv-search').css('cursor', 'default'); 1099 $('.csv-search form').css('cursor', 'default'); 1100 $('.csv-search input').css('cursor', 'default'); 1101 $('.csv-search').off('click', '.search-submit'); 1102 $('.csvhtml-pagination').off('click', 'a'); 1103 $('.csv-search').off('click', '.reset-submit'); 1104 $('.csv-search').off('keyup','.search-text'); 1105 $('table.csvtohtml-sortable').find('thead th').off('click'); 1106 tablewrapper_obj[0].outerHTML = response.tabledata; 1107 1108 1109 //Reinitiate for click to work after replacing html-content table/pagination 1110 $('.csv-search').on('click','.search-submit', function(e) { 1111 searchTable(e, $(this)) 1112 }); 1113 $('.csvhtml-pagination').on('click', 'a', reloadTable); 1114 $('.csv-search').on('click','.reset-submit', resetTable); 1115 checkSearchRealtime(); 1116 $('table.csvtohtml-sortable').find('thead th').on('click',function(e) { 1117 doSorting(e, $(this)); 1118 }); 1119 $('table.csvtohtml').show(); 1120 searching = false; 1121 }) 1122 .fail(function(textStatus) { 1123 ths.disabled = false; 1124 $('body').css('cursor','default'); 1125 $('.csv-search').css('cursor', 'default'); 1126 $('.csv-search form').css('cursor', 'default'); 1127 $('.csv-search input').css('cursor', 'default'); 1128 $('.csv-search').off('click', '.search-submit'); 1129 $('.csvhtml-pagination').off('click', 'a'); 1130 $('.csv-search').off('click', '.reset-submit'); 1131 $('.csv-search').off('keyup','.search-text'); 1132 $('table.csvtohtml-sortable').find('thead th').off('click'); 1133 1134 $('.csv-search').on('click','.search-submit', function(e) { 1135 searchTable(e, $(this)) 1136 }); 1137 $('.csvhtml-pagination').on('click', 'a', reloadTable); 1138 $('.csv-search').on('click','.reset-submit', resetTable); 1139 $('table.csvtohtml-sortable').find('thead th').on('click',function(e) { 1140 doSorting(e, $(this)); 1141 }); 1142 1143 checkSearchRealtime(); 1144 searching = false; 1145 console.log('failed searchTable'); 1146 console.log(textStatus); 1147 }); 1148 }; 1149 1150 1151 //Pagination click - reload table based on what row to start on 1152 //(pagination) 1153 $('.csvhtml-pagination').on('click', 'a', reloadTable); 1154 1155 //this is a separate function because a reinitation is need after every click 1156 //because html is replaced totally from shortcode 1157 function reloadTable(e) { 1158 if (searching == true) {return false;}; 1159 searching = true; 1160 1161 e.preventDefault(); 1162 var h = $(this).data(); 1163 var tablewrapper_obj = $('#wrapper-' + h.htmlid); 1164 var shortcode_attributes = tablewrapper_obj.find('form.sc_attributes'); 1165 1166 $('body').css('cursor','wait'); 1167 $('.csvhtml-pagination').css('cursor', 'wait'); 1168 $('.csvhtml-pagination a').css('cursor', 'wait'); 1169 1170 var current_url = my_ajax_object.ajax_url; 1171 $.ajax({
1172 url: current_url, 1173 method: 'POST', 1174 dataType: 'json', 1175 data:{ 1176 security: my_ajax_object.security, // Include the nonce 1177 action: 'fetchtable', 1178 attrs: shortcode_attributes.serialize(), 1179 pagination_start: h.pagination 1180 } 1181 }) 1182 .done(function( response ) { 1183 $('body').css('cursor','default'); 1184 $('.csvhtml-pagination').css('cursor', 'default'); 1185 $('.csvhtml-pagination a').css('cursor', 'default'); 1186 $('.csv-search').off('click', '.search-submit'); 1187 $('.csvhtml-pagination').off('click', 'a'); 1188 $('.csv-search').off('click', '.reset-submit'); 1189 $('.csv-search').off('keyup','.search-text'); 1190 $('table.csvtohtml-sortable').find('thead th').off('click'); 1191 1192 tablewrapper_obj[0].outerHTML = response.tabledata; 1193 $('.csvhtml-pagination').on('click', 'a', reloadTable); //Reinitiate for click to work after replacing html-content table/pagination 1194 $('.csv-search').on('click','.search-submit', function(e) { 1195 searchTable(e, $(this)) 1196 }); 1197 $('.csv-search').on('click','.reset-submit', resetTable); 1198 checkSearchRealtime(); 1199 editable(); 1200 1201 $('table.csvtohtml-sortable').find('thead th').on('click',function(e) { 1202 doSorting(e, $(this)); 1203 }); 1204 $('table.csvtohtml').show(); 1205 searching = false; 1206 }) 1207 .fail(function(textStatus) { 1208 $('body').css('cursor','default'); 1209 $('.csvhtml-pagination').css('cursor', 'default'); 1210 $('.csvhtml-pagination a').css('cursor', 'default'); 1211 $('.csvhtml-pagination').off('click', 'a'); 1212 $('.csv-search').off('click', '.search-submit'); 1213 $('.csv-search').off('click', '.reset-submit'); 1214 $('.csv-search').off('keyup','.search-text'); 1215 $('.csvhtml-pagination').on('click', 'a', reloadTable); //Reinitiate for click to work after replacing html-content table/pagination 1216 $('.csv-search').on('click','.search-submit', function(e) { 1217 var t = $(this); 1218 searchTable(e, t) 1219 }); 1220 $('table.csvtohtml-sortable').find('thead th').off('click'); 1221 $('.csv-search').on('click','.reset-submit', resetTable); 1222 checkSearchRealtime(); 1223 $('table.csvtohtml-sortable').find('thead th').on('click',function(e) { 1224 doSorting(e, $(this)); 1225 }); 1226 searching = false; 1227 1228 console.log('failed reloadTable'); 1229 console.log(textStatus); 1230 }); 1231 }; 1232});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.