https://szs.org.pl/wp-content/plugins/wp-file-download/app/site/assets/js/search_filter.js?ver=6.3.6
1function initSorting() { 2 var $ = jQuery; 3 $('.orderingCol').click(function (e) { 4 e.preventDefault(); 5 var formID = '#' + $(this).closest('form').attr('id'); 6 var ordering = $(this).data('ordering'); 7 var direction = $(this).data('direction'); 8 ajaxSearch(formID, ordering, direction); 9 }); 10 11 12 if (jQuery(".list-results .wpfd-pagination").length) { 13 jQuery(".list-results .wpfd-pagination a.page-numbers:not('.wpfd-form-search-file-category .list-results .wpfd-pagination')").on('click', function (e) { 14 e.preventDefault(); 15 jQuery('[name="wpfd_search_page"]').val(jQuery(this).data('page')); 16 var formID = '#' + jQuery(this).closest('form').attr('id'); 17 ajaxSearch(formID); 18 return false; 19 }); 20 } 21 22 $(".list-results #limit:not('.wpfd-form-search-file-category .list-results #limit')").change(function (e) { 23 e.preventDefault(); 24 var formID = '#' + $(this).closest('form').attr('id'); 25 $(formID).find('[name="limit"]').val($(this).val()); 26 ajaxSearch(formID); 27 return false; 28 }); 29} 30 31function showDefautTags() { 32 var $ = jQuery; 33 if (typeof defaultAllTags !== 'undefined' && defaultAllTags.length > 0) { 34 $('.chk-tags-filtering ul').empty(); 35 defaultAllTags.sort(function (a, b) { 36 if (a > b) { 37 return 1 38 } 39 if (a < b) { 40 return -1 41 } 42 return 0; 43 }); 44 var checklable1 = $('<label class="labletags">' + wpfdvars.msg_filter_by_tags + '</label>'); 45 $('.chk-tags-filtering ul').append(checklable1); 46 $.each(defaultAllTags, function (index, tag) { 47 var key = 'wpfd' + tag.replace(/-/g, ''); 48 var element = $('<li class="tags-item"><span> ' + tagsLabel[key] + ' </span> <input title="" type="checkbox" name="chk_ftags[]" onclick="fillInputTags();" class="ju-input chk_ftags" id="ftags' + index + '" value="' + tag + '"></li>'); 49 $('.chk-tags-filtering ul').append(element); 50 }); 51 $(".input_tags").val(""); 52 selectdChecktags(); 53 } 54} 55 56function catChange(filterCatElem) { 57 var $ = jQuery; 58 var catId = filterCatElem.val(); 59 var catType = filterCatElem.attr('data-cattype'); 60 var catSlug = filterCatElem.attr('data-slug'); 61 if (!catType) { 62 catType = 'default'; 63 } 64 if (!catSlug) { 65 catSlug = ''; 66 } 67 68 // Kill file tag ajax is running 69 var prevFileTagAjax = window.file_tag_ajax_on_search; 70 if (prevFileTagAjax !== null) { 71 prevFileTagAjax.abort(); 72 } 73 74 var boxSearchFilter = $(filterCatElem).parents('.box-search-filter').get(0); 75 if (parseInt(catId) === 0) { 76 if (typeof availTags !== 'undefined' && availTags.length > 0 && availTags[catId].length > 0) { 77 $(boxSearchFilter).find('.chk-tags-filtering ul').empty(); 78 $.each(availTags[catId], function (index, value) { 79 var tagKey = value['id']; 80 var tagLabel = value['label']; 81 var tagVal = value['value']; 82 var element = $('<li class="tags-item"><span> ' + tagLabel + ' </span> <input title="" type="checkbox" name="chk_ftags[]" class="ju-input chk_ftags" id="ftags' + tagKey + '" value="' + tagLabel + '"></li>'); 83 $(boxSearchFilter).find('.chk-tags-filtering ul').append(element); 84 }); 85 $(boxSearchFilter).find(".input_tags").val(""); 86 selectdChecktags(); 87 } 88 showDefautTags(); 89 $(boxSearchFilter).find('.chk_ftags').parent().show(); 90 return; 91 } 92 if ($(boxSearchFilter).find('.chk-tags-filtering ul').length === 0) { 93 return; 94 } 95 96 window.file_tag_ajax_on_search = $.ajax({ 97 type: "GET", 98 url: wpfdajaxurl + "task=search.getTagByCatId", 99 data: { 100 catId: catId, 101 catType: catType, 102 catSlug: catSlug 103 } 104 }).done(function (tags) { 105 if (tags === '0') {
106 $(boxSearchFilter).find('.chk-tags-filtering ul').empty(); 107 var message = $('<li>' + wpfdvars.msg_no_tag_in_this_category_found + '</li>'); 108 $(boxSearchFilter).find('.chk-tags-filtering ul').append(message); 109 $(boxSearchFilter).find(".input_tags").val(""); 110 $('#Category_container').trigger('wpfd_search_engine_without_available_tags'); 111 } else { 112 if (tags.success === true) { 113 $(boxSearchFilter).find('.chk-tags-filtering ul').empty(); 114 $.each(tags.tags, function (index, tag) { 115 var element = $('<li class="tags-item"><input title="" type="checkbox" name="chk_ftags[]" onclick="fillInputTags();" class="ju-input chk_ftags" id="ftags' + index + '" value="' + tag['name'] + '"> <span>' + tag['name'].replace(/-/g, ' ') + '</span></li>'); 116 $(boxSearchFilter).find('.chk-tags-filtering ul').append(element); 117 }); 118 $(boxSearchFilter).find(".input_tags").val(""); 119 selectdChecktags(); 120 $('#Category_container').trigger('wpfd_search_engine_with_available_tags'); 121 } else { 122 $(boxSearchFilter).find('.chk-tags-filtering ul').empty(); 123 var message = $('<li>' + tags.message + '</li>'); 124 $(boxSearchFilter).find('.chk-tags-filtering ul').append(message); 125 $(boxSearchFilter).find(".input_tags").val(""); 126 $('#Category_container').trigger('wpfd_search_engine_without_available_tags'); 127 } 128 } 129 }); 130} 131 132function fillInputTags() { 133 var tagVal = []; 134 jQuery('.chk_ftags').each(function () { 135 if (this.checked && jQuery(this).is(":visible")) { 136 tagVal.push(jQuery(this).val()); 137 } 138 }); 139 if (tagVal.length > 0) { 140 jQuery(".input_tags").val(tagVal.join(",")); 141 } else { 142 jQuery(".input_tags").val(""); 143 } 144} 145 146function getSearchParams(k) { 147 var p = {}; 148 location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (s, k, v) { 149 p[k] = v 150 }); 151 return k ? p[k] : p; 152} 153 154function ajaxSearch(element, ordering, direction, pushState = true) { 155 var $ = jQuery; 156 var sform = element; 157 var filterType = ($(sform).find('select[name=extension]').length && $(sform).find('select[name=extension]').val() !== null) ? true : false; 158 var isTypeFilter = (filterType && $(sform).find('select[name=extension]').val() !== '0') ? true : false; 159 var isFromWeightFilter = ($(sform).find('input[name=from_weight]').length 160 && $(sform).find('input[name=from_weight]').val() !== '' && $(sform).find('input[name=from_weight]').val() !== 'NaN') ? true : false; 161 var isFromWeightUnitFilter = ($(sform).find('select[name=from_weight_unit]').length && $(sform).find('select[name=from_weight_unit]').val() !== 'kb') ? true : false; 162 var isToWeightFilter = ($(sform).find('input[name=to_weight]').length 163 && $(sform).find('input[name=to_weight]').val() !== '' && $(sform).find('input[name=to_weight]').val() !== 'NaN') ? true : false; 164 var isToWeightUnitFilter = ($(sform).find('select[name=to_weight_unit]').length && $(sform).find('select[name=to_weight_unit]').val() !== 'kb') ? true : false; 165 var $key = $(sform).find('input[name=q]').val(); 166 var $placeholder = $(sform).find('input[name=q]').attr('placeholder'); 167 var $paged = $(sform).find('input[name=wpfd_search_page]').length ? $(sform).find('input[name=wpfd_search_page]').val() : 1; 168 var isSearchAll = ($(sform).find('input[name=wpfd_search_all]').length && $(sform).find('input[name=wpfd_search_all]').val() !== null) ? parseInt($(sform).find('input[name=wpfd_search_all]').val()) : 1; 169 170 // Avoid conflict key search 171 if (($key || '') === ($placeholder || '')) { 172 $key = ''; 173 } 174 175 if (parseInt($(sform).find('[name=catid]').val()) == 0 && isSearchAll == 0) { 176 return false; 177 } 178 // Get the form data 179 var formData = { 180 'q': $key, 181 'catid': $(sform).find('[name=catid]').val(), 182 'exclude': $(sform).find('[name=exclude]').val(), 183 'theme': $(sform).find('[name=theme]').val(), 184 'ftags': $(sform).find('input[name=ftags]').val(), 185 'cfrom': $(sform).find('input[name=cfrom]').val(), 186 'cto': $(sform).find('input[name=cto]').val(), 187 'ufrom': $(sform).find('input[name=ufrom]').val(), 188 'uto': $(sform).find('input[name=uto]').val(), 189 'show_pagination': $(sform).find('input[name=show_pagination]').val(), 190 'paged': $paged, 191 'limit': $(sform).find('[name=limit]').val(), 192 'theme_column': $(sform).find('input[name=theme_column]').val(), 193 'wpfd_search_nonce': $(sform).find('input[name=wpfd_search_nonce]').val() 194 }; 195 196 if (isTypeFilter) { 197 const extensionValue = $(sform).find('select[name=extension]').val(); 198 199 if (Array.isArray(extensionValue)) { 200 formData.type = extensionValue.join(','); 201 } else if (extensionValue && extensionValue !== '0') { 202 formData.type = extensionValue; 203 } 204 } 205 206 if (isFromWeightFilter) { 207 formData.wfrom = $(sform).find('input[name=from_weight]').val(); 208 } 209 210 if (isFromWeightUnitFilter) { 211 formData.wfromunit = $(sform).find('select[name=from_weight_unit]').val(); 212 } 213 214 if (isToWeightFilter) { 215 formData.wto = $(sform).find('input[name=to_weight]').val(); 216 } 217 218 if (isToWeightUnitFilter) { 219 formData.wtounit = $(sform).find('select[name=to_weight_unit]').val(); 220 } 221 222 formData = cleanObj(formData); 223 224 if (jQuery.isEmptyObject(formData) || 225 (typeof (formData.q) === 'undefined' && 226 typeof (formData.ftags) === 'undefined' && 227 typeof (formData.cfrom) === 'undefined' && 228 typeof (formData.cto) === 'undefined' && 229 typeof (formData.ufrom) === 'undefined' && 230 typeof (formData.uto) === 'undefined' && 231 typeof (formData.type) === 'undefined' && 232 typeof (formData.wfrom) === 'undefined' && 233 typeof (formData.wto) === 'undefined' && 234 (typeof (formData.catid) === 'undefined' 235 || (typeof (formData.catid) !== 'undefined' && parseInt(formData.catid) === 0 && typeof (wpfdvars.verify_key_search) !== 'undefined' && parseInt(wpfdvars.verify_key_search) === 1)))) { 236 $(element).find(".txtfilename").focus(); 237 return false;
238 } 239 240 if (typeof (wpfdvars.check_empty_key_search) !== 'undefined' && parseInt(wpfdvars.check_empty_key_search) === 1 && $key === '') { 241 $(element).find('.txtfilename').focus(); 242 return false; 243 } 244 245 if (isFromWeightFilter && formData.wfrom !== '') { 246 if (parseInt(formData.wfrom) < 0) { 247 alert('Weight from is positive integer.'); 248 return false; 249 } 250 251 switch (formData.wfromunit) { 252 case 'mb': 253 formData.wfrom = parseFloat(formData.wfrom) * 1024 * 1024; 254 break; 255 case 'gb': 256 formData.wfrom = parseFloat(formData.wfrom) * 1024 * 1024 * 1024; 257 break; 258 default: 259 formData.wfrom = parseFloat(formData.wfrom) * 1024; 260 break; 261 } 262 } 263 264 if (isToWeightFilter && formData.wto !== '') { 265 if (parseInt(formData.wto) < 0) { 266 alert('Weight to is positive integer.'); 267 return false; 268 } 269 270 switch (formData.wtounit) { 271 case 'mb': 272 formData.wto = parseFloat(formData.wto) * 1024 * 1024; 273 break; 274 case 'gb': 275 formData.wto = parseFloat(formData.wto) * 1024 * 1024 * 1024; 276 break; 277 default: 278 formData.wto = parseFloat(formData.wto) * 1024; 279 break; 280 } 281 } 282 283 if (isFromWeightFilter && formData.wfrom !== '' && isToWeightFilter && formData.wto !== '' 284 && parseFloat(formData.wfrom) > parseFloat(formData.wto)) { 285 alert('Weight from must be less than weight to.'); 286 return false; 287 } 288 289 // Not search in category filters 290 if ($(sform).parent('.wpfd-content').length) { 291 return false; 292 } 293 294 if ((typeof ordering !== 'undefined') && ordering) formData.ordering = ordering; 295 if ((typeof direction !== 'undefined') && direction) formData.dir = direction; 296 297 // Pagination 298 if (pushState) { 299 var filter_url = jQuery.param(formData); 300 var currentUrl = window.location.search; 301 var pushUrl; 302 if (typeof URLSearchParams !== 'undefined') { 303 var currentFilters = new URLSearchParams(currentUrl.substring(1)); 304 Object.keys(formData).forEach(function (key) { 305 if (currentFilters.has(key)) { 306 currentFilters.delete(key); 307 } 308 if (key === 'theme_column') { 309 delete formData.theme_column; 310 // currentFilters.delete(key); 311 } 312 }); 313 filter_url = jQuery.param(formData); 314 if (currentUrl.substring(1) === '?' && currentFilters.toString() !== '') { 315 pushUrl = currentFilters.toString() + '&' + filter_url; 316 317 } else { 318 pushUrl = '?' + filter_url; 319 } 320 321 window.history.pushState(formData, "", pushUrl); 322 } 323 } 324 325 var theme_column = $(sform).find('input[name=theme_column]').val(); 326 if (typeof (theme_column) !== 'undefined') { 327 formData.theme_column = theme_column 328 } 329 330 var wpfdSearchUrl = wpfdajaxurl + "task=search.display"; 331 if (typeof wpfdvars.locale !== "undefined" && wpfdvars.locale) { 332 wpfdSearchUrl += "&lang=" + wpfdvars.locale; 333 } 334 window.ajax_search_handler = $.ajax({ 335 method: "POST", 336 url: wpfdSearchUrl, 337 data: formData, 338 beforeSend: function () { 339 $(element).find(".wpfd-results").html(''); 340 $(element).find(".wpfd-results").prepend($(element).find("#loader").clone().show()); 341 $(element).find(".wpfd_search_file_suggestion").html(''); 342 $(element).find(".wpfd_search_file_suggestion").fadeOut(300); 343 $(element).find('.wpfd-icon-search').show(); 344 $(element).find('.wpfd-icon-search-loading').hide(); 345 }, 346 success: function (result) { 347 $(element).find(".wpfd_search_file_suggestion").html(''); 348 $(element).find(".wpfd_search_file_suggestion").fadeOut(300); 349 350 if (parseInt(wpfdvars.downloadSelected) === 1) { 351 var dls_contents = '<div class="wpfd-search-result-download-files-section">'; 352 dls_contents += '<a type="button" id="search_download_selected_btn" class="search-download-selected" style="display: none">'; 353 dls_contents += wpfdvars.translates.download_selected + ' <i class="zmdi zmdi-check-all wpfd-download-category"></i></a>'; 354 dls_contents += '<input type="hidden" id="search_result_download_selected_list" class="search_result_download_selected_list" />'; 355 dls_contents += '<input type="hidden" id="search_result_download_selected_file_with_category_list" class="search_result_download_selected_file_with_category_list" /></div>'; 356 result = dls_contents + result; 357 } 358 359 $(element).find(".wpfd-results").html(result); 360 if ($(element).find('.wpfd_search_page').length) { 361 $(element).find('.wpfd_search_page').val(1); 362 } 363 initSorting(); 364 if (typeof wpfdColorboxInit !== 'undefined') { 365 wpfdColorboxInit(); 366 } 367 preSearchDownloadSelectedFiles(); 368 searchDownloadSelectedFiles(); 369 370 if ($(element).find('.wpfd-results .cbox_file_download').length) { 371 $(element).find('.wpfd-results .cbox_file_download').addClass('search-download-checkbox'); 372 } 373 374 window.ajax_search_handler = null; 375 376 $(element).find('.wpfd-icon-search').show(); 377 $(element).find('.wpfd-icon-search-loading').hide(); 378 379 // Safe actions 380 if (typeof formData.theme !== "undefined" && formData.theme === 'ggd') { 381 wpfdSearchGGDThemeActions(); 382 } 383 384 if (typeof formData.theme !== "undefined" && formData.theme === 'preview') { 385 wpfdSearchPreviewThemeActions(); 386 } 387 388 wpfdWooCommerceAddToCart(); 389 390 wpfdViewMoreFileDescription(); 391 } 392 }); 393} 394 395var activeSearchForm = null; 396 397function makeFileSuggestion(element, ordering, direction, pushState = true) { 398 var $ = jQuery; 399 var sform = element; 400 var $placeholder = '<div class="wpfd_file_suggestion_placeholder"></div>'; 401 var $keySearch = $(sform).find('input[name=q]').val(); 402 403 // Check key search valid for making file suggestion 404 if ($keySearch.length < 3) { 405 return; 406 } 407 408 // Get the form data 409 var formData = { 410 'q': $keySearch, 411 'catid': $(sform).find('[name=catid]').val(), 412 'exclude': $(sform).find('[name=exclude]').val(), 413 'make_file_suggestion': '1', 414 'wpfd_search_nonce': $(sform).find('input[name=wpfd_search_nonce]').val() 415 }; 416 417 formData = cleanObj(formData); 418 419 if ((typeof ordering !== 'undefined') && ordering) { 420 formData.ordering = ordering; 421 } 422 423 if ((typeof direction !== 'undefined') && direction) { 424 formData.dir = direction; 425 } 426
427 // Do not make file suggestion when searching 428 if (window.ajax_search_handler !== null) { 429 return; 430 } 431 432 // Kill file suggestion ajax is running 433 var prevFileSuggestionAjax = window.file_suggestion_ajax_on_search; 434 435 if (prevFileSuggestionAjax !== null && activeSearchForm === sform) { 436 prevFileSuggestionAjax.abort(); 437 } 438 activeSearchForm = sform; 439 var wpfdSearchUrl = wpfdajaxurl + "task=search.display"; 440 if (typeof wpfdvars.locale !== "undefined" && wpfdvars.locale) { 441 wpfdSearchUrl += "&lang=" + wpfdvars.locale; 442 } 443 window.file_suggestion_ajax_on_search = $.ajax({ 444 method: "POST", 445 url: wpfdSearchUrl, 446 data: formData, 447 beforeSend: function () { 448 var $placeholder = '<div class="ph-item"><div class="ph-col-12"><div class="ph-picture"></div><div class="ph-row"><div class="ph-col-6 big"></div><div class="ph-col-4 empty big"></div><div class="ph-col-2 big"></div><div class="ph-col-4"></div><div class="ph-col-8 empty"></div><div class="ph-col-6"></div><div class="ph-col-6 empty"></div><div class="ph-col-12"></div></div></div></div>'; 449 $(element).find(".wpfd_search_file_suggestion").html(''); 450 $(element).find(".wpfd_search_file_suggestion").append($(element).findplaceholder).fadeIn('slow'); 451 $(element).find(".wpfd_search_file_suggestion").addClass('placeholder'); 452 $(element).find('.wpfd-icon-search').hide(); 453 $(element).find('.wpfd-icon-search-loading').show(); 454 $(element).find('.txtfilename').addClass('is-file-suggestion'); 455 }, 456 success: function (result) { 457 $(element).find(".wpfd_search_file_suggestion").html(result); 458 $(element).find(".wpfd_search_file_suggestion").removeClass('placeholder'); 459 $(element).find('.wpfd-icon-search').show(); 460 $(element).find('.wpfd-icon-search-loading').hide(); 461 462 if ($(element).find(".wpfd_search_file_suggestion .table").length) { 463 $(element).find(".wpfd_search_file_suggestion .table thead").remove(); 464 $(element).find(".wpfd_search_file_suggestion .table .file_desc").remove(); 465 $(element).find(".wpfd_search_file_suggestion .table .file_category").remove(); 466 $(element).find(".wpfd_search_file_suggestion .table .wpfd_checkbox").remove(); 467 $(element).find(".wpfd_search_file_suggestion .table .file_version").remove(); 468 $(element).find(".wpfd_search_file_suggestion .table .file_size").remove(); 469 $(element).find(".wpfd_search_file_suggestion .table .file_hits").remove(); 470 $(element).find(".wpfd_search_file_suggestion .table .file_created").remove(); 471 $(element).find(".wpfd_search_file_suggestion .wpfd-num").remove(); 472 $(element).find(".wpfd_search_file_suggestion .table .wpfd-file-link").attr('href', ''); 473 $(element).find(".wpfd_search_file_suggestion").fadeIn('slow').slideDown('slow'); 474 475 $(element).find(".wpfd_search_file_suggestion .table td.file_title").on('click', function (e) { 476 e.preventDefault(); 477 var selected_file_name = $(this).find('.wpfd-file-link').attr('title'); 478 if (selected_file_name && selected_file_name !== '') { 479 $(element).find('.txtfilename').val(selected_file_name); 480 ajaxSearch(element); 481 $(element).find('.wpfd_search_file_suggestion').fadeOut(300); 482 $(element).find('.txtfilename').removeClass('is-file-suggestion'); 483 484 return false; 485 } 486 }); 487 488 $(element).find(".wpfd_search_file_suggestion .protected-title").on('click', function (e) { 489 e.preventDefault(); 490 var selected_file_name = $(this).attr('title'); 491 if (selected_file_name && selected_file_name !== '') { 492 $(element).find('.txtfilename').val(selected_file_name); 493 ajaxSearch(element); 494 $(element).find('.wpfd_search_file_suggestion').fadeOut(300); 495 $(element).find('.txtfilename').removeClass('is-file-suggestion'); 496 497 return false;
498 } 499 }); 500 } else { 501 // Return default search 502 $(element).find('.txtfilename').removeClass('is-file-suggestion'); 503 $(element).find(".wpfd_search_file_suggestion").fadeOut(300); 504 } 505 506 if (typeof wpfdColorboxInit !== 'undefined') { 507 wpfdColorboxInit(); 508 } 509 510 // Close suggestion list on click outside 511 $(document).click(function (e) { 512 var $target = $(e.target); 513 if ((!$target.closest('.wpfd_search_file_suggestion').length && $('.wpfd_search_file_suggestion').is(":visible")) 514 && (!$target.closest('.txtfilename').length && !$target.closest('.categories-filtering-selection').length && $('.wpfd_search_file_suggestion').is(":visible"))) { 515 $('.wpfd_search_file_suggestion').hide(); 516 $('.txtfilename').removeClass('is-file-suggestion'); 517 } 518 }); 519 } 520 }); 521} 522 523function openSearchfilter(evt, searchName) { 524 evt.preventDefault(); 525 526 var $ = jQuery; 527 var $this = $(evt.target); 528 529 $this.parent().find('.tablinks').removeClass('active'); 530 $this.addClass('active'); 531 532 $this.parent().parent().find('.wpfd_tabcontainer .wpfd_tabcontent').removeClass('active'); 533 $this.parent().parent().find('.wpfd_tabcontainer #' + searchName).addClass('active'); 534 535 return false; 536} 537 538function clearFilterTypes() { 539 var $ = jQuery; 540 541 if ($('#wpfd-search-file-type').length <= 0) { 542 return; 543 } 544 545 var $extension = $('#wpfd-search-file-type').val(); 546 var $echo = $('#wpfd-search-file-type + .chzn-container .chzn-single > span'); 547 if ($extension === '0') { 548 $echo.addClass('normal'); 549 } else { 550 $echo.removeClass('normal'); 551 } 552} 553 554function selectdChecktags() { 555 var $ = jQuery; 556 var captured = /ftags=([^&]+)/.exec(window.location.search); 557 var tags = typeof captured !== "null" ? decodeURIComponent(captured).split(',') : false; 558 559 $('li.tags-item').off("click"); 560 $('li.tags-item').on('click', function () { 561 $(this).toggleClass("active"); 562 if ($(this).hasClass("active")) { 563 $(this).children("input[type='checkbox']").prop('checked', true); 564 } else { 565 $(this).children("input[type='checkbox']").prop('checked', false); 566 } 567 var tagVal = []; 568 $(this).parent('ul').find(".chk_ftags").each(function () { 569 if ($(this).prop("checked") == true) { 570 tagVal.push($(this).val()); 571 } 572 }); 573 if (tagVal.length > 0) { 574 $(this).parents('.wpfd-tags').find(".input_tags").val(tagVal.join(",")); 575 } else { 576 $(this).parents('.wpfd-tags').find(".input_tags").val(""); 577 } 578 }); 579 580 // Check load/reload url has tag(s) selected 581 $('li.tags-item').each(function () { 582 var currentname = $(this).find('input').val(); 583 if (tags.indexOf(currentname) > -1) { 584 $(this).click(); 585 } 586 }); 587} 588 589function wpfdshowCateReload() { 590 var $, SelectedCateReloadCase, wpfddisplayCateReloadCase; 591 $ = jQuery; 592 SelectedCateReloadCase = $(".categories-filtering .cate-item.choosed label").text(); 593 wpfddisplayCateReloadCase = $(".categories-filtering .cate-lab"); 594 var selectedCatecontentReloadCase = "<label>" + SelectedCateReloadCase + "</label>"; 595 if ($(".cate-item.choosed").length > 0) { 596 wpfddisplayCateReloadCase.addClass('display-cate'); 597 wpfddisplayCateReloadCase.empty(); 598 wpfddisplayCateReloadCase.append(selectedCatecontentReloadCase); 599 if (wpfddisplayCateReloadCase.text() !== null) { 600 wpfddisplayCateReloadCase.append('<a class="cancel"></a>'); 601 } 602 } 603 // wpfdcancelSelectedCate(); 604} 605 606function showCategory() { 607 var $ = jQuery; 608 $(".categories-filtering .categories-filtering-overlay").unbind('click').on('click', function (e) { 609 e.preventDefault(); 610 var $this = $(this); 611 $('.wpfd_search_input').css('z-index', '1'); 612 if ($this.closest('.box-search-filter').height() < 600 && $this.closest('.box-search-filter').height() > 200) { 613 var listCateHeight = parseInt($this.closest('.box-search-filter').height()) - 40; 614 $this.closest('.box-search-filter').find('.wpfd-listCate').css('max-height', listCateHeight + 'px'); 615 } else { 616 $this.closest('.box-search-filter').find('.wpfd-listCate').css('max-height', '600px'); 617 } 618 if (!$this.closest('.box-search-filter').find('.wpfd-listCate-opened').length) { 619 var width_listCate = parseInt($this.closest('.box-search-filter').find('.wpfd-listCate').width()) + 26; 620 $this.closest('.box-search-filter').find('.wpfd-listCate').css('width', width_listCate + 'px').addClass('wpfd-listCate-opened'); 621 } 622 $this.closest('.wpfd_search_input').css('z-index', '12'); 623 var $container = $this.parent(); 624 $('.wpfd-listCate', $container).toggle(); 625 626 selectCategoriesActions($container); 627 }); 628} 629 630function selectCategoriesActions($container) { 631 var $ = jQuery; 632 if (typeof $container === 'undefined') {
633 $container = $('.categories-filtering'); 634 } 635 $('li.cate-item', $container).unbind('click').on('click', function () { 636 $('li.cate-item.checked', $container).removeClass("checked"); 637 $('li.cate-item', $container).removeClass("choosed"); 638 639 $(this).addClass("checked"); 640 if ($(".filter_catid", $container).val().toString() !== $(this).data('catid').toString()) { 641 $(".filter_catid", $container).val($(this).data('catid')); 642 $(".filter_catid", $container).attr('data-cattype', $(this).data('cattype')); 643 $(".filter_catid", $container).attr('data-slug', $(this).data('slug')).trigger("change"); 644 } 645 $('.wpfd-listCate', $container).hide(); 646 647 // Show selected category 648 var wpfdSelectedCatename = $(".cate-item.checked label", $container).text(); 649 var wpfddisplayCate = $('.cate-lab', $container); 650 if ($('.showitems', $container).length > 0) { 651 $('.show-selected-cate', $container).css("display", ""); 652 } else { 653 var selectedCatecontent = "<label title='" + wpfdSelectedCatename + "' class='ju-setting-label'>" + wpfdSelectedCatename + "</label>"; 654 $('.show-selected-cate', $container).css("display", "block"); 655 if ($('.cate-item.checked', $container).length === 1) { 656 wpfddisplayCate.addClass('display-cate'); 657 wpfddisplayCate.empty(); 658 wpfddisplayCate.append(selectedCatecontent); 659 if (wpfddisplayCate.text() !== null) { 660 wpfddisplayCate.append('<a class="cancel"></a>'); 661 } 662 } 663 } 664 665 $('#btnsearchbelow').trigger('wpfd_search_new_selected_category'); 666 }); 667 668 $(document).mouseup(function (e) { 669 if (!$(".categories-filtering > .ui-widget").is(e.target) // If the target of the click isn't the container... 670 && !$(".categories-filtering .categories-filtering-overlay").is(e.target) 671 && $(".categories-filtering > .ui-widget").has(e.target).length === 0) // ... nor a descendant of the container 672 { 673 $(".categories-filtering > .ui-widget").hide(); 674 } 675 }); 676} 677 678function wpfdAddPlaceholder() { 679 var $ = jQuery; 680 if ($(".tags-filtering .tagit-new input").length) { 681 $(".tags-filtering .tagit-new input").attr("placeholder", wpfdvars.msg_search_box_placeholder); 682 } else { 683 setTimeout(function () { 684 jQuery(".tagit.input_tags").tagit({allowSpaces: true}); 685 if ($(".tags-filtering .tagit-new input").length) { 686 $(".tags-filtering .tagit-new input").attr("placeholder", wpfdvars.msg_search_box_placeholder); 687 } 688 }, 3000); 689 } 690 691 if ($('.fusion-builder-live').length || $('.et_divi_theme.et-fb').length) { 692 setInterval(function () { 693 if ($(".wpfd-adminForm").length) { 694 if ($(".input_tags").length) { 695 if ($(".tags-filtering .tagit-new input").length) { 696 $(".tags-filtering .tagit-new input").attr("placeholder", wpfdvars.msg_search_box_placeholder); 697 } else { 698 if ($('.fusion-builder-live').length) { 699 $('.wpfd-tags .tags-filtering .input_tags').remove(); 700 var inputField = $('<input>').attr({ 701 'type': 'text', 702 'name': 'ftags' 703 }).addClass('tagit input_tags'); 704 $('.wpfd-tags .tags-filtering').append(inputField); 705 inputField.tagit({allowSpaces: true}); 706 } else { 707 setTimeout(function () { 708 jQuery(".tagit.input_tags").tagit({allowSpaces: true}); 709 if ($(".tags-filtering .tagit-new input").length) { 710 $(".tags-filtering .tagit-new input").attr("placeholder", wpfdvars.msg_search_box_placeholder); 711 } 712 }, 3000); 713 } 714 715 } 716 } 717 } 718 }, 1000); 719 } 720} 721 722// Add class to search button 723function addtoSearchbuttonbelow() { 724 var $ = jQuery; 725 var searchbox = $("#Tags").children();
726 if (searchbox.hasClass("tags-filtering")) { 727 $(".box-btngroup-below").addClass("searchboxClass"); 728 } 729} 730 731function parentFolderIcon() { 732 var $ = jQuery; 733 $("li.cate-item").each(function () { 734 var count = $(this).find('span.child-cate').length; 735 var prelevel = $(this).prev().attr("data-catlevel"); 736 var catelevel = $(this).attr("data-catlevel"); 737 if ((count == 1 && catelevel > prelevel) || (count == 1 && prelevel == 9)) { 738 $(this).prev().addClass("parent-cate"); 739 } 740 }); 741} 742 743function noTagscase() { 744 var $ = jQuery; 745 if ($("#Tags .no-tags").length > 0) { 746 $("#Tags .no-tags").each(function () { 747 $(this).parents('.box-search-filter').find('.box-btngroup-below').addClass("notags-case"); 748 }); 749 } else { 750 $(".feature .box-btngroup-below").removeClass("notags-case"); 751 } 752} 753 754function wpfdSingleDateTimePicker(input, sform) { 755 var $ = jQuery; 756 var timer = $(input); 757 var dateType = $(input).attr('name'); 758 if (!timer.length) { 759 return; 760 } 761 762 var $options = { 763 locale: wpfdLocaleSettings, 764 "alwaysShowCalendars": true, 765 autoApply: true, 766 autoUpdateInput: false, 767 singleDatePicker: true 768 }; 769 770 if (timer.val() !== '') { 771 $options.startDate = timer.val(); 772 } 773 774 var is_filter_create_date_from = $(sform).find('.cfrom').length ? true : false; 775 var is_filter_create_date_to = $(sform).find('.cto').length ? true : false; 776 var is_filter_update_date_from = $(sform).find('.ufrom').length ? true : false; 777 var is_filter_update_date_to = $(sform).find('.uto').length ? true : false; 778 779 timer.daterangepicker($options, function (start, end, label) { 780 // Let update the fields manually this event fires on selection of range 781 var time = start.format(wpfdvars.dateFormat); 782 var char = time.charAt(2);// Return '/' or '-' 783 var timeNumber = Date.parse(time.split(char).reverse().join(char)); 784 785 switch (dateType) { 786 case 'cfrom': 787 var cToDate = $(sform).find('.cto').val(); 788 var ctoTimeNumber = Date.parse(cToDate.split(char).reverse().join(char)); 789 var timeValid = timeNumber < ctoTimeNumber ? true : false; 790 if (is_filter_create_date_to && cToDate.toString() !== '' && cToDate.toString() !== time.toString() && !timeValid) { 791 wpfdFilterMessages(sform); 792 793 return; 794 } 795 break; 796 case 'cto': 797 var cFromDate = $(sform).find('.cfrom').val(); 798 var cfromTimeNumber = Date.parse(cFromDate.split(char).reverse().join(char)); 799 var timeValid = timeNumber > cfromTimeNumber ? true : false; 800 if (is_filter_create_date_from && cFromDate.toString() !== '' && cFromDate.toString() !== time.toString() && !timeValid) { 801 wpfdFilterMessages(sform); 802 803 return; 804 } 805 break; 806 case 'ufrom': 807 var uToDate = $(sform).find('.uto').val(); 808 var utoTimeNumber = Date.parse(uToDate.split(char).reverse().join(char)); 809 var timeValid = timeNumber < utoTimeNumber ? true : false; 810 if (is_filter_update_date_to && uToDate.toString() !== '' && uToDate.toString() !== time.toString() && !timeValid) { 811 wpfdFilterMessages(sform); 812 813 return; 814 } 815 break; 816 case 'uto': 817 var uFromDate = $(sform).find('.ufrom').val(); 818 var ufromTimeNumber = Date.parse(uFromDate.split(char).reverse().join(char)); 819 var timeValid = timeNumber > ufromTimeNumber ? true : false; 820 if (is_filter_update_date_from && uFromDate.toString() !== '' && uFromDate.toString() !== time.toString() && !timeValid) { 821 wpfdFilterMessages(sform); 822 823 return; 824 } 825 break; 826 default: 827 break; 828 } 829 830 timer.val(time); 831 832 // Setting the selection of dates on calender on check field 833 var checkInPicker = timer.data('daterangepicker'); 834 checkInPicker.setStartDate(time); 835 }); 836 timer.next().on('click', function (e) { 837 $(this).prev().trigger('click') 838 }); 839} 840 841function wpfdFilterMessages(sform) { 842 var $ = jQuery; 843 844 if (!$(sform).find('.wpfd-search-date-filter-message-container').length) { 845 return; 846 } 847 848 $(sform).find('.wpfd-search-date-filter-message-container').empty(); 849 $(sform).find('.wpfd-search-date-filter-message-container').append(wpfdvars.msg_to_date_greater_than_from_date).removeClass('hidden'); 850 851 setTimeout(function () { 852 $(sform).find('.wpfd-search-date-filter-message-container').addClass('hidden'); 853 }, 3000); 854} 855 856function fullWidthSearch() { 857 var $ = jQuery; 858 var $inputSearchContainer = $('.wpfd_search_input'); 859 860 if ($inputSearchContainer.parent().prev().hasClass('categories-filter
860ing')) { 861 $inputSearchContainer.addClass("fullwidth"); 862 } else { 863 $inputSearchContainer.removeClass("fullwidth"); 864 } 865} 866 867function preSearchDownloadSelectedFiles() { 868 var $ = jQuery; 869 if ($('#wpfd-results input.cbox_file_download').length) { 870 $('#wpfd-results input.cbox_file_download').each(function () { 871 var fileId = $(this).data('id'); 872 if (!$.isNumeric(fileId)) { 873 $(this).parent().hide(); 874 } 875 }); 876 } 877 878 $('#wpfd-results input.cbox_file_download').on('change', function () { 879 var filesId = []; 880 var filesWithCategoryId = {}; 881 var selectedFiles = $("#wpfd-results input.cbox_file_download:checked"); 882 var selectedCategory = $('#cate-list .cate-item.checked').data('catid'); 883 if (selectedFiles.length) { 884 selectedFiles.each(function (index, file) { 885 filesId.push($(file).data('id')); 886 if (typeof (selectedCategory) === 'undefined' || selectedCategory === '') { 887 filesWithCategoryId[$(file).data('id')] = $(file).data('catid'); 888 } 889 }); 890 } 891 892 if (filesId.length > 0) { 893 $('.search-download-selected').show(); 894 $('#search_result_download_selected_list').val(''); 895 $('#search_result_download_selected_list').val(filesId.join(',')); 896 897 if (!$.isEmptyObject(filesWithCategoryId)) { 898 var values = JSON.stringify(filesWithCategoryId); 899 $('#search_result_download_selected_file_with_category_list').val(values); 900 } 901 } else { 902 $('.search-download-selected').hide(); 903 } 904 }); 905} 906 907function searchDownloadSelectedFiles() { 908 var $ = jQuery; 909 $('#search_download_selected_btn').on('click', function () { 910 var current_category = $('.cate-list .cate-item.checked').data('catid'); 911 current_category = typeof (current_category) === 'undefined' ? $(this).closest('.box-search-filter').find('#filter_catid').val() : current_category; 912 var category_name = 'wp-file-download-search'; 913 var selectedFilesId = $('#search_result_download_selected_list').val(); 914 915 if (typeof (current_category) !== 'undefined' && current_category !== '') { 916 $.ajax({ 917 url: wpfdajaxurl + "task=files.zipSeletedFiles&filesId=" + selectedFilesId + "&wpfd_category_id=" + current_category, 918 dataType: "json", 919 }).done(function (results) { 920 if (results.success) { 921 var hash = results.data.hash; 922 window.location.href = wpfdajaxurl + "task=files.downloadZipedFile&hash=" + hash + "&wpfd_category_id=" + current_category + "&wpfd_category_name=" + category_name; 923 } else { 924 alert(results.data.message); 925 } 926 }) 927 } else { 928 var selectedFileWithCategoryIds = $('#search_result_download_selected_file_with_category_list').val(); 929 if (selectedFilesId !== '' && selectedFileWithCategoryIds !== '') { 930 selectedFileWithCategoryIds = $.parseJSON(selectedFileWithCategoryIds); 931 $.ajax({ 932 url: wpfdajaxurl + "task=files.zipSeletedFilesMultipleCategories", 933 type: "POST", 934 data: { 935 filesId: selectedFilesId, 936 selectedFileWithCategoryIds: selectedFileWithCategoryIds 937 }, 938 success: function (results) { 939 if (results.success) { 940 var hash = results.data.hash; 941 window.location.href = wpfdajaxurl + "task=files.downloadZipedFileMultipleCategories&hash=" + hash + "&wpfd_search_name=" + category_name; 942 } else { 943 alert(results.data.message); 944 } 945 } 946 }); 947 } else { 948 return; 949 } 950 } 951 }); 952} 953 954function wpfdSearchGGDThemeActions() { 955 var $ = jQuery; 956 var sourcefile = $("#wpfd-template-ggd-box").html(); 957 $('.wpfd-content .wpfd-file-link').unbind('click').click(function (e) { 958 e.preventDefault(); 959 var fileid = $(this).data('id'); 960 var categoryid = $(this).data('category_id'); 961 var ggd_root_cat = $(this).data('category_id'); 962 $.ajax({ 963 url: wpfdajaxurl + "task=file.display&view=file&id=" + fileid + "&categoryid=" + categoryid + "&rootcat=" + ggd_root_cat, 964 dataType: "json", 965 beforeSend: function () { 966 // setting a timeout 967 if ($('body').has('wpfd-ggd-box-loader') !== true) { 968 $('body').append('<div class="wpfd-ggd-box-loader"></div>'); 969 } 970 } 971 }).done(function (file) { 972 var template = Handlebars.compile(sourcefile); 973 var html = template(file); 974 var box = $("#wpfd-ggd-box"); 975 $('.wpfd-ggd-box-loader').each(function () { 976 $(this).remove(); 977 }); 978 if (box.length === 0) { 979 $('body').append('<div id="wpfd-ggd-box" style="display: none;"></div>'); 980 box = $("#wpfd-ggd-box"); 981 } 982 box.empty(); 983 box.prepend(html); 984 box.click(function (e) { 985 if ($(e.target).is('#wpfd-ggd-box')) { 986 box.hide(); 987 } 988 $('#wpfd-ggd-box').unbind('click.box').bind('click.box', function (e) { 989 if ($(e.target).is('#wpfd-ggd-box')) { 990 box.hide(); 991 } 992 }); 993 }); 994 $('#wpfd-ggd-box .wpfd-close').click(function (e) { 995 e.preventDefault(); 996 box.hide(); 997 }); 998 999 box.show(); 1000 1001 var dropblock = box.find('.dropblock'); 1002 if ($(window).width() < 400) { 1003 dropblock.css('margin-top', '0'); 1004 dropblock.css('margin-left', '0'); 1005 dropblock.css('top', '0'); 1006 dropblock.css('left', '0'); 1007 dropblock.height($(window).height() - parseInt(dropblock.css('padding-top'), 10) - parseInt(dropblock.css('padding-bottom'), 10)); 1008 dropblock.width($(window).width() - parseInt(dropblock.css('padding-left'), 10) - parseInt(dropblock.css('padding-right'), 10)); 1009 } else { 1010 dropblock.css('margin-top', (-(dropblock.height() / 2) - 20) + 'px'); 1011 dropblock.css('margin-left', (-(dropblock.width() / 2) - 20) + 'px'); 1012 dropblock.css('height', ''); 1013 dropblock.css('width', ''); 1014 dropblock.css('top', ''); 1015 dropblock.css('left', ''); 1016 } 1017 1018 if (typeof wpfdColorboxInit !== 'undefined') { 1019 wpfdColorboxInit(); 1020 } 1021 // wpfdTrackDownload(); 1022 1023 $('body.elementor-default #wpfd-ggd-box a.wpfd_downloadlink').on('click', function (e) { 1024 e.preventDefault(); 1025 e.stopPropagation(); 1026 var link = $(this).attr('href'); 1027 window.location.href = link; 1028 }); 1029 }); 1030 }); 1031} 1032 1033function wpfdSearchPreviewThemeActions() { 1034 var $ = jQuery; 1035 var sourcefile = $("#wpfd-template-preview-box").html(); 1036 $('.wpfd-content .wpfd-file-link').unbind('click').click(function (e) { 1037 e.preventDefault(); 1038 var fileid = $(this).data('id'); 1039 var categoryid = $(this).data('category_id'); 1040 var preview_root_cat = $(this).data('category_id'); 1041 $.ajax({ 1042 url: wpfdparams.wpfdajaxurl + "task=file.display&view=file&id=" + fileid + "&categoryid=" + categoryid + "&rootcat=" + preview_root_cat, 1043 dataType: "json", 1044 beforeSend: function () { 1045 // setting a timeout 1046 if ($('body').has('wpfd-preview-box-loader') !== true) { 1047 $('body').append('<div class="wpfd-preview-box-loader"></div>'); 1048 } 1049 } 1050 }).done(function (file) { 1051 var template = Handlebars.compile(sourcefile); 1052 var html = template(file); 1053 var box = $("#wpfd-preview-box"); 1054 $('.wpfd-preview-box-loader').each(function () { 1055 $(this).remove(); 1056 }); 1057 if (box.length === 0) { 1058 $('body').append('<div id="wpfd-preview-box" style="display: none;"></div>'); 1059 box = $("#wpfd-preview-box"); 1060 } 1061 box.empty(); 1062 box.prepend(html); 1063 box.attr('data-id', fileid); 1064 box.attr('data-catid', categoryid);
1065 box.attr('class', 'wpfd-preview-box wpfd-download-box wpfd-search-preview-box'); 1066 if (typeof (file.file.ext) !== 'undefined') { 1067 box.attr('data-type', file.file.ext); 1068 box.addClass(file.file.ext); 1069 } 1070 box.click(function (e) { 1071 if ($(e.target).is('#wpfd-preview-box')) { 1072 box.hide(); 1073 } 1074 $('#wpfd-preview-box').unbind('click.box').bind('click.box', function (e) { 1075 if ($(e.target).is('#wpfd-preview-box')) { 1076 box.hide(); 1077 } 1078 }); 1079 }); 1080 1081 if ($("#wpfd-preview-box .file-custom-field.file-url").length) { 1082 var link = typeof (wpfdparams.translates.wpfd_url_custom_field) !== 'undefined' ? wpfdparams.translates.wpfd_url_custom_field : 'Link'; 1083 $("#wpfd-preview-box .file-custom-field.file-url").each(function () { 1084 var label = $(this).attr('data-field-label'); 1085 var url = $(this).attr('data-field-val'); 1086 var urlContents = '<div><span>
1086' + label + ': </span><a href="' + url + '" target="_blank">' + link + '</a></div>'; 1087 $(this).empty().append(urlContents); 1088 }); 1089 } 1090 1091 if (typeof (file.file.linkdownload) !== 'undefined') { 1092 var previewLinkDownload = '<input type="hidden" class="wpfd_file_preview_link_download" value="' + file.file.linkdownload + '" data-filetitle="' + file.file.post_title + '" />'; 1093 box.prepend(previewLinkDownload); 1094 } 1095 1096 $('#wpfd-preview-box .wpfd-close').click(function (e) { 1097 e.preventDefault(); 1098 box.hide(); 1099 }); 1100 1101 box.show(); 1102 1103 var dropblock = box.find('.dropblock'); 1104 if ($(window).width() < 400) { 1105 dropblock.css('margin-top', '0'); 1106 dropblock.css('margin-left', '0'); 1107 dropblock.css('top', '0'); 1108 dropblock.css('left', '0'); 1109 dropblock.height($(window).height() - parseInt(dropblock.css('padding-top'), 10) - parseInt(dropblock.css('padding-bottom'), 10)); 1110 dropblock.width($(window).width() - parseInt(dropblock.css('padding-left'), 10) - parseInt(dropblock.css('padding-right'), 10)); 1111 } else { 1112 dropblock.css('margin-top', (-(dropblock.height() / 2) - 20) + 'px'); 1113 dropblock.css('margin-left', (-(dropblock.width() / 2) - 20) + 'px'); 1114 dropblock.css('height', ''); 1115 dropblock.css('width', ''); 1116 dropblock.css('top', ''); 1117 dropblock.css('left', ''); 1118 } 1119 1120 if (dropblock && typeof (file.file.ID) !== 'undefined') { 1121 dropblock.attr('data-id', file.file.ID); 1122 } 1123 1124 if (typeof wpfdColorboxInit !== 'undefined') { 1125 wpfdColorboxInit(); 1126 } 1127 1128 $('body.elementor-default #wpfd-preview-box a.wpfd_downloadlink').on('click', function (e) { 1129 e.preventDefault(); 1130 e.stopPropagation(); 1131 var link = $(this).attr('href'); 1132 window.location.href = link; 1133 }); 1134 1135 if (typeof (wpfdparams.wpfd_directly_preview_on_popup) !== 'undefined' 1136 && parseInt(wpfdparams.wpfd_directly_preview_on_popup) === 1 && $('#wpfd-preview-box.wpfd-search-preview-box .wpfd_previewlink').length) { 1137 $('#wpfd-preview-box.wpfd-search-preview-box .wpfd_previewlink').click(); 1138 $('#wpfd-preview-box.wpfd-search-preview-box').hide(); 1139 } 1140 }); 1141 }); 1142} 1143 1144function wpfdWooCommerceAddToCart() { 1145 if (typeof ('wc_add_to_cart_params') === "undefined") { 1146 return false; 1147 } 1148 1149 var $ = jQuery; 1150 $('.wpfd_downloadlink:has(.wpfd-add-to-cart)').unbind('click').click(function (e) { 1151 var $this = $(this); 1152 1153 if (!$this.attr('data-product_id')) { 1154 return true; 1155 } 1156 1157 e.preventDefault(); 1158 1159 var url = $this.attr('href'); 1160 var data = {}; 1161 $.each($this.data(), function (key, value) { 1162 data[key] = value; 1163 }); 1164 1165 jQuery.ajax({ 1166 url: wc_add_to_cart_params.wc_ajax_url.toString().replace('%%endpoint%%', 'add_to_cart'), 1167 method: 'POST', 1168 data: data, 1169 success: function (response, status, xhr) { 1170 if (!response) { 1171 return; 1172 } 1173 1174 if (response.error && response.product_url) { 1175 window.location = response.product_url; 1176 return; 1177 } 1178 1179 // Redirect to cart option 1180 if (wc_add_to_cart_params.cart_redirect_after_add === 'yes') { 1181 window.location = wc_add_to_cart_params.cart_url; 1182 return; 1183 } 1184 1185 // Trigger event so themes can refresh other areas. 1186 $(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash, $this]); 1187 1188 // Fallback, made sure added to cart button added. 1189 if (!wc_add_to_cart_params.is_cart && $this.parent().find('.added_to_cart').length === 0) { 1190 $this.removeClass('loading'); 1191 $this.addClass('added'); 1192 $this.after(' <a href="' + wc_add_to_cart_params.cart_url + '" class="added_to_cart wc-forward" title="' + 1193 wc_add_to_cart_params.i18n_view_cart + '">' + wc_add_to_cart_params.i18n_view_cart + '</a>'); 1194 } 1195 }, 1196 }); 1197 return false;
1198 }); 1199} 1200 1201function wpfdViewMoreFileDescription() { 1202 var $ = jQuery; 1203 $('.wpfd-file-view-more-description').unbind('click').click(function (e) { 1204 var $this = $(this); 1205 1206 e.preventDefault(); 1207 1208 var description = ''; 1209 if ($(this).parent().find('.wpfd-file-description')) { 1210 description = $(this).parent().find('.wpfd-file-description').val(); 1211 } 1212 1213 var box = $("#wpfd-file-description-box"); 1214 if (box.length === 0) { 1215 $('body').append('<div id="wpfd-file-description-box" style="display: none;"></div>'); 1216 box = $("#wpfd-file-description-box"); 1217 } 1218 box.empty(); 1219 box.prepend('<p class="files-desc-contents">' + description + '</p>'); 1220 box.append('<button title="Close (Esc)" type="button" class="wpfd-close">Ã</button>'); 1221 1222 box.click(function (e) { 1223 if ($(e.target).is('#wpfd-file-description-box')) { 1224 box.hide(); 1225 } 1226 $('#wpfd-file-description-box').unbind('click.box').bind('click.box', function (e) { 1227 if ($(e.target).is('#wpfd-file-description-box')) { 1228 box.hide(); 1229 } 1230 }); 1231 }); 1232 1233 $('#wpfd-file-description-box .wpfd-close').click(function (e) { 1234 e.preventDefault(); 1235 box.hide(); 1236 }); 1237 1238 box.show(); 1239 1240 var dropblock = box.find('.dropblock'); 1241 if ($(window).width() < 400) { 1242 dropblock.css('margin-top', '0'); 1243 dropblock.css('margin-left', '0'); 1244 dropblock.css('top', '0'); 1245 dropblock.css('left', '0'); 1246 dropblock.height($(window).height() - parseInt(dropblock.css('padding-top'), 10) - parseInt(dropblock.css('padding-bottom'), 10)); 1247 dropblock.width($(window).width() - parseInt(dropblock.css('padding-left'), 10) - parseInt(dropblock.css('padding-right'), 10)); 1248 } else { 1249 dropblock.css('margin-top', (-(dropblock.height() / 2) - 20) + 'px'); 1250 dropblock.css('margin-left', (-(dropblock.width() / 2) - 20) + 'px'); 1251 dropblock.css('height', ''); 1252 dropblock.css('width', ''); 1253 dropblock.css('top', ''); 1254 dropblock.css('left', ''); 1255 } 1256 }); 1257} 1258 1259// Prevent manually typing into the input (date filter), but allow to delete old value 1260function wpfdCheckInput(event) { 1261 var key = event.keyCode || event.charCode; 1262 // detect backspace or del key 1263 if (key != 8 && key != 46) { 1264 return false; 1265 } 1266} 1267 1268// Validate number input for weight filter, but allow to delete old value 1269function wpfdValidateNumberInput(e) { 1270 var key = e.keyCode || e.charCode; 1271 // detect backspace or del key 1272 if (key != 8 && key != 46 && isNaN(e.key)) { 1273 return false; 1274 } 1275} 1276 1277jQuery(document).ready(function ($) { 1278 window.file_suggestion_ajax_on_search = null; 1279 window.ajax_search_handler = null; 1280 window.file_tag_ajax_on_search = null; 1281 var suggestionEventId; 1282 initSorting(); 1283 1284 // Init tags 1285 $(".chk_ftags").click(function () { 1286 fillInputTags(); 1287 }); 1288 1289 // Call filter type chosen 1290 if ($('select[name="extension"]').length) { 1291 $('select[name="extension"]').chosen({width: '100%', search_contains: true}); 1292 } else { 1293 setTimeout(function () { 1294 if ($('select[name="extension"]').length) { 1295 $('select[name="extension"]').chosen({width: '100%', search_contains: true}); 1296 } 1297 }, 3000); 1298 } 1299 if ($('.fusion-builder-live').length || $('.et_divi_theme.et-fb').length) { 1300 setInterval(function () { 1301 if ($(".wpfd-adminForm").length) { 1302 if ($('select[name="extension"]').length) { 1303 if ($('.et_divi_theme.et-fb').length) { 1304 $('select[name="extension"]').chosen({width: '100%', search_contains: true}); 1305 } else { 1306 $('select[name="extension"]').empty(); 1307 var newOption = $('<option value="1">test</option>'); 1308 $('select[name="extension"]').append(newOption); 1309 $('select[name="extension"]').trigger("chosen:updated"); 1310 } 1311 } else { 1312 setTimeout(function () { 1313 if ($('select[name="extension"]').length) { 1314 if ($('.et_divi_theme.et-fb').length) { 1315 $('select[name="extension"]').chosen({width: '100%', search_contains: true}); 1316 } else { 1317 $('select[name="extension"]').empty(); 1318 var newOption = $('<option value="1">test</option>'); 1319 $('select[name="extension"]').append(newOption); 1320 $('select[name="extension"]').trigger("chosen:updated"); 1321 } 1322 } 1323 }, 3000); 1324 } 1325 } 1326 }, 1000); 1327 } 1328 1329 $(".filter_catid").change(function () { 1330 // Clear search 1331 var $ = jQuery; 1332 var categoryId = $(this).val(); 1333 var cateType = $(this).parent().find('.cate-list .cate-item[data-catid="' + categoryId + '"]').data('cattype'); 1334 catChange($(this)); 1335 }); 1336 1337 $('.qCatesearch').on('keydown keyup', function (e) { 1338 if (e.keyCode === 13 || e.which === 13 || e.key === 'Enter') { 1339 e.preventDefault(); 1340 return; 1341 } 1342 var scateList, filter, labl, txtValue; 1343 var $this = $(this); 1344 scateList = $("li.cate-item", $this.parent().parent()); 1345 1346 filter = $this.val().toUpperCase(); 1347 scateList.each(function () { 1348 labl = $(this).find("label"); 1349 txtValue = labl.text().toUpperCase(); 1350 if (txtValue.indexOf(filter) > -1) { 1351 $(this).css("display", ""); 1352 } else { 1353 $(this).css("display", "none"); 1354 } 1355 }); 1356 }); 1357 $(".wpfd-adminForm").submit(function (e) { 1358 e.preventDefault(); 1359 return false;
1360 }); 1361 $('.txtfilename:not(".wpfd-form-search-file-category .txtfilename")').on('keyup', function (e) { 1362 var $this = $(this); 1363 if (e.keyCode === 13 || e.which === 13 || e.key === 'Enter') { 1364 e.preventDefault(); 1365 1366 if ($this.val() === '') { 1367 return; 1368 } 1369 1370 var prevFileSuggestionAjax = window.file_suggestion_ajax_on_search; 1371 if (prevFileSuggestionAjax !== null) { 1372 prevFileSuggestionAjax.abort(); 1373 } 1374 1375 $this.closest('form').find('.wpfd-icon-search').show(); 1376 $this.closest('form').find('.wpfd-icon-search-loading').hide(); 1377 1378 var formID = '#' + $this.closest('form').attr('id'); 1379 ajaxSearch(formID); 1380 1381 return; 1382 } 1383 }); 1384 1385 // Make file suggestion handler 1386 $('.txtfilename:not(".wpfd-form-search-file-category .txtfilename")').on('input', function (e) { 1387 // Only make file suggestion on search engine when enabling option 1388 if (!parseInt(wpfdvars.search_file_suggestion)) { 1389 return; 1390 } 1391 1392 var keySearch = $(this).val(); 1393 var searchLength = keySearch.replace(/ /g, '').length; 1394 var doFilterSuggestion = searchLength >= 3 ? true : false; 1395 var formID = '#' + $(this).closest('form').attr('id'); 1396 $(this).closest('form').find(".wpfd_search_file_suggestion").hide(); 1397 1398 if (doFilterSuggestion) { 1399 clearTimeout(suggestionEventId); 1400 suggestionEventId = setTimeout(function () { 1401 makeFileSuggestion(formID); 1402 }, 800); 1403 } else { 1404 var prevFileSuggestionAjax = window.file_suggestion_ajax_on_search; 1405 1406 if (prevFileSuggestionAjax !== null && activeSearchForm === formID) { 1407 prevFileSuggestionAjax.abort(); 1408 } 1409 1410 $(this).closest('form').find('.wpfd-icon-search').show(); 1411 $(this).closest('form').find('.wpfd-icon-search-loading').hide(); 1412 } 1413 }); 1414 1415 jQuery('.icon-date').click(function () { 1416 var txt = jQuery(this).attr('data-id'); 1417 if (txt !== 'cfrom' && txt !== 'cto' && txt !== 'ufrom' && txt !== 'uto') { 1418 jQuery('#' + txt).datetimepicker('show'); 1419 } 1420 }); 1421 1422 // Date time picker 1423 jQuery('.wpfd-adminForm').each(function () { 1424 $sForm = $(this); 1425 wpfdSingleDateTimePicker($sForm.find('.cfrom'), $sForm); 1426 wpfdSingleDateTimePicker($sForm.find('.cto'), $sForm); 1427 wpfdSingleDateTimePicker($sForm.find('.ufrom'), $sForm); 1428 wpfdSingleDateTimePicker($sForm.find('.uto'), $sForm); 1429 }); 1430 1431 jQuery('.feature-toggle').click(function () { 1432 var containerId = jQuery(this).parents('.wpfd-adminForm').attr('id'); 1433 var container = '#' + containerId; 1434 jQuery(container).find('.feature').slideToggle('slow', function () { 1435 jQuery(container).find('.feature-toggle').toggleClass(function () { 1436 if (jQuery(this).is(".toggle-arrow-up-alt")) { 1437 return "toggle-arrow-down-alt"; 1438 } else { 1439 return "toggle-arrow-up-alt"; 1440 } 1441 }); 1442 }); 1443 }); 1444 1445 // Ajax filters 1446 $(".btnsearchbelow:not('.wpfd-form-search-file-category .btnsearchbelow'):not('#btnReset'), .btnsearch:not('.wpfd-form-search-file-category .btnsearchbelow')").on('click', function (e) { 1447 e.preventDefault(); 1448 var prevFileSuggestionAjax = window.file_suggestion_ajax_on_search; 1449 if (prevFileSuggestionAjax !== null) { 1450 prevFileSuggestionAjax.abort(); 1451 } 1452 1453 $(this).closest('form').find('.wpfd-icon-search').show(); 1454 $(this).closest('form').find('.wpfd-icon-search-loading').hide(); 1455 var formID = '#' + $(this).closest('form').attr('id'); 1456 ajaxSearch(formID); 1457 return false; 1458 }); 1459 1460 $('#btnReset').on('click', function (e) { 1461 e.preventDefault(); 1462 resetFilters('.wpfd-adminForm'); 1463 $('#wpfd-results').html(''); 1464 return false; 1465 }); 1466 1467 $("#widget_btnReset").on('click', function (e) { 1468 e.preventDefault(); 1469 resetFilters('#widget_search'); 1470 }); 1471 1472 // Get checkbox tags 1473 selectdChecktags(); 1474 1475 // Show category 1476 showCategory(); 1477 1478 // Select categories actions 1479 selectCategoriesActions(); 1480 1481 // Display selected category when reload. 1482 wpfdshowCateReload(); 1483 1484 // Set folder icon for parent-folder 1485 parentFolderIcon(); 1486 1487 // Add placeholder when tag search box is selected 1488 wpfdAddPlaceholder(); 1489 1490 // Get search full width 1491 fullWidthSearch(); 1492 1493 // Get searchbox 1494 addtoSearchbuttonbelow(); 1495 1496 noTagscase(); 1497 1498 jQuery('.list-results table tr td a.file-item').click(function (e) { 1499 return true; 1500 }); 1501 1502 resetFilters = function (formSelect) { 1503 var sform = $("#adminForm"); 1504 if (formSelect !== null && formSelect !== undefined) { 1505 sform = $(formSelect); 1506 }
1507 var inputs = $(sform).find('input:not([name="catid"]):not([name="theme"]), select:not([name="from_weight_unit"]):not([name="to_weight_unit"])'); 1508 1509 $.each(inputs, function (i, el) { 1510 var eType = $(el).attr('type'); 1511 if (eType === 'checkbox') { 1512 $(el).prop('checked', false); 1513 } else { 1514 $(el).val(''); 1515 if ($(el).hasClass("tagit")) { 1516 $(el).tagit("removeAll"); 1517 } 1518 } 1519 }); 1520 1521 if ($('select[name="from_weight_unit"]').length) { 1522 $('select[name="from_weight_unit"]').val('kb'); 1523 } 1524 1525 if ($('select[name="to_weight_unit"]').length) { 1526 $('select[name="to_weight_unit"]').val('kb'); 1527 } 1528 1529 if ($('select[name="extension"]').length) { 1530 $('select[name="extension"]').val(''); 1531 $('select[name="extension"] + .chzn-container .chzn-single > span').html('-- Select type --'); 1532 $('select[name="extension"] + .chzn-container .chzn-choices .search-choice').remove(); 1533 } 1534 1535 if (!$('.wpfd-listCate').is(':hidden')) { 1536 $('#filter_catid').val(''); 1537 } 1538 1539 $('.tags-item').removeClass('active'); 1540 if ($('.categories-filtering-selection .cate-lab').length) { 1541 $('.cate-item').removeClass('checked'); 1542 var wpfdlCurrentselectedCate = $(".categories-filtering .cate-lab"); 1543 if (wpfdlCurrentselectedCate.hasClass('display-cate')) { 1544 wpfdlCurrentselectedCate.removeClass('display-cate'); 1545 } 1546 wpfdlCurrentselectedCate.empty(); 1547 var rootCateId = $('.categories-filtering-selection #cate-list > .search-cate + li.cate-item').data('catid'); 1548 var rootSearchCategoryLabel = $('.categories-filtering-selection #cate-list > .search-cate + li.cate-item').find('label').html(); 1549 rootSearchCategoryLabel = rootSearchCategoryLabel !== '' ? rootSearchCategoryLabel : wpfdvars.msg_file_category; 1550 $('.categories-filtering-selection #filter_catid').val(rootCateId); 1551 wpfdlCurrentselectedCate.append("<label id='root-cate'>" + rootSearchCategoryLabel + "</label>"); 1552 } 1553 }; 1554 1555 populateFilters = function (filters) { 1556 var sform = $("#adminForm"); 1557 $.each(filters, function (f, v) { 1558 var els = $('[name=' + f + ']', sform); 1559 if (els.length > 0) { 1560 if ($(els).hasClass("tagit")) { 1561 $(els).tagit("removeAll"); 1562 if (v !== "") { 1563 var tgs = v.split(","); 1564 for (var i = 0; i < tgs.length; i++) { 1565 $(els).tagit("createTag", tgs[i]); 1566 } 1567 } 1568 } else { 1569 $(els).val(v); 1570 } 1571 $(els).trigger('change').trigger("liszt:updated").trigger("chosen:updated"); 1572 } 1573 }); 1574 }; 1575 1576 // Remove property with empty value 1577 cleanObj = function (obj) { 1578 for (var k in obj) { 1579 if (obj.hasOwnProperty(k)) { 1580 if (!obj[k]) delete obj[k]; 1581 } 1582 } 1583 return obj; 1584 }; 1585 1586 // Back on browser 1587 jQuery(window).on('popstate', function (event) { 1588 var state = event.originalEvent && typeof event.originalEvent.state !== 'undefined' ? event.originalEvent.state : event.state; 1589 resetFilters(); 1590 if (state !== null) { 1591 var params = getSearchParams(); 1592 if (typeof params === 'object' && !jQuery.isEmptyObject(params)) { 1593 var formData = state; 1594 populateFilters(formData); 1595 ajaxSearch('.wpfd-adminForm', false, false, false); 1596 } else { 1597 $("#wpfd-results").html(""); 1598 } 1599 } else { 1600 $("#wpfd-results").html(""); 1601 } 1602 }); 1603 var params = getSearchParams(); 1604 if (params.q !== undefined || 1605 params.catid !== undefined || 1606 params.ftags !== undefined || 1607 params.cfrom !== undefined || 1608 params.cto !== undefined || 1609 params.ufrom !== undefined || 1610 params.uto !== undefined 1611 ) { 1612 ajaxSearch('.wpfd-adminForm'); 1613 } 1614 1615 preSearchDownloadSelectedFiles(); 1616 searchDownloadSelectedFiles(); 1617 wpfdSearchGGDThemeActions(); 1618 wpfdViewMoreFileDescription(); 1619});
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.