$(function() { var scntDiv = $('#uploadArea'); var i = 1; i++; $('#image1').fileupload({ disableImageResize: false, imageForceResize: true, imageQuality: 0.2 }); $(document).on('click', '#removeUpload2', function() { $('#preview2').css('background-image', 'url(https://media.profilelink.ru/showcase/plus.png)'); $("#image2").val(''); $("#removeUpload2").hide(); }); $(document).on('click', '#removeUpload3', function() { $('#preview3').css('background-image', 'url(https://media.profilelink.ru/showcase/plus.png)'); $("#image3").val(''); $("#removeUpload3").hide(); }); $(document).on('click', '#removeUpload4', function() { $('#preview4').css('background-image', 'url(https://media.profilelink.ru/showcase/plus.png)'); $("#image4").val(''); $("#removeUpload4").hide(); }); $(document).on('click', '#removeUpload5', function() { $('#preview5').css('background-image', 'url(https://media.profilelink.ru/showcase/plus.png)'); $("#image5").val(''); $("#removeUpload5").hide(); }); $(document).on('click', '#removeUpload6', function() { $('#preview6').css('background-image', 'url(https://media.profilelink.ru/showcase/plus.png)'); $("#image6").val(''); $("#removeUpload6").hide(); }); }); function ValidateSize(file) { var FileSize = file.files[0].size / 1024 / 1024; // in MB if (FileSize > 5) { alert('Максимальный размер изображения - 5 мегабайт.\nПожалуйста, выберите другое изображение.'); $(file).val(''); //for clearing with Jquery } } $(function () { $("#sale").click(function () { if ($(this).is(":checked")) { $("#forSale").show(); } else { $("#forSale").hide(); $("#sellprice").val(""); } }); }); $(function () { $("#inputSite").click(function () { if ($(this).is(":checked")) { $("#site").show(); } else { $("#site").hide(); $("#url_title").val(""); $("#urlAdr").val(""); } }); }); function pr1(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('#preview1').css('background-image', 'url(' + e.target.result + ')'); } reader.readAsDataURL(input.files[0]); // convert to base64 string $("#img2").show(); } } $("#image1").change(function() { pr1(this); }); function pr2(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('#preview2').css('background-image', 'url(' + e.target.result + ')'); } reader.readAsDataURL(input.files[0]); // convert to base64 string $("#img3").show(); $('#removeUpload2').css('display', 'block'); } } $("#image2").change(function() { pr2(this); }); function pr3(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('#preview3').css('background-image', 'url(' + e.target.result + ')'); } reader.readAsDataURL(input.files[0]); // convert to base64 string $("#img4").show(); $('#removeUpload3').css('display', 'block'); } } $("#image3").change(function() { pr3(this); }); function pr4(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('#preview4').css('background-image', 'url(' + e.target.result + ')'); } reader.readAsDataURL(input.files[0]); // convert to base64 string $("#img5").show(); $('#removeUpload4').css('display', 'block'); } } $("#image4").change(function() { pr4(this); }); function pr5(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('#preview5').css('background-image', 'url(' + e.target.result + ')'); } reader.readAsDataURL(input.files[0]); // convert to base64 string $("#img6").show(); $('#removeUpload5').css('display', 'block'); } } $("#image5").change(function() { pr5(this); }); function pr6(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e) { $('#preview6').css('background-image', 'url(' + e.target.result + ')'); } reader.readAsDataURL(input.files[0]); // convert to base64 string $('#removeUpload6').css('display', 'block'); } } $("#image6").change(function() { pr6(this); }); function search() { var query = document.querySelector('#productSearch').value.toUpperCase(); var elements = document.querySelectorAll('tbody > tr'); for (var i = 0; i < elements.length; i ++) { var el = elements[i]; if (el.innerText.toUpperCase().indexOf(query) !== -1) { el.style.display = ''; //document.getElementById('ohno').style.display = 'none'; //document.getElementById('productsTable').style.display = ''; } else { el.style.display = 'none'; //document.getElementById('ohno').style.display = 'block'; //document.getElementById('productsTable').style.display = 'none'; } } } $('form[name="create_category"]').on('submit', event => { $.ajax({ type: 'POST', url: 'store-ajax', data: $(event.currentTarget).serialize(), success: (data) => { if(data.status == 'error') { let notification_container = $(event.currentTarget).find('.notification-container'); notification_container.html(''); display_notifications(data.message, 'error', notification_container); } else if(data.status == 'success') { /* Fade out refresh */ fade_out_redirect({ url: data.details.url, full: true }); } }, dataType: 'json' }); event.preventDefault(); }); $('form[name="edit_category"]').on('submit', event => { $.ajax({ type: 'POST', url: 'store-ajax', data: $(event.currentTarget).serialize(), success: (data) => { if(data.status == 'error') { let notification_container = $(event.currentTarget).find('.notification-container'); notification_container.html(''); display_notifications(data.message, 'error', notification_container); } else if(data.status == 'success') { /* Fade out refresh */ fade_out_redirect({ url: data.details.url, full: true }); } }, dataType: 'json' }); event.preventDefault(); }); $('[data-delete-category]').on('click', event => { /* Continue with the deletion */ ajax_call_helper(event, 'store-ajax', 'delete_category', () => { /* On success delete the actual row from the DOM */ $(event.currentTarget).closest('tr').remove(); fade_out_redirect({ url: `store` }); }); event.preventDefault(); }); $('[data-delete]').on('click', event => { /* Continue with the deletion */ ajax_call_helper(event, 'store-ajax', 'delete', () => { /* On success delete the actual row from the DOM */ $(event.currentTarget).closest('tr').remove(); fade_out_redirect({ url: `store` }); }); event.preventDefault(); });