1var sdmt_js; 2jQuery(function ($) { 3 // run on load to assign css classes properly 4 get_send_data(); 5 first_run_select_all(); 6 7 var clipboard = new Clipboard('.sdmt_copy_button'); 8 9 const emptyCartMessage = $('.sdmt_cart-empty-message').clone(); 10 11 clipboard.on('success', 12 function(e){ 13 e.clearSelection(); 14 showTooltip(e.trigger,'Copied!'); 15 }); 16 clipboard.on('error', 17 function(e){ 18 showTooltip(e.trigger,fallbackMessage(e.action)); 19 }); 20 21 $('#sdmt_tabs').tabs({active: 0}); 22 23 $('.sdmt_content').on('click', '.sdmt_toggle_el', function (e) { 24 e.preventDefault(); 25 var th = $(this), 26 target = th.data('target'), 27 search_in = th.data('searchin'), 28 default_text = th.data('defaulttext'), 29 close_text = th.data('closetext'); 30 31 if (th.hasClass('sdmt_open')) { 32 th.closest(search_in).find(target).slideUp(); 33 th.removeClass('sdmt_open'); 34 th.text(default_text); 35 } else { 36 th.closest(search_in).find(target).slideDown(); 37 th.addClass('sdmt_open'); 38 th.text(close_text); 39 } 40 }); 41 42 // $('.swipebox').swipebox(); 43 $('.swipebox').swipebox('.swipebox'); 44 45 var doc_center_success = function (response, target, target_docs, parent) { 46 if (typeof(response.terms) !== 'undefined') { 47 add_doc_content(response, target); 48 } 49 if (typeof(response.docs) !== 'undefined') { 50 add_doc_file_content(response, target_docs); 51 } 52 parent.addClass('loaded').addClass('open'); 53 }; 54 55 56 var es_products_success = function (response, target, target_docs, parent) { 57 if (typeof(response.terms) !== 'undefined') { 58 add_doc_content(response, target); 59 } 60 if (typeof(response.products) !== 'undefined') { 61 add_product_content(response, target_docs); 62 } 63 parent.addClass('loaded').addClass('open'); 64 }; 65 66 var es_details_success = function (response, target, target_docs, parent) { 67 if (typeof(response.terms) !== 'undefined') { 68 add_series_content(response, target); 69 } 70 if (typeof(response.docs) !== 'undefined') { 71 add_series_file_content(response, target_docs); 72 } 73 parent.addClass('loaded').addClass('open'); 74 }; 75 76 var doc_center = $('#sto_documentation_center'); 77 if (doc_center.length > 0) { 78 var action = 'sto_get_acc_content'; 79 var opts = {}; 80 var success_function = doc_center_success; 81 if ( typeof(doc_center.data('type')) !== 'undefined' ) { 82 if ( doc_center.data('type') == 'add_products' ) { 83 action = 'sdmt_es_products_content'; 84 success_function = es_products_success; 85 opts = doc_center.data('project_id'); 86 } 87 if ( doc_center.data('type') == 'add_details' ) { 88 action = 'sdmt_es_details_content'; 89 success_function = es_details_success; 90 opts = doc_center.data('project_id'); 91 } 92 } 93 doc_center.on('click', '.sdmt_doc_center_open', function (e) { 94 e.preventDefault(); 95 var th = $(this); 96 var parent = th.parent(); 97 if (parent.hasClass('loaded')) { 98 return parent.toggleClass('open'); 99 } 100 sdmt_loader(th,0); 101 var id = $(this).data('id'); 102 var tax = $(this).data('get'); 103 var current = $(this).data('current'); 104 var target = $(this).parent().find('.sdmt_doc_center_categories'); 105 var target_docs = $(this).parent().find('.sdmt_doc_center_docs'); 106 var taxes = getTaxes($(this)); 107 var send_obj = { 108 action: action, 109 id: id, 110 tax: tax, 111 opts : opts, 112 current: current, 113 taxes: taxes 114 }; 115 $.ajax({ 116 url: sdmt_js.ajax_url, 117 data: send_obj, 118 dataType: 'json', 119 success: function(data) { 120 success_function(data, target, target_docs, parent); 121 sdmt_loader(th,1); 122 } 123 }); 124 }); 125 126 function getTaxes(el, taxes) { 127 if ( typeof(taxes) == 'undefined' ) { 128 taxes = []; 129 } 130 131 taxes.push({'tax':el.data('get'), id:el.data('id')}); 132 var parent = el.parent().parent(); 133 var next_search = parent.closest('.loaded'); 134 var next_el = next_search.children('.sdmt_doc_center_title'); 135 136 if ( next_el.length > 0 ) { 137 return getTaxes(next_el, taxes); 138 } else { 139 return taxes; 140 } 141 } 142 143 // get the cart 144 const add_cart_el = $('.sdmt_file_cart_selected').first(); 145 // add to cart 146 doc_center.on('click', '.sdmt_docs_add_file', function (e) { 147 e.preventDefault(); 148 e.stopPropagation(); 149 150 // get parent 151 const parent = $(this).parent(); 152 const self = $(this); 153 let addHappened = false;
154 155 // find pdf link 156 parent.find('.sdmt_cart').each(function () { 157 // the id 158 const id = $(this).data('file_id'); 159 const target = $(this).attr('href'); 160 const fileTitle = $(this).attr('title'); 161 162 // get the category 163 const fileCategoryID = fileTitle.replace(/[^a-zA-Z]+/g, ''); 164 165 // get the file type 166 let fileType = (target.includes('.') ? target.substring(target.lastIndexOf('/') + 1) : false); 167 fileType = (fileType.includes('.') ? fileType.substring(fileType.lastIndexOf('.') + 1) : false); 168 169 const fileTypeString = (fileType ? fileType.toUpperCase() : 'file'); 170 171 // catch adding duplicate files 172 if (add_cart_el.find('[data-id="' + id + '"]').length > 0) { 173 // show tooltip notification 174 if (addHappened) { 175 showToolTip(self, e, 'added to cart'); 176 } else { 177 showToolTip(self, e, 'item(s) already in cart', false); 178 } 179 180 return; 181 } 182 183 // the html 184 const html = '<li data-id="' + id + '" class="sdmt_file_cart_include">' + 185 '<a href="#" class="sdmt_remove" title="Remove ' + fileTitle + ' (' + fileTypeString + ') from cart"></a>' + 186 fileTypeString + 187 '</li>'; 188 189 // if we don't have the group create it 190 if (add_cart_el.find('#' + fileCategoryID).length == 0) { 191 add_cart_el.append('<div id="' + fileCategoryID + '" class="dc-grouped-products"><p><strong>' + fileTitle + '</strong></p><ul></ul></div>'); 192 } 193 194 // show tooltip notification 195 showToolTip(self, e, 'added to cart'); 196 197 addHappened = true; 198 199 // append to cart 200 add_cart_el.find('#' + fileCategoryID + ' ul').append(html); 201 }); 202 toggleDownloadButton(); 203 }); 204 205 /** 206 * Show a tooltip where the user clicks 207 * @param {object} self what was clicked on 208 * @param {object} event the event 209 * @param {string} message the message 210 * @param {boolean} good status of tooltip 211 */ 212 function showToolTip(self, event, message, good = true) { 213 const toolTip = $('#sdmt_doc_center_file-tooltip'); 214 const toolTipTop = self.offset().top - window.scrollY + 25; 215 const clickedItemHeight = self.outerHeight(); 216 const caretHeight = 20; 217 const showBottom = (window.innerHeight - event.clientY <= (toolTip.outerHeight() + 20)); 218 219 // determine if above or below 220 let subtractFromTop = (showBottom ? (toolTip.outerHeight() + caretHeight + clickedItemHeight) : 0); 221 toolTip.addClass((showBottom ? 'bottom' : 'top')); 222 toolTip.removeClass((showBottom ? 'top' : 'bottom')); 223 224 // populate tooltip and move it 225 toolTip.find('.message').text(message); 226 toolTip.css({'top': toolTipTop - subtractFromTop, 'left': (event.pageX - (toolTip.outerWidth() / 2))}); 227 228 // add/remove proper classes 229 toolTip 230 .removeClass((good ? 'bad' : 'good')) 231 .addClass('show ' + (good ? 'good' : 'bad')); 232 } 233 234 // hide tooltip on clicking on body 235 $('body').on('click', function() { 236 $('#sdmt_doc_center_file-tooltip').removeClass('show'); 237 }); 238 239 // if scroll, hide tooltip 240 $(window).scroll(function() { 241 $('#sdmt_doc_center_file-tooltip').removeClass('show'); 242 }); 243 244 // prevent tooltip from closing when clicked on 245 $('#sdmt_doc_center_file-tooltip').on('click', function(e) { 246 e.stopPropagation(); 247 }) 248 249 // removing an item from the cart 250 $('.sdmt_file_cart').on('click', '.sdmt_remove', function (e) { 251 e.preventDefault(); 252 253 const holder = $(this).closest('.dc-grouped-products');
254 const holderItems = holder.find('.sdmt_file_cart_include').length - 1; 255 256 $(this).parent().remove(); 257 258 // remove holder if no items 259 if (holderItems <= 0) { 260 holder.remove(); 261 } 262 263 // update cart 264 toggleDownloadButton(); 265 }); 266 267 // clearing the cart 268 $('.sdmt_file_cart_clear').on('click', function(e) { 269 e.preventDefault(); 270 $(this).closest('.sdmt_file_cart').find('.sdmt_file_cart_selected').empty(); 271 toggleDownloadButton(); 272 }); 273 } 274 275 function sdmt_loader(el, hide) { 276 var loader_el = $('#sdmt_loader'); 277 if ( hide == 1 ) { 278 loader_el.hide(); 279 } else { 280 var offset = el.offset(); 281 var width = el.outerWidth(); 282 var height = el.outerHeight(); 283 var left = offset.left + width - 30; 284 var top = offset.top + ( height / 2) - 8; 285 // console.log(left); 286 loader_el.css({ 287 left : left + 'px', 288 top : top + 'px' 289 }); 290 loader_el.show(); 291 } 292 } 293 294 function add_doc_content(data, target) { 295 var html = ''; 296 $.each(data.terms, function (i, v) { 297 298 html += '<div class="' + data.current + '">'; 299 html += '<a href="#" class="sdmt_doc_center_title sdmt_doc_center_open" data-id="' + v.term_id + '" data-get="' + v.get + '" data-current="' + v.current + '"><span class="sdmt_plus"></span>' + v.name + '</a>'; 300 html += '<div class="sdmt_doc_center_categories"></div>'; 301 html += '<div class="sdmt_doc_center_docs doc"></div>'; 302 html += '</div>'; 303 }); 304 305 target.html(html); 306 307 } 308 309 function add_series_content(data, target) { 310 var html = ''; 311 $.each(data.terms, function (i, v) { 312 html += '<div class="sto_category">'; 313 html += '<a href="#" class="sdmt_doc_center_title sdmt_doc_center_open" data-id="' + v.term_id + '" data-get="' + v.get + '" data-current="' + v.current + '"><span class="sdmt_plus"></span>' + v.name + '</a>'; 314 html += '<div class="sdmt_doc_center_categories"></div>'; 315 html += '<div class="sdmt_doc_center_docs series">'; 316 html += '</div>'; 317 html += '</div>'; 318 }); 319 320 target.html(html); 321 } 322 323 function add_series_file_content(data, target_docs) { 324 var html_docs = ''; 325 $.each(data.docs, function (i, v) { 326 html_docs += '<div class="sdmt_doc_center_file">'; 327 html_docs += '<span class="sdmt_doc_center_file_title">'+v.post_title+'</span>'; 328 html_docs += '<div class="sdmt_pull_right">'; 329 html_docs += '<label><input type="checkbox" value="'+v.main_file_id+'" data-project="'+data.project_id+'" class="sdmt_es_detail_toggle" '+v.checked+' /> PDF</label>'; 330 html_docs += '</div><div class="clearfix"></div>'; 331 html_docs += '</div>'; 332 }); 333 334 target_docs.html(html_docs); 335 } 336 337 function add_doc_file_content(data, target_docs) { 338 var html_docs = ''; 339 $.each(data.docs, function (i, v) { 340 html_docs += '<div class="sdmt_doc_center_file">'; 341 html_docs += '<span class="sdmt_doc_center_file_title">'+v.post_title+'</span>'; 342 html_docs += '<div class="sdmt_pull_right">'; 343 if (v.additional_format) { 344 html_docs += '<a title="' + v.additional_title + '" data-file_id="' + v.additional_id + '" href="' + v.additional_format + '" class="sdmt_cart sdmt_file_type ' + v.additional_format_ext + '">' + v.additional_format_ext + '</a>'; 345 } 346 if (v.main_file) { 347 html_docs += '<a target="_blank" title="' + v.main_file_title + '" data-file_id="' + v.main_file_id + '" href="' + v.main_file + '" class="sdmt_cart sdmt_file_type ' + v.main_file_ext + '">' + v.main_file_ext + '</a>'; 348 html_docs += v.main_file_copy; 349 } 350 if ( (v.main_file_ext !== 'video' && v.main_file_ext !== 'doc') && (v.main_file_ext !== 'url') ) { 351 html_docs += data.add_link; 352 } 353 354 html_docs += '</div><div class="clearfix"></div>'; 355 html_docs += '</div>'; 356 }); 357 358 target_docs.html(html_docs); 359 } 360 361 362 function add_product_content(data, target_docs) { 363 var html_docs = ''; 364 $.each(data.products, function (i, v) { 365 html_docs += v; 366 }); 367 368 target_docs.html(html_docs); 369 } 370 371 function toggleDownloadButton() { 372 const downloadHolder = $('.sdmt_file_cart_download');
373 const totalFilesSpan = downloadHolder.find('.sdmt_file_cart_download__total-files span'); 374 375 if ($('.sdmt_file_cart_selected').find('.sdmt_file_cart_include').length > 0) { 376 const dwbtn = $('.sdmt_download_file_cart'); 377 378 let ids = []; 379 let href = dwbtn.data('base_href'); 380 381 // remove empty cart message 382 $('.sdmt_file_cart_selected .sdmt_cart-empty-message').remove(); 383 384 $('.sdmt_file_cart_include').each(function (i) { 385 ids[i] = $(this).data('id'); 386 }); 387 388 // only get unique ids 389 ids = [...new Set(ids)]; 390 391 // set the amount of files 392 totalFilesSpan.text(ids.length); 393 394 // show downloads holder 395 downloadHolder.show(); 396 397 href += ids.join(','); 398 dwbtn.attr('href', href); 399 } else { 400 // hide downloads holder 401 downloadHolder.hide(); 402 403 // reset count 404 totalFilesSpan.text(0); 405 406 // add empty cart message 407 $('.sdmt_file_cart_selected').append(emptyCartMessage); 408 } 409 } 410 411 var search_button = $('.sdmt_search a'); 412 search_button.attr('href', sdmt_js.search_url); 413 // search_button.swipebox(); 414 search_button.swipebox('.sdmt_search a'); 415 416 // $('.sdmt_open_modal').swipebox(); 417 $('.sdmt_open_modal').swipebox('.sdmt_open_modal'); 418 $(document.body).on('click touchend','#swipebox-slider .current', function(e){ 419 if ( $(e.target).hasClass('current') || $(e.target).hasClass('swipebox-video-container') ) { 420 jQuery('#swipebox-close').trigger('click'); 421 } 422 }); 423 424 $('.sdmt_products_select').select2({ 425 placeholder: sdmt_js.select_a_product, 426 escapeMarkup : function(data) { 427 return data; 428 }, 429 allowClear : true, 430 ajax: { 431 url: sdmt_js.ajax_url, 432 dataType: 'json', 433 delay: 250, 434 data: function (params) { 435 console.log(params); 436 return { 437 q: params.term, // search term 438 page: params.page, 439 action: 'sdmt_products_select' 440 }; 441 }, 442 processResults: function (data, params) { 443 params.page = data.page || 1; 444 445 return { 446 results: data.items, 447 pagination: { 448 more: (params.page * 10) < data.total_count 449 } 450 }; 451 }, 452 cache: false 453 } 454 }); 455 456 $('select.sdmt_input').not('.sdmt_products_select').select2(); 457 458 $('form.sdmt_validate').validate({ignore: false}); 459 460 $('#sdmt_search_submit').click(function (e) { 461 e.preventDefault(); 462 var sdmt_search_product = $('#sdmt_search_product').val(); 463 var sdmt_search_product_number = $('#sdmt_search_product_number').val(); 464 window.parent.showSearch(sdmt_search_product, sdmt_search_product_number); 465 }); 466 467 $('.esubmittal_content').on('change', '.sdmt_select_all', function(e) { 468 var th = $(this); 469 470 var checkboxes = th.closest('.sdmt_docs_check').find('.sdmt_doc_checkbox'); 471 checkboxes.prop("checked", th.prop("checked")); 472 checkboxes.last().trigger('change'); 473 }); 474 475 $('.add_selected_docs').on( 'click', function(e) { 476 e.preventDefault(); 477 show_loader(); 478 $(this).hide(); 479 var th = $(this), 480 project_id = th.data('id'), 481 send_data = get_send_data(); 482 save_project_data(project_id, send_data); 483 setTimeout(function() { 484 $('#remove_system').show(); 485 }, 300); 486 }); 487 488 $('#remove_system').on('click', function(e) { 489 e.preventDefault(); 490 $('#system_select_all').prop('checked', false).trigger('change'); 491 $('#remove_system').hide(); 492 $('.add_selected_docs').show(); 493 }); 494 495 $('.esubmittal_content').on( 'change', '.sdmt_doc_checkbox', function (e) { 496 $('.add_selected_docs').trigger('click'); 497 var th = $(this); 498 var parent = th.closest('.sdmt_docs_check'); 499 var id = parent.data('id'); 500 if ( parent.hasClass('sdmt_docs_pull_info') ) { 501 if ( th.is(':checked') ) { 502 add_product_components(id); 503 } else { 504 $('.sdmt_load_product_components').html(''); 505 } 506 } 507 }); 508 509 function get_send_data() { 510 var send_data = {}, 511 remove = {}, 512 c = 0, 513 d = 0; 514 $('.sdmt_docs_check').each( function(i,v) { 515 var type = $(this).data('type'), 516 id = $(this).data('id'), 517 th = $(this),
518 checked = $(this).find('.sdmt_doc_checkbox:checked'); 519 if ( checked.length ) { 520 send_data[c] = {}; 521 send_data[c]['type'] = type; 522 send_data[c]['id'] = id; 523 send_data[c]['docs'] = []; 524 checked.each(function (ii,vv) { 525 send_data[c]['docs'][ii] = $(this).val(); 526 }); 527 c++; 528 if ( th.hasClass('sdmt_docs_check_one') ) { 529 th.parent().find('.sdmt_docs_check_one').not(th).addClass('disabled'); 530 531 } 532 } else { 533 if ( th.hasClass('sdmt_docs_check_one') ) { 534 th.parent().find('.sdmt_docs_check_one').not(th).removeClass('disabled'); 535 } 536 if ( typeof(remove[type]) == 'undefined' ) { remove[type] = {}; } 537 remove[type][id] = id; 538 d++; 539 } 540 }); 541 send_data.remove = remove; 542 return send_data; 543 } 544 545 function add_product_components(id) { 546 show_loader(); 547 var project_id = $('.add_selected_docs').data('id'); 548 jQuery.ajax({ 549 url: sdmt_js.ajax_url, 550 method : "POST", 551 dataType : 'json', 552 data : { 553 action : 'sdmt_get_product_components', 554 product_id : id, 555 project_id : project_id, 556 }, 557 success : function(data) { 558 if ( data ){ 559 var html = '<h2>Air & Moisture Barrier Accessories</h2>'; 560 $.each(data, function (i,v) { 561 html += '<h3>'+v.title+'</h3>'; 562 html += '<div class="sdmt_section_products">'; 563 $.each(v.products, function(x,product) { 564 html += '<h4>'+product.title+'</h4>'; 565 $.each(product.products_rendered, function(ii,vv) { 566 html += vv; 567 }); 568 }); 569 html += '</div>' 570 }); 571 $('.sdmt_load_product_components').html(html); 572 } 573 hide_loader(); 574 } 575 }); 576 } 577 578 function first_run_select_all() { 579 jQuery('.sdmt_docs_check').each( function() { 580 var check = false; 581 var th = jQuery(this); 582 th.find('.sdmt_checkbox_row').not('.sdmt_select_all_label').each( function() { 583 if ( jQuery(this).find('input').is(':checked' ) ) { 584 check = true; 585 } else { 586 check = false; 587 return; 588 } 589 }); 590 if ( check ) { 591 th.find('.sdmt_select_all_label').trigger('click'); 592 var parent = th.closest('.sdmt_docs_check'); 593 if ( parent.hasClass('sdmt_docs_pull_info') ) { 594 add_product_components(parent.data('id')); 595 } 596 } 597 }); 598 } 599 600 function save_project_data(project_id,send_data) { 601 jQuery.ajax({ 602 url : sdmt_js.ajax_url, 603 method : "POST", 604 dataType : 'json', 605 data : { 606 action : 'sdmt_add_docs_to_project', 607 project_id : project_id, 608 send_data : JSON.stringify(send_data) 609 }, 610 success : function(data) { 611 updateCount(data.count); 612 hide_loader(); 613 } 614 }); 615 } 616 617 $('.sdmt_content').on('change', '.sdmt_es_detail_toggle', function(e) { 618 var detail_id = $(this).val(), 619 project_id = $(this).data('project'); 620 jQuery.ajax({ 621 url : sdmt_js.ajax_url, 622 method : "POST", 623 dataType : 'json', 624 data : { 625 action : 'sdmt_add_details_to_project', 626 project_id : project_id, 627 detail_id : detail_id 628 }, 629 success : function(data) { 630 updateCount(data.count); 631 hide_loader(); 632 } 633 }); 634 }); 635 636 function show_loader() { 637 $('.show_loader').show(); 638 $('.es_add_content').addClass('loading'); 639 } 640 function hide_loader() { 641 $('.es_add_content').removeClass('loading'); 642 } 643 644 function updateCount(data) { 645 if ( typeof(data.systems) !== 'undefined' ) { 646 $('#es_systems_count').text(data.systems); 647 } 648 649 if ( typeof(data.products) !== 'undefined' ) { 650 $('#es_products_count').text(data.products); 651 } 652 653 if ( typeof(data.details) !== 'undefined' ) { 654 $('#es_details_count').text(data.details); 655 } 656 } 657 658 $('.sdmt_es_sortable').sortable({ 659 helper: "clone", 660 update: function (event, ui) { 661 var data = $(this).sortable('serialize')+'&action=sdmt_save_project_docs_order'+'&project_id='+$(this).data('project'); 662 $.ajax({
663 url : sdmt_js.ajax_url, 664 method : "POST", 665 data: data, 666 type: 'POST' 667 }); 668 } 669 }); 670 671 $('.sdmt_remove_doc').click( function(e) { 672 e.preventDefault(); 673 var c = confirm('Aer you sure you want to remove this item from the project?'); 674 var row = $(this).closest('.sdmt_es_sortable_item'); 675 if ( c===true) { 676 row.find('input[type="checkbox"]').prop('checked', '').last().trigger('change'); 677 row.fadeOut(function(){ 678 row.remove(); 679 }); 680 } 681 682 }); 683 684 $('#sdmt_generate_cancel').click( function (e) { 685 e.preventDefault(); 686 window.parent.jQuery('#swipebox-close').trigger('click'); 687 }); 688 689 $('#save_project_file').click( function(e) { 690 var href = $(this).attr('href'); 691 var project_id = $(this).data('project_id'); 692 if ( $('#sdmt_contact_me').is(':checked') ) { 693 e.preventDefault(); 694 var data = { 695 action : 'sdmt_update_contact_project', 696 project_id : project_id 697 }; 698 $.post(sdmt_js.ajax_url, data, function () { 699 window.location = href; 700 }); 701 } 702 }); 703 704 $('.sto_delete_project').click( function(e) { 705 e.preventDefault(); 706 var project_id = $(this).data('id'); 707 var c = confirm('Are you sure you want to delete this project?'); 708 if ( c === true ) { 709 var data = { 710 action : 'sdmt_delete_project', 711 project_id : project_id 712 }; 713 $.post(sdmt_js.ajax_url, data, function () { 714 location.reload(); 715 }); 716 } 717 }); 718 719}); 720 721function showSearch(product, product_number) { 722 window.location = sdmt_js.search_results_url + '?product_id=' + product + '&product_number=' + product_number; 723}
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.